1import{r as e,j as s,a1 as t,ad as r,ae as a,X as o,af as n,ah as i,ai as l,aj as d,ak as c,z as u,ab as h,ac as m}from"./vendor-DKpN-gn6.js";import{u as x,s as p,B as j,c as g}from"./index-CjqWG2Gu.js";import{C as b,b as v,c as f,d as y,a as k}from"./card-C0twyzQf.js";import{I as N}from"./input-BczSeZo5.js";import{I as w}from"./ImportCSVDialog-DDdn8rq6.js";import{b as S,c as C,T as _,d as F,e as B,a as E}from"./table-DbVpf6SP.js";import{B as L}from"./badge-BupusfKi.js";import{T as z,a as A,b as P,c as D}from"./tooltip-FmFdmcE2.js";import{A as O,a as T,b as q,c as R,d as V,e as $,f as I,g as U}from"./alert-dialog-BdTOaT7i.js";import{D as M,a as W,c as J,d as G,e as K,f as Q}from"./dialog-vWJa2GV8.js";import{u as Y,t as H,F as X,a as Z,b as ee,c as se,d as te,e as re}from"./form-gUyvjEUn.js";import{z as ae}from"./index-Cpv5ucUd.js";import{i as oe,j as ne,L as ie,k as le,l as de,m as ce}from"./ui-DbiJ6HOd.js";import{S as ue,a as he,b as me,c as xe,d as pe}from"./select-CjMQhslo.js";import{I as je}from"./ImplementationNotice-DgNcf9f2.js";import{L as ge}from"./label-D75N5ztj.js";import"./auth-D0Oxv0aP.js";import"./alert-CTiCasZu.js";const be=()=>{const{bookstores:s,setBookstores:t,loading:r,error:a,fetchBookstores:o}=(()=>{const[s,t]=e.useState([]),[r,a]=e.useState(!1),[o,n]=e.useState(null),{toast:i}=x();return{bookstores:s,setBookstores:t,loading:r,error:o,fetchBookstores:async()=>{a(!0),n(null);try{const{data:e,error:s}=await p.from("bookstores").select("*").order("name");if(s)throw s;const r=e?[...e].sort(((e,s)=>e.featured&&!s.featured?-1:!e.featured&&s.featured?1:e.name.localeCompare(s.name))):[];t(r)}catch(e){n(e.message||"Failed to load bookstores"),i({variant:"destructive",title:"Error",description:"Failed to load bookstores. Please try again."})}finally{a(!1)}}}})(),{loading:n,createBookstore:i}=(s=>{const[t,r]=e.useState(!1),{toast:a}=x();return{loading:t,createBookstore:async e=>{r(!0);try{const{data:t,error:r}=await p.from("bookstores").insert([e]).select().single();if(r)throw r;return s&&s((e=>[...e,t].sort(((e,s)=>e.name.localeCompare(s.name))))),a({title:"Bookstore Created",description:`${e.name} has been created successfully.`}),!0}catch(t){return a({variant:"destructive",title:"Error",description:"Failed to create bookstore. Please try again."}),!1}finally{r(!1)}}}})(t),{loading:l,updateBookstore:d}=(s=>{const[t,r]=e.useState(!1),{toast:a}=x();return{loading:t,updateBookstore:async(e,t)=>{r(!0);try{const{data:r,error:o}=await p.from("bookstores").update(t).eq("id",e).select().single();if(o)throw o;return s&&s((s=>s.map((s=>s.id===e?r:s)))),a({title:"Bookstore Updated",description:`${t.name} has been updated successfully.`}),!0}catch(o){return a({variant:"destructive",title:"Error",description:"Failed to update bookstore. Please try again."}),!1}finally{r(!1)}}}})(t),{loading:c,deleteBookstore:u}=(s=>{const[t,r]=e.useState(!1),{toast:a}=x();return{loading:t,deleteBookstore:async e=>{r(!0);try{const{error:t}=await p.from("bookstores").delete().eq("id",e);if(t)throw t;return s&&s((s=>s.filter((s=>s.id!==e)))),a({title:"Bookstore Deleted",description:"The bookstore has been deleted successfully."}),!0}catch(t){return a({variant:"destructive",title:"Error",description:"Failed to delete bookstore. Please try again."}),!1}finally{r(!1)}}}})(t),{loading:h,toggleFeatured:m,toggleStatus:j}=(s=>{const[t,r]=e.useState(!1),{toast:a}=x();return{loading:t,toggleFeatured:async e=>{r(!0);try{const{error:t}=await p.from("bookstores").update({featured:!e.featured}).eq("id",e.id);if(t)throw t;return s&&s((s=>s.map((s=>s.id===e.id?{...s,featured:!s.featured}:{...s})))),a({title:e.featured?"Bookstore Unfeatured":"Bookstore Featured",description:`${e.name} has been ${e.featured?"unfeatured":"featured"} successfully.`}),!0}catch(t){return a({variant:"destructive",title:"Error",description:"Failed to update featured status. Please try again."}),!1}finally{r(!1)}},toggleStatus:async e=>{const t="active"===e.status?"inactive":"active";r(!0);try{const{error:r}=await p.from("bookstores").update({status:t}).eq("id",e.id);if(r)throw r;return s&&s((s=>s.map((s=>s.id===e.id?{...s,status:t}:{...s}
1)))),a({title:"Status Updated",description:`${e.name} is now ${t}.`}),!0}catch(o){return a({variant:"destructive",title:"Error",description:"Failed to update status. Please try again."}),!1}finally{r(!1)}}}})(t);return{bookstores:s,loading:r||n||l||c||h,error:a,fetchBookstores:o,createBookstore:i,updateBookstore:d,toggleFeatured:m,toggleStatus:j,deleteBookstore:u}},ve=({bookstores:e,isLoading:i,toggleFeatured:l,toggleStatus:d,onEdit:c,onDelete:u})=>s.jsx("div",{className:"border rounded-md overflow-hidden",children:s.jsxs(S,{children:[s.jsx(C,{children:s.jsxs(_,{children:[s.jsx(F,{children:"Name"}),s.jsx(F,{className:"hidden md:table-cell",children:"Location"}),s.jsx(F,{className:"hidden md:table-cell",children:"Status"}),s.jsx(F,{className:"hidden md:table-cell",children:"Type"}),s.jsx(F,{className:"hidden md:table-cell",children:"Book Status"}),s.jsx(F,{className:"hidden md:table-cell text-center",children:"Featured"}),s.jsx(F,{className:"text-right",children:"Actions"})]})}),s.jsx(B,{children:i?s.jsx(_,{children:s.jsx(E,{colSpan:7,className:"text-center py-16",children:s.jsxs("div",{className:"flex flex-col items-center justify-center",children:[s.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-brand-blue border-t-transparent mb-2"}),s.jsx("p",{className:"text-gray-500",children:"Loading bookstores..."})]})})}):0===e.length?s.jsx(_,{children:s.jsx(E,{colSpan:7,className:"text-center py-16",children:s.jsx("p",{className:"text-gray-500",children:"No bookstores found"})})}):e.map((e=>s.jsxs(_,{children:[s.jsx(E,{className:"font-medium",children:s.jsxs("div",{children:[e.name,s.jsxs("div",{className:"md:hidden text-xs text-gray-500",children:[e.city,", ",e.province]})]})}),s.jsxs(E,{className:"hidden md:table-cell",children:[e.city,", ",e.province,", ",e.country]}),s.jsx(E,{className:"hidden md:table-cell",children:s.jsx(L,{variant:"active"===e.status?"default":"outline",children:e.status||"active"})}),s.jsx(E,{className:"hidden md:table-cell",children:e.type||"-"}),s.jsx(E,{className:"hidden md:table-cell",children:e.book_status||"-"}),s.jsx(E,{className:"hidden md:table-cell text-center",children:e.featured?s.jsx(t,{size:18,className:"text-yellow-500 fill-yellow-500 mx-auto"}):null}),s.jsx(E,{className:"text-right",children:s.jsxs("div",{className:"flex justify-end space-x-2",children:[s.jsx(z,{children:s.jsxs(A,{children:[s.jsx(P,{asChild:!0,children:s.jsxs(j,{variant:"ghost",size:"icon",onClick:()=>l(e),children:[e.featured?s.jsx(t,{size:18,className:"text-yellow-500 fill-yellow-500"}):s.jsx(t,{size:18}),s.jsx("span",{className:"sr-only",children:e.featured?"Unfeature":"Feature"})]})}),s.jsx(D,{children:s.jsx("p",{children:e.featured?"Unfeature":"Feature"})})]})}),s.jsx(z,{children:s.jsxs(A,{children:[s.jsx(P,{asChild:!0,children:s.jsxs(j,{variant:"ghost",size:"icon",onClick:()=>c(e),children:[s.jsx(r,{size:18}),s.jsx("span",{className:"sr-only",children:"Edit"})]})}),s.jsx(D,{children:s.jsx("p",{children:"Edit"})})]})}),s.jsx(z,{children:s.jsxs(A,{children:[s.jsx(P,{asChild:!0,children:s.jsxs(j,{variant:"ghost",size:"icon",onClick:()=>u(e),children:[s.jsx(a,{size:18}),s.jsx("span",{className:"sr-only",children:"Delete"})]})}),s.jsx(D,{children:s.jsx("p",{children:"Delete"})})]})}),s.jsx(z,{children:s.jsxs(A,{children:[s.jsx(P,{asChild:!0,children:s.jsxs(j,{variant:"ghost",size:"icon",onClick:()=>d(e),children:["active"===e.status?s.jsx(o,{size:18}):s.jsx(n,{size:18}),s.jsx("span",{className:"sr-only",children:"active"===e.status?"Deactivate":"Activate"})]})}),s.jsx(D,{children:s.jsx("p",{children:"active"===e.status?"Deactivate":"Activate"})})]})})]})})]},e.id)))})]})}),fe=({open:e,onOpenChange:t,bookstoreName:r,onConfirm:a})=>s.jsx(O,{open:e,onOpenChange:t,children:s.jsxs(T,{children:[s.jsxs(q,{children:[s.jsx(R,{children:"Are you sure?"}),s.jsxs(V,{children:['This will permanently delete the bookstore "',r,'" and cannot be undone.']})]}),s.jsxs($,{children:[s.jsx(I,{children:"Cancel"}),s.jsx(U,{onClick:a,className:"bg-red-600 hover:bg-red-700",children:"Delete"})]})]})}),ye=e.forwardRef((({className:e,...t},r)=>s.jsx(oe,{ref:r,className:g("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",e),...t,children:s.jsx(ne,{className:g("flex items-center justify-center text-current"),children:s.jsx(n,{className:"h-4 w-4"})})})));
1ye.displayName=oe.displayName;const ke=ae.object({name:ae.string().min(1,"Name is required"),address_1:ae.string().min(1,"Address is required"),address_2:ae.string().optional(),city:ae.string().min(1,"City is required"),province:ae.string().min(1,"Province is required"),country:ae.string().min(1,"Country is required"),postal_code:ae.string().min(1,"Postal code is required"),phone_number:ae.string().optional(),website:ae.string().optional(),book_status:ae.string().optional().nullable(),type:ae.string().optional().nullable(),status:ae.string().min(1,"Status is required"),featured:ae.boolean().default(!1)}),Ne=({bookstore:t,onSubmit:r,isLoading:a})=>{const[o,n]=e.useState([]),[i,l]=e.useState([]),[d,c]=e.useState([]),[u,h]=e.useState([]),m=Y({resolver:H(ke),defaultValues:{name:t?.name||"",address_1:t?.address_1||"",address_2:t?.address_2||"",city:t?.city||"",province:t?.province||"",country:t?.country||"",postal_code:t?.postal_code||"",phone_number:t?.phone_number||"",website:t?.website||"",book_status:t?.book_status||null,type:t?.type||null,status:t?.status||"active",featured:t?.featured||!1}});return e.useEffect((()=>{(async()=>{try{const{data:e}=await p.from("bookstores").select("province").not("province","is",null),{data:s}=await p.from("bookstores").select("country").not("country","is",null),{data:t}=await p.from("bookstores").select("book_status").not("book_status","is",null),{data:r}=await p.from("bookstores").select("type").not("type","is",null),a=[...new Set(e?.map((e=>e.province)))].sort(),o=[...new Set(s?.map((e=>e.country)))].sort(),i=[...new Set(t?.map((e=>e.book_status)).filter(Boolean))].sort(),d=[...new Set(r?.map((e=>e.type)).filter(Boolean))].sort();n(a),l(o),c(i),h(d)}catch(e){n([]),l([]),c([]),h([])}})()}),[]),s.jsx(X,{...m,children:s.jsxs("form",{onSubmit:m.handleSubmit(r),className:"space-y-6",children:[s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[s.jsx(Z,{control:m.control,name:"name",render:({field:e})=>s.jsxs(ee,{children:[s.jsx(se,{children:"Bookstore Name*"}),s.jsx(te,{children:s.jsx(N,{...e,placeholder:"Enter bookstore name"})}),s.jsx(re,{})]})}),s.jsx(Z,{control:m.control,name:"status",render:({field:e})=>s.jsxs(ee,{children:[s.jsx(se,{children:"Status*"}),s.jsxs(ue,{onValueChange:e.onChange,defaultValue:e.value,children:[s.jsx(te,{children:s.jsx(he,{children:s.jsx(me,{placeholder:"Select status"})})}),s.jsxs(xe,{children:[s.jsx(pe,{value:"active",children:"Active"}),s.jsx(pe,{value:"inactive",children:"Inactive"})]})]}),s.jsx(re,{})]})})]}),s.jsx(Z,{control:m.control,name:"address_1",render:({field:e})=>s.jsxs(ee,{children:[s.jsx(se,{children:"Address Line 1*"}),s.jsx(te,{children:s.jsx(N,{...e,placeholder:"Enter address line 1"})}),s.jsx(re,{})]})}),s.jsx(Z,{control:m.control,name:"address_2",render:({field:e})=>s.jsxs(ee,{children:[s.jsx(se,{children:"Address Line 2"}),s.jsx(te,{children:s.jsx(N,{...e,placeholder:"Enter address line 2 (optional)"})}),s.jsx(re,{})]})}),s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[s.jsx(Z,{control:m.control,name:"city",render:({field:e})=>s.jsxs(ee,{children:[s.jsx(se,{children:"City*"}),s.jsx(te,{children:s.jsx(N,{...e,placeholder:"Enter city"})}),s.jsx(re,{})]})}),s.jsx(Z,{control:m.control,name:"province",render:({field:e})=>s.jsxs(ee,{children:[s.jsx(se,{children:"Province/State*"}),s.jsx(te,{children:s.jsx(N,{...e,placeholder:"Enter province/state",list:"province-options"})}),s.jsx("datalist",{id:"province-options",children:o.map((e=>s.jsx("option",{value:e},e)))}),s.jsx(re,{})]})})]}),s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[s.jsx(Z,{control:m.control,name:"country",render:({field:e})=>s.jsxs(ee,{children:[s.jsx(se,{children:"Country*"}),s.jsx(te,{children:s.jsx(N,{...e,placeholder:"Enter country",list:"country-options"})}),s.jsx("datalist",{id:"country-options",children:i.map((e=>s.jsx("option",{value:e},e)))}),s.jsx(re,{})]})}),s.jsx(Z,{control:m.control,name:"postal_code",render:({field:e})=>s.jsxs(ee,{children:[s.jsx(se,{children:"Postal Code*"}),s.jsx(te,{children:s.jsx(N,{...e,placeholder:"Enter postal code"})}),s.jsx(re,{})]})})]}),s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[s.jsx(Z,{control:m.control,name:"phone_number",render:({field:e})=>s.jsxs(ee,{children:[s.jsx(se,{children:"Phone Number"}),s.jsx(te,{children:s.jsx(N,{...e,placeholder:"Enter phone number (optional)"})}),s.jsx(re,{})]})}),s.jsx(Z,{control:m.control,name:"website",render:({field:e})=>s.jsxs(ee,{children:[s.jsx(se,{children:"Website"}),s.jsx(te,{children:s.jsx(N,{...e,placeholder:"Enter website URL (optional)"})}),s.jsx(re,{})]})})]}),s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[s.jsx(Z,{control:m.control,name:"book_status",render:({field:e})=>s.jsxs(ee,{children:[s.jsx(se,{children:"Book Status"}),s.jsx(te,{children:s.jsx(N,{value:e.value||"",onChange:s=>e.onChange(s.target.value||null),placeholder:"Enter book status (optional)",list:"book-status-options"})}),s.jsx("datalist",{id:"book-status-options",children:d.map((e=>s.jsx("option",{value:e},e)))}),s.jsx(re,{})]})}),s.jsx(Z,{control:m.control,name:"type",render:({field:e})=>s.jsxs(ee,{children:[s.jsx(se,{children:"Store Type"}),s.jsx(te,{children:s.jsx(N,{value:e.value||"",onChange:s=>e.onChange(s.target.value||null),placeholder:"Enter store type (optional)",list:"store-type-options"})}),s.jsx("datalist",{id:"store-type-options",children:u.map((e=>s.jsx("option",{value:e},e)))}),s.jsx(re,{})]})})]}),s.jsx(Z,{control:m.control,name:"featured",render:({field:e})=>s.jsxs(ee,{className:"flex flex-row items-start space-x-3 space-y-0 rounded-md border p-4",children:[s.jsx(te,{children:s.jsx(ye,{checked:e.value,onCheckedChange:e.onChange})}),s.jsxs("div",{className:"space-y-1 leading-none",children:[s.jsx(se,{children:"Featured"}),s.jsx("p",{className:"text-sm text-muted-foreground",children:"This bookstore will be highlighted on the public bookstore page."})]})]})}),s.jsx("div",{className:"flex justify-end space-x-4",children:s.jsx(j,{type:"submit",disabled:a,children:a?"Saving...":t?"Update Bookstore":"Create Bookstore"})})]})})},we=({open:e,onOpenChange:t,onSubmit:r,isLoading:a})=>s.jsx(M,{open:e,onOpenChange:t,children:s.jsxs(W,{className:"max-w-3xl max-h-[90vh] overflow-y-auto",children:[s.jsxs(J,{children:[s.jsx(G,{children:"Add New Bookstore"}),s.jsx(K,{children:"Fill in the details to add a new bookstore location."})]}),s.jsx(Ne,{onSubmit:r,isLoading:a})]})}),Se=({open:e,onOpenChange:t,bookstore:r,onSubmit:a,isLoading:o})=>r?s.jsx(M,{open:e,onOpenChange:t,children:s.jsxs(W,{className:"max-w-3xl max-h-[90vh] overflow-y-auto",children:[s.jsxs(J,{children:[s.jsxs(G,{children:["Edit Bookstore: ",r.name]}),s.jsx(K,{children:"Update the bookstore information below."})]}),s.jsx(Ne,{bookstore:r,onSubmit:a,isLoading:o})]})}):null,Ce=ce,_e=e.forwardRef((({className:e,...t},r)=>s.jsx(ie,{ref:r,className:g("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",e),...t})));_e.displayName=ie.displayName;const Fe=e.forwardRef((({className:e,...t},r)=>s.jsx(le,{ref:r,className:g("inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",e),...t})));Fe.displayName=le.displayName;const Be=e.forwardRef((({className:e,...t},r)=>s.jsx(de,{ref:r,className:g("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",e),...t})));
1Be.displayName=de.displayName;const Ee=({suggestions:e,isLoading:t,onApprove:r,onReject:o,onEdit:n,onDelete:u})=>{const h=e=>{switch(e){case"approved":return s.jsx(L,{className:"bg-green-500",children:"Approved"});case"rejected":return s.jsx(L,{variant:"destructive",children:"Rejected"});default:return s.jsx(L,{variant:"outline",className:"text-amber-600 border-amber-600",children:"Pending"})}};return s.jsx("div",{className:"border rounded-md overflow-hidden",children:s.jsxs(S,{children:[s.jsx(C,{children:s.jsxs(_,{children:[s.jsx(F,{children:"Name"}),s.jsx(F,{className:"hidden md:table-cell",children:"Location"}),s.jsx(F,{className:"hidden md:table-cell",children:"Type"}),s.jsx(F,{className:"hidden md:table-cell",children:"Submitted By"}),s.jsx(F,{className:"hidden md:table-cell",children:"Date"}),s.jsx(F,{children:"Status"}),s.jsx(F,{className:"text-right",children:"Actions"})]})}),s.jsx(B,{children:t?s.jsx(_,{children:s.jsx(E,{colSpan:7,className:"text-center py-16",children:s.jsxs("div",{className:"flex flex-col items-center justify-center",children:[s.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-brand-purple border-t-transparent mb-2"}),s.jsx("p",{className:"text-gray-500",children:"Loading suggestions..."})]})})}):0===e.length?s.jsx(_,{children:s.jsx(E,{colSpan:7,className:"text-center py-16",children:s.jsx("p",{className:"text-gray-500",children:"No bookstore suggestions found"})})}):e.map((e=>s.jsxs(_,{children:[s.jsx(E,{className:"font-medium",children:s.jsxs("div",{children:[e.name,s.jsxs("div",{className:"md:hidden text-xs text-gray-500",children:[e.city,", ",e.province]}),s.jsxs("div",{className:"md:hidden text-xs text-gray-500",children:["Type: ",e.type||"Not specified"]})]})}),s.jsxs(E,{className:"hidden md:table-cell",children:[e.city,", ",e.province,", ",e.country]}),s.jsx(E,{className:"hidden md:table-cell",children:e.type||"Not specified"}),s.jsx(E,{className:"hidden md:table-cell",children:s.jsxs("div",{className:"text-sm",children:[s.jsx("p",{children:e.submitter_name}),s.jsx("p",{className:"text-xs text-gray-500",children:e.submitter_email})]})}),s.jsx(E,{className:"hidden md:table-cell",children:new Date(e.created_at).toLocaleDateString()}),s.jsx(E,{children:h(e.status)}),s.jsx(E,{className:"text-right",children:s.jsxs("div",{className:"flex justify-end gap-2",children:["pending"===e.status&&s.jsxs(s.Fragment,{children:[s.jsxs(j,{variant:"outline",size:"sm",onClick:()=>r(e),className:"text-green-600 border-green-600 hover:border-green-600 hover:text-green-600 hover:bg-transparent",children:[s.jsx(i,{size:16,className:"mr-1"}),"Approve"]}),s.jsxs(j,{variant:"outline",size:"sm",onClick:()=>o(e.id),className:"text-red-600 border-red-600 hover:border-red-600 hover:text-red-600 hover:bg-transparent",children:[s.jsx(l,{size:16,className:"mr-1"}),"Reject"]})]}),"rejected"===e.status&&s.jsxs(j,{variant:"outline",size:"sm",onClick:()=>r(e),className:"text-green-600 border-green-600 hover:border-green-600 hover:text-green-600 hover:bg-transparent",children:[s.jsx(i,{size:16,className:"mr-1"}),"Approve"]}),n&&s.jsx(j,{variant:"outline",size:"sm",onClick:()=>n(e),className:"text-blue-600 border-blue-600 hover:border-brand-orange hover:text-brand-orange hover:bg-transparent",title:"Edit",children:s.jsx(d,{size:16})}),u&&s.jsx(j,{variant:"outline",size:"sm",onClick:()=>u(e.id),className:"text-red-600 border-red-600 hover:border-brand-orange hover:text-brand-orange hover:bg-transparent",title:"Delete",children:s.jsx(a,{size:16})}),e.website&&s.jsx(j,{variant:"ghost",size:"sm",onClick:()=>window.open(e.website,"_blank"),title:"Visit website",children:s.jsx(c,{size:16})})]})})]},e.id)))})]})})},Le=()=>{const[t,r]=e.useState("all"),{suggestions:a,loading:o,error:n,fetchSuggestions:i,approveSuggestion:l,rejectSuggestion:d,updateSuggestion:c,deleteSuggestion:u}=(()=>{const[s,t]=e.useState([]),[r,a]=e.useState(!1),[o,n]=e.useState(null),{toast:i}=x();return{suggestions:s,loading:r,error:o,fetchSuggestions:async()=>{a(!0),n(null);try{const{data:e,error:s}=await p.from("bookstore_suggestions").select("*").order("created_at",{ascending:!1});if(s)throw s;t(e||[])}catch(e){n(e.message||"Failed to load bookstore suggestions"),i({variant:"destructive",title:"Error",description:"Failed to load bookstore suggestions. Please try again."})}finally{a(!1)}},approveSuggestion:async e=>{try{const r={name:e.name,address_1:e.address_1,address_2:e.address_2,city:e.city,province:e.province,country:e.country,postal_code:e.postal_code,ph
1one_number:e.phone_number,website:e.website,book_status:e.book_status,type:e.type,status:"active"},{data:a,error:o}=await p.from("bookstores").insert(r).select().single();if(o)throw o;const{error:n}=await p.from("bookstore_suggestions").update({status:"approved",bookstore_id:a.id}).eq("id",e.id);if(n)throw n;t(s.map((s=>s.id===e.id?{...s,status:"approved"}:s))),i({title:"Suggestion Approved",description:`${e.name} has been added to the bookstores.`})}catch(r){i({variant:"destructive",title:"Error",description:"Failed to approve bookstore suggestion. Please try again."})}},rejectSuggestion:async e=>{try{const{error:r}=await p.from("bookstore_suggestions").update({status:"rejected"}).eq("id",e);if(r)throw r;t(s.map((s=>s.id===e?{...s,status:"rejected"}:s))),i({title:"Suggestion Rejected",description:"The bookstore suggestion has been rejected."})}catch(r){i({variant:"destructive",title:"Error",description:"Failed to reject bookstore suggestion. Please try again."})}},updateSuggestion:async(e,r)=>{try{const{error:a}=await p.from("bookstore_suggestions").update(r).eq("id",e);if(a)throw a;return t(s.map((s=>s.id===e?{...s,...r}:s))),i({title:"Suggestion Updated",description:"The bookstore suggestion has been updated successfully."}),!0}catch(a){return i({variant:"destructive",title:"Error",description:"Failed to update bookstore suggestion. Please try again."}),!1}},deleteSuggestion:async e=>{try{const{error:r}=await p.from("bookstore_suggestions").delete().eq("id",e);if(r)throw r;return t(s.filter((s=>s.id!==e))),i({title:"Suggestion Deleted",description:"The bookstore suggestion has been deleted permanently."}),!0}catch(r){return i({variant:"destructive",title:"Error",description:"Failed to delete bookstore suggestion. Please try again."}),!1}}}})(),[h,m]=e.useState(!1),[g,w]=e.useState(!1),[S,C]=e.useState(null),[_,F]=e.useState({}),[B,E]=e.useState(!1),L=a.filter((e=>"all"===t||e.status===t)),z=a.filter((e=>"pending"===e.status)).length,A=a.filter((e=>"approved"===e.status)).length,P=a.filter((e=>"rejected"===e.status)).length;e.useEffect((()=>{i()}),[]);const D=e=>{const{name:s,value:t}=e.target;F((e=>({...e,[s]:t})))};return s.jsxs(b,{children:[s.jsxs(v,{children:[s.jsx(f,{children:"Bookstore Suggestions"}),s.jsx(y,{children:"Review and approve suggested bookstores"})]}),s.jsx(k,{children:s.jsxs(Ce,{defaultValue:"all",value:t,onValueChange:r,children:[s.jsxs(_e,{className:"mb-4",children:[s.jsxs(Fe,{value:"all",children:["All (",a.length,")"]}),s.jsxs(Fe,{value:"pending",children:["Pending (",z,")"]}),s.jsxs(Fe,{value:"approved",children:["Approved (",A,")"]}),s.jsxs(Fe,{value:"rejected",children:["Rejected (",P,")"]})]}),s.jsx(Be,{value:t,children:n?s.jsxs("div",{className:"text-center p-6 border rounded-md border-red-200 bg-red-50",children:[s.jsx("p",{className:"text-red-600",children:n}),s.jsx("button",{onClick:i,className:"mt-2 text-brand-purple hover:underline",children:"Try Again"})]}):0!==a.length||o?s.jsx(Ee,{suggestions:L,isLoading:o,onApprove:l,onReject:d,onEdit:e=>{C(e),F({name:e.name,address_1:e.address_1,address_2:e.address_2||"",city:e.city,province:e.province,country:e.country,postal_code:e.postal_code,phone_number:e.phone_number||"",website:e.website||"",book_status:e.book_status||"",type:e.type||""}),m(!0)},onDelete:e=>{const s=a.find((s=>s.id===e));s&&(C(s),w(!0))}}):s.jsx(je,{title:"No Suggestions Yet",description:"When users suggest bookstores, they will appear here for review.",type:"info"})})]})}),s.jsx(M,{open:h,onOpenChange:m,children:s.jsxs(W,{className:"max-w-md max-h-[90vh] overflow-y-auto",children:[s.jsxs(J,{children:[s.jsx(G,{children:"Edit Bookstore Suggestion"}),s.jsx(K,{children:"Make changes to the bookstore suggestion below."})]}),s.jsxs("div",{className:"grid gap-4 py-4",children:[s.jsxs("div",{className:"grid gap-2",children:[s.jsx(ge,{htmlFor:"name",children:"Name"}),s.jsx(N,{id:"name",name:"name",value:_.name||"",onChange:D})]}),s.jsxs("div",{className:"grid gap-2",children:[s.jsx(ge,{htmlFor:"address_1",children:"Address Line 1"}),s.jsx(N,{id:"address_1",name:"address_1",value:_.address_1||"",onChange:D})]}),s.jsxs("div",{className:"grid gap-2",children:[s.jsx(ge,{htmlFor:"address_2",children:"Address Line 2 (Optional)"}),s.jsx(N,{id:"address_2",name:"address_2",value:_.address_2||"",onChange:D})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[s.jsxs("div",{className:"grid gap-2",children:[s.jsx(ge,{htmlFor:"city",children:"City"}),s.jsx(N,{id:"city",name:"city",value:_.city||"",onChange:D})]}),s.jsxs("div",{className:"grid gap-2",children:[s.jsx(ge,{htmlFor:"province",children:"Province/State"}),s.jsx(N,{id:"province",name:"province",value:_.province||"",onChange:D})]})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[s.jsxs("div",{className:"grid gap-2",children:[s.jsx(ge,{htmlFor:"country",children:"Country"}),s.jsx(N,{id:"country",name:"country",value:_.country||"",onChange:D})]}),s.jsxs("div",{className:"grid gap-2",children:[s.jsx(ge,{htmlFor:"postal_code",children:"Postal Code"}),s.jsx(N,{id:"postal_code",name:"postal_code",value:_.postal_code||"",onChange:D})]})]}),s.jsxs("div",{className:"grid gap-2",children:[s.jsx(ge,{htmlFor:"phone_number",children:"Phone Number (Optional)"}),s.jsx(N,{id:"phone_number",name:"phone_number",value:_.phone_number||"",onChange:D})]}),s.jsxs("div",{className:"grid gap-2",children:[s.jsx(ge,{htmlFor:"website",children:"Website URL (Optional)"}),s.jsx(N,{id:"website",name:"website",value:_.website||"",onChange:D})]}),s.jsxs("div",{className:"grid gap-2",children:[s.jsx(ge,{htmlFor:"book_status",children:"Book Status (Optional)"}),s.jsx(N,{id:"book_status",name:"book_status",value:_.book_status||"",onChange:D})]}),s.jsxs("div",{className:"grid gap-2",children:[s.jsx(ge,{htmlFor:"type",children:"Store Type (Optional)"}),s.jsx(N,{id:"type",name:"type",value:_.type||"",onChange:D})]})]}),s.jsxs(Q,{children:[s.jsx(j,{variant:"outline",onClick:()=>m(!1),className:"hover:border-brand-orange hover:text-brand-orange hover:bg-transparent",children:"Cancel"}),s.jsx(j,{onClick:async()=>
1{if(!S)return;E(!0);const e=await c(S.id,_);E(!1),e&&(m(!1),C(null))},disabled:B,className:"bg-orange-500 hover:bg-orange-600",children:B?"Saving...":"Save Changes"})]})]})}),s.jsx(O,{open:g,onOpenChange:w,children:s.jsxs(T,{children:[s.jsxs(q,{children:[s.jsx(R,{children:"Are you sure?"}),s.jsxs(V,{children:['This will permanently delete the bookstore suggestion "',S?.name,'". This action cannot be undone.']})]}),s.jsxs($,{children:[s.jsx(I,{className:"hover:border-brand-orange hover:text-brand-orange hover:bg-transparent",children:"Cancel"}),s.jsx(U,{onClick:async()=>{if(!S)return;await u(S.id)&&(w(!1),C(null))},className:"bg-red-600 hover:bg-red-700",children:"Delete"})]})]})})]})},ze=()=>{const[t,r]=e.useState(""),[a,o]=e.useState(!1),[n,i]=e.useState(!1),[l,d]=e.useState(!1),[c,g]=e.useState(!1),[S,C]=e.useState(null),[_,F]=e.useState(null),[B,E]=e.useState([]),[L,z]=e.useState(!1),{toast:A}=x(),{bookstores:P,loading:D,error:O,fetchBookstores:T,createBookstore:q,updateBookstore:R,toggleFeatured:V,toggleStatus:$,deleteBookstore:I}=be();e.useEffect((()=>{T()}),[]),e.useEffect((()=>{if(""===t.trim())return void E(P);const e=t.toLowerCase(),s=P.filter((s=>s.name.toLowerCase().includes(e)||s.city.toLowerCase().includes(e)||s.province.toLowerCase().includes(e)||s.country.toLowerCase().includes(e)||s.type&&s.type.toLowerCase().includes(e)));E(s)}),[t,P]);return s.jsxs("div",{className:"space-y-6",children:[s.jsx(Le,{}),s.jsxs(b,{children:[s.jsxs(v,{className:"flex flex-col sm:flex-row sm:items-center gap-4",children:[s.jsxs("div",{children:[s.jsx(f,{children:"Bookstores Management"}),s.jsx(y,{children:"Manage bookstore listings for BrandJitsuâ¢"})]}),s.jsxs("div",{className:"ml-auto flex flex-col sm:flex-row gap-3",children:[s.jsxs("div",{className:"relative",children:[s.jsx(u,{className:"absolute left-2 top-1/2 transform -translate-y-1/2 text-gray-400",size:18}),s.jsx(N,{className:"pl-8 w-full",placeholder:"Search bookstores...",value:t,onChange:e=>r(e.target.value)})]}),s.jsxs(j,{variant:"outline",onClick:()=>o(!0),children:[s.jsx(h,{size:16,className:"mr-2"})," Import CSV"]}),s.jsxs(j,{onClick:()=>i(!0),children:[s.jsx(m,{size:16,className:"mr-2"})," Add Bookstore"]})]})]}),s.jsx(k,{children:O?s.jsxs("div",{className:"text-center p-6 border rounded-md border-red-200 bg-red-50",children:[s.jsx("p",{className:"text-red-600",children:O}),s.jsx(j,{onClick:T,variant:"outline",className:"mt-2",children:"Try Again"})]}):s.jsx(ve,{bookstores:B,isLoading:D,toggleFeatured:V,toggleStatus:$,onEdit:e=>{C(e),d(!0)},onDelete:e=>{F(e),g(!0)}})})]}),s.jsx(w,{open:a,onOpenChange:o,handleImportCSV:async e=>{const s=e.target.files?.[0];if(!s)return;const t=new FileReader;t.onload=async e=>{try{const s=e.target?.result,t=s.split("\n"),r=t[0].split(",").map((e=>e.trim())),a=["name","address_1","city","province","country","postal_code"],n=a.filter((e=>!r.includes(e)));if(n.length>0)return void A({title:"CSV Format Error",description:`Missing required columns: ${n.join(", ")}`,variant:"destructive"});r.indexOf("status");const i=t.slice(1).filter((e=>""!==e.trim())).map((e=>{const s=e.split(",").map((e=>e.trim())),t={name:"",address_1:"",city:"",province:"",country:"",postal_code:""};return r.forEach(((e,r)=>{if(r<s.length)if("featured"===e)t.featured="true"===s[r].toLowerCase();else if("status"===e){const e=s[r].toLowerCase();t.status="active"===e||"inactive"===e?e:"active"}else a.includes(e)?t[e]=s[r]||"":s[r]&&(t[e]=s[r])})),t})),l=i.filter((e=>!(e.name&&e.address_1&&e.city&&e.province&&e.country&&e.postal_code)));if(l.length>0)return void A({title:"Validation Error",description:`${l.length} bookstores have missing required fields`,variant:"destructive"});let d=0,c=0;for(const e of i){const{error:s}=await p.from("bookstores").insert(e);s?c++:d++}c>0?A({title:"Import Partially Successful",description:`Successfully imported ${d} bookstores. Failed to import ${c} bookstores.`,variant:"destructive"}):(A({title:"Import Successful",description:`Successfully imported ${i.length} bookstores.`}),T()),o(!1)}catch(s){A({title:"Import Failed",description:s.message,variant:"destructive"})}},t.onerror=()=>{A({title:"File Reading Error",description:"Failed to read the CSV file",variant:"destructive"})},t.readAsText(s)}}),s.jsx(we,{open:n,onOpenChange:i,onSubmit:async e=>{z(!0);const s=await q(e);z(!1),s&&i(!1)},isLoading:L}),s.jsx(Se,{open:l,onOpenChange:d,bookstore:S,onSubmit:async e=>{if(!S)return;z(!0);const s=await R(S.id,e);z(!1),s&&(d(!1),C(null))},isLoading:L}
1),_&&s.jsx(fe,{open:c,onOpenChange:g,bookstoreName:_.name,onConfirm:async()=>{_&&(await I(_.id),g(!1),F(null))}})]})};export{ze 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.