bettertend/frontend/dist/assets/PreventiveMaintenanceDetail...

2 lines
25 KiB
JavaScript

import{r as _,c as se,s as De,o as ke,m as _e,i as ae,w as u,l as be,v as Ce,g as y,a as x,j as M,d as c,b as e,e as o,k as g,t as l,F as D,af as le,aQ as ie}from"./index-BUdRbiwj.js";import{u as Me,a as Se}from"./usePreventiveMaintenanceDisplay-Bhncwa9c.js";import{u as Ve,a as Ee}from"./usePreventiveMaintenanceOperations-LTA5pnar.js";import{F as Pe,a as Ie}from"./FPPageHeader-CTG2L28r.js";import{F as J}from"./FPInput-CzR_dWoe.js";import{F as oe}from"./FPModal-DWGF1LV8.js";import{F as ne}from"./FPBadge-BKY5dPnL.js";function Ae(){const re=_(new Date),z=_("month"),N=i=>!i||!Array.isArray(i)?[]:i.map(a=>({id:`pm-${a.id}`,title:a.name,start:new Date(a.nextDue),end:new Date(new Date(a.nextDue).getTime()+(a.estimatedDuration||30)*6e4),backgroundColor:A(a.priority),borderColor:A(a.priority,!0),textColor:"#FFFFFF",extendedProps:{type:"preventive-maintenance",scheduleId:a.id,assetId:a.assetId,assetName:a.assetName,priority:a.priority,status:a.status,frequency:a.frequency,estimatedDuration:a.estimatedDuration,instructions:a.instructions,description:a.description}})),A=(i,a=!1)=>{const v={LOW:a?"#059669":"#10B981",MEDIUM:a?"#2563EB":"#3B82F6",HIGH:a?"#D97706":"#F59E0B",CRITICAL:a?"#DC2626":"#EF4444"};return v[i]||v.MEDIUM},U=(i="month")=>({...{initialView:`${i}View`,headerToolbar:{left:"prev,next today",center:"title",right:"dayGridMonth,timeGridWeek,timeGridDay"},height:"auto",nowIndicator:!0,editable:!0,droppable:!0,eventResizable:!0,eventDurationEditable:!0,eventStartEditable:!0,slotMinTime:"06:00:00",slotMaxTime:"22:00:00",slotDuration:"00:30:00",scrollTime:"08:00:00",businessHours:{daysOfWeek:[1,2,3,4,5],startTime:"08:00",endTime:"17:00"}},...{month:{dayMaxEvents:3,moreLinkClick:"popover",eventDisplay:"block"},week:{allDaySlot:!1,eventMinHeight:15},day:{allDaySlot:!1,eventMinHeight:20}}[i]}),G=(i,a)=>{if(!i||!a)return[];const v=new Date(a.start),f=new Date(a.end);return i.filter(r=>{var p,k;if(r.id===a.id||((p=r.extendedProps)==null?void 0:p.assetId)!==((k=a.extendedProps)==null?void 0:k.assetId))return!1;const h=new Date(r.start),m=new Date(r.end);return v<m&&f>h})},Y=(i,a=60,v=[],f={})=>{const{startHour:r=8,endHour:h=17,slotInterval:m=30,bufferTime:p=15}=f,k=[],s=new Date(i);for(let w=r;w<h;w++)for(let S=0;S<60;S+=m){const V=new Date(s);V.setHours(w,S,0,0);const P=new Date(V.getTime()+a*6e4);if(P.getHours()>h)continue;v.some(I=>{const F=new Date(I.start),O=new Date(I.end),W=new Date(F.getTime()-p*6e4),q=new Date(O.getTime()+p*6e4);return V<q&&P>W})||k.push({start:new Date(V),end:new Date(P),score:Z(V,f)})}return k.sort((w,S)=>S.score-w.score)},Z=(i,a={})=>{const{preferredHours:v=[8,9,10,14,15],avoidHours:f=[12,13],weekdayBonus:r=10,preferredHourBonus:h=20,avoidHourPenalty:m=-15}=a;let p=0;const k=i.getHours(),s=i.getDay();return s>=1&&s<=5&&(p+=r),v.includes(k)&&(p+=h),f.includes(k)&&(p+=m),p+=(17-k)*2,p},K=(i,a=new Date,v=12)=>{const f=[];let r=new Date(a);const{frequency:h,frequencyValue:m=1}=i;for(let p=0;p<v;p++)switch(f.push({date:new Date(r),scheduleId:i.id,occurrence:p+1}),h==null?void 0:h.toUpperCase()){case"DAILY":r.setDate(r.getDate()+m);break;case"WEEKLY":r.setDate(r.getDate()+m*7);break;case"MONTHLY":r.setMonth(r.getMonth()+m);break;case"QUARTERLY":r.setMonth(r.getMonth()+m*3);break;case"YEARLY":r.setFullYear(r.getFullYear()+m);break}return f},X=i=>{const{event:a,delta:v,revert:f}=i,r=a.extendedProps.scheduleId,h=a.start,m=a.end;return h<new Date?(f(),{success:!1,error:"Cannot schedule maintenance in the past"}):{success:!0,scheduleId:r,newStart:h,newEnd:m,originalEvent:a}},ee=i=>{const{event:a,revert:v}=i,f=a.extendedProps.scheduleId,r=(a.end-a.start)/6e4;return r<15?(v(),{success:!1,error:"Minimum maintenance duration is 15 minutes"}):r>8*60?(v(),{success:!1,error:"Maximum maintenance duration is 8 hours"}):{success:!0,scheduleId:f,newDuration:r,originalEvent:a}},Q=(i,a,v)=>!i||!Array.isArray(i)?[]:i.filter(f=>{if(!f.nextDue)return!1;const r=new Date(f.nextDue);return r>=a&&r<=v});return{selectedDate:re,viewMode:z,convertSchedulesToEvents:N,getPriorityColor:A,getCalendarConfig:U,findSchedulingConflicts:G,findAvailableTimeSlots:Y,generateRecurringSchedule:K,handleEventDrop:X,handleEventResize:ee,filterSchedulesByDateRange:Q,getScheduleStatistics:(i,a,v)=>{const f=Q(i,a,v),r={total:f.length,overdue:0,dueToday:0,dueSoon:0,scheduled:0,byPriority:{LOW:0,MEDIUM:0,HIGH:0,CRITICAL:0},byAsset:{},totalDuration:0},h=new Date;return h.setHours(0,0,0,0),f.forEach(m=>{const p=new Date(m.nextDue),k=Math.ceil((p-h)/(1e3*60*60*24));k<0?r.overdue++:k===0?r.dueToday++:k<=3?r.dueSoon++:r.scheduled++,m.priority&&r.byPriority[m.priority]!==void 0&&r.byPriority[m.priority]++;const s=m.assetName||`Asset ${m.assetId}`;r.byAsset[s]=(r.byAsset[s]||0)+1,r.totalDuration+=m.estimatedDuration||30}),r}}}const Te={key:0,class:"p-6"},Fe={class:"grid grid-cols-1 xl:grid-cols-3 gap-6"},He={class:"xl:col-span-2 space-y-6"},Le={class:"bg-white shadow rounded-lg p-6"},Re={class:"flex items-center justify-between mb-4"},je={class:"flex items-center space-x-2"},Be={class:"grid grid-cols-1 md:grid-cols-2 gap-6"},ze={class:"mt-1 text-sm text-gray-900"},Ne={class:"mt-1 text-sm text-gray-900"},Oe={class:"mt-1 text-sm text-gray-900"},We={class:"mt-1 text-sm text-gray-900"},qe={class:"mt-1 text-sm"},$e={class:"text-gray-900"},Ue={class:"text-gray-500"},Ge={class:"mt-1 text-sm text-gray-900"},Ye={key:0,class:"md:col-span-2"},Ze={class:"mt-1 text-sm text-gray-900"},Qe={key:0,class:"bg-white shadow rounded-lg p-6"},Je={class:"space-y-6"},Ke={key:0},Xe={class:"text-sm text-gray-900 whitespace-pre-wrap bg-gray-50 rounded-md p-3"},et={key:1},tt={class:"text-sm text-gray-900 whitespace-pre-wrap bg-gray-50 rounded-md p-3"},st={key:2},at={class:"text-sm text-gray-900 whitespace-pre-wrap bg-gray-50 rounded-md p-3"},ot={class:"bg-white shadow rounded-lg p-6"},nt={class:"flex items-center justify-between mb-4"},rt={key:0,class:"text-center py-8"},lt={key:1,class:"text-center py-8"},it={key:2,class:"space-y-4"},dt={class:"flex items-center justify-between mb-2"},ut={class:"flex items-center space-x-2"},ct={class:"font-medium text-gray-900"},mt={class:"text-sm text-gray-500"},vt={class:"text-sm text-gray-600 space-y-1"},ft={key:0},yt={key:1},gt={key:0,class:"mt-2 text-sm text-gray-600 bg-gray-50 rounded-md p-2"},pt={class:"space-y-6"},ht={class:"bg-white shadow rounded-lg p-6"},xt={class:"space-y-4"},wt={class:"flex justify-between"},Dt={class:"text-sm text-gray-900"},kt={class:"flex justify-between"},_t={class:"text-sm text-gray-900"},bt={class:"flex justify-between"},Ct={class:"text-sm text-gray-900"},Mt={class:"flex justify-between"},St={class:"text-sm text-gray-900"},Vt={class:"flex justify-between"},Et={class:"text-sm text-gray-900"},Pt={class:"bg-white shadow rounded-lg p-6"},It={class:"space-y-3"},At={class:"text-sm text-gray-900"},Tt={class:"text-xs text-gray-500"},Ft={class:"text-xs text-gray-500"},Ht={class:"bg-white shadow rounded-lg p-6"},Lt={class:"space-y-3"},Rt={key:1,class:"p-6"},jt={key:2,class:"p-6"},Bt={class:"text-center py-12"},zt={class:"mt-1 text-sm text-gray-500"},Nt={class:"mt-6"},Ot={class:"space-y-4"},Wt={class:"bg-gray-50 rounded-lg p-4"},qt={class:"font-medium text-gray-900"},$t={class:"text-sm text-gray-600 mt-1"},Ut={class:"text-sm text-gray-600"},Gt={class:"flex justify-end space-x-3"},Yt={class:"space-y-4"},Zt={class:"flex justify-end space-x-3"},Qt={class:"space-y-4"},Jt={class:"flex"},Kt={class:"ml-3"},Xt={class:"mt-2"},es={class:"text-sm text-gray-500"},ts={class:"flex justify-end space-x-3"},ds={__name:"PreventiveMaintenanceDetailView",setup(re){const z=Ce(),N=De(),A=Me(),{showSuccess:U,showError:G}=be(),{calculateScheduleStatus:Y}=Ve(),{formatFrequency:Z,getPriorityVariant:K,getStatusVariant:X,formatPriority:ee,formatStatus:Q,formatDate:T,formatRelativeTime:i,formatDuration:a,formatAssetDisplay:v}=Se(),{handleScheduleDeletion:f,handleWorkOrderGeneration:r,handleSchedulePause:h,handleScheduleResume:m,handleScheduleDuplication:p}=Ee(A),{generateRecurringSchedule:k}=Ae(),s=_(null),w=_([]),S=_(!1),V=_(!1),P=_(null),R=_(!1),I=_(!1),F=_(!1),O=_(!1),W=_(!1),q=_(!1),H=_({scheduledDate:"",notes:""}),j=_({newDate:"",reason:""}),C=se(()=>N.params.id),$=se(()=>{if(!w.value.length)return{};const d=w.value.filter(b=>b.status==="COMPLETED"),t=w.value.reduce((b,E)=>b+(E.actualDuration||0),0),n=w.value.reduce((b,E)=>b+(E.totalCost||0),0);return{totalWorkOrders:w.value.length,completedWorkOrders:d.length,completionRate:w.value.length?Math.round(d.length/w.value.length*100):0,avgDuration:d.length?Math.round(t/d.length):0,totalCost:n}}),de=se(()=>s.value?k({id:s.value.id,frequency:s.value.frequency,frequencyValue:s.value.frequencyValue},new Date(s.value.nextDue),5):[]),L=async()=>{if(C.value){S.value=!0,P.value=null;try{if(s.value=await A.fetchScheduleById(parseInt(C.value)),!s.value)throw new Error("Schedule not found")}catch(d){console.error("Failed to load schedule:",d),P.value=d.message||"Failed to load schedule"}finally{S.value=!1}}},te=async()=>{var d,t;if(C.value){V.value=!0;try{w.value=[{id:1001,title:`PM: ${(d=s.value)==null?void 0:d.name}`,status:"COMPLETED",scheduledDate:"2024-01-15T09:00:00Z",completedAt:"2024-01-15T11:30:00Z",assignedTo:"John Smith",actualDuration:150,totalCost:250,notes:"All filters replaced successfully. Found minor wear on belt - noted for next maintenance.",createdAt:"2024-01-10T10:00:00Z"},{id:1002,title:`PM: ${(t=s.value)==null?void 0:t.name}`,status:"IN_PROGRESS",scheduledDate:"2024-02-15T09:00:00Z",assignedTo:"Mike Johnson",notes:"Scheduled maintenance check",createdAt:"2024-02-10T10:00:00Z"}]}catch(n){console.error("Failed to load work orders:",n),G("Failed to load work orders")}finally{V.value=!1}}},ue=()=>{te()},ce=()=>{z.push(`/maintenance/preventive/${C.value}/edit`)},me=()=>{s.value&&(H.value={scheduledDate:s.value.nextDue?new Date(s.value.nextDue).toISOString().slice(0,16):"",notes:""},R.value=!0)},ve=async()=>{O.value=!0;try{(await r(parseInt(C.value),{scheduledDate:new Date(H.value.scheduledDate),notes:H.value.notes})).success&&(R.value=!1,te(),L())}finally{O.value=!1}},fe=async()=>{try{(await h(parseInt(C.value),"Paused from detail view")).success&&L()}catch(d){console.error("Failed to pause schedule:",d)}},ye=async()=>{try{(await m(parseInt(C.value))).success&&L()}catch(d){console.error("Failed to resume schedule:",d)}},ge=async()=>{try{const d=await p(parseInt(C.value),{name:`${s.value.name} (Copy)`});d.success&&(U("Schedule duplicated successfully"),z.push(`/maintenance/preventive/${d.data.id}`))}catch(d){console.error("Failed to duplicate schedule:",d)}},pe=async()=>{W.value=!0;try{await A.rescheduleMaintenacne(parseInt(C.value),new Date(j.value.newDate),j.value.reason),U("Schedule rescheduled successfully"),I.value=!1,L()}catch(d){console.error("Failed to reschedule:",d),G("Failed to reschedule maintenance")}finally{W.value=!1}},he=async()=>{q.value=!0;try{(await f(parseInt(C.value))).success&&(F.value=!1,z.push("/maintenance/preventive"))}finally{q.value=!1}},xe=()=>{console.log("Exporting schedule details...")},we=d=>({PENDING:"warning",IN_PROGRESS:"info",COMPLETED:"success",CANCELLED:"error",ON_HOLD:"secondary"})[d]||"secondary";return ke(async()=>{await L(),s.value&&te()}),_e(()=>N.params.id,()=>{N.params.id&&L()}),(d,t)=>(y(),ae(Pe,null,{header:u(()=>{var n,b;return[c(Ie,{title:((n=s.value)==null?void 0:n.name)||"Schedule Details",description:s.value?`${s.value.assetName||"Asset"} - ${o(Z)(s.value.frequency,s.value.frequencyValue)}`:"Loading schedule details...",breadcrumbs:[{text:"Maintenance",to:"/maintenance"},{text:"Preventive Maintenance",to:"/maintenance/preventive"},{text:((b=s.value)==null?void 0:b.name)||"Details",to:null}]},{actions:u(()=>{var E,B;return[c(o(D),{variant:"outline",size:"sm",onClick:me,disabled:!s.value},{default:u(()=>t[12]||(t[12]=[e("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M9 5H7a2 2 0 00-2 2v10a2 2 0 002 2h8a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"})],-1),g(" Generate Work Order ",-1)])),_:1,__:[12]},8,["disabled"]),c(o(D),{variant:"outline",size:"sm",onClick:ge,disabled:!s.value},{default:u(()=>t[13]||(t[13]=[e("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})],-1),g(" Duplicate ",-1)])),_:1,__:[13]},8,["disabled"]),c(o(D),{variant:"outline",size:"sm",onClick:ce,disabled:!s.value},{default:u(()=>t[14]||(t[14]=[e("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})],-1),g(" Edit ",-1)])),_:1,__:[14]},8,["disabled"]),((E=s.value)==null?void 0:E.status)==="ACTIVE"?(y(),ae(o(D),{key:0,variant:"outline",size:"sm",onClick:fe},{default:u(()=>t[15]||(t[15]=[e("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M10 9v6m4-6v6m7-3a9 9 0 11-18 0 9 9 0 0118 0z"})],-1),g(" Pause ",-1)])),_:1,__:[15]})):((B=s.value)==null?void 0:B.status)==="PAUSED"?(y(),ae(o(D),{key:1,variant:"outline",size:"sm",onClick:ye},{default:u(()=>t[16]||(t[16]=[e("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M14.828 14.828a4 4 0 01-5.656 0M9 10h1m4 0h1m-6 4h8m-5-4v4m0 0V8a2 2 0 012-2h2a2 2 0 012 2v12l-4-4z"})],-1),g(" Resume ",-1)])),_:1,__:[16]})):M("",!0)]}),_:1},8,["title","description","breadcrumbs"])]}),default:u(()=>[s.value?(y(),x("div",Te,[e("div",Fe,[e("div",He,[e("div",Le,[e("div",Re,[t[17]||(t[17]=e("h3",{class:"text-lg font-medium text-gray-900"},"Schedule Information",-1)),e("div",je,[c(o(ne),{variant:o(K)(s.value.priority)},{default:u(()=>[g(l(o(ee)(s.value.priority)),1)]),_:1},8,["variant"]),c(o(ne),{variant:o(X)(o(Y)(s.value))},{default:u(()=>[g(l(o(Q)(o(Y)(s.value))),1)]),_:1},8,["variant"])])]),e("dl",Be,[e("div",null,[t[18]||(t[18]=e("dt",{class:"text-sm font-medium text-gray-500"},"Schedule Name",-1)),e("dd",ze,l(s.value.name),1)]),e("div",null,[t[19]||(t[19]=e("dt",{class:"text-sm font-medium text-gray-500"},"Asset",-1)),e("dd",Ne,l(o(v)(s.value.assetName||s.value.asset)),1)]),e("div",null,[t[20]||(t[20]=e("dt",{class:"text-sm font-medium text-gray-500"},"Frequency",-1)),e("dd",Oe,l(o(Z)(s.value.frequency,s.value.frequencyValue)),1)]),e("div",null,[t[21]||(t[21]=e("dt",{class:"text-sm font-medium text-gray-500"},"Estimated Duration",-1)),e("dd",We,l(o(a)(s.value.estimatedDuration)),1)]),e("div",null,[t[22]||(t[22]=e("dt",{class:"text-sm font-medium text-gray-500"},"Next Due",-1)),e("dd",qe,[e("div",$e,l(o(T)(s.value.nextDue)),1),e("div",Ue,l(o(i)(s.value.nextDue)),1)])]),e("div",null,[t[23]||(t[23]=e("dt",{class:"text-sm font-medium text-gray-500"},"Last Completed",-1)),e("dd",Ge,l(s.value.lastCompleted?o(T)(s.value.lastCompleted):"Never"),1)]),s.value.description?(y(),x("div",Ye,[t[24]||(t[24]=e("dt",{class:"text-sm font-medium text-gray-500"},"Description",-1)),e("dd",Ze,l(s.value.description),1)])):M("",!0)])]),s.value.instructions||s.value.notes||s.value.requiredParts?(y(),x("div",Qe,[t[28]||(t[28]=e("h3",{class:"text-lg font-medium text-gray-900 mb-4"},"Instructions & Details",-1)),e("div",Je,[s.value.instructions?(y(),x("div",Ke,[t[25]||(t[25]=e("dt",{class:"text-sm font-medium text-gray-500 mb-2"},"Maintenance Instructions",-1)),e("dd",Xe,l(s.value.instructions),1)])):M("",!0),s.value.requiredParts?(y(),x("div",et,[t[26]||(t[26]=e("dt",{class:"text-sm font-medium text-gray-500 mb-2"},"Required Parts",-1)),e("dd",tt,l(s.value.requiredParts),1)])):M("",!0),s.value.notes?(y(),x("div",st,[t[27]||(t[27]=e("dt",{class:"text-sm font-medium text-gray-500 mb-2"},"Additional Notes",-1)),e("dd",at,l(s.value.notes),1)])):M("",!0)])])):M("",!0),e("div",ot,[e("div",nt,[t[30]||(t[30]=e("h3",{class:"text-lg font-medium text-gray-900"},"Work Order History",-1)),c(o(D),{variant:"outline",size:"sm",onClick:ue},{default:u(()=>t[29]||(t[29]=[e("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})],-1),g(" Refresh ",-1)])),_:1,__:[29]})]),V.value?(y(),x("div",rt,t[31]||(t[31]=[e("div",{class:"inline-flex items-center"},[e("svg",{class:"animate-spin -ml-1 mr-3 h-5 w-5 text-gray-500",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24"},[e("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"}),e("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]),g(" Loading work orders... ")],-1)]))):w.value.length===0?(y(),x("div",lt,t[32]||(t[32]=[e("svg",{class:"mx-auto h-12 w-12 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M9 5H7a2 2 0 00-2 2v10a2 2 0 002 2h8a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01"})],-1),e("p",{class:"mt-2 text-sm text-gray-600"},"No work orders generated yet",-1)]))):(y(),x("div",it,[(y(!0),x(le,null,ie(w.value,n=>(y(),x("div",{key:n.id,class:"border border-gray-200 rounded-lg p-4 hover:border-gray-300 transition-colors"},[e("div",dt,[e("div",ut,[e("h4",ct,l(n.title||`Work Order #${n.id}`),1),c(o(ne),{variant:we(n.status)},{default:u(()=>[g(l(n.status),1)]),_:2},1032,["variant"])]),e("span",mt,l(o(T)(n.createdAt)),1)]),e("div",vt,[e("div",null,"Scheduled: "+l(o(T)(n.scheduledDate)),1),n.assignedTo?(y(),x("div",ft,"Assigned to: "+l(n.assignedTo),1)):M("",!0),n.completedAt?(y(),x("div",yt,"Completed: "+l(o(T)(n.completedAt)),1)):M("",!0)]),n.notes?(y(),x("div",gt,l(n.notes),1)):M("",!0)]))),128))]))])]),e("div",pt,[e("div",ht,[t[38]||(t[38]=e("h3",{class:"text-lg font-medium text-gray-900 mb-4"},"Quick Stats",-1)),e("dl",xt,[e("div",wt,[t[33]||(t[33]=e("dt",{class:"text-sm font-medium text-gray-500"},"Total Work Orders",-1)),e("dd",Dt,l($.value.totalWorkOrders||0),1)]),e("div",kt,[t[34]||(t[34]=e("dt",{class:"text-sm font-medium text-gray-500"},"Completed",-1)),e("dd",_t,l($.value.completedWorkOrders||0),1)]),e("div",bt,[t[35]||(t[35]=e("dt",{class:"text-sm font-medium text-gray-500"},"Completion Rate",-1)),e("dd",Ct,l($.value.completionRate||0)+"%",1)]),e("div",Mt,[t[36]||(t[36]=e("dt",{class:"text-sm font-medium text-gray-500"},"Avg. Duration",-1)),e("dd",St,l(o(a)($.value.avgDuration)||"N/A"),1)]),e("div",Vt,[t[37]||(t[37]=e("dt",{class:"text-sm font-medium text-gray-500"},"Total Cost",-1)),e("dd",Et,"$"+l(($.value.totalCost||0).toLocaleString()),1)])])]),e("div",Pt,[t[39]||(t[39]=e("h3",{class:"text-lg font-medium text-gray-900 mb-4"},"Upcoming Occurrences",-1)),e("div",It,[(y(!0),x(le,null,ie(de.value,(n,b)=>(y(),x("div",{key:b,class:"flex justify-between items-center py-2 border-b border-gray-100 last:border-b-0"},[e("div",null,[e("div",At,l(o(T)(n.date)),1),e("div",Tt,l(o(i)(n.date)),1)]),e("div",Ft," #"+l(n.occurrence),1)]))),128))])]),e("div",Ht,[t[43]||(t[43]=e("h3",{class:"text-lg font-medium text-gray-900 mb-4"},"Actions",-1)),e("div",Lt,[c(o(D),{variant:"outline",size:"sm",class:"w-full justify-start",onClick:t[0]||(t[0]=n=>I.value=!0)},{default:u(()=>t[40]||(t[40]=[e("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})],-1),g(" Reschedule ",-1)])),_:1,__:[40]}),c(o(D),{variant:"outline",size:"sm",class:"w-full justify-start",onClick:xe},{default:u(()=>t[41]||(t[41]=[e("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e("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),g(" Export Details ",-1)])),_:1,__:[41]}),c(o(D),{variant:"outline",size:"sm",class:"w-full justify-start text-red-600 hover:text-red-700",onClick:t[1]||(t[1]=n=>F.value=!0)},{default:u(()=>t[42]||(t[42]=[e("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})],-1),g(" Delete Schedule ",-1)])),_:1,__:[42]})])])])])])):S.value?(y(),x("div",Rt,t[44]||(t[44]=[e("div",{class:"text-center py-12"},[e("div",{class:"inline-flex items-center"},[e("svg",{class:"animate-spin -ml-1 mr-3 h-8 w-8 text-gray-500",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24"},[e("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"}),e("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]),e("span",{class:"text-lg text-gray-600"},"Loading schedule details...")])],-1)]))):P.value?(y(),x("div",jt,[e("div",Bt,[t[46]||(t[46]=e("svg",{class:"mx-auto h-12 w-12 text-red-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.268 16.5c-.77.833.192 2.5 1.732 2.5z"})],-1)),t[47]||(t[47]=e("h3",{class:"mt-2 text-sm font-medium text-gray-900"},"Error loading schedule",-1)),e("p",zt,l(P.value),1),e("div",Nt,[c(o(D),{variant:"primary",onClick:L},{default:u(()=>t[45]||(t[45]=[g(" Try Again ",-1)])),_:1,__:[45]})])])])):M("",!0),c(o(oe),{modelValue:R.value,"onUpdate:modelValue":t[5]||(t[5]=n=>R.value=n),title:"Generate Work Order",size:"md"},{footer:u(()=>[e("div",Gt,[c(o(D),{variant:"secondary",onClick:t[4]||(t[4]=n=>R.value=!1)},{default:u(()=>t[48]||(t[48]=[g(" Cancel ",-1)])),_:1,__:[48]}),c(o(D),{variant:"primary",loading:O.value,onClick:ve},{default:u(()=>t[49]||(t[49]=[g(" Generate Work Order ",-1)])),_:1,__:[49]},8,["loading"])])]),default:u(()=>{var n,b,E;return[e("div",Ot,[e("div",Wt,[e("h4",qt,l((n=s.value)==null?void 0:n.name),1),e("p",$t,l(o(v)((b=s.value)==null?void 0:b.assetName)),1),e("p",Ut,"Estimated Duration: "+l(o(a)((E=s.value)==null?void 0:E.estimatedDuration)),1)]),c(o(J),{modelValue:H.value.scheduledDate,"onUpdate:modelValue":t[2]||(t[2]=B=>H.value.scheduledDate=B),label:"Scheduled Date",type:"datetime-local",required:""},null,8,["modelValue"]),c(o(J),{modelValue:H.value.notes,"onUpdate:modelValue":t[3]||(t[3]=B=>H.value.notes=B),label:"Work Order Notes",type:"textarea",placeholder:"Additional notes for this work order...",rows:"3"},null,8,["modelValue"])])]}),_:1},8,["modelValue"]),c(o(oe),{modelValue:I.value,"onUpdate:modelValue":t[9]||(t[9]=n=>I.value=n),title:"Reschedule Maintenance",size:"md"},{footer:u(()=>[e("div",Zt,[c(o(D),{variant:"secondary",onClick:t[8]||(t[8]=n=>I.value=!1)},{default:u(()=>t[50]||(t[50]=[g(" Cancel ",-1)])),_:1,__:[50]}),c(o(D),{variant:"primary",loading:W.value,onClick:pe},{default:u(()=>t[51]||(t[51]=[g(" Reschedule ",-1)])),_:1,__:[51]},8,["loading"])])]),default:u(()=>[e("div",Yt,[c(o(J),{modelValue:j.value.newDate,"onUpdate:modelValue":t[6]||(t[6]=n=>j.value.newDate=n),label:"New Due Date",type:"datetime-local",required:""},null,8,["modelValue"]),c(o(J),{modelValue:j.value.reason,"onUpdate:modelValue":t[7]||(t[7]=n=>j.value.reason=n),label:"Reason for Rescheduling",type:"textarea",placeholder:"Explain why this maintenance is being rescheduled...",rows:"3",required:""},null,8,["modelValue"])])]),_:1},8,["modelValue"]),c(o(oe),{modelValue:F.value,"onUpdate:modelValue":t[11]||(t[11]=n=>F.value=n),title:"Delete Schedule",size:"sm"},{footer:u(()=>[e("div",ts,[c(o(D),{variant:"secondary",onClick:t[10]||(t[10]=n=>F.value=!1)},{default:u(()=>t[54]||(t[54]=[g(" Cancel ",-1)])),_:1,__:[54]}),c(o(D),{variant:"danger",loading:q.value,onClick:he},{default:u(()=>t[55]||(t[55]=[g(" Delete Schedule ",-1)])),_:1,__:[55]},8,["loading"])])]),default:u(()=>{var n;return[e("div",Qt,[e("div",Jt,[t[53]||(t[53]=e("div",{class:"flex-shrink-0"},[e("svg",{class:"h-6 w-6 text-red-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.268 16.5c-.77.833.192 2.5 1.732 2.5z"})])],-1)),e("div",Kt,[t[52]||(t[52]=e("h3",{class:"text-lg font-medium text-gray-900"},"Delete Schedule",-1)),e("div",Xt,[e("p",es,' Are you sure you want to delete "'+l((n=s.value)==null?void 0:n.name)+'"? This action cannot be undone and will remove all associated work orders and history. ',1)])])])])]}),_:1},8,["modelValue"])]),_:1}))}};export{ds as default};