1import{m as d,k as t}from"./BSYLsQ-1.js";import{k1 as y,it as v,jd as M,jE as F,gn as K,bp as B,br as I,bv as w,bw as P,bs as Q,cc as U,cg as O,ae as E,k0 as ae,jU as ne,jT as q,jO as S,fr as re,bL as se,bl as oe,d$ as ie,fM as le,en as ce,ep as de}from"./sSvtHvyR.js";import{u as me}from"./DDqtQ-Fi.js";import{A as ue}from"./e0Y6qrIs.js";import{D as pe}from"./B1S2JH2m.js";import{B as f}from"./DLJ5nik9.js";import"./J_Wt1L_a.js";import"./DjlRatrT.js";import"./SFk0Fnst.js";function fe({open:i,onClose:g,onSubmit:l,isLoading:n}){const{t:s}=y("KitapKategorileri"),{t:o,ready:m}=y("Shared"),h=d.useMemo(()=>m?v({Name:M().min(1,o("Required"))}):v({}),[o,m]),a=F({resolver:K(h),defaultValues:{Name:""}});d.useEffect(()=>{i&&a.reset({Name:""})},[i,a]);const c=p=>{n||l(p)},u=()=>{a.reset(),g()};return t.jsx(B,{open:i,onOpenChange:u,children:t.jsxs(I,{className:"max-w-2xl p-0 gap-0",children:[t.jsxs(w,{className:"px-6 pt-6 pb-4 bg-gradient-to-r from-primary/5 to-transparent border-b",children:[t.jsx(P,{className:"tracking-tight text-xl font-semibold text-foreground",children:s("Create")}),t.jsx(Q,{className:"sr-only",children:s("CreateDescription")})]}),t.jsx(U,{...a,children:t.jsx("form",{onSubmit:a.handleSubmit(c),className:"px-6 py-5 overflow-y-auto space-y-4",children:t.jsx(O,{control:a.control,name:"Name",label:s("name"),type:"text",placeholder:s("Entername"),required:!0,disabled:n})})}),t.jsxs("div",{className:"px-6 py-4 bg-muted/20 border-t flex items-center justify-end gap-3",children:[t.jsx(E,{type:"button",variant:"outline",onClick:u,disabled:n,className:"min-w-[100px]",children:o("Cancel")}),t.jsx(E,{type:"submit",variant:"primary",disabled:n,className:"min-w-[120px]",onClick:a.handleSubmit(c),children:o(n?"Saving":"Save")})]})]})})}function ge({onClose:i,onSubmit:g,isLoading:l,item:n}){const{t:s}=y("KitapKategorileri"),{t:o,ready:m}=y("Shared"),h=d.useMemo(()=>m?v({Name:M().min(1,o("Required"))}):v({}),[o,m]),a=F({resolver:K(h),defaultValues:{Name:n.name||""}});d.useEffect(()=>{n&&a.reset({Name:n.name||""})},[n,a]);const c=u=>{l||g(u)};return t.jsx(B,{open:!0,onOpenChange:i,children:t.jsxs(I,{className:"max-w-2xl p-0 gap-0",children:[t.jsxs(w,{className:"px-6 pt-6 pb-4 bg-gradient-to-r from-primary/5 to-transparent border-b",children:[t.jsx(P,{className:"tracking-tight text-xl font-semibold text-foreground",children:s("Update")}),t.jsx(Q,{className:"sr-only",children:s("UpdateDescription")})]}),t.jsx(U,{...a,children:t.jsx("form",{onSubmit:a.handleSubmit(c),className:"px-6 py-5 overflow-y-auto space-y-4",children:t.jsx(O,{control:a.control,name:"Name",label:s("name"),type:"text",placeholder:s("Entername"),required:!0,disabled:l})})}),t.jsxs("div",{className:"px-6 py-4 bg-muted/20 border-t flex items-center justify-end gap-3",children:[t.jsx(E,{type:"button",variant:"outline",onClick:i,disabled:l,className:"min-w-[100px]",children:o("Cancel")}),t.jsx(E,{type:"submit",variant:"primary",disabled:l,className:"min-w-[120px]",onClick:a.handleSubmit(c),children:o(l?"Saving":"Save")})]})]})})}function Ne(){const{t:i}=y("KitapKategorileri"),{t:g}=y("Shared"),{showSuccess:l,showError:n}=ae(),s=ne(),[o,m]=d.useState({open:!1,item:null}),[h,a]=d.useState(!1),[c,u]=d.useState({open:!1,item:null}),[p,k]=d.useState(null),{data:N,isPending:_,error:x}=q({queryKey:["bookCategory"],queryFn:()=>f.getAll(),retry:2,retryDelay:1e3}),R=(N==null?void 0:N.data)??[],{data:b}=q({queryKey:["bookCategory-detail",p],queryFn:()=>f.getById(p),enabled:!!p,staleTime:de.NO_CACHE,gcTime:ce.NO_CACHE});d.useEffect(()=>{x&&n(x,"DataLoadError")},[x,n]),d.useEffect(()=>{b!=null&&b.data&&p&&(u({open:!0,item:b.data}),k(null))},[b,p]);const C=S({mutationFn:e=>f.delete(e),onSuccess:()=>{s.invalidateQueries({queryKey:["bookCategory"]}),l("delete")},onError:e=>{console.error("Delete error:",e),n(e)}}),D=S({mutationFn:e=>f.create(e),onSuccess:()=>{s.invalidateQueries({queryKey:["bookCategory"]}),a(!1),l("save")},onError:e=>{console.error("Create error:",e),n(e)}}),A=S({mutationFn:({id:e,data:r})=>f.update(e,r),onSuccess:()=>{s.invalidateQueries({queryKey:["bookCategory"]}),u({open:!1,item:null}),l("update")},onError:e=>{console.error("Update error:",e),n(e)}}),H=S({mutationFn:({id:e,propertyName:r,propertyValue:j})=>f.patch(e,r,j),onSuccess:()=>{s.invalidateQueries({queryKey:["bookCategory"]}),l("changes")}
1,onError:e=>{console.error("Patch error:",e),n(e),s.invalidateQueries({queryKey:["bookCategory"]})}}),G=me({queryKey:["bookCategory"],mutationFn:(e,r)=>f.patch(e,"IsActive",r),toggleField:"isActive",showSuccessToast:!0}),V=[{field:"name",headerName:i("name"),filterType:"string",flex:1,editable:!0,editType:"text"},{field:"isActive",headerName:i("isActive"),filterType:"boolean",flex:1,cellStyle:{display:"flex",alignItems:"center",justifyContent:"center",padding:"0 !important",margin:"0 !important"},customCellRenderer:e=>{const r=e.data;return!r||!r.id?null:t.jsx(re,{checked:!!e.value,onCheckedChange:()=>G.toggle(r.id,!r.isActive),size:"sm"})}}],Y=e=>{e.id&&k(e.id)},z=e=>{C.isPending||!e.id||m({open:!0,item:e})},$=()=>{var e;(e=o.item)!=null&&e.id&&(C.mutate(o.item.id),m({open:!1,item:null}))},T=()=>{m({open:!1,item:null})},J=()=>{a(!0)},W=e=>{D.mutate(e)},X=e=>{var r;(r=c.item)!=null&&r.id&&A.mutate({id:c.item.id,data:e})},Z=(e,r,j,ee)=>{if(j===ee||!e.id)return;const te=r.charAt(0).toUpperCase()+r.slice(1);H.mutate({id:e.id,propertyName:te,propertyValue:j})},L=e=>[{label:g("Edit"),icon:ie,onClick:()=>Y(e),variant:"default"},{label:C.isPending?i("Deleting"):i("Delete"),icon:le,onClick:()=>z(e),variant:"destructive"}];return x?t.jsx("div",{className:"flex items-center justify-center h-96",children:t.jsxs("div",{className:"text-red-500",children:[i("Error"),": ",x.message]})}):t.jsxs(se,{children:[t.jsx(oe,{data:R,columns:V,title:i("BookCategory"),description:i("Description"),isPending:_,onAddClick:J,onCellEdit:Z,actions:e=>t.jsx(ue,{row:e,actions:L(e)}),texts:{addButtonLabel:g("Add")}}),t.jsx(pe,{open:o.open,onOpenChange:e=>!e&&T(),onConfirm:$,onCancel:T,isLoading:C.isPending}),t.jsx(fe,{open:h,onClose:()=>a(!1),onSubmit:W,isLoading:D.isPending}),c.open&&c.item&&t.jsx(ge,{onClose:()=>u({open:!1,item:null}),onSubmit:X,isLoading:A.isPending,item:c.item},c.item.id)]})}export{Ne as BookCategoryPage,f as BookCategoryService,fe as CreateBookCategory,ge as EditBookCategory};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.