@camstack/addon-admin-ui 1.2.441 → 1.2.443
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AddonAssetIcon-CCzVCA49.js → AddonAssetIcon-BZ3nAoxI.js} +1 -1
- package/dist/assets/Addons-BGWXApJO.js +4 -0
- package/dist/assets/{AdminPage--m3xHpjx.js → AdminPage-BrNVYSyo.js} +1 -1
- package/dist/assets/{AdminSectionedPage-D5J86Kfp.js → AdminSectionedPage-Dh0h99mU.js} +1 -1
- package/dist/assets/AiProfiles-LVK8z9CZ.js +3 -0
- package/dist/assets/{BrokerForm-Cd5z8Mk0.js → BrokerForm-Ccq1Ih2O.js} +1 -1
- package/dist/assets/Build-C_Zu-Je3.js +40 -0
- package/dist/assets/{Calendars-CVnE0N6y.js → Calendars-1uP96v-V.js} +1 -1
- package/dist/assets/Cluster-BnmZh2Nn.js +1 -0
- package/dist/assets/ClusterStepModel-B6c_UMsA.js +1 -0
- package/dist/assets/CompositionEditor-joJfcrqc.js +1 -0
- package/dist/assets/{CompositionEditorPage-D3LiFLq4.js → CompositionEditorPage-y89GyEA5.js} +1 -1
- package/dist/assets/Data-DX8kzB-3.js +2 -0
- package/dist/assets/{DeviceDetail-Ry7b522t.js → DeviceDetail-B8U3Yepm.js} +2 -2
- package/dist/assets/{DeviceDoActionFields-n2-NdVST.js → DeviceDoActionFields-q6xVAIAa.js} +1 -1
- package/dist/assets/{Devices-BacO9x6N.js → Devices-AoATGKWU.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-DgFNOUrt.js → EmbedPlayerPage-Du1J1yTM.js} +1 -1
- package/dist/assets/Identity-BOfwyXgX.js +1 -0
- package/dist/assets/IntegrationDetail-DCQjP8LU.js +1 -0
- package/dist/assets/IntegrationHub-B-RxXA9_.js +1 -0
- package/dist/assets/Integrations-CzTceJFE.js +1 -0
- package/dist/assets/Integrations-WPdqnrXU.js +1 -0
- package/dist/assets/{Library-yKp-qGfV.js → Library-B67zZRsd.js} +1 -1
- package/dist/assets/Locations-HaHa_Fsr.js +3 -0
- package/dist/assets/{Logs-DWz6dVJo.js → Logs-D5P4nUT8.js} +1 -1
- package/dist/assets/{MaskShapeCanvas-wkrQJhyN.js → MaskShapeCanvas-DImE8rL3.js} +1 -1
- package/dist/assets/{MotionZonesSettings-BZneggiu.js → MotionZonesSettings-0CuyxGPc.js} +1 -1
- package/dist/assets/MyAccess-CvUaUk6O.js +2 -0
- package/dist/assets/Network-Cn22Onk0.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-BxeQZ-hu.js → NodeAddonsSettingsPanel-D2a6eJdl.js} +1 -1
- package/dist/assets/Notifications-DDmcZBvb.js +1 -0
- package/dist/assets/{PrivacyMaskSettings-CN2hF3qR.js → PrivacyMaskSettings-iuZ15_7K.js} +1 -1
- package/dist/assets/Recordings-DDufOAKc.js +1 -0
- package/dist/assets/{ScanNetworkModal-CfHHLP_k.js → ScanNetworkModal-DMI4Puj8.js} +1 -1
- package/dist/assets/{SceneMonitorEditor-CU-Yj4Sw.js → SceneMonitorEditor-BeQX-lOK.js} +1 -1
- package/dist/assets/SessionsList-DJQsiJpZ.js +2 -0
- package/dist/assets/{Showroom-ChGRG_dB.js → Showroom-yw0GMHMG.js} +1 -1
- package/dist/assets/{System-GfppoElu.js → System-CiRePLgR.js} +1 -1
- package/dist/assets/{Terminal-C7azorOj.js → Terminal-BISFdyS_.js} +3 -3
- package/dist/assets/{Viewer-DWdf6_8H.js → Viewer-C9JIf56u.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CGI8Rmb1.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-PnsnCmkC.js} +1 -1
- package/dist/assets/{addon-icons-context-D3LZwxs2.js → addon-icons-context-Ci899mcp.js} +1 -1
- package/dist/assets/{archive-BOODG6Jz.js → archive-LCkF1dZb.js} +1 -1
- package/dist/assets/{authed-media-F_SweyTm.js → authed-media-D_mDMacH.js} +1 -1
- package/dist/assets/{bell-off-acWBqVHX.js → bell-off-GaaNTQY2.js} +1 -1
- package/dist/assets/{board-model-Bdetmchn.js → board-model-D4eidiUD.js} +1 -1
- package/dist/assets/{boxes-U2BARjlG.js → boxes-C5tX31nL.js} +1 -1
- package/dist/assets/circle-slash-DB409D2V.js +1 -0
- package/dist/assets/client-C7PU3uqv.js +358 -0
- package/dist/assets/{cloud-upload-C12rtBFh.js → cloud-upload-VkAtqPMg.js} +1 -1
- package/dist/assets/crop-CpbGKQ8Q.js +1 -0
- package/dist/assets/{device-integration-icon-BeeizbXV.js → device-integration-icon-DQ-h2aqY.js} +1 -1
- package/dist/assets/device-picker-model-BtWCNPPD.js +1 -0
- package/dist/assets/dist-D10PjgBb.js +358 -0
- package/dist/assets/{dist-CQud2KJs.js → dist-D8lgrNhR.js} +1 -1
- package/dist/assets/{eraser-BmJjK2wc.js → eraser-fzzWtRJk.js} +1 -1
- package/dist/assets/{hard-drive-download-DfnBSa39.js → hard-drive-download-BoCYHTOr.js} +1 -1
- package/dist/assets/{history-CNfarVY1.js → history-CRzL5JIS.js} +1 -1
- package/dist/assets/{hostInit-Df4MAORd.js → hostInit-Cez0g2jV.js} +1 -1
- package/dist/assets/i18n-DPnbeqSW.js +1 -0
- package/dist/assets/{icons-BLn-D-gO.js → icons-C1hjXP2s.js} +1 -1
- package/dist/assets/{index-CcAR8Rlk.js → index-P4Ykaww9.js} +3 -3
- package/dist/assets/{key-BF4fZLz_.js → key-B8BAPcXc.js} +1 -1
- package/dist/assets/{key-round-CjE9GF4T.js → key-round-BJ8BVDGZ.js} +1 -1
- package/dist/assets/{layers-b-H6nVdd.js → layers-CD_tu1Pc.js} +1 -1
- package/dist/assets/{linked-devices-model-BMUapBfD.js → linked-devices-model-BpLdQSS2.js} +1 -1
- package/dist/assets/{list-ordered-CxtL1h3H.js → list-ordered-CV8Mey9J.js} +1 -1
- package/dist/assets/{location-owned-usage-DVh3ypCw.js → location-owned-usage-BWKIfwEv.js} +1 -1
- package/dist/assets/{log-in-D4y0eEu8.js → log-in-CssruFII.js} +1 -1
- package/dist/assets/{memory-stick-jw7STOQc.js → memory-stick-CGxsa350.js} +1 -1
- package/dist/assets/{message-square-plus-EaPlmlsM.js → message-square-plus-CBy6WJpr.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-8a2679ae.js → mf-entry-bootstrap-0-c381d6e5.js} +2 -2
- package/dist/assets/{mic-off-DiEVWn3e.js → mic-off-DZ1gYAW7.js} +1 -1
- package/dist/assets/{monitor-off-bCAhCbCp.js → monitor-off-CLe0AluZ.js} +1 -1
- package/dist/assets/{monitor-smartphone-ASdELIYw.js → monitor-smartphone-ClAfVDzo.js} +1 -1
- package/dist/assets/mount-BtWCNPPD.js +1 -0
- package/dist/assets/notification-schedule-field-DZeBBmOz.js +1 -0
- package/dist/assets/{player-overlays-Fx6RE6kI.js → player-overlays-HaJLnfsi.js} +1 -1
- package/dist/assets/{recycle-twm2_92b.js → recycle-zmChefCS.js} +1 -1
- package/dist/assets/remoteEntry-m6BFtz9i.js +1 -0
- package/dist/assets/{scan-eye-DuyDP-FQ.js → scan-eye-CMTwtxZj.js} +1 -1
- package/dist/assets/{scissors-BJ2tjgEs.js → scissors-BlRdwWP1.js} +1 -1
- package/dist/assets/{search-x-C9z-zNBZ.js → search-x-CbwcvDCN.js} +1 -1
- package/dist/assets/{send-C_-A97md.js → send-6r6Ib9OA.js} +1 -1
- package/dist/assets/{settings-2-A0nya3CH.js → settings-2-BcvvKclK.js} +1 -1
- package/dist/assets/{speaker-C8juqhRE.js → speaker-CMJy4ydK.js} +1 -1
- package/dist/assets/src-DVZ_yCN-.js +67 -0
- package/dist/assets/{timer-reset-DHBRudwU.js → timer-reset-BdRlRB62.js} +1 -1
- package/dist/assets/{ungroup-BLEMoVnk.js → ungroup-BpleWEEi.js} +1 -1
- package/dist/assets/{unlink-YiKNaJO_.js → unlink-DKyXFXyJ.js} +1 -1
- package/dist/assets/{usb-DzR5JdOt.js → usb-6pnA3ol4.js} +1 -1
- package/dist/assets/{use-scenes-feed-wz6RYR34.js → use-scenes-feed-DaSpiEjT.js} +1 -1
- package/dist/assets/{use-stationary-objects-ByxBafUy.js → use-stationary-objects-CMuPPZiU.js} +1 -1
- package/dist/assets/useEventInvalidation-BtWCNPPD.js +1 -0
- package/dist/assets/{useNodeUrlSelection-v_RZ_Gxk.js → useNodeUrlSelection-DKMh9oxh.js} +1 -1
- package/dist/assets/user-round-DvLwlL_U.js +1 -0
- package/dist/assets/{user-x-CY41cwk1.js → user-x-BRy73Tug.js} +1 -1
- package/dist/assets/{video-BRgeujOO.js → video-C_Glztyb.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BrkS3kK7.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-Bwge-Brs.js} +2 -2
- package/dist/index.html +10 -10
- package/dist/server/addon.js +420 -125
- package/package.json +1 -1
- package/dist/assets/Addons-CUPFTOFz.js +0 -4
- package/dist/assets/AiProfiles-CEZqx-Sw.js +0 -3
- package/dist/assets/Build-RW9SjiCM.js +0 -40
- package/dist/assets/Cluster-DdgLAQcF.js +0 -1
- package/dist/assets/ClusterStepModel-BbVbEWqh.js +0 -1
- package/dist/assets/CompositionEditor-BDEQF7e9.js +0 -1
- package/dist/assets/Data-TI1fXQ8e.js +0 -2
- package/dist/assets/Identity-BPWd0o-B.js +0 -1
- package/dist/assets/IntegrationDetail-CFsboI2-.js +0 -1
- package/dist/assets/IntegrationHub-BRMnV56J.js +0 -1
- package/dist/assets/Integrations-Bf2SzcCT.js +0 -1
- package/dist/assets/Integrations-CBqnh8t8.js +0 -1
- package/dist/assets/Locations-BCY7diBp.js +0 -3
- package/dist/assets/MyAccess-DmuNu2nC.js +0 -2
- package/dist/assets/Network-CMlIm20D.js +0 -1
- package/dist/assets/Notifications-B0nD4977.js +0 -1
- package/dist/assets/Recordings-CkHyBhqh.js +0 -1
- package/dist/assets/SessionsList-DrSkZMrj.js +0 -2
- package/dist/assets/circle-slash-90QkMLx4.js +0 -1
- package/dist/assets/client-yfOXPkcm.js +0 -358
- package/dist/assets/crop-BjSJZpbg.js +0 -1
- package/dist/assets/device-picker-model-CRpYde_B.js +0 -1
- package/dist/assets/dist-BfR6seq4.js +0 -358
- package/dist/assets/i18n-B1bxeya5.js +0 -1
- package/dist/assets/mount-CRpYde_B.js +0 -1
- package/dist/assets/notification-schedule-field-BKROBLSv.js +0 -1
- package/dist/assets/remoteEntry-D-hdlf-C.js +0 -1
- package/dist/assets/src-AhVPNkCn.js +0 -67
- package/dist/assets/useEventInvalidation-CRpYde_B.js +0 -1
- package/dist/assets/user-round-CjXCVqIf.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,J as n,K as r,L as i,S as a,b as o,q as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{D as l,O as u,V as d,oa as f,ot as p}from"./player-overlays-Fx6RE6kI.js";import{Dr as m,Er as h,Hr as g,Ir as _,Lr as v,Or as y,Sr as b,Tr as x,Ur as S,_r as C,br as w,cn as ee,kr as T,ln as te,on as ne,sn as re,un as ie,wr as ae,xr as oe,yn as E}from"./client-yfOXPkcm.js";import{$n as se,Hn as D,Ka as ce,Ni as le,_a as O,ga as ue,gu as de,mu as fe,nu as pe,s as me,sr as he,zi as ge,zn as k}from"./src-AhVPNkCn.js";import{t as A}from"./i18n-B1bxeya5.js";import{t as j}from"./useTranslation-D3Is_4B6.js";e();function _e(e){return{target:{kind:`new`,type:e},name:``,features:[]}}function ve(e){return{target:{kind:`existing`,device:e},name:``,features:[]}}function M(e,t){return{target:e.target,name:t,features:e.features.flatMap(e=>e.kind===`fields`?[e]:[])}}function N(e,t,n){return{...e,features:e.features.map(e=>e.cap===t?n(e):e)}}function P(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>e!==t))}function ye(e,t){switch(t.type){case`set-new-type`:return e.target.kind===`new`?{...e,target:{...e.target,type:t.deviceType}}:e;case`set-new-role`:{if(e.target.kind!==`new`)return e;let{role:n,...r}=e.target;return{...e,target:t.role===null?r:{...r,role:t.role}}}case`set-name`:return{...e,name:t.name};case`add-feature`:return e.features.some(e=>e.cap===t.cap)?e:{...e,features:[...e.features,{kind:`fields`,cap:t.cap,fields:{}}]};case`remove-feature`:return{...e,features:e.features.filter(e=>e.cap!==t.cap)};case`set-field`:return N(e,t.cap,e=>({...e,fields:{...e.fields,[t.path]:t.source}}));case`clear-field`:return N(e,t.cap,e=>({...e,fields:P(e.fields,t.path)}));case`remove-binding`:return N(e,t.cap,e=>{let n=e.fields[t.path];return n?.kind===`expression`?{...e,fields:{...e.fields,[t.path]:{...n,bindings:P(n.bindings,t.bindingName)}}}:e});case`copy-feature`:return N(e,t.cap,e=>({...e,fields:{...e.fields,...Object.fromEntries(t.paths.map(e=>[e,{kind:`from`,source:t.from,cap:t.sourceCap,fieldPath:e}]))}}))}}function be(e){let t=b.safeParse({target:e.target,features:e.features});return t.success?{ok:!0,composition:t.data}:{ok:!1,problems:t.error.issues.map(e=>`${e.path.join(`.`)||`composition`}: ${e.message}`)}}function xe(e,t){return JSON.stringify(e)!==JSON.stringify(t)}function Se(e){for(let t=1;;t++){let n=`s${t}`;if(!e.includes(n))return n}}var Ce=[`room`,`converted-sensor`,`derived-binary`],F={addonId:`provider-homeassistant`,stableId:`sensor.template_source`};function we(){return M(te({temperatureSources:re,motionSources:ne,occupancyWindowMs:ee}),`Room`)}function Te(){return M({target:{kind:`new`,type:S.Sensor},features:[{kind:`fields`,cap:`numeric-sensor`,fields:{value:{kind:`expression`,expr:`convert(v, "°C", "°F")`,bindings:{v:{kind:`from`,source:F,cap:`numeric-sensor`,fieldPath:`value`}}},unit:{kind:`expression`,expr:`"°F"`,bindings:{}},lastFetchedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Converted sensor`)}function Ee(){return M({target:{kind:`new`,type:S.Sensor},features:[{kind:`fields`,cap:`binary`,fields:{on:{kind:`expression`,expr:`v > 20`,bindings:{v:{kind:`from`,source:F,cap:`temperature-sensor`,fieldPath:`celsius`}}},lastChangedAt:{kind:`expression`,expr:`now`,bindings:{}}}}]},`Derived binary`)}function De(e){switch(e){case`room`:return we();case`converted-sensor`:return Te();case`derived-binary`:return Ee()}}function Oe(e,t){return typeof t==`number`&&Number.isFinite(t)&&t>0?{kind:`device`,path:`/devices/${t}`}:{kind:`editor`,path:`/build/compositions/${encodeURIComponent(e)}`}}var I=`rounded-lg border border-border bg-surface p-4`,ke=I;function Ae(e){return{addonId:e.addonId,stableId:e.stableId}}function L(e){return new Map(e.map(e=>[y(Ae(e)),e]))}function je(e,t,n){let r=e?.features??[],i=r.findIndex(e=>e.cap===n.cap);return{target:e?.target??{kind:`existing`,device:t},features:i===-1?[...r,n]:r.map((e,t)=>t===i?n:e)}}function Me(e,t){let n=e.features.filter(e=>e.cap!==t);return n.length===0?null:{target:e.target,features:n}}function Ne(e,t){let n=e?.features.find(e=>e.cap===t);return n!==void 0&&n.kind===`fields`?n:null}function R(e){return Array.isArray(e)?e.map(R):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,R(t)]))}function z(e){return JSON.stringify(R(e))}function Pe(e,t){return z(e)===z(t)}function B(e,t){return z(e)===z(t)}function Fe(e,t){switch(e.kind){case`pending`:return{kind:`refused`,reason:A.t(`helpers.customizationSave.notReadYet`)};case`unknown`:return{kind:`refused`,reason:`the customization could not be read: ${e.reason}`};case`not-loaded`:return{kind:`refused`,reason:`the customizations are not loaded yet: ${e.reason}`};case`none`:return t===null?{kind:`noop`}:{kind:`create`,input:{enabled:!0,composition:t}};case`present`:{let n=e.view.block.id;return t===null?{kind:`delete`,blockId:n}:z(t)===z(e.composition)?{kind:`noop`}:{kind:`update`,blockId:n,expectedUpdatedAt:e.view.block.updatedAt,composition:t}}}}function V(e,t){let n=e===`enum`?`string`:e,r=t.kind===`enum`?`string`:t.kind,i={source:t.source,cap:t.cap,fieldPath:t.fieldPath};return r===n?{kind:`from`,...i}:n===`number`&&r===`string`?{kind:`expression`,expr:`number(x)`,bindings:{x:{kind:`from`,...i}}}:null}function H(e){return{kind:`expression`,expr:e,bindings:{}}}function U(e){let t=V(`number`,e.percentage);return t===null?null:{kind:`fields`,cap:`battery`,fields:e.mode===`replace`?{percentage:t}:{percentage:t,charging:H(`"unknown"`),sleeping:H(`false`),lastUpdated:H(`now`)}}}var Ie=[`percent`,...E.options];function W(e,t){return t===`percent`?{level:e}:{"remaining.value":e,"remaining.unit":H(JSON.stringify(t))}}function Le(e,t){let n=V(`number`,t.remaining);if(n===null||!oe.test(t.key)||t.label.trim()===``)return null;let r={label:t.label.trim(),fields:W(n,t.unit)};return{kind:`fields`,cap:`consumables`,...e?.enabled===void 0?{}:{enabled:e.enabled},fields:e?.fields??{lastChangedAt:H(`now`),lastFetchedAt:H(`now`)},items:{...e?.items,[t.key]:r}}}function Re(e){if(e.level!==void 0)return`percent`;let t=e[`remaining.unit`];if(t===void 0||t.kind!==`expression`)return null;try{let e=E.safeParse(JSON.parse(t.expr));return e.success?e.data:null}catch{return null}}function ze(e){return Object.entries(e?.items??{}).map(([e,t])=>{let n=Re(t.fields),r=G(t.fields.level??t.fields[`remaining.value`]),i=r===null?null:V(`number`,r);return n!==null&&i!==null&&Pe(W(i,n),t.fields)?{key:e,label:t.label,unit:n,source:r}:{key:e,label:t.label,unit:null,source:null}})}function Be(e,t){let n=Object.fromEntries(Object.entries(e.items??{}).filter(([e])=>e!==t));return Object.keys(n).length===0?null:{...e,items:n}}function Ve(e){return e.toLowerCase().normalize(`NFD`).replace(/[\u0300-\u036f]/g,``).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,48)}function He(e){let t=e.fields.lastPressedAt;if(t===void 0||t.kind!==`expression`)return[];let n=Object.entries(t.bindings).filter(([e])=>e.startsWith(`active`)).flatMap(([,e])=>e.kind===`from`?[e.source]:[]);return[...new Map(n.map(e=>[y(e),e])).values()]}function Ue(e){let t=e.fields.lastPressedAt;if(t===void 0||t.kind!==`expression`)return[];let n=t.bindings;return Object.entries(n).flatMap(([e,t])=>{if(!e.startsWith(`active`)||t.kind!==`from`)return[];let r=n[`changed${e.slice(6)}`];return r===void 0||r.kind!==`from`?[]:[{source:t.source,cap:t.cap,activeField:t.fieldPath,changedAtField:r.fieldPath}]})}function G(e){if(e===void 0)return null;if(e.kind===`from`){let{kind:t,...n}=e;return{...n,kind:`number`}}if(e.kind!==`expression`||e.expr!==`number(x)`)return null;let t=e.bindings.x;if(t===void 0||t.kind!==`from`||Object.keys(e.bindings).length!==1)return null;let{kind:n,...r}=t;return{...r,kind:`string`}}function We(e,t){let n=G(e.fields.percentage);if(n===null)return!1;let r=U({percentage:n,mode:t}),{enabled:i,...a}=e;return r!==null&&B(a,r)}function K(e){return e.map(e=>({id:e.id,name:e.name,addonId:e.addonId,stableId:e.stableId,location:e.location,type:e.type}))}function Ge(e,t,n){let r=t.trim().toLowerCase();return r===``?[]:e.filter(e=>!n.includes(e.id)&&[e.name,e.stableId,e.location??``].some(e=>e.toLowerCase().includes(r))).toSorted((e,t)=>e.name.localeCompare(t.name)).slice(0,20)}function q(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n||Array.isArray(n))return;n=Object.getOwnPropertyDescriptor(n,e)?.value}return n}function Ke(e,t,n,r){return r===null?{kind:`from`,source:e,cap:t,fieldPath:n.path}:V(r,{source:e,cap:t,fieldPath:n.path,kind:n.kind})}function qe(e,t,n,r){let i={addonId:e.addonId,stableId:e.stableId};return t.caps.flatMap(e=>e.fields.filter(e=>e.item!==!0).map(t=>({cap:e.cap,path:t.path,kind:t.kind,value:n===null?void 0:q(n[e.cap],t.path),source:Ke(i,e.cap,t,r)})))}function J(e,t){return t?e===void 0?`—`:e===null?`null`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e):`…`}var Je=[];function Y({title:e,targetKind:t,excludeDeviceIds:r=Je,onPick:i,onCancel:o}){let{t:s}=j(),[f,p]=n(null);return a(`aside`,{"aria-label":e,className:`${u} ${l} flex flex-col gap-2`,children:[c(`h3`,{className:d,children:e}),f===null?c(Ye,{excludeDeviceIds:r,onSelect:p}):c(X,{device:f,targetKind:t,onPick:i,onBack:()=>p(null)}),c(`div`,{children:c(D,{variant:`ghost`,size:`sm`,onClick:o,children:s(`customize.picker.cancel`)})})]})}function Ye({excludeDeviceIds:e,onSelect:t}){let{t:r}=j(),[i,s]=n(``),l=O({projection:`slim`});return a(o,{children:[a(`label`,{className:`flex flex-col gap-1 text-[11px] text-foreground-subtle`,children:[r(`customize.picker.search`),c(pe,{type:`search`,"aria-label":r(`customize.picker.search`),value:i,onChange:e=>s(e.target.value)})]}),l.status===`pending`&&c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:r(`customize.picker.loadingDevices`)}),l.status===`error`&&c(k,{title:r(`customize.picker.devicesFailed`),message:l.error?.message??``}),l.status===`success`&&c(`ul`,{className:`flex flex-col gap-1`,children:Ge(K(l.data),i,e).map(e=>c(`li`,{children:a(`button`,{type:`button`,className:`text-left text-[11px] hover:underline`,onClick:()=>t(e),children:[e.name,` `,a(`span`,{className:`text-foreground-subtle`,children:[`· `,e.stableId]})]})},e.id))})]})}function X({device:e,targetKind:t,selected:n,onPick:r,onBack:i}){let{t:o}=j(),s=ue({deviceId:e.id}),l=ce({deviceId:e.id});if(s.status===`pending`)return c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:o(`customize.picker.loadingFields`)});if(s.status===`error`)return c(k,{title:o(`customize.picker.fieldsFailed`),message:s.error?.message??``});let u=qe(e,s.data,l.status===`success`?l.data:null,t),d=u.filter(e=>e.source===null).length,f={addonId:e.addonId,stableId:e.stableId};return a(`div`,{className:`flex flex-col gap-1`,children:[a(`button`,{type:`button`,className:`text-left text-[11px] text-primary`,onClick:i,children:[`← `,e.name]}),l.status===`error`&&c(`p`,{role:`alert`,className:`text-[10px] text-warning`,children:o(`customize.picker.valuesFailed`,{reason:l.error?.message??``})}),c(`ul`,{role:`listbox`,"aria-label":o(`customize.picker.fields`),className:`flex flex-col gap-1`,children:u.map(t=>{let i=t.source;if(i===null)return null;let o=()=>r({device:e,ref:f,cap:t.cap,path:t.path,kind:t.kind,source:i,value:t.value});return a(`li`,{role:`option`,"aria-selected":n?.cap===t.cap&&n.path===t.path,tabIndex:0,className:`flex justify-between gap-2 text-[11px] cursor-pointer hover:bg-surface-hover rounded px-1`,onClick:o,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&o()},children:[a(`span`,{className:`font-mono`,children:[t.cap,`.`,t.path]}),c(`span`,{children:J(t.value,l.status===`success`)})]},`${t.cap}.${t.path}`)})}),d>0&&t!==null&&c(`p`,{className:`text-[10px] text-foreground-subtle`,children:o(`customize.picker.hidden`,{count:d,kind:o(`customize.kinds.${t}`)})})]})}var Xe=`integration`;function Z(e,t){switch(e.kind){case`from`:{let n=y(e.source);return`${t.get(n)??n} · ${e.cap}.${e.fieldPath}`}case`expression`:return e.expr;case`code`:return`code`}}function Ze(e,t){if(e.kind===`unreachable`)return{kind:`unknown`,reason:e.error};if(e.state===null)return{kind:`unknown`,reason:A.t(`helpers.fieldsTableRows.composerNotReported`)};let n=e.state.fields.find(t);return n===void 0?{kind:`unknown`,reason:A.t(`helpers.fieldsTableRows.noValue`)}:n.state===`unavailable`?{kind:`unavailable`,reason:n.reason??A.t(`common.unavailable`)}:{kind:`value`,value:n.value,staleReason:n.state===`stale`?n.reason??A.t(`common.stale`):null}}function Q(e,t,n,r){return{key:`${e.feature.cap}.${t}`,cap:e.feature.cap,field:t,origin:`composed`,mode:e.mode,from:Z(n,e.input.sourceNames),value:e.enabled?Ze(e.input.state,r):{kind:`off`}}}function Qe(e){let t=e.feature.cap;return Object.entries(e.feature.fields).map(([n,r])=>Q(e,n,r,e=>e.cap===t&&e.path===n&&e.item===void 0))}function $e(e){let t=e.feature.cap;return Object.entries(e.feature.items??{}).flatMap(([n,r])=>Object.entries(r.fields).map(([r,i])=>Q(e,x(w,n,r),i,e=>e.cap===t&&e.path===r&&e.item?.arrayPath===`items`&&e.item.key===n)))}function et(e,t,n){if(e===null)return{kind:`unknown`,reason:A.t(`helpers.fieldsTableRows.stateUnreadable`)};let r=q(e[t],n),i=r===void 0?void 0:_(r);return i===void 0?{kind:`unknown`,reason:A.t(`helpers.fieldsTableRows.notReported`)}:{kind:`value`,value:i,staleReason:null}}function tt(e){if(e.mode!==`replace`)return[];let t=e.feature.cap,n=new Set(Object.keys(e.feature.fields));return(e.input.nativeFields.get(t)??[]).filter(e=>!n.has(e)).map(n=>({key:`${t}.${n}`,cap:t,field:n,origin:`native`,mode:e.mode,from:Xe,value:et(e.input.snapshot,t,n)}))}function nt(e){return e.composition.features.flatMap(t=>{if(t.kind!==`fields`)return[];let n={feature:t,mode:e.nativeCaps.has(t.cap)?`replace`:`add`,enabled:ae(t),input:e};return[...Qe(n),...$e(n),...tt(n)]})}var rt={min:`min(a, b, …)`,max:`max(a, b, …)`,abs:`abs(x)`,floor:`floor(x)`,ceil:`ceil(x)`,sqrt:`sqrt(x)`,round:`round(x, digits?)`,pow:`pow(x, y)`,clamp:`clamp(x, lo, hi)`,avg:`avg(a, b, …)`,sum:`sum(a, b, …)`,coalesce:`coalesce(a, b, …)`,age:`age(now, ts)`,convert:`convert(x, "from", "to")`,any:`any(a, b, …)`,all:`all(a, b, …)`,within:`within(ts, ms)`,number:`number(x)`,latest:`latest(ts, …)`,rose:`rose(level, changedAt, debounceMs?)`,count:`count(x)`},it=/[A-Za-z_][A-Za-z0-9_]*$/;function at(e,t,n){let r=it.exec(e.slice(0,t))?.[0]??``;if(r===``)return[];let i=n.filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`binding`,label:e,insert:e,hintKey:null})),a=`now`.startsWith(r)?[{kind:`now`,label:`now`,insert:`now`,hintKey:`compositionEditor.now`}]:[],o=[...v].filter(e=>e.startsWith(r)).toSorted().map(e=>({kind:`builtin`,label:rt[e]??e,insert:`${e}(`,hintKey:`compositionEditor.builtins.${e}`}));return[...i,...a,...o].slice(0,8)}function ot(e,t,n){let r=t-(it.exec(e.slice(0,t))?.[0]??``).length;return{text:`${e.slice(0,r)}${n.insert}${e.slice(t)}`,cursor:r+n.insert.length}}e();function st({label:e,value:t,bindings:r,onChange:i}){let{t:o}=j(),l=s(null),[u,d]=n(t.length),f=at(t,u,r);return a(`div`,{className:`flex flex-col gap-1`,children:[a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[e,c(`input`,{ref:l,className:`font-mono px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`,value:t,onChange:e=>{i(e.target.value),d(e.target.selectionStart??e.target.value.length)},onSelect:e=>d(e.currentTarget.selectionStart??t.length)})]}),f.length>0&&c(`ul`,{role:`listbox`,"aria-label":o(`compositionEditor.suggestions`),className:`rounded border border-border bg-surface text-[11px]`,children:f.map(e=>a(`li`,{role:`option`,"aria-selected":!1,tabIndex:0,className:`flex justify-between gap-2 px-1 cursor-pointer hover:bg-surface-hover`,onClick:()=>{let n=ot(t,u,e);i(n.text),d(n.cursor),l.current?.focus()},children:[c(`span`,{className:`font-mono`,children:e.label}),e.hintKey!==null&&c(`span`,{className:`text-foreground-subtle`,children:o(e.hintKey)})]},`${e.kind}:${e.label}`))})]})}function ct(e,t,n){if(e.kind===`code`)return{kind:`unavailable`,reason:A.t(`helpers.fieldPreview.codeFields`)};if(e.kind===`expression`&&(C(e.expr,`rose`)||C(e.expr,`count`)))return{kind:`runtime-only`};let r=T(e).filter(e=>t.get(m(e.source,e.cap))?.kind!==`value`).map(h);if(r.length>0)return{kind:`waiting`,missing:r};let i=ie({source:e,now:n,read:e=>{let n=t.get(m(e.source,e.cap)),r=n?.kind===`value`?q(n.slice,e.fieldPath):void 0,i=r===void 0?void 0:_(r);return i===void 0?{state:`unavailable`,reason:A.t(`helpers.fieldPreview.notReported`,{path:`${e.cap}.${e.fieldPath}`}),fatal:!1}:{state:`fresh`,value:i}}});return i.state===`unavailable`?{kind:`unavailable`,reason:i.reason}:{kind:`value`,value:i.value,stale:i.reason}}e();function lt({sliceKey:e,deviceId:n,capName:r,onReading:i}){let a=me(p().trpcClient,n,r);return t(()=>{i(e,a===void 0?{kind:`pending`}:{kind:`value`,slice:a})},[e,a,i]),null}function ut(e,t){return[...new Map(T(e).map(e=>[m(e.source,e.cap),e]))].map(([e,n])=>({key:e,read:n,device:t.get(y(n.source))}))}function dt({source:e}){let{t}=j(),r=O({projection:`slim`}),[o,s]=n(new Map),l=i((e,t)=>{s(n=>new Map([...n,[e,t]]))},[]),u=ut(e,L(r.status===`success`?K(r.data):[])),d=r.status===`success`?u.filter(e=>e.device===void 0).map(e=>y(e.read.source)):[];return a(`div`,{className:`flex flex-wrap items-center gap-2 text-[11px]`,children:[u.map(e=>e.device===void 0?null:c(lt,{sliceKey:e.key,deviceId:e.device.id,capName:e.read.cap,onReading:l},e.key)),c(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.label`)}),r.status===`error`?c(`span`,{className:`text-warning`,children:t(`compositionEditor.preview.devicesFailed`,{reason:r.error?.message??``})}):d.length>0?c(`span`,{className:`text-warning`,children:t(`compositionEditor.preview.unknownDevice`,{sources:d.join(`, `)})}):c(ft,{preview:ct(e,o,Date.now())})]})}function ft({preview:e}){let{t}=j();switch(e.kind){case`value`:return a(`strong`,{children:[`→ `,J(e.value,!0),e.stale===null?``:` (${e.stale})`]});case`unavailable`:return c(`span`,{className:`text-warning`,children:e.reason});case`waiting`:return c(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.waiting`,{sources:e.missing.join(`, `)})});case`runtime-only`:return c(`span`,{className:`text-foreground-subtle`,children:t(`compositionEditor.preview.runtimeOnly`)})}}e();function pt({path:e,kind:t,required:r,source:i,onSet:s,onClear:l,onRemoveBinding:u,sourceNames:d}){let{t:f}=j(),[p,m]=n(`idle`),h=i?.kind===`expression`?i:null;return a(`div`,{className:`flex flex-col gap-1 rounded border border-border p-2`,children:[a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[c(`span`,{className:`font-mono text-[11px]`,children:e}),a(`span`,{className:`text-[10px] text-foreground-subtle`,children:[f(`customize.kinds.${t}`),r?` · ${f(`compositionEditor.required`)}`:``]}),c(D,{size:`sm`,variant:`outline`,onClick:()=>m(`take`),children:f(`compositionEditor.takeFrom`)}),c(D,{size:`sm`,variant:`outline`,"aria-pressed":h!==null,onClick:()=>s(h??{kind:`expression`,expr:`null`,bindings:{}}),children:f(`compositionEditor.formula`)}),i!==void 0&&c(D,{size:`sm`,variant:`ghost`,onClick:l,children:f(`compositionEditor.clear`)})]}),i?.kind===`from`&&c(`span`,{className:`text-[11px]`,children:Z(i,d)}),h!==null&&a(o,{children:[c(st,{label:f(`compositionEditor.formulaFor`,{path:e}),value:h.expr,bindings:Object.keys(h.bindings),onChange:e=>s({...h,expr:e})}),c(`ul`,{className:`text-[11px] flex flex-col gap-0.5`,children:Object.entries(h.bindings).map(([e,t])=>a(`li`,{className:`flex flex-wrap items-center gap-2`,children:[c(`span`,{className:`font-mono`,children:e}),c(`span`,{children:t.kind===`from`?Z(t,d):JSON.stringify(t.value)}),c(D,{size:`sm`,variant:`ghost`,"aria-label":f(`compositionEditor.removeBinding`,{name:e}),onClick:()=>u(e),children:`×`})]},e))}),c(D,{size:`sm`,variant:`ghost`,onClick:()=>m(`add-binding`),children:f(`compositionEditor.addSource`)})]}),p!==`idle`&&c(Y,{title:f(p===`take`?`compositionEditor.takeFrom`:`compositionEditor.addSource`),targetKind:p===`take`?t:null,onCancel:()=>m(`idle`),onPick:e=>{if(p===`take`)s(e.source);else if(h!==null){let t=Se(Object.keys(h.bindings));s({...h,bindings:{...h.bindings,[t]:{kind:`from`,source:e.ref,cap:e.cap,fieldPath:e.path}}})}m(`idle`)}}),i!==void 0&&c(dt,{source:i})]})}e();function mt(e){return e===null||e.kind===`known`?null:e}function ht({draft:e,deviceType:t,nativeCaps:r,targetFields:i,dispatch:s}){let{t:l}=j(),u=le({deviceType:t}),d=O({projection:`slim`}),f=new Map([...L(d.status===`success`?K(d.data):[])].map(([e,t])=>[e,t.name])),[p,m]=n(null),h=mt(r)??mt(i),g=r?.kind===`known`?r.value:new Set,_=new Set(e.features.map(e=>e.cap)),v=u.status===`success`?u.data.caps.filter(e=>!_.has(e.cap)&&!g.has(e.cap)):[],y=[...g].filter(e=>!_.has(e)),b=e=>g.has(e)?((i?.kind===`known`?i.value.caps.find(t=>t.cap===e):void 0)?.fields??[]).filter(e=>e.item!==!0&&!e.path.includes(`.`)).map(e=>({path:e.path,kind:e.kind,required:!1})):((u.status===`success`?u.data.caps.find(t=>t.cap===e):void 0)?.fields??[]).map(e=>({path:e.path,kind:e.kind,required:e.required}));return h===null?a(o,{children:[a(`section`,{"aria-labelledby":`editor-features`,className:`${I} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),u.status===`pending`&&c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.checking`)}),u.status===`error`&&c(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.unknown`,{reason:u.error?.message??``})}),a(`div`,{className:`flex flex-wrap gap-1`,children:[e.features.map(e=>a(`span`,{className:`flex items-center gap-1 rounded border border-border px-1.5 text-[11px]`,children:[e.cap,c(he,{variant:g.has(e.cap)?`default`:`info`,children:g.has(e.cap)?l(`compositionEditor.replaces`):l(`compositionEditor.added`)}),c(`button`,{type:`button`,"aria-label":l(`compositionEditor.removeFeature`,{cap:e.cap}),onClick:()=>s({type:`remove-feature`,cap:e.cap}),children:`×`})]},e.cap)),v.map(e=>a(D,{size:`sm`,variant:`outline`,onClick:()=>s({type:`add-feature`,cap:e.cap}),children:[`+ `,e.cap]},e.cap)),y.map(e=>c(D,{size:`sm`,variant:`ghost`,onClick:()=>s({type:`add-feature`,cap:e}),children:l(`compositionEditor.replaceIn`,{cap:e})},e))]})]}),e.features.map(e=>a(`section`,{"aria-label":l(`compositionEditor.steps.fieldsOf`,{cap:e.cap}),className:`${I} flex flex-col gap-2`,children:[a(`div`,{className:`flex items-center justify-between`,children:[c(`h2`,{className:`text-sm font-semibold`,children:l(`compositionEditor.steps.fieldsOf`,{cap:e.cap})}),c(D,{size:`sm`,variant:`outline`,onClick:()=>m(e.cap),children:l(`compositionEditor.copyFeature`)})]}),p===e.cap&&c(Y,{title:l(`compositionEditor.copyFeature`),targetKind:null,onCancel:()=>m(null),onPick:t=>{s({type:`copy-feature`,cap:e.cap,from:t.ref,sourceCap:t.cap,paths:b(e.cap).map(e=>e.path)}),m(null)}}),b(e.cap).map(t=>c(pt,{path:t.path,kind:t.kind,required:t.required,source:e.fields[t.path],onSet:n=>s({type:`set-field`,cap:e.cap,path:t.path,source:n}),onClear:()=>s({type:`clear-field`,cap:e.cap,path:t.path}),onRemoveBinding:n=>s({type:`remove-binding`,cap:e.cap,path:t.path,bindingName:n}),sourceNames:f},t.path))]},e.cap))]}):a(`section`,{"aria-labelledby":`editor-features`,className:`${I} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-features`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.features`)}),c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:h.kind===`unknown`?h.reason:l(`compositionEditor.reading`)})]})}var $=`px-1.5 py-0.5 text-[11px] bg-background border border-border rounded`;function gt({draft:e,targetName:t,dispatch:n}){let r=f(),{t:i}=j(),o=e.target;return a(`section`,{"aria-labelledby":`editor-target`,className:`${I} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-target`,className:`text-sm font-semibold`,children:i(`compositionEditor.steps.target`)}),o.kind===`existing`?c(`p`,{className:`text-[11px]`,children:i(`compositionEditor.existingTarget`,{name:t??`${o.device.addonId}/${o.device.stableId}`})}):a(`div`,{className:`grid grid-cols-3 gap-2`,children:[a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[i(`compositionEditor.targetType`),c(`select`,{className:$,value:o.type,onChange:e=>{let t=Object.values(S).find(t=>t===e.target.value);t!==void 0&&n({type:`set-new-type`,deviceType:t})},children:Object.values(S).map(e=>c(`option`,{value:e,children:de(e,r).label},e))})]}),a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[i(`customize.identity.role`),a(`select`,{className:$,value:o.role??``,onChange:e=>n({type:`set-new-role`,role:Object.values(g).find(t=>t===e.target.value)??null}),children:[c(`option`,{value:``,children:i(`customize.identity.noRole`)}),Object.values(g).map(e=>c(`option`,{value:e,children:fe(e,r).label},e))]})]}),a(`label`,{className:`flex flex-col gap-1 text-[11px]`,children:[i(`compositionEditor.name`),c(`input`,{className:$,value:e.name,onChange:e=>n({type:`set-name`,name:e.target.value})})]})]})]})}e();function _t({draft:e,blockId:r,saving:i,onSave:o,onCancel:s}){let{t:l}=j(),u=ge(),d=be(e),f=d.ok?JSON.stringify(d.composition):``,[p,m]=n({key:``,state:{kind:`checking`}});t(()=>{if(!d.ok)return;let e=d.composition,t=setTimeout(()=>{u.mutateAsync({composition:e,...r===null?{}:{blockId:r}}).then(e=>m({key:f,state:e.ok?{kind:`ok`}:{kind:`refused`,problems:e.problems}})).catch(e=>m({key:f,state:{kind:`unknown`,reason:e instanceof Error?e.message:String(e)}}))},500);return()=>clearTimeout(t)},[f,r]);let h=d.ok?p.key===f?p.state:{kind:`checking`}:{kind:`invalid-draft`,problems:d.problems};return a(`section`,{"aria-labelledby":`editor-verify`,className:`${I} flex flex-col gap-2`,children:[c(`h2`,{id:`editor-verify`,className:`text-sm font-semibold`,children:l(`compositionEditor.steps.verify`)}),h.kind===`checking`&&c(`p`,{role:`status`,className:`text-[11px] text-foreground-subtle`,children:l(`compositionEditor.verify.checking`)}),h.kind===`ok`&&c(`p`,{className:`text-[11px] text-success`,children:l(`compositionEditor.verify.ok`)}),h.kind===`unknown`&&c(`p`,{role:`alert`,className:`text-[11px] text-warning`,children:l(`compositionEditor.verify.unknown`,{reason:h.reason})}),(h.kind===`invalid-draft`||h.kind===`refused`)&&c(`ul`,{role:`alert`,className:`flex flex-col gap-1 text-[11px] text-danger`,children:h.kind===`invalid-draft`?h.problems.map(e=>c(`li`,{children:e},e)):h.problems.map(e=>a(`li`,{children:[c(`span`,{className:`font-mono`,children:e.path}),` — `,e.message]},`${e.path}:${e.code}`))}),a(`div`,{className:`flex gap-2`,children:[c(D,{variant:`ghost`,onClick:s,children:l(`compositionEditor.cancel`)}),c(D,{disabled:h.kind!==`ok`||i||!d.ok,onClick:()=>d.ok&&o(d.composition),children:l(`compositionEditor.save`)})]})]})}e();function vt({initial:e,blockId:t,deviceType:r,targetName:i=null,nativeCaps:a,targetFields:o,save:s,onCancel:l,showTemplates:u=!1}){let[d,f]=n(e),p=`${d.name}:${d.features.map(e=>e.cap).join(`,`)}:${d.target.kind===`new`?d.target.type:`existing`}`;return c(yt,{seed:d,blockId:t,deviceType:r,targetName:i,nativeCaps:a,targetFields:o,showTemplates:u,onApplyTemplate:e=>{f(De(e))},save:s,onCancel:l},p)}function yt({seed:e,blockId:t,deviceType:i,targetName:o,nativeCaps:s,targetFields:l,showTemplates:u,onApplyTemplate:d,save:f,onCancel:p}){let{t:m}=j(),h=se(),[g,_]=r(ye,e),[v,y]=n(!1),[b,x]=n(null),S=async t=>{xe(e,g)&&!await h({title:m(`compositionEditor.templates.confirmTitle`),message:m(`compositionEditor.templates.confirmMessage`),confirmLabel:m(`compositionEditor.templates.confirmApply`),variant:`danger`})||d(t)},C=g.target.kind===`new`?g.target.type:i,w=async e=>{y(!0);let t=await f(e,g.name);y(!1),x(t.kind===`refused`?t.reason:null)};return a(`div`,{className:`flex flex-col gap-4`,children:[u&&g.target.kind===`new`&&a(`div`,{className:`rounded-lg border border-border bg-surface p-4 flex flex-wrap gap-2`,"data-testid":`composition-templates`,children:[c(`span`,{className:`text-[11px] text-foreground-subtle self-center`,children:m(`compositionEditor.templates.label`)}),Ce.map(e=>c(D,{size:`sm`,variant:`outline`,onClick:()=>void S(e),children:m(`compositionEditor.templates.${e}`)},e))]}),c(gt,{draft:g,targetName:o,dispatch:_}),c(ht,{draft:g,deviceType:C,nativeCaps:s,targetFields:l,dispatch:_}),c(_t,{draft:g,blockId:t,saving:v,onSave:e=>void w(e),onCancel:p}),b!==null&&c(`p`,{role:`alert`,className:`text-[11px] text-danger break-words`,children:b})]})}export{Me as C,ve as D,M as E,_e as O,je as S,Oe as T,G as _,X as a,Fe as b,K as c,Le as d,ze as f,Ve as g,We as h,nt as i,Ie as l,Ue as m,ct as n,J as o,He as p,st as r,q as s,vt as t,U as u,Be as v,ke as w,B as x,Ne as y};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,L as i,S as a,b as o,o as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{An as l,D as u,Fn as d,It as f,Ji as p,Jr as m,Nt as h,Q as g,Wi as _,Wr as v,Yi as y,Zr as b,ai as x,fn as S,ir as C,kn as w,or as T,pi as E,rr as D,si as O,vn as k,xi as A,yi as j}from"./player-overlays-Fx6RE6kI.js";import{n as M,t as N}from"./cloud-upload-C12rtBFh.js";import{t as P}from"./circle-slash-90QkMLx4.js";import{t as F}from"./hard-drive-download-DfnBSa39.js";import{$n as I,$r as L,B as R,Bn as ee,Dn as te,F as ne,Fr as re,Gc as ie,Gt as ae,Hn as z,Kc as oe,Kt as se,Mc as ce,Mn as le,Nn as ue,On as de,Qr as fe,Uc as pe,V as me,Wc as he,Zl as ge,Zr as _e,ai as ve,al as ye,an as be,ci as xe,di as Se,ei as Ce,fi as we,ii as Te,in as Ee,jn as De,kn as B,li as Oe,na as ke,ni as Ae,nn as je,nu as V,oi as Me,q as H,ri as Ne,ru as U,si as Pe,sn as Fe,ti as Ie,ui as Le,z as Re,zn as ze}from"./src-AhVPNkCn.js";import{t as W}from"./i18n-B1bxeya5.js";import{t as G}from"./useTranslation-D3Is_4B6.js";import"./mount-CRpYde_B.js";import{$ as Be,T as Ve,Z as He,nt as Ue}from"./index-CcAR8Rlk.js";import{t as We}from"./AdminSectionedPage-D5J86Kfp.js";import{t as Ge}from"./AdminPage--m3xHpjx.js";import{n as Ke}from"./authed-media-F_SweyTm.js";import{t as K}from"./format-size-DIxKXxtj.js";import{a as qe,c as Je,l as Ye,n as Xe,o as Ze,s as Qe,t as $e,u as et}from"./location-owned-usage-DVh3ypCw.js";e();function tt(){let{t:e}=G(),r=s(),i=I(),{data:o,isLoading:l,isError:u}=oe({}),d=ie(),f=n(()=>d.data??[],[d.data]),{data:p}=ce({},{refetchOnWindowFocus:!1}),m=n(()=>$e(o??[],p?.locations),[o,p?.locations]),{data:h}=he({},{refetchOnWindowFocus:!1}),g=n(()=>qe(h),[h]),{state:_,openNew:v,openEdit:y,close:b}=Re(),[x,S]=R(`type`),C=()=>{S(null),b()},w=e=>{S(e),v()},T=e=>{S(null),y(e.id)},E=o??[],D=_.mode===`edit`?E.find(e=>e.id===_.id)??null:null;t(()=>{_.mode===`new`&&(x===null||x===``)&&(S(null),b())},[_.mode,x,b,S]),t(()=>{_.mode===`edit`&&!l&&D===null&&(S(null),b())},[_.mode,l,D,b,S]),t(()=>{_.mode===`closed`&&x!==null&&S(null)},[_.mode,x,S]);let O=pe({onSuccess:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),k=ye({onSuccess:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),A=async(t,n)=>{Ye(n)&&!await i({title:e(`system.storage.disable`,`Disable "{{displayName}}"?`,{displayName:t.displayName}),message:e(`system.storage.nothingIsDeletedSetThe`,`{{consequence}} Nothing is deleted — set the location back to Read-only or Active to bring its footage back.`,{consequence:Je(n).consequence}),confirmLabel:e(`common.disable`,`Disable`),variant:`danger`})||k.mutate(Qe(t,{mode:n}))},j=async t=>{if(await i({title:e(`system.storage.deleteLocation`,`Delete location "{{displayName}}"?`,{displayName:t.displayName}),message:e(`system.storage.thisRemovesTheLocationRecord`,`This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.`),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`}))try{await O.mutateAsync({id:t.id}),_.mode===`edit`&&_.id===t.id&&C()}catch(n){await i({title:e(`system.storage.deleteAnyway`,`Delete anyway?`),message:e(`system.storage.forcingNote`,{error:n instanceof Error?n.message:String(n)}),confirmLabel:e(`system.storage.forceDelete`,`Force delete`),variant:`danger`})&&O.mutate({id:t.id,force:!0},{onSuccess:()=>{_.mode===`edit`&&_.id===t.id&&C()}})}},M=n(()=>{let e=new Map;for(let t of o??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[o]),N=l||d.isLoading,P=u||d.isError,F=_.mode===`new`&&x!==null&&x!==``,L=_.mode===`edit`&&D!==null;return a(Ge,{embedded:!0,children:[N&&c(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:e(`system.storage.loadingLocations`,`Loading locations…`)}),P&&c(`div`,{className:`text-xs text-danger`,children:e(`system.storage.failedToLoadStorageLocations`,`Failed to load storage locations.`)}),!N&&!P&&a(`div`,{className:`space-y-3`,children:[f.length===0&&c(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:e(`system.storage.noStorageLocationsDeclaredBy`,`No storage locations declared by any installed addon.`)}),f.map(e=>c(Xe,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:M.get(e.id)??[],onAdd:w,onEdit:T,onDelete:e=>{j(e)},ownedBytesById:m,drainById:g,onSetMode:(e,t)=>{A(e,t)}},e.id))]}),F&&x!==null&&c(et,{initialType:x,onClose:C,onCreated:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),C()}}),L&&D!==null&&c(Ze,{location:D,onClose:C,onSaved:()=>{r.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),C()}})]})}var q={settings:{labelKey:`helpers.backupDatabases.settings.label`,descriptionKey:`helpers.backupDatabases.settings.description`,shortKey:`helpers.backupDatabases.settings.short`},events:{labelKey:`helpers.backupDatabases.events.label`,descriptionKey:`helpers.backupDatabases.events.description`,shortKey:`helpers.backupDatabases.events.short`},history:{labelKey:`helpers.backupDatabases.history.label`,descriptionKey:`helpers.backupDatabases.history.description`,shortKey:`helpers.backupDatabases.history.short`}},nt=Object.keys(q),J=[`settings`];function rt(){return W.t(`helpers.backupDatabases.notCreated`)}function it(e){return W.t(q[e].labelKey)}function at(e){return W.t(q[e].shortKey)}function ot(e){return W.t(q[e].descriptionKey)}function Y(e){let t=new Set(e);return nt.filter(e=>t.has(e))}function X(e){return e!==void 0&&e.length>0?Y(e):J}function st(e){return Y(e)}function ct(e,t){return t===void 0||!t.answered?`unknown`:t.databases.includes(e)?`present`:`absent`}function lt(e,t,n){return ct(e,t)===`absent`&&!n.has(e)}function ut(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function dt(e){return!e.includes(`settings`)}function ft(e){return{databases:[...st(e)]}}function pt(e,t){return e!==void 0&&e.length>0?Y(e):t!==void 0&&t.length>0?Y(t.map(e=>e.databaseId??`settings`)):J}function Z({databases:e}){return c(`span`,{className:`text-xs font-medium uppercase tracking-wide text-foreground-muted`,"data-testid":`backup-database-badges`,children:e.map(e=>at(e)).join(` · `)})}e();var mt=[[`backup`,`listDestinations`]],ht=[`backup`,`listArchives`];function gt({destinationId:e,restoreSupported:t,onOpenRestoreWizard:o}){let{t:l}=G(),u=s(),d=I(),{data:p,isLoading:m,isError:h}=Ne({destinationId:e}),g=p??[],_=fe({onSuccess:()=>{u.invalidateQueries({queryKey:[[...ht]]}),u.invalidateQueries({queryKey:mt})}}),y=i(async t=>{await d({title:l(`backup.archiveList.deleteThisArchive`,`Delete this archive?`),message:l(`backup.archiveList.permanentlyDeletesAndFrees`,`Permanently deletes "{{value1}}" and frees {{value2}}.`,{value1:t.label??t.id,value2:K(t.sizeBytes)}),confirmLabel:l(`common.delete`,`Delete`),variant:`danger`})&&_.mutate({destinationId:e,backupId:t.id})},[d,e,_,l]),[b,x]=r(null),S=i(async t=>{x(t.id);try{let n=await Ke(_t(e,t.id)),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${t.label??t.id}.tar.gz${t.encryption===void 0?``:`.csbk`}`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}finally{x(null)}},[e]),C=n(()=>[...g].toSorted((e,t)=>t.createdAt-e.createdAt),[g]);return m?c(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:l(`backup.archiveList.loadingArchives`,`Loading archives…`)}):h?c(`div`,{className:`text-xs text-danger py-2`,children:l(`backup.archiveList.failedToReadManifestFor`,`Failed to read manifest for this destination`)}):C.length===0?c(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:l(`backup.archiveList.noArchivesAtThisDestination`,`No archives at this destination yet.`)}):c(ae,{columns:[{key:`when`,header:l(`backup.archiveList.when`,`When`),sortValue:e=>e.createdAt,render:e=>c(`span`,{className:`tabular-nums`,children:vt(e.createdAt)})},{key:`label`,header:l(`backup.archiveList.label`,`Label`),sortValue:e=>e.label??null,render:e=>a(`span`,{className:`inline-flex items-center gap-1`,children:[e.encryption!==void 0&&c(D,{className:`h-3 w-3 text-success`,"aria-label":l(`backup.archiveList.encryptedRestoreNeedsBackupKey`,`encrypted — restore needs backup key {{keyId}}`,{keyId:e.encryption.keyId})}),e.label??c(`span`,{className:`text-foreground-subtle italic`,children:`—`})]})},{key:`databases`,header:l(`backup.archiveList.databases`,`Databases`),nowrap:!1,notSortableReason:`Database badges`,render:e=>c(Z,{databases:X(e.databases)})},{key:`includes`,header:l(`backup.archiveList.files`,`Files`),nowrap:!1,notSortableReason:`Location list`,render:e=>e.locations.length>0?c(`span`,{className:`text-foreground-subtle`,children:e.locations.join(`, `)}):c(`span`,{className:`text-foreground-subtle italic`,children:l(`common.none`)})},{key:`size`,header:l(`backup.archiveList.size`,`Size`),align:`right`,sortValue:e=>e.sizeBytes,render:e=>c(`span`,{className:`tabular-nums`,children:K(e.sizeBytes)})},{key:`actions`,header:``,align:`right`,notSortableReason:`Actions`,render:n=>a(`span`,{className:`flex items-center justify-end gap-1`,children:[a(z,{variant:`ghost`,size:`sm`,onClick:()=>{S(n)},disabled:b===n.id,title:l(`backup.archiveList.downloadArchive`,`Download archive`),children:[b===n.id?c(T,{className:`h-3 w-3 animate-spin`}):c(v,{className:`h-3 w-3`}),l(`backup.archiveList.download`,`Download`)]}),t&&o&&a(z,{variant:`ghost`,size:`sm`,onClick:()=>o({destinationId:e,archiveId:n.id}),title:l(`backup.archiveList.restoreFromThisArchive`,`Restore from this archive`),children:[c(k,{className:`h-3 w-3`}),l(`backup.archiveList.restore`,`Restore`)]}),c(U,{variant:`ghost`,size:`sm`,icon:f,"aria-label":l(`backup.archiveList.delete`,`Delete {{value1}}`,{value1:n.label??n.id}),disabled:_.isPending,onClick:()=>{y(n)}})]})}],rows:C,rowKey:e=>e.id,minWidthPx:760,emptyMessage:l(`backup.archiveList.noArchivesAtThisDestination`,`No archives at this destination yet.`)})}function _t(e,t){return g(`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`)}function vt(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}e();var yt=[[`backup`,`listSchedules`]];function bt({onEdit:e,onOpenRestoreWizard:t}){let{t:o}=G(),{data:s,isLoading:l,isError:u,error:d,refetch:f}=Pe(),p=s??[],m=ve().data??[],h=n(()=>{let e=new Map;for(let t of m)e.set(t.id,t);return e},[m]),[g,_]=r(null),v=i(e=>{_(t=>t===e?null:e)},[]),y=n(()=>xt({destById:h,expandedId:g,onToggleExpand:v,onEdit:e}),[h,g,v,e]);return l?a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle animate-pulse`,children:[c(T,{className:`h-3.5 w-3.5 animate-spin`}),o(`backup.backupEntriesTable.loadingBackupEntries`,`Loading backup entries…`)]}):u?c(ze,{title:o(`backup.backupEntriesTable.failedToLoadBackupEntries`,`Failed to load backup entries`),message:d instanceof Error?d.message:o(`backup.backupEntriesTable.unknownError`,`Unknown error`),onRetry:()=>void f()}):p.length===0?c(ee,{icon:M,title:o(`backup.backupEntriesTable.noBackupEntriesYet`,`No backup entries yet`),description:o(`backup.backupEntriesTable.createOneToScheduleBackups`,`Create one to schedule backups across one or more storage locations.`)}):c(ae,{columns:y,rows:p,rowKey:e=>e.id,minWidthPx:980,maxBodyHeight:se,emptyMessage:o(`backup.backupEntriesTable.noBackupEntriesYet`,`No backup entries yet`),onRowClick:t=>e(t),isExpanded:e=>e.id===g,renderExpanded:e=>c(Ot,{row:e,destById:h,...t?{onOpenRestoreWizard:t}:{}})})}function xt(e){return[{key:`expand`,header:``,width:`w-8`,nowrap:!0,notSortableReason:`Expand control`,render:t=>{let n=e.expandedId===t.id;return c(U,{variant:`ghost`,size:`sm`,icon:n?A:j,"aria-label":n?W.t(`backup.backupEntriesTable.hideArchives`,`Hide archives`):W.t(`backup.backupEntriesTable.showArchives`,`Show archives`),"aria-expanded":n,onClick:n=>{n.stopPropagation(),e.onToggleExpand(t.id)}})}},{key:`entry`,header:W.t(`backup.backupEntriesTable.entry`,`Entry`),sortValue:e=>e.label,render:e=>a(`span`,{className:`flex min-w-0 flex-col`,children:[c(`span`,{className:`truncate font-medium text-foreground`,children:e.label||W.t(`backup.backupEntriesTable.unnamed`,`(unnamed)`)}),e.lastRunAt!==void 0&&c(`span`,{className:`text-[10px] text-foreground-subtle`,children:W.t(`backup.backupEntriesTable.lastRun`,{when:new Date(e.lastRunAt).toLocaleString()})})]})},{key:`enabled`,header:W.t(`backup.backupEntriesTable.enabled`,`Enabled`),width:`w-20`,nowrap:!0,sortValue:e=>+!!e.enabled,render:e=>c(`span`,{onClick:e=>e.stopPropagation(),children:c(Tt,{row:e})})},{key:`databases`,header:W.t(`backup.backupEntriesTable.backsUp`,`Backs up`),nowrap:!1,notSortableReason:`Database badges`,render:e=>c(Z,{databases:X(e.databases)})},{key:`locations`,header:W.t(`backup.backupEntriesTable.locations`,`Locations`),nowrap:!1,notSortableReason:`Location chips`,render:t=>c(St,{row:t,destById:e.destById})},{key:`retention`,header:W.t(`backup.backupEntriesTable.retention`,`Retention`),width:`w-24`,nowrap:!0,sortValue:e=>e.retentionCount,render:e=>c(`span`,{onClick:e=>e.stopPropagation(),children:c(Et,{row:e})})},{key:`schedule`,header:W.t(`backup.backupEntriesTable.schedule`,`Schedule`),width:`w-48`,nowrap:!0,sortValue:e=>e.cron,render:e=>c(Ct,{row:e})},{key:`actions`,header:``,align:`right`,nowrap:!0,notSortableReason:`Actions`,render:t=>c(`span`,{onClick:e=>e.stopPropagation(),children:c(Dt,{row:t,onEdit:()=>e.onEdit(t)})})}]}function St({row:e,destById:t}){let{t:n}=G();return e.locationIds.length===0?c(`span`,{className:`text-[11px] italic text-danger`,children:n(`backup.backupEntriesTable.noLocations`,`No locations`)}):c(`span`,{className:`flex flex-wrap gap-1`,children:e.locationIds.map(e=>c(`span`,{className:`inline-flex items-center rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-foreground`,title:e,children:t.get(e)?.displayName??e},e))})}function Ct({row:e}){let{t}=G(),n=e.cron.trim().length>0;return a(`span`,{className:`flex flex-col items-start gap-0.5`,children:[a(`span`,{className:`inline-flex items-center gap-1`,children:[c(M,{className:`h-3 w-3 text-foreground-subtle`}),c(`span`,{className:`font-mono text-[11px] text-foreground`,children:n?e.cron:t(`backup.backupEntriesTable.manual`,`Manual`)})]}),n&&e.nextRunAt!==void 0&&c(`span`,{className:`text-[10px] text-foreground-subtle`,children:W.t(`common.nextRun`,{when:new Date(e.nextRunAt).toLocaleString()})})]})}function wt(e){return n(()=>({id:e.id,label:e.label,cron:e.cron,locationIds:[...e.locationIds],retentionCount:e.retentionCount,...e.dataSources?{dataSources:[...e.dataSources]}:{},...e.databases?{databases:[...e.databases]}:{}}),[e])}function Tt({row:e}){let{t}=G(),n=s(),r=we({onSuccess:()=>{n.invalidateQueries({queryKey:yt})}}),i=wt(e);return c(`label`,{className:`inline-flex cursor-pointer items-center`,children:c(`input`,{type:`checkbox`,className:`accent-primary`,checked:e.enabled,disabled:r.isPending,onChange:e=>r.mutate({...i,enabled:e.target.checked}),"aria-label":t(`backup.backupEntriesTable.enable`,`Enable {{value1}}`,{value1:e.label||e.id})})})}function Et({row:e}){let{t:n}=G(),i=s(),a=we({onSuccess:()=>{i.invalidateQueries({queryKey:yt})}}),o=wt(e),[l,u]=r(String(e.retentionCount));return t(()=>{u(String(e.retentionCount))},[e.retentionCount]),c(V,{type:`number`,min:1,max:1e3,value:l,disabled:a.isPending,onChange:e=>u(e.target.value),onBlur:()=>{let t=Number.parseInt(l,10);if(Number.isNaN(t)||t<1){u(String(e.retentionCount));return}t!==e.retentionCount&&a.mutate({...o,enabled:e.enabled,retentionCount:t})},onKeyDown:t=>{t.key===`Enter`&&t.target.blur(),t.key===`Escape`&&u(String(e.retentionCount))},className:`w-16`,"aria-label":n(`backup.backupEntriesTable.retentionFor`,`Retention for {{value1}}`,{value1:e.label||e.id})})}function Dt({row:e,onEdit:t}){let{t:n}=G(),r=s(),i=I(),o=L({onSuccess:()=>{r.invalidateQueries({queryKey:yt})}}),u=Se({onMutate:()=>{r.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{r.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),r.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),r.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})}}),p=()=>{e.locationIds.length!==0&&u.mutate({destinations:[...e.locationIds],...e.dataSources&&e.dataSources.length>0?{locations:[...e.dataSources]}:{},label:e.label,retentionCount:e.retentionCount,databases:[...X(e.databases)]})},m=async()=>{await i({title:n(`backup.backupEntriesTable.deleteBackupEntry`,`Delete backup entry?`),message:n(`backup.backupEntriesTable.willStopRunningExistingArchives`,`"{{value1}}" will stop running. Existing archives are kept.`,{value1:e.label||e.id}),confirmLabel:n(`common.delete`,`Delete`),variant:`warning`})&&o.mutate({id:e.id})};return a(`span`,{className:`flex items-center justify-end gap-1.5`,children:[a(z,{size:`sm`,type:`button`,onClick:p,disabled:u.isPending||e.locationIds.length===0,title:n(`backup.backupEntriesTable.runThisEntryNow`,`Run this entry now`),children:[u.isPending?c(T,{className:`h-3 w-3 animate-spin`}):c(l,{className:`h-3 w-3`}),n(`backup.backupEntriesTable.runNow`,`Run now`)]}),c(U,{variant:`ghost`,size:`sm`,icon:d,"aria-label":n(`backup.backupEntriesTable.edit`,`Edit {{value1}}`,{value1:e.label||e.id}),onClick:t}),c(U,{variant:`ghost`,size:`sm`,icon:f,"aria-label":n(`backup.backupEntriesTable.delete`,`Delete {{value1}}`,{value1:e.label||e.id}),disabled:o.isPending,onClick:()=>{m()}})]})}function Ot({row:e,destById:t,onOpenRestoreWizard:n}){let{t:r}=G();return a(`div`,{className:`space-y-4 rounded-lg border border-border bg-background/30 px-4 py-3`,children:[c(`p`,{className:`text-[11px] font-medium text-foreground-subtle`,children:r(`backup.backupEntriesTable.archivesFor`,{name:e.label||e.id})}),e.locationIds.length===0&&c(`p`,{className:`text-xs italic text-foreground-subtle`,children:r(`backup.backupEntriesTable.thisEntryHasNoLocations`,`This entry has no locations selected.`)}),e.locationIds.map(e=>a(`div`,{className:`space-y-1.5`,children:[c(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:t.get(e)?.displayName??e}),c(gt,{destinationId:e,restoreSupported:t.get(e)?.restoreSupported??!0,...n?{onOpenRestoreWizard:n}:{}})]},e))]})}function kt({selected:e,onChange:t,disabled:n=!1,testId:r=`backup-databases`}){let{t:i}=G(),o=Te().data,s=e.size>0&&dt(Y(e)),l=e.size===0?`Pick at least one.`:s?`Snapshots only: configuration and files are not part of this backup.`:null;return c(H,{label:i(`backup.backupDatabasePicker.whatToBackUp`,`What to back up`),required:!0,...l===null?{}:{description:l},children:c(`div`,{className:`divide-y divide-border rounded border border-border bg-background`,"data-testid":r,children:nt.map(i=>{let s=ct(i,o),l=n||lt(i,o,e);return a(`label`,{className:`flex items-start gap-2 px-3 py-2 text-xs ${l?`opacity-60`:`cursor-pointer hover:bg-primary/5`}`,children:[c(Fe,{checked:e.has(i),disabled:l,onChange:()=>t(ut(e,i)),"data-testid":`${r}-${i}`}),a(`span`,{className:`min-w-0 flex-1`,children:[c(`span`,{className:`flex flex-wrap items-center gap-1.5 text-foreground`,children:it(i)}),c(`span`,{className:`block text-[11px] text-foreground-subtle`,children:s===`absent`?rt():ot(i)})]})]},i)})})})}e();function At({onClose:e}){let{t}=G(),n=s(),[i,o]=r(new Set(J)),u=Se({onMutate:()=>{n.invalidateQueries({queryKey:[[`backup`,`listRuns`]]})},onSuccess:()=>{n.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),n.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]}),n.invalidateQueries({queryKey:[[`backup`,`listRuns`]]}),e()}});return c(te,{open:!0,onOpenChange:t=>!t&&e(),children:a(B,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(le,{children:[c(ue,{children:t(`backup.backupNowDialog.backUpNow`,`Back up now`)}),c(`p`,{className:`text-xs text-foreground-subtle`,children:t(`backup.backupNowDialog.runsOnceAndWritesThe`,`Runs once and writes the archive to every enabled backup location.`)})]}),c(de,{children:a(`div`,{className:`p-4`,children:[c(kt,{selected:i,onChange:o,disabled:u.isPending,testId:`backup-now-databases`}),u.error&&c(`p`,{role:`alert`,className:`pt-2 text-xs text-danger`,children:u.error.message})]})}),a(De,{children:[c(z,{variant:`outline`,size:`sm`,onClick:e,children:t(`common.cancel`,`Cancel`)}),a(z,{size:`sm`,onClick:()=>{i.size!==0&&u.mutate(ft(i))},disabled:i.size===0||u.isPending,"data-testid":`backup-now-run`,children:[u.isPending?c(T,{className:`h-3.5 w-3.5 animate-spin`}):c(l,{className:`h-3.5 w-3.5`}),t(`backup.backupNowDialog.backUpNow`,`Back up now`)]})]})]})})}e();function jt(e){return e===null?`—`:new Date(e).toLocaleString()}function Mt(e){let t=new Blob([`${e.secretKey}\n`],{type:`text/plain`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`camstack-backup-key-${e.keyId}.txt`,r.click(),URL.revokeObjectURL(n)}function Nt({revealed:e,onDone:t}){let{t:n}=G(),[i,o]=r(!1),[s,l]=r(!1);return c(te,{open:!0,onOpenChange:e=>!e&&i&&t(),children:a(B,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`border-danger/40`,"aria-labelledby":`backup-key-title`,children:[c(le,{children:c(ue,{id:`backup-key-title`,children:n(`backup.encryptionCard.yourKey`,{keyId:e.keyId})})}),a(de,{className:`space-y-3`,children:[a(`p`,{className:`flex items-start gap-2 rounded-md border border-danger/40 bg-danger/10 p-2 text-xs text-foreground`,children:[c(h,{className:`mt-0.5 h-4 w-4 shrink-0 text-danger`}),c(`span`,{children:n(`backup.backupEncryptionCard.thisKeyIsShownOnly`,`This key is shown only once. CamStack does not keep it — not the hub, not its database, not its backups. Without it, an encrypted backup cannot be restored by anyone, including you. Store it in a password manager or print it, away from this server.`)})]}),c(`div`,{className:`break-all rounded-md border border-border bg-background p-2 font-mono text-xs text-foreground select-all`,children:e.secretKey}),a(`div`,{className:`flex flex-wrap gap-2`,children:[a(z,{size:`sm`,variant:`outline`,onClick:()=>{navigator.clipboard?.writeText(e.secretKey).then(()=>l(!0))},children:[c(b,{className:`mr-1 h-3.5 w-3.5`}),s?n(`backup.backupEncryptionCard.copied`,`Copied`):n(`common.copy`,`Copy`)]}),a(z,{size:`sm`,variant:`outline`,onClick:()=>Mt(e),children:[c(v,{className:`mr-1 h-3.5 w-3.5`}),n(`backup.backupEncryptionCard.downloadAsFile`,`Download as file`)]})]}),a(`label`,{className:`flex items-center gap-2 text-xs text-foreground`,children:[c(`input`,{type:`checkbox`,checked:i,onChange:e=>o(e.target.checked),className:`accent-primary`}),n(`backup.backupEncryptionCard.iHaveStoredThisKey`,`I have stored this key somewhere safe, off this server.`)]})]}),c(De,{children:c(z,{size:`sm`,disabled:!i,onClick:t,children:n(`backup.backupEncryptionCard.iHaveStoredIt`,`I have stored it`)})})]})})}function Pt(){let{t:e}=G(),t=Ie(),n=Le(),i=Ce(),s=I(),[l,u]=r(null),[d,f]=r(null),p=t.data?.enabled??!1,m=t.data?.active??null,h=(t.data?.keys??[]).filter(e=>e.retiredAt!==null),g=async()=>{if(await s({title:p?e(`backup.backupEncryptionCard.replaceTheBackupKey`,`Replace the backup key`):e(`backup.backupEncryptionCard.encryptBackups`,`Encrypt backups`),message:p?e(`backup.backupEncryptionCard.aNewKeyIsGenerated`,`A new key is generated and shown once; new backups are encrypted to it. Older backups keep needing the key they were made with — keep that one too.`):e(`backup.backupEncryptionCard.aBackupKeyIsGenerated`,`A backup key is generated and shown once. Every new backup is encrypted to it, and restoring one will ask for it. Existing backups stay as they are.`),confirmLabel:p?e(`backup.backupEncryptionCard.generateANewKey`,`Generate a new key`):e(`backup.backupEncryptionCard.generateTheKey`,`Generate the key`),variant:`warning`})){f(null);try{let e=await n.mutateAsync({});u({keyId:e.keyId,secretKey:e.secretKey})}catch(e){f(e instanceof Error?e.message:String(e))}}},_=async()=>{if(await s({title:e(`backup.backupEncryptionCard.turnBackupEncryptionOff`,`Turn backup encryption off`),message:e(`backup.backupEncryptionCard.newBackupsWillBeWritten`,`New backups will be written unencrypted. Existing encrypted backups still need their key to be restored.`),confirmLabel:e(`backup.backupEncryptionCard.turnOff`,`Turn off`),variant:`danger`})){f(null);try{await i.mutateAsync({}),t.refetch()}catch(e){f(e instanceof Error?e.message:String(e))}}};return a(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-4`,children:[a(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[a(`div`,{className:`flex items-center gap-2`,children:[p?c(D,{className:`h-4 w-4 text-success`}):c(C,{className:`h-4 w-4 text-foreground-subtle`}),c(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`backup.backupEncryptionCard.encryption`,`Encryption`)}),c(`span`,{className:`text-xs text-foreground-subtle`,children:p&&m!==null?e(`backup.backupEncryptionCard.onKeySince`,`On — key {{keyId}}, since {{value2}}`,{keyId:m.keyId,value2:jt(m.createdAt)}):e(`backup.backupEncryptionCard.offBackupsAreNotEncrypted`,`Off — backups are not encrypted`)})]}),c(`div`,{className:`flex gap-2`,children:p?a(o,{children:[c(z,{size:`sm`,variant:`outline`,disabled:n.isPending,onClick:()=>void g(),children:e(`backup.backupEncryptionCard.replaceKey`,`Replace key`)}),c(z,{size:`sm`,variant:`outline`,disabled:i.isPending,onClick:()=>void _(),children:e(`backup.backupEncryptionCard.turnOff`,`Turn off`)})]}):c(z,{size:`sm`,disabled:n.isPending,onClick:()=>void g(),children:e(`backup.backupEncryptionCard.enableEncryption`,`Enable encryption`)})})]}),c(`p`,{className:`text-xs text-foreground-subtle`,children:e(`backup.backupEncryptionCard.archivesAreEncryptedOnThis`,`Archives are encrypted on this server before they reach any destination. The server keeps only a public key, so it can encrypt scheduled backups but cannot decrypt them — only your backup key can. Covers the database snapshot, config.yaml, addon data (HomeKit pairing, Matter fabric, Tailscale state) and TLS.`)}),h.length>0&&a(`div`,{className:`text-xs`,children:[c(`p`,{className:`text-foreground-subtle`,children:e(`backup.backupEncryptionCard.olderKeysBackupsMadeWith`,`Older keys (backups made with them still need them):`)}),c(`ul`,{className:`font-mono text-foreground`,children:h.map(e=>a(`li`,{children:[e.keyId,` · `,jt(e.createdAt),` → `,jt(e.retiredAt)]},e.keyId))})]}),d!==null&&c(`p`,{className:`text-xs text-danger`,children:d}),l!==null&&c(Nt,{revealed:l,onDone:()=>{u(null),t.refetch()}})]})}e();var Ft=[{id:`manual`,labelKey:`backup.cronEditor.presetManual`,cron:``},{id:`hourly`,labelKey:`backup.cronEditor.presetHourly`,cron:`0 * * * *`,descriptionKey:`backup.cronEditor.presetHourlyDesc`},{id:`every-3h`,labelKey:`backup.cronEditor.preset3h`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,labelKey:`backup.cronEditor.preset6h`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,labelKey:`backup.cronEditor.presetDaily`,cron:`0 3 * * *`,descriptionKey:`backup.cronEditor.presetDailyDesc`},{id:`weekly-sun`,labelKey:`backup.cronEditor.presetWeekly`,cron:`0 3 * * 0`,descriptionKey:`backup.cronEditor.presetWeeklyDesc`}];function It(e){let t=e.trim();for(let e of Ft)if(e.cron===t)return e.id;return`custom`}function Lt({value:e,onChange:n,previewCount:i=5,disabled:o=!1}){let{t:s}=G(),l=It(e),[u,d]=r(l===`custom`);t(()=>{l!==`custom`&&d(!1)},[l]);let f=Bt(e,250),p=xe({cron:f,count:i},{enabled:f.trim().length>0}),m=p.data??null,h=e=>{d(!1),n(e.cron)},g=u||l===`custom`;return a(`div`,{className:`space-y-3`,children:[a(`div`,{className:`space-y-1`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:s(`backup.cronEditor.schedulePreset`,`Schedule preset`)}),a(`div`,{className:`flex flex-wrap gap-1.5`,children:[Ft.map(e=>c(`button`,{type:`button`,onClick:()=>h(e),disabled:o,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!u&&l===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.descriptionKey===void 0?e.description??s(e.labelKey):s(e.descriptionKey),children:s(e.labelKey)},e.id)),c(`button`,{type:`button`,onClick:()=>{d(!0),e.trim().length===0&&n(`0 3 * * *`)},disabled:o,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(g?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:s(`backup.cronEditor.custom`,`Custom…`)})]})]}),g&&a(`div`,{className:`space-y-1`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:s(`backup.cronEditor.cronExpression5FieldPosix`,`Cron expression (5-field POSIX)`)}),c(`input`,{type:`text`,value:e,onChange:e=>n(e.target.value),disabled:o,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),a(`p`,{className:`text-[10px] text-foreground-subtle`,children:[s(`backup.cronEditor.format`,`Format:`),` `,c(He,{i18nKey:`backup.cronEditor.formatLine`,components:{code:c(`span`,{className:`font-mono`})}})]})]}),c(Rt,{cron:f,preview:m,loading:p.isFetching})]})}function Rt({cron:e,preview:t,loading:n}){let{t:r}=G();return n&&t===null?a(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[c(T,{className:`h-3 w-3 animate-spin`}),r(`backup.cronEditor.validating`,`Validating…`)]}):t===null?null:t.ok?t.nextRuns.length===0?c(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:r(`backup.cronEditor.noFutureRunsMatchThis`,`No future runs match this expression.`)}):a(`div`,{className:`space-y-1`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:r(`backup.cronEditor.nextRuns`,`Next runs`)}),c(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>a(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[c(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),c(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:zt(e)})]},`${e}-${t}`))})]}):c(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??r(`backup.cronEditor.invalidCronExpression`,`Invalid cron expression`)})}function zt(e){let t=e-Date.now();if(t<=0)return W.t(`helpers.relativeTime.now`);let n=Math.floor(t/1e3);if(n<60)return W.t(`helpers.relativeTime.inSeconds`,{count:n});let r=Math.floor(n/60);if(r<60)return W.t(`helpers.relativeTime.inMinutes`,{count:r});let i=Math.floor(r/60);if(i<24)return W.t(`helpers.relativeTime.inHours`,{count:i});let a=Math.floor(i/24);return W.t(`helpers.relativeTime.inDays`,{count:a})}function Bt(e,i){let[a,o]=r(e),s=n(()=>e,[e]);return t(()=>{let e=setTimeout(()=>o(s),i);return()=>clearTimeout(e)},[s,i]),a}e();var Vt=[[`backup`,`listSchedules`]];function Ht({entry:e,onClose:t,onSaved:i}){let{t:o}=G(),l=s(),u=ve(),d=u.data??[],[f,p]=r(e?.label??``),[m,h]=r(e?.cron??`0 3 * * *`),[g,_]=r(e?.enabled??!0),[v,y]=r(String(e?.retentionCount??7)),[b,x]=r(new Set(e?.locationIds??[])),[S,C]=r(new Set(e===null?J:X(e.databases))),w=we({onSuccess:()=>{l.invalidateQueries({queryKey:Vt}),i()}}),E=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},D=Number.parseInt(v,10),O=n(()=>f.trim().length>0&&b.size>0&&S.size>0&&!Number.isNaN(D)&&D>=1&&D<=1e3,[f,b,S,D]),k=()=>{O&&w.mutate({...e?{id:e.id}:{},label:f.trim(),cron:m.trim(),enabled:g,locationIds:Array.from(b),retentionCount:D,databases:[...st(S)]})},A=w.error instanceof Error?w.error.message:null;return c(me,{open:!0,onClose:t,title:e?o(`backup.backupEntryModal.editBackupEntry`,`Edit backup entry`):o(`backup.backupEntryModal.newBackupEntry`,`New backup entry`),icon:M,error:A,width:`lg`,testId:`backup-entry-form`,footer:a(z,{size:`sm`,type:`button`,onClick:k,disabled:!O||w.isPending,children:[w.isPending?c(T,{className:`h-3.5 w-3.5 animate-spin`}):null,e?o(`common.save`,`Save`):o(`backup.backupEntryModal.createEntry`,`Create entry`)]}),children:a(`div`,{className:`space-y-4`,children:[c(H,{label:o(`backup.backupEntryModal.name`,`Name`),required:!0,children:c(V,{value:f,onChange:e=>p(e.target.value),placeholder:o(`backup.backupEntryModal.nightlyOffsite`,`Nightly offsite`),autoFocus:!0,"data-testid":`backup-entry-name`})}),a(H,{label:o(`backup.backupEntryModal.locationsSelected`,`Locations ({{value1}} selected)`,{value1:String(b.size)}),required:!0,children:[u.isLoading&&a(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[c(T,{className:`h-3.5 w-3.5 animate-spin`}),o(`backup.backupEntryModal.loadingLocations`,`Loading locations…`)]}),!u.isLoading&&d.length===0&&c(`div`,{className:`rounded border border-border bg-background px-3 py-2 text-xs text-foreground-subtle italic`,children:o(`backup.backupEntryModal.noBackupsStorageLocationsConfigured`,"No `backups` storage locations configured. Add one in Settings → Storage first.")}),d.length>0&&c(`div`,{className:`max-h-52 divide-y divide-border overflow-y-auto rounded border border-border bg-background`,children:d.map(e=>a(`label`,{className:`flex cursor-pointer items-center justify-between px-3 py-2 text-xs hover:bg-primary/5`,children:[a(`div`,{className:`flex items-center gap-2`,children:[c(`input`,{type:`checkbox`,checked:b.has(e.id),onChange:()=>E(e.id),className:`accent-primary`}),c(`span`,{className:`text-foreground`,children:e.displayName})]}),a(`div`,{className:`flex items-center gap-1.5`,children:[c(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-foreground-subtle`,children:e.kind}),c(`span`,{className:`font-mono text-[10px] text-foreground-subtle`,children:e.id})]})]},e.id))})]}),c(kt,{selected:S,onChange:C,disabled:w.isPending,testId:`backup-entry-databases`}),a(`div`,{className:`grid grid-cols-2 gap-3`,children:[c(H,{label:o(`backup.backupEntryModal.retentionArchivesKept`,`Retention (archives kept)`),required:!0,children:c(V,{type:`number`,min:1,max:1e3,value:v,onChange:e=>y(e.target.value),"data-testid":`backup-entry-retention`})}),c(H,{label:o(`backup.backupEntryModal.enabled`,`Enabled`),description:o(`backup.backupEntryModal.runOnScheduleWhenChecked`,`Run on schedule when checked.`),children:a(`label`,{className:`inline-flex cursor-pointer items-center gap-2 py-1.5 text-xs text-foreground`,children:[c(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`accent-primary`,"data-testid":`backup-entry-enabled`}),c(`span`,{children:o(`backup.backupEntryModal.runOnSchedule`,`Run on schedule`)})]})})]}),c(H,{label:o(`backup.backupEntryModal.schedule`,`Schedule`),children:c(Lt,{value:m,onChange:h,disabled:w.isPending})})]})})}e();var Ut=2e3,Wt=5e3;function Q(e){return e.state===`queued`||e.state===`running`}function Gt(e){if(e.state===`queued`)return{title:W.t(`backup.backupRunsPanel.cancelQueuedBackupRun`,`Cancel queued backup run?`),message:W.t(`backup.backupRunsPanel.thisRunHasNotStarted`,`This run has not started. Cancelling removes it from the queue — nothing has been written, nothing is deleted.`),confirmLabel:W.t(`backup.backupRunsPanel.cancelRun`,`Cancel run`),variant:`warning`};let t=e.completedDestinationIds.length,n=t>0?`${t===1?`The 1 destination`:`The ${t} destinations`} that already completed KEEP${t===1?`S`:``} the archive.`:`No destination has completed yet, so nothing will be kept.`;return{title:W.t(`backup.backupRunsPanel.stopThisBackupRun`,`Stop this backup run?`),message:W.t(`backup.backupRunsPanel.theHalfWrittenStagingArchive`,`The half-written staging archive is deleted and the destination currently uploading discards its partial copy. {{keptSentence}}`,{keptSentence:n}),confirmLabel:W.t(`backup.backupRunsPanel.stopRun`,`Stop run`),variant:`danger`}}function Kt(){let e=I(),[t,n]=r(null),a=Me(void 0,{refetchInterval:e=>(e.state.data??[]).some(Q)?Ut:Wt}),o=_e({onSettled:()=>{n(null),a.refetch()}}),s=i(async t=>{await e(Gt(t))&&(n(t.id),o.mutate({runId:t.id}))},[e,o]);return c(qt,{queryState:a.isError?`error`:a.data===void 0?`pending`:`ready`,runs:a.data??[],cancelingId:t,onCancelRequest:e=>{s(e)},now:Date.now()})}function qt({queryState:e,runs:t,cancelingId:n,onCancelRequest:r,now:i}){let{t:o}=G(),s=e===`ready`&&t.some(Q),l=t.filter(e=>e.state===`running`),u=t.filter(e=>e.state===`queued`),d=t.filter(e=>!Q(e)),f=[...l,...u,...d];return a(`section`,{className:`rounded-lg border border-border bg-surface`,children:[a(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border`,children:[c(`h2`,{className:`text-xs font-semibold text-foreground`,children:o(`backup.backupRunsPanel.runs`,`Runs`)}),s&&a(`span`,{className:`inline-flex items-center gap-1 text-[10px] font-medium text-primary`,title:o(`backup.backupRunsPanel.aBackupRunIsIn`,`A backup run is in progress`),children:[c(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary animate-pulse`}),o(`backup.runsPanel.live`)]}),c(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:o(`backup.backupRunsPanel.oneRunExecutesAtA`,`One run executes at a time — queued runs wait in line.`)})]}),e===`pending`&&c(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle animate-pulse`,children:o(`backup.backupRunsPanel.checkingForBackupRuns`,`Checking for backup runs…`)}),e===`error`&&c(`div`,{className:`px-3 py-2.5 text-xs text-danger`,children:o(`backup.backupRunsPanel.couldNotReadBackupRuns`,`Could not read backup runs — the orchestrator did not answer.`)}),e===`ready`&&t.length===0&&c(`div`,{className:`px-3 py-2.5 text-xs text-foreground-subtle italic`,children:o(`backup.backupRunsPanel.noBackupRunsYetRuns`,`No backup runs yet. Runs appear here the moment one starts — manual or scheduled.`)}),e===`ready`&&t.length>0&&c(`div`,{className:`overflow-x-auto`,children:a(`table`,{className:`w-full text-xs min-w-[720px]`,children:[c(`thead`,{children:a(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.run`,`Run`)}),c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.state`,`State`)}),c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.progress`,`Progress`)}),c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.destinations`,`Destinations`)}),c(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:o(`backup.backupRunsPanel.timing`,`Timing`)}),c(`th`,{className:`text-right px-3 py-1.5 font-medium w-28`,children:o(`backup.backupRunsPanel.actions`,`Actions`)})]})}),c(`tbody`,{children:f.map(e=>c(Jt,{run:e,canceling:n===e.id,onCancelRequest:r,now:i},e.id))})]})})]})}function Jt({run:e,canceling:t,onCancelRequest:n,now:r}){let{t:i}=G(),o=Q(e);return a(`tr`,{className:`border-t border-border hover:bg-primary/5 align-top`,children:[c(`td`,{className:`px-3 py-2`,children:c(`div`,{className:`text-foreground`,title:e.id,children:e.label??c(`span`,{className:`text-foreground-subtle italic`,children:i(`backup.runsPanel.manual`)})})}),a(`td`,{className:`px-3 py-2`,children:[c(Yt,{run:e}),e.state===`failed`&&e.error!==void 0&&c(`div`,{className:`mt-1 text-[10px] text-danger max-w-56 truncate`,title:e.error,children:e.error})]}),c(`td`,{className:`px-3 py-2`,children:c(Xt,{run:e})}),c(`td`,{className:`px-3 py-2`,children:c(Zt,{run:e})}),c(`td`,{className:`px-3 py-2 text-foreground-subtle tabular-nums`,children:c(Qt,{run:e,now:r})}),c(`td`,{className:`px-3 py-2`,children:c(`div`,{className:`flex justify-end`,children:o&&a(`button`,{onClick:()=>n(e),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:e.state===`queued`?i(`backup.backupRunsPanel.removeThisRunFromThe`,`Remove this run from the queue before it starts`):i(`backup.backupRunsPanel.stopThisRunTheHalf`,`Stop this run — the half-written archive is discarded`),children:[t?c(T,{className:`h-3 w-3 animate-spin`}):c(_,{className:`h-3 w-3`}),e.state===`queued`?i(`common.cancel`,`Cancel`):i(`backup.backupRunsPanel.stop`,`Stop`)]})})})]})}function Yt({run:e}){let{t}=G();switch(e.state){case`queued`:return a(`span`,{className:`inline-flex items-center gap-1 rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:[c(x,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.queued`,`Queued`)]});case`running`:return a(`span`,{className:`inline-flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`,children:[c(T,{className:`h-3 w-3 animate-spin`}),e.phase===`uploading`?t(`backup.backupRunsPanel.uploading`,`Uploading`):t(`backup.backupRunsPanel.buildingArchive`,`Building archive`)]});case`succeeded`:return a(`span`,{className:`inline-flex items-center gap-1 rounded bg-success/10 px-1.5 py-0.5 text-[10px] font-medium text-success`,children:[c(E,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.succeeded`,`Succeeded`)]});case`failed`:return a(`span`,{className:`inline-flex items-center gap-1 rounded bg-danger/10 px-1.5 py-0.5 text-[10px] font-medium text-danger`,children:[c(O,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.failed`,`Failed`)]});case`cancelled`:return a(`span`,{className:`inline-flex items-center gap-1 rounded bg-amber-500/10 px-1.5 py-0.5 text-[10px] font-medium text-amber-700 dark:text-amber-300`,title:t(`backup.backupRunsPanel.stoppedBeforeCompletingEveryDestination`,`Stopped before completing every destination — not a success`),children:[c(P,{className:`h-3 w-3`}),t(`backup.backupRunsPanel.stopped`,`Stopped`)]})}}function Xt({run:e}){let{t}=G();if(e.state===`queued`)return c(`span`,{className:`text-foreground-subtle`,children:e.queuePosition===void 0?c(`span`,{className:`italic`,children:t(`backup.backupRunsPanel.waitingItsTurn`,`waiting its turn`)}):a(`span`,{className:`inline-flex items-center gap-1`,children:[c(`span`,{className:e.queuePosition===1?`rounded bg-primary/10 px-1.5 py-0.5 text-[10px] font-medium text-primary`:`rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-medium`,children:$t(e.queuePosition)}),t(`backup.backupRunsPanel.inLine`,`in line`)]})});if(e.state===`running`&&e.phase===`building`)return a(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[c(F,{className:`h-3 w-3 text-primary`}),c(`span`,{className:`tabular-nums font-medium animate-pulse`,children:K(e.stagedBytes)}),c(`span`,{className:`text-foreground-subtle`,children:t(`backup.backupRunsPanel.stagedSoFar`,`staged so far`)})]});if(e.state===`running`){let n=e.archiveSizeBytes;return a(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,children:[c(N,{className:`h-3 w-3 text-primary`}),a(`span`,{className:`tabular-nums font-medium`,children:[K(e.uploadedBytes),n===void 0?``:` / ${K(n)}`]}),c(`span`,{className:`text-foreground-subtle`,children:t(`backup.backupRunsPanel.toCurrentDestination`,`to current destination`)})]})}let n=e.archiveSizeBytes??(e.stagedBytes>0?e.stagedBytes:void 0);return n===void 0?c(`span`,{className:`text-foreground-subtle italic`,children:`—`}):c(`span`,{className:`tabular-nums text-foreground`,children:t(`backup.runsPanel.archiveSize`,{size:K(n)})})}function Zt({run:e}){let{t}=G(),n=e.destinationIds.length,r=e.completedDestinationIds.length,i=e.failedDestinationIds.length;return n===0?c(`span`,{className:`text-foreground-subtle italic`,children:t(`backup.backupRunsPanel.notResolvedYet`,`not resolved yet`)}):a(`div`,{className:`flex flex-col gap-0.5`,children:[c(`span`,{className:`text-foreground-subtle`,title:e.destinationIds.join(`, `),children:t(`backup.runsPanel.targets`,{count:n})}),a(`span`,{className:`inline-flex items-center gap-2 text-[10px]`,children:[r>0&&c(`span`,{className:`text-success`,title:t(`backup.backupRunsPanel.keptTheirArchive`,`Kept their archive: {{value1}}`,{value1:e.completedDestinationIds.join(`, `)}),children:t(`backup.runsPanel.completed`,{count:r})}),i>0&&c(`span`,{className:`text-danger`,title:t(`backup.backupRunsPanel.failed2`,`Failed: {{value1}}`,{value1:e.failedDestinationIds.join(`, `)}),children:t(`backup.runsPanel.failedCount`,{count:i})})]})]})}function Qt({run:e,now:t}){let{t:n}=G();return e.state===`queued`?c(`span`,{children:n(`backup.runsPanel.queuedAgo`,{elapsed:en(t-e.requestedAt)})}):e.startedAt===void 0?c(`span`,{children:`—`}):e.finishedAt===void 0?c(`span`,{children:n(`backup.runsPanel.runningFor`,{elapsed:en(t-e.startedAt)})}):a(`div`,{className:`flex flex-col gap-0.5`,children:[c(`span`,{children:tn(e.finishedAt)}),c(`span`,{className:`text-[10px]`,children:n(`backup.runsPanel.took`,{elapsed:en(e.finishedAt-e.startedAt)})})]})}function $t(e){if(e<=1)return`next`;let t=e%100;if(t>=11&&t<=13)return`${e}th`;switch(e%10){case 1:return`${e}st`;case 2:return`${e}nd`;case 3:return`${e}rd`;default:return`${e}th`}}function en(e){let t=Math.max(0,Math.floor(e/1e3));if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m ${String(t%60).padStart(2,`0`)}s`:`${Math.floor(n/60)}h ${String(n%60).padStart(2,`0`)}m`}function tn(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,hour:`2-digit`,minute:`2-digit`})}e();var nn=[[`backup`,`list`]];function rn({initialDestinationId:e,initialArchiveId:i,onClose:o,onScheduled:l}){let{t:u}=G(),d=s(),[f,m]=r(e&&i?2:1),[h,g]=r(e),[_,v]=r(i),[b,x]=r(new Set),[S,C]=r(``),{data:w}=ve(),E=w??[],{data:D,isLoading:O}=Ne({destinationId:h??``},{enabled:!!h}),A=D??[];t(()=>{if(h!==void 0)return;let e=E.filter(e=>e.restoreSupported);e.length===1&&g(e[0].id)},[h,E]);let{data:j}=Ae({destinationId:h??``,backupId:_??``},{enabled:!!h&&!!_}),M=n(()=>j?.locations??[],[j]);t(()=>{M.length!==0&&x(e=>e.size===0?new Set(M):e)},[M]);let N=Oe({onSuccess:()=>{d.invalidateQueries({queryKey:nn}),l(),o()}}),P=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},F=A.find(e=>e.id===_),I=F?.encryption!==void 0,L=pt(F?.databases,j?.sqliteSnapshots),R=dt(L),ee=!!h&&!!_,ne=R||b.size>0,re=ee&&ne&&!N.isPending&&(!I||S.trim().length>0),ie=()=>{!h||!_||N.mutate({destinationId:h,backupId:_,...R?{}:{locations:[...b]},...I?{backupSecretKey:S.trim()}:{}})};return c(te,{open:!0,onOpenChange:e=>!e&&o(),children:a(B,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[a(le,{children:[c(ue,{children:u(`backup.restoreWizard.restoreBackup`,`Restore Backup`)}),c(`p`,{className:`text-xs text-foreground-subtle`,children:u(`backup.restoreWizard.stepOf`,{step:f,name:f===1?u(`backup.restoreWizard.pickSource`,`pick source`):f===2?u(`backup.restoreWizard.pickLocations`,`pick locations`):u(`backup.restoreWizard.confirmStep`)})})]}),a(de,{children:[f===1&&c(an,{destinations:E,destinationId:h,onPickDestination:e=>{g(e),v(void 0),x(new Set)},archives:A,archivesLoading:O,archiveId:_,onPickArchive:v}),f===2&&c(on,{locations:M,picked:b,onToggle:P,databases:L,snapshotsOnly:R}),f===3&&c(sn,{destinationName:E.find(e=>e.id===h)?.displayName??h??``,archive:F,picked:[...b],databases:L,snapshotsOnly:R}),f===3&&F?.encryption!==void 0&&c(cn,{keyId:F.encryption.keyId,value:S,onChange:C}),f===3&&N.error&&c(`p`,{role:`alert`,className:`px-4 pb-2 text-xs text-danger`,children:N.error.message})]}),a(De,{className:`justify-between`,children:[c(`div`,{children:f>1&&a(z,{variant:`outline`,size:`sm`,onClick:()=>m(e=>e===3?2:1),children:[c(y,{className:`h-3 w-3`}),u(`common.back`,`Back`)]})}),a(`div`,{className:`flex items-center gap-2`,children:[c(z,{variant:`outline`,size:`sm`,onClick:o,children:u(`common.cancel`,`Cancel`)}),f<3?a(z,{size:`sm`,disabled:f===1&&!ee||f===2&&!ne,onClick:()=>m(e=>e===1?2:3),children:[u(`common.next`,`Next`),c(p,{className:`h-3 w-3`})]}):a(z,{size:`sm`,onClick:ie,disabled:!re,children:[N.isPending?c(T,{className:`h-3.5 w-3.5 animate-spin`}):c(k,{className:`h-3.5 w-3.5`}),u(`backup.restoreWizard.scheduleRestore`,`Schedule Restore`)]})]})]})]})})}function an({destinations:e,destinationId:t,onPickDestination:n,archives:r,archivesLoading:i,archiveId:o,onPickArchive:s}){let{t:l}=G(),u=e.filter(e=>e.restoreSupported);return a(`div`,{className:`p-4 space-y-3`,children:[a(`div`,{className:`space-y-1.5`,children:[c(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:l(`backup.restoreWizard.destination`,`Destination`)}),c(ge,{value:t??``,onChange:e=>n(e.target.value),options:[{value:``,label:l(`backup.restoreWizard.selectDestination`,`Select destination…`)},...u.map(e=>({value:e.id,label:`${e.displayName} (${e.kind})`}))]})]}),a(`div`,{className:`space-y-1.5`,children:[c(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:l(`backup.restoreWizard.archive`,`Archive`)}),!t&&c(`div`,{className:`text-xs text-foreground-subtle italic`,children:l(`backup.restoreWizard.pickADestinationFirst`,`Pick a destination first.`)}),t&&i&&c(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:l(`backup.restoreWizard.readingArchives`,`Reading archives…`)}),t&&!i&&r.length===0&&c(`div`,{className:`text-xs text-foreground-subtle italic`,children:l(`backup.restoreWizard.noArchivesAvailableAtThis`,`No archives available at this destination.`)}),t&&r.length>0&&c(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:r.map(e=>{let t=o===e.id;return a(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[a(`div`,{className:`flex items-center gap-2`,children:[c(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>s(e.id),className:`accent-primary`}),a(`div`,{children:[a(`div`,{className:`flex items-center gap-1 font-medium text-foreground`,children:[e.encryption!==void 0&&c(D,{className:`h-3 w-3 text-success`,"aria-label":l(`backup.restoreWizard.encryptedKey`,`encrypted (key {{keyId}})`,{keyId:e.encryption.keyId})}),e.label??e.id]}),c(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()}),c(`div`,{className:`pt-1`,children:c(Z,{databases:pt(e.databases,void 0)})})]})]}),c(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:K(e.sizeBytes)})]},e.id)})})]})]})}function on({locations:e,picked:t,onToggle:n,databases:r,snapshotsOnly:i}){let{t:o}=G();return i?a(`div`,{className:`space-y-3 p-4`,children:[a(`div`,{className:`space-y-1.5`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:o(`backup.restoreWizard.databasesInThisArchive`,`Databases in this archive`)}),c(Z,{databases:r})]}),c(`div`,{className:`rounded border border-info/30 bg-info/10 px-3 py-2 text-[11px] text-info`,children:o(`backup.restoreWizard.snapshotsOnlyRestoringThisArchive`,`Snapshots only: restoring this archive replaces just these databases. It does NOT touch configuration, addons, addon data or certificates.`)})]}):e.length===0?c(`div`,{className:`p-4`,children:c(`div`,{className:`text-xs text-foreground-subtle`,children:o(`backup.restoreWizard.loadingArchiveManifestIfThis`,`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`)})}):a(`div`,{className:`p-4 space-y-3`,children:[a(`div`,{className:`space-y-1.5`,children:[c(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:o(`backup.restoreWizard.databasesInThisArchive`,`Databases in this archive`)}),c(Z,{databases:r})]}),c(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-[11px] text-warning`,children:o(`backup.restoreWizard.selectedEntriesWillOverwriteLive`,`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`)}),a(`div`,{className:`space-y-1.5`,children:[c(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:o(`common.apply`,`Apply`)}),c(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>a(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[c(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>n(e),className:`accent-primary`}),c(`span`,{className:`font-mono text-foreground`,children:e}),c(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:un(e)})]},e))})]})]})}function sn({destinationName:e,archive:t,picked:n,databases:r,snapshotsOnly:i}){let{t:o}=G();return a(`div`,{className:`p-4 space-y-3 text-xs`,children:[c(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-warning`,children:o(`backup.restoreWizard.restoreIsAppliedAtNext`,`Restore is applied at next server boot. Active connections will drop when you restart.`)}),a(`dl`,{className:`space-y-1.5`,children:[c($,{term:`Destination`,value:e}),c($,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&c($,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${K(t.sizeBytes)}`}),a(`div`,{className:`flex justify-between gap-3`,children:[c(`dt`,{className:`text-foreground-subtle`,children:`Databases`}),c(`dd`,{className:`text-right`,children:c(Z,{databases:r})})]}),c($,{term:`Locations`,value:i?`none (configuration is not touched)`:n.length>0?n.join(`, `):`— (full archive)`})]})]})}function cn({keyId:e,value:t,onChange:n}){let{t:r}=G();return a(`div`,{className:`space-y-1.5 px-4 pb-3`,children:[c(`label`,{htmlFor:`restore-backup-key`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:r(`backup.restoreWizard.backupKey`,`Backup key`)}),c(`input`,{id:`restore-backup-key`,type:`password`,autoComplete:`off`,spellCheck:!1,value:t,onChange:e=>n(e.target.value),placeholder:r(`backup.restoreWizard.camstackBackupSecretV1`,`camstack-backup-secret-v1:…`),className:`w-full rounded border border-border bg-background px-2 py-1.5 font-mono text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),c(`p`,{className:`text-[11px] text-foreground-subtle`,children:c(He,{i18nKey:`backup.restoreWizard.encryptedTo`,values:{keyId:e},components:{mono:c(`span`,{className:`font-mono`})}})})]})}function $({term:e,value:t}){return a(`div`,{className:`flex justify-between gap-3`,children:[c(`dt`,{className:`text-foreground-subtle`,children:e}),c(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var ln={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function un(e){return ln[e]??``}e();function dn(){let{t:e}=G(),n=I(),i=re(),{state:o,openNew:s,openEdit:u,close:d}=Re({editKey:`edit`,newKey:`new`}),f=Pe(),p=f.data??[],[m,h]=r(null),[g,_]=r(!1),[v,y]=r(!1),[b,x]=r(!1),S=o.mode===`edit`?p.find(e=>e.id===o.id)??null:null;t(()=>{o.mode===`edit`&&!f.isLoading&&S===null&&d()},[o.mode,f.isLoading,S,d]);let C=o.mode===`new`||o.mode===`edit`&&S!==null,E=async()=>{await n({title:e(`system.backup.restartServerNow`,`Restart server now?`),message:e(`system.backup.activeConnectionsWillDropAnd`,`Active connections will drop and the apply-backup hook will run before boot.`),confirmLabel:e(`system.backup.restart`,`Restart`),variant:`warning`})&&i.mutate({confirm:!0})};return a(Ge,{embedded:!0,children:[a(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,"data-testid":`backup-actions`,children:[a(z,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>x(!0),"data-testid":`backup-now`,children:[c(l,{className:`h-3.5 w-3.5`}),e(`system.backup.backUpNow`,`Back up now`)]}),a(z,{variant:`outline`,size:`sm`,type:`button`,onClick:()=>_(!0),children:[c(k,{className:`h-3.5 w-3.5`}),e(`system.backup.restore`,`Restore…`)]}),a(z,{size:`sm`,type:`button`,onClick:s,"data-testid":`backup-new-entry`,children:[c(w,{className:`h-3.5 w-3.5`}),e(`system.backup.newEntry`,`New entry`)]})]}),v&&c(`div`,{className:`rounded-lg border border-warning/30 bg-warning/10 px-3 py-2.5 text-xs text-warning`,children:a(`div`,{className:`flex items-center justify-between gap-3`,children:[a(`div`,{className:`flex items-center gap-2`,children:[c(k,{className:`h-3.5 w-3.5`}),c(`span`,{children:e(`system.backup.restoreScheduledRestartTheServer`,`Restore scheduled. Restart the server to apply.`)})]}),a(z,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>{E()},disabled:i.isPending,children:[i.isPending?c(T,{className:`h-3.5 w-3.5 animate-spin`}):c(k,{className:`h-3.5 w-3.5`}),e(`system.backup.restartNow`,`Restart Now`)]})]})}),c(Pt,{}),c(Kt,{}),c(bt,{onEdit:e=>u(e.id),onOpenRestoreWizard:e=>h(e)}),C&&c(Ht,{entry:S,onClose:d,onSaved:d}),b&&c(At,{onClose:()=>x(!1)}),(m||g)&&c(rn,{...m?{initialDestinationId:m.destinationId,initialArchiveId:m.archiveId}:{},onClose:()=>{h(null),_(!1)},onScheduled:()=>y(!0)})]})}e();function fn(e){return Object.entries(e).map(([e,t])=>`${e} ${t}`).join(` · `)}function pn(e){return e.reduce((e,t)=>e+Object.values(t.stores).reduce((e,t)=>e+t,0),0)}function mn(){let{t:e}=G(),t=I(),n=ke(),[i,s]=r(null),[l,u]=r(null),d=async e=>{u(null);try{s(await n.mutateAsync({confirm:e}))}catch(e){u(e instanceof Error?e.message:String(e))}},p=async()=>{i===null||i.status!==`dry-run`||await t({title:e(`systemPage.deletedDevices.confirmTitle`,`Delete the data of deleted devices?`),message:i.devices.map(e=>`#${e.deviceId}: ${fn(e.stores)}`).join(`
|
|
2
|
-
`),confirmLabel:e(`systemPage.deletedDevices.confirmLabel`,`Delete`),variant:`danger`})&&await d(!0)},m=[{key:`device`,header:e(`systemPage.deletedDevices.device`,`Device`),render:e=>`#${e.deviceId}`},{key:`stores`,header:e(`systemPage.deletedDevices.stores`,`Data held`),nowrap:!1,render:e=>fn(e.stores)}];return a(`div`,{className:`space-y-4`,"data-testid":`deleted-devices-data`,children:[c(`p`,{className:`text-sm text-foreground-muted`,children:e(`systemPage.deletedDevices.intro`,`Data that still belongs to devices that were deleted before deletions were recorded: footage, events, history and per-addon settings. Scanning deletes nothing; deleting asks first and shows what goes.`)}),a(`div`,{className:`flex flex-wrap items-center gap-2`,children:[a(z,{variant:`outline`,onClick:()=>void d(!1),disabled:n.isPending,"data-testid":`deleted-devices-scan`,children:[n.isPending?c(T,{className:`mr-2 h-4 w-4 animate-spin`}):c(S,{className:`mr-2 h-4 w-4`}),e(`systemPage.deletedDevices.scan`,`Scan`)]}),i?.status===`dry-run`&&i.devices.length>0?a(z,{variant:`danger`,onClick:()=>void p(),disabled:n.isPending,"data-testid":`deleted-devices-delete`,children:[c(f,{className:`mr-2 h-4 w-4`}),e(`systemPage.deletedDevices.delete`,`Delete the data of {{count}} devices…`,{count:i.devices.length})]}):null]}),l===null?null:c(`p`,{className:`text-sm text-danger`,children:l}),i?.status===`skipped`?c(`p`,{className:`text-sm text-warning`,"data-testid":`deleted-devices-skipped`,children:e(`systemPage.deletedDevices.skipped`,`Nothing was listed or deleted: the device list could not be trusted ({{reason}}). Try again.`,{reason:i.reason??``})}):null,i!==null&&i.status!==`skipped`?a(o,{children:[c(`p`,{className:`text-sm`,"data-testid":`deleted-devices-summary`,children:i.status===`cleaned`?e(`systemPage.deletedDevices.cleaned`,`Deleted {{rows}} items of {{count}} devices.`,{rows:pn(i.devices),count:i.devices.length}):e(`systemPage.deletedDevices.found`,`{{count}} deleted devices still hold {{rows}} items.`,{rows:pn(i.devices),count:i.devices.length})}),c(ae,{columns:m,rows:i.devices,rowKey:e=>e.deviceId,emptyMessage:e(`systemPage.deletedDevices.none`,`No data belongs to a deleted device.`)}),i.unreachable.length>0?c(`p`,{className:`text-xs text-foreground-muted`,children:e(`systemPage.deletedDevices.unreachable`,`Not asked (unreachable): {{names}}`,{names:i.unreachable.join(`, `)})}):null]}):null]})}var hn=`view`,gn=`kinds`,_n=`deleted-devices`;function vn(){let{t:e}=G(),[t,n]=Ue(),r=t.get(`view`)===`deleted-devices`?_n:gn;return a(`div`,{className:u,children:[a(`div`,{className:`mb-3 space-y-2`,children:[c(je,{appearance:`pills`,value:r,onValueChange:e=>{n(t=>{let n=new URLSearchParams(t);return e===`kinds`?n.delete(hn):n.set(hn,e),n},{replace:!0})},children:a(Ee,{className:`flex flex-wrap gap-1`,children:[c(be,{value:gn,children:e(`systemPage.data.viewKinds`,`Record kinds`)}),c(be,{value:_n,children:e(`systemPage.data.viewDeletedDevices`,`Deleted devices`)})]})}),r===`kinds`?c(`p`,{className:`text-xs text-foreground-muted`,children:e(`systemPage.data.recordsUnifiedIntro`,`Every declared record kind on this hub. Entry kinds can be added, edited and deleted; the rest are read-only. Secret fields are redacted.`)}):null]}),c(r===`kinds`?ne:mn,{})]})}var yn={entries:null,"deleted-devices":`deleted-devices`};function bn(){let{t:e}=G(),t=Ve(`/system/data`,{t:e,isAdmin:!0})??{icon:m,title:e(`system.data`,`Data`)},[n]=Ue(),r=yn[n.get(`tab`)??``];if(r!==void 0){let e=new URLSearchParams(n);return e.set(`tab`,`records`),r!==null&&e.set(`view`,r),c(Be,{replace:!0,to:{search:e.toString()}})}return c(We,{icon:t.icon,title:t.title,defaultSection:`storage`,sectionsLabel:`${t.title} sections`,sections:[{id:`storage`,label:e(`systemPage.data.storage`,`Storage`),content:c(tt,{})},{id:`records`,label:e(`systemPage.data.records`,`Records`),content:c(vn,{}),ownedParams:[`view`,`recordsOwner`,`recordsKind`,`entryNew`,`entryEdit`]},{id:`backup`,label:e(`systemPage.data.backup`,`Backup`),content:c(dn,{})}]})}export{bn as DataPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,L as i,S as a,a as o,b as s,o as c,q as l,t as u,x as d}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{$t as f,D as p,Fn as m,It as h,Nt as g,Rr as _,Tt as v,Wi as y,Wr as b,an as x,bn as S,cn as C,dn as w,dt as T,kn as E,ln as D,lr as O,mi as k,mr as A,oa as j,or as M,ot as N,pn as P,rr as F,sn as I,xi as L,yi as R}from"./player-overlays-Fx6RE6kI.js";import{Ci as z,Si as ee,a as B,c as V,o as te,s as ne,wi as re}from"./client-yfOXPkcm.js";import{i as ie,n as ae,r as oe,t as se}from"./key-BF4fZLz_.js";import{d as H,l as ce,s as le}from"./video-BRgeujOO.js";import{t as ue}from"./history-CNfarVY1.js";import{t as de}from"./key-round-CjE9GF4T.js";import{t as fe}from"./monitor-smartphone-ASdELIYw.js";import{t as pe}from"./unlink-YiKNaJO_.js";import{$ as me,$l as he,$n as U,Bl as ge,Bn as _e,Dn as W,Fl as ve,Fo as ye,Gl as be,Gt as xe,Hl as Se,Hn as G,Ho as Ce,Il as we,Kl as Te,Kt as Ee,Ll as De,Lt as Oe,Ml as ke,Mn as Ae,N as je,Nl as Me,Nn as Ne,No as Pe,On as Fe,Or as Ie,P as Le,Pl as Re,Q as ze,Ql as Be,Rl as Ve,Ro as He,Rt as Ue,Sn as We,Su as K,Tn as Ge,Ul as Ke,Ut as qe,V as Je,Vl as Ye,Vn as Xe,Vo as Ze,Wl as Qe,Wt as q,Zl as $e,_a as et,an as tt,cn as nt,er as rt,eu as it,in as at,jl as ot,jn as st,kn as ct,kr as lt,nn as ut,nu as dt,on as ft,q as pt,sr as J,tu as mt,z as ht,zl as gt,zn as _t}from"./src-AhVPNkCn.js";import{t as Y}from"./i18n-B1bxeya5.js";import{t as X}from"./useTranslation-D3Is_4B6.js";import{$ as vt,Q as yt,T as bt,V as xt,Z as St,a as Ct,d as wt,et as Tt,i as Et,l as Dt,nt as Ot}from"./index-CcAR8Rlk.js";import{t as kt}from"./AdminSectionedPage-D5J86Kfp.js";import{t as At}from"./AdminPage--m3xHpjx.js";import{A as jt,C as Mt,D as Nt,E as Pt,F as Ft,M as It,N as Z,O as Lt,P as Rt,S as zt,T as Bt,_ as Vt,a as Ht,b as Ut,c as Wt,d as Gt,f as Kt,h as qt,i as Jt,j as Yt,k as Xt,l as Zt,m as Qt,n as $t,o as en,p as tn,s as nn,t as rn,u as an,v as on,w as sn,x as cn,y as ln}from"./SessionsList-DrSkZMrj.js";import{i as un,n as dn,r as fn,t as pn}from"./IntegrationHub-BRMnV56J.js";import{n as mn,t as hn}from"./addon-display-names-BkwMrExv.js";e();function gn(){let{t:e}=X(),t=U(),i=K.useUtils(),a=Ft(),{data:o,isLoading:s}=gt(),c=n(()=>o??[],[o]),l=K.useQueries(e=>c.map(t=>e.userManagement.listExternalIdentities({userId:t.id}))),u=K.auth.listLoginMethods.useQuery(),[f,p]=r(null),m=be({onSuccess:()=>void i.userManagement.listExternalIdentities.invalidate(),onError:e=>p(`Remove failed: ${e.message}`)}),h=n(()=>new Map((u.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),[u.data]),g=c.flatMap((e,t)=>l[t]?.data??[]),_=g.map(e=>({...Bt(e,a),kind:h.get(e.provider)??e.provider})),v=async n=>{let r=g.find(e=>sn(e)===n.id);r!==void 0&&await t({title:e(`access.externalIdentitiesSection.removeSignInLink`,`Remove sign-in link`),message:e(`access.externalIdentitiesSection.willNoLongerBeAble`,`"{{ownerName}}" will no longer be able to sign in with this {{kind}} account.`,{ownerName:n.ownerName,kind:n.kind}),confirmLabel:e(`common.remove`,`Remove`),variant:`danger`})&&(p(null),m.mutate({userId:r.userId,provider:r.provider,subject:r.subject}))};return d(Z,{notice:Rt(f),onDismissNotice:()=>{p(null)},id:`external-identities`,title:e(`access.externalIdentitiesSection.signInLinks`,`Sign-in links`),icon:H,description:e(`access.externalIdentitiesSection.externalAccountsSingleSignOn`,`External accounts (single sign-on) each user linked to their CamStack account. Only the owner can link one, from their profile; an admin can remove it.`),children:d(Xt,{rows:_,label:`sign-in links`,isLoading:s||l.some(e=>e.isLoading),loadError:l.find(e=>e.isError)?.error?.message??null,emptyText:`No user has linked a sign-in account.`,expiresNone:`—`,action:{label:e(`common.remove`,`Remove`),icon:pe,isAvailable:()=>!0,onRun:e=>void v(e),busyId:null,disabled:m.isPending}})})}e();function _n(){let{t:e}=X(),t=U(),i=c(),a=Ft(),o=we(),[s,l]=r(null),u=Ye({onSuccess:()=>void i.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),onError:e=>l(`Revoke failed: ${e.message}`)}),f=n(()=>(o.data??[]).map(e=>Mt(e,a)),[o.data,a]),p=async n=>{await t({title:e(`access.legacyApiKeysSection.revoke`,`Revoke "{{name}}"?`,{name:n.name}),message:e(`access.legacyApiKeysSection.anyClientUsingThisKey`,`Any client using this key loses access immediately. This cannot be undone.`),confirmLabel:e(`access.legacyApiKeysSection.revoke2`,`Revoke`),variant:`danger`})&&(l(null),u.mutate({id:n.id}))};return d(Z,{notice:Rt(s),onDismissNotice:()=>{l(null)},id:`legacy-api-keys`,title:e(`access.legacyApiKeysSection.legacyApiKeys`,`Legacy API keys`),icon:ue,description:e(`access.legacyApiKeysSection.keysFromBeforeScopedTokens`,`Keys from before scoped tokens. Nothing creates them any more; revoke them and issue a scoped token instead.`),children:d(Xt,{rows:f,label:e(`access.legacyApiKeysSection.legacyApiKeys2`,`legacy API keys`),isLoading:o.isLoading,loadError:o.isError?o.error?.message??`Request failed`:null,emptyText:`No legacy API keys.`,action:{label:e(`access.legacyApiKeysSection.revoke2`,`Revoke`),icon:h,isAvailable:()=>!0,onRun:e=>void p(e),busyId:u.isPending?u.variables?.id??null:null,disabled:u.isPending}})})}e();var vn={key:`access.nouns.linkedApp`};function yn(e){if(e.type===`category`){let t=e.target??``;return t===`device`?Y.t(`access.linkedAppsSection.allDevices`):Y.t(`access.linkedAppsSection.allTarget`,{target:t})}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function bn(){let{t:e}=X(),t=U(),i=c(),a=Ve(),[o,s]=r(null),l=()=>void i.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]}),u=Se({onSuccess:l,onError:e=>s(`Revoke failed: ${e.message}`)}),f=jt(`oauth-session`,vn,l),p=n(()=>(a.data??[]).map(e=>Pt(e,e.scopes.map(yn).join(`, `))),[a.data]),m=async n=>{await t({title:e(`access.linkedAppsSection.revokeTheLink`,`Revoke the "{{name}}" link?`,{name:n.name}),message:e(`access.linkedAppsSection.losesAccessForOnIts`,`{{name}} loses access for {{ownerName}} on its next call. Linking it again needs the account-link flow from the start.`,{name:n.name,ownerName:n.ownerName}),confirmLabel:e(`access.linkedAppsSection.revoke`,`Revoke`),variant:`danger`})&&(s(null),u.mutate({id:n.id}))},g=u.isPending?u.variables?.id??null:null;return d(Z,{notice:Rt(o,f.outcome),onDismissNotice:()=>{s(null),f.dismiss()},id:`linked-apps`,title:e(`access.linkedAppsSection.linkedApps`,`Linked apps`),icon:O,description:e(`access.linkedAppsSection.externalIntegrationsAlexaLinkedTo`,`External integrations (Alexa, …) linked to this hub through OAuth. Revoking one stops that integration on its next call. Already-revoked rows can be selected and removed from the list.`),children:d(Xt,{rows:p,label:e(`access.linkedAppsSection.linkedApps2`,`linked apps`),isLoading:a.isLoading,loadError:a.isError?a.error?.message??`Request failed`:null,emptyText:`No linked apps — an integration appears here once it completes the account-link flow.`,expiresNone:`—`,action:{label:e(`access.linkedAppsSection.revoke`,`Revoke`),icon:h,isAvailable:e=>e.status===`active`||e.status===`revoked`,onRun:e=>void m(e),busyId:g,disabled:u.isPending||f.busy},bulk:{revoke:f,noun:vn,isSelectable:e=>e.status===`active`||e.status===`revoked`,quickSelect:[{label:e(`access.linkedAppsSection.selectRevoked`,`Select revoked`),match:e=>e.status===`revoked`}]}})})}e();var xn={key:`access.nouns.session`};function Sn(){let{t:e}=X(),t=U(),i=K.useUtils(),a=Ft(),o=K.auth.listSessions.useQuery(),[s,c]=r(null),l=()=>void i.auth.listSessions.invalidate(),u=K.auth.revokeSessions.useMutation({onSuccess:l,onError:e=>c(`Sign out failed: ${e.message}`)}),f=jt(`login-session`,xn,l),p=n(()=>(o.data??[]).map(e=>Nt(e,a,{client:e=>on(e).label,method:ln})),[o.data,a]),m=async n=>{await t({title:e(`access.loginSessionsSection.signOutThisSession`,`Sign out this session`),message:e(`access.loginSessionsSection.onWillHaveToSign`,`{{ownerName}} on {{name}} will have to sign in again.`,{ownerName:n.ownerName,name:n.name}),confirmLabel:e(`access.loginSessionsSection.signOut`,`Sign out`),variant:`danger`})&&(c(null),u.mutate({id:n.id}))};return d(Z,{notice:Rt(s,f.outcome),onDismissNotice:()=>{c(null),f.dismiss()},id:`login-sessions`,title:e(`access.loginSessionsSection.loginSessions`,`Login sessions`),icon:fe,description:e(`access.loginSessionsSection.everyBrowserAndAppSigned`,`Every browser and app signed in to this hub, for every user. Signing one out ends it at once; it has to sign in again. Your own current session is marked and never included in a bulk sign-out.`),children:d(Xt,{rows:p,label:e(`common.sessionsLabel`),isLoading:o.isLoading,loadError:o.isError?o.error?.message??`Request failed`:null,emptyText:`No active sessions.`,action:{label:e(`access.loginSessionsSection.signOut`,`Sign out`),icon:le,isAvailable:e=>e.status===`active`,onRun:e=>void m(e),busyId:u.isPending&&u.variables!==void 0&&`id`in u.variables?u.variables.id:null,disabled:u.isPending||f.busy},bulk:{revoke:f,noun:xn,isSelectable:e=>e.status===`active`}})})}function Cn({token:e,label:t,onClose:n}){let{t:r}=X();return d(W,{open:!0,onOpenChange:e=>!e&&n(),children:a(ct,{width:`md`,scroll:`body`,children:[d(Ae,{children:d(Ne,{children:r(`auth.tokenModals.token`,`Token: {{label}}`,{label:t})})}),a(Fe,{className:`space-y-3`,children:[d(`div`,{className:`rounded-md border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:r(`auth.tokenModals.copyThisTokenNowOnce`,`Copy this token now. Once you close this dialog the secret cannot be displayed again.`)}),d(`div`,{className:`select-all break-all rounded-md border border-border bg-background p-2 font-mono text-[11px] text-foreground`,children:e})]}),a(st,{children:[d(Oe,{value:e,label:r(`common.copy`,`Copy`),srLabel:`token`}),d(G,{type:`button`,variant:`primary`,size:`sm`,onClick:n,children:r(`auth.tokenModals.done`,`Done`)})]})]})})}var wn={token:`newToken`,scoped:`newScoped`,admin:`newAdmin`};e();var Tn=7,En=90,Dn=80;function On(e){let t=Number(e);return Number.isInteger(t)&&t>=1&&t<=En?t:null}function kn({open:e,users:n,onClose:i,onSubmitScoped:o,onSubmitAdmin:c,submitting:l,formError:u,awaitingProof:f}){let{t:p}=X(),m=j(),{user:h}=xt(),g=h?.isAdmin===!0,_=g?null:h?.scopes??[],[v,y]=r(!1),[b,x]=r(n[0]?.id??``),[S,w]=r(``),[T,E]=r([{type:`capability`,target:``,access:[`view`,`create`]}]),[D,O]=r(``),[k,A]=r(String(Tn));t(()=>{e||(y(!1),x(n[0]?.id??``),w(``),E([{type:`capability`,target:``,access:[`view`,`create`]}]),O(``),A(String(Tn)))},[e,n]);let N=S.trim(),P=Le(T,m),F=On(k),L=!v&&b!==``&&N.length>0&&T.length>0&&P===null&&!l,R=v&&g&&N.length>0&&N.length<=Dn&&F!==null&&!l&&!f,z=()=>{if(v){if(!R||F===null)return;c({name:N,expiresInDays:F});return}if(!L)return;let e=parseInt(D,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;o({userId:b,name:N,scopes:T,...t===void 0?{}:{expiresAt:t}})},ee=v,B=v?C:I;return d(Je,{open:e,onClose:i,title:v?p(`access.createTokenModal.createAdminToken`,`Create admin token`):p(`access.createTokenModal.createToken`,`Create token`),icon:v?C:de,error:u,width:`md`,testId:`create-token-dialog`,footer:a(G,{type:`button`,variant:ee?`danger`:`primary`,size:`sm`,onClick:z,disabled:v?!R:!L,children:[l||f?d(M,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}):d(B,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),v?p(`access.createTokenModal.createAdminToken`,`Create admin token`):p(`access.createTokenModal.issueToken`,`Issue token`)]}),children:a(`div`,{className:`space-y-3`,children:[g?a(`label`,{className:`flex items-start gap-2 text-sm text-foreground`,children:[d(`input`,{type:`checkbox`,className:`mt-0.5`,checked:v,onChange:e=>y(e.target.checked),"data-testid":`token-as-admin`}),a(`span`,{children:[d(`span`,{className:`font-medium`,children:p(`access.createTokenModal.administrator`,`Administrator`)}),d(`span`,{className:`block text-[11px] text-foreground-subtle`,children:p(`access.createTokenModal.offScopedToASurface`,`Off = scoped to a surface. On = full admin for scripts (audited, max 90 days).`)})]})]}):null,v?d(`div`,{className:`space-y-1 rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px] leading-relaxed text-foreground`,"data-testid":`admin-token-warning`,children:d(`p`,{children:d(St,{i18nKey:`auth.adminTokenNoticeShort`,components:{strong:d(`strong`,{})}})})}):null,v?null:a(`div`,{className:`space-y-1`,children:[d(nt,{htmlFor:`token-user`,children:p(`access.createTokenModal.onBehalfOfUser`,`On behalf of user`)}),d($e,{id:`token-user`,value:b,onChange:e=>x(e.target.value),options:n.map(e=>({value:e.id,label:e.username}))})]}),d(pt,{label:p(`access.createTokenModal.name`,`Name`),required:!0,children:d(dt,{id:`token-name`,value:S,maxLength:Dn,onChange:e=>w(e.target.value),placeholder:v?`nightly-backup`:`cloudflare-tunnel-route`,autoFocus:!0})}),v?a(`div`,{className:`space-y-1`,children:[d(nt,{htmlFor:`token-admin-days`,children:p(`access.createTokenModal.expiresInDays`,`Expires in (days)`)}),d(dt,{id:`token-admin-days`,type:`number`,min:1,max:En,value:k,onChange:e=>A(e.target.value),state:F===null?`error`:`default`}),F===null?d(`p`,{className:`text-[11px] text-danger`,children:p(`auth.expiryInvalid`,{max:En})}):d(`p`,{className:`text-[11px] text-foreground-subtle`,children:p(`auth.expiryHint`,{max:En})})]}):a(s,{children:[a(`div`,{className:`space-y-1`,children:[d(nt,{children:p(`access.createTokenModal.scopes`,`Scopes`)}),d(je,{value:T,onChange:E,clampToParent:_}),P&&d(`p`,{className:`text-[10px] text-danger`,children:P}),d(`p`,{className:`text-[10px] text-foreground-subtle`,children:p(`access.createTokenModal.eachScopePicksACap`,`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`)})]}),a(`div`,{className:`space-y-1`,children:[d(nt,{htmlFor:`token-scoped-days`,children:p(`access.createTokenModal.expiresInDays`,`Expires in (days)`)}),d(dt,{id:`token-scoped-days`,type:`number`,min:1,value:D,onChange:e=>O(e.target.value),placeholder:`30`}),d(`p`,{className:`text-[10px] text-foreground-subtle`,children:p(`access.createTokenModal.leaveBlankForNonExpiring`,`Leave blank for non-expiring.`)})]})]})]})})}e();var An={key:`access.nouns.token`};function jn(e,t){return e.type===`device`?`device:[${me(e.selector,t)}]`:`${e.type}:${e.target??``}`}function Mn({createRequested:e=!1,onCreateConsumed:i}){let{t:o}=X(),s=j(),{user:l}=xt(),u=U(),f=c(),p=K.useUtils(),m=Ft(),{data:g,isLoading:_}=gt(),v=n(()=>g??[],[g]),y=K.useQueries(e=>v.map(t=>e.userManagement.listScopedTokens({userId:t.id}))),b=K.auth.listAdminTokens.useQuery(void 0,{enabled:l?.isAdmin===!0}),{requestProof:x,dialog:S}=Vt(`Creating an admin token`),{state:C,openNew:w,close:T}=ht({newKey:wn.token}),[E,D]=r(null),[O,k]=r(null),[A,M]=r(!1),[N,P]=r(null),[F,I]=r(null);t(()=>{e&&(w(),i?.())},[e,w,i]);let L=()=>{f.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),p.auth.listAdminTokens.invalidate(),p.auth.listAuthAudit.invalidate()},R=ot({onSuccess:({token:e,record:t})=>{L(),T(),k(null),P({token:e,label:t.name})},onError:e=>{D(`Create failed: ${e.message}`),k(`Create failed: ${e.message}`)}}),z=K.auth.createAdminToken.useMutation({onSuccess:({token:e,record:t})=>{L(),T(),k(null),M(!1),P({token:e,label:t.name})},onError:e=>{D(`Create failed: ${e.message}`),k(`Create failed: ${e.message}`),M(!1)}}),ee=Ke({onSuccess:()=>{I(null),L()},onError:e=>{I(null),D(`Revoke failed: ${e.message}`)}}),B=K.auth.revokeAdminToken.useMutation({onSuccess:()=>{I(null),L()},onError:e=>{I(null),D(`Revoke failed: ${e.message}`)}}),V=It(An,L),te=Date.now(),ne=v.flatMap((e,t)=>(y[t]?.data??[]).map(t=>Lt(t,e.id,m,t.scopes.map(e=>jn(e,s)).join(`, `),te))),re=l?.isAdmin===!0?(b.data??[]).map(e=>zt(e,m,te)):[],ie=[...ne,...re],ae=y.find(e=>e.isError)?.error?.message??(b.isError?b.error?.message??`Request failed`:null),oe=async e=>{let t=e.kind===cn;await u({title:o(`access.tokensSection.revoke`,`Revoke "{{name}}"?`,{name:e.name}),message:t?o(`access.tokensSection.everyScriptUsingItLoses`,`Every script using it loses access immediately. This cannot be undone.`):o(`access.tokensSection.sScopedTokenStopsWorking`,`{{ownerName}}'s scoped token stops working on its next use. This cannot be undone.`,{ownerName:e.ownerName}),confirmLabel:o(`access.tokensSection.revoke2`,`Revoke`),variant:`danger`})&&(D(null),I(e.id),t?B.mutate({id:e.id}):ee.mutate({id:e.id}))},se=R.isPending||z.isPending;return a(`div`,{"data-testid":`tokens`,children:[S,d(Z,{notice:Rt(E,V.outcome),onDismissNotice:()=>{D(null),V.dismiss()},id:`tokens`,title:o(`access.tokensSection.tokens`,`Tokens`),icon:de,description:o(`access.tokensSection.scopedTokensForANarrow`,`Scoped tokens for a narrow surface, and admin tokens for full-administrator scripts. Revoking one stops it on its next use.`),children:d(Xt,{rows:ie,label:o(`common.tokensLabel`),isLoading:_||y.some(e=>e.isLoading)||l?.isAdmin===!0&&b.isLoading,loadError:ae,emptyText:`No tokens.`,action:{label:o(`access.tokensSection.revoke2`,`Revoke`),icon:h,isAvailable:e=>e.status===`active`,onRun:e=>void oe(e),busyId:F,disabled:V.busy||F!==null},bulk:{revoke:V,noun:An,isSelectable:e=>e.status===`active`}})}),d(kn,{open:C.mode===`new`,users:v.map(e=>({id:e.id,username:e.username})),onClose:()=>{T(),k(null),M(!1)},submitting:se,formError:O,awaitingProof:A,onSubmitScoped:e=>R.mutate({userId:e.userId,name:e.name,scopes:e.scopes,expiresAt:e.expiresAt}),onSubmitAdmin:e=>{(async()=>{D(null),k(null),M(!0);let t=await x();M(!1),t!==null&&z.mutate({...e,reauthToken:t})})()}}),N&&d(Cn,{token:N.token,label:N.label,onClose:()=>P(null)})]})}var Nn={"share-link":`helpers.authAuditWording.bulkNoun.shareLink`,"admin-token":`helpers.authAuditWording.bulkNoun.adminToken`,"login-session":`helpers.authAuditWording.bulkNoun.loginSession`};function Q(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:null}function Pn(e,t){let n=Q(e,`tokenId`);return Q(e,`name`)??(n===null?void 0:t.get(n))??n??`?`}function Fn(e){return e.filter(e=>e!==null)}function In(e){let t=Q(e,`prefix`);return t===null?null:Y.t(`helpers.authAuditWording.prefix`,{prefix:t})}function Ln(e,t){let n=e.detail??{};switch(e.action){case`admin-token-created`:{let e=n.expiresAt;return{title:Y.t(`helpers.authAuditWording.tokenCreated`,{name:Pn(n,t)}),details:Fn([In(n),typeof e==`number`?Y.t(`helpers.authAuditWording.expires`,{at:Ut(e)}):null])}}case`admin-token-used`:{let e=Q(n,`path`);return{title:Y.t(`helpers.authAuditWording.tokenUsed`,{name:Pn(n,t)}),details:Fn([In(n),e===null?null:Y.t(`helpers.authAuditWording.call`,{path:e})])}}case`admin-token-revoked`:return{title:Y.t(`helpers.authAuditWording.tokenRevoked`,{name:Pn(n,t)}),details:Fn([In(n)])};case`credentials-revoked`:{let e=Q(n,`kind`)??`credential`,t=n.revoked,r=n.skipped,i=Nn[e],a=i===void 0?`${e}s`:Y.t(i);return{title:Y.t(`helpers.authAuditWording.bulkRevoked`,{n:typeof t==`number`?String(t):`?`,noun:a}),details:Fn([typeof r==`number`&&r>0?Y.t(`helpers.authAuditWording.skipped`,{count:r}):null,Q(n,`ids`)===null?null:Y.t(`helpers.authAuditWording.ids`,{ids:Q(n,`ids`)??``})])}}case`second-factor-skipped`:{let e=Q(n,`method`),t=Q(n,`factors`);return{title:Y.t(`helpers.authAuditWording.secondFactorSkipped`),details:Fn([e===null?null:Y.t(`helpers.authAuditWording.signedInWith`,{method:ln(e)}),t===null?null:Y.t(`helpers.authAuditWording.skippedFactors`,{factors:t.split(`,`).join(`, `)})])}}default:return{title:e.action,details:Object.entries(n).map(([e,t])=>`${e}: ${String(t)}`)}}}e();var Rn=100;function zn(){let{user:e}=xt();return e?.isAdmin?d(Vn,{}):null}function Bn(){let{data:e}=gt(),{data:t}=K.auth.listAdminTokens.useQuery();return n(()=>{let n=new Map;for(let t of e??[])n.set(t.id,t.username);let r=new Map;for(let e of t??[])r.set(e.id,e.name);return{userNameById:n,tokenNameById:r}},[e,t])}function Vn(){let{t:e}=X(),t=K.auth.listAuthAudit.useQuery({limit:Rn}),{userNameById:n,tokenNameById:r}=Bn(),i=t.data??[];return a(`div`,{"data-testid":`auth-audit`,className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[a(`div`,{className:`px-4 py-2.5 border-b border-border flex items-center gap-2`,children:[d(P,{className:`h-3.5 w-3.5 text-foreground-subtle`}),d(`div`,{className:`text-xs font-semibold text-foreground`,children:e(`auth.authAuditSection.authenticationAudit`,`Authentication audit`)}),d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:e(`auth.authAuditSection.latest`,{count:Rn})})]}),d(`div`,{className:`p-4`,children:t.isLoading?a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(M,{className:`h-3.5 w-3.5 animate-spin`}),e(`auth.authAuditSection.loadingAuditTrail`,`Loading audit trail…`)]}):t.isError?a(`div`,{className:`text-[11px] text-danger`,children:[e(`auth.authAuditSection.couldNotLoadTheAudit`,`Could not load the audit trail:`),` `,t.error?.message??e(`auth.authAuditSection.requestFailed`,`Request failed`)]}):i.length===0?a(`div`,{className:`rounded border border-dashed border-border px-3 py-4 text-xs text-foreground-subtle text-center space-y-1`,children:[d(`div`,{children:e(`auth.authAuditSection.noAuthenticationEventsRecordedYet`,`No authentication events recorded yet.`)}),d(`div`,{className:`text-[11px] text-foreground-subtle/90`,children:e(`auth.authAuditSection.thisTrailRecordsAdminToken`,`This trail records admin-token create/use/revoke, trusted-network 2FA skips, and credential revokes (including single share-link revoke). Browser password logins are not listed here.`)})]}):d(`ul`,{className:`divide-y divide-border rounded-md border border-border max-h-[420px] overflow-y-auto`,children:i.map(e=>d(Hn,{record:e,userName:e.userId===void 0?null:n.get(e.userId)??e.userId,tokenNameById:r},e.id))})})]})}function Hn({record:e,userName:t,tokenNameById:n}){let r=Ln(e,n);return a(`li`,{"data-testid":`auth-audit-row`,className:`px-3 py-2 text-xs space-y-0.5`,children:[a(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[d(`span`,{className:`font-medium text-foreground`,children:r.title}),d(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ut(e.at)})]}),a(`div`,{className:`flex flex-wrap gap-x-3 text-[11px] text-foreground-subtle`,children:[t!==null&&d(`span`,{className:`text-foreground`,children:t}),e.ip!==void 0&&d(`span`,{className:`font-mono`,children:e.ip}),r.details.map(e=>d(`span`,{className:`font-mono`,children:e},e))]})]})}e();var $={loginSessions:`login-sessions`,linkedApps:`linked-apps`,tokens:`tokens`,scopedTokens:`scoped-tokens`,adminTokens:`admin-tokens`,shareLinks:`share-links`,legacyApiKeys:`legacy-api-keys`,externalIdentities:`external-identities`,audit:`auth-audit`},Un={[$.scopedTokens]:$.tokens,[$.adminTokens]:$.tokens};function Wn(e){return[{id:$.loginSessions,label:Y.t(`system.access.loginSessions`,`Login sessions`),icon:fe,render:()=>d(Sn,{})},{id:$.linkedApps,label:Y.t(`system.access.linkedApps`,`Linked apps`),icon:O,render:()=>d(bn,{})},{id:$.tokens,label:Y.t(`system.access.tokens`,`Tokens`),icon:de,render:({createRequested:e,onCreateConsumed:t})=>d(Mn,{headerOwnsCreate:!0,createRequested:e,onCreateConsumed:t})},{id:$.shareLinks,label:Y.t(`system.access.shareLinks`,`Share links`),icon:D,render:()=>d(qt,{})},...e?[{id:$.legacyApiKeys,label:Y.t(`system.access.legacyApiKeys`,`Legacy API keys`),icon:ue,render:()=>d(_n,{})}]:[],{id:$.externalIdentities,label:Y.t(`system.access.signInLinks`,`Sign-in links`),icon:H,render:()=>d(gn,{})},{id:$.audit,label:Y.t(`system.access.audit`,`Audit`),icon:P,render:()=>d(zn,{})}]}function Gn({createRequested:e=!1,onCreateConsumed:t}){let{t:r}=X(),i=we(),o=(i.data??[]).length>0,s=n(()=>Wn(o),[o]),c=un({ids:n(()=>s.map(e=>e.id),[s]),answered:!i.isLoading}),l=Tt(),[u]=Ot(),f=u.get(`integration`),p=f===null?void 0:Un[f];if(p!==void 0){let e=new URLSearchParams(u);return e.set(`integration`,p),d(vt,{to:`?${e.toString()}`,replace:!0})}let m=s.find(e=>e.id===c.selectedId)??s[0],h=m?.id??$.loginSessions;return i.isLoading?d(`div`,{className:`text-sm text-foreground-subtle`,"data-testid":`access-page`,children:r(`common.loading`,`Loading…`)}):a(`div`,{className:`flex flex-col gap-3`,"data-testid":`access-page`,children:[d(ut,{appearance:`pills`,value:h,onValueChange:e=>{l(`?${wt(u,e,null,null).toString()}`)},children:d(at,{"aria-label":r(`system.access.credentialKinds`,`Credential kinds`),children:s.map(e=>a(tt,{value:e.id,"data-testid":`access-kind-${e.id}`,children:[d(e.icon,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),e.label]},e.id))})}),m===void 0?null:d(`div`,{role:`region`,"aria-label":m.label,"data-testid":`access-kind-body`,children:m.render({createRequested:e&&m.id===$.tokens,onCreateConsumed:t??(()=>void 0)})},m.id)]})}function Kn(e,t){if(e===$.tokens)return a(G,{size:`sm`,type:`button`,"data-testid":`access-new-token`,onClick:t,children:[d(de,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),Y.t(`system.access.newToken`,`New token`)]})}function qn(){let[e,t]=r(!1);return{createRequested:e,requestCreate:()=>t(!0),clearCreate:()=>t(!1)}}e();var Jn=[`oidcConnections`,`listConnections`],Yn=[`oidcConnections`,`connectionFormSchema`],Xn={displayName:`OpenID Connect`,icon:`shield-check`,issuerUrl:``,clientId:``,clientSecret:``,redirectUri:``,scopes:`openid profile email`,usernameClaim:`preferred_username`},Zn=/^[a-z0-9][a-z0-9-]{0,63}$/;function Qn(e){return e instanceof Error?e.message:String(e)}function $n(e,t){if(t)return typeof e==`string`&&e.length>0?e:void 0;if(z(e))return ee;if(typeof e==`string`&&e.length>0)return e;re(e)}function er(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function tr({addonId:e}){let{t:f}=X(),p=N(),m=c(),g=U(),_=ht({editKey:`oidcEdit`,newKey:`oidcNew`}),[v,y]=r(!1),[b,x]=r(null),[S,C]=r(``),[w,T]=r({...Xn}),D=l(null),O=o({queryKey:[...Jn,e],queryFn:async()=>p.trpcClient.oidcConnections.listConnections.query({})}),k=o({queryKey:Yn,queryFn:async()=>p.trpcClient.oidcConnections.connectionFormSchema.query({})}),A=O.data??[],j=er(k.data)?k.data:void 0,M=_.state,P=M.mode===`edit`?A.find(e=>e.id===M.id)??null:null;t(()=>{if(_.state.mode===`edit`&&P!==null){let e=`edit:${P.id}`;if(D.current===e)return;D.current=e,x(null),C(P.id),T(P.formValues===void 0?{...Xn}:{...P.formValues});return}if(_.state.mode===`new`){if(D.current===`new`)return;D.current=`new`,x(null),C(``),T({...Xn})}},[P,_.state]);let F=i(async()=>{await m.invalidateQueries({queryKey:Jn})},[m]),L=u({mutationFn:async e=>p.trpcClient.oidcConnections.deleteConnection.mutate({id:e}),onSuccess:async()=>F()}),R=i(async e=>{await g({title:f(`system.oidcSettingsConnections.deleteOidcConnection`,`Delete OIDC connection?`),message:f(`system.oidcSettingsConnections.removeTheLoginButtonAnd`,`Remove “{{displayName}}” ({{id}}). The login button and IdP credentials for this id are dropped.`,{displayName:e.displayName,id:e.id}),confirmLabel:f(`common.delete`,`Delete`),cancelLabel:f(`common.cancel`,`Cancel`),variant:`danger`})&&(await L.mutateAsync(e.id),_.state.mode===`edit`&&_.state.id===e.id&&(_.close(),D.current=null))},[g,L,_,f]),z=i(async()=>{let e=w.displayName,t=typeof e==`string`&&e.trim()!==``?e.trim():``;if(t===``){x(`Display name is required.`);return}let n=_.state.mode===`new`,r=n?S.trim():P?.id??``;if(n&&!Zn.test(r)){x(`Instance id must be a lowercase slug (e.g. authentik, google).`);return}if(r===``){x(`That connection is no longer available.`);return}let i=$n(w.clientSecret,n),a=w.icon,o=w.issuerUrl,s=w.clientId,c=w.redirectUri,l=w.scopes,u=w.usernameClaim,d=u===`email`||u===`sub`?u:`preferred_username`;y(!0),x(null);try{n&&await p.trpcClient.oidcConnections.createConnection.mutate({id:r,displayName:t}),await p.trpcClient.oidcConnections.updateConnection.mutate({id:r,displayName:t,icon:typeof a==`string`?a:`shield-check`,issuerUrl:typeof o==`string`?o:``,clientId:typeof s==`string`?s:``,...i===void 0?{}:{clientSecret:i},redirectUri:typeof c==`string`?c:``,scopes:typeof l==`string`?l:`openid profile email`,usernameClaim:d}),await F(),_.close(),D.current=null}catch(e){x(Qn(e))}finally{y(!1)}},[S,P?.id,_,w,F,p]),ee=n(()=>[{key:`id`,header:f(`system.oidcSettingsConnections.id`,`Id`),sortValue:e=>e.id,render:e=>d(`span`,{className:`font-mono text-xs text-foreground`,children:e.id})},{key:`name`,header:f(`system.oidcSettingsConnections.name`,`Name`),sortValue:e=>e.displayName,render:e=>d(`span`,{className:`truncate font-medium text-foreground`,children:e.displayName})},{key:`issuer`,header:f(`system.oidcSettingsConnections.issuer`,`Issuer`),sortValue:e=>e.issuerUrl,render:e=>d(`span`,{className:`truncate text-xs text-foreground-muted`,children:e.issuerUrl===``?`—`:e.issuerUrl})},{key:`status`,header:f(`system.oidcSettingsConnections.status`,`Status`),notSortableReason:`Badge`,render:e=>d(J,{variant:e.configured?`success`:`warning`,children:e.configured?f(`system.oidcSettingsConnections.configured`,`Configured`):f(`system.oidcSettingsConnections.notConfigured`,`Not configured`)})},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,nowrap:!0,render:e=>a(`div`,{className:`flex justify-end gap-1`,children:[d(G,{type:`button`,size:`sm`,variant:`secondary`,onClick:t=>{t.stopPropagation(),_.openEdit(e.id)},children:f(`common.edit`,`Edit`)}),d(G,{type:`button`,size:`sm`,variant:`ghost`,"aria-label":f(`system.oidcSettingsConnections.delete`,`Delete {{displayName}}`,{displayName:e.displayName}),title:f(`common.delete`,`Delete`),onClick:t=>{t.stopPropagation(),R(e)},children:d(h,{className:`h-3.5 w-3.5 text-danger`})})]})}],[_,R,f]),B=_.state.mode===`new`,V=B||P!==null,te=B?`new`:P===null?`closed`:`edit:${P.id}:${P.configured?`cfg`:`empty`}`;return a(`div`,{className:`flex min-h-0 flex-col gap-3`,"data-testid":`oidc-settings-connections`,children:[a(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[a(`p`,{className:`text-sm text-foreground-muted`,children:[f(`system.oidcSettingsConnections.eachRowIsOneIdp`,`Each row is one IdP. Redirect URI:`),` `,d(`span`,{className:`font-mono text-xs`,children:`/addon/${e}/<id>/callback`})]}),a(G,{type:`button`,size:`sm`,"data-testid":`oidc-connections-add`,onClick:()=>_.openNew(),children:[d(E,{className:`h-3.5 w-3.5`}),f(`system.oidcSettingsConnections.addConnection`,`Add connection`)]})]}),O.isError?d(`p`,{className:`text-sm text-danger`,children:f(`system.oidcSettingsConnections.couldNotLoadConnections`,`Could not load connections.`)}):null,O.isPending?d(Xe,{className:`h-32 w-full`}):d(xe,{columns:ee,rows:A,rowKey:e=>e.id,pageSize:25,emptyMessage:f(`system.oidcSettingsConnections.noOidcConnectionsYetAdd`,`No OIDC connections yet. Add one to register an IdP.`),onRowClick:e=>_.openEdit(e.id),defaultSort:{columnKey:`name`,dir:`asc`}}),d(Je,{open:V,onClose:()=>{_.close(),x(null),D.current=null},title:B?f(`system.oidcSettingsConnections.addOidcConnection`,`Add OIDC connection`):f(`system.oidcSettingsConnections.edit`,`Edit {{value1}}`,{value1:P?.displayName??`connection`}),icon:I,width:`xl`,testId:`oidc-connection-editor`,error:b,footer:d(G,{type:`button`,size:`sm`,disabled:v||B&&S.trim()===``,onClick:()=>void z(),children:v?f(`system.oidcSettingsConnections.saving`,`Saving…`):f(`common.save`,`Save`)}),children:V?a(s,{children:[B?a(`div`,{children:[d(nt,{htmlFor:`oidc-connection-id`,children:f(`system.oidcSettingsConnections.instanceId`,`Instance id`)}),d(dt,{id:`oidc-connection-id`,value:S,onChange:e=>C(e.target.value),placeholder:`authentik`,autoComplete:`off`}),d(`p`,{className:`mt-1 text-xs text-foreground-muted`,children:f(`system.oidcSettingsConnections.urlSlugAppearsInAddon`,`URL slug — appears in /addon/{{addonId}}/<id>/callback. Stable; renaming is not supported after save.`,{addonId:e})})]}):a(`p`,{className:`text-sm text-foreground-muted`,children:[f(`system.oidcSettingsConnections.instanceId2`,`Instance id:`),` `,d(`span`,{className:`font-mono`,children:P?.id})]}),j===void 0?d(`p`,{className:`text-sm text-foreground-muted`,children:f(`system.oidcSettingsConnections.loadingForm`,`Loading form…`)}):d(We,{schema:j,values:w,onChange:T,bare:!0},te)]}):null})]})}e();var nr=3e4,rr=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],ir={titleKey:`system.authentication.sectionTitle`,subtitleKey:`system.authentication.sectionSubtitle`,emptyTitleKey:`system.authentication.sectionEmptyTitle`,emptyDescriptionKey:`system.authentication.sectionEmptyDescription`,installLabelKey:`system.authentication.sectionInstall`};function ar(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:ae,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA is self-enrolled: each user enables it from their own profile page (My access → Two-factor authentication).`,`Scoped tokens, admin tokens and sessions are managed from Identity → Tokens & sessions.`],setupSteps:[`A fresh hub has one account, admin / changeme — the first sign-in asks for a new password. Add users from Users → New user.`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:ce,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`Explicit linking only: an IdP account signs in only the CamStack user who linked it from their profile (My access → Linked sign-in accounts). No auto-created users, no email matching.`,`The linked user’s role, scopes and two-factor authentication apply.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Choose a stable instance id (slug). Set the IdP redirect URI to `https://<this-hub>/addon/auth-oidc/<id>/callback`.",`In Settings below, Add connection — enter the id, issuer, and credentials; Save.`,`Each user then links their IdP account from My access → Linked sign-in accounts.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:ce,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:f,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)?{headline:`TOTP — second factor.`,icon:f,bullets:[`Time-based codes from an authenticator app (RFC 6238).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:I,bullets:[`Generic authentication provider. No additional hints registered.`]}}function or(){let{t:e}=X(),t=lt({capName:rr[0].capName},{refetchInterval:nr}),r=lt({capName:rr[1].capName},{refetchInterval:nr}),i=Ie(void 0,{refetchInterval:nr}),a=n(()=>hn(i.data??[]),[i.data]),o=n(()=>{let e=[],n=[t.data??[],r.data??[]];for(let[t,r]of rr.entries())for(let i of n[t]??[])e.push({addonId:i.addonId,displayName:a.get(i.addonId)??i.addonId,isActive:i.isActive,capName:r.capName,stageBadge:r.stageBadge});return e},[t.data,r.data,a]),s=[{id:`authentication`,label:e(`system.authentication.authenticationProviders`,`Authentication providers`),install:{capability:rr[0].capName,label:e(ir.installLabelKey)},entries:o.map(t=>({id:t.addonId,name:t.displayName,fallbackIcon:I,...mn(t.isActive),render:()=>d(dn,{addonId:t.addonId,displayName:t.displayName,capName:t.capName,isActive:t.isActive,badges:t.stageBadge===null?null:d(J,{variant:`info`,className:fn,children:t.stageBadge}),settingsContent:t.addonId.startsWith(`auth-oidc`)?d(tr,{addonId:t.addonId}):void 0,panels:[{id:`about`,title:e(`system.authentication.about`,`About`),icon:ar(t.addonId).icon,content:d(sr,{addonId:t.addonId})}]})}))}];return d(pn,{embedded:!0,icon:I,title:e(ir.titleKey),subtitle:e(ir.subtitleKey),groups:s,isLoading:t.isLoading||r.isLoading,emptyTitle:e(ir.emptyTitleKey),emptyDescription:e(ir.emptyDescriptionKey)})}function sr({addonId:e}){let{t}=X(),n=ar(e),r=n.icon;return a(`div`,{className:`space-y-3 rounded-lg border border-border bg-surface p-2 sm:p-4`,children:[a(`div`,{className:`flex items-start gap-2.5`,children:[d(r,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),d(`div`,{className:`text-xs text-foreground font-medium`,children:n.headline})]}),d(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:n.bullets.map((e,t)=>d(`li`,{children:e},t))}),n.setupSteps&&n.setupSteps.length>0&&a(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[a(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[d(ie,{className:`h-3 w-3`}),t(`system.authentication.setupSteps`,`Setup steps`)]}),d(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:n.setupSteps.map((e,t)=>d(`li`,{children:e},t))})]}),e===`local-auth`&&a(`div`,{className:`rounded-md border border-info/30 bg-info/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[d(A,{className:`h-3.5 w-3.5 mt-0.5 text-info shrink-0`}),d(`span`,{children:d(St,{i18nKey:`system.authentication.totpNote`,components:{access:d(yt,{to:`/system/my-access`,className:`underline text-primary`}),users:d(yt,{to:`/system/identity?tab=users`,className:`underline text-primary`})}})})]})]})}function cr({isPending:e,error:t,what:n,onRetry:r,children:i}){let{t:o}=X();return e?a(`div`,{className:`flex items-center gap-2 py-3 text-xs text-foreground-subtle`,role:`status`,"data-testid":`query-pending`,children:[d(M,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),o(`certificates.queryBody.reading`,{what:n})]}):t===null?i:d(_t,{title:o(`certificates.queryBody.couldNotRead`,`Could not read {{what}}`,{what:n}),message:t.message.length>0?t.message:o(`certificates.queryBody.requestFailed`,`Request failed`),onRetry:r})}function lr(){let{t:e}=X(),t=K.deviceCredentials.getDeviceCaStatus.useQuery({}),n=t.data;return d(Z,{id:`device-ca`,title:e(`certificates.deviceCaCard.deviceCertificateAuthority`,`Device certificate authority`),icon:I,description:e(`certificates.deviceCaCard.signsTheCertificateEachPaired`,`Signs the certificate each paired device holds. It is created the first time a device is paired.`),children:d(cr,{isPending:t.isPending,error:t.error,what:`the device CA`,onRetry:()=>void t.refetch(),children:n!==void 0&&a(`div`,{className:`space-y-1`,"data-testid":`device-ca-status`,children:[a(q,{label:e(`certificates.deviceCaCard.state`,`State`),children:[n.state===`ready`&&d(J,{variant:`success`,children:e(`certificates.deviceCaCard.ready`,`Ready`)}),n.state===`absent`&&d(J,{variant:`default`,children:e(`certificates.deviceCaCard.notCreatedYet`,`Not created yet`)}),n.state===`unavailable`&&d(J,{variant:`danger`,children:e(`certificates.deviceCaCard.unavailable`,`Unavailable`)})]}),n.state===`ready`&&a(s,{children:[d(q,{label:e(`certificates.deviceCaCard.subject`,`Subject`),valueClassName:`font-mono`,children:n.subject}),d(q,{label:e(`certificates.deviceCaCard.fingerprintSha256`,`Fingerprint (SHA-256)`),valueClassName:`font-mono`,children:n.fingerprintSha256}),d(q,{label:e(`certificates.deviceCaCard.validUntil`,`Valid until`),children:n.validTo})]}),n.state===`unavailable`&&d(q,{label:e(`certificates.deviceCaCard.reason`,`Reason`),children:d(`span`,{className:`text-danger`,children:n.reason})})]})})})}e();function ur(){let{t:e}=X(),t=K.useUtils(),n=K.deviceCredentials.getDeviceCertificateSettings.useQuery({}),[i,o]=r(null),s=K.deviceCredentials.setDeviceCertificateSettings.useMutation({onSuccess:()=>{o(null),t.deviceCredentials.getDeviceCertificateSettings.invalidate()},onError:e=>o(`Could not save: ${e.message}`)});return d(cr,{isPending:n.isPending,error:n.error,what:`the enrollment setting`,onRetry:()=>void n.refetch(),children:n.data!==void 0&&a(q,{label:e(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),actions:d(ft,{checked:n.data.selfEnrollment===`allowed`,disabled:s.isPending,"aria-label":e(`certificates.deviceSettingsRow.usersCanEnrollTheirOwn`,`Users can enroll their own devices`),onCheckedChange:e=>s.mutate({selfEnrollment:e?`allowed`:`disabled`})}),children:[d(`span`,{className:`text-[11px] text-foreground-subtle`,children:n.data.selfEnrollment===`allowed`?e(`certificates.deviceSettingsRow.allowedAUserSignedIn`,`Allowed - a user signed in on a phone can keep it signed in. Pairing by QR works either way.`):e(`certificates.deviceSettingsRow.disabledOnlyAnAdminCan`,`Disabled - only an admin can pair a device, with a QR code.`)}),i!==null&&d(`span`,{className:`block text-[11px] text-danger`,children:i})]})})}e();function dr(e){let[n,i]=r(()=>Date.now());return t(()=>{let t=setInterval(()=>i(Date.now()),e);return()=>clearInterval(t)},[e]),n}e();var fr=80,pr=208;function mr({open:e,users:t,onClose:n,onPaired:i}){let{t:o}=X(),s=K.deviceCredentials.startEnrollment.useMutation({onSuccess:i}),[c,l]=r(``),[u,p]=r(``),m=c===``?t[0]?.id??``:c,h=s.data,g=()=>{s.reset(),p(``),n()};return d(Je,{open:e,onClose:g,title:o(`certificates.pairDeviceDialog.pairADevice`,`Pair a device`),icon:f,width:`md`,testId:`pair-device-dialog`,error:s.isError?s.error.message:null,footer:h===void 0?a(G,{type:`button`,onClick:()=>{let e=u.trim();m===``||e===``||s.mutate({userId:m,deviceName:e})},disabled:s.isPending||m===``||u.trim()===``,children:[s.isPending&&d(M,{className:`h-3.5 w-3.5 animate-spin`,"aria-hidden":!0}),o(`certificates.pairDeviceDialog.createPairingCode`,`Create pairing code`)]}):d(G,{type:`button`,variant:`outline`,onClick:g,children:o(`certificates.pairDeviceDialog.done`,`Done`)}),children:h===void 0?a(`div`,{className:`space-y-3`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:o(`certificates.pairDeviceDialog.createsAOneTimeCode`,`Creates a one-time code for a phone you hold. Scan it with the CamStack app on that phone; the phone then stays signed in as the chosen user until you revoke it.`)}),d(pt,{label:o(`certificates.pairDeviceDialog.user`,`User`),required:!0,children:d($e,{value:m,onChange:e=>l(e.target.value),options:t.map(e=>({value:e.id,label:e.username}))})}),d(pt,{label:o(`certificates.pairDeviceDialog.deviceName`,`Device name`),required:!0,description:o(`certificates.pairDeviceDialog.howThisPhoneIsListed`,`How this phone is listed, e.g. Anna's iPhone.`),children:d(dt,{value:u,maxLength:fr,onChange:e=>p(e.target.value),placeholder:o(`certificates.pairDeviceDialog.annaSIphone`,`Anna's iPhone`),autoFocus:!0})})]}):d(hr,{enrollUrl:h.enrollUrl,expiresAt:h.expiresAt,hubKnown:h.hubOrigin!==null,onRestart:()=>s.reset()})})}function hr({enrollUrl:e,expiresAt:t,hubKnown:n,onRestart:r}){let{t:i}=X(),o=en(t,dr(1e3));return d(`div`,{className:`space-y-3`,"data-testid":`pair-issued`,children:a(`div`,{className:`flex flex-col items-center gap-3 sm:flex-row sm:items-start`,children:[d(`div`,{className:o.expired?`opacity-30`:void 0,children:d(Ge,{value:e,size:pr,alt:i(`certificates.pairDeviceDialog.enrollmentQrCode`,`Enrollment QR code`)})}),a(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[d(`p`,{className:`text-[11px] text-foreground-subtle`,children:i(`certificates.pairDeviceDialog.openTheCamstackAppOn`,`Open the CamStack app on the phone and scan this code. It works once.`)}),d(`div`,{className:`text-sm font-semibold tabular-nums text-foreground`,role:`timer`,"data-testid":`pair-countdown`,children:o.expired?i(`certificates.pairDeviceDialog.expiredCreateANewCode`,`Expired - create a new code`):i(`certificates.pairDeviceDialog.expiresIn`,`Expires in {{label}}`,{label:o.label})}),a(`div`,{className:`flex items-center gap-1 rounded-md border border-border bg-background px-2 py-1`,children:[d(`code`,{className:`min-w-0 flex-1 select-all break-all font-mono text-[11px] text-foreground`,children:e}),d(Oe,{value:e,srLabel:`Enrollment link`})]}),!n&&a(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[d(g,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),d(`span`,{children:i(`certificates.pairDeviceDialog.theHubCouldNotName`,`The hub could not name an address for this link, so the app must already know it.`)})]}),o.expired&&d(G,{type:`button`,variant:`outline`,size:`sm`,onClick:r,children:i(`certificates.pairDeviceDialog.newCode`,`New code`)})]})]})})}e();var gr={key:`access.nouns.device`};function _r({pairOpen:e,onPairClose:t}){let{t:i}=X(),o=U(),s=rt(),c=K.useUtils(),l=K.deviceCredentials.listDeviceCredentials.useQuery({includeRevoked:!0}),u=gt(),[p,g]=r(null),[_,v]=r(null),b=()=>void c.deviceCredentials.listDeviceCredentials.invalidate(),x=e=>t=>{v(null),g(`${e} failed: ${t.message}`)},S=()=>{v(null),b()},C=K.deviceCredentials.revokeDeviceCredential.useMutation({onSuccess:S,onError:x(`Revoke`)}),w=K.deviceCredentials.deleteDeviceCredential.useMutation({onSuccess:e=>{e.result!==`deleted`&&g(e.result===`live`?`Only a revoked device can be deleted: revoke it first.`:`That device no longer exists.`),S()},onError:x(`Delete`)}),T=K.deviceCredentials.renameDeviceCredential.useMutation({onSuccess:S,onError:x(`Rename`)}),E=Yt(gr,e=>C.mutateAsync({id:e}),b),D=E.busy||_!==null,O=n(()=>(l.data??[]).map($t),[l.data]),k=async e=>{await o({title:i(`certificates.devicesCard.revoke`,`Revoke "{{name}}"?`,{name:e.name}),message:i(`certificates.devicesCard.sDeviceStopsSigningIn`,`{{ownerName}}'s device stops signing in at once and its open sessions end. To use it again it has to be paired anew. This cannot be undone.`,{ownerName:e.ownerName}),confirmLabel:i(`certificates.devicesCard.revoke2`,`Revoke`),variant:`danger`})&&(g(null),v(e.id),C.mutate({id:e.id}))},A=async e=>{await o({title:i(`certificates.devicesCard.delete`,`Delete "{{name}}"?`,{name:e.name}),message:i(`certificates.devicesCard.isRemovedFromTheList`,`{{name}} is removed from the list. The audit trail keeps the revocation.`,{name:e.name}),confirmLabel:i(`common.delete`,`Delete`),variant:`danger`})&&(g(null),v(e.id),w.mutate({id:e.id}))},j=async e=>{let t=(await s({title:i(`certificates.devicesCard.renameDevice`,`Rename device`),label:i(`certificates.devicesCard.deviceName`,`Device name`),defaultValue:e.name,confirmLabel:i(`certificates.devicesCard.rename`,`Rename`)}))?.trim()??``;t===``||t===e.name||(g(null),v(e.id),T.mutate({id:e.id,deviceName:t}))},M={label:i(`certificates.devicesCard.revoke2`,`Revoke`),icon:y,isAvailable:Ht,onRun:e=>void k(e),busyId:C.isPending?_:null,disabled:D},N=[{label:i(`certificates.devicesCard.rename`,`Rename`),icon:m,tone:`neutral`,isAvailable:()=>!0,onRun:e=>void j(e),busyId:T.isPending?_:null,disabled:D},{label:i(`common.delete`,`Delete`),icon:h,isAvailable:Jt,onRun:e=>void A(e),busyId:w.isPending?_:null,disabled:D}];return a(Z,{id:`devices`,title:i(`certificates.devicesCard.devices`,`Devices`),icon:f,description:i(`certificates.devicesCard.phonesThatStaySignedIn`,`Phones that stay signed in with a certificate instead of a login. Revoking one signs it out at once; it has to be paired again.`),notice:Rt(p,E.outcome),onDismissNotice:()=>{g(null),E.dismiss()},children:[d(ur,{}),d(Xt,{rows:O,label:i(`certificates.devicesCard.label`),isLoading:l.isPending,loadError:l.error===null?null:l.error.message||`Request failed`,emptyText:`No devices paired yet.`,expiresNone:`—`,action:M,extraActions:N,bulk:{revoke:E,noun:gr,isSelectable:Ht}}),d(mr,{open:e,users:u.data??[],onClose:t,onPaired:b})]})}var vr=/-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/,yr=/-----BEGIN ((?:RSA |EC |ENCRYPTED )?PRIVATE KEY)-----[\s\S]+?-----END \1-----/,br={certificate:`.pem,.crt,.cer`,privateKey:`.pem,.key`,ca:`.pem,.crt,.cer`};function xr(e,t){if(t.trim()===``)return null;if(e===`privateKey`){let e=yr.exec(t);return e===null?vr.test(t)?Y.t(`helpers.pemFile.isCert`):Y.t(`helpers.pemFile.notKey`):e[1]===`ENCRYPTED PRIVATE KEY`?Y.t(`helpers.pemFile.encrypted`):null}return vr.test(t)?e===`certificate`&&yr.test(t)?Y.t(`helpers.pemFile.certHasKey`):null:yr.test(t)?Y.t(`helpers.pemFile.isKey`):Y.t(`helpers.pemFile.notCert`)}function Sr(e){return e.text()}e();function Cr({kind:e,label:t,value:n,onChange:i,rows:o=6}){let{t:s}=X(),c=l(null),[u,f]=r(null),[p,m]=r(null),h=p??xr(e,n),g=`pem-${e}`,_=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t!==void 0){f(t.name);try{let e=await Sr(t);m(null),i(e)}catch(e){m(`Could not read ${t.name}: ${e instanceof Error?e.message:String(e)}`)}}};return a(`div`,{className:`space-y-1`,children:[a(`div`,{className:`flex items-center justify-between gap-2`,children:[d(`label`,{htmlFor:g,className:`text-[11px] text-foreground-subtle`,children:t}),a(`div`,{className:`flex min-w-0 items-center gap-2`,children:[u!==null&&d(`span`,{className:`truncate font-mono text-[10px] text-foreground-subtle`,"data-testid":`${g}-file-name`,children:u}),d(`input`,{ref:c,type:`file`,accept:br[e],onChange:e=>void _(e),className:`hidden`,"data-testid":`${g}-file`}),a(G,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>c.current?.click(),children:[d(oe,{className:`mr-1 h-3 w-3`}),s(`system.pemField.chooseFile`,`Choose file`)]})]})]}),d(`textarea`,{id:g,value:n,onChange:e=>{f(null),m(null),i(e.target.value)},rows:o,"aria-invalid":h!==null,className:`w-full rounded border border-border bg-surface px-2 py-1 font-mono text-[11px]`}),h!==null&&d(`p`,{className:`text-[11px] text-danger`,role:`alert`,children:h})]})}e();var wr=30;function Tr(e){let t=Date.parse(e);return!Number.isNaN(t)&&Date.now()-t<wr*864e5}function Er(e){if(e===null||e===``)return`—`;let t=e.replace(/:/g,``);return t.length<=16?e:`${t.slice(0,8)}…${t.slice(-8)}`}function Dr(){let{t:e}=X(),t=c(),n=Pe(void 0,{refetchInterval:15e3}),i=ye({onSuccess:()=>void t.invalidateQueries({queryKey:[[`localNetwork`]]})}),o=He({onSuccess:()=>void t.invalidateQueries({queryKey:[[`localNetwork`]]})}),s=Ce({onSuccess:()=>void t.invalidateQueries({queryKey:[[`localNetwork`]]})}),l=Ze({onSuccess:()=>{m(!1),g(``),v(``),b(``),t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),u=n.data,[f,m]=r(!1),[h,g]=r(``),[_,v]=r(``),[y,b]=r(``),S=()=>{if(!u?.caCertPem)return;let e=new Blob([u.caCertPem],{type:`application/x-pem-file`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`camstack-ca.crt`,n.click(),URL.revokeObjectURL(t)},C=u?.mode===`uploaded`?`Uploaded`:u?.mode===`generated`?`Generated local CA`:`TLS disabled`;return d(qe,{headingId:`local-access-certificate`,title:e(`system.localAccess.certificate`,`Certificate`),icon:x,children:a(`div`,{className:`${p} space-y-3`,children:[n.isError&&d(`p`,{className:`text-xs text-danger`,children:e(`system.localAccess.couldNotReadTlsStatus`,`Could not read TLS status.`)}),u?.reissueError&&d(_t,{variant:`warning`,title:e(`system.localAccess.certificateReissue`,`Certificate reissue`),message:u.reissueError}),u?.restartRequired&&d(_t,{variant:`warning`,title:e(`system.localAccess.restartRequired`,`Restart required`),message:e(`system.localAccess.theHttpsListenerStillServes`,`The HTTPS listener still serves the previous certificate. Restart the hub to apply it.`)}),u?.caMissing===!0&&d(_t,{variant:`warning`,title:e(`system.localAccess.caMissingTitle`,`CA missing - devices cannot trust this hub`),message:e(`system.localAccess.caMissingBody`,"The uploaded certificate was not issued by a public CA and no CA was stored with it, so Download CA has nothing to hand out. Upload the certificate again together with its CA (for mkcert, the rootCA.pem in the folder `mkcert -CAROOT` prints).")}),u?.caReplacedAt!=null&&Tr(u.caReplacedAt)&&d(_t,{variant:`warning`,title:e(`system.localAccess.caReplacedTitle`,`The local CA was replaced - re-install it on your devices`),message:e(`system.localAccess.caReplacedBody`,`The previous local CA had no name constraints: if its key ever leaked it could vouch for any website. The hub now uses a CA limited to private addresses and local names. Download it again and trust it on every phone and computer that used the old one (replaced {{when}}).`,{when:new Date(u.caReplacedAt).toLocaleString()})}),a(`dl`,{className:`grid grid-cols-1 gap-2 text-xs sm:grid-cols-2`,children:[a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.mode`,`Mode`)}),d(`dd`,{className:`font-medium`,children:C})]}),a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.validTo`,`Valid to`)}),d(`dd`,{className:`font-mono`,children:u?.validTo?new Date(u.validTo).toLocaleString():`—`})]}),a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.leafSha256`,`Leaf SHA-256`)}),d(`dd`,{className:`font-mono`,title:u?.leafFingerprintSha256??void 0,children:Er(u?.leafFingerprintSha256??null)})]}),u?.storedUpload!=null&&a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.storedUpload`,`Stored upload`)}),d(`dd`,{className:`font-medium`,children:e(`system.localAccess.storedUploadValue`,`valid to {{validTo}}, {{ca}}`,{validTo:new Date(u.storedUpload.validTo).toLocaleDateString(),ca:u.storedUpload.hasCa?e(`system.localAccess.storedUploadWithCa`,`with its CA`):e(`system.localAccess.storedUploadNoCa`,`no CA`)})})]}),a(`div`,{children:[d(`dt`,{className:`text-foreground-subtle`,children:e(`system.localAccess.caSha256`,`CA SHA-256`)}),d(`dd`,{className:`font-mono`,title:u?.caFingerprintSha256??void 0,children:u?.mode===`uploaded`&&u.caFingerprintSha256===null?d(`span`,{className:`font-sans text-foreground-subtle`,children:e(`system.localAccess.issuerNotIncludedInThe`,`Issuer not included in the upload (not the local CA)`)}):Er(u?.caFingerprintSha256??null)})]})]}),u&&u.sans.length>0&&d(`div`,{className:`flex flex-wrap gap-1`,children:u.sans.map(e=>d(`span`,{className:`rounded border border-border bg-surface px-1.5 py-0.5 font-mono text-[10px] text-foreground-subtle`,children:e},e))}),a(`div`,{className:`flex flex-wrap gap-2`,children:[d(Ue,{label:e(`system.localAccess.regenerate`,`Regenerate`),title:e(`system.localAccess.issueANewLeaf`,`Issue a new leaf?`),description:e(`system.localAccess.issuesANewLeafUnder`,`Issues a new leaf under the current local CA. Clients that trust the CA keep working. The HTTPS listener reloads.`),confirmLabel:e(`system.localAccess.regenerate`,`Regenerate`),disabled:u?.mode===`uploaded`||i.isPending,action:()=>i.mutateAsync({})}),d(G,{size:`sm`,variant:`outline`,onClick:()=>m(e=>!e),children:e(`system.localAccess.upload`,`Upload`)}),u?.caCertPem&&d(G,{size:`sm`,variant:`outline`,onClick:S,children:e(`system.localAccess.downloadCa`,`Download CA`)}),u?.mode===`uploaded`&&d(Ue,{label:e(`system.localAccess.revertToGenerated`,`Revert to generated`),title:e(`system.localAccess.revertTitle`,`Switch back to the generated certificate?`),description:e(`system.localAccess.keepsTheUploadedPair`,`Returns to the generated local CA. The uploaded certificate and its CA stay stored here; you can select them again.`),confirmLabel:e(`system.localAccess.revert`,`Revert`),disabled:o.isPending,action:()=>o.mutateAsync({})}),u?.mode===`generated`&&u.storedUpload!=null&&d(Ue,{label:e(`system.localAccess.useUploaded`,`Use uploaded certificate`),title:e(`system.localAccess.useUploadedTitle`,`Serve the stored upload again?`),description:e(`system.localAccess.useUploadedDescription`,`The stored uploaded certificate replaces the generated one on the HTTPS listener. The generated certificate stays stored.`),confirmLabel:e(`system.localAccess.useUploaded`,`Use uploaded certificate`),disabled:s.isPending,action:()=>s.mutateAsync(void 0)})]}),f&&a(`div`,{className:`space-y-2 border-t border-border pt-3`,children:[d(Cr,{kind:`certificate`,label:e(`system.localAccess.certificateOrFullChainPem`,`Certificate or full chain (PEM)`),value:h,onChange:g}),d(Cr,{kind:`privateKey`,label:e(`system.localAccess.privateKeyPem`,`Private key (PEM)`),value:_,onChange:v}),d(Cr,{kind:`ca`,label:e(`system.localAccess.caPemRequired`,`CA (PEM) - required unless the certificate comes from a public CA`),value:y,onChange:b,rows:4}),d(G,{size:`sm`,disabled:!h.trim()||!_.trim()||xr(`certificate`,h)!==null||xr(`privateKey`,_)!==null||xr(`ca`,y)!==null||l.isPending,onClick:()=>l.mutate({certPem:h,keyPem:_,...y.trim()?{caPem:y}:{}}),children:e(`system.localAccess.saveCertificate`,`Save certificate`)}),l.isError&&d(`p`,{className:`text-xs text-danger`,children:l.error instanceof Error?l.error.message:e(`system.localAccess.uploadFailed`,`Upload failed`)})]})]})})}var Or={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`};function kr(e){let t=e.find(e=>e.isHub);return t?.https.kind===`served`?t.https.status.caFingerprintSha256:null}function Ar({https:e,mesh:t,now:n}){let{t:r}=X(),i=Pe().data?.caCertPem??``,o=()=>{if(i===``)return;let e=URL.createObjectURL(new Blob([i],{type:`application/x-pem-file`})),t=document.createElement(`a`);t.href=e,t.download=`camstack-ca.crt`,t.click(),URL.revokeObjectURL(e)},s=t?.ca,c=s?.state===`ready`?Date.parse(s.validTo):null,l=t?.listener;return a(`div`,{className:`space-y-1`,"data-testid":`ca-strip`,children:[d(q,{label:r(`certificates.caStrip.localHttpsCaSha256`,`Local HTTPS CA (SHA-256)`),valueClassName:`font-mono`,children:a(`span`,{className:`flex flex-wrap items-center gap-2`,children:[kr(e)??`—`,i!==``&&a(G,{type:`button`,variant:`ghost`,size:`sm`,onClick:o,children:[d(b,{className:`h-3 w-3`,"aria-hidden":!0}),r(`certificates.caStrip.downloadCa`,`Download CA`)]})]})}),d(q,{label:r(`certificates.caStrip.clusterCaSha256`,`Cluster CA (SHA-256)`),valueClassName:`font-mono`,children:s===void 0?`—`:s.state===`ready`?s.fingerprintSha256:d(`span`,{className:`text-danger`,children:r(`certificates.caStrip.unavailable`,{reason:s.reason})})}),s?.state===`ready`&&a(q,{label:r(`certificates.caStrip.clusterCaValidUntil`,`Cluster CA valid until`),children:[s.validTo,c!==null&&!Number.isNaN(c)&&a(`span`,{className:`ml-2 text-[10px] ${Or[an(c,n)]}`,children:[`(`,Wt(c,n),`)`]})]}),l!==void 0&&a(q,{label:r(`certificates.caStrip.nodeListener`,`Node listener`),children:[l.state===`open`&&d(J,{variant:`success`,children:r(`certificates.caStrip.open`,`Open`)}),l.state===`not-started`&&d(J,{variant:`default`,children:r(`certificates.caStrip.notStarted`,`Not started`)}),l.state===`closed`&&a(`span`,{className:`text-danger`,children:[r(`certificates.caStrip.closedSince`,{when:Gt(l.since)}),` `,l.reason]})]}),t!==void 0&&!t.registryAvailable&&a(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-2.5 py-1.5 text-[11px] text-foreground`,children:[d(g,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),d(`span`,{children:r(`certificates.caStrip.theCertificateRegistryIsNot`,`The certificate registry is not up, so the node list below is incomplete.`)})]})]})}function jr(e,t){let n=new Set;for(let t of e)n.add(t.nodeId);for(let e of t?.nodes??[])n.add(e.nodeId);return[...n].map(n=>{let r=e.find(e=>e.nodeId===n)??null,i=t?.nodes.find(e=>e.nodeId===n)??null;return{nodeId:n,isHub:r?.isHub??n===`hub`,online:r?.online??i?.online??!1,https:r,mesh:i}}).toSorted((e,t)=>Number(t.isHub)-Number(e.isHub)||e.nodeId.localeCompare(t.nodeId))}function Mr(e){return e.isHub?Y.t(`helpers.nodesModel.hubReissued`):e.mesh===null?Y.t(`helpers.nodesModel.noCertRecorded`):e.online?null:Y.t(`helpers.certificateModel.nodeOffline`)}function Nr(e){return e.isHub||e.mesh===null?Mr(e):null}var Pr={ok:`text-foreground-subtle`,soon:`text-warning`,expired:`text-danger`,unknown:`text-foreground-subtle`},Fr={enroll:`Issued at enrollment`,renewal:`Issued by a renewal`,boot:`Issued at boot`,pairing:`Issued at pairing`,observed:`Observed on its connection`},Ir={uploaded:`Uploaded`,generated:`Generated`,disabled:`Disabled`};function Lr(e){let t=e.https?.https;return t?.kind===`served`?nn(t.status.validTo):null}function Rr({ms:e,now:t}){return e===null?d(`span`,{className:`text-foreground-subtle`,children:`—`}):a(`div`,{children:[d(`div`,{children:Gt(e)}),d(`div`,{className:`text-[10px] ${Pr[an(e,t)]}`,children:Wt(e,t)})]})}function zr({row:e}){let{t}=X(),n=e.https?.https;return n===void 0?d(`span`,{className:`text-foreground-subtle`,children:`—`}):n.kind===`served`?a(`div`,{title:n.status.leafFingerprintSha256??``,children:[d(J,{variant:`success`,className:`text-[10px]`,children:t(`certificates.nodesColumns.served`,`Served`)}),d(`span`,{className:`ml-1.5 text-[10px] text-foreground-subtle`,children:Ir[n.status.mode]}),d(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:tn(n.status.leafFingerprintSha256)}),n.status.sans.length>0&&d(`div`,{className:`mt-0.5 max-w-[14rem] truncate font-mono text-[10px] text-foreground-subtle`,title:n.status.sans.join(`, `),children:n.status.sans.join(`, `)})]}):a(`div`,{className:`max-w-[16rem]`,children:[d(J,{variant:n.kind===`unreadable`?`danger`:`warning`,className:`text-[10px]`,children:n.kind===`unreadable`?t(`certificates.nodesColumns.unreadable`,`Unreadable`):t(`certificates.nodesColumns.notServed`,`Not served`)}),d(`div`,{className:`mt-1 whitespace-normal text-[10px] text-foreground-subtle`,children:n.reason})]})}function Br({row:e}){let{t}=X(),n=e.mesh?.current??null;if(n===null)return d(`span`,{className:`text-foreground-subtle`,children:t(`certificates.nodesColumns.noneRecorded`,`None recorded`)});let r=e.mesh?.history.length??0;return a(`div`,{children:[d(`div`,{className:`font-mono text-[11px]`,title:n.serial,children:Qt(n.serial)}),d(`div`,{className:`font-mono text-[10px] text-foreground-subtle`,title:n.fingerprintSha256,children:tn(n.fingerprintSha256)}),a(`div`,{className:`text-[10px] text-foreground-subtle`,children:[Fr[n.issuedVia],r>0?` · ${t(`certificates.nodesColumns.earlier`,{count:r})}`:``]})]})}function Vr({row:e}){let{t}=X(),n=e.mesh?.presentingCurrent??null;return n===null?d(`span`,{className:`text-foreground-subtle`,children:e.online?`—`:t(`certificates.nodesColumns.offline`,`Offline`)}):n?d(J,{variant:`success`,className:`text-[10px]`,children:t(`common.yes`,`Yes`)}):d(J,{variant:`warning`,className:`text-[10px]`,children:t(`certificates.nodesColumns.noPresentsAnother`,`No - presents another`)})}function Hr(e){let t=e.icon;return a(G,{type:`button`,variant:`ghost`,size:`sm`,className:e.danger?`text-danger hover:bg-danger/10`:void 0,disabled:e.reason!==null||e.busy,title:e.reason??void 0,"aria-label":e.ariaLabel,onClick:e.onClick,children:[e.spinning?d(M,{className:`h-3 w-3 animate-spin`,"aria-hidden":!0}):d(t,{className:`h-3 w-3`,"aria-hidden":!0}),e.label]})}function Ur({reasons:e}){let{t}=X();return a(he,{className:`inline-block`,children:[d(mt,{children:d(`span`,{className:`cursor-help text-[11px] text-foreground-subtle`,"data-testid":`hub-managed-note`,children:t(`certificates.nodesColumns.managedByTheHub`,`Managed by the hub`)})}),d(it,{children:d(`ul`,{className:`max-w-xs space-y-1 whitespace-normal text-left text-[11px]`,children:e.map(e=>d(`li`,{children:e},e))})})]})}function Wr({row:e,o:t}){let{t:n}=X(),r=e.https===null?`No HTTPS inventory for this node.`:Kt(e.https).reason,i=Mr(e),o=Nr(e),s=n=>t.running?.nodeId===e.nodeId&&t.running.action===n,c=t=>!e.isHub||t===null,l=[r,i,o].filter((e,t,n)=>e!==null&&n.indexOf(e)===t);return a(`div`,{className:`flex w-44 flex-col items-end gap-1`,children:[a(`div`,{className:`flex flex-col items-end gap-0.5`,children:[c(r)&&d(Hr,{label:n(`certificates.nodesColumns.renewHttps`,`Renew HTTPS`),ariaLabel:n(`certificates.nodesColumns.renewTheCertificateOn`,`Renew the certificate on {{nodeId}}`,{nodeId:e.nodeId}),icon:S,reason:r,busy:t.busy,spinning:s(`renew-https`),danger:!1,onClick:()=>t.onRenewHttps(e)}),c(i)&&d(Hr,{label:s(`renew-identity`)?n(`certificates.nodesColumns.renewing`,`Renewing…`):n(`certificates.nodesColumns.renewIdentity`,`Renew identity`),ariaLabel:n(`certificates.nodesColumns.renewTheClusterCertificateOf`,`Renew the cluster certificate of {{nodeId}}`,{nodeId:e.nodeId}),icon:S,reason:i,busy:t.busy,spinning:s(`renew-identity`),danger:!1,onClick:()=>t.onRenewIdentity(e)}),c(o)&&d(Hr,{label:n(`certificates.nodesColumns.revokeIdentity`,`Revoke identity`),ariaLabel:n(`certificates.nodesColumns.revokeTheClusterCertificateOf`,`Revoke the cluster certificate of {{nodeId}}`,{nodeId:e.nodeId}),icon:y,reason:o,busy:t.busy,spinning:s(`revoke-identity`),danger:!0,onClick:()=>t.onRevokeIdentity(e)})]}),e.isHub&&l.length>0&&d(Ur,{reasons:l}),!e.isHub&&r!==null&&e.https!==null&&d(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`renew-reason-${e.nodeId}`,children:r}),!e.isHub&&i!==null&&d(`div`,{className:`w-full whitespace-normal text-right text-[10px] text-foreground-subtle`,"data-testid":`mesh-reason-${e.nodeId}`,children:i})]})}function Gr(e){return[{key:`node`,header:Y.t(`certificates.nodesColumns.node`,`Node`),sortValue:e=>e.isHub?``:e.nodeId.toLowerCase(),render:e=>a(`div`,{className:`flex items-center gap-1.5`,children:[d(`span`,{className:`font-medium text-foreground`,children:e.nodeId}),e.nodeId===`hub`&&d(J,{variant:`info`,className:`text-[10px]`,children:Y.t(`common.hubWord`)}),!e.online&&d(J,{variant:`default`,className:`text-[10px]`,children:Y.t(`common.offline`)})]})},{key:`https-state`,header:`HTTPS`,notSortableReason:`A state with a reason has no single order.`,render:e=>d(zr,{row:e})},{key:`https-expires`,header:Y.t(`certificates.nodesColumns.httpsExpires`,`HTTPS expires`),sortValue:e=>Lr(e),render:t=>d(Rr,{ms:Lr(t),now:e.now})},{key:`identity`,header:Y.t(`certificates.nodesColumns.identity`,`Identity`),sortValue:e=>e.mesh?.current?.serial??null,render:e=>d(Br,{row:e})},{key:`identity-expires`,header:Y.t(`certificates.nodesColumns.identityExpires`,`Identity expires`),sortValue:e=>e.mesh?.current?.notAfter??null,render:t=>d(Rr,{ms:t.mesh?.current?.notAfter??null,now:e.now})},{key:`presenting`,header:Y.t(`certificates.nodesColumns.inUse`,`In use`),notSortableReason:`Offline nodes have no answer to order by.`,render:e=>d(Vr,{row:e})},{key:`actions`,header:Y.t(`certificates.nodesColumns.actions`,`Actions`),align:`right`,notSortableReason:`Actions have no order.`,render:t=>d(Wr,{row:t,o:e})}]}e();function Kr(){let{t:e}=X(),t=U(),i=K.useUtils(),o=dr(6e4),s=K.certificates.listHttpsCertificates.useQuery(),c=K.certificates.getMeshCertificates.useQuery(),[l,u]=r(null),[f,p]=r(null),[m,h]=r(null),g=()=>{h(null),i.certificates.listHttpsCertificates.invalidate(),i.certificates.getMeshCertificates.invalidate()},_=e=>(t,n)=>{h(null),u(`${n.nodeId}: ${e} - ${t.message}`)},v=K.certificates.renewHttpsOnNode.useMutation({onSuccess:(t,n)=>{p({tone:`success`,message:t.restartRequired?e(`certificates.nodesCard.newCertificateIssuedRestartThe`,`{{nodeId}}: new certificate issued. Restart the node to serve it.`,{nodeId:n.nodeId}):e(`certificates.nodesCard.newCertificateIssuedAndServed`,`{{nodeId}}: new certificate issued and served.`,{nodeId:n.nodeId})}),g()},onError:_(`renewal failed`)}),y=K.certificates.renewMeshOnNode.useMutation({onSuccess:e=>{p(Zt(e)),g()},onError:_(`renewal could not start`)}),b=K.certificates.revokeMeshOnNode.useMutation({onSuccess:e=>{p({tone:`success`,message:`${e.nodeId}: ${e.next}`}),g()},onError:_(`revoke failed`)}),x=v.isPending||y.isPending||b.isPending,S=(e,t)=>{u(null),p(null),h({nodeId:e,action:t})},C=async n=>{await t({title:e(`certificates.nodesCard.renewHttpsOn`,`Renew HTTPS on "{{nodeId}}"?`,{nodeId:n.nodeId}),message:n.isHub?e(`certificates.nodesCard.aNewCertificateIsIssued`,`A new certificate is issued from the local CA. Clients that trust the CA keep working.`):e(`certificates.nodesCard.theNodeMakesANew`,`The node makes a new key, the hub signs it and the node switches over without a restart. It keeps serving what it had if anything fails.`),confirmLabel:e(`certificates.nodesCard.renew`,`Renew`)})&&(S(n.nodeId,`renew-https`),v.mutate({nodeId:n.nodeId}))},T=e=>{S(e.nodeId,`renew-identity`),y.mutate({nodeId:e.nodeId})},E=async n=>{await t({title:e(`certificates.nodesCard.revokeTheIdentityOf`,`Revoke the identity of "{{nodeId}}"?`,{nodeId:n.nodeId}),message:e(`certificates.nodesCard.isDisconnectedAtOnceAnd`,`{{nodeId}} is disconnected at once and can no longer connect. To bring it back it must be paired again from System → Cluster → Agents. It stays in the node list until you forget it on the Cluster page. This cannot be undone.`,{nodeId:n.nodeId}),confirmLabel:e(`certificates.nodesCard.revokeAndDisconnect`,`Revoke and disconnect`),variant:`danger`})&&(S(n.nodeId,`revoke-identity`),b.mutate({nodeId:n.nodeId}))},D=Gr({now:o,busy:x,running:m,onRenewHttps:e=>void C(e),onRenewIdentity:T,onRevokeIdentity:e=>void E(e)}),O=n(()=>jr(s.data??[],c.data),[s.data,c.data]),k=c.data?.registryAvailable??!0;return d(Z,{id:`nodes`,title:e(`certificates.nodesCard.nodes`,`Nodes`),icon:w,description:e(`certificates.nodesCard.eachNodeHoldsTwoCertificates`,`Each node holds two certificates: one it serves over HTTPS, one that proves its identity to the hub. Renewing replaces a certificate without a gap; revoking an identity cuts the node off until it re-joins.`),notice:Rt(l,f),onDismissNotice:()=>{u(null),p(null)},children:d(cr,{isPending:s.isPending||c.isPending,error:s.error??c.error,what:`node certificates`,onRetry:()=>{s.refetch(),c.refetch()},children:a(`div`,{className:`space-y-3`,children:[d(Ar,{https:s.data??[],mesh:c.data,now:o}),d(xe,{columns:D,rows:O,rowKey:e=>e.nodeId,minWidthPx:960,maxBodyHeight:Ee,defaultSort:{columnKey:`node`,dir:`asc`},emptyMessage:k?e(`certificates.nodesCard.noNodesReported`,`No nodes reported.`):e(`certificates.nodesCard.theCertificateRegistryIsNot`,`The certificate registry is not available yet, so nodes cannot be listed.`)})]})})})}function qr({pairOpen:e,onPairClose:t}){return a(`div`,{className:`space-y-4`,"data-testid":`certificates-page`,children:[d(_r,{pairOpen:e,onPairClose:t}),d(lr,{}),d(Dr,{}),d(Kr,{})]})}function Jr({userId:e,username:t,onClose:n}){let{t:r}=X(),i=U(),o=K.useUtils(),s=De({userId:e}),c=K.auth.listLoginMethods.useQuery(),l=be({onSuccess:()=>void o.userManagement.listExternalIdentities.invalidate()}),u=new Map((c.data??[]).flatMap(e=>e.kind===`redirect`?[[e.id,e.label]]:[])),f=s.data??[],p=async(n,a)=>{await i({title:r(`users.externalIdentitiesModal.removeSignInLink`,`Remove sign-in link`),message:r(`users.externalIdentitiesModal.willNoLongerBeAble`,`"{{username}}" will no longer be able to sign in with this {{label}} account.`,{username:t,label:a}),confirmLabel:r(`common.remove`,`Remove`),variant:`danger`})&&l.mutate({userId:e,provider:n.provider,subject:n.subject})};return d(W,{open:!0,onOpenChange:e=>!e&&n(),children:a(ct,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`external-identities-modal`,children:[d(Ae,{children:a(Ne,{className:`flex items-center gap-2`,children:[d(O,{className:`h-4 w-4 text-primary`}),a(`span`,{children:[r(`users.externalIdentitiesModal.linkedSignInAccounts`,`Linked sign-in accounts`),a(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[r(`users.externalIdentitiesModal.user`,`User:`),` `,d(`span`,{className:`font-mono`,children:t})]})]})]})}),d(Fe,{className:`space-y-3`,children:s.isLoading?a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(M,{className:`h-3.5 w-3.5 animate-spin`}),r(`common.loading`,`Loading…`)]}):f.length===0?d(`p`,{className:`text-xs text-foreground-subtle`,children:r(`users.externalIdentitiesModal.noLinkedAccountsOnlyThe`,`No linked accounts. Only the user can link one, from their own profile page.`)}):d(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:f.map(e=>{let t=u.get(e.provider),n=t??e.provider;return a(`li`,{className:`flex items-center gap-3 px-3 py-2 text-xs`,children:[a(`div`,{className:`flex-1 min-w-0`,children:[a(`div`,{className:`font-medium text-foreground truncate`,children:[n,t===void 0&&d(`span`,{className:`ml-2 rounded bg-foreground-subtle/15 px-1.5 py-0.5 text-[10px] font-normal text-foreground-subtle`,children:r(`users.externalIdentitiesModal.providerUnavailable`,`provider unavailable`)})]}),a(`div`,{className:`text-[11px] text-foreground-subtle truncate`,children:[e.label??e.subject,` ·`,` `,new Date(e.linkedAt).toLocaleDateString()]})]}),a(`button`,{onClick:()=>void p(e,n),disabled:l.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[d(pe,{className:`h-3 w-3`}),r(`common.remove`,`Remove`)]})]},`${e.provider}|${e.subject}`)})})}),d(st,{children:d(G,{onClick:n,variant:`secondary`,children:r(`common.close`,`Close`)})})]})})}function Yr({userId:e,username:t,onClose:n}){let{t:r}=X(),i=c(),o=U(),l=ve({userId:e}),u=l.data,p=()=>i.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),m=Re({onSuccess:()=>{p(),n()}}),h=l.isLoading?`loading`:u?.enabled?`enrolled`:`not_enrolled`;return d(W,{open:!0,onOpenChange:e=>!e&&n(),children:a(ct,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[d(Ae,{children:a(Ne,{className:`flex items-center gap-2`,children:[d(f,{className:`h-4 w-4 text-primary`}),a(`span`,{children:[r(`users.totpModal.twoFactorAuthentication`,`Two-factor authentication`),a(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[r(`users.totpModal.user`,`User:`),` `,d(`span`,{className:`font-mono`,children:t})]})]})]})}),a(Fe,{className:`space-y-4`,children:[h===`loading`&&a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(M,{className:`h-3.5 w-3.5 animate-spin`}),r(`users.totpModal.checkingStatus`,`Checking status…`)]}),h===`not_enrolled`&&a(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[d(A,{className:`h-4 w-4 mt-0.5 shrink-0`}),a(`div`,{children:[d(`div`,{className:`font-medium text-foreground`,children:r(`users.totpModal.2faNotEnrolled`,`2FA not enrolled`)}),d(`p`,{className:`mt-0.5`,children:r(`users.totpModal.onlyTheUserThemselvesCan`,`Only the user themselves can enable 2FA, from their own profile page.`)})]})]}),h===`enrolled`&&u&&a(s,{children:[a(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[d(k,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),a(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[d(`div`,{className:`font-medium`,children:r(`users.totpModal.2faIsActive`,`2FA is active`)}),d(`div`,{className:`text-foreground-subtle`,children:r(`common.enrolledOn`,{when:u.confirmedAt?new Date(u.confirmedAt).toLocaleString():`—`})})]})]}),d(`div`,{className:`text-[11px] text-foreground-subtle`,children:r(`users.totpModal.removingHereClearsTheServer`,`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`)}),a(`div`,{className:`flex justify-end gap-2`,children:[d(G,{onClick:n,variant:`secondary`,children:r(`common.close`,`Close`)}),a(`button`,{onClick:async()=>{await o({title:r(`users.totpModal.remove2fa`,`Remove 2FA`),message:r(`users.totpModal.removeTwoFactorAuthenticationFor`,`Remove two-factor authentication for "{{username}}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,{username:t}),confirmLabel:r(`common.remove`,`Remove`),variant:`danger`})&&m.mutate({userId:e})},disabled:m.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[m.isPending?d(M,{className:`h-3 w-3 animate-spin`}):d(T,{className:`h-3 w-3`}),r(`users.totpModal.remove2fa`,`Remove 2FA`)]})]})]})]})]})})}e();function Xr({userId:e,username:t,onClose:n}){let{t:i}=X(),{user:o,logout:s}=xt(),c=o?.id===e,l=U(),u=K.useUtils(),f=K.auth.listSessions.useQuery({userId:e}),[p,m]=r(null),h=K.auth.revokeSessions.useMutation({onSuccess:(e,t)=>{if(c&&`userId`in t){s();return}u.auth.listSessions.invalidate()},onError:e=>m(`Sign out failed: ${e.message}`)}),g=async e=>{await l({title:i(`users.userSessionsModal.signOutThisSession`,`Sign out this session`),message:i(`users.userSessionsModal.onWillHaveToSign`,`"{{username}}" on {{label}} will have to sign in again.`,{username:t,label:on(e.client).label}),confirmLabel:i(`users.userSessionsModal.signOut`,`Sign out`),variant:`danger`})&&(m(null),h.mutate({id:e.id}))},_=async()=>{await l({title:i(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),message:c?i(`users.userSessionsModal.everySessionOfYourOwn`,`Every session of your own account ends, this browser included: you will be signed out here too.`):i(`users.userSessionsModal.everySessionOfEndsAt`,`Every session of "{{username}}" ends at once; each device has to sign in again.`,{username:t}),confirmLabel:i(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`),variant:`danger`})&&(m(null),h.mutate({userId:e}))},v=h.isPending&&h.variables!==void 0&&`id`in h.variables?h.variables.id:null;return d(W,{open:!0,onOpenChange:e=>!e&&n(),children:a(ct,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,"data-testid":`user-sessions-modal`,children:[d(Ae,{children:a(Ne,{className:`flex items-center gap-2`,children:[d(fe,{className:`h-4 w-4 text-primary`}),a(`span`,{children:[i(`users.userSessionsModal.activeSessions`,`Active sessions`),a(`span`,{className:`mt-0.5 block text-[11px] font-normal text-foreground-subtle`,children:[i(`users.userSessionsModal.user`,`User:`),` `,d(`span`,{className:`font-mono`,children:t})]})]})]})}),a(Fe,{className:`space-y-3`,children:[p!==null&&d(`div`,{className:`text-[11px] text-danger`,children:p}),d(rn,{sessions:f.data??[],isLoading:f.isLoading,loadError:f.isError?f.error?.message??`Request failed`:null,emptyText:`No active sessions.`,onRevoke:e=>void g(e),revokingId:v})]}),a(st,{className:`justify-between`,children:[a(`button`,{onClick:()=>void _(),disabled:h.isPending||(f.data??[]).length===0,className:`inline-flex items-center gap-1.5 rounded border border-danger/40 px-2.5 py-1 text-[11px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,children:[h.isPending&&v===null?d(M,{className:`h-3 w-3 animate-spin`}):d(le,{className:`h-3 w-3`}),i(`users.userSessionsModal.signOutEverywhere`,`Sign out everywhere`)]}),d(G,{onClick:n,variant:`secondary`,children:i(`common.close`,`Close`)})]})]})})}function Zr({icon:e,label:t,count:n,all:r,total:i}){let{t:o}=X();return a(`div`,{className:`flex items-center gap-2 text-[11px]`,children:[d(e,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),d(`span`,{className:`min-w-0 flex-1 text-foreground-subtle`,children:t}),d(`span`,{className:n===0?`text-foreground-subtle`:`font-medium text-foreground`,children:n===0?o(`common.none`):r?o(`users.scopePreview.all`,`all {{total}}`,{total:i}):o(`users.scopePreview.of`,`{{count}} of {{total}}`,{count:n,total:i})})]})}function Qr({scopes:e,isAdmin:t,invalidReason:n}){let{t:r}=X(),i=N(),c=o({queryKey:[`auth`,`previewScope`,e,t],enabled:n===null,queryFn:()=>i.trpcClient.auth.previewScope.query({scopes:[...e],isAdmin:t})}),{data:l}=et({projection:`slim`}),u=l?.length??0;if(n!==null)return d(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:a(`p`,{className:`flex items-center gap-1.5 text-[11px] text-warning`,children:[d(C,{className:`h-3 w-3 shrink-0`}),n]})});if(c.isLoading)return a(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface p-3 text-[11px] text-foreground-subtle`,children:[d(M,{className:`h-3 w-3 animate-spin`}),r(`users.scopePreview.resolving`,`Resolving…`)]});if(c.isError||!c.data)return d(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:d(`p`,{className:`text-[11px] text-danger`,children:r(`users.scopePreview.couldNotResolveThisGrant`,`Could not resolve this grant set. Saving is still allowed — the server enforces the same rules either way.`)})});let f=c.data;return d(`div`,{className:`space-y-2 rounded-lg border border-border bg-surface p-3`,children:f.isAdmin?a(`p`,{className:`text-[11px] text-foreground`,children:[d(`span`,{className:`font-medium`,children:r(`users.scopePreview.administrator`,`Administrator`)}),` `,r(`users.scopePreview.unrestricted`)]}):a(s,{children:[d(Zr,{icon:_,label:r(`users.scopePreview.devicesTheyCanSee`,`Devices they can see`),count:f.device.view.deviceCount,all:f.device.view.all,total:u}),d(Zr,{icon:m,label:r(`users.scopePreview.devicesTheyCanOperate`,`Devices they can operate`),count:f.device.create.deviceCount,all:f.device.create.all,total:u}),d(Zr,{icon:h,label:r(`users.scopePreview.devicesTheyCanDelete`,`Devices they can delete`),count:f.device.delete.deviceCount,all:f.device.delete.all,total:u}),a(`div`,{className:`border-t border-border pt-2 text-[10px] text-foreground-subtle`,children:[r(`users.scopePreview.systemAccess`,`System access:`),` `,f.system.length===0?r(`common.none`):f.system.join(`, `),f.capabilities.length>0&&a(s,{children:[` `,r(`users.scopePreview.extraCapabilities`,`· Extra capabilities:`),` `,f.capabilities.map(e=>e.name).join(`, `)]}),f.addons.length>0&&a(s,{children:[` `,r(`users.scopePreview.addons`,`· Addons:`),` `,f.addons.map(e=>e.name).join(`, `)]})]}),f.device.view.deviceCount===0&&d(`p`,{className:`text-[10px] text-warning`,children:r(`users.scopePreview.thisUserWillNotBe`,`This user will not be able to see any device.`)})]})})}e();function $r(e){let t=ne(e);return t===null?{mode:e.length===0?`role`:`advanced`,roleId:null,selector:{kind:`all`},includeLinked:!0,advancedScopes:e}:{mode:`role`,roleId:t.roleId,selector:t.selector,includeLinked:t.includeLinked,advancedScopes:e}}function ei(e){return e.mode===`advanced`?e.advancedScopes:e.roleId===null?[]:te({roleId:e.roleId,selector:e.selector,includeLinked:e.includeLinked})}function ti({user:e,onClose:t,onSubmit:i,submitting:o,callerScopes:c}){let{t:l}=X(),u=j(),f=n(()=>$r(e.scopes??[]),[e.scopes]),[p,m]=r(f),[h,g]=r(f.mode===`advanced`),_=n(()=>ei(p),[p]),v=!e.isAdmin&&p.mode===`role`&&p.roleId===null,y=n(()=>e.isAdmin?null:p.mode===`role`&&p.roleId===null?l(`users.userAccessModal.pickAccess`):Le(_,u),[e.isAdmin,p.mode,p.roleId,_]),b=e=>m({...p,...e});return d(W,{open:!0,onOpenChange:e=>!e&&t(),children:a(ct,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-2xl`,children:[a(Ae,{children:[d(Ne,{children:l(`users.userAccessModal.title`,{name:e.username})}),d(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?l(`users.userAccessModal.thisUserIsAnAdministrator`,`This user is an administrator — they can do everything, and the settings below are ignored.`):l(`users.userAccessModal.chooseWhatTheyCanDo`,`Choose what they can do, then which devices it applies to.`)})]}),a(Fe,{className:`space-y-4`,children:[v&&a(`div`,{className:`flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3`,children:[d(C,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`}),a(`p`,{className:`text-[11px] text-foreground`,children:[d(`span`,{className:`font-medium`,children:l(`users.userAccessModal.noAccess`,`No access.`)}),` `,d(`span`,{className:`text-foreground-subtle`,children:l(`users.userAccessModal.cannotSeeAnything`,{name:e.username})})]})]}),a(`section`,{className:`space-y-2`,children:[d(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:l(`users.userAccessModal.1WhatCanTheyDo`,`1 · What can they do`)}),d(`div`,{className:`space-y-1.5`,children:B.map(e=>{let t=p.mode===`role`&&p.roleId===e.id;return a(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-lg border p-2.5 transition-colors ${t?`border-primary bg-primary/5`:`border-border hover:bg-foreground-subtle/5`}`,children:[d(`input`,{type:`radio`,name:`access-role`,checked:t,onChange:()=>b({mode:`role`,roleId:e.id}),className:`mt-0.5 border-border focus:ring-primary`}),a(`span`,{className:`min-w-0`,children:[d(`span`,{className:`block text-[12px] font-medium text-foreground`,children:e.label}),d(`span`,{className:`mt-0.5 block text-[10px] text-foreground-subtle`,children:e.description})]})]},e.id)})}),a(`button`,{type:`button`,onClick:()=>{if(!h){m({...p,mode:`advanced`,advancedScopes:_}),g(!0);return}g(!1),m($r(p.advancedScopes))},className:`inline-flex items-center gap-1 rounded px-1.5 py-1 text-[10px] text-foreground-subtle transition-colors hover:bg-foreground-subtle/10 hover:text-foreground`,children:[d(h?L:R,{className:`h-3 w-3`}),l(`users.userAccessModal.advancedEditRawGrants`,`Advanced — edit raw grants`)]}),h&&a(`div`,{className:`rounded-lg border border-border p-2`,children:[d(`p`,{className:`mb-2 text-[10px] text-foreground-subtle`,children:l(`users.userAccessModal.oneRowPerGrantAnything`,`One row per grant. Anything expressible here overrides the three roles above; close this section to go back to them.`)}),d(je,{value:p.advancedScopes,onChange:e=>b({mode:`advanced`,advancedScopes:e}),clampToParent:c,emptyHint:d(s,{children:d(St,{i18nKey:`users.userAccessModal.noGrants`,values:{name:e.username},components:{b:d(`span`,{className:`font-medium text-foreground`})}})})})]})]}),p.mode===`role`&&a(`section`,{className:`space-y-2`,children:[d(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:l(`users.userAccessModal.2OnWhichDevices`,`2 · On which devices`)}),d(ze,{value:p.selector,onChange:e=>b({selector:e}),includeLinked:p.includeLinked,onIncludeLinkedChange:e=>b({includeLinked:e}),clampToDeviceIds:null})]}),a(`section`,{className:`space-y-2`,children:[d(`h3`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:p.mode===`role`?l(`users.userAccessModal.3Result`,`3 · Result`):l(`users.userAccessModal.2Result`,`2 · Result`)}),d(Qr,{scopes:_,isAdmin:e.isAdmin,invalidReason:y})]})]}),a(st,{children:[d(G,{variant:`outline`,size:`sm`,onClick:t,children:l(`common.cancel`,`Cancel`)}),d(G,{size:`sm`,onClick:()=>i([..._]),disabled:o||y!==null,children:o?d(M,{className:`h-3 w-3 animate-spin`}):l(`users.userAccessModal.saveAccess`,`Save access`)})]})]})})}e();var ni=8;function ri(){return{username:``,password:``,isAdmin:!1}}function ii(e){return{id:e.id,username:e.username,password:``,isAdmin:e.isAdmin}}function ai(e){return e instanceof Error?e.message:Y.t(`admin.system.users.genericError`)}function oi(){let{t:e}=X(),n=c(),{user:i}=xt(),{state:o,openNew:l,openEdit:u,close:p}=ht(),[g,_]=r(null),[y,b]=r(null),[x,S]=r(!1),{data:C,isLoading:w,isError:T,error:D,refetch:k}=gt(),A=U(),j=rt(),N=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),P=ke(),F=Me({onSuccess:N}),L=Te({onSuccess:N}),R=ge({onSuccess:N}),z=Qe({onSuccess:()=>{N(),B(null)}}),[ee,B]=r(null),[V,te]=r(null),[ne,re]=r(null),[ie,ae]=r(null),oe=C??[],H=o.mode===`edit`?oe.find(e=>e.id===o.id)??null:null,ce=()=>{_(null),b(null),S(!1),P.reset(),L.reset(),p()};t(()=>{if(o.mode===`closed`){_(null),b(null),S(!1);return}if(o.mode===`new`){_(e=>e!==null&&e.id===void 0?e:ri());return}if(H===null){w||p();return}_(e=>e?.id===H.id?e:ii(H))},[o,H,w,p]);let le=o.mode===`new`&&g!==null&&g.id===void 0||o.mode===`edit`&&g!==null&&H!==null;async function ue(t){await A({title:e(`admin.system.users.deleteUser`,`Delete user`),message:e(`admin.system.users.permanentlyDeleteUserThisCannot`,`Permanently delete user "{{username}}"? This cannot be undone — any active sessions will be revoked on next request.`,{username:t.username}),confirmLabel:e(`common.delete`,`Delete`),variant:`danger`})&&(F.mutate({id:t.id}),o.mode===`edit`&&o.id===t.id&&ce())}async function de(t){let n=await j({title:e(`admin.system.users.resetPassword`,`Reset password`),message:e(`admin.system.users.setANewPasswordFor`,`Set a new password for "{{username}}".`,{username:t.username}),label:e(`admin.system.users.newPassword`,`New password`),inputType:`password`,placeholder:e(`admin.system.users.atLeast8Characters`,`At least 8 characters`),confirmLabel:e(`admin.system.users.continue`,`Continue`),validate:e=>e.length<ni?Y.t(`admin.system.users.passwordTooShort`,{min:ni}):null});n===null||n.length===0||await A({title:e(`admin.system.users.resetPassword`,`Reset password`),message:e(`admin.system.users.resetThePasswordForThey`,`Reset the password for "{{username}}"? They will need to use the new password on their next login.`,{username:t.username}),confirmLabel:e(`common.reset`,`Reset`)})&&R.mutate({id:t.id,newPassword:n})}function pe(e,t){t!==e.isAdmin&&L.mutate({id:e.id,isAdmin:t})}async function me(){if(g!==null){b(null);try{if(g.id===void 0){let e=g.username.trim();if(e===``||g.password.length<ni)return;await P.mutateAsync({username:e,password:g.password,isAdmin:g.isAdmin})}else await L.mutateAsync({id:g.id,isAdmin:g.isAdmin});N(),ce()}catch(e){b(ai(e))}}}function he(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}let W=P.isPending||L.isPending,ve=g!==null&&g.id===void 0&&g.username.trim()!==``&&g.password.length>=ni,ye=g!==null&&g.id!==void 0,be=W||(g?.id===void 0?!ve:!ye),Se=e=>F.isPending&&F.variables?.id===e.id||L.isPending&&L.variables?.id===e.id||R.isPending&&R.variables?.id===e.id,Ce=[{key:`username`,header:e(`admin.system.users.username`,`Username`),sortValue:e=>e.username,render:e=>d(`span`,{className:`font-medium text-foreground`,"data-testid":`user-open-${e.id}`,children:e.username})},{key:`isAdmin`,header:e(`admin.system.users.admin`,`Admin`),nowrap:!0,sortValue:e=>+!!e.isAdmin,render:t=>d(`span`,{onClick:e=>e.stopPropagation(),children:a(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[d(`input`,{type:`checkbox`,checked:t.isAdmin,onChange:e=>pe(t,e.target.checked),disabled:Se(t),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),d(`span`,{className:t.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:t.isAdmin?e(`admin.system.users.admin`,`Admin`):e(`admin.system.users.regular`,`Regular`)})]})})},{key:`scopes`,header:e(`admin.system.users.access`,`Access`),render:t=>t.isAdmin?d(`span`,{className:`text-[10px] italic text-foreground-subtle`,children:e(`admin.system.users.everythingAdmin`,`everything (admin)`)}):d(`span`,{onClick:e=>e.stopPropagation(),children:a(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>B(t),title:e(`admin.system.users.configureAccess`,`Configure access`),children:[d(I,{className:`h-3 w-3 shrink-0 text-foreground-subtle`}),d(si,{scopes:t.scopes??[]})]})})},{key:`createdAt`,header:e(`admin.system.users.created`,`Created`),nowrap:!0,sortValue:e=>e.createdAt,render:e=>d(`span`,{className:`text-foreground-subtle`,children:he(e.createdAt)})},{key:`actions`,header:e(`admin.system.users.actions`,`Actions`),align:`right`,nowrap:!0,notSortableReason:`Row actions`,render:t=>{let n=Se(t),r=t.id!==i?.id&&t.totpEnabled;return a(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:[a(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>u(t.id),disabled:n,title:e(`admin.system.users.editUser`,`Edit user`),children:[d(m,{className:`h-3 w-3`}),e(`common.edit`,`Edit`)]}),r&&a(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>te(t),disabled:n,title:e(`admin.system.users.removeTwoFactorAuthentication`,`Remove two-factor authentication`),children:[d(f,{className:`h-3 w-3`}),e(`admin.system.users.remove2fa`,`Remove 2FA`)]}),a(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>re(t),disabled:n,title:e(`admin.system.users.linkedSignInAccounts`,`Linked sign-in accounts`),children:[d(O,{className:`h-3 w-3`}),e(`admin.system.users.signInLinks`,`Sign-in links`)]}),a(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>ae(t),disabled:n,title:e(`admin.system.users.activeSessions`,`Active sessions`),children:[d(fe,{className:`h-3 w-3`}),e(`admin.system.users.sessions`,`Sessions`)]}),a(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void de(t),disabled:n,title:e(`admin.system.users.resetPassword`,`Reset password`),children:[d(se,{className:`h-3 w-3`}),e(`admin.system.users.resetPassword`,`Reset password`)]}),a(G,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>void ue(t),disabled:n,title:e(`admin.system.users.deleteUser`,`Delete user`),className:`text-danger hover:bg-danger/10`,children:[n?d(M,{className:`h-3 w-3 animate-spin`}):d(h,{className:`h-3 w-3`}),e(`common.delete`,`Delete`)]})]})}}];return a(At,{embedded:!0,icon:v,title:e(`admin.system.users.users`,`Users`),subtitle:e(`admin.system.users.hubAccountsAdminFlagAccess`,`Hub accounts, admin flag, access scopes, sessions and sign-in links.`),actions:a(G,{size:`sm`,type:`button`,onClick:()=>{b(null),l()},children:[d(E,{className:`h-3.5 w-3.5`}),e(`admin.system.users.createUser`,`Create User`)]}),children:[T&&d(_t,{title:e(`admin.system.users.couldNotLoadUsers`,`Could not load users`),message:ai(D),onRetry:()=>void k()}),w&&a(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[d(M,{className:`h-3.5 w-3.5 animate-spin`}),e(`common.loading`,`Loading…`)]}),!w&&!T&&oe.length===0&&d(_e,{icon:v,title:e(`admin.system.users.noUsersYet`,`No users yet`),description:e(`admin.system.users.createAUserToGrant`,`Create a user to grant hub access.`)}),!w&&!T&&oe.length>0&&d(xe,{columns:Ce,rows:oe,rowKey:e=>e.id,minWidthPx:560,maxBodyHeight:`max-h-[60vh]`,onRowClick:e=>u(e.id)}),d(Je,{open:le,onClose:ce,title:g?.id===void 0?e(`admin.system.users.createUser`,`Create User`):e(`admin.system.users.edit`,`Edit {{value1}}`,{value1:g.username||`user`}),icon:v,error:y,testId:`user-form-dialog`,footer:d(G,{size:`sm`,type:`button`,disabled:be,onClick:()=>void me(),children:W?a(s,{children:[d(M,{className:`h-3.5 w-3.5 animate-spin`}),e(`admin.system.users.saving`,`Saving…`)]}):g?.id===void 0?e(`admin.system.users.create`,`Create`):e(`common.save`,`Save`)}),children:g!==null&&a(`div`,{className:`space-y-3`,children:[d(pt,{label:e(`admin.system.users.username`,`Username`),required:g.id===void 0,children:d(dt,{value:g.username,onChange:e=>_({...g,username:e.target.value}),placeholder:`john`,autoFocus:g.id===void 0,disabled:g.id!==void 0,"data-testid":`user-form-username`})}),g.id===void 0&&d(pt,{label:e(`admin.system.users.password`,`Password`),required:!0,description:e(`admin.system.users.atLeastCharacters`,`At least {{value1}} characters.`,{value1:String(ni)}),children:d(Be,{value:g.password,onValueChange:e=>_({...g,password:e}),shown:x,onToggleShown:()=>S(e=>!e),placeholder:`••••••••`,"data-testid":`user-form-password`})}),d(pt,{label:e(`admin.system.users.admin`,`Admin`),description:e(`admin.system.users.unrestrictedAccessToEveryCapability`,`Unrestricted access to every capability and device.`),children:a(`label`,{className:`inline-flex items-center gap-2 text-xs text-foreground cursor-pointer`,children:[d(`input`,{type:`checkbox`,checked:g.isAdmin,onChange:e=>_({...g,isAdmin:e.target.checked}),className:`rounded border-border focus:ring-primary`,"data-testid":`user-form-admin`}),d(`span`,{children:e(`admin.system.users.admin`,`Admin`)})]})}),g.id!==void 0&&d(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`admin.system.users.toChangeThePasswordUse`,`To change the password, use Reset password on the user's row. Access scopes are configured from the Access column.`)})]})}),V&&d(Yr,{userId:V.id,username:V.username,onClose:()=>te(null)}),ne&&d(Jr,{userId:ne.id,username:ne.username,onClose:()=>re(null)}),ie&&d(Xr,{userId:ie.id,username:ie.username,onClose:()=>ae(null)}),ee&&d(ci,{user:ee,onClose:()=>B(null),onSubmit:e=>z.mutate({userId:ee.id,scopes:e}),submitting:z.isPending})]})}function si({scopes:e}){let{t}=X(),n=j();if(e.length===0)return d(`span`,{className:`font-medium text-warning`,children:t(`admin.system.users.noAccess`,`No access`)});let r=ne(e);return r===null?d(`span`,{className:`text-foreground-subtle`,children:t(`users.customGrants`,{count:e.length})}):a(`span`,{className:`text-foreground-subtle`,children:[d(`span`,{className:`font-medium text-foreground`,children:V(r.roleId).label}),` ·`,` `,me(r.selector,n)]})}function ci(e){let{user:t}=xt(),n=t?.isAdmin===!0;return d(ti,{...e,callerScopes:n?null:t?.scopes??[]})}e();var li={"api-keys":$.tokens,"linked-sessions":$.linkedApps},ui=`certificates`;function di(e){return a(G,{size:`sm`,type:`button`,"data-testid":`certificates-pair-device`,onClick:e,children:[d(f,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),Y.t(`systemPage.identity.pairADevice`,`Pair a device`)]})}function fi(){let{t:e}=X(),[t]=Ot(),n=qn(),[i,a]=r(!1),o=li[t.get(`tab`)??``];if(o!==void 0)return d(vt,{to:Dt(`access`,{integration:o}),replace:!0});let s=bt(`/system/identity`,{t:e,isAdmin:!0})??{icon:F,title:e(`system.identity`,`Identity & Access`)},c=t.get(`tab`)??`users`,l=t.get(`integration`),u=c===Ct.access.tab?Kn(l,n.requestCreate):c===`certificates`?di(()=>a(!0)):void 0;return d(kt,{icon:s.icon,title:s.title,defaultSection:`users`,sectionsLabel:`${s.title} sections`,actions:u,sections:[{id:`users`,label:e(`systemPage.identity.users`,`Users`),content:d(oi,{})},{id:Ct.access.tab,label:e(`systemPage.identity.tokensSessions`,`Tokens & sessions`),content:d(Gn,{createRequested:n.createRequested,onCreateConsumed:n.clearCreate}),ownedParams:Et.concat([wn.token,wn.scoped,wn.admin])},{id:ui,label:e(`systemPage.identity.certificates`,`Certificates`),content:d(qr,{pairOpen:i,onPairClose:()=>a(!1)})},{id:Ct.authentication.tab,label:e(`systemPage.identity.authentication`,`Authentication`),content:d(or,{}),ownedParams:Et}]})}export{fi as IdentityPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,L as i,S as a,o,q as s,x as c}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Cn as l,It as u,Nt as d,Rr as f,Si as p,Yi as m,bn as h,dt as g,ht as _,kn as v,oa as y,or as b,ot as x,pi as S,pn as C,si as w,un as T,vn as E,xi as ee,yi as D,zr as O}from"./player-overlays-Fx6RE6kI.js";import{Ur as k}from"./client-yfOXPkcm.js";import{t as A}from"./search-x-C9z-zNBZ.js";import{$i as j,Dn as M,Dt as N,Ea as te,Jt as P,Mn as F,Nn as I,On as L,Pr as ne,Qi as R,Rt as z,Ua as B,Xi as V,Yi as H,Zi as U,_a as W,_r as re,at as ie,ca as G,co as K,do as ae,fa as oe,fo as se,gr as ce,gu as q,ia as le,kn as ue,la as de,lo as fe,mo as pe,nt as me,on as he,pu as ge,ra as J,rt as _e,so as ve,ta as ye,uo as be,wa as Y,xn as xe}from"./src-AhVPNkCn.js";import{t as X}from"./useTranslation-D3Is_4B6.js";import{n as Se}from"./addon-icons-context-D3LZwxs2.js";import{Z as Ce,et as we,nt as Te,tt as Ee,z as De}from"./index-CcAR8Rlk.js";import{t as Oe}from"./NodeAddonsSettingsPanel-BxeQZ-hu.js";import{t as ke}from"./device-integration-icon-BeeizbXV.js";import{n as Ae,r as je,t as Me}from"./ScanNetworkModal-CfHHLP_k.js";e();function Z(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Z(n.fields));return t}function Ne(e,t,a){let[o,s]=r(`idle`),[c,l]=r({}),u=n(()=>{let t=[];for(let n of e.sections)t.push(...Z(n.fields));return t},[e]),d=u.length>0&&a!==void 0,f=i(e=>{l(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:o,hasProbeFields:d,probeResults:c,handleTestAll:i(async()=>{if(!a)return;let e=u.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;s(`testing`);let n={};for(let t of e)n[t]={status:`probing`};l(n);let r=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await a(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),i={};for(let e of r)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;i[t]={status:n.status===`ok`?`ok`:`error`,result:n}}l(i),s(`idle`)},[a,u,t]),clearProbeResult:f}}e();function Pe(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Pe(n.fields));return t}function Fe(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Ie(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Ie(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function Le(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Re({open:e,integrationId:s,addonId:l,onClose:u}){let{t:f}=X(),p=o(),[m,h]=r({}),[v,y]=r(!1),[x,S]=r(null),[w,T]=r(Le),E=Y({addonId:l},{enabled:e}),D=E.data?.deviceType??null,O=oe({addonId:l,type:D??k.Camera},{enabled:e&&E.isSuccess&&D!==null}),A=O.data??null;t(()=>{e&&(h(A?Ie(A.sections.flatMap(e=>e.fields)):{}),T(Le()),y(!1),S(null))},[e,s,A]);let j=n(()=>({...m,_probeRequestId:w}),[m,w]),M=J({onSuccess:()=>{p.invalidateQueries({queryKey:[[`deviceManager`]]})}}),te=B(),P=i(async(e,t)=>{y(!0);let n=await te.mutateAsync({addonId:l,type:D??k.Camera,key:e,value:t,formValues:j});return n.status===`ok`&&n.suggestedValues&&h(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Fe(e[i])&&!Fe(a)&&(r[i]=a,t=!0);return t?r:e}),n},[te,l,j,D]),{testAllStatus:F,hasProbeFields:I,probeResults:L,handleTestAll:ne,clearProbeResult:R}=Ne(A??{sections:[]},m,P);async function z(e){S(null);try{await M.mutateAsync({addonId:l,type:D??k.Camera,config:m,integrationId:s}),e?h(A?Ie(A.sections.flatMap(e=>e.fields)):{}):u()}catch(e){S(e instanceof Error?e.message:String(e))}}if(!e)return null;let V=Pe((A?.sections??[]).flatMap(e=>e.fields)).filter(e=>Fe(m[e])),H=V.length===0,U=E.isLoading||D!==null&&O.isLoading,W=E.isError||E.isSuccess&&D===null||O.isError||O.isSuccess&&A===null;return a(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:u}),a(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[calc(90dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl`,children:[a(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:f(`integrations.addDevice`)}),c(`button`,{onClick:u,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:c(g,{className:`h-4 w-4`})})]}),c(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:U?c(`div`,{className:`flex items-center justify-center py-8`,children:c(b,{className:`h-5 w-5 animate-spin text-primary`})}):W?a(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[c(d,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),a(`div`,{className:`space-y-1`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:f(`integrations.addDeviceDialog.providerUnavailable`,`Provider unavailable`)}),c(`p`,{className:`text-xs text-foreground-subtle`,children:c(Ce,{i18nKey:`integrations.addDeviceDialog.notReady`,values:{addonId:l},components:{mono:c(`span`,{className:`font-mono`})}})})]})]}):c(De,{schema:A,values:m,onChange:h,onTestField:P,probeResults:L,onClearProbe:R})}),!W&&!U&&a(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[a(`button`,{type:`button`,onClick:()=>y(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[a(`span`,{className:`flex items-center gap-2`,children:[c(C,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceDialog.testLogs`,`Test logs`),c(`span`,{className:`font-mono text-[9px] opacity-60`,children:w.slice(0,14)})]}),c(ee,{className:`h-3.5 w-3.5 transition-transform ${v?`rotate-180`:``}`})]}),v&&c(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:c(N,{addonId:l,requestId:w,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!W&&!U&&(x||V.length>0)&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:a(`div`,{className:`flex items-start gap-2`,children:[c(d,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:x||f(`integrations.addDeviceDialog.required`,`Required: {{value1}}`,{value1:V.join(`, `)})})]})}),a(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[a(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:u,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:f(`integrations.cancel`)}),!W&&I&&a(`button`,{type:`button`,onClick:ne,disabled:F===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[F===`testing`?c(b,{className:`h-3.5 w-3.5 animate-spin`}):c(_,{className:`h-3.5 w-3.5`}),f(`integrations.addDeviceDialog.testAll`,`Test All`)]})]}),a(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:()=>z(!0),disabled:W||!H||M.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:f(`integrations.saveAndNew`)}),c(`button`,{onClick:()=>z(!1),disabled:W||!H||M.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:M.isPending?f(`integrations.saving`):f(`integrations.save`)})]})]})]})]})}var Q=1500;function ze({addonId:e,integrationId:t,jobId:n,onFinished:r}){let{t:i}=X(),o=H(),s=(R({addonId:e,integrationId:t},{refetchInterval:e=>(e.state.data??[]).some(e=>e.state===`running`)?Q:!1}).data??[]).find(e=>e.jobId===n);if(!s)return null;let l=s.state===`running`,u=s.processed,f=s.total>0?Math.round(u/s.total*100):0;!l&&s.finishedAt!==null&&r();let p=[`${u}/${s.total} ${i(`integrations.adoptJobProcessed`,{defaultValue:`processed`})}`];s.adopted>0&&p.push(`${s.adopted} ${i(`integrations.adoptJobAdded`,{defaultValue:`added`})}`),s.alreadyAdopted>0&&p.push(`${s.alreadyAdopted} ${i(`integrations.adoptJobSkipped`,{defaultValue:`already there`})}`),s.failed>0&&p.push(`${s.failed} ${i(`integrations.adoptJobFailed`,{defaultValue:`failed`})}`);let m=p.join(` · `);return a(`div`,{className:`border-t border-border px-5 py-3 shrink-0 space-y-2`,children:[a(`div`,{className:`flex items-center gap-2`,children:[l?c(b,{className:`h-3.5 w-3.5 animate-spin text-primary shrink-0`}):s.failed>0?c(d,{className:`h-3.5 w-3.5 text-destructive shrink-0`}):s.state===`cancelled`?c(w,{className:`h-3.5 w-3.5 text-foreground-subtle shrink-0`}):c(S,{className:`h-3.5 w-3.5 text-primary shrink-0`}),c(`p`,{className:`text-[11px] text-foreground`,children:m}),l&&c(`button`,{onClick:()=>o.mutate({jobId:n}),className:`ml-auto rounded-lg border border-border px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:i(`integrations.adoptJobCancel`,{defaultValue:`Stop`})})]}),c(`div`,{className:`h-1 w-full rounded-full bg-border overflow-hidden`,children:c(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${f}%`},role:`progressbar`,"aria-valuenow":f,"aria-valuemin":0,"aria-valuemax":100})}),s.results.filter(e=>e.outcome===`failed`).slice(0,5).map(e=>a(`p`,{className:`text-[11px] text-destructive`,children:[e.childNativeId,`: `,e.error]},e.childNativeId))]})}function Be(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}e();var $=`devices`;function Ve(e){return{id:$,label:e(`integrations.adoptDevicesModal.defaultFilter`),isDefault:!0}}var He=2e4,Ue=100;function We({addonId:e,integrationId:n,onClose:l}){let u=y(),{t:f}=X(),m=o(),[h,_]=r(new Set),[v,x]=r(new Set),[S,C]=r(new Map),[w,T]=r(null),{data:ee}=fe(),D=(ee??[]).find(t=>t.addonId===e)?.supportsLocationImport??!1,[O,k]=r(!0),A=V({addonId:e,integrationId:n}).data?.filters,M=A&&A.length>0?A:[Ve(f)],[N,te]=r(M.find(e=>e.isDefault)?.id??(M.some(e=>e.id===$)?$:M[0].id)),P=N!==$,F=j(),I=U({addonId:e,integrationId:n,page:1,pageSize:He,filter:N}),L=I.refetch,ne=F.mutate,R=i(()=>{ne({addonId:e,integrationId:n},{onSettled:()=>{L()}})},[ne,e,n,L]),z=s(null);t(()=>{let t=`${e}::${n}`;z.current===t||I.isLoading||(z.current=t,(I.data?.candidates.length??0)===0&&R())},[e,n,I.isLoading,I.data,R]);let B=F.isPending,H=F.isError?F.error instanceof Error?F.error.message:String(F.error):null,W=typeof F.data?.lastError==`string`&&F.data.lastError.length>0?F.data.lastError:null,re=I.data?.candidates??[],ie=I.isError?I.error instanceof Error?I.error.message:String(I.error):null,G=ye(),[K,ae]=r(null),oe=i(e=>{e.alreadyAdopted||_(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),se=i(e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),ce=i((e,t)=>{C(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),le=i(e=>{let t={};for(let n of e){let e=S.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[S]),ue=i(async()=>{T(null);let t=[...h];if(t.length!==0)try{let r=le(t),{jobId:i}=await G.mutateAsync({addonId:e,integrationId:n,filter:N,childNativeIds:t,...r?{perCandidate:r}:{},...D?{importLocations:O}:{}});ae(i),_(new Set),C(new Map)}catch(e){T(e instanceof Error?e.message:String(e))}},[h,le,G,e,n,N,D,O]),de=s(null),pe=i(()=>{K===null||de.current===K||(de.current=K,L(),m.invalidateQueries({queryKey:[[`integrations`]]}),m.invalidateQueries({queryKey:[[`deviceManager`]]}))},[K,L,m]),he=i(e=>{te(e),_(new Set),x(new Set),C(new Map),T(null)},[]),J=h.size,_e=K!==null&&J===0&&!G.isPending;return a(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[c(`div`,{className:`absolute inset-0 bg-black/60`,onClick:l}),a(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[a(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[a(`div`,{className:`min-w-0`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:f(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),c(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:f(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),a(`div`,{className:`flex items-center gap-3 shrink-0`,children:[D&&a(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[c(`input`,{type:`checkbox`,checked:O,onChange:e=>k(e.target.checked),className:`accent-primary`}),f(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),c(`button`,{onClick:l,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":f(`common.close`,`Close`),children:c(g,{className:`h-4 w-4`})})]})]}),a(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(H??ie??W)&&re.length===0&&c(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:a(`div`,{className:`flex items-start gap-2`,children:[c(d,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),a(`div`,{className:`min-w-0`,children:[c(`p`,{className:`text-xs font-medium text-destructive`,children:f(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),c(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:H??ie??W})]})]})}),M.length>1&&c(Ge,{filters:M,activeFilter:N,onSelect:he}),c(`div`,{className:`flex-1 min-h-0`,children:c(me,{mode:`generic`,items:re,pageSize:Ue,getKey:e=>e.childNativeId,getSearchText:Be,getFilterType:e=>e.type,filterOptions:ge(u),filterLabel:f(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:I.isLoading||B&&re.length===0,searchPlaceholder:f(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(H??ie??W)&&re.length===0?``:f(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:a(`button`,{type:`button`,onClick:R,disabled:B,title:f(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[c(E,{className:`h-3.5 w-3.5 ${B?`animate-spin`:``}`}),f(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:f(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>c(Ke,{candidate:e,expandable:!P,expanded:v.has(e.childNativeId),onToggleExpand:()=>se(e.childNativeId),adoptedLabel:f(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:f(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=q(e.type,u),n=t.icon;return a(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[c(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>c(`div`,{className:`flex items-center justify-end`,children:c(`button`,{onClick:()=>oe(e),disabled:e.alreadyAdopted,"aria-label":h.has(e.childNativeId)?f(`integrations.adoptDevicesModal.deselect`,`Deselect`):f(`integrations.adoptDevicesModal.select`,`Select`),className:`inline-flex h-5 w-5 items-center justify-center rounded border ${h.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:h.has(e.childNativeId)&&c(p,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!P&&v.has(e.childNativeId),renderExpanded:P?void 0:e=>c(qe,{candidate:e,hiddenChildIds:S.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>ce(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:h.has(e.childNativeId)?`bg-primary/5`:``})})]}),w&&c(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:a(`div`,{className:`flex items-start gap-2`,children:[c(d,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),c(`p`,{className:`text-[11px] text-destructive`,children:w})]})}),K!==null&&c(ze,{addonId:e,integrationId:n,jobId:K,onFinished:pe}),a(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[c(`div`,{}),a(`div`,{className:`flex items-center gap-2`,children:[c(`button`,{onClick:l,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:f(`integrations.cancel`,{defaultValue:`Cancel`})}),a(`button`,{onClick:_e?l:ue,disabled:!_e&&(J===0||G.isPending),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[G.isPending&&c(b,{className:`h-3.5 w-3.5 animate-spin`}),_e?f(`integrations.close`,{defaultValue:`Close`}):f(`integrations.addSelected`,{defaultValue:`Add selected`}),!_e&&J>0?` (${J})`:``]})]})]})]})]})}function Ge({filters:e,activeFilter:t,onSelect:n}){let{t:r}=X();return c(`div`,{role:`tablist`,"aria-label":r(`integrations.adoptDevicesModal.discoveryGranularity`,`Discovery granularity`),className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return c(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function Ke({candidate:e,expandable:t,expanded:n,onToggleExpand:r,adoptedLabel:i}){let{t:o}=X(),s=(e.children??[]).length;return a(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&s>0?a(`button`,{type:`button`,onClick:r,"aria-label":n?o(`integrations.adoptDevicesModal.collapse`,`Collapse`):o(`integrations.adoptDevicesModal.expand`,`Expand`),"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[c(n?ee:D,{className:`h-3.5 w-3.5`}),s]}):c(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),c(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&c(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:i})]})}function qe({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let{t:r}=X(),i=e.children??[];return i.length===0?null:c(`div`,{className:`space-y-1 py-1`,children:i.map(e=>{let i=t.has(e.childNativeId),o=e.capabilities??[];return a(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${i?`opacity-50`:``}`,children:[c(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),o.length>0&&c(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:o.join(`, `)}),c(`button`,{onClick:()=>n(e.childNativeId),"aria-label":i?r(`integrations.adoptDevicesModal.showChild`,`Show child`):r(`integrations.adoptDevicesModal.hideChild`,`Hide child`),title:i?r(`integrations.adoptDevicesModal.showAfterAdopt`,`Show after adopt`):r(`integrations.adoptDevicesModal.hideAfterAdopt`,`Hide after adopt`),className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:c(i?O:f,{className:`h-3 w-3`})})]},e.childNativeId)})})}e();function Je(e){let t=[];for(let n of e){if(n.type===`group`){t.push(...Je(n.fields));continue}`key`in n&&typeof n.key==`string`&&t.push(n.key)}return t}function Ye(e,t){if(!e)return{};let n=new Set(e.sections.flatMap(e=>Je(e.fields))),r={};for(let e of n)Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}function Xe(e){return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{if(`value`in e){let{value:t,...n}=e;return n}return e})}))}}function Ze({integrationId:e,addonId:t,name:r,kind:i,mode:s,brokerKind:l,canTest:u=!1,trpc:d,onClose:f}){let{t:p}=X(),m=o(),{data:h,isLoading:g}=be({id:e},{enabled:s===`account`||s===`broker`}),_=n(()=>{let e=h?.brokerId;return typeof e==`string`?e:null},[h]),{data:v,isLoading:y}=ce({addonId:t,nodeId:`hub`},{enabled:s===`account`}),x=n(()=>v?Xe(v):null,[v]),S=se(),C=(t,n)=>{S.mutate({id:e,settings:t,...n?{secretKeys:[...n]}:{}},{onSuccess:()=>{m.invalidateQueries(),f()}})};return c(M,{open:!0,onOpenChange:e=>!e&&f(),children:a(ue,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[c(F,{children:a(I,{children:[p(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,r]})}),c(L,{children:s===`broker`?l?a(`div`,{className:`space-y-3`,children:[c(`p`,{className:`text-[11px] text-foreground-subtle`,children:p(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),_&&a(`p`,{className:`text-[11px] text-foreground`,children:[p(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,c(`span`,{className:`font-mono text-foreground-subtle`,children:_})]}),S.isPending?a(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(b,{className:`h-3 w-3 animate-spin`}),p(`integrations.saving`,{defaultValue:`Saving…`})]}):c(je,{kind:l,onResolved:e=>{C({brokerId:e})},onBack:f}),S.isError&&c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):c(`p`,{className:`text-[11px] text-danger`,children:p(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):s===`account`?g||y?a(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[c(b,{className:`h-3 w-3 animate-spin`}),p(`integrations.loading`,{defaultValue:`Loading…`})]}):c(Ae,{addonId:t,configSchema:x,canTest:u,initialName:r,initialConfig:Ye(x,h??{}),submitLabel:p(`integrations.save`,{defaultValue:`Save`}),hideName:!0,onSave:({config:e,secretKeys:t})=>C(e,t),onBack:f}):c(xe,{trpc:d,addonId:t,nodeId:`hub`,title:r})})]})})}function Qe(e){return e==null?!1:e.sections.some(e=>e.fields.length>0)}e();function $e(){let{t:e}=X(),{integrationId:s}=Ee(),d=o(),f=we(),[p,g]=Te(),_=x(),[y,S]=r(!1),[w,E]=r(!1),[ee,D]=r(!1),[O,k]=r(!1),{data:j,isLoading:R}=K({id:s??``},{enabled:!!s}),{data:B}=ce({addonId:j?.addonId??``,nodeId:`hub`},{enabled:!!j?.addonId}),{data:V,isSuccess:H}=fe(),U=n(()=>{let e=j?.addonId;return!e||!H?null:(V??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[V,j?.addonId,H]),{data:oe}=G({}),se=n(()=>(oe?.providers??[]).some(e=>e.addonId===j?.addonId),[oe,j?.addonId]),q=U!==null,ge=j?.info?.fixed===!0,J=q?U===`device-adoption`?e(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):e(`integrations.addDevice`):e(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),ye=n(()=>{let e=j?.addonId;return!e||!H?null:(V??[]).find(t=>t.addonId===e)?.brokerKind??null},[V,j?.addonId,H]),be=n(()=>{let e=j?.addonId;return!e||!H?!1:(V??[]).find(t=>t.addonId===e)?.canTest===!0},[V,j?.addonId,H]),Y=n(()=>{let e=j?.addonId;return!e||!H?null:(V??[]).find(t=>t.addonId===e)?.mode??null},[V,j?.addonId,H]);t(()=>{p.get(`add`)===`1`&&q&&(S(!0),g(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[p,q,g]);let xe=B!=null&&Array.isArray(B.sections)&&B.sections.some(e=>e.fields.length>0),{data:Se}=re({addonId:j?.addonId??``,nodeId:`hub`},{enabled:!!j?.addonId&&Y!==`account`}),Ce=Y!==null&&Y!==`account`&&Qe(Se),De=n(()=>j?.addonId?[j.addonId]:[],[j?.addonId]),{data:Ae}=W({projection:`slim`},{refetchInterval:3e4}),je=[[`integrations`,`get`],{input:{id:s??``},type:`query`}],Z=pe({onMutate:async e=>{await d.cancelQueries({queryKey:je});let t=d.getQueryData(je);return t!=null&&d.setQueryData(je,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&d.setQueryData(je,r.previous)},onSettled:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ne=ve({onSuccess:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}),f(`/integrations`)}}),Pe=ne({onSuccess:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=te({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ie=le({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=de({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=n(()=>Ae??[],[Ae]),ze=n(()=>{let e=new Map;for(let t of Q)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[Q]),Be=i(e=>ze.get(e)??null,[ze]),{data:$}=ae(void 0),Ve=n(()=>_e($),[$]),He=i(e=>f(`/devices/${String(e)}`),[f]),Ue=n(()=>{let e=j?.id;return e?Q.filter(t=>{let n=Ve(t);return n.kind===`resolved`&&n.integration.id===e}):[]},[Q,j?.id,Ve]),Ge=n(()=>$===void 0?null:ie(Ue).length,[$,Ue])??`…`;return R?a(`div`,{className:`p-4`,children:[c(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),c(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):j?a(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[c(P,{items:[{label:e(`integrationDetail.integrations`,`Integrations`),onClick:()=>f(`/integrations`)},{label:j.name}]}),a(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[a(`div`,{className:`flex items-center gap-3 min-w-0`,children:[c(et,{addonId:j.addonId}),a(`div`,{className:`min-w-0`,children:[c(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:j.name}),a(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[j.addonId,` · `,Ge,` `,e(`integrations.devices`)]})]})]}),a(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[se&&a(`button`,{onClick:()=>E(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:e(`integrationDetail.scanTheNetworkForDevices`,`Scan the network for devices (incl. a different subnet)`),children:[c(l,{className:`h-3.5 w-3.5`}),e(`integrationDetail.scanNetwork`,`Scan network`)]}),!ge&&a(`button`,{onClick:()=>S(!0),disabled:!q,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:J,children:[c(v,{className:`h-3.5 w-3.5`}),J]}),a(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Z.isPending?`opacity-60`:``} ${j.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:e(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[c(he,{checked:j.enabled,onCheckedChange:e=>Z.mutate({id:s,enabled:e}),disabled:Z.isPending,"aria-label":j.enabled?e(`integrationDetail.disableIntegration`,`Disable integration`):e(`integrationDetail.enableIntegration`,`Enable integration`)}),c(`span`,{className:`text-[11px] font-medium ${j.enabled?`text-success`:`text-foreground-subtle`}`,children:j.enabled?e(`integrationDetail.enabled`,`Enabled`):e(`integrationDetail.disabled`,`Disabled`)}),Z.isPending&&c(b,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Y!==`standalone`&&(xe||U===`device-adoption`)&&a(`button`,{onClick:()=>D(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[c(T,{className:`h-3 w-3`}),e(`integrations.config`)]}),a(`button`,{onClick:()=>k(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:e(`integrations.logs`,{defaultValue:`View logs`}),children:[c(C,{className:`h-3 w-3`}),e(`integrations.logs`,{defaultValue:`Logs`})]}),c(z,{label:e(`integrationDetail.restart`,`Restart`),icon:h,title:e(`integrationDetail.restart2`,`Restart "{{name}}"?`,{name:j.name}),description:e(`integrationDetail.restartingTheAddonWillBriefly`,`Restarting the addon will briefly disconnect every device backed by it ({{topLevelCountLabel}} active). Streams will reconnect automatically.`,{topLevelCountLabel:Ge}),confirmLabel:e(`integrationDetail.restart`,`Restart`),triggerVariant:`outline`,confirmVariant:`danger`,disabled:Pe.isPending,action:()=>Pe.mutateAsync({addonId:j.addonId})}),!ge&&s&&c(z,{label:e(`integrations.delete`,{defaultValue:`Delete`}),icon:u,title:e(`integrations.deleteTitle`,{defaultValue:`Delete integration?`}),description:e(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:j.name,count:Ge}),confirmLabel:e(`integrations.confirmDelete`,{defaultValue:`Delete integration`}),triggerVariant:`outline`,confirmVariant:`danger`,className:`border-danger bg-danger/10 text-danger hover:bg-danger hover:text-background`,disabled:Ne.isPending,action:()=>Ne.mutateAsync({id:s})})]})]}),Ce&&c(Oe,{nodeId:null,addonIds:De,level:`global`,surface:`integration`,title:e(`integrations.settings`,{defaultValue:`Settings`})}),c(me,{context:`integration-detail`,devices:Q,trpc:_.trpcClient,integrationOf:Ve,forceIntegrationId:j.id,urlScope:`root`,lsKey:`integration-detail:${j.addonId}`,resolveIntegrationIcon:ke,resolveParent:Be,onNavigate:He,batchActions:{remove:Fe.mutate,disable:Ie.mutate,enable:Le.mutate},...ge?{}:{onDeleteDevice:e=>Fe.mutate({deviceId:e.id})}}),y&&s&&U===`device-adoption`&&c(We,{addonId:j.addonId,integrationId:s,onClose:()=>S(!1)}),y&&s&&U===`device-provider`&&c(Re,{open:y,integrationId:s,addonId:j.addonId,onClose:()=>S(!1)}),w&&j&&c(Me,{open:w,scope:{addonId:j.addonId,label:j.name},onClose:()=>E(!1)}),ee&&s&&U!==null&&Y!==null&&c(Ze,{integrationId:s,addonId:j.addonId,name:j.name,kind:U,mode:Y,brokerKind:ye,canTest:be,trpc:_.trpcClient,onClose:()=>D(!1)}),O&&c(M,{open:!0,onOpenChange:e=>!e&&k(!1),children:a(ue,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,className:`md:max-w-5xl md:h-[80vh]`,children:[c(F,{className:`mb-0`,children:a(I,{className:`flex items-center gap-2 min-w-0`,children:[c(C,{className:`h-4 w-4 text-primary shrink-0`}),c(`span`,{className:`truncate`,children:j.name}),a(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate font-normal`,children:[j.addonId,s?` · ${s}`:``]})]})}),c(L,{className:`min-h-0 overflow-hidden p-0`,children:c(N,{addonId:j.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})})]}):a(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[c(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:c(A,{className:`h-6 w-6 text-foreground-subtle`})}),a(`div`,{className:`space-y-1 max-w-sm`,children:[c(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),c(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:s??``})})]}),a(`button`,{onClick:()=>f(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[c(m,{className:`h-3 w-3`}),e(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}function et({addonId:e}){let t=Se(e),[n,i]=r(!1);return!t||n?null:c(`img`,{src:t,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:()=>i(!0)})}export{$e as IntegrationDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{$ as e,B as t,G as n,J as r,O as i,R as a,S as o,b as s,o as c,q as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{An as d,Ii as f,Nt as p,V as m,Yt as h,bn as g,kn as _,lr as v,or as y,pn as b}from"./player-overlays-Fx6RE6kI.js";import{Kn as x}from"./client-yfOXPkcm.js";import{t as S}from"./settings-2-A0nya3CH.js";import{Bn as C,Br as w,Dt as ee,Et as te,Hn as T,In as E,Pr as D,Rt as O,Ut as k,sr as ne,zn as re}from"./src-AhVPNkCn.js";import{t as A}from"./useTranslation-D3Is_4B6.js";import{Q as j,Z as M,c as N,d as P,nt as F,o as I,r as L,s as R,u as z}from"./index-CcAR8Rlk.js";import{t as B}from"./AdminPage--m3xHpjx.js";import{t as V}from"./NodeAddonsSettingsPanel-BxeQZ-hu.js";import{t as H}from"./AddonAssetIcon-CCzVCA49.js";e();function U(e){let{ids:t,answered:r,legacyGroupParam:i=null,groupFirst:a}=e,[o]=F(),s=o.get(I),c=i===null?null:o.get(i),l=o.get(R),u=n(()=>z({ids:t,requested:s,answered:r,legacyGroup:c,...a===void 0?{}:{groupFirst:a}}),[t,s,r,c,a]),d=n(()=>(e,t)=>`?${P(o,e,i,t??null).toString()}`,[o,i]);return{...u,requestedSection:l,hrefFor:d}}var W=[[[`addons`,`listCapabilityProviders`]],[[`addons`,`list`]]],G=`text-[10px]`;function K({isActive:e}){let{t}=A();return u(ne,{variant:e?`success`:`default`,className:G,children:e?t(`integrationHub.addonControls.enabled`,`Enabled`):t(`integrationHub.addonControls.disabled`,`Disabled`)})}function q({capName:e,addonId:t,isActive:n}){let{t:r}=A(),i=c(),a=w({onSuccess:()=>{for(let e of W)i.invalidateQueries({queryKey:e})}}),s=a.isPending;return o(T,{size:`sm`,variant:n?`secondary`:`primary`,disabled:s,onClick:()=>a.mutate({capName:e,addonId:t,enabled:!n}),children:[s?u(y,{className:`h-3 w-3 animate-spin`}):u(n?h:d,{className:`h-3 w-3`}),n?r(`common.disable`,`Disable`):r(`common.enable`,`Enable`)]})}function ie({addonId:e,displayName:t}){let{t:n}=A(),r=c(),i=D({onSuccess:()=>{for(let e of W)r.invalidateQueries({queryKey:e})}});return u(O,{label:n(`integrationHub.addonControls.restart`,`Restart`),icon:g,size:`sm`,title:n(`integrationHub.addonControls.restart2`,`Restart "{{displayName}}"?`,{displayName:t}),description:n(`integrationHub.addonControls.restartingTheAddonBouncesIts`,`Restarting the addon bounces its subprocess — the provider will briefly drop and reconnect automatically.`),confirmLabel:n(`integrationHub.addonControls.restart`,`Restart`),triggerVariant:`ghost`,confirmVariant:`danger`,disabled:i.isPending,action:()=>i.mutateAsync({addonId:e})})}e();var J=600,Y=i(null);function X({id:e,title:t,icon:n,actions:r,framed:i=!1,children:c}){let{t:d}=A(),f=a(Y),p=l(null),h=`integration-section-${e}`;ae(p,f,e);let g=o(s,{children:[f===null?null:u(j,{to:f.sectionHref(e),"aria-label":d(`integrationHub.integrationSection.linkTo`,`Link to {{title}}`,{title:t}),title:d(`integrationHub.integrationSection.linkTo`,`Link to {{title}}`,{title:t}),className:`rounded p-0.5 text-foreground-subtle/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,children:u(v,{className:`h-3 w-3`,"aria-hidden":!0})}),r]});return i?u(`div`,{ref:p,className:`scroll-mt-4`,children:u(k,{headingId:h,title:t,icon:n,actions:g,children:c})}):o(`section`,{ref:p,"aria-labelledby":h,className:`scroll-mt-4 space-y-2`,children:[o(`header`,{className:`flex min-h-7 flex-wrap items-center gap-2 px-0.5`,children:[n!==void 0&&u(n,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`,"aria-hidden":!0}),u(`h2`,{id:h,className:`${m} min-w-0 flex-1`,children:t}),g]}),c]})}function ae(e,n,r){let i=n?.requestedSection===r,a=n?.integrationId;t(()=>{if(!i)return;let t=()=>e.current?.scrollIntoView?.({block:`start`});t();let n=!1,r=()=>{n=!0},a=[`wheel`,`touchmove`,`keydown`];for(let e of a)window.addEventListener(e,r,{once:!0,passive:!0});let o=window.setTimeout(()=>{n||t()},J);return()=>{window.clearTimeout(o);for(let e of a)window.removeEventListener(e,r)}},[i,a,e])}e();var Z=`max-h-72`;function oe({addonId:e,displayName:t,capName:n,isActive:r,badges:i,primaryAction:a,error:s=null,lead:c,panels:l=[],settingsContent:d}){let{t:f}=A(),p=l.filter(e=>e.placement!==`end`),m=l.filter(e=>e.placement===`end`);return o(`div`,{className:`flex flex-col gap-4`,children:[u(se,{addonId:e,displayName:t,capName:n,isActive:r,badges:i,primaryAction:a}),s!==null&&u(re,{message:s}),c,u(Q,{panels:p}),u(X,{id:N,title:f(`integrationHub.addonIntegrationBody.settings`,`Settings`),icon:S,children:d===void 0?u(V,{nodeId:`hub`,addonIds:[e],level:`global`,capability:n}):d}),u(le,{addonId:e}),u(Q,{panels:m})]})}function Q({panels:e}){return u(s,{children:e.map(e=>u(X,{id:e.id,title:e.title,icon:e.icon,children:e.content},e.id))})}function se({addonId:e,displayName:t,capName:n,isActive:r,badges:i,primaryAction:a}){return o(`div`,{className:`flex flex-wrap items-center justify-between gap-2 rounded-lg border border-border bg-surface px-2 py-1.5 sm:px-3`,"data-testid":`integration-status-strip`,children:[o(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[u(K,{isActive:r}),i,u(`span`,{className:`break-all font-mono text-[11px] text-foreground-subtle`,children:e})]}),o(`div`,{className:`flex flex-wrap items-center justify-end gap-1`,children:[a,u(q,{capName:n,addonId:e,isActive:r}),u(ie,{addonId:e,displayName:t})]})]})}var ce=[{kind:`logs`,labelKey:`common.logs`,icon:b},{kind:`events`,labelKey:`common.events`,icon:f}];function le({addonId:e}){let{t}=A(),[n,i]=r(`logs`);return u(X,{id:L,title:t(`integrationHub.addonIntegrationBody.activity`,`Activity`),framed:!0,actions:u(`div`,{role:`group`,"aria-label":t(`integrationHub.addonIntegrationBody.activityStream`,`Activity stream`),className:`flex items-center gap-1`,children:ce.map(({kind:e,labelKey:r,icon:a})=>o(`button`,{type:`button`,"aria-pressed":n===e,onClick:()=>i(e),className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium transition-colors ${n===e?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[u(a,{className:`h-3 w-3`,"aria-hidden":!0}),t(r)]},e))}),children:n===`logs`?u(ee,{addonId:e,maxHeight:Z,showFilters:!1}):u(te,{addonId:e,category:`addon.*`,maxHeight:Z})})}var ue=`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,de=`border-primary bg-primary/10 text-primary font-medium`,fe=`border-border bg-surface text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,pe={ok:`bg-success`,off:`bg-foreground-subtle/60`,error:`bg-danger`,unknown:`border border-foreground-subtle bg-transparent`};function $({label:e,groups:t,selectedId:n,hrefFor:r}){let i=t.length>1;return u(`nav`,{"aria-label":e,className:i?`flex flex-col gap-2 sm:grid sm:grid-cols-[max-content_minmax(0,1fr)] sm:items-start sm:gap-x-3`:`flex flex-col`,children:t.map(e=>o(`div`,{role:`group`,"aria-label":e.label,className:i?`flex min-w-0 flex-col gap-1 sm:col-span-2 sm:grid sm:grid-cols-subgrid sm:items-start`:`min-w-0`,children:[i&&u(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle sm:pt-2`,children:e.label}),o(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[e.entries.map(e=>u(me,{entry:e,current:e.id===n,href:r(e.id)},e.id)),e.install&&o(j,{to:x(e.install.capability),className:`inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-full border py-1 pl-1 pr-2.5 text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 border-dashed border-border pl-2 text-foreground-subtle hover:border-primary/50 hover:text-foreground`,children:[u(_,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":!0}),u(`span`,{className:`truncate`,children:e.install.label})]})]})]},e.id))})}function me({entry:e,current:t,href:n}){let r=e.state===`ok`;return o(j,{to:n,"aria-current":t?`true`:void 0,className:`${ue} ${t?de:fe}`,"data-testid":`integration-pill-${e.id}`,children:[u(H,{addonId:e.id,fallback:e.fallbackIcon,tileClassName:``,size:`sm`}),u(`span`,{className:`truncate`,children:e.name}),e.showState!==!1&&u(he,{entry:e,quiet:r})]})}function he({entry:e,quiet:t}){return o(s,{children:[u(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${pe[e.state]}`,"aria-hidden":!0}),u(`span`,{className:t?`sr-only`:`shrink-0 text-[10px] font-normal text-foreground-subtle`,children:e.stateLabel})]})}e();function ge({icon:e,title:t,subtitle:r,groups:i,isLoading:a,emptyTitle:c,emptyDescription:l,legacyGroupParam:d,trailing:f,embedded:p=!1}){let{t:m}=A(),h=n(()=>i.flatMap(e=>e.entries),[i]),g=n(()=>h.map(e=>e.id),[h]),_=n(()=>{let e={};for(let t of i){let n=t.entries[0];n!==void 0&&(e[t.id]=n.id)}return e},[i]),v=U({ids:g,answered:!a,legacyGroupParam:d??null,groupFirst:_}),y=h.find(e=>e.id===v.selectedId)??null,b=n(()=>y===null?null:{integrationId:y.id,requestedSection:v.requestedSection,sectionHref:e=>v.hrefFor(y.id,e)},[y,v]),x=a?null:u($,{label:m(`integrationHub.integrationHub.integrations`,`{{title}} integrations`,{title:t}),groups:i,selectedId:v.selectedId,hrefFor:e=>v.hrefFor(e)}),S=a?u(E,{children:u(`div`,{className:`p-6 text-sm text-foreground-subtle`,children:m(`common.loading`,`Loading…`)})}):o(s,{children:[v.staleId!==null&&u(ve,{staleId:v.staleId,shownName:y?.name??null}),y!==null&&b!==null?u(Y.Provider,{value:b,children:u(`div`,{role:`region`,"aria-label":y.name,"data-testid":`integration-body`,children:y.render()},y.id)}):u(_e,{groups:i,title:c,description:l}),f]});return p?o(`div`,{className:`space-y-3`,"data-testid":`integration-hub-embedded`,children:[x,S]}):u(B,{icon:e,title:t,subtitle:r,nav:x,children:S})}function _e({groups:e,title:t,description:n}){let r=e.find(e=>e.install!==void 0)?.install;return u(E,{children:u(C,{title:t,description:n,action:r?u(j,{to:x(r.capability),children:o(T,{variant:`primary`,size:`sm`,children:[u(_,{className:`mr-1 h-3.5 w-3.5`}),r.label]})}):void 0})})}function ve({staleId:e,shownName:t}){let{t:n}=A();return o(`div`,{role:`status`,className:`flex items-start gap-2 rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-[11px] text-foreground-subtle`,children:[u(p,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-warning`,"aria-hidden":!0}),o(`span`,{children:[u(M,{i18nKey:`integrationHub.staleIntegration.notice`,values:{id:e},components:{mono:u(`span`,{className:`font-mono text-foreground`})}}),t!==null&&o(s,{children:[` `,u(M,{i18nKey:`integrationHub.staleIntegration.showing`,values:{name:t},components:{b:u(`span`,{className:`font-medium text-foreground`})}})]})]})]})}export{U as i,oe as n,G as r,ge as t};
|