1import{r as v,j as e,aX as k,aY as B,aZ as F,aK as p,o as N,O as y,W as u,a_ as S,a0 as T,a$ as I,_ as O}from"./vendor-BuFaoZ7W.js";import{u as Y,q as L,B as m,r as w}from"./index-7cjzHoP-.js";import{I as j}from"./Input-BHizAjS-.js";import{T as _}from"./Textarea-BRMIPssL.js";import{D as E,a as V,b as z,c as A,e as P,f as q}from"./Dialog-JSWLgpD_.js";import{u as M,F as R,a as n,b as o,c as d,d as c}from"./Form-CWTH6NWS.js";import{I as H}from"./ImageUploadField-B-wQx3AP.js";import"./Input.module-Dmb6Vdaa.js";const K="_container_f6ga5_1",U="_header_f6ga5_7",W="_title_f6ga5_13",X="_tableContainer_f6ga5_21",Z="_table_f6ga5_21",$="_th_f6ga5_34",G="_tr_f6ga5_43",J="_td_f6ga5_51",Q="_actions_f6ga5_63",ee="_emptyState_f6ga5_68",se="_formFields_f6ga5_74",t={container:K,header:U,title:W,tableContainer:X,table:Z,th:$,tr:G,td:J,actions:Q,emptyState:ee,formFields:se},ae=N({id:O().optional(),title:u().min(1,"Title is required"),coverImage:u().nullable(),shortDescription:u().nullable(),fullDescription:u().nullable(),publicationYear:S([y.number(),T(""),I()]).transform(l=>l===""?null:l),externalLink:u().nullable(),displayOrder:y.number().default(0)});function te({book:l,onClose:x}){const{mutateAsync:g,isPending:h}=w(),s=M({schema:ae,defaultValues:{id:l?.id,title:l?.title??"",coverImage:l?.coverImage??"",shortDescription:l?.shortDescription??"",fullDescription:l?.fullDescription??"",publicationYear:l?.publicationYear??null,externalLink:l?.externalLink??"",displayOrder:l?.displayOrder??0}}),f=async a=>{try{await g(a),p.success(l?"Book updated":"Book created"),x()}catch(r){p.error(r.message||"Failed to save book")}};return e.jsx(R,{...s,children:e.jsxs("form",{onSubmit:s.handleSubmit(f),children:[e.jsx(z,{children:e.jsx(A,{children:l?"Edit Book":"New Book"})}),e.jsxs("div",{className:t.formFields,children:[e.jsxs(n,{name:"title",children:[e.jsx(o,{children:"Title"}),e.jsx(d,{children:e.jsx(j,{value:s.values.title,onChange:a=>s.setValues(r=>({...r,title:a.target.value})),placeholder:"Enter book title"})}),e.jsx(c,{})]}),e.jsxs(n,{name:"coverImage",children:[e.jsx(o,{children:"Cover Image"}),e.jsx(H,{value:s.values.coverImage??null,onChange:a=>s.setValues(r=>({...r,coverImage:a}))}),e.jsx(c,{})]}),e.jsxs(n,{name:"shortDescription",children:[e.jsx(o,{children:"Short Description"}),e.jsx(d,{children:e.jsx(_,{value:s.values.shortDescription??"",onChange:a=>s.setValues(r=>({...r,shortDescription:a.target.value})),placeholder:"Brief summary for listings"})}),e.jsx(c,{})]}),e.jsxs(n,{name:"fullDescription",children:[e.jsx(o,{children:"Full Description"}),e.jsx(d,{children:e.jsx(_,{value:s.values.fullDescription??"",onChange:a=>s.setValues(r=>({...r,fullDescription:a.target.value})),placeholder:"Detailed book description",rows:5})}),e.jsx(c,{})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"var(--spacing-4)"},children:[e.jsxs(n,{name:"publicationYear",children:[e.jsx(o,{children:"Publication Year"}),e.jsx(d,{children:e.jsx(j,{type:"number",value:s.values.publicationYear??"",onChange:a=>s.setValues(r=>({...r,publicationYear:a.target.value})),placeholder:"e.g. 2023"})}),e.jsx(c,{})]}),e.jsxs(n,{name:"displayOrder",children:[e.jsx(o,{children:"Display Order"}),e.jsx(d,{children:e.jsx(j,{type:"number",value:s.values.displayOrder??0,onChange:a=>s.setValues(r=>({...r,displayOrder:a.target.value}))})}),e.jsx(c,{})]})]}),e.jsxs(n,{name:"externalLink",children:[e.jsx(o,{children:"External Link (Buy / Read)"}),e.jsx(d,{children:e.jsx(j,{value:s.values.externalLink??"",onChange:a=>s.setValues(r=>({...r,externalLink:a.target.value})),placeholder:"https://..."})}),e.jsx(c,{})]})]}),e.jsxs(P,{children:[e.jsx(q,{asChild:!0,children:e.jsx(m,{variant:"outline",onClick:x,type:"button",children:"Cancel"})}),e.jsx(m,{type:"submit",disabled:h,children:h?"Saving...":"Save Book"})]})]})})}function ue(){const{data:l,isFetching:x}=Y(),{mutateAsync:g}=L(),[h,s]=v.useState(!1),[f,a]=v.useState(),r=()=>{a(void 0),s(!0)},b=i=>{a(i),s(!0)},D=async i=>{if(window.confirm("Are you sure you want to delete this book?"))try{await g({id:i}),p.success("Book deleted")}catch(C){p.error(C.message||"Failed to delete book")}};return e.jsxs("div",{className:t.container,children:[e.jsxs("div",{className:t.header,children:[e.jsx("h1",{className:t.title,children:"Books Manager"}),e.jsxs(m,{onClick:r,children:[e.jsx(k,{size:16})," New Book"]})]}),e.jsx("div",{className:t.tableContainer,children:e.jsxs("table",{className:t.table,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:t.th,children:"Title"}),e.jsx("th",{className:t.th,children:"Publication Year"}),e.jsx("th",{className:t.th,children:"Display Order"}),e.jsx("th",{className:t.th,children:"Actions"})]})}),e.jsx("tbody",{children:x&&!l?e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:t.emptyState,children:"Loading..."})}):l?.items.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:t.emptyState,children:"No books found. Create one to get started."})}):l?.items.map(i=>e.jsxs("tr",{className:t.tr,children:[e.jsx("td",{className:t.td,children:e.jsx("strong",{children:i.title})}),e.jsx("td",{className:t.td,children:i.publicationYear||"â"}),e.jsx("td",{className:t.td,children:i.displayOrder}),e.jsx("td",{className:t.td,children:e.jsxs("div",{className:t.actions,children:[e.jsxs(m,{variant:"outline",size:"sm",onClick:()=>b(i),children:[e.jsx(B,{size:14})," Edit"]}),e.jsxs(m,{variant:"destructive",size:"sm",onClick:()=>D(i.id),children:[e.jsx(F,{size:14})," Delete"]})]})})]},i.id))})]})}),e.jsx(E,{open:h,onOpenChange:s,children:e.jsx(V,{children:h&&e.jsx(te,{book:f,onClose:()=>s(!1)})})})]})}export{ue as default};
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.