1import{r as p,j as e,I as k,B as h,C as E,X as Je,T as $,b as g,u as ee,n as Ze,L as es,h as ss,W as de,x as O,ab as me,i as as,a as W,e as U,f as ts,d as te}from"./app-21bd15b.js";import{u as C}from"./useMutation-QiqyDoaA.js";import{C as T,a as R,b as L,c as M}from"./card-Ds0j_ph3.js";import{B as P}from"./badge-Cx-7w76d.js";import{L as j}from"./label-Dvdwz9eU.js";import{S as B,a as q,b as H,c as Q,d as y}from"./select-2JGt060E.js";import{D as G,a as K,b as Y,c as X}from"./dialog-Dd4w7Uwn.js";import{T as is,a as rs,b as ie,c as re}from"./tabs-he0w6Hqf.js";import{t as f}from"./index-DaBZ-6EK.js";import{T as pe}from"./triangle-alert-B0AOK7DH.js";import{C as ns}from"./camera-CbGSnfhq.js";import{D as he}from"./DVIViewer-Co32Dnzk.js";import{C as J}from"./clock-DMz2uqKZ.js";import{C as ls}from"./circle-alert-DZMvMefy.js";import{f as os}from"./format-DNwwlEmA.js";import{C as Z}from"./circle-check-big-DKY6ALt1.js";import{D as cs}from"./dollar-sign-Ch5b25dj.js";import{P as ne}from"./package-DoSFEGvl.js";import{P as ue}from"./plus-CzpE0IOQ.js";import{r as ds}from"./ServiceTabsBar-nnPoKAx2.js";import{c as ms,b as ps}from"./index-BnvPF5iF.js";import{R as hs,c as xe,P as us,W as xs,C as js,b as vs,D as gs,a as je,O as fs,T as Ns}from"./index-DldW0TNm.js";import{A as bs}from"./arrow-left-CJ8Wlslf.js";import{F as _s}from"./file-text-CSP-SbwO.js";import{S as ys}from"./square-pen-Dd3vSe5M.js";import{T as Ss}from"./trash-2-C7C2yBDo.js";import{S as Cs}from"./save-BnKQXv5Z.js";import"./index-BdQq_4o_.js";import"./index-DCXHIrWX.js";import"./Combination-V874_T0s.js";import"./index-CIGkH_3_.js";import"./index-CFdLmJ9e.js";import"./index-C1tL7dmQ.js";import"./index-BdklNUBx.js";import"./index-CGPW-Lqh.js";import"./index-DrSPxx2l.js";import"./zoom-in-Bw-AZi5y.js";import"./en-US-wfBU2YNu.js";import"./dropdown-menu-DPKGy-_2.js";import"./chevron-right-DE7dblQK.js";import"./VINDisplay-DvLcW24r.js";import"./copy-M9xHNozu.js";import"./user-BI__STKR.js";const le=[{name:"Battery System",items:["Battery Health","Battery Degradation","Charging System","Charging Port Condition","High Voltage System"]},{name:"Drivetrain",items:["Electric Motor","Inverter","Coolant Level","Drive Axles"]},{name:"Brakes",items:["Front Brake Pads","Rear Brake Pads","Brake Fluid","Brake Lines"]},{name:"Tires & Suspension",items:["Front Left Tire","Front Right Tire","Rear Left Tire","Rear Right Tire","Suspension"]},{name:"Safety",items:["Lights","Wipers","Horn","Seat Belts","Airbags"]}];function oe({vehicleId:i,roId:s,existingInspection:t,onComplete:l}){const[r,m]=p.useState({vehicle_id:i,ro_id:s,inspection_type:"pre_service",overall_condition:"good",inspection_points:le.flatMap(d=>d.items.map(N=>({category:d.name,item:N,status:"pass",notes:"",photo_urls:[]}))),ev_specific_checks:{battery_health_percentage:"",estimated_range:"",software_version:"",diagnostic_codes:[]}}),[u,b]=p.useState(!1),x=(d,N,a)=>{const c=[...r.inspection_points];c[d]={...c[d],[N]:a},m({...r,inspection_points:c})},_=async(d,N)=>{b(!0);try{const{file_url:a}=await g.integrations.Core.UploadFile({file:N}),c=[...r.inspection_points];c[d].photo_urls=[...c[d].photo_urls||[],a],m({...r,inspection_points:c}),f.success("Photo uploaded")}catch{f.error("Failed to upload photo")}finally{b(!1)}},S=async()=>{try{const d=await g.auth.me(),N={...r,inspector_id:d.email,inspection_date:new Date().toISOString(),safety_concerns:r.inspection_points.some(a=>a.status==="fail"),immediate_attention_needed:r.inspection_points.some(a=>a.status==="fail")};t?await g.entities.VehicleInspection.update(t.id,N):await g.entities.VehicleInspection.create(N),f.success("Inspection saved"),l==null||l()}catch{f.error("Failed to save inspection")}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx(j,{children:"Inspection Type"}),e.jsxs(B,{value:r.inspection_type,onValueChange:d=>m({...r,inspection_type:d}),children:[e.jsx(q,{children:e.jsx(H,{})}),e.jsxs(Q,{children:[e.jsx(y,{value:"pre_service",children:"Pre-Service"}),e.jsx(y,{value:"multi_point",children:"Multi-Point"}),e.jsx(y,{value:"ev_health_check",children:"EV Health Check"})]})]})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Overall Condition"}),e.jsxs(B,{value:r.overall_condition,onValueChange:d=>m({...r,overall_condition:d}),children:[e.jsx(q,{children:e.jsx(H,{})}),e.jsxs(Q,{children:[e.jsx(y,{value:"excellent",children:"Excellent"}),e.jsx(y,{value:"good",children:"Good"}),e.jsx(y,{value:"fair",children:"Fair"}),e.jsx(y,{value:"poor",children:"Poor"})]})]})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Odometer Reading"}),e.jsx(k,{type:"number",value:r.odometer_reading||"",onChange:d=>m({...r,odometer_reading:parseInt(d.target.value)})})]})]}),e.jsx(T,{children:e.jsxs(R,{className:"pt-6",children:[e.jsx("h3",{className:"font-semibold mb-4",children:"EV-Specific Checks"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(j,{children:"Battery Health %"}),e.jsx(k,{type:"number",value:r.ev_specific_checks.battery_health_percentage||"",onChange:d=>m({...r,ev_specific_checks:{...r.ev_specific_checks,battery_health_percentage:parseFloat(d.target.value)}})})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Estimated Range (mi)"}),e.jsx(k,{type:"number",value:r.ev_specific_checks.estimated_range||"",onChange:d=>m({...r,ev_specific_checks:{...r.ev_specific_checks,estimated_range:parseFloat(d.target.value)}})})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Software Version"}),e.jsx(k,{value:r.ev_specific_checks.software_version||"",onChange:d=>
1m({...r,ev_specific_checks:{...r.ev_specific_checks,software_version:d.target.value}})})]})]})]})}),le.map((d,N)=>e.jsx(T,{children:e.jsxs(R,{className:"pt-6",children:[e.jsx("h3",{className:"font-semibold mb-4",children:d.name}),e.jsx("div",{className:"space-y-4",children:r.inspection_points.map((a,c)=>({point:a,idx:c})).filter(({point:a})=>a.category===d.name).map(({point:a,idx:c})=>{var n;return e.jsxs("div",{className:"border rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx(j,{children:a.item}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(h,{size:"sm",variant:a.status==="pass"?"default":"outline",onClick:()=>x(c,"status","pass"),className:"h-8",children:[e.jsx(E,{className:"w-4 h-4 mr-1"}),"Pass"]}),e.jsxs(h,{size:"sm",variant:a.status==="attention_needed"?"default":"outline",onClick:()=>x(c,"status","attention_needed"),className:"h-8",children:[e.jsx(pe,{className:"w-4 h-4 mr-1"}),"Attention"]}),e.jsxs(h,{size:"sm",variant:a.status==="fail"?"destructive":"outline",onClick:()=>x(c,"status","fail"),className:"h-8",children:[e.jsx(Je,{className:"w-4 h-4 mr-1"}),"Fail"]})]})]}),e.jsx($,{placeholder:"Notes...",value:a.notes||"",onChange:F=>x(c,"notes",F.target.value),className:"mb-2"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(j,{className:"cursor-pointer",children:[e.jsx(k,{type:"file",accept:"image/*",className:"hidden",onChange:F=>F.target.files[0]&&_(c,F.target.files[0]),disabled:u}),e.jsxs(h,{size:"sm",variant:"outline",disabled:u,type:"button",children:[e.jsx(ns,{className:"w-4 h-4 mr-2"}),"Add Photo"]})]}),((n=a.photo_urls)==null?void 0:n.length)>0&&e.jsxs(P,{variant:"secondary",children:[a.photo_urls.length," photos"]})]})]},c)})})]})},N)),e.jsx(h,{onClick:S,className:"w-full",size:"lg",children:"Save Inspection"})]})}const ce=[{key:"open",label:"Opened",icon:J},{key:"in_progress",label:"In Progress",icon:J},{key:"pending_approval",label:"Pending Approval",icon:ls},{key:"approved",label:"Approved",icon:E},{key:"completed",label:"Completed",icon:E},{key:"invoiced",label:"Invoiced",icon:E},{key:"paid",label:"Paid",icon:E}];function ws({ro:i}){const s=ce.findIndex(t=>t.key===i.status);return e.jsxs(T,{children:[e.jsx(L,{children:e.jsx(M,{children:"Status Timeline"})}),e.jsx(R,{children:e.jsx("div",{className:"space-y-4",children:ce.map((t,l)=>{const r=t.icon,m=l<s,u=l===s,b=l>s;return e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:`w-8 h-8 rounded-full flex items-center justify-center ${m?"bg-green-100":u?"bg-blue-100":"bg-slate-100"}`,children:e.jsx(r,{className:`w-4 h-4 ${m?"text-green-600":u?"text-blue-600":"text-slate-400"}`})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:`font-medium ${b?"text-slate-400":""}`,children:t.label}),u&&i.updated_date&&e.jsx("p",{className:"text-xs text-slate-500",children:os(new Date(i.updated_date),"PPp")})]}),u&&e.jsx(P,{children:"Current"}),m&&e.jsx(E,{className:"w-4 h-4 text-green-600"})]},t.key)})})})]})}function Ds({open:i,onOpenChange:s,ro:t,inspection:l}){var N;const r=ee(),[m,u]=p.useState(""),[b,x]=p.useState(!1),_=C({mutationFn:({id:a,data:c})=>g.entities.RepairOrder.update(a,c),onSuccess:()=>{r.invalidateQueries(["repair-order"]),f.success("Customer notified"),s(!1)}}),S=C({mutationFn:({id:a,data:c})=>g.entities.VehicleInspection.update(a,c),onSuccess:()=>{r.invalidateQueries(["vehicle-inspection"])}}),d=async()=>{var a,c;x(!0);try{l&&await S.mutateAsync({id:l.id,data:{shared_with_customer:!0,shared_at:new Date().toISOString()}}),await _.mutateAsync({id:t.id,data:{status:"pending_approval"}});const n=await g.entities.Customer.filter({id:t.customer_id});(a=n[0])!=null&&a.email&&await g.integrations.Core.SendEmail({to:n[0].email,subject:`Service Approval Needed - RO #${t.ro_number||t.id.slice(0,8)}`,body:`Hello, 2 3Your vehicle inspection is complete. Please review and approve the recommended services. 4 5${m} 6 7Estimated Total: $${((c=t.total_cost)==null?void 0:c.toLocaleString())||"0.00"} 8 9View full details and approve in your customer portal. 10 11Best regards, 12Platt Auto Service Team`}),f.success("Approval request sent to customer"),s(!1)}catch{f.error("Failed to send approval request")}finally{x(!1)}};return e.jsx(G,{open:i,onOpenChange:s,children:e.jsxs(K,{className:"max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsx(Y,{children:e.jsx(X,{children:"Send for Customer Approval"})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"p-4 bg-slate-50 rounded-lg",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("span",{className:"font-semibold",children:["RO #",t.ro_number||t.id.slice(0,8)]}),e.jsx(P,{children:t.status})]}),e.jsx("p",{className:"text-sm text-slate-600 mb-3",children:t.diagnosis}),e.jsxs("div",{className:"flex items-center justify-between pt-3 border-t",children:[e.jsx("span",{className:"font-medium",children:"Estimated Total"}),e.jsxs("span",{className:"text-xl font-bold",children:["$",((N=t.total_cost)==null?void 0:N.toLocaleStr
12ing())||"0.00"]})]})]}),l&&e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold mb-3",children:"Inspection Report Preview"}),e.jsx("div",{className:"border rounded-lg p-4 max-h-96 overflow-y-auto",children:e.jsx(he,{inspection:l,customerView:!0})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-2",children:"Message to Customer"}),e.jsx($,{value:m,onChange:a=>u(a.target.value),placeholder:"Add a personal message explaining the recommended services...",rows:4})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs(h,{onClick:d,disabled:b,className:"flex-1",children:[e.jsx(Ze,{className:"w-4 h-4 mr-2"}),b?"Sending...":"Send for Approval"]}),e.jsx(h,{variant:"outline",onClick:()=>s(!1),children:"Cancel"})]})]})]})})}function As({ro:i,tasks:s,inspection:t}){const l=ee(),r=C({mutationFn:({id:_,data:S})=>g.entities.RepairOrder.update(_,S),onSuccess:()=>{l.invalidateQueries(["repair-order"]),f.success("Status updated")}}),m=()=>{r.mutate({id:i.id,data:{status:"in_progress",started_at:new Date().toISOString()}})},u=()=>{r.mutate({id:i.id,data:{status:"completed",completed_at:new Date().toISOString()}})},b=()=>{r.mutate({id:i.id,data:{status:"invoiced"}})},x=s.length>0&&s.every(_=>_.status==="completed");return e.jsx(T,{className:"border-2 border-blue-200 bg-blue-50",children:e.jsx(R,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold mb-1",children:"Next Action"}),e.jsxs("p",{className:"text-sm text-slate-600",children:[i.status==="open"&&"Ready to start work",i.status==="in_progress"&&"Work in progress",i.status==="pending_approval"&&"Waiting for customer approval",i.status==="approved"&&"Customer approved - complete work",i.status==="completed"&&"Ready to invoice"]})]}),e.jsxs("div",{children:[i.status==="open"&&e.jsxs(h,{onClick:m,className:"bg-blue-600 hover:bg-blue-700",children:[e.jsx(J,{className:"w-4 h-4 mr-2"}),"Start Work"]}),i.status==="in_progress"&&x&&e.jsxs(h,{onClick:u,className:"bg-green-600 hover:bg-green-700",children:[e.jsx(Z,{className:"w-4 h-4 mr-2"}),"Mark Complete"]}),i.status==="approved"&&x&&e.jsxs(h,{onClick:u,className:"bg-green-600 hover:bg-green-700",children:[e.jsx(Z,{className:"w-4 h-4 mr-2"}),"Complete Work"]}),i.status==="completed"&&e.jsxs(h,{onClick:b,className:"bg-purple-600 hover:bg-purple-700",children:[e.jsx(cs,{className:"w-4 h-4 mr-2"}),"Create Invoice"]})]})]})})})}function ks({vehicleId:i,roId:s,onPartAdded:t}){const[l,r]=p.useState(""),[m,u]=p.useState([]),[b,x]=p.useState(!1),_=C({mutationFn:async a=>(await g.functions.invoke("worldpacGetProductQuotes",a)).data,onSuccess:a=>{var c;u(a.results||[]),x(!1),((c=a.results)==null?void 0:c.length)===0?f.info("No parts found"):f.success(`Found ${a.results.length} parts`)},onError:a=>{x(!1),f.error("Search failed: "+a.message)}}),S=C({mutationFn:async({partNumber:a,quantity:c})=>(await g.functions.invoke("worldpacCreateOrder",{partNumber:a,quantity:c,roId:s,vehicleId:i})).data,onSuccess:a=>{f.success("Part ordered successfully"),t&&t()},onError:a=>{f.error("Order failed: "+a.message)}}),d=()=>{if(!l.trim()){f.error("Please enter a search term");return}x(!0),_.mutate({searchTerm:l.trim(),vehicleId:i})},N=a=>{confirm(`Order ${a.part_name} (${a.part_number})? 13Price: $${a.price}`)&&S.mutate({partNumber:a.part_number,quantity:1})};return e.jsxs(T,{children:[e.jsx(L,{children:e.jsxs(M,{className:"flex items-center gap-2",children:[e.jsx(ne,{className:"w-5 h-5"}),"Parts Catalog Search"]})}),e.jsxs(R,{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"flex-1",children:e.jsx(k,{placeholder:"Search for parts...",value:l,onChange:a=>r(a.target.value),onKeyPress:a=>a.key==="Enter"&&d()})}),e.jsx(h,{onClick:d,disabled:b,children:b?e.jsx(es,{className:"w-4 h-4 animate-spin"}):e.jsx(ss,{className:"w-4 h-4"})})]}),m.length>0&&e.jsx("div",{className:"space-y-2 max-h-96 overflow-y-auto",children:m.map((a,c)=>{var n;return e.jsx("div",{className:"border rounded-lg p-4 hover:bg-slate-50",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("h4",{className:"font-medium",children:a.part_name}),a.fitment_verified&&e.jsxs(P,{variant:"outline",className:"text-xs",children:[e.jsx(Z,{className:"w-3 h-3 mr-1"}),"Verified Fit"]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm text-slate-600",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Part #:"})," ",a.part_number]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Brand:"})," ",a.brand]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Price:"})," $",(n=a.price)==null?void 0:n.toFixed(2)]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Availability:"})," ",e.jsx(P,{className:a.availability==="in_stock"?"bg-green-100 text-green-700":"bg-orange-100 text-orange-700",children:a.availability})]}),a.quantity_available&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Qty:"})," ",a.quantity_available]}),a.estimated_delivery&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Delivery:"})," ",a.estimated_delivery]})]})]}),e.jsxs(h,{size:"sm",onClick:()=>N(a),disabled:S.isLoading,children:[e.jsx(ue,{className:"w-4 h-4 mr-1"}),"Order"]})]})},c)})}),!b&&m.length===0&&e.jsxs("div",{className:"text-center py-8 text-slate-500",children:[e.jsx(ne,{className:"w-12 h-12 mx-auto mb-2 text-slate-300"}),e.jsx("p",{children:"Search for parts using the search bar above"})]})]})]})}var Ts=Symbol("radix.slottable");function Rs(i){const s=({children:t})=>e.jsx(e.Fragment,{children:t});return s.displayName=`${i}.Slottable`,s.__radixId=Ts,s}var ve="AlertDialog",[Ps]=ps(ve,[xe]),w=xe(),ge=i=>{const{__scopeAlertDialog:s,...t}=i,l=w(s);return e.jsx(hs,{...l,...t,modal:!0})};ge.displayName=ve;var Os="AlertDialogTrigger",Is=p.forwardRef((i,s)=>{const{__scopeAlertDialog:t,...l}=i,r=w(t);return e.jsx(Ns,{...r,...l,ref:s})});Is.displayName=Os;var Fs="AlertDialogPortal",fe=i=>{const{__scopeAlertDialog:s,...t}=i,l=w(s);return e.jsx(us,{...l,...t})};fe.displayName=Fs;var Es="AlertDialogOverlay",Ne=p.forwardRef((i,s)=>{const{__scopeAlertDialog:t,...l}=i,r=w(t);return e.jsx(fs,{...r,...l,ref:s})});Ne.displayName=Es;var V="AlertDialogContent",[Vs,$s]=Ps(V),Ls=Rs("AlertDialogContent"),be=p.forwardRef((i,s)=>{const{__scopeAlertDialog:t,children:l,...r}=i,m=w(t),u=p.useRef(null),b=de(s,u),x=p.useRef(null);return e.jsx(xs,{contentName:V,titleName:_e,docsSlug:"alert-dialog",children:e.jsx(Vs,{scope:t,cancelRef:x,children:e.jsxs(js,{role:"alertdialog",...m,...r,ref:b,onOpenAutoFocus:ms(r.onOpenAutoFocus,_=>{var S;_.preventDefault(),(S=x.current)==null||S.focus({preventScroll:!0})}),onPointerDownOutside:_=>_.preventDefault(),onInteractOutside:_=>_.preventDefault(),children:[e.jsx(Ls,{children:l}),e.jsx(Bs,{contentRef:u})]})})})});be.displayName=V;var _e="AlertDialogTitle",ye=p.forwardRef((i,s)=>{const{__scopeAlertDialog:t,...l}=i,r=w(t);return e.jsx(vs,{...r,...l,ref:s})});ye.displayName=_e;var Se="AlertDialogDescription",Ce=p.forwardRef((i,s)=>{const{__scopeAlertDialog:t,...l}=i,r=w(t);return e.jsx(gs,{...r,...l,ref:s})});Ce.displayName=Se;var Ms="AlertDialogAction",we=p.forwardRef((i,s)=>{const{__scopeAlertDialog:t,...l}=i,r=w(t);return e.jsx(je,{...r,...l,ref:s})});
13we.displayName=Ms;var De="AlertDialogCancel",Ae=p.forwardRef((i,s)=>{const{__scopeAlertDialog:t,...l}=i,{cancelRef:r}=$s(De,t),m=w(t),u=de(s,r);return e.jsx(je,{...m,...l,ref:u})});Ae.displayName=De;var Bs=({contentRef:i})=>{const s=`\`${V}\` requires a description for the component to be accessible for screen reader users. 14 15You can add a description to the \`${V}\` by passing a \`${Se}\` component as a child, which also benefits sighted users by adding visible context to the dialog. 16 17Alternatively, you can use your own component as a description by assigning it an \`id\` and passing the same value to the \`aria-describedby\` prop in \`${V}\`. If the description is confusing or duplicative for sighted users, you can use the \`@radix-ui/react-visually-hidden\` primitive as a wrapper around your description component. 18 19For more information, see https://radix-ui.com/primitives/docs/components/alert-dialog`;return p.useEffect(()=>{var l;document.getElementById((l=i.current)==null?void 0:l.getAttribute("aria-describedby"))||console.warn(s)},[s,i]),null},qs=ge,Hs=fe,ke=Ne,Te=be,Re=we,Pe=Ae,Oe=ye,Ie=Ce;const Qs=qs,zs=Hs,Fe=p.forwardRef(({className:i,...s},t)=>e.jsx(ke,{className:O("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",i),...s,ref:t}));Fe.displayName=ke.displayName;const Ee=p.forwardRef(({className:i,...s},t)=>e.jsxs(zs,{children:[e.jsx(Fe,{}),e.jsx(Te,{ref:t,className:O("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",i),...s})]}));Ee.displayName=Te.displayName;const Ve=({className:i,...s})=>e.jsx("div",{className:O("flex flex-col space-y-2 text-center sm:text-left",i),...s});Ve.displayName="AlertDialogHeader";const $e=({className:i,...s})=>e.jsx("div",{className:O("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",i),...s});$e.displayName="AlertDialogFooter";const Le=p.forwardRef(({className:i,...s},t)=>e.jsx(Oe,{ref:t,className:O("text-lg font-semibold",i),...s}));Le.displayName=Oe.displayName;const Me=p.forwardRef(({className:i,...s},t)=>e.jsx(Ie,{ref:t,className:O("text-sm text-muted-foreground",i),...s}));Me.displayName=Ie.displayName;const Be=p.forwardRef(({className:i,...s},t)=>e.jsx(Re,{ref:t,className:O(me(),i),...s}));Be.displayName=Re.displayName;const qe=p.forwardRef(({className:i,...s},t)=>e.jsx(Pe,{ref:t,className:O(me({variant:"outline"}),"mt-2 sm:mt-0",i),...s}));qe.displayName=Pe.displayName;function Fa(){var ae;const[i]=as(),s=i.get("id"),t=ee(),[l,r]=p.useState(!1),[m,u]=p.useState(!1),[b,x]=p.useState(!1),[_,S]=p.useState(!1),[d,N]=p.useState(!1),[a,c]=p.useState({}),{data:n,isLoading:F}=W({queryKey:["repair-order",s],queryFn:()=>g.entities.RepairOrder.filter({id:s}),select:o=>o[0],enabled:!!s}),{data:D=[]}=W({queryKey:["service-tasks",s],queryFn:()=>g.entities.ServiceTask.filter({ro_id:s}),enabled:!!s}),{data:A}=W({queryKey:["vehicle-inspection",n==null?void 0:n.dvi_id],queryFn:()=>g.entities.VehicleInspection.filter({id:n.dvi_id}),select:o=>o[0],enabled:!!(n!=null&&n.dvi_id)}),He=C({mutationFn:({id:o,data:v})=>g.entities.RepairOrder.update(o,v),onSuccess:()=>{t.invalidateQueries(["repair-order",s]),f.success("Repair order updated"),u(!1)}}),Qe=C({mutationFn:({id:o,data:v})=>g.entities.ServiceTask.update(o,v),onSuccess:()=>{t.invalidateQueries(["service-tasks",s]),f.success("Task updated")}}),ze=C({mutationFn:async()=>{for(const o of D)await g.entities.ServiceTask.delete(o.id);await g.entities.RepairOrder.delete(s)},onSuccess:()=>{ds(s),t.invalidateQueries(["repair-orders"]),f.success("Repair order deleted"),window.location.href=U("ShopDashboard")},onError:o=>{f.error("Failed to delete: "+o.message)}}),We=C({mutationFn:o=>g.entities.ServiceTask.create(o),onSuccess:()=>{t.invalidateQueries(["service-tasks",s]),r(!1),f.success("Task added")}});ts.useEffect(()=>{n&&c(n)},[n]);const Ue=()=>{He.mutate({id:s,data:a})},Ge=o=>{o.preventDefault();const v=o.target,I={ro_id:s,task_name:v.task_name.value,description:v.description.value,task_type:v.task_type.value,labor_hours:parseFloat(v.labor_hours.value)||0};We.mutate(I)},se=(o,v)=>{const I=new Date().toISOString(),z={status:v};v==="in_progress"&&!D.find(Xe=>Xe.id===o).started_at&&(z.started_at=I),v==="completed"&&(z.completed_at=I),Qe.mutate({id:o,data:z})};if(F)return e.jsx("div",{className:"p-6",children:"Loading..."});if(!n)return e.jsxs("div",{className:"p-6",children:[e.jsx("p",{children:"Repair order not found"}
19),e.jsx(te,{to:U("ShopDashboard"),children:e.jsx(h,{className:"mt-4",children:"Back to Dashboard"})})]});const Ke=D.reduce((o,v)=>o+(v.labor_hours||0),0),Ye=D.reduce((o,v)=>{var I;return o+(((I=v.parts_used)==null?void 0:I.length)||0)},0);return e.jsxs("div",{className:"min-h-screen bg-slate-50 p-6",children:[e.jsxs("div",{className:"max-w-7xl mx-auto 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(te,{to:U("ShopDashboard"),children:e.jsx(h,{variant:"ghost",size:"icon",children:e.jsx(bs,{className:"w-5 h-5"})})}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold",children:["RO #",n.ro_number||n.id.slice(0,8)]}),e.jsx("p",{className:"text-slate-600",children:n.customer_concern})]})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs(h,{variant:"outline",onClick:()=>x(!0),children:[e.jsx(_s,{className:"w-4 h-4 mr-2"}),A?"View":"Create"," DVI"]}),n.status==="in_progress"&&A&&e.jsx(h,{onClick:()=>S(!0),className:"bg-blue-600 hover:bg-blue-700",children:"Send for Approval"}),e.jsxs(h,{onClick:()=>u(!m),children:[e.jsx(ys,{className:"w-4 h-4 mr-2"}),m?"Cancel Edit":"Edit RO"]}),e.jsxs(h,{variant:"destructive",onClick:()=>N(!0),children:[e.jsx(Ss,{className:"w-4 h-4 mr-2"}),"Delete"]})]})]}),e.jsx(As,{ro:n,tasks:D,inspection:A}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"lg:col-span-2 space-y-6",children:[e.jsxs(T,{children:[e.jsx(L,{children:e.jsx(M,{children:"Repair Order Details"})}),e.jsx(R,{className:"space-y-4",children:m?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx(j,{children:"Status"}),e.jsxs(B,{value:a.status,onValueChange:o=>c({...a,status:o}),children:[e.jsx(q,{children:e.jsx(H,{})}),e.jsxs(Q,{children:[e.jsx(y,{value:"open",children:"Open"}),e.jsx(y,{value:"in_progress",children:"In Progress"}),e.jsx(y,{value:"pending_approval",children:"Pending Approval"}),e.jsx(y,{value:"completed",children:"Completed"})]})]})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Customer Concern"}),e.jsx($,{value:a.customer_concern||"",onChange:o=>c({...a,customer_concern:o.target.value})})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Diagnosis"}),e.jsx($,{value:a.diagnosis||"",onChange:o=>c({...a,diagnosis:o.target.value})})]}),e.jsxs(h,{onClick:Ue,children:[e.jsx(Cs,{className:"w-4 h-4 mr-2"}),"Save Changes"]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(j,{className:"text-slate-500",children:"Status"}),e.jsx(P,{className:"mt-1",children:n.status})]}),e.jsxs("div",{children:[e.jsx(j,{className:"text-slate-500",children:"Priority"}),e.jsx(P,{className:"mt-1",children:n.priority})]}),e.jsxs("div",{children:[e.jsx(j,{className:"text-slate-500",children:"Vehicle ID"}),e.jsx("p",{className:"text-sm",children:n.vehicle_id})]}),e.jsxs("div",{children:[e.jsx(j,{className:"text-slate-500",children:"Customer ID"}),e.jsx("p",{className:"text-sm",children:n.customer_id})]})]}),e.jsxs("div",{children:[e.jsx(j,{className:"text-slate-500",children:"Customer Concern"}),e.jsx("p",{className:"text-sm mt-1",children:n.customer_concern||"None"})]}),n.diagnosis&&e.jsxs("div",{children:[e.jsx(j,{className:"text-slate-500",children:"Diagnosis"}),e.jsx("p",{className:"text-sm mt-1",children:n.diagnosis})]})]})})]}),e.jsx(ks,{vehicleId:n.vehicle_id,roId:s,onPartAdded:()=>t.invalidateQueries(["service-tasks",s])}),e.jsxs(T,{children:[e.jsx(L,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(M,{children:"Service Tasks"}),e.jsxs(h,{onClick:()=>r(!0),children:[e.jsx(ue,{className:"w-4 h-4 mr-2"}),"Add Task"]})]})}),e.jsx(R,{children:D.length===0?e.jsx("p",{className:"text-center text-slate-500 py-8",children:"No tasks yet"}):e.jsx("div",{className:"space-y-3",children:D.map(o=>{var v;return e.jsxs("div",{className:"border rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium",children:o.task_name}),e.jsx("p",{className:"text-sm text-slate-600",children:o.description})]}),e.jsx(P,{children:o.status})]}),e.jsxs("div",{className:"flex items-center gap-4 text-sm text-slate-600",children:[e.jsxs("span",{children:[o.labor_hours||0,"h labor"]}
19),e.jsxs("span",{children:[((v=o.parts_used)==null?void 0:v.length)||0," parts"]})]}),e.jsxs("div",{className:"flex gap-2 mt-3",children:[o.status==="pending"&&e.jsx(h,{size:"sm",onClick:()=>se(o.id,"in_progress"),children:"Start"}),o.status==="in_progress"&&e.jsx(h,{size:"sm",onClick:()=>se(o.id,"completed"),children:"Complete"})]})]},o.id)})})})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs(T,{children:[e.jsx(L,{children:e.jsx(M,{children:"Summary"})}),e.jsxs(R,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-slate-600",children:"Labor Hours"}),e.jsxs("span",{className:"font-semibold",children:[Ke.toFixed(1),"h"]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-slate-600",children:"Parts Used"}),e.jsx("span",{className:"font-semibold",children:Ye})]}),e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[e.jsx("span",{className:"font-medium",children:"Total Cost"}),e.jsxs("span",{className:"text-xl font-bold",children:["$",((ae=n.total_cost)==null?void 0:ae.toLocaleString())||"0.00"]})]})]})]}),e.jsx(ws,{ro:n})]})]})]}),e.jsx(G,{open:l,onOpenChange:r,children:e.jsxs(K,{children:[e.jsx(Y,{children:e.jsx(X,{children:"Add Service Task"})}),e.jsxs("form",{onSubmit:Ge,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(j,{children:"Task Name"}),e.jsx(k,{name:"task_name",required:!0})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Description"}),e.jsx($,{name:"description"})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Task Type"}),e.jsxs(B,{name:"task_type",defaultValue:"repair",children:[e.jsx(q,{children:e.jsx(H,{})}),e.jsxs(Q,{children:[e.jsx(y,{value:"diagnostic",children:"Diagnostic"}),e.jsx(y,{value:"repair",children:"Repair"}),e.jsx(y,{value:"replacement",children:"Replacement"}),e.jsx(y,{value:"maintenance",children:"Maintenance"})]})]})]}),e.jsxs("div",{children:[e.jsx(j,{children:"Labor Hours"}),e.jsx(k,{name:"labor_hours",type:"number",step:"0.5",defaultValue:"1"})]}),e.jsx(h,{type:"submit",children:"Add Task"})]})]})}),e.jsx(G,{open:b,onOpenChange:x,children:e.jsxs(K,{className:"max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsx(Y,{children:e.jsx(X,{children:"Digital Vehicle Inspection"})}),A?e.jsxs(is,{defaultValue:"view",children:[e.jsxs(rs,{children:[e.jsx(ie,{value:"view",children:"View Report"}),e.jsx(ie,{value:"edit",children:"Edit"})]}),e.jsx(re,{value:"view",children:e.jsx(he,{inspection:A})}),e.jsx(re,{value:"edit",children:e.jsx(oe,{vehicleId:n.vehicle_id,roId:s,existingInspection:A,onComplete:()=>{t.invalidateQueries(["vehicle-inspection"]),x(!1)}})})]}):e.jsx(oe,{vehicleId:n.vehicle_id,roId:s,existingInspection:A,onComplete:()=>{t.invalidateQueries(["vehicle-inspection"]),x(!1)}})]})}),e.jsx(Ds,{open:_,onOpenChange:S,ro:n,inspection:A}),e.jsx(Qs,{open:d,onOpenChange:N,children:e.jsxs(Ee,{children:[e.jsxs(Ve,{children:[e.jsxs(Le,{className:"flex items-center gap-2",children:[e.jsx(pe,{className:"w-5 h-5 text-red-500"}),"Delete Repair Order"]}),e.jsxs(Me,{children:["Are you sure you want to delete RO #",(n==null?void 0:n.ro_number)||(n==null?void 0:n.id.slice(0,8)),"? This will also delete ",D.length," associated task(s). This action cannot be undone."]})]}),e.jsxs($e,{children:[e.jsx(qe,{children:"Cancel"}),e.jsx(Be,{onClick:()=>ze.mutate(),className:"bg-red-600 hover:bg-red-700",children:"Delete"})]})]})})]})}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.