<!DOCTYPE html>
<?php
/* Owner-only advisory composer — Owner→client push console.
   Vars: $baseUrl, $assetsUrl, $user, $advisories, $targets, $token */
if (!isset($baseUrl)) $baseUrl = '';
if (!isset($assetsUrl)) $assetsUrl = rtrim($baseUrl, '/') . '/assets';
$b = rtrim($baseUrl, '/');
$advisories = $advisories ?? [];
$targets = $targets ?? [];
$sevMeta = [
    'info'     => ['#4f46e5', 'megaphone', 'Notice'],
    'success'  => ['#10b981', 'check-circle', 'Good news'],
    'warning'  => ['#f59e0b', 'exclamation-triangle', 'Warning'],
    'critical' => ['#ef4444', 'shield-exclamation', 'Critical'],
];
?>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= htmlspecialchars(\PpPhp\Core\Brand::name()) ?> · Push advisories</title>
    <?php include constant('BASE_PATH') . '/core/views/favicon.php'; ?>
    <link href="<?= $assetsUrl ?>/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="<?= $assetsUrl ?>/icons/bootstrap-icons.css" rel="stylesheet">
    <?php include constant('BASE_PATH') . '/core/views/theme-head.php'; ?>
    <link href="<?= $assetsUrl ?>/sweetalert2/sweetalert2.min.css" rel="stylesheet">
    <script src="<?= $assetsUrl ?>/sweetalert2/sweetalert2.min.js"></script>
    <style>
        body { background: var(--pp-app-bg, #f5f6fa); color: var(--pp-text, #172033); }
        .adv-topbar { background: var(--pp-surface, #fff); border-bottom: 1px solid var(--pp-border, #e6e9f0);
            padding: .7rem 1rem; display: flex; align-items: center; gap: .8rem;
            position: sticky; top: 0; z-index: 1030; }
        .adv-topbar .brand { font-weight: 800; display: flex; align-items: center; gap: .5rem; color: var(--pp-text); text-decoration: none; }
        .adv-topbar .brand .bi { color: var(--pp-accent, #4f46e5); }
        .adv-wrap { max-width: 1120px; margin: 1.4rem auto 3rem; padding: 0 1rem;
            display: grid; grid-template-columns: 1.05fr 1fr; gap: 1.1rem; align-items: start; }
        @media (max-width: 900px) { .adv-wrap { grid-template-columns: 1fr; } }
        .adv-card { background: var(--pp-surface, #fff); border: 1px solid var(--pp-border, #e6e9f0);
            border-radius: 14px; padding: 1.25rem 1.35rem; margin-bottom: 1.1rem; }
        .adv-card h2 { font-size: 1rem; font-weight: 800; margin: 0 0 .2rem; display: flex; align-items: center; gap: .5rem; }
        .adv-card h2 .bi { color: var(--pp-accent, #4f46e5); }
        .adv-sub { color: var(--pp-text-muted, #64748b); font-size: .84rem; margin: 0 0 1rem; max-width: 66ch; }
        .adv-field { margin-bottom: .85rem; }
        .adv-field label { display: block; font-weight: 700; font-size: .8rem; margin-bottom: .3rem; }
        .adv-hint { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px;
            margin-left: .25rem; border-radius: 50%; background: var(--pp-surface-soft, #f1f5f9);
            color: var(--pp-text-muted, #94a3b8); font-size: .62rem; font-weight: 800; cursor: help; vertical-align: middle; }
        .adv-hint:hover, .adv-hint:focus-visible { background: color-mix(in srgb, var(--pp-accent, #4f46e5) 16%, transparent);
            color: var(--pp-accent, #4f46e5); outline: none; }

        /* ── Live bell preview (mirrors core/views/notification-bell.php) ── */
        .adv-preview { margin: 0 0 1.1rem; }
        .adv-preview-label { font-size: .68rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase;
            color: var(--pp-text-muted, #94a3b8); margin-bottom: .4rem; display: flex; align-items: center; gap: .35rem; }
        .adv-bellitem { --sev: #4f46e5; display: flex; gap: 11px; padding: 12px 13px; text-decoration: none; color: inherit;
            border: 1px solid var(--pp-border, #e6e9f0); border-radius: 13px; background: var(--pp-surface, #fff);
            box-shadow: 0 10px 26px rgba(2, 6, 23, .10); transition: box-shadow .18s; }
        .adv-bellitem.pinned { background: linear-gradient(120deg, color-mix(in srgb, var(--sev) 12%, var(--pp-surface, #fff)),
            color-mix(in srgb, var(--sev) 4%, var(--pp-surface, #fff))); border-color: color-mix(in srgb, var(--sev) 26%, transparent); }
        .adv-bellitem.sev-left { box-shadow: inset 3px 0 0 var(--sev), 0 10px 26px rgba(2, 6, 23, .10); }
        .adv-bell-ic { flex: 0 0 34px; width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center;
            justify-content: center; font-size: 15px; color: var(--sev);
            background: color-mix(in srgb, var(--sev) 14%, var(--pp-surface, #fff)); }
        .adv-bellitem.pinned .adv-bell-ic { color: #fff; background: linear-gradient(135deg, var(--sev), color-mix(in srgb, var(--sev) 60%, #000)); }
        .adv-bell-body { min-width: 0; flex: 1; }
        .adv-bell-title { display: block; font-size: 13px; font-weight: 800; color: var(--pp-text, #1e293b); }
        .adv-bell-pill { display: none; margin-left: 7px; vertical-align: middle; padding: 1px 7px; border-radius: 999px;
            font-size: 9.5px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: #fff; background: var(--sev); }
        .adv-bellitem.show-pill .adv-bell-pill { display: inline-block; }
        .adv-bell-text { display: block; font-size: 12px; line-height: 1.5; color: var(--pp-text-muted, #64748b); margin-top: 2px; overflow-wrap: anywhere; }
        .adv-bell-time { display: block; font-size: 10.5px; color: var(--pp-text-muted, #94a3b8); margin-top: 4px; }
        .adv-field .form-control, .adv-field .form-select { border-radius: 9px; }
        .adv-seg { display: flex; gap: .4rem; flex-wrap: wrap; }
        .adv-seg input { position: absolute; opacity: 0; pointer-events: none; }
        .adv-seg label { cursor: pointer; border: 1px solid var(--pp-border, #e2e8f0); border-radius: 999px;
            padding: .35rem .8rem; font-size: .8rem; font-weight: 700; margin: 0; display: inline-flex; align-items: center; gap: .35rem;
            color: var(--pp-text-muted, #64748b); background: var(--pp-surface, #fff); transition: all .12s; }
        .adv-seg input:checked + label { color: #fff; border-color: transparent; }
        .adv-seg.sev input[value="info"]:checked + label     { background: #4f46e5; }
        .adv-seg.sev input[value="success"]:checked + label  { background: #10b981; }
        .adv-seg.sev input[value="warning"]:checked + label  { background: #f59e0b; }
        .adv-seg.sev input[value="critical"]:checked + label { background: #ef4444; }
        .adv-seg.gen input:checked + label { background: var(--pp-accent, #4f46e5); }
        .adv-targets { border: 1px solid var(--pp-border, #e2e8f0); border-radius: 10px; max-height: 190px; overflow-y: auto; padding: .3rem; }
        .adv-targets .t { display: flex; align-items: center; gap: .5rem; padding: .3rem .45rem; border-radius: 7px; font-size: .82rem; }
        .adv-targets .t:hover { background: var(--pp-surface-soft, #f8fafc); }
        .adv-targets .t small { color: var(--pp-text-muted, #94a3b8); }
        .adv-list-item { border: 1px solid var(--pp-border, #e6e9f0); border-radius: 12px; padding: .85rem 1rem; margin-bottom: .7rem;
            display: flex; gap: .8rem; align-items: flex-start; }
        .adv-list-item .ic { flex: 0 0 34px; width: 34px; height: 34px; border-radius: 9px; display: flex; align-items: center;
            justify-content: center; color: #fff; font-size: 16px; }
        .adv-list-item .meta { flex: 1; min-width: 0; }
        .adv-list-item .meta strong { font-size: .92rem; }
        .adv-list-item .meta .b { color: var(--pp-text-muted, #64748b); font-size: .82rem; margin-top: 2px; }
        .adv-badge { display: inline-block; font-size: .66rem; font-weight: 800; text-transform: uppercase; letter-spacing: .03em;
            padding: 1px 7px; border-radius: 999px; margin-left: .4rem; vertical-align: middle; }
        .adv-badge.live { background: color-mix(in srgb, #10b981 16%, var(--pp-surface)); color: #047857; }
        .adv-badge.retired { background: var(--pp-surface-soft, #eef1f6); color: var(--pp-text-muted, #64748b); }
        .adv-badge.apply { background: color-mix(in srgb, #ef4444 16%, var(--pp-surface)); color: #b91c1c; }
        .adv-actions { display: flex; gap: .35rem; flex-shrink: 0; }
        .adv-actions button { border: 1px solid var(--pp-border, #e2e8f0); background: var(--pp-surface, #fff); border-radius: 8px;
            width: 32px; height: 32px; cursor: pointer; color: var(--pp-text-muted, #64748b); }
        .adv-actions button:hover { color: var(--pp-accent, #4f46e5); border-color: var(--pp-accent, #4f46e5); }
        .adv-empty { text-align: center; color: var(--pp-text-muted, #64748b); padding: 26px; font-size: .88rem; }
        .adv-hero { background: linear-gradient(135deg, color-mix(in srgb, var(--pp-accent) 12%, var(--pp-surface)),
            color-mix(in srgb, var(--pp-accent) 3%, var(--pp-surface))); border: 1px solid color-mix(in srgb, var(--pp-accent) 22%, transparent);
            border-radius: 14px; padding: 1rem 1.2rem; margin-bottom: 1.1rem; }
        .adv-hero h1 { font-size: 1.15rem; font-weight: 800; margin: 0 0 .2rem; }
        .adv-hero p { margin: 0; color: var(--pp-text-muted, #64748b); font-size: .85rem; }
    </style>
</head>
<body>
<div class="adv-topbar">
    <a href="<?= $b ?>/licensing/server" class="brand"><i class="bi bi-arrow-left-short"></i> Licence server</a>
    <span style="color:var(--pp-text-muted);font-size:.85rem">/ Push advisories</span>
    <div class="ms-auto d-flex align-items-center gap-2" style="margin-left:auto">
        <a href="<?= $b ?>/help/advisories" target="_blank" rel="noopener" class="btn btn-sm btn-outline-secondary"
           data-tip="How pushing notices &amp; critical patches to your clients works">
            <i class="bi bi-question-circle"></i> Guide
        </a>
        <?php include constant('BASE_PATH') . '/core/views/theme-toggle.php'; ?>
    </div>
</div>

<div style="max-width:1120px;margin:1.2rem auto 0;padding:0 1rem">
    <div class="adv-hero">
        <h1><i class="bi bi-broadcast"></i> Push advisories to your licensed clients</h1>
        <p>Compose a notice or a critical security patch. Every licensed client verifies it against your signing key and shows it in the bell on its next check-in — critical patches can install themselves. Nothing is ever sent to an unlicensed or tampered copy.</p>
    </div>
</div>

<div class="adv-wrap">
    <!-- Composer -->
    <div>
        <div class="adv-card">
            <h2><i class="bi bi-pencil-square"></i> <span id="advFormTitle">New advisory</span></h2>
            <p class="adv-sub">Fill this in and publish. Live advisories reach clients on their next check-in.</p>

            <div class="adv-preview">
                <div class="adv-preview-label"><i class="bi bi-bell"></i> Live preview — how it lands in the client's bell</div>
                <a class="adv-bellitem" id="advPrev">
                    <span class="adv-bell-ic" id="advPrevIc"><i class="bi bi-megaphone"></i></span>
                    <span class="adv-bell-body">
                        <span class="adv-bell-title"><span id="advPrevTitle">Your title…</span><span class="adv-bell-pill" id="advPrevPill">Update</span></span>
                        <span class="adv-bell-text" id="advPrevText">Your message shows here.</span>
                        <span class="adv-bell-time">Just now</span>
                    </span>
                </a>
            </div>

            <form id="advForm">
                <input type="hidden" name="uid" id="advUid" value="">
                <div class="adv-field">
                    <label for="advTitle">Title</label>
                    <input class="form-control" id="advTitle" name="title" maxlength="180" placeholder="e.g. Important security update" required>
                </div>
                <div class="adv-field">
                    <label for="advBody">Message</label>
                    <textarea class="form-control" id="advBody" name="body" rows="3" placeholder="What the administrator should know…"></textarea>
                </div>
                <div class="adv-field">
                    <label>Severity <span class="adv-hint" tabindex="0" title="How prominent the notice is on the client: Critical shows red and pinned; Warning amber; Notice/Good news are calmer. Critical is also required for an auto-installing patch.">?</span></label>
                    <div class="adv-seg sev" id="advSev">
                        <?php foreach ($sevMeta as $k => $m): ?>
                        <input type="radio" name="severity" id="sev_<?= $k ?>" value="<?= $k ?>" <?= $k === 'info' ? 'checked' : '' ?>>
                        <label for="sev_<?= $k ?>"><i class="bi bi-<?= $m[1] ?>"></i> <?= $m[2] ?></label>
                        <?php endforeach; ?>
                    </div>
                </div>
                <div class="adv-field">
                    <label>Type <span class="adv-hint" tabindex="0" title="Notice only = a message in the client bell. Critical patch = also tells clients (with auto-security on) to install a specific version through the signed pipeline, restore-point first.">?</span></label>
                    <div class="adv-seg gen" id="advAction">
                        <input type="radio" name="action" id="act_notice" value="notice" checked>
                        <label for="act_notice"><i class="bi bi-chat-left-text"></i> Notice only</label>
                        <input type="radio" name="action" id="act_apply" value="apply">
                        <label for="act_apply"><i class="bi bi-shield-lock"></i> Critical patch (auto-install)</label>
                    </div>
                    <div id="advApplyRow" class="mt-2" style="display:none">
                        <input class="form-control" name="applyVersion" id="advApplyVersion" placeholder="Target version (optional, e.g. 1.4.0) — leave blank for latest">
                        <small class="text-muted">Clients with auto-security on install this through the signed pipeline (restore-point first). Forces severity to Critical.</small>
                    </div>
                </div>
                <div class="adv-field">
                    <label for="advLink">Link (optional) <span class="adv-hint" tabindex="0" title="Where the bell notice takes the admin when clicked — e.g. /platform/updates, or a full https:// URL.">?</span></label>
                    <input class="form-control" id="advLink" name="link" placeholder="/platform/updates or https://…">
                </div>
                <div class="adv-field">
                    <label>Audience <span class="adv-hint" tabindex="0" title="Everyone = all your licensed clients. Specific installs = only the installations you pick below (targeting is decided on the server from the authenticated licence).">?</span></label>
                    <div class="adv-seg gen" id="advAudience">
                        <input type="radio" name="audience" id="aud_all" value="all" checked>
                        <label for="aud_all"><i class="bi bi-globe"></i> Everyone</label>
                        <input type="radio" name="audience" id="aud_lic" value="licenses">
                        <label for="aud_lic"><i class="bi bi-bullseye"></i> Specific installs</label>
                    </div>
                    <div id="advTargetsWrap" class="mt-2" style="display:none">
                        <div class="adv-targets" id="advTargets">
                            <?php if (!$targets): ?>
                                <div class="adv-empty">No installations have checked in yet.</div>
                            <?php else: foreach ($targets as $t): ?>
                                <label class="t">
                                    <input type="checkbox" class="advTgt" value="<?= htmlspecialchars($t['id']) ?>">
                                    <span><?= htmlspecialchars($t['label']) ?> <small><?= htmlspecialchars(substr($t['id'], 0, 12)) ?>…</small></span>
                                </label>
                            <?php endforeach; endif; ?>
                        </div>
                    </div>
                </div>
                <div class="adv-field">
                    <label for="advExpires">Expires (optional) <span class="adv-hint" tabindex="0" title="After this date/time the advisory stops being sent to clients. Leave blank to keep pushing it until you retire it.">?</span></label>
                    <input class="form-control" id="advExpires" name="expiresAt" placeholder="YYYY-MM-DD HH:MM — blank = never">
                </div>
                <div class="d-flex gap-2 mt-3">
                    <button type="submit" class="btn btn-primary"><i class="bi bi-send"></i> Publish advisory</button>
                    <button type="button" class="btn btn-link text-muted" id="advReset">Clear</button>
                </div>
            </form>
        </div>
    </div>

    <!-- Existing advisories -->
    <div>
        <div class="adv-card">
            <h2><i class="bi bi-collection"></i> Published &amp; drafts</h2>
            <p class="adv-sub">Retire an advisory to stop pushing it; clients keep any they've already received.</p>
            <div id="advList">
                <?php if (!$advisories): ?>
                    <div class="adv-empty"><i class="bi bi-inbox d-block" style="font-size:26px;opacity:.5"></i>No advisories yet.</div>
                <?php else: foreach ($advisories as $a):
                    $m = $sevMeta[$a['severity']] ?? $sevMeta['info']; ?>
                    <div class="adv-list-item" data-adv='<?= htmlspecialchars(json_encode($a), ENT_QUOTES) ?>'>
                        <div class="ic" style="background:<?= $m[0] ?>"><i class="bi bi-<?= $m[1] ?>"></i></div>
                        <div class="meta">
                            <strong><?= htmlspecialchars($a['title']) ?></strong>
                            <span class="adv-badge <?= $a['status'] === 'live' ? 'live' : 'retired' ?>"><?= htmlspecialchars($a['status']) ?></span>
                            <?php if ($a['action'] === 'apply'): ?><span class="adv-badge apply">auto-install</span><?php endif; ?>
                            <div class="b"><?= htmlspecialchars(mb_strimwidth((string) $a['body'], 0, 90, '…')) ?></div>
                            <div class="b" style="font-size:.74rem;opacity:.8">
                                <?= $a['audience'] === 'all' ? 'Everyone' : (count($a['targets']) . ' install(s)') ?>
                                · <?= htmlspecialchars($a['createdAt']) ?>
                            </div>
                        </div>
                        <div class="adv-actions">
                            <button title="Edit" data-act="edit"><i class="bi bi-pencil"></i></button>
                            <button title="<?= $a['status'] === 'live' ? 'Retire' : 'Re-activate' ?>" data-act="toggle"><i class="bi bi-<?= $a['status'] === 'live' ? 'pause' : 'play' ?>"></i></button>
                            <button title="Delete" data-act="delete"><i class="bi bi-trash"></i></button>
                        </div>
                    </div>
                <?php endforeach; endif; ?>
            </div>
        </div>
    </div>
</div>

<script>
(function () {
    var b = <?= json_encode($b) ?>, token = <?= json_encode($token) ?>;
    var form = document.getElementById('advForm');
    var applyRow = document.getElementById('advApplyRow'), targetsWrap = document.getElementById('advTargetsWrap');

    var SEV = { info: ['megaphone', '#4f46e5'], success: ['check-circle', '#10b981'],
               warning: ['exclamation-triangle', '#f59e0b'], critical: ['shield-exclamation', '#ef4444'] };

    function currentSeverity() {
        var r = document.querySelector('input[name="severity"]:checked');
        return r ? r.value : 'info';
    }
    function updatePreview() {
        var prev = document.getElementById('advPrev');
        var sev = currentSeverity();
        var meta = SEV[sev] || SEV.info;
        var isApply = document.getElementById('act_apply').checked;
        var link = (document.getElementById('advLink').value || '').trim();
        prev.style.setProperty('--sev', meta[1]);
        document.getElementById('advPrevIc').innerHTML = '<i class="bi bi-' + (isApply ? 'shield-exclamation' : meta[0]) + '"></i>';
        var title = (document.getElementById('advTitle').value || '').trim();
        var body = (document.getElementById('advBody').value || '').trim();
        document.getElementById('advPrevTitle').textContent = title || 'Your title…';
        document.getElementById('advPrevText').textContent = body || 'Your message shows here.';
        // Pinned/pill when it links to updates or is a critical patch — mirrors the bell.
        var pinned = isApply || /\/platform\/updates$/.test(link);
        prev.classList.toggle('pinned', pinned);
        prev.classList.toggle('show-pill', pinned);
        prev.classList.toggle('sev-left', !pinned && (sev === 'warning' || sev === 'critical'));
        document.getElementById('advPrevPill').textContent = isApply ? 'Security' : 'Update';
    }

    function syncConditionals() {
        applyRow.style.display = document.getElementById('act_apply').checked ? '' : 'none';
        targetsWrap.style.display = document.getElementById('aud_lic').checked ? '' : 'none';
        // A critical patch forces severity to Critical.
        if (document.getElementById('act_apply').checked) {
            var c = document.getElementById('sev_critical'); if (c) c.checked = true;
        }
        updatePreview();
    }
    document.getElementById('advAction').addEventListener('change', syncConditionals);
    document.getElementById('advAudience').addEventListener('change', syncConditionals);
    document.getElementById('advSev').addEventListener('change', updatePreview);
    ['advTitle', 'advBody', 'advLink'].forEach(function (id) { document.getElementById(id).addEventListener('input', updatePreview); });

    function post(path, body) {
        return fetch(b + path, {
            method: 'POST', headers: { 'Content-Type': 'application/json' },
            credentials: 'same-origin', body: JSON.stringify(Object.assign({ _token: token }, body))
        }).then(function (r) { return r.json(); });
    }
    function toast(icon, title) { Swal.fire({ toast: true, position: 'top-end', icon: icon, title: title, showConfirmButton: false, timer: 2200, timerProgressBar: true }); }

    form.addEventListener('submit', function (e) {
        e.preventDefault();
        var fd = new FormData(form);
        var targets = Array.prototype.map.call(document.querySelectorAll('.advTgt:checked'), function (c) { return c.value; });
        var body = {
            uid: fd.get('uid') || '', title: fd.get('title') || '', body: fd.get('body') || '',
            severity: fd.get('severity') || 'info', action: fd.get('action') || 'notice',
            applyVersion: fd.get('applyVersion') || '', audience: fd.get('audience') || 'all',
            targets: targets, link: fd.get('link') || '', expiresAt: fd.get('expiresAt') || '', status: 'live'
        };
        if (!body.title.trim()) { toast('error', 'A title is required.'); return; }
        if (body.audience === 'licenses' && !targets.length) { toast('error', 'Pick at least one install.'); return; }
        post('/licensing/advisories/save', body).then(function (j) {
            if (j && j.success) { toast('success', 'Advisory published.'); setTimeout(function () { location.reload(); }, 700); }
            else { Swal.fire({ icon: 'error', title: 'Could not save', text: (j && j.message) || 'Unknown error' }); }
        });
    });

    document.getElementById('advReset').addEventListener('click', function () {
        form.reset(); document.getElementById('advUid').value = '';
        document.getElementById('advFormTitle').textContent = 'New advisory';
        Array.prototype.forEach.call(document.querySelectorAll('.advTgt'), function (c) { c.checked = false; });
        syncConditionals();
    });

    document.getElementById('advList').addEventListener('click', function (e) {
        var btn = e.target.closest('button[data-act]'); if (!btn) return;
        var item = btn.closest('.adv-list-item'); var a = JSON.parse(item.getAttribute('data-adv'));
        var act = btn.getAttribute('data-act');
        if (act === 'edit') {
            document.getElementById('advUid').value = a.uid;
            document.getElementById('advTitle').value = a.title;
            document.getElementById('advBody').value = a.body;
            var sev = document.getElementById('sev_' + a.severity); if (sev) sev.checked = true;
            document.getElementById(a.action === 'apply' ? 'act_apply' : 'act_notice').checked = true;
            document.getElementById('advApplyVersion').value = a.applyVersion || '';
            document.getElementById('advLink').value = a.link || '';
            document.getElementById('advExpires').value = a.expiresAt || '';
            document.getElementById(a.audience === 'licenses' ? 'aud_lic' : 'aud_all').checked = true;
            Array.prototype.forEach.call(document.querySelectorAll('.advTgt'), function (c) { c.checked = (a.targets || []).indexOf(c.value) >= 0; });
            document.getElementById('advFormTitle').textContent = 'Edit advisory';
            syncConditionals();
            window.scrollTo({ top: 0, behavior: 'smooth' });
        } else if (act === 'toggle') {
            var next = a.status === 'live' ? 'retired' : 'live';
            post('/licensing/advisories/status', { uid: a.uid, status: next }).then(function (j) {
                if (j && j.success) { toast('success', j.message); setTimeout(function () { location.reload(); }, 500); }
            });
        } else if (act === 'delete') {
            Swal.fire({
                icon: 'warning', title: 'Delete this advisory?',
                text: 'Clients that already received it keep it; it just stops being pushed.',
                showCancelButton: true, confirmButtonText: 'Delete', confirmButtonColor: '#ef4444'
            }).then(function (res) {
                if (!res.isConfirmed) return;
                post('/licensing/advisories/delete', { uid: a.uid }).then(function (j) {
                    if (j && j.success) { toast('success', 'Deleted.'); setTimeout(function () { location.reload(); }, 500); }
                });
            });
        }
    });

    syncConditionals();
}());
</script>
</body>
</html>
