import{_ as W,q as $,r as n,c as C,o as H,a as u,j as D,b as t,t as k,d as r,w as m,e as s,F as b,f as z,h as G,s as j,v as J,g as v,k as y}from"./index-BUdRbiwj.js";import{F as w}from"./FPInput-CzR_dWoe.js";import{F as p}from"./FPSelect-C7p47Ma2.js";import{T as Z}from"./TimeTracker-Ch4gtOrh.js";import{T as K,P as Q,A as X}from"./AudioRecorder-CcKMXbWt.js";import{D as Y}from"./DigitalSignature-B20bSUAg.js";import"./FPCheckbox-Bu8jNAEW.js";import"./FPBadge-BKY5dPnL.js";const ee={class:"edit-work-order"},te={key:0,class:"flex items-center justify-center min-h-96"},le={key:1,class:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8"},ae={class:"bg-red-50 border border-red-200 rounded-lg p-6"},oe={class:"flex"},re={class:"ml-3"},se={class:"text-sm text-red-700 mt-1"},ie={class:"mt-4"},de={key:2,class:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8"},ne={class:"mb-8"},ue={class:"flex","aria-label":"Breadcrumb"},ve={class:"flex items-center space-x-4"},me={class:"mt-2 flex items-center justify-between"},pe={class:"text-gray-600"},ge={class:"flex space-x-2"},ce={key:0},be={key:1},ye={class:"bg-white shadow rounded-lg p-6"},fe={class:"grid grid-cols-1 gap-6 sm:grid-cols-2"},ke={class:"sm:col-span-2"},we={class:"sm:col-span-2"},xe={class:"bg-white shadow rounded-lg p-6"},Ie={class:"grid grid-cols-1 gap-6 sm:grid-cols-2"},Ve={class:"bg-white shadow rounded-lg p-6"},he={class:"grid grid-cols-1 gap-6 sm:grid-cols-3"},Se={class:"grid grid-cols-1 lg:grid-cols-2 gap-8"},Te={class:"bg-white shadow rounded-lg p-6"},Ce={class:"bg-white shadow rounded-lg p-6"},De={class:"bg-white shadow rounded-lg p-6"},Ee={class:"bg-white shadow rounded-lg p-6"},Oe={key:0,class:"bg-white shadow rounded-lg p-6"},Me={class:"flex justify-end space-x-4 pt-6 border-t border-gray-200"},Ue={key:0},Re={key:1},_e={__name:"EditWorkOrderView",props:{id:{type:[String,Number],required:!0}},setup(E){j();const O=J(),M=$(),I=E,d=n(null),x=n(!0),g=n(!1),c=n(null),i=n({}),l=n({title:"",description:"",status:"OPEN",priority:"MEDIUM",dueDate:"",estimatedDuration:null,primaryUserId:null,assignedToIds:[],assetId:null,locationId:null,categoryId:null,tasks:[],parts:[],timeEntries:[],audioRecordings:[],signature:null}),U=[{value:"OPEN",label:"Open"},{value:"IN_PROGRESS",label:"In Progress"},{value:"ON_HOLD",label:"On Hold"},{value:"COMPLETED",label:"Completed"},{value:"CANCELLED",label:"Cancelled"}],R=[{value:"LOW",label:"Low"},{value:"MEDIUM",label:"Medium"},{value:"HIGH",label:"High"},{value:"CRITICAL",label:"Critical"}],V=n([{value:1,label:"John Smith"},{value:2,label:"Jane Doe"},{value:3,label:"Mike Johnson"}]),_=n([{value:1,label:"Conveyor Belt System A1"},{value:2,label:"Hydraulic Press B2"},{value:3,label:"CNC Machine C3"}]),P=n([{value:1,label:"Production Floor A"},{value:2,label:"Warehouse B"},{value:3,label:"Maintenance Shop"}]),N=n([{value:1,label:"Mechanical Repair"},{value:2,label:"Electrical Maintenance"},{value:3,label:"Preventive Maintenance"}]),f=C(()=>M.user),L=C(()=>l.value.status==="IN_PROGRESS"||l.value.status==="COMPLETED"),h=async()=>{try{x.value=!0,c.value=null,await new Promise(e=>setTimeout(e,1e3));const a={id:I.id,workOrderId:`WO-${String(I.id).padStart(6,"0")}`,title:"Repair Conveyor Belt Motor",description:"The conveyor belt motor in the production line has been making unusual noises and requires inspection and repair.",status:"IN_PROGRESS",priority:"HIGH",createdAt:"2024-01-15T08:00:00Z",dueDate:"2024-01-17T17:00:00Z",estimatedDuration:4,primaryUserId:1,assignedToIds:[2],assetId:1,locationId:1,categoryId:1,tasks:[{id:1,title:"Inspect motor bearings",description:"Check for wear and tear",completed:!0,required:!0,estimatedDuration:1},{id:2,title:"Replace worn components",description:"Replace any damaged parts found during inspection",completed:!1,required:!0,estimatedDuration:2}],timeEntries:[{id:1,type:"timer",duration:2.5,description:"Initial inspection and diagnosis",startTime:"2024-01-15T08:00:00Z",endTime:"2024-01-15T10:30:00Z",user:{id:1,firstName:"John",lastName:"Smith"},hourlyRate:55,date:"2024-01-15"}],audioRecordings:[{id:1,title:"Initial Inspection Notes",description:"Motor sounds and initial observations",duration:120,size:256e4,createdAt:"2024-01-15T08:30:00Z",user:{id:1,firstName:"John",lastName:"Smith"},transcription:"Motor is making grinding noise, likely bearing issue.",transcriptionConfidence:.92}],parts:[{id:1,partId:101,name:"Motor Bearing Set",partNumber:"BRG-M15",quantityUsed:1,unitPrice:45}],signature:null};d.value=a,l.value={title:a.title,description:a.description,status:a.status,priority:a.priority,dueDate:a.dueDate?a.dueDate.slice(0,16):"",estimatedDuration:a.estimatedDuration,primaryUserId:a.primaryUserId,assignedToIds:a.assignedToIds,assetId:a.assetId,locationId:a.locationId,categoryId:a.categoryId,tasks:[...a.tasks],parts:[...a.parts],timeEntries:[...a.timeEntries],audioRecordings:[...a.audioRecordings],signature:a.signature}}catch(a){c.value=a.message||"Failed to load work order"}finally{x.value=!1}},A=()=>{var e;i.value={};let a=!0;return(e=l.value.title)!=null&&e.trim()||(i.value.title="Title is required",a=!1),l.value.status||(i.value.status="Status is required",a=!1),l.value.priority||(i.value.priority="Priority is required",a=!1),a},S=async()=>{if(A())try{g.value=!0,await new Promise(a=>setTimeout(a,1500)),console.log("Saving work order:",l.value),O.push(`/work-orders/${d.value.id}`)}catch(a){c.value=a.message||"Failed to save work order"}finally{g.value=!1}},B=a=>{console.log("Time entry saved:",a)},q=a=>{console.log("Recording saved:",a)},F=a=>{console.log("Signature saved:",a)};return H(()=>{h()}),(a,e)=>{const T=z("router-link");return v(),u("div",ee,[x.value?(v(),u("div",te,e[18]||(e[18]=[t("div",{class:"text-center"},[t("div",{class:"animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto mb-4"}),t("p",{class:"text-gray-600"},"Loading work order...")],-1)]))):c.value?(v(),u("div",le,[t("div",ae,[t("div",oe,[e[21]||(e[21]=t("svg",{class:"w-6 h-6 text-red-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[t("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.854-.833-2.598 0L3.732 16.5c-.77.833.192 2.5 1.732 2.5z"})],-1)),t("div",re,[e[20]||(e[20]=t("h3",{class:"text-sm font-medium text-red-800"},"Error Loading Work Order",-1)),t("p",se,k(c.value),1),t("div",ie,[r(s(b),{variant:"outline",size:"sm",onClick:h},{default:m(()=>e[19]||(e[19]=[y(" Try Again ",-1)])),_:1,__:[19]})])])])])])):d.value?(v(),u("div",de,[t("div",ne,[t("nav",ue,[t("ol",ve,[t("li",null,[r(T,{to:"/work-orders",class:"text-gray-400 hover:text-gray-500"},{default:m(()=>e[22]||(e[22]=[y(" Work Orders ",-1)])),_:1,__:[22]})]),e[23]||(e[23]=t("li",null,[t("svg",{class:"flex-shrink-0 h-5 w-5 text-gray-300",fill:"currentColor",viewBox:"0 0 20 20"},[t("path",{"fill-rule":"evenodd",d:"M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z","clip-rule":"evenodd"})])],-1)),t("li",null,[r(T,{to:`/work-orders/${d.value.id}`,class:"text-gray-400 hover:text-gray-500"},{default:m(()=>[y(k(d.value.workOrderId),1)]),_:1},8,["to"])]),e[24]||(e[24]=t("li",null,[t("svg",{class:"flex-shrink-0 h-5 w-5 text-gray-300",fill:"currentColor",viewBox:"0 0 20 20"},[t("path",{"fill-rule":"evenodd",d:"M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z","clip-rule":"evenodd"})])],-1)),e[25]||(e[25]=t("li",{class:"text-gray-500"},"Edit",-1))])]),t("div",me,[t("div",null,[e[26]||(e[26]=t("h1",{class:"text-2xl font-bold text-gray-900"},"Edit Work Order",-1)),t("p",pe,k(d.value.workOrderId)+" - "+k(d.value.title),1)]),t("div",ge,[r(s(b),{variant:"outline",onClick:e[0]||(e[0]=o=>a.$router.push(`/work-orders/${d.value.id}`))},{default:m(()=>e[27]||(e[27]=[y(" Cancel ",-1)])),_:1,__:[27]}),r(s(b),{variant:"primary",onClick:S,disabled:g.value},{default:m(()=>[g.value?(v(),u("span",ce,"Saving...")):(v(),u("span",be,"Save Changes"))]),_:1},8,["disabled"])])])]),t("form",{onSubmit:G(S,["prevent"]),class:"space-y-8"},[t("div",ye,[e[28]||(e[28]=t("h2",{class:"text-lg font-medium text-gray-900 mb-6"},"Basic Information",-1)),t("div",fe,[t("div",ke,[r(s(w),{modelValue:l.value.title,"onUpdate:modelValue":e[1]||(e[1]=o=>l.value.title=o),label:"Title",placeholder:"Enter work order title",required:"",error:i.value.title},null,8,["modelValue","error"])]),t("div",we,[r(s(w),{modelValue:l.value.description,"onUpdate:modelValue":e[2]||(e[2]=o=>l.value.description=o),label:"Description",type:"textarea",rows:"4",placeholder:"Enter detailed description of the work to be performed",error:i.value.description},null,8,["modelValue","error"])]),t("div",null,[r(s(p),{modelValue:l.value.status,"onUpdate:modelValue":e[3]||(e[3]=o=>l.value.status=o),label:"Status",options:U,error:i.value.status},null,8,["modelValue","error"])]),t("div",null,[r(s(p),{modelValue:l.value.priority,"onUpdate:modelValue":e[4]||(e[4]=o=>l.value.priority=o),label:"Priority",options:R,error:i.value.priority},null,8,["modelValue","error"])]),t("div",null,[r(s(w),{modelValue:l.value.dueDate,"onUpdate:modelValue":e[5]||(e[5]=o=>l.value.dueDate=o),label:"Due Date",type:"datetime-local",error:i.value.dueDate},null,8,["modelValue","error"])]),t("div",null,[r(s(w),{modelValue:l.value.estimatedDuration,"onUpdate:modelValue":e[6]||(e[6]=o=>l.value.estimatedDuration=o),label:"Estimated Duration (hours)",type:"number",step:"0.5",min:"0",error:i.value.estimatedDuration},null,8,["modelValue","error"])])])]),t("div",xe,[e[29]||(e[29]=t("h2",{class:"text-lg font-medium text-gray-900 mb-6"},"Assignment",-1)),t("div",Ie,[t("div",null,[r(s(p),{modelValue:l.value.primaryUserId,"onUpdate:modelValue":e[7]||(e[7]=o=>l.value.primaryUserId=o),label:"Primary Assignee",options:V.value,searchable:"",error:i.value.primaryUserId},null,8,["modelValue","options","error"])]),t("div",null,[r(s(p),{modelValue:l.value.assignedToIds,"onUpdate:modelValue":e[8]||(e[8]=o=>l.value.assignedToIds=o),label:"Team Members",options:V.value,multiple:"",searchable:"",error:i.value.assignedToIds},null,8,["modelValue","options","error"])])])]),t("div",Ve,[e[30]||(e[30]=t("h2",{class:"text-lg font-medium text-gray-900 mb-6"},"Asset & Location",-1)),t("div",he,[t("div",null,[r(s(p),{modelValue:l.value.assetId,"onUpdate:modelValue":e[9]||(e[9]=o=>l.value.assetId=o),label:"Asset",options:_.value,searchable:"",clearable:"",error:i.value.assetId},null,8,["modelValue","options","error"])]),t("div",null,[r(s(p),{modelValue:l.value.locationId,"onUpdate:modelValue":e[10]||(e[10]=o=>l.value.locationId=o),label:"Location",options:P.value,searchable:"",clearable:"",error:i.value.locationId},null,8,["modelValue","options","error"])]),t("div",null,[r(s(p),{modelValue:l.value.categoryId,"onUpdate:modelValue":e[11]||(e[11]=o=>l.value.categoryId=o),label:"Category",options:N.value,searchable:"",clearable:"",error:i.value.categoryId},null,8,["modelValue","options","error"])])])]),t("div",Se,[t("div",Te,[e[31]||(e[31]=t("h2",{class:"text-lg font-medium text-gray-900 mb-6"},"Tasks",-1)),r(K,{modelValue:l.value.tasks,"onUpdate:modelValue":e[12]||(e[12]=o=>l.value.tasks=o),"work-order-id":d.value.id,"current-user":f.value},null,8,["modelValue","work-order-id","current-user"])]),t("div",Ce,[e[32]||(e[32]=t("h2",{class:"text-lg font-medium text-gray-900 mb-6"},"Parts & Materials",-1)),r(Q,{modelValue:l.value.parts,"onUpdate:modelValue":e[13]||(e[13]=o=>l.value.parts=o),"work-order-id":d.value.id},null,8,["modelValue","work-order-id"])])]),t("div",De,[e[33]||(e[33]=t("h2",{class:"text-lg font-medium text-gray-900 mb-6"},"Time Tracking",-1)),r(Z,{modelValue:l.value.timeEntries,"onUpdate:modelValue":e[14]||(e[14]=o=>l.value.timeEntries=o),"work-order-id":d.value.id,"current-user":f.value,"auto-save":!1,onTimeEntrySaved:B},null,8,["modelValue","work-order-id","current-user"])]),t("div",Ee,[e[34]||(e[34]=t("h2",{class:"text-lg font-medium text-gray-900 mb-6"},"Audio Notes",-1)),r(X,{modelValue:l.value.audioRecordings,"onUpdate:modelValue":e[15]||(e[15]=o=>l.value.audioRecordings=o),"work-order-id":d.value.id,"current-user":f.value,"auto-transcribe":!0,"enable-visualization":!0,"auto-save":!1,onRecordingSaved:q},null,8,["modelValue","work-order-id","current-user"])]),L.value?(v(),u("div",Oe,[e[35]||(e[35]=t("h2",{class:"text-lg font-medium text-gray-900 mb-6"},"Completion Signature",-1)),r(Y,{modelValue:l.value.signature,"onUpdate:modelValue":e[16]||(e[16]=o=>l.value.signature=o),"work-order-id":d.value.id,"current-user":f.value,"auto-save":!1,"enable-validation":!0,onSignatureSaved:F},null,8,["modelValue","work-order-id","current-user"])])):D("",!0),t("div",Me,[r(s(b),{type:"button",variant:"outline",onClick:e[17]||(e[17]=o=>a.$router.push(`/work-orders/${d.value.id}`))},{default:m(()=>e[36]||(e[36]=[y(" Cancel ",-1)])),_:1,__:[36]}),r(s(b),{type:"submit",variant:"primary",disabled:g.value},{default:m(()=>[g.value?(v(),u("span",Ue,"Saving...")):(v(),u("span",Re,"Save Changes"))]),_:1},8,["disabled"])])],32)])):D("",!0)])}}},$e=W(_e,[["__scopeId","data-v-06f2a370"]]);export{$e as default};