bettertend/frontend/dist/assets/DashboardView-Ud-cY9iD.js

18 lines
42 KiB
JavaScript

import{r as z,c as G,o as ye,aO as pe,m as we,aP as xe,aQ as ne,_ as me,v as ke,f as he,i as ce,g as P,w as T,b as e,a as I,j as Y,d as V,e as A,F as le,k as q,t as C,af as se,aR as oe,n as ge,Q as ue}from"./index-QAlcqU00.js";import{u as Oe}from"./assets-CvfPiugk.js";import{F as Se,a as De}from"./FPPageHeader-CFIwZZgQ.js";import{F as de}from"./FPCard-AB6NRXg5.js";import{F as be}from"./FPModal-DMoPysvU.js";import{F as re}from"./FPBadge-DvOitM1C.js";import{u as _e}from"./useUniversalCalendar-C6fCeunY.js";import{F as Ce}from"./FPStats-DOY0PQQF.js";import"./useWorkOrders-CVmaGBfy.js";import"./useFormAutoSave-BrW9Wl2Q.js";import"./workOrder-jNxj_kjQ.js";import"./usePreventiveMaintenanceDisplay-DE1jAbPb.js";function Ee(){const d="atlas-cmms-offline",g={pendingActions:"pendingActions",offlineData:"offlineData"},F=z(!1),U=z((navigator==null?void 0:navigator.onLine)??!0),j=z(!1),b=z(null),k=z(null),H=z(0),S=z(null),R=G(()=>"indexedDB"in window&&F.value),K=G(()=>H.value>0),X=async()=>{b.value=null;try{if(!("indexedDB"in window))throw new Error("IndexedDB not supported in this browser");return new Promise((i,c)=>{const u=indexedDB.open(d,1);u.onerror=()=>{const t="Failed to initialize offline database";b.value=t,c(new Error(t))},u.onsuccess=()=>{k.value=u.result,F.value=!0,console.log("[OfflineSync] Database initialized successfully"),i()},u.onupgradeneeded=t=>{const v=t.target.result;if(!v.objectStoreNames.contains(g.pendingActions)){const h=v.createObjectStore(g.pendingActions,{keyPath:"id",autoIncrement:!0});h.createIndex("timestamp","timestamp",{unique:!1}),h.createIndex("type","type",{unique:!1}),h.createIndex("priority","priority",{unique:!1}),h.createIndex("status","status",{unique:!1})}if(!v.objectStoreNames.contains(g.offlineData)){const h=v.createObjectStore(g.offlineData,{keyPath:"id"});h.createIndex("type","type",{unique:!1}),h.createIndex("lastModified","lastModified",{unique:!1})}console.log("[OfflineSync] Database schema created/updated")}})}catch(i){throw b.value=`Failed to initialize offline database: ${i.message}`,console.error("[OfflineSync]",b.value),i}},J=()=>{k.value&&(k.value.close(),k.value=null,F.value=!1,console.log("[OfflineSync] Database connection closed"))},a=async i=>{try{if(!R.value)throw new Error("Offline sync not available");const u=k.value.transaction([g.offlineData],"readwrite").objectStore(g.offlineData),t={...i,lastModified:i.lastModified||Date.now()};await new Promise((v,h)=>{const E=u.put(t);E.onsuccess=()=>v(E.result),E.onerror=()=>h(E.error)}),console.log("[OfflineSync] Data saved offline:",i.id)}catch(c){throw b.value=`Failed to save offline data: ${c.message}`,console.error("[OfflineSync]",b.value),c}},y=async i=>{try{if(!R.value)return null;const u=k.value.transaction([g.offlineData],"readonly").objectStore(g.offlineData);return new Promise((t,v)=>{const h=u.get(i);h.onsuccess=()=>t(h.result||null),h.onerror=()=>v(h.error)})}catch(c){return console.error("[OfflineSync] Failed to get offline data:",c),null}},_=async i=>{try{if(!R.value)return[];const t=k.value.transaction([g.offlineData],"readonly").objectStore(g.offlineData).index("type");return new Promise((v,h)=>{const E=t.getAll(i);E.onsuccess=()=>v(E.result||[]),E.onerror=()=>h(E.error)})}catch(c){return console.error("[OfflineSync] Failed to get offline data by type:",c),[]}},l=async i=>{try{if(!R.value)return;const u=k.value.transaction([g.offlineData],"readwrite").objectStore(g.offlineData);await new Promise((t,v)=>{const h=u.delete(i);h.onsuccess=()=>t(),h.onerror=()=>v(h.error)}),console.log("[OfflineSync] Offline data deleted:",i)}catch(c){b.value=`Failed to delete offline data: ${c.message}`,console.error("[OfflineSync]",b.value)}},s=async()=>{try{if(!R.value)return;const c=k.value.transaction([g.offlineData],"readwrite").objectStore(g.offlineData);await new Promise((u,t)=>{const v=c.clear();v.onsuccess=()=>u(),v.onerror=()=>t(v.error)}),console.log("[OfflineSync] All offline data cleared")}catch(i){b.value=`Failed to clear offline data: ${i.message}`,console.error("[OfflineSync]",b.value)}},m=async i=>{try{if(!R.value)throw new Error("Offline sync not available");const u=k.value.transaction([g.pendingActions],"readwrite").objectStore(g.pendingActions),t={...i,timestamp:Date.now(),retryCount:0,status:"pending"};await new Promise((v,h)=>{const E=u.add(t);E.onsuccess=()=>v(E.result),E.onerror=()=>h(E.error)}),await n(),console.log("[OfflineSync] Action queued:",i.type)}catch(c){throw b.value=`Failed to queue action: ${c.message}`,console.error("[OfflineSync]",b.value),c}},D=async()=>{try{if(!R.value)return[];const c=k.value.transaction([g.pendingActions],"readonly").objectStore(g.pendingActions);return new Promise((u,t)=>{const v=c.getAll();v.onsuccess=()=>u(v.result||[]),v.onerror=()=>t(v.error)})}catch(i){return console.error("[OfflineSync] Failed to get pending actions:",i),[]}},B=async i=>{try{if(!R.value)return;const u=k.value.transaction([g.pendingActions],"readwrite").objectStore(g.pendingActions);await new Promise((t,v)=>{const h=u.delete(i);h.onsuccess=()=>t(),h.onerror=()=>v(h.error)}),await n(),console.log("[OfflineSync] Action removed from queue:",i)}catch(c){console.error("[OfflineSync] Failed to remove action:",c)}},r=async i=>{try{if(!R.value)return;const u=k.value.transaction([g.pendingActions],"readwrite").objectStore(g.pendingActions),t=await new Promise((v,h)=>{const E=u.get(i);E.onsuccess=()=>v(E.result),E.onerror=()=>h(E.error)});t&&(t.retryCount=(t.retryCount||0)+1,t.lastRetry=Date.now(),await new Promise((v,h)=>{const E=u.put(t);E.onsuccess=()=>v(),E.onerror=()=>h(E.error)}))}catch(c){console.error("[OfflineSync] Failed to update retry count:",c)}},n=async()=>{try{const i=await D();H.value=i.length}catch(i){console.error("[OfflineSync] Failed to update pending actions count:",i)}},w=async()=>{if(!U.value||j.value)return{successful:0,failed:0};j.value=!0;let i=0,c=0;try{const u=await D();for(const t of u)try{if(t.retryCount>=3){console.warn("[OfflineSync] Max retries exceeded, removing action:",t.id),await B(t.id),c++;continue}const v=await fetch(t.endpoint,{method:t.method,headers:{"Content-Type":"application/json"},body:t.data?JSON.stringify(t.data):void 0});v.ok?(await B(t.id),i++,console.log("[OfflineSync] Action synced successfully:",t.type)):(await r(t.id),c++,console.warn("[OfflineSync] Action sync failed:",t.type,v.status))}catch(v){await r(t.id),c++,console.error("[OfflineSync] Action sync error:",t.type,v.message)}S.value=new Date,console.log(`[OfflineSync] Sync completed: ${i} successful, ${c} failed`)}catch(u){b.value=`Sync failed: ${u.message}`,console.error("[OfflineSync]",b.value)}finally{j.value=!1}return{successful:i,failed:c}},O=async(i,c)=>{try{if(!U.value)return;const u=await fetch(c);if(!u.ok)throw new Error(`HTTP ${u.status}: ${u.statusText}`);const t=await u.json(),v=t.data||t;for(const h of v)await a({id:h.id,type:i,data:h,lastModified:h.lastModified||Date.now()});console.log(`[OfflineSync] ${i} data synced from server:`,v.length,"items")}catch(u){b.value=`Failed to sync ${i}: ${u.message}`,console.error("[OfflineSync]",b.value)}},x=(i,c=3e5)=>!i||!i.lastModified?!0:Date.now()-i.lastModified>c,$=()=>{const i=()=>{U.value=navigator.onLine,console.log("[OfflineSync] Network status changed:",U.value?"online":"offline"),U.value&&K.value&&setTimeout(()=>{w()},1e3)};return window.addEventListener("online",i),window.addEventListener("offline",i),()=>{window.removeEventListener("online",i),window.removeEventListener("offline",i)}},W=async()=>{var i;try{if(!((i=navigator.storage)!=null&&i.estimate))return null;const c=await navigator.storage.estimate(),u=c.quota||0,t=c.usage||0,v=u-t,h=u>0?Math.round(t/u*100):0;return{quota:u,usage:t,available:v,usagePercentage:h}}catch(c){return console.error("[OfflineSync] Failed to get storage usage:",c),null}},Q=async(i=7)=>{try{if(!R.value)return;const c=Date.now()-i*24*60*60*1e3,t=(await new Promise((E,te)=>{const ee=k.value.transaction([g.offlineData],"readonly").objectStore(g.offlineData).getAll();ee.onsuccess=()=>E(ee.result||[]),ee.onerror=()=>te(ee.error)})).filter(E=>E.lastModified<c),h=k.value.transaction([g.offlineData],"readwrite").objectStore(g.offlineData);for(const E of t)await new Promise((te,ie)=>{const Z=h.delete(E.id);Z.onsuccess=()=>te(),Z.onerror=()=>ie(Z.error)});console.log(`[OfflineSync] Cleaned up ${t.length} old data items`)}catch(c){console.error("[OfflineSync] Failed to cleanup old data:",c)}},fe=(i,c)=>!i||!c?!1:i.version!==c.version||i.lastModified!==c.lastModified,ae=(i,c,u="server-wins")=>{switch(u){case"server-wins":return c;case"client-wins":return i;case"merge":return{...i,...c,lastModified:Date.now()};default:return c}},ve=()=>{b.value=null};let f=null,o=null;return ye(async()=>{try{await X(),await n(),f=$(),o=setInterval(async()=>{U.value&&K.value&&await w()},3e5),console.log("[OfflineSync] Offline sync initialized")}catch(i){console.error("[OfflineSync] Failed to initialize:",i)}}),pe(()=>{f&&f(),o&&clearInterval(o),J()}),{isInitialized:F,isOnline:U,isSyncing:j,error:b,pendingActionsCount:H,lastSyncTime:S,isOfflineSyncAvailable:R,hasPendingActions:K,initializeDatabase:X,closeDatabase:J,saveOfflineData:a,getOfflineData:y,getOfflineDataByType:_,deleteOfflineData:l,clearOfflineData:s,queueAction:m,getPendingActions:D,removeAction:B,updateActionRetryCount:r,syncPendingActions:w,syncDataFromServer:O,needsSync:x,setupNetworkListeners:$,getStorageUsage:W,cleanupOldData:Q,hasConflict:fe,resolveConflict:ae,clearError:ve}}function Pe(){const d=Ee(),p={workOrders:{storeName:"workOrders",keyPath:"id",syncEndpoint:"/api/work-orders",ttl:24*60*60*1e3,priority:"high"},assets:{storeName:"assets",keyPath:"id",syncEndpoint:"/api/assets",ttl:24*60*60*1e3,priority:"high"},locations:{storeName:"locations",keyPath:"id",syncEndpoint:"/api/locations",ttl:7*24*60*60*1e3,priority:"medium"},users:{storeName:"users",keyPath:"id",syncEndpoint:"/api/users",ttl:24*60*60*1e3,priority:"medium"},parts:{storeName:"parts",keyPath:"id",syncEndpoint:"/api/parts",ttl:7*24*60*60*1e3,priority:"low"}},L=z({totalCachedItems:0,lastCacheUpdate:null,cacheSize:0,syncErrors:[]});z([]);const N=z(!1),M=G(()=>{const a=new Date,y=L.value.lastCacheUpdate,_=30*60*1e3;return y&&a-new Date(y)<_}),g=G(()=>d.isOnline.value&&d.hasPendingActions.value&&!d.isSyncing.value),F=async()=>{try{if(await d.initializeDatabase(),d.database.value){const a=d.database.value;if(a.version<2)return a.close(),new Promise((y,_)=>{const l=indexedDB.open("atlas-cmms-offline",2);l.onupgradeneeded=s=>{const m=s.target.result;Object.entries(p).forEach(([D,B])=>{if(!m.objectStoreNames.contains(B.storeName)){const r=m.createObjectStore(B.storeName,{keyPath:B.keyPath});r.createIndex("lastModified","lastModified",{unique:!1}),r.createIndex("syncStatus","syncStatus",{unique:!1}),console.log(`[OfflineData] Created store: ${B.storeName}`)}}),m.objectStoreNames.contains("cacheMetadata")||m.createObjectStore("cacheMetadata",{keyPath:"key"}).createIndex("lastUpdated","lastUpdated",{unique:!1})},l.onsuccess=()=>{d.database.value=l.result,N.value=!0,console.log("[OfflineData] Database upgraded for data caching"),y()},l.onerror=()=>{_(new Error("Failed to upgrade database for data caching"))}});N.value=!0}}catch(a){throw console.error("[OfflineData] Failed to initialize:",a),a}},U=async(a,y,_={})=>{if(!N.value||!p[a])throw new Error(`Invalid data type or uninitialized: ${a}`);const l=p[a],s=d.database.value;return new Promise((m,D)=>{const B=s.transaction([l.storeName],"readwrite"),r=B.objectStore(l.storeName),n=Array.isArray(y)?y:[y],w=new Date().toISOString(),O=n.map(W=>({...W,lastModified:w,cachedAt:w,syncStatus:"cached",ttl:w+l.ttl,source:_.source||"api"}));let x=0;const $=O.length;O.forEach(W=>{const Q=r.put(W);Q.onsuccess=()=>{x++,x===$&&(S(),console.log(`[OfflineData] Cached ${$} ${a} items`),m(O))},Q.onerror=()=>{D(new Error(`Failed to cache ${a} item`))}}),B.onerror=()=>{D(new Error(`Transaction failed for ${a} caching`))}})},j=async(a,y={})=>{if(!N.value||!p[a])return[];const _=p[a],l=d.database.value;return new Promise((s,m)=>{const r=l.transaction([_.storeName],"readonly").objectStore(_.storeName).getAll();r.onsuccess=()=>{let n=r.result||[];const w=new Date;if(n=n.filter(O=>O.ttl&&new Date(O.ttl)<w?(K(a,O[_.keyPath]),!1):!0),y.id&&(n=n.filter(O=>O[_.keyPath]===y.id)),y.status&&(n=n.filter(O=>O.status===y.status)),y.search){const O=y.search.toLowerCase();n=n.filter(x=>{var $,W,Q;return(($=x.title)==null?void 0:$.toLowerCase().includes(O))||((W=x.name)==null?void 0:W.toLowerCase().includes(O))||((Q=x.description)==null?void 0:Q.toLowerCase().includes(O))})}console.log(`[OfflineData] Retrieved ${n.length} cached ${a} items`),s(n)},r.onerror=()=>{m(new Error(`Failed to retrieve cached ${a}`))}})},b=async(a,y=null)=>{if(!N.value||!p[a])return;const _=p[a],l=d.database.value;return new Promise((s,m)=>{const B=l.transaction([_.storeName],"readwrite").objectStore(_.storeName);if(y){const r=B.delete(y);r.onsuccess=()=>{console.log(`[OfflineData] Invalidated ${a} item: ${y}`),S(),s()},r.onerror=()=>m(new Error(`Failed to invalidate ${a} item`))}else{const r=B.clear();r.onsuccess=()=>{console.log(`[OfflineData] Invalidated all ${a} cache`),S(),s()},r.onerror=()=>m(new Error(`Failed to clear ${a} cache`))}})},k=async(a,y=!1)=>{if(!d.isOnline.value)return console.log(`[OfflineData] Cannot sync ${a} - offline`),j(a);const _=p[a];try{if(!y&&M.value){const m=await j(a);if(m.length>0)return console.log(`[OfflineData] Using fresh cache for ${a}`),m}console.log(`[OfflineData] Syncing ${a} from network`);const l=await fetch(_.syncEndpoint);if(!l.ok)throw new Error(`Network request failed: ${l.status}`);const s=await l.json();return await U(a,s.data||s,{source:"network"}),s.data||s}catch(l){console.error(`[OfflineData] Sync failed for ${a}:`,l);const s=await j(a);if(s.length>0)return console.log(`[OfflineData] Using cached ${a} due to sync failure`),s;throw l}},H=async(a,y)=>{var s;if(!d.isOnline.value)return console.log(`[OfflineData] Cannot sync ${a} changes - offline`),!1;const _=p[a];let l=0;for(const m of y)try{const D=await fetch(_.syncEndpoint,{method:m.action==="create"?"POST":m.action==="update"?"PUT":"DELETE",headers:{"Content-Type":"application/json"},body:m.action!=="delete"?JSON.stringify(m.data):void 0});if(D.ok){if(await d.removePendingAction(m.id),l++,m.action!=="delete"&&((s=D.headers.get("content-type"))!=null&&s.includes("json"))){const B=await D.json();await U(a,B,{source:"sync"})}}else console.error(`[OfflineData] Failed to sync ${a} change:`,D.status)}catch(D){console.error(`[OfflineData] Error syncing ${a} change:`,D)}return console.log(`[OfflineData] Synced ${l}/${y.length} ${a} changes`),l===y.length},S=async()=>{if(!N.value)return;const a=d.database.value;let y=0;for(const[_,l]of Object.entries(p))try{const D=a.transaction([l.storeName],"readonly").objectStore(l.storeName).count();D.onsuccess=()=>{y+=D.result,L.value={totalCachedItems:y,lastCacheUpdate:new Date().toISOString(),cacheSize:R(y),syncErrors:L.value.syncErrors}}}catch(s){console.error("[OfflineData] Error updating cache stats:",s)}},R=a=>Math.round(a*2048/1024),K=async(a,y)=>{try{await b(a,y),console.log(`[OfflineData] Cleaned up expired ${a} item: ${y}`)}catch(_){console.error("[OfflineData] Failed to cleanup expired item:",_)}},X=async(a,y={},_={})=>{const{forceNetwork:l=!1,cacheFirst:s=!0}=_;try{if(l||!s&&d.isOnline.value)return await k(a,!0);{const m=await j(a,y);return m.length>0&&!l?(d.isOnline.value&&k(a).catch(D=>{console.warn(`[OfflineData] Background sync failed for ${a}:`,D)}),m):await k(a)}}catch(m){console.error(`[OfflineData] Failed to get ${a} data:`,m);const D=await j(a,y);if(D.length>0)return D;throw m}};we(()=>d.isOnline.value,a=>{a&&g.value&&(console.log("[OfflineData] Coming online - triggering sync"),setTimeout(()=>{J()},1e3))});const J=async()=>{if(!(!d.isOnline.value||d.isSyncing.value))try{const a=await d.getPendingActions(),y={};a.forEach(_=>{const l=_.entityType;y[l]||(y[l]=[]),y[l].push(_)});for(const[_,l]of Object.entries(y))p[_]&&await H(_,l);console.log("[OfflineData] Pending changes sync completed")}catch(a){console.error("[OfflineData] Failed to sync pending changes:",a)}};return{isInitialized:N,cacheStats:L,isCacheHealthy:M,needsSync:g,...d,initializeOfflineStores:F,cacheData:U,getCachedData:j,invalidateCache:b,syncFromNetwork:k,syncToNetwork:H,getData:X,syncPendingChanges:J,DATA_TYPES:p}}const Ae=xe("workOrders",()=>{const d=Pe(),p=z([]),L=z(null),N=z(!1),M=z(null),g=z(0),F=z({status:null,priority:null,assignedTo:null,search:"",dateRange:null}),U=G(()=>{let r=p.value;if(F.value.status&&(r=r.filter(n=>n.status===F.value.status)),F.value.priority&&(r=r.filter(n=>n.priority===F.value.priority)),F.value.assignedTo&&(r=r.filter(n=>{var w;return((w=n.assignedTo)==null?void 0:w.id)===F.value.assignedTo})),F.value.search){const n=F.value.search.toLowerCase();r=r.filter(w=>{var O,x,$;return((O=w.title)==null?void 0:O.toLowerCase().includes(n))||((x=w.description)==null?void 0:x.toLowerCase().includes(n))||(($=w.id)==null?void 0:$.toString().includes(n))})}return r}),j=G(()=>p.value.reduce((r,n)=>(r[n.status]||(r[n.status]=[]),r[n.status].push(n),r),{})),b=G(()=>p.value.reduce((r,n)=>(r[n.priority]||(r[n.priority]=[]),r[n.priority].push(n),r),{})),k=G(()=>{const r=new Date;return p.value.filter(n=>n.dueDate&&new Date(n.dueDate)<r&&n.status!=="COMPLETED")}),H=async(r={})=>{try{N.value=!0,M.value=null,d.isInitialized.value||await d.initializeOfflineStores();const n=await d.getData("workOrders",r);return p.value=Array.isArray(n)?n:n.content||[],g.value=Array.isArray(n)?n.length:n.totalElements||n.length,n}catch(n){throw M.value=n.message||"Failed to fetch work orders",n}finally{N.value=!1}};return{workOrders:p,currentWorkOrder:L,loading:N,error:M,totalCount:g,filters:F,filteredWorkOrders:U,workOrdersByStatus:j,workOrdersByPriority:b,overdueWorkOrders:k,fetchWorkOrders:H,fetchWorkOrderById:async r=>{try{N.value=!0,M.value=null,d.isInitialized.value||await d.initializeOfflineStores();const n=await d.getCachedData("workOrders",{id:r});if(n.length>0){L.value=n[0];const x=p.value.findIndex($=>$.id===r);return x>=0&&(p.value[x]=n[0]),d.isOnline.value&&d.syncFromNetwork("workOrders").catch($=>{console.warn("Background sync failed:",$)}),n[0]}const w=await ne.getById(r);L.value=w,await d.cacheData("workOrders",w);const O=p.value.findIndex(x=>x.id===r);return O!==-1&&(p.value[O]=w),w}catch(n){throw M.value=n.message||"Failed to fetch work order",n}finally{N.value=!1}},createWorkOrder:async r=>{try{if(N.value=!0,M.value=null,d.isInitialized.value||await d.initializeOfflineStores(),d.isOnline.value){const n=await ne.create(r);return p.value.unshift(n),g.value+=1,await d.cacheData("workOrders",n),n}else{const n=`temp_${Date.now()}`,w={...r,id:n,status:"DRAFT",createdAt:new Date().toISOString(),syncStatus:"pending"};return p.value.unshift(w),g.value+=1,await d.queueAction({type:"create",entityType:"workOrders",endpoint:"/api/work-orders",method:"POST",data:r,tempId:n,priority:1}),await d.cacheData("workOrders",w),w}}catch(n){throw M.value=n.message||"Failed to create work order",n}finally{N.value=!1}},updateWorkOrder:async(r,n)=>{var w,O;try{if(N.value=!0,M.value=null,d.isInitialized.value||await d.initializeOfflineStores(),d.isOnline.value){const x=await ne.update(r,n),$=p.value.findIndex(W=>W.id===r);return $!==-1&&(p.value[$]=x),((w=L.value)==null?void 0:w.id)===r&&(L.value=x),await d.cacheData("workOrders",x),x}else{const x=p.value.findIndex(Q=>Q.id===r),W={...x!==-1?p.value[x]:L.value,...n,lastModified:new Date().toISOString(),syncStatus:"pending"};return x!==-1&&(p.value[x]=W),((O=L.value)==null?void 0:O.id)===r&&(L.value=W),await d.queueAction({type:"update",entityType:"workOrders",endpoint:`/api/work-orders/${r}`,method:"PUT",data:n,itemId:r,priority:1}),await d.cacheData("workOrders",W),W}}catch(x){throw M.value=x.message||"Failed to update work order",x}finally{N.value=!1}},updateWorkOrderStatus:async(r,n,w="")=>{var O;try{N.value=!0,M.value=null;const x=await ne.updateStatus(r,n,w),$=p.value.findIndex(W=>W.id===r);return $!==-1&&(p.value[$]=x),((O=L.value)==null?void 0:O.id)===r&&(L.value=x),x}catch(x){throw M.value=x.message||"Failed to update work order status",x}finally{N.value=!1}},assignWorkOrder:async(r,n)=>{var w;try{N.value=!0,M.value=null;const O=await ne.assignWorkOrder(r,n),x=p.value.findIndex($=>$.id===r);return x!==-1&&(p.value[x]=O),((w=L.value)==null?void 0:w.id)===r&&(L.value=O),O}catch(O){throw M.value=O.message||"Failed to assign work order",O}finally{N.value=!1}},deleteWorkOrder:async r=>{var n;try{return N.value=!0,M.value=null,await ne.delete(r),p.value=p.value.filter(w=>w.id!==r),g.value-=1,((n=L.value)==null?void 0:n.id)===r&&(L.value=null),!0}catch(w){throw M.value=w.message||"Failed to delete work order",w}finally{N.value=!1}},setFilters:r=>{F.value={...F.value,...r}},clearFilters:()=>{F.value={status:null,priority:null,assignedTo:null,search:"",dateRange:null}},clearError:()=>{M.value=null},refreshFromNetwork:async(r=!1)=>{try{d.isInitialized.value||await d.initializeOfflineStores();const n=await d.syncFromNetwork("workOrders",r);return p.value=Array.isArray(n)?n:n.content||[],g.value=Array.isArray(n)?n.length:n.totalElements||n.length,n}catch(n){throw console.error("Failed to refresh from network:",n),n}},getCacheStats:()=>{var r,n,w,O;return{isOnline:((r=d.isOnline)==null?void 0:r.value)||!1,isCacheHealthy:((n=d.isCacheHealthy)==null?void 0:n.value)||!1,hasPendingActions:((w=d.hasPendingActions)==null?void 0:w.value)||!1,cacheStats:((O=d.cacheStats)==null?void 0:O.value)||{}}},clearCache:async()=>{try{d.isInitialized.value||await d.initializeOfflineStores(),await d.invalidateCache("workOrders"),console.log("[WorkOrderStore] Cache cleared successfully")}catch(r){throw console.error("[WorkOrderStore] Failed to clear cache:",r),r}},syncPendingChanges:async()=>{try{d.isInitialized.value||await d.initializeOfflineStores(),await d.syncPendingChanges(),await H()}catch(r){throw console.error("[WorkOrderStore] Failed to sync pending changes:",r),r}}}}),Ie={class:"flex items-center justify-between mb-4"},Ne={class:"flex items-center space-x-2"},$e={class:"mb-6"},Me={class:"flex items-center justify-between mb-3"},Fe={class:"text-sm font-medium text-gray-700"},Le={class:"grid grid-cols-7 gap-1 text-xs"},Te=["onClick"],je={key:0,class:"absolute bottom-0.5 left-1/2 transform -translate-x-1/2 w-1 h-1 bg-primary-500 rounded-full"},We={class:"mb-6"},ze={key:0,class:"text-center py-4"},Re={key:1,class:"space-y-2"},Be=["onClick"],qe={class:"flex-1 min-w-0"},Ue={class:"text-sm font-medium text-gray-900 truncate"},Ve={class:"text-xs text-gray-500"},He={key:0,class:"text-center py-4 text-gray-500 text-sm"},Ye={class:"mb-6"},Ge={key:0,class:"text-center py-4"},Qe={key:1,class:"space-y-2"},Ke=["onClick"],Je={class:"flex-1 min-w-0"},Xe={class:"text-sm font-medium text-gray-900 truncate"},Ze={class:"flex items-center space-x-2 text-xs text-gray-500 mt-1"},et={key:0},tt={key:1,class:"truncate"},nt={class:"flex items-center space-x-2"},rt={key:0,class:"text-center py-4 text-gray-500 text-sm"},st={key:0,class:"mb-6"},ot={class:"text-sm font-medium text-red-700 mb-3 flex items-center"},at={class:"space-y-2"},it=["onClick"],lt={class:"flex-1 min-w-0"},ct={class:"text-sm font-medium text-red-900 truncate"},dt={class:"flex items-center space-x-2 text-xs text-red-600 mt-1"},ut={key:0,class:"text-center"},ft={class:"grid grid-cols-2 gap-3 pt-4 border-t border-gray-200"},vt={class:"text-center"},gt={class:"text-lg font-semibold text-gray-900"},yt={class:"text-center"},mt={class:"text-lg font-semibold text-gray-900"},ht={key:0,class:"space-y-4"},pt={class:"flex items-center space-x-2"},wt={class:"text-sm space-y-2"},xt={key:0},kt={key:1},Ot={key:2},St={key:3},Dt={__name:"CalendarWidget",setup(d){const p=ke(),{allCalendarEvents:L,upcomingEvents:N,todaysEvents:M,overdueEvents:g,eventStatistics:F,eventTypes:U,loading:j,refreshCalendarData:b}=_e(),k=z(new Date),H=z(new Date().toISOString().split("T")[0]),S=z(null),R=z(!1),K=["S","M","T","W","T","F","S"],X=G(()=>k.value.toLocaleDateString("en-US",{month:"long",year:"numeric"})),J=G(()=>{const f=k.value.getFullYear(),o=k.value.getMonth(),i=new Date(f,o,1),c=new Date(i);c.setDate(c.getDate()-i.getDay());const u=[],t=new Date(c),v=new Date;for(let h=0;h<42;h++){const E=t.toISOString().split("T")[0];u.push({date:E,dayNumber:t.getDate(),isCurrentMonth:t.getMonth()===o,isToday:t.toDateString()===v.toDateString(),isSelected:E===H.value}),t.setDate(t.getDate()+1)}return u}),a=()=>{k.value=new Date(k.value.getFullYear(),k.value.getMonth()-1,1)},y=()=>{k.value=new Date(k.value.getFullYear(),k.value.getMonth()+1,1)},_=f=>{H.value=f},l=f=>L.value.filter(o=>{if(!o||!o.start)return!1;try{return new Date(o.start).toISOString().split("T")[0]===f}catch{return console.warn("Invalid event date:",o.start),!1}}).length,s=f=>{S.value=f,R.value=!0},m=()=>{R.value=!1,S.value=null},D=()=>{if(S.value&&S.value.extendedProps){const f=S.value.extendedProps.type,o=S.value.extendedProps.originalData;f==="WORK_ORDER"&&(o!=null&&o.id)?p.push(`/work-orders?edit=${o.id}`):f==="PREVENTIVE_MAINTENANCE"&&(o!=null&&o.id)&&p.push(`/maintenance/preventive/${o.id}`),m()}},B=async()=>{await b()},r=f=>{if(!f)return"";try{return new Date(f).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit"})}catch{return console.warn("Invalid date for formatting:",f),""}},n=f=>{if(!f)return"";try{return new Date(f).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}catch{return console.warn("Invalid date for formatting:",f),""}},w=f=>{if(!f)return"";try{const c=new Date(f)-new Date,u=Math.ceil(c/(1e3*60*60*24));return u===0?"Today":u===1?"Tomorrow":u===-1?"Yesterday":u>0?`In ${u} days`:`${Math.abs(u)} days ago`}catch{return console.warn("Invalid date for relative formatting:",f),""}},O=f=>{if(!f)return"";try{const o=new Date(f),c=new Date-o,u=Math.floor(c/(1e3*60*60*24));return u===0?"Due today":u===1?"1 day overdue":`${u} days overdue`}catch{return console.warn("Invalid date for overdue formatting:",f),""}},x=f=>f?f.charAt(0)+f.slice(1).toLowerCase():"N/A",$=f=>f?f.replace("_"," ").toLowerCase().replace(/\b\w/g,o=>o.toUpperCase()):"N/A",W=f=>{var o;return((o=U[f])==null?void 0:o.label)||f},Q=f=>f==="WORK_ORDER"?"Edit Work Order":f==="PREVENTIVE_MAINTENANCE"?"View Schedule":"View Details",fe=f=>({WORK_ORDER:"primary",PREVENTIVE_MAINTENANCE:"success",ASSET_INSPECTION:"warning",SCHEDULED_DOWNTIME:"error"})[f]||"secondary",ae=f=>({LOW:"secondary",MEDIUM:"primary",HIGH:"warning",CRITICAL:"error"})[f]||"secondary",ve=f=>({OPEN:"primary",IN_PROGRESS:"warning",COMPLETED:"success",ON_HOLD:"warning",CANCELLED:"secondary",ACTIVE:"success",PAUSED:"warning",INACTIVE:"secondary"})[f]||"secondary";return ye(async()=>{try{await b()}catch(f){console.error("Failed to initialize calendar data:",f)}}),(f,o)=>{const i=he("router-link");return P(),ce(A(de),{padding:"lg",class:"calendar-widget"},{default:T(()=>{var c,u;return[e("div",Ie,[o[3]||(o[3]=e("h3",{class:"text-lg font-semibold text-gray-900"},"Upcoming Events",-1)),e("div",Ne,[V(A(le),{variant:"ghost",size:"xs",onClick:B},{default:T(()=>o[1]||(o[1]=[e("svg",{class:"w-4 h-4",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)])),_:1,__:[1]}),V(i,{to:"/calendar",class:"text-sm text-primary-600 hover:text-primary-700 font-medium"},{default:T(()=>o[2]||(o[2]=[q(" View All → ",-1)])),_:1,__:[2]})])]),e("div",$e,[e("div",Me,[e("h4",Fe,C(X.value),1),e("div",{class:"flex items-center space-x-1"},[e("button",{onClick:a,class:"p-1 rounded hover:bg-gray-100 transition-colors"},o[4]||(o[4]=[e("svg",{class:"w-4 h-4 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M15 19l-7-7 7-7"})],-1)])),e("button",{onClick:y,class:"p-1 rounded hover:bg-gray-100 transition-colors"},o[5]||(o[5]=[e("svg",{class:"w-4 h-4 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 5l7 7-7 7"})],-1)]))])]),e("div",Le,[(P(),I(se,null,oe(K,t=>e("div",{key:t,class:"p-2 text-center text-gray-500 font-medium"},C(t),1)),64)),(P(!0),I(se,null,oe(J.value,t=>(P(),I("button",{key:t.date,onClick:v=>_(t.date),class:ge(["p-2 text-center rounded hover:bg-gray-100 transition-colors relative",{"text-gray-400":!t.isCurrentMonth,"bg-primary-100 text-primary-700 font-semibold":t.isToday,"bg-primary-50":t.isSelected,"text-gray-900":t.isCurrentMonth&&!t.isToday}])},[q(C(t.dayNumber)+" ",1),!A(j)&&l(t.date)>0?(P(),I("div",je)):Y("",!0)],10,Te))),128))])]),e("div",We,[o[7]||(o[7]=e("h4",{class:"text-sm font-medium text-gray-700 mb-3"},"Today's Events",-1)),A(j)?(P(),I("div",ze,o[6]||(o[6]=[e("div",{class:"animate-pulse"},"Loading events...",-1)]))):(P(),I("div",Re,[(P(!0),I(se,null,oe(A(M),t=>(P(),I("div",{key:t.id,class:"flex items-center space-x-3 p-3 bg-gray-50 rounded-lg hover:bg-gray-100 transition-colors cursor-pointer",onClick:v=>s(t)},[e("div",{class:"w-3 h-3 rounded-full flex-shrink-0",style:ue({backgroundColor:t.borderColor})},null,4),e("div",qe,[e("p",Ue,C(t.title),1),e("p",Ve,C(r(t.start))+" • "+C(W(t.extendedProps.type)),1)]),V(A(re),{variant:ae(t.extendedProps.priority),size:"xs"},{default:T(()=>[q(C(x(t.extendedProps.priority)),1)]),_:2},1032,["variant"])],8,Be))),128)),!A(j)&&A(M).length===0?(P(),I("div",He," No events scheduled for today ")):Y("",!0)]))]),e("div",Ye,[o[10]||(o[10]=e("h4",{class:"text-sm font-medium text-gray-700 mb-3"},"Upcoming This Week",-1)),A(j)?(P(),I("div",Ge,o[8]||(o[8]=[e("div",{class:"animate-pulse"},"Loading events...",-1)]))):(P(),I("div",Qe,[(P(!0),I(se,null,oe(A(N),t=>(P(),I("div",{key:t.id,class:"flex items-start space-x-3 p-3 bg-gray-50 rounded-lg hover:bg-gray-100 transition-colors cursor-pointer",onClick:v=>s(t)},[e("div",{class:"w-3 h-3 rounded-full flex-shrink-0 mt-0.5",style:ue({backgroundColor:t.borderColor})},null,4),e("div",Je,[e("p",Xe,C(t.title),1),e("div",Ze,[e("span",null,C(w(t.start)),1),o[9]||(o[9]=e("span",null,"•",-1)),e("span",null,C(W(t.extendedProps.type)),1),t.extendedProps.assetName?(P(),I("span",et,"•")):Y("",!0),t.extendedProps.assetName?(P(),I("span",tt,C(t.extendedProps.assetName),1)):Y("",!0)])]),e("div",nt,[V(A(re),{variant:ae(t.extendedProps.priority),size:"xs"},{default:T(()=>[q(C(x(t.extendedProps.priority)),1)]),_:2},1032,["variant"])])],8,Ke))),128)),!A(j)&&A(N).length===0?(P(),I("div",rt," No upcoming events this week ")):Y("",!0)]))]),A(g).length>0?(P(),I("div",st,[e("h4",ot,[o[11]||(o[11]=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 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)),q(" Overdue ("+C(A(g).length)+") ",1)]),e("div",at,[(P(!0),I(se,null,oe(A(g).slice(0,3),t=>(P(),I("div",{key:t.id,class:"flex items-start space-x-3 p-3 bg-red-50 border border-red-100 rounded-lg hover:bg-red-100 transition-colors cursor-pointer",onClick:v=>s(t)},[o[14]||(o[14]=e("div",{class:"w-3 h-3 rounded-full flex-shrink-0 mt-0.5 bg-red-500"},null,-1)),e("div",lt,[e("p",ct,C(t.title),1),e("div",dt,[e("span",null,C(O(t.start)),1),o[12]||(o[12]=e("span",null,"•",-1)),e("span",null,C(W(t.extendedProps.type)),1)])]),V(A(re),{variant:"error",size:"xs"},{default:T(()=>o[13]||(o[13]=[q("Overdue",-1)])),_:1,__:[13]})],8,it))),128)),A(g).length>3?(P(),I("div",ut,[V(i,{to:"/calendar?filter=overdue",class:"text-xs text-red-600 hover:text-red-700 font-medium"},{default:T(()=>[q(" View "+C(A(g).length-3)+" more overdue items → ",1)]),_:1})])):Y("",!0)])])):Y("",!0),e("div",ft,[e("div",vt,[e("div",gt,C(A(F).today),1),o[15]||(o[15]=e("div",{class:"text-xs text-gray-500"},"Today",-1))]),e("div",yt,[e("div",mt,C(A(F).upcoming),1),o[16]||(o[16]=e("div",{class:"text-xs text-gray-500"},"This Week",-1))])]),V(A(be),{modelValue:R.value,"onUpdate:modelValue":o[0]||(o[0]=t=>R.value=t),title:((c=S.value)==null?void 0:c.title)||"Event Details",size:"md",onConfirm:D,onCancel:m,"confirm-text":S.value?Q((u=S.value.extendedProps)==null?void 0:u.type):"Close","cancel-text":"Close"},{default:T(()=>{var t,v,h,E,te,ie,Z;return[S.value?(P(),I("div",ht,[e("div",pt,[V(A(re),{variant:fe((t=S.value.extendedProps)==null?void 0:t.type)},{default:T(()=>{var ee;return[q(C(W((ee=S.value.extendedProps)==null?void 0:ee.type)),1)]}),_:1},8,["variant"]),(v=S.value.extendedProps)!=null&&v.priority?(P(),ce(A(re),{key:0,variant:ae(S.value.extendedProps.priority)},{default:T(()=>[q(C(x(S.value.extendedProps.priority)),1)]),_:1},8,["variant"])):Y("",!0),(h=S.value.extendedProps)!=null&&h.status?(P(),ce(A(re),{key:1,variant:ve(S.value.extendedProps.status)},{default:T(()=>[q(C($(S.value.extendedProps.status)),1)]),_:1},8,["variant"])):Y("",!0)]),e("div",wt,[e("div",null,[o[17]||(o[17]=e("strong",null,"Time:",-1)),q(" "+C(n(S.value.start))+" at "+C(r(S.value.start)),1)]),(E=S.value.extendedProps)!=null&&E.description?(P(),I("div",xt,[o[18]||(o[18]=e("strong",null,"Description:",-1)),q(" "+C(S.value.extendedProps.description),1)])):Y("",!0),(te=S.value.extendedProps)!=null&&te.assetName?(P(),I("div",kt,[o[19]||(o[19]=e("strong",null,"Asset:",-1)),q(" "+C(S.value.extendedProps.assetName),1)])):Y("",!0),(ie=S.value.extendedProps)!=null&&ie.location?(P(),I("div",Ot,[o[20]||(o[20]=e("strong",null,"Location:",-1)),q(" "+C(S.value.extendedProps.location),1)])):Y("",!0),(Z=S.value.extendedProps)!=null&&Z.frequency?(P(),I("div",St,[o[21]||(o[21]=e("strong",null,"Frequency:",-1)),q(" "+C(S.value.extendedProps.frequency),1)])):Y("",!0)])])):Y("",!0)]}),_:1},8,["modelValue","title","confirm-text"])]}),_:1})}}},bt=me(Dt,[["__scopeId","data-v-9772e3c3"]]),_t={class:"space-y-8 p-6"},Ct={class:"grid grid-cols-1 lg:grid-cols-3 gap-8"},Et={class:"lg:col-span-2"},Pt={class:"flex items-center justify-between mb-6"},At={key:0,class:"flex justify-center py-8"},It={key:1,class:"text-center py-8 text-gray-500"},Nt={key:2,class:"space-y-4"},$t={class:"flex-1"},Mt={class:"font-medium text-gray-900"},Ft={class:"text-sm text-gray-600 mt-1"},Lt={class:"flex items-center mt-2 space-x-4"},Tt={class:"text-right text-sm text-gray-500"},jt={class:"mt-1"},Wt={class:"space-y-6"},zt={class:"grid grid-cols-1 lg:grid-cols-2 gap-8"},Rt={class:"space-y-3"},Bt={class:"space-y-4"},qt={class:"flex items-center justify-between"},Ut={class:"flex items-center"},Vt={class:"text-sm font-medium mr-2"},Ht={class:"w-16 bg-gray-200 rounded-full h-2"},Yt={class:"flex items-center justify-between"},Gt={class:"flex items-center"},Qt={class:"text-sm font-medium mr-2"},Kt={class:"w-16 bg-gray-200 rounded-full h-2"},Jt={__name:"DashboardView",setup(d){const p={template:`
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
<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" />
</svg>
`},L={template:`
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4" />
</svg>
`},N={template:`
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
<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.728-.833-2.498 0L4.316 16.5c-.77.833.192 2.5 1.732 2.5z" />
</svg>
`},M={template:`
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
`},g=Ae(),F=Oe(),U=z(!1),j=z(!1),b=G(()=>{var s;const l=g.workOrders;return{total:l.length,open:l.filter(m=>m.status==="OPEN").length,inProgress:l.filter(m=>m.status==="IN_PROGRESS").length,completed:l.filter(m=>m.status==="COMPLETED").length,critical:l.filter(m=>m.priority==="CRITICAL").length,overdue:((s=g.overdueWorkOrders)==null?void 0:s.length)||0}}),k=G(()=>{const l=F.assets;return{total:l.length,operational:l.filter(s=>s.status==="OPERATIONAL").length,down:l.filter(s=>s.status==="DOWN").length,maintenance:l.filter(s=>s.status==="MAINTENANCE").length}}),H=G(()=>[{name:"Work Orders",value:b.value.total,subtitle:`${b.value.open} open`,icon:p,iconBg:"bg-blue-100",iconColor:"text-blue-600",change:12},{name:"Assets",value:k.value.total,subtitle:`${k.value.operational} operational`,icon:L,iconBg:"bg-green-100",iconColor:"text-green-600",change:5},{name:"Critical Issues",value:b.value.critical,subtitle:"Needs attention",icon:N,iconBg:"bg-red-100",iconColor:"text-red-600",change:-8},{name:"Overdue Tasks",value:b.value.overdue,subtitle:"Past due date",icon:M,iconBg:"bg-yellow-100",iconColor:"text-yellow-600",change:-15}]),S=G(()=>g.workOrders.slice().sort((l,s)=>new Date(s.createdAt)-new Date(l.createdAt)).slice(0,5)),R=l=>({OPEN:"bg-blue-100 text-blue-800",IN_PROGRESS:"bg-yellow-100 text-yellow-800",COMPLETED:"bg-green-100 text-green-800",CANCELLED:"bg-gray-100 text-gray-800"})[l]||"bg-gray-100 text-gray-800",K=l=>({LOW:"bg-gray-100 text-gray-800",MEDIUM:"bg-blue-100 text-blue-800",HIGH:"bg-orange-100 text-orange-800",CRITICAL:"bg-red-100 text-red-800"})[l]||"bg-gray-100 text-gray-800",X=l=>l.replace("_"," ").toLowerCase().replace(/\b\w/g,s=>s.toUpperCase()),J=l=>l.toLowerCase().replace(/\b\w/g,s=>s.toUpperCase()),a=l=>new Date(l).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),y=async()=>{await _()},_=async()=>{try{U.value=!0,j.value=!0,await Promise.all([g.fetchWorkOrders({page:0,size:20}),F.fetchAssets({page:0,size:10})])}catch(l){console.error("Failed to load dashboard data:",l)}finally{U.value=!1,j.value=!1}};return ye(()=>{_()}),(l,s)=>{const m=he("router-link");return P(),ce(Se,null,{header:T(()=>[V(De,{title:"Dashboard",description:"Overview of your facility management operations",breadcrumbs:[{text:"Dashboard",to:null}]},{actions:T(()=>[V(A(le),{variant:"primary",size:"sm",onClick:y},{default:T(()=>s[3]||(s[3]=[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),q(" Refresh ",-1)])),_:1,__:[3]})]),stats:T(()=>[V(A(Ce),{stats:H.value},null,8,["stats"])]),_:1})]),default:T(()=>[e("div",_t,[e("div",Ct,[e("div",Et,[V(A(de),{padding:"lg"},{default:T(()=>[e("div",Pt,[s[5]||(s[5]=e("h3",{class:"text-lg font-semibold text-gray-900"},"Recent Work Orders",-1)),V(m,{to:"/work-orders",class:"text-sm text-primary-600 hover:text-primary-700 font-medium"},{default:T(()=>s[4]||(s[4]=[q(" View All → ",-1)])),_:1,__:[4]})]),U.value?(P(),I("div",At,s[6]||(s[6]=[e("div",{class:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary-600"},null,-1)]))):S.value.length===0?(P(),I("div",It," No work orders found ")):(P(),I("div",Nt,[(P(!0),I(se,null,oe(S.value,D=>(P(),I("div",{key:D.id,class:"flex items-center justify-between p-4 border border-gray-200 rounded hover:bg-gray-50 transition-colors"},[e("div",$t,[e("h4",Mt,C(D.title),1),e("p",Ft,C(D.description),1),e("div",Lt,[e("span",{class:ge([R(D.status),"px-2 py-1 text-xs font-medium rounded"])},C(X(D.status)),3),e("span",{class:ge([K(D.priority),"px-2 py-1 text-xs font-medium rounded"])},C(J(D.priority)),3)])]),e("div",Tt,[e("p",null,C(a(D.createdAt)),1),e("p",jt,C(D.assignee||"Unassigned"),1)])]))),128))]))]),_:1})]),e("div",Wt,[V(bt)])]),e("div",zt,[V(A(de),{padding:"lg"},{default:T(()=>[s[10]||(s[10]=e("h3",{class:"text-lg font-semibold text-gray-900 mb-4"},"Quick Actions",-1)),e("div",Rt,[V(A(le),{variant:"primary",size:"sm",block:"",onClick:s[0]||(s[0]=()=>l.$router.push("/work-orders/create"))},{default:T(()=>s[7]||(s[7]=[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 4v16m8-8H4"})],-1),q(" Create Work Order ",-1)])),_:1,__:[7]}),V(A(le),{variant:"secondary",size:"sm",block:"",onClick:s[1]||(s[1]=()=>l.$router.push("/assets"))},{default:T(()=>s[8]||(s[8]=[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 4v16m8-8H4"})],-1),q(" Add Asset ",-1)])),_:1,__:[8]}),V(A(le),{variant:"outline",size:"sm",block:"",onClick:s[2]||(s[2]=()=>l.$router.push("/reports"))},{default:T(()=>s[9]||(s[9]=[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 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"})],-1),q(" View Reports ",-1)])),_:1,__:[9]})])]),_:1,__:[10]}),V(A(de),{padding:"lg"},{default:T(()=>[s[14]||(s[14]=e("h3",{class:"text-lg font-semibold text-gray-900 mb-4"},"System Status",-1)),e("div",Bt,[e("div",qt,[s[11]||(s[11]=e("span",{class:"text-sm text-gray-600"},"Assets Operational",-1)),e("div",Ut,[e("span",Vt,C(k.value.total>0?Math.round(k.value.operational/k.value.total*100):0)+"% ",1),e("div",Ht,[e("div",{class:"bg-green-500 h-2 rounded-full transition-all duration-300",style:ue({width:`${k.value.total>0?k.value.operational/k.value.total*100:0}%`})},null,4)])])]),e("div",Yt,[s[12]||(s[12]=e("span",{class:"text-sm text-gray-600"},"Work Order Completion",-1)),e("div",Gt,[e("span",Qt,C(b.value.total>0?Math.round(b.value.completed/b.value.total*100):0)+"% ",1),e("div",Kt,[e("div",{class:"bg-blue-500 h-2 rounded-full transition-all duration-300",style:ue({width:`${b.value.total>0?b.value.completed/b.value.total*100:0}%`})},null,4)])])]),s[13]||(s[13]=e("div",{class:"flex items-center justify-between"},[e("span",{class:"text-sm text-gray-600"},"System Health"),e("span",{class:"px-2 py-1 bg-green-100 text-green-700 text-xs font-medium rounded"}," Excellent ")],-1))])]),_:1,__:[14]})])])]),_:1})}}},un=me(Jt,[["__scopeId","data-v-77944288"]]);export{un as default};