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-ChE_eana.js";import{Dt as a,Fr as o,G as s,Gr as c,H as l,Hr as u,Kr as d,Nr as f,Ur as p,Vn as m,hr as h,ii as g,j as _,ni as v}from"./mui-vendor-K60S-ugg.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-DPe2hEjt.js";var D=e(g(),1),O=v(),k=()=>{let e=t(),g=n(),{setBreadcrumbs:v}=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)(()=>(v([{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)(_,{fontSize:`small`})}]),()=>v([])),[v]);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:()=>{g.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)(o,{sx:{display:`flex`,justifyContent:`center`,alignItems:`center`,height:`100vh`},children:(0,O.jsx)(c,{})}):F?(0,O.jsx)(o,{sx:T(),children:(0,O.jsx)(p,{severity:`error`,children:`Failed to load general settings.`})}):(0,O.jsxs)(o,{sx:T(),children:[(0,O.jsx)(o,{sx:E(),children:(0,O.jsxs)(o,{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)(f,{variant:`contained`,size:`small`,startIcon:I.isPending?(0,O.jsx)(c,{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)(o,{sx:x(),children:(0,O.jsxs)(d,{elevation:1,sx:{p:3},children:[(0,O.jsx)(u,{variant:`h6`,sx:{mb:2,color:`primary.main`,fontWeight:600},children:`Sales Controls`}),(0,O.jsxs)(o,{sx:{mb:3},children:[(0,O.jsx)(h,{control:(0,O.jsx)(m,{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)(u,{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)(o,{children:[(0,O.jsx)(h,{control:(0,O.jsx)(m,{checked:j.allow_multiple_schemes,onChange:e=>M(t=>({...t,allow_multiple_schemes:e.target.checked}))}),label:`Allow Multiple Schemes`}),(0,O.jsx)(u,{variant:`body2`,color:`text.secondary`,sx:{ml:1},children:`When disabled, only one scheme can be selected per sales order.`})]})]})})]})};export{k as default};