From f368af57a943d046b9e1cef5a4653ea083851ab7 Mon Sep 17 00:00:00 2001 From: Dillon <260170482+dillonlille@users.noreply.github.com> Date: Sun, 13 Sep 2026 00:55:37 +0000 Subject: [PATCH 1/2] Fix Paycom credential saves under DSP capacity contention --- core/accounts/src/onboarding-store.js | 6 +- core/accounts/src/owner-paycom-setup.js | 7 +- core/api/directory-platform.js | 4 +- core/auth-broker/README.md | 6 ++ core/auth-broker/coordinator.js | 11 ++- core/auth-broker/tests/coordinator.test.js | 75 +++++++++++++++++++ core/auth-broker/tests/enrollment.test.js | 43 +++++++++++ core/installations/src/owner-onboarding.js | 6 +- dashboard/frontend/src/pages/Connections.tsx | 9 ++- dashboard/public/assets/frontend.js | 2 +- .../browser/connections-persistence.spec.cjs | 49 +++++++++++- .../tests/connections-persistence.test.js | 54 +++++++++++++ dashboard/tests/helpers/connections-stack.cjs | 21 +++++- host/controller/paycom-enrollment.js | 34 +++++++++ 14 files changed, 309 insertions(+), 18 deletions(-) create mode 100644 core/auth-broker/tests/enrollment.test.js create mode 100644 host/controller/paycom-enrollment.js diff --git a/core/accounts/src/onboarding-store.js b/core/accounts/src/onboarding-store.js index 2fbe5dc..3cc48a6 100644 --- a/core/accounts/src/onboarding-store.js +++ b/core/accounts/src/onboarding-store.js @@ -57,6 +57,10 @@ function createOnboardingStore(store, clock = Date.now) { if (db.prepare("UPDATE installation_onboarding_requests SET status=?,failure_code=?,lease_expires_at=NULL,updated_at=? WHERE id=? AND status='running' AND worker_id=? AND fence=? AND lease_expires_at>?") .run(code ? 'failed' : 'succeeded', code, clock(), row.id, row.worker_id, row.fence, clock()).changes !== 1) fail(); } - return { get, latest, prior, begin, enrolled, enrollmentFailed, candidates, claim, renew, finish, requeue }; + function defer(row) { + if (db.prepare("UPDATE installation_onboarding_requests SET status='queued',attempt=attempt-1,worker_id=NULL,lease_expires_at=NULL,updated_at=? WHERE id=? AND status='running' AND worker_id=? AND fence=? AND lease_expires_at>?") + .run(clock(), row.id, row.worker_id, row.fence, clock()).changes !== 1) fail(); + } + return { get, latest, prior, begin, enrolled, enrollmentFailed, candidates, claim, renew, finish, requeue, defer }; } module.exports = { createOnboardingStore, LEASE_MS }; diff --git a/core/accounts/src/owner-paycom-setup.js b/core/accounts/src/owner-paycom-setup.js index a83960d..f22e549 100644 --- a/core/accounts/src/owner-paycom-setup.js +++ b/core/accounts/src/owner-paycom-setup.js @@ -7,7 +7,8 @@ const { managedInstallationContext } = require('./installation-authority'); const { createAccessInstallationActivationAuthority } = require('./installation-activation'); const { createOnboardingStore } = require('./onboarding-store'); function fail(code, status = 409) { throw new AccessError(code, status); } -function createOwnerPaycomSetup({ store, access, invoke, clock = Date.now }) { +function createOwnerPaycomSetup({ store, access, invoke, clock = Date.now, + enroll = (key, input) => invoke(key, 'paycom.setup', input) }) { const requests = createOnboardingStore(store, clock); function context(session) { require('./plugins').requirePlugin(access, session, 'paycom'); @@ -89,7 +90,7 @@ function createOwnerPaycomSetup({ store, access, invoke, clock = Date.now }) { guard(); row = requests.begin(selected.organization.id, session.user.id, input.idempotencyKey, input.intent, selected.manifest.revision); }); - const result = await invoke(selected.manifest.runtime.key, 'paycom.setup', { + const result = await enroll(selected.manifest.runtime.key, { command: 'enroll', requestId: row.id, expiresAt: clock() + 30_000, credentials, intent: input.intent, }); if (!result?.ok || result.status !== 'succeeded' || result.data?.configured !== true) fail(setupFailure(result?.status)); @@ -111,7 +112,7 @@ function createOwnerPaycomSetup({ store, access, invoke, clock = Date.now }) { try { row = requests.begin(selected.organization.id, session.user.id, input.idempotencyKey, input.intent, selected.manifest.revision); authority.guard(() => true); - const result = await invoke(selected.manifest.runtime.key, 'paycom.setup', { + const result = await enroll(selected.manifest.runtime.key, { command: 'enroll', requestId: row.id, expiresAt: clock() + 30_000, credentials, intent: input.intent, }); authority.guard(() => true); diff --git a/core/api/directory-platform.js b/core/api/directory-platform.js index 6d3845b..153a35b 100644 --- a/core/api/directory-platform.js +++ b/core/api/directory-platform.js @@ -80,7 +80,9 @@ async function startDirectoryApi({ paths, installation, host, port = 4310, addre ? require('../../host/plugins/directory-lifecycle').createDirectoryInstallation({ paths, manager: runtime.manager, execution, store }) : null; const plugins = require('../accounts/src/plugins').createPluginService({ store, access, invoke, installationCoordinator, settingsPort: runtime.manager.pluginBackend ? (id,pluginId,request) => runtime.manager.pluginBackend.request(id,'plugin.settings',{pluginId,request}) : null }); - const paycomSetup = createOwnerPaycomSetup({ store, access, invoke }); + const paycomSetup = createOwnerPaycomSetup({ store, access, invoke, + ...(runtime.manager.pluginBackend ? { enroll: require('../../host/controller/paycom-enrollment') + .createPaycomEnrollment({ backend: runtime.manager.pluginBackend }) } : {}) }); const connections = createOwnerConnections({ store, access, invoke, paycomSetup }); const onboarding = createOwnerOnboardingWorker({ store, invoke, backends: [BACKEND] }); const backups = new ManualBackups({ paths, store, access }); diff --git a/core/auth-broker/README.md b/core/auth-broker/README.md index fb85a30..ad55283 100644 --- a/core/auth-broker/README.md +++ b/core/auth-broker/README.md @@ -19,6 +19,12 @@ pin the DSP's acknowledged package digest and revision; declaring a service in a manifest does not grant it automatically. Core may relay owner credentials in memory to that DSP's worker, but does not persist them or log them. +When another DSP is queued, idle authentication workers yield their slots even +if status polling keeps them warm. Active requests, provider verification and +plugin browser leases retain their workers. Directory DSPs enroll Paycom through +the vault worker without waking the full collection runtime; subsequent setup +waits in its existing onboarding queue when runtime capacity is occupied. + The existing provider session, attempt-guard, native Chrome and assistance code is reused. Paycom's adapter comes from the DSP's installed package. Cortex stays a built-in automatic sign-in and owner-entered email-code connection. A plugin diff --git a/core/auth-broker/coordinator.js b/core/auth-broker/coordinator.js index 00aaa43..7b1bb91 100644 --- a/core/auth-broker/coordinator.js +++ b/core/auth-broker/coordinator.js @@ -155,12 +155,17 @@ class AuthenticationCoordinator { if (this.polling) return this.polling; this.polling = (async () => { for (const [dspId, entry] of this.dsps) { - if (!entry.row || entry.requests || entry.closing) continue; + if (!entry.row || entry.requests || entry.waiters || entry.closing) continue; try { const response = await this.workers.request(entry.row, { action: 'activity' }); if (!response.ok) throw new Error(); - if (entry.requests) continue; - if (!response.busy && this.clock() - entry.lastUsed >= this.idleMs) await this.closeEntry(dspId, entry); + if (entry.requests || entry.waiters) continue; + const leased = [...this.sessions.values()].some(session => session.entry === entry); + // Status polling can keep an otherwise idle worker warm forever. + // Give queued DSPs its slot after the worker confirms it is idle; + // in-progress sign-ins, verification and plugin leases stay intact. + const waiting = this.manager.status().queued > 0; + if (!response.busy && !leased && (waiting || this.clock() - entry.lastUsed >= this.idleMs)) await this.closeEntry(dspId, entry); else await this.manager.renew(entry.context, entry.lease.leaseId); } catch { await this.closeEntry(dspId, entry); } } diff --git a/core/auth-broker/tests/coordinator.test.js b/core/auth-broker/tests/coordinator.test.js index c44084a..6792611 100644 --- a/core/auth-broker/tests/coordinator.test.js +++ b/core/auth-broker/tests/coordinator.test.js @@ -69,3 +69,78 @@ test('one admitted auth worker serves a DSP; SDK leases remain bound to the orig assert.equal(stopped.length, 2); assert.equal(manager.status().sessions, 0); }); +test('a third DSP can save while status polling keeps idle authentication workers warm', async t => { + const root = fs.mkdtempSync(path.join(os.tmpdir(), 'dispatch-auth-fairness-')); + const store = new BrowserStore(path.join(root, 'state/browser.sqlite3')); + const ids = ['a', 'b', 'c'].map(letter => 'dsp_' + letter.repeat(32)); + const busy = new Set([ids[0]]), stopped = [], saved = []; + const workers = { + start: async row => ({ protocol: 'worker', endpoint: 'worker://' + row.id, access: row.id }), + close: async row => { stopped.push(row.dsp_id); return true; }, + request: async (row, request) => { + if (request.action === 'activity') return { ok: true, busy: busy.has(row.dsp_id) }; + if (request.action === 'connections') return { ok: true, items: [] }; + assert.equal(request.action, 'enroll-paycom'); + saved.push(row.dsp_id); return { ok: true, status: 'configured' }; + }, + }; + const manager = new BrowserManager({ store, workers, authorize: () => true, limits: { sessions: 2, tabs: 12 } }); + await manager.start(); + const coordinator = new AuthenticationCoordinator({ manager, workers, idleMs: 60000, + contextFor: dspId => ({ dspId, pluginId: 'core-auth', installationRevision: 1, jobId: 'auth' }), + authorizeRequest: () => true, authorizePlugin: () => true, relay: () => { throw new Error('no browser needed'); }, + }); + t.after(async () => { await coordinator.close(); await manager.close(); store.close(); fs.rmSync(root, { recursive: true, force: true }); }); + for (const id of ids.slice(0, 2)) await coordinator.request(id, { action: 'connections', input: { command: 'list' } }); + const pending = coordinator.request(ids[2], { action: 'enroll-paycom', intent: 'create', credentials: { password: 'synthetic-fair-save' } }, + { signal: AbortSignal.timeout(3000) }); + // Attach immediately so a regression's timeout is an ordinary test failure. + const outcome = pending.then(value => ({ value }), error => ({ error })); + await new Promise(resolve => setImmediate(resolve)); + assert.equal(manager.status().queued, 1); + await coordinator.poll(); + assert.deepEqual(stopped, [ids[1]], 'the active sign-in must keep its worker'); + await manager.pump(); + const result = await outcome; + assert.equal(result.error, undefined); + assert.equal(result.value.status, 'configured'); + assert.deepEqual(saved, [ids[2]]); + assert.equal(manager.status().sessions, 2); + assert.equal(fs.readFileSync(path.join(root, 'state/browser.sqlite3')).includes('synthetic-fair-save'), false); +}); + +test('queued DSPs do not evict an in-flight request or an outstanding plugin browser lease', async t => { + const root = fs.mkdtempSync(path.join(os.tmpdir(), 'dispatch-auth-contention-')); + const store = new BrowserStore(path.join(root, 'state/browser.sqlite3')); + const ids = ['a', 'b'].map(letter => 'dsp_' + letter.repeat(32)), stopped = []; + let unblock, hold = false; + const workers = { + start: async row => ({ protocol: 'worker', endpoint: 'worker://' + row.id, access: row.id }), + close: async row => { stopped.push(row.dsp_id); return true; }, + request: async (_row, request) => { + if (request.action === 'activity') return { ok: true, busy: false }; + if (hold) await new Promise(resolve => { unblock = resolve; }); + return { ok: true, items: [] }; + }, + }; + const manager = new BrowserManager({ store, workers, authorize: () => true, limits: { sessions: 1, tabs: 6 } }); + await manager.start(); + const coordinator = new AuthenticationCoordinator({ manager, workers, idleMs: 60000, + contextFor: dspId => ({ dspId, pluginId: 'core-auth', installationRevision: 1, jobId: 'auth' }), + authorizeRequest: () => true, authorizePlugin: () => true, relay: () => {}, + }); + t.after(async () => { unblock?.(); coordinator.sessions.clear(); await coordinator.close(); await manager.close(); store.close(); fs.rmSync(root, { recursive: true, force: true }); }); + const list = id => coordinator.request(id, { action: 'connections', input: { command: 'list' } }); + await list(ids[0]); hold = true; + const reading = list(ids[0]); + await new Promise(resolve => setImmediate(resolve)); + const cancel = new AbortController(); + const queued = coordinator.request(ids[1], { action: 'connections', input: { command: 'list' } }, { signal: cancel.signal }); + const cancelled = assert.rejects(queued, { code: 'cancelled' }); + await new Promise(resolve => setImmediate(resolve)); + await coordinator.poll(); assert.deepEqual(stopped, []); + hold = false; unblock(); await reading; + coordinator.sessions.set('retained', { entry: coordinator.dsps.get(ids[0]) }); + await coordinator.poll(); assert.deepEqual(stopped, []); + coordinator.sessions.clear(); cancel.abort(); await cancelled; +}); diff --git a/core/auth-broker/tests/enrollment.test.js b/core/auth-broker/tests/enrollment.test.js new file mode 100644 index 0000000..45fbb1b --- /dev/null +++ b/core/auth-broker/tests/enrollment.test.js @@ -0,0 +1,43 @@ +'use strict'; +const test = require('node:test'); +const assert = require('node:assert/strict'); +const { createPaycomEnrollment } = require('../../../host/controller/paycom-enrollment'); +const dsp = 'dsp_' + 'a'.repeat(32); +const input = () => ({ command: 'enroll', requestId: 'setup_' + 'b'.repeat(32), expiresAt: Date.now() + 30000, + intent: 'create', credentials: { clientCode: 'synthetic', username: 'synthetic', password: 'synthetic-secret', + pin1: 'one', pin2: 'two', pin3: 'three', pin4: 'four', pin5: 'five' } }); + +test('direct enrollment forwards only to the selected DSP and confirms the vault acknowledgement', async () => { + const calls = []; + const enroll = createPaycomEnrollment({ backend: { request: async (...args) => { + calls.push(args); return { ok: true, status: 'configured' }; + } } }); + assert.deepEqual(await enroll(dsp, input()), { contractVersion: 1, ok: true, status: 'succeeded', data: { configured: true } }); + assert.equal(calls[0][0], dsp); assert.equal(calls[0][1], 'auth.request'); + assert.equal(calls[0][2].action, 'enroll-paycom'); assert.equal(calls[0][2].intent, 'create'); + assert.ok(calls[0][3].signal instanceof AbortSignal); + assert.equal((await enroll(dsp, { ...input(), expiresAt: Date.now() - 1 })).status, 'invalid_input'); + assert.equal(calls.length, 1); +}); + +test('only an explicit missing profile permits create fallback for replacement', async () => { + let status = 'profile_not_configured'; const intents = []; + const enroll = createPaycomEnrollment({ backend: { request: async (_id, _op, request) => { + intents.push(request.intent); + return request.intent === 'create' ? { ok: true, status: 'configured' } : { ok: false, status }; + } } }); + assert.equal((await enroll(dsp, { ...input(), intent: 'replace' })).ok, true); + assert.deepEqual(intents, ['replace', 'create']); + status = 'profile_locked'; intents.length = 0; + assert.equal((await enroll(dsp, { ...input(), intent: 'replace' })).status, 'profile_locked'); + assert.deepEqual(intents, ['replace']); +}); + +test('lost or invalid enrollment acknowledgements report an unconfirmed save without replay', async () => { + for (const respond of [() => { throw new Error('lost response'); }, () => ({ ok: true, status: 'unexpected' })]) { + let calls = 0; + const enroll = createPaycomEnrollment({ backend: { request: async () => { calls++; return respond(); } } }); + await assert.rejects(enroll(dsp, input()), { code: 'auth_unavailable', statusCode: 503 }); + assert.equal(calls, 1); + } +}); diff --git a/core/installations/src/owner-onboarding.js b/core/installations/src/owner-onboarding.js index ae7c0c4..e921aaa 100644 --- a/core/installations/src/owner-onboarding.js +++ b/core/installations/src/owner-onboarding.js @@ -43,6 +43,10 @@ function createOwnerOnboardingWorker({ store, invoke, backends = ['oci_container manifestAuthority: selected.manifestAuthority, parameters: {}, }); guard(); + if (!result?.ok && result?.status === 'execution_capacity_wait' && selected.backend === 'directory_service_v1') { + requests.defer(row); + return { status: 'queued' }; + } if (!result?.ok) fail(setupFailure(result?.status)); if (result.status === 'succeeded') { if (step === 'sync') { @@ -75,7 +79,7 @@ function createOwnerOnboardingWorker({ store, invoke, backends = ['oci_container for (const [index, row] of candidates.entries()) { try { const result = await run(row.id, `${workerId}_${index}`); - if (result.status === 'succeeded') completed += 1; else failed += 1; + if (result.status === 'succeeded') completed += 1; else if (result.status === 'failed') failed += 1; } catch { failed += 1; } } return { processed: candidates.length, completed, failed }; diff --git a/dashboard/frontend/src/pages/Connections.tsx b/dashboard/frontend/src/pages/Connections.tsx index 7618cca..4500fa1 100644 --- a/dashboard/frontend/src/pages/Connections.tsx +++ b/dashboard/frontend/src/pages/Connections.tsx @@ -269,7 +269,9 @@ export function Connections() { caught.status >= 500) ) { setSaveUnconfirmed(true); - await query.refetch(); + // Reconcile in the background so a slow status check cannot trap the + // owner in a disabled credential dialog after the save already failed. + void query.refetch().catch(() => {}); } } finally { setBusy(null); @@ -490,7 +492,10 @@ export function Connections() { > Cancel - + Save and connect diff --git a/dashboard/public/assets/frontend.js b/dashboard/public/assets/frontend.js index 68aff9b..3033b45 100644 --- a/dashboard/public/assets/frontend.js +++ b/dashboard/public/assets/frontend.js @@ -46,4 +46,4 @@ Error generating stack: `+e.message+` `},Ss=function(){var e=parseInt(document.body.getAttribute(`data-scroll-locked`)||`0`,10);return isFinite(e)?e:0},Cs=function(){x.useEffect(function(){return document.body.setAttribute(bs,(Ss()+1).toString()),function(){var e=Ss()-1;e<=0?document.body.removeAttribute(bs):document.body.setAttribute(bs,e.toString())}},[])},ws=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,i=r===void 0?`margin`:r;Cs();var a=x.useMemo(function(){return vs(i)},[i]);return x.createElement(ys,{styles:xs(a,!t,i,n?``:`!important`)})},Ts=!1;if(typeof window<`u`)try{var Es=Object.defineProperty({},"passive",{get:function(){return Ts=!0,!0}});window.addEventListener(`test`,Es,Es),window.removeEventListener(`test`,Es,Es)}catch{Ts=!1}var Ds=Ts?{passive:!1}:!1,Os=function(e){return e.tagName===`TEXTAREA`},ks=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!==`hidden`&&!(n.overflowY===n.overflowX&&!Os(e)&&n[t]===`visible`)},As=function(e){return ks(e,`overflowY`)},js=function(e){return ks(e,`overflowX`)},Ms=function(e,t){var n=t.ownerDocument,r=t;do{if(typeof ShadowRoot<`u`&&r instanceof ShadowRoot&&(r=r.host),Fs(e,r)){var i=Is(e,r);if(i[1]>i[2])return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Ns=function(e){return[e.scrollTop,e.scrollHeight,e.clientHeight]},Ps=function(e){return[e.scrollLeft,e.scrollWidth,e.clientWidth]},Fs=function(e,t){return e===`v`?As(t):js(t)},Is=function(e,t){return e===`v`?Ns(t):Ps(t)},Ls=function(e,t){return e===`h`&&t===`rtl`?-1:1},Rs=function(e,t,n,r,i){var a=Ls(e,window.getComputedStyle(t).direction),o=a*r,s=n.target,c=t.contains(s),l=!1,u=o>0,d=0,f=0;do{if(!s)break;var p=Is(e,s),m=p[0],h=p[1]-p[2]-a*m;(m||h)&&Fs(e,s)&&(d+=h,f+=m);var g=s.parentNode;s=g&&g.nodeType===Node.DOCUMENT_FRAGMENT_NODE?g.host:g}while(!c&&s!==document.body||c&&(t.contains(s)||t===s));return(u&&(i&&Math.abs(d)<1||!i&&o>d)||!u&&(i&&Math.abs(f)<1||!i&&-o>f))&&(l=!0),l},zs=function(e){return`changedTouches`in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Bs=function(e){return[e.deltaX,e.deltaY]},Vs=function(e){return e&&`current`in e?e.current:e},Hs=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Us=function(e){return` .block-interactivity-${e} {pointer-events: none;} .allow-interactivity-${e} {pointer-events: all;} -`},Ws=0,Gs=[];function Ks(e){var t=x.useRef([]),n=x.useRef([0,0]),r=x.useRef(),i=x.useState(Ws++)[0],a=x.useState(ms)[0],o=x.useRef(e);x.useEffect(function(){o.current=e},[e]),x.useEffect(function(){if(e.inert){document.body.classList.add(`block-interactivity-${i}`);var t=Ho([e.lockRef.current],(e.shards||[]).map(Vs),!0).filter(Boolean);return t.forEach(function(e){return e.classList.add(`allow-interactivity-${i}`)}),function(){document.body.classList.remove(`block-interactivity-${i}`),t.forEach(function(e){return e.classList.remove(`allow-interactivity-${i}`)})}}},[e.inert,e.lockRef.current,e.shards]);var s=x.useCallback(function(e,t){if(`touches`in e&&e.touches.length===2||e.type===`wheel`&&e.ctrlKey)return!o.current.allowPinchZoom;var i=zs(e),a=n.current,s=`deltaX`in e?e.deltaX:a[0]-i[0],c=`deltaY`in e?e.deltaY:a[1]-i[1],l,u=e.target,d=Math.abs(s)>Math.abs(c)?`h`:`v`;if(`touches`in e&&d===`h`&&u.type===`range`)return!1;var f=window.getSelection(),p=f&&f.anchorNode;if(p&&(p===u||p.contains(u)))return!1;var m=Ms(d,u);if(!m)return!0;if(m?l=d:(l=d===`v`?`h`:`v`,m=Ms(d,u)),!m)return!1;if(!r.current&&`changedTouches`in e&&(s||c)&&(r.current=l),!l)return!0;var h=r.current||l;return Rs(h,t,e,h===`h`?s:c,!0)},[]),c=x.useCallback(function(e){var n=e;if(Gs.length&&Gs[Gs.length-1]===a){var r=`deltaY`in n?Bs(n):zs(n),i=t.current.filter(function(e){return e.name===n.type&&(e.target===n.target||n.target===e.shadowParent)&&Hs(e.delta,r)})[0];if(i&&i.should){n.cancelable&&n.preventDefault();return}if(!i){var c=(o.current.shards||[]).map(Vs).filter(Boolean).filter(function(e){return e.contains(n.target)});(c.length>0?s(n,c[0]):!o.current.noIsolation)&&n.cancelable&&n.preventDefault()}}},[]),l=x.useCallback(function(e,n,r,i){var a={name:e,delta:n,target:r,should:i,shadowParent:qs(r)};t.current.push(a),setTimeout(function(){t.current=t.current.filter(function(e){return e!==a})},1)},[]),u=x.useCallback(function(e){n.current=zs(e),r.current=void 0},[]),d=x.useCallback(function(t){l(t.type,Bs(t),t.target,s(t,e.lockRef.current))},[]),f=x.useCallback(function(t){l(t.type,zs(t),t.target,s(t,e.lockRef.current))},[]);x.useEffect(function(){return Gs.push(a),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:f}),document.addEventListener(`wheel`,c,Ds),document.addEventListener(`touchmove`,c,Ds),document.addEventListener(`touchstart`,u,Ds),function(){Gs=Gs.filter(function(e){return e!==a}),document.removeEventListener(`wheel`,c,Ds),document.removeEventListener(`touchmove`,c,Ds),document.removeEventListener(`touchstart`,u,Ds)}},[]);var p=e.removeScrollBar,m=e.inert;return x.createElement(x.Fragment,null,m?x.createElement(a,{styles:Us(i)}):null,p?x.createElement(ws,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function qs(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}var Js=ns(rs,Ks),Ys=x.forwardRef(function(e,t){return x.createElement(as,Bo({},e,{ref:t,sideCar:Js}))});Ys.classNames=as.classNames;var Xs=function(e){return typeof document>`u`?null:(Array.isArray(e)?e[0]:e).ownerDocument.body},Zs=new WeakMap,Qs=new WeakMap,$s={},ec=0,tc=function(e){return e&&(e.host||tc(e.parentNode))},nc=function(e,t){return t.map(function(t){if(e.contains(t))return t;var n=tc(t);return n&&e.contains(n)?n:(console.error(`aria-hidden`,t,`in not contained inside`,e,`. Doing nothing`),null)}).filter(function(e){return!!e})},rc=function(e,t,n,r){var i=nc(t,Array.isArray(e)?e:[e]);$s[n]||($s[n]=new WeakMap);var a=$s[n],o=[],s=new Set,c=new Set(i),l=function(e){e&&!s.has(e)&&(s.add(e),l(e.parentNode))};i.forEach(l);var u=function(e){e&&!c.has(e)&&Array.prototype.forEach.call(e.children,function(e){if(s.has(e))u(e);else try{var t=e.getAttribute(r),i=t!==null&&t!==`false`,c=(Zs.get(e)||0)+1,l=(a.get(e)||0)+1;Zs.set(e,c),a.set(e,l),o.push(e),c===1&&i&&Qs.set(e,!0),l===1&&e.setAttribute(n,`true`),i||e.setAttribute(r,`true`)}catch(t){console.error(`aria-hidden: cannot operate on `,e,t)}})};return u(t),s.clear(),ec++,function(){o.forEach(function(e){var t=Zs.get(e)-1,i=a.get(e)-1;Zs.set(e,t),a.set(e,i),t||(Qs.has(e)||e.removeAttribute(r),Qs.delete(e)),i||e.removeAttribute(n)}),ec--,ec||(Zs=new WeakMap,Zs=new WeakMap,Qs=new WeakMap,$s={})}},ic=function(e,t,n){n===void 0&&(n=`data-aria-hidden`);var r=Array.from(Array.isArray(e)?e:[e]),i=t||Xs(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll(`[aria-live], script`))),rc(r,i,n,`aria-hidden`)):function(){return null}},ac=Object.defineProperty,oc=(e,t)=>ac(e,`name`,{value:t,configurable:!0}),sc=`Dialog`,[cc,lc]=Zi(sc),[uc,dc]=cc(sc),fc=oc(e=>{let{__scopeDialog:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:o=!0}=e,s=x.useRef(null),c=x.useRef(null),[l,u]=Oa({prop:r,defaultProp:i??!1,onChange:a,caller:sc}),[d,f]=x.useState(0),[p,m]=x.useState(0);return(0,S.jsx)(uc,{scope:t,triggerRef:s,contentRef:c,contentId:Ka(),titleId:Ka(),descriptionId:Ka(),titlePresent:d>0,descriptionPresent:p>0,setTitleCount:f,setDescriptionCount:m,open:l,onOpenChange:u,onOpenToggle:x.useCallback(()=>u(e=>!e),[u]),modal:o,children:n})},`Dialog`),pc=`DialogPortal`,[mc,hc]=cc(pc,{forceMount:void 0}),gc=oc(e=>{let{__scopeDialog:t,forceMount:n,children:r,container:i}=e,a=dc(pc,t);return(0,S.jsx)(mc,{scope:t,forceMount:n,children:x.Children.map(r,e=>(0,S.jsx)(Ia,{present:n||a.open,children:(0,S.jsx)(Mo,{asChild:!0,container:i,children:e})}))})},`DialogPortal`),_c=`DialogOverlay`,vc=x.forwardRef(oc(function(e,t){let n=hc(_c,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=dc(_c,e.__scopeDialog);return a.modal?(0,S.jsx)(Ia,{present:r||a.open,children:(0,S.jsx)(bc,{...i,ref:t})}):null},`DialogOverlay`)),yc=W(`DialogOverlay.RemoveScroll`),bc=x.forwardRef(oc(function(e,t){let{__scopeDialog:n,...r}=e,i=dc(_c,n),a=Oi(t,so());return(0,S.jsx)(Ys,{as:yc,allowPinchZoom:!0,shards:[i.contentRef],children:(0,S.jsx)(Ki.div,{"data-state":Mc(i.open),...r,ref:a,style:{pointerEvents:`auto`,...r.style}})})},`DialogOverlayImpl`)),xc=`DialogContent`,Sc=x.forwardRef(oc(function(e,t){let n=hc(xc,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=dc(xc,e.__scopeDialog);return(0,S.jsx)(Ia,{present:r||a.open,children:a.modal?(0,S.jsx)(Cc,{...i,ref:t}):(0,S.jsx)(wc,{...i,ref:t})})},`DialogContent`)),Cc=x.forwardRef(oc(function(e,t){let n=dc(xc,e.__scopeDialog),r=x.useRef(null),i=Oi(t,n.contentRef,r);return x.useEffect(()=>{let e=r.current;if(e)return ic(e)},[]),(0,S.jsx)(Tc,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:G(e.onCloseAutoFocus,e=>{e.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:G(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0;(t.button===2||n)&&e.preventDefault()}),onFocusOutside:G(e.onFocusOutside,e=>e.preventDefault())})},`DialogContentModal`)),wc=x.forwardRef(oc(function(e,t){let n=dc(xc,e.__scopeDialog),r=x.useRef(!1),i=x.useRef(!1);return(0,S.jsx)(Tc,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),t.defaultPrevented||(r.current||n.triggerRef.current?.focus(),t.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||(r.current=!0,t.detail.originalEvent.type===`pointerdown`&&(i.current=!0));let a=t.target;n.triggerRef.current?.contains(a)&&t.preventDefault(),t.detail.originalEvent.type===`focusin`&&i.current&&t.preventDefault()}})},`DialogContentNonModal`)),Tc=x.forwardRef(oc(function(e,t){let{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,...o}=e,s=dc(xc,n);return Ro(),(0,S.jsx)(S.Fragment,{children:(0,S.jsx)(yo,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:(0,S.jsx)(K,{role:`dialog`,id:s.contentId,"aria-describedby":s.descriptionPresent?s.descriptionId:void 0,"aria-labelledby":s.titlePresent?s.titleId:void 0,"data-state":Mc(s.open),...o,ref:t,deferPointerDownOutside:!0,onDismiss:()=>s.onOpenChange(!1)})})})},`DialogContentImpl`)),Ec=`DialogTitle`,Dc=x.forwardRef(oc(function(e,t){let{__scopeDialog:n,...r}=e,i=dc(Ec,n),{setTitleCount:a}=i;return ya(()=>(a(e=>e+1),()=>a(e=>e-1)),[a]),(0,S.jsx)(Ki.h2,{id:i.titleId,...r,ref:t})},`DialogTitle`)),Oc=`DialogDescription`,kc=x.forwardRef(oc(function(e,t){let{__scopeDialog:n,...r}=e,i=dc(Oc,n),{setDescriptionCount:a}=i;return ya(()=>(a(e=>e+1),()=>a(e=>e-1)),[a]),(0,S.jsx)(Ki.p,{id:i.descriptionId,...r,ref:t})},`DialogDescription`)),Ac=`DialogClose`,jc=x.forwardRef(oc(function(e,t){let{__scopeDialog:n,...r}=e,i=dc(Ac,n);return(0,S.jsx)(Ki.button,{type:`button`,...r,ref:t,onClick:G(e.onClick,()=>i.onOpenChange(!1))})},`DialogClose`));function Mc(e){return e?`open`:`closed`}oc(Mc,`getState`);var Nc=Object.defineProperty,Pc=(e,t)=>Nc(e,`name`,{value:t,configurable:!0});function Fc(e){let[t,n]=x.useState(void 0);return ya(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});let t=new ResizeObserver(t=>{if(!Array.isArray(t)||!t.length)return;let r=t[0],i,a;if(`borderBoxSize`in r){let e=r.borderBoxSize,t=Array.isArray(e)?e[0]:e;i=t.inlineSize,a=t.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return t.observe(e,{box:`border-box`}),()=>t.unobserve(e)}n(void 0)},[e]),t}Pc(Fc,`useSize`);var Ic=[`top`,`right`,`bottom`,`left`],Lc=Math.min,Rc=Math.max,zc=Math.round,Bc=Math.floor,Vc=e=>({x:e,y:e}),Hc={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function Uc(e,t,n){return Rc(e,Lc(t,n))}function Wc(e,t){return typeof e==`function`?e(t):e}function Gc(e){return e.split(`-`)[0]}function Kc(e){return e.split(`-`)[1]}function qc(e){return e===`x`?`y`:`x`}function Jc(e){return e===`y`?`height`:`width`}function Yc(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function Xc(e){return qc(Yc(e))}function Zc(e,t,n){n===void 0&&(n=!1);let r=Kc(e),i=Xc(e),a=Jc(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=ol(o)),[o,ol(o)]}function Qc(e){let t=ol(e);return[$c(e),t,$c(t)]}function $c(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var el=[`left`,`right`],tl=[`right`,`left`],nl=[`top`,`bottom`],rl=[`bottom`,`top`];function il(e,t,n){switch(e){case`top`:case`bottom`:return n?t?tl:el:t?el:tl;case`left`:case`right`:return t?nl:rl;default:return[]}}function al(e,t,n,r){let i=Kc(e),a=il(Gc(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map($c)))),a}function ol(e){let t=Gc(e);return Hc[t]+e.slice(t.length)}function sl(e){return{top:e.top??0,right:e.right??0,bottom:e.bottom??0,left:e.left??0}}function cl(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:sl(e)}function ll(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function ul(e,t,n){let{reference:r,floating:i}=e,a=Yc(t),o=Xc(t),s=Jc(o),c=Gc(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}let m=Kc(t);return m&&(p[o]+=f*(m===`end`?1:-1)*(n&&l?-1:1)),p}async function dl(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=Wc(t,e),p=cl(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=ll(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=ll(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}var fl=50,pl=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:dl},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=ul(l,r,c),f=r,p=0,m={};for(let n=0;n({name:`arrow`,options:e,async fn(t){let{x:n,y:r,placement:i,rects:a,platform:o,elements:s,middlewareData:c}=t,{element:l,padding:u=0}=Wc(e,t)||{};if(l==null)return{};let d=cl(u),f={x:n,y:r},p=Xc(i),m=Jc(p),h=await o.getDimensions(l),g=p===`y`,_=g?`top`:`left`,v=g?`bottom`:`right`,y=g?`clientHeight`:`clientWidth`,b=a.reference[m]+a.reference[p]-f[p]-a.floating[m],x=f[p]-a.reference[p],S=await(o.getOffsetParent==null?void 0:o.getOffsetParent(l)),C=S?S[y]:0;(!C||!await(o.isElement==null?void 0:o.isElement(S)))&&(C=s.floating[y]||a.floating[m]);let w=b/2-x/2,T=C/2-h[m]/2-1,E=Lc(d[_],T),D=Lc(d[v],T),O=C-h[m]-D,ee=C/2-h[m]/2+w,k=Uc(E,ee,O),A=!c.arrow&&Kc(i)!=null&&ee!==k&&a.reference[m]/2-(eee<=0)){let e=(i.flip?.index||0)+1,t=S[e];if(t&&(u!==`alignment`||_===Yc(t)||T.every(e=>Yc(e.placement)!==_||e.overflows[0]>0)))return{data:{index:e,overflows:T},reset:{placement:t}};let n=T.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=T.filter(e=>{if(x){let t=Yc(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o}if(r!==n)return{reset:{placement:n}}}return{}}}};function gl(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function _l(e){return Ic.some(t=>e[t]>=0)}var vl=function(e){return e===void 0&&(e={}),{name:`hide`,options:e,async fn(t){let{rects:n,platform:r}=t,{strategy:i=`referenceHidden`,...a}=Wc(e,t);switch(i){case`referenceHidden`:{let e=gl(await r.detectOverflow(t,{...a,elementContext:`reference`}),n.reference);return{data:{referenceHiddenOffsets:e,referenceHidden:_l(e)}}}case`escaped`:{let e=gl(await r.detectOverflow(t,{...a,altBoundary:!0}),n.floating);return{data:{escapedOffsets:e,escaped:_l(e)}}}default:return{}}}}},yl=new Set([`left`,`top`]);async function bl(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=Gc(n),s=Kc(n),c=Yc(n)===`y`,l=yl.has(o)?-1:1,u=a&&c?-1:1,d=Wc(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}var xl=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await bl(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},Sl=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i,platform:a}=t,{mainAxis:o=!0,crossAxis:s=!1,limiter:c={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...l}=Wc(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=Yc(i),p=qc(f),m=u[p],h=u[f],g=(e,t)=>Uc(t+d[e===`y`?`top`:`left`],t,t-d[e===`y`?`bottom`:`right`]);o&&(m=g(p,m)),s&&(h=g(f,h));let _=c.fn({...t,[p]:m,[f]:h});return{..._,data:{x:_.x-n,y:_.y-r,enabled:{[p]:o,[f]:s}}}}}},Cl=function(e){return e===void 0&&(e={}),{options:e,fn(t){let{x:n,y:r,placement:i,rects:a,middlewareData:o}=t,{offset:s=0,mainAxis:c=!0,crossAxis:l=!0}=Wc(e,t),u={x:n,y:r},d=Yc(i),f=qc(d),p=u[f],m=u[d],h=Wc(s,t),g=typeof h==`number`?{mainAxis:h,crossAxis:0}:{mainAxis:h.mainAxis??0,crossAxis:h.crossAxis??0};if(c){let e=f===`y`?`height`:`width`,t=a.reference[f]-a.floating[e]+g.mainAxis,n=a.reference[f]+a.reference[e]-g.mainAxis;pn&&(p=n)}if(l){let e=f===`y`?`width`:`height`,t=yl.has(Gc(i)),n=a.reference[d]-a.floating[e]+(t&&o.offset?.[d]||0)+(t?0:g.crossAxis),r=a.reference[d]+a.reference[e]+(t?0:o.offset?.[d]||0)-(t?g.crossAxis:0);mr&&(m=r)}return{[f]:p,[d]:m}}}},wl=function(e){return e===void 0&&(e={}),{name:`size`,options:e,async fn(t){let{placement:n,rects:r,platform:i,elements:a}=t,{apply:o=()=>{},...s}=Wc(e,t),c=await i.detectOverflow(t,s),l=Gc(n),u=Kc(n),d=Yc(n)===`y`,{width:f,height:p}=r.floating,m,h;l===`top`||l===`bottom`?(m=l,h=u===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?`start`:`end`)?`left`:`right`):(h=l,m=u===`end`?`top`:`bottom`);let g=p-c.top-c.bottom,_=f-c.left-c.right,v=Lc(p-c[m],g),y=Lc(f-c[h],_),b=t.middlewareData.shift,x=!b,S=v,C=y;b!=null&&b.enabled.x&&(C=_),b!=null&&b.enabled.y&&(S=g),x&&!u&&(d?C=f-2*Rc(c.left,c.right):S=p-2*Rc(c.top,c.bottom)),await o({...t,availableWidth:C,availableHeight:S});let w=await i.getDimensions(a.floating);return f!==w.width||p!==w.height?{reset:{rects:!0}}:{}}}};function Tl(){return typeof window<`u`}function El(e){return kl(e)?(e.nodeName||``).toLowerCase():`#document`}function Dl(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function Ol(e){return((kl(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function kl(e){return Tl()?e instanceof Node||e instanceof Dl(e).Node:!1}function Al(e){return Tl()?e instanceof Element||e instanceof Dl(e).Element:!1}function jl(e){return Tl()?e instanceof HTMLElement||e instanceof Dl(e).HTMLElement:!1}function Ml(e){return!Tl()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof Dl(e).ShadowRoot}function Nl(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=Bl(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function Pl(e){return/^(table|td|th)$/.test(El(e))}function Fl(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var Il=/transform|translate|scale|rotate|perspective|filter/,Ll=/paint|layout|strict|content/,q=e=>!!e&&e!==`none`,Rl;function J(e){let t=Al(e)?Bl(e):e;return q(t.transform)||q(t.translate)||q(t.scale)||q(t.rotate)||q(t.perspective)||!X()&&(q(t.backdropFilter)||q(t.filter))||Il.test(t.willChange||``)||Ll.test(t.contain||``)}function Y(e){let t=Hl(e);for(;jl(t)&&!zl(t);){if(J(t))return t;if(Fl(t))return null;t=Hl(t)}return null}function X(){return Rl??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),Rl}function zl(e){return/^(html|body|#document)$/.test(El(e))}function Bl(e){return Dl(e).getComputedStyle(e)}function Vl(e){return Al(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Hl(e){if(El(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||Ml(e)&&e.host||Ol(e);return Ml(t)?t.host:t}function Ul(e){let t=Hl(e);return zl(t)?(e.ownerDocument||e).body:jl(t)&&Nl(t)?t:Ul(t)}function Wl(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=Ul(e),i=r===e.ownerDocument?.body,a=Dl(r);if(i){let e=Gl(a);return t.concat(a,a.visualViewport||[],Nl(r)?r:[],e&&n?Wl(e):[])}return t.concat(r,Wl(r,[],n))}function Gl(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Kl(e){let t=Bl(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=jl(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=zc(n)!==a||zc(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function ql(e){return Al(e)?e:e.contextElement}function Jl(e){let t=ql(e);if(!jl(t))return Vc(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=Kl(t),o=(a?zc(n.width):n.width)/r,s=(a?zc(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}var Yl=Vc(0);function Xl(e){let t=Dl(e);return!X()||!t.visualViewport?Yl:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Zl(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===Dl(e)}function Ql(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=ql(e),o=Vc(1);t&&(r?Al(r)&&(o=Jl(r)):o=Jl(e));let s=Zl(a,n,r)?Xl(a):Vc(0),c=(i.left+s.x)/o.x,l=(i.top+s.y)/o.y,u=i.width/o.x,d=i.height/o.y;if(a&&r){let e=Dl(a),t=Al(r)?Dl(r):r,n=e,i=Gl(n);for(;i&&t!==n;){let e=Jl(i),t=i.getBoundingClientRect(),r=Bl(i),a=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,o=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;c*=e.x,l*=e.y,u*=e.x,d*=e.y,c+=a,l+=o,n=Dl(i),i=Gl(n)}}return ll({width:u,height:d,x:c,y:l})}function $l(e,t){let n=Vl(e).scrollLeft;return t?t.left+n:Ql(Ol(e)).left+n}function eu(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-$l(e,n),y:n.top+t.scrollTop}}function tu(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=Ol(r),s=t?Fl(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=Vc(1),u=Vc(0),d=jl(r);if((d||!a)&&((El(r)!==`body`||Nl(o))&&(c=Vl(r)),d)){let e=Ql(r);l=Jl(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?eu(o,c):Vc(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function nu(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function ru(e){let t=Vl(e),n=e.ownerDocument.body,r=Rc(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=Rc(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight),a=-t.scrollLeft+$l(e),o=-t.scrollTop;return Bl(n).direction===`rtl`&&(a+=Rc(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:o}}var iu=25;function au(e,t,n){n===void 0&&(n=`viewport`);let r=n===`layoutViewport`,i=Dl(e),a=Ol(e),o=i.visualViewport,s=a.clientWidth,c=a.clientHeight,l=0,u=0;if(o){let e=!X()||t===`fixed`;r?e||(l=-o.offsetLeft,u=-o.offsetTop):(s=o.width,c=o.height,e&&(l=o.offsetLeft,u=o.offsetTop))}if($l(a)<=0){let e=a.ownerDocument,t=e.body,n=getComputedStyle(t),r=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,i=Math.abs(a.clientWidth-t.clientWidth-r),o=getComputedStyle(a).scrollbarGutter===`stable both-edges`?i/2:i;o<=iu&&(s-=o)}return{width:s,height:c,x:l,y:u}}function ou(e,t){let n=Ql(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=Jl(e);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function su(e,t,n){let r;if(t===`viewport`||t===`layoutViewport`)r=au(e,n,t);else if(t===`document`)r=ru(Ol(e));else if(Al(t))r=ou(t,n);else{let n=Xl(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return ll(r)}function cu(e,t){let n=t.get(e);if(n)return n;let r=Wl(e,[],!1).filter(e=>Al(e)&&El(e)!==`body`),i=null,a=Bl(e).position===`fixed`,o=a?Hl(e):e;for(;Al(o)&&!zl(o);){let e=Bl(o),t=J(o),n=i?i.position:a?`fixed`:``;!t&&(n===`fixed`||n===`absolute`&&e.position===`static`)?r=r.filter(e=>e!==o):i=e,o=Hl(o)}return t.set(e,r),r}function lu(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?Fl(t)?[]:cu(t,this._c):[].concat(n),r],o=su(t,a[0],i),s=o.top,c=o.right,l=o.bottom,u=o.left;for(let e=1;e{s(!1,1e-7)},1e3)}y=!1}try{r=new IntersectionObserver(b,{...v,root:a.ownerDocument})}catch{r=new IntersectionObserver(b,v)}r.observe(e)}let c=Dl(e),l=()=>s(n);return c.addEventListener(`resize`,l),s(!0),()=>{c.removeEventListener(`resize`,l),o()}}function bu(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=ql(e),u=i||a?[...l?Wl(l):[],...t?Wl(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n),a&&e.addEventListener(`resize`,n)});let d=l&&s?yu(l,n,a):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&t&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),t&&p.observe(t));let m,h=c?Ql(e):null;c&&g();function g(){let t=Ql(e);h&&!vu(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}var xu=xl,Su=Sl,Cu=hl,wu=wl,Tu=vl,Eu=ml,Du=Cl,Ou=(e,t,n)=>{let r=new Map,i=n??{},a={..._u,...i.platform,_c:r};return pl(e,t,{...i,platform:a})},ku=typeof document<`u`?x.useLayoutEffect:function(){};function Au(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e==`function`&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e==`object`){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!Au(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){let n=i[r];if(!(n===`_owner`&&e.$$typeof)&&!Au(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function ju(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Mu(e,t){let n=ju(e);return Math.round(t*n)/n}function Nu(e){let t=x.useRef(e);return ku(()=>{t.current=e}),t}function Pu(e){e===void 0&&(e={});let{placement:t=`bottom`,strategy:n=`absolute`,middleware:r=[],platform:i,elements:{reference:a,floating:o}={},transform:s=!0,whileElementsMounted:c,open:l}=e,[u,d]=x.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[f,p]=x.useState(r);Au(f,r)||p(r);let[m,h]=x.useState(null),[g,_]=x.useState(null),v=x.useCallback(e=>{e!==C.current&&(C.current=e,h(e))},[]),y=x.useCallback(e=>{e!==w.current&&(w.current=e,_(e))},[]),b=a||m,S=o||g,C=x.useRef(null),w=x.useRef(null),T=x.useRef(u),E=c!=null,D=Nu(c),O=Nu(i),ee=Nu(l),k=x.useCallback(()=>{if(!C.current||!w.current)return;let e={placement:t,strategy:n,middleware:f};O.current&&(e.platform=O.current),Ou(C.current,w.current,e).then(e=>{let t={...e,isPositioned:ee.current!==!1};A.current&&!Au(T.current,t)&&(T.current=t,Ui.flushSync(()=>{d(t)}))})},[f,t,n,O,ee]);ku(()=>{l===!1&&T.current.isPositioned&&(T.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let A=x.useRef(!1);ku(()=>(A.current=!0,()=>{A.current=!1}),[]),ku(()=>{if(b&&(C.current=b),S&&(w.current=S),b&&S){if(D.current)return D.current(b,S,k);k()}},[b,S,k,D,E]);let j=x.useMemo(()=>({reference:C,floating:w,setReference:v,setFloating:y}),[v,y]),te=x.useMemo(()=>({reference:b,floating:S}),[b,S]),M=x.useMemo(()=>{let e={position:n,left:0,top:0};if(!te.floating)return e;let t=Mu(te.floating,u.x),r=Mu(te.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...ju(te.floating)>=1.5&&{willChange:`transform`}}:{position:n,left:t,top:r}},[n,s,te.floating,u.x,u.y]);return x.useMemo(()=>({...u,update:k,refs:j,elements:te,floatingStyles:M}),[u,k,j,te,M])}var Fu=e=>{function t(e){return{}.hasOwnProperty.call(e,`current`)}return{name:`arrow`,options:e,fn(n){let{element:r,padding:i}=typeof e==`function`?e(n):e;return r&&t(r)?r.current==null?{}:Eu({element:r.current,padding:i}).fn(n):r?Eu({element:r,padding:i}).fn(n):{}}}},Iu=(e,t)=>{let n=xu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Lu=(e,t)=>{let n=Su(e);return{name:n.name,fn:n.fn,options:[e,t]}},Ru=(e,t)=>({fn:Du(e).fn,options:[e,t]}),zu=(e,t)=>{let n=Cu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Bu=(e,t)=>{let n=wu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Vu=(e,t)=>{let n=Tu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Hu=(e,t)=>{let n=Fu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Uu=Object.defineProperty,Wu=(e,t)=>Uu(e,`name`,{value:t,configurable:!0}),Z=`Popper`,[Gu,Ku]=Zi(Z),[qu,Ju]=Gu(Z),Yu=Wu(e=>{let{__scopePopper:t,children:n}=e,[r,i]=x.useState(null),[a,o]=x.useState(void 0);return(0,S.jsx)(qu,{scope:t,anchor:r,onAnchorChange:i,placementState:a,setPlacementState:o,children:n})},`Popper`),Xu=`PopperAnchor`,Zu=x.forwardRef(Wu(function(e,t){let{__scopePopper:n,virtualRef:r,...i}=e,a=Ju(Xu,n),o=x.useRef(null),s=a.onAnchorChange,c=Oi(t,x.useCallback(e=>{o.current=e,e&&s(e)},[s])),l=x.useRef(null);x.useEffect(()=>{if(!r)return;let e=l.current;l.current=r.current,e!==l.current&&s(l.current)});let u=a.placementState&&id(a.placementState),d=u?.[0],f=u?.[1];return r?null:(0,S.jsx)(Ki.div,{"data-radix-popper-side":d,"data-radix-popper-align":f,...i,ref:c})},`PopperAnchor`)),Qu=`PopperContent`,[$u,ed]=Gu(Qu),td=x.forwardRef(Wu(function(e,t){let{__scopePopper:n,side:r=`bottom`,sideOffset:i=0,align:a=`center`,alignOffset:o=0,arrowPadding:s=0,avoidCollisions:c=!0,collisionBoundary:l=[],collisionPadding:u=0,sticky:d=`partial`,hideWhenDetached:f=!1,updatePositionStrategy:p=`optimized`,onPlaced:m,...h}=e,g=Ju(Qu,n),[_,v]=x.useState(null),y=Oi(t,v),[b,C]=x.useState(null),w=Fc(b),T=w?.width??0,E=w?.height??0,D=r+(a===`center`?``:`-`+a),O=typeof u==`number`?u:{top:0,right:0,bottom:0,left:0,...u},ee=Array.isArray(l)?l:[l],k=ee.length>0,A={padding:O,boundary:ee.filter(nd),altBoundary:k},{refs:j,floatingStyles:te,placement:M,isPositioned:ne,middlewareData:N}=Pu({strategy:`fixed`,placement:D,whileElementsMounted:Wu((...e)=>bu(...e,{animationFrame:p===`always`}),`whileElementsMounted`),elements:{reference:g.anchor},middleware:[Iu({mainAxis:i+E,alignmentAxis:o}),c&&Lu({mainAxis:!0,crossAxis:!1,limiter:d===`partial`?Ru():void 0,...A}),c&&zu({...A}),Bu({...A,apply:Wu(({elements:e,rects:t,availableWidth:n,availableHeight:r})=>{let{width:i,height:a}=t.reference,o=e.floating.style;o.setProperty(`--radix-popper-available-width`,`${n}px`),o.setProperty(`--radix-popper-available-height`,`${r}px`),o.setProperty(`--radix-popper-anchor-width`,`${i}px`),o.setProperty(`--radix-popper-anchor-height`,`${a}px`)},`apply`)}),b&&Hu({element:b,padding:s}),rd({arrowWidth:T,arrowHeight:E}),f&&Vu({strategy:`referenceHidden`,...A,boundary:k?A.boundary:void 0})]}),P=g.setPlacementState;ya(()=>(P(M),()=>{P(void 0)}),[M,P]);let[re,ie]=id(M),ae=$a(m);ya(()=>{ne&&ae?.()},[ne,ae]);let F=N.arrow?.x,I=N.arrow?.y,L=N.arrow?.centerOffset!==0,[oe,se]=x.useState();return ya(()=>{_&&se(window.getComputedStyle(_).zIndex)},[_]),(0,S.jsx)(`div`,{ref:j.setFloating,"data-radix-popper-content-wrapper":``,style:{...te,transform:ne?te.transform:`translate(0, -200%)`,minWidth:`max-content`,zIndex:oe,"--radix-popper-transform-origin":[N.transformOrigin?.x,N.transformOrigin?.y].join(` `),...N.hide?.referenceHidden&&{visibility:`hidden`,pointerEvents:`none`}},dir:e.dir,children:(0,S.jsx)($u,{scope:n,placedSide:re,placedAlign:ie,onArrowChange:C,arrowX:F,arrowY:I,shouldHideArrow:L,children:(0,S.jsx)(Ki.div,{"data-side":re,"data-align":ie,...h,ref:y,style:{...h.style,animation:ne?h.style?.animation:`none`}})})})},`PopperContent`));function nd(e){return e!==null}Wu(nd,`isNotNull`);var rd=Wu(e=>({name:`transformOrigin`,options:e,fn(t){let{placement:n,rects:r,middlewareData:i}=t,a=i.arrow?.centerOffset!==0,o=a?0:e.arrowWidth,s=a?0:e.arrowHeight,[c,l]=id(n),u={start:`0%`,center:`50%`,end:`100%`}[l],d=(i.arrow?.x??0)+o/2,f=(i.arrow?.y??0)+s/2,p=``,m=``;return c===`bottom`?(p=a?u:`${d}px`,m=`${-s}px`):c===`top`?(p=a?u:`${d}px`,m=`${r.floating.height+s}px`):c===`right`?(p=`${-s}px`,m=a?u:`${f}px`):c===`left`&&(p=`${r.floating.width+s}px`,m=a?u:`${f}px`),{data:{x:p,y:m}}}}),`transformOrigin`);function id(e){let[t,n=`center`]=e.split(`-`);return[t,n]}Wu(id,`getSideAndAlignFromPlacement`);var ad=Yu,od=Zu,sd=td,cd=Object.defineProperty,ld=(e,t)=>cd(e,`name`,{value:t,configurable:!0}),ud=!1;function dd(){let[e,t]=x.useState(ud);return x.useEffect(()=>{ud||(ud=!0,t(!0))},[]),e}ld(dd,`useIsHydrated`);var fd=x.useSyncExternalStore;function pd(){return()=>{}}ld(pd,`subscribe`);function md(){return fd(pd,()=>!0,()=>!1)}ld(md,`useIsHydratedModern`);var hd=typeof fd==`function`?md:dd,gd=Object.defineProperty,_d=(e,t)=>gd(e,`name`,{value:t,configurable:!0}),vd=`rovingFocusGroup.onEntryFocus`,yd={bubbles:!1,cancelable:!0},Q=`RovingFocusGroup`,[bd,xd,Sd]=ta(Q),[Cd,wd]=Zi(Q,[Sd]),[Td,Ed]=Cd(Q),Dd=x.forwardRef(_d(function(e,t){return(0,S.jsx)(bd.Provider,{scope:e.__scopeRovingFocusGroup,children:(0,S.jsx)(bd.Slot,{scope:e.__scopeRovingFocusGroup,children:(0,S.jsx)(Od,{...e,ref:t})})})},`RovingFocusGroup`)),Od=x.forwardRef(_d(function(e,t){let{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:a,currentTabStopId:o,defaultCurrentTabStopId:s,onCurrentTabStopIdChange:c,onEntryFocus:l,preventScrollOnEntryFocus:u=!1,...d}=e,f=x.useRef(null),p=Oi(t,f),m=Xa(a),[h,g]=Oa({prop:o,defaultProp:s??null,onChange:c,caller:Q}),[_,v]=x.useState(!1),y=$a(l),b=xd(n),C=x.useRef(!1),[w,T]=x.useState(0);return x.useEffect(()=>{let e=f.current;if(e)return e.addEventListener(vd,y),()=>e.removeEventListener(vd,y)},[y]),(0,S.jsx)(Td,{scope:n,orientation:r,dir:m,loop:i,currentTabStopId:h,onItemFocus:x.useCallback(e=>g(e),[g]),onItemShiftTab:x.useCallback(()=>v(!0),[]),onFocusableItemAdd:x.useCallback(()=>T(e=>e+1),[]),onFocusableItemRemove:x.useCallback(()=>T(e=>e-1),[]),children:(0,S.jsx)(Ki.div,{tabIndex:_||w===0?-1:0,"data-orientation":r,...d,ref:p,style:{outline:`none`,...e.style},onMouseDown:G(e.onMouseDown,()=>{C.current=!0}),onFocus:G(e.onFocus,e=>{let t=!C.current;if(e.target===e.currentTarget&&t&&!_){let t=new CustomEvent(vd,yd);if(e.currentTarget.dispatchEvent(t),!t.defaultPrevented){let e=b().filter(e=>e.focusable);Pd([e.find(e=>e.active),e.find(e=>e.id===h),...e].filter(Boolean).map(e=>e.ref.current),u)}}C.current=!1}),onBlur:G(e.onBlur,()=>v(!1))})})},`RovingFocusGroupImpl`)),kd=`RovingFocusGroupItem`,Ad=x.forwardRef(_d(function(e,t){let{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:a,children:o,...s}=e,c=Ka(),l=a||c,u=Ed(kd,n),d=u.currentTabStopId===l,f=xd(n),{onFocusableItemAdd:p,onFocusableItemRemove:m,currentTabStopId:h}=u,g=hd();return ya(()=>{if(g&&r)return p(),()=>m()},[g,r,p,m]),x.useEffect(()=>{if(!g&&r)return p(),()=>m()},[g,r,p,m]),(0,S.jsx)(bd.ItemSlot,{scope:n,id:l,focusable:r,active:i,children:(0,S.jsx)(Ki.span,{tabIndex:d?0:-1,"data-orientation":u.orientation,...s,ref:t,onMouseDown:G(e.onMouseDown,e=>{r?u.onItemFocus(l):e.preventDefault()}),onFocus:G(e.onFocus,()=>u.onItemFocus(l)),onKeyDown:G(e.onKeyDown,e=>{if(e.key===`Tab`&&e.shiftKey){u.onItemShiftTab();return}if(e.target!==e.currentTarget)return;let t=Nd(e,u.orientation,u.dir);if(t!==void 0){if(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)return;e.preventDefault();let n=f().filter(e=>e.focusable).map(e=>e.ref.current);if(t===`last`)n.reverse();else if(t===`prev`||t===`next`){t===`prev`&&n.reverse();let r=n.indexOf(e.currentTarget);n=u.loop?Fd(n,r+1):n.slice(r+1)}setTimeout(()=>Pd(n))}}),children:typeof o==`function`?o({isCurrentTabStop:d,hasTabStop:h!=null}):o})})},`RovingFocusGroupItem`)),jd={ArrowLeft:`prev`,ArrowUp:`prev`,ArrowRight:`next`,ArrowDown:`next`,PageUp:`first`,Home:`first`,PageDown:`last`,End:`last`};function Md(e,t){return t===`rtl`?e===`ArrowLeft`?`ArrowRight`:e===`ArrowRight`?`ArrowLeft`:e:e}_d(Md,`getDirectionAwareKey`);function Nd(e,t,n){let r=Md(e.key,n);if(!(t===`vertical`&&[`ArrowLeft`,`ArrowRight`].includes(r))&&!(t===`horizontal`&&[`ArrowUp`,`ArrowDown`].includes(r)))return jd[r]}_d(Nd,`getFocusIntent`);function Pd(e,t=!1){let n=document.activeElement;for(let r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}_d(Pd,`focusFirst`);function Fd(e,t){return e.map((n,r)=>e[(t+r)%e.length])}_d(Fd,`wrapArray`);var Id=Dd,Ld=Ad,Rd=Object.defineProperty,zd=(e,t)=>Rd(e,`name`,{value:t,configurable:!0}),Bd=[`Enter`,` `],Vd=[`ArrowDown`,`PageUp`,`Home`],Hd=[`ArrowUp`,`PageDown`,`End`],Ud=[...Vd,...Hd];[...Bd],[...Bd];var Wd=`Menu`,[Gd,Kd,qd]=ta(Wd),[Jd,Yd]=Zi(Wd,[qd,Ku,wd]),Xd=Ku(),Zd=wd(),[Qd,$d]=Jd(Wd),[ef,tf]=Jd(Wd),nf=zd(e=>{let{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:a,modal:o=!0}=e,s=Xd(t),[c,l]=x.useState(null),u=x.useRef(!1),d=$a(a),f=Xa(i);return x.useEffect(()=>{let e=zd(()=>{u.current=!0,document.addEventListener(`pointerdown`,t,{capture:!0,once:!0}),document.addEventListener(`pointermove`,t,{capture:!0,once:!0})},`handleKeyDown`),t=zd(()=>u.current=!1,`handlePointer`);return document.addEventListener(`keydown`,e,{capture:!0}),()=>{document.removeEventListener(`keydown`,e,{capture:!0}),document.removeEventListener(`pointerdown`,t,{capture:!0}),document.removeEventListener(`pointermove`,t,{capture:!0})}},[]),x.useEffect(()=>{if(!n)return;let e=zd(()=>d(!1),`handleBlur`);return window.addEventListener(`blur`,e),()=>window.removeEventListener(`blur`,e)},[n,d]),(0,S.jsx)(ad,{...s,children:(0,S.jsx)(Qd,{scope:t,open:n,onOpenChange:d,content:c,onContentChange:l,children:(0,S.jsx)(ef,{scope:t,onClose:x.useCallback(()=>d(!1),[d]),isUsingKeyboardRef:u,dir:f,modal:o,children:r})})})},`Menu`),rf=x.forwardRef(zd(function(e,t){let{__scopeMenu:n,...r}=e,i=Xd(n);return(0,S.jsx)(od,{...i,...r,ref:t})},`MenuAnchor`)),af=`MenuPortal`,[of,sf]=Jd(af,{forceMount:void 0}),cf=zd(e=>{let{__scopeMenu:t,forceMount:n,children:r,container:i}=e,a=$d(af,t);return(0,S.jsx)(of,{scope:t,forceMount:n,children:(0,S.jsx)(Ia,{present:n||a.open,children:(0,S.jsx)(Mo,{asChild:!0,container:i,children:r})})})},`MenuPortal`),lf=`MenuContent`,[uf,df]=Jd(lf),ff=x.forwardRef(zd(function(e,t){let n=sf(lf,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,a=$d(lf,e.__scopeMenu),o=tf(lf,e.__scopeMenu);return(0,S.jsx)(Gd.Provider,{scope:e.__scopeMenu,children:(0,S.jsx)(Ia,{present:r||a.open,children:(0,S.jsx)(Gd.Slot,{scope:e.__scopeMenu,children:o.modal?(0,S.jsx)(pf,{...i,ref:t}):(0,S.jsx)(mf,{...i,ref:t})})})})},`MenuContent`)),pf=x.forwardRef(zd(function(e,t){let n=$d(lf,e.__scopeMenu),r=x.useRef(null),i=Oi(t,r);return x.useEffect(()=>{let e=r.current;if(e)return ic(e)},[]),(0,S.jsx)(gf,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:G(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})},`MenuRootContentModal`)),mf=x.forwardRef(zd(function(e,t){let n=$d(lf,e.__scopeMenu);return(0,S.jsx)(gf,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})},`MenuRootContentNonModal`)),hf=W(`MenuContent.ScrollLock`),gf=x.forwardRef(zd(function(e,t){let{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:o,disableOutsidePointerEvents:s,onEntryFocus:c,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,onDismiss:p,disableOutsideScroll:m,...h}=e,g=$d(lf,n),_=tf(lf,n),v=Xd(n),y=Zd(n),b=Kd(n),[C,w]=x.useState(null),T=x.useRef(null),E=Oi(t,T,g.onContentChange),D=x.useRef(0),O=x.useRef(``),ee=x.useRef(0),k=x.useRef(null),A=x.useRef(`right`),j=x.useRef(0),te=m?Ys:x.Fragment,M=m?{as:hf,allowPinchZoom:!0}:void 0,ne=zd(e=>{let t=O.current+e,n=b().filter(e=>!e.disabled),r=document.activeElement,i=n.find(e=>e.ref.current===r)?.textValue,a=Nf(n.map(e=>e.textValue),t,i),o=n.find(e=>e.textValue===a)?.ref.current;zd((function e(t){O.current=t,window.clearTimeout(D.current),t!==``&&(D.current=window.setTimeout(()=>e(``),1e3))}),`updateSearch`)(t),o&&setTimeout(()=>o.focus())},`handleTypeaheadSearch`);x.useEffect(()=>()=>window.clearTimeout(D.current),[]),Ro();let N=x.useCallback(e=>A.current===k.current?.side&&Ff(e,k.current?.area),[]);return(0,S.jsx)(uf,{scope:n,searchRef:O,onItemEnter:x.useCallback(e=>{N(e)&&e.preventDefault()},[N]),onItemLeave:x.useCallback(e=>{N(e)||(T.current?.focus(),w(null))},[N]),onTriggerLeave:x.useCallback(e=>{N(e)&&e.preventDefault()},[N]),pointerGraceTimerRef:ee,onPointerGraceIntentChange:x.useCallback(e=>{k.current=e},[]),children:(0,S.jsx)(te,{...M,children:(0,S.jsx)(yo,{asChild:!0,trapped:i,onMountAutoFocus:G(a,e=>{e.preventDefault(),T.current?.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:(0,S.jsx)(K,{asChild:!0,disableOutsidePointerEvents:s,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,onDismiss:p,children:(0,S.jsx)(Id,{asChild:!0,...y,dir:_.dir,orientation:`vertical`,loop:r,currentTabStopId:C,onCurrentTabStopIdChange:w,onEntryFocus:G(c,e=>{_.isUsingKeyboardRef.current||e.preventDefault()}),preventScrollOnEntryFocus:!0,children:(0,S.jsx)(sd,{role:`menu`,"aria-orientation":`vertical`,"data-state":Of(g.open),"data-radix-menu-content":``,dir:_.dir,...v,...h,ref:E,style:{outline:`none`,...h.style},onKeyDown:G(h.onKeyDown,e=>{let t=e.target.closest(`[data-radix-menu-content]`)===e.currentTarget,n=e.ctrlKey||e.altKey||e.metaKey,r=e.key.length===1;t&&(e.key===`Tab`&&e.preventDefault(),!n&&r&&ne(e.key));let i=T.current;if(e.target!==i||!Ud.includes(e.key))return;e.preventDefault();let a=b().filter(e=>!e.disabled).map(e=>e.ref.current);Hd.includes(e.key)&&a.reverse(),jf(a)}),onBlur:G(e.onBlur,e=>{e.currentTarget.contains(e.target)||(window.clearTimeout(D.current),O.current=``)}),onPointerMove:G(e.onPointerMove,If(e=>{let t=e.target,n=j.current!==e.clientX;if(e.currentTarget.contains(t)&&n){let t=e.clientX>j.current?`right`:`left`;A.current=t,j.current=e.clientX}}))})})})})})})},`MenuContentImpl`)),_f=x.forwardRef(zd(function(e,t){let{__scopeMenu:n,...r}=e;return(0,S.jsx)(Ki.div,{role:`group`,...r,ref:t})},`MenuGroup`)),vf=`MenuItem`,yf=`menu.itemSelect`,bf=x.forwardRef(zd(function(e,t){let{disabled:n=!1,onSelect:r,...i}=e,a=x.useRef(null),o=tf(vf,e.__scopeMenu),s=df(vf,e.__scopeMenu),c=Oi(t,a),l=x.useRef(!1),u=zd(()=>{let e=a.current;if(!n&&e){let t=new CustomEvent(yf,{bubbles:!0,cancelable:!0});e.addEventListener(yf,e=>r?.(e),{once:!0}),qi(e,t),t.defaultPrevented?l.current=!1:o.onClose()}},`handleSelect`);return(0,S.jsx)(xf,{...i,ref:c,disabled:n,onClick:G(e.onClick,u),onPointerDown:t=>{e.onPointerDown?.(t),l.current=!0},onPointerUp:G(e.onPointerUp,e=>{l.current||e.currentTarget?.click()}),onKeyDown:G(e.onKeyDown,e=>{n||e.target!==e.currentTarget||(s.searchRef.current===``||e.key!==` `)&&Bd.includes(e.key)&&(e.currentTarget.click(),e.preventDefault())})})},`MenuItem`)),xf=x.forwardRef(zd(function(e,t){let{__scopeMenu:n,disabled:r=!1,textValue:i,...a}=e,o=df(vf,n),s=Zd(n),c=x.useRef(null),l=Oi(t,c),[u,d]=x.useState(!1),[f,p]=x.useState(``);return x.useEffect(()=>{let e=c.current;e&&p((e.textContent??``).trim())},[a.children]),(0,S.jsx)(Gd.ItemSlot,{scope:n,disabled:r,textValue:i??f,children:(0,S.jsx)(Ld,{asChild:!0,...s,focusable:!r,children:(0,S.jsx)(Ki.div,{role:`menuitem`,"data-highlighted":u?``:void 0,"aria-disabled":r||void 0,"data-disabled":r?``:void 0,...a,ref:l,onPointerMove:G(e.onPointerMove,If(e=>{r?o.onItemLeave(e):(o.onItemEnter(e),e.defaultPrevented||e.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:G(e.onPointerLeave,If(e=>o.onItemLeave(e))),onFocus:G(e.onFocus,()=>d(!0)),onBlur:G(e.onBlur,()=>d(!1))})})})},`MenuItemImpl`)),[Sf,Cf]=Jd(`MenuRadioGroup`,{value:void 0,onValueChange:zd(()=>{},`onValueChange`)}),[wf,Tf]=Jd(`MenuItemIndicator`,{checked:!1}),[Ef,Df]=Jd(`MenuSub`);function Of(e){return e?`open`:`closed`}zd(Of,`getOpenState`);function kf(e){return e===`indeterminate`}zd(kf,`isIndeterminate`);function Af(e){return kf(e)?`indeterminate`:e?`checked`:`unchecked`}zd(Af,`getCheckedState`);function jf(e){let t=document.activeElement;for(let n of e)if(n===t||(n.focus(),document.activeElement!==t))return}zd(jf,`focusFirst`);function Mf(e,t){return e.map((n,r)=>e[(t+r)%e.length])}zd(Mf,`wrapArray`);function Nf(e,t,n){let r=t.length>1&&Array.from(t).every(e=>e===t[0])?t[0]:t,i=n?e.indexOf(n):-1,a=Mf(e,Math.max(i,0));r.length===1&&(a=a.filter(e=>e!==n));let o=a.find(e=>e.toLowerCase().startsWith(r.toLowerCase()));return o===n?void 0:o}zd(Nf,`getNextMatch`);function Pf(e,t){let{x:n,y:r}=e,i=!1;for(let e=0,a=t.length-1;er!=d>r&&n<(u-c)*(r-l)/(d-l)+c&&(i=!i)}return i}zd(Pf,`isPointInPolygon`);function Ff(e,t){return t?Pf({x:e.clientX,y:e.clientY},t):!1}zd(Ff,`isPointerInGraceArea`);function If(e){return t=>t.pointerType===`mouse`?e(t):void 0}zd(If,`whenMouse`);var Lf=nf,Rf=rf,zf=cf,Bf=ff,Vf=_f,Hf=bf,Uf=Object.defineProperty,Wf=(e,t)=>Uf(e,`name`,{value:t,configurable:!0}),Gf=`DropdownMenu`,[Kf,qf]=Zi(Gf,[Yd]),Jf=Yd(),[Yf,Xf]=Kf(Gf),Zf=Wf(e=>{let{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:a,onOpenChange:o,modal:s=!0}=e,c=Jf(t),l=x.useRef(null),[u,d]=Oa({prop:i,defaultProp:a??!1,onChange:o,caller:Gf});return(0,S.jsx)(Yf,{scope:t,triggerId:Ka(),triggerRef:l,contentId:Ka(),open:u,onOpenChange:d,onOpenToggle:x.useCallback(()=>d(e=>!e),[d]),modal:s,children:(0,S.jsx)(Lf,{...c,open:u,onOpenChange:d,dir:r,modal:s,children:n})})},`DropdownMenu`),Qf=`DropdownMenuTrigger`,$f=x.forwardRef(Wf(function(e,t){let{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,a=Xf(Qf,n),o=Jf(n),s=Oi(t,a.triggerRef);return(0,S.jsx)(Rf,{asChild:!0,...o,children:(0,S.jsx)(Ki.button,{type:`button`,id:a.triggerId,"aria-haspopup":`menu`,"aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":a.open?`open`:`closed`,"data-disabled":r?``:void 0,disabled:r,...i,ref:s,onPointerDown:G(e.onPointerDown,e=>{!r&&e.button===0&&e.ctrlKey===!1&&(a.onOpenToggle(),a.open||e.preventDefault())}),onKeyDown:G(e.onKeyDown,e=>{r||([`Enter`,` `].includes(e.key)&&a.onOpenToggle(),e.key===`ArrowDown`&&a.onOpenChange(!0),[`Enter`,` `,`ArrowDown`].includes(e.key)&&e.preventDefault())})})})},`DropdownMenuTrigger`)),ep=Wf(e=>{let{__scopeDropdownMenu:t,...n}=e,r=Jf(t);return(0,S.jsx)(zf,{...r,...n})},`DropdownMenuPortal`),tp=`DropdownMenuContent`,np=x.forwardRef(Wf(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=Xf(tp,n),a=Jf(n),o=x.useRef(!1);return(0,S.jsx)(Bf,{id:i.contentId,"aria-labelledby":i.triggerId,...a,...r,ref:t,onCloseAutoFocus:G(e.onCloseAutoFocus,e=>{o.current||i.triggerRef.current?.focus(),o.current=!1,e.preventDefault()}),onInteractOutside:G(e.onInteractOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0,r=t.button===2||n;(!i.modal||r)&&(o.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-dropdown-menu-content-available-width":`var(--radix-popper-available-width)`,"--radix-dropdown-menu-content-available-height":`var(--radix-popper-available-height)`,"--radix-dropdown-menu-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-dropdown-menu-trigger-height":`var(--radix-popper-anchor-height)`}})},`DropdownMenuContent`)),rp=x.forwardRef(Wf(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=Jf(n);return(0,S.jsx)(Vf,{...i,...r,ref:t})},`DropdownMenuGroup`)),ip=x.forwardRef(Wf(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=Jf(n);return(0,S.jsx)(Hf,{...i,...r,ref:t})},`DropdownMenuItem`)),ap=Zf,op=$f,sp=ep,cp=np,lp=rp,up=ip,dp=Object.defineProperty,fp=x.forwardRef(((e,t)=>dp(e,`name`,{value:t,configurable:!0}))(function(e,t){return(0,S.jsx)(Ki.label,{...e,ref:t,onMouseDown:t=>{t.target.closest(`button, input, select, textarea`)||(e.onMouseDown?.(t),!t.defaultPrevented&&t.detail>1&&t.preventDefault())}})},`Label`)),pp=Object.defineProperty,mp=(e,t)=>pp(e,`name`,{value:t,configurable:!0}),hp=`Tabs`,[gp,_p]=Zi(hp,[wd]),vp=wd(),[yp,bp]=gp(hp),xp=x.forwardRef(mp(function(e,t){let{__scopeTabs:n,value:r,onValueChange:i,defaultValue:a,orientation:o=`horizontal`,dir:s,activationMode:c=`automatic`,...l}=e,u=Xa(s),[d,f]=Oa({prop:r,onChange:i,defaultProp:a??``,caller:hp});return(0,S.jsx)(yp,{scope:n,baseId:Ka(),value:d,onValueChange:f,orientation:o,dir:u,activationMode:c,children:(0,S.jsx)(Ki.div,{dir:u,"data-orientation":o,...l,ref:t})})},`Tabs`)),Sp=`TabsList`,Cp=x.forwardRef(mp(function(e,t){let{__scopeTabs:n,loop:r=!0,...i}=e,a=bp(Sp,n),o=vp(n);return(0,S.jsx)(Id,{asChild:!0,...o,orientation:a.orientation,dir:a.dir,loop:r,children:(0,S.jsx)(Ki.div,{role:`tablist`,"aria-orientation":a.orientation,...i,ref:t})})},`TabsList`)),wp=`TabsTrigger`,Tp=x.forwardRef(mp(function(e,t){let{__scopeTabs:n,value:r,disabled:i=!1,...a}=e,o=bp(wp,n),s=vp(n),c=Op(o.baseId,r),l=kp(o.baseId,r),u=r===o.value;return(0,S.jsx)(Ld,{asChild:!0,...s,focusable:!i,active:u,children:(0,S.jsx)(Ki.button,{type:`button`,role:`tab`,"aria-selected":u,"aria-controls":l,"data-state":u?`active`:`inactive`,"data-disabled":i?``:void 0,disabled:i,id:c,...a,ref:t,onMouseDown:G(e.onMouseDown,e=>{!i&&e.button===0&&e.ctrlKey===!1?o.onValueChange(r):e.preventDefault()}),onKeyDown:G(e.onKeyDown,e=>{i||e.target!==e.currentTarget||[` `,`Enter`].includes(e.key)&&o.onValueChange(r)}),onFocus:G(e.onFocus,()=>{let e=o.activationMode!==`manual`;!u&&!i&&e&&o.onValueChange(r)})})})},`TabsTrigger`)),Ep=`TabsContent`,Dp=x.forwardRef(mp(function(e,t){let{__scopeTabs:n,value:r,forceMount:i,children:a,...o}=e,s=bp(Ep,n),c=Op(s.baseId,r),l=kp(s.baseId,r),u=r===s.value,d=x.useRef(u);return x.useEffect(()=>{let e=requestAnimationFrame(()=>d.current=!1);return()=>cancelAnimationFrame(e)},[]),(0,S.jsx)(Ia,{present:i||u,children:({present:n})=>(0,S.jsx)(Ki.div,{"data-state":u?`active`:`inactive`,"data-orientation":s.orientation,role:`tabpanel`,"aria-labelledby":c,hidden:!n,id:l,tabIndex:0,...o,ref:t,style:{...e.style,animationDuration:d.current?`0s`:void 0},children:n&&a})})},`TabsContent`));function Op(e,t){return`${e}-trigger-${t}`}mp(Op,`makeTriggerId`);function kp(e,t){return`${e}-content-${t}`}mp(kp,`makeContentId`);var Ap=xp,jp=Cp,Mp=Tp,Np=Dp,Pp=Qn(`inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary/90`,destructive:`bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40`,outline:`border bg-background hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50`,secondary:`bg-secondary text-secondary-foreground hover:bg-secondary/80`,ghost:`hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-9 px-4 py-2 has-[>svg]:px-3`,xs:`h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3`,sm:`h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5`,lg:`h-10 rounded-md px-6 has-[>svg]:px-4`,icon:`size-9`,"icon-xs":`size-6 rounded-md [&_svg:not([class*='size-'])]:size-3`,"icon-sm":`size-8`,"icon-lg":`size-10`}},defaultVariants:{variant:`default`,size:`default`}});function $({className:e,variant:t=`default`,size:n=`default`,asChild:r=!1,...i}){let a=r?Ai:`button`;return(0,S.jsx)(a,{"data-slot":`button`,"data-variant":t,"data-size":n,className:H(Pp({variant:t,size:n,className:e})),...i})}function Fp({className:e,orientation:t=`horizontal`,...n}){return(0,S.jsx)(Ap,{"data-slot":`tabs`,"data-orientation":t,orientation:t,className:H(`group/tabs flex gap-2 data-[orientation=horizontal]:flex-col`,e),...n})}var Ip=Qn(`group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-[orientation=horizontal]/tabs:h-9 group-data-[orientation=vertical]/tabs:h-fit group-data-[orientation=vertical]/tabs:flex-col data-[variant=line]:rounded-none`,{variants:{variant:{default:`bg-muted`,line:`gap-1 bg-transparent`}},defaultVariants:{variant:`default`}});function Lp({className:e,variant:t=`default`,...n}){return(0,S.jsx)(jp,{"data-slot":`tabs-list`,"data-variant":t,className:H(Ip({variant:t}),e),...n})}function Rp({className:e,...t}){return(0,S.jsx)(Mp,{"data-slot":`tabs-trigger`,className:H(`relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-[orientation=vertical]/tabs:w-full group-data-[orientation=vertical]/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 group-data-[variant=default]/tabs-list:data-[state=active]:shadow-sm group-data-[variant=line]/tabs-list:data-[state=active]:shadow-none dark:text-muted-foreground dark:hover:text-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,`group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:border-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent`,`data-[state=active]:bg-background data-[state=active]:text-foreground dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 dark:data-[state=active]:text-foreground`,`after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-[orientation=horizontal]/tabs:after:inset-x-0 group-data-[orientation=horizontal]/tabs:after:bottom-[-5px] group-data-[orientation=horizontal]/tabs:after:h-0.5 group-data-[orientation=vertical]/tabs:after:inset-y-0 group-data-[orientation=vertical]/tabs:after:-right-1 group-data-[orientation=vertical]/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-[state=active]:after:opacity-100`,e),...t})}function zp({className:e,...t}){return(0,S.jsx)(Np,{"data-slot":`tabs-content`,className:H(`flex-1 outline-none`,e),...t})}function Bp(e){if(e.apiVersion!==1||!/^[a-z][a-z0-9-]*$/.test(e.id))throw Error(`Invalid theme pack: ${e.id}`);return e}var Vp=Bp({apiVersion:1,id:`precision`,name:`Precision`,description:`Clear typography, quiet surfaces, and a cobalt accent.`}),Hp=Object.assign({"./packs/precision/index.ts":Vp}),Up=`precision`,Wp=Object.values(Hp).sort((e,t)=>e.id===`precision`?-1:t.id===`precision`?1:e.name.localeCompare(t.name)),Gp=new Map;for(let e of Wp){if(Gp.has(e.id))throw Error(`Duplicate theme pack: ${e.id}`);Gp.set(e.id,e)}if(!Gp.has(`precision`))throw Error(`The default theme is required`);function Kp(e){return Gp.get(e)||Gp.get(`precision`)}var qp={themeId:Up,appearance:`light`},Jp=e=>e===`light`||e===`dark`||e===`system`,Yp=e=>`dispatch:theme:v1:${e}`;function Xp(e){try{let t=e?localStorage.getItem(Yp(e)):null;if(!t)return qp;let n=JSON.parse(t);return!n||typeof n!=`object`?qp:{themeId:Kp(n.themeId).id,appearance:Jp(n.appearance)?n.appearance:`light`}}catch{return qp}}var Zp=(0,x.createContext)(null);function Qp({userId:e,children:t}){let[n,r]=(0,x.useState)(()=>({userId:e,preference:Xp(e),storageUnavailable:!1}));n.userId!==e&&r({userId:e,preference:Xp(e),storageUnavailable:!1});let{preference:i,storageUnavailable:a}=n,{appearance:o,themeId:s}=i,c=Kp(s),[l,u]=(0,x.useState)(()=>matchMedia(`(prefers-color-scheme: dark)`).matches),d=o===`system`?l?`dark`:`light`:o;(0,x.useLayoutEffect)(()=>{document.documentElement.dataset.theme=d,document.documentElement.dataset.themePack=c.id,document.querySelector(`meta[name="theme-color"]`)?.setAttribute(`content`,getComputedStyle(document.documentElement).getPropertyValue(`--background`).trim())},[d,c.id]),(0,x.useEffect)(()=>{let e=matchMedia(`(prefers-color-scheme: dark)`),t=()=>u(e.matches);return t(),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),(0,x.useEffect)(()=>{if(!e)return;let t=t=>{(t.key===null||t.key===Yp(e))&&r(t=>t.userId===e?{...t,preference:Xp(e)}:t)};return window.addEventListener(`storage`,t),()=>window.removeEventListener(`storage`,t)},[e]);function f(t){let n=!1;try{if(!e)return;localStorage.setItem(Yp(e),JSON.stringify(t))}catch{n=!0}r({userId:e,preference:t,storageUnavailable:n})}return(0,S.jsx)(Zp.Provider,{value:{appearance:o,themePack:c,storageUnavailable:a,setAppearance:e=>f({...i,appearance:e}),setThemePack:e=>f({...i,themeId:Kp(e).id})},children:t})}function $p(){let e=(0,x.useContext)(Zp);if(!e)throw Error(`ThemeProvider is required`);return e}function em({className:e,...t}){return(0,S.jsx)(fp,{"data-slot":`label`,className:H(`flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50`,e),...t})}function tm({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`field-group`,className:H(`group/field-group @container/field-group flex w-full flex-col gap-7 data-[slot=checkbox-group]:gap-3 [&>[data-slot=field-group]]:gap-4`,e),...t})}var nm=Qn(`group/field flex w-full gap-3 data-[invalid=true]:text-destructive`,{variants:{orientation:{vertical:[`flex-col [&>*]:w-full [&>.sr-only]:w-auto`],horizontal:[`flex-row items-center`,`[&>[data-slot=field-label]]:flex-auto`,`has-[>[data-slot=field-content]]:items-start has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px`],responsive:[`flex-col @md/field-group:flex-row @md/field-group:items-center [&>*]:w-full @md/field-group:[&>*]:w-auto [&>.sr-only]:w-auto`,`@md/field-group:[&>[data-slot=field-label]]:flex-auto`,`@md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px`]}},defaultVariants:{orientation:`vertical`}});function rm({className:e,orientation:t=`vertical`,...n}){return(0,S.jsx)(`div`,{role:`group`,"data-slot":`field`,"data-orientation":t,className:H(nm({orientation:t}),e),...n})}function im({className:e,...t}){return(0,S.jsx)(em,{"data-slot":`field-label`,className:H(`group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50`,`has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border [&>*]:data-[slot=field]:p-4`,`has-data-[state=checked]:border-primary has-data-[state=checked]:bg-primary/5 dark:has-data-[state=checked]:bg-primary/10`,e),...t})}function am({className:e,...t}){return(0,S.jsx)(`p`,{"data-slot":`field-description`,className:H(`text-sm leading-normal font-normal text-muted-foreground group-has-[[data-orientation=horizontal]]/field:text-balance`,`last:mt-0 nth-last-2:-mt-1 [[data-variant=legend]+&]:-mt-1.5`,`[&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary`,e),...t})}function om({className:e,type:t,...n}){return(0,S.jsx)(`input`,{type:t,"data-slot":`input`,className:H(`h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none selection:bg-primary selection:text-primary-foreground file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:bg-input/30`,`focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50`,`aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40`,e),...n})}function sm({...e}){return(0,S.jsx)(fc,{"data-slot":`sheet`,...e})}function cm({...e}){return(0,S.jsx)(gc,{"data-slot":`sheet-portal`,...e})}function lm({className:e,...t}){return(0,S.jsx)(vc,{"data-slot":`sheet-overlay`,className:H(`fixed inset-0 z-50 bg-black/15 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0`,e),...t})}function um({className:e,children:t,side:n=`right`,showCloseButton:r=!0,...i}){return(0,S.jsxs)(cm,{children:[(0,S.jsx)(lm,{}),(0,S.jsxs)(Sc,{"data-slot":`sheet-content`,className:H(`fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:animate-in data-[state=open]:duration-200`,n===`right`&&`inset-y-0 right-0 h-full w-full border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-[440px]`,n===`left`&&`inset-y-0 left-0 h-full w-full border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-[440px]`,n===`top`&&`inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top`,n===`bottom`&&`inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom`,e),...i,children:[t,r&&(0,S.jsxs)(jc,{className:`absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-secondary`,children:[(0,S.jsx)(qn,{className:`size-4`}),(0,S.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function dm({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`sheet-header`,className:H(`flex flex-col gap-1.5 p-4`,e),...t})}function fm({className:e,...t}){return(0,S.jsx)(Dc,{"data-slot":`sheet-title`,className:H(`font-semibold text-foreground`,e),...t})}function pm({className:e,...t}){return(0,S.jsx)(kc,{"data-slot":`sheet-description`,className:H(`text-sm text-muted-foreground`,e),...t})}function mm({...e}){return(0,S.jsx)(fc,{"data-slot":`dialog`,...e})}function hm({...e}){return(0,S.jsx)(gc,{"data-slot":`dialog-portal`,...e})}function gm({className:e,...t}){return(0,S.jsx)(vc,{"data-slot":`dialog-overlay`,className:H(`fixed inset-0 z-50 bg-black/15 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0`,e),...t})}function _m({className:e,children:t,showCloseButton:n=!0,...r}){return(0,S.jsxs)(hm,{"data-slot":`dialog-portal`,children:[(0,S.jsx)(gm,{}),(0,S.jsxs)(Sc,{"data-slot":`dialog-content`,className:H(`fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg`,e),...r,children:[t,n&&(0,S.jsxs)(jc,{"data-slot":`dialog-close`,className:`absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,children:[(0,S.jsx)(qn,{}),(0,S.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function vm({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`dialog-header`,className:H(`flex flex-col gap-2 text-center sm:text-left`,e),...t})}function ym({className:e,showCloseButton:t=!1,children:n,...r}){return(0,S.jsxs)(`div`,{"data-slot":`dialog-footer`,className:H(`flex flex-col-reverse gap-2 sm:flex-row sm:justify-end`,e),...r,children:[n,t&&(0,S.jsx)(jc,{asChild:!0,children:(0,S.jsx)($,{variant:`outline`,children:`Close`})})]})}function bm({className:e,...t}){return(0,S.jsx)(Dc,{"data-slot":`dialog-title`,className:H(`text-lg leading-none font-semibold`,e),...t})}function xm({className:e,...t}){return(0,S.jsx)(kc,{"data-slot":`dialog-description`,className:H(`text-sm text-muted-foreground`,e),...t})}var Sm=Qn(`relative grid w-full grid-cols-[0_1fr] items-start gap-y-0.5 rounded-lg border px-4 py-3 text-sm has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] has-[>svg]:gap-x-3 [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current`,{variants:{variant:{default:`bg-card text-card-foreground`,destructive:`bg-card text-destructive *:data-[slot=alert-description]:text-destructive/90 [&>svg]:text-current`}},defaultVariants:{variant:`default`}});function Cm({className:e,variant:t,...n}){return(0,S.jsx)(`div`,{"data-slot":`alert`,role:`alert`,className:H(Sm({variant:t}),e),...n})}function wm({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`alert-description`,className:H(`col-start-2 grid justify-items-start gap-1 text-sm text-muted-foreground [&_p]:leading-relaxed`,e),...t})}function Tm({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`skeleton`,className:H(`animate-pulse rounded-md bg-accent`,e),...t})}function Em({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`empty`,className:H(`flex min-w-0 flex-1 flex-col items-center justify-center gap-6 rounded-lg border-dashed p-6 text-center text-balance md:p-12`,e),...t})}function Dm({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`empty-header`,className:H(`flex max-w-sm flex-col items-center gap-2 text-center`,e),...t})}function Om({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`empty-title`,className:H(`text-lg font-medium tracking-tight`,e),...t})}function km({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`empty-description`,className:H(`text-sm/relaxed text-muted-foreground [&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary`,e),...t})}function Am(e){return{dsp_view_scope:`Exit this DSP to use platform controls or switch accounts.`,dsp_view_unavailable:`This DSP view expired or is no longer available. Open it again from DSPs.`,dsp_view_changed:`The DSP view changed. Refresh to load the current workspace.`,invalid_input:`Check the fields and use a valid station code and business timezone.`,container_provisioning_required:`DSP provisioning is not configured on this server. Contact the platform operator.`,native_migration_required:`Finish migrating or removing existing legacy DSPs before starting this update.`,organization_details_required:`Finish your DSP details before continuing setup.`,organization_details_complete:`Your DSP details have already been saved.`,update_unavailable:`This update is no longer available. Refresh and try again.`,rollout_in_progress:`A rollout is already in progress.`,rollout_empty:`Create a DSP before starting a rollout.`,rollout_not_active:`There is no active rollout to change.`,invalid_credentials:`The email address or password was not accepted.`,password_reset_invalid:`This reset link is invalid or has expired. Request a new link to continue.`,password_recovery_rate_limited:`Too many recovery attempts. Please try again in 15 minutes.`,password_recovery_busy:`Password recovery is busy. Please try again shortly.`,password_recovery_unavailable:`Password recovery is temporarily unavailable. Please contact your Dispatch administrator.`,turnstile_required:`Complete the security check before continuing.`,turnstile_invalid:`The security check was not accepted. Please verify again and retry.`,turnstile_unavailable:`Security verification is temporarily unavailable. Please try again shortly.`,login_rate_limited:`Too many sign-in attempts. Wait before trying again.`,invitation_invalid:`This invitation is invalid, expired, revoked, or already used.`,invitation_email_mismatch:`Sign in with the exact email address named by this invitation.`,password_policy_failed:`Use a password containing at least 12 characters.`,password_confirmation_mismatch:`The password confirmation does not match.`,user_already_belongs_to_dsp:`This user already belongs to another DSP.`,current_password_invalid:`The current password was not accepted.`,password_unchanged:`Choose a new password that differs from the current password.`,account_exists:`An account already exists for this invitation. Sign in instead.`,invitation_pending:`A pending invitation already exists for that email.`,membership_exists:`That user already belongs to this DSP.`,conflict:`That name or account is already in use.`,role_in_use:`Move all members off this role before deleting it.`,fixed_roles_only:`DSP roles are fixed to Owner, Manager, Dispatcher, and Driver.`,last_owner_protected:`Assign another Owner before changing or removing the last Owner.`,system_role_protected:`System roles are protected and cannot be changed.`,role_not_assignable:`Choose a standard role from this DSP.`,self_role_change_forbidden:`You cannot change your own role.`,organization_forbidden:`Your account does not have permission for that DSP.`,workforce_changed:`The employee list changed while loading. Please retry.`,workforce_unavailable:`Workforce data is temporarily unavailable. Please retry.`,not_initialized:`Paycom has not collected workforce data yet.`,employee_not_found:`This employee is no longer in the collected roster.`,paycom_credentials_invalid:`Complete all Paycom fields and enter five distinct security PINs in their original Paycom numbering.`,confirmation_mismatch:`Type the DSP name exactly as displayed to confirm.`,primary_credentials_rejected:`Paycom did not accept the client code, username or password.`,security_answers_rejected:`Paycom did not accept the security PINs.`,attempt_cooldown:`Paycom setup is waiting for the authentication cooldown. Retry after it clears.`,profile_locked:`This Paycom profile is locked. Review the failure before replacing its credentials.`,provider_setup_failed:`Paycom setup could not complete. Review your details and retry.`,profile_exists:`Paycom credentials are already saved. Select replacement only if you intend to change them.`,captcha_required:`Paycom needs verification. Contact the Platform Owner.`,manual_verification_required:`Paycom needs verification. Contact the Platform Owner.`,mfa_required:`Paycom requires additional verification. Resolve it with your authorized Paycom administrator before retrying.`,account_locked:`Paycom reports that the account is locked. Resolve the lock before retrying.`,setup_interrupted:`Setup was interrupted. Review your details and retry.`,platform_forbidden:`You do not have permission to manage DSP installations.`,platform_control_invalid:`This control expired or belongs to another session. Refresh and try again.`,installation_operator_disabled:`DSP provisioning is not enabled on this server. Server setup must be completed before creating DSPs or starting updates.`,invitation_email_unavailable:`Invitation email is not configured on this server. No invitation was sent. Contact the platform owner to finish email setup.`,dashboard_unavailable:`Dispatch is temporarily unavailable. Refresh to check whether your request completed before trying again.`,installation_revision_conflict:`The installation changed in another session. Refresh before trying again.`,installation_operation_in_progress:`An installation operation is already in progress. Its status will keep updating.`,installation_operation_not_allowed:`This installation cannot be changed from its current state.`,installation_operation_not_found:`That installation operation is no longer available. Refresh the status.`,idempotency_conflict:`This request was reused for different input. Refresh and try again.`,installation_not_ready:`This DSP runtime is not ready yet. Operational data will be available after setup completes.`,provider_auth_required:`Paycom access needs attention. Contact the platform owner for assistance.`,first_publication_failed:`Private runtime verification did not complete. Contact the platform operator.`,runtime_boundary_violation:`The private runtime could not be verified. Contact the platform operator.`}[typeof e==`string`?e:e instanceof Jt?e.code:``]||`The request could not be completed. Please try again.`}function jm(e){if(typeof e!=`string`||!e||e.length>64)return!1;try{return new Intl.DateTimeFormat(void 0,{timeZone:e}).format(0),!0}catch{return!1}}function Mm(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||`UTC`}catch{return`UTC`}}function Nm(e,t=Mm()){let n=e instanceof Date?e:new Date(e);return Number.isFinite(n.valueOf())?new Intl.DateTimeFormat(void 0,{year:`numeric`,month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`,timeZoneName:`short`,timeZone:t}).format(n):`—`}function Pm(e,t=new Date){let n=Object.fromEntries(new Intl.DateTimeFormat(`en-CA`,{timeZone:e,year:`numeric`,month:`2-digit`,day:`2-digit`}).formatToParts(t).map(e=>[e.type,e.value]));return`${n.year}-${n.month}-${n.day}`}function Fm(e){if(!/^\d{4}-\d{2}-\d{2}$/.test(e))throw Error(`invalid_calendar_date`);let t=new Date(`${e}T12:00:00Z`);if(!Number.isFinite(t.valueOf())||t.toISOString().slice(0,10)!==e)throw Error(`invalid_calendar_date`);return t}function Im(e,t){if(!Number.isInteger(t))throw Error(`invalid_calendar_date`);let n=Fm(e);return n.setUTCDate(n.getUTCDate()+t),n.toISOString().slice(0,10)}function Lm(e){return new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,year:`numeric`,timeZone:`UTC`}).format(Fm(e))}function Rm(e){let t=$p().themePack.components?.PageHeading||zm;return(0,S.jsx)(t,{...e})}function zm({title:e,description:t,children:n}){return(0,S.jsxs)(`div`,{className:`page-heading`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h1`,{tabIndex:-1,children:e}),t&&(0,S.jsx)(`p`,{children:t})]}),n&&(0,S.jsx)(`div`,{className:`page-actions`,children:n})]})}function Bm({label:e,description:t,...n}){let r=(0,x.useId)();return(0,S.jsxs)(rm,{"data-disabled":n.disabled,children:[(0,S.jsx)(im,{htmlFor:r,children:e}),(0,S.jsx)(om,{id:r,...n}),t&&(0,S.jsx)(am,{children:t})]})}function Vm({children:e,error:t=!1}){return(0,S.jsx)(Cm,{variant:t?`destructive`:`default`,role:t?`alert`:`status`,className:`my-4`,children:(0,S.jsx)(wm,{children:e})})}function Hm({error:e}){return e?(0,S.jsx)(Vm,{error:!0,children:Am(e)}):null}function Um(){return(0,S.jsxs)(`div`,{className:`flex flex-col gap-5 py-8`,role:`status`,"aria-label":`Loading`,children:[(0,S.jsx)(Tm,{className:`h-6 w-48`}),[0,1,2].map(e=>(0,S.jsx)(Tm,{className:`h-12 w-full`},e))]})}function Wm({title:e,description:t}){return(0,S.jsx)(Em,{children:(0,S.jsxs)(Dm,{children:[(0,S.jsx)(Om,{children:e}),t&&(0,S.jsx)(km,{children:t})]})})}function Gm({onClick:e,busy:t=!1}){return(0,S.jsx)($,{variant:`outline`,size:`icon`,"aria-label":`Refresh`,disabled:t,onClick:e,children:(0,S.jsx)(Vn,{"data-icon":`inline-start`,className:H(t&&`animate-spin`)})})}function Km({value:e,onChange:t,placeholder:n}){return(0,S.jsxs)(`label`,{className:`search-input`,children:[(0,S.jsx)(Hn,{"aria-hidden":`true`}),(0,S.jsx)(om,{type:`search`,"aria-label":n,placeholder:n,value:e,onChange:e=>t(e.target.value)})]})}function qm({busy:e,children:t,...n}){return(0,S.jsxs)($,{type:`submit`,disabled:e,...n,children:[e&&(0,S.jsx)(Nn,{"data-icon":`inline-start`,className:`animate-spin`}),t]})}function Jm({value:e,children:t}){return(0,S.jsxs)(`span`,{className:H(`status`,`status-${e.replaceAll(`_`,`-`)}`),children:[(0,S.jsx)(`span`,{"aria-hidden":`true`}),t||e.replaceAll(`_`,` `)]})}function Ym({open:e,onClose:t,title:n,description:r,children:i,busy:a=!1}){let o=(0,x.useRef)(null);return(0,S.jsx)(sm,{open:e,onOpenChange:e=>{!e&&!a&&t()},children:(0,S.jsxs)(um,{showCloseButton:!a,onOpenAutoFocus:()=>{o.current=document.activeElement},onCloseAutoFocus:e=>{e.preventDefault(),o.current?.isConnected?o.current.focus():document.querySelector(`.page-heading h1`)?.focus()},children:[(0,S.jsxs)(dm,{children:[(0,S.jsx)(fm,{children:n}),(0,S.jsx)(pm,{children:r||`Review details and manage access.`})]}),i]})})}function Xm({title:e,description:t,confirmation:n,passwordRequired:r=!1,onConfirm:i,onClose:a}){let[o,s]=(0,x.useState)(``),[c,l]=(0,x.useState)(!1),[u,d]=(0,x.useState)(null);return(0,S.jsx)(mm,{open:!0,onOpenChange:e=>{!e&&!c&&a()},children:(0,S.jsxs)(_m,{showCloseButton:!c,children:[(0,S.jsxs)(vm,{children:[(0,S.jsx)(bm,{children:e}),(0,S.jsx)(xm,{children:t})]}),(0,S.jsxs)(`form`,{onSubmit:async e=>{if(e.preventDefault(),!(n&&o!==n)){l(!0),d(null);try{await i(r?o:void 0),a()}catch(e){r&&s(``),d(e)}finally{l(!1)}}},className:`flex flex-col gap-5`,children:[r&&(0,S.jsx)(Bm,{label:`Your password`,type:`password`,autoComplete:`current-password`,value:o,onChange:e=>s(e.target.value),required:!0,disabled:c}),n&&(0,S.jsx)(Bm,{label:`Type ${n} to confirm`,value:o,onChange:e=>s(e.target.value),autoComplete:`off`,disabled:c,required:!0}),(0,S.jsx)(Hm,{error:u}),(0,S.jsxs)(ym,{children:[(0,S.jsx)($,{type:`button`,variant:`outline`,disabled:c,onClick:a,children:`Cancel`}),(0,S.jsx)(qm,{busy:c,variant:`destructive`,disabled:c||!!(n&&o!==n)||r&&!o,children:e})]})]})]})})}function Zm({result:e}){if(!e)return null;let t=e.ownerInvitation?.email||e.invitation?.email||`the recipient`;if(e.delivery?.status===`accepted`)return(0,S.jsxs)(Vm,{children:[`Invitation sent to `,t,`.`]});if(!e.invitationPath)return(0,S.jsx)(Vm,{children:`The invitation request was already processed. No new invitation was sent.`});let n=new URL(e.invitationPath,window.location.origin).href;return(0,S.jsx)(Vm,{children:(0,S.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,S.jsx)(`p`,{children:e.delivery?.status===`unknown`?`Email delivery could not be confirmed. Use this same link if a private handoff is needed.`:e.delivery?.status===`failed`?`The invitation email could not be sent. Share this one-time invitation through a private channel.`:`No email was sent because invitation email is not configured. Share this one-time invitation through a private channel.`}),(0,S.jsx)(om,{"aria-label":`Invitation link`,value:n,readOnly:!0,onFocus:e=>e.target.select()}),(0,S.jsx)($,{variant:`outline`,onClick:()=>navigator.clipboard.writeText(n).catch(()=>{}),children:`Copy link`})]})})}function Qm(e){let t=e.toLocaleUpperCase(`en-US`).match(/[\p{L}\p{N}]+/gu)||[];return{initials:t.length>1?`${[...t[0]][0]}${[...t[1]][0]}`:[...t[0]||`?`].slice(0,2).join(``),className:`dsp-avatar tone-${[...t.join(` `)].reduce((e,t)=>e*31+t.codePointAt(0)>>>0,0)%5}`}}var $m=e=>`dispatch:timezone:v1:${e}`;function eh(e){try{let t=e?JSON.parse(localStorage.getItem($m(e))||`null`):null;return jm(t?.timeZone)?t.timeZone:null}catch{return null}}var th=(0,x.createContext)(null);function nh({userId:e,children:t}){let[n,r]=(0,x.useState)(()=>({userId:e,preference:eh(e),storageUnavailable:!1}));n.userId!==e&&r({userId:e,preference:eh(e),storageUnavailable:!1});let[i,a]=(0,x.useState)(Mm);(0,x.useEffect)(()=>{let e=()=>a(Mm()),t=window.setInterval(e,6e4);return window.addEventListener(`focus`,e),document.addEventListener(`visibilitychange`,e),()=>{clearInterval(t),window.removeEventListener(`focus`,e),document.removeEventListener(`visibilitychange`,e)}},[]),(0,x.useEffect)(()=>{if(!e)return;let t=t=>{(t.key===null||t.key===$m(e))&&r(t=>t.userId===e?{...t,preference:eh(e)}:t)};return window.addEventListener(`storage`,t),()=>window.removeEventListener(`storage`,t)},[e]);function o(t){if(!e||t!==null&&!jm(t))return;let n=!1;try{localStorage.setItem($m(e),JSON.stringify({timeZone:t}))}catch{n=!0}r({userId:e,preference:t,storageUnavailable:n})}return(0,S.jsx)(th.Provider,{value:{timeZone:n.preference||i,deviceZone:i,preference:n.preference,setPreference:o,storageUnavailable:n.storageUnavailable},children:t})}function rh(){let e=(0,x.useContext)(th);if(!e)throw Error(`TimezoneProvider is required`);return e}function ih(e){let[t,n]=(0,x.useState)(Date.now);return(0,x.useEffect)(()=>{let e=()=>n(Date.now()),t=window.setInterval(e,3e4);return window.addEventListener(`focus`,e),document.addEventListener(`visibilitychange`,e),()=>{clearInterval(t),window.removeEventListener(`focus`,e),document.removeEventListener(`visibilitychange`,e)}},[]),Pm(e,t)}var ah={timeZone:void 0,dspIdentity:Qm,byId:e=>document.getElementById(e),node:(e,t,n)=>{let r=document.createElement(e);return t&&(r.className=t),n!==void 0&&(r.textContent=String(n)),r},mutation:rn,request:nn,mutationKey:on,settleMutationKey:sn,errorMessage:Am};function oh({page:e,hash:t}){let{timeZone:n}=rh(),r=(0,x.useMemo)(()=>e===`updates`?window.createUpdatesViews({...ah,timeZone:n}):window.createBackupsViews({...ah,timeZone:n}),[e,n]),[i,a]=(0,x.useState)(null),o=()=>`renderUpdates`in r?r.renderUpdates():r.renderBackups();return(0,x.useEffect)(()=>(window.showToast=(e,t,n)=>a({text:[e,t].filter(Boolean).join(`. `),error:n===`error`}),`setUpdatesActive`in r?r.setUpdatesActive(!0):r.setBackupsActive(!0),o(),()=>{`setUpdatesActive`in r?r.setUpdatesActive(!1):r.setBackupsActive(!1),delete window.showToast}),[r,t]),(0,S.jsxs)(S.Fragment,{children:[e===`updates`&&(0,S.jsx)(Rm,{title:`Updates`,description:`Explore what’s new in Dispatch.`,children:(0,S.jsx)(Gm,{onClick:()=>void o()})}),i&&(0,S.jsx)(Vm,{error:i.error,children:i.text}),(0,S.jsx)(`div`,{id:e===`updates`?`platform-updates-content`:`platform-backups-content`,className:e===`updates`?`updates-workspace`:`backup-workspace`})]})}var sh={release_changed:`A newer release is available. Review it and try again.`,release_dev_required:`Install the latest release on Dev before starting rollout.`,release_dsp_not_ready:`This DSP needs to be running and finish setup before it can be updated.`,release_health_failed:`Health checks failed. The previous version was restored.`,release_recovery_required:`The update needs recovery before another update can start.`,release_interrupted:`The update worker restarted. Review the state before continuing.`,release_baseline_required:`The installed version must be registered before updates can begin.`,release_fleet_changed:`The DSP list changed. Review it and start rollout again.`,release_verification_failed:`The release could not be verified. Check the worker’s GitHub connection and retry.`};function ch({hash:e}){let[t,n]=(0,x.useState)(`core`),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(!1),[s,c]=(0,x.useState)(null),l=Mt({queryKey:[`independent-updates`,r],queryFn:()=>nn(`/api/platform/updates${r?`?releaseId=${encodeURIComponent(r)}`:``}`),refetchInterval:3e3}),u=l.data,d=(0,x.useRef)(void 0),f=u?.tracks?.core.installedDigest;if((0,x.useEffect)(()=>{if(u?.mode!==`independent`)return;let e=d.current;d.current=f,e!==void 0&&f&&e!==f&&window.location.reload()},[u?.mode,f]),u&&u.mode!==`independent`)return(0,S.jsx)(oh,{page:`updates`,hash:e});async function p(e,n=null){if(!a){o(!0),c(null);try{await cn(`updates:${e}:${t}:${n}`,`/api/platform/updates`,{action:e,product:t,digest:n}),await Yt.invalidateQueries({queryKey:[`independent-updates`]})}catch(e){c(e)}finally{o(!1)}}}let m=u?.jobs.find(e=>[`queued`,`running`].includes(e.status)),h=u?.jobs[0]?.status===`failed`?u.jobs[0].failure:null,g=m?.action===`update_core`||u?.operation?.product===`core`;return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Rm,{title:`Updates`,description:`Choose when Core and your DSPs receive new releases.`,children:(0,S.jsxs)($,{variant:`outline`,disabled:a||u?.busy||!u?.worker.available,onClick:()=>void p(`refresh`),children:[(0,S.jsx)(Vn,{"aria-hidden":`true`}),`Check for updates`]})}),(0,S.jsx)(Hm,{error:s||(g?null:l.error)}),g&&(0,S.jsx)(Vm,{children:`Core is updating. This page will reconnect when it’s ready.`}),l.isPending?(0,S.jsx)(Um,{}):u?(0,S.jsxs)(`div`,{className:`space-y-5`,id:`platform-updates-content`,children:[!u.enabled&&(0,S.jsx)(Vm,{children:`Updates need initial setup. Your current services will continue running.`}),u.enabled&&!u.worker.available&&(0,S.jsx)(Vm,{error:!0,children:`The update worker is offline. Releases remain available to read.`}),h&&(0,S.jsx)(Vm,{error:!0,children:sh[h]||`The update could not finish. Review the current state, then retry or recover.`}),u.operation&&!g&&(0,S.jsxs)(Vm,{children:[u.operation.dspName||`Dev DSP`,` is updating. Private data is being preserved.`]}),u.recoveryRequired&&!m&&(0,S.jsxs)(`div`,{className:`rounded-xl border bg-card p-5 space-y-3`,children:[(0,S.jsx)(`p`,{children:`Recover the interrupted update before installing another release.`}),(0,S.jsx)($,{disabled:a||!u.worker.available,onClick:()=>void p(`recover`),children:`Recover update`})]}),(0,S.jsxs)(Fp,{value:t,onValueChange:e=>{n(e),i(null),c(null)},children:[(0,S.jsxs)(Lp,{"aria-label":`Update products`,children:[(0,S.jsxs)(Rp,{value:`core`,children:[(0,S.jsx)(Un,{"aria-hidden":`true`}),`Core`]}),(0,S.jsxs)(Rp,{value:`dsp`,children:[(0,S.jsx)(jn,{"aria-hidden":`true`}),`DSPs`]})]}),[`core`,`dsp`].map(e=>{let t=u.tracks[e],n=t.release,r=!!(n&&n.digest===t.latest),o=u.rollout&&u.rollout.status!==`completed`,s=e===`core`?`update_core`:t.tested?`rollout`:`update_dev`,c=e===`core`?`Update Core`:t.tested?`Rollout Update`:`Update Dev`;return(0,S.jsxs)(zp,{value:e,className:`space-y-5 pt-3`,children:[(0,S.jsxs)(`section`,{className:`rounded-xl border bg-card p-6 space-y-5`,"aria-label":`${e===`core`?`Core`:`DSP`} release`,children:[(0,S.jsxs)(`div`,{className:`flex flex-wrap justify-between items-start gap-4`,children:[(0,S.jsxs)(`div`,{className:`space-y-1`,children:[(0,S.jsx)(`h2`,{className:`text-xl font-semibold`,children:e===`core`?`Dispatch Core`:`DSP runtime and plugins`}),(0,S.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[e===`core`?`Installed`:`Installed on ${u.dev.name}`,`: `,t.installedVersion||`Not registered`]})]}),(0,S.jsxs)($,{disabled:a||!t.canUpdate||!r||e===`dsp`&&(!u.dev.available||!!o),onClick:()=>void p(s,t.latest),children:[(0,S.jsx)(Dn,{"aria-hidden":`true`}),c]})]}),(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e===`core`?`Updates the shared dashboard, API and Core services. Installed DSP runtimes and plugins keep their current versions.`:t.tested?`Dev has passed installation checks. Test the changes, then roll this version out to your DSPs one at a time.`:`Install this version on the permanent Dev DSP first. Your other DSPs receive it when you start rollout.`}),(0,S.jsxs)(`div`,{className:`border-t pt-5 space-y-4`,children:[t.history.length>0&&(0,S.jsxs)(`label`,{className:`flex flex-wrap items-center gap-3 text-sm font-medium`,children:[`Release history`,(0,S.jsx)(`select`,{"aria-label":`${e===`core`?`Core`:`DSP`} release history`,value:n?.id||``,onChange:e=>i(e.target.value),className:`rounded-md border bg-background px-3 py-2 max-w-full`,children:t.history.map(e=>(0,S.jsxs)(`option`,{value:e.id,children:[`Version `,e.version]},e.id))})]}),n?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`flex flex-wrap justify-between gap-3 items-baseline`,children:[(0,S.jsxs)(`h3`,{className:`text-lg font-semibold`,children:[`Version `,n.version]}),n.url&&(0,S.jsx)(`a`,{className:`text-sm underline underline-offset-4`,href:n.url,target:`_blank`,rel:`noreferrer`,children:`View release on GitHub`})]}),(0,S.jsx)(`div`,{className:`whitespace-pre-wrap break-words text-sm leading-7`,"aria-label":`Changelog`,children:n.notes}),!r&&(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`You’re reading a previous release. Select the latest version to update.`})]}):(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No verified releases yet.`})]})]}),e===`dsp`&&u.rollout&&(0,S.jsxs)(`section`,{className:`rounded-xl border bg-card p-6 space-y-4`,"aria-label":`Rollout progress`,children:[(0,S.jsxs)(`div`,{className:`flex flex-wrap justify-between gap-3 items-center`,children:[(0,S.jsxs)(`h2`,{className:`text-lg font-semibold`,children:[`Rollout · `,u.rollout.version]}),u.rollout.status===`running`&&(0,S.jsxs)($,{variant:`outline`,disabled:a||!u.worker.available,onClick:()=>void p(`pause`),children:[(0,S.jsx)(In,{"aria-hidden":`true`}),`Pause rollout`]}),u.rollout.status===`paused`&&(0,S.jsxs)($,{disabled:a||u.recoveryRequired||!u.worker.available||!!m,onClick:()=>void p(`resume`),children:[(0,S.jsx)(Ln,{"aria-hidden":`true`}),`Resume rollout`]})]}),(0,S.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[u.rollout.updated,` of `,u.rollout.total,` DSPs updated · `,u.rollout.status]}),u.rollout.status===`paused`&&(0,S.jsx)(Vm,{children:`The rollout is paused. Resolve the affected DSP before resuming this version.`}),(0,S.jsx)(`progress`,{"aria-label":`DSPs updated`,value:u.rollout.updated,max:Math.max(1,u.rollout.total),className:`w-full accent-primary`}),(0,S.jsx)(`ul`,{className:`divide-y`,children:u.rollout.members.map((e,t)=>(0,S.jsxs)(`li`,{className:`flex justify-between gap-4 py-3 text-sm`,children:[(0,S.jsx)(`span`,{children:e.name}),(0,S.jsx)(`span`,{className:`text-muted-foreground`,children:e.status})]},t))})]})]},e)})]})]}):null]})}function lh(){return(0,S.jsxs)(`span`,{className:`brand`,children:[(0,S.jsx)(`svg`,{viewBox:`0 0 28 28`,"aria-hidden":`true`,children:(0,S.jsx)(`path`,{fill:`currentColor`,d:`M3 3h9C20 3 25 7.5 25 14s-5 11-13 11H3v-7h6v2h3c4.5 0 7-2.2 7-6s-2.5-6-7-6H9v6H3V3Z`})}),(0,S.jsx)(`span`,{children:`Dispatch`})]})}var uh=null;function dh(){return window.turnstile?Promise.resolve(window.turnstile):uh||(uh=new Promise((e,t)=>{let n=document.createElement(`script`);n.src=`https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit`,n.async=!0;let r=()=>{clearTimeout(i),n.onload=null,n.onerror=null,n.remove(),t(Error(`turnstile_unavailable`))},i=window.setTimeout(r,15e3);n.onerror=r,n.onload=()=>{if(!window.turnstile)return r();clearTimeout(i),n.onload=null,n.onerror=null,e(window.turnstile)},document.head.appendChild(n)}).catch(e=>{throw uh=null,e}),uh)}function fh({siteKey:e,action:t,onToken:n,busy:r}){let i=(0,x.useRef)(null),[a,o]=(0,x.useState)(0),[s,c]=(0,x.useState)(`checking`);return(0,x.useEffect)(()=>{let r=!1,a,o;n(``),c(`checking`);let s=e=>{r||(n(``),c(e))};return dh().then(l=>{!r&&i.current&&(a=l,o=a.render(i.current,{sitekey:e,action:t,size:`flexible`,"response-field":!1,callback:e=>{r||(n(e),c(`ready`))},"error-callback":()=>s(`error`),"expired-callback":()=>s(`expired`),"timeout-callback":()=>s(`expired`),"unsupported-callback":()=>s(`error`)}))}).catch(()=>s(`error`)),()=>{r=!0,o!==void 0&&a?.remove(o)}},[e,t,a,n]),(0,S.jsxs)(`div`,{className:`min-w-0 space-y-2`,"aria-label":`Security verification`,children:[(0,S.jsx)(`div`,{ref:i}),(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,role:`status`,"aria-live":`polite`,children:s===`checking`?`Checking your browser…`:s===`ready`?`Security check complete.`:s===`expired`?`Security check expired. Please verify again.`:`Security check could not load. Check your connection and try again.`}),(s===`error`||s===`expired`)&&(0,S.jsx)($,{type:`button`,variant:`outline`,disabled:r,onClick:()=>o(e=>e+1),children:`Retry security check`})]})}function ph({hash:e,session:t,refresh:n}){let r=e===`#/forgot-password`,[i,a]=(0,x.useState)(()=>/^#\/reset-password\/([A-Za-z0-9_-]{43})$/.exec(e)?.[1]||``),[o,s]=(0,x.useState)(!1),[c,l]=(0,x.useState)(null),[u,d]=(0,x.useState)(``),[f,p]=(0,x.useState)(``),[m,h]=(0,x.useState)(0),g=r?t?.turnstile?.siteKey:null;(0,x.useEffect)(()=>{r||history.replaceState(null,``,`${location.pathname}#/reset-password`)},[r]);async function _(e){if(e.preventDefault(),o||g&&!f)return;let t=e.currentTarget,c=new FormData(t);s(!0),l(null);try{let e=await fetch(r?`/api/auth/forgot-password`:`/api/auth/reset-password`,{method:`POST`,credentials:`omit`,cache:`no-store`,referrerPolicy:`no-referrer`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({...Object.fromEntries(c),...r?g?{turnstileToken:f}:{}:{token:i}})}),o=await e.json().catch(()=>null);if(!e.ok||!o?.ok)throw new Jt(o?.error?.code||`request_failed`,e.status);t.reset(),d(o.data.message),r||(a(``),n().catch(()=>{}))}catch(e){l(e)}finally{s(!1),p(``),h(e=>e+1)}}return(0,S.jsxs)(`main`,{className:`auth-layout`,children:[(0,S.jsx)(`div`,{className:`auth-brand`,children:(0,S.jsx)(lh,{})}),(0,S.jsxs)(`section`,{className:`auth-panel`,children:[(0,S.jsx)(`h1`,{children:u?r?`Check your email`:`Password reset`:r?`Forgot your password?`:`Set a new password`}),(0,S.jsx)(`p`,{className:`auth-description`,children:r?`Enter your Dispatch account email and we’ll send you a reset link.`:`Choose a password you haven’t used elsewhere.`}),(0,S.jsx)(Hm,{error:c}),u?(0,S.jsx)(Vm,{children:u}):!r&&!i?(0,S.jsx)(Vm,{children:`This reset link is invalid or has expired. Request a new link to continue.`}):(0,S.jsx)(`form`,{onSubmit:_,children:(0,S.jsxs)(tm,{children:[r?(0,S.jsx)(Bm,{label:`Email address`,name:`email`,type:`email`,autoComplete:`username`,required:!0,maxLength:254,disabled:o}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Bm,{label:`New password`,name:`newPassword`,type:`password`,autoComplete:`new-password`,required:!0,minLength:12,maxLength:128,disabled:o,description:`Use 12–128 characters.`}),(0,S.jsx)(Bm,{label:`Confirm new password`,name:`confirmPassword`,type:`password`,autoComplete:`new-password`,required:!0,minLength:12,maxLength:128,disabled:o})]}),g&&(0,S.jsx)(fh,{siteKey:g,action:`forgot_password`,onToken:p,busy:o},m),(0,S.jsx)(qm,{busy:o,disabled:o||!(!g||f),children:r?`Send reset link`:`Reset password`})]})}),(0,S.jsxs)(`div`,{className:`mt-6 flex flex-wrap gap-4 text-sm text-primary`,children:[(0,S.jsx)(`a`,{className:`underline-offset-4 hover:underline`,href:`#/login`,children:`Back to sign in`}),!r&&(0,S.jsx)(`a`,{className:`underline-offset-4 hover:underline`,href:`#/forgot-password`,children:`Request a new link`})]})]}),(0,S.jsx)(`p`,{className:`auth-footnote`,children:r?`Reset links expire after 30 minutes.`:`Resetting your password signs out your existing sessions.`})]})}function mh({navigation:e,mobileNavigation:t,banner:n,header:r,children:i}){return(0,S.jsxs)(`div`,{className:`application`,children:[(0,S.jsx)(`aside`,{className:`desktop-sidebar`,children:e}),t,(0,S.jsxs)(`div`,{className:`main-area`,children:[n,(0,S.jsx)(`header`,{className:`topbar`,children:r}),(0,S.jsx)(`main`,{id:`main-content`,className:`page-container`,tabIndex:-1,children:i})]})]})}var hh=(0,x.createContext)(null);function gh(){let e=(0,x.useContext)(hh);if(!e)throw Error(`Session required`);return e}var _h=Qn(`inline-flex w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-full border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3`,{variants:{variant:{default:`bg-primary text-primary-foreground [a&]:hover:bg-primary/90`,secondary:`bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90`,destructive:`bg-destructive text-white focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40 [a&]:hover:bg-destructive/90`,outline:`border-border text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground`,ghost:`[a&]:hover:bg-accent [a&]:hover:text-accent-foreground`,link:`text-primary underline-offset-4 [a&]:hover:underline`}},defaultVariants:{variant:`default`}});function vh({className:e,variant:t=`default`,asChild:n=!1,...r}){let i=n?Ai:`span`;return(0,S.jsx)(i,{"data-slot":`badge`,"data-variant":t,className:H(_h({variant:t}),e),...r})}function yh({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`table-container`,className:`relative w-full overflow-x-auto`,children:(0,S.jsx)(`table`,{"data-slot":`table`,className:H(`w-full caption-bottom text-sm`,e),...t})})}function bh({className:e,...t}){return(0,S.jsx)(`thead`,{"data-slot":`table-header`,className:H(`[&_tr]:border-b`,e),...t})}function xh({className:e,...t}){return(0,S.jsx)(`tbody`,{"data-slot":`table-body`,className:H(`[&_tr:last-child]:border-0`,e),...t})}function Sh({className:e,...t}){return(0,S.jsx)(`tr`,{"data-slot":`table-row`,className:H(`border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted`,e),...t})}function Ch({className:e,...t}){return(0,S.jsx)(`th`,{"data-slot":`table-head`,className:H(`h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]`,e),...t})}function wh({className:e,...t}){return(0,S.jsx)(`td`,{"data-slot":`table-cell`,className:H(`p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]`,e),...t})}var Th=o(((e,t)=>{var n=(e,t)=>JSON.stringify(e)===JSON.stringify(t);function r(e,t){return!e||n(t[e.field],e.equals)}function i(e,t){return(e.rules||[]).filter(e=>{if(!r(e.when,t))return!1;if(e.kind===`included`){let n=t[e.selection],r=t[e.field];return r!==null&&n!==null&&!n.includes(r)}return!r(e.require,t)}).map(e=>({id:e.id,field:e.field||e.require.field,severity:e.severity,message:e.message}))}function a(e,t,n={}){if(t===void 0)return`Not recorded`;if(t===null)return`All current and future options`;if(typeof t==`boolean`)return t?`On`:`Off`;let r=e.options||n[e.optionsSource]||[],i=e=>r.find(t=>t.value===e)?.label||String(e);return Array.isArray(t)?t.length?t.map(i).join(`, `):`None`:i(t)}function o(e,t,r,i={}){let a=r.find(t=>t.id===e.field);if(e.kind===`choice`)return e.examples.find(e=>n(e.value,t[a.id]))?.text||``;if(e.kind===`columns`)return[e.leading,...(t[a.id]||[]).map(e=>(a.options||[]).find(t=>t.value===e)?.label||e)].filter(Boolean).join(` · `);let o=i[a.optionsSource]||[],s=t[a.id],c=s===null?o:o.filter(e=>s.includes(e.value));return`${c.reduce((e,t)=>e+(t.count||0),0)} ${e.unit} from ${c.length} ${e.groupLabel}.`}t.exports={same:n,conditionMatches:r,settingsIssues:i,formatSettingValue:a,settingsPreview:o,EFFECTS:Object.freeze({immediate:`Display changes take effect after saving.`,next_job:`Collection changes apply to new jobs. Running jobs keep their current settings.`,next_connection:`Changes apply to the next connection. An active connection keeps its current settings.`,schedule:`The schedule is updated after saving. Running collections are allowed to finish.`})}}))();function Eh({pluginId:e,scope:t,snapshot:n,busy:r,onRestore:i}){let[a,o]=(0,x.useState)([null]),s=a[a.length-1],{timeZone:c}=rh(),l=Mt({queryKey:[`plugin-settings`,e,t,`history`,n.revision,s],queryFn:({signal:t})=>nn(`/api/organization/plugins/${encodeURIComponent(e)}/settings/history${s===null?``:`?before=${s}`}`,{signal:t})});return(0,S.jsxs)(`section`,{className:`plugin-settings-history`,"aria-label":`Settings change history`,children:[(0,S.jsx)(`h2`,{children:`Change history`}),(0,S.jsx)(`p`,{children:`Restore values into your draft, then review and save. History belongs to this DSP.`}),(0,S.jsx)(Hm,{error:l.error}),l.isPending&&(0,S.jsx)(Um,{}),l.data?.items.map(e=>(0,S.jsxs)(`details`,{"data-revision":e.revision,children:[(0,S.jsxs)(`summary`,{children:[Nm(e.updatedAt,c),` ·`,` `,e.kind===`initial`?`Initial settings`:e.actorName||`Plugin update`,` `,`· Revision `,e.revision]}),e.changes.length?(0,S.jsx)(`ul`,{children:e.changes.map(e=>{let t=n.definition.fields.find(t=>t.id===e.field),r=e=>t?(0,Th.formatSettingValue)(t,e):JSON.stringify(e);return(0,S.jsxs)(`li`,{children:[(0,S.jsx)(`strong`,{children:e.label}),`: `,r(e.before),` →`,` `,r(e.after),e.beforeSource!==e.afterSource&&(0,S.jsxs)(`span`,{children:[` `,`(`,e.afterSource==="default"?`Plugin default`:`DSP override`,`)`]})]},e.field)})}):(0,S.jsx)(`p`,{children:`No values changed.`}),e.canRestore?(0,S.jsxs)(`div`,{className:`plugin-settings-history-actions`,children:[n.definition.sections.map(t=>(0,S.jsxs)($,{variant:`outline`,size:`sm`,disabled:r,onClick:()=>i(e.values,e.sources,n.definition.fields.filter(e=>e.section===t.id).map(e=>e.id)),children:[`Restore `,t.label]},t.id)),(0,S.jsxs)(`details`,{children:[(0,S.jsx)(`summary`,{children:`Restore an individual setting`}),n.definition.fields.map(t=>(0,S.jsxs)($,{variant:`ghost`,size:`sm`,disabled:r,onClick:()=>i(e.values,e.sources,[t.id]),children:[`Restore `,t.label]},t.id))]})]}):(0,S.jsx)(`p`,{children:`This entry predates the current settings definition and cannot be restored directly.`})]},e.revision)),(0,S.jsxs)(`div`,{className:`plugin-settings-history-pagination`,children:[(0,S.jsx)($,{variant:`outline`,disabled:a.length===1||l.isFetching,onClick:()=>o(e=>e.slice(0,-1)),children:`Newer changes`}),(0,S.jsx)($,{variant:`outline`,disabled:l.data?.nextBefore==null||l.isFetching,onClick:()=>o(e=>[...e,l.data.nextBefore]),children:`Older changes`})]})]})}function Dh(e,t=!1){let{session:n}=gh(),r=dn(n),i=`${n.user?.id}:${r?.organizationId}:${n.dspView?.viewRef||`member`}`,a=`${r?.organizationId}:${n.dspView?.viewRef||`member`}`,o=`/api/organization/plugins/${encodeURIComponent(e)}/settings`,s=[`plugin-settings`,e,i],c=w(),l=n.authenticated&&!!r;return{query:Mt({queryKey:s,queryFn:({signal:e})=>nn(o,{signal:e}),enabled:l,refetchInterval:15e3}),options:Mt({queryKey:[...s,`options`],queryFn:({signal:e})=>nn(`${o}/options`,{signal:e}),enabled:l&&t,staleTime:3e4}),update:Wt({mutationFn:({values:t,snapshot:n,sources:r})=>cn(`plugin-settings:${e}:${i}:${n.revision}`,o,{values:t,...r?{sources:r}:{},expectedRevision:n.revision,definitionVersion:n.definitionVersion}),onSuccess:async t=>{c.setQueryData(s,t),await c.invalidateQueries({predicate:t=>t.queryKey[0]!==`plugin-settings`&&String(t.queryKey[0]).startsWith(e+`-`)&&t.queryKey.some(e=>e===i||e===a)})}}),scope:i}}function Oh({field:e,value:t,options:n={},disabled:r=!1,onChange:i}){let a=e.options||e.optionsSource&&n[e.optionsSource]||[],o=`plugin-setting-${(0,x.useId)()}`;if(e.type===`boolean`)return(0,S.jsxs)(`div`,{className:`plugin-setting-toggle`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`label`,{htmlFor:o,children:e.label}),e.description&&(0,S.jsx)(`p`,{children:e.description})]}),(0,S.jsx)(`input`,{id:o,type:`checkbox`,role:`switch`,checked:t===!0,disabled:r,onChange:e=>i(e.target.checked)})]});if(e.type===`strings`){let n=t===null?a.map(e=>String(e.value)):t,o=new Map(a.map(e=>[String(e.value),e])),c=[...n,...a.map(e=>String(e.value)).filter(e=>!n.includes(e))];function s(e,t){i(t?[...n,e]:n.filter(t=>t!==e))}return(0,S.jsxs)(`fieldset`,{className:`plugin-setting-multiple`,disabled:r,children:[(0,S.jsx)(`legend`,{children:e.label}),e.description&&(0,S.jsx)(`p`,{children:e.description}),e.nullable&&(0,S.jsxs)(`label`,{className:`plugin-setting-choice`,children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:t===null,onChange:e=>i(e.target.checked?null:[...n])}),`Include all current and future options`]}),(0,S.jsx)(`div`,{className:`plugin-setting-choices`,children:c.map((a,c)=>{let l=o.get(a),u=n.includes(a);return(0,S.jsxs)(`div`,{className:`plugin-setting-option`,children:[(0,S.jsxs)(`label`,{className:`plugin-setting-choice`,children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:u,disabled:t===null,onChange:e=>s(a,e.target.checked)}),(0,S.jsx)(`span`,{children:l?.label||`${a} (not currently available)`}),l?.count!==void 0&&(0,S.jsx)(`span`,{className:`plugin-setting-count`,children:l.count})]}),e.ordered&&u&&(0,S.jsx)(`div`,{className:`plugin-setting-order`,children:[-1,1].map(e=>(0,S.jsx)($,{type:`button`,variant:`ghost`,size:`sm`,"aria-label":`Move ${l?.label||a} ${e<0?`earlier`:`later`}`,disabled:r||c+e<0||c+e>=n.length,onClick:()=>{let t=[...n];[t[c],t[c+e]]=[t[c+e],t[c]],i(t)},children:e<0?`↑`:`↓`},e))})]},a)})}),!c.length&&(0,S.jsx)(`p`,{children:`No options are available yet.`})]})}if(a.length||e.optionsSource){let n=t!==null&&!a.some(e=>String(e.value)===String(t));return(0,S.jsxs)(`div`,{className:`plugin-setting-field`,children:[(0,S.jsx)(`label`,{htmlFor:o,children:e.label}),(0,S.jsxs)(`select`,{id:o,value:t===null?``:String(t),disabled:r,onChange:t=>i(t.target.value===``&&e.nullable?null:e.type===`integer`?Number(t.target.value):t.target.value),children:[e.nullable&&(0,S.jsxs)(`option`,{value:``,children:[`All `,e.optionsSource||`options`]}),n&&(0,S.jsxs)(`option`,{value:String(t),children:[String(t),` (not currently available)`]}),a.map(e=>(0,S.jsx)(`option`,{value:String(e.value),children:e.label},String(e.value)))]}),e.description&&(0,S.jsx)(`p`,{children:e.description})]})}return(0,S.jsxs)(`div`,{className:`plugin-setting-field`,children:[(0,S.jsx)(`label`,{htmlFor:o,children:e.label}),(0,S.jsx)(`input`,{id:o,type:e.type===`integer`?`number`:`text`,value:String(t??``),min:e.minimum,max:e.maximum,maxLength:128,disabled:r,onChange:t=>i(e.type===`integer`?Number(t.target.value):t.target.value)}),e.description&&(0,S.jsx)(`p`,{children:e.description})]})}function kh({pluginId:e,title:t,description:n,backHref:r,renderSection:i}){let{session:a}=gh(),o=Dh(e,!0),[s,c]=(0,x.useState)(null),[l,u]=(0,x.useState)(null),[d,f]=(0,x.useState)(!1),[p,m]=(0,x.useState)({}),[h,g]=(0,x.useState)(!1),[_,v]=(0,x.useState)(``),[y,b]=(0,x.useState)([]),C=!!s&&(JSON.stringify(l)!==JSON.stringify(s.values)||JSON.stringify(p)!==JSON.stringify(s.sources));(0,x.useEffect)(()=>{o.query.data&&!C&&(c(o.query.data),u(structuredClone(o.query.data.values)),m({...o.query.data.sources}))},[o.query.data,C]);let w=!!s&&!!o.query.data&&(s.revision!==o.query.data.revision||s.definitionVersion!==o.query.data.definitionVersion);if(!fn(a))return(0,S.jsx)(Vm,{children:`Your DSP owner can manage plugin settings.`});if(o.query.isPending)return(0,S.jsx)(Um,{});if(!s||!l)return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Hm,{error:o.query.error}),(0,S.jsx)($,{onClick:()=>void o.query.refetch(),children:`Retry settings`})]});let T=o.options.data||{},E=o.update.isPending,D=(0,Th.settingsIssues)(s.definition,l),O=D.some(e=>e.severity===`error`);async function ee(){if(s&&l)try{let e=await o.update.mutateAsync({values:l,snapshot:s,sources:p}),t=new Set(s.definition.fields.filter(t=>JSON.stringify(s.values[t.id])!==JSON.stringify(e.values[t.id])).map(e=>e.applies).filter(e=>e!==void 0));b([...t].map(e=>Th.EFFECTS[e])),c(e),u(structuredClone(e.values)),m({...e.sources}),v(``)}catch{}}function k(){let e=o.query.data||s;e&&(c(e),u(structuredClone(e.values)),m({...e.sources}),v(``),b([]),o.update.reset())}function A(e,t,n){u(r=>({...r,...Object.fromEntries(n.map(n=>[n,structuredClone(t[n]==="default"?s.definition.fields.find(e=>e.id===n).default:e[n])]))})),m(e=>({...e,...Object.fromEntries(n.map(e=>[e,t[e]]))})),v(`Restored into your draft. Review your changes before saving.`),o.update.reset()}function j(e){A(Object.fromEntries(s.definition.fields.map(e=>[e.id,e.default])),Object.fromEntries(e.map(e=>[e,`default`])),e)}return(0,S.jsxs)(`div`,{className:`plugin-settings-page`,children:[(0,S.jsx)(`a`,{className:`plugin-settings-back`,href:r,children:`← Back`}),(0,S.jsx)(Rm,{title:t,description:n}),(0,S.jsx)(Hm,{error:o.query.error||o.options.error||o.update.error}),w&&(0,S.jsx)(Vm,{children:`These settings changed in another session. Discard your draft to load the latest settings before saving.`}),_&&(0,S.jsx)(Vm,{children:_}),D.map(e=>(0,S.jsx)(`p`,{className:`plugin-settings-rule`,role:e.severity===`error`?`alert`:`status`,children:e.message},e.id)),(0,S.jsxs)(Fp,{defaultValue:s.definition.sections[0].id,children:[(0,S.jsx)(Lp,{variant:`line`,"aria-label":`${t} sections`,children:s.definition.sections.map(e=>(0,S.jsx)(Rp,{value:e.id,children:e.label},e.id))}),s.definition.sections.map(e=>(0,S.jsxs)(zp,{value:e.id,children:[e.description&&(0,S.jsx)(`p`,{className:`plugin-settings-description`,children:e.description}),(0,S.jsx)(`div`,{className:`plugin-settings-fields`,children:s.definition.fields.filter(t=>t.section===e.id&&(0,Th.conditionMatches)(t.visibleWhen,l)).map(e=>(0,S.jsxs)(`div`,{className:e.type===`boolean`||e.type===`strings`?`plugin-setting-wide`:``,children:[(0,S.jsx)(Oh,{field:e,value:l[e.id],options:T,disabled:E||!(0,Th.conditionMatches)(e.enabledWhen,l)||!!e.optionsSource&&o.options.isPending,onChange:t=>{u(n=>({...n,[e.id]:t})),m(t=>({...t,[e.id]:`override`})),v(``),o.update.reset()}}),!(0,Th.conditionMatches)(e.enabledWhen,l)&&e.disabledReason&&(0,S.jsx)(`p`,{className:`plugin-setting-help`,children:e.disabledReason}),(0,S.jsxs)(`div`,{className:`plugin-setting-source`,children:[(0,S.jsx)(`span`,{children:p[e.id]==="default"?`Plugin default`:`DSP override`}),(0,S.jsx)($,{type:`button`,variant:`ghost`,size:`sm`,disabled:E,"aria-label":p[e.id]==="default"?`Keep current value for ${e.label}`:`Use plugin default for ${e.label}`,onClick:()=>p[e.id]==="default"?m(t=>({...t,[e.id]:`override`})):j([e.id]),children:p[e.id]==="default"?`Keep this value`:`Use plugin default`})]}),(0,S.jsxs)(`p`,{className:`plugin-setting-help`,children:[`Default:`,` `,(0,Th.formatSettingValue)(e,e.default,T)]})]},e.id))}),(s.definition.previews||[]).filter(t=>t.section===e.id).map(e=>(0,S.jsxs)(`p`,{role:`status`,className:`plugin-settings-preview`,children:[e.label,`:`,` `,(0,Th.settingsPreview)(e,l,s.definition.fields,T)]},e.id)),i?.(e.id,l,T),(0,S.jsxs)($,{type:`button`,variant:`outline`,size:`sm`,disabled:E,onClick:()=>j(s.definition.fields.filter(t=>t.section===e.id).map(e=>e.id)),children:[`Restore `,e.label,` defaults`]})]},e.id))]}),(0,S.jsxs)(`div`,{className:`plugin-settings-defaults`,children:[(0,S.jsx)($,{type:`button`,variant:`ghost`,disabled:E,onClick:()=>f(!0),children:`Restore defaults`}),(0,S.jsx)($,{variant:`ghost`,type:`button`,onClick:()=>g(e=>!e),"aria-expanded":h,children:`Change history`}),(0,S.jsx)(`span`,{children:`Settings apply to this DSP.`})]}),h&&(0,S.jsx)(Eh,{pluginId:e,scope:o.scope,snapshot:s,busy:E||w,onRestore:A},o.scope),!C&&y.map(e=>(0,S.jsx)(`p`,{className:`plugin-settings-effect`,role:`status`,children:e},e)),(0,S.jsxs)(`footer`,{className:`plugin-settings-footer`,children:[(0,S.jsx)(`span`,{role:`status`,children:C?`You have unsaved changes`:s.appliedRevision===s.revision?o.update.isSuccess?`Settings saved`:`All changes saved`:`Saved. Applying settings…`}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)($,{variant:`outline`,disabled:!C||E,onClick:k,children:`Discard`}),(0,S.jsx)($,{disabled:!C||E||w||O,onClick:()=>void ee(),children:E?`Saving…`:`Save changes`})]})]}),(0,S.jsx)(mm,{open:d,onOpenChange:f,children:(0,S.jsxs)(_m,{children:[(0,S.jsxs)(vm,{children:[(0,S.jsx)(bm,{children:`Restore plugin defaults?`}),(0,S.jsx)(xm,{children:`Your connection and collected records are preserved. Review the defaults before saving.`})]}),(0,S.jsxs)(ym,{children:[(0,S.jsx)($,{variant:`outline`,onClick:()=>f(!1),children:`Cancel`}),(0,S.jsx)($,{onClick:()=>{j(s.definition.fields.map(e=>e.id)),f(!1)},children:`Restore defaults`})]})]})})]})}function Ah(e){let{session:t}=gh(),n=`${e.pluginId}:${t.user?.id}:${dn(t)?.organizationId}:${t.dspView?.viewRef||`member`}`;return(0,S.jsx)(kh,{...e},n)}async function jh(e,t,n,r){if(!/^[a-z][a-z0-9-]{0,63}$/.test(e)||!/^[a-z][a-z0-9_.]{0,63}$/.test(t))throw Error(`Invalid plugin operation`);return{ok:!0,data:await rn(`/api/plugins/${e}/${t}`,`POST`,n,r)}}var Mh=s({ApiError:()=>Jt,Badge:()=>vh,Button:()=>$,EmptyState:()=>Wm,ErrorNotice:()=>Hm,Loading:()=>Um,Notice:()=>Vm,PageHeading:()=>Rm,PluginSettingsField:()=>Oh,PluginSettingsForm:()=>Ah,Table:()=>yh,TableBody:()=>xh,TableCell:()=>wh,TableHead:()=>Ch,TableHeader:()=>bh,TableRow:()=>Sh,Tabs:()=>Fp,TabsContent:()=>zp,TabsList:()=>Lp,TabsTrigger:()=>Rp,TextField:()=>Bm,activeMembership:()=>dn,calendarDateLabel:()=>Lm,dateTime:()=>Nm,has:()=>ln,idempotent:()=>cn,invokePluginOperation:()=>jh,isDspOwner:()=>fn,moveCalendarDate:()=>Im,mutation:()=>rn,request:()=>nn,useBusinessToday:()=>ih,usePluginSettings:()=>Dh,useSession:()=>gh,useTimezone:()=>rh}),Nh=new Map,Ph=(e,t)=>Nh.get(`${e}@${t}`);Object.defineProperty(globalThis,"DispatchPluginHost",{value:Object.freeze({react:x,jsx:S,query:qt,ui:Mh,register(e){if(e.apiVersion!==1||!/^[a-z][a-z0-9-]{0,63}$/.test(e.id)||!/^\d+\.\d+\.\d+$/.test(e.version)||!e.pages||Object.values(e.pages).some(e=>typeof e!=`function`))throw Error(`Plugin interface unavailable`);if(Nh.size>=64)throw Error(`Plugin limit reached`);Nh.set(`${e.id}@${e.version}`,Object.freeze(e))}}),writable:!1,configurable:!1});var Fh=new Map,Ih=new Map;window.addEventListener(`dispatch-authority-changed`,()=>{Fh.clear(),Ih.clear()});async function Lh(e,t,n){let r=await nn(`/api/plugin-assets/${e}/${n}`);if(r.id!==e||r.version!==t||r.revision!==n||typeof r.javascript!=`string`||r.javascript.length>2097152||typeof r.stylesheet!=`string`||r.stylesheet.length>1048576)throw new Jt(`plugin_unavailable`);let i=document.querySelector(`meta[name=dispatch-style-nonce]`)?.content;if(!i)throw new Jt(`plugin_unavailable`);let a=document.createElement(`script`);if(a.nonce=i,a.textContent=r.javascript,document.head.append(a),a.remove(),!Ph(e,t))throw new Jt(`plugin_unavailable`);let o=document.createElement(`style`);o.nonce=i,o.textContent=r.stylesheet,o.dataset.dispatchPlugin=`${e}@${t}`,document.head.append(o)}function Rh(e,t,n,r){let i=`${e}@${t}:${n}`,a=`${i}/${r}`,o=Fh.get(a);return o||(o=(0,x.lazy)(async()=>{if(!Ph(e,t)){let r=Ih.get(i);r||(r=Lh(e,t,n).catch(e=>{throw Ih.delete(i),e}),Ih.set(i,r)),await r}let a=Ph(e,t)?.pages[r];if(!a)throw new Jt(`plugin_unavailable`);return{default:a}}),Fh.size>=128&&Fh.delete(Fh.keys().next().value),Fh.set(a,o)),o}var zh=class extends x.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}render(){return this.state.error?(0,S.jsx)(Hm,{error:this.state.error}):(0,S.jsx)(x.Suspense,{fallback:(0,S.jsx)(Um,{}),children:this.props.children})}},Bh=[{title:`New`,kinds:[`added`]},{title:`Improved`,kinds:[`improved`,`changed`]},{title:`Fixed`,kinds:[`fixed`]},{title:`Removed`,kinds:[`removed`]}];function Vh(){let{session:e}=gh(),{timeZone:t}=rh(),[n,r]=(0,x.useState)(null),[i,a]=(0,x.useState)(!1),[o,s]=(0,x.useState)(!1),c=(0,x.useRef)(!1),l=(0,x.useRef)(null);(0,x.useEffect)(()=>{let e=!1;return nn(`/api/updates/popup`).then(t=>{e||r(t.release)}).catch(()=>{}),()=>{e=!0}},[]);async function u(){if(n&&!c.current){c.current=!0,a(!0),s(!1);try{await rn(`/api/updates/popup`,`POST`,{releaseId:n.releaseId}),r(null)}catch{s(!0)}finally{c.current=!1,a(!1)}}}return(0,x.useEffect)(()=>{if(!n)return;let e=()=>{nn(`/api/updates/popup`).then(e=>{e.release||r(null)}).catch(()=>{})};return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[n]),!n||e.dspView?null:(0,S.jsx)(mm,{open:!0,onOpenChange:e=>{e||u()},children:(0,S.jsxs)(_m,{className:`release-popup`,showCloseButton:!1,onInteractOutside:e=>e.preventDefault(),onOpenAutoFocus:e=>{e.preventDefault(),l.current?.focus()},onCloseAutoFocus:e=>{e.preventDefault(),document.getElementById(`main-content`)?.focus()},children:[(0,S.jsxs)(`header`,{className:`release-popup-header`,children:[(0,S.jsx)(`p`,{className:`release-popup-eyebrow`,children:`What’s new`}),(0,S.jsxs)(bm,{ref:l,tabIndex:-1,className:`release-popup-title`,children:[`Dispatch `,n.version]}),(0,S.jsxs)(xm,{children:[(0,S.jsx)(`time`,{dateTime:n.publishedAt,children:new Date(n.publishedAt).toLocaleDateString(void 0,{month:`long`,day:`numeric`,year:`numeric`,timeZone:t})}),(0,S.jsx)(`span`,{className:`release-popup-intro`,children:`Here’s what changed in the latest release.`})]}),(0,S.jsx)($,{variant:`ghost`,size:`icon`,className:`release-popup-close`,"aria-label":`Close update`,disabled:i,onClick:()=>void u(),children:(0,S.jsx)(qn,{"aria-hidden":`true`})})]}),(0,S.jsxs)(`div`,{className:`release-popup-body`,children:[Bh.map(e=>{let t=n.changelog.filter(t=>e.kinds.includes(t.kind));return t.length?(0,S.jsxs)(`section`,{"aria-label":e.title,children:[(0,S.jsx)(`h3`,{children:e.title}),(0,S.jsx)(`ul`,{children:t.map((e,t)=>(0,S.jsxs)(`li`,{children:[(0,S.jsx)(`strong`,{children:e.title}),e.description&&(0,S.jsx)(`p`,{children:e.description})]},t))})]},e.title):null}),n.afterUpdating.length>0&&(0,S.jsxs)(`section`,{"aria-label":`After updating`,children:[(0,S.jsx)(`h3`,{children:`After updating`}),(0,S.jsx)(`ul`,{children:n.afterUpdating.map((e,t)=>(0,S.jsxs)(`li`,{children:[(0,S.jsx)(`strong`,{children:e.title}),(0,S.jsx)(`p`,{children:e.description})]},t))})]})]}),(0,S.jsxs)(`footer`,{className:`release-popup-footer`,children:[o&&(0,S.jsx)(`p`,{role:`alert`,children:`We couldn’t save your dismissal. Please try again.`}),(0,S.jsx)($,{disabled:i,onClick:()=>void u(),children:i?`Saving…`:o?`Try again`:`Got it`})]})]})})}function Hh({...e}){return(0,S.jsx)(ap,{"data-slot":`dropdown-menu`,...e})}function Uh({...e}){return(0,S.jsx)(op,{"data-slot":`dropdown-menu-trigger`,...e})}function Wh({className:e,sideOffset:t=4,...n}){return(0,S.jsx)(sp,{children:(0,S.jsx)(cp,{"data-slot":`dropdown-menu-content`,sideOffset:t,className:H(`z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,e),...n})})}function Gh({...e}){return(0,S.jsx)(lp,{"data-slot":`dropdown-menu-group`,...e})}function Kh({className:e,inset:t,variant:n=`default`,...r}){return(0,S.jsx)(up,{"data-slot":`dropdown-menu-item`,"data-inset":t,"data-variant":n,className:H(`relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!`,e),...r})}function qh({name:e}){let{initials:t,className:n}=Qm(e);return(0,S.jsx)(`span`,{"aria-hidden":`true`,className:n,children:t})}function Jh(e){let t=$p().themePack.components?.DspAvatar||qh;return(0,S.jsx)(t,{...e})}var Yh=e=>e.installation.operation?.kind===`destroy`,Xh=e=>Yh(e)||e.installation.operation?.kind===`restore_dsp`||[`decommissioning`,`decommissioned`].includes(e.installation.state)||e.installation.operation?.kind===`decommission`,Zh=e=>!Xh(e)&&!Yh(e)&&e.organizationStatus===`active`&&e.installation.state===`ready`,Qh=e=>!Xh(e)&&!Yh(e)&&!Zh(e)&&e.organizationStatus!==`suspended`,$h={ready:`Running`,pending:`Queued`,provisioning:`Creating`,waiting_for_owner:`Prepared`,waiting_for_provider_auth:`Prepared`,verifying:`Verifying`,failed:`Needs attention`,suspended:`Suspended`,decommissioning:`Removing`,decommissioned:`Removed`},eg={provision:`Start provisioning`,retry_provision:`Retry provisioning`,decommission:`Remove DSP`,destroy:`Permanently delete DSP`,restore_dsp:`Restore DSP`,suspend:`Suspend DSP`,resume:`Resume DSP`,restart:`Restart runtime`,revoke_owner_invitation:`Revoke invitation`,issue_owner_invitation:`Invite owner`},tg=e=>e.detailsStatus===`required`?e.ownerEmail||`New DSP`:e.name;function ng(e){return Yh(e)||Xh(e)?`Closed`:e.ownerStatus===`pending`?`Invitation pending`:e.ownerStatus===`missing`?`Invite needed`:e.detailsStatus===`complete`?[`ready`,`suspended`].includes(e.installation.state)?`Complete`:`Finishing setup`:`DSP details needed`}function rg(e){return Yh(e)?e.installation.operation?.status===`failed`?`Deletion failed`:`Deleting`:e.installation.operation?.kind===`restore_dsp`?e.installation.operation.status===`failed`?`Restore failed`:`Restoring`:$h[e.installation.state]||`Unavailable`}function ig(){let{refresh:e}=gh(),t=Mt({queryKey:[`fleet`],queryFn:({signal:e})=>nn(`/api/platform/organizations`,{signal:e}),refetchInterval:5e3}),[n,r]=(0,x.useState)(``),[i,a]=(0,x.useState)(`all`),[o,s]=(0,x.useState)(!1),[c,l]=(0,x.useState)(null),[u,d]=(0,x.useState)(null),[f,p]=(0,x.useState)(null),[m,h]=(0,x.useState)(null),[g,_]=(0,x.useState)(!1),[v,y]=(0,x.useState)(null),[b,C]=(0,x.useState)(``),w=t.data||[],T=w.filter(e=>(i===`removed`?Xh(e):i===`running`?Zh(e):i===`onboarding`?Qh(e):!Xh(e))&&`${e.name} ${e.abbreviation||``} ${e.ownerEmail||``} ${e.stations.map(e=>e.code).join(` `)}`.toLowerCase().includes(n.trim().toLowerCase())),E=t.error?void 0:w.find(e=>e.continuityRef===c),D=e=>!Xh(e)&&!Yh(e)&&e.organizationStatus!==`suspended`;async function O(t){_(!0),y(null);try{let n=await rn(`/api/platform/organization/view`,`POST`,{controlRef:t.controlRef});$t(n.dspView.viewRef),await e(n),location.hash=n.memberships[0].organization.status===`active`?`#/dashboard`:`#/team`}catch(e){y(e)}finally{_(!1)}}async function ee(e){e.preventDefault(),_(!0),y(null);let n=new FormData(e.currentTarget).get(`ownerEmail`);try{let e=await cn(f?`${f.continuityRef}:invite`:`organization:create`,f?`/api/platform/organization/owner-invitation`:`/api/platform/organizations`,{ownerEmail:n,...f?{controlRef:f.controlRef}:{}});h(e),s(!1),p(null),await t.refetch()}catch(e){y(e)}finally{_(!1)}}async function k(e){if(!u)return;let{org:n,kind:r}=u,i=w.find(e=>e.continuityRef===n.continuityRef);if(!i)throw Error(`DSP unavailable`);let a=`${n.continuityRef}:${r}`;try{r===`revoke_owner_invitation`?await cn(a,`/api/platform/organization/owner-invitation/revoke`,{controlRef:i.controlRef}):await cn(a,`/api/platform/installation/${{provision:`provision`,retry_provision:`retry`,decommission:`remove`,destroy:`delete`,restore_dsp:`restore`,suspend:`suspend`,resume:`resume`,restart:`restart`}[r]}`,{controlRef:i.controlRef,expectedRevision:i.installation.revision,...r===`destroy`?{password:e}:{}}),C(`${n.name}: request accepted.`)}finally{await t.refetch()}}function A(e){return[...e.installation.availableActions,...e.availableActions].filter(e=>eg[e]&&(![`destroy`,`restore_dsp`].includes(e)||i===`removed`))}function j(e,t){l(null),y(null),t===`issue_owner_invitation`?p(e):d({org:e,kind:t})}return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Rm,{title:`DSPs`,description:`Manage your DSPs and onboarding.`,children:(0,S.jsxs)($,{onClick:()=>{s(!0),y(null)},children:[(0,S.jsx)(zn,{"data-icon":`inline-start`}),`Create new DSP`]})}),(0,S.jsxs)(`div`,{className:`inline-summary`,"aria-label":`DSP summary`,children:[(0,S.jsxs)(`span`,{children:[(0,S.jsx)(`strong`,{children:w.filter(e=>!Xh(e)).length}),` `,`DSPs`]}),(0,S.jsxs)(`span`,{children:[(0,S.jsx)(`strong`,{children:w.filter(Zh).length}),` running`]}),(0,S.jsxs)(`span`,{children:[(0,S.jsx)(`strong`,{children:w.filter(Qh).length}),` onboarding`]})]}),(0,S.jsx)(Zm,{result:m}),b&&(0,S.jsx)(Vm,{children:b}),(0,S.jsx)(Fp,{value:i,onValueChange:a,children:(0,S.jsx)(Lp,{variant:`line`,className:`page-tabs`,children:[[`all`,`All DSPs`],[`running`,`Running`],[`onboarding`,`Onboarding`],[`removed`,`Removed`]].map(([e,t])=>(0,S.jsx)(Rp,{value:e,children:t},e))})}),(0,S.jsxs)(`div`,{className:`table-toolbar`,children:[(0,S.jsx)(Km,{value:n,onChange:r,placeholder:`Search DSPs or owner email`}),(0,S.jsx)(Gm,{onClick:()=>void t.refetch(),busy:t.isFetching})]}),(0,S.jsx)(Hm,{error:t.error}),(0,S.jsx)(Hm,{error:v}),t.isPending?(0,S.jsx)(Um,{}):t.error?null:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(yh,{className:`fleet-table`,children:[(0,S.jsx)(bh,{children:(0,S.jsxs)(Sh,{children:[(0,S.jsx)(Ch,{className:`w-[28%]`,children:`DSP`}),(0,S.jsx)(Ch,{children:`Owner`}),(0,S.jsx)(Ch,{children:`Runtime`}),(0,S.jsx)(Ch,{children:`Onboarding`}),(0,S.jsx)(Ch,{children:(0,S.jsx)(`span`,{className:`sr-only`,children:`Actions`})})]})}),(0,S.jsx)(xh,{children:T.map(e=>(0,S.jsxs)(Sh,{"data-state":c===e.continuityRef?`selected`:void 0,children:[(0,S.jsx)(wh,{children:(0,S.jsxs)(`button`,{className:`identity-button`,onClick:()=>l(e.continuityRef),children:[(0,S.jsx)(Jh,{name:tg(e)}),(0,S.jsxs)(`span`,{className:`dsp-identity-copy`,children:[(0,S.jsx)(`strong`,{children:tg(e)}),(0,S.jsx)(`span`,{children:e.detailsStatus===`complete`?e.abbreviation||e.stations.map(e=>e.code).join(`, `):e.detailsStatus===`submitted`?`Applying DSP details`:`Awaiting DSP details`})]})]})}),(0,S.jsx)(wh,{className:`text-muted-foreground`,children:e.ownerEmail||`No owner assigned`}),(0,S.jsx)(wh,{children:(0,S.jsx)(Jm,{value:e.installation.state,children:rg(e)})}),(0,S.jsx)(wh,{children:(0,S.jsx)(Jm,{value:ng(e)===`Complete`?`neutral`:`pending`,children:ng(e)})}),(0,S.jsx)(wh,{className:`text-right`,children:(0,S.jsxs)(Hh,{children:[(0,S.jsx)(Uh,{asChild:!0,children:(0,S.jsx)($,{variant:`ghost`,size:`icon`,"aria-label":`Actions for ${tg(e)}`,children:(0,S.jsx)(kn,{})})}),(0,S.jsx)(Wh,{align:`end`,children:(0,S.jsxs)(Gh,{children:[(0,S.jsxs)(Kh,{disabled:g||!D(e),onSelect:()=>void O(e),children:[(0,S.jsx)(An,{}),` View`]}),A(e).map(t=>(0,S.jsx)(Kh,{disabled:!A(e).includes(t),variant:[`destroy`,`decommission`,`suspend`,`revoke_owner_invitation`].includes(t)?`destructive`:`default`,onSelect:()=>j(e,t),children:eg[t]},t))]})})]})})]},e.continuityRef))})]}),!T.length&&(0,S.jsx)(Wm,{title:n?`No DSPs match your search`:i===`removed`?`No removed DSPs`:`No DSPs here yet`,description:n?`Try another name or email.`:`Create a DSP to invite its owner.`}),(0,S.jsxs)(`p`,{className:`table-count`,children:[T.length,` DSP`,T.length===1?``:`s`]})]}),(0,S.jsx)(Ym,{open:o||!!f,onClose:()=>{s(!1),p(null)},title:f?`Invite DSP owner`:`Create new DSP`,description:`Invite an owner. Their workspace will be prepared while they finish setup.`,busy:g,children:(0,S.jsxs)(`form`,{onSubmit:ee,className:`panel-form`,children:[(0,S.jsxs)(tm,{children:[(0,S.jsx)(Bm,{label:`Owner email`,name:`ownerEmail`,type:`email`,autoComplete:`off`,maxLength:254,required:!0,disabled:g}),(0,S.jsx)(Hm,{error:v})]}),(0,S.jsxs)(`div`,{className:`panel-footer`,children:[(0,S.jsx)($,{type:`button`,variant:`outline`,disabled:g,onClick:()=>{s(!1),p(null)},children:`Cancel`}),(0,S.jsx)(qm,{busy:g,children:f?`Create invitation`:`Create DSP`})]})]})}),(0,S.jsx)(Ym,{open:!!E,onClose:()=>l(null),title:E?(0,S.jsxs)(`span`,{className:`dsp-panel-identity`,children:[(0,S.jsx)(Jh,{name:tg(E)}),(0,S.jsx)(`span`,{children:tg(E)})]}):`DSP details`,description:`DSP ownership and runtime status.`,children:E&&(0,S.jsxs)(`div`,{className:`panel-body`,children:[(0,S.jsxs)(`dl`,{className:`detail-list`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`Owner`}),(0,S.jsx)(`dd`,{children:E.ownerEmail||`Not assigned`})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`Runtime`}),(0,S.jsx)(`dd`,{children:(0,S.jsx)(Jm,{value:E.installation.state,children:rg(E)})})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`Onboarding`}),(0,S.jsx)(`dd`,{children:ng(E)})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`Station`}),(0,S.jsx)(`dd`,{children:E.stations.map(e=>e.code).join(`, `)||`—`})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`Timezone`}),(0,S.jsx)(`dd`,{children:E.timezone||`—`})]})]}),!!E.installation.failure&&(0,S.jsx)(Vm,{error:!0,children:`This DSP needs attention. Review its setup or retry the failed operation.`}),(0,S.jsxs)(`div`,{className:`flex flex-col gap-2 mt-6`,children:[(0,S.jsxs)($,{disabled:g||!D(E),onClick:()=>void O(E),children:[(0,S.jsx)(An,{}),` `,g?`Opening…`:`View`]}),!D(E)&&(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Viewing is unavailable for suspended or removed DSPs.`}),(0,S.jsx)(Hm,{error:v}),A(E).map(e=>(0,S.jsxs)($,{variant:`outline`,onClick:()=>j(E,e),children:[eg[e],(0,S.jsx)(Cn,{"data-icon":`inline-end`})]},e))]})]})}),u&&(0,S.jsx)(Xm,{title:eg[u.kind],passwordRequired:u.kind===`destroy`,description:u.kind===`destroy`?`Permanently delete ${u.org.name} and all its runtime data and backups. Everyone will lose access. This cannot be undone.`:u.kind===`decommission`?`Remove ${u.org.name}. Access will stop immediately and its services will stop. Existing data will be retained so you can restore this DSP later.`:u.kind===`restore_dsp`?`Restore ${u.org.name} with its retained data and settings. Users can sign in again once services are healthy.`:u.kind===`suspend`?`Suspend ${u.org.name}. User access and collection will stop. All data and saved connections will be retained.`:u.kind===`resume`?`Resume ${u.org.name}. Its services and user access will return once the runtime is healthy.`:u.kind===`restart`?`Restart the runtime for ${u.org.name}. Collection and user access will pause briefly.`:u.kind===`revoke_owner_invitation`?`Revoke the owner invitation for ${u.org.name}? The invitation link will stop working.`:`Confirm this action for ${u.org.name}.`,onClose:()=>d(null),onConfirm:k},`${u.org.continuityRef}:${u.kind}`)]})}function ag(){let[e,t]=(0,x.useState)(!1),[n,r]=(0,x.useState)(null),i=Mt({queryKey:[`platform-diagnostics`],queryFn:()=>nn(`/api/platform/diagnostics`),refetchInterval:5e3}),a=Mt({queryKey:[`platform-runtime`],queryFn:()=>nn(`/api/platform/runtime`),refetchInterval:5e3});async function o(){if(!e){t(!0),r(null);try{let e=await cn(`diagnostics-create`,`/api/platform/diagnostics`,{});Yt.setQueryData([`platform-diagnostics`],e),await Yt.invalidateQueries({queryKey:[`fleet`]})}catch(e){r(e)}finally{t(!1)}}}return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Rm,{title:`Diagnostics`,description:`Check runtime health and create test DSPs.`}),(0,S.jsx)(Hm,{error:n||i.error||a.error}),a.data?.enabled&&(0,S.jsxs)(`section`,{"aria-label":`Runtime health`,className:`rounded-xl border bg-card p-6 mb-6 space-y-3`,children:[(0,S.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Runtime health`}),(0,S.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Available storage: `,((a.data.storageAvailableBytes??0)/1024**3).toFixed(1),` GiB`]}),a.data.runtimes.map(e=>(0,S.jsxs)(`div`,{className:`flex flex-wrap justify-between gap-2 border-t pt-3 text-sm`,children:[(0,S.jsx)(`span`,{children:e.name}),(0,S.jsxs)(`span`,{children:[e.status,` · `,e.memoryBytes===null?`—`:`${Math.round(e.memoryBytes/1024**2)} MiB`,` · `,e.tasks??0,` tasks`,e.storage?.limited?` · ${((e.storage.availableBytes??0)/1024**3).toFixed(1)} GiB storage free`:e.storage?.limited===!1?` · Storage limit pending migration`:` · Storage unavailable`]})]},e.reference)),!a.data.runtimes.length&&(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No DSP runtimes yet.`})]}),i.isPending?(0,S.jsx)(Um,{}):i.data?(0,S.jsxs)(`div`,{className:`space-y-6`,children:[(0,S.jsxs)(`section`,{className:`rounded-xl border bg-card p-6 space-y-4`,"aria-labelledby":`test-dsp-title`,children:[(0,S.jsx)(`h2`,{id:`test-dsp-title`,className:`text-lg font-semibold`,children:`Test DSP`}),(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Deploy a DSP with synthetic employees and timecards. It stays available until you delete it from DSPs. Provider collection stays stopped, and no invitation email is sent.`}),(0,S.jsxs)($,{onClick:o,disabled:e||!i.data.enabled,children:[(0,S.jsx)(jn,{"aria-hidden":`true`}),e?`Requesting test DSP…`:`Deploy test DSP`]}),i.data.enabled?null:(0,S.jsx)(Vm,{children:`Test DSP deployment is unavailable on this installation.`})]}),(0,S.jsx)(`section`,{"aria-label":`Test DSP deployments`,className:`space-y-3`,"aria-live":`polite`,children:i.data.dsps.map(e=>(0,S.jsxs)(`div`,{className:`rounded-xl border p-4`,children:[(0,S.jsx)(`h3`,{className:`font-medium`,children:e.name}),(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.status===`pending`?`Creating DSP and preparing synthetic data…`:e.status===`failed`?`Setup needs attention. Open DSPs to inspect or delete this test DSP.`:`Synthetic data prepared · ${e.installation.state===`ready`?`Available`:e.installation.state}`})]},e.name))}),(0,S.jsx)(`a`,{href:`#/platform`,className:`text-sm underline`,children:`Manage test DSPs in DSPs`})]}):null]})}function og({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`card`,className:H(`flex flex-col gap-6 rounded-xl border bg-card py-6 text-card-foreground shadow-sm`,e),...t})}function sg({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`card-header`,className:H(`@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6`,e),...t})}function cg({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`card-title`,className:H(`leading-none font-semibold`,e),...t})}function lg({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`card-description`,className:H(`text-sm text-muted-foreground`,e),...t})}function ug({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`card-content`,className:H(`px-6`,e),...t})}function dg({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`card-footer`,className:H(`flex items-center px-6 [.border-t]:pt-6`,e),...t})}var fg={not_connected:`Not connected`,not_verified:`Not verified`,checking:`Checking connection`,connected:`Connected`,verification_required:`Verification required`,credentials_rejected:`Credentials rejected`,temporarily_unavailable:`Temporarily unavailable`};function pg(e){if(e.state===`checking`){if(e.assistance)return`Completing CAPTCHA`;if(e.check?.phase===`checking_session`)return`Checking session`;if(e.check?.phase===`signing_in`)return`Signing in`}return fg[e.state]}function mg(e){return e.assistance?.phase===`queued`?`Paycom requested a CAPTCHA. Waiting for automatic verification to start.`:e.assistance?.phase===`solving`?`Completing Paycom’s CAPTCHA automatically. You can leave this page while verification finishes.`:e.assistance?.phase===`verifying`?`Checking Paycom’s response before continuing.`:e.check?.phase===`checking_session`?`Checking whether your saved Paycom session is still signed in.`:e.check?.phase===`signing_in`?`Signing in to Paycom with your saved credentials and security answers.`:e.reason===`verification_code_rejected`?`Amazon didn’t accept that code. Enter the newest code from your email.`:e.reason===`verification_expired`?`This verification attempt ended. Test the connection to start a new sign-in.`:e.verification&&e.state!==`checking`?`Amazon sent you an email verification code. Enter it below to finish signing in.`:e.reason===`attempt_cooldown`?`The service needs a pause before another login attempt. Retry after the time shown below.`:e.service===`paycom`&&e.reason===`captcha_required`?`Paycom requires a CAPTCHA before sign-in can finish. Contact your Dispatch administrator to complete verification. Connection tests will remain blocked until it is resolved.`:e.service===`paycom`&&e.reason===`security_answers_rejected`?`Paycom rejected the security-answer step. Contact your Dispatch administrator to verify the saved numbered PINs and complete sign-in.`:e.state===`verification_required`?`The service needs human verification. Contact your Dispatch administrator to complete it, then test the connection again.`:e.state===`credentials_rejected`?`The service rejected the saved login. Check your account details and update the credentials.`:e.state===`temporarily_unavailable`?`We couldn’t verify this connection. Your credentials remain saved. Try testing it again shortly.`:e.state===`checking`?`Verifying your login. You can leave this page while the check finishes.`:e.state===`not_verified`?`Credentials are saved. Test the connection to verify access.`:e.state===`connected`?`Signed in successfully. Your DSP’s connection is saved securely.`:`Connect once to make this service available to your DSP’s features.`}function hg({verification:e,busy:t,onVerify:n}){let{timeZone:r}=rh();async function i(t){t.preventDefault();let r=t.currentTarget,i={code:String(new FormData(r).get(`code`)||``).trim(),verificationId:e.id};r.reset();try{await n(i)}finally{i.code=``}}return(0,S.jsxs)(`form`,{onSubmit:i,className:`flex flex-col gap-3`,"aria-label":`Cortex email verification`,children:[(0,S.jsx)(Bm,{label:`Email verification code`,name:`code`,type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,pattern:`[0-9]{6}`,minLength:6,maxLength:6,required:!0,disabled:t}),(0,S.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Enter the six-digit code. This prompt expires at`,` `,Nm(e.expiresAt,r),`.`]}),(0,S.jsx)(qm,{busy:t,disabled:t||e.attemptsRemaining===0,children:`Verify code`})]})}function gg(){let{timeZone:e}=rh(),{session:t}=gh(),n=dn(t),r=fn(t),i=Mt({queryKey:[`connections`,n?.organizationId],queryFn:({signal:e})=>nn(`/api/organization/connections`,{signal:e}),enabled:r,refetchInterval:e=>e.state.data?.items.some(e=>e.state===`checking`||e.state===`not_verified`||!!e.verification)?2e3:15e3}),[a,o]=(0,x.useState)(null),[s,c]=(0,x.useState)(null),[l,u]=(0,x.useState)(null),[d,f]=(0,x.useState)(null),[p,m]=(0,x.useState)(null),[h,g]=(0,x.useState)(!1),_=i.data?.items.find(e=>e.service===p),v=p&&_?`${i.data?.services.find(e=>e.id===p)?.name}: ${s===p?`Checking session`:pg(_)}.`:null;if(!r)return null;async function y(e,t,r){c(e.id),u(null),f(null),m(t===`test`?e.id:null),g(!1);try{let a=await rn(`/api/organization/connections/${e.id}/${t}`,`POST`,t===`save`?{credentials:r}:t===`verify`?r:{});t===`test`&&Yt.setQueryData([`connections`,n?.organizationId],t=>t&&{...t,items:t.items.map(t=>t.service===e.id?a:t)}),await Yt.invalidateQueries({queryKey:[`paycom-connection`,n?.organizationId]}),o(null),f(t===`verify`?null:t===`disconnect`?`${e.name} disconnected.`:t===`save`?`${e.name} credentials saved.`:null),await i.refetch()}catch(e){u(e),m(null),t===`save`&&(!(e instanceof Jt)||!e.status||e.status>=500)&&(g(!0),await i.refetch())}finally{c(null)}}async function b(e){if(e.preventDefault(),!a)return;let t=e.currentTarget,n=Object.fromEntries(new FormData(t));t.reset(),await y(a.service,`save`,n);for(let e of Object.keys(n))n[e]=``}return(0,S.jsxs)(`section`,{className:`flex flex-col gap-6 py-6`,"aria-labelledby":`connections-heading`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h2`,{id:`connections-heading`,className:`text-lg font-semibold`,children:`Connections`}),(0,S.jsx)(`p`,{className:`text-muted-foreground`,children:`Connect the services your DSP uses. All supported features share these connections.`})]}),!a&&(0,S.jsx)(Hm,{error:l||i.error}),d&&(0,S.jsx)(Vm,{children:d}),v&&(0,S.jsx)(`div`,{role:`status`,children:(0,S.jsx)(Vm,{error:!!_&&![`checking`,`connected`].includes(_.state),children:v})}),i.isPending?(0,S.jsx)(Um,{}):i.data?(0,S.jsx)(`div`,{className:`grid gap-6 lg:grid-cols-2`,children:i.data.services.map(t=>{let n=i.data.items.find(e=>e.service===t.id);if(!n)return null;let r=n.state===`checking`,a=s!==null||r;return(0,S.jsxs)(og,{children:[(0,S.jsxs)(sg,{children:[(0,S.jsxs)(cg,{className:`flex items-center gap-3`,children:[(0,S.jsx)(Rn,{className:`size-5`,"aria-hidden":`true`}),t.name]}),(0,S.jsx)(lg,{children:t.id===`cortex`?`Amazon Logistics dashboard`:`Workforce and timecards`})]}),(0,S.jsxs)(ug,{className:`flex flex-col gap-4`,children:[(0,S.jsx)(`div`,{role:`status`,children:(0,S.jsx)(vh,{variant:n.state===`connected`?`default`:`secondary`,children:pg(n)})}),(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:mg(n)}),n.verification&&(0,S.jsx)(hg,{verification:n.verification,busy:a,onVerify:e=>y(t,`verify`,e)},n.verification.id),n.checkedAt&&(0,S.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Last checked: `,Nm(n.checkedAt,e)]}),n.retryAt&&(0,S.jsxs)(`p`,{className:`text-sm`,children:[`Retry after `,Nm(n.retryAt,e)]})]}),(0,S.jsxs)(dg,{className:`mt-auto flex flex-wrap gap-2`,children:[(0,S.jsx)($,{disabled:a,onClick:()=>{u(null),g(!1),o({service:t,action:`save`})},children:n.configured?`Update credentials`:`Connect ${t.name}`}),n.configured&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)($,{variant:`outline`,disabled:a||!!n.verification||t.id!==`paycom`&&!!n.retryAt&&Date.parse(n.retryAt)>Date.now(),onClick:()=>void y(t,`test`),children:[(0,S.jsx)(Vn,{className:`size-4`,"aria-hidden":`true`}),`Test connection`]}),(0,S.jsx)($,{variant:`ghost`,disabled:a,onClick:()=>{u(null),o({service:t,action:`disconnect`})},children:`Disconnect`})]})]})]},t.id)})}):(0,S.jsx)($,{variant:`outline`,onClick:()=>void i.refetch(),children:`Retry loading connections`}),(0,S.jsxs)(`p`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,S.jsx)(Gn,{className:`size-4 shrink-0`,"aria-hidden":`true`}),`DSP owners and platform owners can manage these credentials.`]}),(0,S.jsx)(mm,{open:a!==null,onOpenChange:e=>{!e&&!s&&(o(null),u(null))},children:(0,S.jsxs)(_m,{className:`max-h-[90dvh] overflow-y-auto`,children:[(0,S.jsxs)(vm,{children:[(0,S.jsx)(bm,{children:a?.action===`disconnect`?`Disconnect ${a.service.name}?`:`${a?.service.name||`Service`} credentials`}),(0,S.jsx)(xm,{children:a?.action===`disconnect`?`Features will lose access to this service until you reconnect. Previously collected data will remain available.`:`Enter the account your DSP uses. Saved credentials are encrypted and are never displayed here.`})]}),a?.action===`save`?(0,S.jsx)(`form`,{onSubmit:b,children:(0,S.jsxs)(tm,{children:[a.service.fields.map(e=>(0,S.jsx)(Bm,{name:e.name,label:e.label,type:e.name===`password`||e.name.startsWith(`pin`)?`password`:`text`,autoComplete:e.name===`username`?`username`:`off`,maxLength:e.maximum,required:!0,disabled:s!==null},e.name)),a.service.id===`paycom`&&(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Enter all five distinct security answers in the order configured for your Paycom account.`}),(0,S.jsx)(Hm,{error:l}),h&&(0,S.jsx)(Vm,{children:`We couldn’t confirm this save. Your credentials may already be stored. Close this form to check the connection before retrying.`}),(0,S.jsxs)(ym,{children:[(0,S.jsx)($,{type:`button`,variant:`outline`,disabled:s!==null,onClick:()=>o(null),children:`Cancel`}),(0,S.jsx)(qm,{busy:s!==null,disabled:s!==null,children:`Save and connect`})]})]})},a.service.id):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Hm,{error:l}),(0,S.jsxs)(ym,{children:[(0,S.jsx)($,{variant:`outline`,disabled:s!==null,onClick:()=>o(null),children:`Cancel`}),(0,S.jsx)($,{variant:`destructive`,disabled:s!==null,onClick:()=>a&&void y(a.service,`disconnect`),children:`Disconnect`})]})]})]})})]})}function _g(){let{session:e}=gh(),{timeZone:t}=rh(),n=dn(e),r=n?.organization.status===`suspended`,i=Mt({queryKey:[`organization-audit`,n?.organizationId],queryFn:({signal:e})=>nn(`/api/organization/audit`,{signal:e}),enabled:ln(n,`audit.read`)&&!r,refetchInterval:15e3});return r?(0,S.jsx)(Vm,{children:`This DSP is suspended. The audit log is unavailable.`}):ln(n,`audit.read`)?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`table-toolbar`,children:[(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Recent changes to your DSP, team, and access.`}),(0,S.jsx)(Gm,{onClick:()=>void i.refetch(),busy:i.isFetching})]}),(0,S.jsx)(Hm,{error:i.error}),i.isPending?(0,S.jsx)(Um,{}):i.data&&!i.error?i.data.audit.length?(0,S.jsxs)(yh,{children:[(0,S.jsx)(bh,{children:(0,S.jsxs)(Sh,{children:[(0,S.jsx)(Ch,{children:`Action`}),(0,S.jsx)(Ch,{children:`By`}),(0,S.jsx)(Ch,{children:`Date`}),(0,S.jsx)(Ch,{children:`Result`})]})}),(0,S.jsx)(xh,{children:i.data.audit.map((e,n)=>(0,S.jsxs)(Sh,{children:[(0,S.jsx)(wh,{children:e.action.replaceAll(`.`,` `)}),(0,S.jsx)(wh,{children:e.actor}),(0,S.jsx)(wh,{children:Nm(e.createdAt,t)}),(0,S.jsx)(wh,{children:(0,S.jsx)(Jm,{value:e.result,children:e.result})})]},e.id||n))})]}):(0,S.jsx)(Wm,{title:`No audit events yet`,description:`Changes to your DSP will appear here.`}):null]}):null}var vg=[{value:`light`,label:`Light`,description:`A bright, clean workspace.`},{value:`dark`,label:`Dark`,description:`A calm, low-light workspace.`},{value:`system`,label:`System`,description:`Match your device settings.`}];function yg({mode:e}){let{themePack:t}=$p();return(0,S.jsxs)(`span`,{className:`theme-preview-ui theme-preview-scope`,"data-theme":e,"data-theme-pack":t.id,children:[(0,S.jsxs)(`span`,{className:`theme-preview-sidebar`,children:[(0,S.jsx)(`i`,{}),(0,S.jsx)(`i`,{}),(0,S.jsx)(`i`,{}),(0,S.jsx)(`i`,{})]}),(0,S.jsxs)(`span`,{className:`theme-preview-content`,children:[(0,S.jsx)(`span`,{className:`theme-preview-heading`}),(0,S.jsx)(`span`,{className:`theme-preview-subheading`}),(0,S.jsx)(`span`,{className:`theme-preview-table`,children:[0,1,2].map(e=>(0,S.jsxs)(`span`,{children:[(0,S.jsx)(`i`,{}),(0,S.jsx)(`i`,{}),(0,S.jsx)(`i`,{})]},e))})]})]})}function bg(){let{appearance:e,setAppearance:t,themePack:n,setThemePack:r,storageUnavailable:i}=$p();return(0,S.jsxs)(`section`,{className:`theme-section`,children:[(0,S.jsxs)(`div`,{className:`theme-pack-field`,children:[(0,S.jsx)(`label`,{htmlFor:`theme-pack`,children:`Theme`}),(0,S.jsx)(`select`,{id:`theme-pack`,value:n.id,onChange:e=>r(e.target.value),"aria-describedby":`theme-pack-description`,children:Wp.map(e=>(0,S.jsx)(`option`,{value:e.id,children:e.name},e.id))}),(0,S.jsx)(`p`,{id:`theme-pack-description`,children:n.description})]}),(0,S.jsxs)(`fieldset`,{"aria-describedby":`theme-description theme-persistence`,children:[(0,S.jsx)(`legend`,{children:`Appearance`}),(0,S.jsx)(`p`,{id:`theme-description`,children:`Choose how Dispatch looks for you.`}),(0,S.jsx)(`div`,{className:`theme-options`,children:vg.map(({value:n,label:r,description:i})=>(0,S.jsxs)(`label`,{className:`theme-option`,children:[(0,S.jsx)(`input`,{type:`radio`,name:`theme`,value:n,checked:e===n,onChange:()=>t(n),"aria-label":r,"aria-describedby":`theme-${n}-description`}),(0,S.jsxs)(`span`,{className:`theme-preview theme-preview-${n}`,"aria-hidden":`true`,children:[(0,S.jsx)(yg,{mode:n===`dark`?`dark`:`light`}),n===`system`&&(0,S.jsx)(yg,{mode:`dark`})]}),(0,S.jsx)(`span`,{className:`theme-option-label`,children:r}),(0,S.jsx)(`span`,{id:`theme-${n}-description`,className:`theme-option-description`,children:i})]},n))}),(0,S.jsx)(`p`,{id:`theme-persistence`,className:`theme-persistence`,children:`Saved for your account on this browser. Other users keep their own theme.`}),i&&(0,S.jsx)(`p`,{role:`status`,className:`theme-storage-notice`,children:`Theme applied for this visit. Browser storage is unavailable, so it could not be saved.`})]})]})}var xg=typeof Intl.supportedValuesOf==`function`?Intl.supportedValuesOf(`timeZone`):[`America/Los_Angeles`,`America/Phoenix`,`America/Denver`,`America/Chicago`,`America/New_York`,`Europe/London`];function Sg(){let{timeZone:e,deviceZone:t,preference:n,setPreference:r,storageUnavailable:i}=rh(),a=[...new Set([`UTC`,t,n,...xg].filter(jm))].sort();return(0,S.jsxs)(`section`,{className:`settings-section`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h2`,{children:`Date & time`}),(0,S.jsx)(`p`,{children:`Choose how event times appear for you.`})]}),(0,S.jsxs)(`div`,{className:`theme-pack-field`,children:[(0,S.jsx)(`label`,{htmlFor:`display-timezone`,children:`Display timezone`}),(0,S.jsxs)(`select`,{id:`display-timezone`,value:n||`automatic`,onChange:e=>r(e.target.value===`automatic`?null:e.target.value),"aria-describedby":`display-timezone-description`,children:[(0,S.jsxs)(`option`,{value:`automatic`,children:[`Automatic — device timezone (`,t.replaceAll(`_`,` `),`)`]}),a.map(e=>(0,S.jsx)(`option`,{value:e,children:e.replaceAll(`_`,` `)},e))]}),(0,S.jsxs)(`p`,{id:`display-timezone-description`,children:[`Sync and activity times use `,e.replaceAll(`_`,` `),`. Timecards keep the DSP’s business timezone.`]}),(0,S.jsx)(`p`,{children:`Saved for your account on this browser.`}),i&&(0,S.jsx)(`p`,{role:`status`,children:`Applied for this visit. Browser storage is unavailable, so this preference could not be saved.`})]})]})}function Cg({onboarding:e=!1}){let{session:t,refresh:n}=gh(),r=e?t.memberships.find(e=>e.organizationId===t.activeOrganizationId)||null:dn(t),i=Mt({queryKey:[`profile`,r?.organizationId],queryFn:()=>nn(`/api/organization/profile`),enabled:ln(r,`organization.owner`)&&r?.organization.status!==`suspended`,refetchInterval:e=>e.state.data?.status===`submitted`&&2e3}),[a,o]=(0,x.useState)(!1),[s,c]=(0,x.useState)(null);if(!ln(r,`organization.owner`))return null;if(i.error)return(0,S.jsx)(Hm,{error:i.error});if(!i.data)return e?(0,S.jsx)(Um,{}):null;if(i.data.status===`complete`||i.data.status===`submitted`)return!e&&i.data.status===`complete`?null:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Vm,{children:i.data.status===`complete`?`Your DSP details are complete. You can continue to your workspace.`:`Your DSP details are saved. They’ll be applied when your workspace is ready.`}),e&&(0,S.jsx)($,{className:`mt-6`,onClick:()=>{location.hash=un(t)?`#/platform`:`#/settings`},children:`Continue to workspace`})]});async function l(e){e.preventDefault();let t=Object.fromEntries(new FormData(e.currentTarget));o(!0),c(null);try{await rn(`/api/organization/profile`,`POST`,t),await i.refetch(),await n()}catch(e){c(e)}finally{o(!1)}}return(0,S.jsxs)(`section`,{className:e?`onboarding-details`:`setup-section`,children:[!e&&(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h2`,{children:`Set up your DSP`}),(0,S.jsx)(`p`,{children:`Your workspace is being prepared. Add your DSP details to finish onboarding.`})]}),(0,S.jsx)(`form`,{onSubmit:l,children:(0,S.jsxs)(tm,{children:[(0,S.jsx)(Bm,{label:`DSP name`,name:`name`,minLength:2,maxLength:120,required:!0,disabled:a}),(0,S.jsx)(Bm,{label:`Abbreviation (optional)`,name:`abbreviation`,maxLength:16,disabled:a}),(0,S.jsx)(Bm,{label:`Station code`,name:`stationCode`,pattern:`[A-Za-z0-9]{3,8}`,maxLength:8,required:!0,disabled:a}),(0,S.jsx)(Bm,{label:`Business timezone`,name:`timezone`,defaultValue:Mm(),maxLength:64,required:!0,disabled:a}),(0,S.jsx)(Hm,{error:s}),(0,S.jsx)(qm,{busy:a,disabled:a,children:`Save DSP details`})]})})]})}function wg(){let{session:e,refresh:t}=gh(),n=()=>{let e=new URLSearchParams(location.hash.split(`?`)[1]).get(`tab`);return e===`theme`||e===`security`||e===`audit`||e===`connections`?e:`general`},[r,i]=(0,x.useState)(n);(0,x.useEffect)(()=>{let e=()=>i(n());return window.addEventListener(`hashchange`,e),()=>window.removeEventListener(`hashchange`,e)},[]);let a=un(e),o=dn(e),s=fn(e),c=!a&&ln(o,`audit.read`),[l,u]=(0,x.useState)(!1),[d,f]=(0,x.useState)(null),[p,m]=(0,x.useState)(!1);async function h(e){e.preventDefault();let n=e.currentTarget,r=Object.fromEntries(new FormData(n));u(!0),m(!1),f(null);try{await rn(`/api/auth/change-password`,`POST`,r),await t(),n.reset(),m(!0)}catch(e){f(e)}finally{u(!1)}}return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Rm,{title:`Settings`,description:a?`Your platform account and security.`:`Your account, workspace, and security.`}),(0,S.jsxs)(Fp,{value:r===`audit`&&!c||r===`connections`&&!s?`general`:r,onValueChange:e=>{i(e),history.replaceState({},``,`${location.pathname}${location.search}${location.hash.split(`?`)[0]}?tab=${e}`)},children:[(0,S.jsxs)(Lp,{variant:`line`,className:`page-tabs`,children:[(0,S.jsx)(Rp,{value:`general`,children:`General`}),(0,S.jsx)(Rp,{value:`security`,children:`Security`}),s&&(0,S.jsx)(Rp,{value:`connections`,children:`Connections`}),(0,S.jsx)(Rp,{value:`theme`,children:`Theme`}),c&&(0,S.jsx)(Rp,{value:`audit`,children:`Audit log`})]}),s&&(0,S.jsx)(zp,{value:`connections`,children:(0,S.jsx)(gg,{},o?.organizationId)}),(0,S.jsxs)(zp,{value:`general`,children:[(0,S.jsxs)(`section`,{className:`settings-section`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h2`,{children:`Account`}),(0,S.jsx)(`p`,{children:e.dspView?`You are signed in with your platform account.`:`Your Dispatch sign-in details.`})]}),(0,S.jsxs)(`dl`,{className:`detail-list`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`Name`}),(0,S.jsx)(`dd`,{children:e.user.name})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`Email address`}),(0,S.jsx)(`dd`,{children:e.user.email})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`Role`}),(0,S.jsx)(`dd`,{children:a||e.dspView?`Platform owner`:o?.roleName||`No DSP access`})]})]})]}),(0,S.jsx)(Sg,{}),!a&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`section`,{className:`settings-section`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h2`,{children:`Workspace`}),(0,S.jsx)(`p`,{children:`Your current DSP context.`})]}),(0,S.jsxs)(`dl`,{className:`detail-list`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`DSP`}),(0,S.jsx)(`dd`,{children:o?.organization.name||`No DSP selected`})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`Station`}),(0,S.jsx)(`dd`,{children:o?.organization.stations.map(e=>e.code).join(`, `)||`—`})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`Business timezone`}),(0,S.jsx)(`dd`,{children:o?.organization.timezone||`—`})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`Status`}),(0,S.jsx)(`dd`,{children:o?.organization.status.replaceAll(`_`,` `)||`Unavailable`})]})]})]}),(0,S.jsx)(Cg,{})]})]}),c&&(0,S.jsx)(zp,{value:`audit`,children:(0,S.jsx)(_g,{})}),(0,S.jsx)(zp,{value:`theme`,children:(0,S.jsx)(bg,{})}),(0,S.jsx)(zp,{value:`security`,children:(0,S.jsxs)(`section`,{className:`settings-section`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h2`,{children:`Change password`}),(0,S.jsx)(`p`,{children:`Changing your password signs out every other session.`})]}),(0,S.jsx)(`form`,{onSubmit:h,className:`max-w-md`,children:(0,S.jsxs)(tm,{children:[(0,S.jsx)(Bm,{label:`Current password`,name:`currentPassword`,type:`password`,autoComplete:`current-password`,maxLength:128,required:!0,disabled:l}),(0,S.jsx)(Bm,{label:`New password`,name:`newPassword`,type:`password`,autoComplete:`new-password`,minLength:12,maxLength:128,required:!0,disabled:l,description:`Use at least 12 characters.`}),(0,S.jsx)(Bm,{label:`Confirm new password`,name:`confirmPassword`,type:`password`,autoComplete:`new-password`,minLength:12,maxLength:128,required:!0,disabled:l}),(0,S.jsx)(Hm,{error:d}),p&&(0,S.jsx)(Vm,{children:`Password changed. Other sessions have been signed out.`}),(0,S.jsx)(`div`,{children:(0,S.jsx)(qm,{busy:l,disabled:l,children:`Change password`})})]})})]})})]})]})}function Tg(){return(0,x.useEffect)(()=>{document.title=`Set up your DSP · Dispatch`},[]),(0,S.jsxs)(`main`,{className:`auth-layout`,children:[(0,S.jsx)(`div`,{className:`auth-brand`,children:(0,S.jsx)(lh,{})}),(0,S.jsxs)(`section`,{className:`auth-panel`,children:[(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground mb-3`,children:`Step 2 of 2 · DSP details`}),(0,S.jsx)(`h1`,{children:`Set up your DSP`}),(0,S.jsx)(`p`,{className:`auth-description`,children:`Your account is ready. Add your DSP details while we prepare your workspace.`}),(0,S.jsx)(Cg,{onboarding:!0})]})]})}function Eg(e,t){let n=e.find(e=>e.available&&e.pages.some(e=>e.id===t));return n?Rh(n.id,n.version,n.revision,t):void 0}function Dg(e,t){let n=dn(t);return e.filter(e=>e.available).flatMap(e=>e.pages).filter(e=>ln(n,e.permission))}function Og(e){let t=un(e),n=dn(e);return Mt({queryKey:[`plugins`,t?`platform`:n?.organizationId],queryFn:({signal:e})=>nn(t?`/api/platform/plugins`:`/api/organization/plugins`,{signal:e}),initialData:!t&&e.plugins?{items:e.plugins}:void 0,enabled:e.authenticated&&(t||!!n&&ln(n,`dashboard.view`)),refetchInterval:e=>e.state.data?.items.some(e=>e.pending)?2e3:15e3})}function kg(){let{session:e,refresh:t}=gh(),n=un(e),r=fn(e),i=Og(e),[a,o]=(0,x.useState)(null),[s,c]=(0,x.useState)(null),[l,u]=(0,x.useState)(null);async function d(n,r){o(n.id),c(null);try{await cn(`plugin:${n.id}:${r}:${n.revision}`,`/api/organization/plugins/${n.id}`,{action:r,expectedRevision:n.revision}),u(null),await i.refetch(),await Yt.invalidateQueries({queryKey:[`connections`,dn(e)?.organizationId]}),await t()}catch(e){c(e)}finally{o(null)}}return(0,S.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,S.jsx)(Rm,{title:`Plugins`,description:n?`Available plugins that DSP owners can install for their workspace.`:`Choose the features your DSP uses. Your saved data stays with your DSP.`}),(0,S.jsx)(Hm,{error:s||i.error}),i.isPending?(0,S.jsx)(Um,{}):(0,S.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:i.data?.items.map(e=>(0,S.jsxs)(og,{children:[(0,S.jsxs)(sg,{children:[(0,S.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,S.jsx)(Bn,{"aria-hidden":`true`,className:`size-5 text-muted-foreground`}),!n&&(0,S.jsx)(vh,{variant:`secondary`,children:e.pending?`Applying changes`:e.state===`enabled`?`Installed`:e.state===`disabled`?`Disabled`:`Not installed`})]}),(0,S.jsx)(cg,{children:e.name}),(0,S.jsx)(lg,{children:e.description})]}),(0,S.jsx)(ug,{children:e.failureCode?(0,S.jsx)(Vm,{error:!0,children:`We couldn’t finish applying this change. Dispatch will retry when your DSP is available.`}):e.pending?(0,S.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:`Updating this plugin for your DSP…`}):!n&&e.state===`disabled`?(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Its pages and background work are stopped. Your saved data and credentials are retained.`}):null}),!n&&r&&(0,S.jsx)(dg,{className:`flex flex-wrap gap-2`,children:e.state===`uninstalled`?(0,S.jsxs)($,{disabled:!!a||e.pending,onClick:()=>void d(e,`install`),children:[`Install `,e.name]}):(0,S.jsxs)(S.Fragment,{children:[e.available&&e.pages[0]&&(0,S.jsx)($,{asChild:!0,children:(0,S.jsxs)(`a`,{href:`#/${e.pages[0].id}`,children:[`Open `,e.name]})}),e.available&&e.hasSettings&&e.pages[0]&&(0,S.jsx)($,{asChild:!0,variant:`outline`,children:(0,S.jsx)(`a`,{href:`#/${e.pages[0].id}?settings`,children:`Settings`})}),(0,S.jsx)($,{variant:`outline`,disabled:!!a||e.pending,onClick:()=>void d(e,e.state===`disabled`?`enable`:`disable`),children:e.state===`disabled`?`Enable`:`Disable`}),(0,S.jsx)($,{variant:`ghost`,disabled:!!a||e.pending,onClick:()=>u(e),children:`Uninstall`})]})})]},e.id))}),(0,S.jsx)(mm,{open:!!l,onOpenChange:e=>{!e&&!a&&u(null)},children:(0,S.jsxs)(_m,{children:[(0,S.jsxs)(vm,{children:[(0,S.jsxs)(bm,{children:[`Uninstall `,l?.name,`?`]}),(0,S.jsx)(xm,{children:`Its pages and background work will stop. Your collected data and saved credentials will stay with this DSP so you can reinstall it later.`})]}),(0,S.jsxs)(ym,{children:[(0,S.jsx)($,{variant:`outline`,disabled:!!a,onClick:()=>u(null),children:`Cancel`}),(0,S.jsx)($,{disabled:!!a,onClick:()=>l&&void d(l,`uninstall`),children:`Uninstall plugin`})]})]})})]})}function Ag({className:e,size:t=`default`,...n}){return(0,S.jsxs)(`div`,{className:`group/native-select relative w-fit has-[select:disabled]:opacity-50`,"data-slot":`native-select-wrapper`,children:[(0,S.jsx)(`select`,{"data-slot":`native-select`,"data-size":t,className:H(`h-9 w-full min-w-0 appearance-none rounded-md border border-input bg-transparent px-3 py-2 pr-9 text-sm shadow-xs transition-[color,box-shadow] outline-none selection:bg-primary selection:text-primary-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed data-[size=sm]:h-8 data-[size=sm]:py-1 dark:bg-input/30 dark:hover:bg-input/50`,`focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50`,`aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40`,e),...n}),(0,S.jsx)(En,{className:`pointer-events-none absolute top-1/2 right-3.5 size-4 -translate-y-1/2 text-muted-foreground opacity-50 select-none`,"aria-hidden":`true`,"data-slot":`native-select-icon`})]})}function jg({className:e,...t}){return(0,S.jsx)(`option`,{"data-slot":`native-select-option`,className:H(`bg-[Canvas] text-[CanvasText]`,e),...t})}function Mg(){let{session:e}=gh(),{timeZone:t}=rh(),n=dn(e),r=n?.organization.status===`suspended`,i=Mt({queryKey:[`team`,n?.organizationId],queryFn:({signal:e})=>nn(`/api/organization/administration`,{signal:e}),enabled:!r,refetchInterval:15e3}),[a,o]=(0,x.useState)(`members`),[s,c]=(0,x.useState)(``),[l,u]=(0,x.useState)(null),[d,f]=(0,x.useState)(!1),[p,m]=(0,x.useState)(null),[h,g]=(0,x.useState)(null),[_,v]=(0,x.useState)(null),y=i.data,b=y?.roles.filter(e=>e.permissions.every(e=>n?.permissions.includes(e)))||[],C=y?.members.filter(e=>`${e.user.name} ${e.user.email}`.toLowerCase().includes(s.toLowerCase()))||[];function w(e){m(null),u(e)}async function T(e){if(e.preventDefault(),!l)return;f(!0),m(null);let t=new FormData(e.currentTarget);try{l.kind===`invite`?g(await rn(`/api/organization/invitations`,`POST`,{email:t.get(`email`),roleId:t.get(`roleId`)})):l.kind===`member`&&await rn(`/api/organization/members/${l.member.id}/role`,`PUT`,{roleId:t.get(`roleId`)}),u(null),await i.refetch()}catch(e){m(e)}finally{f(!1)}}let E=y?.invitations.filter(e=>e.status===`pending`)||[];return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Rm,{title:`Team & Roles`,description:`Manage your team and their access.`,children:!r&&ln(n,`members.invite`)&&(0,S.jsxs)($,{onClick:()=>w({kind:`invite`}),children:[(0,S.jsx)(zn,{"data-icon":`inline-start`}),`Invite member`]})}),r?(0,S.jsx)(Vm,{children:`This DSP is suspended. Team administration is unavailable.`}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Cg,{}),(0,S.jsx)(Zm,{result:h}),(0,S.jsx)(Hm,{error:i.error}),i.isPending?(0,S.jsx)(Um,{}):y&&!i.error?(0,S.jsxs)(Fp,{value:a,onValueChange:o,children:[(0,S.jsxs)(Lp,{variant:`line`,className:`page-tabs`,children:[(0,S.jsx)(Rp,{value:`members`,children:`Members`}),(0,S.jsx)(Rp,{value:`roles`,children:`Roles`}),(0,S.jsxs)(Rp,{value:`invitations`,children:[`Invitations`,E.length>0&&(0,S.jsx)(`span`,{className:`tab-count`,children:E.length})]})]}),(0,S.jsxs)(zp,{value:`members`,children:[(0,S.jsxs)(`div`,{className:`table-toolbar`,children:[(0,S.jsx)(Km,{value:s,onChange:c,placeholder:`Search members`}),(0,S.jsx)(Gm,{onClick:()=>void i.refetch(),busy:i.isFetching})]}),(0,S.jsxs)(yh,{children:[(0,S.jsx)(bh,{children:(0,S.jsxs)(Sh,{children:[(0,S.jsx)(Ch,{className:`w-[45%]`,children:`Member`}),(0,S.jsx)(Ch,{children:`Role`}),(0,S.jsx)(Ch,{children:`Access`}),(0,S.jsx)(Ch,{children:(0,S.jsx)(`span`,{className:`sr-only`,children:`Actions`})})]})}),(0,S.jsx)(xh,{children:C.map(t=>(0,S.jsxs)(Sh,{children:[(0,S.jsx)(wh,{children:(0,S.jsxs)(`div`,{className:`member-identity`,children:[(0,S.jsx)(`span`,{className:`avatar`,children:t.user.name.split(/\s+/).map(e=>e[0]).slice(0,2).join(``)}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`strong`,{children:t.user.name}),(0,S.jsx)(`span`,{children:t.user.email})]})]})}),(0,S.jsx)(wh,{children:t.role.name}),(0,S.jsx)(wh,{children:(0,S.jsx)(Jm,{value:`active`,children:`Active`})}),(0,S.jsx)(wh,{className:`text-right`,children:t.user.id!==e.user.id&&ln(n,`members.manage`)&&(0,S.jsxs)(Hh,{children:[(0,S.jsx)(Uh,{asChild:!0,children:(0,S.jsx)($,{size:`icon`,variant:`ghost`,"aria-label":`Actions for ${t.user.name}`,children:(0,S.jsx)(kn,{})})}),(0,S.jsx)(Wh,{align:`end`,children:(0,S.jsxs)(Gh,{children:[(0,S.jsx)(Kh,{onSelect:()=>w({kind:`member`,member:t}),children:`Change role`}),(0,S.jsx)(Kh,{variant:`destructive`,onSelect:()=>v({title:`Remove member`,description:`Remove ${t.user.name} from ${y.organization.name}?`,path:`/api/organization/members/${t.id}`}),children:`Remove member`})]})})]})})]},t.id))})]}),!C.length&&(0,S.jsx)(Wm,{title:`No members found`,description:`Try a different name or email.`}),(0,S.jsxs)(`p`,{className:`table-count`,children:[C.length,` member`,C.length===1?``:`s`]})]}),(0,S.jsxs)(zp,{value:`roles`,children:[(0,S.jsx)(`div`,{className:`table-toolbar`,children:(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Standard roles for your DSP. All roles currently have the same permissions.`})}),(0,S.jsx)(`div`,{className:`role-list`,children:y.roles.map(e=>(0,S.jsx)(`section`,{className:`role-row`,children:(0,S.jsxs)(`div`,{children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,S.jsx)(`h2`,{children:e.name}),(0,S.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Standard role`})]}),(0,S.jsx)(`p`,{children:e.description})]})},e.id))})]}),(0,S.jsxs)(zp,{value:`invitations`,children:[(0,S.jsxs)(`div`,{className:`table-toolbar`,children:[(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Pending invitations to your DSP.`}),(0,S.jsx)(Gm,{onClick:()=>void i.refetch(),busy:i.isFetching})]}),(0,S.jsxs)(yh,{children:[(0,S.jsx)(bh,{children:(0,S.jsxs)(Sh,{children:[(0,S.jsx)(Ch,{children:`Email address`}),(0,S.jsx)(Ch,{children:`Role`}),(0,S.jsx)(Ch,{children:`Expires`}),(0,S.jsx)(Ch,{children:(0,S.jsx)(`span`,{className:`sr-only`,children:`Actions`})})]})}),(0,S.jsx)(xh,{children:E.map(e=>(0,S.jsxs)(Sh,{children:[(0,S.jsx)(wh,{children:e.email}),(0,S.jsx)(wh,{children:e.roleName}),(0,S.jsx)(wh,{children:Nm(e.expiresAt,t)}),(0,S.jsx)(wh,{className:`text-right`,children:ln(n,`members.invite`)&&(0,S.jsx)($,{variant:`ghost`,size:`sm`,"aria-label":`Revoke invitation for ${e.email}`,onClick:()=>v({title:`Revoke invitation`,description:`Revoke the invitation for ${e.email}?`,path:`/api/organization/invitations/${e.id}`}),children:`Revoke`})})]},e.id))})]}),!E.length&&(0,S.jsx)(Wm,{title:`No pending invitations`,description:`New invitations will appear here until they’re accepted.`})]})]}):null]}),(0,S.jsx)(Ym,{open:!!l,onClose:()=>u(null),title:l?.kind===`invite`?`Invite member`:`Change role`,description:l?.kind===`member`?`Update the role for ${l.member.user.name}.`:`Send an invitation to join your DSP.`,busy:d,children:l&&(0,S.jsxs)(`form`,{onSubmit:T,className:`panel-form`,children:[(0,S.jsxs)(tm,{children:[l.kind===`invite`&&(0,S.jsx)(Bm,{label:`Email address`,name:`email`,type:`email`,autoComplete:`off`,required:!0,disabled:d}),` `,(0,S.jsxs)(rm,{children:[(0,S.jsx)(im,{htmlFor:`editor-role`,children:`Role`}),(0,S.jsx)(Ag,{id:`editor-role`,name:`roleId`,defaultValue:l.kind===`member`?l.member.role.id:b.find(e=>e.key===`driver`)?.id,disabled:d,required:!0,children:b.map(e=>(0,S.jsx)(jg,{value:e.id,children:e.name},e.id))})]}),(0,S.jsx)(Hm,{error:p})]}),(0,S.jsxs)(`div`,{className:`panel-footer`,children:[(0,S.jsx)($,{variant:`outline`,type:`button`,disabled:d,onClick:()=>u(null),children:`Cancel`}),(0,S.jsx)(qm,{busy:d,children:l.kind===`invite`?`Send invitation`:`Save role`})]})]},l.kind===`member`?l.member.id:`invite`)}),_&&(0,S.jsx)(Xm,{title:_.title,description:_.description,onClose:()=>v(null),onConfirm:async()=>{await rn(_.path,`DELETE`,{}),await i.refetch()}})]})}function Ng({session:e,refresh:t,token:n}){let[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(null),s=Mt({queryKey:[`invitation`,n],enabled:!!n&&!r,queryFn:()=>rn(`/api/auth/invitation/inspect`,`POST`,{token:n}),refetchOnWindowFocus:!1});(0,x.useEffect)(()=>{o(null)},[n]);let c=s.data,l=!!n,u=l&&!c?.accountExists,d=u?`register`:`login`,f=e?.turnstile?.siteKey,p=`${f}:${d}:${n||``}`,[m,h]=(0,x.useState)({scope:``,token:``}),[g,_]=(0,x.useState)(0),v=m.scope===p?m.token:``,y=(0,x.useCallback)(e=>{h({scope:p,token:e})},[p]),b=c?.kind===`organization_owner`;async function C(){await t(),history.replaceState({},``,`${location.pathname}${location.search}${b?`#/onboarding`:`#/team`}`),window.dispatchEvent(new HashChangeEvent(`hashchange`))}async function w(e){if(e.preventDefault(),r)return;if(f&&!v){o(`turnstile_required`);return}let a=new FormData(e.currentTarget),s=f?{turnstileToken:v}:{};i(!0),o(null);try{u?(await rn(`/api/auth/register`,`POST`,{token:n,...Object.fromEntries(a),...s}),await C()):(await rn(`/api/auth/login`,`POST`,{...Object.fromEntries(a),...s}),await t(),l&&(await rn(`/api/auth/accept-invitation`,`POST`,{token:n}),await C()))}catch(e){o(e),y(``),_(e=>e+1)}finally{i(!1)}}async function T(){i(!0),o(null);try{await rn(`/api/auth/accept-invitation`,`POST`,{token:n}),await C()}catch(e){o(e)}finally{i(!1)}}return(0,S.jsxs)(`main`,{className:`auth-layout`,children:[(0,S.jsx)(`div`,{className:`auth-brand`,children:(0,S.jsx)(lh,{})}),(0,S.jsxs)(`section`,{className:`auth-panel`,children:[l&&b&&(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground mb-3`,children:`Step 1 of 2 · Your account`}),(0,S.jsx)(`h1`,{children:l&&b?`Create your DSP`:l?c?.kind===`platform_owner`?`Join Dispatch`:`Join ${c?.organization?.name||`Dispatch`}`:`Sign in to Dispatch`}),(0,S.jsx)(`p`,{className:`auth-description`,children:l?c?`${c.email} · ${c.role?.name||`Platform owner`}`:`Checking your invitation…`:`Welcome back. Sign in to your workspace.`}),l&&c&&(0,S.jsx)(`p`,{className:`auth-description`,children:c.accountExists?`You already have a Dispatch account. Use it to continue`+(b?` setting up your new DSP.`:` with this invitation.`):b?`Create your account, then add your DSP details to finish setup.`:`Create your account to accept this invitation.`}),(0,S.jsx)(Hm,{error:a||s.error}),e?.bootstrap?.initialized===!1&&(0,S.jsx)(Vm,{children:`Platform setup required. Create the platform owner using the private access administration command.`}),l&&s.isPending?(0,S.jsx)(Um,{}):l&&!c?null:l&&c?.accountExists&&e?.authenticated?(0,S.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,S.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Signed in as `,e.user.email,`.`]}),(0,S.jsx)($,{disabled:r,onClick:T,children:b?`Continue to DSP setup`:`Accept invitation`}),(0,S.jsx)($,{variant:`outline`,disabled:r,onClick:async()=>{i(!0);try{await rn(`/api/auth/logout`,`POST`,{}),await t()}catch(e){o(e)}finally{i(!1)}},children:`Use another account`})]}):(0,S.jsx)(`form`,{onSubmit:w,children:(0,S.jsxs)(tm,{children:[u?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Bm,{label:`First name`,name:`firstName`,autoComplete:`given-name`,required:!0,maxLength:80,disabled:r}),(0,S.jsx)(Bm,{label:`Last name`,name:`lastName`,autoComplete:`family-name`,required:!0,maxLength:80,disabled:r})]}):(0,S.jsx)(Bm,{label:`Email address`,name:`email`,type:`email`,autoComplete:`username`,required:!0,maxLength:254,disabled:r}),(0,S.jsx)(Bm,{label:`Password`,name:`password`,type:`password`,autoComplete:u?`new-password`:`current-password`,minLength:u?12:void 0,maxLength:128,required:!0,disabled:r,description:u?`Use at least 12 characters.`:void 0}),!u&&(0,S.jsx)(`a`,{className:`text-sm text-primary underline-offset-4 hover:underline`,href:`#/forgot-password`,children:`Forgot password?`}),u&&(0,S.jsx)(Bm,{label:`Confirm password`,name:`confirmPassword`,type:`password`,autoComplete:`new-password`,required:!0,minLength:12,maxLength:128,disabled:r}),f&&(0,S.jsx)(fh,{siteKey:f,action:d,onToken:y,busy:r},`${p}:${g}`),(0,S.jsx)(qm,{busy:r,disabled:r||!(!f||v),children:u?b?`Create account and continue`:`Create account and accept`:l?`Sign in and continue`:`Sign in`})]})})]}),(0,S.jsx)(`p`,{className:`auth-footnote`,children:`Access is by invitation.`})]})}function Pg(e,t){if(un(e))return[{id:`platform`,label:`DSPs`,icon:wn},{id:`updates`,label:`Updates`,icon:Sn},{id:`backups`,label:`Backups`,icon:On},{id:`plugins`,label:`Plugins`,icon:Bn},{id:`diagnostics`,label:`Diagnostics`,icon:jn},{id:`platform-settings`,label:`Settings`,icon:Wn}];let n=dn(e),r=n?.organization.status===`active`;return[...r&&ln(n,`dashboard.view`)?[{id:`dashboard`,label:`Home Page`,icon:Mn}]:[],...r?Dg(t,e).map(e=>({id:e.id,label:e.label,icon:e.icon===`calendar`?Tn:Bn})):[],...r&&fn(e)?[{id:`plugins`,label:`Plugins`,icon:Bn}]:[],...ln(n,`members.read`)&&ln(n,`roles.read`)?[{id:`team`,label:`Team & Roles`,icon:Kn}]:[],{id:`settings`,label:`Settings`,icon:Wn}]}function Fg({session:e,refresh:t,hash:n,viewEnded:r}){let i=$p().themePack.components?.ShellLayout||mh,a=un(e),o=dn(e),s=Og(e).data?.items||[],c=Pg(e,s),l=n.replace(/^#\//,``).split(/[/?]/)[0],u=c.find(e=>e.id===l)||c[0],d=Eg(s,u.id),[f,p]=(0,x.useState)(!1),[m,h]=(0,x.useState)(null),[g,_]=(0,x.useState)(!1);async function v(){_(!0),h(null);try{$t(null),await t(),location.hash=`#/platform`}catch(e){h(e)}finally{_(!1)}}(0,x.useEffect)(()=>{l!==u.id&&(history.replaceState({},``,`${location.pathname}${location.search}#/${u.id}`),window.dispatchEvent(new HashChangeEvent(`hashchange`))),document.title=`${u.label} · Dispatch`,p(!1)},[l,u.id,u.label]);let y=(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`sidebar-brand`,children:[(0,S.jsx)(lh,{}),(0,S.jsx)(`p`,{children:a?`Platform`:o?.organization.name||`Workspace`})]}),(0,S.jsx)(`nav`,{className:`nav-list`,"aria-label":`Primary navigation`,children:c.map(({id:e,label:t,icon:n})=>(0,S.jsxs)(`a`,{href:`#/${e}`,"aria-current":e===u.id?`page`:void 0,className:`nav-item`,onClick:()=>p(!1),children:[(0,S.jsx)(n,{"aria-hidden":`true`}),(0,S.jsx)(`span`,{children:t})]},e))}),(0,S.jsx)(`div`,{className:`sidebar-account`,children:(0,S.jsxs)(Hh,{children:[(0,S.jsx)(Uh,{asChild:!0,children:(0,S.jsxs)(`button`,{className:`account-button`,children:[(0,S.jsxs)(`span`,{className:`avatar`,children:[e.user.firstName?.[0],e.user.lastName?.[0]]}),(0,S.jsxs)(`span`,{className:`account-copy`,children:[(0,S.jsx)(`strong`,{children:e.user.name}),(0,S.jsx)(`span`,{children:e.dspView?`Platform owner · Viewing DSP`:a?`Platform owner`:o?.roleName||`No DSP access`})]}),(0,S.jsx)(En,{"aria-hidden":`true`})]})}),(0,S.jsx)(Wh,{align:`start`,children:(0,S.jsxs)(Gh,{children:[(0,S.jsx)(Kh,{asChild:!0,children:(0,S.jsx)(`a`,{href:`#/${a?`platform-settings`:`settings`}`,children:`Account settings`})}),(0,S.jsxs)(Kh,{disabled:g,onSelect:async()=>{_(!0);try{await rn(`/api/auth/logout`,`POST`,{}),$t(null),tn(null),Yt.clear(),location.hash=``,await t()}catch(e){h(e)}finally{_(!1)}},children:[(0,S.jsx)(Pn,{}),`Sign out`]})]})})]})})]});return(0,S.jsxs)(hh.Provider,{value:{session:e,refresh:t},children:[(0,S.jsx)(`a`,{href:`#main-content`,className:`skip-link`,onClick:e=>{e.preventDefault(),document.getElementById(`main-content`)?.focus()},children:`Skip to content`}),(0,S.jsxs)(i,{navigation:y,mobileNavigation:(0,S.jsx)(sm,{open:f,onOpenChange:p,children:(0,S.jsxs)(um,{side:`left`,className:`mobile-sidebar`,children:[(0,S.jsx)(fm,{className:`sr-only`,children:`Navigation`}),(0,S.jsx)(pm,{className:`sr-only`,children:`Your Dispatch workspace pages.`}),y]})}),banner:e.dspView&&(0,S.jsxs)(`div`,{className:`dsp-view-banner`,role:`region`,"aria-label":`DSP viewing mode`,children:[(0,S.jsx)(An,{"aria-hidden":`true`}),(0,S.jsxs)(`div`,{children:[(0,S.jsxs)(`strong`,{children:[`Viewing `,o?.organization.name,` as DSP owner`]}),(0,S.jsx)(`span`,{children:`Full owner access. Changes are saved to this DSP.`})]}),(0,S.jsx)($,{variant:`outline`,disabled:g,onClick:()=>void v(),children:g?`Exiting…`:`Exit view`})]}),header:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)($,{className:`mobile-menu`,size:`icon`,variant:`ghost`,"aria-label":`Open navigation`,onClick:()=>p(!0),children:(0,S.jsx)(Fn,{})}),(0,S.jsxs)(`div`,{className:`breadcrumb`,children:[(0,S.jsx)(`span`,{children:a?`Platform`:o?.organization.name||`Workspace`}),(0,S.jsx)(`span`,{"aria-hidden":`true`,children:`/`}),(0,S.jsx)(`strong`,{children:u.label})]})]}),children:[r&&!e.dspView&&(0,S.jsx)(Vm,{children:`The DSP view expired or is no longer available. You’re back in the platform console.`}),(0,S.jsx)(Hm,{error:m}),u.id===`platform`?(0,S.jsx)(ig,{}):u.id===`diagnostics`?(0,S.jsx)(ag,{}):u.id===`updates`?(0,S.jsx)(ch,{hash:n}):u.id===`backups`?(0,S.jsx)(oh,{page:u.id,hash:n},u.id):u.id===`plugins`?(0,S.jsx)(kg,{}):d?(0,S.jsx)(zh,{children:(0,S.jsx)(d,{})},`${u.id}:${s.find(e=>e.pages.some(e=>e.id===u.id))?.revision}`):u.id===`team`?(0,S.jsx)(Mg,{}):u.id===`settings`||u.id===`platform-settings`?(0,S.jsx)(wg,{},u.id):(0,S.jsx)(Rm,{title:u.label})]}),(0,S.jsx)(Vh,{})]})}function Ig(){let[e,t]=(0,x.useState)(null),[n,r]=(0,x.useState)(!1),[i,a]=(0,x.useState)(null),[o,s]=(0,x.useState)(location.hash),[c,l]=(0,x.useState)(0),[u,d]=(0,x.useState)(!1),f=(0,x.useCallback)(async e=>{let n;try{n=e||await nn(`/api/auth/session`)}catch(e){if(!(e instanceof Jt)||e.code!==`dsp_view_unavailable`)throw e;d(!0),n=await nn(`/api/auth/session`)}(n.dspView||!n.authenticated)&&d(!1),n.authenticated||$t(null),tn(n),t(n),r(!0),a(null)},[]);(0,x.useEffect)(()=>{f().catch(e=>{a(e),r(!0)});let e=()=>{s(location.hash),l(e=>e+1)},n=()=>{tn(null),t(null)},i=()=>{d(!0),f().catch(a)};return window.addEventListener(`hashchange`,e),window.addEventListener(`dispatch-session-expired`,n),window.addEventListener(`dispatch-dsp-view-ended`,i),()=>{window.removeEventListener(`hashchange`,e),window.removeEventListener(`dispatch-session-expired`,n),window.removeEventListener(`dispatch-dsp-view-ended`,i)}},[f]),(0,x.useEffect)(()=>{if(!e?.authenticated)return;let t=()=>{f().catch(()=>{})};return window.addEventListener(`focus`,t),()=>window.removeEventListener(`focus`,t)},[e?.authenticated,f]),(0,x.useEffect)(()=>{if(!e?.dspView)return;let t=window.setTimeout(()=>void f().catch(a),Math.max(0,Date.parse(e.dspView.expiresAt)-Date.now())+100);return()=>window.clearTimeout(t)},[e?.dspView?.expiresAt,f]);function p(){if(!n)return(0,S.jsxs)(`div`,{className:`initial-loading`,children:[(0,S.jsx)(lh,{}),(0,S.jsx)(Um,{})]});if(i)return(0,S.jsxs)(`main`,{className:`initial-loading`,children:[(0,S.jsx)(lh,{}),(0,S.jsx)(Hm,{error:i}),(0,S.jsx)($,{onClick:()=>void f().catch(a),children:`Try again`})]});if(o===`#/forgot-password`||o===`#/reset-password`||o.startsWith(`#/reset-password/`))return(0,S.jsx)(ph,{hash:o,session:e,refresh:f},`${o}:${c}`);let t=/^#\/invitation\/([A-Za-z0-9_-]{43})$/.exec(o)?.[1]||null;return!e?.authenticated||t?(0,S.jsx)(Ng,{session:e,refresh:f,token:t}):!e.dspView&&o===`#/onboarding`&&e.memberships.some(t=>t.organizationId===e.activeOrganizationId&&t.organization.status!==`suspended`&&t.permissions.includes(`organization.owner`))?(0,S.jsx)(hh.Provider,{value:{session:e,refresh:f},children:(0,S.jsx)(Tg,{})}):(0,S.jsx)(Fg,{session:e,refresh:f,hash:o,viewEnded:u},`${e.user.id}:${e.dspView?.viewRef||e.activeOrganizationId||`platform`}`)}let m=e?.authenticated?e.user.id:null;return(0,S.jsx)(Qp,{userId:m,children:(0,S.jsx)(nh,{userId:m,children:p()})})}var Lg=document.querySelector(`meta[name=dispatch-style-nonce]`)?.content;Lg&&ss(Lg),(0,b.createRoot)(document.getElementById(`root`)).render((0,S.jsx)(T,{client:Yt,children:(0,S.jsx)(Ig,{})}))})(); \ No newline at end of file +`},Ws=0,Gs=[];function Ks(e){var t=x.useRef([]),n=x.useRef([0,0]),r=x.useRef(),i=x.useState(Ws++)[0],a=x.useState(ms)[0],o=x.useRef(e);x.useEffect(function(){o.current=e},[e]),x.useEffect(function(){if(e.inert){document.body.classList.add(`block-interactivity-${i}`);var t=Ho([e.lockRef.current],(e.shards||[]).map(Vs),!0).filter(Boolean);return t.forEach(function(e){return e.classList.add(`allow-interactivity-${i}`)}),function(){document.body.classList.remove(`block-interactivity-${i}`),t.forEach(function(e){return e.classList.remove(`allow-interactivity-${i}`)})}}},[e.inert,e.lockRef.current,e.shards]);var s=x.useCallback(function(e,t){if(`touches`in e&&e.touches.length===2||e.type===`wheel`&&e.ctrlKey)return!o.current.allowPinchZoom;var i=zs(e),a=n.current,s=`deltaX`in e?e.deltaX:a[0]-i[0],c=`deltaY`in e?e.deltaY:a[1]-i[1],l,u=e.target,d=Math.abs(s)>Math.abs(c)?`h`:`v`;if(`touches`in e&&d===`h`&&u.type===`range`)return!1;var f=window.getSelection(),p=f&&f.anchorNode;if(p&&(p===u||p.contains(u)))return!1;var m=Ms(d,u);if(!m)return!0;if(m?l=d:(l=d===`v`?`h`:`v`,m=Ms(d,u)),!m)return!1;if(!r.current&&`changedTouches`in e&&(s||c)&&(r.current=l),!l)return!0;var h=r.current||l;return Rs(h,t,e,h===`h`?s:c,!0)},[]),c=x.useCallback(function(e){var n=e;if(Gs.length&&Gs[Gs.length-1]===a){var r=`deltaY`in n?Bs(n):zs(n),i=t.current.filter(function(e){return e.name===n.type&&(e.target===n.target||n.target===e.shadowParent)&&Hs(e.delta,r)})[0];if(i&&i.should){n.cancelable&&n.preventDefault();return}if(!i){var c=(o.current.shards||[]).map(Vs).filter(Boolean).filter(function(e){return e.contains(n.target)});(c.length>0?s(n,c[0]):!o.current.noIsolation)&&n.cancelable&&n.preventDefault()}}},[]),l=x.useCallback(function(e,n,r,i){var a={name:e,delta:n,target:r,should:i,shadowParent:qs(r)};t.current.push(a),setTimeout(function(){t.current=t.current.filter(function(e){return e!==a})},1)},[]),u=x.useCallback(function(e){n.current=zs(e),r.current=void 0},[]),d=x.useCallback(function(t){l(t.type,Bs(t),t.target,s(t,e.lockRef.current))},[]),f=x.useCallback(function(t){l(t.type,zs(t),t.target,s(t,e.lockRef.current))},[]);x.useEffect(function(){return Gs.push(a),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:f}),document.addEventListener(`wheel`,c,Ds),document.addEventListener(`touchmove`,c,Ds),document.addEventListener(`touchstart`,u,Ds),function(){Gs=Gs.filter(function(e){return e!==a}),document.removeEventListener(`wheel`,c,Ds),document.removeEventListener(`touchmove`,c,Ds),document.removeEventListener(`touchstart`,u,Ds)}},[]);var p=e.removeScrollBar,m=e.inert;return x.createElement(x.Fragment,null,m?x.createElement(a,{styles:Us(i)}):null,p?x.createElement(ws,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function qs(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}var Js=ns(rs,Ks),Ys=x.forwardRef(function(e,t){return x.createElement(as,Bo({},e,{ref:t,sideCar:Js}))});Ys.classNames=as.classNames;var Xs=function(e){return typeof document>`u`?null:(Array.isArray(e)?e[0]:e).ownerDocument.body},Zs=new WeakMap,Qs=new WeakMap,$s={},ec=0,tc=function(e){return e&&(e.host||tc(e.parentNode))},nc=function(e,t){return t.map(function(t){if(e.contains(t))return t;var n=tc(t);return n&&e.contains(n)?n:(console.error(`aria-hidden`,t,`in not contained inside`,e,`. Doing nothing`),null)}).filter(function(e){return!!e})},rc=function(e,t,n,r){var i=nc(t,Array.isArray(e)?e:[e]);$s[n]||($s[n]=new WeakMap);var a=$s[n],o=[],s=new Set,c=new Set(i),l=function(e){e&&!s.has(e)&&(s.add(e),l(e.parentNode))};i.forEach(l);var u=function(e){e&&!c.has(e)&&Array.prototype.forEach.call(e.children,function(e){if(s.has(e))u(e);else try{var t=e.getAttribute(r),i=t!==null&&t!==`false`,c=(Zs.get(e)||0)+1,l=(a.get(e)||0)+1;Zs.set(e,c),a.set(e,l),o.push(e),c===1&&i&&Qs.set(e,!0),l===1&&e.setAttribute(n,`true`),i||e.setAttribute(r,`true`)}catch(t){console.error(`aria-hidden: cannot operate on `,e,t)}})};return u(t),s.clear(),ec++,function(){o.forEach(function(e){var t=Zs.get(e)-1,i=a.get(e)-1;Zs.set(e,t),a.set(e,i),t||(Qs.has(e)||e.removeAttribute(r),Qs.delete(e)),i||e.removeAttribute(n)}),ec--,ec||(Zs=new WeakMap,Zs=new WeakMap,Qs=new WeakMap,$s={})}},ic=function(e,t,n){n===void 0&&(n=`data-aria-hidden`);var r=Array.from(Array.isArray(e)?e:[e]),i=t||Xs(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll(`[aria-live], script`))),rc(r,i,n,`aria-hidden`)):function(){return null}},ac=Object.defineProperty,oc=(e,t)=>ac(e,`name`,{value:t,configurable:!0}),sc=`Dialog`,[cc,lc]=Zi(sc),[uc,dc]=cc(sc),fc=oc(e=>{let{__scopeDialog:t,children:n,open:r,defaultOpen:i,onOpenChange:a,modal:o=!0}=e,s=x.useRef(null),c=x.useRef(null),[l,u]=Oa({prop:r,defaultProp:i??!1,onChange:a,caller:sc}),[d,f]=x.useState(0),[p,m]=x.useState(0);return(0,S.jsx)(uc,{scope:t,triggerRef:s,contentRef:c,contentId:Ka(),titleId:Ka(),descriptionId:Ka(),titlePresent:d>0,descriptionPresent:p>0,setTitleCount:f,setDescriptionCount:m,open:l,onOpenChange:u,onOpenToggle:x.useCallback(()=>u(e=>!e),[u]),modal:o,children:n})},`Dialog`),pc=`DialogPortal`,[mc,hc]=cc(pc,{forceMount:void 0}),gc=oc(e=>{let{__scopeDialog:t,forceMount:n,children:r,container:i}=e,a=dc(pc,t);return(0,S.jsx)(mc,{scope:t,forceMount:n,children:x.Children.map(r,e=>(0,S.jsx)(Ia,{present:n||a.open,children:(0,S.jsx)(Mo,{asChild:!0,container:i,children:e})}))})},`DialogPortal`),_c=`DialogOverlay`,vc=x.forwardRef(oc(function(e,t){let n=hc(_c,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=dc(_c,e.__scopeDialog);return a.modal?(0,S.jsx)(Ia,{present:r||a.open,children:(0,S.jsx)(bc,{...i,ref:t})}):null},`DialogOverlay`)),yc=W(`DialogOverlay.RemoveScroll`),bc=x.forwardRef(oc(function(e,t){let{__scopeDialog:n,...r}=e,i=dc(_c,n),a=Oi(t,so());return(0,S.jsx)(Ys,{as:yc,allowPinchZoom:!0,shards:[i.contentRef],children:(0,S.jsx)(Ki.div,{"data-state":Mc(i.open),...r,ref:a,style:{pointerEvents:`auto`,...r.style}})})},`DialogOverlayImpl`)),xc=`DialogContent`,Sc=x.forwardRef(oc(function(e,t){let n=hc(xc,e.__scopeDialog),{forceMount:r=n.forceMount,...i}=e,a=dc(xc,e.__scopeDialog);return(0,S.jsx)(Ia,{present:r||a.open,children:a.modal?(0,S.jsx)(Cc,{...i,ref:t}):(0,S.jsx)(wc,{...i,ref:t})})},`DialogContent`)),Cc=x.forwardRef(oc(function(e,t){let n=dc(xc,e.__scopeDialog),r=x.useRef(null),i=Oi(t,n.contentRef,r);return x.useEffect(()=>{let e=r.current;if(e)return ic(e)},[]),(0,S.jsx)(Tc,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,onCloseAutoFocus:G(e.onCloseAutoFocus,e=>{e.preventDefault(),n.triggerRef.current?.focus()}),onPointerDownOutside:G(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0;(t.button===2||n)&&e.preventDefault()}),onFocusOutside:G(e.onFocusOutside,e=>e.preventDefault())})},`DialogContentModal`)),wc=x.forwardRef(oc(function(e,t){let n=dc(xc,e.__scopeDialog),r=x.useRef(!1),i=x.useRef(!1);return(0,S.jsx)(Tc,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),t.defaultPrevented||(r.current||n.triggerRef.current?.focus(),t.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||(r.current=!0,t.detail.originalEvent.type===`pointerdown`&&(i.current=!0));let a=t.target;n.triggerRef.current?.contains(a)&&t.preventDefault(),t.detail.originalEvent.type===`focusin`&&i.current&&t.preventDefault()}})},`DialogContentNonModal`)),Tc=x.forwardRef(oc(function(e,t){let{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:a,...o}=e,s=dc(xc,n);return Ro(),(0,S.jsx)(S.Fragment,{children:(0,S.jsx)(yo,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:a,children:(0,S.jsx)(K,{role:`dialog`,id:s.contentId,"aria-describedby":s.descriptionPresent?s.descriptionId:void 0,"aria-labelledby":s.titlePresent?s.titleId:void 0,"data-state":Mc(s.open),...o,ref:t,deferPointerDownOutside:!0,onDismiss:()=>s.onOpenChange(!1)})})})},`DialogContentImpl`)),Ec=`DialogTitle`,Dc=x.forwardRef(oc(function(e,t){let{__scopeDialog:n,...r}=e,i=dc(Ec,n),{setTitleCount:a}=i;return ya(()=>(a(e=>e+1),()=>a(e=>e-1)),[a]),(0,S.jsx)(Ki.h2,{id:i.titleId,...r,ref:t})},`DialogTitle`)),Oc=`DialogDescription`,kc=x.forwardRef(oc(function(e,t){let{__scopeDialog:n,...r}=e,i=dc(Oc,n),{setDescriptionCount:a}=i;return ya(()=>(a(e=>e+1),()=>a(e=>e-1)),[a]),(0,S.jsx)(Ki.p,{id:i.descriptionId,...r,ref:t})},`DialogDescription`)),Ac=`DialogClose`,jc=x.forwardRef(oc(function(e,t){let{__scopeDialog:n,...r}=e,i=dc(Ac,n);return(0,S.jsx)(Ki.button,{type:`button`,...r,ref:t,onClick:G(e.onClick,()=>i.onOpenChange(!1))})},`DialogClose`));function Mc(e){return e?`open`:`closed`}oc(Mc,`getState`);var Nc=Object.defineProperty,Pc=(e,t)=>Nc(e,`name`,{value:t,configurable:!0});function Fc(e){let[t,n]=x.useState(void 0);return ya(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});let t=new ResizeObserver(t=>{if(!Array.isArray(t)||!t.length)return;let r=t[0],i,a;if(`borderBoxSize`in r){let e=r.borderBoxSize,t=Array.isArray(e)?e[0]:e;i=t.inlineSize,a=t.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return t.observe(e,{box:`border-box`}),()=>t.unobserve(e)}n(void 0)},[e]),t}Pc(Fc,`useSize`);var Ic=[`top`,`right`,`bottom`,`left`],Lc=Math.min,Rc=Math.max,zc=Math.round,Bc=Math.floor,Vc=e=>({x:e,y:e}),Hc={left:`right`,right:`left`,bottom:`top`,top:`bottom`};function Uc(e,t,n){return Rc(e,Lc(t,n))}function Wc(e,t){return typeof e==`function`?e(t):e}function Gc(e){return e.split(`-`)[0]}function Kc(e){return e.split(`-`)[1]}function qc(e){return e===`x`?`y`:`x`}function Jc(e){return e===`y`?`height`:`width`}function Yc(e){let t=e[0];return t===`t`||t===`b`?`y`:`x`}function Xc(e){return qc(Yc(e))}function Zc(e,t,n){n===void 0&&(n=!1);let r=Kc(e),i=Xc(e),a=Jc(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=ol(o)),[o,ol(o)]}function Qc(e){let t=ol(e);return[$c(e),t,$c(t)]}function $c(e){return e.includes(`start`)?e.replace(`start`,`end`):e.replace(`end`,`start`)}var el=[`left`,`right`],tl=[`right`,`left`],nl=[`top`,`bottom`],rl=[`bottom`,`top`];function il(e,t,n){switch(e){case`top`:case`bottom`:return n?t?tl:el:t?el:tl;case`left`:case`right`:return t?nl:rl;default:return[]}}function al(e,t,n,r){let i=Kc(e),a=il(Gc(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map($c)))),a}function ol(e){let t=Gc(e);return Hc[t]+e.slice(t.length)}function sl(e){return{top:e.top??0,right:e.right??0,bottom:e.bottom??0,left:e.left??0}}function cl(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:sl(e)}function ll(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function ul(e,t,n){let{reference:r,floating:i}=e,a=Yc(t),o=Xc(t),s=Jc(o),c=Gc(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}let m=Kc(t);return m&&(p[o]+=f*(m===`end`?1:-1)*(n&&l?-1:1)),p}async function dl(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=Wc(t,e),p=cl(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=ll(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=ll(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}var fl=50,pl=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=o.detectOverflow?o:{...o,detectOverflow:dl},c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=ul(l,r,c),f=r,p=0,m={};for(let n=0;n({name:`arrow`,options:e,async fn(t){let{x:n,y:r,placement:i,rects:a,platform:o,elements:s,middlewareData:c}=t,{element:l,padding:u=0}=Wc(e,t)||{};if(l==null)return{};let d=cl(u),f={x:n,y:r},p=Xc(i),m=Jc(p),h=await o.getDimensions(l),g=p===`y`,_=g?`top`:`left`,v=g?`bottom`:`right`,y=g?`clientHeight`:`clientWidth`,b=a.reference[m]+a.reference[p]-f[p]-a.floating[m],x=f[p]-a.reference[p],S=await(o.getOffsetParent==null?void 0:o.getOffsetParent(l)),C=S?S[y]:0;(!C||!await(o.isElement==null?void 0:o.isElement(S)))&&(C=s.floating[y]||a.floating[m]);let w=b/2-x/2,T=C/2-h[m]/2-1,E=Lc(d[_],T),D=Lc(d[v],T),O=C-h[m]-D,ee=C/2-h[m]/2+w,k=Uc(E,ee,O),A=!c.arrow&&Kc(i)!=null&&ee!==k&&a.reference[m]/2-(eee<=0)){let e=(i.flip?.index||0)+1,t=S[e];if(t&&(u!==`alignment`||_===Yc(t)||T.every(e=>Yc(e.placement)!==_||e.overflows[0]>0)))return{data:{index:e,overflows:T},reset:{placement:t}};let n=T.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=T.filter(e=>{if(x){let t=Yc(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o}if(r!==n)return{reset:{placement:n}}}return{}}}};function gl(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function _l(e){return Ic.some(t=>e[t]>=0)}var vl=function(e){return e===void 0&&(e={}),{name:`hide`,options:e,async fn(t){let{rects:n,platform:r}=t,{strategy:i=`referenceHidden`,...a}=Wc(e,t);switch(i){case`referenceHidden`:{let e=gl(await r.detectOverflow(t,{...a,elementContext:`reference`}),n.reference);return{data:{referenceHiddenOffsets:e,referenceHidden:_l(e)}}}case`escaped`:{let e=gl(await r.detectOverflow(t,{...a,altBoundary:!0}),n.floating);return{data:{escapedOffsets:e,escaped:_l(e)}}}default:return{}}}}},yl=new Set([`left`,`top`]);async function bl(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=Gc(n),s=Kc(n),c=Yc(n)===`y`,l=yl.has(o)?-1:1,u=a&&c?-1:1,d=Wc(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}var xl=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await bl(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},Sl=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i,platform:a}=t,{mainAxis:o=!0,crossAxis:s=!1,limiter:c={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...l}=Wc(e,t),u={x:n,y:r},d=await a.detectOverflow(t,l),f=Yc(i),p=qc(f),m=u[p],h=u[f],g=(e,t)=>Uc(t+d[e===`y`?`top`:`left`],t,t-d[e===`y`?`bottom`:`right`]);o&&(m=g(p,m)),s&&(h=g(f,h));let _=c.fn({...t,[p]:m,[f]:h});return{..._,data:{x:_.x-n,y:_.y-r,enabled:{[p]:o,[f]:s}}}}}},Cl=function(e){return e===void 0&&(e={}),{options:e,fn(t){let{x:n,y:r,placement:i,rects:a,middlewareData:o}=t,{offset:s=0,mainAxis:c=!0,crossAxis:l=!0}=Wc(e,t),u={x:n,y:r},d=Yc(i),f=qc(d),p=u[f],m=u[d],h=Wc(s,t),g=typeof h==`number`?{mainAxis:h,crossAxis:0}:{mainAxis:h.mainAxis??0,crossAxis:h.crossAxis??0};if(c){let e=f===`y`?`height`:`width`,t=a.reference[f]-a.floating[e]+g.mainAxis,n=a.reference[f]+a.reference[e]-g.mainAxis;pn&&(p=n)}if(l){let e=f===`y`?`width`:`height`,t=yl.has(Gc(i)),n=a.reference[d]-a.floating[e]+(t&&o.offset?.[d]||0)+(t?0:g.crossAxis),r=a.reference[d]+a.reference[e]+(t?0:o.offset?.[d]||0)-(t?g.crossAxis:0);mr&&(m=r)}return{[f]:p,[d]:m}}}},wl=function(e){return e===void 0&&(e={}),{name:`size`,options:e,async fn(t){let{placement:n,rects:r,platform:i,elements:a}=t,{apply:o=()=>{},...s}=Wc(e,t),c=await i.detectOverflow(t,s),l=Gc(n),u=Kc(n),d=Yc(n)===`y`,{width:f,height:p}=r.floating,m,h;l===`top`||l===`bottom`?(m=l,h=u===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?`start`:`end`)?`left`:`right`):(h=l,m=u===`end`?`top`:`bottom`);let g=p-c.top-c.bottom,_=f-c.left-c.right,v=Lc(p-c[m],g),y=Lc(f-c[h],_),b=t.middlewareData.shift,x=!b,S=v,C=y;b!=null&&b.enabled.x&&(C=_),b!=null&&b.enabled.y&&(S=g),x&&!u&&(d?C=f-2*Rc(c.left,c.right):S=p-2*Rc(c.top,c.bottom)),await o({...t,availableWidth:C,availableHeight:S});let w=await i.getDimensions(a.floating);return f!==w.width||p!==w.height?{reset:{rects:!0}}:{}}}};function Tl(){return typeof window<`u`}function El(e){return kl(e)?(e.nodeName||``).toLowerCase():`#document`}function Dl(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function Ol(e){return((kl(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function kl(e){return Tl()?e instanceof Node||e instanceof Dl(e).Node:!1}function Al(e){return Tl()?e instanceof Element||e instanceof Dl(e).Element:!1}function jl(e){return Tl()?e instanceof HTMLElement||e instanceof Dl(e).HTMLElement:!1}function Ml(e){return!Tl()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof Dl(e).ShadowRoot}function Nl(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=Bl(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function Pl(e){return/^(table|td|th)$/.test(El(e))}function Fl(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var Il=/transform|translate|scale|rotate|perspective|filter/,Ll=/paint|layout|strict|content/,q=e=>!!e&&e!==`none`,Rl;function J(e){let t=Al(e)?Bl(e):e;return q(t.transform)||q(t.translate)||q(t.scale)||q(t.rotate)||q(t.perspective)||!X()&&(q(t.backdropFilter)||q(t.filter))||Il.test(t.willChange||``)||Ll.test(t.contain||``)}function Y(e){let t=Hl(e);for(;jl(t)&&!zl(t);){if(J(t))return t;if(Fl(t))return null;t=Hl(t)}return null}function X(){return Rl??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),Rl}function zl(e){return/^(html|body|#document)$/.test(El(e))}function Bl(e){return Dl(e).getComputedStyle(e)}function Vl(e){return Al(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Hl(e){if(El(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||Ml(e)&&e.host||Ol(e);return Ml(t)?t.host:t}function Ul(e){let t=Hl(e);return zl(t)?(e.ownerDocument||e).body:jl(t)&&Nl(t)?t:Ul(t)}function Wl(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=Ul(e),i=r===e.ownerDocument?.body,a=Dl(r);if(i){let e=Gl(a);return t.concat(a,a.visualViewport||[],Nl(r)?r:[],e&&n?Wl(e):[])}return t.concat(r,Wl(r,[],n))}function Gl(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Kl(e){let t=Bl(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=jl(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=zc(n)!==a||zc(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function ql(e){return Al(e)?e:e.contextElement}function Jl(e){let t=ql(e);if(!jl(t))return Vc(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=Kl(t),o=(a?zc(n.width):n.width)/r,s=(a?zc(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}var Yl=Vc(0);function Xl(e){let t=Dl(e);return!X()||!t.visualViewport?Yl:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Zl(e,t,n){return t===void 0&&(t=!1),!!n&&t&&n===Dl(e)}function Ql(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=ql(e),o=Vc(1);t&&(r?Al(r)&&(o=Jl(r)):o=Jl(e));let s=Zl(a,n,r)?Xl(a):Vc(0),c=(i.left+s.x)/o.x,l=(i.top+s.y)/o.y,u=i.width/o.x,d=i.height/o.y;if(a&&r){let e=Dl(a),t=Al(r)?Dl(r):r,n=e,i=Gl(n);for(;i&&t!==n;){let e=Jl(i),t=i.getBoundingClientRect(),r=Bl(i),a=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,o=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;c*=e.x,l*=e.y,u*=e.x,d*=e.y,c+=a,l+=o,n=Dl(i),i=Gl(n)}}return ll({width:u,height:d,x:c,y:l})}function $l(e,t){let n=Vl(e).scrollLeft;return t?t.left+n:Ql(Ol(e)).left+n}function eu(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-$l(e,n),y:n.top+t.scrollTop}}function tu(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=Ol(r),s=t?Fl(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=Vc(1),u=Vc(0),d=jl(r);if((d||!a)&&((El(r)!==`body`||Nl(o))&&(c=Vl(r)),d)){let e=Ql(r);l=Jl(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?eu(o,c):Vc(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function nu(e){return e.getClientRects?Array.from(e.getClientRects()):[]}function ru(e){let t=Vl(e),n=e.ownerDocument.body,r=Rc(e.scrollWidth,e.clientWidth,n.scrollWidth,n.clientWidth),i=Rc(e.scrollHeight,e.clientHeight,n.scrollHeight,n.clientHeight),a=-t.scrollLeft+$l(e),o=-t.scrollTop;return Bl(n).direction===`rtl`&&(a+=Rc(e.clientWidth,n.clientWidth)-r),{width:r,height:i,x:a,y:o}}var iu=25;function au(e,t,n){n===void 0&&(n=`viewport`);let r=n===`layoutViewport`,i=Dl(e),a=Ol(e),o=i.visualViewport,s=a.clientWidth,c=a.clientHeight,l=0,u=0;if(o){let e=!X()||t===`fixed`;r?e||(l=-o.offsetLeft,u=-o.offsetTop):(s=o.width,c=o.height,e&&(l=o.offsetLeft,u=o.offsetTop))}if($l(a)<=0){let e=a.ownerDocument,t=e.body,n=getComputedStyle(t),r=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,i=Math.abs(a.clientWidth-t.clientWidth-r),o=getComputedStyle(a).scrollbarGutter===`stable both-edges`?i/2:i;o<=iu&&(s-=o)}return{width:s,height:c,x:l,y:u}}function ou(e,t){let n=Ql(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=Jl(e);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function su(e,t,n){let r;if(t===`viewport`||t===`layoutViewport`)r=au(e,n,t);else if(t===`document`)r=ru(Ol(e));else if(Al(t))r=ou(t,n);else{let n=Xl(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return ll(r)}function cu(e,t){let n=t.get(e);if(n)return n;let r=Wl(e,[],!1).filter(e=>Al(e)&&El(e)!==`body`),i=null,a=Bl(e).position===`fixed`,o=a?Hl(e):e;for(;Al(o)&&!zl(o);){let e=Bl(o),t=J(o),n=i?i.position:a?`fixed`:``;!t&&(n===`fixed`||n===`absolute`&&e.position===`static`)?r=r.filter(e=>e!==o):i=e,o=Hl(o)}return t.set(e,r),r}function lu(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?Fl(t)?[]:cu(t,this._c):[].concat(n),r],o=su(t,a[0],i),s=o.top,c=o.right,l=o.bottom,u=o.left;for(let e=1;e{s(!1,1e-7)},1e3)}y=!1}try{r=new IntersectionObserver(b,{...v,root:a.ownerDocument})}catch{r=new IntersectionObserver(b,v)}r.observe(e)}let c=Dl(e),l=()=>s(n);return c.addEventListener(`resize`,l),s(!0),()=>{c.removeEventListener(`resize`,l),o()}}function bu(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=ql(e),u=i||a?[...l?Wl(l):[],...t?Wl(t):[]]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n),a&&e.addEventListener(`resize`,n)});let d=l&&s?yu(l,n,a):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&t&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),t&&p.observe(t));let m,h=c?Ql(e):null;c&&g();function g(){let t=Ql(e);h&&!vu(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}var xu=xl,Su=Sl,Cu=hl,wu=wl,Tu=vl,Eu=ml,Du=Cl,Ou=(e,t,n)=>{let r=new Map,i=n??{},a={..._u,...i.platform,_c:r};return pl(e,t,{...i,platform:a})},ku=typeof document<`u`?x.useLayoutEffect:function(){};function Au(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e==`function`&&e.toString()===t.toString())return!0;let n,r,i;if(e&&t&&typeof e==`object`){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!Au(e[r],t[r]))return!1;return!0}if(i=Object.keys(e),n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){let n=i[r];if(!(n===`_owner`&&e.$$typeof)&&!Au(e[n],t[n]))return!1}return!0}return e!==e&&t!==t}function ju(e){return typeof window>`u`?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Mu(e,t){let n=ju(e);return Math.round(t*n)/n}function Nu(e){let t=x.useRef(e);return ku(()=>{t.current=e}),t}function Pu(e){e===void 0&&(e={});let{placement:t=`bottom`,strategy:n=`absolute`,middleware:r=[],platform:i,elements:{reference:a,floating:o}={},transform:s=!0,whileElementsMounted:c,open:l}=e,[u,d]=x.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[f,p]=x.useState(r);Au(f,r)||p(r);let[m,h]=x.useState(null),[g,_]=x.useState(null),v=x.useCallback(e=>{e!==C.current&&(C.current=e,h(e))},[]),y=x.useCallback(e=>{e!==w.current&&(w.current=e,_(e))},[]),b=a||m,S=o||g,C=x.useRef(null),w=x.useRef(null),T=x.useRef(u),E=c!=null,D=Nu(c),O=Nu(i),ee=Nu(l),k=x.useCallback(()=>{if(!C.current||!w.current)return;let e={placement:t,strategy:n,middleware:f};O.current&&(e.platform=O.current),Ou(C.current,w.current,e).then(e=>{let t={...e,isPositioned:ee.current!==!1};A.current&&!Au(T.current,t)&&(T.current=t,Ui.flushSync(()=>{d(t)}))})},[f,t,n,O,ee]);ku(()=>{l===!1&&T.current.isPositioned&&(T.current.isPositioned=!1,d(e=>({...e,isPositioned:!1})))},[l]);let A=x.useRef(!1);ku(()=>(A.current=!0,()=>{A.current=!1}),[]),ku(()=>{if(b&&(C.current=b),S&&(w.current=S),b&&S){if(D.current)return D.current(b,S,k);k()}},[b,S,k,D,E]);let j=x.useMemo(()=>({reference:C,floating:w,setReference:v,setFloating:y}),[v,y]),te=x.useMemo(()=>({reference:b,floating:S}),[b,S]),M=x.useMemo(()=>{let e={position:n,left:0,top:0};if(!te.floating)return e;let t=Mu(te.floating,u.x),r=Mu(te.floating,u.y);return s?{...e,transform:`translate(`+t+`px, `+r+`px)`,...ju(te.floating)>=1.5&&{willChange:`transform`}}:{position:n,left:t,top:r}},[n,s,te.floating,u.x,u.y]);return x.useMemo(()=>({...u,update:k,refs:j,elements:te,floatingStyles:M}),[u,k,j,te,M])}var Fu=e=>{function t(e){return{}.hasOwnProperty.call(e,`current`)}return{name:`arrow`,options:e,fn(n){let{element:r,padding:i}=typeof e==`function`?e(n):e;return r&&t(r)?r.current==null?{}:Eu({element:r.current,padding:i}).fn(n):r?Eu({element:r,padding:i}).fn(n):{}}}},Iu=(e,t)=>{let n=xu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Lu=(e,t)=>{let n=Su(e);return{name:n.name,fn:n.fn,options:[e,t]}},Ru=(e,t)=>({fn:Du(e).fn,options:[e,t]}),zu=(e,t)=>{let n=Cu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Bu=(e,t)=>{let n=wu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Vu=(e,t)=>{let n=Tu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Hu=(e,t)=>{let n=Fu(e);return{name:n.name,fn:n.fn,options:[e,t]}},Uu=Object.defineProperty,Wu=(e,t)=>Uu(e,`name`,{value:t,configurable:!0}),Z=`Popper`,[Gu,Ku]=Zi(Z),[qu,Ju]=Gu(Z),Yu=Wu(e=>{let{__scopePopper:t,children:n}=e,[r,i]=x.useState(null),[a,o]=x.useState(void 0);return(0,S.jsx)(qu,{scope:t,anchor:r,onAnchorChange:i,placementState:a,setPlacementState:o,children:n})},`Popper`),Xu=`PopperAnchor`,Zu=x.forwardRef(Wu(function(e,t){let{__scopePopper:n,virtualRef:r,...i}=e,a=Ju(Xu,n),o=x.useRef(null),s=a.onAnchorChange,c=Oi(t,x.useCallback(e=>{o.current=e,e&&s(e)},[s])),l=x.useRef(null);x.useEffect(()=>{if(!r)return;let e=l.current;l.current=r.current,e!==l.current&&s(l.current)});let u=a.placementState&&id(a.placementState),d=u?.[0],f=u?.[1];return r?null:(0,S.jsx)(Ki.div,{"data-radix-popper-side":d,"data-radix-popper-align":f,...i,ref:c})},`PopperAnchor`)),Qu=`PopperContent`,[$u,ed]=Gu(Qu),td=x.forwardRef(Wu(function(e,t){let{__scopePopper:n,side:r=`bottom`,sideOffset:i=0,align:a=`center`,alignOffset:o=0,arrowPadding:s=0,avoidCollisions:c=!0,collisionBoundary:l=[],collisionPadding:u=0,sticky:d=`partial`,hideWhenDetached:f=!1,updatePositionStrategy:p=`optimized`,onPlaced:m,...h}=e,g=Ju(Qu,n),[_,v]=x.useState(null),y=Oi(t,v),[b,C]=x.useState(null),w=Fc(b),T=w?.width??0,E=w?.height??0,D=r+(a===`center`?``:`-`+a),O=typeof u==`number`?u:{top:0,right:0,bottom:0,left:0,...u},ee=Array.isArray(l)?l:[l],k=ee.length>0,A={padding:O,boundary:ee.filter(nd),altBoundary:k},{refs:j,floatingStyles:te,placement:M,isPositioned:ne,middlewareData:N}=Pu({strategy:`fixed`,placement:D,whileElementsMounted:Wu((...e)=>bu(...e,{animationFrame:p===`always`}),`whileElementsMounted`),elements:{reference:g.anchor},middleware:[Iu({mainAxis:i+E,alignmentAxis:o}),c&&Lu({mainAxis:!0,crossAxis:!1,limiter:d===`partial`?Ru():void 0,...A}),c&&zu({...A}),Bu({...A,apply:Wu(({elements:e,rects:t,availableWidth:n,availableHeight:r})=>{let{width:i,height:a}=t.reference,o=e.floating.style;o.setProperty(`--radix-popper-available-width`,`${n}px`),o.setProperty(`--radix-popper-available-height`,`${r}px`),o.setProperty(`--radix-popper-anchor-width`,`${i}px`),o.setProperty(`--radix-popper-anchor-height`,`${a}px`)},`apply`)}),b&&Hu({element:b,padding:s}),rd({arrowWidth:T,arrowHeight:E}),f&&Vu({strategy:`referenceHidden`,...A,boundary:k?A.boundary:void 0})]}),P=g.setPlacementState;ya(()=>(P(M),()=>{P(void 0)}),[M,P]);let[re,ie]=id(M),ae=$a(m);ya(()=>{ne&&ae?.()},[ne,ae]);let F=N.arrow?.x,I=N.arrow?.y,L=N.arrow?.centerOffset!==0,[oe,se]=x.useState();return ya(()=>{_&&se(window.getComputedStyle(_).zIndex)},[_]),(0,S.jsx)(`div`,{ref:j.setFloating,"data-radix-popper-content-wrapper":``,style:{...te,transform:ne?te.transform:`translate(0, -200%)`,minWidth:`max-content`,zIndex:oe,"--radix-popper-transform-origin":[N.transformOrigin?.x,N.transformOrigin?.y].join(` `),...N.hide?.referenceHidden&&{visibility:`hidden`,pointerEvents:`none`}},dir:e.dir,children:(0,S.jsx)($u,{scope:n,placedSide:re,placedAlign:ie,onArrowChange:C,arrowX:F,arrowY:I,shouldHideArrow:L,children:(0,S.jsx)(Ki.div,{"data-side":re,"data-align":ie,...h,ref:y,style:{...h.style,animation:ne?h.style?.animation:`none`}})})})},`PopperContent`));function nd(e){return e!==null}Wu(nd,`isNotNull`);var rd=Wu(e=>({name:`transformOrigin`,options:e,fn(t){let{placement:n,rects:r,middlewareData:i}=t,a=i.arrow?.centerOffset!==0,o=a?0:e.arrowWidth,s=a?0:e.arrowHeight,[c,l]=id(n),u={start:`0%`,center:`50%`,end:`100%`}[l],d=(i.arrow?.x??0)+o/2,f=(i.arrow?.y??0)+s/2,p=``,m=``;return c===`bottom`?(p=a?u:`${d}px`,m=`${-s}px`):c===`top`?(p=a?u:`${d}px`,m=`${r.floating.height+s}px`):c===`right`?(p=`${-s}px`,m=a?u:`${f}px`):c===`left`&&(p=`${r.floating.width+s}px`,m=a?u:`${f}px`),{data:{x:p,y:m}}}}),`transformOrigin`);function id(e){let[t,n=`center`]=e.split(`-`);return[t,n]}Wu(id,`getSideAndAlignFromPlacement`);var ad=Yu,od=Zu,sd=td,cd=Object.defineProperty,ld=(e,t)=>cd(e,`name`,{value:t,configurable:!0}),ud=!1;function dd(){let[e,t]=x.useState(ud);return x.useEffect(()=>{ud||(ud=!0,t(!0))},[]),e}ld(dd,`useIsHydrated`);var fd=x.useSyncExternalStore;function pd(){return()=>{}}ld(pd,`subscribe`);function md(){return fd(pd,()=>!0,()=>!1)}ld(md,`useIsHydratedModern`);var hd=typeof fd==`function`?md:dd,gd=Object.defineProperty,_d=(e,t)=>gd(e,`name`,{value:t,configurable:!0}),vd=`rovingFocusGroup.onEntryFocus`,yd={bubbles:!1,cancelable:!0},Q=`RovingFocusGroup`,[bd,xd,Sd]=ta(Q),[Cd,wd]=Zi(Q,[Sd]),[Td,Ed]=Cd(Q),Dd=x.forwardRef(_d(function(e,t){return(0,S.jsx)(bd.Provider,{scope:e.__scopeRovingFocusGroup,children:(0,S.jsx)(bd.Slot,{scope:e.__scopeRovingFocusGroup,children:(0,S.jsx)(Od,{...e,ref:t})})})},`RovingFocusGroup`)),Od=x.forwardRef(_d(function(e,t){let{__scopeRovingFocusGroup:n,orientation:r,loop:i=!1,dir:a,currentTabStopId:o,defaultCurrentTabStopId:s,onCurrentTabStopIdChange:c,onEntryFocus:l,preventScrollOnEntryFocus:u=!1,...d}=e,f=x.useRef(null),p=Oi(t,f),m=Xa(a),[h,g]=Oa({prop:o,defaultProp:s??null,onChange:c,caller:Q}),[_,v]=x.useState(!1),y=$a(l),b=xd(n),C=x.useRef(!1),[w,T]=x.useState(0);return x.useEffect(()=>{let e=f.current;if(e)return e.addEventListener(vd,y),()=>e.removeEventListener(vd,y)},[y]),(0,S.jsx)(Td,{scope:n,orientation:r,dir:m,loop:i,currentTabStopId:h,onItemFocus:x.useCallback(e=>g(e),[g]),onItemShiftTab:x.useCallback(()=>v(!0),[]),onFocusableItemAdd:x.useCallback(()=>T(e=>e+1),[]),onFocusableItemRemove:x.useCallback(()=>T(e=>e-1),[]),children:(0,S.jsx)(Ki.div,{tabIndex:_||w===0?-1:0,"data-orientation":r,...d,ref:p,style:{outline:`none`,...e.style},onMouseDown:G(e.onMouseDown,()=>{C.current=!0}),onFocus:G(e.onFocus,e=>{let t=!C.current;if(e.target===e.currentTarget&&t&&!_){let t=new CustomEvent(vd,yd);if(e.currentTarget.dispatchEvent(t),!t.defaultPrevented){let e=b().filter(e=>e.focusable);Pd([e.find(e=>e.active),e.find(e=>e.id===h),...e].filter(Boolean).map(e=>e.ref.current),u)}}C.current=!1}),onBlur:G(e.onBlur,()=>v(!1))})})},`RovingFocusGroupImpl`)),kd=`RovingFocusGroupItem`,Ad=x.forwardRef(_d(function(e,t){let{__scopeRovingFocusGroup:n,focusable:r=!0,active:i=!1,tabStopId:a,children:o,...s}=e,c=Ka(),l=a||c,u=Ed(kd,n),d=u.currentTabStopId===l,f=xd(n),{onFocusableItemAdd:p,onFocusableItemRemove:m,currentTabStopId:h}=u,g=hd();return ya(()=>{if(g&&r)return p(),()=>m()},[g,r,p,m]),x.useEffect(()=>{if(!g&&r)return p(),()=>m()},[g,r,p,m]),(0,S.jsx)(bd.ItemSlot,{scope:n,id:l,focusable:r,active:i,children:(0,S.jsx)(Ki.span,{tabIndex:d?0:-1,"data-orientation":u.orientation,...s,ref:t,onMouseDown:G(e.onMouseDown,e=>{r?u.onItemFocus(l):e.preventDefault()}),onFocus:G(e.onFocus,()=>u.onItemFocus(l)),onKeyDown:G(e.onKeyDown,e=>{if(e.key===`Tab`&&e.shiftKey){u.onItemShiftTab();return}if(e.target!==e.currentTarget)return;let t=Nd(e,u.orientation,u.dir);if(t!==void 0){if(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)return;e.preventDefault();let n=f().filter(e=>e.focusable).map(e=>e.ref.current);if(t===`last`)n.reverse();else if(t===`prev`||t===`next`){t===`prev`&&n.reverse();let r=n.indexOf(e.currentTarget);n=u.loop?Fd(n,r+1):n.slice(r+1)}setTimeout(()=>Pd(n))}}),children:typeof o==`function`?o({isCurrentTabStop:d,hasTabStop:h!=null}):o})})},`RovingFocusGroupItem`)),jd={ArrowLeft:`prev`,ArrowUp:`prev`,ArrowRight:`next`,ArrowDown:`next`,PageUp:`first`,Home:`first`,PageDown:`last`,End:`last`};function Md(e,t){return t===`rtl`?e===`ArrowLeft`?`ArrowRight`:e===`ArrowRight`?`ArrowLeft`:e:e}_d(Md,`getDirectionAwareKey`);function Nd(e,t,n){let r=Md(e.key,n);if(!(t===`vertical`&&[`ArrowLeft`,`ArrowRight`].includes(r))&&!(t===`horizontal`&&[`ArrowUp`,`ArrowDown`].includes(r)))return jd[r]}_d(Nd,`getFocusIntent`);function Pd(e,t=!1){let n=document.activeElement;for(let r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}_d(Pd,`focusFirst`);function Fd(e,t){return e.map((n,r)=>e[(t+r)%e.length])}_d(Fd,`wrapArray`);var Id=Dd,Ld=Ad,Rd=Object.defineProperty,zd=(e,t)=>Rd(e,`name`,{value:t,configurable:!0}),Bd=[`Enter`,` `],Vd=[`ArrowDown`,`PageUp`,`Home`],Hd=[`ArrowUp`,`PageDown`,`End`],Ud=[...Vd,...Hd];[...Bd],[...Bd];var Wd=`Menu`,[Gd,Kd,qd]=ta(Wd),[Jd,Yd]=Zi(Wd,[qd,Ku,wd]),Xd=Ku(),Zd=wd(),[Qd,$d]=Jd(Wd),[ef,tf]=Jd(Wd),nf=zd(e=>{let{__scopeMenu:t,open:n=!1,children:r,dir:i,onOpenChange:a,modal:o=!0}=e,s=Xd(t),[c,l]=x.useState(null),u=x.useRef(!1),d=$a(a),f=Xa(i);return x.useEffect(()=>{let e=zd(()=>{u.current=!0,document.addEventListener(`pointerdown`,t,{capture:!0,once:!0}),document.addEventListener(`pointermove`,t,{capture:!0,once:!0})},`handleKeyDown`),t=zd(()=>u.current=!1,`handlePointer`);return document.addEventListener(`keydown`,e,{capture:!0}),()=>{document.removeEventListener(`keydown`,e,{capture:!0}),document.removeEventListener(`pointerdown`,t,{capture:!0}),document.removeEventListener(`pointermove`,t,{capture:!0})}},[]),x.useEffect(()=>{if(!n)return;let e=zd(()=>d(!1),`handleBlur`);return window.addEventListener(`blur`,e),()=>window.removeEventListener(`blur`,e)},[n,d]),(0,S.jsx)(ad,{...s,children:(0,S.jsx)(Qd,{scope:t,open:n,onOpenChange:d,content:c,onContentChange:l,children:(0,S.jsx)(ef,{scope:t,onClose:x.useCallback(()=>d(!1),[d]),isUsingKeyboardRef:u,dir:f,modal:o,children:r})})})},`Menu`),rf=x.forwardRef(zd(function(e,t){let{__scopeMenu:n,...r}=e,i=Xd(n);return(0,S.jsx)(od,{...i,...r,ref:t})},`MenuAnchor`)),af=`MenuPortal`,[of,sf]=Jd(af,{forceMount:void 0}),cf=zd(e=>{let{__scopeMenu:t,forceMount:n,children:r,container:i}=e,a=$d(af,t);return(0,S.jsx)(of,{scope:t,forceMount:n,children:(0,S.jsx)(Ia,{present:n||a.open,children:(0,S.jsx)(Mo,{asChild:!0,container:i,children:r})})})},`MenuPortal`),lf=`MenuContent`,[uf,df]=Jd(lf),ff=x.forwardRef(zd(function(e,t){let n=sf(lf,e.__scopeMenu),{forceMount:r=n.forceMount,...i}=e,a=$d(lf,e.__scopeMenu),o=tf(lf,e.__scopeMenu);return(0,S.jsx)(Gd.Provider,{scope:e.__scopeMenu,children:(0,S.jsx)(Ia,{present:r||a.open,children:(0,S.jsx)(Gd.Slot,{scope:e.__scopeMenu,children:o.modal?(0,S.jsx)(pf,{...i,ref:t}):(0,S.jsx)(mf,{...i,ref:t})})})})},`MenuContent`)),pf=x.forwardRef(zd(function(e,t){let n=$d(lf,e.__scopeMenu),r=x.useRef(null),i=Oi(t,r);return x.useEffect(()=>{let e=r.current;if(e)return ic(e)},[]),(0,S.jsx)(gf,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:G(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})},`MenuRootContentModal`)),mf=x.forwardRef(zd(function(e,t){let n=$d(lf,e.__scopeMenu);return(0,S.jsx)(gf,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})},`MenuRootContentNonModal`)),hf=W(`MenuContent.ScrollLock`),gf=x.forwardRef(zd(function(e,t){let{__scopeMenu:n,loop:r=!1,trapFocus:i,onOpenAutoFocus:a,onCloseAutoFocus:o,disableOutsidePointerEvents:s,onEntryFocus:c,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,onDismiss:p,disableOutsideScroll:m,...h}=e,g=$d(lf,n),_=tf(lf,n),v=Xd(n),y=Zd(n),b=Kd(n),[C,w]=x.useState(null),T=x.useRef(null),E=Oi(t,T,g.onContentChange),D=x.useRef(0),O=x.useRef(``),ee=x.useRef(0),k=x.useRef(null),A=x.useRef(`right`),j=x.useRef(0),te=m?Ys:x.Fragment,M=m?{as:hf,allowPinchZoom:!0}:void 0,ne=zd(e=>{let t=O.current+e,n=b().filter(e=>!e.disabled),r=document.activeElement,i=n.find(e=>e.ref.current===r)?.textValue,a=Nf(n.map(e=>e.textValue),t,i),o=n.find(e=>e.textValue===a)?.ref.current;zd((function e(t){O.current=t,window.clearTimeout(D.current),t!==``&&(D.current=window.setTimeout(()=>e(``),1e3))}),`updateSearch`)(t),o&&setTimeout(()=>o.focus())},`handleTypeaheadSearch`);x.useEffect(()=>()=>window.clearTimeout(D.current),[]),Ro();let N=x.useCallback(e=>A.current===k.current?.side&&Ff(e,k.current?.area),[]);return(0,S.jsx)(uf,{scope:n,searchRef:O,onItemEnter:x.useCallback(e=>{N(e)&&e.preventDefault()},[N]),onItemLeave:x.useCallback(e=>{N(e)||(T.current?.focus(),w(null))},[N]),onTriggerLeave:x.useCallback(e=>{N(e)&&e.preventDefault()},[N]),pointerGraceTimerRef:ee,onPointerGraceIntentChange:x.useCallback(e=>{k.current=e},[]),children:(0,S.jsx)(te,{...M,children:(0,S.jsx)(yo,{asChild:!0,trapped:i,onMountAutoFocus:G(a,e=>{e.preventDefault(),T.current?.focus({preventScroll:!0})}),onUnmountAutoFocus:o,children:(0,S.jsx)(K,{asChild:!0,disableOutsidePointerEvents:s,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,onDismiss:p,children:(0,S.jsx)(Id,{asChild:!0,...y,dir:_.dir,orientation:`vertical`,loop:r,currentTabStopId:C,onCurrentTabStopIdChange:w,onEntryFocus:G(c,e=>{_.isUsingKeyboardRef.current||e.preventDefault()}),preventScrollOnEntryFocus:!0,children:(0,S.jsx)(sd,{role:`menu`,"aria-orientation":`vertical`,"data-state":Of(g.open),"data-radix-menu-content":``,dir:_.dir,...v,...h,ref:E,style:{outline:`none`,...h.style},onKeyDown:G(h.onKeyDown,e=>{let t=e.target.closest(`[data-radix-menu-content]`)===e.currentTarget,n=e.ctrlKey||e.altKey||e.metaKey,r=e.key.length===1;t&&(e.key===`Tab`&&e.preventDefault(),!n&&r&&ne(e.key));let i=T.current;if(e.target!==i||!Ud.includes(e.key))return;e.preventDefault();let a=b().filter(e=>!e.disabled).map(e=>e.ref.current);Hd.includes(e.key)&&a.reverse(),jf(a)}),onBlur:G(e.onBlur,e=>{e.currentTarget.contains(e.target)||(window.clearTimeout(D.current),O.current=``)}),onPointerMove:G(e.onPointerMove,If(e=>{let t=e.target,n=j.current!==e.clientX;if(e.currentTarget.contains(t)&&n){let t=e.clientX>j.current?`right`:`left`;A.current=t,j.current=e.clientX}}))})})})})})})},`MenuContentImpl`)),_f=x.forwardRef(zd(function(e,t){let{__scopeMenu:n,...r}=e;return(0,S.jsx)(Ki.div,{role:`group`,...r,ref:t})},`MenuGroup`)),vf=`MenuItem`,yf=`menu.itemSelect`,bf=x.forwardRef(zd(function(e,t){let{disabled:n=!1,onSelect:r,...i}=e,a=x.useRef(null),o=tf(vf,e.__scopeMenu),s=df(vf,e.__scopeMenu),c=Oi(t,a),l=x.useRef(!1),u=zd(()=>{let e=a.current;if(!n&&e){let t=new CustomEvent(yf,{bubbles:!0,cancelable:!0});e.addEventListener(yf,e=>r?.(e),{once:!0}),qi(e,t),t.defaultPrevented?l.current=!1:o.onClose()}},`handleSelect`);return(0,S.jsx)(xf,{...i,ref:c,disabled:n,onClick:G(e.onClick,u),onPointerDown:t=>{e.onPointerDown?.(t),l.current=!0},onPointerUp:G(e.onPointerUp,e=>{l.current||e.currentTarget?.click()}),onKeyDown:G(e.onKeyDown,e=>{n||e.target!==e.currentTarget||(s.searchRef.current===``||e.key!==` `)&&Bd.includes(e.key)&&(e.currentTarget.click(),e.preventDefault())})})},`MenuItem`)),xf=x.forwardRef(zd(function(e,t){let{__scopeMenu:n,disabled:r=!1,textValue:i,...a}=e,o=df(vf,n),s=Zd(n),c=x.useRef(null),l=Oi(t,c),[u,d]=x.useState(!1),[f,p]=x.useState(``);return x.useEffect(()=>{let e=c.current;e&&p((e.textContent??``).trim())},[a.children]),(0,S.jsx)(Gd.ItemSlot,{scope:n,disabled:r,textValue:i??f,children:(0,S.jsx)(Ld,{asChild:!0,...s,focusable:!r,children:(0,S.jsx)(Ki.div,{role:`menuitem`,"data-highlighted":u?``:void 0,"aria-disabled":r||void 0,"data-disabled":r?``:void 0,...a,ref:l,onPointerMove:G(e.onPointerMove,If(e=>{r?o.onItemLeave(e):(o.onItemEnter(e),e.defaultPrevented||e.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:G(e.onPointerLeave,If(e=>o.onItemLeave(e))),onFocus:G(e.onFocus,()=>d(!0)),onBlur:G(e.onBlur,()=>d(!1))})})})},`MenuItemImpl`)),[Sf,Cf]=Jd(`MenuRadioGroup`,{value:void 0,onValueChange:zd(()=>{},`onValueChange`)}),[wf,Tf]=Jd(`MenuItemIndicator`,{checked:!1}),[Ef,Df]=Jd(`MenuSub`);function Of(e){return e?`open`:`closed`}zd(Of,`getOpenState`);function kf(e){return e===`indeterminate`}zd(kf,`isIndeterminate`);function Af(e){return kf(e)?`indeterminate`:e?`checked`:`unchecked`}zd(Af,`getCheckedState`);function jf(e){let t=document.activeElement;for(let n of e)if(n===t||(n.focus(),document.activeElement!==t))return}zd(jf,`focusFirst`);function Mf(e,t){return e.map((n,r)=>e[(t+r)%e.length])}zd(Mf,`wrapArray`);function Nf(e,t,n){let r=t.length>1&&Array.from(t).every(e=>e===t[0])?t[0]:t,i=n?e.indexOf(n):-1,a=Mf(e,Math.max(i,0));r.length===1&&(a=a.filter(e=>e!==n));let o=a.find(e=>e.toLowerCase().startsWith(r.toLowerCase()));return o===n?void 0:o}zd(Nf,`getNextMatch`);function Pf(e,t){let{x:n,y:r}=e,i=!1;for(let e=0,a=t.length-1;er!=d>r&&n<(u-c)*(r-l)/(d-l)+c&&(i=!i)}return i}zd(Pf,`isPointInPolygon`);function Ff(e,t){return t?Pf({x:e.clientX,y:e.clientY},t):!1}zd(Ff,`isPointerInGraceArea`);function If(e){return t=>t.pointerType===`mouse`?e(t):void 0}zd(If,`whenMouse`);var Lf=nf,Rf=rf,zf=cf,Bf=ff,Vf=_f,Hf=bf,Uf=Object.defineProperty,Wf=(e,t)=>Uf(e,`name`,{value:t,configurable:!0}),Gf=`DropdownMenu`,[Kf,qf]=Zi(Gf,[Yd]),Jf=Yd(),[Yf,Xf]=Kf(Gf),Zf=Wf(e=>{let{__scopeDropdownMenu:t,children:n,dir:r,open:i,defaultOpen:a,onOpenChange:o,modal:s=!0}=e,c=Jf(t),l=x.useRef(null),[u,d]=Oa({prop:i,defaultProp:a??!1,onChange:o,caller:Gf});return(0,S.jsx)(Yf,{scope:t,triggerId:Ka(),triggerRef:l,contentId:Ka(),open:u,onOpenChange:d,onOpenToggle:x.useCallback(()=>d(e=>!e),[d]),modal:s,children:(0,S.jsx)(Lf,{...c,open:u,onOpenChange:d,dir:r,modal:s,children:n})})},`DropdownMenu`),Qf=`DropdownMenuTrigger`,$f=x.forwardRef(Wf(function(e,t){let{__scopeDropdownMenu:n,disabled:r=!1,...i}=e,a=Xf(Qf,n),o=Jf(n),s=Oi(t,a.triggerRef);return(0,S.jsx)(Rf,{asChild:!0,...o,children:(0,S.jsx)(Ki.button,{type:`button`,id:a.triggerId,"aria-haspopup":`menu`,"aria-expanded":a.open,"aria-controls":a.open?a.contentId:void 0,"data-state":a.open?`open`:`closed`,"data-disabled":r?``:void 0,disabled:r,...i,ref:s,onPointerDown:G(e.onPointerDown,e=>{!r&&e.button===0&&e.ctrlKey===!1&&(a.onOpenToggle(),a.open||e.preventDefault())}),onKeyDown:G(e.onKeyDown,e=>{r||([`Enter`,` `].includes(e.key)&&a.onOpenToggle(),e.key===`ArrowDown`&&a.onOpenChange(!0),[`Enter`,` `,`ArrowDown`].includes(e.key)&&e.preventDefault())})})})},`DropdownMenuTrigger`)),ep=Wf(e=>{let{__scopeDropdownMenu:t,...n}=e,r=Jf(t);return(0,S.jsx)(zf,{...r,...n})},`DropdownMenuPortal`),tp=`DropdownMenuContent`,np=x.forwardRef(Wf(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=Xf(tp,n),a=Jf(n),o=x.useRef(!1);return(0,S.jsx)(Bf,{id:i.contentId,"aria-labelledby":i.triggerId,...a,...r,ref:t,onCloseAutoFocus:G(e.onCloseAutoFocus,e=>{o.current||i.triggerRef.current?.focus(),o.current=!1,e.preventDefault()}),onInteractOutside:G(e.onInteractOutside,e=>{let t=e.detail.originalEvent,n=t.button===0&&t.ctrlKey===!0,r=t.button===2||n;(!i.modal||r)&&(o.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-dropdown-menu-content-available-width":`var(--radix-popper-available-width)`,"--radix-dropdown-menu-content-available-height":`var(--radix-popper-available-height)`,"--radix-dropdown-menu-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-dropdown-menu-trigger-height":`var(--radix-popper-anchor-height)`}})},`DropdownMenuContent`)),rp=x.forwardRef(Wf(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=Jf(n);return(0,S.jsx)(Vf,{...i,...r,ref:t})},`DropdownMenuGroup`)),ip=x.forwardRef(Wf(function(e,t){let{__scopeDropdownMenu:n,...r}=e,i=Jf(n);return(0,S.jsx)(Hf,{...i,...r,ref:t})},`DropdownMenuItem`)),ap=Zf,op=$f,sp=ep,cp=np,lp=rp,up=ip,dp=Object.defineProperty,fp=x.forwardRef(((e,t)=>dp(e,`name`,{value:t,configurable:!0}))(function(e,t){return(0,S.jsx)(Ki.label,{...e,ref:t,onMouseDown:t=>{t.target.closest(`button, input, select, textarea`)||(e.onMouseDown?.(t),!t.defaultPrevented&&t.detail>1&&t.preventDefault())}})},`Label`)),pp=Object.defineProperty,mp=(e,t)=>pp(e,`name`,{value:t,configurable:!0}),hp=`Tabs`,[gp,_p]=Zi(hp,[wd]),vp=wd(),[yp,bp]=gp(hp),xp=x.forwardRef(mp(function(e,t){let{__scopeTabs:n,value:r,onValueChange:i,defaultValue:a,orientation:o=`horizontal`,dir:s,activationMode:c=`automatic`,...l}=e,u=Xa(s),[d,f]=Oa({prop:r,onChange:i,defaultProp:a??``,caller:hp});return(0,S.jsx)(yp,{scope:n,baseId:Ka(),value:d,onValueChange:f,orientation:o,dir:u,activationMode:c,children:(0,S.jsx)(Ki.div,{dir:u,"data-orientation":o,...l,ref:t})})},`Tabs`)),Sp=`TabsList`,Cp=x.forwardRef(mp(function(e,t){let{__scopeTabs:n,loop:r=!0,...i}=e,a=bp(Sp,n),o=vp(n);return(0,S.jsx)(Id,{asChild:!0,...o,orientation:a.orientation,dir:a.dir,loop:r,children:(0,S.jsx)(Ki.div,{role:`tablist`,"aria-orientation":a.orientation,...i,ref:t})})},`TabsList`)),wp=`TabsTrigger`,Tp=x.forwardRef(mp(function(e,t){let{__scopeTabs:n,value:r,disabled:i=!1,...a}=e,o=bp(wp,n),s=vp(n),c=Op(o.baseId,r),l=kp(o.baseId,r),u=r===o.value;return(0,S.jsx)(Ld,{asChild:!0,...s,focusable:!i,active:u,children:(0,S.jsx)(Ki.button,{type:`button`,role:`tab`,"aria-selected":u,"aria-controls":l,"data-state":u?`active`:`inactive`,"data-disabled":i?``:void 0,disabled:i,id:c,...a,ref:t,onMouseDown:G(e.onMouseDown,e=>{!i&&e.button===0&&e.ctrlKey===!1?o.onValueChange(r):e.preventDefault()}),onKeyDown:G(e.onKeyDown,e=>{i||e.target!==e.currentTarget||[` `,`Enter`].includes(e.key)&&o.onValueChange(r)}),onFocus:G(e.onFocus,()=>{let e=o.activationMode!==`manual`;!u&&!i&&e&&o.onValueChange(r)})})})},`TabsTrigger`)),Ep=`TabsContent`,Dp=x.forwardRef(mp(function(e,t){let{__scopeTabs:n,value:r,forceMount:i,children:a,...o}=e,s=bp(Ep,n),c=Op(s.baseId,r),l=kp(s.baseId,r),u=r===s.value,d=x.useRef(u);return x.useEffect(()=>{let e=requestAnimationFrame(()=>d.current=!1);return()=>cancelAnimationFrame(e)},[]),(0,S.jsx)(Ia,{present:i||u,children:({present:n})=>(0,S.jsx)(Ki.div,{"data-state":u?`active`:`inactive`,"data-orientation":s.orientation,role:`tabpanel`,"aria-labelledby":c,hidden:!n,id:l,tabIndex:0,...o,ref:t,style:{...e.style,animationDuration:d.current?`0s`:void 0},children:n&&a})})},`TabsContent`));function Op(e,t){return`${e}-trigger-${t}`}mp(Op,`makeTriggerId`);function kp(e,t){return`${e}-content-${t}`}mp(kp,`makeContentId`);var Ap=xp,jp=Cp,Mp=Tp,Np=Dp,Pp=Qn(`inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary/90`,destructive:`bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40`,outline:`border bg-background hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50`,secondary:`bg-secondary text-secondary-foreground hover:bg-secondary/80`,ghost:`hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-9 px-4 py-2 has-[>svg]:px-3`,xs:`h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3`,sm:`h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5`,lg:`h-10 rounded-md px-6 has-[>svg]:px-4`,icon:`size-9`,"icon-xs":`size-6 rounded-md [&_svg:not([class*='size-'])]:size-3`,"icon-sm":`size-8`,"icon-lg":`size-10`}},defaultVariants:{variant:`default`,size:`default`}});function $({className:e,variant:t=`default`,size:n=`default`,asChild:r=!1,...i}){let a=r?Ai:`button`;return(0,S.jsx)(a,{"data-slot":`button`,"data-variant":t,"data-size":n,className:H(Pp({variant:t,size:n,className:e})),...i})}function Fp({className:e,orientation:t=`horizontal`,...n}){return(0,S.jsx)(Ap,{"data-slot":`tabs`,"data-orientation":t,orientation:t,className:H(`group/tabs flex gap-2 data-[orientation=horizontal]:flex-col`,e),...n})}var Ip=Qn(`group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-[orientation=horizontal]/tabs:h-9 group-data-[orientation=vertical]/tabs:h-fit group-data-[orientation=vertical]/tabs:flex-col data-[variant=line]:rounded-none`,{variants:{variant:{default:`bg-muted`,line:`gap-1 bg-transparent`}},defaultVariants:{variant:`default`}});function Lp({className:e,variant:t=`default`,...n}){return(0,S.jsx)(jp,{"data-slot":`tabs-list`,"data-variant":t,className:H(Ip({variant:t}),e),...n})}function Rp({className:e,...t}){return(0,S.jsx)(Mp,{"data-slot":`tabs-trigger`,className:H(`relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-[orientation=vertical]/tabs:w-full group-data-[orientation=vertical]/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 group-data-[variant=default]/tabs-list:data-[state=active]:shadow-sm group-data-[variant=line]/tabs-list:data-[state=active]:shadow-none dark:text-muted-foreground dark:hover:text-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,`group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:border-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent`,`data-[state=active]:bg-background data-[state=active]:text-foreground dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 dark:data-[state=active]:text-foreground`,`after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-[orientation=horizontal]/tabs:after:inset-x-0 group-data-[orientation=horizontal]/tabs:after:bottom-[-5px] group-data-[orientation=horizontal]/tabs:after:h-0.5 group-data-[orientation=vertical]/tabs:after:inset-y-0 group-data-[orientation=vertical]/tabs:after:-right-1 group-data-[orientation=vertical]/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-[state=active]:after:opacity-100`,e),...t})}function zp({className:e,...t}){return(0,S.jsx)(Np,{"data-slot":`tabs-content`,className:H(`flex-1 outline-none`,e),...t})}function Bp(e){if(e.apiVersion!==1||!/^[a-z][a-z0-9-]*$/.test(e.id))throw Error(`Invalid theme pack: ${e.id}`);return e}var Vp=Bp({apiVersion:1,id:`precision`,name:`Precision`,description:`Clear typography, quiet surfaces, and a cobalt accent.`}),Hp=Object.assign({"./packs/precision/index.ts":Vp}),Up=`precision`,Wp=Object.values(Hp).sort((e,t)=>e.id===`precision`?-1:t.id===`precision`?1:e.name.localeCompare(t.name)),Gp=new Map;for(let e of Wp){if(Gp.has(e.id))throw Error(`Duplicate theme pack: ${e.id}`);Gp.set(e.id,e)}if(!Gp.has(`precision`))throw Error(`The default theme is required`);function Kp(e){return Gp.get(e)||Gp.get(`precision`)}var qp={themeId:Up,appearance:`light`},Jp=e=>e===`light`||e===`dark`||e===`system`,Yp=e=>`dispatch:theme:v1:${e}`;function Xp(e){try{let t=e?localStorage.getItem(Yp(e)):null;if(!t)return qp;let n=JSON.parse(t);return!n||typeof n!=`object`?qp:{themeId:Kp(n.themeId).id,appearance:Jp(n.appearance)?n.appearance:`light`}}catch{return qp}}var Zp=(0,x.createContext)(null);function Qp({userId:e,children:t}){let[n,r]=(0,x.useState)(()=>({userId:e,preference:Xp(e),storageUnavailable:!1}));n.userId!==e&&r({userId:e,preference:Xp(e),storageUnavailable:!1});let{preference:i,storageUnavailable:a}=n,{appearance:o,themeId:s}=i,c=Kp(s),[l,u]=(0,x.useState)(()=>matchMedia(`(prefers-color-scheme: dark)`).matches),d=o===`system`?l?`dark`:`light`:o;(0,x.useLayoutEffect)(()=>{document.documentElement.dataset.theme=d,document.documentElement.dataset.themePack=c.id,document.querySelector(`meta[name="theme-color"]`)?.setAttribute(`content`,getComputedStyle(document.documentElement).getPropertyValue(`--background`).trim())},[d,c.id]),(0,x.useEffect)(()=>{let e=matchMedia(`(prefers-color-scheme: dark)`),t=()=>u(e.matches);return t(),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),(0,x.useEffect)(()=>{if(!e)return;let t=t=>{(t.key===null||t.key===Yp(e))&&r(t=>t.userId===e?{...t,preference:Xp(e)}:t)};return window.addEventListener(`storage`,t),()=>window.removeEventListener(`storage`,t)},[e]);function f(t){let n=!1;try{if(!e)return;localStorage.setItem(Yp(e),JSON.stringify(t))}catch{n=!0}r({userId:e,preference:t,storageUnavailable:n})}return(0,S.jsx)(Zp.Provider,{value:{appearance:o,themePack:c,storageUnavailable:a,setAppearance:e=>f({...i,appearance:e}),setThemePack:e=>f({...i,themeId:Kp(e).id})},children:t})}function $p(){let e=(0,x.useContext)(Zp);if(!e)throw Error(`ThemeProvider is required`);return e}function em({className:e,...t}){return(0,S.jsx)(fp,{"data-slot":`label`,className:H(`flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50`,e),...t})}function tm({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`field-group`,className:H(`group/field-group @container/field-group flex w-full flex-col gap-7 data-[slot=checkbox-group]:gap-3 [&>[data-slot=field-group]]:gap-4`,e),...t})}var nm=Qn(`group/field flex w-full gap-3 data-[invalid=true]:text-destructive`,{variants:{orientation:{vertical:[`flex-col [&>*]:w-full [&>.sr-only]:w-auto`],horizontal:[`flex-row items-center`,`[&>[data-slot=field-label]]:flex-auto`,`has-[>[data-slot=field-content]]:items-start has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px`],responsive:[`flex-col @md/field-group:flex-row @md/field-group:items-center [&>*]:w-full @md/field-group:[&>*]:w-auto [&>.sr-only]:w-auto`,`@md/field-group:[&>[data-slot=field-label]]:flex-auto`,`@md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px`]}},defaultVariants:{orientation:`vertical`}});function rm({className:e,orientation:t=`vertical`,...n}){return(0,S.jsx)(`div`,{role:`group`,"data-slot":`field`,"data-orientation":t,className:H(nm({orientation:t}),e),...n})}function im({className:e,...t}){return(0,S.jsx)(em,{"data-slot":`field-label`,className:H(`group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50`,`has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border [&>*]:data-[slot=field]:p-4`,`has-data-[state=checked]:border-primary has-data-[state=checked]:bg-primary/5 dark:has-data-[state=checked]:bg-primary/10`,e),...t})}function am({className:e,...t}){return(0,S.jsx)(`p`,{"data-slot":`field-description`,className:H(`text-sm leading-normal font-normal text-muted-foreground group-has-[[data-orientation=horizontal]]/field:text-balance`,`last:mt-0 nth-last-2:-mt-1 [[data-variant=legend]+&]:-mt-1.5`,`[&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary`,e),...t})}function om({className:e,type:t,...n}){return(0,S.jsx)(`input`,{type:t,"data-slot":`input`,className:H(`h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none selection:bg-primary selection:text-primary-foreground file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:bg-input/30`,`focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50`,`aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40`,e),...n})}function sm({...e}){return(0,S.jsx)(fc,{"data-slot":`sheet`,...e})}function cm({...e}){return(0,S.jsx)(gc,{"data-slot":`sheet-portal`,...e})}function lm({className:e,...t}){return(0,S.jsx)(vc,{"data-slot":`sheet-overlay`,className:H(`fixed inset-0 z-50 bg-black/15 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0`,e),...t})}function um({className:e,children:t,side:n=`right`,showCloseButton:r=!0,...i}){return(0,S.jsxs)(cm,{children:[(0,S.jsx)(lm,{}),(0,S.jsxs)(Sc,{"data-slot":`sheet-content`,className:H(`fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:animate-in data-[state=open]:duration-200`,n===`right`&&`inset-y-0 right-0 h-full w-full border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-[440px]`,n===`left`&&`inset-y-0 left-0 h-full w-full border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-[440px]`,n===`top`&&`inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top`,n===`bottom`&&`inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom`,e),...i,children:[t,r&&(0,S.jsxs)(jc,{className:`absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-secondary`,children:[(0,S.jsx)(qn,{className:`size-4`}),(0,S.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function dm({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`sheet-header`,className:H(`flex flex-col gap-1.5 p-4`,e),...t})}function fm({className:e,...t}){return(0,S.jsx)(Dc,{"data-slot":`sheet-title`,className:H(`font-semibold text-foreground`,e),...t})}function pm({className:e,...t}){return(0,S.jsx)(kc,{"data-slot":`sheet-description`,className:H(`text-sm text-muted-foreground`,e),...t})}function mm({...e}){return(0,S.jsx)(fc,{"data-slot":`dialog`,...e})}function hm({...e}){return(0,S.jsx)(gc,{"data-slot":`dialog-portal`,...e})}function gm({className:e,...t}){return(0,S.jsx)(vc,{"data-slot":`dialog-overlay`,className:H(`fixed inset-0 z-50 bg-black/15 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0`,e),...t})}function _m({className:e,children:t,showCloseButton:n=!0,...r}){return(0,S.jsxs)(hm,{"data-slot":`dialog-portal`,children:[(0,S.jsx)(gm,{}),(0,S.jsxs)(Sc,{"data-slot":`dialog-content`,className:H(`fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg`,e),...r,children:[t,n&&(0,S.jsxs)(jc,{"data-slot":`dialog-close`,className:`absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,children:[(0,S.jsx)(qn,{}),(0,S.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function vm({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`dialog-header`,className:H(`flex flex-col gap-2 text-center sm:text-left`,e),...t})}function ym({className:e,showCloseButton:t=!1,children:n,...r}){return(0,S.jsxs)(`div`,{"data-slot":`dialog-footer`,className:H(`flex flex-col-reverse gap-2 sm:flex-row sm:justify-end`,e),...r,children:[n,t&&(0,S.jsx)(jc,{asChild:!0,children:(0,S.jsx)($,{variant:`outline`,children:`Close`})})]})}function bm({className:e,...t}){return(0,S.jsx)(Dc,{"data-slot":`dialog-title`,className:H(`text-lg leading-none font-semibold`,e),...t})}function xm({className:e,...t}){return(0,S.jsx)(kc,{"data-slot":`dialog-description`,className:H(`text-sm text-muted-foreground`,e),...t})}var Sm=Qn(`relative grid w-full grid-cols-[0_1fr] items-start gap-y-0.5 rounded-lg border px-4 py-3 text-sm has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] has-[>svg]:gap-x-3 [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current`,{variants:{variant:{default:`bg-card text-card-foreground`,destructive:`bg-card text-destructive *:data-[slot=alert-description]:text-destructive/90 [&>svg]:text-current`}},defaultVariants:{variant:`default`}});function Cm({className:e,variant:t,...n}){return(0,S.jsx)(`div`,{"data-slot":`alert`,role:`alert`,className:H(Sm({variant:t}),e),...n})}function wm({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`alert-description`,className:H(`col-start-2 grid justify-items-start gap-1 text-sm text-muted-foreground [&_p]:leading-relaxed`,e),...t})}function Tm({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`skeleton`,className:H(`animate-pulse rounded-md bg-accent`,e),...t})}function Em({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`empty`,className:H(`flex min-w-0 flex-1 flex-col items-center justify-center gap-6 rounded-lg border-dashed p-6 text-center text-balance md:p-12`,e),...t})}function Dm({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`empty-header`,className:H(`flex max-w-sm flex-col items-center gap-2 text-center`,e),...t})}function Om({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`empty-title`,className:H(`text-lg font-medium tracking-tight`,e),...t})}function km({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`empty-description`,className:H(`text-sm/relaxed text-muted-foreground [&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary`,e),...t})}function Am(e){return{dsp_view_scope:`Exit this DSP to use platform controls or switch accounts.`,dsp_view_unavailable:`This DSP view expired or is no longer available. Open it again from DSPs.`,dsp_view_changed:`The DSP view changed. Refresh to load the current workspace.`,invalid_input:`Check the fields and use a valid station code and business timezone.`,container_provisioning_required:`DSP provisioning is not configured on this server. Contact the platform operator.`,native_migration_required:`Finish migrating or removing existing legacy DSPs before starting this update.`,organization_details_required:`Finish your DSP details before continuing setup.`,organization_details_complete:`Your DSP details have already been saved.`,update_unavailable:`This update is no longer available. Refresh and try again.`,rollout_in_progress:`A rollout is already in progress.`,rollout_empty:`Create a DSP before starting a rollout.`,rollout_not_active:`There is no active rollout to change.`,invalid_credentials:`The email address or password was not accepted.`,password_reset_invalid:`This reset link is invalid or has expired. Request a new link to continue.`,password_recovery_rate_limited:`Too many recovery attempts. Please try again in 15 minutes.`,password_recovery_busy:`Password recovery is busy. Please try again shortly.`,password_recovery_unavailable:`Password recovery is temporarily unavailable. Please contact your Dispatch administrator.`,turnstile_required:`Complete the security check before continuing.`,turnstile_invalid:`The security check was not accepted. Please verify again and retry.`,turnstile_unavailable:`Security verification is temporarily unavailable. Please try again shortly.`,login_rate_limited:`Too many sign-in attempts. Wait before trying again.`,invitation_invalid:`This invitation is invalid, expired, revoked, or already used.`,invitation_email_mismatch:`Sign in with the exact email address named by this invitation.`,password_policy_failed:`Use a password containing at least 12 characters.`,password_confirmation_mismatch:`The password confirmation does not match.`,user_already_belongs_to_dsp:`This user already belongs to another DSP.`,current_password_invalid:`The current password was not accepted.`,password_unchanged:`Choose a new password that differs from the current password.`,account_exists:`An account already exists for this invitation. Sign in instead.`,invitation_pending:`A pending invitation already exists for that email.`,membership_exists:`That user already belongs to this DSP.`,conflict:`That name or account is already in use.`,role_in_use:`Move all members off this role before deleting it.`,fixed_roles_only:`DSP roles are fixed to Owner, Manager, Dispatcher, and Driver.`,last_owner_protected:`Assign another Owner before changing or removing the last Owner.`,system_role_protected:`System roles are protected and cannot be changed.`,role_not_assignable:`Choose a standard role from this DSP.`,self_role_change_forbidden:`You cannot change your own role.`,organization_forbidden:`Your account does not have permission for that DSP.`,workforce_changed:`The employee list changed while loading. Please retry.`,workforce_unavailable:`Workforce data is temporarily unavailable. Please retry.`,not_initialized:`Paycom has not collected workforce data yet.`,employee_not_found:`This employee is no longer in the collected roster.`,paycom_credentials_invalid:`Complete all Paycom fields and enter five distinct security PINs in their original Paycom numbering.`,confirmation_mismatch:`Type the DSP name exactly as displayed to confirm.`,primary_credentials_rejected:`Paycom did not accept the client code, username or password.`,security_answers_rejected:`Paycom did not accept the security PINs.`,attempt_cooldown:`Paycom setup is waiting for the authentication cooldown. Retry after it clears.`,profile_locked:`This Paycom profile is locked. Review the failure before replacing its credentials.`,provider_setup_failed:`Paycom setup could not complete. Review your details and retry.`,profile_exists:`Paycom credentials are already saved. Select replacement only if you intend to change them.`,captcha_required:`Paycom needs verification. Contact the Platform Owner.`,manual_verification_required:`Paycom needs verification. Contact the Platform Owner.`,mfa_required:`Paycom requires additional verification. Resolve it with your authorized Paycom administrator before retrying.`,account_locked:`Paycom reports that the account is locked. Resolve the lock before retrying.`,setup_interrupted:`Setup was interrupted. Review your details and retry.`,platform_forbidden:`You do not have permission to manage DSP installations.`,platform_control_invalid:`This control expired or belongs to another session. Refresh and try again.`,installation_operator_disabled:`DSP provisioning is not enabled on this server. Server setup must be completed before creating DSPs or starting updates.`,invitation_email_unavailable:`Invitation email is not configured on this server. No invitation was sent. Contact the platform owner to finish email setup.`,dashboard_unavailable:`Dispatch is temporarily unavailable. Refresh to check whether your request completed before trying again.`,installation_revision_conflict:`The installation changed in another session. Refresh before trying again.`,installation_operation_in_progress:`An installation operation is already in progress. Its status will keep updating.`,installation_operation_not_allowed:`This installation cannot be changed from its current state.`,installation_operation_not_found:`That installation operation is no longer available. Refresh the status.`,idempotency_conflict:`This request was reused for different input. Refresh and try again.`,installation_not_ready:`This DSP runtime is not ready yet. Operational data will be available after setup completes.`,provider_auth_required:`Paycom access needs attention. Contact the platform owner for assistance.`,first_publication_failed:`Private runtime verification did not complete. Contact the platform operator.`,runtime_boundary_violation:`The private runtime could not be verified. Contact the platform operator.`}[typeof e==`string`?e:e instanceof Jt?e.code:``]||`The request could not be completed. Please try again.`}function jm(e){if(typeof e!=`string`||!e||e.length>64)return!1;try{return new Intl.DateTimeFormat(void 0,{timeZone:e}).format(0),!0}catch{return!1}}function Mm(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||`UTC`}catch{return`UTC`}}function Nm(e,t=Mm()){let n=e instanceof Date?e:new Date(e);return Number.isFinite(n.valueOf())?new Intl.DateTimeFormat(void 0,{year:`numeric`,month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`,timeZoneName:`short`,timeZone:t}).format(n):`—`}function Pm(e,t=new Date){let n=Object.fromEntries(new Intl.DateTimeFormat(`en-CA`,{timeZone:e,year:`numeric`,month:`2-digit`,day:`2-digit`}).formatToParts(t).map(e=>[e.type,e.value]));return`${n.year}-${n.month}-${n.day}`}function Fm(e){if(!/^\d{4}-\d{2}-\d{2}$/.test(e))throw Error(`invalid_calendar_date`);let t=new Date(`${e}T12:00:00Z`);if(!Number.isFinite(t.valueOf())||t.toISOString().slice(0,10)!==e)throw Error(`invalid_calendar_date`);return t}function Im(e,t){if(!Number.isInteger(t))throw Error(`invalid_calendar_date`);let n=Fm(e);return n.setUTCDate(n.getUTCDate()+t),n.toISOString().slice(0,10)}function Lm(e){return new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,year:`numeric`,timeZone:`UTC`}).format(Fm(e))}function Rm(e){let t=$p().themePack.components?.PageHeading||zm;return(0,S.jsx)(t,{...e})}function zm({title:e,description:t,children:n}){return(0,S.jsxs)(`div`,{className:`page-heading`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h1`,{tabIndex:-1,children:e}),t&&(0,S.jsx)(`p`,{children:t})]}),n&&(0,S.jsx)(`div`,{className:`page-actions`,children:n})]})}function Bm({label:e,description:t,...n}){let r=(0,x.useId)();return(0,S.jsxs)(rm,{"data-disabled":n.disabled,children:[(0,S.jsx)(im,{htmlFor:r,children:e}),(0,S.jsx)(om,{id:r,...n}),t&&(0,S.jsx)(am,{children:t})]})}function Vm({children:e,error:t=!1}){return(0,S.jsx)(Cm,{variant:t?`destructive`:`default`,role:t?`alert`:`status`,className:`my-4`,children:(0,S.jsx)(wm,{children:e})})}function Hm({error:e}){return e?(0,S.jsx)(Vm,{error:!0,children:Am(e)}):null}function Um(){return(0,S.jsxs)(`div`,{className:`flex flex-col gap-5 py-8`,role:`status`,"aria-label":`Loading`,children:[(0,S.jsx)(Tm,{className:`h-6 w-48`}),[0,1,2].map(e=>(0,S.jsx)(Tm,{className:`h-12 w-full`},e))]})}function Wm({title:e,description:t}){return(0,S.jsx)(Em,{children:(0,S.jsxs)(Dm,{children:[(0,S.jsx)(Om,{children:e}),t&&(0,S.jsx)(km,{children:t})]})})}function Gm({onClick:e,busy:t=!1}){return(0,S.jsx)($,{variant:`outline`,size:`icon`,"aria-label":`Refresh`,disabled:t,onClick:e,children:(0,S.jsx)(Vn,{"data-icon":`inline-start`,className:H(t&&`animate-spin`)})})}function Km({value:e,onChange:t,placeholder:n}){return(0,S.jsxs)(`label`,{className:`search-input`,children:[(0,S.jsx)(Hn,{"aria-hidden":`true`}),(0,S.jsx)(om,{type:`search`,"aria-label":n,placeholder:n,value:e,onChange:e=>t(e.target.value)})]})}function qm({busy:e,children:t,...n}){return(0,S.jsxs)($,{type:`submit`,disabled:e,...n,children:[e&&(0,S.jsx)(Nn,{"data-icon":`inline-start`,className:`animate-spin`}),t]})}function Jm({value:e,children:t}){return(0,S.jsxs)(`span`,{className:H(`status`,`status-${e.replaceAll(`_`,`-`)}`),children:[(0,S.jsx)(`span`,{"aria-hidden":`true`}),t||e.replaceAll(`_`,` `)]})}function Ym({open:e,onClose:t,title:n,description:r,children:i,busy:a=!1}){let o=(0,x.useRef)(null);return(0,S.jsx)(sm,{open:e,onOpenChange:e=>{!e&&!a&&t()},children:(0,S.jsxs)(um,{showCloseButton:!a,onOpenAutoFocus:()=>{o.current=document.activeElement},onCloseAutoFocus:e=>{e.preventDefault(),o.current?.isConnected?o.current.focus():document.querySelector(`.page-heading h1`)?.focus()},children:[(0,S.jsxs)(dm,{children:[(0,S.jsx)(fm,{children:n}),(0,S.jsx)(pm,{children:r||`Review details and manage access.`})]}),i]})})}function Xm({title:e,description:t,confirmation:n,passwordRequired:r=!1,onConfirm:i,onClose:a}){let[o,s]=(0,x.useState)(``),[c,l]=(0,x.useState)(!1),[u,d]=(0,x.useState)(null);return(0,S.jsx)(mm,{open:!0,onOpenChange:e=>{!e&&!c&&a()},children:(0,S.jsxs)(_m,{showCloseButton:!c,children:[(0,S.jsxs)(vm,{children:[(0,S.jsx)(bm,{children:e}),(0,S.jsx)(xm,{children:t})]}),(0,S.jsxs)(`form`,{onSubmit:async e=>{if(e.preventDefault(),!(n&&o!==n)){l(!0),d(null);try{await i(r?o:void 0),a()}catch(e){r&&s(``),d(e)}finally{l(!1)}}},className:`flex flex-col gap-5`,children:[r&&(0,S.jsx)(Bm,{label:`Your password`,type:`password`,autoComplete:`current-password`,value:o,onChange:e=>s(e.target.value),required:!0,disabled:c}),n&&(0,S.jsx)(Bm,{label:`Type ${n} to confirm`,value:o,onChange:e=>s(e.target.value),autoComplete:`off`,disabled:c,required:!0}),(0,S.jsx)(Hm,{error:u}),(0,S.jsxs)(ym,{children:[(0,S.jsx)($,{type:`button`,variant:`outline`,disabled:c,onClick:a,children:`Cancel`}),(0,S.jsx)(qm,{busy:c,variant:`destructive`,disabled:c||!!(n&&o!==n)||r&&!o,children:e})]})]})]})})}function Zm({result:e}){if(!e)return null;let t=e.ownerInvitation?.email||e.invitation?.email||`the recipient`;if(e.delivery?.status===`accepted`)return(0,S.jsxs)(Vm,{children:[`Invitation sent to `,t,`.`]});if(!e.invitationPath)return(0,S.jsx)(Vm,{children:`The invitation request was already processed. No new invitation was sent.`});let n=new URL(e.invitationPath,window.location.origin).href;return(0,S.jsx)(Vm,{children:(0,S.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,S.jsx)(`p`,{children:e.delivery?.status===`unknown`?`Email delivery could not be confirmed. Use this same link if a private handoff is needed.`:e.delivery?.status===`failed`?`The invitation email could not be sent. Share this one-time invitation through a private channel.`:`No email was sent because invitation email is not configured. Share this one-time invitation through a private channel.`}),(0,S.jsx)(om,{"aria-label":`Invitation link`,value:n,readOnly:!0,onFocus:e=>e.target.select()}),(0,S.jsx)($,{variant:`outline`,onClick:()=>navigator.clipboard.writeText(n).catch(()=>{}),children:`Copy link`})]})})}function Qm(e){let t=e.toLocaleUpperCase(`en-US`).match(/[\p{L}\p{N}]+/gu)||[];return{initials:t.length>1?`${[...t[0]][0]}${[...t[1]][0]}`:[...t[0]||`?`].slice(0,2).join(``),className:`dsp-avatar tone-${[...t.join(` `)].reduce((e,t)=>e*31+t.codePointAt(0)>>>0,0)%5}`}}var $m=e=>`dispatch:timezone:v1:${e}`;function eh(e){try{let t=e?JSON.parse(localStorage.getItem($m(e))||`null`):null;return jm(t?.timeZone)?t.timeZone:null}catch{return null}}var th=(0,x.createContext)(null);function nh({userId:e,children:t}){let[n,r]=(0,x.useState)(()=>({userId:e,preference:eh(e),storageUnavailable:!1}));n.userId!==e&&r({userId:e,preference:eh(e),storageUnavailable:!1});let[i,a]=(0,x.useState)(Mm);(0,x.useEffect)(()=>{let e=()=>a(Mm()),t=window.setInterval(e,6e4);return window.addEventListener(`focus`,e),document.addEventListener(`visibilitychange`,e),()=>{clearInterval(t),window.removeEventListener(`focus`,e),document.removeEventListener(`visibilitychange`,e)}},[]),(0,x.useEffect)(()=>{if(!e)return;let t=t=>{(t.key===null||t.key===$m(e))&&r(t=>t.userId===e?{...t,preference:eh(e)}:t)};return window.addEventListener(`storage`,t),()=>window.removeEventListener(`storage`,t)},[e]);function o(t){if(!e||t!==null&&!jm(t))return;let n=!1;try{localStorage.setItem($m(e),JSON.stringify({timeZone:t}))}catch{n=!0}r({userId:e,preference:t,storageUnavailable:n})}return(0,S.jsx)(th.Provider,{value:{timeZone:n.preference||i,deviceZone:i,preference:n.preference,setPreference:o,storageUnavailable:n.storageUnavailable},children:t})}function rh(){let e=(0,x.useContext)(th);if(!e)throw Error(`TimezoneProvider is required`);return e}function ih(e){let[t,n]=(0,x.useState)(Date.now);return(0,x.useEffect)(()=>{let e=()=>n(Date.now()),t=window.setInterval(e,3e4);return window.addEventListener(`focus`,e),document.addEventListener(`visibilitychange`,e),()=>{clearInterval(t),window.removeEventListener(`focus`,e),document.removeEventListener(`visibilitychange`,e)}},[]),Pm(e,t)}var ah={timeZone:void 0,dspIdentity:Qm,byId:e=>document.getElementById(e),node:(e,t,n)=>{let r=document.createElement(e);return t&&(r.className=t),n!==void 0&&(r.textContent=String(n)),r},mutation:rn,request:nn,mutationKey:on,settleMutationKey:sn,errorMessage:Am};function oh({page:e,hash:t}){let{timeZone:n}=rh(),r=(0,x.useMemo)(()=>e===`updates`?window.createUpdatesViews({...ah,timeZone:n}):window.createBackupsViews({...ah,timeZone:n}),[e,n]),[i,a]=(0,x.useState)(null),o=()=>`renderUpdates`in r?r.renderUpdates():r.renderBackups();return(0,x.useEffect)(()=>(window.showToast=(e,t,n)=>a({text:[e,t].filter(Boolean).join(`. `),error:n===`error`}),`setUpdatesActive`in r?r.setUpdatesActive(!0):r.setBackupsActive(!0),o(),()=>{`setUpdatesActive`in r?r.setUpdatesActive(!1):r.setBackupsActive(!1),delete window.showToast}),[r,t]),(0,S.jsxs)(S.Fragment,{children:[e===`updates`&&(0,S.jsx)(Rm,{title:`Updates`,description:`Explore what’s new in Dispatch.`,children:(0,S.jsx)(Gm,{onClick:()=>void o()})}),i&&(0,S.jsx)(Vm,{error:i.error,children:i.text}),(0,S.jsx)(`div`,{id:e===`updates`?`platform-updates-content`:`platform-backups-content`,className:e===`updates`?`updates-workspace`:`backup-workspace`})]})}var sh={release_changed:`A newer release is available. Review it and try again.`,release_dev_required:`Install the latest release on Dev before starting rollout.`,release_dsp_not_ready:`This DSP needs to be running and finish setup before it can be updated.`,release_health_failed:`Health checks failed. The previous version was restored.`,release_recovery_required:`The update needs recovery before another update can start.`,release_interrupted:`The update worker restarted. Review the state before continuing.`,release_baseline_required:`The installed version must be registered before updates can begin.`,release_fleet_changed:`The DSP list changed. Review it and start rollout again.`,release_verification_failed:`The release could not be verified. Check the worker’s GitHub connection and retry.`};function ch({hash:e}){let[t,n]=(0,x.useState)(`core`),[r,i]=(0,x.useState)(null),[a,o]=(0,x.useState)(!1),[s,c]=(0,x.useState)(null),l=Mt({queryKey:[`independent-updates`,r],queryFn:()=>nn(`/api/platform/updates${r?`?releaseId=${encodeURIComponent(r)}`:``}`),refetchInterval:3e3}),u=l.data,d=(0,x.useRef)(void 0),f=u?.tracks?.core.installedDigest;if((0,x.useEffect)(()=>{if(u?.mode!==`independent`)return;let e=d.current;d.current=f,e!==void 0&&f&&e!==f&&window.location.reload()},[u?.mode,f]),u&&u.mode!==`independent`)return(0,S.jsx)(oh,{page:`updates`,hash:e});async function p(e,n=null){if(!a){o(!0),c(null);try{await cn(`updates:${e}:${t}:${n}`,`/api/platform/updates`,{action:e,product:t,digest:n}),await Yt.invalidateQueries({queryKey:[`independent-updates`]})}catch(e){c(e)}finally{o(!1)}}}let m=u?.jobs.find(e=>[`queued`,`running`].includes(e.status)),h=u?.jobs[0]?.status===`failed`?u.jobs[0].failure:null,g=m?.action===`update_core`||u?.operation?.product===`core`;return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Rm,{title:`Updates`,description:`Choose when Core and your DSPs receive new releases.`,children:(0,S.jsxs)($,{variant:`outline`,disabled:a||u?.busy||!u?.worker.available,onClick:()=>void p(`refresh`),children:[(0,S.jsx)(Vn,{"aria-hidden":`true`}),`Check for updates`]})}),(0,S.jsx)(Hm,{error:s||(g?null:l.error)}),g&&(0,S.jsx)(Vm,{children:`Core is updating. This page will reconnect when it’s ready.`}),l.isPending?(0,S.jsx)(Um,{}):u?(0,S.jsxs)(`div`,{className:`space-y-5`,id:`platform-updates-content`,children:[!u.enabled&&(0,S.jsx)(Vm,{children:`Updates need initial setup. Your current services will continue running.`}),u.enabled&&!u.worker.available&&(0,S.jsx)(Vm,{error:!0,children:`The update worker is offline. Releases remain available to read.`}),h&&(0,S.jsx)(Vm,{error:!0,children:sh[h]||`The update could not finish. Review the current state, then retry or recover.`}),u.operation&&!g&&(0,S.jsxs)(Vm,{children:[u.operation.dspName||`Dev DSP`,` is updating. Private data is being preserved.`]}),u.recoveryRequired&&!m&&(0,S.jsxs)(`div`,{className:`rounded-xl border bg-card p-5 space-y-3`,children:[(0,S.jsx)(`p`,{children:`Recover the interrupted update before installing another release.`}),(0,S.jsx)($,{disabled:a||!u.worker.available,onClick:()=>void p(`recover`),children:`Recover update`})]}),(0,S.jsxs)(Fp,{value:t,onValueChange:e=>{n(e),i(null),c(null)},children:[(0,S.jsxs)(Lp,{"aria-label":`Update products`,children:[(0,S.jsxs)(Rp,{value:`core`,children:[(0,S.jsx)(Un,{"aria-hidden":`true`}),`Core`]}),(0,S.jsxs)(Rp,{value:`dsp`,children:[(0,S.jsx)(jn,{"aria-hidden":`true`}),`DSPs`]})]}),[`core`,`dsp`].map(e=>{let t=u.tracks[e],n=t.release,r=!!(n&&n.digest===t.latest),o=u.rollout&&u.rollout.status!==`completed`,s=e===`core`?`update_core`:t.tested?`rollout`:`update_dev`,c=e===`core`?`Update Core`:t.tested?`Rollout Update`:`Update Dev`;return(0,S.jsxs)(zp,{value:e,className:`space-y-5 pt-3`,children:[(0,S.jsxs)(`section`,{className:`rounded-xl border bg-card p-6 space-y-5`,"aria-label":`${e===`core`?`Core`:`DSP`} release`,children:[(0,S.jsxs)(`div`,{className:`flex flex-wrap justify-between items-start gap-4`,children:[(0,S.jsxs)(`div`,{className:`space-y-1`,children:[(0,S.jsx)(`h2`,{className:`text-xl font-semibold`,children:e===`core`?`Dispatch Core`:`DSP runtime and plugins`}),(0,S.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[e===`core`?`Installed`:`Installed on ${u.dev.name}`,`: `,t.installedVersion||`Not registered`]})]}),(0,S.jsxs)($,{disabled:a||!t.canUpdate||!r||e===`dsp`&&(!u.dev.available||!!o),onClick:()=>void p(s,t.latest),children:[(0,S.jsx)(Dn,{"aria-hidden":`true`}),c]})]}),(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e===`core`?`Updates the shared dashboard, API and Core services. Installed DSP runtimes and plugins keep their current versions.`:t.tested?`Dev has passed installation checks. Test the changes, then roll this version out to your DSPs one at a time.`:`Install this version on the permanent Dev DSP first. Your other DSPs receive it when you start rollout.`}),(0,S.jsxs)(`div`,{className:`border-t pt-5 space-y-4`,children:[t.history.length>0&&(0,S.jsxs)(`label`,{className:`flex flex-wrap items-center gap-3 text-sm font-medium`,children:[`Release history`,(0,S.jsx)(`select`,{"aria-label":`${e===`core`?`Core`:`DSP`} release history`,value:n?.id||``,onChange:e=>i(e.target.value),className:`rounded-md border bg-background px-3 py-2 max-w-full`,children:t.history.map(e=>(0,S.jsxs)(`option`,{value:e.id,children:[`Version `,e.version]},e.id))})]}),n?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`flex flex-wrap justify-between gap-3 items-baseline`,children:[(0,S.jsxs)(`h3`,{className:`text-lg font-semibold`,children:[`Version `,n.version]}),n.url&&(0,S.jsx)(`a`,{className:`text-sm underline underline-offset-4`,href:n.url,target:`_blank`,rel:`noreferrer`,children:`View release on GitHub`})]}),(0,S.jsx)(`div`,{className:`whitespace-pre-wrap break-words text-sm leading-7`,"aria-label":`Changelog`,children:n.notes}),!r&&(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`You’re reading a previous release. Select the latest version to update.`})]}):(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No verified releases yet.`})]})]}),e===`dsp`&&u.rollout&&(0,S.jsxs)(`section`,{className:`rounded-xl border bg-card p-6 space-y-4`,"aria-label":`Rollout progress`,children:[(0,S.jsxs)(`div`,{className:`flex flex-wrap justify-between gap-3 items-center`,children:[(0,S.jsxs)(`h2`,{className:`text-lg font-semibold`,children:[`Rollout · `,u.rollout.version]}),u.rollout.status===`running`&&(0,S.jsxs)($,{variant:`outline`,disabled:a||!u.worker.available,onClick:()=>void p(`pause`),children:[(0,S.jsx)(In,{"aria-hidden":`true`}),`Pause rollout`]}),u.rollout.status===`paused`&&(0,S.jsxs)($,{disabled:a||u.recoveryRequired||!u.worker.available||!!m,onClick:()=>void p(`resume`),children:[(0,S.jsx)(Ln,{"aria-hidden":`true`}),`Resume rollout`]})]}),(0,S.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[u.rollout.updated,` of `,u.rollout.total,` DSPs updated · `,u.rollout.status]}),u.rollout.status===`paused`&&(0,S.jsx)(Vm,{children:`The rollout is paused. Resolve the affected DSP before resuming this version.`}),(0,S.jsx)(`progress`,{"aria-label":`DSPs updated`,value:u.rollout.updated,max:Math.max(1,u.rollout.total),className:`w-full accent-primary`}),(0,S.jsx)(`ul`,{className:`divide-y`,children:u.rollout.members.map((e,t)=>(0,S.jsxs)(`li`,{className:`flex justify-between gap-4 py-3 text-sm`,children:[(0,S.jsx)(`span`,{children:e.name}),(0,S.jsx)(`span`,{className:`text-muted-foreground`,children:e.status})]},t))})]})]},e)})]})]}):null]})}function lh(){return(0,S.jsxs)(`span`,{className:`brand`,children:[(0,S.jsx)(`svg`,{viewBox:`0 0 28 28`,"aria-hidden":`true`,children:(0,S.jsx)(`path`,{fill:`currentColor`,d:`M3 3h9C20 3 25 7.5 25 14s-5 11-13 11H3v-7h6v2h3c4.5 0 7-2.2 7-6s-2.5-6-7-6H9v6H3V3Z`})}),(0,S.jsx)(`span`,{children:`Dispatch`})]})}var uh=null;function dh(){return window.turnstile?Promise.resolve(window.turnstile):uh||(uh=new Promise((e,t)=>{let n=document.createElement(`script`);n.src=`https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit`,n.async=!0;let r=()=>{clearTimeout(i),n.onload=null,n.onerror=null,n.remove(),t(Error(`turnstile_unavailable`))},i=window.setTimeout(r,15e3);n.onerror=r,n.onload=()=>{if(!window.turnstile)return r();clearTimeout(i),n.onload=null,n.onerror=null,e(window.turnstile)},document.head.appendChild(n)}).catch(e=>{throw uh=null,e}),uh)}function fh({siteKey:e,action:t,onToken:n,busy:r}){let i=(0,x.useRef)(null),[a,o]=(0,x.useState)(0),[s,c]=(0,x.useState)(`checking`);return(0,x.useEffect)(()=>{let r=!1,a,o;n(``),c(`checking`);let s=e=>{r||(n(``),c(e))};return dh().then(l=>{!r&&i.current&&(a=l,o=a.render(i.current,{sitekey:e,action:t,size:`flexible`,"response-field":!1,callback:e=>{r||(n(e),c(`ready`))},"error-callback":()=>s(`error`),"expired-callback":()=>s(`expired`),"timeout-callback":()=>s(`expired`),"unsupported-callback":()=>s(`error`)}))}).catch(()=>s(`error`)),()=>{r=!0,o!==void 0&&a?.remove(o)}},[e,t,a,n]),(0,S.jsxs)(`div`,{className:`min-w-0 space-y-2`,"aria-label":`Security verification`,children:[(0,S.jsx)(`div`,{ref:i}),(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,role:`status`,"aria-live":`polite`,children:s===`checking`?`Checking your browser…`:s===`ready`?`Security check complete.`:s===`expired`?`Security check expired. Please verify again.`:`Security check could not load. Check your connection and try again.`}),(s===`error`||s===`expired`)&&(0,S.jsx)($,{type:`button`,variant:`outline`,disabled:r,onClick:()=>o(e=>e+1),children:`Retry security check`})]})}function ph({hash:e,session:t,refresh:n}){let r=e===`#/forgot-password`,[i,a]=(0,x.useState)(()=>/^#\/reset-password\/([A-Za-z0-9_-]{43})$/.exec(e)?.[1]||``),[o,s]=(0,x.useState)(!1),[c,l]=(0,x.useState)(null),[u,d]=(0,x.useState)(``),[f,p]=(0,x.useState)(``),[m,h]=(0,x.useState)(0),g=r?t?.turnstile?.siteKey:null;(0,x.useEffect)(()=>{r||history.replaceState(null,``,`${location.pathname}#/reset-password`)},[r]);async function _(e){if(e.preventDefault(),o||g&&!f)return;let t=e.currentTarget,c=new FormData(t);s(!0),l(null);try{let e=await fetch(r?`/api/auth/forgot-password`:`/api/auth/reset-password`,{method:`POST`,credentials:`omit`,cache:`no-store`,referrerPolicy:`no-referrer`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({...Object.fromEntries(c),...r?g?{turnstileToken:f}:{}:{token:i}})}),o=await e.json().catch(()=>null);if(!e.ok||!o?.ok)throw new Jt(o?.error?.code||`request_failed`,e.status);t.reset(),d(o.data.message),r||(a(``),n().catch(()=>{}))}catch(e){l(e)}finally{s(!1),p(``),h(e=>e+1)}}return(0,S.jsxs)(`main`,{className:`auth-layout`,children:[(0,S.jsx)(`div`,{className:`auth-brand`,children:(0,S.jsx)(lh,{})}),(0,S.jsxs)(`section`,{className:`auth-panel`,children:[(0,S.jsx)(`h1`,{children:u?r?`Check your email`:`Password reset`:r?`Forgot your password?`:`Set a new password`}),(0,S.jsx)(`p`,{className:`auth-description`,children:r?`Enter your Dispatch account email and we’ll send you a reset link.`:`Choose a password you haven’t used elsewhere.`}),(0,S.jsx)(Hm,{error:c}),u?(0,S.jsx)(Vm,{children:u}):!r&&!i?(0,S.jsx)(Vm,{children:`This reset link is invalid or has expired. Request a new link to continue.`}):(0,S.jsx)(`form`,{onSubmit:_,children:(0,S.jsxs)(tm,{children:[r?(0,S.jsx)(Bm,{label:`Email address`,name:`email`,type:`email`,autoComplete:`username`,required:!0,maxLength:254,disabled:o}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Bm,{label:`New password`,name:`newPassword`,type:`password`,autoComplete:`new-password`,required:!0,minLength:12,maxLength:128,disabled:o,description:`Use 12–128 characters.`}),(0,S.jsx)(Bm,{label:`Confirm new password`,name:`confirmPassword`,type:`password`,autoComplete:`new-password`,required:!0,minLength:12,maxLength:128,disabled:o})]}),g&&(0,S.jsx)(fh,{siteKey:g,action:`forgot_password`,onToken:p,busy:o},m),(0,S.jsx)(qm,{busy:o,disabled:o||!(!g||f),children:r?`Send reset link`:`Reset password`})]})}),(0,S.jsxs)(`div`,{className:`mt-6 flex flex-wrap gap-4 text-sm text-primary`,children:[(0,S.jsx)(`a`,{className:`underline-offset-4 hover:underline`,href:`#/login`,children:`Back to sign in`}),!r&&(0,S.jsx)(`a`,{className:`underline-offset-4 hover:underline`,href:`#/forgot-password`,children:`Request a new link`})]})]}),(0,S.jsx)(`p`,{className:`auth-footnote`,children:r?`Reset links expire after 30 minutes.`:`Resetting your password signs out your existing sessions.`})]})}function mh({navigation:e,mobileNavigation:t,banner:n,header:r,children:i}){return(0,S.jsxs)(`div`,{className:`application`,children:[(0,S.jsx)(`aside`,{className:`desktop-sidebar`,children:e}),t,(0,S.jsxs)(`div`,{className:`main-area`,children:[n,(0,S.jsx)(`header`,{className:`topbar`,children:r}),(0,S.jsx)(`main`,{id:`main-content`,className:`page-container`,tabIndex:-1,children:i})]})]})}var hh=(0,x.createContext)(null);function gh(){let e=(0,x.useContext)(hh);if(!e)throw Error(`Session required`);return e}var _h=Qn(`inline-flex w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-full border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3`,{variants:{variant:{default:`bg-primary text-primary-foreground [a&]:hover:bg-primary/90`,secondary:`bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90`,destructive:`bg-destructive text-white focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40 [a&]:hover:bg-destructive/90`,outline:`border-border text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground`,ghost:`[a&]:hover:bg-accent [a&]:hover:text-accent-foreground`,link:`text-primary underline-offset-4 [a&]:hover:underline`}},defaultVariants:{variant:`default`}});function vh({className:e,variant:t=`default`,asChild:n=!1,...r}){let i=n?Ai:`span`;return(0,S.jsx)(i,{"data-slot":`badge`,"data-variant":t,className:H(_h({variant:t}),e),...r})}function yh({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`table-container`,className:`relative w-full overflow-x-auto`,children:(0,S.jsx)(`table`,{"data-slot":`table`,className:H(`w-full caption-bottom text-sm`,e),...t})})}function bh({className:e,...t}){return(0,S.jsx)(`thead`,{"data-slot":`table-header`,className:H(`[&_tr]:border-b`,e),...t})}function xh({className:e,...t}){return(0,S.jsx)(`tbody`,{"data-slot":`table-body`,className:H(`[&_tr:last-child]:border-0`,e),...t})}function Sh({className:e,...t}){return(0,S.jsx)(`tr`,{"data-slot":`table-row`,className:H(`border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted`,e),...t})}function Ch({className:e,...t}){return(0,S.jsx)(`th`,{"data-slot":`table-head`,className:H(`h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]`,e),...t})}function wh({className:e,...t}){return(0,S.jsx)(`td`,{"data-slot":`table-cell`,className:H(`p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]`,e),...t})}var Th=o(((e,t)=>{var n=(e,t)=>JSON.stringify(e)===JSON.stringify(t);function r(e,t){return!e||n(t[e.field],e.equals)}function i(e,t){return(e.rules||[]).filter(e=>{if(!r(e.when,t))return!1;if(e.kind===`included`){let n=t[e.selection],r=t[e.field];return r!==null&&n!==null&&!n.includes(r)}return!r(e.require,t)}).map(e=>({id:e.id,field:e.field||e.require.field,severity:e.severity,message:e.message}))}function a(e,t,n={}){if(t===void 0)return`Not recorded`;if(t===null)return`All current and future options`;if(typeof t==`boolean`)return t?`On`:`Off`;let r=e.options||n[e.optionsSource]||[],i=e=>r.find(t=>t.value===e)?.label||String(e);return Array.isArray(t)?t.length?t.map(i).join(`, `):`None`:i(t)}function o(e,t,r,i={}){let a=r.find(t=>t.id===e.field);if(e.kind===`choice`)return e.examples.find(e=>n(e.value,t[a.id]))?.text||``;if(e.kind===`columns`)return[e.leading,...(t[a.id]||[]).map(e=>(a.options||[]).find(t=>t.value===e)?.label||e)].filter(Boolean).join(` · `);let o=i[a.optionsSource]||[],s=t[a.id],c=s===null?o:o.filter(e=>s.includes(e.value));return`${c.reduce((e,t)=>e+(t.count||0),0)} ${e.unit} from ${c.length} ${e.groupLabel}.`}t.exports={same:n,conditionMatches:r,settingsIssues:i,formatSettingValue:a,settingsPreview:o,EFFECTS:Object.freeze({immediate:`Display changes take effect after saving.`,next_job:`Collection changes apply to new jobs. Running jobs keep their current settings.`,next_connection:`Changes apply to the next connection. An active connection keeps its current settings.`,schedule:`The schedule is updated after saving. Running collections are allowed to finish.`})}}))();function Eh({pluginId:e,scope:t,snapshot:n,busy:r,onRestore:i}){let[a,o]=(0,x.useState)([null]),s=a[a.length-1],{timeZone:c}=rh(),l=Mt({queryKey:[`plugin-settings`,e,t,`history`,n.revision,s],queryFn:({signal:t})=>nn(`/api/organization/plugins/${encodeURIComponent(e)}/settings/history${s===null?``:`?before=${s}`}`,{signal:t})});return(0,S.jsxs)(`section`,{className:`plugin-settings-history`,"aria-label":`Settings change history`,children:[(0,S.jsx)(`h2`,{children:`Change history`}),(0,S.jsx)(`p`,{children:`Restore values into your draft, then review and save. History belongs to this DSP.`}),(0,S.jsx)(Hm,{error:l.error}),l.isPending&&(0,S.jsx)(Um,{}),l.data?.items.map(e=>(0,S.jsxs)(`details`,{"data-revision":e.revision,children:[(0,S.jsxs)(`summary`,{children:[Nm(e.updatedAt,c),` ·`,` `,e.kind===`initial`?`Initial settings`:e.actorName||`Plugin update`,` `,`· Revision `,e.revision]}),e.changes.length?(0,S.jsx)(`ul`,{children:e.changes.map(e=>{let t=n.definition.fields.find(t=>t.id===e.field),r=e=>t?(0,Th.formatSettingValue)(t,e):JSON.stringify(e);return(0,S.jsxs)(`li`,{children:[(0,S.jsx)(`strong`,{children:e.label}),`: `,r(e.before),` →`,` `,r(e.after),e.beforeSource!==e.afterSource&&(0,S.jsxs)(`span`,{children:[` `,`(`,e.afterSource==="default"?`Plugin default`:`DSP override`,`)`]})]},e.field)})}):(0,S.jsx)(`p`,{children:`No values changed.`}),e.canRestore?(0,S.jsxs)(`div`,{className:`plugin-settings-history-actions`,children:[n.definition.sections.map(t=>(0,S.jsxs)($,{variant:`outline`,size:`sm`,disabled:r,onClick:()=>i(e.values,e.sources,n.definition.fields.filter(e=>e.section===t.id).map(e=>e.id)),children:[`Restore `,t.label]},t.id)),(0,S.jsxs)(`details`,{children:[(0,S.jsx)(`summary`,{children:`Restore an individual setting`}),n.definition.fields.map(t=>(0,S.jsxs)($,{variant:`ghost`,size:`sm`,disabled:r,onClick:()=>i(e.values,e.sources,[t.id]),children:[`Restore `,t.label]},t.id))]})]}):(0,S.jsx)(`p`,{children:`This entry predates the current settings definition and cannot be restored directly.`})]},e.revision)),(0,S.jsxs)(`div`,{className:`plugin-settings-history-pagination`,children:[(0,S.jsx)($,{variant:`outline`,disabled:a.length===1||l.isFetching,onClick:()=>o(e=>e.slice(0,-1)),children:`Newer changes`}),(0,S.jsx)($,{variant:`outline`,disabled:l.data?.nextBefore==null||l.isFetching,onClick:()=>o(e=>[...e,l.data.nextBefore]),children:`Older changes`})]})]})}function Dh(e,t=!1){let{session:n}=gh(),r=dn(n),i=`${n.user?.id}:${r?.organizationId}:${n.dspView?.viewRef||`member`}`,a=`${r?.organizationId}:${n.dspView?.viewRef||`member`}`,o=`/api/organization/plugins/${encodeURIComponent(e)}/settings`,s=[`plugin-settings`,e,i],c=w(),l=n.authenticated&&!!r;return{query:Mt({queryKey:s,queryFn:({signal:e})=>nn(o,{signal:e}),enabled:l,refetchInterval:15e3}),options:Mt({queryKey:[...s,`options`],queryFn:({signal:e})=>nn(`${o}/options`,{signal:e}),enabled:l&&t,staleTime:3e4}),update:Wt({mutationFn:({values:t,snapshot:n,sources:r})=>cn(`plugin-settings:${e}:${i}:${n.revision}`,o,{values:t,...r?{sources:r}:{},expectedRevision:n.revision,definitionVersion:n.definitionVersion}),onSuccess:async t=>{c.setQueryData(s,t),await c.invalidateQueries({predicate:t=>t.queryKey[0]!==`plugin-settings`&&String(t.queryKey[0]).startsWith(e+`-`)&&t.queryKey.some(e=>e===i||e===a)})}}),scope:i}}function Oh({field:e,value:t,options:n={},disabled:r=!1,onChange:i}){let a=e.options||e.optionsSource&&n[e.optionsSource]||[],o=`plugin-setting-${(0,x.useId)()}`;if(e.type===`boolean`)return(0,S.jsxs)(`div`,{className:`plugin-setting-toggle`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`label`,{htmlFor:o,children:e.label}),e.description&&(0,S.jsx)(`p`,{children:e.description})]}),(0,S.jsx)(`input`,{id:o,type:`checkbox`,role:`switch`,checked:t===!0,disabled:r,onChange:e=>i(e.target.checked)})]});if(e.type===`strings`){let n=t===null?a.map(e=>String(e.value)):t,o=new Map(a.map(e=>[String(e.value),e])),c=[...n,...a.map(e=>String(e.value)).filter(e=>!n.includes(e))];function s(e,t){i(t?[...n,e]:n.filter(t=>t!==e))}return(0,S.jsxs)(`fieldset`,{className:`plugin-setting-multiple`,disabled:r,children:[(0,S.jsx)(`legend`,{children:e.label}),e.description&&(0,S.jsx)(`p`,{children:e.description}),e.nullable&&(0,S.jsxs)(`label`,{className:`plugin-setting-choice`,children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:t===null,onChange:e=>i(e.target.checked?null:[...n])}),`Include all current and future options`]}),(0,S.jsx)(`div`,{className:`plugin-setting-choices`,children:c.map((a,c)=>{let l=o.get(a),u=n.includes(a);return(0,S.jsxs)(`div`,{className:`plugin-setting-option`,children:[(0,S.jsxs)(`label`,{className:`plugin-setting-choice`,children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:u,disabled:t===null,onChange:e=>s(a,e.target.checked)}),(0,S.jsx)(`span`,{children:l?.label||`${a} (not currently available)`}),l?.count!==void 0&&(0,S.jsx)(`span`,{className:`plugin-setting-count`,children:l.count})]}),e.ordered&&u&&(0,S.jsx)(`div`,{className:`plugin-setting-order`,children:[-1,1].map(e=>(0,S.jsx)($,{type:`button`,variant:`ghost`,size:`sm`,"aria-label":`Move ${l?.label||a} ${e<0?`earlier`:`later`}`,disabled:r||c+e<0||c+e>=n.length,onClick:()=>{let t=[...n];[t[c],t[c+e]]=[t[c+e],t[c]],i(t)},children:e<0?`↑`:`↓`},e))})]},a)})}),!c.length&&(0,S.jsx)(`p`,{children:`No options are available yet.`})]})}if(a.length||e.optionsSource){let n=t!==null&&!a.some(e=>String(e.value)===String(t));return(0,S.jsxs)(`div`,{className:`plugin-setting-field`,children:[(0,S.jsx)(`label`,{htmlFor:o,children:e.label}),(0,S.jsxs)(`select`,{id:o,value:t===null?``:String(t),disabled:r,onChange:t=>i(t.target.value===``&&e.nullable?null:e.type===`integer`?Number(t.target.value):t.target.value),children:[e.nullable&&(0,S.jsxs)(`option`,{value:``,children:[`All `,e.optionsSource||`options`]}),n&&(0,S.jsxs)(`option`,{value:String(t),children:[String(t),` (not currently available)`]}),a.map(e=>(0,S.jsx)(`option`,{value:String(e.value),children:e.label},String(e.value)))]}),e.description&&(0,S.jsx)(`p`,{children:e.description})]})}return(0,S.jsxs)(`div`,{className:`plugin-setting-field`,children:[(0,S.jsx)(`label`,{htmlFor:o,children:e.label}),(0,S.jsx)(`input`,{id:o,type:e.type===`integer`?`number`:`text`,value:String(t??``),min:e.minimum,max:e.maximum,maxLength:128,disabled:r,onChange:t=>i(e.type===`integer`?Number(t.target.value):t.target.value)}),e.description&&(0,S.jsx)(`p`,{children:e.description})]})}function kh({pluginId:e,title:t,description:n,backHref:r,renderSection:i}){let{session:a}=gh(),o=Dh(e,!0),[s,c]=(0,x.useState)(null),[l,u]=(0,x.useState)(null),[d,f]=(0,x.useState)(!1),[p,m]=(0,x.useState)({}),[h,g]=(0,x.useState)(!1),[_,v]=(0,x.useState)(``),[y,b]=(0,x.useState)([]),C=!!s&&(JSON.stringify(l)!==JSON.stringify(s.values)||JSON.stringify(p)!==JSON.stringify(s.sources));(0,x.useEffect)(()=>{o.query.data&&!C&&(c(o.query.data),u(structuredClone(o.query.data.values)),m({...o.query.data.sources}))},[o.query.data,C]);let w=!!s&&!!o.query.data&&(s.revision!==o.query.data.revision||s.definitionVersion!==o.query.data.definitionVersion);if(!fn(a))return(0,S.jsx)(Vm,{children:`Your DSP owner can manage plugin settings.`});if(o.query.isPending)return(0,S.jsx)(Um,{});if(!s||!l)return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Hm,{error:o.query.error}),(0,S.jsx)($,{onClick:()=>void o.query.refetch(),children:`Retry settings`})]});let T=o.options.data||{},E=o.update.isPending,D=(0,Th.settingsIssues)(s.definition,l),O=D.some(e=>e.severity===`error`);async function ee(){if(s&&l)try{let e=await o.update.mutateAsync({values:l,snapshot:s,sources:p}),t=new Set(s.definition.fields.filter(t=>JSON.stringify(s.values[t.id])!==JSON.stringify(e.values[t.id])).map(e=>e.applies).filter(e=>e!==void 0));b([...t].map(e=>Th.EFFECTS[e])),c(e),u(structuredClone(e.values)),m({...e.sources}),v(``)}catch{}}function k(){let e=o.query.data||s;e&&(c(e),u(structuredClone(e.values)),m({...e.sources}),v(``),b([]),o.update.reset())}function A(e,t,n){u(r=>({...r,...Object.fromEntries(n.map(n=>[n,structuredClone(t[n]==="default"?s.definition.fields.find(e=>e.id===n).default:e[n])]))})),m(e=>({...e,...Object.fromEntries(n.map(e=>[e,t[e]]))})),v(`Restored into your draft. Review your changes before saving.`),o.update.reset()}function j(e){A(Object.fromEntries(s.definition.fields.map(e=>[e.id,e.default])),Object.fromEntries(e.map(e=>[e,`default`])),e)}return(0,S.jsxs)(`div`,{className:`plugin-settings-page`,children:[(0,S.jsx)(`a`,{className:`plugin-settings-back`,href:r,children:`← Back`}),(0,S.jsx)(Rm,{title:t,description:n}),(0,S.jsx)(Hm,{error:o.query.error||o.options.error||o.update.error}),w&&(0,S.jsx)(Vm,{children:`These settings changed in another session. Discard your draft to load the latest settings before saving.`}),_&&(0,S.jsx)(Vm,{children:_}),D.map(e=>(0,S.jsx)(`p`,{className:`plugin-settings-rule`,role:e.severity===`error`?`alert`:`status`,children:e.message},e.id)),(0,S.jsxs)(Fp,{defaultValue:s.definition.sections[0].id,children:[(0,S.jsx)(Lp,{variant:`line`,"aria-label":`${t} sections`,children:s.definition.sections.map(e=>(0,S.jsx)(Rp,{value:e.id,children:e.label},e.id))}),s.definition.sections.map(e=>(0,S.jsxs)(zp,{value:e.id,children:[e.description&&(0,S.jsx)(`p`,{className:`plugin-settings-description`,children:e.description}),(0,S.jsx)(`div`,{className:`plugin-settings-fields`,children:s.definition.fields.filter(t=>t.section===e.id&&(0,Th.conditionMatches)(t.visibleWhen,l)).map(e=>(0,S.jsxs)(`div`,{className:e.type===`boolean`||e.type===`strings`?`plugin-setting-wide`:``,children:[(0,S.jsx)(Oh,{field:e,value:l[e.id],options:T,disabled:E||!(0,Th.conditionMatches)(e.enabledWhen,l)||!!e.optionsSource&&o.options.isPending,onChange:t=>{u(n=>({...n,[e.id]:t})),m(t=>({...t,[e.id]:`override`})),v(``),o.update.reset()}}),!(0,Th.conditionMatches)(e.enabledWhen,l)&&e.disabledReason&&(0,S.jsx)(`p`,{className:`plugin-setting-help`,children:e.disabledReason}),(0,S.jsxs)(`div`,{className:`plugin-setting-source`,children:[(0,S.jsx)(`span`,{children:p[e.id]==="default"?`Plugin default`:`DSP override`}),(0,S.jsx)($,{type:`button`,variant:`ghost`,size:`sm`,disabled:E,"aria-label":p[e.id]==="default"?`Keep current value for ${e.label}`:`Use plugin default for ${e.label}`,onClick:()=>p[e.id]==="default"?m(t=>({...t,[e.id]:`override`})):j([e.id]),children:p[e.id]==="default"?`Keep this value`:`Use plugin default`})]}),(0,S.jsxs)(`p`,{className:`plugin-setting-help`,children:[`Default:`,` `,(0,Th.formatSettingValue)(e,e.default,T)]})]},e.id))}),(s.definition.previews||[]).filter(t=>t.section===e.id).map(e=>(0,S.jsxs)(`p`,{role:`status`,className:`plugin-settings-preview`,children:[e.label,`:`,` `,(0,Th.settingsPreview)(e,l,s.definition.fields,T)]},e.id)),i?.(e.id,l,T),(0,S.jsxs)($,{type:`button`,variant:`outline`,size:`sm`,disabled:E,onClick:()=>j(s.definition.fields.filter(t=>t.section===e.id).map(e=>e.id)),children:[`Restore `,e.label,` defaults`]})]},e.id))]}),(0,S.jsxs)(`div`,{className:`plugin-settings-defaults`,children:[(0,S.jsx)($,{type:`button`,variant:`ghost`,disabled:E,onClick:()=>f(!0),children:`Restore defaults`}),(0,S.jsx)($,{variant:`ghost`,type:`button`,onClick:()=>g(e=>!e),"aria-expanded":h,children:`Change history`}),(0,S.jsx)(`span`,{children:`Settings apply to this DSP.`})]}),h&&(0,S.jsx)(Eh,{pluginId:e,scope:o.scope,snapshot:s,busy:E||w,onRestore:A},o.scope),!C&&y.map(e=>(0,S.jsx)(`p`,{className:`plugin-settings-effect`,role:`status`,children:e},e)),(0,S.jsxs)(`footer`,{className:`plugin-settings-footer`,children:[(0,S.jsx)(`span`,{role:`status`,children:C?`You have unsaved changes`:s.appliedRevision===s.revision?o.update.isSuccess?`Settings saved`:`All changes saved`:`Saved. Applying settings…`}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)($,{variant:`outline`,disabled:!C||E,onClick:k,children:`Discard`}),(0,S.jsx)($,{disabled:!C||E||w||O,onClick:()=>void ee(),children:E?`Saving…`:`Save changes`})]})]}),(0,S.jsx)(mm,{open:d,onOpenChange:f,children:(0,S.jsxs)(_m,{children:[(0,S.jsxs)(vm,{children:[(0,S.jsx)(bm,{children:`Restore plugin defaults?`}),(0,S.jsx)(xm,{children:`Your connection and collected records are preserved. Review the defaults before saving.`})]}),(0,S.jsxs)(ym,{children:[(0,S.jsx)($,{variant:`outline`,onClick:()=>f(!1),children:`Cancel`}),(0,S.jsx)($,{onClick:()=>{j(s.definition.fields.map(e=>e.id)),f(!1)},children:`Restore defaults`})]})]})})]})}function Ah(e){let{session:t}=gh(),n=`${e.pluginId}:${t.user?.id}:${dn(t)?.organizationId}:${t.dspView?.viewRef||`member`}`;return(0,S.jsx)(kh,{...e},n)}async function jh(e,t,n,r){if(!/^[a-z][a-z0-9-]{0,63}$/.test(e)||!/^[a-z][a-z0-9_.]{0,63}$/.test(t))throw Error(`Invalid plugin operation`);return{ok:!0,data:await rn(`/api/plugins/${e}/${t}`,`POST`,n,r)}}var Mh=s({ApiError:()=>Jt,Badge:()=>vh,Button:()=>$,EmptyState:()=>Wm,ErrorNotice:()=>Hm,Loading:()=>Um,Notice:()=>Vm,PageHeading:()=>Rm,PluginSettingsField:()=>Oh,PluginSettingsForm:()=>Ah,Table:()=>yh,TableBody:()=>xh,TableCell:()=>wh,TableHead:()=>Ch,TableHeader:()=>bh,TableRow:()=>Sh,Tabs:()=>Fp,TabsContent:()=>zp,TabsList:()=>Lp,TabsTrigger:()=>Rp,TextField:()=>Bm,activeMembership:()=>dn,calendarDateLabel:()=>Lm,dateTime:()=>Nm,has:()=>ln,idempotent:()=>cn,invokePluginOperation:()=>jh,isDspOwner:()=>fn,moveCalendarDate:()=>Im,mutation:()=>rn,request:()=>nn,useBusinessToday:()=>ih,usePluginSettings:()=>Dh,useSession:()=>gh,useTimezone:()=>rh}),Nh=new Map,Ph=(e,t)=>Nh.get(`${e}@${t}`);Object.defineProperty(globalThis,"DispatchPluginHost",{value:Object.freeze({react:x,jsx:S,query:qt,ui:Mh,register(e){if(e.apiVersion!==1||!/^[a-z][a-z0-9-]{0,63}$/.test(e.id)||!/^\d+\.\d+\.\d+$/.test(e.version)||!e.pages||Object.values(e.pages).some(e=>typeof e!=`function`))throw Error(`Plugin interface unavailable`);if(Nh.size>=64)throw Error(`Plugin limit reached`);Nh.set(`${e.id}@${e.version}`,Object.freeze(e))}}),writable:!1,configurable:!1});var Fh=new Map,Ih=new Map;window.addEventListener(`dispatch-authority-changed`,()=>{Fh.clear(),Ih.clear()});async function Lh(e,t,n){let r=await nn(`/api/plugin-assets/${e}/${n}`);if(r.id!==e||r.version!==t||r.revision!==n||typeof r.javascript!=`string`||r.javascript.length>2097152||typeof r.stylesheet!=`string`||r.stylesheet.length>1048576)throw new Jt(`plugin_unavailable`);let i=document.querySelector(`meta[name=dispatch-style-nonce]`)?.content;if(!i)throw new Jt(`plugin_unavailable`);let a=document.createElement(`script`);if(a.nonce=i,a.textContent=r.javascript,document.head.append(a),a.remove(),!Ph(e,t))throw new Jt(`plugin_unavailable`);let o=document.createElement(`style`);o.nonce=i,o.textContent=r.stylesheet,o.dataset.dispatchPlugin=`${e}@${t}`,document.head.append(o)}function Rh(e,t,n,r){let i=`${e}@${t}:${n}`,a=`${i}/${r}`,o=Fh.get(a);return o||(o=(0,x.lazy)(async()=>{if(!Ph(e,t)){let r=Ih.get(i);r||(r=Lh(e,t,n).catch(e=>{throw Ih.delete(i),e}),Ih.set(i,r)),await r}let a=Ph(e,t)?.pages[r];if(!a)throw new Jt(`plugin_unavailable`);return{default:a}}),Fh.size>=128&&Fh.delete(Fh.keys().next().value),Fh.set(a,o)),o}var zh=class extends x.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}render(){return this.state.error?(0,S.jsx)(Hm,{error:this.state.error}):(0,S.jsx)(x.Suspense,{fallback:(0,S.jsx)(Um,{}),children:this.props.children})}},Bh=[{title:`New`,kinds:[`added`]},{title:`Improved`,kinds:[`improved`,`changed`]},{title:`Fixed`,kinds:[`fixed`]},{title:`Removed`,kinds:[`removed`]}];function Vh(){let{session:e}=gh(),{timeZone:t}=rh(),[n,r]=(0,x.useState)(null),[i,a]=(0,x.useState)(!1),[o,s]=(0,x.useState)(!1),c=(0,x.useRef)(!1),l=(0,x.useRef)(null);(0,x.useEffect)(()=>{let e=!1;return nn(`/api/updates/popup`).then(t=>{e||r(t.release)}).catch(()=>{}),()=>{e=!0}},[]);async function u(){if(n&&!c.current){c.current=!0,a(!0),s(!1);try{await rn(`/api/updates/popup`,`POST`,{releaseId:n.releaseId}),r(null)}catch{s(!0)}finally{c.current=!1,a(!1)}}}return(0,x.useEffect)(()=>{if(!n)return;let e=()=>{nn(`/api/updates/popup`).then(e=>{e.release||r(null)}).catch(()=>{})};return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[n]),!n||e.dspView?null:(0,S.jsx)(mm,{open:!0,onOpenChange:e=>{e||u()},children:(0,S.jsxs)(_m,{className:`release-popup`,showCloseButton:!1,onInteractOutside:e=>e.preventDefault(),onOpenAutoFocus:e=>{e.preventDefault(),l.current?.focus()},onCloseAutoFocus:e=>{e.preventDefault(),document.getElementById(`main-content`)?.focus()},children:[(0,S.jsxs)(`header`,{className:`release-popup-header`,children:[(0,S.jsx)(`p`,{className:`release-popup-eyebrow`,children:`What’s new`}),(0,S.jsxs)(bm,{ref:l,tabIndex:-1,className:`release-popup-title`,children:[`Dispatch `,n.version]}),(0,S.jsxs)(xm,{children:[(0,S.jsx)(`time`,{dateTime:n.publishedAt,children:new Date(n.publishedAt).toLocaleDateString(void 0,{month:`long`,day:`numeric`,year:`numeric`,timeZone:t})}),(0,S.jsx)(`span`,{className:`release-popup-intro`,children:`Here’s what changed in the latest release.`})]}),(0,S.jsx)($,{variant:`ghost`,size:`icon`,className:`release-popup-close`,"aria-label":`Close update`,disabled:i,onClick:()=>void u(),children:(0,S.jsx)(qn,{"aria-hidden":`true`})})]}),(0,S.jsxs)(`div`,{className:`release-popup-body`,children:[Bh.map(e=>{let t=n.changelog.filter(t=>e.kinds.includes(t.kind));return t.length?(0,S.jsxs)(`section`,{"aria-label":e.title,children:[(0,S.jsx)(`h3`,{children:e.title}),(0,S.jsx)(`ul`,{children:t.map((e,t)=>(0,S.jsxs)(`li`,{children:[(0,S.jsx)(`strong`,{children:e.title}),e.description&&(0,S.jsx)(`p`,{children:e.description})]},t))})]},e.title):null}),n.afterUpdating.length>0&&(0,S.jsxs)(`section`,{"aria-label":`After updating`,children:[(0,S.jsx)(`h3`,{children:`After updating`}),(0,S.jsx)(`ul`,{children:n.afterUpdating.map((e,t)=>(0,S.jsxs)(`li`,{children:[(0,S.jsx)(`strong`,{children:e.title}),(0,S.jsx)(`p`,{children:e.description})]},t))})]})]}),(0,S.jsxs)(`footer`,{className:`release-popup-footer`,children:[o&&(0,S.jsx)(`p`,{role:`alert`,children:`We couldn’t save your dismissal. Please try again.`}),(0,S.jsx)($,{disabled:i,onClick:()=>void u(),children:i?`Saving…`:o?`Try again`:`Got it`})]})]})})}function Hh({...e}){return(0,S.jsx)(ap,{"data-slot":`dropdown-menu`,...e})}function Uh({...e}){return(0,S.jsx)(op,{"data-slot":`dropdown-menu-trigger`,...e})}function Wh({className:e,sideOffset:t=4,...n}){return(0,S.jsx)(sp,{children:(0,S.jsx)(cp,{"data-slot":`dropdown-menu-content`,sideOffset:t,className:H(`z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,e),...n})})}function Gh({...e}){return(0,S.jsx)(lp,{"data-slot":`dropdown-menu-group`,...e})}function Kh({className:e,inset:t,variant:n=`default`,...r}){return(0,S.jsx)(up,{"data-slot":`dropdown-menu-item`,"data-inset":t,"data-variant":n,className:H(`relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!`,e),...r})}function qh({name:e}){let{initials:t,className:n}=Qm(e);return(0,S.jsx)(`span`,{"aria-hidden":`true`,className:n,children:t})}function Jh(e){let t=$p().themePack.components?.DspAvatar||qh;return(0,S.jsx)(t,{...e})}var Yh=e=>e.installation.operation?.kind===`destroy`,Xh=e=>Yh(e)||e.installation.operation?.kind===`restore_dsp`||[`decommissioning`,`decommissioned`].includes(e.installation.state)||e.installation.operation?.kind===`decommission`,Zh=e=>!Xh(e)&&!Yh(e)&&e.organizationStatus===`active`&&e.installation.state===`ready`,Qh=e=>!Xh(e)&&!Yh(e)&&!Zh(e)&&e.organizationStatus!==`suspended`,$h={ready:`Running`,pending:`Queued`,provisioning:`Creating`,waiting_for_owner:`Prepared`,waiting_for_provider_auth:`Prepared`,verifying:`Verifying`,failed:`Needs attention`,suspended:`Suspended`,decommissioning:`Removing`,decommissioned:`Removed`},eg={provision:`Start provisioning`,retry_provision:`Retry provisioning`,decommission:`Remove DSP`,destroy:`Permanently delete DSP`,restore_dsp:`Restore DSP`,suspend:`Suspend DSP`,resume:`Resume DSP`,restart:`Restart runtime`,revoke_owner_invitation:`Revoke invitation`,issue_owner_invitation:`Invite owner`},tg=e=>e.detailsStatus===`required`?e.ownerEmail||`New DSP`:e.name;function ng(e){return Yh(e)||Xh(e)?`Closed`:e.ownerStatus===`pending`?`Invitation pending`:e.ownerStatus===`missing`?`Invite needed`:e.detailsStatus===`complete`?[`ready`,`suspended`].includes(e.installation.state)?`Complete`:`Finishing setup`:`DSP details needed`}function rg(e){return Yh(e)?e.installation.operation?.status===`failed`?`Deletion failed`:`Deleting`:e.installation.operation?.kind===`restore_dsp`?e.installation.operation.status===`failed`?`Restore failed`:`Restoring`:$h[e.installation.state]||`Unavailable`}function ig(){let{refresh:e}=gh(),t=Mt({queryKey:[`fleet`],queryFn:({signal:e})=>nn(`/api/platform/organizations`,{signal:e}),refetchInterval:5e3}),[n,r]=(0,x.useState)(``),[i,a]=(0,x.useState)(`all`),[o,s]=(0,x.useState)(!1),[c,l]=(0,x.useState)(null),[u,d]=(0,x.useState)(null),[f,p]=(0,x.useState)(null),[m,h]=(0,x.useState)(null),[g,_]=(0,x.useState)(!1),[v,y]=(0,x.useState)(null),[b,C]=(0,x.useState)(``),w=t.data||[],T=w.filter(e=>(i===`removed`?Xh(e):i===`running`?Zh(e):i===`onboarding`?Qh(e):!Xh(e))&&`${e.name} ${e.abbreviation||``} ${e.ownerEmail||``} ${e.stations.map(e=>e.code).join(` `)}`.toLowerCase().includes(n.trim().toLowerCase())),E=t.error?void 0:w.find(e=>e.continuityRef===c),D=e=>!Xh(e)&&!Yh(e)&&e.organizationStatus!==`suspended`;async function O(t){_(!0),y(null);try{let n=await rn(`/api/platform/organization/view`,`POST`,{controlRef:t.controlRef});$t(n.dspView.viewRef),await e(n),location.hash=n.memberships[0].organization.status===`active`?`#/dashboard`:`#/team`}catch(e){y(e)}finally{_(!1)}}async function ee(e){e.preventDefault(),_(!0),y(null);let n=new FormData(e.currentTarget).get(`ownerEmail`);try{let e=await cn(f?`${f.continuityRef}:invite`:`organization:create`,f?`/api/platform/organization/owner-invitation`:`/api/platform/organizations`,{ownerEmail:n,...f?{controlRef:f.controlRef}:{}});h(e),s(!1),p(null),await t.refetch()}catch(e){y(e)}finally{_(!1)}}async function k(e){if(!u)return;let{org:n,kind:r}=u,i=w.find(e=>e.continuityRef===n.continuityRef);if(!i)throw Error(`DSP unavailable`);let a=`${n.continuityRef}:${r}`;try{r===`revoke_owner_invitation`?await cn(a,`/api/platform/organization/owner-invitation/revoke`,{controlRef:i.controlRef}):await cn(a,`/api/platform/installation/${{provision:`provision`,retry_provision:`retry`,decommission:`remove`,destroy:`delete`,restore_dsp:`restore`,suspend:`suspend`,resume:`resume`,restart:`restart`}[r]}`,{controlRef:i.controlRef,expectedRevision:i.installation.revision,...r===`destroy`?{password:e}:{}}),C(`${n.name}: request accepted.`)}finally{await t.refetch()}}function A(e){return[...e.installation.availableActions,...e.availableActions].filter(e=>eg[e]&&(![`destroy`,`restore_dsp`].includes(e)||i===`removed`))}function j(e,t){l(null),y(null),t===`issue_owner_invitation`?p(e):d({org:e,kind:t})}return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Rm,{title:`DSPs`,description:`Manage your DSPs and onboarding.`,children:(0,S.jsxs)($,{onClick:()=>{s(!0),y(null)},children:[(0,S.jsx)(zn,{"data-icon":`inline-start`}),`Create new DSP`]})}),(0,S.jsxs)(`div`,{className:`inline-summary`,"aria-label":`DSP summary`,children:[(0,S.jsxs)(`span`,{children:[(0,S.jsx)(`strong`,{children:w.filter(e=>!Xh(e)).length}),` `,`DSPs`]}),(0,S.jsxs)(`span`,{children:[(0,S.jsx)(`strong`,{children:w.filter(Zh).length}),` running`]}),(0,S.jsxs)(`span`,{children:[(0,S.jsx)(`strong`,{children:w.filter(Qh).length}),` onboarding`]})]}),(0,S.jsx)(Zm,{result:m}),b&&(0,S.jsx)(Vm,{children:b}),(0,S.jsx)(Fp,{value:i,onValueChange:a,children:(0,S.jsx)(Lp,{variant:`line`,className:`page-tabs`,children:[[`all`,`All DSPs`],[`running`,`Running`],[`onboarding`,`Onboarding`],[`removed`,`Removed`]].map(([e,t])=>(0,S.jsx)(Rp,{value:e,children:t},e))})}),(0,S.jsxs)(`div`,{className:`table-toolbar`,children:[(0,S.jsx)(Km,{value:n,onChange:r,placeholder:`Search DSPs or owner email`}),(0,S.jsx)(Gm,{onClick:()=>void t.refetch(),busy:t.isFetching})]}),(0,S.jsx)(Hm,{error:t.error}),(0,S.jsx)(Hm,{error:v}),t.isPending?(0,S.jsx)(Um,{}):t.error?null:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(yh,{className:`fleet-table`,children:[(0,S.jsx)(bh,{children:(0,S.jsxs)(Sh,{children:[(0,S.jsx)(Ch,{className:`w-[28%]`,children:`DSP`}),(0,S.jsx)(Ch,{children:`Owner`}),(0,S.jsx)(Ch,{children:`Runtime`}),(0,S.jsx)(Ch,{children:`Onboarding`}),(0,S.jsx)(Ch,{children:(0,S.jsx)(`span`,{className:`sr-only`,children:`Actions`})})]})}),(0,S.jsx)(xh,{children:T.map(e=>(0,S.jsxs)(Sh,{"data-state":c===e.continuityRef?`selected`:void 0,children:[(0,S.jsx)(wh,{children:(0,S.jsxs)(`button`,{className:`identity-button`,onClick:()=>l(e.continuityRef),children:[(0,S.jsx)(Jh,{name:tg(e)}),(0,S.jsxs)(`span`,{className:`dsp-identity-copy`,children:[(0,S.jsx)(`strong`,{children:tg(e)}),(0,S.jsx)(`span`,{children:e.detailsStatus===`complete`?e.abbreviation||e.stations.map(e=>e.code).join(`, `):e.detailsStatus===`submitted`?`Applying DSP details`:`Awaiting DSP details`})]})]})}),(0,S.jsx)(wh,{className:`text-muted-foreground`,children:e.ownerEmail||`No owner assigned`}),(0,S.jsx)(wh,{children:(0,S.jsx)(Jm,{value:e.installation.state,children:rg(e)})}),(0,S.jsx)(wh,{children:(0,S.jsx)(Jm,{value:ng(e)===`Complete`?`neutral`:`pending`,children:ng(e)})}),(0,S.jsx)(wh,{className:`text-right`,children:(0,S.jsxs)(Hh,{children:[(0,S.jsx)(Uh,{asChild:!0,children:(0,S.jsx)($,{variant:`ghost`,size:`icon`,"aria-label":`Actions for ${tg(e)}`,children:(0,S.jsx)(kn,{})})}),(0,S.jsx)(Wh,{align:`end`,children:(0,S.jsxs)(Gh,{children:[(0,S.jsxs)(Kh,{disabled:g||!D(e),onSelect:()=>void O(e),children:[(0,S.jsx)(An,{}),` View`]}),A(e).map(t=>(0,S.jsx)(Kh,{disabled:!A(e).includes(t),variant:[`destroy`,`decommission`,`suspend`,`revoke_owner_invitation`].includes(t)?`destructive`:`default`,onSelect:()=>j(e,t),children:eg[t]},t))]})})]})})]},e.continuityRef))})]}),!T.length&&(0,S.jsx)(Wm,{title:n?`No DSPs match your search`:i===`removed`?`No removed DSPs`:`No DSPs here yet`,description:n?`Try another name or email.`:`Create a DSP to invite its owner.`}),(0,S.jsxs)(`p`,{className:`table-count`,children:[T.length,` DSP`,T.length===1?``:`s`]})]}),(0,S.jsx)(Ym,{open:o||!!f,onClose:()=>{s(!1),p(null)},title:f?`Invite DSP owner`:`Create new DSP`,description:`Invite an owner. Their workspace will be prepared while they finish setup.`,busy:g,children:(0,S.jsxs)(`form`,{onSubmit:ee,className:`panel-form`,children:[(0,S.jsxs)(tm,{children:[(0,S.jsx)(Bm,{label:`Owner email`,name:`ownerEmail`,type:`email`,autoComplete:`off`,maxLength:254,required:!0,disabled:g}),(0,S.jsx)(Hm,{error:v})]}),(0,S.jsxs)(`div`,{className:`panel-footer`,children:[(0,S.jsx)($,{type:`button`,variant:`outline`,disabled:g,onClick:()=>{s(!1),p(null)},children:`Cancel`}),(0,S.jsx)(qm,{busy:g,children:f?`Create invitation`:`Create DSP`})]})]})}),(0,S.jsx)(Ym,{open:!!E,onClose:()=>l(null),title:E?(0,S.jsxs)(`span`,{className:`dsp-panel-identity`,children:[(0,S.jsx)(Jh,{name:tg(E)}),(0,S.jsx)(`span`,{children:tg(E)})]}):`DSP details`,description:`DSP ownership and runtime status.`,children:E&&(0,S.jsxs)(`div`,{className:`panel-body`,children:[(0,S.jsxs)(`dl`,{className:`detail-list`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`Owner`}),(0,S.jsx)(`dd`,{children:E.ownerEmail||`Not assigned`})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`Runtime`}),(0,S.jsx)(`dd`,{children:(0,S.jsx)(Jm,{value:E.installation.state,children:rg(E)})})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`Onboarding`}),(0,S.jsx)(`dd`,{children:ng(E)})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`Station`}),(0,S.jsx)(`dd`,{children:E.stations.map(e=>e.code).join(`, `)||`—`})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`Timezone`}),(0,S.jsx)(`dd`,{children:E.timezone||`—`})]})]}),!!E.installation.failure&&(0,S.jsx)(Vm,{error:!0,children:`This DSP needs attention. Review its setup or retry the failed operation.`}),(0,S.jsxs)(`div`,{className:`flex flex-col gap-2 mt-6`,children:[(0,S.jsxs)($,{disabled:g||!D(E),onClick:()=>void O(E),children:[(0,S.jsx)(An,{}),` `,g?`Opening…`:`View`]}),!D(E)&&(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Viewing is unavailable for suspended or removed DSPs.`}),(0,S.jsx)(Hm,{error:v}),A(E).map(e=>(0,S.jsxs)($,{variant:`outline`,onClick:()=>j(E,e),children:[eg[e],(0,S.jsx)(Cn,{"data-icon":`inline-end`})]},e))]})]})}),u&&(0,S.jsx)(Xm,{title:eg[u.kind],passwordRequired:u.kind===`destroy`,description:u.kind===`destroy`?`Permanently delete ${u.org.name} and all its runtime data and backups. Everyone will lose access. This cannot be undone.`:u.kind===`decommission`?`Remove ${u.org.name}. Access will stop immediately and its services will stop. Existing data will be retained so you can restore this DSP later.`:u.kind===`restore_dsp`?`Restore ${u.org.name} with its retained data and settings. Users can sign in again once services are healthy.`:u.kind===`suspend`?`Suspend ${u.org.name}. User access and collection will stop. All data and saved connections will be retained.`:u.kind===`resume`?`Resume ${u.org.name}. Its services and user access will return once the runtime is healthy.`:u.kind===`restart`?`Restart the runtime for ${u.org.name}. Collection and user access will pause briefly.`:u.kind===`revoke_owner_invitation`?`Revoke the owner invitation for ${u.org.name}? The invitation link will stop working.`:`Confirm this action for ${u.org.name}.`,onClose:()=>d(null),onConfirm:k},`${u.org.continuityRef}:${u.kind}`)]})}function ag(){let[e,t]=(0,x.useState)(!1),[n,r]=(0,x.useState)(null),i=Mt({queryKey:[`platform-diagnostics`],queryFn:()=>nn(`/api/platform/diagnostics`),refetchInterval:5e3}),a=Mt({queryKey:[`platform-runtime`],queryFn:()=>nn(`/api/platform/runtime`),refetchInterval:5e3});async function o(){if(!e){t(!0),r(null);try{let e=await cn(`diagnostics-create`,`/api/platform/diagnostics`,{});Yt.setQueryData([`platform-diagnostics`],e),await Yt.invalidateQueries({queryKey:[`fleet`]})}catch(e){r(e)}finally{t(!1)}}}return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Rm,{title:`Diagnostics`,description:`Check runtime health and create test DSPs.`}),(0,S.jsx)(Hm,{error:n||i.error||a.error}),a.data?.enabled&&(0,S.jsxs)(`section`,{"aria-label":`Runtime health`,className:`rounded-xl border bg-card p-6 mb-6 space-y-3`,children:[(0,S.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Runtime health`}),(0,S.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Available storage: `,((a.data.storageAvailableBytes??0)/1024**3).toFixed(1),` GiB`]}),a.data.runtimes.map(e=>(0,S.jsxs)(`div`,{className:`flex flex-wrap justify-between gap-2 border-t pt-3 text-sm`,children:[(0,S.jsx)(`span`,{children:e.name}),(0,S.jsxs)(`span`,{children:[e.status,` · `,e.memoryBytes===null?`—`:`${Math.round(e.memoryBytes/1024**2)} MiB`,` · `,e.tasks??0,` tasks`,e.storage?.limited?` · ${((e.storage.availableBytes??0)/1024**3).toFixed(1)} GiB storage free`:e.storage?.limited===!1?` · Storage limit pending migration`:` · Storage unavailable`]})]},e.reference)),!a.data.runtimes.length&&(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No DSP runtimes yet.`})]}),i.isPending?(0,S.jsx)(Um,{}):i.data?(0,S.jsxs)(`div`,{className:`space-y-6`,children:[(0,S.jsxs)(`section`,{className:`rounded-xl border bg-card p-6 space-y-4`,"aria-labelledby":`test-dsp-title`,children:[(0,S.jsx)(`h2`,{id:`test-dsp-title`,className:`text-lg font-semibold`,children:`Test DSP`}),(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Deploy a DSP with synthetic employees and timecards. It stays available until you delete it from DSPs. Provider collection stays stopped, and no invitation email is sent.`}),(0,S.jsxs)($,{onClick:o,disabled:e||!i.data.enabled,children:[(0,S.jsx)(jn,{"aria-hidden":`true`}),e?`Requesting test DSP…`:`Deploy test DSP`]}),i.data.enabled?null:(0,S.jsx)(Vm,{children:`Test DSP deployment is unavailable on this installation.`})]}),(0,S.jsx)(`section`,{"aria-label":`Test DSP deployments`,className:`space-y-3`,"aria-live":`polite`,children:i.data.dsps.map(e=>(0,S.jsxs)(`div`,{className:`rounded-xl border p-4`,children:[(0,S.jsx)(`h3`,{className:`font-medium`,children:e.name}),(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.status===`pending`?`Creating DSP and preparing synthetic data…`:e.status===`failed`?`Setup needs attention. Open DSPs to inspect or delete this test DSP.`:`Synthetic data prepared · ${e.installation.state===`ready`?`Available`:e.installation.state}`})]},e.name))}),(0,S.jsx)(`a`,{href:`#/platform`,className:`text-sm underline`,children:`Manage test DSPs in DSPs`})]}):null]})}function og({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`card`,className:H(`flex flex-col gap-6 rounded-xl border bg-card py-6 text-card-foreground shadow-sm`,e),...t})}function sg({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`card-header`,className:H(`@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6`,e),...t})}function cg({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`card-title`,className:H(`leading-none font-semibold`,e),...t})}function lg({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`card-description`,className:H(`text-sm text-muted-foreground`,e),...t})}function ug({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`card-content`,className:H(`px-6`,e),...t})}function dg({className:e,...t}){return(0,S.jsx)(`div`,{"data-slot":`card-footer`,className:H(`flex items-center px-6 [.border-t]:pt-6`,e),...t})}var fg={not_connected:`Not connected`,not_verified:`Not verified`,checking:`Checking connection`,connected:`Connected`,verification_required:`Verification required`,credentials_rejected:`Credentials rejected`,temporarily_unavailable:`Temporarily unavailable`};function pg(e){if(e.state===`checking`){if(e.assistance)return`Completing CAPTCHA`;if(e.check?.phase===`checking_session`)return`Checking session`;if(e.check?.phase===`signing_in`)return`Signing in`}return fg[e.state]}function mg(e){return e.assistance?.phase===`queued`?`Paycom requested a CAPTCHA. Waiting for automatic verification to start.`:e.assistance?.phase===`solving`?`Completing Paycom’s CAPTCHA automatically. You can leave this page while verification finishes.`:e.assistance?.phase===`verifying`?`Checking Paycom’s response before continuing.`:e.check?.phase===`checking_session`?`Checking whether your saved Paycom session is still signed in.`:e.check?.phase===`signing_in`?`Signing in to Paycom with your saved credentials and security answers.`:e.reason===`verification_code_rejected`?`Amazon didn’t accept that code. Enter the newest code from your email.`:e.reason===`verification_expired`?`This verification attempt ended. Test the connection to start a new sign-in.`:e.verification&&e.state!==`checking`?`Amazon sent you an email verification code. Enter it below to finish signing in.`:e.reason===`attempt_cooldown`?`The service needs a pause before another login attempt. Retry after the time shown below.`:e.service===`paycom`&&e.reason===`captcha_required`?`Paycom requires a CAPTCHA before sign-in can finish. Contact your Dispatch administrator to complete verification. Connection tests will remain blocked until it is resolved.`:e.service===`paycom`&&e.reason===`security_answers_rejected`?`Paycom rejected the security-answer step. Contact your Dispatch administrator to verify the saved numbered PINs and complete sign-in.`:e.state===`verification_required`?`The service needs human verification. Contact your Dispatch administrator to complete it, then test the connection again.`:e.state===`credentials_rejected`?`The service rejected the saved login. Check your account details and update the credentials.`:e.state===`temporarily_unavailable`?`We couldn’t verify this connection. Your credentials remain saved. Try testing it again shortly.`:e.state===`checking`?`Verifying your login. You can leave this page while the check finishes.`:e.state===`not_verified`?`Credentials are saved. Test the connection to verify access.`:e.state===`connected`?`Signed in successfully. Your DSP’s connection is saved securely.`:`Connect once to make this service available to your DSP’s features.`}function hg({verification:e,busy:t,onVerify:n}){let{timeZone:r}=rh();async function i(t){t.preventDefault();let r=t.currentTarget,i={code:String(new FormData(r).get(`code`)||``).trim(),verificationId:e.id};r.reset();try{await n(i)}finally{i.code=``}}return(0,S.jsxs)(`form`,{onSubmit:i,className:`flex flex-col gap-3`,"aria-label":`Cortex email verification`,children:[(0,S.jsx)(Bm,{label:`Email verification code`,name:`code`,type:`text`,inputMode:`numeric`,autoComplete:`one-time-code`,pattern:`[0-9]{6}`,minLength:6,maxLength:6,required:!0,disabled:t}),(0,S.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Enter the six-digit code. This prompt expires at`,` `,Nm(e.expiresAt,r),`.`]}),(0,S.jsx)(qm,{busy:t,disabled:t||e.attemptsRemaining===0,children:`Verify code`})]})}function gg(){let{timeZone:e}=rh(),{session:t}=gh(),n=dn(t),r=fn(t),i=Mt({queryKey:[`connections`,n?.organizationId],queryFn:({signal:e})=>nn(`/api/organization/connections`,{signal:e}),enabled:r,refetchInterval:e=>e.state.data?.items.some(e=>e.state===`checking`||e.state===`not_verified`||!!e.verification)?2e3:15e3}),[a,o]=(0,x.useState)(null),[s,c]=(0,x.useState)(null),[l,u]=(0,x.useState)(null),[d,f]=(0,x.useState)(null),[p,m]=(0,x.useState)(null),[h,g]=(0,x.useState)(!1),_=i.data?.items.find(e=>e.service===p),v=p&&_?`${i.data?.services.find(e=>e.id===p)?.name}: ${s===p?`Checking session`:pg(_)}.`:null;if(!r)return null;async function y(e,t,r){c(e.id),u(null),f(null),m(t===`test`?e.id:null),g(!1);try{let a=await rn(`/api/organization/connections/${e.id}/${t}`,`POST`,t===`save`?{credentials:r}:t===`verify`?r:{});t===`test`&&Yt.setQueryData([`connections`,n?.organizationId],t=>t&&{...t,items:t.items.map(t=>t.service===e.id?a:t)}),await Yt.invalidateQueries({queryKey:[`paycom-connection`,n?.organizationId]}),o(null),f(t===`verify`?null:t===`disconnect`?`${e.name} disconnected.`:t===`save`?`${e.name} credentials saved.`:null),await i.refetch()}catch(e){u(e),m(null),t===`save`&&(!(e instanceof Jt)||!e.status||e.status>=500)&&(g(!0),i.refetch().catch(()=>{}))}finally{c(null)}}async function b(e){if(e.preventDefault(),!a)return;let t=e.currentTarget,n=Object.fromEntries(new FormData(t));t.reset(),await y(a.service,`save`,n);for(let e of Object.keys(n))n[e]=``}return(0,S.jsxs)(`section`,{className:`flex flex-col gap-6 py-6`,"aria-labelledby":`connections-heading`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h2`,{id:`connections-heading`,className:`text-lg font-semibold`,children:`Connections`}),(0,S.jsx)(`p`,{className:`text-muted-foreground`,children:`Connect the services your DSP uses. All supported features share these connections.`})]}),!a&&(0,S.jsx)(Hm,{error:l||i.error}),d&&(0,S.jsx)(Vm,{children:d}),v&&(0,S.jsx)(`div`,{role:`status`,children:(0,S.jsx)(Vm,{error:!!_&&![`checking`,`connected`].includes(_.state),children:v})}),i.isPending?(0,S.jsx)(Um,{}):i.data?(0,S.jsx)(`div`,{className:`grid gap-6 lg:grid-cols-2`,children:i.data.services.map(t=>{let n=i.data.items.find(e=>e.service===t.id);if(!n)return null;let r=n.state===`checking`,a=s!==null||r;return(0,S.jsxs)(og,{children:[(0,S.jsxs)(sg,{children:[(0,S.jsxs)(cg,{className:`flex items-center gap-3`,children:[(0,S.jsx)(Rn,{className:`size-5`,"aria-hidden":`true`}),t.name]}),(0,S.jsx)(lg,{children:t.id===`cortex`?`Amazon Logistics dashboard`:`Workforce and timecards`})]}),(0,S.jsxs)(ug,{className:`flex flex-col gap-4`,children:[(0,S.jsx)(`div`,{role:`status`,children:(0,S.jsx)(vh,{variant:n.state===`connected`?`default`:`secondary`,children:pg(n)})}),(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:mg(n)}),n.verification&&(0,S.jsx)(hg,{verification:n.verification,busy:a,onVerify:e=>y(t,`verify`,e)},n.verification.id),n.checkedAt&&(0,S.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Last checked: `,Nm(n.checkedAt,e)]}),n.retryAt&&(0,S.jsxs)(`p`,{className:`text-sm`,children:[`Retry after `,Nm(n.retryAt,e)]})]}),(0,S.jsxs)(dg,{className:`mt-auto flex flex-wrap gap-2`,children:[(0,S.jsx)($,{disabled:a,onClick:()=>{u(null),g(!1),o({service:t,action:`save`})},children:n.configured?`Update credentials`:`Connect ${t.name}`}),n.configured&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)($,{variant:`outline`,disabled:a||!!n.verification||t.id!==`paycom`&&!!n.retryAt&&Date.parse(n.retryAt)>Date.now(),onClick:()=>void y(t,`test`),children:[(0,S.jsx)(Vn,{className:`size-4`,"aria-hidden":`true`}),`Test connection`]}),(0,S.jsx)($,{variant:`ghost`,disabled:a,onClick:()=>{u(null),o({service:t,action:`disconnect`})},children:`Disconnect`})]})]})]},t.id)})}):(0,S.jsx)($,{variant:`outline`,onClick:()=>void i.refetch(),children:`Retry loading connections`}),(0,S.jsxs)(`p`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,S.jsx)(Gn,{className:`size-4 shrink-0`,"aria-hidden":`true`}),`DSP owners and platform owners can manage these credentials.`]}),(0,S.jsx)(mm,{open:a!==null,onOpenChange:e=>{!e&&!s&&(o(null),u(null))},children:(0,S.jsxs)(_m,{className:`max-h-[90dvh] overflow-y-auto`,children:[(0,S.jsxs)(vm,{children:[(0,S.jsx)(bm,{children:a?.action===`disconnect`?`Disconnect ${a.service.name}?`:`${a?.service.name||`Service`} credentials`}),(0,S.jsx)(xm,{children:a?.action===`disconnect`?`Features will lose access to this service until you reconnect. Previously collected data will remain available.`:`Enter the account your DSP uses. Saved credentials are encrypted and are never displayed here.`})]}),a?.action===`save`?(0,S.jsx)(`form`,{onSubmit:b,children:(0,S.jsxs)(tm,{children:[a.service.fields.map(e=>(0,S.jsx)(Bm,{name:e.name,label:e.label,type:e.name===`password`||e.name.startsWith(`pin`)?`password`:`text`,autoComplete:e.name===`username`?`username`:`off`,maxLength:e.maximum,required:!0,disabled:s!==null},e.name)),a.service.id===`paycom`&&(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Enter all five distinct security answers in the order configured for your Paycom account.`}),(0,S.jsx)(Hm,{error:l}),h&&(0,S.jsx)(Vm,{children:`We couldn’t confirm this save. Your credentials may already be stored. Close this form to check the connection before retrying.`}),(0,S.jsxs)(ym,{children:[(0,S.jsx)($,{type:`button`,variant:`outline`,disabled:s!==null,onClick:()=>o(null),children:`Cancel`}),(0,S.jsx)(qm,{busy:s!==null,disabled:s!==null||h,children:`Save and connect`})]})]})},a.service.id):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Hm,{error:l}),(0,S.jsxs)(ym,{children:[(0,S.jsx)($,{variant:`outline`,disabled:s!==null,onClick:()=>o(null),children:`Cancel`}),(0,S.jsx)($,{variant:`destructive`,disabled:s!==null,onClick:()=>a&&void y(a.service,`disconnect`),children:`Disconnect`})]})]})]})})]})}function _g(){let{session:e}=gh(),{timeZone:t}=rh(),n=dn(e),r=n?.organization.status===`suspended`,i=Mt({queryKey:[`organization-audit`,n?.organizationId],queryFn:({signal:e})=>nn(`/api/organization/audit`,{signal:e}),enabled:ln(n,`audit.read`)&&!r,refetchInterval:15e3});return r?(0,S.jsx)(Vm,{children:`This DSP is suspended. The audit log is unavailable.`}):ln(n,`audit.read`)?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`table-toolbar`,children:[(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Recent changes to your DSP, team, and access.`}),(0,S.jsx)(Gm,{onClick:()=>void i.refetch(),busy:i.isFetching})]}),(0,S.jsx)(Hm,{error:i.error}),i.isPending?(0,S.jsx)(Um,{}):i.data&&!i.error?i.data.audit.length?(0,S.jsxs)(yh,{children:[(0,S.jsx)(bh,{children:(0,S.jsxs)(Sh,{children:[(0,S.jsx)(Ch,{children:`Action`}),(0,S.jsx)(Ch,{children:`By`}),(0,S.jsx)(Ch,{children:`Date`}),(0,S.jsx)(Ch,{children:`Result`})]})}),(0,S.jsx)(xh,{children:i.data.audit.map((e,n)=>(0,S.jsxs)(Sh,{children:[(0,S.jsx)(wh,{children:e.action.replaceAll(`.`,` `)}),(0,S.jsx)(wh,{children:e.actor}),(0,S.jsx)(wh,{children:Nm(e.createdAt,t)}),(0,S.jsx)(wh,{children:(0,S.jsx)(Jm,{value:e.result,children:e.result})})]},e.id||n))})]}):(0,S.jsx)(Wm,{title:`No audit events yet`,description:`Changes to your DSP will appear here.`}):null]}):null}var vg=[{value:`light`,label:`Light`,description:`A bright, clean workspace.`},{value:`dark`,label:`Dark`,description:`A calm, low-light workspace.`},{value:`system`,label:`System`,description:`Match your device settings.`}];function yg({mode:e}){let{themePack:t}=$p();return(0,S.jsxs)(`span`,{className:`theme-preview-ui theme-preview-scope`,"data-theme":e,"data-theme-pack":t.id,children:[(0,S.jsxs)(`span`,{className:`theme-preview-sidebar`,children:[(0,S.jsx)(`i`,{}),(0,S.jsx)(`i`,{}),(0,S.jsx)(`i`,{}),(0,S.jsx)(`i`,{})]}),(0,S.jsxs)(`span`,{className:`theme-preview-content`,children:[(0,S.jsx)(`span`,{className:`theme-preview-heading`}),(0,S.jsx)(`span`,{className:`theme-preview-subheading`}),(0,S.jsx)(`span`,{className:`theme-preview-table`,children:[0,1,2].map(e=>(0,S.jsxs)(`span`,{children:[(0,S.jsx)(`i`,{}),(0,S.jsx)(`i`,{}),(0,S.jsx)(`i`,{})]},e))})]})]})}function bg(){let{appearance:e,setAppearance:t,themePack:n,setThemePack:r,storageUnavailable:i}=$p();return(0,S.jsxs)(`section`,{className:`theme-section`,children:[(0,S.jsxs)(`div`,{className:`theme-pack-field`,children:[(0,S.jsx)(`label`,{htmlFor:`theme-pack`,children:`Theme`}),(0,S.jsx)(`select`,{id:`theme-pack`,value:n.id,onChange:e=>r(e.target.value),"aria-describedby":`theme-pack-description`,children:Wp.map(e=>(0,S.jsx)(`option`,{value:e.id,children:e.name},e.id))}),(0,S.jsx)(`p`,{id:`theme-pack-description`,children:n.description})]}),(0,S.jsxs)(`fieldset`,{"aria-describedby":`theme-description theme-persistence`,children:[(0,S.jsx)(`legend`,{children:`Appearance`}),(0,S.jsx)(`p`,{id:`theme-description`,children:`Choose how Dispatch looks for you.`}),(0,S.jsx)(`div`,{className:`theme-options`,children:vg.map(({value:n,label:r,description:i})=>(0,S.jsxs)(`label`,{className:`theme-option`,children:[(0,S.jsx)(`input`,{type:`radio`,name:`theme`,value:n,checked:e===n,onChange:()=>t(n),"aria-label":r,"aria-describedby":`theme-${n}-description`}),(0,S.jsxs)(`span`,{className:`theme-preview theme-preview-${n}`,"aria-hidden":`true`,children:[(0,S.jsx)(yg,{mode:n===`dark`?`dark`:`light`}),n===`system`&&(0,S.jsx)(yg,{mode:`dark`})]}),(0,S.jsx)(`span`,{className:`theme-option-label`,children:r}),(0,S.jsx)(`span`,{id:`theme-${n}-description`,className:`theme-option-description`,children:i})]},n))}),(0,S.jsx)(`p`,{id:`theme-persistence`,className:`theme-persistence`,children:`Saved for your account on this browser. Other users keep their own theme.`}),i&&(0,S.jsx)(`p`,{role:`status`,className:`theme-storage-notice`,children:`Theme applied for this visit. Browser storage is unavailable, so it could not be saved.`})]})]})}var xg=typeof Intl.supportedValuesOf==`function`?Intl.supportedValuesOf(`timeZone`):[`America/Los_Angeles`,`America/Phoenix`,`America/Denver`,`America/Chicago`,`America/New_York`,`Europe/London`];function Sg(){let{timeZone:e,deviceZone:t,preference:n,setPreference:r,storageUnavailable:i}=rh(),a=[...new Set([`UTC`,t,n,...xg].filter(jm))].sort();return(0,S.jsxs)(`section`,{className:`settings-section`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h2`,{children:`Date & time`}),(0,S.jsx)(`p`,{children:`Choose how event times appear for you.`})]}),(0,S.jsxs)(`div`,{className:`theme-pack-field`,children:[(0,S.jsx)(`label`,{htmlFor:`display-timezone`,children:`Display timezone`}),(0,S.jsxs)(`select`,{id:`display-timezone`,value:n||`automatic`,onChange:e=>r(e.target.value===`automatic`?null:e.target.value),"aria-describedby":`display-timezone-description`,children:[(0,S.jsxs)(`option`,{value:`automatic`,children:[`Automatic — device timezone (`,t.replaceAll(`_`,` `),`)`]}),a.map(e=>(0,S.jsx)(`option`,{value:e,children:e.replaceAll(`_`,` `)},e))]}),(0,S.jsxs)(`p`,{id:`display-timezone-description`,children:[`Sync and activity times use `,e.replaceAll(`_`,` `),`. Timecards keep the DSP’s business timezone.`]}),(0,S.jsx)(`p`,{children:`Saved for your account on this browser.`}),i&&(0,S.jsx)(`p`,{role:`status`,children:`Applied for this visit. Browser storage is unavailable, so this preference could not be saved.`})]})]})}function Cg({onboarding:e=!1}){let{session:t,refresh:n}=gh(),r=e?t.memberships.find(e=>e.organizationId===t.activeOrganizationId)||null:dn(t),i=Mt({queryKey:[`profile`,r?.organizationId],queryFn:()=>nn(`/api/organization/profile`),enabled:ln(r,`organization.owner`)&&r?.organization.status!==`suspended`,refetchInterval:e=>e.state.data?.status===`submitted`&&2e3}),[a,o]=(0,x.useState)(!1),[s,c]=(0,x.useState)(null);if(!ln(r,`organization.owner`))return null;if(i.error)return(0,S.jsx)(Hm,{error:i.error});if(!i.data)return e?(0,S.jsx)(Um,{}):null;if(i.data.status===`complete`||i.data.status===`submitted`)return!e&&i.data.status===`complete`?null:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Vm,{children:i.data.status===`complete`?`Your DSP details are complete. You can continue to your workspace.`:`Your DSP details are saved. They’ll be applied when your workspace is ready.`}),e&&(0,S.jsx)($,{className:`mt-6`,onClick:()=>{location.hash=un(t)?`#/platform`:`#/settings`},children:`Continue to workspace`})]});async function l(e){e.preventDefault();let t=Object.fromEntries(new FormData(e.currentTarget));o(!0),c(null);try{await rn(`/api/organization/profile`,`POST`,t),await i.refetch(),await n()}catch(e){c(e)}finally{o(!1)}}return(0,S.jsxs)(`section`,{className:e?`onboarding-details`:`setup-section`,children:[!e&&(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h2`,{children:`Set up your DSP`}),(0,S.jsx)(`p`,{children:`Your workspace is being prepared. Add your DSP details to finish onboarding.`})]}),(0,S.jsx)(`form`,{onSubmit:l,children:(0,S.jsxs)(tm,{children:[(0,S.jsx)(Bm,{label:`DSP name`,name:`name`,minLength:2,maxLength:120,required:!0,disabled:a}),(0,S.jsx)(Bm,{label:`Abbreviation (optional)`,name:`abbreviation`,maxLength:16,disabled:a}),(0,S.jsx)(Bm,{label:`Station code`,name:`stationCode`,pattern:`[A-Za-z0-9]{3,8}`,maxLength:8,required:!0,disabled:a}),(0,S.jsx)(Bm,{label:`Business timezone`,name:`timezone`,defaultValue:Mm(),maxLength:64,required:!0,disabled:a}),(0,S.jsx)(Hm,{error:s}),(0,S.jsx)(qm,{busy:a,disabled:a,children:`Save DSP details`})]})})]})}function wg(){let{session:e,refresh:t}=gh(),n=()=>{let e=new URLSearchParams(location.hash.split(`?`)[1]).get(`tab`);return e===`theme`||e===`security`||e===`audit`||e===`connections`?e:`general`},[r,i]=(0,x.useState)(n);(0,x.useEffect)(()=>{let e=()=>i(n());return window.addEventListener(`hashchange`,e),()=>window.removeEventListener(`hashchange`,e)},[]);let a=un(e),o=dn(e),s=fn(e),c=!a&&ln(o,`audit.read`),[l,u]=(0,x.useState)(!1),[d,f]=(0,x.useState)(null),[p,m]=(0,x.useState)(!1);async function h(e){e.preventDefault();let n=e.currentTarget,r=Object.fromEntries(new FormData(n));u(!0),m(!1),f(null);try{await rn(`/api/auth/change-password`,`POST`,r),await t(),n.reset(),m(!0)}catch(e){f(e)}finally{u(!1)}}return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Rm,{title:`Settings`,description:a?`Your platform account and security.`:`Your account, workspace, and security.`}),(0,S.jsxs)(Fp,{value:r===`audit`&&!c||r===`connections`&&!s?`general`:r,onValueChange:e=>{i(e),history.replaceState({},``,`${location.pathname}${location.search}${location.hash.split(`?`)[0]}?tab=${e}`)},children:[(0,S.jsxs)(Lp,{variant:`line`,className:`page-tabs`,children:[(0,S.jsx)(Rp,{value:`general`,children:`General`}),(0,S.jsx)(Rp,{value:`security`,children:`Security`}),s&&(0,S.jsx)(Rp,{value:`connections`,children:`Connections`}),(0,S.jsx)(Rp,{value:`theme`,children:`Theme`}),c&&(0,S.jsx)(Rp,{value:`audit`,children:`Audit log`})]}),s&&(0,S.jsx)(zp,{value:`connections`,children:(0,S.jsx)(gg,{},o?.organizationId)}),(0,S.jsxs)(zp,{value:`general`,children:[(0,S.jsxs)(`section`,{className:`settings-section`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h2`,{children:`Account`}),(0,S.jsx)(`p`,{children:e.dspView?`You are signed in with your platform account.`:`Your Dispatch sign-in details.`})]}),(0,S.jsxs)(`dl`,{className:`detail-list`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`Name`}),(0,S.jsx)(`dd`,{children:e.user.name})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`Email address`}),(0,S.jsx)(`dd`,{children:e.user.email})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`Role`}),(0,S.jsx)(`dd`,{children:a||e.dspView?`Platform owner`:o?.roleName||`No DSP access`})]})]})]}),(0,S.jsx)(Sg,{}),!a&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`section`,{className:`settings-section`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h2`,{children:`Workspace`}),(0,S.jsx)(`p`,{children:`Your current DSP context.`})]}),(0,S.jsxs)(`dl`,{className:`detail-list`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`DSP`}),(0,S.jsx)(`dd`,{children:o?.organization.name||`No DSP selected`})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`Station`}),(0,S.jsx)(`dd`,{children:o?.organization.stations.map(e=>e.code).join(`, `)||`—`})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`Business timezone`}),(0,S.jsx)(`dd`,{children:o?.organization.timezone||`—`})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`dt`,{children:`Status`}),(0,S.jsx)(`dd`,{children:o?.organization.status.replaceAll(`_`,` `)||`Unavailable`})]})]})]}),(0,S.jsx)(Cg,{})]})]}),c&&(0,S.jsx)(zp,{value:`audit`,children:(0,S.jsx)(_g,{})}),(0,S.jsx)(zp,{value:`theme`,children:(0,S.jsx)(bg,{})}),(0,S.jsx)(zp,{value:`security`,children:(0,S.jsxs)(`section`,{className:`settings-section`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h2`,{children:`Change password`}),(0,S.jsx)(`p`,{children:`Changing your password signs out every other session.`})]}),(0,S.jsx)(`form`,{onSubmit:h,className:`max-w-md`,children:(0,S.jsxs)(tm,{children:[(0,S.jsx)(Bm,{label:`Current password`,name:`currentPassword`,type:`password`,autoComplete:`current-password`,maxLength:128,required:!0,disabled:l}),(0,S.jsx)(Bm,{label:`New password`,name:`newPassword`,type:`password`,autoComplete:`new-password`,minLength:12,maxLength:128,required:!0,disabled:l,description:`Use at least 12 characters.`}),(0,S.jsx)(Bm,{label:`Confirm new password`,name:`confirmPassword`,type:`password`,autoComplete:`new-password`,minLength:12,maxLength:128,required:!0,disabled:l}),(0,S.jsx)(Hm,{error:d}),p&&(0,S.jsx)(Vm,{children:`Password changed. Other sessions have been signed out.`}),(0,S.jsx)(`div`,{children:(0,S.jsx)(qm,{busy:l,disabled:l,children:`Change password`})})]})})]})})]})]})}function Tg(){return(0,x.useEffect)(()=>{document.title=`Set up your DSP · Dispatch`},[]),(0,S.jsxs)(`main`,{className:`auth-layout`,children:[(0,S.jsx)(`div`,{className:`auth-brand`,children:(0,S.jsx)(lh,{})}),(0,S.jsxs)(`section`,{className:`auth-panel`,children:[(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground mb-3`,children:`Step 2 of 2 · DSP details`}),(0,S.jsx)(`h1`,{children:`Set up your DSP`}),(0,S.jsx)(`p`,{className:`auth-description`,children:`Your account is ready. Add your DSP details while we prepare your workspace.`}),(0,S.jsx)(Cg,{onboarding:!0})]})]})}function Eg(e,t){let n=e.find(e=>e.available&&e.pages.some(e=>e.id===t));return n?Rh(n.id,n.version,n.revision,t):void 0}function Dg(e,t){let n=dn(t);return e.filter(e=>e.available).flatMap(e=>e.pages).filter(e=>ln(n,e.permission))}function Og(e){let t=un(e),n=dn(e);return Mt({queryKey:[`plugins`,t?`platform`:n?.organizationId],queryFn:({signal:e})=>nn(t?`/api/platform/plugins`:`/api/organization/plugins`,{signal:e}),initialData:!t&&e.plugins?{items:e.plugins}:void 0,enabled:e.authenticated&&(t||!!n&&ln(n,`dashboard.view`)),refetchInterval:e=>e.state.data?.items.some(e=>e.pending)?2e3:15e3})}function kg(){let{session:e,refresh:t}=gh(),n=un(e),r=fn(e),i=Og(e),[a,o]=(0,x.useState)(null),[s,c]=(0,x.useState)(null),[l,u]=(0,x.useState)(null);async function d(n,r){o(n.id),c(null);try{await cn(`plugin:${n.id}:${r}:${n.revision}`,`/api/organization/plugins/${n.id}`,{action:r,expectedRevision:n.revision}),u(null),await i.refetch(),await Yt.invalidateQueries({queryKey:[`connections`,dn(e)?.organizationId]}),await t()}catch(e){c(e)}finally{o(null)}}return(0,S.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,S.jsx)(Rm,{title:`Plugins`,description:n?`Available plugins that DSP owners can install for their workspace.`:`Choose the features your DSP uses. Your saved data stays with your DSP.`}),(0,S.jsx)(Hm,{error:s||i.error}),i.isPending?(0,S.jsx)(Um,{}):(0,S.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:i.data?.items.map(e=>(0,S.jsxs)(og,{children:[(0,S.jsxs)(sg,{children:[(0,S.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,S.jsx)(Bn,{"aria-hidden":`true`,className:`size-5 text-muted-foreground`}),!n&&(0,S.jsx)(vh,{variant:`secondary`,children:e.pending?`Applying changes`:e.state===`enabled`?`Installed`:e.state===`disabled`?`Disabled`:`Not installed`})]}),(0,S.jsx)(cg,{children:e.name}),(0,S.jsx)(lg,{children:e.description})]}),(0,S.jsx)(ug,{children:e.failureCode?(0,S.jsx)(Vm,{error:!0,children:`We couldn’t finish applying this change. Dispatch will retry when your DSP is available.`}):e.pending?(0,S.jsx)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:`Updating this plugin for your DSP…`}):!n&&e.state===`disabled`?(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Its pages and background work are stopped. Your saved data and credentials are retained.`}):null}),!n&&r&&(0,S.jsx)(dg,{className:`flex flex-wrap gap-2`,children:e.state===`uninstalled`?(0,S.jsxs)($,{disabled:!!a||e.pending,onClick:()=>void d(e,`install`),children:[`Install `,e.name]}):(0,S.jsxs)(S.Fragment,{children:[e.available&&e.pages[0]&&(0,S.jsx)($,{asChild:!0,children:(0,S.jsxs)(`a`,{href:`#/${e.pages[0].id}`,children:[`Open `,e.name]})}),e.available&&e.hasSettings&&e.pages[0]&&(0,S.jsx)($,{asChild:!0,variant:`outline`,children:(0,S.jsx)(`a`,{href:`#/${e.pages[0].id}?settings`,children:`Settings`})}),(0,S.jsx)($,{variant:`outline`,disabled:!!a||e.pending,onClick:()=>void d(e,e.state===`disabled`?`enable`:`disable`),children:e.state===`disabled`?`Enable`:`Disable`}),(0,S.jsx)($,{variant:`ghost`,disabled:!!a||e.pending,onClick:()=>u(e),children:`Uninstall`})]})})]},e.id))}),(0,S.jsx)(mm,{open:!!l,onOpenChange:e=>{!e&&!a&&u(null)},children:(0,S.jsxs)(_m,{children:[(0,S.jsxs)(vm,{children:[(0,S.jsxs)(bm,{children:[`Uninstall `,l?.name,`?`]}),(0,S.jsx)(xm,{children:`Its pages and background work will stop. Your collected data and saved credentials will stay with this DSP so you can reinstall it later.`})]}),(0,S.jsxs)(ym,{children:[(0,S.jsx)($,{variant:`outline`,disabled:!!a,onClick:()=>u(null),children:`Cancel`}),(0,S.jsx)($,{disabled:!!a,onClick:()=>l&&void d(l,`uninstall`),children:`Uninstall plugin`})]})]})})]})}function Ag({className:e,size:t=`default`,...n}){return(0,S.jsxs)(`div`,{className:`group/native-select relative w-fit has-[select:disabled]:opacity-50`,"data-slot":`native-select-wrapper`,children:[(0,S.jsx)(`select`,{"data-slot":`native-select`,"data-size":t,className:H(`h-9 w-full min-w-0 appearance-none rounded-md border border-input bg-transparent px-3 py-2 pr-9 text-sm shadow-xs transition-[color,box-shadow] outline-none selection:bg-primary selection:text-primary-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed data-[size=sm]:h-8 data-[size=sm]:py-1 dark:bg-input/30 dark:hover:bg-input/50`,`focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50`,`aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40`,e),...n}),(0,S.jsx)(En,{className:`pointer-events-none absolute top-1/2 right-3.5 size-4 -translate-y-1/2 text-muted-foreground opacity-50 select-none`,"aria-hidden":`true`,"data-slot":`native-select-icon`})]})}function jg({className:e,...t}){return(0,S.jsx)(`option`,{"data-slot":`native-select-option`,className:H(`bg-[Canvas] text-[CanvasText]`,e),...t})}function Mg(){let{session:e}=gh(),{timeZone:t}=rh(),n=dn(e),r=n?.organization.status===`suspended`,i=Mt({queryKey:[`team`,n?.organizationId],queryFn:({signal:e})=>nn(`/api/organization/administration`,{signal:e}),enabled:!r,refetchInterval:15e3}),[a,o]=(0,x.useState)(`members`),[s,c]=(0,x.useState)(``),[l,u]=(0,x.useState)(null),[d,f]=(0,x.useState)(!1),[p,m]=(0,x.useState)(null),[h,g]=(0,x.useState)(null),[_,v]=(0,x.useState)(null),y=i.data,b=y?.roles.filter(e=>e.permissions.every(e=>n?.permissions.includes(e)))||[],C=y?.members.filter(e=>`${e.user.name} ${e.user.email}`.toLowerCase().includes(s.toLowerCase()))||[];function w(e){m(null),u(e)}async function T(e){if(e.preventDefault(),!l)return;f(!0),m(null);let t=new FormData(e.currentTarget);try{l.kind===`invite`?g(await rn(`/api/organization/invitations`,`POST`,{email:t.get(`email`),roleId:t.get(`roleId`)})):l.kind===`member`&&await rn(`/api/organization/members/${l.member.id}/role`,`PUT`,{roleId:t.get(`roleId`)}),u(null),await i.refetch()}catch(e){m(e)}finally{f(!1)}}let E=y?.invitations.filter(e=>e.status===`pending`)||[];return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Rm,{title:`Team & Roles`,description:`Manage your team and their access.`,children:!r&&ln(n,`members.invite`)&&(0,S.jsxs)($,{onClick:()=>w({kind:`invite`}),children:[(0,S.jsx)(zn,{"data-icon":`inline-start`}),`Invite member`]})}),r?(0,S.jsx)(Vm,{children:`This DSP is suspended. Team administration is unavailable.`}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Cg,{}),(0,S.jsx)(Zm,{result:h}),(0,S.jsx)(Hm,{error:i.error}),i.isPending?(0,S.jsx)(Um,{}):y&&!i.error?(0,S.jsxs)(Fp,{value:a,onValueChange:o,children:[(0,S.jsxs)(Lp,{variant:`line`,className:`page-tabs`,children:[(0,S.jsx)(Rp,{value:`members`,children:`Members`}),(0,S.jsx)(Rp,{value:`roles`,children:`Roles`}),(0,S.jsxs)(Rp,{value:`invitations`,children:[`Invitations`,E.length>0&&(0,S.jsx)(`span`,{className:`tab-count`,children:E.length})]})]}),(0,S.jsxs)(zp,{value:`members`,children:[(0,S.jsxs)(`div`,{className:`table-toolbar`,children:[(0,S.jsx)(Km,{value:s,onChange:c,placeholder:`Search members`}),(0,S.jsx)(Gm,{onClick:()=>void i.refetch(),busy:i.isFetching})]}),(0,S.jsxs)(yh,{children:[(0,S.jsx)(bh,{children:(0,S.jsxs)(Sh,{children:[(0,S.jsx)(Ch,{className:`w-[45%]`,children:`Member`}),(0,S.jsx)(Ch,{children:`Role`}),(0,S.jsx)(Ch,{children:`Access`}),(0,S.jsx)(Ch,{children:(0,S.jsx)(`span`,{className:`sr-only`,children:`Actions`})})]})}),(0,S.jsx)(xh,{children:C.map(t=>(0,S.jsxs)(Sh,{children:[(0,S.jsx)(wh,{children:(0,S.jsxs)(`div`,{className:`member-identity`,children:[(0,S.jsx)(`span`,{className:`avatar`,children:t.user.name.split(/\s+/).map(e=>e[0]).slice(0,2).join(``)}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`strong`,{children:t.user.name}),(0,S.jsx)(`span`,{children:t.user.email})]})]})}),(0,S.jsx)(wh,{children:t.role.name}),(0,S.jsx)(wh,{children:(0,S.jsx)(Jm,{value:`active`,children:`Active`})}),(0,S.jsx)(wh,{className:`text-right`,children:t.user.id!==e.user.id&&ln(n,`members.manage`)&&(0,S.jsxs)(Hh,{children:[(0,S.jsx)(Uh,{asChild:!0,children:(0,S.jsx)($,{size:`icon`,variant:`ghost`,"aria-label":`Actions for ${t.user.name}`,children:(0,S.jsx)(kn,{})})}),(0,S.jsx)(Wh,{align:`end`,children:(0,S.jsxs)(Gh,{children:[(0,S.jsx)(Kh,{onSelect:()=>w({kind:`member`,member:t}),children:`Change role`}),(0,S.jsx)(Kh,{variant:`destructive`,onSelect:()=>v({title:`Remove member`,description:`Remove ${t.user.name} from ${y.organization.name}?`,path:`/api/organization/members/${t.id}`}),children:`Remove member`})]})})]})})]},t.id))})]}),!C.length&&(0,S.jsx)(Wm,{title:`No members found`,description:`Try a different name or email.`}),(0,S.jsxs)(`p`,{className:`table-count`,children:[C.length,` member`,C.length===1?``:`s`]})]}),(0,S.jsxs)(zp,{value:`roles`,children:[(0,S.jsx)(`div`,{className:`table-toolbar`,children:(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Standard roles for your DSP. All roles currently have the same permissions.`})}),(0,S.jsx)(`div`,{className:`role-list`,children:y.roles.map(e=>(0,S.jsx)(`section`,{className:`role-row`,children:(0,S.jsxs)(`div`,{children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,S.jsx)(`h2`,{children:e.name}),(0,S.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Standard role`})]}),(0,S.jsx)(`p`,{children:e.description})]})},e.id))})]}),(0,S.jsxs)(zp,{value:`invitations`,children:[(0,S.jsxs)(`div`,{className:`table-toolbar`,children:[(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Pending invitations to your DSP.`}),(0,S.jsx)(Gm,{onClick:()=>void i.refetch(),busy:i.isFetching})]}),(0,S.jsxs)(yh,{children:[(0,S.jsx)(bh,{children:(0,S.jsxs)(Sh,{children:[(0,S.jsx)(Ch,{children:`Email address`}),(0,S.jsx)(Ch,{children:`Role`}),(0,S.jsx)(Ch,{children:`Expires`}),(0,S.jsx)(Ch,{children:(0,S.jsx)(`span`,{className:`sr-only`,children:`Actions`})})]})}),(0,S.jsx)(xh,{children:E.map(e=>(0,S.jsxs)(Sh,{children:[(0,S.jsx)(wh,{children:e.email}),(0,S.jsx)(wh,{children:e.roleName}),(0,S.jsx)(wh,{children:Nm(e.expiresAt,t)}),(0,S.jsx)(wh,{className:`text-right`,children:ln(n,`members.invite`)&&(0,S.jsx)($,{variant:`ghost`,size:`sm`,"aria-label":`Revoke invitation for ${e.email}`,onClick:()=>v({title:`Revoke invitation`,description:`Revoke the invitation for ${e.email}?`,path:`/api/organization/invitations/${e.id}`}),children:`Revoke`})})]},e.id))})]}),!E.length&&(0,S.jsx)(Wm,{title:`No pending invitations`,description:`New invitations will appear here until they’re accepted.`})]})]}):null]}),(0,S.jsx)(Ym,{open:!!l,onClose:()=>u(null),title:l?.kind===`invite`?`Invite member`:`Change role`,description:l?.kind===`member`?`Update the role for ${l.member.user.name}.`:`Send an invitation to join your DSP.`,busy:d,children:l&&(0,S.jsxs)(`form`,{onSubmit:T,className:`panel-form`,children:[(0,S.jsxs)(tm,{children:[l.kind===`invite`&&(0,S.jsx)(Bm,{label:`Email address`,name:`email`,type:`email`,autoComplete:`off`,required:!0,disabled:d}),` `,(0,S.jsxs)(rm,{children:[(0,S.jsx)(im,{htmlFor:`editor-role`,children:`Role`}),(0,S.jsx)(Ag,{id:`editor-role`,name:`roleId`,defaultValue:l.kind===`member`?l.member.role.id:b.find(e=>e.key===`driver`)?.id,disabled:d,required:!0,children:b.map(e=>(0,S.jsx)(jg,{value:e.id,children:e.name},e.id))})]}),(0,S.jsx)(Hm,{error:p})]}),(0,S.jsxs)(`div`,{className:`panel-footer`,children:[(0,S.jsx)($,{variant:`outline`,type:`button`,disabled:d,onClick:()=>u(null),children:`Cancel`}),(0,S.jsx)(qm,{busy:d,children:l.kind===`invite`?`Send invitation`:`Save role`})]})]},l.kind===`member`?l.member.id:`invite`)}),_&&(0,S.jsx)(Xm,{title:_.title,description:_.description,onClose:()=>v(null),onConfirm:async()=>{await rn(_.path,`DELETE`,{}),await i.refetch()}})]})}function Ng({session:e,refresh:t,token:n}){let[r,i]=(0,x.useState)(!1),[a,o]=(0,x.useState)(null),s=Mt({queryKey:[`invitation`,n],enabled:!!n&&!r,queryFn:()=>rn(`/api/auth/invitation/inspect`,`POST`,{token:n}),refetchOnWindowFocus:!1});(0,x.useEffect)(()=>{o(null)},[n]);let c=s.data,l=!!n,u=l&&!c?.accountExists,d=u?`register`:`login`,f=e?.turnstile?.siteKey,p=`${f}:${d}:${n||``}`,[m,h]=(0,x.useState)({scope:``,token:``}),[g,_]=(0,x.useState)(0),v=m.scope===p?m.token:``,y=(0,x.useCallback)(e=>{h({scope:p,token:e})},[p]),b=c?.kind===`organization_owner`;async function C(){await t(),history.replaceState({},``,`${location.pathname}${location.search}${b?`#/onboarding`:`#/team`}`),window.dispatchEvent(new HashChangeEvent(`hashchange`))}async function w(e){if(e.preventDefault(),r)return;if(f&&!v){o(`turnstile_required`);return}let a=new FormData(e.currentTarget),s=f?{turnstileToken:v}:{};i(!0),o(null);try{u?(await rn(`/api/auth/register`,`POST`,{token:n,...Object.fromEntries(a),...s}),await C()):(await rn(`/api/auth/login`,`POST`,{...Object.fromEntries(a),...s}),await t(),l&&(await rn(`/api/auth/accept-invitation`,`POST`,{token:n}),await C()))}catch(e){o(e),y(``),_(e=>e+1)}finally{i(!1)}}async function T(){i(!0),o(null);try{await rn(`/api/auth/accept-invitation`,`POST`,{token:n}),await C()}catch(e){o(e)}finally{i(!1)}}return(0,S.jsxs)(`main`,{className:`auth-layout`,children:[(0,S.jsx)(`div`,{className:`auth-brand`,children:(0,S.jsx)(lh,{})}),(0,S.jsxs)(`section`,{className:`auth-panel`,children:[l&&b&&(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground mb-3`,children:`Step 1 of 2 · Your account`}),(0,S.jsx)(`h1`,{children:l&&b?`Create your DSP`:l?c?.kind===`platform_owner`?`Join Dispatch`:`Join ${c?.organization?.name||`Dispatch`}`:`Sign in to Dispatch`}),(0,S.jsx)(`p`,{className:`auth-description`,children:l?c?`${c.email} · ${c.role?.name||`Platform owner`}`:`Checking your invitation…`:`Welcome back. Sign in to your workspace.`}),l&&c&&(0,S.jsx)(`p`,{className:`auth-description`,children:c.accountExists?`You already have a Dispatch account. Use it to continue`+(b?` setting up your new DSP.`:` with this invitation.`):b?`Create your account, then add your DSP details to finish setup.`:`Create your account to accept this invitation.`}),(0,S.jsx)(Hm,{error:a||s.error}),e?.bootstrap?.initialized===!1&&(0,S.jsx)(Vm,{children:`Platform setup required. Create the platform owner using the private access administration command.`}),l&&s.isPending?(0,S.jsx)(Um,{}):l&&!c?null:l&&c?.accountExists&&e?.authenticated?(0,S.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,S.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Signed in as `,e.user.email,`.`]}),(0,S.jsx)($,{disabled:r,onClick:T,children:b?`Continue to DSP setup`:`Accept invitation`}),(0,S.jsx)($,{variant:`outline`,disabled:r,onClick:async()=>{i(!0);try{await rn(`/api/auth/logout`,`POST`,{}),await t()}catch(e){o(e)}finally{i(!1)}},children:`Use another account`})]}):(0,S.jsx)(`form`,{onSubmit:w,children:(0,S.jsxs)(tm,{children:[u?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(Bm,{label:`First name`,name:`firstName`,autoComplete:`given-name`,required:!0,maxLength:80,disabled:r}),(0,S.jsx)(Bm,{label:`Last name`,name:`lastName`,autoComplete:`family-name`,required:!0,maxLength:80,disabled:r})]}):(0,S.jsx)(Bm,{label:`Email address`,name:`email`,type:`email`,autoComplete:`username`,required:!0,maxLength:254,disabled:r}),(0,S.jsx)(Bm,{label:`Password`,name:`password`,type:`password`,autoComplete:u?`new-password`:`current-password`,minLength:u?12:void 0,maxLength:128,required:!0,disabled:r,description:u?`Use at least 12 characters.`:void 0}),!u&&(0,S.jsx)(`a`,{className:`text-sm text-primary underline-offset-4 hover:underline`,href:`#/forgot-password`,children:`Forgot password?`}),u&&(0,S.jsx)(Bm,{label:`Confirm password`,name:`confirmPassword`,type:`password`,autoComplete:`new-password`,required:!0,minLength:12,maxLength:128,disabled:r}),f&&(0,S.jsx)(fh,{siteKey:f,action:d,onToken:y,busy:r},`${p}:${g}`),(0,S.jsx)(qm,{busy:r,disabled:r||!(!f||v),children:u?b?`Create account and continue`:`Create account and accept`:l?`Sign in and continue`:`Sign in`})]})})]}),(0,S.jsx)(`p`,{className:`auth-footnote`,children:`Access is by invitation.`})]})}function Pg(e,t){if(un(e))return[{id:`platform`,label:`DSPs`,icon:wn},{id:`updates`,label:`Updates`,icon:Sn},{id:`backups`,label:`Backups`,icon:On},{id:`plugins`,label:`Plugins`,icon:Bn},{id:`diagnostics`,label:`Diagnostics`,icon:jn},{id:`platform-settings`,label:`Settings`,icon:Wn}];let n=dn(e),r=n?.organization.status===`active`;return[...r&&ln(n,`dashboard.view`)?[{id:`dashboard`,label:`Home Page`,icon:Mn}]:[],...r?Dg(t,e).map(e=>({id:e.id,label:e.label,icon:e.icon===`calendar`?Tn:Bn})):[],...r&&fn(e)?[{id:`plugins`,label:`Plugins`,icon:Bn}]:[],...ln(n,`members.read`)&&ln(n,`roles.read`)?[{id:`team`,label:`Team & Roles`,icon:Kn}]:[],{id:`settings`,label:`Settings`,icon:Wn}]}function Fg({session:e,refresh:t,hash:n,viewEnded:r}){let i=$p().themePack.components?.ShellLayout||mh,a=un(e),o=dn(e),s=Og(e).data?.items||[],c=Pg(e,s),l=n.replace(/^#\//,``).split(/[/?]/)[0],u=c.find(e=>e.id===l)||c[0],d=Eg(s,u.id),[f,p]=(0,x.useState)(!1),[m,h]=(0,x.useState)(null),[g,_]=(0,x.useState)(!1);async function v(){_(!0),h(null);try{$t(null),await t(),location.hash=`#/platform`}catch(e){h(e)}finally{_(!1)}}(0,x.useEffect)(()=>{l!==u.id&&(history.replaceState({},``,`${location.pathname}${location.search}#/${u.id}`),window.dispatchEvent(new HashChangeEvent(`hashchange`))),document.title=`${u.label} · Dispatch`,p(!1)},[l,u.id,u.label]);let y=(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`sidebar-brand`,children:[(0,S.jsx)(lh,{}),(0,S.jsx)(`p`,{children:a?`Platform`:o?.organization.name||`Workspace`})]}),(0,S.jsx)(`nav`,{className:`nav-list`,"aria-label":`Primary navigation`,children:c.map(({id:e,label:t,icon:n})=>(0,S.jsxs)(`a`,{href:`#/${e}`,"aria-current":e===u.id?`page`:void 0,className:`nav-item`,onClick:()=>p(!1),children:[(0,S.jsx)(n,{"aria-hidden":`true`}),(0,S.jsx)(`span`,{children:t})]},e))}),(0,S.jsx)(`div`,{className:`sidebar-account`,children:(0,S.jsxs)(Hh,{children:[(0,S.jsx)(Uh,{asChild:!0,children:(0,S.jsxs)(`button`,{className:`account-button`,children:[(0,S.jsxs)(`span`,{className:`avatar`,children:[e.user.firstName?.[0],e.user.lastName?.[0]]}),(0,S.jsxs)(`span`,{className:`account-copy`,children:[(0,S.jsx)(`strong`,{children:e.user.name}),(0,S.jsx)(`span`,{children:e.dspView?`Platform owner · Viewing DSP`:a?`Platform owner`:o?.roleName||`No DSP access`})]}),(0,S.jsx)(En,{"aria-hidden":`true`})]})}),(0,S.jsx)(Wh,{align:`start`,children:(0,S.jsxs)(Gh,{children:[(0,S.jsx)(Kh,{asChild:!0,children:(0,S.jsx)(`a`,{href:`#/${a?`platform-settings`:`settings`}`,children:`Account settings`})}),(0,S.jsxs)(Kh,{disabled:g,onSelect:async()=>{_(!0);try{await rn(`/api/auth/logout`,`POST`,{}),$t(null),tn(null),Yt.clear(),location.hash=``,await t()}catch(e){h(e)}finally{_(!1)}},children:[(0,S.jsx)(Pn,{}),`Sign out`]})]})})]})})]});return(0,S.jsxs)(hh.Provider,{value:{session:e,refresh:t},children:[(0,S.jsx)(`a`,{href:`#main-content`,className:`skip-link`,onClick:e=>{e.preventDefault(),document.getElementById(`main-content`)?.focus()},children:`Skip to content`}),(0,S.jsxs)(i,{navigation:y,mobileNavigation:(0,S.jsx)(sm,{open:f,onOpenChange:p,children:(0,S.jsxs)(um,{side:`left`,className:`mobile-sidebar`,children:[(0,S.jsx)(fm,{className:`sr-only`,children:`Navigation`}),(0,S.jsx)(pm,{className:`sr-only`,children:`Your Dispatch workspace pages.`}),y]})}),banner:e.dspView&&(0,S.jsxs)(`div`,{className:`dsp-view-banner`,role:`region`,"aria-label":`DSP viewing mode`,children:[(0,S.jsx)(An,{"aria-hidden":`true`}),(0,S.jsxs)(`div`,{children:[(0,S.jsxs)(`strong`,{children:[`Viewing `,o?.organization.name,` as DSP owner`]}),(0,S.jsx)(`span`,{children:`Full owner access. Changes are saved to this DSP.`})]}),(0,S.jsx)($,{variant:`outline`,disabled:g,onClick:()=>void v(),children:g?`Exiting…`:`Exit view`})]}),header:(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)($,{className:`mobile-menu`,size:`icon`,variant:`ghost`,"aria-label":`Open navigation`,onClick:()=>p(!0),children:(0,S.jsx)(Fn,{})}),(0,S.jsxs)(`div`,{className:`breadcrumb`,children:[(0,S.jsx)(`span`,{children:a?`Platform`:o?.organization.name||`Workspace`}),(0,S.jsx)(`span`,{"aria-hidden":`true`,children:`/`}),(0,S.jsx)(`strong`,{children:u.label})]})]}),children:[r&&!e.dspView&&(0,S.jsx)(Vm,{children:`The DSP view expired or is no longer available. You’re back in the platform console.`}),(0,S.jsx)(Hm,{error:m}),u.id===`platform`?(0,S.jsx)(ig,{}):u.id===`diagnostics`?(0,S.jsx)(ag,{}):u.id===`updates`?(0,S.jsx)(ch,{hash:n}):u.id===`backups`?(0,S.jsx)(oh,{page:u.id,hash:n},u.id):u.id===`plugins`?(0,S.jsx)(kg,{}):d?(0,S.jsx)(zh,{children:(0,S.jsx)(d,{})},`${u.id}:${s.find(e=>e.pages.some(e=>e.id===u.id))?.revision}`):u.id===`team`?(0,S.jsx)(Mg,{}):u.id===`settings`||u.id===`platform-settings`?(0,S.jsx)(wg,{},u.id):(0,S.jsx)(Rm,{title:u.label})]}),(0,S.jsx)(Vh,{})]})}function Ig(){let[e,t]=(0,x.useState)(null),[n,r]=(0,x.useState)(!1),[i,a]=(0,x.useState)(null),[o,s]=(0,x.useState)(location.hash),[c,l]=(0,x.useState)(0),[u,d]=(0,x.useState)(!1),f=(0,x.useCallback)(async e=>{let n;try{n=e||await nn(`/api/auth/session`)}catch(e){if(!(e instanceof Jt)||e.code!==`dsp_view_unavailable`)throw e;d(!0),n=await nn(`/api/auth/session`)}(n.dspView||!n.authenticated)&&d(!1),n.authenticated||$t(null),tn(n),t(n),r(!0),a(null)},[]);(0,x.useEffect)(()=>{f().catch(e=>{a(e),r(!0)});let e=()=>{s(location.hash),l(e=>e+1)},n=()=>{tn(null),t(null)},i=()=>{d(!0),f().catch(a)};return window.addEventListener(`hashchange`,e),window.addEventListener(`dispatch-session-expired`,n),window.addEventListener(`dispatch-dsp-view-ended`,i),()=>{window.removeEventListener(`hashchange`,e),window.removeEventListener(`dispatch-session-expired`,n),window.removeEventListener(`dispatch-dsp-view-ended`,i)}},[f]),(0,x.useEffect)(()=>{if(!e?.authenticated)return;let t=()=>{f().catch(()=>{})};return window.addEventListener(`focus`,t),()=>window.removeEventListener(`focus`,t)},[e?.authenticated,f]),(0,x.useEffect)(()=>{if(!e?.dspView)return;let t=window.setTimeout(()=>void f().catch(a),Math.max(0,Date.parse(e.dspView.expiresAt)-Date.now())+100);return()=>window.clearTimeout(t)},[e?.dspView?.expiresAt,f]);function p(){if(!n)return(0,S.jsxs)(`div`,{className:`initial-loading`,children:[(0,S.jsx)(lh,{}),(0,S.jsx)(Um,{})]});if(i)return(0,S.jsxs)(`main`,{className:`initial-loading`,children:[(0,S.jsx)(lh,{}),(0,S.jsx)(Hm,{error:i}),(0,S.jsx)($,{onClick:()=>void f().catch(a),children:`Try again`})]});if(o===`#/forgot-password`||o===`#/reset-password`||o.startsWith(`#/reset-password/`))return(0,S.jsx)(ph,{hash:o,session:e,refresh:f},`${o}:${c}`);let t=/^#\/invitation\/([A-Za-z0-9_-]{43})$/.exec(o)?.[1]||null;return!e?.authenticated||t?(0,S.jsx)(Ng,{session:e,refresh:f,token:t}):!e.dspView&&o===`#/onboarding`&&e.memberships.some(t=>t.organizationId===e.activeOrganizationId&&t.organization.status!==`suspended`&&t.permissions.includes(`organization.owner`))?(0,S.jsx)(hh.Provider,{value:{session:e,refresh:f},children:(0,S.jsx)(Tg,{})}):(0,S.jsx)(Fg,{session:e,refresh:f,hash:o,viewEnded:u},`${e.user.id}:${e.dspView?.viewRef||e.activeOrganizationId||`platform`}`)}let m=e?.authenticated?e.user.id:null;return(0,S.jsx)(Qp,{userId:m,children:(0,S.jsx)(nh,{userId:m,children:p()})})}var Lg=document.querySelector(`meta[name=dispatch-style-nonce]`)?.content;Lg&&ss(Lg),(0,b.createRoot)(document.getElementById(`root`)).render((0,S.jsx)(T,{client:Yt,children:(0,S.jsx)(Ig,{})}))})(); \ No newline at end of file diff --git a/dashboard/tests/browser/connections-persistence.spec.cjs b/dashboard/tests/browser/connections-persistence.spec.cjs index aa5b253..6ce3da7 100644 --- a/dashboard/tests/browser/connections-persistence.spec.cjs +++ b/dashboard/tests/browser/connections-persistence.spec.cjs @@ -10,8 +10,8 @@ async function login(page, f) { await expect(page.getByRole('heading', { name: 'Connections', exact: true })).toBeVisible(); } -for (const mobile of [false, true]) test(`form credentials reach the real encrypted vault (${mobile ? 'mobile' : 'desktop'})`, async ({ page }) => { - const f = await createConnectionsStack(); +for (const mobile of [false, true]) test(`form credentials reach a directory DSP vault without a runtime slot (${mobile ? 'mobile' : 'desktop'})`, async ({ page }) => { + const f = await createConnectionsStack({ directoryEnrollment: true }); const errors = []; page.on('pageerror', error => errors.push(error.message)); page.on('console', message => { if (message.type() === 'error') errors.push(message.text()); }); @@ -47,6 +47,7 @@ for (const mobile of [false, true]) test(`form credentials reach the real encryp const paycomSaved = page.waitForResponse(response => response.url().endsWith('/connections/paycom/save')); await dialog.getByRole('button', { name: 'Save and connect' }).click(); expect((await paycomSaved).status()).toBe(202); + expect(f.state.runtimeEnrollments).toBe(0); await expect(dialog).toHaveCount(0); await f.restartBroker(); expect(f.state.broker.vault.readForAdapter('paycom-main').credentials).toEqual(paycom); @@ -60,6 +61,50 @@ for (const mobile of [false, true]) test(`form credentials reach the real encryp } finally { await page.close(); await f.close(); } }); +for (const mobile of [false, true]) test(`an unconfirmed Paycom save stays dismissible during a stalled status check (${mobile ? 'mobile' : 'desktop'})`, async ({ page }) => { + const f = await createConnectionsStack({ directoryEnrollment: true }); + let releaseStatus, failed = false, saves = 0; + const pendingStatus = new Promise(resolve => { releaseStatus = resolve; }); + const errors = []; + page.on('pageerror', error => errors.push(error.message)); + page.on('console', message => { + if (message.type() === 'error' && !message.text().includes('503 (Service Unavailable)')) errors.push(message.text()); + }); + try { + if (mobile) await page.setViewportSize({ width: 390, height: 844 }); + await login(page, f); + await page.route('**/api/organization/connections', async route => { + if (failed) await pendingStatus; + await route.continue(); + }); + await page.route('**/api/organization/connections/paycom/save', async route => { + saves++; failed = true; + await route.fulfill({ status: 503, json: { ok: false, error: { code: 'dashboard_unavailable' } } }); + }); + await page.getByRole('button', { name: 'Connect Paycom', exact: true }).click(); + const dialog = page.getByRole('dialog'); + for (const [label, value] of [['Client code', 'synthetic'], ['Username', 'synthetic'], ['Password', 'synthetic-form-secret'], + ...[1, 2, 3, 4, 5].map(index => [`Security answer ${index}`, `synthetic-${index}`])]) { + await dialog.getByLabel(label, { exact: true }).fill(value); + } + await dialog.getByRole('button', { name: 'Save and connect' }).click(); + await expect(dialog.getByText('We couldn’t confirm this save.', { exact: false })).toBeVisible(); + await expect(dialog.getByLabel('Password', { exact: true })).toHaveValue(''); + await expect(dialog.getByRole('button', { name: 'Cancel', exact: true })).toBeEnabled(); + await expect(dialog.getByRole('button', { name: 'Save and connect' })).toBeDisabled(); + await expect(page).toHaveTitle('Settings · Dispatch'); + await expect(page).toHaveURL(/#\/settings\?tab=connections$/); + expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBeTruthy(); + await dialog.getByRole('button', { name: 'Cancel', exact: true }).scrollIntoViewIfNeeded(); + await page.screenshot({ path: `/tmp/dispatch-save-stalled-${mobile ? 'mobile' : 'desktop'}.png` }); + await dialog.getByRole('button', { name: 'Cancel', exact: true }).click(); + await expect(dialog).toHaveCount(0); + expect(saves).toBe(1); + expect(await page.evaluate(() => JSON.stringify([localStorage, sessionStorage]))).not.toContain('synthetic-form-secret'); + expect(errors).toEqual([]); + } finally { releaseStatus(); await page.close(); await f.close(); } +}); + test('lost acknowledgement explains uncertainty while the saved connection can be recovered', async ({ page }) => { const f = await createConnectionsStack(); try { diff --git a/dashboard/tests/connections-persistence.test.js b/dashboard/tests/connections-persistence.test.js index 5e73d2a..72dcc17 100644 --- a/dashboard/tests/connections-persistence.test.js +++ b/dashboard/tests/connections-persistence.test.js @@ -35,6 +35,60 @@ test('HTTP credentials persist encrypted across broker restarts for Cortex and P .latest(f.organizationId).status, 'queued'); }); +test('a sleeping directory DSP saves Paycom directly in its vault while runtime capacity is full', async t => { + const f = await createConnectionsStack({ directoryEnrollment: true }); t.after(() => f.close()); + const platform = f.access.session(f.platform.token); + const viewed = f.access.beginDspView(platform, { controlRef: f.access.issuePlatformControlRef(platform, f.organizationId) }); + const response = await fetch(`${f.base}/api/organization/connections/paycom/save`, { + method: 'POST', headers: { ...f.headers, Cookie: `dispatch_session=${f.platform.token}`, + 'X-Dispatch-CSRF': platform.csrfToken, 'X-Dispatch-DSP-View': viewed.dspView.viewRef }, + body: JSON.stringify({ credentials: PAYCOM }), + }); + assert.equal(response.status, 202); + assert.equal((await response.json()).data.configured, true); + assert.equal(f.state.runtimeEnrollments, 0); + assert.deepEqual(f.state.broker.vault.readForAdapter('paycom-main').credentials, PAYCOM); + const requests = require('../../core/accounts/src/onboarding-store').createOnboardingStore(f.store); + const job = requests.latest(f.organizationId); + assert.equal(job.status, 'queued'); + let capacity = false; + const worker = require('../../core/installations/src/owner-onboarding').createOwnerOnboardingWorker({ + store: f.store, backends: ['directory_service_v1'], invoke: async (_id, _action, input) => { + if (!capacity) return { ok: false, status: 'execution_capacity_wait' }; + return { ok: true, status: 'succeeded', data: input.step === 'sync' + ? { syncId: 'paycom-main-workforce', intervalSeconds: 3600, desiredState: 'running' } + : { profileId: 'paycom-main', provider: 'paycom', status: 'authenticated', testedAt: new Date().toISOString() } }; + }, + }); + for (let i = 0; i < 4; i++) { + const result = await worker.runPending('synthetic-worker'); + assert.equal(result.failed, 0); + assert.equal(requests.latest(f.organizationId).status, 'queued'); + assert.equal(requests.latest(f.organizationId).attempt, 0); + } + const stale = requests.claim(job.id, 'stale-worker'); requests.defer(stale); + const current = requests.claim(job.id, 'current-worker'); + assert.throws(() => requests.defer(stale), /installation_operation_in_progress/); + requests.defer(current); + capacity = true; + assert.equal((await worker.runPending('available-worker')).completed, 1); + assert.equal(requests.latest(f.organizationId).status, 'succeeded'); + await f.restartBroker(); + assert.deepEqual(f.state.broker.vault.readForAdapter('paycom-main').credentials, PAYCOM); + assertNoPlaintext(f.root, PAYCOM.password); +}); + +test('a directory enrollment with a lost response stays recoverable without a runtime slot', async t => { + const f = await createConnectionsStack({ directoryEnrollment: true }); t.after(() => f.close()); + f.state.dropReply = true; + assert.equal((await f.save('paycom', PAYCOM)).status, 503); + await f.restartBroker(); + assert.deepEqual(f.state.broker.vault.readForAdapter('paycom-main').credentials, PAYCOM); + assert.equal((await f.save('paycom', { ...PAYCOM, password: 'synthetic-replacement' })).status, 202); + assert.equal(f.state.runtimeEnrollments, 0); + assert.equal(f.state.broker.vault.readForAdapter('paycom-main').credentials.password, 'synthetic-replacement'); +}); + test('platform owner DSP view saves Cortex and Paycom through HTTP into the selected encrypted vault', async t => { const f = await fixture(t), platform = f.access.session(f.platform.token); const viewed = f.access.beginDspView(platform, { controlRef: f.access.issuePlatformControlRef(platform, f.organizationId) }); diff --git a/dashboard/tests/helpers/connections-stack.cjs b/dashboard/tests/helpers/connections-stack.cjs index d390996..ce1dd62 100644 --- a/dashboard/tests/helpers/connections-stack.cjs +++ b/dashboard/tests/helpers/connections-stack.cjs @@ -15,7 +15,7 @@ const { createRuntimeGatewayDispatchClient } = require('../../../shared/gateway/ const { createRuntimeConnections } = require('dispatch-runtime-kit/supervisor/src/connections'); const { createContainerPaycomSetup } = require('dispatch-dsp/plugins/paycom/backend/runtime/setup.js'); -async function createConnectionsStack() { +async function createConnectionsStack({ directoryEnrollment = false } = {}) { const root = fs.mkdtempSync(path.join(os.tmpdir(), 'dispatch-save-')); fs.chmodSync(root, 0o700); const oldEnvironment = ['DISPATCH_MANAGED_RUNTIME', 'DISPATCH_PROJECT_ROOT'].map(key => [key, process.env[key]]); @@ -24,7 +24,8 @@ async function createConnectionsStack() { const paths = defaultPaths({ databaseRoot: path.join(root, 'vault'), secretRoot: path.join(root, 'secret'), stateRoot: path.join(root, 'state'), runtimeRoot: path.join(root, 'run') }); const store = new AccessStore({ databaseRoot: path.join(root, 'core'), database: path.join(root, 'core', 'access.sqlite3') }); - const access = new AccessControlService(store, { installationOperatorEnabled: true, installationBackend: 'native_service_v1' }); + const access = new AccessControlService(store, { installationOperatorEnabled: true, + installationBackend: directoryEnrollment ? 'directory_service_v1' : 'native_service_v1' }); const password = 'isolated dashboard owner password'; const platformInvite = access.createPlatformBootstrap({ email: 'platform@save.test' }); const platform = await access.acceptNewUser({ token: platformInvite.token, firstName: 'Platform', lastName: 'Owner', @@ -38,7 +39,7 @@ async function createConnectionsStack() { store.updateOrganizationStatus(dsp.organization.id, 'active', Date.now()); require('../../../core/accounts/tests/plugin-fixture').enableFixturePlugin(store, dsp.organization.id); const runtimeKey = store.installationControl(dsp.organization.id).runtimeKey; - const state = { dropReply: false, authentication: null, verification: null, browsers: [], broker: null }; + const state = { dropReply: false, authentication: null, verification: null, browsers: [], broker: null, runtimeEnrollments: 0 }; const options = { browserRuntime: { launch: async () => { const browser = { endpoint: 'http://127.0.0.1:43210', closed: false, @@ -66,6 +67,10 @@ async function createConnectionsStack() { const transport = createRuntimeGatewayDispatchClient({ socketPath, runtimeKey }); const invoke = async (key, action, input) => { if (key !== runtimeKey) throw new Error('wrong DSP'); + if (input.command === 'enroll') { + state.runtimeEnrollments++; + if (directoryEnrollment) return { ok: false, status: 'execution_capacity_wait' }; + } const result = await (action === 'connections.manage' ? transport.connectionsManage(input) : transport.paycomSetup(input)); if (state.dropReply && (input.command === 'save' || input.command === 'enroll')) { state.dropReply = false; @@ -73,7 +78,15 @@ async function createConnectionsStack() { } return result; }; - const paycomSetup = createOwnerPaycomSetup({ store, access, invoke }); + const enroll = directoryEnrollment ? require('../../../host/controller/paycom-enrollment').createPaycomEnrollment({ + backend: { async request(id, operation, input, options) { + if (id !== runtimeKey || operation !== 'auth.request') throw new Error('wrong DSP'); + const result = await require('dispatch-runtime-kit/auth-broker/src/client').request(paths.socket, input, options); + if (state.dropReply) { state.dropReply = false; throw new Error('lost enrollment response'); } + return result; + } }, + }) : undefined; + const paycomSetup = createOwnerPaycomSetup({ store, access, invoke, ...(enroll ? { enroll } : {}) }); const connections = createOwnerConnections({ store, access, invoke, paycomSetup }); const server = createDashboardServer({ access, connections, paycomSetup, client: { workforce: { day: unused }, sync: { status: unused, runNow: unused }, system: { status: unused }, diff --git a/host/controller/paycom-enrollment.js b/host/controller/paycom-enrollment.js new file mode 100644 index 0000000..e3fe293 --- /dev/null +++ b/host/controller/paycom-enrollment.js @@ -0,0 +1,34 @@ +'use strict'; + +const { setupRequest, setupFailure } = require('../../shared/contracts/src/paycom-setup'); +const { success, failure } = require('../../shared/contracts/src/result'); +const { AccessError } = require('../../core/accounts/src/validation'); + +// The owner setup service owns authorization, idempotency and the onboarding +// receipt. Send credentials straight to the DSP's isolated vault worker so +// saving them never requires a collection-runtime slot or a persisted job body. +function createPaycomEnrollment({ backend, clock = Date.now }) { + return async (dspId, value) => { + const input = setupRequest(value, dspId); + if (input.command !== 'enroll') return failure('invalid_input'); + const remaining = input.expiresAt - clock(); + if (remaining <= 0 || remaining > 60000) return failure('invalid_input'); + const options = { signal: AbortSignal.timeout(remaining) }; + try { + const send = intent => backend.request(dspId, 'auth.request', { + action: 'enroll-paycom', credentials: input.credentials, intent, + }, options); + let result = await send(input.intent); + if (!result.ok && result.status === 'profile_not_configured' && input.intent === 'replace') result = await send('create'); + if (!result.ok) return failure(setupFailure(result.status)); + if (result.status !== 'configured') throw new Error('invalid_response'); + return success('succeeded', { configured: true }); + } catch { + // A lost response may follow persistence. Keep the existing unconfirmed + // save behavior instead of claiming the credentials were rejected. + throw new AccessError('auth_unavailable', 503); + } + }; +} + +module.exports = { createPaycomEnrollment }; From 854d0f4f9d2a77b8c6a55d10e410d7e704d7e41b Mon Sep 17 00:00:00 2001 From: Dillon <260170482+dillonlille@users.noreply.github.com> Date: Sun, 13 Sep 2026 00:58:40 +0000 Subject: [PATCH 2/2] Bound authentication handoff to the idle capacity needed --- core/auth-broker/coordinator.js | 9 ++++++--- core/auth-broker/tests/coordinator.test.js | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/core/auth-broker/coordinator.js b/core/auth-broker/coordinator.js index 7b1bb91..8bc4b13 100644 --- a/core/auth-broker/coordinator.js +++ b/core/auth-broker/coordinator.js @@ -154,7 +154,7 @@ class AuthenticationCoordinator { poll() { if (this.polling) return this.polling; this.polling = (async () => { - for (const [dspId, entry] of this.dsps) { + for (const [dspId, entry] of [...this.dsps]) { if (!entry.row || entry.requests || entry.waiters || entry.closing) continue; try { const response = await this.workers.request(entry.row, { action: 'activity' }); @@ -165,8 +165,11 @@ class AuthenticationCoordinator { // Give queued DSPs its slot after the worker confirms it is idle; // in-progress sign-ins, verification and plugin leases stay intact. const waiting = this.manager.status().queued > 0; - if (!response.busy && !leased && (waiting || this.clock() - entry.lastUsed >= this.idleMs)) await this.closeEntry(dspId, entry); - else await this.manager.renew(entry.context, entry.lease.leaseId); + if (!response.busy && !leased && (waiting || this.clock() - entry.lastUsed >= this.idleMs)) { + await this.closeEntry(dspId, entry); + // Admit the queued DSP before considering another warm worker. + await this.manager.pump(); + } else await this.manager.renew(entry.context, entry.lease.leaseId); } catch { await this.closeEntry(dspId, entry); } } })().finally(() => { this.polling = null; }); diff --git a/core/auth-broker/tests/coordinator.test.js b/core/auth-broker/tests/coordinator.test.js index 6792611..83aecc4 100644 --- a/core/auth-broker/tests/coordinator.test.js +++ b/core/auth-broker/tests/coordinator.test.js @@ -69,11 +69,11 @@ test('one admitted auth worker serves a DSP; SDK leases remain bound to the orig assert.equal(stopped.length, 2); assert.equal(manager.status().sessions, 0); }); -test('a third DSP can save while status polling keeps idle authentication workers warm', async t => { +for (const signingIn of [false, true]) test(`a third DSP can save while status polling keeps idle authentication workers warm (sign-in: ${signingIn})`, async t => { const root = fs.mkdtempSync(path.join(os.tmpdir(), 'dispatch-auth-fairness-')); const store = new BrowserStore(path.join(root, 'state/browser.sqlite3')); const ids = ['a', 'b', 'c'].map(letter => 'dsp_' + letter.repeat(32)); - const busy = new Set([ids[0]]), stopped = [], saved = []; + const busy = new Set(signingIn ? [ids[0]] : []), stopped = [], saved = []; const workers = { start: async row => ({ protocol: 'worker', endpoint: 'worker://' + row.id, access: row.id }), close: async row => { stopped.push(row.dsp_id); return true; }, @@ -99,7 +99,7 @@ test('a third DSP can save while status polling keeps idle authentication worker await new Promise(resolve => setImmediate(resolve)); assert.equal(manager.status().queued, 1); await coordinator.poll(); - assert.deepEqual(stopped, [ids[1]], 'the active sign-in must keep its worker'); + assert.deepEqual(stopped, [ids[signingIn ? 1 : 0]], 'yield only the one idle worker needed by the queue'); await manager.pump(); const result = await outcome; assert.equal(result.error, undefined);