@camstack/addon-admin-ui 1.2.477 → 1.2.479
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/Addons-2bVk9gQP.js +5 -0
- package/dist/assets/{AdminSectionedPage-DtiHBXGC.js → AdminSectionedPage-5g5LDrXG.js} +1 -1
- package/dist/assets/{AiProfiles-7FToWDqj.js → AiProfiles-CjexfGhj.js} +1 -1
- package/dist/assets/{BrokerForm-D5-q8F_8.js → BrokerForm-Behibhry.js} +1 -1
- package/dist/assets/{Build-DwW5kYsa.js → Build-EtMIMKRO.js} +3 -3
- package/dist/assets/{Calendars-BhMRY6EV.js → Calendars-DH3P_u96.js} +1 -1
- package/dist/assets/{Cluster-z11q6anB.js → Cluster-CFnD0vXf.js} +1 -1
- package/dist/assets/{CompositionBlockEditor-CElNVsCR.js → CompositionBlockEditor-BsmLsHO7.js} +1 -1
- package/dist/assets/{CompositionEditorPage-NzgZB76B.js → CompositionEditorPage-DbFLOjT0.js} +1 -1
- package/dist/assets/{Data-D_U-HkwO.js → Data-DaycWn5V.js} +2 -2
- package/dist/assets/{DeviceDetail-D89wXQHP.js → DeviceDetail-DABbOvpp.js} +2 -2
- package/dist/assets/{DeviceDoActionFields-Bj4gX0r-.js → DeviceDoActionFields-DESERgis.js} +1 -1
- package/dist/assets/{Devices-BnhDZU3y.js → Devices-e9WRZF8o.js} +1 -1
- package/dist/assets/{HelperWizard-CrXHYd19.js → HelperWizard-B5Evcb8G.js} +1 -1
- package/dist/assets/{History-BsJBR2zt.js → History-CUBYC5vJ.js} +1 -1
- package/dist/assets/{Identity-B_6I_sCY.js → Identity-YiQC97gk.js} +1 -1
- package/dist/assets/IntegrationDetail-LZqy5tnJ.js +1 -0
- package/dist/assets/{IntegrationHub-CSaA690G.js → IntegrationHub-oKQf8Hqh.js} +1 -1
- package/dist/assets/Integrations-Bb8hbB7-.js +1 -0
- package/dist/assets/Integrations-CSF7awEo.js +1 -0
- package/dist/assets/{Library-3dGkOQB5.js → Library-CLum5n0h.js} +1 -1
- package/dist/assets/{Locations-Bh5GRDCv.js → Locations-CyGnajVJ.js} +1 -1
- package/dist/assets/{Logs-diqSxXEc.js → Logs-DTwpZ7zU.js} +1 -1
- package/dist/assets/{MyAccess-BqulMSGv.js → MyAccess--2ZT-HhR.js} +1 -1
- package/dist/assets/{Network-C8Gpb2Vn.js → Network-DAts0LIq.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-Dq6sGWkR.js → NodeAddonsSettingsPanel-96SuINk0.js} +1 -1
- package/dist/assets/{Notifications-C5w5t75z.js → Notifications-BLt2f-nc.js} +1 -1
- package/dist/assets/{Pipeline-CjumfHMc.js → Pipeline-Bn9VYb0p.js} +1 -1
- package/dist/assets/{Recordings-DE76fgEt.js → Recordings-vrFJrZh0.js} +1 -1
- package/dist/assets/ScanNetworkModal-u-7qAdO5.js +1 -0
- package/dist/assets/{SessionsList-Ca-zN1Fi.js → SessionsList-DJR70bvB.js} +1 -1
- package/dist/assets/{Showroom-B9HZ38O5.js → Showroom-CK5L2uo3.js} +1 -1
- package/dist/assets/{System-CHEbMPI_.js → System-Bp5NGMuQ.js} +1 -1
- package/dist/assets/{Terminal-CWFZuQLg.js → Terminal-BnNXFsMP.js} +1 -1
- package/dist/assets/{assignment-candidates-BcnFMc1B.js → assignment-candidates-BMhC6h3l.js} +1 -1
- package/dist/assets/{board-model-gmvqxkjB.js → board-model--9Jw6SCm.js} +1 -1
- package/dist/assets/{device-integration-icon-0oWIIjcP.js → device-integration-icon-CdgkjIk4.js} +1 -1
- package/dist/assets/{format-CIO4xeN9.js → format-fYneBFV6.js} +1 -1
- package/dist/assets/i18n-D0o08mg-.js +1 -0
- package/dist/assets/{index-D4ZlWCxy.css → index-D4id__eL.css} +1 -1
- package/dist/assets/index-D_Tm4B7S.js +4 -0
- package/dist/assets/{linked-devices-model-BoOq02QT.js → linked-devices-model-DMEJU3bE.js} +1 -1
- package/dist/assets/{location-owned-usage-IF2k-L3A.js → location-owned-usage-BqMUhVoi.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-f45a46c2.js → mf-entry-bootstrap-0-e328376a.js} +1 -1
- package/dist/assets/{step-inspector-model-CyqFN-LU.js → step-inspector-model-G2bS8NkA.js} +1 -1
- package/dist/assets/{useNodeUrlSelection-DGV2ltbG.js → useNodeUrlSelection-XYqqUh3q.js} +1 -1
- package/dist/index.html +4 -4
- package/dist/server/addon.js +1 -1
- package/package.json +1 -1
- package/dist/assets/Addons-CbHidHOJ.js +0 -5
- package/dist/assets/IntegrationDetail-B9L7AfYy.js +0 -1
- package/dist/assets/Integrations-B-KtSB_m.js +0 -1
- package/dist/assets/Integrations-CMW4LOX-.js +0 -1
- package/dist/assets/ScanNetworkModal-DXzDOpxk.js +0 -1
- package/dist/assets/i18n-xhwARoF0.js +0 -1
- package/dist/assets/index-C3uCLHv0.js +0 -4
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,a as s,et as c,o 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-CEyXHAdg.js";import{Fn as f,It as p,On as m,ht as h,kn as g,ln as _,nr as v,or as y,ot as b,xn as x}from"./player-overlays-Dbv95cvz.js";import{Ci as S,Jr as ee,en as C}from"./client-DvJxGh2F.js";import{h as w,s as T}from"./video-D7jv0spx.js";import{t as E}from"./log-in-D1BPSCDn.js";import{t as D}from"./monitor-smartphone-6w2T5Ht_.js";import{t as te}from"./recycle-DcScXiTi.js";import{$r as O,Ar as ne,At as k,Dr as A,Ia as j,Kr as M,Si as N,Wr as re,ca as P,cr as ie,da as F,dt as ae,fa as I,gr as L,gt as oe,ha as R,hr as z,jl as B,kt as se,ma as V,mr as H,mt as ce,pa as le,pr as U,sa as W,ua as G,vr as ue,wn as de,yr as fe}from"./src-DntJrWmU.js";import{t as K}from"./i18n-xhwARoF0.js";import{t as q}from"./useTranslation-BJr-n0es.js";import{P as J,fr as pe,h as Y,i as me,mr as he,x as ge}from"./index-C3uCLHv0.js";import{t as _e}from"./AdminSectionedPage-DtiHBXGC.js";import{t as ve}from"./BrokerForm-D5-q8F_8.js";import{t as ye}from"./NodeAddonsSettingsPanel-Dq6sGWkR.js";import{n as be,r as X,t as xe}from"./IntegrationHub-CSaA690G.js";c();var Z=`kind`,Q=`name`,Se=`restore`,Ce=`restoreId`;function we(e){return{sections:[{id:`broker-identity`,title:K.t(`helpers.brokerIdentitySchema.title`),columns:1,fields:[{type:`select`,key:Z,label:K.t(`helpers.brokerIdentitySchema.kind`),options:e.map(e=>({value:e.key,label:e.label})),disabled:e.length<=1},{type:`text`,key:Q,label:K.t(`helpers.brokerIdentitySchema.name`),placeholder:K.t(`helpers.brokerIdentitySchema.namePlaceholder`),required:!0},{type:`boolean`,key:Se,label:K.t(`helpers.brokerIdentitySchema.restore`),description:K.t(`helpers.brokerIdentitySchema.restoreHint`)},{type:`text`,key:Ce,label:K.t(`helpers.brokerIdentitySchema.originalId`),placeholder:`ha_004`,required:!0,showWhen:{field:Se,equals:!0}}]}]}}function Te(e){let t=t=>{let n=e[t];return typeof n==`string`?n.trim():``},n=t(Z);if(n===``)return{ok:!1,problem:`Pick a kind.`};let r=t(Q);if(r===``)return{ok:!1,problem:`Enter a name before saving.`};if(e.restore!==!0)return{ok:!0,identity:{kindKey:n,name:r,restoreId:null}};let i=t(Ce);return i===``?{ok:!1,problem:`Enter the original id, or turn restore off to create a new broker.`}:{ok:!0,identity:{kindKey:n,name:r,restoreId:i}}}var Ee={"home-assistant":`Home Assistant`,mqtt:`MQTT`};function De(e){return Ee[e]??e}function Oe(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var ke={connected:`success`,connecting:`warning`,disconnected:`default`,"auth-failed":`danger`,unreachable:`danger`,error:`danger`};function Ae({status:e}){return i(O,{variant:ke[e],className:`text-[10px]`,children:e})}function je(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function Me({title:t,subtitle:n,onClose:r,children:a}){return i(U,{open:!0,onOpenChange:e=>!e&&r(),children:e(z,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[e(ue,{children:[i(fe,{children:t}),n&&i(L,{children:n})]}),i(H,{className:`space-y-3 pr-1`,children:a})]})})}function Ne({kinds:t,onClose:r,onDone:a}){let{t:s}=q(),c=l(),u=n(()=>we(t.map(e=>({key:$(e),label:e.label}))),[t]),[d,f]=o(()=>({[Z]:$(t[0]),[Q]:``,[Se]:!1,[Ce]:``})),[p,m]=o(null),h=t.find(e=>$(e)===d.kind)??t[0],g=h?.kind??``,_=h?.addonId,v=h?.interactiveConnectPath,y=W({onSuccess:e=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]});let t=typeof e==`object`&&e&&typeof e.id==`string`?e.id:null;t!==null&&v!==void 0&&v.length>0&&Y(v,t,()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]})}),a()}}),b=e=>{let t=Te(d);if(!t.ok){m(t.problem);return}m(null);let{name:n,restoreId:r}=t.identity;y.mutate({kind:g,name:n,settings:e,...r===null?{}:{id:r},..._===void 0?{}:{addonId:_}})};return e(Me,{title:s(`brokers.brokerManager.addBroker`,`Add broker`),subtitle:s(`brokers.brokerManager.registerAMessageBrokerFor`,`Register a message broker for exporters and automations.`),onClose:y.isPending?()=>{}:r,children:[i(J,{schema:u,values:d,onChange:f}),p!==null&&i(A,{message:p}),y.isError&&i(A,{message:y.error instanceof Error?y.error.message:String(y.error)}),g&&i(ve,{kind:g,..._===void 0?{}:{addonId:_},onSubmit:b,onCancel:r,submitLabel:y.isPending?s(`brokers.brokerManager.adding`,`Adding…`):s(`brokers.brokerManager.addBroker`,`Add broker`),disabled:y.isPending},$(h))]})}function $(e){return e===void 0?``:`${e.addonId??``}::${e.kind}`}function Pe({broker:t,onClose:r,onDone:a}){let{t:o}=q(),s=l(),c=P({id:t.id,addonId:t.addonId}),u=V({onSuccess:()=>{s.invalidateQueries({queryKey:[[`broker`,`list`]]}),s.invalidateQueries({queryKey:[[`broker`,`getSettings`],{input:{id:t.id,addonId:t.addonId}}]}),a()}}),d=n(()=>{let e=c.data;return e&&typeof e==`object`?{...e}:{}},[c.data]);return i(Me,{title:o(`brokers.brokerManager.edit`,`Edit {{name}}`,{name:t.name}),subtitle:`${De(t.kind)} · ${t.id}`,onClose:u.isPending?()=>{}:r,children:c.isLoading?e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(y,{className:`h-3.5 w-3.5 animate-spin`}),` `,o(`brokers.brokerManager.loadingSettings`)]}):c.isError?e(`div`,{className:`space-y-3`,children:[i(A,{message:o(`brokers.brokerManager.loadSettingsFailed`,{message:c.error instanceof Error?c.error.message:o(`common.unknownError`)})}),i(`div`,{className:`flex justify-end`,children:i(M,{variant:`outline`,size:`sm`,onClick:r,children:o(`common.close`,`Close`)})})]}):e(`div`,{className:`space-y-3`,children:[u.isError&&i(A,{message:u.error instanceof Error?u.error.message:String(u.error)}),i(ve,{kind:t.kind,addonId:t.addonId,brokerId:t.id,initialValues:d,onSubmit:e=>{u.mutate({id:t.id,settings:e,addonId:t.addonId})},onCancel:r,submitLabel:u.isPending?o(`brokers.brokerManager.saving`,`Saving…`):o(`common.save`,`Save`),disabled:u.isPending})]})})}function Fe({broker:t,interactiveConnectPath:n,interactiveDisconnectPath:r,onEdit:a}){let{t:s}=q(),c=l(),u=re(),[d,m]=o(null),g=R({onSuccess:e=>m(e.ok?{ok:!0}:{ok:!1,error:e.error}),onError:e=>m({ok:!1,error:e instanceof Error?e.message:String(e)})}),_=le({onSuccess:()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]})}}),v=async()=>{await u({title:s(`brokers.brokerManager.deleteBroker`,`Delete broker`),message:s(`brokers.brokerManager.deleteBrokerIntegrationsThatDepend`,`Delete broker "{{name}}"? Integrations that depend on it will stop working.`,{name:t.name}),confirmLabel:s(`common.delete`,`Delete`),variant:`danger`})&&_.mutate({id:t.id,addonId:t.addonId})},b=n!==void 0&&n.length>0&&t.status!==`connected`,x=r!==void 0&&r.length>0&&t.status===`connected`;return e(`tr`,{className:`border-b border-border last:border-0`,children:[i(`td`,{className:`px-3 py-2 text-xs text-foreground font-medium`,children:t.name}),i(`td`,{className:`px-3 py-2 text-xs text-foreground-subtle`,children:De(t.kind)}),e(`td`,{className:`px-3 py-2`,children:[i(Ae,{status:t.status}),d&&i(`span`,{className:`ml-2 text-[10px] ${d.ok?`text-success`:`text-danger`}`,children:d.ok?`OK`:d.error??s(`common.failedWord`)})]}),i(`td`,{className:`px-3 py-2`,children:e(`div`,{className:`flex items-center justify-end gap-1.5`,children:[b&&e(M,{variant:`primary`,size:`sm`,onClick:()=>{Y(n,t.id,()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]})})},title:s(`brokers.brokerManager.signInOpensAPopup`,`Sign in — opens a popup that closes when done`),children:[i(E,{className:`h-3 w-3`}),` `,s(`brokers.brokerManager.signIn`)]}),x&&e(M,{variant:`outline`,size:`sm`,onClick:()=>{Y(r,t.id,()=>{c.invalidateQueries({queryKey:[[`broker`,`list`]]})})},title:s(`brokers.brokerManager.signOutClearsTheLinked`,`Sign out — clears the linked Google account on this broker`),children:[i(T,{className:`h-3 w-3`}),` `,s(`brokers.brokerManager.signOut`)]}),e(M,{variant:`outline`,size:`sm`,onClick:()=>g.mutate({id:t.id,addonId:t.addonId}),disabled:g.isPending,title:s(`brokers.brokerManager.testConnection`,`Test connection`),children:[g.isPending?i(y,{className:`h-3 w-3 animate-spin`}):i(h,{className:`h-3 w-3`}),s(`brokers.brokerManager.test`,`Test`)]}),e(M,{variant:`outline`,size:`sm`,onClick:()=>a(t),title:s(`common.edit`,`Edit`),children:[i(f,{className:`h-3 w-3`}),` `,s(`common.edit`)]}),e(M,{variant:`outline`,size:`sm`,className:`border-danger/40 text-danger hover:bg-danger/10`,onClick:()=>{v()},disabled:_.isPending,title:s(`common.delete`,`Delete`),children:[_.isPending?i(y,{className:`h-3 w-3 animate-spin`}):i(p,{className:`h-3 w-3`}),s(`common.delete`,`Delete`)]})]})})]})}function Ie({addonId:t}={}){let{t:r}=q(),a=F({}),s=I(),c=n(()=>je(a.data).filter(e=>t===void 0||e.addonId===t),[a.data,t]),[l,u]=o(!1),[d,f]=o(null),p=n(()=>{let e=new Map;for(let n of Oe(s.data))if(!(t!==void 0&&n.addonId!==t))for(let t of n.kinds){let r=typeof t.interactiveConnectPath==`string`&&t.interactiveConnectPath.length>0?t.interactiveConnectPath:void 0,i=typeof t.interactiveDisconnectPath==`string`&&t.interactiveDisconnectPath.length>0?t.interactiveDisconnectPath:void 0;e.set(`${n.addonId}::${t.kind}`,{addonId:n.addonId,kind:t.kind,label:t.label,...r===void 0?{}:{interactiveConnectPath:r},...i===void 0?{}:{interactiveDisconnectPath:i}})}for(let t of c)[...e.values()].some(e=>e.kind===t.kind)||e.set(`::${t.kind}`,{kind:t.kind,label:De(t.kind)});return[...e.values()]},[c,s.data,t]),m=n(()=>{let e=new Map;for(let t of p)e.has(t.kind)||e.set(t.kind,{...t.interactiveConnectPath===void 0?{}:{connect:t.interactiveConnectPath},...t.interactiveDisconnectPath===void 0?{}:{disconnect:t.interactiveDisconnectPath}});return e},[p]);return e(`div`,{className:`space-y-3`,children:[i(`div`,{className:`flex items-center justify-end`,children:e(M,{variant:`primary`,size:`sm`,onClick:()=>u(!0),disabled:p.length===0,title:p.length===0?r(`brokers.brokerManager.noBrokerProvidersAvailable`,`No broker providers available`):void 0,children:[i(g,{className:`h-3.5 w-3.5`}),` `,r(`brokers.brokerManager.addBroker`)]})}),i(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:e(`table`,{className:`w-full min-w-[36rem] border-collapse`,children:[i(`thead`,{children:e(`tr`,{className:`border-b border-border bg-background/50`,children:[i(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:r(`brokers.brokerManager.name`,`Name`)}),i(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:r(`brokers.brokerManager.kind`,`Kind`)}),i(`th`,{className:`px-3 py-2 text-left text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:r(`brokers.brokerManager.status`,`Status`)}),i(`th`,{className:`px-3 py-2 text-right text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:r(`brokers.brokerManager.actions`,`Actions`)})]})}),e(`tbody`,{children:[a.isLoading&&i(`tr`,{children:e(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:[i(y,{className:`inline h-4 w-4 animate-spin`}),` `,r(`brokers.brokerManager.loadingBrokers`)]})}),a.isError&&i(`tr`,{children:e(`td`,{colSpan:4,className:`px-3 py-4 text-center text-xs text-danger`,children:[r(`brokers.brokerManager.failedToLoadBrokers`,`Failed to load brokers:`),` `,a.error instanceof Error?a.error.message:r(`brokers.brokerManager.unknownError`,`Unknown error`)]})}),!a.isLoading&&!a.isError&&c.length===0&&i(`tr`,{children:i(`td`,{colSpan:4,className:`px-3 py-6 text-center text-xs text-foreground-subtle`,children:r(`brokers.brokerManager.noBrokersRegisteredYetAdd`,`No brokers registered yet. Add one to publish device events for downstream automations.`)})}),c.map(e=>{let t=m.get(e.kind);return i(Fe,{broker:e,...t?.connect===void 0?{}:{interactiveConnectPath:t.connect},...t?.disconnect===void 0?{}:{interactiveDisconnectPath:t.disconnect},onEdit:f},e.id)})]})]})}),l&&i(Ne,{kinds:p,onClose:()=>u(!1),onDone:()=>u(!1)}),d&&i(Pe,{broker:d,onClose:()=>f(null),onDone:()=>f(null)})]})}c();function Le({addonId:e,fallback:t}){let{t:n}=q(),r=B({});if(r.isPending)return i(`div`,{className:`flex justify-center py-8`,children:i(y,{className:`size-6 animate-spin text-muted-foreground`})});if(r.isError)return i(A,{message:n(`brokers.brokerRecordEntriesPanel.loadKindsFailed`,`Could not load entry kinds`)});let a=r.data.kinds.find(t=>t.owner===e&&t.kind===`brokers`);return a===void 0?t:i(Re,{addonId:e,kind:a})}function Re({addonId:t,kind:r}){let{t:a}=q(),o=l(),s=F({}),c=I(),u=n(()=>{let e=new Map;for(let n of je(s.data))n.addonId===t&&e.set(n.id,n);return e},[s.data,t]),f=n(()=>{let e=new Map;for(let t of Oe(c.data))for(let n of t.kinds){let r=n.interactiveConnectPath,i=n.interactiveDisconnectPath;e.set(`${t.addonId}::${n.kind}`,{...typeof r==`string`&&r.length>0?{connect:r}:{},...typeof i==`string`&&i.length>0?{disconnect:i}:{}})}return e},[c.data]),p=()=>{o.invalidateQueries({queryKey:[[`broker`]]}),o.invalidateQueries({queryKey:[[`recordEntries`]]})};return i(ae,{kind:r,extraColumns:n(()=>[{key:`status`,header:a(`brokers.brokerManager.status`,`Status`),nowrap:!0,width:`w-px`,render:e=>{let t=u.get(e.id);return t===void 0?null:i(Ae,{status:t.status})}}],[u,a]),rowActions:t=>{let n=u.get(t.id);if(n===void 0)return null;let r=f.get(`${n.addonId}::${n.kind}`);if(r===void 0)return null;let o=n.status===`connected`;return e(d,{children:[r.connect!==void 0&&!o&&e(M,{variant:`primary`,size:`sm`,"aria-label":a(`brokers.brokerManager.signIn`),onClick:()=>Y(r.connect??``,n.id,p),title:a(`brokers.brokerManager.signInOpensAPopup`,`Sign in — opens a popup that closes when done`),children:[i(E,{className:`h-3 w-3`}),i(`span`,{className:`hidden sm:inline`,children:a(`brokers.brokerManager.signIn`)})]}),r.disconnect!==void 0&&o&&e(M,{variant:`outline`,size:`sm`,"aria-label":a(`brokers.brokerManager.signOut`),onClick:()=>Y(r.disconnect??``,n.id,p),title:a(`brokers.brokerManager.signOutClearsTheLinked`,`Sign out — clears the linked Google account on this broker`),children:[i(T,{className:`h-3 w-3`}),i(`span`,{className:`hidden sm:inline`,children:a(`brokers.brokerManager.signOut`)})]})]})},showUpdated:!1,minWidthPx:340})}function ze(e){if(typeof e==`string`)return e;if(typeof e==`object`&&e){let t=e.name;if(typeof t==`string`)return t}return null}function Be(e){let t=e,n=t?.manifest;if(n?.id===void 0)return null;let r=(n.capabilities??[]).map(ze).filter(e=>e!==null);return{addonId:n.id,displayName:n.packageDisplayName??n.name??n.id,capNames:r,processState:t?.process?.state??null}}function Ve(e,t){return Object.entries(e).filter(([,e])=>e===t).map(([e])=>e)}function He(e,t){return t.find(t=>e.capNames.includes(t))??null}function Ue(e){switch(e){case`running`:return{state:`ok`,label:K.t(`helpers.connectivityModel.running`)};case`crashed`:case`failed`:return{state:`error`,label:e};case`stopped`:case`disabled`:return{state:`off`,label:K.t(`helpers.connectivityModel.stopped`)};default:return{state:`unknown`,label:e??K.t(`common.unknownWord`)}}}c();var We=[`wasteCollections`,`listSources`],Ge=[`wasteCollections`,`listCountries`];function Ke(e){return e instanceof Error?e.message:String(e)}function qe(e){return typeof e!=`object`||!e?!1:Array.isArray(Reflect.get(e,`sections`))}function Je(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n!=`object`||!n)continue;let e=Reflect.get(n,`id`),r=Reflect.get(n,`label`),i=Reflect.get(n,`module`);if(typeof e!=`string`||typeof r!=`string`||typeof i!=`string`)continue;let a=Reflect.get(n,`enabled`),o=Reflect.get(n,`formValues`),s=Reflect.get(n,`serviceId`),c=Reflect.get(n,`countryId`);t.push({id:e,label:r,module:i,enabled:typeof a==`boolean`?a:!0,formValues:typeof o==`object`&&o&&!Array.isArray(o)?o:void 0,serviceId:typeof s==`string`?s:void 0,countryId:typeof c==`string`?c:void 0})}return t}function Ye(e){return Array.isArray(e)?e.flatMap(e=>{if(typeof e!=`object`||!e)return[];let t=Reflect.get(e,`id`),n=Reflect.get(e,`label`);return typeof t!=`string`||typeof n!=`string`?[]:[{id:t,label:n}]}):[]}function Xe(e){return Array.isArray(e)?e.flatMap(e=>{if(typeof e!=`object`||!e)return[];let t=Reflect.get(e,`id`),n=Reflect.get(e,`label`),r=Reflect.get(e,`module`);if(typeof t!=`string`||typeof n!=`string`||typeof r!=`string`)return[];let i=Reflect.get(e,`title`);return[{id:t,label:n,title:typeof i==`string`&&i.length>0?i:n,module:r}]}):[]}function Ze(e,t,n){return{sections:[{id:`picker`,title:K.t(`system.wasteSettingsSources.countryService`,`Country & service`),columns:2,fields:[{type:`select`,key:`countryId`,label:K.t(`system.wasteSettingsSources.country`,`Country`),options:[{value:``,label:K.t(`system.wasteSettingsSources.selectCountry`,`Select country…`)},...e.map(e=>({value:e.id,label:e.label}))]},{type:`select`,key:`serviceId`,label:K.t(`system.wasteSettingsSources.service`,`Service`),options:[{value:``,label:n===``?K.t(`system.wasteSettingsSources.pickACountryFirst`,`Pick a country first`):K.t(`system.wasteSettingsSources.selectService`,`Select service…`)},...t.map(e=>({value:e.id,label:e.label}))]}]}]}}function Qe({addonId:c,capName:f}){let{t:m}=q(),h=b(),_=l(),v=re(),y=ce({editKey:`wasteEdit`,newKey:`wasteNew`}),[x,S]=o(!1),[ee,C]=o(null),[w,T]=o({countryId:``,serviceId:``}),[E,D]=o({label:m(`system.wasteSettingsSources.newSource`,`New source`),enabled:!0}),k=t(null),A=typeof w.countryId==`string`?w.countryId:``,j=typeof w.serviceId==`string`?w.serviceId:``,N=r((e,t)=>h.trpcClient.addons.custom.mutate({addonId:c,action:e,input:t}),[c,h]),P=s({queryKey:[...We,c],queryFn:async()=>Je(await N(`listSources`,{}))}),F=s({queryKey:[...Ge,c],queryFn:async()=>Ye(await N(`listCountries`,{}))}),ae=s({queryKey:[`wasteCollections`,`listServices`,c,A],enabled:A!==``,queryFn:async()=>Xe(await N(`listServices`,{countryId:A}))}),I=s({queryKey:[`wasteCollections`,`serviceFormSchema`,c,j],enabled:j!==``,queryFn:async()=>N(`serviceFormSchema`,{serviceId:j})}),L=P.data??[],R=F.data??[],z=ae.data??[],B=qe(I.data)?I.data:void 0,se=n(()=>Ze(R,A===``?[]:z,A),[R,z,A]),V=y.state,H=V.mode===`edit`?L.find(e=>e.id===V.id)??null:null;a(()=>{if(y.state.mode===`edit`&&H!==null){let e=`edit:${H.id}`;if(k.current===e)return;k.current=e,C(null),T({countryId:H.countryId??``,serviceId:H.serviceId??``}),D(H.formValues===void 0?{label:H.label,enabled:H.enabled}:{...H.formValues});return}if(y.state.mode===`new`){if(k.current===`new`)return;k.current=`new`,C(null),T({countryId:``,serviceId:``}),D({label:m(`system.wasteSettingsSources.newSource`,`New source`),enabled:!0})}},[H,y.state]),a(()=>{if(y.state.mode!==`new`||j===``)return;let e=z.find(e=>e.id===j);e&&D(t=>{let n=t.label;return typeof n==`string`&&n!==``&&n!==`New source`?t:{...t,label:e.title}})},[y.state.mode,j,z]);let le=r(e=>{T(t=>{let n=typeof e.countryId==`string`?e.countryId:``;return n===(typeof t.countryId==`string`?t.countryId:``)?e:{countryId:n,serviceId:``}})},[]),U=r(async()=>{await _.invalidateQueries({queryKey:We})},[_]),W=u({mutationFn:async e=>N(`deleteSource`,{id:e}),onSuccess:async()=>U()}),G=r(async e=>{await v({title:m(`system.wasteSettingsSources.deleteWasteSource`,`Delete waste source?`),message:m(`system.wasteSettingsSources.removeItsCalendarUnderSystem`,`Remove “{{label}}” ({{id}}). Its calendar under System → Calendars is dropped.`,{label:e.label,id:e.id}),confirmLabel:m(`common.delete`,`Delete`),cancelLabel:m(`common.cancel`,`Cancel`),variant:`danger`})&&(await W.mutateAsync(e.id),y.state.mode===`edit`&&y.state.id===e.id&&(y.close(),k.current=null))},[v,W,y,m]),ue=r(async()=>{let e=E.label,t=typeof e==`string`&&e.trim()!==``?e.trim():``;if(t===``){C(`Label is required.`);return}if(j===``){C(`Pick a country and a service.`);return}let n=y.state.mode===`new`,r=H?.id;if(!n&&(r===void 0||r===``)){C(`That source is no longer available.`);return}let i=E.enabled,a={...E};delete a.label,delete a.enabled,S(!0),C(null);try{n?await N(`createSource`,{label:t,serviceId:j,args:a,enabled:typeof i==`boolean`?i:!0}):r!==void 0&&await N(`updateSource`,{id:r,label:t,serviceId:j,args:a,enabled:typeof i==`boolean`?i:!0}),await U(),y.close(),k.current=null}catch(e){C(Ke(e))}finally{S(!1)}},[N,H,y,E,U,j]),fe=n(()=>[{key:`label`,header:m(`system.wasteSettingsSources.label`,`Label`),sortValue:e=>e.label,render:e=>i(`span`,{className:`text-sm text-foreground`,children:e.label})},{key:`module`,header:m(`system.wasteSettingsSources.module`,`Module`),sortValue:e=>e.module,render:e=>i(`span`,{className:`font-mono text-xs text-foreground-muted`,children:e.module})},{key:`enabled`,header:m(`system.wasteSettingsSources.enabled`,`Enabled`),sortValue:e=>+!!e.enabled,render:e=>i(O,{variant:e.enabled?`success`:`default`,children:e.enabled?m(`system.wasteSettingsSources.on`,`On`):m(`system.wasteSettingsSources.off`,`Off`)})},{key:`actions`,header:``,notSortableReason:`actions`,render:e=>i(M,{type:`button`,size:`sm`,variant:`ghost`,"aria-label":m(`system.wasteSettingsSources.delete`,`Delete {{label}}`,{label:e.label}),"data-testid":`waste-source-delete-${e.id}`,onClick:t=>{t.stopPropagation(),G(e)},children:i(p,{className:`h-3.5 w-3.5 text-danger`})})}],[G,m]),K=y.state.mode===`new`,J=K||H!==null,pe=`${j}:${K?`new`:H?.id??`closed`}`;return e(`div`,{className:`flex min-h-0 flex-col gap-4`,"data-testid":`waste-settings-sources`,children:[e(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[i(`p`,{className:`text-sm text-foreground-muted`,children:m(`system.wasteSettingsSources.pickACountryAndA`,`Pick a country and a service — configuration fields come from that HACS source.`)}),e(M,{type:`button`,size:`sm`,"data-testid":`waste-sources-add`,onClick:()=>y.openNew(),children:[i(g,{className:`h-3.5 w-3.5`}),m(`system.wasteSettingsSources.addSource`,`Add source`)]})]}),P.isError?i(`p`,{className:`text-sm text-danger`,children:m(`system.wasteSettingsSources.couldNotLoadSources`,`Could not load sources.`)}):null,P.isPending?i(ne,{className:`h-32 w-full`}):i(de,{columns:fe,rows:L,rowKey:e=>e.id,pageSize:25,emptyMessage:m(`system.wasteSettingsSources.noWasteSourcesYetAdd`,`No waste sources yet. Add one to register a municipal service.`),onRowClick:e=>y.openEdit(e.id),defaultSort:{columnKey:`label`,dir:`asc`}}),i(oe,{open:J,onClose:()=>{y.close(),C(null),k.current=null},title:K?m(`system.wasteSettingsSources.addWasteSource`,`Add waste source`):m(`system.wasteSettingsSources.edit`,`Edit {{value1}}`,{value1:H?.label??`source`}),icon:te,width:`xl`,testId:`waste-source-editor`,error:ee,footer:i(M,{type:`button`,size:`sm`,disabled:x||j===``,onClick:()=>void ue(),children:x?m(`system.wasteSettingsSources.saving`,`Saving…`):m(`common.save`,`Save`)}),children:J?e(d,{children:[i(`div`,{"data-testid":`waste-country-service`,children:i(ie,{schema:se,values:w,onChange:le},`picker:${A}:${z.length}`)}),j!==``&&B!==void 0?i(ie,{schema:B,values:E,onChange:D,bare:!0},pe):j!==``&&I.isPending?i(`p`,{className:`text-sm text-foreground-muted`,children:m(`system.wasteSettingsSources.loadingFields`,`Loading fields…`)}):i(`p`,{className:`text-sm text-foreground-muted`,children:m(`system.wasteSettingsSources.chooseACountryAndService`,`Choose a country and service to see the required fields.`)})]}):null}),i(ye,{nodeId:`hub`,addonIds:[c],level:`global`,capability:f,hideSectionChrome:!0})]})}c();var $e=1e4,et={"device-export":`exporters`,exporters:`exporters`,email:`email`,broker:`brokers`,brokers:`brokers`,"message-brokers":`brokers`,calendar:`calendars`,calendars:`calendars`,"calendar-source":`calendars`},tt=[{sectionId:`exporters`,kind:`device-export`,labelKey:`system.connectivity.exporters`,icon:_,installLabelKey:`system.connectivity.exportersInstall`,emptyTitleKey:`system.connectivity.exportersEmptyTitle`,emptyDescriptionKey:`system.connectivity.exportersEmptyDescription`},{sectionId:`email`,kind:`email`,labelKey:`system.connectivity.email`,icon:v,installLabelKey:`system.connectivity.emailInstall`,emptyTitleKey:`system.connectivity.emailEmptyTitle`,emptyDescriptionKey:`system.connectivity.emailEmptyDescription`},{sectionId:`brokers`,kind:`broker`,labelKey:`system.connectivity.brokers`,icon:x,installLabelKey:`system.connectivity.brokersInstall`,emptyTitleKey:`system.connectivity.brokersEmptyTitle`,emptyDescriptionKey:`system.connectivity.brokersEmptyDescription`},{sectionId:`calendars`,kind:`calendar`,labelKey:`system.connectivity.calendars`,icon:w,installLabelKey:`system.connectivity.calendarsInstall`,emptyTitleKey:`system.connectivity.calendarsEmptyTitle`,emptyDescriptionKey:`system.connectivity.calendarsEmptyDescription`}];function nt(t,n,r,a){let o=Ve(C,t.kind),s=n.flatMap(n=>{let a=He(n,o);if(a===null)return[];let s=Ue(n.processState);return[{id:n.addonId,name:n.displayName,fallbackIcon:t.icon,state:s.state,stateLabel:s.label,render:()=>i(be,{addonId:n.addonId,displayName:n.displayName,capName:a,isActive:n.processState===`running`,badges:e(d,{children:[i(ot,{processState:n.processState}),i(st,{kind:t.kind,addonId:n.addonId})]}),lead:t.kind===`device-export`?i(k,{addonId:n.addonId}):void 0,panels:at(t.kind,n.addonId,e=>r(`/devices/${e}`)),settingsContent:n.addonId===`waste-collections`?i(Qe,{addonId:n.addonId,capName:a}):void 0})}]});return{id:t.sectionId,label:a(t.labelKey),entries:s,install:{capability:o[0]??t.kind,label:a(t.installLabelKey)}}}function rt({descriptor:e,rows:t,isLoading:r}){let{t:a}=q(),o=pe(),s=n(()=>nt(e,t,o,a),[e,t,o,a]);return i(xe,{embedded:!0,icon:e.icon,title:a(e.labelKey),subtitle:null,groups:[s],isLoading:r,emptyTitle:a(e.emptyTitleKey),emptyDescription:a(e.emptyDescriptionKey)})}function it(){let{t:e}=q(),t=N(void 0,{refetchInterval:$e}),[r,o]=he(),s=ge(`/system/integrations`,{t:e,isAdmin:!0})??{icon:m,title:e(`admin.system.integrations.connectivity`,`Connectivity`)};a(()=>{let e=r.get(`tab`);if(e===null)return;let t=et[e];t===void 0||t===e||o(e=>{let n=new URLSearchParams(e);return n.set(`tab`,t),n},{replace:!0})},[r,o]);let c=n(()=>(t.data??[]).map(Be).filter(e=>e!==null),[t.data]),l=n(()=>tt.map(n=>({id:n.sectionId,label:e(n.labelKey),ownedParams:me,content:i(rt,{descriptor:n,rows:c,isLoading:t.isLoading})})),[t.isLoading,c,e]);return i(_e,{icon:s.icon,title:s.title,subtitle:e(`admin.system.integrations.externalSystemsThisHubTalks`,`External systems this hub talks to — exporters, email, brokers and calendar sources.`),defaultSection:`exporters`,sectionsLabel:`Connectivity sections`,sections:l})}function at(e,t,n){return e===`device-export`?[{id:`devices`,title:K.t(`admin.system.integrations.devices`,`Devices`),icon:D,placement:`end`,content:i(se,{addonId:t,onOpenDevice:n,showSetup:!1})}]:e===`broker`?[{id:`connections`,title:K.t(`admin.system.integrations.connections`,`Connections`),icon:x,content:i(Le,{addonId:t,fallback:i(Ie,{addonId:t})})}]:[]}function ot({processState:e}){let{state:t,label:n}=Ue(e);return i(O,{variant:t===`ok`?`success`:t===`error`?`danger`:`default`,className:`${X} capitalize`,children:n})}function st({kind:e,addonId:t}){return e===`broker`?i(ct,{addonId:t}):e===`device-export`?i(lt,{addonId:t}):null}function ct({addonId:e}){let{t}=q(),{data:n}=G({addonId:e},{refetchInterval:$e,retry:!1}),r=S.safeParse(n);if(!r.success)return null;let{brokerCount:a,connectedCount:o}=r.data;return i(O,{variant:`info`,className:X,children:o>0?t(`system.connectivity.connectionsConnected`,{count:a,connected:o}):t(`system.connectivity.connections`,{count:a})})}function lt({addonId:e}){let{t}=q(),{data:n}=j({addonId:e},{refetchInterval:$e,retry:!1}),r=ee.safeParse(n);if(!r.success)return null;let{linkState:a,exposedDeviceCount:o}=r.data;return i(O,{variant:a===`linked`?`success`:a===`error`?`danger`:`default`,className:X,children:t(`admin.system.integrations.exposed`,`{{linkState}} · {{exposedDeviceCount}} exposed`,{linkState:a,exposedDeviceCount:o})})}export{it as IntegrationsPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et as s,o as c,x as l}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEyXHAdg.js";import{Cn as u,Di as d,On as f,Si as p,bn as m,dt as h,fn as g,fr as _,kn as v,or as ee,ot as y,un as b,xi as x,yi as S}from"./player-overlays-Dbv95cvz.js";import{t as te}from"./table-2-CTZnEliG.js";import{$u as C,Dr as ne,F as w,Kr as T,Mt as E,Pt as re,Ua as D,as as ie,cs as O,ed as k,fo as ae,jt as A,li as j,ot as M,r as N,sd as P,to as F,us as oe}from"./src-DntJrWmU.js";import{t as I}from"./i18n-xhwARoF0.js";import{t as L}from"./useTranslation-BJr-n0es.js";import{fr as se,mr as ce,sr as R}from"./index-C3uCLHv0.js";import{t as le}from"./AdminPage-3JxWocN3.js";import"./useEventInvalidation-CUPf26ML.js";import{t as z}from"./device-integration-icon-0oWIIjcP.js";import{n as B,r as V,t as H}from"./ScanNetworkModal-DXzDOpxk.js";s();function U({rows:t,isExpanded:r,onToggleExpand:a,onOpen:s,renderExpanded:c,searchPlaceholder:l,emptyLabel:u}){let{t:d}=L(),[f,p]=o(``),m=n(()=>{let e=f.trim().toLowerCase();return e.length===0?t:t.filter(t=>`${t.name} ${t.addonId}`.toLowerCase().includes(e))},[f,t]);return e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`relative`,children:[i(g,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`,"aria-hidden":!0}),i(C,{type:`search`,value:f,onChange:e=>p(e.target.value),placeholder:l,"aria-label":l,className:`pl-8`})]}),m.length===0?i(`p`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:u}):i(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2 sm:gap-3 lg:grid-cols-3`,children:m.map(e=>i(W,{integration:e,expanded:r(e),onToggleExpand:a,onOpen:s,renderExpanded:c},e.id))})]})}function W({integration:t,expanded:n,onToggleExpand:r,onOpen:a,renderExpanded:o}){let{t:s}=L(),c=n?s(`integrations.integrationColumns.collapse`,`Collapse`):s(`integrations.integrationColumns.expand`,`Expand`);return e(`article`,{"data-testid":`integration-card-${t.id}`,className:P(`flex min-w-0 flex-col gap-2 rounded-lg border border-border bg-surface p-3`,n&&`sm:col-span-2 lg:col-span-3`),children:[e(`div`,{className:`flex items-start gap-2`,children:[i(R,{type:t.addonId,size:`md`}),e(`div`,{className:`min-w-0 flex-1`,children:[i(`p`,{className:`truncate text-xs font-semibold text-foreground`,children:t.name}),i(`p`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.addonId})]}),i(M,{status:t.status,className:`shrink-0`})]}),i(`p`,{className:`text-[11px] text-foreground-muted`,children:s(`integrations.integrationColumns.deviceCount`,{count:t.deviceCount})}),e(`div`,{className:`flex flex-wrap items-center justify-end gap-1`,children:[i(k,{type:`button`,variant:`ghost`,size:`sm`,icon:n?x:S,"aria-label":c,"aria-expanded":n,onClick:()=>r(t.addonId)}),i(T,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>a(t),children:s(`integrations.open`,`Open`)})]}),n?o(t):null]})}s();var G=`camstack.admin.integrations.view`;function K(e){return e===`table`||e===`grid`}function q(){try{return typeof window>`u`?null:window.localStorage}catch{return null}}function J(e=q()){if(e===null)return`table`;try{let t=e.getItem(G);return K(t)?t:`table`}catch{return`table`}}function Y(e,t=q()){if(t!==null)try{t.setItem(G,e)}catch{}}function ue(){let[e,t]=o(()=>J());return[e,r(e=>{t(e),Y(e)},[])]}s();function de(e=!0){a(()=>{if(!e)return;let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=t}},[e])}s();function fe(e,t){let[n,r]=o(!1);return a(()=>{if(!e){r(!1);return}r(!1);let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),n}s();function pe({providerId:t,onImport:n,onSkip:r}){let{t:s}=L(),[c,l]=o(new Set),u=F(),f=u.data,m=u.isPending||!u.data&&!u.isError;a(()=>{t&&(u.isPending||u.data||u.mutate({addonId:t}))},[t,u]);function h(e){l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}if(m)return e(`div`,{className:`flex flex-col items-center py-12`,children:[i(`div`,{className:`h-6 w-6 animate-spin rounded-full border-2 border-primary border-t-transparent`}),i(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:s(`integrations.searchingDevices`)})]});let g=f??[];return e(`div`,{className:`space-y-4`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:g.length>0?s(`integrations.foundDevices`,{count:g.length}):s(`integrations.noDevicesFound`)}),g.length>0&&i(`div`,{className:`space-y-1.5 max-h-64 overflow-y-auto`,children:g.map(t=>{let n=t.stableId,r=t.suggestedName??n,a=c.has(n),o=t.alreadyOnboarded===!0;return e(`button`,{onClick:()=>{o||h(n)},disabled:o,title:o?s(`integrations.alreadyAddedHint`,{defaultValue:`Already added as "{{name}}" — re-adding would overwrite its settings.`,name:t.onboardedName??r}):void 0,className:`flex w-full items-center gap-3 rounded-lg border p-3 text-left transition-colors ${o?`border-border bg-surface opacity-60 cursor-not-allowed`:a?`border-primary/40 bg-primary/5`:`border-border bg-surface hover:border-foreground-subtle/30`}`,children:[i(`div`,{className:`flex h-5 w-5 items-center justify-center rounded border flex-shrink-0 ${a&&!o?`border-primary bg-primary`:`border-border`}`,children:a&&!o&&i(p,{className:`h-3 w-3 text-primary-foreground`})}),i(d,{className:`h-3.5 w-3.5 text-foreground-subtle flex-shrink-0`}),i(`span`,{className:`text-xs font-medium text-foreground truncate`,children:r}),o&&i(`span`,{className:`ml-auto flex-shrink-0 rounded bg-surface-muted px-1.5 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:s(`integrations.alreadyAdded`,{defaultValue:`Already added`})})]},n)})}),e(`div`,{className:`flex items-center justify-between pt-2`,children:[i(`button`,{onClick:r,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:s(`integrations.skip`)}),g.length>0&&e(`button`,{onClick:()=>n(Array.from(c)),disabled:c.size===0,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:[s(`integrations.importSelected`),` (`,c.size,`)`]})]})]})}var X=`(hover: none) and (pointer: coarse)`;function me(){if(typeof window>`u`||typeof window.matchMedia!=`function`)return!0;try{return!window.matchMedia(X).matches}catch{return!0}}s();function he({onSelect:r,onClose:s,pendingAddonId:c=null}){let{t:l}=L(),u=se(),[d,f]=o(``),p=t(null),{data:m,isLoading:h}=O();a(()=>{h||!me()||p.current?.focus()},[h]);let _=n(()=>{let e=m??[],t=d.trim().toLowerCase();return t.length===0?e:e.filter(e=>`${e.name} ${e.description??``} ${e.addonId}`.toLowerCase().includes(t))},[m,d]);if(h)return i(`div`,{className:`grid grid-cols-2 gap-2 p-2`,children:[1,2,3,4].map(e=>i(`div`,{className:`h-24 rounded-lg bg-surface animate-pulse`},e))});let v=c!==null;return e(`div`,{className:`space-y-3`,"data-testid":`provider-picker`,children:[e(`div`,{className:`relative`,children:[i(g,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-foreground-subtle`,"aria-hidden":!0}),i(C,{ref:p,type:`search`,value:d,onChange:e=>f(e.target.value),placeholder:l(`integrations.searchProviders`,`Search integrations…`),className:`pl-8`,"data-testid":`provider-picker-search`,"aria-label":l(`integrations.searchProviders`,`Search integrations…`)})]}),i(`div`,{className:`grid grid-cols-2 gap-2`,children:_.map(t=>{let n=t.instanceMode===`unique`&&t.existingInstances.length>0,a=c===t.addonId,o=v;return e(`button`,{type:`button`,disabled:o,"data-testid":`provider-pick-${t.addonId}`,onClick:()=>{if(!o)if(n){let e=t.existingInstances[0].id;s(),u(`/integrations/${e}`)}else r(t.addonId,t.instanceMode,t.discoveryMode,t.name,t.kind,t.brokerKind,t.mode,t.canTest)},className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-center text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors disabled:opacity-60 disabled:cursor-not-allowed disabled:hover:border-border`,children:[t.iconUrl?i(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${t.color}15`},children:i(`img`,{src:t.iconUrl,alt:``,className:`h-5 w-5`})}):i(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg flex-shrink-0`,style:{backgroundColor:`${t.color}15`},children:i(`span`,{className:`text-sm`,style:{color:t.color},children:`◉`})}),i(`p`,{className:`w-full truncate text-xs font-semibold text-foreground`,children:t.name}),t.description?i(`p`,{className:`w-full line-clamp-2 text-[10px] text-foreground-subtle`,children:t.description}):null,a?i(ee,{className:`h-4 w-4 animate-spin text-primary`}):n?e(`span`,{className:`flex items-center gap-1 text-[10px] font-medium text-foreground-subtle`,children:[i(b,{className:`h-3 w-3`}),l(`integrations.manage`)]}):null]},t.addonId)})}),_.length===0&&i(`div`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:(m??[]).length===0?l(`integrations.noProviders`):l(`integrations.noProvidersMatch`,`No integrations match your search.`)})]})}s();function ge(e){let t=e=>{if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`)return{...e,fields:e.fields.map(e=>t(e))};let{value:n,...r}=e;return r};return{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>({...e,fields:e.fields.map(t)}))}}var _e=2e4;function ve({open:t,onClose:r}){let{t:s}=L(),u=se(),d=c(),[f,p]=o(`picker`),[m,g]=o(null),[_,v]=o(null),[y,b]=o(`manual`),[x,S]=o(null),[te,C]=o(``),[ne,w]=o(null),[T,E]=o(null),[re,O]=o(!1),{data:k}=j({addonId:m??``,nodeId:`hub`},{enabled:m!=null}),ae=n(()=>k?ge(k):null,[k]),A=ie({onSuccess:()=>d.invalidateQueries({queryKey:[[`integrations`]]})}),M=F(),N=M.data;a(()=>{f!==`discovery`||!_||!m||M.isPending||M.data||M.mutate({addonId:m})},[f,_,m,M]);let P=D({onSuccess:()=>d.invalidateQueries({queryKey:[[`deviceManager`]]})});function oe(e,t,n,r,i,a,o,s){if(!A.isPending){if(g(e),O(s),b(n),C(r),E(null),o===`broker`){if(!a){E(`Addon '${e}' declares mode 'broker' but no brokerKind in its manifest`);return}S(a),p(`broker`);return}if(o===`account`){p(`config`);return}I(e,r)}}async function I(e,t){try{let n=await A.mutateAsync({addonId:e,name:t,settings:{}});r(),H(),u(`/integrations/${n.id}?add=1`)}catch{}}async function ce(e){if(m)try{let t=await A.mutateAsync({addonId:m,name:e.name,settings:e.config,secretKeys:[...e.secretKeys]});v(t.id),w(t.id),y===`auto`||y===`both`?p(`discovery`):z(t.id,{openAdd:!0})}catch{}}async function R(e){if(m)try{let t=await A.mutateAsync({addonId:m,name:te,settings:{brokerId:e}});w(t.id),v(t.id),z(t.id)}catch{}}async function le(e){if(m){for(let t of e){let e=N?.find(e=>e.stableId===t);e&&await P.mutateAsync({addonId:m,candidate:e,...ne===null?{}:{integrationId:ne}})}z()}}function z(e,t){let n=e??_??m;r(),H(),n&&u(t?.openAdd===!0?`/integrations/${n}?add=1`:`/integrations/${n}`)}function H(){p(`picker`),g(null),v(null),b(`manual`),S(null),C(``),w(null),E(null),O(!1)}function U(){r(),H()}de(t);let W=A.isPending,G=fe(W,_e);if(!t)return null;let K={picker:s(`integrations.newIntegration`),config:s(`integrations.configureIntegration`),discovery:s(`integrations.importDevices`),broker:s(`integrations.connectBroker`,{defaultValue:`Connect a broker`})},q=W?m:null,J=A.error,Y=W&&!G;return e(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[i(`div`,{className:`absolute inset-0 bg-black/60`,onClick:Y?void 0:U}),e(`div`,{className:`relative z-10 w-full max-w-lg max-h-[calc(85dvh-2*max(env(safe-area-inset-top),env(safe-area-inset-bottom)))] rounded-xl border border-border bg-background shadow-2xl flex flex-col overflow-hidden`,children:[e(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 flex-shrink-0`,children:[i(`h2`,{className:`text-sm font-semibold text-foreground`,children:K[f]}),i(`button`,{onClick:U,disabled:Y,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:i(h,{className:`h-4 w-4`})})]}),e(`div`,{className:`px-5 py-4 flex-1 overflow-y-auto overscroll-contain`,children:[J&&!W&&i(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:J instanceof Error?J.message:String(J)}),f===`picker`&&e(l,{children:[T&&i(`div`,{className:`mb-3 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:T}),i(he,{onSelect:oe,onClose:U,pendingAddonId:q})]}),f===`config`&&m&&i(B,{addonId:m,configSchema:ae??null,canTest:re,onSave:ce,onBack:()=>p(`picker`)}),f===`broker`&&x&&i(V,{kind:x,onResolved:e=>{R(e)},onBack:()=>p(`picker`)}),f===`discovery`&&_&&i(pe,{providerId:_,onImport:le,onSkip:z})]}),W&&e(`div`,{className:`absolute inset-0 z-20 flex flex-col items-center justify-center gap-2 rounded-xl bg-background/85 backdrop-blur-sm px-6 text-center`,children:[i(ee,{className:`h-6 w-6 animate-spin text-primary`}),i(`p`,{className:`text-xs font-medium text-foreground`,children:s(`integrations.creating`,{defaultValue:`Creating integration…`})}),!G&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:s(`integrations.creatingHint`,{defaultValue:`Waiting for the addon to restart and register`})}),G&&e(l,{children:[i(`p`,{className:`text-[10px] text-foreground-subtle max-w-xs`,children:s(`integrations.creatingOverdue`,{defaultValue:`This is taking longer than expected. The integration may already have been created — close this dialog and refresh to check.`})}),i(`button`,{onClick:U,className:`mt-1 rounded-md border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:s(`integrations.closeAndRefresh`,{defaultValue:`Close`})})]})]})]})]})}function Z({integration:t,expanded:n,onToggleExpand:r}){let{t:a}=L();return e(`div`,{className:`flex items-center gap-2.5`,children:[i(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),r(t.addonId)},"aria-label":n?a(`integrations.integrationColumns.collapse`,`Collapse`):a(`integrations.integrationColumns.expand`,`Expand`),"aria-expanded":n,className:`flex h-5 w-5 flex-shrink-0 items-center justify-center rounded text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:i(n?x:S,{className:`h-3.5 w-3.5`})}),i(R,{type:t.addonId,size:`sm`}),e(`div`,{className:`flex min-w-0 flex-col`,children:[i(`span`,{className:`truncate text-xs font-semibold text-foreground`,children:t.name}),i(`span`,{className:`truncate text-[10px] text-foreground-subtle`,children:t.addonId})]})]})}function ye(e){let{isExpanded:t,onToggleExpand:n}=e;return[{key:`name`,header:I.t(`integrations.integrationColumns.integration`,`Integration`),headerClassName:`w-[55%]`,cell:e=>i(Z,{integration:e,expanded:t(e),onToggleExpand:n})},{key:`devices`,header:I.t(`integrations.integrationColumns.devices`,`Devices`),headerClassName:`w-[15%]`,cellClassName:`text-[11px] text-foreground-subtle`,cell:e=>I.t(`integrations.integrationColumns.deviceCount`,{count:e.deviceCount})},{key:`status`,header:I.t(`integrations.integrationColumns.status`,`Status`),headerClassName:`w-[15%]`,cell:e=>i(M,{status:e.status})}]}s();function be(e){if(!e.enabled)return`disabled`;switch(e.processState){case`running`:return`running`;default:return`stopped`}}var Q=`expand`;function $(){let{t}=L(),a=se(),s=y(),[c]=ce(),[d,p]=ue(),[h,g]=o(!1),ee=r(()=>g(!0),[]),b=r(()=>g(!1),[]),[x,S]=o(!1),C=r(()=>S(!0),[]),T=r(()=>S(!1),[]);N([`integrations`],[`integration.enabled`,`integration.disabled`,`integration.deleted`,`provider.started`,`provider.stopped`,`addon.installed`,`addon.uninstalled`,`addon.started`,`addon.stopped`,`addon.updated`]),N([`deviceManager`],[`device.registered`,`device.unregistered`,`device.online`,`device.offline`,`device.disabled`,`device.enabled`]);let{data:D,isLoading:ie,isError:O,refetch:k}=oe(void 0),{data:j,isLoading:M,isError:F,refetch:I}=ae({projection:`slim`}),R=n(()=>j??[],[j]),B=n(()=>D??[],[D]),V=n(()=>{let e=new Map;for(let t of R)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[R]),W=n(()=>E(D),[D]),G=n(()=>{let e=new Map;for(let t of re(R)){let n=W(t);if(n.kind!==`resolved`)continue;let r=n.integration.id;e.set(r,(e.get(r)??0)+1)}return e},[R,W]),K=n(()=>B.map(e=>({id:e.id,addonId:e.addonId,name:e.name,enabled:e.enabled,status:be(e),deviceCount:G.get(e.id)??0})),[B,G]),q=c.get(Q),J=r(e=>{let t=new URLSearchParams(window.location.search);t.get(Q)===e?t.delete(Q):t.set(Q,e);let n=t.toString(),r=`${window.location.pathname}${n?`?${n}`:``}${window.location.hash}`;window.history.replaceState(window.history.state,``,r),window.dispatchEvent(new PopStateEvent(`popstate`))},[]),Y=r(e=>a(`/integrations/${e.id}`),[a]),de=r(e=>V.get(e)??null,[V]),fe=r(e=>a(`/devices/${String(e)}`),[a]),pe=r(e=>i(A,{context:`integration-detail`,devices:R,trpc:s.trpcClient,integrationOf:W,forceIntegrationId:e.id,urlScope:`nested`,lsKey:`integrations:nested:${e.addonId}`,resolveIntegrationIcon:z,resolveParent:de,onNavigate:fe}),[R,s.trpcClient,W,de,fe]),X=r(e=>q===e.addonId,[q]),me=n(()=>ye({isExpanded:X,onToggleExpand:J}),[X,J]),he=r(e=>`${e.name} ${e.addonId}`,[]),ge=r(e=>e.addonId,[]),_e=r(()=>{k(),I()},[k,I]),Z=O===!0||F===!0,$=!Z&&(ie||M||D===void 0||j===void 0),xe=B.length>0,Se=[{id:`table`,label:t(`integrations.viewTable`,`Table`),icon:te},{id:`grid`,label:t(`integrations.viewGrid`,`Grid`),icon:_}];return e(le,{icon:f,title:t(`nav.integrations`,`Integrations`),actions:e(l,{children:[i(w,{ariaLabel:t(`integrations.viewLabel`,`Layout`),value:d,onChange:p,options:Se,testId:`integrations-view`}),i(`button`,{onClick:_e,disabled:$,className:`flex items-center gap-1 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 disabled:opacity-50`,title:t(`common.refresh`,`Refresh`),children:i(m,{className:P(`h-3.5 w-3.5`,$&&`animate-spin`)})}),e(`button`,{onClick:C,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:t(`integrations.scanTheLocalNetworkFor`,`Scan the local network for devices`),children:[i(u,{className:`h-3.5 w-3.5`}),t(`integrations.scanNetwork`,`Scan network`)]}),e(`button`,{onClick:ee,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`,children:[i(v,{className:`h-3.5 w-3.5`}),t(`integrations.newIntegration`,`New Integration`)]})]}),children:[Z&&i(ne,{message:t(`integrations.loadFailed`,`Integrations could not be loaded.`),onRetry:_e}),$&&i(`div`,{className:`space-y-2`,"data-testid":`integrations-pending`,children:[1,2,3].map(e=>i(`div`,{className:`h-12 rounded-lg border border-border bg-surface animate-pulse`},e))}),!Z&&!$&&!xe&&e(`div`,{className:`flex flex-col items-center py-20 text-foreground-subtle`,children:[i(`p`,{className:`text-sm`,children:t(`integrations.noIntegrationsConfigured`,`No integrations configured.`)}),i(`p`,{className:`text-xs mt-1`,children:t(`integrations.clickNewIntegrationToConnect`,`Click "New Integration" to connect cameras and devices.`)})]}),!Z&&!$&&xe&&d===`table`&&i(A,{mode:`generic`,items:K,getKey:ge,getSearchText:he,columns:me,onRowClick:Y,isExpanded:X,renderExpanded:pe,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),!Z&&!$&&xe&&d===`grid`&&i(U,{rows:K,isExpanded:X,onToggleExpand:J,onOpen:Y,renderExpanded:pe,searchPlaceholder:t(`integrations.search`,{defaultValue:`Search integrations…`}),emptyLabel:t(`integrations.empty`,{defaultValue:`No integrations found.`})}),i(ve,{open:h,onClose:b}),i(H,{open:x,onClose:T})]})}export{$ as IntegrationsPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{C as e,J as t,K as n,R as r,S as i,V as a,Y as o,et 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-CEyXHAdg.js";import{Br as l,Cn as u,Nt as d,Q as f,Si as p,Wr as m,bi as h,bn as g,dt as _,or as v}from"./player-overlays-Dbv95cvz.js";import{Ma as y,ka as b}from"./client-DvJxGh2F.js";import{Ua as x,da as S,eo as C,fa as w,fo as T,fs as E,mi as D,no as O,sa as k,xo as A}from"./src-DntJrWmU.js";import{t as j}from"./useTranslation-BJr-n0es.js";import"./mount-CUPf26ML.js";import{P as M,lr as N}from"./index-C3uCLHv0.js";import{t as P}from"./BrokerForm-D5-q8F_8.js";s();var F=[`amazon.com`,`amazon.it`,`amazon.de`,`amazon.co.uk`,`amazon.fr`,`amazon.es`,`amazon.ca`,`amazon.com.au`,`amazon.co.jp`,`amazon.in`,`amazon.com.br`,`amazon.com.mx`],I=f(`/addon/import-alexa`),L=2e3;function R(e){return typeof e==`object`&&!!e&&typeof e.sessionId==`string`&&typeof e.loginUrl==`string`}function z(e){return typeof e==`object`&&!!e&&typeof e.phase==`string`&&typeof e.sessionId==`string`}function B(e){return typeof e==`object`&&!!e&&typeof e.brokerId==`string`}function V(e){return{"Content-Type":`application/json`,Authorization:`Bearer ${localStorage.getItem(`camstack_admin_token`)??``}`,...e}}async function H(e,t,n){let r=await fetch(`${I}${e}`,{method:`POST`,headers:V(),body:JSON.stringify(t)}),i=await r.json();if(!r.ok){let e=typeof i==`object`&&i?i.error??`Unknown error`:`Unknown error`;throw Error(String(e))}if(!n(i))throw Error(`Unexpected response from server`);return i}async function U(e){let t=new URLSearchParams({sessionId:e}),n=localStorage.getItem(`camstack_admin_token`)??``,r=await fetch(`${I}/login/status?${t.toString()}`,{headers:{Authorization:`Bearer ${n}`}}),i=await r.json();if(!r.ok){let e=typeof i==`object`&&i?i.error??`Unknown error`:`Unknown error`;throw Error(String(e))}if(!z(i))throw Error(`Unexpected status response from server`);return i}async function W(e){try{await fetch(`${I}/login/cancel`,{method:`POST`,headers:V(),body:JSON.stringify({sessionId:e})})}catch{}}function G({brokerId:n,onResolved:s,onCancel:c}){let{t:u}=j(),[f,p]=o(`amazon.it`),[m,h]=o(`Alexa account`),[_,y]=o({kind:`idle`}),b=t(!0);a(()=>(b.current=!0,()=>{b.current=!1}),[]);let x=t(null),S=t(null),C=r(()=>{S.current!==null&&(clearInterval(S.current),S.current=null)},[]),w=r(async e=>{C(),b.current&&y({kind:`committing`,sessionId:e});try{let t=await H(`/login/commit`,{sessionId:e,name:m.trim().length>0?m.trim():`Alexa account`,...n===void 0?{}:{brokerId:n}},B);x.current=null,s(t.brokerId)}catch(t){let n=t instanceof Error?t.message:String(t);b.current&&y({kind:`error`,message:n,sessionId:e})}},[n,m,s,C]),T=r((e,t)=>{C();let n=async()=>{try{let n=await U(e);if(n.phase===`captured`){C(),w(e);return}if(n.phase===`error`){C(),b.current&&y({kind:`error`,message:n.error??u(`integrations.alexaLoginStep.loginProxyReturnedAnError`,`Login proxy returned an error`),sessionId:e});return}if(n.phase===`cancelled`){C(),b.current&&y({kind:`idle`});return}b.current&&y({kind:`polling`,sessionId:e,loginUrl:n.loginUrl||t,phase:n.phase})}catch(e){let t=e instanceof Error?e.message:String(e);b.current&&y(e=>e.kind===`polling`?{...e}:{kind:`error`,message:t,sessionId:null})}};S.current=setInterval(()=>{n()},L)},[C,w,u]);a(()=>()=>{C(),x.current!==null&&W(x.current)},[C]);let E=async()=>{C(),x.current!==null&&(W(x.current),x.current=null),y({kind:`starting`});try{let e=await H(`/login/start`,{amazonDomain:f},R);x.current=e.sessionId,y({kind:`polling`,sessionId:e.sessionId,loginUrl:e.loginUrl,phase:`starting`}),T(e.sessionId,e.loginUrl)}catch(e){y({kind:`error`,message:e instanceof Error?e.message:String(e),sessionId:null})}},D=()=>{C(),x.current!==null&&(W(x.current),x.current=null),y({kind:`idle`})},O=()=>{D()},k=_.kind===`idle`,A=_.kind===`starting`,M=_.kind===`polling`,P=_.kind===`committing`,I=_.kind===`error`,z=A||M||P,V=_.kind===`polling`?_.phase:null,G=_.kind===`polling`?_.loginUrl:null,K=M&&V===`awaiting-login`,q=M&&(V===`starting`||V===null);return e(`div`,{className:`space-y-4`,children:[(k||I)&&e(`div`,{className:`space-y-3`,children:[n===void 0&&e(`div`,{className:`space-y-1`,children:[i(`label`,{htmlFor:`alexa-account-name`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:u(`integrations.alexaLoginStep.accountName`,`Account name`)}),i(`input`,{id:`alexa-account-name`,type:`text`,value:m,onChange:e=>h(e.target.value),placeholder:u(`integrations.alexaLoginStep.alexaAccount`,`Alexa account`),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),e(`div`,{className:`space-y-1`,children:[i(`label`,{htmlFor:`alexa-amazon-region`,className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:u(`integrations.alexaLoginStep.amazonRegion`,`Amazon region`)}),i(`select`,{id:`alexa-amazon-region`,value:f,onChange:e=>p(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:F.map(e=>i(`option`,{value:e,children:e},e))})]})]}),I&&e(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px] flex items-start gap-2`,children:[i(d,{className:`h-3.5 w-3.5 mt-0.5 flex-shrink-0`}),i(`span`,{children:_.message})]}),A&&e(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[i(v,{className:`h-4 w-4 animate-spin flex-shrink-0`}),u(`integrations.alexaLoginStep.startingLoginProxy`,`Starting login proxy…`)]}),q&&e(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[i(v,{className:`h-4 w-4 animate-spin flex-shrink-0`}),u(`integrations.alexaLoginStep.waitingForProxyToBe`,`Waiting for proxy to be ready…`)]}),P&&e(`div`,{className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-3 py-3 text-xs text-foreground-subtle`,children:[i(v,{className:`h-4 w-4 animate-spin flex-shrink-0`}),u(`integrations.alexaLoginStep.savingCredentials`,`Saving credentials…`)]}),K&&G!==null&&e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-2`,children:[i(`p`,{className:`text-xs font-semibold text-foreground`,children:u(`integrations.alexaLoginStep.openTheLinkBelowTo`,`Open the link below to log in to your Amazon account`)}),i(`p`,{className:`text-[10px] text-foreground-subtle`,children:u(`integrations.alexaLoginStep.afterCompletingTheLoginAnd`,`After completing the login and any 2FA steps, this wizard will continue automatically.`)}),e(`a`,{href:G,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[i(l,{className:`h-3.5 w-3.5`}),u(`integrations.alexaLoginStep.loginToAmazon`,`Login to Amazon`)]})]}),i(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-[10px] text-warning`,children:i(N,{i18nKey:`integrations.alexaLoginStep.proxyNote`,components:{b:i(`strong`,{}),code:i(`code`,{className:`font-mono`})}})}),e(`div`,{className:`flex items-center gap-2 text-[10px] text-foreground-subtle`,children:[i(v,{className:`h-3 w-3 animate-spin`}),u(`integrations.alexaLoginStep.waitingForAmazonLoginTo`,`Waiting for Amazon login to complete…`)]})]}),e(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[i(`button`,{type:`button`,onClick:z?D:c,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:z?u(`integrations.alexaLoginStep.cancelLogin`,`Cancel login`):u(`common.back`,`Back`)}),e(`div`,{className:`flex items-center gap-2`,children:[I&&e(`button`,{type:`button`,onClick:O,className:`inline-flex items-center gap-1.5 rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10`,children:[i(g,{className:`h-3.5 w-3.5`}),u(`common.retry`,`Retry`)]}),k&&i(`button`,{type:`button`,onClick:()=>{E()},disabled:n===void 0&&m.trim().length===0,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:u(`integrations.alexaLoginStep.startLogin`,`Start login`)})]})]})]})}s();var K=`alexa`;function q(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`):[]}function J(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.addonId==`string`&&Array.isArray(e.kinds)):[]}var Y={connected:`bg-success/15 text-success`,connecting:`bg-warning/15 text-warning`,disconnected:`bg-foreground-subtle/15 text-foreground-subtle`,"auth-failed":`bg-danger/15 text-danger`,unreachable:`bg-danger/15 text-danger`,error:`bg-danger/15 text-danger`};function X({kind:t,onResolved:r,onBack:a}){let{t:s}=j(),[c,l]=o(t===K?`alexa-login`:`existing`),u=S({kind:t}),d=n(()=>q(u.data).filter(e=>e.kind===t),[u.data,t]),f=w(),p=n(()=>{for(let e of J(f.data))if(e.kinds.some(e=>e.kind===t))return e.addonId},[f.data,t]),[m,g]=o(null),[_,y]=o(``),b=k({}),x=()=>{m&&r(m)},C=async e=>{_.trim().length!==0&&r((await b.mutateAsync({kind:t,name:_.trim(),settings:e,...p===void 0?{}:{addonId:p}})).id)},T=e=>{e===`new`?g(null):b.reset(),l(e)};return e(`div`,{className:`space-y-4`,children:[e(`button`,{type:`button`,onClick:a,className:`inline-flex items-center gap-1 text-[11px] text-foreground-subtle hover:text-foreground`,children:[i(h,{className:`h-3.5 w-3.5`}),` `,s(`common.back`)]}),e(`div`,{className:`inline-flex rounded-lg border border-border p-0.5 flex-wrap gap-0.5`,children:[t===K&&i(`button`,{type:`button`,onClick:()=>T(`alexa-login`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${c===`alexa-login`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:s(`integrations.brokerStep.loginInteractively`,`Login interactively`)}),i(`button`,{type:`button`,onClick:()=>T(`existing`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${c===`existing`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:s(`integrations.brokerStep.useExisting`,`Use existing`)}),i(`button`,{type:`button`,onClick:()=>T(`new`),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${c===`new`?`bg-primary text-primary-foreground`:`text-foreground-subtle hover:text-foreground`}`,children:t===K?s(`integrations.brokerStep.pasteCookie`,`Paste cookie`):s(`integrations.brokerStep.createNew`,`Create new`)})]}),c===`alexa-login`&&i(G,{onResolved:r,onCancel:a}),c===`existing`&&e(`div`,{className:`space-y-3`,children:[u.isLoading&&e(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[i(v,{className:`h-3.5 w-3.5 animate-spin`}),` `,s(`integrations.brokerStep.loadingBrokers`)]}),u.isError&&e(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[s(`integrations.brokerStep.failedToLoadBrokers`,`Failed to load brokers:`),` `,u.error instanceof Error?u.error.message:s(`integrations.brokerStep.unknownError`,`Unknown error`)]}),!u.isLoading&&!u.isError&&d.length===0&&i(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-6 text-center text-xs text-foreground-subtle`,children:i(N,{i18nKey:`integrations.brokerStep.noBrokers`,values:{mode:t===K?s(`integrations.brokerStep.loginInteractively`,`Login interactively`):s(`integrations.brokerStep.createNew`,`Create new`)},components:{b:i(`span`,{className:`font-medium text-foreground`})}})}),i(`div`,{className:`space-y-2`,children:d.map(t=>e(`button`,{type:`button`,onClick:()=>g(t.id),className:`flex w-full items-center justify-between gap-3 rounded-lg border bg-surface p-3 text-left transition-colors ${m===t.id?`border-primary ring-1 ring-primary`:`border-border hover:border-foreground-subtle/30`}`,children:[i(`span`,{className:`text-xs font-semibold text-foreground`,children:t.name}),i(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Y[t.status]}`,children:t.status})]},t.id))}),d.length>0&&i(`div`,{className:`flex justify-end pt-1`,children:i(`button`,{type:`button`,onClick:x,disabled:!m,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:s(`integrations.brokerStep.useThisBroker`,`Use this broker`)})})]}),c===`new`&&e(`div`,{className:`space-y-3`,children:[e(`div`,{className:`space-y-1`,children:[i(`label`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:s(`integrations.brokerStep.name`,`Name`)}),i(`input`,{type:`text`,value:_,onChange:e=>y(e.target.value),placeholder:s(`integrations.brokerStep.myHomeAssistant`,`My Home Assistant`),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),b.isError&&i(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:b.error instanceof Error?b.error.message:String(b.error)}),i(P,{kind:t,...p===void 0?{}:{addonId:p},onSubmit:e=>{C(e).catch(()=>{})},onCancel:a,submitLabel:b.isPending?s(`integrations.brokerStep.creating`,`Creating…`):s(`integrations.brokerStep.createBroker`,`Create broker`),disabled:b.isPending||_.trim().length===0}),_.trim().length===0&&i(`p`,{className:`text-[10px] text-foreground-subtle`,children:s(`integrations.brokerStep.enterANameBeforeCreating`,`Enter a name before creating.`)})]})]})}s();function Z(e){return{status:e.status===`validated`||e.status===`rejected`||e.status===`inconclusive`||e.status===`unsupported`?e.status:e.success?`validated`:`rejected`,...e.error===void 0?{}:{error:e.error},...e.detail===void 0?{}:{detail:e.detail}}}var Q={validated:`border-success/30 bg-success/5 text-success`,rejected:`border-danger/30 bg-danger/5 text-danger`,inconclusive:`border-warning/30 bg-warning/5 text-warning`,unsupported:`border-border bg-surface text-foreground-subtle`};function ee({addonId:t,configSchema:n,canTest:r=!0,initialName:a,initialConfig:s,submitLabel:c,hideName:l=!1,onSave:u,onBack:d}){let{t:f}=j(),[p,m]=o(a??``),[h,g]=o(s??{}),[_,v]=o(null),x=E({onSuccess:e=>v(Z(e)),onError:e=>v({status:`inconclusive`,error:String(e)})}),S=D(),C=!r||_?.status===`validated`,w=!l&&p.trim().length===0,T=!w&&C;return e(`div`,{className:`space-y-4`,children:[!l&&e(`div`,{children:[i(`label`,{htmlFor:`integration-name`,className:`block text-[11px] font-medium text-foreground mb-1`,children:f(`integrations.integrationName`)}),i(`input`,{id:`integration-name`,type:`text`,value:p,onChange:e=>m(e.target.value),placeholder:f(`integrations.integrationNamePlaceholder`),"aria-invalid":w,"aria-describedby":w?`integration-name-error`:void 0,className:`w-full rounded-lg border bg-surface px-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none ${w?`border-danger focus:border-danger`:`border-border focus:border-primary/50`}`}),w&&i(`p`,{id:`integration-name-error`,"data-testid":`integration-name-error`,className:`mt-1 text-xs text-danger`,children:f(`integrations.nameRequired`,`Name is required`)})]}),n&&i(M,{schema:n,values:h,onChange:e=>{g(e),v(null)},onAction:async(e,i,a)=>{let o=await S.mutateAsync({addonId:t,action:e,input:a??{}});if(r&&typeof o==`object`&&o){let e=o;if(!(typeof e.token==`string`||typeof e.sslCertificate==`string`||typeof e.host==`string`))return o;let r={...h};for(let[t,n]of Object.entries(e))typeof n==`string`&&t!==`summary`&&(r[t]=n);let i=y(n,r);g(i),v(null),x.mutate({addonId:t,settings:i})}return o}}),_&&i(`div`,{className:`rounded-lg border px-3 py-2 text-xs ${Q[_.status]}`,children:(e=>{switch(e.status){case`validated`:return e.detail?`${f(`integrations.connectionSuccess`)} — ${e.detail}`:f(`integrations.connectionSuccess`);case`rejected`:return`${f(`integrations.errorPrefix`)} ${e.error??``}`;case`inconclusive`:return`${f(`integrations.connectionInconclusive`,{defaultValue:`Could not be checked:`})} ${e.error??``}`;case`unsupported`:return e.error??f(`integrations.connectionUntestable`,{defaultValue:`This integration cannot be tested before it is created.`})}})(_)}),e(`div`,{className:`flex items-center justify-between pt-2`,children:[i(`button`,{onClick:d,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:f(`integrations.back`)}),e(`div`,{className:`flex items-center gap-2`,children:[i(`button`,{onClick:()=>x.mutate({addonId:t,settings:y(n,h)}),disabled:x.isPending||!r,title:r?void 0:f(`integrations.connectionUntestable`,{defaultValue:`This integration cannot be tested before it is created.`}),className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:x.isPending?f(`integrations.testing`):f(`integrations.testConnection`)}),e(`div`,{className:`flex flex-col items-end gap-1`,children:[w&&i(`p`,{"data-testid":`integration-name-submit-error`,className:`text-xs text-danger`,children:f(`integrations.nameRequiredSubmit`,`Enter a name before continuing.`)}),i(`button`,{onClick:()=>{w||u({name:p,config:y(n,h),secretKeys:[...b(n)]})},disabled:!T,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:c??f(`integrations.forward`)})]})]})]})]})}s();function te({open:t,onClose:a,scope:s}){let{t:c}=j(),l=x(),[d,f]=o(new Set),[h,g]=o(new Set),{data:y}=T({projection:`slim`}),b=n(()=>new Set((y??[]).map(e=>e.stableId)),[y]),S=r(async(e,t)=>{g(e=>new Set(e).add(t.stableId));try{await l.mutateAsync({addonId:e,candidate:t}),f(e=>new Set(e).add(t.stableId))}catch{}finally{g(e=>{let n=new Set(e);return n.delete(t.stableId),n})}},[l]),C=r((t,n)=>{let r=typeof n.prefilledConfig.host==`string`?n.prefilledConfig.host:null,a=b.has(n.stableId),o=d.has(n.stableId)||a,s=h.has(n.stableId);return e(`div`,{className:`flex items-center justify-between rounded-lg border border-border bg-surface px-3 py-2`,children:[e(`div`,{className:`min-w-0`,children:[i(`p`,{className:`truncate text-xs font-medium text-foreground`,children:n.suggestedName}),r&&i(`p`,{className:`truncate text-[10px] font-mono text-foreground-subtle`,children:r})]}),o?e(`span`,{className:`flex items-center gap-1 text-[11px] text-foreground-subtle`,children:[i(p,{className:`h-3.5 w-3.5`}),` `,a?c(`integrations.scanNetworkModal.alreadyAdded`,`Already added`):c(`integrations.scanNetworkModal.added`,`Added`)]}):e(`button`,{type:`button`,onClick:()=>void S(t,n),disabled:s,className:`flex items-center gap-1 rounded-md bg-primary px-2.5 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-50`,children:[s?i(v,{className:`h-3.5 w-3.5 animate-spin`}):i(m,{className:`h-3.5 w-3.5`}),c(`common.add`,`Add`)]})]},n.stableId)},[d,h,b,S,c]);if(!t)return null;let w=s?`Scan network — ${s.label}`:`Scan network for devices`;return e(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[i(`div`,{className:`absolute inset-0 bg-black/60`,onClick:a}),e(`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:[e(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[e(`div`,{className:`flex items-center gap-2`,children:[i(u,{className:`h-4 w-4 text-primary`}),i(`h2`,{className:`text-sm font-semibold text-foreground`,children:w})]}),i(`button`,{onClick:a,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:i(_,{className:`h-4 w-4`})})]}),s?i(re,{scope:s,onAdopt:C,onReset:()=>f(new Set)}):i(ne,{onAdopt:C,onReset:()=>f(new Set)})]})]})}function ne({onAdopt:t,onReset:o}){let{t:s}=j(),l=C(),u=r(()=>{o(),l.mutate({})},[l,o]);a(()=>{!l.isPending&&!l.data&&u()},[]);let d=n(()=>(l.data?.groups??[]).filter(e=>e.candidates.length>0),[l.data]),f=n(()=>d.reduce((e,t)=>e+t.candidates.length,0),[d]);return e(c,{children:[i(`div`,{className:`flex items-center justify-end gap-2 border-b border-border px-5 py-2 shrink-0`,children:e(`button`,{onClick:u,disabled:l.isPending,className:`flex items-center gap-1 rounded-md border border-border px-2 py-1 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[i(g,{className:`h-3.5 w-3.5 ${l.isPending?`animate-spin`:``}`}),s(`integrations.scanNetworkModal.reScan`,`Re-scan`)]})}),e(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-4`,children:[l.isPending&&i(ie,{label:s(`integrations.scanNetworkModal.scanningTheLocalNetwork`,`Scanning the local network…`)}),!l.isPending&&l.isError&&i($,{}),!l.isPending&&l.data&&d.length===0&&i(`p`,{className:`py-8 text-center text-xs text-foreground-subtle`,children:s(`integrations.scanNetworkModal.noDevicesRespondedToThe`,`No devices responded to the scan.`)}),!l.isPending&&d.length>0&&i(`p`,{className:`text-xs text-foreground-subtle`,children:s(`integrations.scanNetworkModal.found`,{count:f})}),!l.isPending&&d.map(n=>e(`div`,{className:`space-y-1.5`,children:[e(`div`,{className:`flex items-center gap-2`,children:[i(`span`,{className:`text-[11px] font-semibold text-foreground`,children:n.label}),e(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`(`,n.candidates.length,`)`]})]}),n.candidates.map(e=>t(n.addonId,e))]},n.addonId))]})]})}function re({scope:t,onAdopt:n,onReset:a}){let{t:s}=j(),l=A({addonId:t.addonId}).data??null,[d,f]=o({}),p=O(),m=r(()=>{a(),p.mutate({addonId:t.addonId,params:d})},[p,t.addonId,d,a]),h=p.data?.candidates??[];return i(c,{children:e(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-4`,children:[l&&i(M,{schema:l,values:d,onChange:f}),e(`button`,{onClick:m,disabled:p.isPending,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:[p.isPending?i(v,{className:`h-3.5 w-3.5 animate-spin`}):i(u,{className:`h-3.5 w-3.5`}),p.isPending?s(`integrations.scanNetworkModal.scanning`,`Scanning…`):s(`integrations.scanNetworkModal.scan`,`Scan`)]}),p.isError&&i($,{}),!p.isPending&&p.data&&h.length===0&&i(`p`,{className:`py-6 text-center text-xs text-foreground-subtle`,children:s(`integrations.scanNetworkModal.noDevicesRespondedToThe`,`No devices responded to the scan.`)}),!p.isPending&&h.length>0&&e(`div`,{className:`space-y-1.5`,children:[i(`p`,{className:`text-xs text-foreground-subtle`,children:s(`integrations.scanNetworkModal.foundShort`,{count:h.length})}),h.map(e=>n(t.addonId,e))]})]})})}function ie({label:t}){return e(`div`,{className:`flex flex-col items-center py-12`,children:[i(v,{className:`h-6 w-6 animate-spin text-primary`}),i(`p`,{className:`mt-3 text-xs text-foreground-subtle`,children:t})]})}function $(){let{t}=j();return e(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[i(d,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),i(`p`,{className:`text-xs text-destructive`,children:t(`integrations.scanNetworkModal.theScanFailedTryAgain`,`The scan failed. Try again.`)})]})}export{ee as n,X as r,te as t};
|