import{_ as le,r as P,c as w,o as re,m as se,a as c,g as m,b as a,j as A,t as i,d as s,w as f,k as y,e as n,F as x,af as N,aQ as Y}from"./index-BUdRbiwj.js";import{F as D}from"./FPInput-CzR_dWoe.js";import{F as W}from"./FPSelect-C7p47Ma2.js";const ne={class:"work-order-id-generator"},de={class:"mb-4 p-4 bg-blue-50 border border-blue-200 rounded-lg"},ue={class:"flex items-center justify-between"},ie={class:"text-lg font-bold text-blue-900 font-mono"},ce={class:"flex items-center space-x-2"},me={key:0,class:"mb-4 p-4 bg-yellow-50 border border-yellow-200 rounded-lg"},pe={class:"flex items-center space-x-3"},ve={key:1,class:"mb-6 p-4 bg-gray-50 border border-gray-200 rounded-lg"},ge={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"},ye={key:0,class:"mb-4"},xe={class:"mb-4 p-3 bg-white border border-gray-200 rounded"},be={class:"flex items-center justify-between"},we={class:"font-mono text-lg text-gray-900"},Oe={class:"flex items-center space-x-2"},ke={key:2,class:"mb-4"},Ce={class:"grid grid-cols-2 md:grid-cols-4 gap-2 text-xs"},$e=["onClick"],Ie={class:"font-medium text-gray-900"},Se={class:"font-mono text-gray-600"},he={key:3,class:"mb-4"},Pe={class:"space-y-1"},Ae={class:"font-mono"},De={class:"text-gray-500"},Re={class:"p-4 bg-gray-50 rounded-lg"},Te={class:"grid grid-cols-2 md:grid-cols-4 gap-4 text-sm"},Ve={class:"ml-2 font-medium text-gray-900"},_e={class:"ml-2 font-medium text-gray-900"},Ee={class:"ml-2 font-medium text-gray-900"},Me={class:"ml-2 font-medium text-gray-900"},Fe={__name:"WorkOrderIdGenerator",props:{modelValue:{type:String,default:""},category:{type:Object,default:null},location:{type:Object,default:null},disabled:{type:Boolean,default:!1},allowManualEntry:{type:Boolean,default:!1}},emits:["update:modelValue"],setup(O,{emit:L}){const u=O,U=L,p=P(u.modelValue),k=P(!1),v=P(""),C=P([]),t=P({template:"standard",prefix:"WO",separator:"-",counterLength:4,counterType:"sequential",customPattern:""}),T=[{value:"standard",title:"Standard (WO-0001)"},{value:"date",title:"Date-based (WO-2024-0001)"},{value:"category",title:"Category-based (PM-0001)"},{value:"location",title:"Location-based (NYC-WO-0001)"},{value:"custom",title:"Custom Pattern"}],j=[{value:"sequential",title:"Sequential (1, 2, 3...)"},{value:"yearly",title:"Reset Yearly"},{value:"monthly",title:"Reset Monthly"},{value:"daily",title:"Reset Daily"}],z=[{name:"Standard",preview:"WO-0001",template:"standard"},{name:"Year-Month",preview:"WO-2024-01-0001",template:"date"},{name:"Category",preview:"PM-0001",template:"category"},{name:"Location",preview:"NYC-WO-0001",template:"location"}],B=w(()=>X()),G=w(()=>{const l=T.find(e=>e.value===t.value.template);return{name:(l==null?void 0:l.title)||"Custom"}}),V=w(()=>1245),H=w(()=>C.value.length),q=w(()=>{const l=new Date().getMonth(),e=new Date().getFullYear();return C.value.filter(o=>{const g=new Date(o.createdAt);return g.getMonth()===l&&g.getFullYear()===e}).length}),_=w(()=>!u.disabled&&p.value),E=()=>{var $,I,S,h;const l=new Date,e=l.getFullYear().toString(),o=(l.getMonth()+1).toString().padStart(2,"0"),g=l.getDate().toString().padStart(2,"0"),d=V.value.toString().padStart(t.value.counterLength,"0");let r="";switch(t.value.template){case"standard":r=`${t.value.prefix}${t.value.separator}${d}`;break;case"date":r=`${t.value.prefix}${t.value.separator}${e}${t.value.separator}${o}${t.value.separator}${d}`;break;case"category":r=`${(($=u.category)==null?void 0:$.code)||t.value.prefix}${t.value.separator}${d}`;break;case"location":r=`${((I=u.location)==null?void 0:I.code)||"LOC"}${t.value.separator}${t.value.prefix}${t.value.separator}${d}`;break;case"custom":r=t.value.customPattern.replace("{PREFIX}",t.value.prefix).replace("{SEPARATOR}",t.value.separator).replace("{YEAR}",e).replace("{MONTH}",o).replace("{DAY}",g).replace("{COUNTER}",d).replace("{CATEGORY}",((S=u.category)==null?void 0:S.code)||"CAT").replace("{LOCATION}",((h=u.location)==null?void 0:h.code)||"LOC");break;default:r=`${t.value.prefix}${t.value.separator}${d}`}return r},X=()=>{var $,I,S,h;const l=new Date,e=l.getFullYear().toString(),o=(l.getMonth()+1).toString().padStart(2,"0"),g=l.getDate().toString().padStart(2,"0"),d="0001";let r="";switch(t.value.template){case"standard":r=`${t.value.prefix}${t.value.separator}${d}`;break;case"date":r=`${t.value.prefix}${t.value.separator}${e}${t.value.separator}${o}${t.value.separator}${d}`;break;case"category":r=`${(($=u.category)==null?void 0:$.code)||"PM"}${t.value.separator}${d}`;break;case"location":r=`${((I=u.location)==null?void 0:I.code)||"NYC"}${t.value.separator}${t.value.prefix}${t.value.separator}${d}`;break;case"custom":r=t.value.customPattern.replace("{PREFIX}",t.value.prefix).replace("{SEPARATOR}",t.value.separator).replace("{YEAR}",e).replace("{MONTH}",o).replace("{DAY}",g).replace("{COUNTER}",d).replace("{CATEGORY}",((S=u.category)==null?void 0:S.code)||"CAT").replace("{LOCATION}",((h=u.location)==null?void 0:h.code)||"LOC");break;default:r=`${t.value.prefix}${t.value.separator}${d}`}return r},M=()=>{_.value&&(p.value=E(),R())},J=()=>{v.value&&(p.value=v.value,v.value="",R())},Q=()=>{v.value=""},F=()=>{k.value=!k.value},b=()=>{},K=()=>{localStorage.setItem("workOrderIdFormat",JSON.stringify(t.value)),M(),k.value=!1},Z=()=>{t.value={template:"standard",prefix:"WO",separator:"-",counterLength:4,counterType:"sequential",customPattern:""}},ee=l=>{t.value.template=l.template},te=l=>new Date(l).toLocaleDateString("en-US",{month:"short",day:"numeric"}),R=()=>{U("update:modelValue",p.value)};return re(()=>{const l=localStorage.getItem("workOrderIdFormat");if(l)try{t.value=JSON.parse(l)}catch{console.warn("Failed to load saved ID format")}u.modelValue||(p.value=E(),R()),C.value=[{id:1,workOrderId:"WO-1244",createdAt:new Date(Date.now()-864e5).toISOString()},{id:2,workOrderId:"WO-1243",createdAt:new Date(Date.now()-1728e5).toISOString()},{id:3,workOrderId:"WO-1242",createdAt:new Date(Date.now()-2592e5).toISOString()}]}),se(()=>u.modelValue,l=>{p.value=l}),(l,e)=>(m(),c("div",ne,[a("div",de,[a("div",ue,[a("div",null,[e[7]||(e[7]=a("h4",{class:"text-sm font-medium text-blue-900"},"Work Order ID",-1)),a("p",ie,i(p.value||"Auto-generated"),1)]),a("div",ce,[s(n(x),{variant:"outline",size:"sm",onClick:M,disabled:O.disabled||!_.value},{default:f(()=>e[8]||(e[8]=[a("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[a("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),y(" Regenerate ",-1)])),_:1,__:[8]},8,["disabled"]),s(n(x),{variant:"ghost",size:"sm",onClick:F},{default:f(()=>e[9]||(e[9]=[a("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[a("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),a("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})],-1),y(" Customize ",-1)])),_:1,__:[9]})])])]),O.allowManualEntry?(m(),c("div",me,[e[12]||(e[12]=a("h4",{class:"text-sm font-medium text-yellow-900 mb-2"},"Manual ID Entry",-1)),a("div",pe,[s(n(D),{modelValue:v.value,"onUpdate:modelValue":e[0]||(e[0]=o=>v.value=o),placeholder:"Enter custom ID...",disabled:O.disabled,class:"flex-1"},null,8,["modelValue","disabled"]),s(n(x),{onClick:J,disabled:!v.value||O.disabled},{default:f(()=>e[10]||(e[10]=[y(" Use This ID ",-1)])),_:1,__:[10]},8,["disabled"]),s(n(x),{variant:"secondary",onClick:Q},{default:f(()=>e[11]||(e[11]=[y(" Cancel ",-1)])),_:1,__:[11]})]),e[13]||(e[13]=a("p",{class:"text-xs text-yellow-700 mt-2"}," Warning: Manual IDs should follow your organization's numbering convention ",-1))])):A("",!0),k.value?(m(),c("div",ve,[e[19]||(e[19]=a("h4",{class:"text-sm font-medium text-gray-900 mb-3"},"ID Format Configuration",-1)),a("div",ge,[s(n(W),{modelValue:t.value.template,"onUpdate:modelValue":[e[1]||(e[1]=o=>t.value.template=o),b],label:"Template",options:T},null,8,["modelValue"]),s(n(W),{modelValue:t.value.counterType,"onUpdate:modelValue":[e[2]||(e[2]=o=>t.value.counterType=o),b],label:"Counter Type",options:j},null,8,["modelValue"])]),a("div",fe,[s(n(D),{modelValue:t.value.prefix,"onUpdate:modelValue":e[3]||(e[3]=o=>t.value.prefix=o),label:"Prefix",placeholder:"WO",onInput:b},null,8,["modelValue"]),s(n(D),{modelValue:t.value.counterLength,"onUpdate:modelValue":e[4]||(e[4]=o=>t.value.counterLength=o),modelModifiers:{number:!0},label:"Counter Length",type:"number",min:"1",max:"10",onInput:b},null,8,["modelValue"]),s(n(D),{modelValue:t.value.separator,"onUpdate:modelValue":e[5]||(e[5]=o=>t.value.separator=o),label:"Separator",placeholder:"-",onInput:b},null,8,["modelValue"])]),t.value.template==="custom"?(m(),c("div",ye,[s(n(D),{modelValue:t.value.customPattern,"onUpdate:modelValue":e[6]||(e[6]=o=>t.value.customPattern=o),label:"Custom Pattern",placeholder:"{PREFIX}{SEPARATOR}{YEAR}{MONTH}{SEPARATOR}{COUNTER}",onInput:b},null,8,["modelValue"]),e[14]||(e[14]=a("p",{class:"text-xs text-gray-600 mt-1"}," Available tokens: {PREFIX}, {SEPARATOR}, {YEAR}, {MONTH}, {DAY}, {COUNTER}, {CATEGORY}, {LOCATION} ",-1))])):A("",!0),a("div",xe,[a("div",be,[e[15]||(e[15]=a("span",{class:"text-sm text-gray-600"},"Preview:",-1)),a("span",we,i(B.value),1)])]),a("div",Oe,[s(n(x),{onClick:K},{default:f(()=>e[16]||(e[16]=[y("Save Format",-1)])),_:1,__:[16]}),s(n(x),{variant:"secondary",onClick:Z},{default:f(()=>e[17]||(e[17]=[y("Reset to Default",-1)])),_:1,__:[17]}),s(n(x),{variant:"ghost",onClick:F},{default:f(()=>e[18]||(e[18]=[y("Cancel",-1)])),_:1,__:[18]})])])):A("",!0),k.value?A("",!0):(m(),c("div",ke,[e[20]||(e[20]=a("h4",{class:"text-sm font-medium text-gray-900 mb-2"},"Format Examples",-1)),a("div",Ce,[(m(),c(N,null,Y(z,o=>a("div",{key:o.name,class:"p-2 bg-gray-50 rounded border cursor-pointer hover:bg-gray-100 transition-colors",onClick:g=>ee(o)},[a("div",Ie,i(o.name),1),a("div",Se,i(o.preview),1)],8,$e)),64))])])),C.value.length>0?(m(),c("div",he,[e[21]||(e[21]=a("h4",{class:"text-sm font-medium text-gray-900 mb-2"},"Recent IDs",-1)),a("div",Pe,[(m(!0),c(N,null,Y(C.value.slice(0,5),o=>(m(),c("div",{key:o.id,class:"flex items-center justify-between text-sm p-2 bg-gray-50 rounded"},[a("span",Ae,i(o.workOrderId),1),a("span",De,i(te(o.createdAt)),1)]))),128))])])):A("",!0),a("div",Re,[e[26]||(e[26]=a("h4",{class:"text-sm font-medium text-gray-900 mb-3"},"ID Statistics",-1)),a("div",Te,[a("div",null,[e[22]||(e[22]=a("span",{class:"text-gray-600"},"Current Format:",-1)),a("span",Ve,i(G.value.name),1)]),a("div",null,[e[23]||(e[23]=a("span",{class:"text-gray-600"},"Next Counter:",-1)),a("span",_e,i(V.value),1)]),a("div",null,[e[24]||(e[24]=a("span",{class:"text-gray-600"},"Total Generated:",-1)),a("span",Ee,i(H.value),1)]),a("div",null,[e[25]||(e[25]=a("span",{class:"text-gray-600"},"This Month:",-1)),a("span",Me,i(q.value),1)])])])]))}},Le=le(Fe,[["__scopeId","data-v-f0d78cff"]]);export{Le as W};