| 1 |
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{A as t,E as n,T as r,o as i,w as a}from"./client-DJ2k8Bkd.js";import{d as o,l as s,n as c}from"./chunk-62JRHF6Z-62UIvfxE.js";import{n as l}from"./QueryClientProvider-NYoTmQud.js";import{t as u}from"./useQuery-CeIc68fT.js";import{t as d}from"./useMutation-XVnfRW5u.js";import{t as f}from"./arrow-left-DId9Sc5n.js";import{t as p}from"./check-B5nucgMH.js";import{n as m}from"./ToastContext-PXQkWm-m.js";import{t as h}from"./loader-circle-s_Jy23um.js";import{t as g}from"./minus-4NdoE8Ka.js";import{t as _}from"./plus-C2X4TO2J.js";import{t as v}from"./printer-XRpYW3_E.js";import{t as y}from"./save-Bb6Yhgeo.js";import{t as ee}from"./search-i6jT-1pw.js";import{t as b}from"./shield-C_Wph3H8.js";import{t as x}from"./triangle-alert-DpPZK8pO.js";import{t as S}from"./x-Bc8zXHIi.js";import{t as C}from"./Card-ToEWQYwA.js";import{t as w}from"./Button-CHEL-SVe.js";import{o as T}from"./filamentScope-CbJ4OV9T.js";var E=a(`spool`,[[`path`,{d:`M17 13.44 4.442 17.082A2 2 0 0 0 4.982 21H19a2 2 0 0 0 .558-3.921l-1.115-.32A2 2 0 0 1 17 14.837V7.66`,key:`13vns8`}],[`path`,{d:`m7 10.56 12.558-3.642A2 2 0 0 0 19.018 3H5a2 2 0 0 0-.558 3.921l1.115.32A2 2 0 0 1 7 9.163v7.178`,key:`s8x3u0`}]]),D=e(t(),1),O=r(),k=[`PLA`,`PETG`,`PCTG`,`ABS`,`ASA`,`TPU`,`PC`,`PA`,`PA-CF`,`PAHT-CF`,`PET-CF`,`PVA`,`HIPS`,`PP`];function te({enabled:e,mode:t,rules:r,disabled:i=!1,onChange:a,onPendingRulesChange:o}){let{t:s}=n(),[c,l]=(0,D.useState)(`material`),[u,d]=(0,D.useState)(``),[f,p]=(0,D.useState)(e);e!==f&&(p(e),e||d(``));let m=n=>a({enabled:e,mode:t,rules:r,...n});(0,D.useEffect)(()=>{o?.(e?T(r,c,u):r)},[e,r,c,u,o]);let h=()=>{let e=T(r,c,u);e!==r&&m({rules:e}),d(``)};return(0,O.jsx)(C,{children:(0,O.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(E,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,O.jsx)(`span`,{className:`text-white font-medium text-sm`,children:s(`groups.editor.filamentAccess`)})]}),i?(0,O.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:s(`groups.editor.adminsUseAllFilaments`)}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-white cursor-pointer`,children:[(0,O.jsx)(`input`,{type:`checkbox`,checked:e,onChange:e=>m({enabled:e.target.checked}),className:`w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark-secondary`}),s(`groups.editor.limitFilaments`)]}),e?(0,O.jsxs)(`div`,{className:`space-y-3`,children:[(0,O.jsx)(`div`,{className:`flex flex-wrap gap-4 text-sm text-white`,children:[`block`,`allow`].map(e=>(0,O.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,O.jsx)(`input`,{type:`radio`,name:`filament-rule-mode`,checked:t===e,onChange:()=>m({mode:e}),className:`text-bambu-green focus:ring-bambu-green bg-bambu-dark-secondary`}),s(e===`block`?`groups.editor.filamentModeBlock`:`groups.editor.filamentModeAllow`)]},e))}),(0,O.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:r.length===0?(0,O.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:s(`groups.editor.noFilamentRules`)}):r.map(e=>(0,O.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 rounded bg-bambu-dark-tertiary text-sm text-white`,children:[(0,O.jsxs)(`span`,{className:`text-bambu-gray`,children:[e.match===`material`?s(`groups.editor.filamentMatchMaterial`):s(`groups.editor.filamentMatchId`),`:`]}),e.value,(0,O.jsx)(`button`,{type:`button`,"aria-label":s(`groups.editor.removeFilamentRule`,{value:e.value}),onClick:()=>m({rules:r.filter(t=>t!==e)}),className:`text-bambu-gray hover:text-white`,children:(0,O.jsx)(S,{className:`w-3 h-3`})})]},`${e.match}:${e.value}`))}),t===`allow`&&r.length===0&&(0,O.jsxs)(`p`,{role:`status`,className:`flex items-center gap-2 text-sm text-yellow-700 dark:text-yellow-400`,children:[(0,O.jsx)(x,{className:`w-4 h-4 shrink-0`}),s(`groups.editor.filamentAllowEmptyWarning`)]}),(0,O.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,O.jsxs)(`select`,{value:c,onChange:e=>{l(e.target.value),d(``)},className:`px-3 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white`,children:[(0,O.jsx)(`option`,{value:`material`,children:s(`groups.editor.filamentMatchMaterial`)}),(0,O.jsx)(`option`,{value:`filament_id`,children:s(`groups.editor.filamentMatchId`)})]}),(0,O.jsx)(`input`,{type:`text`,"aria-label":s(`groups.editor.filamentRuleValue`),value:u,list:c===`material`?`filament-material-suggestions`:void 0,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),h())},placeholder:s(c===`material`?`groups.editor.filamentRuleMaterialPlaceholder`:`groups.editor.filamentRuleIdPlaceholder`),maxLength:64,className:`px-3 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray w-48`}),(0,O.jsx)(`datalist`,{id:`filament-material-suggestions`,children:k.map(e=>(0,O.jsx)(`option`,{value:e},e))}),(0,O.jsxs)(w,{size:`sm`,variant:`secondary`,onClick:h,disabled:!u.trim(),children:[(0,O.jsx)(_,{className:`w-4 h-4`}),s(`groups.editor.addFilamentRule`)]})]}),(0,O.jsx)(`p`,{className:`text-xs text-bambu-gray/80`,children:s(`groups.editor.filamentRulesHint`)})]}):(0,O.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:s(`groups.editor.filamentAccessOpen`)})]})]})})}function A(){let{id:e}=o(),t=s(),r=l(),{t:a}=n(),{showToast:_}=m(),S=!!e,[T,E]=(0,D.useState)(``),[k,A]=(0,D.useState)(``),[j,M]=(0,D.useState)([]),[N,P]=(0,D.useState)(``),[F,I]=(0,D.useState)(!1),[L,R]=(0,D.useState)(!1),[z,B]=(0,D.useState)(`block`),[V,H]=(0,D.useState)([]),[U,W]=(0,D.useState)(null),{data:G,isLoading:K}=u({queryKey:[`group`,e],queryFn:()=>i.getGroup(Number(e)),enabled:S}),{data:q,isLoading:ne}=u({queryKey:[`permissions`],queryFn:()=>i.getPermissions()});S&&G&&!F&&(E(G.name),A(G.description||``),M(G.permissions),R(G.restrict_filaments??!1),B(G.filament_rule_mode??`block`),H(G.filament_rules??[]),I(!0));let J=d({mutationFn:e=>i.createGroup(e),onSuccess:()=>{r.invalidateQueries({queryKey:[`groups`]}),r.invalidateQueries({queryKey:[`group`]}),_(a(`groups.toast.created`)),t(`/settings?tab=users`)},onError:e=>{_(e.message,`error`)}}),Y=d({mutationFn:t=>i.updateGroup(Number(e),t),onSuccess:n=>{r.invalidateQueries({queryKey:[`groups`]}),n&&r.setQueryData([`group`,e],n),_(a(`groups.toast.updated`)),t(`/settings?tab=users`)},onError:e=>{_(e.message,`error`)}}),X=J.isPending||Y.isPending,Z=S&&G?.is_system===!0&&G.name===`Administrators`,re=()=>{if(!T.trim()){_(a(`groups.toast.enterGroupName`),`error`);return}if(S){let e=!G||j.length!==G.permissions.length||j.some(e=>!G.permissions.includes(e));Y.mutate({name:T===G?.name?void 0:T,description:k,permissions:G?.is_system&&!e?void 0:j,...Z?{}:{restrict_filaments:L,filament_rule_mode:z,filament_rules:U??V}})}else J.mutate({name:T,description:k||void 0,permissions:j,restrict_filaments:L,filament_rule_mode:z,filament_rules:U??V})},ie=e=>{M(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},ae=(e,t)=>{let n=e.permissions.map(e=>e.value);M(e=>{let r=e.filter(e=>!n.includes(e));return t?[...r,...n]:r})},oe=e=>e.permissions.every(e=>j.includes(e.value)),se=e=>{let t=e.permissions.filter(e=>j.includes(e.value)).length;return t>0&&t<e.permissions.length},ce=()=>{q&&M(q.all_permissions)},le=()=>{M([])},Q=N.toLowerCase(),$=(0,D.useMemo)(()=>q?Q?q.categories.map(e=>({...e,permissions:e.permissions.filter(e=>e.label.toLowerCase().includes(Q))})).filter(e=>e.permissions.length>0):q.categories:[],[q,Q]),ue=q?.all_permissions.length??0;return K||ne?(0,O.jsx)(`div`,{className:`flex items-center justify-center py-16`,children:(0,O.jsx)(h,{className:`w-8 h-8 text-bambu-green animate-spin`})}):(0,O.jsxs)(`div`,{className:`space-y-6 max-w-5xl mx-auto`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,O.jsx)(`button`,{onClick:()=>t(`/settings?tab=users`),className:`p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors`,children:(0,O.jsx)(f,{className:`w-5 h-5`})}),(0,O.jsx)(`h1`,{className:`text-xl font-bold text-white`,children:a(S?`groups.editor.title`:`groups.editor.createTitle`)})]}),S&&G?.is_system&&(0,O.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-yellow-50 dark:bg-yellow-500/10 border border-yellow-300 dark:border-yellow-500/20 text-yellow-700 dark:text-yellow-400 text-sm`,children:[(0,O.jsx)(x,{className:`w-4 h-4 shrink-0`}),a(`groups.form.systemGroupWarning`)]}),(0,O.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:a(`groups.form.groupName`)}),(0,O.jsx)(`input`,{type:`text`,value:T,onChange:e=>E(e.target.value),disabled:S&&G?.is_system,className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-50`,placeholder:a(`groups.form.groupNamePlaceholder`)})]}),(0,O.jsxs)(`div`,{children:[(0,O.jsx)(`label`,{className:`block text-sm font-medium text-white mb-2`,children:a(`groups.form.description`)}),(0,O.jsx)(`input`,{type:`text`,value:k,onChange:e=>A(e.target.value),className:`w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:a(`groups.form.descriptionPlaceholder`)})]})]}),(0,O.jsx)(C,{children:(0,O.jsxs)(`div`,{className:`p-4 flex flex-wrap items-center justify-between gap-3`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,O.jsx)(v,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,O.jsx)(`span`,{className:`text-white font-medium text-sm`,children:a(`groups.editor.printerAccess`)}),(0,O.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:Z?a(`groups.editor.adminsSeeAllPrinters`):S?G?.restrict_printers?a(`groups.editor.printerAccessLimited`,{printers:G.printer_ids.length,locations:G.locations?.length??0}):a(`groups.editor.printerAccessOpen`):a(`groups.editor.printerAccessAfterCreate`)})]}),S&&!Z&&(0,O.jsx)(c,{to:`/settings?tab=users&sub=printer-access&group=${e}`,className:`text-sm text-bambu-green hover:underline shrink-0`,children:a(`groups.editor.managePrinterAccess`)})]})}),(0,O.jsx)(te,{enabled:L,mode:z,rules:V,disabled:Z,onChange:({enabled:e,mode:t,rules:n})=>{R(e),B(t),H(n)},onPendingRulesChange:W}),(0,O.jsxs)(`div`,{className:`flex items-center justify-between flex-wrap gap-3`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,O.jsxs)(`span`,{className:`text-sm text-bambu-gray`,children:[a(`groups.editor.permissionsSelected`,{count:j.length}),` / `,ue]}),(0,O.jsx)(w,{size:`sm`,variant:`ghost`,onClick:ce,children:a(`groups.editor.selectAll`)}),(0,O.jsx)(w,{size:`sm`,variant:`ghost`,onClick:le,children:a(`groups.editor.clearAll`)})]}),(0,O.jsxs)(`div`,{className:`relative`,children:[(0,O.jsx)(ee,{className:`w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-bambu-gray`}),(0,O.jsx)(`input`,{type:`text`,value:N,onChange:e=>P(e.target.value),placeholder:a(`groups.editor.search`),className:`pl-9 pr-4 py-2 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors w-64`})]})]}),$.length===0?(0,O.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:a(`groups.editor.noResults`)}):(0,O.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:$.map(e=>{let t=q.categories.find(t=>t.name===e.name),n=t.permissions.filter(e=>j.includes(e.value)).length,r=t.permissions.length,i=oe(t),o=se(t);return(0,O.jsxs)(C,{children:[(0,O.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center justify-between px-4 py-3 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary rounded-t-xl`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,O.jsxs)(`button`,{type:`button`,onClick:()=>ae(t,!i),className:`w-5 h-5 rounded border flex items-center justify-center transition-colors shrink-0 ${i?`bg-bambu-green border-bambu-green`:o?`bg-bambu-green/50 border-bambu-green`:`border-bambu-gray hover:border-white`}`,children:[i&&(0,O.jsx)(p,{className:`w-3 h-3 text-white`}),o&&!i&&(0,O.jsx)(g,{className:`w-3 h-3 text-white`})]}),(0,O.jsx)(b,{className:`w-4 h-4 text-bambu-gray shrink-0`}),(0,O.jsx)(`span`,{className:`text-white font-medium text-sm`,children:e.name})]}),(0,O.jsxs)(`span`,{className:`text-xs text-bambu-gray tabular-nums`,children:[n,`/`,r]})]}),(0,O.jsx)(`div`,{className:`p-3 space-y-1`,children:e.permissions.map(e=>(0,O.jsxs)(`label`,{className:`flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-secondary cursor-pointer`,children:[(0,O.jsx)(`input`,{type:`checkbox`,checked:j.includes(e.value),onChange:()=>ie(e.value),className:`w-4 h-4 shrink-0 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark-secondary`}),(0,O.jsxs)(`span`,{className:`flex flex-col`,children:[(0,O.jsx)(`span`,{className:`text-sm text-bambu-gray`,children:e.label}),e.value===`websocket:connect`&&(0,O.jsx)(`span`,{className:`text-xs text-bambu-gray/60`,children:a(`groups.editor.websocketHint`)})]})]},e.value))})]},e.name)})}),(0,O.jsx)(`div`,{className:`h-16`}),(0,O.jsxs)(`div`,{className:`fixed bottom-0 left-0 right-0 z-20 px-6 py-3 bg-bambu-dark-secondary border-t border-bambu-dark-tertiary flex items-center justify-center gap-3`,children:[(0,O.jsx)(w,{variant:`secondary`,onClick:()=>t(`/settings?tab=users`),children:a(`common.cancel`)}),(0,O.jsx)(w,{onClick:re,disabled:X||!T.trim(),children:X?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(h,{className:`w-4 h-4 animate-spin`}),a(`common.saving`)]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(y,{className:`w-4 h-4`}),a(`common.save`)]})})]})]})}export{A as GroupEditPage};
|