import{_ as ae,r as O,c as x,o as ne,a as i,g as n,b as t,aT as ie,j as m,d as c,w as C,k as u,t as o,e as g,F as S,af as b,aR as k,i as de,aX as ue,n as me}from"./index-QAlcqU00.js";import{F as Q}from"./FPInput-D5RURom0.js";import{F as R}from"./FPCheckbox-DcRYwN3n.js";import{F as X}from"./FPSelect-j7n_x8eB.js";import{S as ce,P as ge}from"./workOrder-jNxj_kjQ.js";import{u as ve}from"./useWorkOrders-CVmaGBfy.js";const ye={class:"report-generator"},be={class:"flex items-center justify-between mb-4"},ke={class:"flex items-center space-x-2"},xe={class:"mb-6 p-4 bg-gray-50 border border-gray-200 rounded-lg"},we={class:"grid grid-cols-1 md:grid-cols-2 gap-4 mb-4"},fe={class:"grid grid-cols-1 md:grid-cols-3 gap-4 mb-4"},pe={class:"mb-4"},he={class:"grid grid-cols-2 md:grid-cols-4 gap-2"},Oe={class:"grid grid-cols-1 md:grid-cols-2 gap-4"},Ce={class:"mb-6"},Se={class:"grid grid-cols-1 md:grid-cols-3 gap-3"},Re=["onClick"],Te={class:"flex items-center mb-2"},Ve={class:"font-medium text-gray-900"},De={class:"text-xs text-gray-600"},Fe={key:0,class:"mb-6 border border-gray-200 rounded-lg overflow-hidden"},Ie={class:"p-6 bg-white max-h-96 overflow-y-auto"},Ae={class:"report-preview"},Pe={class:"mb-6 text-center border-b border-gray-200 pb-4"},Me={class:"text-2xl font-bold text-gray-900"},Ne={key:0,class:"text-gray-600 mt-1"},$e={class:"mt-2 text-sm text-gray-500"},Ue={key:0,class:"mb-6"},Be={class:"grid grid-cols-2 gap-4 text-sm"},Le={key:0,class:"mt-3"},je={class:"mt-1 text-gray-700"},He={key:1,class:"mb-6"},ze={class:"grid grid-cols-2 gap-4 text-sm"},We={key:0},Ge={class:"text-gray-600"},Ee={key:1},qe={class:"text-gray-600"},Qe={key:2,class:"mb-6"},Xe={class:"text-sm space-y-2"},Ye={key:0},Je={key:1},Ke={key:2},Ze={class:"list-disc list-inside ml-4"},_e={key:3,class:"mb-6"},et={class:"space-y-2 text-sm"},tt={class:"mr-2"},st={class:"mt-2 text-sm text-gray-600"},ot={key:4,class:"mb-6"},rt={class:"overflow-x-auto"},lt={class:"w-full text-sm"},at={class:"py-2"},nt={class:"py-2"},it={class:"text-right py-2"},dt={class:"text-right py-2"},ut={class:"text-right py-2"},mt={key:5,class:"mb-6"},ct={class:"overflow-x-auto"},gt={class:"w-full text-sm"},vt={class:"py-2"},yt={class:"py-2"},bt={class:"text-right py-2"},kt={class:"text-right py-2"},xt={class:"text-right py-2"},wt={key:6,class:"mb-6"},ft={class:"bg-gray-50 p-4 rounded"},pt={class:"grid grid-cols-2 gap-4 text-sm"},ht={class:"text-lg col-span-2 text-center border-t pt-2 mt-2"},Ot={key:7,class:"mb-6"},Ct={class:"space-y-2 text-sm"},St={class:"text-gray-600"},Rt={key:0,class:"text-gray-700 italic"},Tt={class:"text-gray-500"},Vt={class:"mt-8 pt-4 border-t border-gray-200 text-center text-xs text-gray-500"},Dt={key:1,class:"mb-4"},Ft={class:"space-y-2"},It={class:"flex items-center"},At={class:"text-sm font-medium text-gray-900"},Pt={class:"text-xs text-gray-500"},Mt={class:"flex items-center space-x-2"},Nt={__name:"ReportGenerator",props:{workOrder:{type:Object,required:!0},disabled:{type:Boolean,default:!1}},emits:["report-generated"],setup(l,{emit:$t}){const w=l,p=ve(),F=O(!1),h=O(!1),T=O([]),r=O({template:"complete",format:"pdf",title:"Work Order Report",subtitle:"Generated on {date}",includeImages:!0,includeAttachments:!1,includeSignature:!0,sections:{basic:!0,asset:!0,assignment:!0,tasks:!0,parts:!0,time:!0,costs:!0,history:!0}}),Y=[{value:"summary",title:"Summary Report"},{value:"complete",title:"Complete Report"},{value:"maintenance",title:"Maintenance Report"},{value:"cost",title:"Cost Report"},{value:"custom",title:"Custom Report"}],J=[{value:"pdf",title:"PDF Document"},{value:"html",title:"HTML Page"},{value:"excel",title:"Excel Spreadsheet"}],K=[{key:"basic",label:"Basic Info"},{key:"asset",label:"Asset & Location"},{key:"assignment",label:"Assignment"},{key:"tasks",label:"Tasks"},{key:"parts",label:"Parts"},{key:"time",label:"Time Tracking"},{key:"costs",label:"Cost Summary"},{key:"history",label:"Status History"}],Z=[{key:"maintenance",name:"Maintenance Report",description:"Focus on tasks, parts, and completion",icon:"svg",sections:{basic:!0,asset:!0,tasks:!0,parts:!0,history:!0}},{key:"cost",name:"Cost Analysis",description:"Detailed cost breakdown and labor",icon:"svg",sections:{basic:!0,parts:!0,time:!0,costs:!0}},{key:"summary",name:"Executive Summary",description:"High-level overview for management",icon:"svg",sections:{basic:!0,assignment:!0,costs:!0}}],_=x(()=>{var a;return((a=w.workOrder.tasks)==null?void 0:a.filter(e=>e.completed).length)||0}),I=x(()=>{var a;return((a=w.workOrder.timeEntries)==null?void 0:a.reduce((e,d)=>e+d.duration*(d.hourlyRate||0),0))||0}),A=x(()=>{var a;return((a=w.workOrder.parts)==null?void 0:a.reduce((e,d)=>e+d.quantity*(d.unitCost||0),0))||0}),P=x(()=>{var a,e;return((e=(a=w.workOrder.costTracking)==null?void 0:a.costs)==null?void 0:e.filter(d=>d.category==="Material").reduce((d,v)=>d+(v.amount||0),0))||0}),M=x(()=>{var a,e;return((e=(a=w.workOrder.costTracking)==null?void 0:a.costs)==null?void 0:e.filter(d=>d.category==="Labor").reduce((d,v)=>d+(v.amount||0),0))||0}),N=x(()=>{var a,e;return((e=(a=w.workOrder.costTracking)==null?void 0:a.costs)==null?void 0:e.filter(d=>d.category==="Other").reduce((d,v)=>d+(v.amount||0),0))||0}),ee=x(()=>I.value+A.value+P.value+M.value+N.value),te=async a=>{try{if(!p){console.error("Work orders composable not available");return}const e={template:r.value.template,format:r.value.format,sections:r.value.sections,title:r.value.customTitle,subtitle:r.value.customSubtitle,includeImages:r.value.includeImages,includeAttachments:r.value.includeAttachments,includeSignatures:r.value.includeSignatures},d=new Date().toISOString().slice(0,19).replace(/:/g,"-"),v=`${a.name}-${d}.${a.format}`;await p.downloadReport(a.workOrderId,e,v),console.log("Report downloaded successfully")}catch(e){throw console.error("Download failed:",e),e}},$=async a=>{try{await te(a)}catch(e){console.error("Report download error:",e)}},se=async a=>{try{if(!p){console.error("Work orders composable not available");return}const e={template:r.value.template,format:"PDF",sections:r.value.sections,title:r.value.customTitle,subtitle:r.value.customSubtitle,includeImages:r.value.includeImages,includeAttachments:r.value.includeAttachments,includeSignatures:r.value.includeSignatures};await p.previewReport(a.workOrderId,e),console.log("Report preview opened")}catch(e){console.error("Preview failed:",e)}},oe=a=>{r.value.sections={...a.sections},r.value.template=a.key},U=a=>{var e;return((e=ce[a])==null?void 0:e.label)||a},re=a=>{var e;return((e=ge[a])==null?void 0:e.label)||a},V=a=>a?new Date(a).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}):"",D=a=>a?new Date(a).toLocaleString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):"",le=a=>{if(!a)return"0:00";const e=Math.floor(a),d=Math.round((a-e)*60);return`${e}:${d.toString().padStart(2,"0")}`};return ne(()=>{T.value=[{id:1,name:"Complete Report - WO-1244",createdAt:new Date(Date.now()-864e5).toISOString(),format:"pdf"},{id:2,name:"Cost Analysis - WO-1243",createdAt:new Date(Date.now()-1728e5).toISOString(),format:"pdf"}]}),(a,e)=>{var d,v,B,L,j,H,z,W,G,E,q;return n(),i("div",ye,[t("div",be,[e[13]||(e[13]=t("div",{class:"flex items-center space-x-3"},[t("h3",{class:"text-lg font-medium text-gray-900"},"Report Generation"),t("div",{class:"px-2 py-1 bg-blue-100 text-blue-800 text-xs font-medium rounded-full"}," 🎠Demo Mode ")],-1)),t("div",ke,[c(g(S),{variant:"outline",size:"sm",onClick:e[0]||(e[0]=s=>h.value=!h.value)},{default:C(()=>[e[10]||(e[10]=t("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})],-1)),u(" "+o(h.value?"Hide Preview":"Show Preview"),1)]),_:1,__:[10]}),c(g(S),{variant:"secondary",size:"sm",onClick:e[1]||(e[1]=s=>se({workOrderId:l.workOrder.id,name:r.value.title})),loading:F.value,disabled:l.disabled},{default:C(()=>e[11]||(e[11]=[t("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})],-1),u(" Preview ",-1)])),_:1,__:[11]},8,["loading","disabled"]),c(g(S),{variant:"primary",size:"sm",onClick:e[2]||(e[2]=s=>$({workOrderId:l.workOrder.id,name:r.value.title})),loading:F.value,disabled:l.disabled},{default:C(()=>e[12]||(e[12]=[t("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})],-1),u(" Download PDF ",-1)])),_:1,__:[12]},8,["loading","disabled"])])]),e[49]||(e[49]=ie('
Demo Mode: PDF reports will be generated using sample data since no backend is connected. The generated PDFs are fully functional and can be downloaded and opened in any PDF viewer.