import{o as e}from"./rolldown-runtime-GyhWBpbT.js";import{F as t,l as n,o as r,s as i}from"./react-vendor-BD_NkAgt.js";import{Dt as a,Fr as o,G as s,Gr as c,H as l,Jr as u,Lr as d,Un as f,Wr as p,_r as m,ii as h,j as g,oi as _,qr as v}from"./mui-vendor-DsoH2_ot.js";import"./state-vendor-Cw2RdylD.js";import{D as y,V as b,_ as x,ft as S,rt as C,w,x as T,y as E}from"./index-Bo9BrBsx.js";var D=e(_(),1),O=h(),k=()=>{let e=t(),h=n(),{setBreadcrumbs:_}=y(),{success:k,error:A}=S(),[j,M]=(0,D.useState)({company_scoped_item_enforcement:!1,allow_multiple_schemes:!0});w(`General Settings`),(0,D.useEffect)(()=>(_([{label:`Home`,path:`/`,icon:(0,O.jsx)(a,{fontSize:`small`})},{label:`Settings`,path:`/settings`,icon:(0,O.jsx)(l,{fontSize:`small`})},{label:`General Settings`,icon:(0,O.jsx)(g,{fontSize:`small`})}]),()=>_([])),[_]);let{data:N,isLoading:P,isError:F}=i({queryKey:[`generalSettings`],queryFn:b.getGeneralSettings});(0,D.useEffect)(()=>{N&&M({company_scoped_item_enforcement:N.company_scoped_item_enforcement,allow_multiple_schemes:N.allow_multiple_schemes})},[N]);let I=r({mutationFn:b.updateGeneralSettings,onSuccess:()=>{h.invalidateQueries({queryKey:[`generalSettings`]}),k(`General settings updated successfully`)},onError:e=>{A(e?.response?.data?.detail||`Failed to update general settings`)}}),L=!!N&&(j.company_scoped_item_enforcement!==N.company_scoped_item_enforcement||j.allow_multiple_schemes!==N.allow_multiple_schemes);return P?(0,O.jsx)(d,{sx:{display:`flex`,justifyContent:`center`,alignItems:`center`,height:`100vh`},children:(0,O.jsx)(v,{})}):F?(0,O.jsx)(d,{sx:T(),children:(0,O.jsx)(c,{severity:`error`,children:`Failed to load general settings.`})}):(0,O.jsxs)(d,{sx:T(),children:[(0,O.jsx)(d,{sx:E(),children:(0,O.jsxs)(d,{sx:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,gap:2,flexWrap:`wrap`},children:[(0,O.jsx)(C,{title:`General Settings`,showBackButton:!0,onBack:()=>e(`/settings`),disableBox:!0}),(0,O.jsx)(o,{variant:`contained`,size:`small`,startIcon:I.isPending?(0,O.jsx)(v,{size:16,color:`inherit`}):(0,O.jsx)(s,{fontSize:`small`}),onClick:()=>{I.mutate(j)},disabled:!L||I.isPending,children:I.isPending?`Saving...`:`Save Changes`})]})}),(0,O.jsx)(d,{sx:x(),children:(0,O.jsxs)(u,{elevation:1,sx:{p:3},children:[(0,O.jsx)(p,{variant:`h6`,sx:{mb:2,color:`primary.main`,fontWeight:600},children:`Sales Controls`}),(0,O.jsxs)(d,{sx:{mb:3},children:[(0,O.jsx)(m,{control:(0,O.jsx)(f,{checked:j.company_scoped_item_enforcement,onChange:e=>M(t=>({...t,company_scoped_item_enforcement:e.target.checked}))}),label:`Company-Scoped Item Enforcement`}),(0,O.jsx)(p,{variant:`body2`,color:`text.secondary`,sx:{ml:1},children:`When enabled, Item Master company becomes mandatory and Sales Order item selection is restricted to the selected header company.`})]}),(0,O.jsxs)(d,{children:[(0,O.jsx)(m,{control:(0,O.jsx)(f,{checked:j.allow_multiple_schemes,onChange:e=>M(t=>({...t,allow_multiple_schemes:e.target.checked}))}),label:`Allow Multiple Schemes`}),(0,O.jsx)(p,{variant:`body2`,color:`text.secondary`,sx:{ml:1},children:`When disabled, only one scheme can be selected per sales order.`})]})]})})]})};export{k as default};