1import{s as le,a6 as rs,p as ae,j as e,ai as Ue,ak as $e,al as Ke,am as He,a2 as We,B as H,L as Qe,ae as Le,D as as,l as is,m as os,n as ls,a5 as ds}from"./index-D_Axm8F4.js";import{r as Z,g as cs,c as us}from"./vendor-recharts-PDzeV0Q9.js";import{a as Ie}from"./useQuery-DBpLPfP6.js";import{S as hs}from"./SEO-aMTZ9ECZ.js";import{O as ms}from"./OrganizerLayout-D-2SQFgH.js";import{I as ue}from"./input-D4Q-4fL_.js";import{S as Se,a as Re,b as Ae,c as De,d as ye}from"./select-D8lPxgfk.js";import{T as fs,a as ps,b as Oe,c as Te}from"./tabs-6JSaQ7MU.js";import{u as xs}from"./useOrganizerContext-BE-VLNkl.js";import{o as gs,s as ve,l as _s}from"./types-lSNCvkhu.js";import{u as be}from"./useMutation-BBc4oSuQ.js";import{u as Pe}from"./use-categories-BlVS__TH.js";import{T as Je,a as Ge,b as Ee,c as xe,d as Ye,e as ce}from"./table-V0q9uSZo.js";import{B as he}from"./badge-BLJx5mOD.js";import{u as Ze,t as Xe}from"./zod-OdmmjTfX.js";import{L as ne}from"./label-DEqjoNPz.js";import{A as js,h as vs,a as bs,b as ys,c as Ns,d as ks,e as ws,f as Cs,g as Es}from"./alert-dialog-DZkfRosy.js";import{C as es}from"./checkbox-DXTf3HIh.js";import{L as ss}from"./loader-circle-tRkch_ee.js";import{C as Ss}from"./chevron-down-W2CCnuna.js";import{C as Rs}from"./chevron-right-VEs56w49.js";import{P as Ve}from"./shield-DKwwo_ip.js";import{f as As}from"./format-DCW6RvxT.js";import{D as Ds}from"./download-DIOebLa0.js";import{U as Fs}from"./upload-lR-g8rux.js";import{C as Be}from"./circle-alert-Bc8pwbSd.js";import{C as Os}from"./check-D1BGo_HC.js";import{A as Ts}from"./arrow-left-BjesOvdY.js";import{S as Ls}from"./search-C77tuuzZ.js";import"./Header-CSK1Ekbf.js";import"./map-pin-dvomu63T.js";import"./store-BlzagHtH.js";import"./building-xC02UO3l.js";import"./popify-logo-DO1722DA.js";import"./list-DIw_v0CZ.js";import"./calendar-tqtt4hbf.js";import"./users-DBsDSHac.js";import"./user-Bcvizkme.js";import"./Layout-CYjSOzGY.js";import"./Footer-Cw0vJbfj.js";import"./chevron-left-2eNW7u6i.js";import"./clipboard-list-CCbzKQfd.js";import"./settings-7qwg5M-R.js";import"./menu-Z8fHNr8F.js";import"./index-R2v3x2uL.js";import"./index-vzZ7al4T.js";import"./chevron-up-B3RRApos.js";import"./index-Cr85CPaF.js";import"./en-US-wfBU2YNu.js";const ze=gs({business_name:ve().min(1,"Business name is required"),category:ve().min(1,"Category is required"),contact_name:ve().optional(),email:ve().email("Please enter a valid email").optional().or(_s("")),phone:ve().optional(),notes:ve().optional(),booth_assignment:ve().optional()});function Vs(n){return n.vendors?{id:`popify-${n.id}`,business_name:n.vendors.business_name,category:n.vendors.category,contact_name:n.vendors.contact_name??void 0,email:n.vendors.email??void 0,phone:n.vendors.phone??void 0,source:"popify",application_status:n.status,application_id:n.id,vendor_id:n.vendor_id}:null}function Is(n){return{id:`external-${n.id}`,business_name:n.business_name,category:n.category,contact_name:n.contact_name??void 0,email:n.email??void 0,phone:n.phone??void 0,notes:n.notes??void 0,booth_assignment:n.booth_assignment??void 0,source:"external",market_roster_entry_id:n.id}}function Ps(n){return n===null?"attended":n==="attended"?"no_show":null}function zs(n){const w=ze.safeParse({business_name:n.business_name??"",category:n.category??"",contact_name:n.contact_name,email:n.email,phone:n.phone,notes:n.notes,booth_assignment:n.booth_assignment});return w.success?{valid:!0,errors:[],data:w.data}:{valid:!1,errors:w.error.issues.map(f=>`${f.path.join(".")}: ${f.message}`)}}function Ms(n,w){return Ie({queryKey:["roster",n],queryFn:async()=>{if(!n||!w)return{rosterEntries:[],popifyCount:0,externalCount:0};const{data:f}=await le.from("applications").select(` 2 id, status, vendor_id, market_id, 3 vendors(business_name, category, contact_name, email, phone) 4 `).eq("market_id",n).in("status",["approved","waitlist"]),{data:d}=await le.from("market_roster_entries").select("*").eq("market_id",n),L=(f||[]).map(y=>Vs(y)).filter(y=>y!==null),u=(d||[]).map(y=>Is(y));return{rosterEntries:[...L,...u],popifyCount:L.length,externalCount:u.length}},enabled:!!n&&!!w})}function ts(n,w){const f=rs(),d=()=>{f.invalidateQueries({queryKey:["roster",n]}),f.invalidateQueries({queryKey:["roster-dates",n]})},L=be({mutationFn:async i=>{const{error:h}=await le.from("market_roster_entries").insert({market_id:n,organizer_id:w,business_name:i.business_name,category:i.category,contact_name:i.contact_name||null,email:i.email||null,phone:i.phone||null,notes:i.notes||null,booth_assignment:i.booth_assignment||null});if(h)throw h},onSuccess:(i,h)=>{ae.success(`${h.business_name} added to roster`),d()},onError:i=>
4{ae.error(`Failed to add vendor: ${i.message}`)}}),u=be({mutationFn:async({id:i,data:h})=>{const{error:N}=await le.from("market_roster_entries").update({...h,updated_at:new Date().toISOString()}).eq("id",i);if(N)throw N},onSuccess:()=>{ae.success("Vendor updated"),d()},onError:i=>{ae.error(`Failed to update vendor: ${i.message}`)}}),V=be({mutationFn:async i=>{const{error:h}=await le.from("market_roster_entries").delete().eq("id",i);if(h)throw h},onSuccess:()=>{ae.success("Vendor removed from roster"),d()},onError:i=>{ae.error(`Failed to remove vendor: ${i.message}`)}}),y=be({mutationFn:async({id:i,isConfirmed:h})=>{const{error:N}=await le.from("roster_date_assignments").update({is_confirmed:h}).eq("id",i);if(N)throw N},onSuccess:()=>{d()},onError:i=>{ae.error(`Failed to update confirmation: ${i.message}`)}}),G=be({mutationFn:async i=>{for(const h of i){const{error:N}=await le.from("roster_date_assignments").update({attendance:h.attendance}).eq("id",h.id);if(N)throw N}},onSuccess:()=>{ae.success("Attendance saved"),d()},onError:i=>{ae.error(`Failed to save attendance: ${i.message}`)}}),a=be({mutationFn:async({rosterEntryId:i,marketDateId:h})=>{const{error:N}=await le.from("roster_date_assignments").insert({roster_entry_id:i,market_date_id:h,is_confirmed:!1});if(N)throw N},onSuccess:()=>{ae.success("Vendor assigned to date"),d()},onError:i=>{ae.error(`Failed to assign vendor: ${i.message}`)}}),c=be({mutationFn:async i=>{const h=i.map(z=>({market_id:n,organizer_id:w,business_name:z.business_name,category:z.category,contact_name:z.contact_name||null,email:z.email||null,phone:z.phone||null,notes:z.notes||null,booth_assignment:z.booth_assignment||null})),{error:N}=await le.from("market_roster_entries").insert(h);if(N)throw N},onSuccess:(i,h)=>{ae.success(`Imported ${h.length} vendors to roster`),d()},onError:i=>{ae.error(`Failed to import vendors: ${i.message}`)}});return{addExternalVendor:L,updateExternalVendor:u,removeExternalVendor:V,toggleConfirmation:y,saveAttendance:G,assignVendorToDate:a,bulkImportVendors:c}}function qs({entries:n,onVendorClick:w}){return e.jsxs(Je,{children:[e.jsx(Ge,{children:e.jsxs(Ee,{children:[e.jsx(xe,{children:"Vendor"}),e.jsx(xe,{children:"Contact"}),e.jsx(xe,{children:"Category"}),e.jsx(xe,{children:"Source"}),e.jsx(xe,{children:"Notes"})]})}),e.jsx(Ye,{children:n.map(f=>e.jsxs(Ee,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>w(f),children:[e.jsx(ce,{className:"font-medium",children:f.business_name}),e.jsx(ce,{children:e.jsxs("div",{className:"text-sm",children:[f.email&&e.jsx("div",{children:f.email}),f.phone&&e.jsx("div",{className:"text-muted-foreground",children:f.phone}),!f.email&&!f.phone&&e.jsx("span",{className:"text-muted-foreground",children:"--"})]})}),e.jsx(ce,{children:f.category}),e.jsx(ce,{children:f.source==="popify"?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(he,{variant:"default",className:"text-xs",children:"Popify"}),f.application_status&&e.jsx(he,{variant:f.application_status==="approved"?"default":"secondary",className:"text-xs",children:f.application_status==="approved"?"Approved":f.application_status==="waitlist"?"Waitlisted":f.application_status})]}):e.jsx(he,{variant:"outline",className:"text-xs",children:"External"})}),e.jsx(ce,{className:"max-w-[200px] truncate text-muted-foreground",children:f.notes||"--"})]},f.id))})]})}function Bs({isOpen:n,onClose:w,onSubmit:f,isSubmitting:d}){const{categoryNames:L}=Pe(),{register:u,handleSubmit:V,setValue:y,reset:G,formState:{errors:a}}=Ze({resolver:Xe(ze),defaultValues:{business_name:"",category:"",contact_name:"",email:"",phone:"",notes:"",booth_assignment:""}}),c=()=>{G(),w()},i=h=>{f(h),G()};return e.jsx(Ue,{open:n,onOpenChange:h=>{h||c()},children:e.jsxs($e,{className:"overflow-y-auto",children:[e.jsx(Ke,{children:e.jsx(He,{children:"Add External Vendor"})}),e.jsxs("form",{onSubmit:V(i),className:"space-y-4 mt-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(ne,{htmlFor:"business_name",children:"Business Name *"}),e.jsx(ue,{id:"business_name",...u("business_name")}),a.business_name&&e.jsx("p",{className:"text-sm text-destructive",children:a.business_name.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ne,{htmlFor:"contact_name",children:"Contact Name"}),e.jsx(ue,{id:"contact_name",...u("contact_name")}
4)]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ne,{htmlFor:"email",children:"Email"}),e.jsx(ue,{id:"email",type:"email",...u("email")}),a.email&&e.jsx("p",{className:"text-sm text-destructive",children:a.email.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ne,{htmlFor:"phone",children:"Phone"}),e.jsx(ue,{id:"phone",...u("phone")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ne,{children:"Category *"}),e.jsxs(Se,{onValueChange:h=>y("category",h),children:[e.jsx(Re,{children:e.jsx(Ae,{placeholder:"Select category"})}),e.jsx(De,{children:L.map(h=>e.jsx(ye,{value:h,children:h},h))})]}),a.category&&e.jsx("p",{className:"text-sm text-destructive",children:a.category.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ne,{htmlFor:"notes",children:"Notes"}),e.jsx(We,{id:"notes",...u("notes"),rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ne,{htmlFor:"booth_assignment",children:"Booth Assignment"}),e.jsx(ue,{id:"booth_assignment",...u("booth_assignment")})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(H,{type:"button",variant:"outline",onClick:c,children:"Cancel"}),e.jsx(H,{type:"submit",disabled:d,children:d?"Adding...":"Save"})]})]})]})})}function Us({entry:n,isOpen:w,onClose:f,onUpdate:d,onRemove:L,isUpdating:u}){const[V,y]=Z.useState(!1),{categoryNames:G}=Pe(),{register:a,handleSubmit:c,setValue:i,reset:h,formState:{errors:N}}=Ze({resolver:Xe(ze)}),z=()=>{y(!1),h(),f()},R=()=>{n&&(h({business_name:n.business_name,category:n.category,contact_name:n.contact_name||"",email:n.email||"",phone:n.phone||"",notes:n.notes||"",booth_assignment:n.booth_assignment||""}),y(!0))},F=M=>{!(n!=null&&n.market_roster_entry_id)||!d||(d(n.market_roster_entry_id,M),y(!1))},A=()=>{!(n!=null&&n.market_roster_entry_id)||!L||(L(n.market_roster_entry_id),z())};return n?e.jsx(Ue,{open:w,onOpenChange:M=>{M||z()},children:e.jsxs($e,{className:"overflow-y-auto",children:[e.jsx(Ke,{children:e.jsxs(He,{className:"flex items-center gap-2",children:[n.business_name,e.jsx(he,{variant:n.source==="popify"?"default":"outline",className:"text-xs",children:n.source==="popify"?"Popify Vendor":"External Vendor"})]})}),e.jsx("div",{className:"mt-6 space-y-6",children:n.source==="popify"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"text-sm font-medium text-muted-foreground",children:"Contact"}),e.jsxs("div",{className:"space-y-1",children:[n.email&&e.jsx("p",{className:"text-sm",children:n.email}),n.phone&&e.jsx("p",{className:"text-sm",children:n.phone}),n.contact_name&&e.jsx("p",{className:"text-sm text-muted-foreground",children:n.contact_name}),!n.email&&!n.phone&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No contact info"})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"text-sm font-medium text-muted-foreground",children:"Details"}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"text-sm",children:["Category: ",n.category]}),n.booth_assignment&&e.jsxs("p",{className:"text-sm",children:["Booth: ",n.booth_assignment]})]})]}),n.application_status&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"text-sm font-medium text-muted-foreground",children:"Application"}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(he,{variant:n.application_status==="approved"?"default":"secondary",children:n.application_status==="approved"?"Approved":n.application_status==="waitlist"?"Waitlisted":n.application_status})}),n.application_id&&e.jsx(Qe,{to:`/organizer/applications/${n.application_id}`,className:"text-sm text-primary hover:underline",children:"View Full Application"})]}),n.notes&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"text-sm font-medium text-muted-foreground",children:"Notes"}),e.jsx("p",{className:"text-sm",children:n.notes})]})]}):V?e.jsxs("form",{onSubmit:c(F),className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(ne,{htmlFor:"edit_business_name",children:"Business Name *"}),e.jsx(ue,{id:"edit_business_name",...a("business_name")}),N.business_name&&e.jsx("p",{className:"text-sm text-destructive",children:N.business_name.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ne,{htmlFor:"edit_contact_name",children:"Contact Name"}),e.jsx(ue,{id:"edit_contact_name",...a("contact_name")}
4)]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ne,{htmlFor:"edit_email",children:"Email"}),e.jsx(ue,{id:"edit_email",type:"email",...a("email")}),N.email&&e.jsx("p",{className:"text-sm text-destructive",children:N.email.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ne,{htmlFor:"edit_phone",children:"Phone"}),e.jsx(ue,{id:"edit_phone",...a("phone")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ne,{children:"Category *"}),e.jsxs(Se,{defaultValue:n.category,onValueChange:M=>i("category",M),children:[e.jsx(Re,{children:e.jsx(Ae,{})}),e.jsx(De,{children:G.map(M=>e.jsx(ye,{value:M,children:M},M))})]}),N.category&&e.jsx("p",{className:"text-sm text-destructive",children:N.category.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ne,{htmlFor:"edit_notes",children:"Notes"}),e.jsx(We,{id:"edit_notes",...a("notes"),rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ne,{htmlFor:"edit_booth",children:"Booth Assignment"}),e.jsx(ue,{id:"edit_booth",...a("booth_assignment")})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(H,{type:"button",variant:"outline",onClick:()=>y(!1),children:"Cancel"}),e.jsx(H,{type:"submit",disabled:u,children:u?"Saving...":"Save"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"text-sm font-medium text-muted-foreground",children:"Contact"}),e.jsxs("div",{className:"space-y-1",children:[n.email&&e.jsx("p",{className:"text-sm",children:n.email}),n.phone&&e.jsx("p",{className:"text-sm",children:n.phone}),n.contact_name&&e.jsx("p",{className:"text-sm text-muted-foreground",children:n.contact_name}),!n.email&&!n.phone&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No contact info"})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"text-sm font-medium text-muted-foreground",children:"Details"}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"text-sm",children:["Category: ",n.category]}),n.booth_assignment&&e.jsxs("p",{className:"text-sm",children:["Booth: ",n.booth_assignment]})]})]}),n.notes&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"text-sm font-medium text-muted-foreground",children:"Notes"}),e.jsx("p",{className:"text-sm",children:n.notes})]}),e.jsxs("div",{className:"flex gap-2 pt-4",children:[e.jsx(H,{variant:"outline",onClick:R,children:"Edit"}),e.jsxs(js,{children:[e.jsx(vs,{asChild:!0,children:e.jsx(H,{variant:"destructive",children:"Remove"})}),e.jsxs(bs,{children:[e.jsxs(ys,{children:[e.jsx(Ns,{children:"Remove vendor?"}),e.jsxs(ks,{children:["This will remove ",n.business_name," from the roster. This action cannot be undone."]})]}),e.jsxs(ws,{children:[e.jsx(Cs,{children:"Cancel"}),e.jsx(Es,{onClick:A,children:"Remove"})]})]})]})]})]})})]})}):null}function $s(n){return Ie({queryKey:["roster-dates",n],queryFn:async()=>{if(!n)return[];const{data:w}=await le.from("market_dates").select("id, date_start, date_end, status").eq("market_id",n).order("date_start",{ascending:!0});if(!w||w.length===0)return[];const f=w.map(u=>u.id),{data:d}=await le.from("roster_date_assignments").select("id, roster_entry_id, market_date_id, is_confirmed, attendance, booth_assignment, market_roster_entries(business_name, category)").in("market_date_id",f),L=new Date;return w.map(u=>{const V=(d||[]).filter(c=>c.market_date_id===u.id).map(c=>{const i=c.market_roster_entries;return{id:c.id,roster_entry_id:c.roster_entry_id,market_date_id:c.market_date_id,is_confirmed:c.is_confirmed??!1,attendance:c.attendance,booth_assignment:c.booth_assignment??void 0,business_name:i==null?void 0:i.business_name,category:i==null?void 0:i.category}}),y=V.filter(c=>c.is_confirmed).length,a=(u.date_end?Le(u.date_end):Le(u.date_start))<L;return{id:u.id,date_start:u.date_start,date_end:u.date_end,status:u.status,assignments:V,confirmedCount:y,totalCount:V.length,isPast:a}})},enabled:!!n})}function Ks({isOpen:n,onClose:w,rosterEntries:f,existingAssignments:d,onAssign:L}){const[u,V]=Z.useState([]),y=f.filter(c=>c.source==="external"&&c.market_roster_entry_id?!d.includes(c.market_roster_entry_id):!1),G=c=>{V(i=>i.includes(c)?i.filter(h=>h!==c):[...i,c])},a=()=>{u.forEach(c=>L(c)),V([]),w()};return e.jsx(as,{open:n,onOpenChange:c=>{c||(V([]),w())},children:e.jsxs(is,{children:[e.jsx(os,{children:e.jsx(ls,{children:"Add Vendor to This Date"})}),y.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"All roster vendors are already assigned to this date."}):e.jsx("div",{className:"space-y-2 max-h-[400px] overflow-y-auto",children:y.map(c=>{const i=c.market_roster_entry_id;return e.jsxs("div",{className:"flex items-center gap-3 p-2 rounded hover:bg-muted/50 cursor-pointer",onClick:()=>G(i),children:[e.jsx(es,{checked:u.includes(i)}),e.jsxs("div",{className:"flex-1",children:[e.jsx("span",{className:"text-sm font-medium",children:c.business_name}),e.jsx("span",{className:"text-xs text-muted-foreground ml-2",children:c.category})]}),e.jsx(he,{variant:c.source==="popify"?"default":"outline",className:"text-xs",children:c.source==="popify"?"Popify":"External"})]},c.id)})}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(H,{variant:"outline",onClick:()=>{V([]),w()},children:"Cancel"}),e.jsxs(H,{onClick:a,disabled:u.length===0,children:["Assign ",u.length>0?`(${u.length})`:""]})]})]})})}function Hs({status:n}){return n==="attended"?e.jsx(he,{className:"bg-green-100 text-green-800 hover:bg-green-100",children:"Attended"}):n==="no_show"?e.jsx(he,{className:"bg-red-100 text-red-800 hover:bg-red-100",children:"No Show"}):e.jsx(he,{variant:"secondary",children:"Unmarked"})}function Ws({marketId:n,organizerId:w,rosterEntries:f}){var je;const{data:d,isLoading:L}=$s(n),u=ts(n,w),[V,y]=Z.useState({}),[G,a]=Z.useState(null),[c,i]=Z.useState({}),[h,N]=Z.useState(null);if(L)return e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(ss,{className:"w-6 h-6 animate-spin text-primary"})});if(!d||d.length===0)return e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:"No dates found for this market."});const z=p=>{y(I=>({...I,[p]:!I[p]}))},R=p=>{a(p.id);const I={};
4p.assignments.forEach(j=>{I[j.id]=j.attendance}),i(I)},F=()=>{a(null),i({})},A=p=>{const I=p.assignments.map(j=>({id:j.id,attendance:c[j.id]??null}));u.saveAttendance.mutate(I,{onSuccess:()=>{a(null),i({})}})},M=p=>{i(I=>({...I,[p]:Ps(I[p]??null)}))},re=new Map;return f.forEach(p=>{p.market_roster_entry_id&&re.set(p.market_roster_entry_id,{name:p.business_name,category:p.category,source:p.source})}),e.jsxs("div",{className:"space-y-4",children:[d.map(p=>{const I=V[p.id]!==!1,j=G===p.id,t=As(Le(p.date_start),"MMM d, yyyy (EEEE)");return e.jsxs("div",{className:"border rounded-lg overflow-hidden",children:[e.jsxs("button",{className:"w-full flex items-center justify-between p-4 hover:bg-muted/50 text-left",onClick:()=>z(p.id),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[I?e.jsx(Ss,{className:"w-4 h-4"}):e.jsx(Rs,{className:"w-4 h-4"}),e.jsx("span",{className:"font-medium",children:t}),p.isPast&&e.jsx(he,{variant:"secondary",className:"text-xs",children:"Past"})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[p.confirmedCount,"/",p.totalCount," confirmed"]})]}),I&&e.jsxs("div",{className:"border-t px-4 pb-4",children:[p.assignments.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"No vendors assigned to this date yet."}):e.jsx("div",{className:"divide-y",children:p.assignments.map(s=>{var r,l,o;return e.jsxs("div",{className:`flex items-center gap-3 py-2 ${j?"cursor-pointer hover:bg-muted/50 rounded px-2 -mx-2":""}`,onClick:j?()=>M(s.id):void 0,children:[j?e.jsx(Hs,{status:c[s.id]??null}):e.jsx(es,{checked:s.is_confirmed,onCheckedChange:_=>{u.toggleConfirmation.mutate({id:s.id,isConfirmed:!!_})}}),e.jsxs("span",{className:"text-sm flex-1",children:[s.business_name||((r=re.get(s.roster_entry_id))==null?void 0:r.name)||"Unknown Vendor",(s.category||((l=re.get(s.roster_entry_id))==null?void 0:l.category))&&e.jsx("span",{className:"text-xs text-muted-foreground ml-2",children:s.category||((o=re.get(s.roster_entry_id))==null?void 0:o.category)})]}),s.booth_assignment&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Booth: ",s.booth_assignment]})]},s.id)})}),e.jsx("div",{className:"flex items-center gap-2 mt-3",children:j?e.jsxs(e.Fragment,{children:[e.jsx(H,{size:"sm",onClick:()=>A(p),disabled:u.saveAttendance.isPending,children:u.saveAttendance.isPending?"Saving...":"Save Attendance"}),e.jsx(H,{size:"sm",variant:"outline",onClick:F,children:"Cancel"})]}):e.jsxs(e.Fragment,{children:[e.jsxs(H,{size:"sm",variant:"outline",onClick:()=>N(p.id),children:[e.jsx(Ve,{className:"w-3 h-3 mr-1"}),"Add Vendor to This Date"]}),p.isPast&&e.jsx(H,{size:"sm",variant:"outline",onClick:()=>R(p),children:"Mark Attendance"})]})})]})]},p.id)}),e.jsx(Ks,{isOpen:!!h,onClose:()=>N(null),marketDateId:h||"",rosterEntries:f,existingAssignments:h?(((je=d==null?void 0:d.find(p=>p.id===h))==null?void 0:je.assignments)||[]).map(p=>p.roster_entry_id):[],onAssign:p=>{u.assignVendorToDate.mutate({rosterEntryId:p,marketDateId:h})}})]})}var ns={exports:{}};/* @license
5Papa Parse 6v5.5.3 7https://github.com/mholt/PapaParse 8License: MIT 9*/(function(n,w){((f,d)=>{n.exports=d()})(us,function f(){var d=typeof self<"u"?self:typeof window<"u"?window:d!==void 0?d:{},L,u=!d.document&&!!d.postMessage,V=d.IS_PAPA_WORKER||!1,y={},G=0,a={};function c(t){this._handle=null,this._finished=!1,this._completed=!1,this._halted=!1,this._input=null,this._baseIndex=0,this._partialLine="",this._rowCount=0,this._start=0,this._nextChunk=null,this.isFirstChunk=!0,this._completeResults={data:[],errors:[],meta:{}},(function(s){var r=p(s);r.chunkSize=parseInt(r.chunkSize),s.step||s.chunk||(r.chunkSize=null),this._handle=new R(r),(this._handle.streamer=this)._config=r}).call(this,t),this.parseChunk=function(s,r){var l=parseInt(this._config.skipFirstNLines)||0;if(this.isFirstChunk&&0<l){let _=this._config.newline;_||(o=this._config.quoteChar||'"',_=this._handle.guessLineEndings(s,o)),s=[...s.split(_).slice(l)].join(_)}this.isFirstChunk&&j(this._config.beforeFirstChunk)&&(o=this._config.beforeFirstChunk(s))!==void 0&&(s=o),this.isFirstChunk=!1,this._halted=!1;var l=this._partialLine+s,o=(this._partialLine="",this._handle.parse(l,this._baseIndex,!this._finished));if(!this._handle.paused()&&!this._handle.aborted()){if(s=o.meta.cursor,l=(this._finished||(this._partialLine=l.substring(s-this._baseIndex),this._baseIndex=s),o&&o.data&&(this._rowCount+=o.data.length),this._finished||this._config.preview&&this._rowCount>=this._config.preview),V)d.postMessage({results:o,workerId:a.WORKER_ID,finished:l});else if(j(this._config.chunk)&&!r){if(this._config.chunk(o,this._handle),this._handle.paused()||this._handle.aborted())return void(this._halted=!0);this._completeResults=o=void 0}return this._config.step||this._config.chunk||(this._completeResults.data=this._completeResults.data.concat(o.data),this._completeResults.errors=this._completeResults.errors.concat(o.errors),this._completeResults.meta=o.meta),this._completed||!l||!j(this._config.complete)||o&&o.meta.aborted||(this._config.complete(this._completeResults,this._input),this._completed=!0),l||o&&o.meta.paused||this._nextChunk(),o}this._halted=!0},this._sendError=function(s){j(this._config.error)?this._config.error(s):V&&this._config.error&&d.postMessage({workerId:a.WORKER_ID,error:s,finished:!1})}}function i(t){var s;(t=t||{}).chunkSize||(t.chunkSize=a.RemoteChunkSize),c.call(this,t),this._nextChunk=u?function(){this._readChunk(),this._chunkLoaded()}:function(){this._readChunk()},this.stream=function(r){this._input=r,this._nextChunk()},this._readChunk=function(){if(this._finished)this._chunkLoaded();else{if(s=new XMLHttpRequest,this._config.withCredentials&&(s.withCredentials=this._config.withCredentials),u||(s.onload=I(this._chunkLoaded,this),s.onerror=I(this._chunkError,this)),s.open(this._config.downloadRequestBody?"POST":"GET",this._input,!u),this._config.downloadRequestHeaders){var r,l=this._config.downloadRequestHeaders;for(r in l)s.setRequestHeader(r,l[r])}var o;this._config.chunkSize&&(o=this._start+this._config.chunkSize-1,s.setRequestHeader("Range","bytes="+this._start+"-"+o));try{s.send(this._config.downloadRequestBody)}catch(_){this._chunkError(_.message)}u&&s.status===0&&this._chunkError()}},this._chunkLoaded=function(){s.readyState===4&&(s.status<200||400<=s.status?this._chunkError():(this._start+=this._config.chunkSize||s.responseText.length,this._finished=!this._config.chunkSize||this._start>=(r=>(r=r.getResponseHeader("Content-Range"))!==null?parseInt(r.substring(r.lastIndexOf("/")+1)):-1)(s),this.parseChunk(s.responseText)))},this._chunkError=function(r){r=s.statusText||r,this._sendError(new Error(r))}}function h(t){(t=t||{}).chunkSize||(t.chunkSize=a.LocalChunkSize),c.call(this,t);var s,r,l=typeof FileReader<"u";this.stream=function(o){this._input=o,r=o.slice||o.webkitSlice||o.mozSlice,l?((s=new FileReader).onload=I(this._chunkLoaded,this),s.onerror=I(this._chunkError,this)):s=new FileReaderSync,this._nextChunk()},this._nextChunk=function(){this._finished||this._config.preview&&!(this._rowCount<this._config.preview)||this._readChunk()},this._readChunk=function(){var o=this._input,_=(this._config.chunkSize&&(_=Math.min(this._start+this._config.chunkSize,this._input.size),o=r.call(o,this._start,_)),s.readAsText(o,this._config.encoding));l||this._chunkLoaded({target:{result:_}})},this._chunkLoaded=function(o){this._start+=this._config.chunkSize,this._finished=!this._config.chunkSize||this._start>=this._input.size,this.parseChunk(o.target.result)},this._chunkError=function(){this._sendError(s.error)}}function N(t){var s;c.call(this,t=t||{}),this.stream=function(r){return s=r,this._nextChunk()},this._nextChunk=function(){var r,l;if(!this._finished)return r=this._config.chunkSize,s=r?(l=s.substring(0,r),s.substring(r)):(l=s,""),this._finished=!s,this.parseChunk(l)}}function z(t){c.call(this,t=t||{});var s=[],r=!0,l=!1;this.pause=function(){c.prototype.pause.apply(this,arguments),this._input.pause()},this.resume=function(){c.prototype.resume.apply(this,arguments),this._input.resume()},this.stream=function(o){this._input=o,this._input.on("data",this._streamData),this._input.on("end",this._streamEnd),this._input.on("error",this._streamError)},this._checkIsFinished=function(){l&&s.length===1&&(this._finished=!0)},this._nextChunk=function(){this._checkIsFinished(),s.length?this.parseChunk(s.shift()):r=!0}
vendor: 9,671 bytes, lines 9-17
9,this._streamData=I(function(o){try{s.push(typeof o=="string"?o:o.toString(this._config.encoding)),r&&(r=!1,this._checkIsFinished(),this.parseChunk(s.shift()))}catch(_){this._streamError(_)}},this),this._streamError=I(function(o){this._streamCleanUp(),this._sendError(o)},this),this._streamEnd=I(function(){this._streamCleanUp(),l=!0,this._streamData("")},this),this._streamCleanUp=I(function(){this._input.removeListener("data",this._streamData),this._input.removeListener("end",this._streamEnd),this._input.removeListener("error",this._streamError)},this)}function R(t){var s,r,l,o,_=Math.pow(2,53),$=-_,se=/^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/,ie=/^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/,k=this,q=0,x=0,X=!1,v=!1,C=[],m={data:[],errors:[],meta:{}};function W(E){return t.skipEmptyLines==="greedy"?E.join("").trim()==="":E.length===1&&E[0].length===0}function K(){if(m&&l&&(oe("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+a.DefaultDelimiter+"'"),l=!1),t.skipEmptyLines&&(m.data=m.data.filter(function(g){return!W(g)})),Y()){let g=function(U,Q){j(t.transformHeader)&&(U=t.transformHeader(U,Q)),C.push(U)};if(m)if(Array.isArray(m.data[0])){for(var E=0;Y()&&E<m.data.length;E++)m.data[E].forEach(g);m.data.splice(0,1)}else m.data.forEach(g)}function D(g,U){for(var Q=t.header?{}:[],O=0;O<g.length;O++){var T=O,S=g[O],S=((de,b)=>(P=>(t.dynamicTypingFunction&&t.dynamicTyping[P]===void 0&&(t.dynamicTyping[P]=t.dynamicTypingFunction(P)),(t.dynamicTyping[P]||t.dynamicTyping)===!0))(de)?b==="true"||b==="TRUE"||b!=="false"&&b!=="FALSE"&&((P=>{if(se.test(P)&&(P=parseFloat(P),$<P&&P<_))return 1})(b)?parseFloat(b):ie.test(b)?new Date(b):b===""?null:b):b)(T=t.header?O>=C.length?"__parsed_extra":C[O]:T,S=t.transform?t.transform(S,T):S);T==="__parsed_extra"?(Q[T]=Q[T]||[],Q[T].push(S)):Q[T]=S}return t.header&&(O>C.length?oe("FieldMismatch","TooManyFields","Too many fields: expected "+C.length+" fields but parsed "+O,x+U):O<C.length&&oe("FieldMismatch","TooFewFields","Too few fields: expected "+C.length+" fields but parsed "+O,x+U)),Q}var B;m&&(t.header||t.dynamicTyping||t.transform)&&(B=1,!m.data.length||Array.isArray(m.data[0])?(m.data=m.data.map(D),B=m.data.length):m.data=D(m.data,0),t.header&&m.meta&&(m.meta.fields=C),x+=B)}function Y(){return t.header&&C.length===0}function oe(E,D,B,g){E={type:E,code:D,message:B},g!==void 0&&(E.row=g),m.errors.push(E)}j(t.step)&&(o=t.step,t.step=function(E){m=E,Y()?K():(K(),m.data.length!==0&&(q+=E.data.length,t.preview&&q>t.preview?r.abort():(m.data=m.data[0],o(m,k))))}),this.parse=function(E,D,B){var g=t.quoteChar||'"',g=(t.newline||(t.newline=this.guessLineEndings(E,g)),l=!1,t.delimiter?j(t.delimiter)&&(t.delimiter=t.delimiter(E),m.meta.delimiter=t.delimiter):((g=((U,Q,O,T,S)=>{var de,b,P,_e;S=S||[","," ","|",";",a.RECORD_SEP,a.UNIT_SEP];for(var Ne=0;Ne<S.length;Ne++){for(var me,we=S[Ne],ee=0,fe=0,J=0,te=(P=void 0,new A({comments:T,delimiter:we,newline:Q,preview:10}).parse(U)),ge=0;ge<te.data.length;ge++)O&&W(te.data[ge])?J++:(me=te.data[ge].length,fe+=me,P===void 0?P=me:0<me&&(ee+=Math.abs(me-P),P=me));0<te.data.length&&(fe/=te.data.length-J),(b===void 0||ee<=b)&&(_e===void 0||_e<fe)&&1.99<fe&&(b=ee,de=we,_e=fe)}return{successful:!!(t.delimiter=de),bestDelimiter:de}})(E,t.newline,t.skipEmptyLines,t.comments,t.delimitersToGuess)).successful?t.delimiter=g.bestDelimiter:(l=!0,t.delimiter=a.DefaultDelimiter),m.meta.delimiter=t.delimiter),p(t));return t.preview&&t.header&&g.preview++,s=E,r=new A(g),m=r.parse(s,D,B),K(),X?{meta:{paused:!0}}:m||{meta:{paused:!1}}},this.paused=function(){return X},this.pause=function(){X=!0,r.abort(),s=j(t.chunk)?"":s.substring(r.getCharIndex())},this.resume=function(){k.streamer._halted?(X=!1,k.streamer.parseChunk(s,!0)):setTimeout(k.resume,3)},this.aborted=function(){return v},this.abort=function(){v=!0,r.abort(),m.meta.aborted=!0,j(t.complete)&&t.complete(m),s=""},this.guessLineEndings=function(U,g){U=U.substring(0,1048576);var g=new RegExp(F(g)+"([^]*?)"+F(g),"gm"),B=(U=U.replace(g,"")).split("\r"),g=U.split(` 10`),U=1<g.length&&g[0].length<B[0].length;if(B.length===1||U)return` 11`;for(var Q=0,O=0;O<B.length;O++)B[O][0]===` 12`&&Q++;return Q>=B.length/2?`\r 13`:"\r"}}function F(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function A(t){var s=(t=t||{}).delimiter,r=t.newline,l=t.comments,o=t.step,_=t.preview,$=t.fastMode,se=null,ie=!1,k=t.quoteChar==null?'"':t.quoteChar,q=k;if(t.escapeChar!==void 0&&(q=t.escapeChar),(typeof s!="string"||-1<a.BAD_DELIMITERS.indexOf(s))&&(s=","),l===s)throw new Error("Comment character same as delimiter");l===!0?l="#":(typeof l!="string"||-1<a.BAD_DELIMITERS.indexOf(l))&&(l=!1),r!==` 14`&&r!=="\r"&&r!==`\r 15`&&(r=` 16`);var x=0,X=!1;this.parse=function(v,C,m){if(typeof v!="string")throw new Error("Input must be a string");var W=v.length,K=s.length,Y=r.length,oe=l.length,E=j(o),D=[],B=[],g=[],U=x=0;if(!v)return ee();if($||$!==!1&&v.indexOf(k)===-1){for(var Q=v.split(r),O=0;O<Q.length;O++){if(g=Q[O],x+=g.length,O!==Q.length-1)x+=r.length;else if(m)return ee();if(!l||g.substring(0,oe)!==l){if(E){if(D=[],_e(g.split(s)),fe(),X)return ee()}else _e(g.split(s));if(_&&_<=O)return D=D.slice(0,_),ee(!0)}}return ee()}for(var T=v.indexOf(s,x),S=v.indexOf(r,x),de=new RegExp(F(q)+F(k),"g"),b=v.indexOf(k,x);;)if(v[x]===k)for(b=x,x++;;){if((b=v.indexOf(k,b+1))===-1)return m||B.push({type:"Quotes",code:"MissingQuotes",message:"Quoted field unterminated",row:D.length,index:x}),me();if(b===W-1)return me(v.substring(x,b).replace(de,k));if(k===q&&v[b+1]===q)b++;else if(k===q||b===0||v[b-1]!==q){T!==-1&&T<b+1&&(T=v.indexOf(s,b+1));var P=Ne((S=S!==-1&&S<b+1?v.indexOf(r,b+1):S)===-1?T:Math.min(T,S));if(v.substr(b+1+P,K)===s){g.push(v.substring(x,b).replace(de,k)),v[x=b+1+P+K]!==k&&(b=v.indexOf(k,x)),T=v.indexOf(s,x),S=v.indexOf(r,x);break}if(P=Ne(S),v.substring(b+1+P,b+1+P+Y)===r){if(g.push(v.substring(x,b).replace(de,k)),we(b+1+P+Y),T=v.indexOf(s,x),b=v.indexOf(k,x),E&&(fe(),X))return ee();if(_&&D.length>=_)return ee(!0);break}B.push({type:"Quotes",code:"InvalidQuotes",message:"Trailing quote on quoted field is malformed",row:D.length,index:x}),b++}}else if(l&&g.length===0&&v.substring(x,x+oe)===l){if(S===-1)return ee();x=S+Y,S=v.indexOf(r,x),T=v.indexOf(s,x)}else if(T!==-1&&(T<S||S===-1))g.push(v.substring(x,T)),x=T+K,T=v.indexOf(s,x);else{if(S===-1)break;if(g.push(v.substring(x,S)),we(S+Y),E&&(fe(),X))return ee();if(_&&D.length>=_)return ee(!0)}return me();function _e(J){D.push(J),U=x}function Ne(J){var te=0;return te=J!==-1&&(J=v.substring(b+1,J))&&J.trim()===""?J.length:te}function me(J){return m||(J===void 0&&(J=v.substring(x)),g.push(J),x=W,_e(g),E&&fe()),ee()}function we(J){x=J,_e(g),g=[],S=v.indexOf(r,x)}function ee(J){if(t.header&&!C&&D.length&&!ie){var te=D[0],ge=Object.create(null),Fe=new Set(te);let Me=!1;for(let ke=0;ke<te.length;ke++){let pe=te[ke];if(ge[pe=j(t.transformHeader)?t.transformHeader(pe,ke):pe]){let Ce,qe=ge[pe];for(;Ce=pe+"_"+qe,qe++,Fe.has(Ce););Fe.add(Ce),te[ke]=Ce,ge[pe]++,Me=!0,(se=se===null?{}:se)[Ce]=pe}else ge[pe]=1,te[ke]=pe;Fe.add(pe)}Me&&console.warn("Duplicate headers found and renamed."),ie=!0}return{data:D,errors:B,meta:{delimiter:s,linebreak:r,aborted:X,truncated:!!J,cursor:U+(C||0),renamedHeaders:se}}}function fe(){o(ee()),D=[],B=[]}},this.abort=function(){X=!0},this.getCharIndex=function(){return x}}function M(t){var s=t.data,r=y[s.workerId],l=!1;if(s.error)r.userError(s.error,s.file);else if(s.results&&s.results.data){var o={abort:function(){l=!0,re(s.workerId,{data:[],errors:[],meta:{aborted:!0}})},pause:je,resume:je};if(j(r.userStep)){for(var _=0;_<s.results.data.length&&(r.userStep({data:s.results.data[_],errors:s.results.errors,meta:s.results.meta},o),!l);_++);delete s.results}else j(r.userChunk)&&(r.userChunk(s.results,o,s.file),delete s.results)}s.finished&&!l&&re(s.workerId,s.results)}function re(t,s){var r=y[t];j(r.userComplete)&&r.userComplete(s),r.terminate(),delete y[t]}function je(){throw new Error("Not implemented.")}function p(t){if(typeof t!="object"||t===null)return t;var s,r=Array.isArray(t)?[]:{};for(s in t)r[s]=p(t[s]);return r}function I(t,s){return function(){t.apply(s,arguments)}}function j(t){return typeof t=="function"}return a.parse=function(t,s){var r=(s=s||{}).dynamicTyping||!1;if(j(r)&&(s.dynamicTypingFunction=r,r={}),s.dynamicTyping=r,s.transform=!!j(s.transform)&&s.transform,!s.worker||!a.WORKERS_SUPPORTED)return r=null,a.NODE_STREAM_INPUT,typeof t=="string"?(t=(l=>l.charCodeAt(0)!==65279?l:l.slice(1))(t),r=new(s.download?i:N)(s)):t.readable===!0&&j(t.read)&&j(t.on)?r=new z(s):(d.File&&t instanceof File||t instanceof Object)&&(r=new h(s)),r.stream(t);(r=(()=>{var l;return!!a.WORKERS_SUPPORTED&&(l=(()=>{var o=d.URL||d.webkitURL||null,_=f.toString();return a.BLOB_URL||(a.BLOB_URL=o.createObjectURL(new Blob(["var global = (function() { if (typeof self !== 'undefined') { return self; } if (typeof window !== 'undefined') { return window; } if (typeof global !== 'undefined') { return global; } return {}; })(); global.IS_PAPA_WORKER=true; ","(",_,")();"],{type:"text/javascript"})))})(),(l=new d.Worker(l)).onmessage=M,l.id=G++,y[l.id]=l)})()).userStep=s.step,r.userChunk=s.chunk,r.userComplete=s.complete,r.userError=s.error,s.step=j(s.step),s.chunk=j(s.chunk),s.complete=j(s.complete),s.error=j(s.error),delete s.worker,r.postMessage({input:t,config:s,workerId:r.id})},a.unparse=function(t,s){var r=!1,l=!0,o=",",_=`\r 17`,$='"',se=$+$,ie=!1,k=null,q=!1,x=((()=>
17{if(typeof s=="object"){if(typeof s.delimiter!="string"||a.BAD_DELIMITERS.filter(function(C){return s.delimiter.indexOf(C)!==-1}).length||(o=s.delimiter),typeof s.quotes!="boolean"&&typeof s.quotes!="function"&&!Array.isArray(s.quotes)||(r=s.quotes),typeof s.skipEmptyLines!="boolean"&&typeof s.skipEmptyLines!="string"||(ie=s.skipEmptyLines),typeof s.newline=="string"&&(_=s.newline),typeof s.quoteChar=="string"&&($=s.quoteChar),typeof s.header=="boolean"&&(l=s.header),Array.isArray(s.columns)){if(s.columns.length===0)throw new Error("Option columns is empty");k=s.columns}s.escapeChar!==void 0&&(se=s.escapeChar+$),s.escapeFormulae instanceof RegExp?q=s.escapeFormulae:typeof s.escapeFormulae=="boolean"&&s.escapeFormulae&&(q=/^[=+\-@\t\r].*$/)}})(),new RegExp(F($),"g"));if(typeof t=="string"&&(t=JSON.parse(t)),Array.isArray(t)){if(!t.length||Array.isArray(t[0]))return X(null,t,ie);if(typeof t[0]=="object")return X(k||Object.keys(t[0]),t,ie)}else if(typeof t=="object")return typeof t.data=="string"&&(t.data=JSON.parse(t.data)),Array.isArray(t.data)&&(t.fields||(t.fields=t.meta&&t.meta.fields||k),t.fields||(t.fields=Array.isArray(t.data[0])?t.fields:typeof t.data[0]=="object"?Object.keys(t.data[0]):[]),Array.isArray(t.data[0])||typeof t.data[0]=="object"||(t.data=[t.data])),X(t.fields||[],t.data||[],ie);throw new Error("Unable to serialize unrecognized input");function X(C,m,W){var K="",Y=(typeof C=="string"&&(C=JSON.parse(C)),typeof m=="string"&&(m=JSON.parse(m)),Array.isArray(C)&&0<C.length),oe=!Array.isArray(m[0]);if(Y&&l){for(var E=0;E<C.length;E++)0<E&&(K+=o),K+=v(C[E],E);0<m.length&&(K+=_)}for(var D=0;D<m.length;D++){var B=(Y?C:m[D]).length,g=!1,U=Y?Object.keys(m[D]).length===0:m[D].length===0;if(W&&!Y&&(g=W==="greedy"?m[D].join("").trim()==="":m[D].length===1&&m[D][0].length===0),W==="greedy"&&Y){for(var Q=[],O=0;O<B;O++){var T=oe?C[O]:O;Q.push(m[D][T])}g=Q.join("").trim()===""}if(!g){for(var S=0;S<B;S++){0<S&&!U&&(K+=o);var de=Y&&oe?C[S]:S;K+=v(m[D][de],S)}D<m.length-1&&(!W||0<B&&!U)&&(K+=_)}}return K}function v(C,m){var W,K;return C==null?"":C.constructor===Date?JSON.stringify(C).slice(1,25):(K=!1,q&&typeof C=="string"&&q.test(C)&&(C="'"+C,K=!0),W=C.toString().replace(x,se),(K=K||r===!0||typeof r=="function"&&r(C,m)||Array.isArray(r)&&r[m]||((Y,oe)=>{for(var E=0;E<oe.length;E++)if(-1<Y.indexOf(oe[E]))return!0;return!1})(W,a.BAD_DELIMITERS)||-1<W.indexOf(o)||W.charAt(0)===" "||W.charAt(W.length-1)===" ")?$+W+$:W)}},a.RECORD_SEP="�",a.UNIT_SEP="�",a.BYTE_ORDER_MARK="\uFEFF",a.BAD_DELIMITERS=["\r",` 18`,'"',a.BYTE_ORDER_MARK],a.WORKERS_SUPPORTED=!u&&!!d.Worker,a.NODE_STREAM_INPUT=1,a.LocalChunkSize=10485760,a.RemoteChunkSize=5242880,a.DefaultDelimiter=",",a.Parser=A,a.ParserHandle=R,a.NetworkStreamer=i,a.FileStreamer=h,a.StringStreamer=N,a.ReadableStreamStreamer=z,d.jQuery&&((L=d.jQuery).fn.parse=function(t){var s=t.config||{},r=[];return this.each(function(_){if(!(L(this).prop("tagName").toUpperCase()==="INPUT"&&L(this).attr("type").toLowerCase()==="file"&&d.FileReader)||!this.files||this.files.length===0)return!0;for(var $=0;$<this.files.length;$++)r.push({file:this.files[$],inputElem:this,instanceConfig:L.extend({},s)})}),l(),this;function l(){if(r.length===0)j(t.complete)&&t.complete();else{var _,$,se,ie,k=r[0];if(j(t.before)){var q=t.before(k.file,k.inputElem);if(typeof q=="object"){if(q.action==="abort")return _="AbortError",$=k.file,se=k.inputElem,ie=q.reason,void(j(t.error)&&t.error({name:_},$,se,ie));if(q.action==="skip")return void o();typeof q.config=="object"&&(k.instanceConfig=L.extend(k.instanceConfig,q.config))}else if(q==="skip")return void o()}var x=k.instanceConfig.complete;k.instanceConfig.complete=function(X){j(x)&&x(X,k.file,k.inputElem),o()},a.parse(k.file,k.instanceConfig)}}function o(){r.splice(0,1),l()}}),V&&(d.onmessage=function(t){t=t.data,a.WORKER_ID===void 0&&t&&(a.WORKER_ID=t.workerId),typeof t.input=="string"?d.postMessage({workerId:a.WORKER_ID,results:a.parse(t.input,t.config),finished:!0}):(d.File&&t.input instanceof File||t.input instanceof Object)&&(t=a.parse(t.input,t.config))&&d.postMessage({workerId:a.WORKER_ID,results:t,finished:!0})}),(i.prototype=Object.create(c.prototype)).constructor=i,(h.prototype=Object.create(c.prototype)).constructor=h,(N.prototype=Object.create(N.prototype)).constructor=N,(z.prototype=Object.create(c.prototype)).constructor=z,a})})(ns);var Qs=ns.exports;const Js=cs(Qs);function Gs({onImport:n,isImporting:w}){const[f,d]=Z.useState([]),[L,u]=Z.useState(""),[V,y]=Z.useState(!1),G=()=>{const R=`business_name,category,contact_name,email,phone,notes 19`,F=new Blob([R],{type:"text/csv"}),A=URL.createObjectURL(F),M=document.createElement("a");M.href=A,M.download="vendor-roster-template.csv",M.click(),URL.revokeObjectURL(A)},a=Z.useCallback(R=>{u(R.name),Js.parse(R,{header:!0,skipEmptyLines:!0,complete:F=>{const A=F.data.map(M=>{const re=zs(M);return{raw:M,valid:re.valid,errors:re.errors,data:re.data}});d(A)}})},[]),c=R=>{var A;const F=(A=R.target.files)==null?void 0:A[0];F&&a(F)},i=R=>{var A;R.preventDefault(),y(!1);const F=(A=R.dataTransfer.files)==null?void 0:A[0];F&&F.name.endsWith(".csv")&&a(F)},h=f.filter(R=>R.valid),N=f.filter(R=>!R.valid),z=()=>{const R=h.map(F=>F.data);n(R),d([]),u("")};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"font-medium",children:"Import Vendors"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Upload a CSV file with your vendor list. Required columns: ",e.jsx("strong",{children:"business_name"}),", ",e.jsx("strong",{children:"category"}),". Optional: contact_name, email, phone, notes."]})]}),e.jsxs(H,{variant:"outline",size:"sm",onClick:G,children:[e.jsx(Ds,{className:"w-4 h-4 mr-1"}),"Download Template CSV"]}),f.length===0?e.jsxs("div",{className:`border-2 border-dashed rounded-lg p-12 text-center transition-colors ${V?"border-primary bg-primary/5":"border-muted-foreground
19/25"}`,onDragOver:R=>{R.preventDefault(),y(!0)},onDragLeave:()=>y(!1),onDrop:i,children:[e.jsx(Fs,{className:"w-8 h-8 mx-auto mb-3 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Drag & drop CSV file here, or click to browse"}),e.jsx("input",{type:"file",accept:".csv",onChange:c,className:"hidden",id:"csv-upload"}),e.jsx(H,{variant:"outline",size:"sm",asChild:!0,children:e.jsx("label",{htmlFor:"csv-upload",className:"cursor-pointer",children:"Browse Files"})})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:L}),e.jsxs(he,{variant:"secondary",children:[f.length," rows"]})]}),e.jsx(H,{variant:"ghost",size:"sm",onClick:()=>{d([]),u("")},children:"Clear"})]}),N.length>0&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-destructive",children:[e.jsx(Be,{className:"w-4 h-4"}),N.length," of ",f.length," rows have errors"]}),e.jsx("div",{className:"border rounded-lg overflow-auto max-h-[300px]",children:e.jsxs(Je,{children:[e.jsx(Ge,{children:e.jsxs(Ee,{children:[e.jsx(xe,{className:"w-8"}),e.jsx(xe,{children:"Business Name"}),e.jsx(xe,{children:"Category"}),e.jsx(xe,{children:"Contact"}),e.jsx(xe,{children:"Email"})]})}),e.jsxs(Ye,{children:[f.slice(0,10).map((R,F)=>e.jsxs(Ee,{className:R.valid?"":"bg-destructive/5",children:[e.jsx(ce,{children:R.valid?e.jsx(Os,{className:"w-4 h-4 text-green-600"}):e.jsx(Be,{className:"w-4 h-4 text-destructive"})}),e.jsx(ce,{className:"text-sm",children:String(R.raw.business_name||"")}),e.jsx(ce,{className:"text-sm",children:String(R.raw.category||"")}),e.jsx(ce,{className:"text-sm",children:String(R.raw.contact_name||"")}),e.jsx(ce,{className:"text-sm",children:String(R.raw.email||"")})]},F)),f.length>10&&e.jsx(Ee,{children:e.jsxs(ce,{colSpan:5,className:"text-center text-sm text-muted-foreground",children:["...and ",f.length-10," more rows"]})})]})]})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(H,{onClick:z,disabled:h.length===0||w,children:w?"Importing...":`Import ${h.length} vendors`}),N.length>0&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[N.length," invalid rows will be skipped"]})]})]})]})}function Ht(){const{marketId:n}=ds(),{organizerId:w,isLoading:f}=xs(),[d,L]=Z.useState(""),[u,V]=Z.useState("all"),[y,G]=Z.useState("all"),[a,c]=Z.useState(!1),[i,h]=Z.useState(null),[N,z]=Z.useState("vendors"),{categoryNames:R}=Pe(),{data:F}=Ie({queryKey:["market-name",n],queryFn:async()=>{if(!n)return null;const{data:s}=await le.from("markets").select("name").eq("id",n).single();return s},enabled:!!n}),{data:A,isLoading:M,isError:re,refetch:je}=Ms(n,w??void 0),p=ts(n,w??void 0),I=f||M,j=Z.useMemo(()=>((A==null?void 0:A.rosterEntries)||[]).filter(r=>{var l;if(d){const o=d.toLowerCase(),_=r.business_name.toLowerCase().includes(o),$=((l=r.email)==null?void 0:l.toLowerCase().includes(o))||!1,se=r.category.toLowerCase().includes(o);if(!_&&!$&&!se)return!1}return!(u!=="all"&&r.category!==u||y==="external"&&r.source!=="external"||y==="popify"&&r.source!=="popify")}),[A==null?void 0:A.rosterEntries,d,u,y]),t=(F==null?void 0:F.name)||"Market";return e.jsxs(ms,{children:[e.jsx(hs,{title:`${t} - Vendor Roster`,description:`Manage vendors for ${t}`,canonical:`/organizer/markets/${n}/roster`}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(Qe,{to:"/organizer/markets",children:e.jsxs(H,{variant:"ghost",size:"sm",children:[e.jsx(Ts,{className:"w-4 h-4 mr-2"}),"Back to Markets"]})}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold",children:[t," - Roster"]}),A&&e.jsxs("p",{className:"text-muted-foreground text-sm",children:["Showing ",A.rosterEntries.length," vendors (",A.popifyCount," Popify, ",A.externalCount," External)"]})]})]}),e.jsxs(H,{onClick:()=>c(!0),children:[e.jsx(Ve,{className:"w-4 h-4 mr-2"}),"Add External Vendor"]})]}),e.jsxs(fs,{value:N,onValueChange:z,children:[e.jsxs(ps,{children:[e.jsx(Oe,{value:"vendors",children:"All Vendors"}),e.jsx(Oe,{value:"dates",children:"By Date"}),e.jsx(Oe,{value:"import",children:"Import"})]}),e.jsxs(Te,{value:"vendors",className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"relative flex-1 max-w-sm",children:[e.jsx(Ls,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(ue,{placeholder:"Search vendors...",value:d,onChange:s=>L(s.target.value),className:"pl-9"})]}),e.jsxs(Se,{value:u,onValueChange:V,children:[e.jsx(Re,{className:"w-48",children:e.jsx(Ae,{placeholder:"Category"})}),e.jsxs(De,{children:[e.jsx(ye,{value:"all",children:"All Categories"}),R.map(s=>e.jsx(ye,{value:s,children:s},s))]})]}),e.jsxs(Se,{value:y,onValueChange:G,children:[e.jsx(Re,{className:"w-40",children:e.jsx(Ae,{placeholder:"Status"})}),e.jsxs(De,{children:[e.jsx(ye,{value:"all",children:"All"}),e.jsx(ye,{value:"popify",children:"Popify"}
19),e.jsx(ye,{value:"external",children:"External"})]})]})]}),I?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(s=>e.jsx("div",{className:"h-16 bg-muted animate-pulse rounded-lg"},s))}):re?e.jsxs("div",{className:"bg-destructive/10 border border-destructive/20 rounded-lg p-4 flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-destructive",children:"Couldn't load roster."}),e.jsx(H,{variant:"outline",size:"sm",onClick:()=>je(),children:"Retry"})]}):j.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx("p",{className:"text-muted-foreground mb-4",children:d||u!=="all"||y!=="all"?"No vendors match your filters":"No vendors yet. Popify vendors will appear here when they apply. You can also add external vendors manually."}),!d&&u==="all"&&y==="all"&&e.jsxs(H,{onClick:()=>c(!0),children:[e.jsx(Ve,{className:"w-4 h-4 mr-2"}),"Add External Vendor"]})]}):e.jsx(qs,{entries:j,onVendorClick:h})]}),e.jsx(Te,{value:"dates",children:n&&w?e.jsx(Ws,{marketId:n,organizerId:w,rosterEntries:(A==null?void 0:A.rosterEntries)||[]}):e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(ss,{className:"w-6 h-6 animate-spin text-primary"})})}),e.jsx(Te,{value:"import",children:e.jsx(Gs,{onImport:s=>{p.bulkImportVendors.mutate(s,{onSuccess:()=>z("vendors")})},isImporting:p.bulkImportVendors.isPending})})]})]}),e.jsx(Bs,{isOpen:a,onClose:()=>c(!1),onSubmit:s=>{p.addExternalVendor.mutate(s,{onSuccess:()=>c(!1)})},isSubmitting:p.addExternalVendor.isPending}),e.jsx(Us,{entry:i,isOpen:!!i,onClose:()=>h(null),onUpdate:(s,r)=>{p.updateExternalVendor.mutate({id:s,data:r})},onRemove:s=>{p.removeExternalVendor.mutate(s,{onSuccess:()=>h(null)})},isUpdating:p.updateExternalVendor.isPending})]})}export{Ht 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.