import{u as E,r as h,j as e,l as L,m as u,t as f,n as z}from"./index-DkVMZPZp.js";import{P as d}from"./index-ssfNqXSw.js";import{u as O,a as A}from"./use-organization-settings-DZiQDtex.js";import{B as H,a as I,b as j,c as R,d as D,e as F}from"./breadcrumb-B1KWdwh9.js";import{B as p}from"./button-CWzK0IXA.js";import{S as M}from"./switch-Cv7KL0jJ.js";import"./useMutation-CFQDhqDA.js";import"./constants-Chp3RuVB.js";import"./ChevronRight-0gQ-Lwyj.js";function W(){const{org:l}=E(),b=O(l.id),{update:v}=A(l.id),[c,r]=h.useState({}),[a,m]=h.useState(!1),o=b?.enabled_plugins??[],S=s=>{const n=c[s];return n!==void 0?n:o.includes(s)},N=()=>{const s=new Set(o);for(const[n,t]of Object.entries(c))t?s.add(n):s.delete(n);return Array.from(s)},g=Object.keys(c).length>0,P=(s,n)=>{const t=o.includes(s);r(n===t?i=>{const{[s]:x,...k}=i;return k}:i=>({...i,[s]:n}))},C=async()=>{m(!0);try{await v.mutateAsync({enabled_plugins:N()}),r({}),f.success("Plugin settings saved")}catch{f.error("Failed to save plugin settings")}finally{m(!1)}},y=()=>{r({})},w=s=>z.find(n=>n.pluginId===s),B=s=>u.find(t=>t.id===s)?.description??null;return e.jsxs(d,{children:[e.jsx(d.Header,{children:e.jsx(d.Header.Left,{children:e.jsx(H,{children:e.jsxs(I,{children:[e.jsx(j,{children:e.jsx(R,{asChild:!0,children:e.jsx(L,{to:"/$org/settings",params:{org:l.slug},children:"Settings"})})}),e.jsx(D,{}),e.jsx(j,{children:e.jsx(F,{children:"Plugins"})})]})})})}),e.jsx(d.Content,{children:e.jsx("div",{className:"flex h-full",children:e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsx("div",{className:"p-5 max-w-2xl",children:e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"Enable or disable plugins for your organization."})}),e.jsx("div",{className:"divide-y divide-border border-y border-border",children:u.map(s=>{const n=w(s.id),t=B(s.id),i=S(s.id);return e.jsxs("div",{className:"flex items-center justify-between gap-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[n?.icon&&e.jsx("div",{className:"flex-shrink-0 text-muted-foreground [&>svg]:size-4",children:n.icon}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:n?.label??s.id}),t&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t})]})]}),e.jsx(M,{checked:i,onCheckedChange:x=>P(s.id,x),disabled:a})]},s.id)})}),u.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No plugins available."}),e.jsxs("div",{className:"flex items-center gap-3 pt-4",children:[e.jsx(p,{variant:"outline",onClick:y,disabled:!g||a,children:"Cancel"}),e.jsx(p,{onClick:C,disabled:!g||a,className:"min-w-24",children:a?"Saving...":"Save Changes"})]})]})})})})})]})}export{W as default};
