1import{r as i,j as e,i as g,B as u,g as h,e as d}from"./index-CWi7Gien.js";import{t as x}from"./index-BewXcZx9.js";import{C as v,c as f}from"./card-Dj6pbwwX.js";import{T as _}from"./textarea-BRHlfX1U.js";import{U as N}from"./user-BLVGbchm.js";import{C as y}from"./circle-check-CWVG8UAr.js";import{B as j}from"./BackToDashboardButton-qdzp10R1.js";import{C as w}from"./clipboard-check-BC9_Zgnc.js";import"./arrow-left-DsKHQcwb.js";function b({job:s,onApproved:l}){var a;const[r,m]=i.useState(s.admin_notes||""),[n,o]=i.useState(!1),c=async()=>{o(!0);try{const t=await d.auth.me().catch(()=>null);await d.entities.InstallJob.update(s.id,{status:"Admin Approved",admin_approved_at:new Date().toISOString(),admin_approved_by:t==null?void 0:t.email,admin_notes:r}),s.opportunity_id?await d.entities.Opportunity.update(s.opportunity_id,{pipeline_stage:"Funded / Closed"}).catch(()=>{}):s.lead_id&&await d.entities.Lead.update(s.lead_id,{pipeline_stage:"Funded / Closed"}).catch(()=>{}),x.success("Install approved â deal moved to Funded / Closed"),l==null||l()}catch(t){console.error(t),x.error("Failed to approve")}finally{o(!1)}};return e.jsx(v,{children:e.jsxs(f,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"font-semibold text-gray-900 truncate",children:s.customer_name}),e.jsxs("p",{className:"text-xs text-gray-500",children:[s.equipment_brand," ",s.equipment_model]})]}),e.jsx("span",{className:"text-[10px] uppercase font-bold px-2 py-0.5 bg-purple-100 text-purple-800 border border-purple-300 rounded",children:"Awaiting Approval"})]}),e.jsxs("div",{className:"text-xs text-gray-600 space-y-1",children:[s.install_address&&e.jsxs("p",{className:"flex items-start gap-1.5",children:[e.jsx(g,{className:"w-3 h-3 mt-0.5"})," ",s.install_address,", ",s.city," ",s.state]}),s.assigned_vendor_name&&e.jsxs("p",{className:"flex items-center gap-1.5",children:[e.jsx(N,{className:"w-3 h-3"})," ",s.assigned_vendor_name]})]}),s.front_photo_url&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-gray-700 mb-1",children:"Front Photo"}),e.jsx("img",{src:s.front_photo_url,alt:"Front",className:"h-40 w-full object-cover rounded-lg border"})]}),((a=s.additional_photo_urls)==null?void 0:a.length)>0&&e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs font-semibold text-gray-700 mb-1",children:["Additional Photos (",s.additional_photo_urls.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:s.additional_photo_urls.map((t,p)=>e.jsx("a",{href:t,target:"_blank",rel:"noreferrer",children:e.jsx("img",{src:t,alt:`Extra ${p+1}`,className:"h-16 w-16 object-cover rounded border"})},p))})]}),s.install_notes&&e.jsxs("div",{className:"bg-gray-50 rounded p-2 text-xs text-gray-700",children:[e.jsx("strong",{children:"Vendor notes:"})," ",s.install_notes]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-gray-700 block mb-1",children:"Admin notes (optional)"}),e.jsx(_,{rows:2,value:r,onChange:t=>m(t.target.value),placeholder:"Internal approval notes..."})]}),e.jsx(u,{onClick:c,disabled:n,className:"w-full bg-emerald-600 hover:bg-emerald-700",children:n?e.jsxs(e.Fragment,{children:[e.jsx(h,{className:"w-4 h-4 mr-2 animate-spin"}),"Approving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(y,{className:"w-4 h-4 mr-2"}),"Approve & Close Deal"]})})]})})}function E(){const[s,l]=i.useState(!0),[r,m]=i.useState([]),[n,o]=i.useState([]),c=async()=>{l(!0);const[a,t]=await Promise.all([d.entities.InstallJob.filter({status:"Installed Awaiting Approval"},"-vendor_completed_at",100).catch(()=>[]),d.entities.InstallJob.filter({status:"Admin Approved"},"-admin_approved_at",20).catch(()=>[])]);m(a),o(t),l(!1)};return i.useEffect(()=>{c()},[]),s?e.jsx("div",{className:"flex items-center justify-center h-screen",children:e.jsx(h,{className:"w-8 h-8 animate-spin text-blue-600"})}):e.jsx("div",{className:"min-h-screen bg-gray-50 p-4 sm:p-6",children:e.jsxs("div",{className:"max-w-7xl mx-auto",children:[e.jsx(j,{}),e.jsxs("div",{className:"mb-6",children:[e.jsxs("h1",{className:"text-2xl font-bold text-gray-900 flex items-center gap-2",children:[e.jsx(w,{className:"w-6 h-6 text-emerald-600"})," Install Approval Queue"]}),e.jsx("p",{className:"text-sm text-gray-500",children:"Review vend
1or-completed installs and close the deal."})]}),e.jsxs("section",{className:"mb-8",children:[e.jsxs("h2",{className:"text-sm font-semibold uppercase text-gray-500 mb-3",children:["Pending Approval (",r.length,")"]}),r.length===0?e.jsx("p",{className:"text-sm text-gray-400 bg-white border rounded-lg p-6 text-center",children:"No installs awaiting approval."}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:r.map(a=>e.jsx(b,{job:a,onApproved:c},a.id))})]}),n.length>0&&e.jsxs("section",{children:[e.jsxs("h2",{className:"text-sm font-semibold uppercase text-gray-500 mb-3",children:["Recently Approved (",n.length,")"]}),e.jsx("div",{className:"bg-white border rounded-lg divide-y",children:n.map(a=>e.jsxs("div",{className:"px-4 py-2 flex items-center justify-between text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:a.customer_name}),e.jsxs("span",{className:"text-gray-500 ml-2",children:["â ",a.assigned_vendor_name||a.assigned_vendor_email]})]}),e.jsx("span",{className:"text-xs text-emerald-700",children:a.admin_approved_at?new Date(a.admin_approved_at).toLocaleDateString():""})]},a.id))})]})]})})}export{E 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.