1import{j as e}from"./ui-vendor-B12AOeKi.js";import{r as u,e as Te}from"./react-vendor-DZt7wVAJ.js";import{T as Ie,b as Me,c as je,a as ye}from"./tabs-Cesl5pOW.js";import{a4 as Ne,Q as z,an as we,i as f,s as _,D as H,b as K,c as B,d as G,B as D,n as ge,L as p,I as M,F as _e,a8 as Pe,T as Ce,e as ie,aq as V,aH as ce,aI as me,l as Y,k as q,o as De,aJ as ue,g as qe,a6 as Ae,a7 as Oe,a9 as Fe,j as Se,u as ke,a as fe,ac as Ee,R as Le,r as $e,A as Ve,f as ze,bp as He,bq as Ke,br as Be,bs as Ge,bt as Qe,bu as Ye,aC as We,ag as he,ah as xe,M as Je,bv as Xe,a1 as Ze,ai as J,ab as Ue,a2 as es,aE as ss}from"./index-CUOC2qQu.js";import{b as as,c as ts,T as de,d as O,e as is,a as A}from"./table-CslgGg9T.js";import{T as pe}from"./textarea-BsyLd3-L.js";import{f as ns}from"./timezone-B4XZUXH7.js";import{S as ee,a as se,b as ae,c as te,d as F,C as rs}from"./select-B8RrBf7t.js";import{C as Re}from"./calendar-CeWNeEDm.js";import{S as os}from"./square-pen-Dp41pHaq.js";import{U as ls}from"./upload-krIPvW5L.js";import{R as be,a as U}from"./radio-group-5gLL5TFZ.js";import{C as ds}from"./chevrons-up-down-C4HP_mQi.js";import{U as cs}from"./UserManagementDialog-DR3C5ykS.js";import{C as ms}from"./CompanyLogoHeader-BjI5B9ds.js";import{R as us}from"./ReportsViewer-DopjVLfD.js";import{u as hs,A as xs}from"./useAppDisabled-93JpaqRn.js";import{T as ps}from"./ThemeToggle-DfhK81zp.js";import{H as gs}from"./HelpLink-B4Y7Lql8.js";import"./charts-vendor-B6q1L48j.js";import"./supabase-vendor-dOy44Gxq.js";import"./animation-vendor-BAVy02gd.js";import"./startOfMonth-DRiPT0Kz.js";import"./endOfMonth-BZsPvsvS.js";import"./isSameMonth-JVC-D8fV.js";import"./differenceInCalendarMonths-dxBA5rpT.js";import"./isBefore-Dfnipc6t.js";import"./isSameDay-D98FJCfs.js";import"./addDays-BsMZix8N.js";import"./subDays-COAzsAQX.js";import"./chevron-left-CYQT2jJ9.js";import"./switch-Doi0_Deq.js";import"./pushNotifications-mzUyT1or.js";import"./tag-DsvJNztT.js";import"./DemoModeIndicator-DtyTTYWR.js";import"./useOrganizationFilter-BceORZS5.js";import"./deleteUser-B-hby5j1.js";import"./BrandLogo-DzyhN8Q1.js";import"./ai-dealer-360-logo-2026-TQeVXUxP.js";import"./HTMLPreviewDialog-CRFrOB6a.js";import"./htmlReportGenerator-OdpaSbGl.js";import"./printer-BNAVOmS6.js";import"./circle-help-40fofBgV.js";import"./book-open-6UO181_a.js";const fs=h=>{const x=/\[([^\]]+)\]\(([^)]+)\)/g,l=[];let s=0,o;for(;(o=x.exec(h))!==null;)o.index>s&&l.push(h.slice(s,o.index)),l.push(e.jsx("a",{href:o[2],target:"_blank",rel:"noopener noreferrer",className:"text-primary underline hover:text-primary/80",download:o[1],children:o[1]},o.index)),s=o.index+o[0].length;return s<h.length&&l.push(h.slice(s)),l.length>0?l:h};function js({registrationId:h,open:x,onOpenChange:l,currentUser:s}){const[o,a]=u.useState(""),t=Ne(),{data:m=[]}=z({queryKey:["registration-notes",h],queryFn:async()=>{const{data:d,error:c}=await _.from("registration_notes").select("*").eq("registration_id",h).order("created_at",{ascending:!1});if(c)throw c;return d||[]},enabled:x}),n=we({mutationFn:async()=>{const{error:d}=await _.from("registration_notes").insert({registration_id:h,note_text:o,created_by:(s==null?void 0:s.name)||"User"});if(d)throw d},onSuccess:()=>{f.success("Note added successfully"),a(""),t.invalidateQueries({queryKey:["registration-notes",h]})},onError:()=>{f.error("Failed to add note")}}),j=d=>{if(d.preventDefault(),!o.trim()){f.error("Please enter a note");return}n.mutate()};return e.jsx(H,{open:x,onOpenChange:l,children:e.jsxs(K,{className:"",children:[e.jsx(B,{children:e.jsx(G,{children:"Registration Notes"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("form",{onSubmit:j,className:"space-y-2",children:[e.jsx(pe,{value:o,onChange:d=>a(d.target.value),placeholder:"Add a note...",className:"min-h-[80px]"}),e.jsx(D,{type:"submit",disabled:n.isPending,children:n.isPending?"Adding...":"Add Note"})]}),e.jsxs("div",{className:"border-t pt-4",children:[e.jsx("h3",{className:"text-sm font-semibold mb-3",children:"Notes History"}),e.jsx(ge,{className:"h-64",children:e.jsx("div",{className:"space-y-3 pr-4",children:m.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No notes yet"}):m.map(d=>e.jsxs("div",{className:"border-b pb-3 last:border-b-0",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2 mb-1",children:[e.jsx("p",{className:"text-xs font-semibold text-primary",children:d.created_by||"Unknown User"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:ns(d.created_at,"MMM dd, yyyy 'at' h:mm a")})]}),e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:fs(d.note_text)})]},d.id))})})]})]})]})})}function ys({registrationId:h,open:x,onOpenChange:l,currentUser:s}){const[o,a]=u.useState(!1),t=Ne(),{data:m=[]}=z({queryKey:["registration-documents",h],queryFn:async()=>{const{data:r,error:v}=await _.storage.from("registration-documents").list(h);if(v)throw v;return r||[]},enabled:x}),n=async(r,v)=>{const y=`ð Document uploaded: [${r}](${v})`;await _.from("registration_notes").insert({registration_id:h,note_text:y,created_by:(s==null?void 0:s.name)||"User"}),t.invalidateQueries({queryKey:["registration-notes",h]})},j=async r=>{var y;const v=(y=r.target.files)==null?void 0:y[0];if(v){a(!0);try{const S=`${h}/${v.name}`,{error:N}=await _.storage.from("registration-documents").upload(S,v);if(N)throw N;const{data:P}=_.storage.from("registration-documents").getPublicUrl(S);await n(v.name,P.publicUrl),f.success("Document uploaded"),t.invalidateQueries({queryKey:["registration-documents",h]})}catch{f.error("Failed to upload document")}finally{a(!1),r.target.value=""}}},d=async r=>{try{const{data:v,error:y}=await _.storage.from("registration-documents").download(`${h}/${r}`);if(y)throw y;const S=URL.createObjectURL(v),N=document.createElement("a");N.href=S,N.download=r,N.click(),URL.revokeObjectURL(S)}catch{f.error("Failed to download document")}},c=we({mutationFn:async r=>{const{error:v}=await _.storage.from("registration-documents").remove([`${h}/${r}`]);if(v)throw v},onSuccess:()=>{t.invalidateQueries({queryKey:["registration-documents",h]}),f.success("Document deleted")},onError:()=>{f.error("Failed to delete document")}});return e.jsx(H,{open:x,onOpenChange:l,children:e.jsxs(K,{children:[e.jsx(B,{children:e.jsx(G,{children:"Registration Documents"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Upload Document"}
1),e.jsx("div",{className:"flex gap-2",children:e.jsx(M,{type:"file",onChange:j,disabled:o,accept:".pdf,.jpg,.jpeg,.png,.doc,.docx"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Uploaded Documents"}),e.jsx(ge,{className:"h-64 border rounded-lg",children:e.jsx("div",{className:"divide-y",children:m.length===0?e.jsx("p",{className:"p-4 text-sm text-muted-foreground",children:"No documents uploaded"}):m.map(r=>e.jsxs("div",{className:"flex items-center justify-between p-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_e,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:r.name})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>d(r.name),children:e.jsx(Pe,{className:"h-4 w-4"})}),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>c.mutate(r.name),children:e.jsx(Ce,{className:"h-4 w-4 text-destructive"})})]})]},r.name))})})]})]})]})})}function bs({open:h,onOpenChange:x,onSubmit:l}){const[s,o]=u.useState({missingCOD:!1,rtaIssue:!1,missingDocs:!1}),[a,t]=u.useState({missingCOD:{amount:"",responsible:[]},rtaIssue:{details:"",responsible:[]},missingDocs:{details:"",responsible:[]}}),m=n=>{n.preventDefault();const j=[];if(s.missingCOD){if(!a.missingCOD.amount||a.missingCOD.responsible.length===0){alert("Please enter COD amount and select at least one responsible party");return}j.push({type:"Missing COD",details:`Amount: $${a.missingCOD.amount}`,responsible:a.missingCOD.responsible,amount:parseFloat(a.missingCOD.amount),completed:!1})}if(s.rtaIssue){if(!a.rtaIssue.details.trim()||a.rtaIssue.responsible.length===0){alert("Please describe the RTA issue and select at least one responsible party");return}j.push({type:"RTA Issue",details:a.rtaIssue.details.trim(),responsible:a.rtaIssue.responsible,completed:!1})}if(s.missingDocs){if(!a.missingDocs.details.trim()||a.missingDocs.responsible.length===0){alert("Please specify missing documents and select at least one responsible party");return}j.push({type:"Missing Docs",details:a.missingDocs.details.trim(),responsible:a.missingDocs.responsible,completed:!1})}if(j.length===0){alert("Please select at least one issue");return}l(j),o({missingCOD:!1,rtaIssue:!1,missingDocs:!1}),t({missingCOD:{amount:"",responsible:[]},rtaIssue:{details:"",responsible:[]},missingDocs:{details:"",responsible:[]}})};return e.jsx(H,{open:h,onOpenChange:x,children:e.jsxs(K,{className:"",children:[e.jsxs(B,{children:[e.jsx(G,{children:"Report Issues"}),e.jsx(ie,{children:"Select all issues that apply and provide required details"})]}),e.jsx(ge,{className:"max-h-[calc(90vh-120px)] pr-4",children:e.jsxs("form",{onSubmit:m,className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3 border-b pb-4",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(V,{id:"missingCOD",checked:s.missingCOD,onCheckedChange:n=>o({...s,missingCOD:!!n})}),e.jsx(p,{htmlFor:"missingCOD",className:"text-base font-semibold",children:"Missing COD"})]}),s.missingCOD&&e.jsxs("div",{className:"ml-6 space-y-3",children:[e.jsxs("div",{children:[e.jsx(p,{children:"COD Amount ($)"}),e.jsx(M,{type:"number",step:"0.01",placeholder:"Enter amount",value:a.missingCOD.amount,onChange:n=>t({...a,missingCOD:{...a.missingCOD,amount:n.target.value}}),required:!0})]}),e.jsxs("div",{children:[e.jsx(p,{children:"Responsible Party (Select all that apply)"}),e.jsx("div",{className:"space-y-2 mt-2",children:["Salesperson","Office","Manager"].map(n=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(V,{id:`cod-${n}`,checked:a.missingCOD.responsible.includes(n),onCheckedChange:j=>{const d=j?[...a.missingCOD.responsible,n]:a.missingCOD.responsible.filter(c=>c!==n);t({...a,missingCOD:{...a.missingCOD,responsible:d}})}}),e.jsx(p,{htmlFor:`cod-${n}`,children:n})]},n))})]})]})]}),e.jsxs("div",{className:"space-y-3 border-b pb-4",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(V,{id:"rtaIssue",checked:s.rtaIssue,onCheckedChange:n=>o({...s,rtaIssue:!!n})}),e.jsx(p,{htmlFor:"rtaIssue",className:"text-base font-semibold",children:"RTA Issue"})]}),s.rtaIssue&&e.jsxs("div",{className:"ml-6 space-y-3",children:[e.jsxs("div",{children:[e.jsx(p,{children:"Issue Description"}),e.jsx(pe,{placeholder:"Describe the RTA issue...",rows:3,value:a.rtaIssue.details,onChange:n=>t({...a,rtaIssue:{...a.rtaIssue,details:n.target.value}}),required:!0})]}),e.jsxs("div",{children:[e.jsx(p,{children:"Responsible Party (Select all that apply)"}),e.jsx("div",{className:"space-y-2 mt-2",children:["Salesperson","Office","Manager"].map(n=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(V,{id:`rta-${n}`,checked:a.rtaIssue.responsible.includes(n),onCheckedChange:j=>{const d=j?[...a.rtaIssue.responsible,n]:a.rtaIssue.responsible.filter(c=>c!==n);t({...a,rtaIssue:{...a.rtaIssue,responsible:d}})}}),e.jsx(p,{htmlFor:`rta-${n}`,children:n})]},n))})]})]})]}),e.jsxs("div",{className:"space-y-3 pb-4",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(V,{id:"missingDocs",checked:s.missingDocs,onCheckedChange:n=>o({...s,missingDocs:!!n})}),e.jsx(p,{htmlFor:"missingDocs",className:"text-base font-semibold",children:"Missing Docs"})]}),s.missingDocs&&e.jsxs("div",{className:"ml-6 space-y-3",children:[e.jsxs("div",{children:[e.jsx(p,{children:"Missing Document(s)"}),e.jsx(pe,{placeholder:"Specify which documents are missing...",rows:3,value:a.missingDocs.details,onChange:n=>t({...a,missingDocs:{...a.missingDocs,details:n.target.value}}),required:!0})]}),e.jsxs("div",{children:[e.jsx(p,{children:"Responsible Party (Select all that apply)"}),e.jsx("div",{className:"space-y-2 mt-2",children:["Salesperson","Office","Manager"].map(n=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(V,{id:`docs-${n}`,checked:a.missingDocs.responsible.includes(n),onCheckedChange:j=>{const d=j?[...a.missingDocs.responsible,n]:a.missingDocs.responsible.filter(c=>c!==n);t({...a,missingDocs:{...a.missingDocs,responsible:d}})}}),e.jsx(p,{htmlFor:`docs-${n}`,children:n})]},n))})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(D,{type:"button",variant:"outline",onClick:()=>x(!1),children:"Cancel"}),e.jsx(D,{type:"submit",children:"Submit Issues"})]})]})})]})})}function vs({open:h,onOpenChange:x,registration:l,onSuccess:s}){const[o,a]=u.useState(l.salesperson_name),[t,m]=u.useState(new Date(l.delivery_date)),[n,j]=u.useState(l.stock_number),[d,c]=u.useState(l.year_make_model),[r,v]=u.useState(l.registration_type),[y,S]=u.useState(l.state||""),{data:N=[]}=z({queryKey:["registration-salespersons"],queryFn:async()=>{const{data:C,error:g}=await _.from("registration_salespersons").select("*").order("name",{ascending:!0});if(g)throw g;return C||[]}}),P=async C=>{C.preventDefault();const{error:g}=await _.from("registrations").update({salesperson_name:o,delivery_date:Y(t,"yyyy-MM-dd"),stock_number:n,year_make_model:d,registration_type:r,state:r==="Out of state"?y:null}).eq("id",l.id);if(g){f.error("Failed to update registration");return}await _.from("registration_notes").insert({registration_id:l.id,note_text:"Registration details updated by office",created_by:"Office"}),f.success("Registration updated successfully"),s(),x(!1)};return e.jsx(H,{open:h,onOpenChange:x,children:e.jsxs(K,{className:"",children:[e.jsx(B,{children:e.jsx(G,{children:"Edit Registration"})}),e.jsxs("form",{onSubmit:P,className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Salesperson"}),e.jsxs(ee,{value:o,onValueChange:a,children:[e.jsx(se,{children:e.jsx(ae,{})}),e.jsx(te,{children:N.map(C=>e.jsx(F,{value:C.name,children:C.name},C.id))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Delivery Date"}),e.jsxs(ce,{children:[e.jsx(me,{asChild:!0,children:e.jsxs(D,{variant:"outline",className:q("w-full justify-start text-left font-normal",!t&&"text-muted-foreground"),children:[e.jsx(De,{className:"mr-2 h-4 w-4"}
1),t?Y(t,"MM/dd/yyyy"):e.jsx("span",{children:"Pick a date"})]})}),e.jsx(ue,{className:"w-auto p-0",children:e.jsx(Re,{mode:"single",selected:t,onSelect:C=>C&&m(C),initialFocus:!0,className:"pointer-events-auto"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Stock Number"}),e.jsx(M,{value:n,onChange:C=>j(C.target.value),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Year / Make / Model"}),e.jsx(M,{value:d,onChange:C=>c(C.target.value),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Registration Type"}),e.jsxs(ee,{value:r,onValueChange:v,children:[e.jsx(se,{children:e.jsx(ae,{})}),e.jsxs(te,{children:[e.jsx(F,{value:"New Plates",children:"New Plates"}),e.jsx(F,{value:"Transfer Plates",children:"Transfer Plates"}),e.jsx(F,{value:"Out of state",children:"Out of state"})]})]})]}),r==="Out of state"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"State"}),e.jsx(M,{value:y,onChange:C=>S(C.target.value),placeholder:"Enter state",required:!0})]})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(D,{type:"button",variant:"outline",onClick:()=>x(!1),children:"Cancel"}),e.jsx(D,{type:"submit",children:"Save Changes"})]})]})]})})}function Ns({registrationId:h,currentStatus:x,isOfficeMode:l,isCompletedTab:s,isViewOnly:o,onStatusChange:a,getStatusBadgeVariant:t}){const{data:m=[]}=z({queryKey:["registration-notes",h],queryFn:async()=>{const{data:c,error:r}=await _.from("registration_notes").select("*").eq("registration_id",h).order("created_at",{ascending:!1});if(r)throw r;return c||[]}}),n=c=>{const r=c.toLowerCase();return r.includes("issue")&&!r.includes("completed")?"bg-red-100 dark:bg-red-900/30 text-red-900 dark:text-red-100":r.includes("reviewing")?"bg-yellow-100 dark:bg-yellow-900/30 text-yellow-900 dark:text-yellow-100":r.includes("completed")?"bg-green-100 dark:bg-green-900/30 text-green-900 dark:text-green-100":""},j=()=>m.length===0?null:e.jsxs("div",{className:"space-y-2 max-w-sm",children:[e.jsx("p",{className:"font-semibold text-sm mb-2",children:"Recent Activity:"}),m.slice(0,5).map(c=>e.jsxs("div",{className:q("p-2 rounded text-xs space-y-1",n(c.note_text)),children:[e.jsx("p",{className:q("font-medium",c.note_text.toLowerCase().includes("completed")&&"line-through"),children:c.note_text}),e.jsxs("p",{className:"text-xs opacity-70",children:[c.created_by," - ",Y(new Date(c.created_at),"MM/dd/yy h:mm a")]})]},c.id)),m.length>5&&e.jsxs("p",{className:"text-xs opacity-70 italic",children:["+ ",m.length-5," more notes (click notes icon to view all)"]})]});if(!x)return e.jsx("span",{className:"text-muted-foreground text-sm",children:"-"});const d=l&&!s&&!o?e.jsxs(ee,{value:x,onValueChange:a,children:[e.jsx(se,{className:q("w-[140px]",t(x)),children:e.jsx(ae,{})}),e.jsxs(te,{className:"bg-background z-50",children:[e.jsx(F,{value:"Pending",children:"Pending"}),e.jsx(F,{value:"Reviewing",children:"Reviewing"}),e.jsx(F,{value:"Issue",children:"Issue"}),e.jsx(F,{value:"Ready",children:"Ready"})]})]}):e.jsx(qe,{className:q(t(x)),children:x});return e.jsxs(Ae,{delayDuration:300,children:[e.jsx(Oe,{asChild:!0,children:e.jsx("div",{className:"cursor-help",children:d})}),e.jsx(Fe,{side:"left",className:"max-w-md p-3",children:e.jsx(j,{})})]})}function ve({registrations:h,isOfficeMode:x,isViewOnly:l=!1,currentUser:s,isCompletedTab:o=!1,onRefresh:a}){const[t,m]=u.useState(null),[n,j]=u.useState(null),[d,c]=u.useState(null),[r,v]=u.useState(null),[y,S]=u.useState(null),N=Se(),{currentUser:P}=ke(),{selectedDealership:C}=fe(),g=async(i,b,k,w)=>{if(k&&(s==null?void 0:s.role)==="User"){f.error("Only Manager and Admin can uncheck 'In Office'");return}const I=!k,$={[b]:I};I&&($.current_status="Pending"),I||($.current_status=null);const{error:re}=await _.from("registrations").update($).eq("id",i);if(re){f.error("Failed to update registration");return}const oe=`${{timeline_in_office:"In Office"}[b]} ${I?"checked":"unchecked"}`;await _.from("registration_notes").insert({registration_id:i,note_text:oe,created_by:(s==null?void 0:s.name)||"User"}),f.success("Registration updated"),a()},T=async(i,b)=>{if(b==="Issue"){v(i);return}const k={current_status:b};b==="Ready"&&(k.completed_at=new Date().toISOString(),k.timeline_registration_ready=!0);const{error:w}=await _.from("registrations").update(k).eq("id",i);if(w){f.error("Failed to update status");return}await _.from("registration_notes").insert({registration_id:i,note_text:`Status changed to: ${b}`,created_by:(s==null?void 0:s.name)||"Office"}),f.success("Status updated"),a()},E=async(i,b)=>{const k=b.map(I=>`${I.type} (${I.responsible.join(", ")}): ${I.details}`).join(" | "),{error:w}=await _.from("registrations").update({timeline_issue:!0,issue_description:k,issues:b,issue_flagged_at:new Date().toISOString(),current_status:"Issue"}).eq("id",i);if(w){f.error("Failed to flag issue");return}for(const I of b)await _.from("registration_notes").insert({registration_id:i,note_text:`Issue flagged - ${I.type} (${I.responsible.join(", ")}): ${I.details}`,created_by:(s==null?void 0:s.name)||"Office"});f.success("Issues flagged"),v(null),a()},R=i=>{switch(i){case"Reviewing":return"bg-yellow-500 text-white hover:bg-yellow-600";case"Issue":return"bg-red-500 text-white hover:bg-red-600";case"Ready":return"bg-green-500 text-white hover:bg-green-600";default:return"bg-gray-500 text-white hover:bg-gray-600"}},X=async i=>{if(!x){f.error("Only office mode can delete records");return}if(!confirm("Are you sure you want to delete this registration?"))return;const{error:b}=await _.from("registrations").delete().eq("id",i);if(b){f.error("Failed to delete registration");return}if(P){const k=h.find(w=>w.id===i);
1await $e({userId:P.id,dealershipId:C==null?void 0:C.id,module:ze.REGISTRATION,action:Ve.DELETE_REGISTRATION,details:{customer_name:k==null?void 0:k.customer_name,stock_number:k==null?void 0:k.stock_number,year_make_model:k==null?void 0:k.year_make_model}})}f.success("Registration deleted"),a()},ne=async i=>{if(!["Manager","Finance Manager","Admin"].includes((s==null?void 0:s.role)||"")){f.error("Only Manager, Finance Manager, or Admin can move registrations");return}if(!confirm("Move this registration back to active?"))return;const{error:b}=await _.from("registrations").update({timeline_registration_ready:!1,completed_at:null,current_status:"Pending"}).eq("id",i);if(b){f.error("Failed to move registration");return}await _.from("registration_notes").insert({registration_id:i,note_text:"Registration moved back to active",created_by:(s==null?void 0:s.name)||"Office"}),f.success("Registration moved to active"),a()};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border rounded-lg overflow-hidden",children:e.jsxs(as,{children:[e.jsx(ts,{children:e.jsxs(de,{children:[e.jsx(O,{className:"w-[50px]"}),e.jsx(O,{children:"Salesperson"}),!l&&e.jsx(O,{children:"Customer Name"}),e.jsx(O,{children:"Delivery Date"}),e.jsx(O,{children:"Stock #"}),e.jsx(O,{children:"Year/Make/Model"}),e.jsx(O,{children:"Registration Type"}),e.jsx(O,{children:"State"}),e.jsx(O,{children:"In Office"}),e.jsx(O,{children:"Current Status"}),e.jsx(O,{children:"Actions"})]})}),e.jsx(is,{children:h.map(i=>e.jsxs(e.Fragment,{children:[e.jsxs(de,{className:q(i.timeline_issue&&"bg-red-50 dark:bg-red-950/20",i.timeline_registration_ready&&"bg-green-50 dark:bg-green-950/20"),children:[e.jsx(A,{children:e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>m(t===i.id?null:i.id),children:t===i.id?e.jsx(rs,{className:"h-4 w-4"}):e.jsx(Ee,{className:"h-4 w-4"})})}),e.jsx(A,{children:i.salesperson_name}),!l&&e.jsx(A,{children:i.customer_name||"-"}),e.jsx(A,{children:Y(new Date(i.delivery_date),"MM/dd/yyyy")}),e.jsx(A,{children:i.stock_number}),e.jsx(A,{children:i.year_make_model}),e.jsx(A,{children:i.registration_type}),e.jsx(A,{children:i.state||"-"}),e.jsx(A,{children:e.jsx(V,{checked:i.timeline_in_office,onCheckedChange:()=>g(i.id,"timeline_in_office",i.timeline_in_office),disabled:o||l||i.timeline_in_office&&(s==null?void 0:s.role)==="User"})}),e.jsx(A,{children:e.jsx(Ns,{registrationId:i.id,currentStatus:i.current_status,isOfficeMode:x,isCompletedTab:o,isViewOnly:l,onStatusChange:b=>T(i.id,b),getStatusBadgeVariant:R})}),e.jsx(A,{children:e.jsxs("div",{className:"flex gap-2",children:[x&&!o&&!l&&N.canEdit&&e.jsx(D,{variant:"outline",size:"sm",onClick:()=>S(i),title:"Edit registration",children:e.jsx(os,{className:"h-4 w-4"})}),o&&!l&&["Manager","Finance Manager","Admin"].includes((s==null?void 0:s.role)||"")&&e.jsx(D,{variant:"outline",size:"sm",onClick:()=>ne(i.id),title:"Move to Active",children:e.jsx(Le,{className:"h-4 w-4"})}),!l&&e.jsx(D,{variant:"outline",size:"sm",onClick:()=>j(i.id),children:e.jsx(_e,{className:"h-4 w-4"})}),!l&&e.jsx(D,{variant:"outline",size:"sm",onClick:()=>c(i.id),children:e.jsx(ls,{className:"h-4 w-4"})}),x&&!l&&N.canDelete&&e.jsx(D,{variant:"destructive",size:"sm",onClick:()=>X(i.id),title:"Delete registration (Admin only)",children:e.jsx(Ce,{className:"h-4 w-4"})})]})})]},i.id),t===i.id&&(i.issue_description||i.issues&&Array.isArray(i.issues)&&i.issues.length>0)&&e.jsx(de,{children:e.jsx(A,{colSpan:12,className:"bg-muted/50",children:e.jsx("div",{className:"p-4 space-y-3",children:i.issues&&Array.isArray(i.issues)&&i.issues.length>0?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm font-semibold",children:"Issues:"}),i.issues.map((b,k)=>e.jsxs("div",{className:"ml-2 p-3 border-l-2 border-red-500 flex items-start gap-3",children:[!l&&e.jsx(V,{checked:b.completed||!1,onCheckedChange:async w=>{const I=[...i.issues];I[k]={...I[k],completed:!!w};const{error:$}=await _.from("registrations").update({issues:I}).eq("id",i.id);$||(await _.from("registration_notes").insert({registration_id:i.id,note_text:`Issue ${w?"completed":"reopened"} - ${b.type}`,created_by:(s==null?void 0:s.name)||"User"}),f.success(w?"Issue marked as complete":"Issue reopened"),a())}}),e.jsxs("div",{className:q("flex-1",b.completed&&"opacity-50"),children:[e.jsx("p",{className:q("text-sm font-medium",b.completed&&"line-through"),children:b.type}),e.jsxs("p",{className:q("text-sm text-muted-foreground",b.completed&&"line-through"),children:["Responsible: ",Array.isArray(b.responsible)?b.responsible.join(", "):b.responsible]}),e.jsx("p",{className:q("text-sm text-muted-foreground",b.completed&&"line-through"),children:b.details}),b.amount&&e.jsxs("p",{className:q("text-sm font-medium text-red-600",b.completed&&"line-through"),children:["Amount: $",b.amount]})]})]},k))]}):i.issue_description&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm font-semibold",children:"Issue Description:"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:i.issue_description})]})})})})]}))})]})}),n&&e.jsx(js,{registrationId:n,open:!0,onOpenChange:i=>!i&&j(null),currentUser:s}),d&&e.jsx(ys,{registrationId:d,open:!0,onOpenChange:i=>!i&&c(null),currentUser:s}),r&&e.jsx(bs,{open:!0,onOpenChange:i=>!i&&v(null),onSubmit:i=>E(r,i)}),y&&e.jsx(vs,{open:!0,onOpenChange:i=>!i&&S(null),registration:y,onSuccess:a})]})}function ws({open:h,onOpenChange:x,onComplete:l}){const[s,o]=u.useState(""),[a,t]=u.useState(""),[m,n]=u.useState(""),j=d=>{d.preventDefault(),l({trade_in_year_make_model:s,trade_in_belongs_to_purchaser:a==="yes",trade_in_relationship:a==="no"?m:null}),o(""),t(""),n("")};return e.jsx(H,{open:h,onOpenChange:x,children:e.jsxs(K,{children:[e.jsxs(B,{children:[e.jsx(G,{children:"Transfer Registration - Trade-In Information"}),e.jsx(ie,{children:"Please provide details about the trade-in vehicle"})]}),e.jsxs("form",{onSubmit:j,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Trade-In Vehicle (Year, Make & Model)"}),e.jsx(M,{value:s,onChange:d=>o(d.target.value),placeholder:"e.g., 2020 Honda Accord",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Does the trade-in belong to the purchaser?"}),e.jsxs(be,{value:a,onValueChange:t,children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(U,{value:"yes",id:"belongs-yes"}),e.jsx(p,{htmlFor:"belongs-yes",children:"Yes"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(U,{value:"no",id:"belongs-no"}),e.jsx(p,{htmlFor:"belongs-no",children:"No"})]})]})]}),a==="no"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Relationship"}),e.jsxs(be,{value:m,onValueChange:n,children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(U,{value:"Household",id:"household"}),e.jsx(p,{htmlFor:"household",children:"Household"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(U,{value:"Gift",id:"gift"}),e.jsx(p,{htmlFor:"gift",children:"Gift"})]})]})]}),a==="no"&&m&&e.jsxs("div",{className:"p-4 bg-blue-50 dark:bg-blue-950/20 border border-blue-200 dark:border-blue-800 rounded-lg space-y-2",children:[e.jsxs("p",{className:"text-sm font-semibold text-blue-900 dark:text-blue-100",children:["Required Form: ",m==="Household"?"MVU-26":"MVU-24"]}),e.jsxs("p",{className:"text-sm text-blue-700 dark:text-blue-300",children:["Please obtain and complete form ",m==="Household"?"MVU-26":"MVU-24"," from the Massachusetts RMV."]})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(D,{type:"button",variant:"outline",onClick:()=>x(!1),children:"Cancel"}),e.jsx(D,{type:"submit",disabled:!s||!a||a==="no"&&!m,children:"Continue"})]})]})]})})}function _s({open:h,onOpenChange:x,onSuccess:l,currentUser:s}){const{selectedDealership:o}=fe(),a=(s==null?void 0:s.role)==="User",[t,m]=u.useState({salesperson_name:a&&(s==null?void 0:s.name)||"",customer_name:"",delivery_date:new Date,deal_number:"",stock_number:"",year_make_model:"",registration_type:"",state:""}),[n,j]=u.useState(!1),[d,c]=u.useState(!1),[r,v]=u.useState(!1),[y,S]=u.useState(null),{data:N=[]}=z({queryKey:["registration-salespersons"],queryFn:async()=>{const{data:g}=await _.from("job_roles").select("id").eq("role_name","Salesperson").single();if(!g)return[];const{data:T,error:E}=await _.from("user_job_roles").select("registration_users(id, name)").eq("job_role_id",g.id).order("registration_users(name)");if(E)throw E;return(T||[]).map(R=>
1R.registration_users).filter(Boolean)}}),P=async g=>{if(g.preventDefault(),(t.registration_type==="Transfer"||t.registration_type==="Transfer Plates")&&!y){c(!0);return}j(!0);try{if(!t.customer_name||!t.deal_number||!t.stock_number||!t.year_make_model||!t.registration_type){f.error("Please fill in all required fields");return}const T={...t,delivery_date:Y(t.delivery_date,"yyyy-MM-dd"),created_by:"User",dealership_id:o==null?void 0:o.id};y&&(T.trade_in_year_make_model=y.trade_in_year_make_model,T.trade_in_belongs_to_purchaser=y.trade_in_belongs_to_purchaser,T.trade_in_relationship=y.trade_in_relationship);const{error:E}=await _.from("registrations").insert(T);if(E)throw E;f.success("Registration created successfully"),l(),x(!1),m({salesperson_name:"",customer_name:"",delivery_date:new Date,deal_number:"",stock_number:"",year_make_model:"",registration_type:"",state:""}),S(null)}catch{f.error("Failed to create registration")}finally{j(!1)}},C=g=>{S(g),c(!1),setTimeout(()=>{const T=document.querySelector("form");T&&T.dispatchEvent(new Event("submit",{cancelable:!0,bubbles:!0}))},100)};return e.jsxs(e.Fragment,{children:[e.jsx(H,{open:h,onOpenChange:x,children:e.jsxs(K,{className:"",children:[e.jsx(B,{children:e.jsx(G,{children:"New Registration"})}),e.jsxs("form",{onSubmit:P,className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Salesperson"}),a?e.jsx(M,{value:t.salesperson_name,disabled:!0,className:"bg-muted"}):e.jsxs(ce,{open:r,onOpenChange:v,children:[e.jsx(me,{asChild:!0,children:e.jsxs(D,{variant:"outline",role:"combobox","aria-expanded":r,className:"w-full justify-between",children:[t.salesperson_name||"Select salesperson...",e.jsx(ds,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(ue,{className:"w-[var(--radix-popover-trigger-width)] p-0 bg-background z-50",align:"start",children:e.jsxs(He,{children:[e.jsx(Ke,{placeholder:"Search salesperson...",className:"h-9"}),e.jsxs(Be,{children:[e.jsx(Ge,{children:"No salesperson found."}),e.jsx(Qe,{children:N.map(g=>e.jsxs(Ye,{value:g.name,onSelect:T=>{m({...t,salesperson_name:T}),v(!1)},className:"cursor-pointer",children:[g.name,e.jsx(We,{className:q("ml-auto h-4 w-4",t.salesperson_name===g.name?"opacity-100":"opacity-0")})]},g.id))})]})]})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Customer Name *"}),e.jsx(M,{value:t.customer_name,onChange:g=>m({...t,customer_name:g.target.value}),placeholder:"Customer Name",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Deal Number *"}),e.jsx(M,{value:t.deal_number,onChange:g=>m({...t,deal_number:g.target.value}),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Delivery Date"}),e.jsxs(ce,{children:[e.jsx(me,{asChild:!0,children:e.jsxs(D,{variant:"outline",className:q("w-full justify-start text-left font-normal",!t.delivery_date&&"text-muted-foreground"),children:[e.jsx(De,{className:"mr-2 h-4 w-4"}),t.delivery_date?Y(t.delivery_date,"PPP"):e.jsx("span",{children:"Pick a date"})]})}),e.jsx(ue,{className:"w-auto p-0",align:"start",children:e.jsx(Re,{mode:"single",selected:t.delivery_date,onSelect:g=>g&&m({...t,delivery_date:g}),initialFocus:!0,className:"pointer-events-auto"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Stock Number *"}),e.jsx(M,{value:t.stock_number,onChange:g=>m({...t,stock_number:g.target.value}),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Year/Make/Model *"}),e.jsx(M,{value:t.year_make_model,onChange:g=>m({...t,year_make_model:g.target.value}),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Registration Type *"}),e.jsxs(ee,{value:t.registration_type,onValueChange:g=>m({...t,registration_type:g}),required:!0,children:[e.jsx(se,{children:e.jsx(ae,{placeholder:"Select type"})}),e.jsxs(te,{children:[e.jsx(F,{value:"New",children:"New Plates"}),e.jsx(F,{value:"Transfer",children:"Transfer Plates"}),e.jsx(F,{value:"Out of State",children:"Out of State"})]})]})]}),t.registration_type==="Out of State"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"State"}),e.jsx(M,{value:t.state,onChange:g=>m({...t,state:g.target.value}),required:!0})]})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(D,{type:"button",variant:"outline",onClick:()=>x(!1),children:"Cancel"}),e.jsx(D,{type:"submit",disabled:n,children:n?"Creating...":"REQUEST REGISTRATION"})]})]})]})}),e.jsx(ws,{open:d,onOpenChange:c,onComplete:C})]})}function Cs({open:h,userId:x,username:l,onPasswordChanged:s}){const[o,a]=u.useState(""),[t,m]=u.useState(""),[n,j]=u.useState(!1),[d,c]=u.useState(!1),[r,v]=u.useState(!1),y=async S=>{if(S.preventDefault(),o!==t){f.error("Passwords don't match");return}if(o==="Temp4pass"){f.error("You cannot use the default password. Please choose a different password.");return}if(o.length<8){f.error("Password must be at least 8 characters long");return}v(!0);try{const{data:N,error:P}=await _.functions.invoke("change-my-password",{body:{current_password:"Temp4pass",new_password:o}});if(P)throw P;if(N&&N.success===!1)throw new Error(N.error||"Failed to change password");f.success("Password changed successfully!"),a(""),m(""),s()}catch(N){f.error((N==null?void 0:N.message)||"Failed to change password")}finally{v(!1)}};return e.jsx(H,{open:h,onOpenChange:()=>{},children:e.jsxs(K,{className:"",onInteractOutside:S=>S.preventDefault(),children:[e.jsxs(B,{children:[e.jsx(G,{children:"Change Required Password"}),e.jsx(ie,{children:'Admin users cannot use the default password "Temp4pass". Please set a new password to continue.'})]}),e.jsxs("form",{onSubmit:y,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Username"}),e.jsx(M,{value:l,disabled:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"New Password"}
1),e.jsxs("div",{className:"relative",children:[e.jsx(M,{type:n?"text":"password",value:o,onChange:S=>a(S.target.value),placeholder:"Enter new password",autoFocus:!0,required:!0,className:"pr-10"}),e.jsx(D,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent",onClick:()=>j(!n),children:n?e.jsx(he,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(xe,{className:"h-4 w-4 text-muted-foreground"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Confirm Password"}),e.jsxs("div",{className:"relative",children:[e.jsx(M,{type:d?"text":"password",value:t,onChange:S=>m(S.target.value),placeholder:"Confirm new password",required:!0,className:"pr-10"}),e.jsx(D,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent",onClick:()=>c(!d),children:d?e.jsx(he,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(xe,{className:"h-4 w-4 text-muted-foreground"})})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(D,{type:"submit",disabled:r,children:r?"Changing...":"Change Password"})})]})]})})}function Ds({open:h,onOpenChange:x,onLoginSuccess:l,onViewOnlyMode:s}){const[o,a]=u.useState(""),[t,m]=u.useState(""),[n,j]=u.useState(!1),[d,c]=u.useState(!1),[r,v]=u.useState(!1),[y,S]=u.useState(null),N=async C=>{C.preventDefault(),c(!0);try{const g=o.trim(),{data:T,error:E}=await _.rpc("verify_user_login",{p_username:g,p_password:t});if(E||!T||T.length===0){f.error("Invalid username or password"),c(!1);return}const R=T[0];if(R.is_extension_only){f.error("This account can only be used with the FB Marketplace Extension. Please use the Chrome extension to log in."),c(!1);return}if(R.role==="Admin"&&t==="Temp4pass"){S(R),v(!0),c(!1);return}f.success(`Welcome, ${R.name}!`),l({id:R.id,name:R.name,username:R.username,role:R.role}),a(""),m(""),x(!1)}catch{f.error("Login failed")}finally{c(!1)}},P=()=>{v(!1),y&&(f.success(`Welcome, ${y.name}!`),l({id:y.id,name:y.name,username:y.username,role:y.role}),a(""),m(""),S(null),x(!1))};return e.jsxs(e.Fragment,{children:[e.jsx(Cs,{open:r,userId:(y==null?void 0:y.id)||"",username:(y==null?void 0:y.username)||"",onPasswordChanged:P}),e.jsx(H,{open:h&&!r,onOpenChange:x,children:e.jsxs(K,{children:[e.jsxs(B,{children:[e.jsx(G,{children:"Registration Tracker Login"}),e.jsx(ie,{children:"Enter your username and password to access the system"})]}),e.jsxs("form",{onSubmit:N,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Username"}),e.jsx(M,{value:o,onChange:C=>a(C.target.value),placeholder:"Enter username",autoFocus:!0,required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Password"}),e.jsxs("div",{className:"relative",children:[e.jsx(M,{type:n?"text":"password",value:t,onChange:C=>m(C.target.value),placeholder:"Enter password",required:!0,className:"pr-10"}),e.jsx(D,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent",onClick:()=>j(!n),children:n?e.jsx(he,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(xe,{className:"h-4 w-4 text-muted-foreground"})})]})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(D,{type:"button",variant:"outline",onClick:()=>{s(),x(!1)},children:"View Mode"}),e.jsx(D,{type:"submit",disabled:d,children:d?"Logging in...":"Login"})]})]})]})})]})}function fa(){const h=Te(),x=Je(),[l,s]=u.useState(!1),[o,a]=u.useState(!1),[t,m]=u.useState(!1),[n,j]=u.useState(!1),[d,c]=u.useState(!1),{currentUser:r,login:v,logout:y,isAdmin:S,isViewOnl
1y:N,enterViewOnlyMode:P,viewAsUser:C,exitViewAsMode:g,isViewingAs:T,actualUser:E}=Xe(),{currentUser:R,getAppRole:X}=ke(),[ne,i]=u.useState(!1),{isDisabled:b}=hs("registration"),k=Se(),{selectedDealership:w}=fe();u.useEffect(()=>{x&&h("/registration-mobile")},[x,h]),u.useEffect(()=>{r&&!N?r.role==="Admin"?(c(!0),j(!0)):r.role==="Manager"?(j(!0),c(!1)):(j(!1),c(!1)):(j(!1),c(!1))},[r,N,R]);const{data:I=[]}=z({queryKey:["registration-users"],queryFn:async()=>{const{data:L,error:Q}=await _.from("registration_users").select("*").order("name");if(Q)throw Q;return L||[]},enabled:d});u.useEffect(()=>{R?v({id:R.id,name:R.name,username:R.username,role:X("registration_tracker")||R.role}):!r&&!N&&m(!0)},[R,X]);const{data:$=[],refetch:re}=z({queryKey:["active-registrations",w==null?void 0:w.id],queryFn:async()=>{let L=_.from("registrations").select("*").is("timeline_registration_ready",!1);w!=null&&w.id&&(L=L.eq("dealership_id",w.id));const{data:Q,error:W}=await L.order("created_at",{ascending:!1});if(W)throw W;return Q||[]},enabled:!!(w!=null&&w.id)}),{data:Z=[],refetch:oe}=z({queryKey:["completed-registrations",w==null?void 0:w.id],queryFn:async()=>{let L=_.from("registrations").select("*").eq("timeline_registration_ready",!0);w!=null&&w.id&&(L=L.eq("dealership_id",w.id));const{data:Q,error:W}=await L.order("completed_at",{ascending:!1});if(W)throw W;return Q||[]},enabled:!!(w!=null&&w.id)}),le=()=>{re(),oe()};return b?e.jsx(xs,{appName:"Registration Tracker"}):e.jsxs("div",{className:"container mx-auto p-6 space-y-6",children:[e.jsx(ms,{className:"mb-4",size:"md"}),e.jsxs("div",{className:"mb-6",children:[e.jsx("div",{className:"flex items-center justify-between mb-4",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ze,{variant:"compact"}),e.jsx(ps,{})]})}),e.jsxs("div",{className:"flex flex-col md:flex-row md:justify-between md:items-center gap-4",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl md:text-3xl font-bold mb-2 flex items-center gap-2",children:["Registration Tracker ",e.jsx(gs,{featureKey:"registration-tracker"})]}),e.jsx("p",{className:"text-sm md:text-base text-muted-foreground",children:N?"View-Only Mode":`Welcome, ${r==null?void 0:r.name}`})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[!N&&k.canEdit&&e.jsx(J,{componentId:"registration:add-delivery-btn",appName:"Registration Tracker",componentType:"button",componentLabel:"Add Delivery Button",defaultRole:"user",children:e.jsxs(D,{onClick:()=>s(!0),variant:"default",size:"sm",className:"flex items-center gap-2","data-demo":"add-registration-btn",children:[e.jsx(Ue,{className:"h-4 w-4"}),"ADD A DELIVERY"]})}),e.jsx(J,{componentId:"registration:main-menu-btn",appName:"Registration Tracker",componentType:"button",componentLabel:"Main Menu Button",defaultRole:"user",children:e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>
1h("/"),className:"flex items-center gap-2",children:[e.jsx(es,{className:"h-4 w-4"}),"Main Menu"]})}),e.jsx(J,{componentId:"registration:logout-btn",appName:"Registration Tracker",componentType:"button",componentLabel:"Logout Button",defaultRole:"user",children:e.jsxs(D,{onClick:y,variant:"outline",size:"sm",className:"flex items-center gap-2",children:[e.jsx(ss,{className:"h-4 w-4"}),N?"Exit View Mode":"Logout"]})})]})]})]}),e.jsxs(Ie,{defaultValue:"active",className:"w-full",children:[e.jsxs(Me,{children:[e.jsx(J,{componentId:"registration:tab-active",appName:"Registration Tracker",componentType:"toggle",componentLabel:"Active Registrations Tab",defaultRole:"user",children:e.jsxs(je,{value:"active",children:["Active Registrations (",$.length,")"]})}),e.jsx(J,{componentId:"registration:tab-completed",appName:"Registration Tracker",componentType:"toggle",componentLabel:"Completed Registrations Tab",defaultRole:"user",children:e.jsxs(je,{value:"completed",children:["Completed Registrations (",Z.length,")"]})})]}),e.jsx(ye,{value:"active",className:"space-y-4",children:e.jsx(ve,{registrations:$,isOfficeMode:n,isViewOnly:N,currentUser:r,onRefresh:le})}),e.jsx(ye,{value:"completed",className:"space-y-4",children:e.jsx(ve,{registrations:Z,isOfficeMode:n,isViewOnly:N,currentUser:r,isCompletedTab:!0,onRefresh:le})})]}),e.jsx(_s,{open:l,onOpenChange:s,onSuccess:le,currentUser:r}),e.jsx(cs,{open:o,onOpenChange:a}),e.jsx(Ds,{open:t,onOpenChange:m,onLoginSuccess:v,onViewOnlyMode:P}),e.jsx(us,{open:ne,onOpenChange:i,appId:"registration_tracker",userRole:(r==null?void 0:r.role)||"User",userId:(r==null?void 0:r.id)||void 0,userName:(r==null?void 0:r.name)||void 0,activeRegistrations:$,completedRegistrations:Z})]})}export{fa 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.