bettertend/frontend/dist/assets/LocationsListView-CZh_u7tU.js

2 lines
29 KiB
JavaScript

import{r as x,c as F,l as ke,v as we,s as xe,o as lt,m as st,i as ie,w as y,g as D,b as l,d as h,e as a,F as M,h as re,t as _,k as q,a as B,j as O,aV as it,ae as rt,n as ut,aU as ct}from"./index-BUdRbiwj.js";import{a as Ce}from"./locations-IQR_pcEX.js";import{u as dt}from"./useFormAutoSave-Jaawgo91.js";import{l as pt}from"./lodash-RqMXHFU9.js";import{F as mt,a as vt}from"./FPPageHeader-CTG2L28r.js";import{F as Z}from"./FPInput-CzR_dWoe.js";import{F as j}from"./FPSelect-C7p47Ma2.js";import{F as gt}from"./FPStats-BGfZcDZc.js";import{F as ft}from"./FPTable-CU8C_NYc.js";import{F as he}from"./FPModal-DWGF1LV8.js";import{F as Le}from"./FPBadge-BKY5dPnL.js";import{F as be}from"./FPTabs-R71V25QN.js";import{_ as yt}from"./FormRestoreNotification-DYBlXhOP.js";import"./_commonjsHelpers-NT8qMgGI.js";import"./FPCard-qHzcEQAE.js";function ht(b={}){const i=x({name:"",description:"",type:"",status:"active",address:"",latitude:null,longitude:null,parentLocationId:null,selectedTeams:[],...b}),c=x({}),v=x("basic"),C=[{key:"basic",label:"Basic Information"},{key:"address",label:"Address & Coordinates"},{key:"assignments",label:"Assignments"}],P=[{label:"Building",value:"building"},{label:"Floor",value:"floor"},{label:"Room",value:"room"},{label:"Area",value:"area"},{label:"Zone",value:"zone"},{label:"Equipment Space",value:"equipment_space"},{label:"General",value:"general"}],T=[{label:"Active",value:"active"},{label:"Inactive",value:"inactive"},{label:"Under Construction",value:"construction"},{label:"Maintenance",value:"maintenance"}],z=F(()=>[{label:"Maintenance Team",value:1},{label:"Facilities Team",value:2},{label:"Security Team",value:3}]),N=()=>{if(c.value={},!i.value.name||i.value.name.trim().length===0?c.value.name="Location name is required":i.value.name.trim().length<2&&(c.value.name="Location name must be at least 2 characters"),i.value.latitude!==null&&i.value.latitude!==void 0&&i.value.latitude!==""){const s=parseFloat(i.value.latitude);(isNaN(s)||s<-90||s>90)&&(c.value.latitude="Latitude must be between -90 and 90")}if(i.value.longitude!==null&&i.value.longitude!==void 0&&i.value.longitude!==""){const s=parseFloat(i.value.longitude);(isNaN(s)||s<-180||s>180)&&(c.value.longitude="Longitude must be between -180 and 180")}return Object.keys(c.value).length===0},U=s=>c.value[s]||null,g=()=>{c.value={}},e=()=>{i.value={name:"",description:"",type:"",status:"active",address:"",latitude:null,longitude:null,parentLocationId:null,selectedTeams:[]},c.value={},v.value="basic"},p=()=>{const s={...i.value};return s.latitude!==null&&s.latitude!==""&&(s.latitude=parseFloat(s.latitude)),s.longitude!==null&&s.longitude!==""&&(s.longitude=parseFloat(s.longitude)),s.parentLocationId&&(s.parentLocation={id:s.parentLocationId},delete s.parentLocationId),s.teams=s.selectedTeams.map(d=>({id:d})),delete s.selectedTeams,s},L=s=>{var d,w;s&&(i.value={name:s.name||"",description:s.description||"",type:s.type||"",status:s.status||"active",address:s.address||"",latitude:s.latitude||null,longitude:s.longitude||null,parentLocationId:((d=s.parentLocation)==null?void 0:d.id)||null,selectedTeams:((w=s.teams)==null?void 0:w.map(I=>I.id))||[]},g())},r=()=>{const s=C.findIndex(d=>d.key===v.value);s<C.length-1&&(v.value=C[s+1].key)},n=()=>{const s=C.findIndex(d=>d.key===v.value);s>0&&(v.value=C[s-1].key)},u=F(()=>Object.keys(c.value).length===0),k=F(()=>Object.keys(c.value).length>0),f=F(()=>v.value==="basic"),V=F(()=>v.value==="assignments");return{formData:i,errors:c,activeTab:v,formTabs:C,typeOptions:P,statusOptions:T,teamOptions:z,isValid:u,hasErrors:k,isFirstTab:f,isLastTab:V,validateForm:N,getFieldError:U,clearErrors:g,resetForm:e,getFormData:p,populateForm:L,nextTab:r,previousTab:n}}function Lt(){const b=x(null),i=x(!1),c=g=>{const e={...g};return e.name&&(e.name=e.name.trim()),e.description&&(e.description=e.description.trim()),e.latitude!==null&&e.latitude!==void 0&&e.latitude!==""?(e.latitude=parseFloat(e.latitude),isNaN(e.latitude)&&(e.latitude=null)):e.latitude=null,e.longitude!==null&&e.longitude!==void 0&&e.longitude!==""?(e.longitude=parseFloat(e.longitude),isNaN(e.longitude)&&(e.longitude=null)):e.longitude=null,e.updatedAt=new Date().toISOString(),e.createdAt||(e.createdAt=new Date().toISOString()),e},v=g=>{const e=[];g.type==="building"&&g.parentLocation&&e.push("Building type locations cannot have a parent location"),["room","area"].includes(g.type)&&!g.parentLocation&&e.push("Room and Area type locations must have a parent location");const p=g.latitude!==null&&g.latitude!==void 0,L=g.longitude!==null&&g.longitude!==void 0;return(p&&!L||!p&&L)&&e.push("Both latitude and longitude must be provided together"),{isValid:e.length===0,errors:e}},C=(g,e=[])=>{var r;if(!g)return"";const p=[];let L=g;for(;L;)p.unshift(L.name),(r=L.parentLocation)!=null&&r.id?L=e.find(n=>n.id===L.parentLocation.id):L=null;return p.join(" → ")},P=g=>{const e={building:{label:"Building",icon:"building",color:"blue",canHaveParent:!1,canHaveChildren:!0,requiresAddress:!0},floor:{label:"Floor",icon:"layers",color:"green",canHaveParent:!0,canHaveChildren:!0,requiresAddress:!1},room:{label:"Room",icon:"home",color:"yellow",canHaveParent:!0,canHaveChildren:!1,requiresAddress:!1},area:{label:"Area",icon:"map",color:"purple",canHaveParent:!0,canHaveChildren:!0,requiresAddress:!1},zone:{label:"Zone",icon:"location",color:"pink",canHaveParent:!0,canHaveChildren:!0,requiresAddress:!1},equipment_space:{label:"Equipment Space",icon:"cog",color:"orange",canHaveParent:!0,canHaveChildren:!1,requiresAddress:!1},general:{label:"General",icon:"pin",color:"gray",canHaveParent:!0,canHaveChildren:!0,requiresAddress:!1}};return e[g]||e.general},T=(g,e=null,p="")=>{if(!P(p).canHaveParent)return[{label:"No Parent Location",value:null}];const r=g.filter(n=>e&&n.id===e.id||e&&z(n,e,g)?!1:P(n.type).canHaveChildren);return[{label:"No Parent Location",value:null},...r.map(n=>({label:n.name,value:n.id}))]},z=(g,e,p)=>{var r;let L=g;for(;(r=L==null?void 0:L.parentLocation)!=null&&r.id;){if(L.parentLocation.id===e.id)return!0;L=p.find(n=>n.id===L.parentLocation.id)}return!1},N=g=>{const e={total:g.length,active:0,inactive:0,byType:{},withCoordinates:0,withParent:0};return g.forEach(p=>{p.status==="active"?e.active++:e.inactive++;const L=p.type||"general";e.byType[L]=(e.byType[L]||0)+1,p.latitude&&p.longitude&&e.withCoordinates++,p.parentLocation&&e.withParent++}),e},U=()=>{b.value=null};return{error:F(()=>b.value),processing:F(()=>i.value),processLocationData:c,validateLocationBusinessRules:v,calculateLocationHierarchy:C,getLocationTypeConfig:P,getValidParentLocations:T,isLocationChild:z,calculateLocationStats:N,clearError:U}}function bt(){const b=e=>({building:"blue",floor:"green",room:"yellow",area:"purple",zone:"pink",equipment_space:"orange",general:"gray"})[e]||"gray",i=e=>({active:"green",inactive:"red",construction:"yellow",maintenance:"orange"})[e]||"gray",c=e=>({active:"Active",inactive:"Inactive",construction:"Under Construction",maintenance:"Maintenance"})[e]||"Unknown",v=e=>({building:"Building",floor:"Floor",room:"Room",area:"Area",zone:"Zone",equipment_space:"Equipment Space",general:"General"})[e]||"General",C=e=>({building:"building",floor:"layers",room:"home",area:"map",zone:"location",equipment_space:"cog",general:"pin"})[e]||"pin",P=e=>({active:"check-circle",inactive:"x-circle",construction:"hammer",maintenance:"wrench"})[e]||"circle",T=(e,p)=>e==null||p===null||p===void 0?"No coordinates":`${e.toFixed(4)}, ${p.toFixed(4)}`;return{getTypeVariant:b,getStatusVariant:i,formatStatus:c,formatType:v,getTypeIcon:C,getStatusIcon:P,formatCoordinates:T,formatLocationAddress:e=>{if(!e)return"";const p=[];return e.address&&p.push(e.address),e.latitude&&e.longitude&&p.push(`(${T(e.latitude,e.longitude)})`),p.join(" ")||"No address"},formatLocationStats:e=>e?[{label:"Total Locations",value:e.total||0,variant:"blue",icon:"building",subtitle:"All locations"},{label:"Active Locations",value:e.active||0,variant:"green",icon:"check-circle",subtitle:`${e.total>0?Math.round(e.active/e.total*100):0}% active`},{label:"Inactive Locations",value:e.inactive||0,variant:"red",icon:"x-circle",subtitle:`${e.total>0?Math.round(e.inactive/e.total*100):0}% inactive`},{label:"Building Types",value:Object.keys(e.byType||{}).length,variant:"purple",icon:"layers",subtitle:"Unique types"}]:[],getStatusTabs:e=>[{key:"all",label:"All Locations",count:(e==null?void 0:e.total)||0},{key:"active",label:"Active",count:(e==null?void 0:e.active)||0},{key:"inactive",label:"Inactive",count:(e==null?void 0:e.inactive)||0},{key:"construction",label:"Construction",count:(e==null?void 0:e.construction)||0},{key:"maintenance",label:"Maintenance",count:(e==null?void 0:e.maintenance)||0}],getLocationTableColumns:(e=!1)=>{const p=[{key:"name",label:"Location",sortable:!0,width:"25%",essential:!0,priority:"high"},{key:"hierarchy",label:"Hierarchy",sortable:!1,width:"20%",priority:"medium"},{key:"address",label:"Address",sortable:!0,width:"20%",priority:"low"},{key:"type",label:"Type",sortable:!0,width:"10%",essential:!0,priority:"high"},{key:"status",label:"Status",sortable:!0,width:"10%",essential:!0,priority:"high"},{key:"assets",label:"Assets",sortable:!1,width:"8%",priority:"medium"},{key:"workOrders",label:"Work Orders",sortable:!1,width:"8%",priority:"low"},{key:"actions",label:"Actions",sortable:!1,width:"12%",essential:!0,priority:"high"}];return e?p.filter(L=>L.essential||L.priority==="high"):p}}}function kt(){const b=Ce(),{showNotification:i}=ke(),c=x(!1),v=x(null),C=async(n,u=!1,k=null)=>{c.value=!0,v.value=null;try{let f;return u&&k?(f=await b.updateLocation(k,n),i("success","Location updated successfully")):(f=await b.createLocation(n),i("success","Location created successfully")),f}catch(f){const V=u?"Failed to update location":"Failed to create location";throw v.value=f.message,i("error",V),console.error("Location submission error:",f),f}finally{c.value=!1}},P=async n=>{c.value=!0,v.value=null;try{await b.deleteLocation(n),i("success","Location deleted successfully")}catch(u){throw v.value=u.message,i("error","Failed to delete location"),console.error("Location deletion error:",u),u}finally{c.value=!1}},T=async()=>{c.value=!0,v.value=null;try{await b.refreshLocations(),i("success","Locations refreshed successfully")}catch(n){throw v.value=n.message,i("error","Failed to refresh locations"),console.error("Locations refresh error:",n),n}finally{c.value=!1}},z=async n=>{c.value=!0,v.value=null;try{return await b.getLocationById(parseInt(n))}catch(u){throw v.value=u.message,i("error","Failed to load location for editing"),console.error("Location load error:",u),u}finally{c.value=!1}},N=async(n={})=>{c.value=!0,v.value=null;try{i("info","Export feature coming soon")}catch(u){throw v.value=u.message,i("error","Failed to export locations"),console.error("Location export error:",u),u}finally{c.value=!1}},U=async(n,u,k)=>{if(!n())return{isValid:!1,type:"form",message:"Please fix the validation errors before submitting"};const f=u(k);return f.isValid?{isValid:!0}:{isValid:!1,type:"business",message:f.errors.join(", ")}};return{isProcessing:c,error:v,handleLocationSubmission:C,handleLocationDeletion:P,handleLocationLoad:z,handleLocationsRefresh:T,handleLocationExport:N,submitLocation:async({validateForm:n,validateBusinessRules:u,getFormData:k,processLocationData:f,isEditMode:V=!1,locationId:s=null,onSuccess:d=null,onError:w=null})=>{try{const I=k(),J=f(I),H=await U(n,u,J);if(!H.isValid)return i("error",H.message),w&&w(new Error(H.message)),{success:!1,error:H.message};const R=await C(J,V,s);return d&&d(R),{success:!0,data:R}}catch(I){return w&&w(I),{success:!1,error:I.message}}},validateLocationSubmission:U,handleLocationSearch:async(n,u={})=>{try{await b.updateSearchTerm(n),Object.keys(u).length>0&&await b.updateFilters(u)}catch(k){v.value=k.message,console.error("Location search error:",k)}},handleLocationPagination:async n=>{try{await b.changePage(n-1)}catch(u){v.value=u.message,console.error("Location pagination error:",u)}},handleLocationSorting:async n=>{try{await b.changeSorting(n.column,n.direction)}catch(u){v.value=u.message,console.error("Location sorting error:",u)}},clearError:()=>{v.value=null}}}function wt(){const b=we(),i=xe(),{showNotification:c}=ke(),v=r=>{b.push(`/locations/${r.id}`)},C=r=>{b.push(`/locations?edit=${r.id}`)},P=(r={})=>{const n={create:"true"};r.parentId&&(n.parentId=r.parentId),r.type&&(n.type=r.type),b.push({path:"/locations",query:n})},T=()=>{b.replace({path:"/locations"})};return{navigateToLocationDetail:v,navigateToLocationEdit:C,navigateToLocationCreate:P,navigateToLocationsList:T,handleLocationQueryParams:async(r,n,u)=>{const k=i.query.edit,f=i.query.create==="true",V=i.query.parentId,s=i.query.type;try{k?setTimeout(async()=>{try{const d=await u(parseInt(k));r(d),T()}catch{c("error","Failed to load location for editing"),T()}},500):f&&setTimeout(()=>{const d={};V&&(d.parentId=parseInt(V)),s&&(d.type=s),n(d),T()},500)}catch{c("error","Failed to handle navigation parameters"),T()}},getLocationRouteParams:()=>({editLocationId:i.query.edit?parseInt(i.query.edit):null,shouldCreate:i.query.create==="true",parentId:i.query.parentId?parseInt(i.query.parentId):null,locationType:i.query.type||null,searchTerm:i.query.search||"",status:i.query.status||"all",type:i.query.type||"",page:i.query.page?parseInt(i.query.page):1}),updateLocationRouteParams:r=>{const n={...i.query};Object.keys(r).forEach(u=>{r[u]!==null&&r[u]!==void 0&&r[u]!==""?n[u]=r[u]:delete n[u]}),b.replace({path:i.path,query:Object.keys(n).length>0?n:void 0})},navigateWithLocationFilters:r=>{const n={};r.search&&(n.search=r.search),r.status&&r.status!=="all"&&(n.status=r.status),r.type&&(n.type=r.type),r.parent&&(n.parent=r.parent),r.page&&r.page>1&&(n.page=r.page),b.push({path:"/locations",query:n})},getLocationBreadcrumbs:(r,n=[])=>{var V;const u=[{text:"Locations",to:"/locations"}];if(!r)return u;const k=[];let f=r;for(;f;)k.unshift({text:f.name,to:`/locations/${f.id}`}),(V=f.parentLocation)!=null&&V.id?f=n.find(s=>s.id===f.parentLocation.id):f=null;return[...u,...k]},handleLocationBack:(r=null)=>{history.length>1?b.back():b.push("/locations"),r&&r()},generateLocationDeepLink:(r,n={})=>{const u=window.location.origin;let k=`/locations/${r.id}`;const f={};n.action==="edit"&&(f.edit=r.id),n.parentId&&(f.parentId=n.parentId);const V=Object.keys(f).length>0?"?"+new URLSearchParams(f).toString():"";return`${u}${k}${V}`}}}const xt={class:"p-6"},Ct={class:"mb-6 grid grid-cols-1 md:grid-cols-4 gap-4"},Ft={class:"bg-white shadow rounded-lg overflow-hidden"},Tt={class:"flex items-center space-x-3"},Vt={class:"font-medium text-gray-900"},St={class:"text-sm text-gray-500"},It={class:"text-sm"},_t={class:"text-gray-600"},Pt={class:"text-sm"},Dt={class:"text-gray-900"},qt={key:0,class:"text-xs text-gray-500 mt-1"},At={class:"text-sm text-center"},Mt={class:"font-medium text-gray-900"},zt={class:"text-sm text-center"},Ut={class:"font-medium text-gray-900"},Bt={class:"flex items-center space-x-2"},Nt={class:"border-b border-gray-200 mb-6"},Ht={key:0,class:"space-y-6"},Ot={class:"grid grid-cols-1 md:grid-cols-2 gap-6"},jt={class:"md:col-span-2"},Rt={key:0,class:"mt-1 text-sm text-red-600"},Et={key:1,class:"space-y-6"},$t={class:"space-y-4"},Gt={class:"grid grid-cols-1 md:grid-cols-2 gap-4"},Qt={key:2,class:"space-y-6"},Wt={class:"space-y-4"},Zt={class:"flex items-center justify-between"},Jt={class:"flex items-center space-x-4"},Xt={key:0,class:"flex items-center text-sm text-gray-500"},Yt={key:0,class:"w-4 h-4 mr-2 text-amber-500 animate-pulse",fill:"currentColor",viewBox:"0 0 20 20"},Kt={key:1,class:"w-4 h-4 mr-2 text-green-500",fill:"currentColor",viewBox:"0 0 20 20"},ea={key:2},ta={key:3},aa={class:"flex space-x-3"},oa={class:"space-y-4"},na={class:"text-gray-600"},la={class:"text-gray-900"},sa={class:"flex justify-end space-x-3"},wa={__name:"LocationsListView",setup(b){we();const i=xe(),c=Ce(),{processLocationData:v,getValidParentLocations:C}=Lt(),{getTypeVariant:P,getStatusVariant:T,formatStatus:z,formatLocationStats:N,getStatusTabs:U,getLocationTableColumns:g}=bt(),{submitLocation:e,handleLocationDeletion:p,handleLocationsRefresh:L,handleLocationExport:r,handleLocationLoad:n,handleLocationSearch:u,handleLocationPagination:k,handleLocationSorting:f}=kt(),{navigateToLocationDetail:V,handleLocationQueryParams:s}=wt(),{formData:d,errors:w,activeTab:I,formTabs:J,typeOptions:H,statusOptions:R,teamOptions:Fe,isLastTab:Te,validateForm:Ve,resetForm:ue,getFormData:Se,populateForm:Ie,nextTab:_e}=ht(),{hasUnsavedChanges:te,lastSaveTime:X,restoreFormData:Pe,clearSavedData:ce,hasSavedData:de,getSavedDataInfo:De,markUserInteraction:qe,finishInitialization:Ae}=dt(d,{storageKey:"atlas_location_form_data",saveInterval:3e3,excludeFields:[]}),E=x(!1),pe=x(null),ae=x("all"),S=x({search:"",type:"",parent:"",status:""}),$=x(!1),Y=x("create"),G=x(null),Q=x(!1),K=x(null),oe=x(!1);x(!1);const Me=F(()=>c.loading.value),ze=F(()=>c.filteredLocations.value),me=F(()=>c.locationStats.value),ne=F(()=>Y.value==="edit"),Ue=F(()=>N(me.value)),Be=F(()=>X.value?new Date(X.value).toLocaleTimeString():""),ve=F(()=>C(c.miniLocations.value||[],G.value,d.value.type)),Ne=F(()=>U(me.value)),He=F(()=>{var m,t,o,W;return{currentPage:(((m=c.searchCriteria.value)==null?void 0:m.page)||0)+1,totalPages:((t=c.locations.value)==null?void 0:t.totalPages)||0,totalItems:((o=c.locations.value)==null?void 0:o.totalElements)||0,pageSize:((W=c.searchCriteria.value)==null?void 0:W.size)||10}}),Oe=F(()=>g(!1)),je=[{label:"All Types",value:""},...H.map(m=>({label:m.label,value:m.value}))],Re=[{label:"All Statuses",value:""},...R.map(m=>({label:m.label,value:m.value}))],Ee=pt.debounce(m=>{u(m,S.value)},300),ee=()=>{u(S.value.search,{type:S.value.type,parent:S.value.parent,status:S.value.status})},$e=m=>{ae.value=m,S.value.status=m==="all"?"":m,ee()},Ge=m=>{f(m)},Qe=m=>{k(m)},We=m=>{V(m)},le=async()=>{await L()},ge=()=>{G.value=null,Y.value="create",Ze(),de()||ue(),$.value=!0},Ze=()=>{Y.value==="create"&&de()&&(pe.value=De(),E.value=!0,console.log("✅ Found saved location data, showing restore notification"))},fe=m=>{G.value=m,Y.value="edit",Ie(m),Ae(),$.value=!0},Je=m=>{K.value=m,Q.value=!0},Xe=async()=>{try{await p(K.value.id),Q.value=!1,K.value=null,await le()}catch{}},se=()=>{$.value=!1,G.value=null,E.value=!1},Ye=async()=>{var m;oe.value=!0;try{(await e({validateForm:Ve,validateBusinessRules,getFormData:Se,processLocationData:v,isEditMode:ne.value,locationId:(m=G.value)==null?void 0:m.id})).success&&(ce(),se(),await le())}finally{oe.value=!1}},Ke=m=>{A(),_e()},et=()=>{Pe(),E.value=!1,console.log("Location form data restored successfully")},tt=()=>{ce(),E.value=!1,ue(),console.log("Location auto-saved data dismissed")},at=async()=>{await r(S.value)},ot=m=>c.getLocationDisplayName(m),ye=()=>{s(fe,ge,n)},A=()=>{console.log("🔥 Location user interaction detected!"),qe()},nt=m=>{I.value=m,A()};return lt(async()=>{await c.initializeLocations(),ye()}),st(()=>i.query,ye),(m,t)=>(D(),ie(mt,null,{header:y(()=>[h(vt,{title:"Locations",description:"Manage and organize facility locations and spaces",breadcrumbs:[{text:"Locations",to:null}]},{actions:y(()=>[h(a(M),{variant:"outline",size:"sm",onClick:at},{default:y(()=>t[19]||(t[19]=[l("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[l("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),q(" Export ",-1)])),_:1,__:[19]}),h(a(M),{variant:"outline",size:"sm",onClick:le},{default:y(()=>t[20]||(t[20]=[l("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[l("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,__:[20]}),h(a(M),{variant:"primary",size:"sm",onClick:ge},{default:y(()=>t[21]||(t[21]=[l("svg",{class:"w-4 h-4 mr-2",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[l("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 4v16m8-8H4"})],-1),q(" Add Location ",-1)])),_:1,__:[21]})]),stats:y(()=>[h(a(gt),{stats:Ue.value},null,8,["stats"])]),tabs:y(()=>[h(a(be),{modelValue:ae.value,"onUpdate:modelValue":t[0]||(t[0]=o=>ae.value=o),tabs:Ne.value,onTabChange:$e},null,8,["modelValue","tabs"])]),_:1})]),default:y(()=>[l("div",xt,[l("div",Ct,[h(a(Z),{modelValue:S.value.search,"onUpdate:modelValue":t[1]||(t[1]=o=>S.value.search=o),placeholder:"Search locations...",onInput:a(Ee)},{prepend:y(()=>t[22]||(t[22]=[l("svg",{class:"w-4 h-4 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[l("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})],-1)])),_:1},8,["modelValue","onInput"]),h(a(j),{modelValue:S.value.type,"onUpdate:modelValue":[t[2]||(t[2]=o=>S.value.type=o),ee],placeholder:"Filter by Type",options:je},null,8,["modelValue"]),h(a(j),{modelValue:S.value.parent,"onUpdate:modelValue":[t[3]||(t[3]=o=>S.value.parent=o),ee],placeholder:"Filter by Parent Location",options:ve.value},null,8,["modelValue","options"]),h(a(j),{modelValue:S.value.status,"onUpdate:modelValue":[t[4]||(t[4]=o=>S.value.status=o),ee],placeholder:"Filter by Status",options:Re},null,8,["modelValue"])]),l("div",Ft,[h(a(ft),{columns:Oe.value,data:ze.value,loading:Me.value,pagination:He.value,"empty-message":"No locations found",onSortChange:Ge,onPageChange:Qe,onRowClick:We},{"column-name":y(({row:o})=>[l("div",Tt,[t[23]||(t[23]=l("div",{class:"w-8 h-8 bg-green-100 rounded-lg flex items-center justify-center"},[l("svg",{class:"w-4 h-4 text-green-600",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[l("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"}),l("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M15 11a3 3 0 11-6 0 3 3 0 016 0z"})])],-1)),l("div",null,[l("h4",Vt,_(o.name),1),l("p",St,_(o.description||"No description"),1)])])]),"column-hierarchy":y(({row:o})=>[l("div",It,[l("span",_t,_(ot(o)),1)])]),"column-address":y(({row:o})=>[l("div",Pt,[l("span",Dt,_(o.address||"No address"),1),o.latitude&&o.longitude?(D(),B("div",qt,_(o.latitude.toFixed(4))+", "+_(o.longitude.toFixed(4)),1)):O("",!0)])]),"column-type":y(({row:o})=>[h(a(Le),{variant:a(P)(o.type)},{default:y(()=>[q(_(o.type||"General"),1)]),_:2},1032,["variant"])]),"column-status":y(({row:o})=>[h(a(Le),{variant:a(T)(o.status)},{default:y(()=>[q(_(a(z)(o.status)),1)]),_:2},1032,["variant"])]),"column-assets":y(({row:o})=>[l("div",At,[l("span",Mt,_(o.assetsCount||0),1),t[24]||(t[24]=l("span",{class:"text-gray-500 block text-xs"},"Assets",-1))])]),"column-workOrders":y(({row:o})=>[l("div",zt,[l("span",Ut,_(o.workOrdersCount||0),1),t[25]||(t[25]=l("span",{class:"text-gray-500 block text-xs"},"Work Orders",-1))])]),"column-actions":y(({row:o})=>[l("div",Bt,[h(a(M),{variant:"ghost",size:"xs",onClick:re(W=>m.viewLocation(o),["stop"]),title:"View Details"},{default:y(()=>t[26]||(t[26]=[l("svg",{class:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[l("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),l("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})],-1)])),_:2,__:[26]},1032,["onClick"]),h(a(M),{variant:"ghost",size:"xs",onClick:re(W=>fe(o),["stop"]),title:"Edit Location"},{default:y(()=>t[27]||(t[27]=[l("svg",{class:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[l("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)])),_:2,__:[27]},1032,["onClick"]),h(a(M),{variant:"ghost",size:"xs",onClick:re(W=>Je(o),["stop"]),title:"Delete Location",class:"text-red-600 hover:text-red-700"},{default:y(()=>t[28]||(t[28]=[l("svg",{class:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[l("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)])),_:2,__:[28]},1032,["onClick"])])]),_:1},8,["columns","data","loading","pagination"])]),h(a(he),{modelValue:$.value,"onUpdate:modelValue":t[16]||(t[16]=o=>$.value=o),title:ne.value?"Edit Location":"Create Location",size:"xl",onCancel:se},{footer:y(()=>[l("div",Zt,[l("div",Jt,[a(te)||a(X)?(D(),B("div",Xt,[a(te)?(D(),B("svg",Yt,t[31]||(t[31]=[l("path",{"fill-rule":"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm1-12a1 1 0 10-2 0v4a1 1 0 00.293.707l2.828 2.829a1 1 0 101.415-1.415L11 9.586V6z","clip-rule":"evenodd"},null,-1)]))):(D(),B("svg",Kt,t[32]||(t[32]=[l("path",{"fill-rule":"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z","clip-rule":"evenodd"},null,-1)]))),a(te)?(D(),B("span",ea,"Auto-saving...")):a(X)?(D(),B("span",ta,"Last saved "+_(Be.value),1)):O("",!0)])):O("",!0)]),l("div",aa,[h(a(M),{variant:"secondary",onClick:se},{default:y(()=>t[33]||(t[33]=[q(" Cancel ",-1)])),_:1,__:[33]}),a(Te)?(D(),ie(a(M),{key:1,variant:"primary",loading:oe.value,onClick:Ye},{default:y(()=>[q(_(ne.value?"Update Location":"Create Location"),1)]),_:1},8,["loading"])):(D(),ie(a(M),{key:0,variant:"primary",onClick:t[15]||(t[15]=o=>Ke("next"))},{default:y(()=>t[34]||(t[34]=[q(" Next ",-1)])),_:1,__:[34]}))])])]),default:y(()=>[h(a(yt),{visible:E.value,"saved-data-info":pe.value,onRestore:et,onDismiss:tt},null,8,["visible","saved-data-info"]),l("div",Nt,[h(a(be),{modelValue:a(I),"onUpdate:modelValue":t[5]||(t[5]=o=>it(I)?I.value=o:null),tabs:a(J),onTabChange:nt},null,8,["modelValue","tabs"])]),a(I)==="basic"?(D(),B("div",Ht,[l("div",Ot,[h(a(Z),{modelValue:a(d).name,"onUpdate:modelValue":t[6]||(t[6]=o=>a(d).name=o),label:"Location Name",placeholder:"Enter location name",required:"",error:a(w).name,onInput:A},null,8,["modelValue","error"]),h(a(j),{modelValue:a(d).type,"onUpdate:modelValue":t[7]||(t[7]=o=>a(d).type=o),label:"Location Type",placeholder:"Select location type",options:a(H),error:a(w).type,onChange:A},null,8,["modelValue","options","error"]),l("div",jt,[t[29]||(t[29]=l("label",{class:"block text-sm font-medium text-gray-700 mb-1"},"Description",-1)),rt(l("textarea",{"onUpdate:modelValue":t[8]||(t[8]=o=>a(d).description=o),class:ut(["w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500",{"border-red-300":a(w).description}]),placeholder:"Describe the location...",rows:"3",onInput:A},null,34),[[ct,a(d).description]]),a(w).description?(D(),B("p",Rt,_(a(w).description),1)):O("",!0)]),h(a(j),{modelValue:a(d).parentLocationId,"onUpdate:modelValue":t[9]||(t[9]=o=>a(d).parentLocationId=o),label:"Parent Location",placeholder:"Select parent location (optional)",options:ve.value,error:a(w).parentLocationId,onChange:A},null,8,["modelValue","options","error"]),h(a(j),{modelValue:a(d).status,"onUpdate:modelValue":t[10]||(t[10]=o=>a(d).status=o),label:"Status",placeholder:"Select status",options:a(R),error:a(w).status,onChange:A},null,8,["modelValue","options","error"])])])):O("",!0),a(I)==="address"?(D(),B("div",Et,[l("div",$t,[h(a(Z),{modelValue:a(d).address,"onUpdate:modelValue":t[11]||(t[11]=o=>a(d).address=o),label:"Street Address",placeholder:"Enter full address",error:a(w).address,onInput:A},null,8,["modelValue","error"]),l("div",Gt,[h(a(Z),{modelValue:a(d).latitude,"onUpdate:modelValue":t[12]||(t[12]=o=>a(d).latitude=o),label:"Latitude",placeholder:"e.g., 40.7128",type:"number",step:"any",error:a(w).latitude,onInput:A},null,8,["modelValue","error"]),h(a(Z),{modelValue:a(d).longitude,"onUpdate:modelValue":t[13]||(t[13]=o=>a(d).longitude=o),label:"Longitude",placeholder:"e.g., -74.0060",type:"number",step:"any",error:a(w).longitude,onInput:A},null,8,["modelValue","error"])])])])):O("",!0),a(I)==="assignments"?(D(),B("div",Qt,[l("div",Wt,[l("div",null,[t[30]||(t[30]=l("label",{class:"block text-sm font-medium text-gray-700 mb-2"}," Assigned Teams ",-1)),h(a(j),{modelValue:a(d).selectedTeams,"onUpdate:modelValue":t[14]||(t[14]=o=>a(d).selectedTeams=o),placeholder:"Select teams to assign to this location",options:a(Fe),multiple:"",error:a(w).teams,onChange:A},null,8,["modelValue","options","error"])])])])):O("",!0)]),_:1},8,["modelValue","title"]),h(a(he),{modelValue:Q.value,"onUpdate:modelValue":t[18]||(t[18]=o=>Q.value=o),title:"Delete Location",size:"md"},{footer:y(()=>[l("div",sa,[h(a(M),{variant:"secondary",onClick:t[17]||(t[17]=o=>Q.value=!1)},{default:y(()=>t[37]||(t[37]=[q(" Cancel ",-1)])),_:1,__:[37]}),h(a(M),{variant:"danger",onClick:Xe},{default:y(()=>t[38]||(t[38]=[q(" Delete Location ",-1)])),_:1,__:[38]})])]),default:y(()=>{var o;return[l("div",oa,[l("p",na,[t[35]||(t[35]=q(" Are you sure you want to delete ",-1)),l("strong",la,"'"+_((o=K.value)==null?void 0:o.name)+"'",1),t[36]||(t[36]=q("? This action cannot be undone. ",-1))])])]}),_:1},8,["modelValue"])])]),_:1}))}};export{wa as default};