@nice2dev/ui-buildings 1.4.3 → 1.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,10 +1,10 @@
1
- "use strict";var gs=Object.defineProperty;var fs=(t,n,s)=>n in t?gs(t,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[n]=s;var St=(t,n,s)=>fs(t,typeof n!="symbol"?n+"":n,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),w=require("@nice2dev/ui"),u=require("react"),_s={light:"lightbulb",dimmer:"lightbulb",rgb_light:"lightbulb",led_strip:"lightbulb",thermostat:"thermometer",heater:"thermometer",air_conditioner:"thermometer",fan:"refresh",heat_pump:"thermometer",lock:"lock",door:"door",window:"window",blind:"columns",shutter:"columns",garage:"home",gate:"door",switch:"plug",outlet:"plug",smart_plug:"plug",power_strip:"plug",camera:"camera",doorbell:"bell",alarm:"bell",siren:"bell",motion_sensor:"eye",door_sensor:"door",window_sensor:"window",smoke_detector:"warning",co_detector:"warning",water_leak:"droplet",gas_detector:"warning",temperature_sensor:"thermometer",humidity_sensor:"droplet",air_quality:"cloud",light_sensor:"sun",presence_sensor:"user",speaker:"volume",tv:"monitor",media_player:"play",vacuum:"refresh",washing_machine:"refresh",dishwasher:"utensils",oven:"utensils",fridge:"box",irrigation:"droplet",pool:"droplet",ev_charger:"zap",solar_panel:"sun",battery:"zap",energy_meter:"zap",hub:"wifi",router:"wifi",other:"settings"};function Vn(t){return _s[t]??"settings"}const bs="_root_1nq8c_1",ys="_shell_1nq8c_27",xs="_dark_1nq8c_35",vs="_topBar_1nq8c_49",js="_floorTabs_1nq8c_79",ws="_floorTab_1nq8c_79",Ns="_floorTabActive_1nq8c_119",Is="_overlayControls_1nq8c_131",ks="_overlayBtn_1nq8c_143",Ss="_overlayBtnActive_1nq8c_179",Cs="_zoomBar_1nq8c_191",Ts="_toolPalette_1nq8c_245",Ls="_toolBtn_1nq8c_275",$s="_toolBtnActive_1nq8c_311",zs="_canvasWrapper_1nq8c_325",Ps="_canvas_1nq8c_325",Es="_cur_select_1nq8c_365",Os="_cur_drawzone_1nq8c_371",Ms="_cur_drawwall_1nq8c_377",As="_cur_placedevice_1nq8c_383",Ds="_cur_placedoor_1nq8c_389",Bs="_cur_placewindow_1nq8c_395",Rs="_cur_pan_1nq8c_401",Fs="_cur_erase_1nq8c_407",Gs="_cur_measure_1nq8c_413",qs="_cur_annotate_1nq8c_419",Vs="_gridLine_1nq8c_429",Ws="_zoneGroup_1nq8c_447",Hs="_zonePath_1nq8c_455",Us="_zoneLabel_1nq8c_463",Ys="_climateLabel_1nq8c_485",Zs="_occupancyLabel_1nq8c_497",Xs="_dimLabel_1nq8c_509",Ks="_deviceGroup_1nq8c_521",Js="_devCircle_1nq8c_529",Qs="_devOnline_1nq8c_541",eo="_devOffline_1nq8c_547",to="_devSelected_1nq8c_553",no="_propPanel_1nq8c_565",so="_propTitle_1nq8c_593",oo="_propRow_1nq8c_615",ao="_statusBar_1nq8c_655",io="_emptyState_1nq8c_687",ie={root:bs,shell:ys,dark:xs,topBar:vs,floorTabs:js,floorTab:ws,floorTabActive:Ns,overlayControls:Is,overlayBtn:ks,overlayBtnActive:Ss,zoomBar:Cs,toolPalette:Ts,toolBtn:Ls,toolBtnActive:$s,canvasWrapper:zs,canvas:Ps,cur_select:Es,cur_drawzone:Os,cur_drawwall:Ms,cur_placedevice:As,cur_placedoor:Ds,cur_placewindow:Bs,cur_pan:Rs,cur_erase:Fs,cur_measure:Gs,cur_annotate:qs,gridLine:Vs,zoneGroup:Ws,zonePath:Hs,zoneLabel:Us,climateLabel:Ys,occupancyLabel:Zs,dimLabel:Xs,deviceGroup:Ks,devCircle:Js,devOnline:Qs,devOffline:eo,devSelected:to,propPanel:no,propTitle:so,propRow:oo,statusBar:ao,emptyState:io},ro=[{target:".nice-floor-plan-editor",titleKey:"tutorial.floorPlanEditor.intro.title",title:"Floor plan editor",contentKey:"tutorial.floorPlanEditor.intro.content",content:"Draw rooms and zones with the tools, place devices on the plan, switch floors and toggle overlays like dimensions, grid and occupancy.",placement:"auto"}],co={living_room:"var(--nice-primary-bg, #dbeafe)",bedroom:"var(--nice-accent-tint-10, #fce7f3)",master_bedroom:"var(--nice-accent-tint-12, #f3e8ff)",kids_room:"var(--nice-warning-bg, #fef3c7)",bathroom:"var(--nice-info-bg, #cffafe)",kitchen:"var(--nice-warning-bg, #fef9c3)",dining_room:"var(--nice-warning-bg, #fde8d8)",hallway:"var(--nice-bg-secondary, #f1f5f9)",office:"var(--nice-success-bg, #dcfce7)",garage:"var(--nice-border, #e2e8f0)",basement:"var(--nice-border, #e5e7eb)",attic:"var(--nice-success-bg, #f0fdf4)",balcony:"var(--nice-success-bg, #ecfdf5)",garden:"var(--nice-success-bg, #d1fae5)",gym:"var(--nice-danger-bg, #fee2e2)",cinema:"var(--nice-accent-tint-10, #ede9fe)",open_office:"var(--nice-success-bg, #dcfce7)",private_office:"var(--nice-success-bg, #d1fae5)",meeting_room:"var(--nice-primary-bg, #dbeafe)",boardroom:"var(--nice-accent-tint-10, #ede9fe)",reception:"var(--nice-warning-bg, #fef3c7)",waiting_area:"var(--nice-warning-bg, #fef9c3)",server_room:"var(--nice-danger-bg, #fee2e2)",it_room:"var(--nice-warning-bg, #fde8d8)",break_room:"var(--nice-accent-tint-10, #fce7f3)",lobby:"var(--nice-primary-bg, #f0f4ff)",corridor:"var(--nice-bg-secondary, #f8fafc)",stairwell:"var(--nice-bg-secondary, #f1f5f9)",parking:"var(--nice-border, #e2e8f0)",mechanical_room:"var(--nice-bg-secondary, #f3f4f6)"};function lo(t){return co[t]??"var(--nice-primary-bg, #f0f4ff)"}function Wn(t){if(!t.length)return{x:0,y:0};const n=t.reduce((s,o)=>({x:s.x+o.x,y:s.y+o.y}),{x:0,y:0});return{x:n.x/t.length,y:n.y/t.length}}function _n(t,n=!0){return t.length<2?"":t.map((s,o)=>`${o===0?"M":"L"}${s.x.toFixed(1)},${s.y.toFixed(1)}`).join(" ")+(n?" Z":"")}function uo(t,n){if(!t)return n?Wn(n.polygon):null;if(!n||!n.polygon.length||t.x>1||t.y>1)return t;const s=n.polygon.map(c=>c.x),o=n.polygon.map(c=>c.y),i=Math.min(...s),a=Math.min(...o);return{x:i+t.x*(Math.max(...s)-i),y:a+t.y*(Math.max(...o)-a)}}function mo(t,n,s){return s?{x:Math.round(t.x/n)*n,y:Math.round(t.y/n)*n}:t}function po(t,n){switch(n.t){case"TOOL":return{...t,tool:n.v,drawing:null,selected:null};case"FLOOR":return{...t,floorId:n.v,drawing:null,selected:null};case"SELECT":return{...t,selected:n.v};case"ZOOM":return{...t,zoom:Math.max(.15,Math.min(5,n.v))};case"PAN":return{...t,pan:n.v};case"DRAW_PT":return{...t,drawing:[...t.drawing??[],n.v]};case"DRAW_END":return{...t,drawing:null};case"TOGGLE":return n.v==="grid"?{...t,showGrid:!t.showGrid}:n.v==="dim"?{...t,showDim:!t.showDim}:n.v==="labels"?{...t,showLabels:!t.showLabels}:n.v==="occupancy"?{...t,showOccupancy:!t.showOccupancy}:{...t,showClimate:!t.showClimate};case"OVERLAYS":return{...t,...n.v};default:return t}}const ho=[{tool:"select",icon:"cursor",key:"buildings.tool.select",label:"Select"},{tool:"draw_zone",icon:"hexagon",key:"buildings.tool.drawZone",label:"Draw zone"},{tool:"draw_wall",icon:"line",key:"buildings.tool.drawWall",label:"Draw wall"},{tool:"place_device",icon:"wifi",key:"buildings.tool.device",label:"Device"},{tool:"place_door",icon:"door",key:"buildings.tool.door",label:"Door"},{tool:"place_window",icon:"window",key:"buildings.tool.window",label:"Window"},{tool:"annotate",icon:"edit",key:"buildings.tool.annotate",label:"Annotation"},{tool:"measure",icon:"ruler",key:"buildings.tool.measure",label:"Measure"},{tool:"erase",icon:"trash",key:"buildings.tool.erase",label:"Erase"},{tool:"pan",icon:"move",key:"buildings.tool.pan",label:"Pan"}],go=({floors:t,defaultFloors:n,devices:s=[],onFloorChange:o,onDeviceMove:i,readOnly:a=!1,initialFloorId:c,showDevices:r=!0,showDimensions:l=!1,showGrid:x=!0,showOccupancy:m=!1,showClimate:h=!0,className:v,style:_,theme:p="light",tutorial:j})=>{var Pe,Fe;const{t:f}=w.useNiceTranslation(),[I,b]=w.useControllableState({value:t,defaultValue:n,fallbackValue:[],onChange:o,componentName:"NiceFloorPlanEditor"}),$=u.useRef(null),y=u.useRef(!1),C=u.useRef({x:0,y:0}),[d,k]=u.useReducer(po,{floorId:c??((Pe=I[0])==null?void 0:Pe.id)??"",tool:"select",selected:null,zoom:1,pan:{x:0,y:0},drawing:null,showGrid:x,showDim:l,showLabels:!0,showOccupancy:m,showClimate:h,snapGrid:!0,gridSize:20});u.useEffect(()=>{k({t:"OVERLAYS",v:{showGrid:x,showDim:l,showOccupancy:m,showClimate:h}})},[x,l,m,h]);const g=I.find(P=>P.id===d.floorId)??I[0],G=u.useCallback(P=>{var ge;const ee=(ge=$.current)==null?void 0:ge.getBoundingClientRect();return ee?{x:(P.clientX-ee.left-d.pan.x)/d.zoom,y:(P.clientY-ee.top-d.pan.y)/d.zoom}:{x:0,y:0}},[d.pan,d.zoom]),T=u.useCallback(P=>{d.tool==="pan"&&(y.current=!0,C.current={x:P.clientX,y:P.clientY})},[d.tool]),R=u.useCallback(P=>{y.current&&(k({t:"PAN",v:{x:d.pan.x+P.clientX-C.current.x,y:d.pan.y+P.clientY-C.current.y}}),C.current={x:P.clientX,y:P.clientY})},[d.pan]),H=u.useCallback(()=>{y.current=!1},[]),se=u.useCallback(P=>{if(d.tool==="draw_zone"){const ee=mo(G(P),d.gridSize,d.snapGrid);k({t:"DRAW_PT",v:ee})}else d.tool==="select"&&k({t:"SELECT",v:null})},[d.tool,d.gridSize,d.snapGrid,G]),ne=u.useCallback(P=>{if(d.tool==="draw_zone"&&d.drawing&&d.drawing.length>=3&&g){const ee={id:`zone-${Date.now()}`,name:"New zone",type:"other",floorId:g.id,polygon:[...d.drawing]};b(I.map(ge=>ge.id===g.id?{...g,zones:[...g.zones,ee]}:ge)),k({t:"DRAW_END"})}},[d.tool,d.drawing,g,I,b]),oe=u.useCallback(P=>{P.preventDefault(),k({t:"ZOOM",v:d.zoom*(P.deltaY>0?.9:1.1)})},[d.zoom]),he=u.useCallback((P,ee)=>{P.stopPropagation(),d.tool==="select"?k({t:"SELECT",v:{type:"zone",id:ee.id}}):d.tool==="erase"&&!a&&g&&b(I.map(ge=>ge.id===g.id?{...g,zones:g.zones.filter(Se=>Se.id!==ee.id)}:ge))},[d.tool,a,g,I,b]);if(!g)return e.jsx("div",{className:ie.emptyState,children:f("buildings.noFloors","No floors.")});const ce=((Fe=d.selected)==null?void 0:Fe.type)==="zone"?g.zones.find(P=>{var ee;return P.id===((ee=d.selected)==null?void 0:ee.id)}):null,Ne=r?s.filter(P=>g.zones.some(ee=>ee.id===P.zoneId)||P.floorPlanPosition):[],Ke=[{key:"grid",icon:"grid",active:d.showGrid},{key:"dim",icon:"ruler",active:d.showDim},{key:"labels",icon:"tag",active:d.showLabels},{key:"occupancy",icon:"users",active:d.showOccupancy},{key:"climate",icon:"thermometer",active:d.showClimate}],De=e.jsxs("div",{className:ie.topBar,children:[e.jsx("div",{className:ie.floorTabs,children:[...I].sort((P,ee)=>P.level-ee.level).map(P=>e.jsx("button",{className:`${ie.floorTab} ${d.floorId===P.id?ie.floorTabActive:""}`,onClick:()=>k({t:"FLOOR",v:P.id}),children:P.name},P.id))}),e.jsx("div",{className:ie.overlayControls,children:Ke.map(P=>e.jsx("button",{title:P.key,"aria-label":P.key,className:`${ie.overlayBtn} ${P.active?ie.overlayBtnActive:""}`,onClick:()=>k({t:"TOGGLE",v:P.key}),children:e.jsx(w.NiceIcon,{name:P.icon,size:16})},P.key))}),e.jsxs("div",{className:ie.zoomBar,children:[e.jsx("button",{onClick:()=>k({t:"ZOOM",v:d.zoom*1.2}),children:"+"}),e.jsxs("span",{children:[Math.round(d.zoom*100),"%"]}),e.jsx("button",{onClick:()=>k({t:"ZOOM",v:d.zoom*.8}),children:"−"}),e.jsx("button",{title:f("buildings.resetView","Reset the view"),"aria-label":f("buildings.resetView","Reset the view"),onClick:()=>{k({t:"ZOOM",v:1}),k({t:"PAN",v:{x:0,y:0}})},children:e.jsx(w.NiceIcon,{name:"refresh",size:16})})]})]}),ve=a?void 0:e.jsx("div",{className:ie.toolPalette,children:ho.map(({tool:P,icon:ee,key:ge,label:Se})=>e.jsx("button",{title:f(ge,Se),"aria-label":f(ge,Se),className:`${ie.toolBtn} ${d.tool===P?ie.toolBtnActive:""}`,onClick:()=>k({t:"TOOL",v:P}),children:e.jsx(w.NiceIcon,{name:ee,size:18})},P))});return e.jsxs("div",{className:`nice-floor-plan-editor ${ie.root} ${p==="dark"?ie.dark:""} ${v??""}`,style:{position:"relative",..._},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:e.jsx(w.NiceTutorialButton,{steps:w.resolveTutorial(j,ro)})}),e.jsx(w.NiceAppShell,{flush:!0,className:ie.shell,menubar:De,sidebar:ve,rightSidebar:ce?e.jsxs("div",{className:ie.propPanel,children:[e.jsx("div",{className:ie.propTitle,children:ce.name}),e.jsxs("div",{className:ie.propRow,children:[e.jsx("span",{children:f("buildings.type","Type")}),e.jsx("span",{children:ce.type})]}),ce.area!=null&&e.jsxs("div",{className:ie.propRow,children:[e.jsx("span",{children:f("buildings.area","Area")}),e.jsxs("span",{children:[ce.area," m²"]})]}),ce.temperature!=null&&e.jsxs("div",{className:ie.propRow,children:[e.jsx("span",{children:f("buildings.temp","Temp.")}),e.jsxs("span",{children:[ce.temperature.toFixed(1)," °C"]})]}),ce.humidity!=null&&e.jsxs("div",{className:ie.propRow,children:[e.jsx("span",{children:f("buildings.humidity","Humidity")}),e.jsxs("span",{children:[ce.humidity," %"]})]}),ce.co2!=null&&e.jsxs("div",{className:ie.propRow,children:[e.jsx("span",{children:"CO₂"}),e.jsxs("span",{children:[ce.co2," ppm"]})]}),ce.occupancy!=null&&e.jsxs("div",{className:ie.propRow,children:[e.jsx("span",{children:f("buildings.occupancy","Occupancy")}),e.jsx("span",{children:f("buildings.people2","{occupancy} people").replace("{occupancy}",String(ce.occupancy))})]})]}):void 0,statusBar:e.jsxs("div",{className:ie.statusBar,children:[d.tool==="draw_zone"?f("buildings.drawHint","Click points; double-click to close the zone."):d.selected?`${f("buildings.selected","Selected")}: ${d.selected.type} #${d.selected.id}`:`${g.name} — ${g.zones.length} ${f("buildings.zones","zones")}`,d.tool==="draw_zone"&&d.drawing&&f("buildings.pts"," ({drawing} pts)").replace("{drawing}",String(d.drawing.length))]}),children:e.jsx("div",{className:ie.canvasWrapper,children:e.jsxs("svg",{ref:$,className:`${ie.canvas} ${ie[`cur_${d.tool.replace("_","")}`]??""}`,onMouseDown:T,onMouseMove:R,onMouseUp:H,onClick:se,onDoubleClick:ne,onWheel:oe,children:[g.backgroundImage&&e.jsx("image",{href:g.backgroundImage,x:d.pan.x,y:d.pan.y,width:g.width*d.zoom,height:g.height*d.zoom,preserveAspectRatio:"xMidYMid meet",opacity:.35}),e.jsxs("g",{transform:`translate(${d.pan.x},${d.pan.y}) scale(${d.zoom})`,children:[d.showGrid&&(()=>{const P=[];for(let ee=0;ee<=g.width;ee+=d.gridSize)P.push(e.jsx("line",{x1:ee,y1:0,x2:ee,y2:g.height,className:ie.gridLine},`v${ee}`));for(let ee=0;ee<=g.height;ee+=d.gridSize)P.push(e.jsx("line",{x1:0,y1:ee,x2:g.width,y2:ee,className:ie.gridLine},`h${ee}`));return e.jsx("g",{children:P})})(),g.zones.map(P=>{var Ee;const ee=((Ee=d.selected)==null?void 0:Ee.id)===P.id,ge=Wn(P.polygon),Se=P.color??lo(P.type);return e.jsxs("g",{className:ie.zoneGroup,onClick:Ce=>he(Ce,P),children:[e.jsx("path",{d:_n(P.polygon),fill:Se,fillOpacity:P.opacity??.55,stroke:ee?"var(--nice-primary-hover, #2563eb)":"var(--nice-text-muted, #94a3b8)",strokeWidth:ee?2.5:1.5,className:ie.zonePath}),d.showLabels&&e.jsx("text",{x:ge.x,y:ge.y,textAnchor:"middle",dominantBaseline:"middle",className:ie.zoneLabel,children:P.name}),d.showClimate&&P.temperature!=null&&e.jsxs("text",{x:ge.x,y:ge.y+14,textAnchor:"middle",className:ie.climateLabel,children:[P.temperature.toFixed(1),"°C"," ",P.humidity!=null?`· ${P.humidity}%`:""]}),d.showOccupancy&&P.occupancy!=null&&e.jsxs("text",{x:ge.x,y:ge.y+26,textAnchor:"middle",className:ie.occupancyLabel,children:[P.occupancy," ",f("buildings.people","people")]}),d.showDim&&P.polygon.length>1&&P.polygon.map((Ce,Ge)=>{const qe=P.polygon[(Ge+1)%P.polygon.length],He=(Ce.x+qe.x)/2,Ae=(Ce.y+qe.y)/2,Oe=Math.sqrt((qe.x-Ce.x)**2+(qe.y-Ce.y)**2),Ie=g.scale??0;return e.jsx("text",{x:He,y:Ae-4,textAnchor:"middle",className:ie.dimLabel,children:Ie>0?`${(Oe/Ie).toFixed(1)}m`:`${Oe.toFixed(0)}px`},Ge)})]},P.id)}),Ne.map(P=>{var Ee;const ee=g.zones.find(Ce=>Ce.id===P.zoneId),ge=uo(P.floorPlanPosition,ee);if(!ge)return null;const Se=((Ee=d.selected)==null?void 0:Ee.id)===P.id;return e.jsxs("g",{transform:`translate(${ge.x},${ge.y})`,className:ie.deviceGroup,onClick:Ce=>{Ce.stopPropagation(),k({t:"SELECT",v:{type:"device",id:P.id}})},children:[e.jsx("circle",{r:14,className:`${ie.devCircle} ${P.status==="online"?ie.devOnline:ie.devOffline} ${Se?ie.devSelected:""}`}),e.jsx("g",{transform:"translate(-8,-8)",children:e.jsx(w.NiceIcon,{name:Vn(P.type),size:16})})]},P.id)}),d.drawing&&d.drawing.length>0&&e.jsxs("g",{children:[e.jsx("path",{d:_n(d.drawing,!1),fill:"none",stroke:"var(--nice-primary-hover, #2563eb)",strokeWidth:2,strokeDasharray:"6,3"}),d.drawing.map((P,ee)=>e.jsx("circle",{cx:P.x,cy:P.y,r:4,fill:"var(--nice-primary-hover, #2563eb)"},ee))]})]})]})})})]})},fo={cellSize:20,majorInterval:5,origin:{x:0,y:0},visible:!0,color:"#e0e0e0",majorColor:"#b0b0b0",opacity:.5,snapModes:["grid","endpoint","center"],snapThreshold:10,angleIncrement:15};function an(t,n){const{cellSize:s,origin:o}=n;return{x:Math.round((t.x-o.x)/s)*s+o.x,y:Math.round((t.y-o.y)/s)*s+o.y}}function _o(t,n){return{x:Math.round(t.x/n)*n,y:Math.round(t.y/n)*n,z:Math.round(t.z/n)*n}}function bo(t){if(t.snapPoints)return t.snapPoints;const{x:n,y:s,width:o,height:i}=t.bounds;return[{x:n,y:s},{x:n+o,y:s},{x:n+o,y:s+i},{x:n,y:s+i},{x:n+o/2,y:s+i/2},{x:n+o/2,y:s},{x:n+o,y:s+i/2},{x:n+o/2,y:s+i},{x:n,y:s+i/2}]}function yo(t,n,s){let o=null;for(const i of n){const a=bo(i);for(const c of a){const r=ft(t,c);r<=s&&(!o||r<o.distance)&&(o={point:c,targetId:i.id,distance:r})}}return o}function ft(t,n){return Math.sqrt((n.x-t.x)**2+(n.y-t.y)**2)}function Hn(t,n,s){const o=[],i={x:t.x+t.width/2,y:t.y+t.height/2};for(const a of n){const c={x:a.bounds.x+a.bounds.width/2,y:a.bounds.y+a.bounds.height/2};Math.abs(i.y-c.y)<=s&&o.push({type:"horizontal",start:{x:Math.min(t.x,a.bounds.x),y:c.y},end:{x:Math.max(t.x+t.width,a.bounds.x+a.bounds.width),y:c.y},distance:Math.abs(i.y-c.y),sourceObjectId:a.id}),Math.abs(i.x-c.x)<=s&&o.push({type:"vertical",start:{x:c.x,y:Math.min(t.y,a.bounds.y)},end:{x:c.x,y:Math.max(t.y+t.height,a.bounds.y+a.bounds.height)},distance:Math.abs(i.x-c.x),sourceObjectId:a.id});const r=[{dragged:t.y,other:a.bounds.y,axis:"horizontal"},{dragged:t.y+t.height,other:a.bounds.y+a.bounds.height,axis:"horizontal"},{dragged:t.x,other:a.bounds.x,axis:"vertical"},{dragged:t.x+t.width,other:a.bounds.x+a.bounds.width,axis:"vertical"}];for(const l of r)Math.abs(l.dragged-l.other)<=s&&(l.axis==="horizontal"?o.push({type:"horizontal",start:{x:Math.min(t.x,a.bounds.x),y:l.other},end:{x:Math.max(t.x+t.width,a.bounds.x+a.bounds.width),y:l.other},distance:Math.abs(l.dragged-l.other),sourceObjectId:a.id}):o.push({type:"vertical",start:{x:l.other,y:Math.min(t.y,a.bounds.y)},end:{x:l.other,y:Math.max(t.y+t.height,a.bounds.y+a.bounds.height)},distance:Math.abs(l.dragged-l.other),sourceObjectId:a.id}))}return xo(o)}function xo(t){const n=new Set;return t.filter(s=>{const o=`${s.type}-${s.start.x.toFixed(1)}-${s.start.y.toFixed(1)}-${s.end.x.toFixed(1)}-${s.end.y.toFixed(1)}`;return n.has(o)?!1:(n.add(o),!0)})}function vo(t,n,s){const o={position:{...t},snapped:!1,snapMode:null,guides:[]},{snapModes:i,snapThreshold:a}=s;if(i.includes("endpoint")||i.includes("center")||i.includes("midpoint")){const c=yo(t,n,a);if(c)return o.position=c.point,o.snapped=!0,o.snapMode="endpoint",o.targetObjectId=c.targetId,o}if(i.includes("grid")){const c=an(t,s);if(ft(t,c)<=a)return o.position=c,o.snapped=!0,o.snapMode="grid",o}return o}const jo=[{id:"sh-light-bulb",name:"Smart Bulb",category:"smart-home",type:"light",icon:"lightbulb",tags:["lighting","bulb"]},{id:"sh-light-dimmer",name:"Dimmer Switch",category:"smart-home",type:"light-dimmer",icon:"lightbulb",tags:["lighting","switch"]},{id:"sh-light-rgb",name:"RGB Light",category:"smart-home",type:"light-rgb",icon:"lightbulb",tags:["lighting","color"]},{id:"sh-light-strip",name:"LED Strip",category:"smart-home",type:"light-strip",icon:"lightbulb",tags:["lighting","strip"]},{id:"sh-thermostat",name:"Thermostat",category:"smart-home",type:"thermostat",icon:"thermometer",tags:["climate","temperature"]},{id:"sh-hvac",name:"HVAC Unit",category:"smart-home",type:"hvac",icon:"thermometer",tags:["climate","cooling","heating"]},{id:"sh-fan",name:"Smart Fan",category:"smart-home",type:"fan",icon:"wifi",tags:["climate","fan"]},{id:"sh-camera",name:"Security Camera",category:"smart-home",type:"camera",icon:"camera",tags:["security","camera"]},{id:"sh-doorbell",name:"Video Doorbell",category:"smart-home",type:"camera-doorbell",icon:"bell",tags:["security","doorbell"]},{id:"sh-lock",name:"Smart Lock",category:"smart-home",type:"lock",icon:"lock",tags:["security","lock"]},{id:"sh-sensor-motion",name:"Motion Sensor",category:"smart-home",type:"sensor-motion",icon:"eye",tags:["security","sensor"]},{id:"sh-sensor-door",name:"Door Sensor",category:"smart-home",type:"sensor-door",icon:"door",tags:["security","sensor"]},{id:"sh-speaker",name:"Smart Speaker",category:"smart-home",type:"speaker",icon:"wifi",tags:["audio","speaker"]},{id:"sh-voice-assistant",name:"Voice Assistant",category:"smart-home",type:"voice-assistant",icon:"mic",tags:["audio","assistant"]},{id:"sh-tv",name:"Smart TV",category:"smart-home",type:"tv",icon:"monitor",tags:["video","tv"]},{id:"furn-sofa-3",name:"3-Seater Sofa",category:"furniture",type:"sofa",defaultSize:{x:2.2,y:.9,z:.85},tags:["seating","sofa"]},{id:"furn-sofa-2",name:"2-Seater Sofa",category:"furniture",type:"sofa",defaultSize:{x:1.6,y:.9,z:.85},tags:["seating","sofa"]},{id:"furn-armchair",name:"Armchair",category:"furniture",type:"armchair",defaultSize:{x:.9,y:.9,z:.85},tags:["seating","chair"]},{id:"furn-dining-chair",name:"Dining Chair",category:"furniture",type:"chair",defaultSize:{x:.45,y:.5,z:.9},tags:["seating","dining"]},{id:"furn-office-chair",name:"Office Chair",category:"furniture",type:"chair",defaultSize:{x:.65,y:.65,z:1.2},tags:["seating","office"]},{id:"furn-dining-table-6",name:"Dining Table (6p)",category:"furniture",type:"table",defaultSize:{x:1.8,y:.9,z:.75},tags:["table","dining"]},{id:"furn-coffee-table",name:"Coffee Table",category:"furniture",type:"table",defaultSize:{x:1.2,y:.6,z:.45},tags:["table","living"]},{id:"furn-desk",name:"Office Desk",category:"furniture",type:"desk",defaultSize:{x:1.6,y:.8,z:.75},tags:["table","office","desk"]},{id:"furn-side-table",name:"Side Table",category:"furniture",type:"table",defaultSize:{x:.5,y:.5,z:.55},tags:["table","side"]},{id:"furn-bed-king",name:"King Bed",category:"furniture",type:"bed",defaultSize:{x:2,y:2.2,z:.5},tags:["bed","bedroom"]},{id:"furn-bed-queen",name:"Queen Bed",category:"furniture",type:"bed",defaultSize:{x:1.6,y:2.1,z:.5},tags:["bed","bedroom"]},{id:"furn-bed-single",name:"Single Bed",category:"furniture",type:"bed",defaultSize:{x:.9,y:2,z:.5},tags:["bed","bedroom"]},{id:"furn-wardrobe",name:"Wardrobe",category:"furniture",type:"wardrobe",defaultSize:{x:1.8,y:.6,z:2.2},tags:["storage","bedroom"]},{id:"furn-bookshelf",name:"Bookshelf",category:"furniture",type:"bookshelf",defaultSize:{x:.8,y:.3,z:2},tags:["storage","books"]},{id:"furn-dresser",name:"Dresser",category:"furniture",type:"dresser",defaultSize:{x:1.2,y:.5,z:.8},tags:["storage","bedroom"]},{id:"net-router",name:"Router",category:"network",type:"router",icon:"wifi",tags:["network","router"]},{id:"net-switch-24",name:"24-Port Switch",category:"network",type:"switch",icon:"plug",tags:["network","switch"]},{id:"net-switch-48",name:"48-Port Switch",category:"network",type:"switch",icon:"plug",tags:["network","switch"]},{id:"net-firewall",name:"Firewall",category:"network",type:"firewall",icon:"lock",tags:["network","security"]},{id:"net-access-point",name:"WiFi Access Point",category:"network",type:"access-point",icon:"wifi",tags:["network","wifi"]},{id:"net-server",name:"Server",category:"network",type:"server",icon:"monitor",tags:["network","server"]},{id:"net-storage",name:"NAS Storage",category:"network",type:"nas",icon:"database",tags:["network","storage"]},{id:"infra-rack-42u",name:"42U Rack",category:"infrastructure",type:"rack-42u",icon:"server",defaultSize:{x:.6,y:1,z:2},tags:["datacenter","rack"]},{id:"infra-rack-24u",name:"24U Rack",category:"infrastructure",type:"rack-24u",icon:"server",defaultSize:{x:.6,y:1,z:1.2},tags:["datacenter","rack"]},{id:"infra-ups",name:"UPS",category:"infrastructure",type:"ups-floor",icon:"zap",tags:["datacenter","power"]},{id:"infra-pdu",name:"PDU",category:"infrastructure",type:"pdu-vertical",icon:"zap",tags:["datacenter","power"]},{id:"infra-cooling",name:"CRAC Unit",category:"infrastructure",type:"cooling-crac",icon:"thermometer",tags:["datacenter","cooling"]},{id:"bld-wall",name:"Wall",category:"building",type:"wall",icon:"square",tags:["building","wall"]},{id:"bld-door",name:"Door",category:"building",type:"door",icon:"door",tags:["building","door"]},{id:"bld-window",name:"Window",category:"building",type:"window",icon:"window",tags:["building","window"]},{id:"bld-stair",name:"Staircase",category:"building",type:"stair",icon:"stairs",tags:["building","stair"]},{id:"game-spawn",name:"Spawn Point",category:"game",type:"spawn-point",icon:"target",tags:["game","spawn"]},{id:"game-checkpoint",name:"Checkpoint",category:"game",type:"checkpoint",icon:"target",tags:["game","checkpoint"]},{id:"game-trigger",name:"Trigger Zone",category:"game",type:"trigger-zone",icon:"zap",tags:["game","trigger"]},{id:"game-item",name:"Item Pickup",category:"game",type:"item-pickup",icon:"box",tags:["game","item"]},{id:"game-enemy",name:"Enemy Spawner",category:"game",type:"enemy-spawner",icon:"gamepad",tags:["game","enemy"]}];function rn(t,n="floor-plan"){const s=new Date().toISOString();return{$schema:"https://nice2dev.com/schemas/nsp-v1.json",version:"1.0.0",type:n,metadata:{id:wo(),name:t,created:s,modified:s},floors:[],settings:{units:"metric",scale:50,grid:{visible:!0,size:.5,snapEnabled:!0},defaultWallHeight:2.7,defaultWallThickness:.15,precision:2}}}function wo(){return`${Date.now().toString(36)}-${Math.random().toString(36).substr(2,9)}`}const bn={ft:3.28084,in:39.3701},yn={"ft²":.092903,acre:4046.86};function No(t){return t*(180/Math.PI)}function Io(t,n){return Math.sqrt((n.x-t.x)**2+(n.y-t.y)**2)}function ko(t){if(t.length<2)return 0;let n=0;for(let s=1;s<t.length;s++)n+=Io(t[s-1],t[s]);return n}function Zt(t,n,s){const o={x:t.x-n.x,y:t.y-n.y},i={x:s.x-n.x,y:s.y-n.y},a=o.x*i.x+o.y*i.y,c=Math.sqrt(o.x**2+o.y**2),r=Math.sqrt(i.x**2+i.y**2);if(c===0||r===0)return 0;const l=a/(c*r);return Math.acos(Math.max(-1,Math.min(1,l)))}function Xt(t){if(t.length<3)return 0;let n=0;const s=t.length;for(let o=0;o<s;o++){const i=(o+1)%s;n+=t[o].x*t[i].y,n-=t[i].x*t[o].y}return Math.abs(n)/2}function ut(t,n="m",s=2){const o=`${t.toFixed(s)} ${n}`;return{value:t,unit:n,formatted:o}}function Ct(t,n="m²",s=2){const o=`${t.toFixed(s)} ${n}`;return{value:t,unit:n,formatted:o}}function Kt(t,n="deg",s=1){const o=n==="deg"?No(t):t,i=n==="deg"?"°":" rad",a=`${o.toFixed(s)}${i}`;return{value:o,unit:n,formatted:a}}function Tt(t,n="metric",s=2){if(n==="metric")return t<.01?ut(t*1e3,"mm",s):t<1?ut(t*100,"cm",s):ut(t,"m",s);{const o=t*bn.ft;return o<1?ut(t*bn.in,"in",s):ut(o,"ft",s)}}function Jt(t,n="metric",s=2){if(n==="metric")return t>=1e4?Ct(t/1e4,"ha",s):Ct(t,"m²",s);{const o=t/yn["ft²"];return o>=43560?Ct(t/yn.acre,"acre",s):Ct(o,"ft²",s)}}function So(t,n={}){const{pretty:s=!1,includeSchema:o=!0,excludeEmptyLayers:i=!1,includeMetadata:a=!0}=n,c=JSON.parse(JSON.stringify(t));if(o&&!c.$schema&&(c.$schema="https://nice2dev.com/schemas/nsp-v1.json"),a&&(c.metadata=c.metadata??{id:"",name:"",created:new Date().toISOString(),modified:new Date().toISOString()},c.metadata.modified=new Date().toISOString()),i)for(const r of c.floors)r.layers=r.layers.filter(l=>l.objects.length>0);return s?JSON.stringify(c,null,2):JSON.stringify(c)}function Co(t,n={}){var c;const s=Mo(t,n),o=So(s),i=new Blob([o],{type:"application/json"});return{format:"nsp",filename:`${((c=t.metadata)==null?void 0:c.name)||"document"}.nsp.json`,mimeType:"application/json",data:i,size:i.size}}const To="http://www.w3.org/2000/svg";function Lo(t,n={}){var p,j;const{floorIds:s,includeGrid:o=!1,scale:i=1,backgroundColor:a}=n,c=s?t.floors.filter(f=>s.includes(f.id)):t.floors;if(c.length===0)throw new Error("No floors to export");const r=Oo(c),l=(r.maxX-r.minX)*i,x=(r.maxY-r.minY)*i,m=((p=t.metadata)==null?void 0:p.name)||"Floor Plan";let h=`<?xml version="1.0" encoding="UTF-8"?>
2
- <svg xmlns="${To}"
1
+ "use strict";var js=Object.defineProperty;var ws=(t,n,s)=>n in t?js(t,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[n]=s;var Lt=(t,n,s)=>ws(t,typeof n!="symbol"?n+"":n,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),N=require("@nice2dev/ui"),u=require("react"),Ns={light:"lightbulb",dimmer:"lightbulb",rgb_light:"lightbulb",led_strip:"lightbulb",thermostat:"thermometer",heater:"thermometer",air_conditioner:"thermometer",fan:"refresh",heat_pump:"thermometer",lock:"lock",door:"door",window:"window",blind:"columns",shutter:"columns",garage:"home",gate:"door",switch:"plug",outlet:"plug",smart_plug:"plug",power_strip:"plug",camera:"camera",doorbell:"bell",alarm:"bell",siren:"bell",motion_sensor:"eye",door_sensor:"door",window_sensor:"window",smoke_detector:"warning",co_detector:"warning",water_leak:"droplet",gas_detector:"warning",temperature_sensor:"thermometer",humidity_sensor:"droplet",air_quality:"cloud",light_sensor:"sun",presence_sensor:"user",speaker:"volume",tv:"monitor",media_player:"play",vacuum:"refresh",washing_machine:"refresh",dishwasher:"utensils",oven:"utensils",fridge:"box",irrigation:"droplet",pool:"droplet",ev_charger:"zap",solar_panel:"sun",battery:"zap",energy_meter:"zap",hub:"wifi",router:"wifi",other:"settings"};function Hn(t){return Ns[t]??"settings"}const Is="_root_1nq8c_1",ks="_shell_1nq8c_27",Ss="_dark_1nq8c_35",Cs="_topBar_1nq8c_49",Ts="_floorTabs_1nq8c_79",Ls="_floorTab_1nq8c_79",$s="_floorTabActive_1nq8c_119",zs="_overlayControls_1nq8c_131",Ps="_overlayBtn_1nq8c_143",Es="_overlayBtnActive_1nq8c_179",Os="_zoomBar_1nq8c_191",Ms="_toolPalette_1nq8c_245",As="_toolBtn_1nq8c_275",Ds="_toolBtnActive_1nq8c_311",Bs="_canvasWrapper_1nq8c_325",Rs="_canvas_1nq8c_325",Fs="_cur_select_1nq8c_365",Gs="_cur_drawzone_1nq8c_371",Vs="_cur_drawwall_1nq8c_377",qs="_cur_placedevice_1nq8c_383",Ws="_cur_placedoor_1nq8c_389",Hs="_cur_placewindow_1nq8c_395",Us="_cur_pan_1nq8c_401",Ys="_cur_erase_1nq8c_407",Zs="_cur_measure_1nq8c_413",Xs="_cur_annotate_1nq8c_419",Ks="_gridLine_1nq8c_429",Js="_zoneGroup_1nq8c_447",Qs="_zonePath_1nq8c_455",eo="_zoneLabel_1nq8c_463",to="_climateLabel_1nq8c_485",no="_occupancyLabel_1nq8c_497",so="_dimLabel_1nq8c_509",oo="_deviceGroup_1nq8c_521",ao="_devCircle_1nq8c_529",io="_devOnline_1nq8c_541",ro="_devOffline_1nq8c_547",co="_devSelected_1nq8c_553",lo="_propPanel_1nq8c_565",uo="_propTitle_1nq8c_593",po="_propRow_1nq8c_615",mo="_statusBar_1nq8c_655",ho="_emptyState_1nq8c_687",oe={root:Is,shell:ks,dark:Ss,topBar:Cs,floorTabs:Ts,floorTab:Ls,floorTabActive:$s,overlayControls:zs,overlayBtn:Ps,overlayBtnActive:Es,zoomBar:Os,toolPalette:Ms,toolBtn:As,toolBtnActive:Ds,canvasWrapper:Bs,canvas:Rs,cur_select:Fs,cur_drawzone:Gs,cur_drawwall:Vs,cur_placedevice:qs,cur_placedoor:Ws,cur_placewindow:Hs,cur_pan:Us,cur_erase:Ys,cur_measure:Zs,cur_annotate:Xs,gridLine:Ks,zoneGroup:Js,zonePath:Qs,zoneLabel:eo,climateLabel:to,occupancyLabel:no,dimLabel:so,deviceGroup:oo,devCircle:ao,devOnline:io,devOffline:ro,devSelected:co,propPanel:lo,propTitle:uo,propRow:po,statusBar:mo,emptyState:ho},go=[{target:".nice-floor-plan-editor",titleKey:"tutorial.floorPlanEditor.intro.title",title:"Floor plan editor",contentKey:"tutorial.floorPlanEditor.intro.content",content:"Draw rooms and zones with the tools, place devices on the plan, switch floors and toggle overlays like dimensions, grid and occupancy.",placement:"auto"}],fo={living_room:"var(--nice-primary-bg, #dbeafe)",bedroom:"var(--nice-accent-tint-10, #fce7f3)",master_bedroom:"var(--nice-accent-tint-12, #f3e8ff)",kids_room:"var(--nice-warning-bg, #fef3c7)",bathroom:"var(--nice-info-bg, #cffafe)",kitchen:"var(--nice-warning-bg, #fef9c3)",dining_room:"var(--nice-warning-bg, #fde8d8)",hallway:"var(--nice-bg-secondary, #f1f5f9)",office:"var(--nice-success-bg, #dcfce7)",garage:"var(--nice-border, #e2e8f0)",basement:"var(--nice-border, #e5e7eb)",attic:"var(--nice-success-bg, #f0fdf4)",balcony:"var(--nice-success-bg, #ecfdf5)",garden:"var(--nice-success-bg, #d1fae5)",gym:"var(--nice-danger-bg, #fee2e2)",cinema:"var(--nice-accent-tint-10, #ede9fe)",open_office:"var(--nice-success-bg, #dcfce7)",private_office:"var(--nice-success-bg, #d1fae5)",meeting_room:"var(--nice-primary-bg, #dbeafe)",boardroom:"var(--nice-accent-tint-10, #ede9fe)",reception:"var(--nice-warning-bg, #fef3c7)",waiting_area:"var(--nice-warning-bg, #fef9c3)",server_room:"var(--nice-danger-bg, #fee2e2)",it_room:"var(--nice-warning-bg, #fde8d8)",break_room:"var(--nice-accent-tint-10, #fce7f3)",lobby:"var(--nice-primary-bg, #f0f4ff)",corridor:"var(--nice-bg-secondary, #f8fafc)",stairwell:"var(--nice-bg-secondary, #f1f5f9)",parking:"var(--nice-border, #e2e8f0)",mechanical_room:"var(--nice-bg-secondary, #f3f4f6)"};function _o(t){return fo[t]??"var(--nice-primary-bg, #f0f4ff)"}function Un(t){if(!t.length)return{x:0,y:0};const n=t.reduce((s,o)=>({x:s.x+o.x,y:s.y+o.y}),{x:0,y:0});return{x:n.x/t.length,y:n.y/t.length}}function yn(t,n=!0){return t.length<2?"":t.map((s,o)=>`${o===0?"M":"L"}${s.x.toFixed(1)},${s.y.toFixed(1)}`).join(" ")+(n?" Z":"")}function bo(t,n){if(!t)return n?Un(n.polygon):null;if(!n||!n.polygon.length||t.x>1||t.y>1)return t;const s=n.polygon.map(c=>c.x),o=n.polygon.map(c=>c.y),i=Math.min(...s),a=Math.min(...o);return{x:i+t.x*(Math.max(...s)-i),y:a+t.y*(Math.max(...o)-a)}}function yo(t,n,s){return s?{x:Math.round(t.x/n)*n,y:Math.round(t.y/n)*n}:t}function xo(t,n){switch(n.t){case"TOOL":return{...t,tool:n.v,drawing:null,selected:null};case"FLOOR":return{...t,floorId:n.v,drawing:null,selected:null};case"SELECT":return{...t,selected:n.v};case"ZOOM":return{...t,zoom:Math.max(.15,Math.min(5,n.v))};case"PAN":return{...t,pan:n.v};case"DRAW_PT":return{...t,drawing:[...t.drawing??[],n.v]};case"DRAW_END":return{...t,drawing:null};case"TOGGLE":return n.v==="grid"?{...t,showGrid:!t.showGrid}:n.v==="dim"?{...t,showDim:!t.showDim}:n.v==="labels"?{...t,showLabels:!t.showLabels}:n.v==="occupancy"?{...t,showOccupancy:!t.showOccupancy}:{...t,showClimate:!t.showClimate};case"OVERLAYS":return{...t,...n.v};default:return t}}const vo=[{tool:"select",icon:"cursor",key:"buildings.tool.select",label:"Select"},{tool:"draw_zone",icon:"hexagon",key:"buildings.tool.drawZone",label:"Draw zone"},{tool:"draw_wall",icon:"line",key:"buildings.tool.drawWall",label:"Draw wall"},{tool:"place_device",icon:"wifi",key:"buildings.tool.device",label:"Device"},{tool:"place_door",icon:"door",key:"buildings.tool.door",label:"Door"},{tool:"place_window",icon:"window",key:"buildings.tool.window",label:"Window"},{tool:"annotate",icon:"edit",key:"buildings.tool.annotate",label:"Annotation"},{tool:"measure",icon:"ruler",key:"buildings.tool.measure",label:"Measure"},{tool:"erase",icon:"trash",key:"buildings.tool.erase",label:"Erase"},{tool:"pan",icon:"move",key:"buildings.tool.pan",label:"Pan"}],jo=({floors:t,defaultFloors:n,devices:s=[],onFloorChange:o,onDeviceMove:i,readOnly:a=!1,initialFloorId:c,showDevices:r=!0,showDimensions:d=!1,showGrid:_=!0,showOccupancy:p=!1,showClimate:f=!0,className:y,style:b,theme:j="light",tutorial:w})=>{var ze,Ge;const{t:x}=N.useNiceTranslation(),[C,g]=N.useControllableState({value:t,defaultValue:n,fallbackValue:[],onChange:o,componentName:"NiceFloorPlanEditor"}),L=u.useRef(null),m=u.useRef(!1),k=u.useRef({x:0,y:0}),[l,I]=u.useReducer(xo,{floorId:c??((ze=C[0])==null?void 0:ze.id)??"",tool:"select",selected:null,zoom:1,pan:{x:0,y:0},drawing:null,showGrid:_,showDim:d,showLabels:!0,showOccupancy:p,showClimate:f,snapGrid:!0,gridSize:20});u.useEffect(()=>{I({t:"OVERLAYS",v:{showGrid:_,showDim:d,showOccupancy:p,showClimate:f}})},[_,d,p,f]);const h=C.find(P=>P.id===l.floorId)??C[0],F=u.useCallback(P=>{var fe;const Q=(fe=L.current)==null?void 0:fe.getBoundingClientRect();return Q?{x:(P.clientX-Q.left-l.pan.x)/l.zoom,y:(P.clientY-Q.top-l.pan.y)/l.zoom}:{x:0,y:0}},[l.pan,l.zoom]),T=u.useCallback(P=>{l.tool==="pan"&&(m.current=!0,k.current={x:P.clientX,y:P.clientY})},[l.tool]),B=u.useCallback(P=>{m.current&&(I({t:"PAN",v:{x:l.pan.x+P.clientX-k.current.x,y:l.pan.y+P.clientY-k.current.y}}),k.current={x:P.clientX,y:P.clientY})},[l.pan]),H=u.useCallback(()=>{m.current=!1},[]),ne=u.useCallback(P=>{if(l.tool==="draw_zone"){const Q=yo(F(P),l.gridSize,l.snapGrid);I({t:"DRAW_PT",v:Q})}else l.tool==="select"&&I({t:"SELECT",v:null})},[l.tool,l.gridSize,l.snapGrid,F]),te=u.useCallback(P=>{if(l.tool==="draw_zone"&&l.drawing&&l.drawing.length>=3&&h){const Q={id:`zone-${Date.now()}`,name:"New zone",type:"other",floorId:h.id,polygon:[...l.drawing]};g(C.map(fe=>fe.id===h.id?{...h,zones:[...h.zones,Q]}:fe)),I({t:"DRAW_END"})}},[l.tool,l.drawing,h,C,g]),ie=u.useCallback(P=>{P.preventDefault(),I({t:"ZOOM",v:l.zoom*(P.deltaY>0?.9:1.1)})},[l.zoom]),_e=u.useCallback((P,Q)=>{P.stopPropagation(),l.tool==="select"?I({t:"SELECT",v:{type:"zone",id:Q.id}}):l.tool==="erase"&&!a&&h&&g(C.map(fe=>fe.id===h.id?{...h,zones:h.zones.filter(Se=>Se.id!==Q.id)}:fe))},[l.tool,a,h,C,g]);if(!h)return e.jsx("div",{className:oe.emptyState,children:x("buildings.noFloors","No floors.")});const de=((Ge=l.selected)==null?void 0:Ge.type)==="zone"?h.zones.find(P=>{var Q;return P.id===((Q=l.selected)==null?void 0:Q.id)}):null,Ne=r?s.filter(P=>h.zones.some(Q=>Q.id===P.zoneId)||P.floorPlanPosition):[],Je=[{key:"grid",icon:"grid",active:l.showGrid},{key:"dim",icon:"ruler",active:l.showDim},{key:"labels",icon:"tag",active:l.showLabels},{key:"occupancy",icon:"users",active:l.showOccupancy},{key:"climate",icon:"thermometer",active:l.showClimate}],Be=e.jsxs("div",{className:oe.topBar,children:[e.jsx("div",{className:oe.floorTabs,children:[...C].sort((P,Q)=>P.level-Q.level).map(P=>e.jsx("button",{className:`${oe.floorTab} ${l.floorId===P.id?oe.floorTabActive:""}`,onClick:()=>I({t:"FLOOR",v:P.id}),children:P.name},P.id))}),e.jsx("div",{className:oe.overlayControls,children:Je.map(P=>e.jsx("button",{title:P.key,"aria-label":P.key,className:`${oe.overlayBtn} ${P.active?oe.overlayBtnActive:""}`,onClick:()=>I({t:"TOGGLE",v:P.key}),children:e.jsx(N.NiceIcon,{name:P.icon,size:16})},P.key))}),e.jsxs("div",{className:oe.zoomBar,children:[e.jsx("button",{onClick:()=>I({t:"ZOOM",v:l.zoom*1.2}),children:"+"}),e.jsxs("span",{children:[Math.round(l.zoom*100),"%"]}),e.jsx("button",{onClick:()=>I({t:"ZOOM",v:l.zoom*.8}),children:"−"}),e.jsx("button",{title:x("buildings.resetView","Reset the view"),"aria-label":x("buildings.resetView","Reset the view"),onClick:()=>{I({t:"ZOOM",v:1}),I({t:"PAN",v:{x:0,y:0}})},children:e.jsx(N.NiceIcon,{name:"refresh",size:16})})]})]}),xe=a?void 0:e.jsx("div",{className:oe.toolPalette,children:vo.map(({tool:P,icon:Q,key:fe,label:Se})=>e.jsx("button",{title:x(fe,Se),"aria-label":x(fe,Se),className:`${oe.toolBtn} ${l.tool===P?oe.toolBtnActive:""}`,onClick:()=>I({t:"TOOL",v:P}),children:e.jsx(N.NiceIcon,{name:Q,size:18})},P))});return e.jsxs("div",{className:`nice-floor-plan-editor ${oe.root} ${j==="dark"?oe.dark:""} ${y??""}`,style:{position:"relative",...b},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:e.jsx(N.NiceTutorialButton,{steps:N.resolveTutorial(w,go)})}),e.jsx(N.NiceAppShell,{flush:!0,className:oe.shell,menubar:Be,sidebar:xe,rightSidebar:de?e.jsxs("div",{className:oe.propPanel,children:[e.jsx("div",{className:oe.propTitle,children:de.name}),e.jsxs("div",{className:oe.propRow,children:[e.jsx("span",{children:x("buildings.type","Type")}),e.jsx("span",{children:de.type})]}),de.area!=null&&e.jsxs("div",{className:oe.propRow,children:[e.jsx("span",{children:x("buildings.area","Area")}),e.jsxs("span",{children:[de.area," m²"]})]}),de.temperature!=null&&e.jsxs("div",{className:oe.propRow,children:[e.jsx("span",{children:x("buildings.temp","Temp.")}),e.jsxs("span",{children:[de.temperature.toFixed(1)," °C"]})]}),de.humidity!=null&&e.jsxs("div",{className:oe.propRow,children:[e.jsx("span",{children:x("buildings.humidity","Humidity")}),e.jsxs("span",{children:[de.humidity," %"]})]}),de.co2!=null&&e.jsxs("div",{className:oe.propRow,children:[e.jsx("span",{children:"CO₂"}),e.jsxs("span",{children:[de.co2," ppm"]})]}),de.occupancy!=null&&e.jsxs("div",{className:oe.propRow,children:[e.jsx("span",{children:x("buildings.occupancy","Occupancy")}),e.jsx("span",{children:x("buildings.people2","{occupancy} people").replace("{occupancy}",String(de.occupancy))})]})]}):void 0,statusBar:e.jsxs("div",{className:oe.statusBar,children:[l.tool==="draw_zone"?x("buildings.drawHint","Click points; double-click to close the zone."):l.selected?`${x("buildings.selected","Selected")}: ${l.selected.type} #${l.selected.id}`:`${h.name} — ${h.zones.length} ${x("buildings.zones","zones")}`,l.tool==="draw_zone"&&l.drawing&&x("buildings.pts"," ({drawing} pts)").replace("{drawing}",String(l.drawing.length))]}),children:e.jsx("div",{className:oe.canvasWrapper,children:e.jsxs("svg",{ref:L,className:`${oe.canvas} ${oe[`cur_${l.tool.replace("_","")}`]??""}`,onMouseDown:T,onMouseMove:B,onMouseUp:H,onClick:ne,onDoubleClick:te,onWheel:ie,children:[h.backgroundImage&&e.jsx("image",{href:h.backgroundImage,x:l.pan.x,y:l.pan.y,width:h.width*l.zoom,height:h.height*l.zoom,preserveAspectRatio:"xMidYMid meet",opacity:.35}),e.jsxs("g",{transform:`translate(${l.pan.x},${l.pan.y}) scale(${l.zoom})`,children:[l.showGrid&&(()=>{const P=[];for(let Q=0;Q<=h.width;Q+=l.gridSize)P.push(e.jsx("line",{x1:Q,y1:0,x2:Q,y2:h.height,className:oe.gridLine},`v${Q}`));for(let Q=0;Q<=h.height;Q+=l.gridSize)P.push(e.jsx("line",{x1:0,y1:Q,x2:h.width,y2:Q,className:oe.gridLine},`h${Q}`));return e.jsx("g",{children:P})})(),h.zones.map(P=>{var Oe;const Q=((Oe=l.selected)==null?void 0:Oe.id)===P.id,fe=Un(P.polygon),Se=P.color??_o(P.type);return e.jsxs("g",{className:oe.zoneGroup,onClick:ke=>_e(ke,P),children:[e.jsx("path",{d:yn(P.polygon),fill:Se,fillOpacity:P.opacity??.55,stroke:Q?"var(--nice-primary-hover, #2563eb)":"var(--nice-text-muted, #94a3b8)",strokeWidth:Q?2.5:1.5,className:oe.zonePath}),l.showLabels&&e.jsx("text",{x:fe.x,y:fe.y,textAnchor:"middle",dominantBaseline:"middle",className:oe.zoneLabel,children:P.name}),l.showClimate&&P.temperature!=null&&e.jsxs("text",{x:fe.x,y:fe.y+14,textAnchor:"middle",className:oe.climateLabel,children:[P.temperature.toFixed(1),"°C"," ",P.humidity!=null?`· ${P.humidity}%`:""]}),l.showOccupancy&&P.occupancy!=null&&e.jsxs("text",{x:fe.x,y:fe.y+26,textAnchor:"middle",className:oe.occupancyLabel,children:[P.occupancy," ",x("buildings.people","people")]}),l.showDim&&P.polygon.length>1&&P.polygon.map((ke,Ve)=>{const Pe=P.polygon[(Ve+1)%P.polygon.length],qe=(ke.x+Pe.x)/2,We=(ke.y+Pe.y)/2,Re=Math.sqrt((Pe.x-ke.x)**2+(Pe.y-ke.y)**2),$e=h.scale??0;return e.jsx("text",{x:qe,y:We-4,textAnchor:"middle",className:oe.dimLabel,children:$e>0?`${(Re/$e).toFixed(1)}m`:`${Re.toFixed(0)}px`},Ve)})]},P.id)}),Ne.map(P=>{var Oe;const Q=h.zones.find(ke=>ke.id===P.zoneId),fe=bo(P.floorPlanPosition,Q);if(!fe)return null;const Se=((Oe=l.selected)==null?void 0:Oe.id)===P.id;return e.jsxs("g",{transform:`translate(${fe.x},${fe.y})`,className:oe.deviceGroup,onClick:ke=>{ke.stopPropagation(),I({t:"SELECT",v:{type:"device",id:P.id}})},children:[e.jsx("circle",{r:14,className:`${oe.devCircle} ${P.status==="online"?oe.devOnline:oe.devOffline} ${Se?oe.devSelected:""}`}),e.jsx("g",{transform:"translate(-8,-8)",children:e.jsx(N.NiceIcon,{name:Hn(P.type),size:16})})]},P.id)}),l.drawing&&l.drawing.length>0&&e.jsxs("g",{children:[e.jsx("path",{d:yn(l.drawing,!1),fill:"none",stroke:"var(--nice-primary-hover, #2563eb)",strokeWidth:2,strokeDasharray:"6,3"}),l.drawing.map((P,Q)=>e.jsx("circle",{cx:P.x,cy:P.y,r:4,fill:"var(--nice-primary-hover, #2563eb)"},Q))]})]})]})})})]})},wo={cellSize:20,majorInterval:5,origin:{x:0,y:0},visible:!0,color:"#e0e0e0",majorColor:"#b0b0b0",opacity:.5,snapModes:["grid","endpoint","center"],snapThreshold:10,angleIncrement:15};function ln(t,n){const{cellSize:s,origin:o}=n;return{x:Math.round((t.x-o.x)/s)*s+o.x,y:Math.round((t.y-o.y)/s)*s+o.y}}function No(t,n){return{x:Math.round(t.x/n)*n,y:Math.round(t.y/n)*n,z:Math.round(t.z/n)*n}}function Io(t){if(t.snapPoints)return t.snapPoints;const{x:n,y:s,width:o,height:i}=t.bounds;return[{x:n,y:s},{x:n+o,y:s},{x:n+o,y:s+i},{x:n,y:s+i},{x:n+o/2,y:s+i/2},{x:n+o/2,y:s},{x:n+o,y:s+i/2},{x:n+o/2,y:s+i},{x:n,y:s+i/2}]}function ko(t,n,s){let o=null;for(const i of n){const a=Io(i);for(const c of a){const r=wt(t,c);r<=s&&(!o||r<o.distance)&&(o={point:c,targetId:i.id,distance:r})}}return o}function wt(t,n){return Math.sqrt((n.x-t.x)**2+(n.y-t.y)**2)}function Yn(t,n,s){const o=[],i={x:t.x+t.width/2,y:t.y+t.height/2};for(const a of n){const c={x:a.bounds.x+a.bounds.width/2,y:a.bounds.y+a.bounds.height/2};Math.abs(i.y-c.y)<=s&&o.push({type:"horizontal",start:{x:Math.min(t.x,a.bounds.x),y:c.y},end:{x:Math.max(t.x+t.width,a.bounds.x+a.bounds.width),y:c.y},distance:Math.abs(i.y-c.y),sourceObjectId:a.id}),Math.abs(i.x-c.x)<=s&&o.push({type:"vertical",start:{x:c.x,y:Math.min(t.y,a.bounds.y)},end:{x:c.x,y:Math.max(t.y+t.height,a.bounds.y+a.bounds.height)},distance:Math.abs(i.x-c.x),sourceObjectId:a.id});const r=[{dragged:t.y,other:a.bounds.y,axis:"horizontal"},{dragged:t.y+t.height,other:a.bounds.y+a.bounds.height,axis:"horizontal"},{dragged:t.x,other:a.bounds.x,axis:"vertical"},{dragged:t.x+t.width,other:a.bounds.x+a.bounds.width,axis:"vertical"}];for(const d of r)Math.abs(d.dragged-d.other)<=s&&(d.axis==="horizontal"?o.push({type:"horizontal",start:{x:Math.min(t.x,a.bounds.x),y:d.other},end:{x:Math.max(t.x+t.width,a.bounds.x+a.bounds.width),y:d.other},distance:Math.abs(d.dragged-d.other),sourceObjectId:a.id}):o.push({type:"vertical",start:{x:d.other,y:Math.min(t.y,a.bounds.y)},end:{x:d.other,y:Math.max(t.y+t.height,a.bounds.y+a.bounds.height)},distance:Math.abs(d.dragged-d.other),sourceObjectId:a.id}))}return So(o)}function So(t){const n=new Set;return t.filter(s=>{const o=`${s.type}-${s.start.x.toFixed(1)}-${s.start.y.toFixed(1)}-${s.end.x.toFixed(1)}-${s.end.y.toFixed(1)}`;return n.has(o)?!1:(n.add(o),!0)})}function Co(t,n,s){const o={position:{...t},snapped:!1,snapMode:null,guides:[]},{snapModes:i,snapThreshold:a}=s;if(i.includes("endpoint")||i.includes("center")||i.includes("midpoint")){const c=ko(t,n,a);if(c)return o.position=c.point,o.snapped=!0,o.snapMode="endpoint",o.targetObjectId=c.targetId,o}if(i.includes("grid")){const c=ln(t,s);if(wt(t,c)<=a)return o.position=c,o.snapped=!0,o.snapMode="grid",o}return o}const To=[{id:"sh-light-bulb",name:"Smart Bulb",category:"smart-home",type:"light",icon:"lightbulb",tags:["lighting","bulb"]},{id:"sh-light-dimmer",name:"Dimmer Switch",category:"smart-home",type:"light-dimmer",icon:"lightbulb",tags:["lighting","switch"]},{id:"sh-light-rgb",name:"RGB Light",category:"smart-home",type:"light-rgb",icon:"lightbulb",tags:["lighting","color"]},{id:"sh-light-strip",name:"LED Strip",category:"smart-home",type:"light-strip",icon:"lightbulb",tags:["lighting","strip"]},{id:"sh-thermostat",name:"Thermostat",category:"smart-home",type:"thermostat",icon:"thermometer",tags:["climate","temperature"]},{id:"sh-hvac",name:"HVAC Unit",category:"smart-home",type:"hvac",icon:"thermometer",tags:["climate","cooling","heating"]},{id:"sh-fan",name:"Smart Fan",category:"smart-home",type:"fan",icon:"wifi",tags:["climate","fan"]},{id:"sh-camera",name:"Security Camera",category:"smart-home",type:"camera",icon:"camera",tags:["security","camera"]},{id:"sh-doorbell",name:"Video Doorbell",category:"smart-home",type:"camera-doorbell",icon:"bell",tags:["security","doorbell"]},{id:"sh-lock",name:"Smart Lock",category:"smart-home",type:"lock",icon:"lock",tags:["security","lock"]},{id:"sh-sensor-motion",name:"Motion Sensor",category:"smart-home",type:"sensor-motion",icon:"eye",tags:["security","sensor"]},{id:"sh-sensor-door",name:"Door Sensor",category:"smart-home",type:"sensor-door",icon:"door",tags:["security","sensor"]},{id:"sh-speaker",name:"Smart Speaker",category:"smart-home",type:"speaker",icon:"wifi",tags:["audio","speaker"]},{id:"sh-voice-assistant",name:"Voice Assistant",category:"smart-home",type:"voice-assistant",icon:"mic",tags:["audio","assistant"]},{id:"sh-tv",name:"Smart TV",category:"smart-home",type:"tv",icon:"monitor",tags:["video","tv"]},{id:"furn-sofa-3",name:"3-Seater Sofa",category:"furniture",type:"sofa",defaultSize:{x:2.2,y:.9,z:.85},tags:["seating","sofa"]},{id:"furn-sofa-2",name:"2-Seater Sofa",category:"furniture",type:"sofa",defaultSize:{x:1.6,y:.9,z:.85},tags:["seating","sofa"]},{id:"furn-armchair",name:"Armchair",category:"furniture",type:"armchair",defaultSize:{x:.9,y:.9,z:.85},tags:["seating","chair"]},{id:"furn-dining-chair",name:"Dining Chair",category:"furniture",type:"chair",defaultSize:{x:.45,y:.5,z:.9},tags:["seating","dining"]},{id:"furn-office-chair",name:"Office Chair",category:"furniture",type:"chair",defaultSize:{x:.65,y:.65,z:1.2},tags:["seating","office"]},{id:"furn-dining-table-6",name:"Dining Table (6p)",category:"furniture",type:"table",defaultSize:{x:1.8,y:.9,z:.75},tags:["table","dining"]},{id:"furn-coffee-table",name:"Coffee Table",category:"furniture",type:"table",defaultSize:{x:1.2,y:.6,z:.45},tags:["table","living"]},{id:"furn-desk",name:"Office Desk",category:"furniture",type:"desk",defaultSize:{x:1.6,y:.8,z:.75},tags:["table","office","desk"]},{id:"furn-side-table",name:"Side Table",category:"furniture",type:"table",defaultSize:{x:.5,y:.5,z:.55},tags:["table","side"]},{id:"furn-bed-king",name:"King Bed",category:"furniture",type:"bed",defaultSize:{x:2,y:2.2,z:.5},tags:["bed","bedroom"]},{id:"furn-bed-queen",name:"Queen Bed",category:"furniture",type:"bed",defaultSize:{x:1.6,y:2.1,z:.5},tags:["bed","bedroom"]},{id:"furn-bed-single",name:"Single Bed",category:"furniture",type:"bed",defaultSize:{x:.9,y:2,z:.5},tags:["bed","bedroom"]},{id:"furn-wardrobe",name:"Wardrobe",category:"furniture",type:"wardrobe",defaultSize:{x:1.8,y:.6,z:2.2},tags:["storage","bedroom"]},{id:"furn-bookshelf",name:"Bookshelf",category:"furniture",type:"bookshelf",defaultSize:{x:.8,y:.3,z:2},tags:["storage","books"]},{id:"furn-dresser",name:"Dresser",category:"furniture",type:"dresser",defaultSize:{x:1.2,y:.5,z:.8},tags:["storage","bedroom"]},{id:"net-router",name:"Router",category:"network",type:"router",icon:"wifi",tags:["network","router"]},{id:"net-switch-24",name:"24-Port Switch",category:"network",type:"switch",icon:"plug",tags:["network","switch"]},{id:"net-switch-48",name:"48-Port Switch",category:"network",type:"switch",icon:"plug",tags:["network","switch"]},{id:"net-firewall",name:"Firewall",category:"network",type:"firewall",icon:"lock",tags:["network","security"]},{id:"net-access-point",name:"WiFi Access Point",category:"network",type:"access-point",icon:"wifi",tags:["network","wifi"]},{id:"net-server",name:"Server",category:"network",type:"server",icon:"monitor",tags:["network","server"]},{id:"net-storage",name:"NAS Storage",category:"network",type:"nas",icon:"database",tags:["network","storage"]},{id:"infra-rack-42u",name:"42U Rack",category:"infrastructure",type:"rack-42u",icon:"server",defaultSize:{x:.6,y:1,z:2},tags:["datacenter","rack"]},{id:"infra-rack-24u",name:"24U Rack",category:"infrastructure",type:"rack-24u",icon:"server",defaultSize:{x:.6,y:1,z:1.2},tags:["datacenter","rack"]},{id:"infra-ups",name:"UPS",category:"infrastructure",type:"ups-floor",icon:"zap",tags:["datacenter","power"]},{id:"infra-pdu",name:"PDU",category:"infrastructure",type:"pdu-vertical",icon:"zap",tags:["datacenter","power"]},{id:"infra-cooling",name:"CRAC Unit",category:"infrastructure",type:"cooling-crac",icon:"thermometer",tags:["datacenter","cooling"]},{id:"bld-wall",name:"Wall",category:"building",type:"wall",icon:"square",tags:["building","wall"]},{id:"bld-door",name:"Door",category:"building",type:"door",icon:"door",tags:["building","door"]},{id:"bld-window",name:"Window",category:"building",type:"window",icon:"window",tags:["building","window"]},{id:"bld-stair",name:"Staircase",category:"building",type:"stair",icon:"stairs",tags:["building","stair"]},{id:"game-spawn",name:"Spawn Point",category:"game",type:"spawn-point",icon:"target",tags:["game","spawn"]},{id:"game-checkpoint",name:"Checkpoint",category:"game",type:"checkpoint",icon:"target",tags:["game","checkpoint"]},{id:"game-trigger",name:"Trigger Zone",category:"game",type:"trigger-zone",icon:"zap",tags:["game","trigger"]},{id:"game-item",name:"Item Pickup",category:"game",type:"item-pickup",icon:"box",tags:["game","item"]},{id:"game-enemy",name:"Enemy Spawner",category:"game",type:"enemy-spawner",icon:"gamepad",tags:["game","enemy"]}];function Rt(t,n="floor-plan"){const s=new Date().toISOString();return{$schema:"https://nice2dev.com/schemas/nsp-v1.json",version:"1.0.0",type:n,metadata:{id:Lo(),name:t,created:s,modified:s},floors:[],settings:{units:"metric",scale:50,grid:{visible:!0,size:.5,snapEnabled:!0},defaultWallHeight:2.7,defaultWallThickness:.15,precision:2}}}function Lo(){return`${Date.now().toString(36)}-${Math.random().toString(36).substr(2,9)}`}const xn={ft:3.28084,in:39.3701},vn={"ft²":.092903,acre:4046.86};function $o(t){return t*(180/Math.PI)}function zo(t,n){return Math.sqrt((n.x-t.x)**2+(n.y-t.y)**2)}function Po(t){if(t.length<2)return 0;let n=0;for(let s=1;s<t.length;s++)n+=zo(t[s-1],t[s]);return n}function Jt(t,n,s){const o={x:t.x-n.x,y:t.y-n.y},i={x:s.x-n.x,y:s.y-n.y},a=o.x*i.x+o.y*i.y,c=Math.sqrt(o.x**2+o.y**2),r=Math.sqrt(i.x**2+i.y**2);if(c===0||r===0)return 0;const d=a/(c*r);return Math.acos(Math.max(-1,Math.min(1,d)))}function Qt(t){if(t.length<3)return 0;let n=0;const s=t.length;for(let o=0;o<s;o++){const i=(o+1)%s;n+=t[o].x*t[i].y,n-=t[i].x*t[o].y}return Math.abs(n)/2}function bt(t,n="m",s=2){const o=`${t.toFixed(s)} ${n}`;return{value:t,unit:n,formatted:o}}function $t(t,n="m²",s=2){const o=`${t.toFixed(s)} ${n}`;return{value:t,unit:n,formatted:o}}function en(t,n="deg",s=1){const o=n==="deg"?$o(t):t,i=n==="deg"?"°":" rad",a=`${o.toFixed(s)}${i}`;return{value:o,unit:n,formatted:a}}function zt(t,n="metric",s=2){if(n==="metric")return t<.01?bt(t*1e3,"mm",s):t<1?bt(t*100,"cm",s):bt(t,"m",s);{const o=t*xn.ft;return o<1?bt(t*xn.in,"in",s):bt(o,"ft",s)}}function tn(t,n="metric",s=2){if(n==="metric")return t>=1e4?$t(t/1e4,"ha",s):$t(t,"m²",s);{const o=t/vn["ft²"];return o>=43560?$t(t/vn.acre,"acre",s):$t(o,"ft²",s)}}function Eo(t,n={}){const{pretty:s=!1,includeSchema:o=!0,excludeEmptyLayers:i=!1,includeMetadata:a=!0}=n,c=JSON.parse(JSON.stringify(t));if(o&&!c.$schema&&(c.$schema="https://nice2dev.com/schemas/nsp-v1.json"),a&&(c.metadata=c.metadata??{id:"",name:"",created:new Date().toISOString(),modified:new Date().toISOString()},c.metadata.modified=new Date().toISOString()),i)for(const r of c.floors)r.layers=r.layers.filter(d=>d.objects.length>0);return s?JSON.stringify(c,null,2):JSON.stringify(c)}function Oo(t,n={}){var c;const s=Vo(t,n),o=Eo(s),i=new Blob([o],{type:"application/json"});return{format:"nsp",filename:`${((c=t.metadata)==null?void 0:c.name)||"document"}.nsp.json`,mimeType:"application/json",data:i,size:i.size}}const Mo="http://www.w3.org/2000/svg";function Ao(t,n={}){var j,w;const{floorIds:s,includeGrid:o=!1,scale:i=1,backgroundColor:a}=n,c=s?t.floors.filter(x=>s.includes(x.id)):t.floors;if(c.length===0)throw new Error("No floors to export");const r=Go(c),d=(r.maxX-r.minX)*i,_=(r.maxY-r.minY)*i,p=((j=t.metadata)==null?void 0:j.name)||"Floor Plan";let f=`<?xml version="1.0" encoding="UTF-8"?>
2
+ <svg xmlns="${Mo}"
3
3
  viewBox="${r.minX} ${r.minY} ${r.maxX-r.minX} ${r.maxY-r.minY}"
4
- width="${l}"
5
- height="${x}"
4
+ width="${d}"
5
+ height="${_}"
6
6
  style="background: ${a||"transparent"}">
7
- <title>${m}</title>
7
+ <title>${p}</title>
8
8
  <desc>Exported from NiceToDev Spatial Editor</desc>
9
9
  <defs>
10
10
  <style>
@@ -18,19 +18,19 @@
18
18
  .annotation { font-family: sans-serif; font-size: 12px; fill: #334155; }
19
19
  </style>
20
20
  </defs>
21
- `;for(const f of c){h+=` <g id="${f.id}" class="floor" data-name="${f.name}">
22
- `,o&&(h+=$o(r));for(const I of f.layers)if(Un(I.name,n)){h+=` <g id="${I.id}" class="layer-${I.name}">
23
- `;for(const b of I.objects)h+=zo(b);h+=` </g>
24
- `}h+=` </g>
25
- `}h+="</svg>";const v=new Blob([h],{type:"image/svg+xml"});return{format:"svg",filename:`${((j=t.metadata)==null?void 0:j.name)||"document"}.svg`,mimeType:"image/svg+xml",data:v,size:v.size}}function $o(t){let s=` <g class="grid">
21
+ `;for(const x of c){f+=` <g id="${x.id}" class="floor" data-name="${x.name}">
22
+ `,o&&(f+=Do(r));for(const C of x.layers)if(Zn(C.name,n)){f+=` <g id="${C.id}" class="layer-${C.name}">
23
+ `;for(const g of C.objects)f+=Bo(g);f+=` </g>
24
+ `}f+=` </g>
25
+ `}f+="</svg>";const y=new Blob([f],{type:"image/svg+xml"});return{format:"svg",filename:`${((w=t.metadata)==null?void 0:w.name)||"document"}.svg`,mimeType:"image/svg+xml",data:y,size:y.size}}function Do(t){let s=` <g class="grid">
26
26
  `;for(let o=Math.floor(t.minX/20)*20;o<=t.maxX;o+=20)s+=` <line x1="${o}" y1="${t.minY}" x2="${o}" y2="${t.maxY}" />
27
27
  `;for(let o=Math.floor(t.minY/20)*20;o<=t.maxY;o+=20)s+=` <line x1="${t.minX}" y1="${o}" x2="${t.maxX}" y2="${o}" />
28
28
  `;return s+=` </g>
29
- `,s}function zo(t){const n=t;if(n.boundary&&Array.isArray(n.boundary)&&n.boundary.length>=3)return` <path d="${n.boundary.map((o,i)=>`${i===0?"M":"L"}${o.x},${o.y}`).join(" ")+" Z"}" class="zone" fill="${n.color||"#dbeafe"}" stroke="${n.color||"#3b82f6"}" />
29
+ `,s}function Bo(t){const n=t;if(n.boundary&&Array.isArray(n.boundary)&&n.boundary.length>=3)return` <path d="${n.boundary.map((o,i)=>`${i===0?"M":"L"}${o.x},${o.y}`).join(" ")+" Z"}" class="zone" fill="${n.color||"#dbeafe"}" stroke="${n.color||"#3b82f6"}" />
30
30
  `;if(n.start&&n.end)return` <line x1="${n.start.x}" y1="${n.start.y}" x2="${n.end.x}" y2="${n.end.y}" class="wall" stroke-width="${n.thickness||3}" />
31
31
  `;if(t.bounds){const{x:s,y:o,width:i,height:a}=t.bounds,c=s+i/2,r=o+a/2;return t.category==="smart-home"?` <circle cx="${c}" cy="${r}" r="${Math.min(i,a)/2}" class="device" />
32
32
  `:` <rect x="${s}" y="${o}" width="${i}" height="${a}" class="${t.category||"object"}" />
33
- `}return""}function Po(t,n={}){var x;const{floorIds:s,scale:o=1}=n,i=s?t.floors.filter(m=>s.includes(m.id)):t.floors;if(i.length===0)throw new Error("No floors to export");let a="";a+=`0
33
+ `}return""}function Ro(t,n={}){var _;const{floorIds:s,scale:o=1}=n,i=s?t.floors.filter(p=>s.includes(p.id)):t.floors;if(i.length===0)throw new Error("No floors to export");let a="";a+=`0
34
34
  SECTION
35
35
  2
36
36
  HEADER
@@ -52,10 +52,10 @@ TABLES
52
52
  TABLE
53
53
  2
54
54
  LAYER
55
- `;const c=new Set;for(const m of i)for(const h of m.layers)c.add(h.name);for(const m of c)a+=`0
55
+ `;const c=new Set;for(const p of i)for(const f of p.layers)c.add(f.name);for(const p of c)a+=`0
56
56
  LAYER
57
57
  2
58
- ${m.toUpperCase()}
58
+ ${p.toUpperCase()}
59
59
  70
60
60
  0
61
61
  62
@@ -70,11 +70,11 @@ ENDSEC
70
70
  SECTION
71
71
  2
72
72
  ENTITIES
73
- `;for(const m of i)for(const h of m.layers){if(!Un(h.name,n))continue;const v=h.name.toUpperCase();for(const _ of h.objects)a+=Eo(_,v,o)}a+=`0
73
+ `;for(const p of i)for(const f of p.layers){if(!Zn(f.name,n))continue;const y=f.name.toUpperCase();for(const b of f.objects)a+=Fo(b,y,o)}a+=`0
74
74
  ENDSEC
75
75
  0
76
76
  EOF
77
- `;const r=new Blob([a],{type:"application/dxf"});return{format:"dxf",filename:`${((x=t.metadata)==null?void 0:x.name)||"document"}.dxf`,mimeType:"application/dxf",data:r,size:r.size}}function Eo(t,n,s){const o=t;if(o.boundary&&Array.isArray(o.boundary)&&o.boundary.length>=3){let i=`0
77
+ `;const r=new Blob([a],{type:"application/dxf"});return{format:"dxf",filename:`${((_=t.metadata)==null?void 0:_.name)||"document"}.dxf`,mimeType:"application/dxf",data:r,size:r.size}}function Fo(t,n,s){const o=t;if(o.boundary&&Array.isArray(o.boundary)&&o.boundary.length>=3){let i=`0
78
78
  LWPOLYLINE
79
79
  8
80
80
  ${n}
@@ -98,16 +98,16 @@ ${o.start.y*s}
98
98
  ${o.end.x*s}
99
99
  21
100
100
  ${o.end.y*s}
101
- `;if(t.bounds){const{x:i,y:a,width:c,height:r}=t.bounds,l=(i+c/2)*s,x=(a+r/2)*s;if(t.category==="smart-home"){const m=Math.min(c,r)/2*s;return`0
101
+ `;if(t.bounds){const{x:i,y:a,width:c,height:r}=t.bounds,d=(i+c/2)*s,_=(a+r/2)*s;if(t.category==="smart-home"){const p=Math.min(c,r)/2*s;return`0
102
102
  CIRCLE
103
103
  8
104
104
  ${n}
105
105
  10
106
- ${l}
106
+ ${d}
107
107
  20
108
- ${x}
108
+ ${_}
109
109
  40
110
- ${m}
110
+ ${p}
111
111
  `}return`0
112
112
  LWPOLYLINE
113
113
  8
@@ -132,8 +132,8 @@ ${(a+r)*s}
132
132
  ${i*s}
133
133
  20
134
134
  ${(a+r)*s}
135
- `}return""}function Oo(t){let n=1/0,s=1/0,o=-1/0,i=-1/0;for(const a of t){a.bounds&&(n=Math.min(n,a.bounds.x),s=Math.min(s,a.bounds.y),o=Math.max(o,a.bounds.x+a.bounds.width),i=Math.max(i,a.bounds.y+a.bounds.height));for(const c of a.layers)for(const r of c.objects){r.bounds&&(n=Math.min(n,r.bounds.x),s=Math.min(s,r.bounds.y),o=Math.max(o,r.bounds.x+r.bounds.width),i=Math.max(i,r.bounds.y+r.bounds.height));const l=r;if(l.boundary)for(const x of l.boundary)n=Math.min(n,x.x),s=Math.min(s,x.y),o=Math.max(o,x.x),i=Math.max(i,x.y)}}return isFinite(n)||(n=0),isFinite(s)||(s=0),isFinite(o)||(o=1e3),isFinite(i)||(i=800),{minX:n,minY:s,maxX:o,maxY:i}}function Mo(t,n){const{floorIds:s,layerNames:o}=n;let i=t.floors;return s&&s.length>0&&(i=i.filter(a=>s.includes(a.id))),o&&o.length>0&&(i=i.map(a=>({...a,layers:a.layers.filter(c=>o.includes(c.name))}))),{...t,floors:i}}function Un(t,n){const{layerNames:s,includeGrid:o,includeDimensions:i}=n;return t==="grid"&&!o||(t==="dimensions"||t==="annotations")&&i===!1?!1:s&&s.length>0?s.includes(t):!0}function Lt(t){const n=t.data instanceof Blob?t.data:new Blob([t.data],{type:t.mimeType}),s=URL.createObjectURL(n),o=document.createElement("a");o.href=s,o.download=t.filename,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(s)}async function Ao(t,n,s={}){const{dpi:o=96,backgroundColor:i="#ffffff"}=s,a=new XMLSerializer().serializeToString(t),c=new Blob([a],{type:"image/svg+xml;charset=utf-8"}),r=URL.createObjectURL(c);return new Promise((l,x)=>{const m=new Image;m.onload=()=>{const h=o/96,v=document.createElement("canvas");v.width=m.width*h,v.height=m.height*h;const _=v.getContext("2d");if(!_){x(new Error("Could not get canvas context"));return}_.fillStyle=i,_.fillRect(0,0,v.width,v.height),_.scale(h,h),_.drawImage(m,0,0),v.toBlob(p=>{if(URL.revokeObjectURL(r),!p){x(new Error("Could not create PNG blob"));return}l({format:"png",filename:n.endsWith(".png")?n:`${n}.png`,mimeType:"image/png",data:p,size:p.size})},"image/png")},m.onerror=()=>{URL.revokeObjectURL(r),x(new Error("Failed to load SVG for PNG export"))},m.src=r})}function Yn(t){const n=new Map;for(const s of t)s.status!=="error"&&(n.has(s.sourceId)||n.set(s.sourceId,[]),n.get(s.sourceId).push({deviceId:s.targetId,connection:s}),n.has(s.targetId)||n.set(s.targetId,[]),n.get(s.targetId).push({deviceId:s.sourceId,connection:s}));return n}function Do(t,n,s,o="latency"){const i=Yn(t);if(!i.has(n)||!i.has(s))return null;const a=new Map,c=new Map,r=new Set,l=[];for(const p of i.keys())a.set(p,1/0),c.set(p,null);for(a.set(n,0),l.push({deviceId:n,distance:0});l.length>0;){l.sort((f,I)=>f.distance-I.distance);const p=l.shift();if(r.has(p.deviceId))continue;if(r.add(p.deviceId),p.deviceId===s)break;const j=i.get(p.deviceId)??[];for(const f of j){if(r.has(f.deviceId))continue;let I;switch(o){case"latency":I=f.connection.latency??1;break;case"hops":I=1;break;case"bandwidth":I=1/(f.connection.bandwidth??1);break}const b=a.get(p.deviceId)+I;b<a.get(f.deviceId)&&(a.set(f.deviceId,b),c.set(f.deviceId,{deviceId:p.deviceId,connection:f.connection}),l.push({deviceId:f.deviceId,distance:b}))}}if(!c.has(s)||a.get(s)===1/0)return null;const x=[];let m=0,h=1/0,v="active",_=s;for(;_&&c.get(_);){const p=c.get(_);x.unshift(p.connection.id),m+=p.connection.latency??0,p.connection.bandwidth!==void 0&&(h=Math.min(h,p.connection.bandwidth)),p.connection.status==="error"?v="error":p.connection.status==="degraded"&&v!=="error"?v="degraded":p.connection.status==="inactive"&&v==="active"&&(v="inactive"),_=p.deviceId}return{id:`path-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,startDeviceId:n,endDeviceId:s,connectionIds:x,totalLatency:m,bottleneckBandwidth:h===1/0?0:h,status:v,isPrimary:!0}}function Bo(t,n,s,o=5){const i=[],a=Yn(t);function c(r,l,x,m){if(i.length>=o)return;if(r===l&&m.length>0){let v=0,_=1/0,p="active";for(const j of m)v+=j.latency??0,j.bandwidth!==void 0&&(_=Math.min(_,j.bandwidth)),j.status==="error"?p="error":j.status==="degraded"&&p!=="error"&&(p="degraded");i.push({id:`path-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,startDeviceId:n,endDeviceId:s,connectionIds:m.map(j=>j.id),totalLatency:v,bottleneckBandwidth:_===1/0?0:_,status:p,isPrimary:i.length===0});return}x.add(r);const h=a.get(r)??[];for(const v of h)x.has(v.deviceId)||c(v.deviceId,l,new Set(x),[...m,v.connection])}return c(n,s,new Set,[]),i}function Ro(t){var l,x;const n=[],s=t.split(/\r?\n/);let o=0,i=!1,a=null,c=[],r=null;for(;o<s.length;){const m=parseInt(((l=s[o])==null?void 0:l.trim())??"",10),h=((x=s[o+1])==null?void 0:x.trim())??"";if(o+=2,m===2&&h==="ENTITIES"){i=!0;continue}if(m===0&&h==="ENDSEC"&&i){a!=null&&a.type&&(c.length>0&&(a.vertices=[...c]),n.push(a)),i=!1;continue}if(i){if(m===0){a!=null&&a.type&&(c.length>0&&(a.vertices=[...c]),n.push(a)),a={type:h,layer:"0"},c=[],r=null;continue}if(a)switch(m){case 8:a.layer=h;break;case 5:a.handle=h;break;case 10:r=parseFloat(h);break;case 20:r!==null&&(c.push({x:r,y:parseFloat(h)}),a.position||(a.position={x:r,y:parseFloat(h)}),r=null);break;case 11:r=parseFloat(h);break;case 21:r!==null&&(c.push({x:r,y:parseFloat(h)}),r=null);break;case 40:(a.type==="CIRCLE"||a.type==="ARC")&&(a.radius=parseFloat(h));break;case 50:a.startAngle=parseFloat(h);break;case 51:a.endAngle=parseFloat(h);break;case 1:a.text=h;break;case 2:a.blockName=h;break;case 70:parseInt(h,10)&1&&(a.closed=!0);break}}}return n}function Fo(t,n={}){var r,l;const s=Date.now(),o=[],i=[],a=n.scaleFactor??1,c=n.originOffset??{x:0,y:0};try{const x=Ro(t),m=[],h=[],v=[],_=new Set;let p=0;for(const f of x){if(_.add(f.layer),n.includeLayers&&!n.includeLayers.includes(f.layer)){p++;continue}if((r=n.excludeLayers)!=null&&r.includes(f.layer)){p++;continue}const I=((l=n.layerMappings)==null?void 0:l[f.layer])??f.layer;switch(f.type){case"LINE":if(f.vertices&&f.vertices.length>=2){const b=we(f.vertices[0],a,c),$=we(f.vertices[1],a,c);m.push({start:b,end:$,layer:I})}break;case"LWPOLYLINE":case"POLYLINE":if(f.vertices&&f.vertices.length>=2){const b=f.vertices.map(y=>we(y,a,c));if(f.closed&&n.convertClosedPolylinesToZones){const y=Zn(b),C=n.minZoneArea??.1;if(y>=C){h.push({name:I,boundary:b,layer:I});continue}}const $=f.closed?b.length:b.length-1;for(let y=0;y<$;y++){const C=b[y],d=b[(y+1)%b.length];m.push({start:C,end:d,layer:I})}}break;case"CIRCLE":if(f.position&&f.radius){const b=we(f.position,a,c);v.push({type:"circle",position:b,layer:I,metadata:{radius:f.radius*a}})}break;case"INSERT":if(f.position&&f.blockName){const b=we(f.position,a,c);v.push({type:"block-reference",position:b,layer:I,metadata:{blockName:f.blockName}})}break;default:p++,o.push({code:"UNSUPPORTED_ENTITY",message:`Unsupported DXF entity type: ${f.type}`,context:{type:f.type,layer:f.layer}})}}return{success:!0,document:Ft(m,h,v,_,{name:"Imported DXF",sourceFormat:"dxf",units:n.defaultUnits??"metric"}),warnings:o,errors:i,stats:{wallsImported:m.length,zonesImported:h.length,objectsImported:v.length,layersFound:_.size,entitiesSkipped:p,importTimeMs:Date.now()-s}}}catch(x){return i.push({code:"PARSE_ERROR",message:x instanceof Error?x.message:"Unknown error parsing DXF",fatal:!0}),{success:!1,warnings:o,errors:i,stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:Date.now()-s}}}}function Go(t){const n=[];let s=[],o=0,i=0,a=0,c=0;const r=t.match(/[MmLlHhVvCcSsQqTtAaZz]|[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[];let l=0;for(;l<r.length;){const x=r[l];l++;const m=()=>{const h=parseFloat(r[l]??"0");return l++,h};switch(x){case"M":s.length>0&&(n.push(s),s=[]),o=m(),i=m(),a=o,c=i,s.push({x:o,y:i});break;case"m":s.length>0&&(n.push(s),s=[]),o+=m(),i+=m(),a=o,c=i,s.push({x:o,y:i});break;case"L":o=m(),i=m(),s.push({x:o,y:i});break;case"l":o+=m(),i+=m(),s.push({x:o,y:i});break;case"H":o=m(),s.push({x:o,y:i});break;case"h":o+=m(),s.push({x:o,y:i});break;case"V":i=m(),s.push({x:o,y:i});break;case"v":i+=m(),s.push({x:o,y:i});break;case"Z":case"z":s.length>0&&s.push({x:a,y:c}),o=a,i=c;break;case"C":m(),m(),m(),m(),o=m(),i=m(),s.push({x:o,y:i});break;case"c":m(),m(),m(),m(),o+=m(),i+=m(),s.push({x:o,y:i});break;case"Q":m(),m(),o=m(),i=m(),s.push({x:o,y:i});break;case"q":m(),m(),o+=m(),i+=m(),s.push({x:o,y:i});break}}return s.length>0&&n.push(s),n}function qo(t){let n=0,s=0,o=1;const i=t.match(/translate\s*\(\s*([-\d.]+)(?:\s*,?\s*([-\d.]+))?\s*\)/);i&&(n=parseFloat(i[1]),s=parseFloat(i[2]??"0"));const a=t.match(/scale\s*\(\s*([-\d.]+)(?:\s*,?\s*([-\d.]+))?\s*\)/);return a&&(o=parseFloat(a[1])),{translate:{x:n,y:s},scale:o}}function Vo(t,n={}){const s=Date.now(),o=[],i=[],a=n.scaleFactor??1,c=n.originOffset??{x:0,y:0};try{const r=[],l=[],x=[],m=new Set,h=/<path[^>]*\bd="([^"]+)"[^>]*>/gi;let v;for(;(v=h.exec(t))!==null;){const y=v[1],C=v[0],d=C.match(/\bid="([^"]+)"/),k=(d==null?void 0:d[1])??"default";m.add(k);const g=C.match(/\btransform="([^"]+)"/),G=g?qo(g[1]):{translate:{x:0,y:0},scale:1},T=Go(y);for(const R of T){if(R.length<2)continue;const H=R.map(ne=>we({x:ne.x*G.scale+G.translate.x,y:ne.y*G.scale+G.translate.y},a,c));if(Math.abs(H[0].x-H[H.length-1].x)<.1&&Math.abs(H[0].y-H[H.length-1].y)<.1&&n.convertClosedPolylinesToZones&&Zn(H)>=(n.minZoneArea??.1)){l.push({name:k,boundary:H,layer:k});continue}for(let ne=0;ne<H.length-1;ne++)r.push({start:H[ne],end:H[ne+1],layer:k})}}const _=/<line[^>]*\bx1="([^"]+)"[^>]*\by1="([^"]+)"[^>]*\bx2="([^"]+)"[^>]*\by2="([^"]+)"[^>]*>/gi;let p;for(;(p=_.exec(t))!==null;){const y=parseFloat(p[1]),C=parseFloat(p[2]),d=parseFloat(p[3]),k=parseFloat(p[4]),g=we({x:y,y:C},a,c),G=we({x:d,y:k},a,c);r.push({start:g,end:G,layer:"default"}),m.add("default")}const j=/<rect[^>]*\bx="([^"]+)"[^>]*\by="([^"]+)"[^>]*\bwidth="([^"]+)"[^>]*\bheight="([^"]+)"[^>]*>/gi;let f;for(;(f=j.exec(t))!==null;){const y=parseFloat(f[1]),C=parseFloat(f[2]),d=parseFloat(f[3]),k=parseFloat(f[4]),g=[we({x:y,y:C},a,c),we({x:y+d,y:C},a,c),we({x:y+d,y:C+k},a,c),we({x:y,y:C+k},a,c)];n.convertClosedPolylinesToZones?l.push({name:"rect",boundary:g,layer:"default"}):(r.push({start:g[0],end:g[1],layer:"default"}),r.push({start:g[1],end:g[2],layer:"default"}),r.push({start:g[2],end:g[3],layer:"default"}),r.push({start:g[3],end:g[0],layer:"default"})),m.add("default")}const I=/<circle[^>]*\bcx="([^"]+)"[^>]*\bcy="([^"]+)"[^>]*\br="([^"]+)"[^>]*>/gi;let b;for(;(b=I.exec(t))!==null;){const y=parseFloat(b[1]),C=parseFloat(b[2]),d=parseFloat(b[3]),k=we({x:y,y:C},a,c);x.push({type:"circle",position:k,layer:"default",metadata:{radius:d*a}}),m.add("default")}return{success:!0,document:Ft(r,l,x,m,{name:"Imported SVG",sourceFormat:"svg",units:n.defaultUnits??"metric"}),warnings:o,errors:i,stats:{wallsImported:r.length,zonesImported:l.length,objectsImported:x.length,layersFound:m.size,entitiesSkipped:0,importTimeMs:Date.now()-s}}}catch(r){return i.push({code:"PARSE_ERROR",message:r instanceof Error?r.message:"Unknown error parsing SVG",fatal:!0}),{success:!1,warnings:o,errors:i,stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:Date.now()-s}}}}function Wo(t,n={}){var r;const s=Date.now(),o=[],i=[],a=n.scaleFactor??1,c=n.originOffset??{x:0,y:0};try{const l=JSON.parse(t),x=[],m=[],h=[],v=new Set;let _=0;const p=l.type==="FeatureCollection"?l.features:[l];for(const f of p){const I=((r=f.properties)==null?void 0:r.layer)??"default";v.add(I);const b=f.geometry;switch(b.type){case"Point":{const $=b.coordinates,y=we({x:$[0],y:$[1]},a,c);h.push({type:"marker",position:y,layer:I,metadata:{properties:f.properties}});break}case"LineString":{const $=b.coordinates;for(let y=0;y<$.length-1;y++){const C=we({x:$[y][0],y:$[y][1]},a,c),d=we({x:$[y+1][0],y:$[y+1][1]},a,c);x.push({start:C,end:d,layer:I})}break}case"MultiLineString":{const $=b.coordinates;for(const y of $)for(let C=0;C<y.length-1;C++){const d=we({x:y[C][0],y:y[C][1]},a,c),k=we({x:y[C+1][0],y:y[C+1][1]},a,c);x.push({start:d,end:k,layer:I})}break}case"Polygon":{const C=b.coordinates[0].map(d=>we({x:d[0],y:d[1]},a,c));m.push({name:I,boundary:C,layer:I});break}case"MultiPolygon":{const $=b.coordinates;for(const y of $){const d=y[0].map(k=>we({x:k[0],y:k[1]},a,c));m.push({name:I,boundary:d,layer:I})}break}default:_++,o.push({code:"UNSUPPORTED_GEOMETRY",message:`Unsupported GeoJSON geometry: ${b.type}`})}}return{success:!0,document:Ft(x,m,h,v,{name:"Imported GeoJSON",sourceFormat:"geojson",units:n.defaultUnits??"metric"}),warnings:o,errors:i,stats:{wallsImported:x.length,zonesImported:m.length,objectsImported:h.length,layersFound:v.size,entitiesSkipped:_,importTimeMs:Date.now()-s}}}catch(l){return i.push({code:"PARSE_ERROR",message:l instanceof Error?l.message:"Unknown error parsing GeoJSON",fatal:!0}),{success:!1,warnings:o,errors:i,stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:Date.now()-s}}}}function Ho(t,n={}){const s=Date.now(),o=[],i=[];o.push({code:"LIMITED_IFC_SUPPORT",message:"IFC import is limited. For full support, use a dedicated IFC library like web-ifc."});try{const a=[],c=[],r=[],l=new Set;let x=0;const m=t.split(/\r?\n/),h=new Map;for(const _ of m){const p=_.match(/^#(\d+)\s*=\s*(\w+)\s*\((.+)\)\s*;?$/);p&&h.set(`#${p[1]}`,{type:p[2],params:p[3]})}for(const[_,p]of h)if(p.type==="IFCWALLSTANDARDCASE"||p.type==="IFCWALL"){l.add("Walls");const j=p.params.match(/'([^']+)'/),f=(j==null?void 0:j[1])??"Wall";o.push({code:"IFC_WALL_SIMPLIFIED",message:`Wall "${f}" (${_}) geometry simplified to placeholder`}),x++}else if(p.type==="IFCSPACE"){l.add("Spaces");const j=p.params.match(/'([^']+)'/),f=(j==null?void 0:j[1])??"Space";o.push({code:"IFC_SPACE_SIMPLIFIED",message:`Space "${f}" (${_}) geometry simplified to placeholder`}),x++}return{success:!0,document:Ft(a,c,r,l,{name:"Imported IFC",sourceFormat:"ifc",units:n.defaultUnits??"metric"}),warnings:o,errors:i,stats:{wallsImported:a.length,zonesImported:c.length,objectsImported:r.length,layersFound:l.size,entitiesSkipped:x,importTimeMs:Date.now()-s}}}catch(a){return i.push({code:"PARSE_ERROR",message:a instanceof Error?a.message:"Unknown error parsing IFC",fatal:!0}),{success:!1,warnings:o,errors:i,stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:Date.now()-s}}}}function Uo(t,n,s={}){switch(n){case"dxf":return Fo(t,s);case"svg":return Vo(t,s);case"geojson":return Wo(t,s);case"ifc":return Ho(t,s);default:return{success:!1,warnings:[],errors:[{code:"UNSUPPORTED_FORMAT",message:`Unsupported import format: ${n}`,fatal:!0}],stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:0}}}}function Yo(t,n){const s=t.toLowerCase().split(".").pop();switch(s){case"dxf":return"dxf";case"svg":return"svg";case"geojson":case"json":return n!=null&&n.includes('"type"')&&(n.includes('"Feature"')||n.includes('"FeatureCollection"'))||s==="geojson"?"geojson":null;case"ifc":return"ifc";default:if(n){if(n.includes("ISO-10303-21")||n.includes("IFCPROJECT"))return"ifc";if(n.includes("<?xml")&&n.includes("<svg"))return"svg";if(n.includes("SECTION")&&n.includes("ENTITIES"))return"dxf"}return null}}async function Zo(t,n={}){return new Promise(s=>{const o=new FileReader;o.onload=()=>{const i=o.result,a=n.format??Yo(t.name,i);if(!a){s({success:!1,warnings:[],errors:[{code:"UNKNOWN_FORMAT",message:`Unable to detect format for file: ${t.name}`,fatal:!0}],stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:0}});return}s(Uo(i,a,n))},o.onerror=()=>{s({success:!1,warnings:[],errors:[{code:"FILE_READ_ERROR",message:"Error reading file",fatal:!0}],stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:0}})},o.readAsText(t)})}function nt(){return`${Date.now()}-${Math.random().toString(36).slice(2,9)}`}function we(t,n,s){return{x:t.x*n+s.x,y:t.y*n+s.y}}function Zn(t){let n=0;const s=t.length;for(let o=0;o<s;o++){const i=(o+1)%s;n+=t[o].x*t[i].y,n-=t[i].x*t[o].y}return Math.abs(n/2)}function xn(t){if(t.length===0)return{x:0,y:0,width:0,height:0};let n=1/0,s=1/0,o=-1/0,i=-1/0;for(const a of t)a.x<n&&(n=a.x),a.y<s&&(s=a.y),a.x>o&&(o=a.x),a.y>i&&(i=a.y);return{x:n,y:s,width:o-n,height:i-s}}function vn(t){let n=0;for(let o=0;o<t.length;o++)n=t.charCodeAt(o)+((n<<5)-n);return`hsl(${Math.abs(n)%360}, 60%, 50%)`}function jn(t){return{position:t,rotation:0,scale:{x:1,y:1}}}function Ft(t,n,s,o,i){const a=new Date().toISOString(),c=`floor-${nt()}`,r=[];for(const j of t)r.push(j.start,j.end);for(const j of n)r.push(...j.boundary);for(const j of s)r.push(j.position);const l=xn(r),x=t.map(j=>({id:`wall-${nt()}`,type:"wall",category:"building",name:"Wall",transform:jn(j.start),bounds:xn([j.start,j.end]),layer:j.layer,locked:!1,visible:!0,metadata:{end:j.end,thickness:j.thickness??.15,importedAt:a},childIds:[]})),m=s.map(j=>({id:`obj-${nt()}`,type:j.type,category:"annotation",name:j.type,transform:jn(j.position),bounds:{x:j.position.x-10,y:j.position.y-10,width:20,height:20},layer:j.layer,locked:!1,visible:!0,metadata:{...j.metadata,importedAt:a},childIds:[]})),h=Array.from(o).map(j=>({id:`layer-${nt()}`,name:j,type:j.toLowerCase().includes("wall")?"walls":"custom",visible:!0,locked:!1,opacity:1,color:vn(j),objects:[...x.filter(f=>f.layer===j),...m.filter(f=>f.layer===j)]})),v={id:c,name:"Imported Floor",level:0,elevation:0,ceilingHeight:2.7,bounds:l,layers:h},_=n.map(j=>({id:`zone-${nt()}`,name:j.name,type:"custom",boundary:j.boundary,floorId:c,roomIds:[],color:vn(j.name)})),p={$schema:"https://nice2dev.com/schemas/nsp-v1.json",version:"1.0.0",type:"floor-plan",metadata:{id:`doc-${nt()}`,name:i.name,description:`Imported from ${i.sourceFormat.toUpperCase()}`,created:a,modified:a,tags:["imported",i.sourceFormat]},floors:[v],settings:{units:i.units,scale:50,grid:{visible:!0,size:.5,snapEnabled:!0},defaultWallHeight:2.7,defaultWallThickness:.15,precision:2}};return p.zones=_,p}const Xo=10,Ko=8;class Jo{constructor(n,s=Xo){St(this,"root");St(this,"maxItems");St(this,"itemMap",new Map);this.root={bounds:n,items:[],children:null},this.maxItems=s}insert(n){this.itemMap.set(n.id,n),this.insertIntoNode(this.root,n,0)}remove(n){const s=this.itemMap.get(n);return s?(this.itemMap.delete(n),this.removeFromNode(this.root,s)):!1}update(n,s){const o=this.itemMap.get(n);return o?(this.remove(n),o.bounds=s,this.insert(o),!0):!1}query(n){const s=[];return this.queryNode(this.root,n,s),s}getAll(){return Array.from(this.itemMap.values())}get(n){return this.itemMap.get(n)}get size(){return this.itemMap.size}clear(){this.itemMap.clear(),this.root.items=[],this.root.children=null}rebuild(){const n=Array.from(this.itemMap.values());this.root.items=[],this.root.children=null;for(const s of n)this.insertIntoNode(this.root,s,0)}insertIntoNode(n,s,o){if(n.children){const i=this.getChildIndex(n,s.bounds);if(i!==-1){this.insertIntoNode(n.children[i],s,o+1);return}n.items.push(s);return}if(n.items.push(s),n.items.length>this.maxItems&&o<Ko){this.split(n);const i=[...n.items];n.items=[];for(const a of i)this.insertIntoNode(n,a,o)}}removeFromNode(n,s){const o=n.items.findIndex(i=>i.id===s.id);if(o!==-1)return n.items.splice(o,1),!0;if(n.children){for(const i of n.children)if(this.boundsIntersect(i.bounds,s.bounds)&&this.removeFromNode(i,s))return!0}return!1}queryNode(n,s,o){for(const i of n.items)this.boundsIntersect(i.bounds,s)&&o.push(i);if(n.children)for(const i of n.children)this.boundsIntersect(i.bounds,s)&&this.queryNode(i,s,o)}split(n){const{x:s,y:o,width:i,height:a}=n.bounds,c=i/2,r=a/2;n.children=[{bounds:{x:s,y:o,width:c,height:r},items:[],children:null},{bounds:{x:s+c,y:o,width:c,height:r},items:[],children:null},{bounds:{x:s,y:o+r,width:c,height:r},items:[],children:null},{bounds:{x:s+c,y:o+r,width:c,height:r},items:[],children:null}]}getChildIndex(n,s){if(!n.children)return-1;const o=n.bounds.x+n.bounds.width/2,i=n.bounds.y+n.bounds.height/2,a=s.x+s.width<=o,c=s.x>=o,r=s.y+s.height<=i,l=s.y>=i;return r&&a?0:r&&c?1:l&&a?2:l&&c?3:-1}boundsIntersect(n,s){return n.x<s.x+s.width&&n.x+n.width>s.x&&n.y<s.y+s.height&&n.y+n.height>s.y}}function Qo(t,n=100){let s=1/0,o=1/0,i=-1/0,a=-1/0;for(const l of t){const{x,y:m}=l.position,{width:h=20,height:v=20}=l.size??{};s=Math.min(s,x-h/2),o=Math.min(o,m-v/2),i=Math.max(i,x+h/2),a=Math.max(a,m+v/2)}Number.isFinite(s)||(s=o=0,i=a=1e3);const c={x:s-n,y:o-n,width:i-s+n*2,height:a-o+n*2},r=new Jo(c);for(const l of t){const{x,y:m}=l.position,{width:h=20,height:v=20}=l.size??{};r.insert({id:l.id,bounds:{x:x-h/2,y:m-v/2,width:h,height:v},data:l.data})}return r}function ea(t,n,s=100){const o=(n.width+s*2)/t.zoom,i=(n.height+s*2)/t.zoom,a=(-t.pan.x-s)/t.zoom,c=(-t.pan.y-s)/t.zoom;return{x:a,y:c,width:o,height:i}}function ta(t,n=200){return t>=n}function na(t,n,s){const o=t-n;return{total:t,visible:n,culled:o,cullPercentage:t>0?Math.round(o/t*100):0,zoom:s.zoom}}const sa="_overlay_1x0xg_9",oa="_dialog_1x0xg_55",aa="_header_1x0xg_103",ia="_title_1x0xg_119",ra="_closeButton_1x0xg_133",ca="_content_1x0xg_167",la="_preview_1x0xg_183",da="_previewCanvas_1x0xg_203",ua="_previewSvg_1x0xg_221",ma="_info_1x0xg_231",pa="_section_1x0xg_241",ha="_sectionTitle_1x0xg_249",ga="_statGrid_1x0xg_269",fa="_stat_1x0xg_269",_a="_statLabel_1x0xg_293",ba="_statValue_1x0xg_305",ya="_warningsList_1x0xg_317",xa="_warning_1x0xg_317",va="_warningIcon_1x0xg_361",ja="_error_1x0xg_371",wa="_errorIcon_1x0xg_403",Na="_footer_1x0xg_413",Ia="_cancelButton_1x0xg_433",ka="_confirmButton_1x0xg_465",Sa="_noWarnings_1x0xg_507",Ca="_layersList_1x0xg_519",Ta="_layer_1x0xg_519",La="_layerIcon_1x0xg_561",$a="_layerName_1x0xg_569",za="_layerCount_1x0xg_579",Z={overlay:sa,dialog:oa,header:aa,title:ia,closeButton:ra,content:ca,preview:la,previewCanvas:da,previewSvg:ua,info:ma,section:pa,sectionTitle:ha,statGrid:ga,stat:fa,statLabel:_a,statValue:ba,warningsList:ya,warning:xa,warningIcon:va,error:ja,errorIcon:wa,footer:Na,cancelButton:Ia,confirmButton:ka,noWarnings:Sa,layersList:Ca,layer:Ta,layerIcon:La,layerName:$a,layerCount:za},Pa=()=>e.jsx(w.NiceIcon,{name:"close",size:20}),wn=()=>e.jsx(w.NiceIcon,{name:"warning",size:14}),Nn=()=>e.jsx(w.NiceIcon,{name:"error",size:14}),In=()=>e.jsx(w.NiceIcon,{name:"layers",size:12}),Ea=()=>e.jsx(w.NiceIcon,{name:"bar-chart",size:14});function Oa({result:t,onConfirm:n,onCancel:s}){const{t:o}=w.useNiceTranslation(),i=t.document,a=u.useMemo(()=>{var $,y;if(!(($=i==null?void 0:i.floors)!=null&&$.length))return null;const h=i.floors[0],v=(h==null?void 0:h.layers)||[],_=v.flatMap(C=>C.objects);let p=1/0,j=1/0,f=-1/0,I=-1/0;for(const C of _)C.bounds?(p=Math.min(p,C.bounds.x),j=Math.min(j,C.bounds.y),f=Math.max(f,C.bounds.x+C.bounds.width),I=Math.max(I,C.bounds.y+C.bounds.height)):(y=C.transform)!=null&&y.position&&(p=Math.min(p,C.transform.position.x),j=Math.min(j,C.transform.position.y),f=Math.max(f,C.transform.position.x),I=Math.max(I,C.transform.position.y));isFinite(p)||(h!=null&&h.bounds?(p=h.bounds.x,j=h.bounds.y,f=h.bounds.x+h.bounds.width,I=h.bounds.y+h.bounds.height):(p=0,j=0,f=1e3,I=800));const b=20;return{viewBox:{x:p-b,y:j-b,width:f-p+b*2,height:I-j+b*2},objects:_,layers:v}},[i]),c=u.useMemo(()=>{if(!a||!i)return null;const{viewBox:h,objects:v}=a,_=[],p=50,j=`
136
- <pattern id="grid" width="${p}" height="${p}" patternUnits="userSpaceOnUse">
137
- <path d="M ${p} 0 L 0 0 0 ${p}" fill="none" stroke="var(--nice-border, #e2e8f0)" strokeWidth="0.5"/>
135
+ `}return""}function Go(t){let n=1/0,s=1/0,o=-1/0,i=-1/0;for(const a of t){a.bounds&&(n=Math.min(n,a.bounds.x),s=Math.min(s,a.bounds.y),o=Math.max(o,a.bounds.x+a.bounds.width),i=Math.max(i,a.bounds.y+a.bounds.height));for(const c of a.layers)for(const r of c.objects){r.bounds&&(n=Math.min(n,r.bounds.x),s=Math.min(s,r.bounds.y),o=Math.max(o,r.bounds.x+r.bounds.width),i=Math.max(i,r.bounds.y+r.bounds.height));const d=r;if(d.boundary)for(const _ of d.boundary)n=Math.min(n,_.x),s=Math.min(s,_.y),o=Math.max(o,_.x),i=Math.max(i,_.y)}}return isFinite(n)||(n=0),isFinite(s)||(s=0),isFinite(o)||(o=1e3),isFinite(i)||(i=800),{minX:n,minY:s,maxX:o,maxY:i}}function Vo(t,n){const{floorIds:s,layerNames:o}=n;let i=t.floors;return s&&s.length>0&&(i=i.filter(a=>s.includes(a.id))),o&&o.length>0&&(i=i.map(a=>({...a,layers:a.layers.filter(c=>o.includes(c.name))}))),{...t,floors:i}}function Zn(t,n){const{layerNames:s,includeGrid:o,includeDimensions:i}=n;return t==="grid"&&!o||(t==="dimensions"||t==="annotations")&&i===!1?!1:s&&s.length>0?s.includes(t):!0}function Pt(t){const n=t.data instanceof Blob?t.data:new Blob([t.data],{type:t.mimeType}),s=URL.createObjectURL(n),o=document.createElement("a");o.href=s,o.download=t.filename,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(s)}async function qo(t,n,s={}){const{dpi:o=96,backgroundColor:i="#ffffff"}=s,a=new XMLSerializer().serializeToString(t),c=new Blob([a],{type:"image/svg+xml;charset=utf-8"}),r=URL.createObjectURL(c);return new Promise((d,_)=>{const p=new Image;p.onload=()=>{const f=o/96,y=document.createElement("canvas");y.width=p.width*f,y.height=p.height*f;const b=y.getContext("2d");if(!b){_(new Error("Could not get canvas context"));return}b.fillStyle=i,b.fillRect(0,0,y.width,y.height),b.scale(f,f),b.drawImage(p,0,0),y.toBlob(j=>{if(URL.revokeObjectURL(r),!j){_(new Error("Could not create PNG blob"));return}d({format:"png",filename:n.endsWith(".png")?n:`${n}.png`,mimeType:"image/png",data:j,size:j.size})},"image/png")},p.onerror=()=>{URL.revokeObjectURL(r),_(new Error("Failed to load SVG for PNG export"))},p.src=r})}function Xn(t){const n=new Map;for(const s of t)s.status!=="error"&&(n.has(s.sourceId)||n.set(s.sourceId,[]),n.get(s.sourceId).push({deviceId:s.targetId,connection:s}),n.has(s.targetId)||n.set(s.targetId,[]),n.get(s.targetId).push({deviceId:s.sourceId,connection:s}));return n}function Wo(t,n,s,o="latency"){const i=Xn(t);if(!i.has(n)||!i.has(s))return null;const a=new Map,c=new Map,r=new Set,d=[];for(const j of i.keys())a.set(j,1/0),c.set(j,null);for(a.set(n,0),d.push({deviceId:n,distance:0});d.length>0;){d.sort((x,C)=>x.distance-C.distance);const j=d.shift();if(r.has(j.deviceId))continue;if(r.add(j.deviceId),j.deviceId===s)break;const w=i.get(j.deviceId)??[];for(const x of w){if(r.has(x.deviceId))continue;let C;switch(o){case"latency":C=x.connection.latency??1;break;case"hops":C=1;break;case"bandwidth":C=1/(x.connection.bandwidth??1);break}const g=a.get(j.deviceId)+C;g<a.get(x.deviceId)&&(a.set(x.deviceId,g),c.set(x.deviceId,{deviceId:j.deviceId,connection:x.connection}),d.push({deviceId:x.deviceId,distance:g}))}}if(!c.has(s)||a.get(s)===1/0)return null;const _=[];let p=0,f=1/0,y="active",b=s;for(;b&&c.get(b);){const j=c.get(b);_.unshift(j.connection.id),p+=j.connection.latency??0,j.connection.bandwidth!==void 0&&(f=Math.min(f,j.connection.bandwidth)),j.connection.status==="error"?y="error":j.connection.status==="degraded"&&y!=="error"?y="degraded":j.connection.status==="inactive"&&y==="active"&&(y="inactive"),b=j.deviceId}return{id:`path-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,startDeviceId:n,endDeviceId:s,connectionIds:_,totalLatency:p,bottleneckBandwidth:f===1/0?0:f,status:y,isPrimary:!0}}function Ho(t,n,s,o=5){const i=[],a=Xn(t);function c(r,d,_,p){if(i.length>=o)return;if(r===d&&p.length>0){let y=0,b=1/0,j="active";for(const w of p)y+=w.latency??0,w.bandwidth!==void 0&&(b=Math.min(b,w.bandwidth)),w.status==="error"?j="error":w.status==="degraded"&&j!=="error"&&(j="degraded");i.push({id:`path-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,startDeviceId:n,endDeviceId:s,connectionIds:p.map(w=>w.id),totalLatency:y,bottleneckBandwidth:b===1/0?0:b,status:j,isPrimary:i.length===0});return}_.add(r);const f=a.get(r)??[];for(const y of f)_.has(y.deviceId)||c(y.deviceId,d,new Set(_),[...p,y.connection])}return c(n,s,new Set,[]),i}function Uo(t){var d,_;const n=[],s=t.split(/\r?\n/);let o=0,i=!1,a=null,c=[],r=null;for(;o<s.length;){const p=parseInt(((d=s[o])==null?void 0:d.trim())??"",10),f=((_=s[o+1])==null?void 0:_.trim())??"";if(o+=2,p===2&&f==="ENTITIES"){i=!0;continue}if(p===0&&f==="ENDSEC"&&i){a!=null&&a.type&&(c.length>0&&(a.vertices=[...c]),n.push(a)),i=!1;continue}if(i){if(p===0){a!=null&&a.type&&(c.length>0&&(a.vertices=[...c]),n.push(a)),a={type:f,layer:"0"},c=[],r=null;continue}if(a)switch(p){case 8:a.layer=f;break;case 5:a.handle=f;break;case 10:r=parseFloat(f);break;case 20:r!==null&&(c.push({x:r,y:parseFloat(f)}),a.position||(a.position={x:r,y:parseFloat(f)}),r=null);break;case 11:r=parseFloat(f);break;case 21:r!==null&&(c.push({x:r,y:parseFloat(f)}),r=null);break;case 40:(a.type==="CIRCLE"||a.type==="ARC")&&(a.radius=parseFloat(f));break;case 50:a.startAngle=parseFloat(f);break;case 51:a.endAngle=parseFloat(f);break;case 1:a.text=f;break;case 2:a.blockName=f;break;case 70:parseInt(f,10)&1&&(a.closed=!0);break}}}return n}function Yo(t,n={}){var r,d;const s=Date.now(),o=[],i=[],a=n.scaleFactor??1,c=n.originOffset??{x:0,y:0};try{const _=Uo(t),p=[],f=[],y=[],b=new Set;let j=0;for(const x of _){if(b.add(x.layer),n.includeLayers&&!n.includeLayers.includes(x.layer)){j++;continue}if((r=n.excludeLayers)!=null&&r.includes(x.layer)){j++;continue}const C=((d=n.layerMappings)==null?void 0:d[x.layer])??x.layer;switch(x.type){case"LINE":if(x.vertices&&x.vertices.length>=2){const g=je(x.vertices[0],a,c),L=je(x.vertices[1],a,c);p.push({start:g,end:L,layer:C})}break;case"LWPOLYLINE":case"POLYLINE":if(x.vertices&&x.vertices.length>=2){const g=x.vertices.map(m=>je(m,a,c));if(x.closed&&n.convertClosedPolylinesToZones){const m=Kn(g),k=n.minZoneArea??.1;if(m>=k){f.push({name:C,boundary:g,layer:C});continue}}const L=x.closed?g.length:g.length-1;for(let m=0;m<L;m++){const k=g[m],l=g[(m+1)%g.length];p.push({start:k,end:l,layer:C})}}break;case"CIRCLE":if(x.position&&x.radius){const g=je(x.position,a,c);y.push({type:"circle",position:g,layer:C,metadata:{radius:x.radius*a}})}break;case"INSERT":if(x.position&&x.blockName){const g=je(x.position,a,c);y.push({type:"block-reference",position:g,layer:C,metadata:{blockName:x.blockName}})}break;default:j++,o.push({code:"UNSUPPORTED_ENTITY",message:`Unsupported DXF entity type: ${x.type}`,context:{type:x.type,layer:x.layer}})}}return{success:!0,document:Wt(p,f,y,b,{name:"Imported DXF",sourceFormat:"dxf",units:n.defaultUnits??"metric"}),warnings:o,errors:i,stats:{wallsImported:p.length,zonesImported:f.length,objectsImported:y.length,layersFound:b.size,entitiesSkipped:j,importTimeMs:Date.now()-s}}}catch(_){return i.push({code:"PARSE_ERROR",message:_ instanceof Error?_.message:"Unknown error parsing DXF",fatal:!0}),{success:!1,warnings:o,errors:i,stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:Date.now()-s}}}}function Zo(t){const n=[];let s=[],o=0,i=0,a=0,c=0;const r=t.match(/[MmLlHhVvCcSsQqTtAaZz]|[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[];let d=0;for(;d<r.length;){const _=r[d];d++;const p=()=>{const f=parseFloat(r[d]??"0");return d++,f};switch(_){case"M":s.length>0&&(n.push(s),s=[]),o=p(),i=p(),a=o,c=i,s.push({x:o,y:i});break;case"m":s.length>0&&(n.push(s),s=[]),o+=p(),i+=p(),a=o,c=i,s.push({x:o,y:i});break;case"L":o=p(),i=p(),s.push({x:o,y:i});break;case"l":o+=p(),i+=p(),s.push({x:o,y:i});break;case"H":o=p(),s.push({x:o,y:i});break;case"h":o+=p(),s.push({x:o,y:i});break;case"V":i=p(),s.push({x:o,y:i});break;case"v":i+=p(),s.push({x:o,y:i});break;case"Z":case"z":s.length>0&&s.push({x:a,y:c}),o=a,i=c;break;case"C":p(),p(),p(),p(),o=p(),i=p(),s.push({x:o,y:i});break;case"c":p(),p(),p(),p(),o+=p(),i+=p(),s.push({x:o,y:i});break;case"Q":p(),p(),o=p(),i=p(),s.push({x:o,y:i});break;case"q":p(),p(),o+=p(),i+=p(),s.push({x:o,y:i});break}}return s.length>0&&n.push(s),n}function Xo(t){let n=0,s=0,o=1;const i=t.match(/translate\s*\(\s*([-\d.]+)(?:\s*,?\s*([-\d.]+))?\s*\)/);i&&(n=parseFloat(i[1]),s=parseFloat(i[2]??"0"));const a=t.match(/scale\s*\(\s*([-\d.]+)(?:\s*,?\s*([-\d.]+))?\s*\)/);return a&&(o=parseFloat(a[1])),{translate:{x:n,y:s},scale:o}}function Ko(t,n={}){const s=Date.now(),o=[],i=[],a=n.scaleFactor??1,c=n.originOffset??{x:0,y:0};try{const r=[],d=[],_=[],p=new Set,f=/<path[^>]*\bd="([^"]+)"[^>]*>/gi;let y;for(;(y=f.exec(t))!==null;){const m=y[1],k=y[0],l=k.match(/\bid="([^"]+)"/),I=(l==null?void 0:l[1])??"default";p.add(I);const h=k.match(/\btransform="([^"]+)"/),F=h?Xo(h[1]):{translate:{x:0,y:0},scale:1},T=Zo(m);for(const B of T){if(B.length<2)continue;const H=B.map(te=>je({x:te.x*F.scale+F.translate.x,y:te.y*F.scale+F.translate.y},a,c));if(Math.abs(H[0].x-H[H.length-1].x)<.1&&Math.abs(H[0].y-H[H.length-1].y)<.1&&n.convertClosedPolylinesToZones&&Kn(H)>=(n.minZoneArea??.1)){d.push({name:I,boundary:H,layer:I});continue}for(let te=0;te<H.length-1;te++)r.push({start:H[te],end:H[te+1],layer:I})}}const b=/<line[^>]*\bx1="([^"]+)"[^>]*\by1="([^"]+)"[^>]*\bx2="([^"]+)"[^>]*\by2="([^"]+)"[^>]*>/gi;let j;for(;(j=b.exec(t))!==null;){const m=parseFloat(j[1]),k=parseFloat(j[2]),l=parseFloat(j[3]),I=parseFloat(j[4]),h=je({x:m,y:k},a,c),F=je({x:l,y:I},a,c);r.push({start:h,end:F,layer:"default"}),p.add("default")}const w=/<rect[^>]*\bx="([^"]+)"[^>]*\by="([^"]+)"[^>]*\bwidth="([^"]+)"[^>]*\bheight="([^"]+)"[^>]*>/gi;let x;for(;(x=w.exec(t))!==null;){const m=parseFloat(x[1]),k=parseFloat(x[2]),l=parseFloat(x[3]),I=parseFloat(x[4]),h=[je({x:m,y:k},a,c),je({x:m+l,y:k},a,c),je({x:m+l,y:k+I},a,c),je({x:m,y:k+I},a,c)];n.convertClosedPolylinesToZones?d.push({name:"rect",boundary:h,layer:"default"}):(r.push({start:h[0],end:h[1],layer:"default"}),r.push({start:h[1],end:h[2],layer:"default"}),r.push({start:h[2],end:h[3],layer:"default"}),r.push({start:h[3],end:h[0],layer:"default"})),p.add("default")}const C=/<circle[^>]*\bcx="([^"]+)"[^>]*\bcy="([^"]+)"[^>]*\br="([^"]+)"[^>]*>/gi;let g;for(;(g=C.exec(t))!==null;){const m=parseFloat(g[1]),k=parseFloat(g[2]),l=parseFloat(g[3]),I=je({x:m,y:k},a,c);_.push({type:"circle",position:I,layer:"default",metadata:{radius:l*a}}),p.add("default")}return{success:!0,document:Wt(r,d,_,p,{name:"Imported SVG",sourceFormat:"svg",units:n.defaultUnits??"metric"}),warnings:o,errors:i,stats:{wallsImported:r.length,zonesImported:d.length,objectsImported:_.length,layersFound:p.size,entitiesSkipped:0,importTimeMs:Date.now()-s}}}catch(r){return i.push({code:"PARSE_ERROR",message:r instanceof Error?r.message:"Unknown error parsing SVG",fatal:!0}),{success:!1,warnings:o,errors:i,stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:Date.now()-s}}}}function Jo(t,n={}){var r;const s=Date.now(),o=[],i=[],a=n.scaleFactor??1,c=n.originOffset??{x:0,y:0};try{const d=JSON.parse(t),_=[],p=[],f=[],y=new Set;let b=0;const j=d.type==="FeatureCollection"?d.features:[d];for(const x of j){const C=((r=x.properties)==null?void 0:r.layer)??"default";y.add(C);const g=x.geometry;switch(g.type){case"Point":{const L=g.coordinates,m=je({x:L[0],y:L[1]},a,c);f.push({type:"marker",position:m,layer:C,metadata:{properties:x.properties}});break}case"LineString":{const L=g.coordinates;for(let m=0;m<L.length-1;m++){const k=je({x:L[m][0],y:L[m][1]},a,c),l=je({x:L[m+1][0],y:L[m+1][1]},a,c);_.push({start:k,end:l,layer:C})}break}case"MultiLineString":{const L=g.coordinates;for(const m of L)for(let k=0;k<m.length-1;k++){const l=je({x:m[k][0],y:m[k][1]},a,c),I=je({x:m[k+1][0],y:m[k+1][1]},a,c);_.push({start:l,end:I,layer:C})}break}case"Polygon":{const k=g.coordinates[0].map(l=>je({x:l[0],y:l[1]},a,c));p.push({name:C,boundary:k,layer:C});break}case"MultiPolygon":{const L=g.coordinates;for(const m of L){const l=m[0].map(I=>je({x:I[0],y:I[1]},a,c));p.push({name:C,boundary:l,layer:C})}break}default:b++,o.push({code:"UNSUPPORTED_GEOMETRY",message:`Unsupported GeoJSON geometry: ${g.type}`})}}return{success:!0,document:Wt(_,p,f,y,{name:"Imported GeoJSON",sourceFormat:"geojson",units:n.defaultUnits??"metric"}),warnings:o,errors:i,stats:{wallsImported:_.length,zonesImported:p.length,objectsImported:f.length,layersFound:y.size,entitiesSkipped:b,importTimeMs:Date.now()-s}}}catch(d){return i.push({code:"PARSE_ERROR",message:d instanceof Error?d.message:"Unknown error parsing GeoJSON",fatal:!0}),{success:!1,warnings:o,errors:i,stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:Date.now()-s}}}}function Qo(t,n={}){const s=Date.now(),o=[],i=[];o.push({code:"LIMITED_IFC_SUPPORT",message:"IFC import is limited. For full support, use a dedicated IFC library like web-ifc."});try{const a=[],c=[],r=[],d=new Set;let _=0;const p=t.split(/\r?\n/),f=new Map;for(const b of p){const j=b.match(/^#(\d+)\s*=\s*(\w+)\s*\((.+)\)\s*;?$/);j&&f.set(`#${j[1]}`,{type:j[2],params:j[3]})}for(const[b,j]of f)if(j.type==="IFCWALLSTANDARDCASE"||j.type==="IFCWALL"){d.add("Walls");const w=j.params.match(/'([^']+)'/),x=(w==null?void 0:w[1])??"Wall";o.push({code:"IFC_WALL_SIMPLIFIED",message:`Wall "${x}" (${b}) geometry simplified to placeholder`}),_++}else if(j.type==="IFCSPACE"){d.add("Spaces");const w=j.params.match(/'([^']+)'/),x=(w==null?void 0:w[1])??"Space";o.push({code:"IFC_SPACE_SIMPLIFIED",message:`Space "${x}" (${b}) geometry simplified to placeholder`}),_++}return{success:!0,document:Wt(a,c,r,d,{name:"Imported IFC",sourceFormat:"ifc",units:n.defaultUnits??"metric"}),warnings:o,errors:i,stats:{wallsImported:a.length,zonesImported:c.length,objectsImported:r.length,layersFound:d.size,entitiesSkipped:_,importTimeMs:Date.now()-s}}}catch(a){return i.push({code:"PARSE_ERROR",message:a instanceof Error?a.message:"Unknown error parsing IFC",fatal:!0}),{success:!1,warnings:o,errors:i,stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:Date.now()-s}}}}function ea(t,n,s={}){switch(n){case"dxf":return Yo(t,s);case"svg":return Ko(t,s);case"geojson":return Jo(t,s);case"ifc":return Qo(t,s);default:return{success:!1,warnings:[],errors:[{code:"UNSUPPORTED_FORMAT",message:`Unsupported import format: ${n}`,fatal:!0}],stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:0}}}}function ta(t,n){const s=t.toLowerCase().split(".").pop();switch(s){case"dxf":return"dxf";case"svg":return"svg";case"geojson":case"json":return n!=null&&n.includes('"type"')&&(n.includes('"Feature"')||n.includes('"FeatureCollection"'))||s==="geojson"?"geojson":null;case"ifc":return"ifc";default:if(n){if(n.includes("ISO-10303-21")||n.includes("IFCPROJECT"))return"ifc";if(n.includes("<?xml")&&n.includes("<svg"))return"svg";if(n.includes("SECTION")&&n.includes("ENTITIES"))return"dxf"}return null}}async function na(t,n={}){return new Promise(s=>{const o=new FileReader;o.onload=()=>{const i=o.result,a=n.format??ta(t.name,i);if(!a){s({success:!1,warnings:[],errors:[{code:"UNKNOWN_FORMAT",message:`Unable to detect format for file: ${t.name}`,fatal:!0}],stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:0}});return}s(ea(i,a,n))},o.onerror=()=>{s({success:!1,warnings:[],errors:[{code:"FILE_READ_ERROR",message:"Error reading file",fatal:!0}],stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:0}})},o.readAsText(t)})}function nt(){return`${Date.now()}-${Math.random().toString(36).slice(2,9)}`}function je(t,n,s){return{x:t.x*n+s.x,y:t.y*n+s.y}}function Kn(t){let n=0;const s=t.length;for(let o=0;o<s;o++){const i=(o+1)%s;n+=t[o].x*t[i].y,n-=t[i].x*t[o].y}return Math.abs(n/2)}function jn(t){if(t.length===0)return{x:0,y:0,width:0,height:0};let n=1/0,s=1/0,o=-1/0,i=-1/0;for(const a of t)a.x<n&&(n=a.x),a.y<s&&(s=a.y),a.x>o&&(o=a.x),a.y>i&&(i=a.y);return{x:n,y:s,width:o-n,height:i-s}}function wn(t){let n=0;for(let o=0;o<t.length;o++)n=t.charCodeAt(o)+((n<<5)-n);return`hsl(${Math.abs(n)%360}, 60%, 50%)`}function Nn(t){return{position:t,rotation:0,scale:{x:1,y:1}}}function Wt(t,n,s,o,i){const a=new Date().toISOString(),c=`floor-${nt()}`,r=[];for(const w of t)r.push(w.start,w.end);for(const w of n)r.push(...w.boundary);for(const w of s)r.push(w.position);const d=jn(r),_=t.map(w=>({id:`wall-${nt()}`,type:"wall",category:"building",name:"Wall",transform:Nn(w.start),bounds:jn([w.start,w.end]),layer:w.layer,locked:!1,visible:!0,metadata:{end:w.end,thickness:w.thickness??.15,importedAt:a},childIds:[]})),p=s.map(w=>({id:`obj-${nt()}`,type:w.type,category:"annotation",name:w.type,transform:Nn(w.position),bounds:{x:w.position.x-10,y:w.position.y-10,width:20,height:20},layer:w.layer,locked:!1,visible:!0,metadata:{...w.metadata,importedAt:a},childIds:[]})),f=Array.from(o).map(w=>({id:`layer-${nt()}`,name:w,type:w.toLowerCase().includes("wall")?"walls":"custom",visible:!0,locked:!1,opacity:1,color:wn(w),objects:[..._.filter(x=>x.layer===w),...p.filter(x=>x.layer===w)]})),y={id:c,name:"Imported Floor",level:0,elevation:0,ceilingHeight:2.7,bounds:d,layers:f},b=n.map(w=>({id:`zone-${nt()}`,name:w.name,type:"custom",boundary:w.boundary,floorId:c,roomIds:[],color:wn(w.name)})),j={$schema:"https://nice2dev.com/schemas/nsp-v1.json",version:"1.0.0",type:"floor-plan",metadata:{id:`doc-${nt()}`,name:i.name,description:`Imported from ${i.sourceFormat.toUpperCase()}`,created:a,modified:a,tags:["imported",i.sourceFormat]},floors:[y],settings:{units:i.units,scale:50,grid:{visible:!0,size:.5,snapEnabled:!0},defaultWallHeight:2.7,defaultWallThickness:.15,precision:2}};return j.zones=b,j}const sa=10,oa=8;class aa{constructor(n,s=sa){Lt(this,"root");Lt(this,"maxItems");Lt(this,"itemMap",new Map);this.root={bounds:n,items:[],children:null},this.maxItems=s}insert(n){this.itemMap.set(n.id,n),this.insertIntoNode(this.root,n,0)}remove(n){const s=this.itemMap.get(n);return s?(this.itemMap.delete(n),this.removeFromNode(this.root,s)):!1}update(n,s){const o=this.itemMap.get(n);return o?(this.remove(n),o.bounds=s,this.insert(o),!0):!1}query(n){const s=[];return this.queryNode(this.root,n,s),s}getAll(){return Array.from(this.itemMap.values())}get(n){return this.itemMap.get(n)}get size(){return this.itemMap.size}clear(){this.itemMap.clear(),this.root.items=[],this.root.children=null}rebuild(){const n=Array.from(this.itemMap.values());this.root.items=[],this.root.children=null;for(const s of n)this.insertIntoNode(this.root,s,0)}insertIntoNode(n,s,o){if(n.children){const i=this.getChildIndex(n,s.bounds);if(i!==-1){this.insertIntoNode(n.children[i],s,o+1);return}n.items.push(s);return}if(n.items.push(s),n.items.length>this.maxItems&&o<oa){this.split(n);const i=[...n.items];n.items=[];for(const a of i)this.insertIntoNode(n,a,o)}}removeFromNode(n,s){const o=n.items.findIndex(i=>i.id===s.id);if(o!==-1)return n.items.splice(o,1),!0;if(n.children){for(const i of n.children)if(this.boundsIntersect(i.bounds,s.bounds)&&this.removeFromNode(i,s))return!0}return!1}queryNode(n,s,o){for(const i of n.items)this.boundsIntersect(i.bounds,s)&&o.push(i);if(n.children)for(const i of n.children)this.boundsIntersect(i.bounds,s)&&this.queryNode(i,s,o)}split(n){const{x:s,y:o,width:i,height:a}=n.bounds,c=i/2,r=a/2;n.children=[{bounds:{x:s,y:o,width:c,height:r},items:[],children:null},{bounds:{x:s+c,y:o,width:c,height:r},items:[],children:null},{bounds:{x:s,y:o+r,width:c,height:r},items:[],children:null},{bounds:{x:s+c,y:o+r,width:c,height:r},items:[],children:null}]}getChildIndex(n,s){if(!n.children)return-1;const o=n.bounds.x+n.bounds.width/2,i=n.bounds.y+n.bounds.height/2,a=s.x+s.width<=o,c=s.x>=o,r=s.y+s.height<=i,d=s.y>=i;return r&&a?0:r&&c?1:d&&a?2:d&&c?3:-1}boundsIntersect(n,s){return n.x<s.x+s.width&&n.x+n.width>s.x&&n.y<s.y+s.height&&n.y+n.height>s.y}}function ia(t,n=100){let s=1/0,o=1/0,i=-1/0,a=-1/0;for(const d of t){const{x:_,y:p}=d.position,{width:f=20,height:y=20}=d.size??{};s=Math.min(s,_-f/2),o=Math.min(o,p-y/2),i=Math.max(i,_+f/2),a=Math.max(a,p+y/2)}Number.isFinite(s)||(s=o=0,i=a=1e3);const c={x:s-n,y:o-n,width:i-s+n*2,height:a-o+n*2},r=new aa(c);for(const d of t){const{x:_,y:p}=d.position,{width:f=20,height:y=20}=d.size??{};r.insert({id:d.id,bounds:{x:_-f/2,y:p-y/2,width:f,height:y},data:d.data})}return r}function ra(t,n,s=100){const o=(n.width+s*2)/t.zoom,i=(n.height+s*2)/t.zoom,a=(-t.pan.x-s)/t.zoom,c=(-t.pan.y-s)/t.zoom;return{x:a,y:c,width:o,height:i}}function ca(t,n=200){return t>=n}function la(t,n,s){const o=t-n;return{total:t,visible:n,culled:o,cullPercentage:t>0?Math.round(o/t*100):0,zoom:s.zoom}}const da="_overlay_1x0xg_9",ua="_dialog_1x0xg_55",pa="_header_1x0xg_103",ma="_title_1x0xg_119",ha="_closeButton_1x0xg_133",ga="_content_1x0xg_167",fa="_preview_1x0xg_183",_a="_previewCanvas_1x0xg_203",ba="_previewSvg_1x0xg_221",ya="_info_1x0xg_231",xa="_section_1x0xg_241",va="_sectionTitle_1x0xg_249",ja="_statGrid_1x0xg_269",wa="_stat_1x0xg_269",Na="_statLabel_1x0xg_293",Ia="_statValue_1x0xg_305",ka="_warningsList_1x0xg_317",Sa="_warning_1x0xg_317",Ca="_warningIcon_1x0xg_361",Ta="_error_1x0xg_371",La="_errorIcon_1x0xg_403",$a="_footer_1x0xg_413",za="_cancelButton_1x0xg_433",Pa="_confirmButton_1x0xg_465",Ea="_noWarnings_1x0xg_507",Oa="_layersList_1x0xg_519",Ma="_layer_1x0xg_519",Aa="_layerIcon_1x0xg_561",Da="_layerName_1x0xg_569",Ba="_layerCount_1x0xg_579",Z={overlay:da,dialog:ua,header:pa,title:ma,closeButton:ha,content:ga,preview:fa,previewCanvas:_a,previewSvg:ba,info:ya,section:xa,sectionTitle:va,statGrid:ja,stat:wa,statLabel:Na,statValue:Ia,warningsList:ka,warning:Sa,warningIcon:Ca,error:Ta,errorIcon:La,footer:$a,cancelButton:za,confirmButton:Pa,noWarnings:Ea,layersList:Oa,layer:Ma,layerIcon:Aa,layerName:Da,layerCount:Ba},Ra=()=>e.jsx(N.NiceIcon,{name:"close",size:20}),In=()=>e.jsx(N.NiceIcon,{name:"warning",size:14}),kn=()=>e.jsx(N.NiceIcon,{name:"error",size:14}),Sn=()=>e.jsx(N.NiceIcon,{name:"layers",size:12}),Fa=()=>e.jsx(N.NiceIcon,{name:"bar-chart",size:14});function Ga({result:t,onConfirm:n,onCancel:s}){const{t:o}=N.useNiceTranslation(),i=t.document,a=u.useMemo(()=>{var L,m;if(!((L=i==null?void 0:i.floors)!=null&&L.length))return null;const f=i.floors[0],y=(f==null?void 0:f.layers)||[],b=y.flatMap(k=>k.objects);let j=1/0,w=1/0,x=-1/0,C=-1/0;for(const k of b)k.bounds?(j=Math.min(j,k.bounds.x),w=Math.min(w,k.bounds.y),x=Math.max(x,k.bounds.x+k.bounds.width),C=Math.max(C,k.bounds.y+k.bounds.height)):(m=k.transform)!=null&&m.position&&(j=Math.min(j,k.transform.position.x),w=Math.min(w,k.transform.position.y),x=Math.max(x,k.transform.position.x),C=Math.max(C,k.transform.position.y));isFinite(j)||(f!=null&&f.bounds?(j=f.bounds.x,w=f.bounds.y,x=f.bounds.x+f.bounds.width,C=f.bounds.y+f.bounds.height):(j=0,w=0,x=1e3,C=800));const g=20;return{viewBox:{x:j-g,y:w-g,width:x-j+g*2,height:C-w+g*2},objects:b,layers:y}},[i]),c=u.useMemo(()=>{if(!a||!i)return null;const{viewBox:f,objects:y}=a,b=[],j=50,w=`
136
+ <pattern id="grid" width="${j}" height="${j}" patternUnits="userSpaceOnUse">
137
+ <path d="M ${j} 0 L 0 0 0 ${j}" fill="none" stroke="var(--nice-border, #e2e8f0)" strokeWidth="0.5"/>
138
138
  </pattern>
139
- `,f=I=>I.boundary;return v.forEach((I,b)=>{const $=f(I);if(I.type==="wall"&&I.bounds)_.push(e.jsx("rect",{x:I.bounds.x,y:I.bounds.y,width:I.bounds.width,height:I.bounds.height,fill:"var(--nice-text-secondary, #475569)",stroke:"var(--nice-text, #334155)",strokeWidth:"1"},`wall-${b}`));else if(I.type==="zone"&&$){const y=$.map((C,d)=>`${d===0?"M":"L"} ${C.x} ${C.y}`).join(" ")+" Z";_.push(e.jsx("path",{d:y,fill:"var(--nice-primary-tint-20, rgba(59, 130, 246, 0.2))",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:"1"},`zone-${b}`))}else if(I.type==="room"&&$){const y=$.map((C,d)=>`${d===0?"M":"L"} ${C.x} ${C.y}`).join(" ")+" Z";_.push(e.jsx("path",{d:y,fill:"var(--nice-success-tint-15, rgba(34, 197, 94, 0.15))",stroke:"var(--nice-success, #22c55e)",strokeWidth:"1"},`room-${b}`))}else I.bounds&&_.push(e.jsx("rect",{x:I.bounds.x,y:I.bounds.y,width:I.bounds.width,height:I.bounds.height,fill:"var(--nice-accent-tint-30, rgba(99, 102, 241, 0.3))",stroke:"var(--nice-info, #6366f1)",strokeWidth:"0.5",rx:"2"},`obj-${b}`))}),e.jsxs("svg",{viewBox:`${h.x} ${h.y} ${h.width} ${h.height}`,className:Z.previewSvg,preserveAspectRatio:"xMidYMid meet",children:[e.jsx("defs",{dangerouslySetInnerHTML:{__html:j}}),e.jsx("rect",{x:h.x,y:h.y,width:h.width,height:h.height,fill:"url(#grid)"}),_]})},[a,i]),r=u.useRef(null);w.useOverlayFocus(r,{open:!0,onClose:s});const l=u.useCallback(h=>{h.target===h.currentTarget&&s()},[s]),x=t.errors.some(h=>h.fatal),m=t.errors.filter(h=>!h.fatal);return e.jsx("div",{className:Z.overlay,role:"presentation",onMouseDown:l,children:e.jsxs("div",{ref:r,className:Z.dialog,tabIndex:-1,role:"dialog","aria-modal":"true","aria-labelledby":"import-preview-title",children:[e.jsxs("div",{className:Z.header,children:[e.jsx("h2",{id:"import-preview-title",className:Z.title,children:o("importPreviewDialog.importPreview","Import Preview")}),e.jsx("button",{className:Z.closeButton,onClick:s,title:o("importPreviewDialog.close","Close"),"aria-label":o("importPreviewDialog.closeDialog","Close dialog"),children:e.jsx(Pa,{})})]}),e.jsxs("div",{className:Z.content,children:[e.jsx("div",{className:Z.preview,children:c||e.jsx("div",{className:Z.previewCanvas,children:o("importPreviewDialog.noPreviewAvailable","No preview available")})}),e.jsxs("div",{className:Z.info,children:[e.jsxs("div",{className:Z.section,children:[e.jsxs("h3",{className:Z.sectionTitle,children:[e.jsx(Ea,{})," ",o("importPreviewDialog.importStatistics","Import Statistics")]}),e.jsxs("div",{className:Z.statGrid,children:[e.jsxs("div",{className:Z.stat,children:[e.jsx("div",{className:Z.statLabel,children:o("importPreviewDialog.walls","Walls")}),e.jsx("div",{className:Z.statValue,children:t.stats.wallsImported})]}),e.jsxs("div",{className:Z.stat,children:[e.jsx("div",{className:Z.statLabel,children:o("importPreviewDialog.zones","Zones")}),e.jsx("div",{className:Z.statValue,children:t.stats.zonesImported})]}),e.jsxs("div",{className:Z.stat,children:[e.jsx("div",{className:Z.statLabel,children:o("importPreviewDialog.objects","Objects")}),e.jsx("div",{className:Z.statValue,children:t.stats.objectsImported})]}),e.jsxs("div",{className:Z.stat,children:[e.jsx("div",{className:Z.statLabel,children:o("importPreviewDialog.skipped","Skipped")}),e.jsx("div",{className:Z.statValue,children:t.stats.entitiesSkipped})]})]})]}),a&&a.layers.length>0&&e.jsxs("div",{className:Z.section,children:[e.jsxs("h3",{className:Z.sectionTitle,children:[e.jsx(In,{})," ",o("importPreviewDialog.layers","Layers ({layers})").replace("{layers}",String(a.layers.length))]}),e.jsxs("ul",{className:Z.layersList,children:[a.layers.slice(0,6).map((h,v)=>{var _;return e.jsxs("li",{className:Z.layer,children:[e.jsx("span",{className:Z.layerIcon,children:e.jsx(In,{})}),e.jsx("span",{className:Z.layerName,children:h.name}),e.jsx("span",{className:Z.layerCount,children:((_=h.objects)==null?void 0:_.length)||0})]},h.id||v)}),a.layers.length>6&&e.jsx("li",{className:Z.layer,children:e.jsx("span",{className:Z.layerName,children:o("importPreviewDialog.more","+{layers} more...").replace("{layers}",String(a.layers.length-6))})})]})]}),t.warnings.length>0&&e.jsxs("div",{className:Z.section,children:[e.jsxs("h3",{className:Z.sectionTitle,children:[e.jsx(wn,{})," ",o("importPreviewDialog.warnings","Warnings ({warnings})").replace("{warnings}",String(t.warnings.length))]}),e.jsxs("ul",{className:Z.warningsList,children:[t.warnings.slice(0,5).map((h,v)=>e.jsxs("li",{className:Z.warning,children:[e.jsx("span",{className:Z.warningIcon,children:e.jsx(wn,{})}),e.jsx("span",{children:h.message})]},v)),t.warnings.length>5&&e.jsx("li",{className:Z.warning,children:o("importPreviewDialog.moreWarnings","+{warnings} more warnings...").replace("{warnings}",String(t.warnings.length-5))})]})]}),m.length>0&&e.jsxs("div",{className:Z.section,children:[e.jsxs("h3",{className:Z.sectionTitle,children:[e.jsx(Nn,{})," ",o("importPreviewDialog.errors","Errors ({nonFatalErrors})").replace("{nonFatalErrors}",String(m.length))]}),e.jsx("ul",{className:Z.warningsList,children:m.slice(0,5).map((h,v)=>e.jsxs("li",{className:Z.error,children:[e.jsx("span",{className:Z.errorIcon,children:e.jsx(Nn,{})}),e.jsx("span",{children:h.message})]},v))})]}),t.warnings.length===0&&m.length===0&&e.jsx("div",{className:Z.section,children:e.jsxs("p",{className:Z.noWarnings,children:[e.jsx(w.NiceIcon,{name:"check",size:14})," ",o("importPreviewDialog.noWarningsOrErrorsFound","No warnings or errors found")]})})]})]}),e.jsxs("div",{className:Z.footer,children:[e.jsx("button",{className:Z.cancelButton,onClick:s,children:o("importPreviewDialog.cancel","Cancel")}),e.jsx("button",{className:Z.confirmButton,onClick:n,disabled:x,children:x?o("importPreviewDialog.cannotImportFatalErrors","Cannot Import (Fatal Errors)"):o("importPreviewDialog.confirmImport","Confirm Import")})]})]})})}const Ma="_overlay_1jmp3_9",Aa="_dialog_1jmp3_55",Da="_header_1jmp3_103",Ba="_title_1jmp3_119",Ra="_closeButton_1jmp3_133",Fa="_content_1jmp3_167",Ga="_description_1jmp3_179",qa="_mappingTable_1jmp3_191",Va="_sourceLayer_1jmp3_241",Wa="_layerIcon_1jmp3_253",Ha="_layerName_1jmp3_261",Ua="_objectCount_1jmp3_273",Ya="_targetSelect_1jmp3_285",Za="_skipOption_1jmp3_327",Xa="_arrowIcon_1jmp3_337",Ka="_presets_1jmp3_347",Ja="_presetButton_1jmp3_361",Qa="_footer_1jmp3_393",ei="_footerLeft_1jmp3_413",ti="_checkbox_1jmp3_425",ni="_checkboxLabel_1jmp3_437",si="_footerRight_1jmp3_447",oi="_cancelButton_1jmp3_457",ai="_confirmButton_1jmp3_489",le={overlay:Ma,dialog:Aa,header:Da,title:Ba,closeButton:Ra,content:Fa,description:Ga,mappingTable:qa,sourceLayer:Va,layerIcon:Wa,layerName:Ha,objectCount:Ua,targetSelect:Ya,skipOption:Za,arrowIcon:Xa,presets:Ka,presetButton:Ja,footer:Qa,footerLeft:ei,checkbox:ti,checkboxLabel:ni,footerRight:si,cancelButton:oi,confirmButton:ai},kn=()=>e.jsx(w.NiceIcon,{name:"close",size:20}),ii=()=>e.jsx(w.NiceIcon,{name:"layers",size:14}),ri=()=>e.jsx(w.NiceIcon,{name:"arrow-right",size:16}),Sn={"floor-plan":"Floor plan",walls:"Walls",rooms:"Rooms",zones:"Strefy","doors-windows":"Doors and windows",furniture:"Meble",devices:"Devices",network:"Network",infrastructure:"Infrastruktura",electrical:"Elektryka",plumbing:"Hydraulika",hvac:"HVAC",annotations:"Adnotacje",dimensions:"Wymiary",grid:"Siatka",background:"Background","game-objects":"Obiekty gry",collision:"Kolizje",custom:"Custom"};function ci(t){if(!t.document)return[];const n=[];for(const s of t.document.floors)for(const o of s.layers)n.push({id:o.id,name:o.name,type:o.type,objectCount:o.objects.length});return n}function li(t){if(!t)return[];const n=[];for(const s of t.floors)for(const o of s.layers)n.find(i=>i.id===o.id)||n.push(o);return n}function Cn(t,n){const s=new Map;for(const o of t){const i=n.find(r=>r.type===o.type);if(i){s.set(o.id,i.id);continue}const a=o.name.toLowerCase(),c=n.find(r=>r.name.toLowerCase()===a);if(c){s.set(o.id,c.id);continue}s.set(o.id,o.id)}return s}const di=({importResult:t,existingDocument:n,onConfirm:s,onCancel:o})=>{const{t:i}=w.useNiceTranslation(),a=u.useMemo(()=>ci(t),[t]),c=u.useMemo(()=>li(n),[n]),[r,l]=u.useState(()=>Cn(a,c)),[x,m]=u.useState(!0),h=u.useCallback((f,I)=>{l(b=>{const $=new Map(b);return $.set(f,I),$})},[]),v=u.useCallback(f=>{const I=new Map;switch(f){case"auto":l(Cn(a,c));return;case"skip-all":for(const b of a)I.set(b.id,"skip");break;case"preserve":for(const b of a)I.set(b.id,b.id);break}l(I)},[a,c]),_=u.useCallback(()=>{s(r,x)},[r,x,s]),p=u.useCallback(f=>{f.key==="Escape"?o():f.key==="Enter"&&(f.ctrlKey||f.metaKey)&&_()},[o,_]),j=u.useCallback(f=>{f.target===f.currentTarget&&o()},[o]);return a.length===0?e.jsx("div",{className:le.overlay,onClick:j,onKeyDown:p,tabIndex:-1,children:e.jsxs("div",{className:le.dialog,children:[e.jsxs("div",{className:le.header,children:[e.jsx("h2",{className:le.title,children:i("buildings.layerMapping","Layer mapping")}),e.jsx("button",{className:le.closeButton,onClick:o,children:e.jsx(kn,{})})]}),e.jsx("div",{className:le.content,children:e.jsx("p",{className:le.description,children:i("buildings.spatial.noLayersInFile","The imported file contains no layers.")})}),e.jsxs("div",{className:le.footer,children:[e.jsx("div",{className:le.footerLeft}),e.jsx("div",{className:le.footerRight,children:e.jsx("button",{className:le.cancelButton,onClick:o,children:i("buildings.spatial.close","Close")})})]})]})}):e.jsx("div",{className:le.overlay,onClick:j,onKeyDown:p,tabIndex:-1,children:e.jsxs("div",{className:le.dialog,children:[e.jsxs("div",{className:le.header,children:[e.jsx("h2",{className:le.title,children:i("buildings.layerMapping","Layer mapping")}),e.jsx("button",{className:le.closeButton,onClick:o,children:e.jsx(kn,{})})]}),e.jsxs("div",{className:le.content,children:[e.jsx("p",{className:le.description,children:i("buildings.spatial.mappingHint","Choose how the layers from the imported file map onto the editor layers.")}),e.jsxs("table",{className:le.mappingTable,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:i("buildings.spatial.sourceLayer","Source layer")}),e.jsx("th",{}),e.jsx("th",{children:i("buildings.targetLayer","Target layer")})]})}),e.jsx("tbody",{children:a.map(f=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsxs("div",{className:le.sourceLayer,children:[e.jsx("span",{className:le.layerIcon,children:e.jsx(ii,{})}),e.jsx("span",{className:le.layerName,children:f.name}),e.jsxs("span",{className:le.objectCount,children:["(",f.objectCount," ",f.objectCount===1?i("buildings.spatial.object","object"):i("buildings.spatial.objects","objects"),")"]})]})}),e.jsx("td",{className:le.arrowIcon,children:e.jsx(ri,{})}),e.jsx("td",{children:e.jsxs("select",{className:le.targetSelect,value:r.get(f.id)||f.id,onChange:I=>h(f.id,I.target.value),children:[e.jsxs("option",{value:"skip",className:le.skipOption,children:["— ",i("buildings.spatial.skipLayer","Skip this layer")," —"]}),e.jsxs("option",{value:f.id,children:[i("buildings.spatial.create","Create"),": ",f.name," (",Sn[f.type],")"]}),c.map(I=>e.jsxs("option",{value:I.id,children:[I.name," (",Sn[I.type],")"]},I.id))]})})]},f.id))})]}),e.jsxs("div",{className:le.presets,children:[e.jsx("button",{className:le.presetButton,onClick:()=>v("auto"),children:i("buildings.autoMapping","Auto-mapping")}),e.jsx("button",{className:le.presetButton,onClick:()=>v("preserve"),children:i("buildings.spatial.keepAll","Keep all")}),e.jsx("button",{className:le.presetButton,onClick:()=>v("skip-all"),children:i("buildings.spatial.skipAll","Skip all")})]})]}),e.jsxs("div",{className:le.footer,children:[e.jsxs("div",{className:le.footerLeft,children:[e.jsx("input",{type:"checkbox",id:"createMissing",className:le.checkbox,checked:x,onChange:f=>m(f.target.checked)}),e.jsx("label",{htmlFor:"createMissing",className:le.checkboxLabel,children:i("buildings.spatial.createMissing","Create the missing layers")})]}),e.jsxs("div",{className:le.footerRight,children:[e.jsx("button",{className:le.cancelButton,onClick:o,children:i("buildings.spatial.cancel","Cancel")}),e.jsx("button",{className:le.confirmButton,onClick:_,children:i("buildings.spatial.applyMapping","Apply mapping")})]})]})]})})},ui="_root_4ino1_9",mi="_header_4ino1_21",pi="_title_4ino1_31",hi="_layerList_4ino1_45",gi="_layerItem_4ino1_55",fi="_hidden_4ino1_83",_i="_locked_4ino1_91",bi="_visibilityBtn_4ino1_99",yi="_lockBtn_4ino1_101",xi="_layerIcon_4ino1_139",vi="_layerName_4ino1_147",ji="_opacitySlider_4ino1_157",ze={root:ui,header:mi,title:pi,layerList:hi,layerItem:gi,hidden:fi,locked:_i,visibilityBtn:bi,lockBtn:yi,layerIcon:xi,layerName:vi,opacitySlider:ji},wi={"floor-plan":{icon:"home",label:"Floor Plan"},zones:{icon:"hexagon",label:"Zones"},devices:{icon:"wifi",label:"Devices"},furniture:{icon:"sofa",label:"Furniture"},network:{icon:"globe",label:"Network"},infrastructure:{icon:"settings",label:"Infrastructure"},annotations:{icon:"edit",label:"Annotations"},dimensions:{icon:"ruler",label:"Dimensions"},grid:{icon:"grid",label:"Grid"},background:{icon:"image",label:"Background"},"game-objects":{icon:"gamepad",label:"Game Objects"},collision:{icon:"square",label:"Collision"}},Xn=({layers:t,onVisibilityToggle:n,onLockToggle:s,onOpacityChange:o,className:i})=>{const{t:a}=w.useNiceTranslation(),c=[...t].sort((r,l)=>l.zIndex-r.zIndex);return e.jsxs("div",{className:`${ze.root} ${i??""}`,children:[e.jsx("div",{className:ze.header,children:e.jsx("h3",{className:ze.title,children:a("layerPanel.layers","Layers")})}),e.jsx("div",{className:ze.layerList,children:c.map(r=>{const l=wi[r.type]||{icon:"box",label:r.type};return e.jsxs("div",{className:`${ze.layerItem} ${r.visible?"":ze.hidden} ${r.locked?ze.locked:""}`,children:[e.jsx("button",{className:ze.visibilityBtn,onClick:()=>n(r.type),title:r.visible?a("layerPanel.hideLayer","Hide layer"):a("layerPanel.showLayer","Show layer"),children:e.jsx(w.NiceIcon,{name:r.visible?"eye":"eye-off",size:16})}),e.jsx("button",{className:ze.lockBtn,onClick:()=>s(r.type),title:r.locked?a("layerPanel.unlockLayer","Unlock layer"):a("layerPanel.lockLayer","Lock layer"),children:e.jsx(w.NiceIcon,{name:"lock",size:16})}),e.jsx("span",{className:ze.layerIcon,children:e.jsx(w.NiceIcon,{name:l.icon,size:16})}),e.jsx("span",{className:ze.layerName,children:l.label}),e.jsx("input",{type:"range",min:"0",max:"1",step:"0.1",value:r.opacity,onChange:x=>o(r.type,parseFloat(x.target.value)),className:ze.opacitySlider,title:a("layerPanel.opacity","Opacity: {opacity}%").replace("{opacity}",String(Math.round(r.opacity*100)))})]},r.type)})})]})};function it(t){return t.find(n=>n.type==="zones")??t.find(n=>n.name==="zones")}function Gt(t){var o;const n=t,s=n.boundary??((o=t.metadata)==null?void 0:o.points)??n.polygon;return Array.isArray(s)&&s.length>=3?s:null}function At(t){var s,o;return t.color??((s=t.metadata)==null?void 0:s.fill)??((o=t.style)==null?void 0:o.fill)}function cn(t){const n=t;return n.start&&n.end?{start:n.start,end:n.end}:null}function Ni(t){const n=t.metadata;return t.type==="connection"&&(n!=null&&n.sourcePosition)&&n.targetPosition?{start:n.sourcePosition,end:n.targetPosition}:null}function bt(t){var i,a,c;if(t.bounds)return t.bounds;const n=(i=t.transform)==null?void 0:i.position;if(n)return{x:n.x,y:n.y,width:((a=t.size)==null?void 0:a.width)??24,height:((c=t.size)==null?void 0:c.height)??24};const s=Gt(t);if(s)return Dt(s);const o=cn(t);return o?Dt([o.start,o.end]):null}function Ii(t,n,s){const o=c=>({...c,x:c.x+n,y:c.y+s}),i=t,a={};if(t.bounds&&(a.bounds={...t.bounds,x:t.bounds.x+n,y:t.bounds.y+s}),t.transform&&(a.transform={...t.transform,position:o(t.transform.position)}),t.position&&(a.position=o(t.position)),i.start&&(a.start=o(i.start)),i.end&&(a.end=o(i.end)),i.boundary&&(a.boundary=i.boundary.map(o)),i.polygon&&(a.polygon=i.polygon.map(o)),t.metadata){const c={...t.metadata};Array.isArray(c.points)&&(c.points=c.points.map(o));for(const r of["sourcePosition","targetPosition"]){const l=c[r];l&&(c[r]=o(l))}a.metadata=c}return a}function Qt(t){if(t.position)return t.position;const n=bt(t);return n?{x:n.x+n.width/2,y:n.y+n.height/2}:null}function Tn(t){if(t.size)return t.size;const n=bt(t);return n?{width:n.width,height:n.height}:{width:20,height:20}}function Dt(t){const n=t.map(a=>a.x),s=t.map(a=>a.y),o=Math.min(...n),i=Math.min(...s);return{x:o,y:i,width:Math.max(...n)-o,height:Math.max(...s)-i}}const ki="_root_1lufq_9",Si="_svg_1lufq_31",Ci="_viewportRect_1lufq_41",Ti="_zoomIndicator_1lufq_49",$t={root:ki,svg:Si,viewportRect:Ci,zoomIndicator:Ti},ln=({document:t,activeFloorId:n,viewport:s,onViewportChange:o,size:i=150,className:a})=>{var $,y;const c=u.useRef(null),r=u.useMemo(()=>t.floors.find(C=>C.id===n)??t.floors[0]??null,[t,n]),l=(($=r==null?void 0:r.dimensions)==null?void 0:$.width)??1e3,x=((y=r==null?void 0:r.dimensions)==null?void 0:y.height)??800,m=Math.min(i/l,i/x)*.9,h=l*m,v=x*m,_=i/s.zoom*m,p=i/s.zoom*m,j=-s.pan.x/s.zoom*m,f=-s.pan.y/s.zoom*m,I=u.useCallback(C=>{var R;const d=(R=c.current)==null?void 0:R.getBoundingClientRect();if(!d)return;const k=(C.clientX-d.left-(i-h)/2)/m,g=(C.clientY-d.top-(i-v)/2)/m,G=-(k-i/s.zoom/2)*s.zoom,T=-(g-i/s.zoom/2)*s.zoom;o({pan:{x:G,y:T}})},[m,i,h,v,s.zoom,o]),b=u.useMemo(()=>{const C=r?it(r.layers):void 0;return C?C.objects.map(d=>{const k=Gt(d);if(!k)return null;const g=k.map((G,T)=>`${T===0?"M":"L"}${G.x*m},${G.y*m}`).join(" ")+" Z";return e.jsx("path",{d:g,fill:At(d)??"var(--nice-primary-bg, #dbeafe)",fillOpacity:.6,stroke:"var(--nice-text-muted, #94a3b8)",strokeWidth:.5},d.id)}):null},[r,m]);return r?e.jsxs("div",{className:`${$t.root} ${a??""}`,children:[e.jsxs("svg",{ref:c,width:i,height:i,viewBox:`0 0 ${i} ${i}`,className:$t.svg,onClick:I,children:[e.jsx("rect",{x:(i-h)/2,y:(i-v)/2,width:h,height:v,fill:"var(--nice-bg-secondary, #1e293b)",stroke:"var(--nice-border-color, #475569)",strokeWidth:1}),e.jsx("g",{transform:`translate(${(i-h)/2}, ${(i-v)/2})`,children:b}),e.jsx("rect",{x:(i-h)/2+j,y:(i-v)/2+f,width:Math.min(_,h),height:Math.min(p,v),fill:"var(--nice-primary-tint-20, rgba(59, 130, 246, 0.2))",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:1.5,rx:2,className:$t.viewportRect})]}),e.jsxs("div",{className:$t.zoomIndicator,children:[Math.round(s.zoom*100),"%"]})]}):null},Li="_panel_1jo5f_9",$i="_header_1jo5f_27",zi="_title_1jo5f_45",Pi="_closeButton_1jo5f_59",Ei="_content_1jo5f_85",Oi="_endpointSection_1jo5f_99",Mi="_endpointLabel_1jo5f_107",Ai="_endpointSelect_1jo5f_123",Di="_optionsSection_1jo5f_157",Bi="_metricButton_1jo5f_169",Ri="_metricButtonActive_1jo5f_205",Fi="_analyzeButton_1jo5f_219",Gi="_resultsSection_1jo5f_267",qi="_resultsTitle_1jo5f_277",Vi="_noResults_1jo5f_293",Wi="_pathCard_1jo5f_309",Hi="_pathCardSelected_1jo5f_333",Ui="_pathCardHeader_1jo5f_343",Yi="_pathCardTitle_1jo5f_361",Zi="_pathBadge_1jo5f_373",Xi="_badgePrimary_1jo5f_389",Ki="_badgeAlternate_1jo5f_399",Ji="_pathName_1jo5f_409",Qi="_pathStatus_1jo5f_421",er="_statusDot_1jo5f_435",tr="_statusActive_1jo5f_447",nr="_statusDegraded_1jo5f_453",sr="_statusInactive_1jo5f_459",or="_statusError_1jo5f_465",ar="_pathStats_1jo5f_475",ir="_statItem_1jo5f_489",rr="_statValue_1jo5f_497",cr="_statLabel_1jo5f_509",lr="_pathVisualization_1jo5f_523",dr="_pathDiagram_1jo5f_535",ur="_pathNode_1jo5f_551",mr="_pathNodeStart_1jo5f_583",pr="_pathNodeEnd_1jo5f_585",hr="_pathLink_1jo5f_595",gr="_pathLinkLine_1jo5f_607",fr="_showOnMapButton_1jo5f_621",_r="_loading_1jo5f_657",br="_spinner_1jo5f_671",yr="_spin_1jo5f_671",Y={panel:Li,header:$i,title:zi,closeButton:Pi,content:Ei,endpointSection:Oi,endpointLabel:Mi,endpointSelect:Ai,optionsSection:Di,metricButton:Bi,metricButtonActive:Ri,analyzeButton:Fi,resultsSection:Gi,resultsTitle:qi,noResults:Vi,pathCard:Wi,pathCardSelected:Hi,pathCardHeader:Ui,pathCardTitle:Yi,pathBadge:Zi,badgePrimary:Xi,badgeAlternate:Ki,pathName:Ji,pathStatus:Qi,statusDot:er,statusActive:tr,statusDegraded:nr,statusInactive:sr,statusError:or,pathStats:ar,statItem:ir,statValue:rr,statLabel:cr,pathVisualization:lr,pathDiagram:dr,pathNode:ur,pathNodeStart:mr,pathNodeEnd:pr,pathLink:hr,pathLinkLine:gr,showOnMapButton:fr,loading:_r,spinner:br,spin:yr},xr=()=>e.jsx(w.NiceIcon,{name:"close",size:16}),vr=()=>e.jsx(w.NiceIcon,{name:"arrow-right",size:16});function jr(t,n){switch(t){case"active":return n("buildings.connectionStatus.active","Active");case"degraded":return n("buildings.connectionStatus.degraded","Degraded");case"inactive":return n("buildings.connectionStatus.inactive","Inactive");case"error":return n("buildings.connectionStatus.error","Error");default:return n("buildings.connectionStatus.unknown","Unknown")}}function wr(t){return t<1?"<1ms":t<1e3?`${Math.round(t)}ms`:`${(t/1e3).toFixed(1)}s`}function Nr(t){return t>=1e3?`${(t/1e3).toFixed(1)} Gbps`:`${Math.round(t)} Mbps`}const Ir=({document:t,connections:n,onHighlightPath:s,onClose:o})=>{const{t:i}=w.useNiceTranslation(),[a,c]=u.useState(""),[r,l]=u.useState(""),[x,m]=u.useState("latency"),[h,v]=u.useState([]),[_,p]=u.useState(null),[j,f]=u.useState(!1),I=u.useMemo(()=>{const d=[];for(const k of t.floors)for(const g of k.layers)if(g.type==="network"||g.type==="devices"||g.type==="infrastructure")for(const G of g.objects)d.push({id:G.id,name:G.name??G.id});return d},[t]),b=u.useCallback(d=>{var k;return((k=I.find(g=>g.id===d))==null?void 0:k.name)??d},[I]),$=u.useCallback(()=>{!a||!r||a===r||(f(!0),v([]),p(null),setTimeout(()=>{const d=Do(n,a,r,x),k=Bo(n,a,r,5),g=[];d&&g.push(d);for(const G of k)g.some(T=>T.connectionIds.length===G.connectionIds.length&&T.connectionIds.every((R,H)=>G.connectionIds[H]===R))||g.push({...G,isPrimary:!1});v(g),g.length>0&&(p(g[0].id),s==null||s(g[0])),f(!1)},300))},[a,r,x,n,s]),y=u.useCallback(d=>{p(d.id),s==null||s(d)},[s]),C=u.useCallback(d=>{const k=[d.startDeviceId];for(const g of d.connectionIds){const G=n.find(T=>T.id===g);if(G){const T=k[k.length-1],R=G.sourceId===T?G.targetId:G.sourceId;k.includes(R)||k.push(R)}}return k},[n]);return e.jsxs("div",{className:Y.panel,children:[e.jsxs("div",{className:Y.header,children:[e.jsx("h3",{className:Y.title,children:i("buildings.spatial.pathAnalysis","Network path analysis")}),o&&e.jsx("button",{className:Y.closeButton,onClick:o,children:e.jsx(xr,{})})]}),e.jsxs("div",{className:Y.content,children:[e.jsxs("div",{className:Y.endpointSection,children:[e.jsx("label",{className:Y.endpointLabel,children:i("buildings.spatial.sourceDevice","Source device")}),e.jsxs("select",{className:Y.endpointSelect,value:a,onChange:d=>c(d.target.value),children:[e.jsxs("option",{value:"",children:["— ",i("buildings.spatial.selectDevice","Select a device")," —"]}),I.map(d=>e.jsx("option",{value:d.id,children:d.name},d.id))]})]}),e.jsxs("div",{className:Y.endpointSection,children:[e.jsx("label",{className:Y.endpointLabel,children:i("buildings.spatial.targetDevice","Target device")}),e.jsxs("select",{className:Y.endpointSelect,value:r,onChange:d=>l(d.target.value),children:[e.jsxs("option",{value:"",children:["— ",i("buildings.spatial.selectDevice","Select a device")," —"]}),I.filter(d=>d.id!==a).map(d=>e.jsx("option",{value:d.id,children:d.name},d.id))]})]}),e.jsxs("div",{className:Y.optionsSection,children:[e.jsx("button",{className:`${Y.metricButton} ${x==="latency"?Y.metricButtonActive:""}`,onClick:()=>m("latency"),children:i("buildings.latency","Latency")}),e.jsx("button",{className:`${Y.metricButton} ${x==="hops"?Y.metricButtonActive:""}`,onClick:()=>m("hops"),children:i("buildings.hops","Hops")}),e.jsx("button",{className:`${Y.metricButton} ${x==="bandwidth"?Y.metricButtonActive:""}`,onClick:()=>m("bandwidth"),children:i("buildings.spatial.bandwidth","Bandwidth")})]}),e.jsx("button",{className:Y.analyzeButton,onClick:$,disabled:!a||!r||a===r||j,children:j?i("buildings.spatial.analysing","Analysing…"):i("buildings.spatial.analysePath","Analyse the path")}),j?e.jsx("div",{className:Y.loading,children:e.jsx("div",{className:Y.spinner})}):h.length>0?e.jsxs("div",{className:Y.resultsSection,children:[e.jsxs("div",{className:Y.resultsTitle,children:[i("buildings.spatial.pathsFound","Paths found")," (",h.length,")"]}),h.map((d,k)=>{const g=C(d),G=_===d.id;return e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:w.clickOnActivationKey,className:`${Y.pathCard} ${G?Y.pathCardSelected:""}`,onClick:()=>y(d),children:[e.jsxs("div",{className:Y.pathCardHeader,children:[e.jsxs("div",{className:Y.pathCardTitle,children:[e.jsx("span",{className:`${Y.pathBadge} ${d.isPrimary?Y.badgePrimary:Y.badgeAlternate}`,children:d.isPrimary?i("buildings.optimal","Optimal"):i("buildings.alt","Alt {index}").replace("{index}",String(k))}),e.jsxs("span",{className:Y.pathName,children:[d.connectionIds.length," ",i("buildings.spatial.connections","connections")]})]}),e.jsxs("div",{className:Y.pathStatus,children:[e.jsx("span",{className:`${Y.statusDot} ${Y[`status${d.status.charAt(0).toUpperCase()+d.status.slice(1)}`]??""}`}),e.jsx("span",{children:jr(d.status,i)})]})]}),e.jsxs("div",{className:Y.pathStats,children:[e.jsxs("div",{className:Y.statItem,children:[e.jsx("div",{className:Y.statValue,children:wr(d.totalLatency)}),e.jsx("div",{className:Y.statLabel,children:i("buildings.latency","Latency")})]}),e.jsxs("div",{className:Y.statItem,children:[e.jsx("div",{className:Y.statValue,children:d.connectionIds.length}),e.jsx("div",{className:Y.statLabel,children:i("buildings.hops","Hops")})]}),e.jsxs("div",{className:Y.statItem,children:[e.jsx("div",{className:Y.statValue,children:d.bottleneckBandwidth>0?Nr(d.bottleneckBandwidth):"N/A"}),e.jsx("div",{className:Y.statLabel,children:i("buildings.spatial.bandwidth","Bandwidth")})]})]}),G&&e.jsxs("div",{className:Y.pathVisualization,children:[e.jsx("div",{className:Y.pathDiagram,children:g.map((T,R)=>e.jsxs(u.Fragment,{children:[e.jsx("div",{className:`${Y.pathNode} ${R===0?Y.pathNodeStart:R===g.length-1?Y.pathNodeEnd:""}`,children:b(T).substring(0,8)}),R<g.length-1&&e.jsxs("div",{className:Y.pathLink,children:[e.jsx("div",{className:Y.pathLinkLine}),e.jsx(vr,{})]})]},T))}),e.jsx("button",{className:Y.showOnMapButton,onClick:T=>{T.stopPropagation(),s==null||s(d)},children:i("buildings.spatial.showOnMap","Show on the map")})]})]},d.id)})]}):a&&r&&a!==r?e.jsx("div",{className:Y.noResults,children:i("buildings.spatial.noResultsHint","Pick two devices and run the analysis")}):e.jsx("div",{className:Y.noResults,children:i("buildings.spatial.pickEndpoints","Pick a source and a target device")})]})]})},kr="_root_6pirz_9",Sr="_header_6pirz_27",Cr="_title_6pirz_37",Tr="_search_6pirz_51",Lr="_categories_6pirz_79",$r="_category_6pirz_91",zr="_categoryHeader_6pirz_107",Pr="_categoryIcon_6pirz_143",Er="_categoryLabel_6pirz_151",Or="_categoryCount_6pirz_161",Mr="_expandIcon_6pirz_171",Ar="_items_6pirz_181",Dr="_item_6pirz_181",Br="_itemIcon_6pirz_241",Rr="_itemName_6pirz_249",Fr="_emptyState_6pirz_269",ke={root:kr,header:Sr,title:Cr,search:Tr,categories:Lr,category:$r,categoryHeader:zr,categoryIcon:Pr,categoryLabel:Er,categoryCount:Or,expandIcon:Mr,items:Ar,item:Dr,itemIcon:Br,itemName:Rr,emptyState:Fr},Gr=t=>t&&/^[a-z][a-z0-9-]*$/.test(t)?t:"box",qr={"floor-plan":["smart-home","building"],"network-topology":["network"],infrastructure:["infrastructure","network"],cad:["building"],interior:["furniture","smart-home"],"game-scene":["game"]},Vr={"smart-home":{icon:"home",label:"Smart Home"},furniture:{icon:"sofa",label:"Furniture"},network:{icon:"globe",label:"Network"},infrastructure:{icon:"settings",label:"Infrastructure"},building:{icon:"building",label:"Building"},zone:{icon:"map-pin",label:"Zones"},game:{icon:"gamepad",label:"Game Objects"},annotation:{icon:"edit",label:"Annotations"}},Kn=({mode:t,onObjectSelect:n,customObjects:s=[],className:o})=>{const{t:i}=w.useNiceTranslation(),[a,c]=u.useState(""),[r,l]=u.useState(new Set(["smart-home","furniture","network"])),x=u.useMemo(()=>qr[t]||[],[t]),m=u.useMemo(()=>{const _={},p=jo.reduce((j,f)=>{var I;return(j[I=f.category]??(j[I]=[])).push(f),j},{});return Object.entries(p).forEach(([j,f])=>{if(!x.includes(j))return;const I=f.filter(b=>!a||b.name.toLowerCase().includes(a.toLowerCase()));I.length>0&&(_[j]=I.map(b=>({id:b.id,name:b.name,category:j,icon:b.icon})))}),s.forEach(j=>{x.includes(j.category)&&(!a||j.name.toLowerCase().includes(a.toLowerCase()))&&(_[j.category]||(_[j.category]=[]),_[j.category].push(j))}),_},[x,a,s]),h=_=>{l(p=>{const j=new Set(p);return j.has(_)?j.delete(_):j.add(_),j})},v=(_,p)=>{_.dataTransfer.setData("application/json",JSON.stringify(p)),_.dataTransfer.effectAllowed="copy"};return e.jsxs("div",{className:`${ke.root} ${o??""}`,children:[e.jsxs("div",{className:ke.header,children:[e.jsx("h3",{className:ke.title,children:i("objectLibrary.objects","Objects")}),e.jsx("input",{type:"text",className:ke.search,placeholder:i("objectLibrary.search","Search..."),value:a,onChange:_=>c(_.target.value)})]}),e.jsxs("div",{className:ke.categories,children:[Object.entries(m).map(([_,p])=>{const j=Vr[_]||{icon:"box",label:_},f=r.has(_);return e.jsxs("div",{className:ke.category,children:[e.jsxs("button",{className:ke.categoryHeader,onClick:()=>h(_),children:[e.jsx("span",{className:ke.categoryIcon,children:e.jsx(w.NiceIcon,{name:j.icon,size:16})}),e.jsx("span",{className:ke.categoryLabel,children:j.label}),e.jsxs("span",{className:ke.categoryCount,children:["(",p.length,")"]}),e.jsx("span",{className:ke.expandIcon,children:e.jsx(w.NiceIcon,{name:f?"chevron-down":"chevron-right",size:14})})]}),f&&e.jsx("div",{className:ke.items,children:p.map(I=>e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:w.clickOnActivationKey,className:ke.item,draggable:!0,onDragStart:b=>v(b,I),onClick:()=>n(I),title:I.name,children:[e.jsx("span",{className:ke.itemIcon,children:e.jsx(w.NiceIcon,{name:Gr(I.icon),size:16})}),e.jsx("span",{className:ke.itemName,children:I.name})]},I.id))})]},_)}),Object.keys(m).length===0&&e.jsx("div",{className:ke.emptyState,children:a?i("objectLibrary.noObjectsMatching",'No objects matching "{searchQuery}"').replace("{searchQuery}",String(a)):i("objectLibrary.noObjectsAvailableForThis","No objects available for this mode")})]})]})},Wr="_root_o3eqo_9",Hr="_header_o3eqo_23",Ur="_title_o3eqo_39",Yr="_multiSelect_o3eqo_53",Zr="_content_o3eqo_63",Xr="_section_o3eqo_73",Kr="_sectionHeader_o3eqo_89",Jr="_sectionContent_o3eqo_127",Qr="_fieldRow_o3eqo_135",ec="_fieldLabel_o3eqo_157",tc="_textInput_o3eqo_169",nc="_numberInput_o3eqo_171",sc="_select_o3eqo_173",oc="_checkbox_o3eqo_215",ac="_colorInput_o3eqo_227",ic="_readOnly_o3eqo_245",rc="_emptyState_o3eqo_263",re={root:Wr,header:Hr,title:Ur,multiSelect:Yr,content:Zr,section:Xr,sectionHeader:Kr,sectionContent:Jr,fieldRow:Qr,fieldLabel:ec,textInput:tc,numberInput:nc,select:sc,checkbox:oc,colorInput:ac,readOnly:ic,emptyState:rc},en=[{key:"name",label:"Name",type:"text"},{key:"position.x",label:"X",type:"number",step:1},{key:"position.y",label:"Y",type:"number",step:1},{key:"rotation",label:"Rotation",type:"number",min:0,max:360,step:1},{key:"visible",label:"Visible",type:"boolean"},{key:"locked",label:"Locked",type:"boolean"}],cc=[{key:"type",label:"Zone Type",type:"select",options:[{value:"living_room",label:"Living Room"},{value:"bedroom",label:"Bedroom"},{value:"bathroom",label:"Bathroom"},{value:"kitchen",label:"Kitchen"},{value:"office",label:"Office"},{value:"hallway",label:"Hallway"},{value:"other",label:"Other"}]},{key:"color",label:"Color",type:"color"},{key:"opacity",label:"Opacity",type:"number",min:0,max:1,step:.1}],lc=[{key:"deviceType",label:"Device Type",type:"text"},{key:"status",label:"Status",type:"select",options:[{value:"online",label:"Online"},{value:"offline",label:"Offline"},{value:"error",label:"Error"}]}],Jn=({selection:t,document:n,onPropertyChange:s,className:o})=>{const{t:i}=w.useNiceTranslation(),[a,c]=u.useState(new Set(["general","position","appearance"])),r=t.objectIds.map(p=>{for(const j of n.floors)for(const f of j.layers){const I=f.objects.find(b=>b.id===p);if(I)return I}return null}).filter(Boolean),l=p=>{c(j=>{const f=new Set(j);return f.has(p)?f.delete(p):f.add(p),f})},x=u.useCallback((p,j)=>{if(j==="position.x"||j==="position.y"){const b=bt(p);return b?j==="position.x"?b.x:b.y:void 0}const f=j.split(".");let I=p;for(const b of f)if(I&&typeof I=="object"&&b in I)I=I[b];else return;return I},[]),m=u.useCallback((p,j)=>{var I;const f=x(j,p.key);switch(p.type){case"text":return e.jsx("input",{type:"text",value:String(f??""),onChange:b=>s(j.id,p.key,b.target.value),className:re.textInput});case"number":return e.jsx("input",{type:"number",value:Number(f??0),min:p.min,max:p.max,step:p.step,onChange:b=>s(j.id,p.key,parseFloat(b.target.value)),className:re.numberInput});case"boolean":return e.jsx("input",{type:"checkbox",checked:!!f,onChange:b=>s(j.id,p.key,b.target.checked),className:re.checkbox});case"color":return e.jsx("input",{type:"color",value:String(f??"var(--nice-bg, #fff)"),onChange:b=>s(j.id,p.key,b.target.value),className:re.colorInput});case"select":return e.jsx("select",{value:String(f??""),onChange:b=>s(j.id,p.key,b.target.value),className:re.select,children:(I=p.options)==null?void 0:I.map(b=>e.jsx("option",{value:b.value,children:b.label},b.value))});default:return e.jsx("span",{children:String(f??"-")})}},[x,s]);if(r.length===0)return e.jsxs("div",{className:`${re.root} ${o??""}`,children:[e.jsx("div",{className:re.header,children:e.jsx("h3",{className:re.title,children:i("propertiesPanel.properties","Properties")})}),e.jsx("div",{className:re.emptyState,children:i("propertiesPanel.noObjectSelected","No object selected")})]});const h=r[0],v=r.length>1,_=h.category==="zone"?cc:["smart-home","network","infrastructure"].includes(h.category??"")?lc:[];return e.jsxs("div",{className:`${re.root} ${o??""}`,children:[e.jsxs("div",{className:re.header,children:[e.jsx("h3",{className:re.title,children:i("propertiesPanel.properties","Properties")}),v&&e.jsx("span",{className:re.multiSelect,children:i("propertiesPanel.selected","{selectedObjects} selected").replace("{selectedObjects}",String(r.length))})]}),e.jsxs("div",{className:re.content,children:[e.jsxs("div",{className:re.section,children:[e.jsxs("button",{className:re.sectionHeader,onClick:()=>l("general"),children:[e.jsx("span",{children:e.jsx(w.NiceIcon,{name:a.has("general")?"chevron-down":"chevron-right",size:14})}),e.jsx("span",{children:i("propertiesPanel.general","General")})]}),a.has("general")&&e.jsxs("div",{className:re.sectionContent,children:[en.slice(0,1).map(p=>e.jsxs("div",{className:re.fieldRow,children:[e.jsx("label",{className:re.fieldLabel,children:p.label}),m(p,h)]},p.key)),e.jsxs("div",{className:re.fieldRow,children:[e.jsx("label",{className:re.fieldLabel,children:"ID"}),e.jsx("span",{className:re.readOnly,children:h.id})]}),e.jsxs("div",{className:re.fieldRow,children:[e.jsx("label",{className:re.fieldLabel,children:i("propertiesPanel.category","Category")}),e.jsx("span",{className:re.readOnly,children:h.category})]})]})]}),e.jsxs("div",{className:re.section,children:[e.jsxs("button",{className:re.sectionHeader,onClick:()=>l("position"),children:[e.jsx("span",{children:e.jsx(w.NiceIcon,{name:a.has("position")?"chevron-down":"chevron-right",size:14})}),e.jsx("span",{children:i("propertiesPanel.transform","Transform")})]}),a.has("position")&&e.jsx("div",{className:re.sectionContent,children:en.slice(1,4).map(p=>e.jsxs("div",{className:re.fieldRow,children:[e.jsx("label",{className:re.fieldLabel,children:p.label}),m(p,h)]},p.key))})]}),_.length>0&&e.jsxs("div",{className:re.section,children:[e.jsxs("button",{className:re.sectionHeader,onClick:()=>l("appearance"),children:[e.jsx("span",{children:e.jsx(w.NiceIcon,{name:a.has("appearance")?"chevron-down":"chevron-right",size:14})}),e.jsx("span",{children:i("propertiesPanel.appearance","Appearance")})]}),a.has("appearance")&&e.jsx("div",{className:re.sectionContent,children:_.map(p=>e.jsxs("div",{className:re.fieldRow,children:[e.jsx("label",{className:re.fieldLabel,children:p.label}),m(p,h)]},p.key))})]}),e.jsxs("div",{className:re.section,children:[e.jsxs("button",{className:re.sectionHeader,onClick:()=>l("visibility"),children:[e.jsx("span",{children:e.jsx(w.NiceIcon,{name:a.has("visibility")?"chevron-down":"chevron-right",size:14})}),e.jsx("span",{children:i("propertiesPanel.visibility","Visibility")})]}),a.has("visibility")&&e.jsx("div",{className:re.sectionContent,children:en.slice(4).map(p=>e.jsxs("div",{className:re.fieldRow,children:[e.jsx("label",{className:re.fieldLabel,children:p.label}),m(p,h)]},p.key))})]})]})]})},dc="_panel_18mro_9",uc="_header_18mro_33",mc="_headerTitle_18mro_51",pc="_title_18mro_65",hc="_closeButton_18mro_79",gc="_summarySection_18mro_111",fc="_summaryStats_18mro_129",_c="_statBadge_18mro_141",bc="_statValue_18mro_155",yc="_statLabel_18mro_167",xc="_visibilityControls_18mro_183",vc="_visibilityLabel_18mro_201",jc="_visibilityButtons_18mro_211",wc="_visibilityBtn_18mro_221",Nc="_active_18mro_251",Ic="_content_18mro_265",kc="_emptyState_18mro_279",Sc="_emptyHint_18mro_325",Cc="_vlanList_18mro_337",Tc="_vlanCard_18mro_351",Lc="_highlighted_18mro_377",$c="_hidden_18mro_387",zc="_vlanHeader_18mro_395",Pc="_colorIndicator_18mro_421",Ec="_vlanInfo_18mro_435",Oc="_vlanName_18mro_445",Mc="_vlanId_18mro_459",Ac="_vlanNameText_18mro_471",Dc="_vlanSubnet_18mro_487",Bc="_vlanStats_18mro_503",Rc="_chipStat_18mro_515",Fc="_vlanActions_18mro_545",Gc="_iconBtn_18mro_557",qc="_inactive_18mro_595",Vc="_expanded_18mro_611",Wc="_vlanDetails_18mro_623",Hc="_detailRow_18mro_635",Uc="_detailLabel_18mro_657",Yc="_detailValue_18mro_675",Zc="_badge_18mro_687",Xc="_badgeSuccess_18mro_701",Kc="_badgeNeutral_18mro_711",Jc="_deviceList_18mro_723",Qc="_deviceItems_18mro_731",el="_deviceItem_18mro_731",tl="_deviceDot_18mro_765",nl="_deviceMore_18mro_779",sl="_highlightButton_18mro_795",ol="_footer_18mro_835",al="_legendTitle_18mro_847",il="_legend_18mro_847",rl="_legendItem_18mro_875",cl="_legendColor_18mro_887",ll="_legendLabel_18mro_901",A={panel:dc,header:uc,headerTitle:mc,title:pc,closeButton:hc,summarySection:gc,summaryStats:fc,statBadge:_c,statValue:bc,statLabel:yc,visibilityControls:xc,visibilityLabel:vc,visibilityButtons:jc,visibilityBtn:wc,active:Nc,content:Ic,emptyState:kc,emptyHint:Sc,vlanList:Cc,vlanCard:Tc,highlighted:Lc,hidden:$c,vlanHeader:zc,colorIndicator:Pc,vlanInfo:Ec,vlanName:Oc,vlanId:Mc,vlanNameText:Ac,vlanSubnet:Dc,vlanStats:Bc,chipStat:Rc,vlanActions:Fc,iconBtn:Gc,inactive:qc,expanded:Vc,vlanDetails:Wc,detailRow:Hc,detailLabel:Uc,detailValue:Yc,badge:Zc,badgeSuccess:Xc,badgeNeutral:Kc,deviceList:Jc,deviceItems:Qc,deviceItem:el,deviceDot:tl,deviceMore:nl,highlightButton:sl,footer:ol,legendTitle:al,legend:il,legendItem:rl,legendColor:cl,legendLabel:ll},dl=()=>e.jsx(w.NiceIcon,{name:"close",size:16}),ul=()=>e.jsx(w.NiceIcon,{name:"eye",size:16}),ml=()=>e.jsx(w.NiceIcon,{name:"eye-off",size:16}),Ln=()=>e.jsx(w.NiceIcon,{name:"git-branch",size:16}),pl=()=>e.jsx(w.NiceIcon,{name:"info",size:14});function hl(t){var n;return((n=t.deviceIds)==null?void 0:n.length)??0}function gl(t,n){return n.filter(s=>s.vlanId===t.id).length}function fl(t){return t||"—"}const _l=({document:t,connections:n,vlans:s,visibleVlanIds:o,onVlanVisibilityChange:i,onHighlightVlan:a,onClose:c})=>{const{t:r}=w.useNiceTranslation(),[l,x]=u.useState(null),[m,h]=u.useState(null),v=u.useMemo(()=>[...s].sort((y,C)=>y.id-C.id),[s]),_=u.useMemo(()=>{const y=new Set,C=new Set;for(const d of s)for(const k of d.deviceIds??[])y.add(k);for(const d of n)d.vlanId!==void 0&&C.add(d.id);return{vlanCount:s.length,deviceCount:y.size,connectionCount:C.size}},[s,n]),p=u.useCallback(y=>{const C=o.has(y);i==null||i(y,!C)},[o,i]),j=u.useCallback(y=>{for(const C of s)i==null||i(C.id,y)},[s,i]),f=u.useCallback(y=>{x((y==null?void 0:y.id)??null),a==null||a(y)},[a]),I=u.useCallback(y=>{h(C=>C===y?null:y)},[]),b=u.useCallback(y=>{const C=[];for(const d of y.deviceIds??[])for(const k of t.floors)for(const g of k.layers){const G=g.objects.find(T=>T.id===d);G&&C.push({id:d,name:G.name??d})}return C},[t]),$=u.useMemo(()=>{const y=s.filter(C=>o.has(C.id)).length;return{visible:y,total:s.length,allVisible:y===s.length,noneVisible:y===0}},[s,o]);return e.jsxs("div",{className:A.panel,children:[e.jsxs("div",{className:A.header,children:[e.jsxs("div",{className:A.headerTitle,children:[e.jsx(Ln,{}),e.jsx("h3",{className:A.title,children:r("buildings.spatial.vlan.title","VLAN overlay")})]}),c&&e.jsx("button",{className:A.closeButton,onClick:c,title:r("buildings.spatial.close","Close"),children:e.jsx(dl,{})})]}),e.jsx("div",{className:A.summarySection,children:e.jsxs("div",{className:A.summaryStats,children:[e.jsxs("div",{className:A.statBadge,children:[e.jsx("span",{className:A.statValue,children:_.vlanCount}),e.jsx("span",{className:A.statLabel,children:r("buildings.vlan2","VLAN")})]}),e.jsxs("div",{className:A.statBadge,children:[e.jsx("span",{className:A.statValue,children:_.deviceCount}),e.jsx("span",{className:A.statLabel,children:r("buildings.spatial.devices","Devices")})]}),e.jsxs("div",{className:A.statBadge,children:[e.jsx("span",{className:A.statValue,children:_.connectionCount}),e.jsx("span",{className:A.statLabel,children:r("buildings.spatial.connectionsLabel","Connections")})]})]})}),e.jsxs("div",{className:A.visibilityControls,children:[e.jsxs("span",{className:A.visibilityLabel,children:[r("buildings.spatial.vlan.visibility","Visibility"),": ",$.visible,"/",$.total]}),e.jsxs("div",{className:A.visibilityButtons,children:[e.jsx("button",{className:`${A.visibilityBtn} ${$.allVisible?A.active:""}`,onClick:()=>j(!0),title:r("buildings.spatial.vlan.showAll","Show all"),children:r("buildings.spatial.vlan.all","All")}),e.jsx("button",{className:`${A.visibilityBtn} ${$.noneVisible?A.active:""}`,onClick:()=>j(!1),title:r("buildings.spatial.vlan.hideAll","Hide all"),children:r("buildings.spatial.vlan.none","None")})]})]}),e.jsx("div",{className:A.content,children:v.length===0?e.jsxs("div",{className:A.emptyState,children:[e.jsx(Ln,{}),e.jsx("p",{children:r("buildings.spatial.vlan.empty","No VLANs defined")}),e.jsx("span",{className:A.emptyHint,children:r("buildings.spatial.vlan.emptyHint","Add a VLAN in network-topology or infrastructure mode")})]}):e.jsx("div",{className:A.vlanList,children:v.map(y=>{const C=o.has(y.id),d=l===y.id,k=m===y.id,g=hl(y),G=gl(y,n),T=k?b(y):[];return e.jsxs("div",{className:`${A.vlanCard} ${d?A.highlighted:""} ${C?"":A.hidden}`,onMouseEnter:()=>f(y),onMouseLeave:()=>f(null),children:[e.jsxs("div",{className:A.vlanHeader,children:[e.jsx("div",{className:A.colorIndicator,style:{backgroundColor:y.color}}),e.jsxs("div",{className:A.vlanInfo,children:[e.jsxs("div",{className:A.vlanName,children:[e.jsx("span",{className:A.vlanId,children:r("buildings.vlan","VLAN {id}").replace("{id}",String(y.id))}),y.name&&e.jsx("span",{className:A.vlanNameText,children:y.name})]}),y.subnet&&e.jsx("div",{className:A.vlanSubnet,children:fl(y.subnet)})]}),e.jsxs("div",{className:A.vlanStats,children:[e.jsx("span",{className:A.chipStat,title:r("buildings.spatial.devices","Devices"),children:g}),e.jsx("span",{className:A.chipStat,title:r("buildings.spatial.connectionsLabel","Connections"),children:G})]}),e.jsxs("div",{className:A.vlanActions,children:[e.jsx("button",{className:`${A.iconBtn} ${C?"":A.inactive}`,onClick:R=>{R.stopPropagation(),p(y.id)},title:C?r("buildings.spatial.vlan.hide","Hide VLAN"):r("buildings.spatial.vlan.show","Show VLAN"),children:C?e.jsx(ul,{}):e.jsx(ml,{})}),e.jsx("button",{className:`${A.iconBtn} ${k?A.expanded:""}`,onClick:R=>{R.stopPropagation(),I(y.id)},title:r("buildings.spatial.details","Details"),children:e.jsx(pl,{})})]})]}),k&&e.jsxs("div",{className:A.vlanDetails,children:[y.description&&e.jsxs("div",{className:A.detailRow,children:[e.jsxs("span",{className:A.detailLabel,children:[r("buildings.spatial.vlan.description","Description"),":"]}),e.jsx("span",{className:A.detailValue,children:y.description})]}),y.subnet&&e.jsxs("div",{className:A.detailRow,children:[e.jsxs("span",{className:A.detailLabel,children:[r("buildings.spatial.vlan.subnet","Subnet"),":"]}),e.jsx("span",{className:A.detailValue,children:y.subnet})]}),y.gateway&&e.jsxs("div",{className:A.detailRow,children:[e.jsxs("span",{className:A.detailLabel,children:[r("buildings.spatial.vlan.gateway","Gateway"),":"]}),e.jsx("span",{className:A.detailValue,children:y.gateway})]}),e.jsxs("div",{className:A.detailRow,children:[e.jsx("span",{className:A.detailLabel,children:r("buildings.dhcp","DHCP:")}),e.jsx("span",{className:`${A.detailValue} ${A.badge} ${y.dhcpEnabled?A.badgeSuccess:A.badgeNeutral}`,children:y.dhcpEnabled?r("buildings.spatial.enabled","Enabled"):r("buildings.spatial.disabled","Disabled")})]}),T.length>0&&e.jsxs("div",{className:A.deviceList,children:[e.jsxs("span",{className:A.detailLabel,children:[r("buildings.spatial.devices","Devices")," (",T.length,"):"]}),e.jsxs("ul",{className:A.deviceItems,children:[T.slice(0,10).map(R=>e.jsxs("li",{className:A.deviceItem,children:[e.jsx("span",{className:A.deviceDot,style:{backgroundColor:y.color}}),R.name]},R.id)),T.length>10&&e.jsxs("li",{className:A.deviceMore,children:["… ",r("buildings.spatial.andMore","and")," ",T.length-10," ",r("buildings.spatial.more","more")]})]})]}),e.jsx("button",{className:A.highlightButton,onClick:()=>a==null?void 0:a(y),children:r("buildings.spatial.selectOnMap","Select on the map")})]})]},y.id)})})}),v.length>0&&e.jsxs("div",{className:A.footer,children:[e.jsx("div",{className:A.legendTitle,children:r("buildings.spatial.colourLegend","Colour legend")}),e.jsx("div",{className:A.legend,children:v.map(y=>e.jsxs("div",{className:A.legendItem,children:[e.jsx("span",{className:A.legendColor,style:{backgroundColor:y.color}}),e.jsxs("span",{className:A.legendLabel,children:[y.id,y.name?`: ${y.name}`:""]})]},y.id))})]})]})},bl="_root_13d9j_9",yl="_shell_13d9j_35",xl="_dark_13d9j_43",vl="_topBar_13d9j_67",jl="_modeSwitcher_13d9j_85",wl="_modeBtn_13d9j_95",Nl="_modeBtnActive_13d9j_131",Il="_modeIcon_13d9j_143",kl="_modeLabel_13d9j_151",Sl="_floorTabs_13d9j_159",Cl="_floorTab_13d9j_159",Tl="_floorTabActive_13d9j_203",Ll="_viewportControls_13d9j_215",$l="_active_13d9j_257",zl="_disabled_13d9j_267",Pl="_separator_13d9j_281",El="_zoomLevel_13d9j_295",Ol="_exportDropdown_13d9j_313",Ml="_exportMenu_13d9j_361",Al="_editorContainer_13d9j_435",Dl="_toolbar_13d9j_461",Bl="_toolGroup_13d9j_481",Rl="_toolBtn_13d9j_509",Fl="_toolBtnActive_13d9j_549",Gl="_canvasWrapper_13d9j_573",ql="_canvas_13d9j_573",Vl="_cursor_select_13d9j_601",Wl="_cursor_multi_select_13d9j_607",Hl="_cursor_pan_13d9j_613",Ul="_cursor_zoom_13d9j_625",Yl="_cursor_draw_wall_13d9j_631",Zl="_cursor_draw_zone_13d9j_633",Xl="_cursor_draw_polyline_13d9j_635",Kl="_cursor_draw_rectangle_13d9j_637",Jl="_cursor_draw_circle_13d9j_639",Ql="_cursor_draw_arc_13d9j_641",ed="_cursor_place_device_13d9j_647",td="_cursor_place_furniture_13d9j_649",nd="_cursor_place_network_13d9j_651",sd="_cursor_place_infra_13d9j_653",od="_cursor_place_door_13d9j_655",ad="_cursor_place_window_13d9j_657",id="_cursor_place_stairs_13d9j_659",rd="_cursor_connect_13d9j_665",cd="_cursor_route_cable_13d9j_667",ld="_cursor_annotate_13d9j_673",dd="_cursor_dimension_13d9j_675",ud="_cursor_label_13d9j_677",md="_cursor_measure_distance_13d9j_683",pd="_cursor_measure_angle_13d9j_685",hd="_cursor_measure_area_13d9j_687",gd="_cursor_move_13d9j_693",fd="_cursor_rotate_13d9j_699",_d="_cursor_scale_13d9j_705",bd="_cursor_erase_13d9j_711",yd="_cursor_copy_13d9j_717",xd="_cursor_paste_13d9j_719",vd="_grid_13d9j_729",jd="_gridLine_13d9j_735",wd="_zonesLayer_13d9j_747",Nd="_zone_13d9j_747",Id="_zoneLabel_13d9j_763",kd="_objectsLayer_13d9j_777",Sd="_object_13d9j_777",Cd="_wall_13d9j_783",Td="_objectLabel_13d9j_795",Ld="_connectionsLayer_13d9j_809",$d="_connection_13d9j_809",zd="_connectionPreview_13d9j_825",Pd="_guides_13d9j_835",Ed="_guideLine_13d9j_841",Od="_drawingPreview_13d9j_855",Md="_rightSidebar_13d9j_867",Ad="_statusBar_13d9j_889",Dd="_modeIndicator_13d9j_911",Bd="_toolIndicator_13d9j_913",Rd="_selectionInfo_13d9j_925",Fd="_drawingInfo_13d9j_927",Gd="_connectingInfo_13d9j_941",qd="_gridInfo_13d9j_955",Vd="_emptyState_13d9j_967",Wd="_emptyIcon_13d9j_989",Hd="_primaryBtn_13d9j_1019",Ud="_modeActions_13d9j_1053",Yd="_actionBtn_13d9j_1071",F={root:bl,shell:yl,dark:xl,topBar:vl,modeSwitcher:jl,modeBtn:wl,modeBtnActive:Nl,modeIcon:Il,modeLabel:kl,floorTabs:Sl,floorTab:Cl,floorTabActive:Tl,viewportControls:Ll,active:$l,disabled:zl,separator:Pl,zoomLevel:El,exportDropdown:Ol,exportMenu:Ml,editorContainer:Al,toolbar:Dl,toolGroup:Bl,toolBtn:Rl,toolBtnActive:Fl,canvasWrapper:Gl,canvas:ql,cursor_select:Vl,cursor_multi_select:Wl,cursor_pan:Hl,cursor_zoom:Ul,cursor_draw_wall:Yl,cursor_draw_zone:Zl,cursor_draw_polyline:Xl,cursor_draw_rectangle:Kl,cursor_draw_circle:Jl,cursor_draw_arc:Ql,cursor_place_device:ed,cursor_place_furniture:td,cursor_place_network:nd,cursor_place_infra:sd,cursor_place_door:od,cursor_place_window:ad,cursor_place_stairs:id,cursor_connect:rd,cursor_route_cable:cd,cursor_annotate:ld,cursor_dimension:dd,cursor_label:ud,cursor_measure_distance:md,cursor_measure_angle:pd,cursor_measure_area:hd,cursor_move:gd,cursor_rotate:fd,cursor_scale:_d,cursor_erase:bd,cursor_copy:yd,cursor_paste:xd,grid:vd,gridLine:jd,zonesLayer:wd,zone:Nd,zoneLabel:Id,objectsLayer:kd,object:Sd,wall:Cd,objectLabel:Td,connectionsLayer:Ld,connection:$d,connectionPreview:zd,guides:Pd,guideLine:Ed,drawingPreview:Od,rightSidebar:Md,statusBar:Ad,modeIndicator:Dd,toolIndicator:Bd,selectionInfo:Rd,drawingInfo:Fd,connectingInfo:Gd,gridInfo:qd,emptyState:Vd,emptyIcon:Wd,primaryBtn:Hd,modeActions:Ud,actionBtn:Yd},ct={"floor-plan":{mode:"floor-plan",label:"Floor Plan",icon:"home",tools:["select","pan","draw-zone","draw-wall","place-device","place-door","place-window","annotate","dimension","measure-distance","measure-area","erase"],layerTypes:["background","floor-plan","zones","devices","annotations","dimensions","grid"],defaultGridSize:20,enable3D:!1},"network-topology":{mode:"network-topology",label:"Network Topology",icon:"globe",tools:["select","pan","place-network","connect","route-cable","annotate","label","measure-distance","erase"],layerTypes:["background","floor-plan","network","annotations","grid"],defaultGridSize:40,enable3D:!1},infrastructure:{mode:"infrastructure",label:"Infrastructure",icon:"building",tools:["select","pan","draw-zone","place-infra","place-network","connect","route-cable","annotate","dimension","measure-distance","measure-area","erase"],layerTypes:["background","floor-plan","zones","infrastructure","network","annotations","dimensions","grid"],defaultGridSize:50,enable3D:!1},cad:{mode:"cad",label:"CAD",icon:"ruler",tools:["select","multi-select","pan","draw-wall","draw-zone","draw-polyline","draw-rectangle","draw-circle","draw-arc","place-door","place-window","place-stairs","annotate","dimension","measure-distance","measure-angle","measure-area","move","rotate","scale","copy","paste","erase"],layerTypes:["background","floor-plan","zones","annotations","dimensions","grid"],defaultGridSize:10,enable3D:!0},interior:{mode:"interior",label:"Interior Design",icon:"sofa",tools:["select","pan","draw-zone","draw-wall","place-furniture","place-device","place-door","place-window","annotate","measure-distance","measure-area","move","rotate","erase"],layerTypes:["background","floor-plan","zones","furniture","devices","annotations","grid"],defaultGridSize:25,enable3D:!0},"game-scene":{mode:"game-scene",label:"Game Scene",icon:"gamepad",tools:["select","multi-select","pan","draw-zone","draw-polyline","draw-rectangle","draw-circle","annotate","move","rotate","scale","copy","paste","erase"],layerTypes:["background","floor-plan","zones","game-objects","collision","annotations","grid"],defaultGridSize:32,enable3D:!0}},rt={select:{tool:"select",icon:"cursor",label:"Select",shortcut:"V",group:"select"},"multi-select":{tool:"multi-select",icon:"grid",label:"Multi-Select",shortcut:"M",group:"select"},pan:{tool:"pan",icon:"cursor",label:"Pan",shortcut:"H",group:"select"},zoom:{tool:"zoom",icon:"search",label:"Zoom",shortcut:"Z",group:"select"},"draw-wall":{tool:"draw-wall",icon:"line",label:"Wall",shortcut:"W",group:"draw"},"draw-zone":{tool:"draw-zone",icon:"hexagon",label:"Zone",shortcut:"R",group:"draw"},"draw-polyline":{tool:"draw-polyline",icon:"pen",label:"Polyline",shortcut:"L",group:"draw"},"draw-rectangle":{tool:"draw-rectangle",icon:"square",label:"Rectangle",shortcut:"U",group:"draw"},"draw-circle":{tool:"draw-circle",icon:"circle",label:"Circle",shortcut:"C",group:"draw"},"draw-arc":{tool:"draw-arc",icon:"pen",label:"Arc",shortcut:"A",group:"draw"},"place-device":{tool:"place-device",icon:"wifi",label:"Device",shortcut:"D",group:"place"},"place-furniture":{tool:"place-furniture",icon:"chair",label:"Furniture",shortcut:"F",group:"place"},"place-network":{tool:"place-network",icon:"server",label:"Network",shortcut:"N",group:"place"},"place-infra":{tool:"place-infra",icon:"settings",label:"Infrastructure",shortcut:"I",group:"place"},"place-door":{tool:"place-door",icon:"door",label:"Door",group:"place"},"place-window":{tool:"place-window",icon:"window",label:"Window",group:"place"},"place-stairs":{tool:"place-stairs",icon:"stairs",label:"Stairs",group:"place"},connect:{tool:"connect",icon:"link",label:"Connect",shortcut:"K",group:"connect"},"route-cable":{tool:"route-cable",icon:"plug",label:"Cable Route",group:"connect"},annotate:{tool:"annotate",icon:"edit",label:"Annotate",shortcut:"T",group:"annotate"},dimension:{tool:"dimension",icon:"ruler",label:"Dimension",group:"annotate"},label:{tool:"label",icon:"tag",label:"Label",group:"annotate"},"measure-distance":{tool:"measure-distance",icon:"ruler",label:"Distance",group:"measure"},"measure-angle":{tool:"measure-angle",icon:"triangle",label:"Angle",group:"measure"},"measure-area":{tool:"measure-area",icon:"square",label:"Area",group:"measure"},move:{tool:"move",icon:"move",label:"Move",shortcut:"G",group:"edit"},rotate:{tool:"rotate",icon:"refresh",label:"Rotate",shortcut:"R",group:"edit"},scale:{tool:"scale",icon:"scale",label:"Scale",shortcut:"S",group:"edit"},erase:{tool:"erase",icon:"trash",label:"Delete",shortcut:"Del",group:"edit"},copy:{tool:"copy",icon:"copy",label:"Copy",shortcut:"Ctrl+C",group:"edit"},paste:{tool:"paste",icon:"clipboard",label:"Paste",shortcut:"Ctrl+V",group:"edit"}},$n=t=>typeof t=="object"&&t!==null&&typeof t.id=="string"&&typeof t.category=="string",Zd={"smart-home":"devices",furniture:"furniture",network:"network",infrastructure:"infrastructure",building:"floor-plan",game:"game-objects",annotation:"annotations","place-device":"devices","place-furniture":"furniture","place-network":"network","place-infra":"infrastructure","place-door":"floor-plan","place-window":"floor-plan","place-stairs":"floor-plan"},Qn={"place-device":"smart-home","place-furniture":"furniture","place-network":"network","place-infra":"infrastructure","place-door":"building","place-window":"building","place-stairs":"building"},mt=28,zn=["#93c5fd","#86efac","#fcd34d","#f9a8d4","#c4b5fd","#67e8f9"],on=t=>`${t}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,7)}`;function Xd(t,n,s){const o=n?n.category:Qn[s],i=Zd[n?n.category:s];if(!o||!i)return null;const a=mt/2,c={x:t.x-a,y:t.y-a,width:mt,height:mt};return{id:on("obj"),type:n?n.id:s.slice(6),category:o,name:n?n.name:rt[s].label,layer:i,transform:{position:{x:c.x,y:c.y},rotation:0,scale:{x:1,y:1}},bounds:c,size:{width:mt,height:mt},visible:!0,locked:!1,childIds:[],metadata:{icon:n?n.icon:rt[s].icon}}}function Kd(t,n,s,o){if(t==="draw-zone"&&n.length>=3){const i=zn[o%zn.length],a=Dt(n);return[{id:on("zone"),type:"zone",category:"zone",name:`Zone ${o+1}`,layer:"zones",boundary:n,color:i,floorId:s,roomIds:[],bounds:a,transform:{position:{x:a.x,y:a.y},rotation:0,scale:{x:1,y:1}},visible:!0,locked:!1,childIds:[]}]}return(t==="draw-wall"||t==="draw-polyline")&&n.length>=2?n.slice(1).map((i,a)=>{const c=n[a],r=Dt([c,i]);return{id:on("wall"),type:"wall",category:"building",elementType:"wall",name:"Wall",layer:"floor-plan",start:c,end:i,height:2.7,thickness:.15,material:"drywall",openings:[],bounds:r,transform:{position:{x:r.x,y:r.y},rotation:0,scale:{x:1,y:1}},visible:!0,locked:!1,childIds:[]}}):[]}function Jd(t){var a;const n=t.defaultMode??"floor-plan",s=ct[n],o=[{type:"grid",visible:!0,locked:!0,opacity:.3,zIndex:0},{type:"background",visible:!0,locked:!0,opacity:.5,zIndex:1},{type:"floor-plan",visible:!0,locked:!1,opacity:1,zIndex:10},{type:"zones",visible:!0,locked:!1,opacity:.6,zIndex:20},{type:"furniture",visible:!0,locked:!1,opacity:1,zIndex:30},{type:"devices",visible:!0,locked:!1,opacity:1,zIndex:40},{type:"network",visible:!0,locked:!1,opacity:1,zIndex:50},{type:"infrastructure",visible:!0,locked:!1,opacity:1,zIndex:60},{type:"game-objects",visible:!0,locked:!1,opacity:1,zIndex:70},{type:"collision",visible:!1,locked:!1,opacity:.4,zIndex:80},{type:"annotations",visible:!0,locked:!1,opacity:1,zIndex:90},{type:"dimensions",visible:!0,locked:!1,opacity:1,zIndex:100}],i=t.document??t.initialDocument??null;return{mode:n,tool:s.tools[0]??"select",document:i,activeFloorId:((a=i==null?void 0:i.floors[0])==null?void 0:a.id)??null,layers:o,selection:{objectIds:[],bounds:null,locked:!1},viewport:{zoom:1,pan:{x:0,y:0},rotation:0,showGrid:!0,gridSize:t.gridSize??s.defaultGridSize,snapEnabled:t.snapEnabled??!0,snapModes:["grid","endpoint","midpoint"]},drawing:{active:!1,points:[],preview:null},connecting:{active:!1,sourceId:null,sourcePosition:null,previewPosition:null},history:{past:[],future:[]},guides:[],dragging:null,clipboard:[],ui:{showObjectLibrary:t.showObjectLibrary??!0,showLayerPanel:t.showLayerPanel??!0,showPropertiesPanel:t.showPropertiesPanel??!0,showMinimap:t.showMinimap??!0}}}function st(t,n,s,o){return{id:`${Date.now()}-${Math.random().toString(36).slice(2,9)}`,timestamp:Date.now(),type:t,objectIds:n,before:s,after:o}}function ot(t,n){return{history:{past:[...t.history.past.slice(-49),n],future:[]}}}function We(t,n){if(t)for(const s of t.floors)for(const o of s.layers){const i=o.objects.find(a=>a.id===n);if(i)return i}}function pt(t,n,s){return{...t,floors:t.floors.map(o=>({...o,layers:o.layers.map(i=>({...i,objects:i.objects.map(a=>a.id===n?{...a,...s}:a)}))})),metadata:{...t.metadata,modified:new Date().toISOString()}}}function zt(t,n){const s=new Set(n);return{...t,floors:t.floors.map(o=>({...o,layers:o.layers.map(i=>({...i,objects:i.objects.filter(a=>!s.has(a.id))}))})),metadata:{...t.metadata,modified:new Date().toISOString()}}}const Qd=new Set(["floor-plan","walls","rooms","zones","doors-windows","furniture","devices","network","infrastructure","electrical","plumbing","hvac","annotations","dimensions","grid","background","game-objects","collision"]);function Pt(t,n,s,o){return{...t,floors:t.floors.map(i=>{if(i.id!==n)return i;let a=i.layers.findIndex(r=>r.name===s);a<0&&(a=i.layers.findIndex(r=>r.type===s));const c=a>=0?i.layers.map((r,l)=>l===a?{...r,objects:[...r.objects,o]}:r):[...i.layers,{id:`layer-${s}-${Date.now().toString(36)}`,name:s,type:Qd.has(s)?s:"custom",visible:!0,locked:!1,opacity:1,objects:[o]}];return{...i,layers:c}}),metadata:{...t.metadata,modified:new Date().toISOString()}}}function eu(t,n){var s;switch(n.type){case"SET_MODE":{const o=ct[n.mode];return{...t,mode:n.mode,tool:o.tools.includes(t.tool)?t.tool:o.tools[0],viewport:{...t.viewport,gridSize:o.defaultGridSize}}}case"SET_TOOL":return{...t,tool:n.tool,drawing:{active:!1,points:[],preview:null},connecting:{active:!1,sourceId:null,sourcePosition:null,previewPosition:null}};case"SET_DOCUMENT":return{...t,document:n.document,activeFloorId:((s=n.document.floors[0])==null?void 0:s.id)??null};case"SET_ACTIVE_FLOOR":return{...t,activeFloorId:n.floorId};case"SET_SELECTION":return{...t,selection:n.selection};case"CLEAR_SELECTION":return{...t,selection:{objectIds:[],bounds:null,locked:!1}};case"SET_VIEWPORT":return{...t,viewport:{...t.viewport,...n.viewport}};case"ZOOM":{const o=Math.max(.1,Math.min(10,t.viewport.zoom*(1+n.delta*.1)));return{...t,viewport:{...t.viewport,zoom:o}}}case"PAN":return{...t,viewport:{...t.viewport,pan:{x:t.viewport.pan.x+n.delta.x,y:t.viewport.pan.y+n.delta.y}}};case"RESET_VIEW":return{...t,viewport:{...t.viewport,zoom:1,pan:{x:0,y:0}}};case"TOGGLE_GRID":return{...t,viewport:{...t.viewport,showGrid:!t.viewport.showGrid}};case"TOGGLE_SNAP":return{...t,viewport:{...t.viewport,snapEnabled:!t.viewport.snapEnabled}};case"SET_GRID_SIZE":return{...t,viewport:{...t.viewport,gridSize:n.size}};case"SET_SNAP_MODES":return{...t,viewport:{...t.viewport,snapModes:n.modes}};case"SET_LAYER_VISIBILITY":return{...t,layers:t.layers.map(o=>o.type===n.layerType?{...o,visible:n.visible}:o)};case"SET_LAYER_LOCKED":return{...t,layers:t.layers.map(o=>o.type===n.layerType?{...o,locked:n.locked}:o)};case"SET_LAYER_OPACITY":return{...t,layers:t.layers.map(o=>o.type===n.layerType?{...o,opacity:n.opacity}:o)};case"START_DRAWING":return{...t,drawing:{active:!0,points:[n.point],preview:null}};case"ADD_DRAWING_POINT":return{...t,drawing:{...t.drawing,points:[...t.drawing.points,n.point]}};case"UPDATE_DRAWING_PREVIEW":return{...t,drawing:{...t.drawing,preview:n.point}};case"FINISH_DRAWING":return{...t,drawing:{active:!1,points:[],preview:null}};case"CANCEL_DRAWING":return{...t,drawing:{active:!1,points:[],preview:null}};case"START_CONNECTING":return{...t,connecting:{active:!0,sourceId:n.sourceId,sourcePort:n.sourcePort,sourcePosition:n.sourcePosition,previewPosition:n.sourcePosition}};case"UPDATE_CONNECTING_PREVIEW":return{...t,connecting:{...t.connecting,previewPosition:n.position}};case"FINISH_CONNECTING":return{...t,connecting:{active:!1,sourceId:null,sourcePosition:null,previewPosition:null}};case"CANCEL_CONNECTING":return{...t,connecting:{active:!1,sourceId:null,sourcePosition:null,previewPosition:null}};case"SET_GUIDES":return{...t,guides:n.guides};case"TOGGLE_OBJECT_LIBRARY":return{...t,ui:{...t.ui,showObjectLibrary:!t.ui.showObjectLibrary}};case"TOGGLE_LAYER_PANEL":return{...t,ui:{...t.ui,showLayerPanel:!t.ui.showLayerPanel}};case"TOGGLE_PROPERTIES_PANEL":return{...t,ui:{...t.ui,showPropertiesPanel:!t.ui.showPropertiesPanel}};case"TOGGLE_MINIMAP":return{...t,ui:{...t.ui,showMinimap:!t.ui.showMinimap}};case"ADD_OBJECT":{if(!t.document||!t.activeFloorId)return t;const o=n.object.layer||"devices",i=Pt(t.document,t.activeFloorId,o,n.object),a=st("create",[n.object.id],null,n.object);return{...t,document:i,...ot(t,a)}}case"UPDATE_OBJECT":{if(!t.document)return t;const o=We(t.document,n.objectId);if(!o)return t;const i=pt(t.document,n.objectId,n.updates),a=st("update",[n.objectId],o,{...o,...n.updates});return{...t,document:i,...ot(t,a)}}case"DELETE_OBJECTS":{if(!t.document||n.objectIds.length===0)return t;const o=n.objectIds.map(c=>We(t.document,c)).filter(Boolean),i=zt(t.document,n.objectIds),a=st("delete",n.objectIds,o,null);return{...t,document:i,selection:{objectIds:[],bounds:null,locked:!1},...ot(t,a)}}case"MOVE_OBJECTS":{if(!t.document||n.objectIds.length===0)return t;const o=n.objectIds.map(m=>We(t.document,m)).filter(Boolean),{x:i,y:a}=n.delta,c=new Set(n.objectIds);let r=t.document;for(const m of n.objectIds){const h=We(r,m);h&&!h.locked&&(r=pt(r,m,Ii(h,i,a)))}for(const m of r.floors)for(const h of m.layers)for(const v of h.objects){const _=v.metadata;if(v.type!=="connection"||!_||c.has(v.id))continue;const p=_.sourceId&&c.has(_.sourceId)?_.sourcePosition:void 0,j=_.targetId&&c.has(_.targetId)?_.targetPosition:void 0;(p||j)&&(r=pt(r,v.id,{metadata:{..._,...p&&{sourcePosition:{x:p.x+i,y:p.y+a}},...j&&{targetPosition:{x:j.x+i,y:j.y+a}}}}))}const l=n.objectIds.map(m=>We(r,m)).filter(Boolean),x=st("move",n.objectIds,o,l);return{...t,document:r,...ot(t,x)}}case"UNDO":{if(t.history.past.length===0||!t.document)return t;const o=t.history.past[t.history.past.length-1];let i=t.document;switch(o.type){case"create":{i=zt(i,o.objectIds);break}case"delete":{const a=o.before;for(const c of a){const r=c.layer||"devices";i=Pt(i,t.activeFloorId??i.floors[0].id,r,c)}break}case"update":case"move":{const a=o.before;for(const c of a)i=pt(i,c.id,c);break}}return{...t,document:i,history:{past:t.history.past.slice(0,-1),future:[o,...t.history.future]}}}case"REDO":{if(t.history.future.length===0||!t.document)return t;const o=t.history.future[0];let i=t.document;switch(o.type){case"create":{const a=o.after,c=a.layer||"devices";i=Pt(i,t.activeFloorId??i.floors[0].id,c,a);break}case"delete":{i=zt(i,o.objectIds);break}case"update":case"move":{const a=o.after;for(const c of a)i=pt(i,c.id,c);break}}return{...t,document:i,history:{past:[...t.history.past,o],future:t.history.future.slice(1)}}}case"COPY":{if(!t.document||t.selection.objectIds.length===0)return t;const o=t.selection.objectIds.map(i=>We(t.document,i)).filter(Boolean);return{...t,clipboard:o}}case"CUT":{if(!t.document||t.selection.objectIds.length===0)return t;const o=t.selection.objectIds.map(c=>We(t.document,c)).filter(Boolean),i=zt(t.document,t.selection.objectIds),a=st("delete",t.selection.objectIds,o,null);return{...t,document:i,clipboard:o,selection:{objectIds:[],bounds:null,locked:!1},...ot(t,a)}}case"PASTE":{if(!t.document||!t.activeFloorId||t.clipboard.length===0)return t;let o=t.document;const i=[],a=[];for(const r of t.clipboard){const l=`${r.id}-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,x=r.transform,m={position:{x:x.position.x+n.position.x+20,y:x.position.y+n.position.y+20},rotation:x.rotation,scale:x.scale},h={...r,id:l,transform:m},v=h.layer||"devices";o=Pt(o,t.activeFloorId,v,h),i.push(l),a.push(h)}const c=st("create",i,null,a);return{...t,document:o,selection:{objectIds:i,bounds:null,locked:!1},...ot(t,c)}}case"START_DRAG":return{...t,dragging:{objectType:n.objectType,objectData:n.objectData,position:null}};case"UPDATE_DRAG_POSITION":return t.dragging?{...t,dragging:{...t.dragging,position:n.position}}:t;case"END_DRAG":return{...t,dragging:null};case"CANCEL_DRAG":return{...t,dragging:null};default:return t}}const tu=({mode:t,activeTool:n,onToolSelect:s,readOnly:o})=>{const a=ct[t].tools.map(r=>rt[r]).filter(Boolean),c=["select","draw","place","connect","annotate","measure","edit"];return e.jsx("div",{className:F.toolbar,children:c.map(r=>{const l=a.filter(x=>x.group===r);return l.length===0?null:e.jsx("div",{className:F.toolGroup,children:l.map(({tool:x,icon:m,label:h,shortcut:v})=>e.jsx("button",{title:`${h}${v?` (${v})`:""}`,className:`${F.toolBtn} ${n===x?F.toolBtnActive:""}`,onClick:()=>s(x),disabled:o&&!["select","pan","zoom","measure-distance","measure-angle","measure-area"].includes(x),children:e.jsx(w.NiceIcon,{name:m,size:16})},x))},r)})})},nu=({currentMode:t,availableModes:n,onModeChange:s})=>e.jsx("div",{className:F.modeSwitcher,children:n.map(o=>{const i=ct[o];return e.jsxs("button",{title:i.label,className:`${F.modeBtn} ${t===o?F.modeBtnActive:""}`,onClick:()=>s(o),children:[e.jsx("span",{className:F.modeIcon,children:e.jsx(w.NiceIcon,{name:i.icon,size:16})}),e.jsx("span",{className:F.modeLabel,children:i.label})]},o)})});function Pn(t){if(!t)return[];const n=[];for(const s of t.floors)for(const o of s.layers)if(o.type==="network"||o.type==="infrastructure"){for(const i of o.objects)if(i.type==="connection"){const a=i.metadata;a!=null&&a.sourceId&&(a!=null&&a.targetId)&&n.push({id:i.id,sourceId:a.sourceId,sourcePort:a.sourcePort,targetId:a.targetId,targetPort:a.targetPort,medium:a.medium??"ethernet-cat6",status:a.status??"unknown",bandwidth:a.bandwidth,latency:a.latency??1,waypoints:a.waypoints??[]})}}return n}function su(t){if(!t)return[];const n=[],s=new Set;for(const o of t.floors)for(const i of o.layers)if(i.type==="network"||i.type==="infrastructure")for(const a of i.objects){const c=a.metadata;if((c==null?void 0:c.vlanId)!==void 0&&!s.has(c.vlanId))s.add(c.vlanId),n.push({id:c.vlanId,name:c.vlanName??`VLAN ${c.vlanId}`,color:c.vlanColor??ou(c.vlanId),deviceIds:[a.id],subnet:c.subnet,gateway:c.gateway,dhcpEnabled:c.dhcpEnabled});else if((c==null?void 0:c.vlanId)!==void 0){const r=n.find(l=>l.id===c.vlanId);r&&!r.deviceIds.includes(a.id)&&r.deviceIds.push(a.id)}}return n.sort((o,i)=>o.id-i.id)}function ou(t){const n=["var(--nice-primary, #3b82f6)","var(--nice-success, #22c55e)","var(--nice-warning, #f59e0b)","var(--nice-danger, #ef4444)","var(--nice-accent, #8b5cf6)","var(--nice-color-accent-pink, #ec4899)","var(--nice-info, #06b6d4)","var(--nice-warning, #f97316)","var(--nice-info, #14b8a6)","var(--nice-accent, #a855f7)"];return n[t%n.length]}const au=[{target:".nice-spatial-editor",titleKey:"tutorial.spatialEditor.intro.title",title:"Spatial editor",contentKey:"tutorial.spatialEditor.intro.content",content:"Lay out floor plans across modes: draw walls, rooms and objects with the tools, manage layers, snap to the grid, then export.",placement:"auto"}],iu=t=>{var dn,un,mn;const{defaultMode:n="floor-plan",availableModes:s=Object.keys(ct),readOnly:o=!1,theme:i="light",locale:a="en",onDocumentChange:c,onSelectionChange:r,onModeChange:l,onExport:x,onImport:m,tutorial:h,className:v,style:_,cookies:p=!1,localStorage:j=!0,sessionStorage:f=!1,storageMode:I,storageKey:b,persistPreferences:$=!1}=t,{t:y}=w.useNiceTranslation(),C=w.useStorageAdapter(b??"nice-spatial-editor"),[d]=u.useState(()=>$?C.get("prefs")??{}:{}),[k,g]=u.useReducer(eu,t,Jd),G=u.useRef(null),T=u.useRef(!1),R=u.useRef({x:0,y:0}),H=u.useRef(null),[se,ne]=u.useState(null),[oe,he]=u.useState(!1),[ce,Ne]=u.useState(!1),[Ke,De]=u.useState(null),[ve,Pe]=u.useState(null),[Fe,P]=u.useState(!1),[ee,ge]=u.useState(!1),[Se,Ee]=u.useState(!1),[Ce,Ge]=u.useState(new Set),[qe,He]=u.useState(null),Ae=u.useRef(null),Oe=u.useRef(null),Ie=u.useRef(null),{mode:$e,tool:fe,document:U,activeFloorId:Me,layers:Be,selection:be,viewport:K,drawing:xe,connecting:me,guides:Je,ui:Ve,history:yt,dragging:Ue}=k,Qe=ct[$e],xt=yt.past.length>0,vt=yt.future.length>0;u.useEffect(()=>{var N,L,q;!$||!d||((d.zoom||d.pan)&&g({type:"SET_VIEWPORT",viewport:{zoom:d.zoom,pan:d.pan,showGrid:(N=d.gridConfig)==null?void 0:N.visible,gridSize:(L=d.gridConfig)==null?void 0:L.size,snapEnabled:(q=d.gridConfig)==null?void 0:q.snapEnabled}}),d.mode&&g({type:"SET_MODE",mode:d.mode}),d.tool&&g({type:"SET_TOOL",tool:d.tool}),d.layerVisibility&&Object.entries(d.layerVisibility).forEach(([W,V])=>{V!==void 0&&g({type:"SET_LAYER_VISIBILITY",layerType:W,visible:V})}))},[]),u.useEffect(()=>{if(!$)return;const N={zoom:K.zoom,pan:K.pan,gridConfig:{size:K.gridSize,visible:K.showGrid,snapEnabled:K.snapEnabled},mode:$e,tool:fe,layerVisibility:Object.fromEntries(Be.map(L=>[L.type,L.visible])),uiPanels:Ve};C.set("prefs",N)},[$,K,$e,fe,Be,Ve,C]);const jt=u.useRef({doc:U,selection:be});u.useEffect(()=>{U&&U!==jt.current.doc&&(c==null||c(U))},[U,c]),u.useEffect(()=>{be!==jt.current.selection&&(r==null||r(be))},[be,r]);const pe=u.useMemo(()=>(U==null?void 0:U.floors.find(N=>N.id===Me))??(U==null?void 0:U.floors[0])??null,[U,Me]),Re=u.useCallback((N,L)=>{var W;const q=(W=G.current)==null?void 0:W.getBoundingClientRect();return q?{x:(N-q.left-K.pan.x)/K.zoom,y:(L-q.top-K.pan.y)/K.zoom}:{x:0,y:0}},[K.pan,K.zoom]),Ye=u.useCallback(N=>{if(!K.snapEnabled)return N;const L={cellSize:K.gridSize,origin:{x:0,y:0},visible:K.showGrid};return an(N,L)},[K.snapEnabled,K.gridSize,K.showGrid]),lt=u.useCallback((N,L)=>{const q=o?null:Xd(N,L,fe);q&&(g({type:"ADD_OBJECT",object:q}),g({type:"SET_SELECTION",selection:{objectIds:[q.id],bounds:null,locked:!1}}),L&&(g({type:"END_DRAG"}),g({type:"SET_TOOL",tool:"select"})))},[o,fe]),qt=u.useCallback(N=>{var V;if(fe==="pan"||N.button===1){T.current=!0,R.current={x:N.clientX,y:N.clientY};return}const L=Ye(Re(N.clientX,N.clientY)),q=Ue==null?void 0:Ue.objectData,W=$n(q)?q:null;if(W||Qn[fe]){lt(L,W);return}if(fe==="draw-zone"||fe==="draw-wall"||fe==="draw-polyline")xe.active?g({type:"ADD_DRAWING_POINT",point:L}):g({type:"START_DRAWING",point:L});else if(fe==="connect"){const B=pe==null?void 0:pe.layers.flatMap(X=>X.objects).find(X=>{if(!X.bounds)return!1;const de=X.bounds;return L.x>=de.x&&L.x<=de.x+de.width&&L.y>=de.y&&L.y<=de.y+de.height});if(B)if(me.active){g({type:"FINISH_CONNECTING",targetId:B.id});const X=`conn-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,de=B.bounds?{x:B.bounds.x+B.bounds.width/2,y:B.bounds.y+B.bounds.height/2}:L,ye={id:X,type:"connection",category:"network",name:"Connection",transform:{position:{x:0,y:0},rotation:0,scale:{x:1,y:1}},layer:"network",locked:!1,visible:!0,childIds:[],bounds:{x:Math.min(me.sourcePosition.x,de.x),y:Math.min(me.sourcePosition.y,de.y),width:Math.abs(de.x-me.sourcePosition.x),height:Math.abs(de.y-me.sourcePosition.y)},metadata:{sourceId:me.sourceId,targetId:B.id,sourcePosition:me.sourcePosition,targetPosition:de,medium:"ethernet-cat6",status:"active"}};g({type:"ADD_OBJECT",object:ye})}else{const X=B.bounds?{x:B.bounds.x+B.bounds.width/2,y:B.bounds.y+B.bounds.height/2}:L;g({type:"START_CONNECTING",sourceId:B.id,sourcePosition:X})}else me.active&&g({type:"CANCEL_CONNECTING"})}else if(fe==="select"){const B=(V=N.target.closest("[data-object-id]"))==null?void 0:V.getAttribute("data-object-id");B?(g({type:"SET_SELECTION",selection:{objectIds:[B],bounds:null,locked:!1}}),o||(H.current=L,ne({ids:[B],dx:0,dy:0}))):g({type:"CLEAR_SELECTION"})}},[fe,xe.active,me.active,me.sourceId,me.sourcePosition,Ye,Re,pe,Ue,lt,o]),Vt=u.useCallback(N=>{if(T.current){const W=N.clientX-R.current.x,V=N.clientY-R.current.y;g({type:"PAN",delta:{x:W,y:V}}),R.current={x:N.clientX,y:N.clientY};return}const L=Ye(Re(N.clientX,N.clientY)),q=H.current;if(se&&q){ne({...se,dx:L.x-q.x,dy:L.y-q.y});return}if(xe.active&&(g({type:"UPDATE_DRAWING_PREVIEW",point:L}),K.snapEnabled&&pe)){const W=pe.layers.flatMap(X=>X.objects.filter(de=>de.bounds).map(de=>({id:de.id,bounds:de.bounds}))),V={x:L.x,y:L.y,width:1,height:1},B=Hn(V,W,10);g({type:"SET_GUIDES",guides:B})}me.active&&g({type:"UPDATE_CONNECTING_PREVIEW",position:L})},[xe.active,me.active,Ye,Re,K.snapEnabled,pe,se]),wt=u.useCallback(()=>{T.current=!1,H.current=null,se&&(se.dx!==0||se.dy!==0)&&g({type:"MOVE_OBJECTS",objectIds:se.ids,delta:{x:se.dx,y:se.dy}}),ne(null)},[se]),et=u.useCallback(()=>{var W;if(!xe.active)return;const N=xe.points.filter((V,B,X)=>B===0||V.x!==X[B-1].x||V.y!==X[B-1].y),L=pe?((W=it(pe.layers))==null?void 0:W.objects.length)??0:0,q=pe?Kd(fe,N,pe.id,L):[];for(const V of q)g({type:"ADD_OBJECT",object:V});g({type:"FINISH_DRAWING"}),g({type:"SET_GUIDES",guides:[]}),q.length>0&&g({type:"SET_SELECTION",selection:{objectIds:q.map(V=>V.id),bounds:null,locked:!1}})},[xe.active,xe.points,pe,fe]),Wt=u.useCallback(N=>{et()},[et]),Ht=u.useCallback(N=>{N.preventDefault();const L=N.deltaY>0?-1:1;g({type:"ZOOM",delta:L,center:Re(N.clientX,N.clientY)})},[Re]),Nt=u.useCallback(N=>{N.key==="Enter"&&xe.active&&et(),N.key==="Escape"&&(xe.active?g({type:"CANCEL_DRAWING"}):me.active?g({type:"CANCEL_CONNECTING"}):g({type:"CLEAR_SELECTION"})),N.key==="Delete"&&be.objectIds.length>0&&g({type:"DELETE_OBJECTS",objectIds:be.objectIds}),(N.ctrlKey||N.metaKey)&&(N.key==="z"&&g({type:"UNDO"}),N.key==="y"&&g({type:"REDO"}),N.key==="c"&&g({type:"COPY"}),N.key==="v"&&g({type:"PASTE",position:{x:0,y:0}}),N.key==="x"&&g({type:"CUT"}))},[xe.active,me.active,be.objectIds,et]),S=u.useCallback(N=>{g({type:"SET_MODE",mode:N}),l==null||l(N)},[l]),z=u.useCallback(N=>{g({type:"SET_TOOL",tool:N})},[]),D=u.useCallback(async N=>{var L;if(U){he(!1);try{const q={includeGrid:!1,includeDimensions:!0};if(N==="nsp"){const W=Co(U,q);Lt(W),x==null||x(N,W.data)}else if(N==="svg"){const W=Lo(U,q);Lt(W),x==null||x(N,W.data)}else if(N==="dxf"){const W=Po(U,q);Lt(W),x==null||x(N,W.data)}else if(N==="png"&&G.current){const W=await Ao(G.current,((L=U.metadata)==null?void 0:L.name)||"export");Lt(W),x==null||x(N,W.data)}}catch(q){console.error(`Export to ${N} failed:`,q)}}},[U,x]),te=u.useCallback(async N=>{var q;const L=(q=N.target.files)==null?void 0:q[0];if(L){Ne(!1);try{const V=await Zo(L,{convertClosedPolylinesToZones:!0,minZoneArea:1});V.success&&V.document?Pe(V):De(V),Ie.current&&(Ie.current.value="")}catch(W){console.error("Import failed:",W),De({success:!1,warnings:[],errors:[{code:"IMPORT_ERROR",message:W instanceof Error?W.message:y("buildings.unknownImportError","Unknown import error"),fatal:!0}],stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:0}})}}},[y]),ae=u.useCallback(()=>{ve!=null&&ve.success&&ve.document?P(!0):Pe(null)},[ve]),ue=u.useCallback(()=>{Pe(null),P(!1)},[]),_e=u.useCallback((N,L)=>{if(!(ve!=null&&ve.document)){P(!1);return}const q=ve.document,W={...q,floors:q.floors.map(V=>({...V,layers:V.layers.filter(B=>N.get(B.id)!=="skip").map(B=>{const X=N.get(B.id);if(X===B.id||!X)return B;const de=U==null?void 0:U.floors.flatMap(ye=>ye.layers).find(ye=>ye.id===X);return de?{...B,id:de.id,name:de.name,type:de.type}:B})}))};g({type:"SET_DOCUMENT",document:W}),m==null||m(W),De(ve),P(!1),Pe(null)},[ve,U,m]),Le=u.useCallback(()=>{P(!1)},[]),Te=u.useCallback(N=>{if(Ie.current){let L=".dxf,.svg,.geojson,.json,.ifc";N==="dxf"?L=".dxf":N==="svg"?L=".svg":N==="geojson"?L=".geojson,.json":N==="ifc"&&(L=".ifc"),Ie.current.accept=L,Ie.current.click()}Ne(!1)},[]);u.useEffect(()=>{const N=L=>{Ae.current&&!Ae.current.contains(L.target)&&he(!1),Oe.current&&!Oe.current.contains(L.target)&&Ne(!1)};return(oe||ce)&&document.addEventListener("mousedown",N),()=>{document.removeEventListener("mousedown",N)}},[oe,ce]);const Ut=u.useCallback(()=>{var V,B;if(!K.showGrid||!pe)return null;const N=[],L=K.gridSize,q=((V=pe.bounds)==null?void 0:V.width)??1e3,W=((B=pe.bounds)==null?void 0:B.height)??800;for(let X=0;X<=q;X+=L)N.push(e.jsx("line",{x1:X,y1:0,x2:X,y2:W,className:F.gridLine},`v${X}`));for(let X=0;X<=W;X+=L)N.push(e.jsx("line",{x1:0,y1:X,x2:q,y2:X,className:F.gridLine},`h${X}`));return e.jsx("g",{className:F.grid,children:N})},[K.showGrid,K.gridSize,pe]),It=u.useCallback(N=>{var L;return((L=Be.find(q=>q.type===N))==null?void 0:L.visible)!==!1},[Be]),dt=u.useCallback(N=>se&&(se.dx!==0||se.dy!==0)&&se.ids.includes(N)?`translate(${se.dx}, ${se.dy})`:void 0,[se]),os=u.useCallback(()=>{if(!pe)return null;const N=it(pe.layers);return!N||!It("zones")?null:e.jsx("g",{className:F.zonesLayer,children:N.objects.map(L=>{const q=Gt(L);if(!q)return null;const W=q.map((X,de)=>`${de===0?"M":"L"}${X.x},${X.y}`).join(" ")+" Z",V=be.objectIds.includes(L.id),B=q.reduce((X,de)=>({x:X.x+de.x/q.length,y:X.y+de.y/q.length}),{x:0,y:0});return e.jsxs("g",{className:F.zone,"data-object-id":L.id,transform:dt(L.id),onClick:X=>{X.stopPropagation(),g({type:"SET_SELECTION",selection:{objectIds:[L.id],bounds:null,locked:!1}})},children:[e.jsx("path",{d:W,fill:At(L)??"var(--nice-primary-bg, #dbeafe)",fillOpacity:.5,stroke:V?"var(--nice-primary-hover, #2563eb)":"var(--nice-text-muted, #94a3b8)",strokeWidth:V?2:1}),L.name&&e.jsx("text",{x:B.x,y:B.y,textAnchor:"middle",dominantBaseline:"middle",className:F.zoneLabel,children:L.name})]},L.id)})})},[pe,be.objectIds,It,dt]),as=u.useCallback(()=>{var q;if(!pe)return null;const N=it(pe.layers),L=Math.max(3,.15*(((q=U==null?void 0:U.settings)==null?void 0:q.scale)??50));return e.jsx("g",{className:F.objectsLayer,children:pe.layers.map(W=>W===N||W.type==="grid"||W.type==="background"||W.visible===!1||!It(W.type)?null:W.objects.map(V=>{var pn,hn,gn,fn;if(V.type==="connection"||V.visible===!1)return null;const B=be.objectIds.includes(V.id),X=kt=>{kt.stopPropagation(),fe==="select"&&g({type:"SET_SELECTION",selection:{objectIds:[V.id],bounds:null,locked:!1}})},de=cn(V);if(de){const kt=V.thickness;return e.jsx("line",{"data-object-id":V.id,className:F.wall,transform:dt(V.id),x1:de.start.x,y1:de.start.y,x2:de.end.x,y2:de.end.y,stroke:B?"var(--nice-primary-hover, #2563eb)":"var(--nice-text-primary, #334155)",strokeWidth:kt?Math.max(3,kt*(((pn=U==null?void 0:U.settings)==null?void 0:pn.scale)??50)):L,strokeLinecap:"round",onClick:X},V.id)}const ye=bt(V);if(!ye)return null;const tt=(hn=V.metadata)==null?void 0:hn.icon,Ze=typeof tt=="string"?tt:void 0,Yt=Math.max(10,Math.min(ye.width,ye.height)-10);return e.jsxs("g",{"data-object-id":V.id,className:`${F.object} ${B?F.objectSelected:""}`,transform:dt(V.id),onClick:X,children:[e.jsx("rect",{x:ye.x,y:ye.y,width:ye.width,height:ye.height,rx:6,fill:((gn=V.style)==null?void 0:gn.fill)??"var(--nice-bg-primary, #ffffff)",stroke:B?"var(--nice-primary-hover, #2563eb)":((fn=V.style)==null?void 0:fn.stroke)??"var(--nice-text-secondary, #64748b)",strokeWidth:B?2.5:1.5}),Ze&&e.jsx("g",{transform:`translate(${ye.x+(ye.width-Yt)/2}, ${ye.y+(ye.height-Yt)/2})`,style:{color:"var(--nice-text-primary, #334155)"},"aria-hidden":"true",children:e.jsx(w.NiceIcon,{name:Ze,size:Yt})}),V.name&&e.jsx("text",{x:ye.x+ye.width/2,y:ye.y+ye.height+12,textAnchor:"middle",className:F.objectLabel,children:V.name})]},V.id)}))})},[pe,be.objectIds,It,fe,(dn=U==null?void 0:U.settings)==null?void 0:dn.scale,dt]),is=u.useCallback(()=>Je.length===0?null:e.jsx("g",{className:F.guides,children:Je.map((N,L)=>e.jsx("line",{x1:N.start.x,y1:N.start.y,x2:N.end.x,y2:N.end.y,className:F.guideLine},L))}),[Je]),rs=u.useCallback(()=>{if(!xe.active||xe.points.length===0)return null;const N=[...xe.points];xe.preview&&N.push(xe.preview);const L=N.map((W,V)=>`${V===0?"M":"L"}${W.x},${W.y}`).join(" "),q=fe==="draw-zone"&&N.length>2;return e.jsxs("g",{className:F.drawingPreview,children:[e.jsx("path",{d:L+(q?" Z":""),fill:q?"var(--nice-primary-tint-10, rgba(37, 99, 235, 0.1))":"none",stroke:"var(--nice-primary-hover, #2563eb)",strokeWidth:2,strokeDasharray:q?"none":"6,3"}),N.map((W,V)=>e.jsx("circle",{cx:W.x,cy:W.y,r:4,fill:"var(--nice-primary-hover, #2563eb)"},V))]})},[xe,fe]),cs=u.useCallback(()=>!me.active||!me.sourcePosition||!me.previewPosition?null:e.jsxs("g",{className:F.connectionPreview,children:[e.jsx("line",{x1:me.sourcePosition.x,y1:me.sourcePosition.y,x2:me.previewPosition.x,y2:me.previewPosition.y,stroke:"var(--nice-success, #10b981)",strokeWidth:2,strokeDasharray:"8,4",markerEnd:"url(#connectionArrow)"}),e.jsx("circle",{cx:me.sourcePosition.x,cy:me.sourcePosition.y,r:6,fill:"var(--nice-success, #10b981)"}),e.jsx("circle",{cx:me.previewPosition.x,cy:me.previewPosition.y,r:6,fill:"var(--nice-success, #10b981)",fillOpacity:.5,stroke:"var(--nice-success, #10b981)",strokeWidth:2}),e.jsx("defs",{children:e.jsx("marker",{id:"connectionArrow",markerWidth:"10",markerHeight:"10",refX:"9",refY:"3",orient:"auto",markerUnits:"strokeWidth",children:e.jsx("path",{d:"M0,0 L0,6 L9,3 z",fill:"var(--nice-success, #10b981)"})})})]}),[me]),ls=u.useCallback(()=>{if(!pe)return null;const N=pe.layers.find(V=>V.type==="network");if(!N)return null;const L=N.objects.filter(V=>V.type==="connection");if(L.length===0)return null;const q={"ethernet-cat5":{color:"var(--nice-primary, #3b82f6)",width:2},"ethernet-cat6":{color:"var(--nice-primary-hover, #2563eb)",width:2},"ethernet-cat6a":{color:"var(--nice-primary-dark, #1d4ed8)",width:2},"ethernet-cat7":{color:"var(--nice-primary-dark, #1e40af)",width:3},"fiber-single":{color:"var(--nice-warning, #f59e0b)",width:3},"fiber-multi":{color:"var(--nice-warning-dark, #d97706)",width:3},"wifi-2.4ghz":{color:"var(--nice-accent, #8b5cf6)",dashArray:"6,4",width:2},"wifi-5ghz":{color:"var(--nice-accent, #7c3aed)",dashArray:"6,4",width:2},"wifi-6ghz":{color:"var(--nice-color-accent-hover, #6d28d9)",dashArray:"6,4",width:2},default:{color:"var(--nice-text-secondary, #64748b)",width:2}},W={active:"var(--nice-success, #10b981)",inactive:"var(--nice-text-muted, #94a3b8)",error:"var(--nice-danger, #ef4444)",degraded:"var(--nice-warning, #f59e0b)",unknown:"var(--nice-text-secondary, #64748b)"};return e.jsx("g",{className:F.connectionsLayer,children:L.map(V=>{const B=V.metadata;if(!(B!=null&&B.sourcePosition)||!(B!=null&&B.targetPosition))return null;const X=q[B.medium??"default"]||q.default,de=W[B.status??"unknown"]||W.unknown,ye=be.objectIds.includes(V.id);let tt=`M${B.sourcePosition.x},${B.sourcePosition.y}`;if(B.waypoints&&B.waypoints.length>0)for(const Ze of B.waypoints)tt+=` L${Ze.x},${Ze.y}`;return tt+=` L${B.targetPosition.x},${B.targetPosition.y}`,e.jsxs("g",{className:F.connection,onClick:Ze=>{Ze.stopPropagation(),g({type:"SET_SELECTION",selection:{objectIds:[V.id],bounds:null,locked:!1}})},children:[e.jsx("path",{d:tt,fill:"none",stroke:ye?"var(--nice-primary-hover, #2563eb)":X.color,strokeWidth:ye?X.width+1:X.width,strokeDasharray:X.dashArray,strokeLinecap:"round",strokeLinejoin:"round"}),B.status&&B.status!=="active"&&e.jsx("circle",{cx:(B.sourcePosition.x+B.targetPosition.x)/2,cy:(B.sourcePosition.y+B.targetPosition.y)/2,r:5,fill:de}),e.jsx("circle",{cx:B.sourcePosition.x,cy:B.sourcePosition.y,r:4,fill:X.color,stroke:"white",strokeWidth:1}),e.jsx("circle",{cx:B.targetPosition.x,cy:B.targetPosition.y,r:4,fill:X.color,stroke:"white",strokeWidth:1})]},V.id)})})},[pe,be.objectIds]);if(!U&&!pe)return e.jsx("div",{className:`${F.root} ${F[i]} ${v??""}`,style:_,children:e.jsxs("div",{className:F.emptyState,children:[e.jsx("div",{className:F.emptyIcon,children:e.jsx(w.NiceIcon,{name:Qe.icon,size:48})}),e.jsx("h3",{children:y("buildings.noDocumentOpen","No Document Open")}),e.jsx("p",{children:y("buildings.createANewDocumentOr","Create a new document or open an existing .nsp.json file")}),e.jsx("button",{className:F.primaryBtn,onClick:()=>{const N=rn("New Project","floor-plan");g({type:"SET_DOCUMENT",document:N})},children:y("buildings.createNewDocument","Create New Document")})]})});const ds=e.jsxs("div",{className:F.topBar,children:[e.jsx(nu,{currentMode:$e,availableModes:s,onModeChange:S}),U&&U.floors.length>1&&e.jsx("div",{className:F.floorTabs,children:U.floors.map(N=>e.jsx("button",{className:`${F.floorTab} ${Me===N.id?F.floorTabActive:""}`,onClick:()=>g({type:"SET_ACTIVE_FLOOR",floorId:N.id}),children:N.name},N.id))}),e.jsxs("div",{className:F.viewportControls,children:[!o&&e.jsxs(e.Fragment,{children:[e.jsx("button",{title:y("buildings.undoCtrlZ","Undo (Ctrl+Z)"),onClick:()=>g({type:"UNDO"}),disabled:!xt,className:xt?"":F.disabled,children:e.jsx(w.NiceIcon,{name:"reply",size:16})}),e.jsx("button",{title:y("buildings.redoCtrlY","Redo (Ctrl+Y)"),onClick:()=>g({type:"REDO"}),disabled:!vt,className:vt?"":F.disabled,children:e.jsx(w.NiceIcon,{name:"forward",size:16})}),e.jsx("div",{className:F.separator})]}),e.jsx("button",{title:y("buildings.toggleGrid","Toggle Grid"),onClick:()=>g({type:"TOGGLE_GRID"}),className:K.showGrid?F.active:"",children:e.jsx(w.NiceIcon,{name:"grid",size:16})}),e.jsx("button",{title:y("buildings.toggleSnap","Toggle Snap"),onClick:()=>g({type:"TOGGLE_SNAP"}),className:K.snapEnabled?F.active:"",children:e.jsx(w.NiceIcon,{name:"target",size:16})}),e.jsxs("span",{className:F.zoomLevel,children:[Math.round(K.zoom*100),"%"]}),e.jsx("button",{title:y("buildings.zoomIn","Zoom In"),onClick:()=>g({type:"ZOOM",delta:1}),children:e.jsx(w.NiceIcon,{name:"plus",size:16})}),e.jsx("button",{title:y("buildings.zoomOut","Zoom Out"),onClick:()=>g({type:"ZOOM",delta:-1}),children:e.jsx(w.NiceIcon,{name:"minus",size:16})}),e.jsx("button",{title:y("buildings.resetView2","Reset View"),onClick:()=>g({type:"RESET_VIEW"}),children:e.jsx(w.NiceIcon,{name:"expand",size:16})}),!o&&e.jsxs("div",{className:F.exportDropdown,ref:Oe,children:[e.jsx("input",{type:"file",ref:Ie,onChange:te,style:{display:"none"}}),e.jsxs("button",{title:y("buildings.import","Import"),onClick:()=>Ne(!ce),className:ce?F.active:"",children:[e.jsx(w.NiceIcon,{name:"download",size:14})," ",y("buildings.import","Import")]}),ce&&e.jsxs("div",{className:F.exportMenu,children:[e.jsxs("button",{onClick:()=>Te(),children:[e.jsx(w.NiceIcon,{name:"file",size:14})," ",y("buildings.autoDetectFormat","Auto-detect format")]}),e.jsxs("button",{onClick:()=>Te("dxf"),children:[e.jsx(w.NiceIcon,{name:"ruler",size:14})," ",y("buildings.autocadDxfDxf","AutoCAD DXF (.dxf)")]}),e.jsxs("button",{onClick:()=>Te("svg"),children:[e.jsx(w.NiceIcon,{name:"image",size:14})," ",y("buildings.svgVectorGraphicsSvg","SVG Vector Graphics (.svg)")]}),e.jsxs("button",{onClick:()=>Te("geojson"),children:[e.jsx(w.NiceIcon,{name:"globe",size:14})," ",y("buildings.geojsonGeojson","GeoJSON (.geojson)")]}),e.jsxs("button",{onClick:()=>Te("ifc"),children:[e.jsx(w.NiceIcon,{name:"building",size:14})," ",y("buildings.ifcBimIfc","IFC (BIM) (.ifc)")]})]})]}),U&&e.jsxs("div",{className:F.exportDropdown,ref:Ae,children:[e.jsxs("button",{title:y("buildings.export","Export"),onClick:()=>he(!oe),className:oe?F.active:"",children:[e.jsx(w.NiceIcon,{name:"upload",size:14})," ",y("buildings.export","Export")]}),oe&&e.jsxs("div",{className:F.exportMenu,children:[e.jsxs("button",{onClick:()=>D("nsp"),children:[e.jsx(w.NiceIcon,{name:"file",size:14})," ",y("buildings.nicetodevSpatialPlanNspJson","NiceToDev Spatial Plan (.nsp.json)")]}),e.jsxs("button",{onClick:()=>D("svg"),children:[e.jsx(w.NiceIcon,{name:"image",size:14})," ",y("buildings.svgVectorGraphicsSvg","SVG Vector Graphics (.svg)")]}),e.jsxs("button",{onClick:()=>D("dxf"),children:[e.jsx(w.NiceIcon,{name:"ruler",size:14})," ",y("buildings.autocadDxfDxf","AutoCAD DXF (.dxf)")]}),e.jsxs("button",{onClick:()=>D("png"),children:[e.jsx(w.NiceIcon,{name:"image",size:14})," ",y("buildings.pngImagePng","PNG Image (.png)")]})]})]})]})]}),us=Ve.showObjectLibrary&&!o?e.jsx(Kn,{mode:$e,onObjectSelect:N=>{g({type:"SET_TOOL",tool:`place-${N.category}`}),g({type:"START_DRAG",objectType:N.category,objectData:N})}}):void 0,ms=e.jsxs("div",{className:F.editorContainer,children:[!o&&e.jsx(tu,{mode:$e,activeTool:fe,onToolSelect:z,readOnly:o}),($e==="network-topology"||$e==="infrastructure")&&e.jsxs("div",{className:F.modeActions,children:[e.jsxs("button",{className:`${F.actionBtn} ${ee?F.active:""}`,onClick:()=>ge(!ee),title:y("buildings.spatial.pathAnalysis","Network path analysis"),children:[e.jsx(w.NiceIcon,{name:"bar-chart",size:14})," ",y("buildings.spatial.path","Path")]}),e.jsxs("button",{className:`${F.actionBtn} ${Se?F.active:""}`,onClick:()=>Ee(!Se),title:y("buildings.spatial.vlan.title","VLAN overlay"),children:[e.jsx(w.NiceIcon,{name:"globe",size:14})," ",y("buildings.vlanOverlay","VLAN Overlay")]})]}),e.jsxs("div",{className:F.canvasWrapper,onDragOver:N=>{!o&&N.dataTransfer.types.includes("application/json")&&N.preventDefault()},onDrop:N=>{let L=null;try{L=JSON.parse(N.dataTransfer.getData("application/json"))}catch{return}$n(L)&&(N.preventDefault(),lt(Ye(Re(N.clientX,N.clientY)),L))},children:[e.jsx("svg",{ref:G,className:`${F.canvas} ${F[`cursor_${fe.replace("-","_")}`]??""}`,onMouseDown:qt,onMouseMove:Vt,onMouseUp:wt,onMouseLeave:wt,onDoubleClick:Wt,onWheel:Ht,children:e.jsxs("g",{transform:`translate(${K.pan.x}, ${K.pan.y}) scale(${K.zoom})`,children:[Ut(),os(),as(),ls(),is(),rs(),cs()]})}),Ve.showMinimap&&e.jsx(ln,{document:U,activeFloorId:Me,viewport:K,onViewportChange:N=>g({type:"SET_VIEWPORT",viewport:N})})]})]}),ps=e.jsxs("div",{className:F.rightSidebar,children:[Ve.showLayerPanel&&e.jsx(Xn,{layers:Be.filter(N=>Qe.layerTypes.includes(N.type)),onVisibilityToggle:N=>{var L;return g({type:"SET_LAYER_VISIBILITY",layerType:N,visible:!((L=Be.find(q=>q.type===N))!=null&&L.visible)})},onLockToggle:N=>{var L;return g({type:"SET_LAYER_LOCKED",layerType:N,locked:!((L=Be.find(q=>q.type===N))!=null&&L.locked)})},onOpacityChange:(N,L)=>g({type:"SET_LAYER_OPACITY",layerType:N,opacity:L})}),Ve.showPropertiesPanel&&be.objectIds.length>0&&e.jsx(Jn,{selection:be,document:U,onPropertyChange:(N,L,q)=>{if(L==="position.x"||L==="position.y"){const W=We(U,N),V=W?bt(W):null;V&&typeof q=="number"&&Number.isFinite(q)&&g({type:"MOVE_OBJECTS",objectIds:[N],delta:L==="position.x"?{x:q-V.x,y:0}:{x:0,y:q-V.y}});return}g({type:"UPDATE_OBJECT",objectId:N,updates:{[L]:q}})}})]}),hs=e.jsxs("div",{className:F.statusBar,children:[e.jsxs("span",{className:F.modeIndicator,children:[e.jsx(w.NiceIcon,{name:Qe.icon,size:14})," ",Qe.label]}),e.jsxs("span",{className:F.toolIndicator,children:[((un=rt[fe])==null?void 0:un.icon)&&e.jsx(w.NiceIcon,{name:rt[fe].icon,size:14})," ",(mn=rt[fe])==null?void 0:mn.label]}),be.objectIds.length>0&&e.jsx("span",{className:F.selectionInfo,children:y("buildings.selected2","{objectIds} selected").replace("{objectIds}",String(be.objectIds.length))}),xe.active&&e.jsx("span",{className:F.drawingInfo,children:y("buildings.drawingPoints","Drawing: {points} points").replace("{points}",String(xe.points.length))}),me.active&&e.jsx("span",{className:F.connectingInfo,children:y("buildings.connectingClickTargetDeviceOr","Connecting: click target device or ESC to cancel")}),e.jsx("span",{className:F.gridInfo,children:y("buildings.gridSnap","Grid: {size}px · Snap: {snap}").replace("{size}",String(K.gridSize)).replace("{snap}",K.snapEnabled?y("buildings.on","ON"):y("buildings.off","OFF"))})]});return e.jsxs("div",{className:`nice-spatial-editor ${F.root} ${F[i]} ${v??""}`,style:{position:"relative",..._},tabIndex:0,onKeyDown:Nt,children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:e.jsx(w.NiceTutorialButton,{steps:w.resolveTutorial(h,au)})}),e.jsx(w.NiceAppShell,{flush:!0,className:F.shell,menubar:ds,sidebar:us,rightSidebar:ps,statusBar:hs,children:ms}),ve&&!Fe&&e.jsx(Oa,{result:ve,onConfirm:ae,onCancel:ue}),ve&&Fe&&e.jsx(di,{importResult:ve,existingDocument:U??void 0,onConfirm:_e,onCancel:Le}),ee&&U&&e.jsx(Ir,{document:U,connections:Pn(U),onHighlightPath:N=>{g(N?{type:"SET_SELECTION",selection:{objectIds:N.connectionIds,bounds:null,locked:!1}}:{type:"SET_SELECTION",selection:{objectIds:[],bounds:null,locked:!1}})},onClose:()=>ge(!1)}),Se&&U&&e.jsx(_l,{document:U,connections:Pn(U),vlans:su(U),visibleVlanIds:Ce,onVlanVisibilityChange:(N,L)=>{Ge(q=>{const W=new Set(q);return L?W.add(N):W.delete(N),W})},onHighlightVlan:N=>{He((N==null?void 0:N.id)??null),g(N?{type:"SET_SELECTION",selection:{objectIds:N.deviceIds,bounds:null,locked:!1}}:{type:"SET_SELECTION",selection:{objectIds:[],bounds:null,locked:!1}})},onClose:()=>Ee(!1)})]})},ru="_viewer_103dp_13",cu="_theme_light_103dp_37",lu="_theme_dark_103dp_59",du="_debugOverlay_103dp_85",uu="_topBar_103dp_137",mu="_searchContainer_103dp_159",pu="_searchInput_103dp_171",hu="_clearBtn_103dp_227",gu="_searchResults_103dp_261",fu="_searchResultItem_103dp_291",_u="_searchResultInfo_103dp_335",bu="_searchResultName_103dp_347",yu="_searchResultDesc_103dp_357",xu="_floorSelector_103dp_371",vu="_navBtn_103dp_421",ju="_active_103dp_459",wu="_layersBtn_103dp_475",Nu="_legendBtn_103dp_529",Iu="_content_103dp_583",ku="_navPanel_103dp_599",Su="_navPanelHeader_103dp_617",Cu="_routeInputs_103dp_671",Tu="_routeInput_103dp_671",Lu="_routeMarker_103dp_705",$u="_routeHint_103dp_745",zu="_routeInfo_103dp_761",Pu="_routeStat_103dp_779",Eu="_routeStatLabel_103dp_791",Ou="_routeStatValue_103dp_805",Mu="_clearRouteBtn_103dp_817",Au="_refPointsList_103dp_851",Du="_refPointItem_103dp_879",Bu="_refPointIcon_103dp_917",Ru="_layersPanel_103dp_929",Fu="_layersPanelHeader_103dp_947",Gu="_layersList_103dp_1001",qu="_layerItem_103dp_1015",Vu="_layerToggle_103dp_1039",Wu="_layerName_103dp_1075",Hu="_layerType_103dp_1087",Uu="_canvasWrapper_103dp_1101",Yu="_canvas_103dp_1101",Zu="_grid_103dp_1137",Xu="_gridLine_103dp_1145",Ku="_zonesLayer_103dp_1161",Ju="_zone_103dp_1161",Qu="_zoneSelected_103dp_1187",em="_zoneLabel_103dp_1197",tm="_objectsLayer_103dp_1213",nm="_object_103dp_1213",sm="_objectSelected_103dp_1237",om="_objectLabel_103dp_1245",am="_referencePoints_103dp_1261",im="_referencePoint_103dp_1261",rm="_refLabel_103dp_1283",cm="_routeLayer_103dp_1299",lm="_routePath_103dp_1305",dm="_routeDash_103dp_1",um="_routeMarkers_103dp_1331",mm="_currentLocation_103dp_1341",pm="_locationPulse_103dp_1347",hm="_pulse_103dp_1",gm="_zoomControls_103dp_1383",fm="_minimapHost_103dp_1461",_m="_legendPanel_103dp_1477",bm="_legendPanelHeader_103dp_1509",ym="_legendList_103dp_1565",xm="_legendItem_103dp_1581",vm="_legendColor_103dp_1605",jm="_legendIcon_103dp_1621",wm="_legendLabel_103dp_1635",Nm="_legendType_103dp_1647",Im="_objectInfo_103dp_1665",km="_objectInfoHeader_103dp_1693",Sm="_navigateBtn_103dp_1763",E={viewer:ru,theme_light:cu,theme_dark:lu,debugOverlay:du,topBar:uu,searchContainer:mu,searchInput:pu,clearBtn:hu,searchResults:gu,searchResultItem:fu,searchResultInfo:_u,searchResultName:bu,searchResultDesc:yu,floorSelector:xu,navBtn:vu,active:ju,layersBtn:wu,legendBtn:Nu,content:Iu,navPanel:ku,navPanelHeader:Su,routeInputs:Cu,routeInput:Tu,routeMarker:Lu,routeHint:$u,routeInfo:zu,routeStat:Pu,routeStatLabel:Eu,routeStatValue:Ou,clearRouteBtn:Mu,refPointsList:Au,refPointItem:Du,refPointIcon:Bu,layersPanel:Ru,layersPanelHeader:Fu,layersList:Gu,layerItem:qu,layerToggle:Vu,layerName:Wu,layerType:Hu,canvasWrapper:Uu,canvas:Yu,grid:Zu,gridLine:Xu,zonesLayer:Ku,zone:Ju,zoneSelected:Qu,zoneLabel:em,objectsLayer:tm,object:nm,objectSelected:sm,objectLabel:om,referencePoints:am,referencePoint:im,refLabel:rm,routeLayer:cm,routePath:lm,routeDash:dm,routeMarkers:um,currentLocation:mm,locationPulse:pm,pulse:hm,zoomControls:gm,minimapHost:fm,legendPanel:_m,legendPanelHeader:bm,legendList:ym,legendItem:xm,legendColor:vm,legendIcon:jm,legendLabel:wm,legendType:Nm,objectInfo:Im,objectInfoHeader:km,navigateBtn:Sm},Cm=()=>e.jsx(w.NiceIcon,{name:"search",size:16}),En=()=>e.jsx(w.NiceIcon,{name:"navigation",size:16}),Tm=()=>e.jsx(w.NiceIcon,{name:"map-pin",size:16}),Lm=()=>e.jsx(w.NiceIcon,{name:"building",size:16}),$m=()=>e.jsx(w.NiceIcon,{name:"git-branch",size:16}),zm=()=>e.jsx(w.NiceIcon,{name:"zoom-in",size:16}),Pm=()=>e.jsx(w.NiceIcon,{name:"zoom-out",size:16}),ht=()=>e.jsx(w.NiceIcon,{name:"close",size:16}),On=()=>e.jsx(w.NiceIcon,{name:"layers",size:16}),Mn=()=>e.jsx(w.NiceIcon,{name:"list",size:16}),Em=()=>e.jsx(w.NiceIcon,{name:"eye",size:16}),Om=()=>e.jsx(w.NiceIcon,{name:"eye-off",size:16}),Mm={entrance:"door",elevator:"elevator",stairs:"stairs",exit:"bell",poi:"map-pin",parking:"map-pin"};function tn(t){return t.icon??Mm[t.type]??"map-pin"}function Am(t,n){return Math.sqrt((n.x-t.x)**2+(n.y-t.y)**2)}function Dm(t){return t<1?"<1m":t<1e3?`${Math.round(t)}m`:`${(t/1e3).toFixed(1)}km`}function Bm(t){if(t<60)return"<1 min";const n=Math.round(t/60);if(n<60)return`${n} min`;const s=Math.floor(n/60),o=n%60;return`${s}h ${o}min`}const Rm=rn(""),Fm=({document:t=Rm,initialFloorId:n,showNavigation:s=!0,showMinimap:o=!0,showFloorSelector:i=!0,showSearch:a=!0,showLayersPanel:c=!0,showLegend:r=!0,enableRoutePlanning:l=!0,referencePoints:x=[],onObjectClick:m,onRouteCalculated:h,currentLocation:v,theme:_="light",className:p,virtualRendering:j,virtualRenderingThreshold:f=200,debugVirtualRendering:I=!1})=>{var Nt;const{t:b}=w.useNiceTranslation(),[$,y]=u.useState(n??((Nt=t.floors[0])==null?void 0:Nt.id)??""),[C,d]=u.useState({zoom:1,pan:{x:0,y:0}}),k=u.useMemo(()=>({zoom:C.zoom,pan:C.pan,rotation:0,showGrid:!1,gridSize:20,snapEnabled:!1,snapModes:[]}),[C]),[g,G]=u.useState(""),[T,R]=u.useState([]),[H,se]=u.useState(null),[ne,oe]=u.useState(null),[he,ce]=u.useState(null),[Ne,Ke]=u.useState(null),[De,ve]=u.useState(!1),[Pe,Fe]=u.useState(!1),[P,ee]=u.useState(!1),[ge,Se]=u.useState(new Map),[Ee,Ce]=u.useState({width:1e3,height:600}),Ge=u.useRef(null),qe=u.useRef(null),He=u.useRef(!1),Ae=u.useRef({x:0,y:0}),Oe=u.useMemo(()=>{const S=t.floors.find(z=>z.id===$);return S?S.layers.reduce((z,D)=>{var te;return z+(((te=D.objects)==null?void 0:te.length)??0)},0):0},[t.floors,$]),Ie=j??ta(Oe,f),$e=u.useMemo(()=>{if(!Ie)return null;const S=t.floors.find(D=>D.id===$);if(!S)return null;const z=[];for(const D of S.layers)if(!(D.type==="zones"||D.type==="grid"||D.type==="background"))for(const te of D.objects??[]){const ae=Qt(te)??{x:0,y:0},ue=Tn(te);z.push({id:te.id,position:ae,size:ue,data:{object:te,layerId:D.id}})}return Qo(z)},[t.floors,$,Ie]),fe=u.useMemo(()=>ea(C,Ee,100),[C,Ee]),U=u.useMemo(()=>!Ie||!$e?null:$e.query(fe),[Ie,$e,fe]),Me=u.useMemo(()=>!I||!Ie?null:na(Oe,(U==null?void 0:U.length)??Oe,C),[I,Ie,Oe,U,C]);u.useEffect(()=>{const S=qe.current;if(!S)return;const z=new ResizeObserver(D=>{for(const te of D)Ce({width:te.contentRect.width,height:te.contentRect.height})});return z.observe(S),()=>z.disconnect()},[]),u.useEffect(()=>{const S=t.floors.find(z=>z.id===$);S&&Se(z=>{const D=new Map;for(const te of S.layers)D.set(te.id,z.get(te.id)??!0);return D})},[$,t.floors]);const Be=u.useCallback(S=>{Se(z=>{const D=new Map(z);return D.set(S,!z.get(S)),D})},[]),be=u.useCallback(S=>ge.get(S)!==!1,[ge]),K=u.useMemo(()=>t.floors.find(S=>S.id===$)??t.floors[0],[t.floors,$]),xe=u.useMemo(()=>{if(!K)return[];const S=[],z=it(K.layers);if(z){const ae=new Map;for(const ue of z.objects){const _e=ue.metadata,Le=(_e==null?void 0:_e.zoneType)??ue.type??"zone";ae.has(Le)||ae.set(Le,At(ue)??"var(--nice-primary, #3b82f6)")}for(const[ue,_e]of ae)S.push({id:`zone-${ue}`,label:ue.charAt(0).toUpperCase()+ue.slice(1).replace(/-/g," "),color:_e,type:"zone"})}const D=new Map;for(const ae of K.layers)if(!(ae.type==="zones"||ae.type==="grid"||ae.type==="background"))for(const ue of ae.objects){const _e=ue.type??"object",Le=D.get(_e);Le?Le.count++:D.set(_e,{count:1,color:"var(--nice-text-secondary, #64748b)"})}for(const[ae,ue]of D)S.push({id:`obj-${ae}`,label:`${ae.charAt(0).toUpperCase()+ae.slice(1).replace(/-/g," ")} (${ue.count})`,color:ue.color,type:"object"});const te=new Map;for(const ae of x.filter(ue=>ue.floorId===$))te.has(ae.type)||te.set(ae.type,tn(ae));for(const[ae,ue]of te)S.push({id:`ref-${ae}`,label:ae.charAt(0).toUpperCase()+ae.slice(1),color:"var(--nice-primary, #3b82f6)",icon:ue,type:"reference"});return S},[K,x,$]),me=u.useCallback((S,z)=>{var te;const D=(te=Ge.current)==null?void 0:te.getBoundingClientRect();return D?{x:(S-D.left-C.pan.x)/C.zoom,y:(z-D.top-C.pan.y)/C.zoom}:{x:0,y:0}},[C]);u.useEffect(()=>{if(!g.trim()){R([]);return}const S=g.toLowerCase(),z=[];for(const D of t.floors)for(const te of D.layers)for(const ae of te.objects){const ue=(ae.name??ae.id).toLowerCase(),_e=(ae.description??"").toLowerCase();(ue.includes(S)||_e.includes(S))&&z.push(ae)}R(z.slice(0,10))},[g,t.floors]);const Je=u.useCallback((S,z)=>{const D=Am(S,z);return{id:`route-${Date.now()}`,startPoint:S,endPoint:z,path:[S,z],floorTransitions:[],totalDistance:D,estimatedTime:D/1.4,instructions:[{type:"straight",distance:D,direction:"forward"},{type:"arrive"}]}},[]);u.useEffect(()=>{if(ne&&he){const S=Je(ne,he);Ke(S),h==null||h(S)}else Ke(null),h==null||h(null)},[ne,he,Je,h]);const Ve=u.useCallback(S=>{(S.button===1||S.button===0&&S.altKey)&&(He.current=!0,Ae.current={x:S.clientX,y:S.clientY},S.preventDefault())},[]),yt=u.useCallback(S=>{if(He.current){const z=S.clientX-Ae.current.x,D=S.clientY-Ae.current.y;Ae.current={x:S.clientX,y:S.clientY},d(te=>({...te,pan:{x:te.pan.x+z,y:te.pan.y+D}}))}},[]),Ue=u.useCallback(()=>{He.current=!1},[]),Qe=u.useCallback(S=>{var ue;S.preventDefault();const z=S.deltaY>0?.9:1.1,D=(ue=Ge.current)==null?void 0:ue.getBoundingClientRect();if(!D)return;const te=S.clientX-D.left,ae=S.clientY-D.top;d(_e=>{const Le=Math.min(Math.max(_e.zoom*z,.1),10),Te=Le/_e.zoom;return{zoom:Le,pan:{x:te-(te-_e.pan.x)*Te,y:ae-(ae-_e.pan.y)*Te}}})},[]),xt=u.useCallback(S=>{if(l&&S.ctrlKey){const z=me(S.clientX,S.clientY);ne?he?(oe(z),ce(null)):ce(z):oe(z)}},[l,ne,he,me]),vt=u.useCallback(()=>{d(S=>({...S,zoom:Math.min(S.zoom*1.25,10)}))},[]),jt=u.useCallback(()=>{d(S=>({...S,zoom:Math.max(S.zoom/1.25,.1)}))},[]),pe=u.useCallback(()=>{d({zoom:1,pan:{x:0,y:0}})},[]),Re=u.useCallback(S=>{se(S);for(const D of t.floors)for(const te of D.layers)if(te.objects.find(ae=>ae.id===S.id)){y(D.id);break}const z=Qt(S)??{x:0,y:0};d(D=>({...D,pan:{x:-(z.x*D.zoom)+400,y:-(z.y*D.zoom)+300}})),G(""),R([]),m==null||m(S)},[t.floors,m]),Ye=u.useCallback(()=>{oe(null),ce(null),Ke(null)},[]),lt=u.useCallback(()=>{const z=[];for(let D=-2e3;D<=2e3;D+=50)z.push(e.jsx("line",{x1:D,y1:-2e3,x2:D,y2:2e3,className:E.gridLine},`v-${D}`));for(let D=-2e3;D<=2e3;D+=50)z.push(e.jsx("line",{x1:-2e3,y1:D,x2:2e3,y2:D,className:E.gridLine},`h-${D}`));return e.jsx("g",{className:E.grid,children:z})},[]),qt=u.useCallback(()=>{if(!K)return null;const S=it(K.layers);return!S||!be(S.id)?null:e.jsx("g",{className:E.zonesLayer,children:S.objects.map(z=>{const D=Gt(z);if(!D)return null;const te={points:D,fill:At(z)},ae=`M${te.points.map(_e=>`${_e.x},${_e.y}`).join(" L")} Z`,ue=(H==null?void 0:H.id)===z.id;return e.jsxs("g",{className:`${E.zone} ${ue?E.zoneSelected:""}`,onClick:()=>{se(z),m==null||m(z)},children:[e.jsx("path",{d:ae,fill:te.fill??"var(--nice-primary, #3b82f6)",fillOpacity:.2,stroke:te.fill??"var(--nice-primary, #3b82f6)",strokeWidth:ue?2:1}),z.name&&e.jsx("text",{x:te.points[0].x+10,y:te.points[0].y+20,className:E.zoneLabel,children:z.name})]},z.id)})})},[K,H,m,be]),Vt=u.useCallback(()=>{if(!K)return null;const S=z=>{const D=(H==null?void 0:H.id)===z.id,te=`${E.object} ${D?E.objectSelected:""}`,ae=Ut=>{Ut.stopPropagation(),se(z),m==null||m(z)},ue=cn(z),_e=ue??Ni(z);if(_e)return e.jsx("line",{className:te,x1:_e.start.x,y1:_e.start.y,x2:_e.end.x,y2:_e.end.y,stroke:D?"var(--nice-primary, #3b82f6)":ue?"var(--nice-text-primary, #334155)":"var(--nice-text-secondary, #64748b)",strokeWidth:ue?6:2,strokeLinecap:"round",onClick:ae},z.id);const Le=Qt(z)??{x:0,y:0},Te=Tn(z);return e.jsxs("g",{className:te,transform:`translate(${Le.x}, ${Le.y})`,onClick:ae,children:[e.jsx("rect",{x:-Te.width/2,y:-Te.height/2,width:Te.width,height:Te.height,rx:4,fill:D?"var(--nice-primary, #3b82f6)":"var(--nice-text-secondary, #64748b)",fillOpacity:.8,stroke:D?"var(--nice-primary-dark, #1d4ed8)":"transparent",strokeWidth:2}),z.name&&e.jsx("text",{y:Te.height/2+14,textAnchor:"middle",className:E.objectLabel,children:z.name})]},z.id)};return Ie&&U?e.jsx("g",{className:E.objectsLayer,children:U.map(z=>{const{object:D,layerId:te}=z.data;return be(te)?S(D):null})}):e.jsx("g",{className:E.objectsLayer,children:K.layers.map(z=>z.type==="zones"||z.type==="grid"||z.type==="background"||!be(z.id)?null:z.objects.map(S))})},[K,H,m,be,Ie,U]),wt=u.useCallback(()=>{const S=x.filter(z=>z.floorId===$);return e.jsx("g",{className:E.referencePoints,children:S.map(z=>e.jsxs("g",{className:E.referencePoint,transform:`translate(${z.position.x}, ${z.position.y})`,onClick:()=>{l&&(ne?ce(z.position):oe(z.position))},children:[e.jsx("circle",{r:16,fill:"white",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:2}),e.jsx("g",{transform:"translate(-8, -8)",style:{color:"var(--nice-primary, #3b82f6)"},"aria-hidden":"true",children:e.jsx(w.NiceIcon,{name:tn(z),size:16})}),e.jsx("text",{y:30,textAnchor:"middle",className:E.refLabel,children:z.name})]},z.id))})},[x,$,l,ne]),et=u.useCallback(()=>{if(!Ne)return null;const S=`M${Ne.path.map(z=>`${z.x},${z.y}`).join(" L")}`;return e.jsxs("g",{className:E.routeLayer,children:[e.jsx("path",{d:S,fill:"none",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:4,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"12,6",className:E.routePath}),e.jsx("circle",{cx:Ne.startPoint.x,cy:Ne.startPoint.y,r:8,fill:"var(--nice-success, #10b981)",stroke:"white",strokeWidth:2}),e.jsx("circle",{cx:Ne.endPoint.x,cy:Ne.endPoint.y,r:8,fill:"var(--nice-danger, #ef4444)",stroke:"white",strokeWidth:2})]})},[Ne]),Wt=u.useCallback(()=>v?e.jsxs("g",{className:E.currentLocation,children:[e.jsx("circle",{cx:v.x,cy:v.y,r:12,fill:"var(--nice-primary, #3b82f6)",fillOpacity:.3,className:E.locationPulse}),e.jsx("circle",{cx:v.x,cy:v.y,r:6,fill:"var(--nice-primary, #3b82f6)",stroke:"white",strokeWidth:2})]}):null,[v]),Ht=u.useCallback(()=>e.jsx("g",{className:E.routeMarkers,children:ne&&!Ne&&e.jsx("circle",{cx:ne.x,cy:ne.y,r:8,fill:"var(--nice-success, #10b981)",stroke:"white",strokeWidth:2})}),[ne,Ne]);return e.jsxs("div",{ref:qe,className:`${E.viewer} ${E[`theme_${_}`]} ${p??""}`,children:[I&&Me&&e.jsxs("div",{className:E.debugOverlay,children:[e.jsx("div",{children:b("buildings.virtualOn","Virtual: ON")}),e.jsx("div",{children:b("buildings.total","Total: {total}").replace("{total}",String(Me.total))}),e.jsx("div",{children:b("buildings.visible","Visible: {visible}").replace("{visible}",String(Me.visible))}),e.jsx("div",{children:b("buildings.culled","Culled: {culled} ({cullPercentage}%)").replace("{culled}",String(Me.culled)).replace("{cullPercentage}",String(Me.cullPercentage))}),e.jsx("div",{children:b("buildings.zoomX","Zoom: {zoom}x").replace("{zoom}",String(Me.zoom.toFixed(2)))})]}),e.jsxs("div",{className:E.topBar,children:[a&&e.jsxs("div",{className:E.searchContainer,children:[e.jsxs("div",{className:E.searchInput,children:[e.jsx(Cm,{}),e.jsx("input",{type:"text",placeholder:b("buildings.spatial.searchPlaces","Search places…"),value:g,onChange:S=>G(S.target.value)}),g&&e.jsx("button",{className:E.clearBtn,onClick:()=>G(""),children:e.jsx(ht,{})})]}),T.length>0&&e.jsx("div",{className:E.searchResults,children:T.map(S=>e.jsxs("button",{className:E.searchResultItem,onClick:()=>Re(S),children:[e.jsx(Tm,{}),e.jsxs("div",{className:E.searchResultInfo,children:[e.jsx("span",{className:E.searchResultName,children:S.name??S.id}),S.description&&e.jsx("span",{className:E.searchResultDesc,children:S.description})]})]},S.id))})]}),i&&t.floors.length>1&&e.jsxs("div",{className:E.floorSelector,children:[e.jsx(Lm,{}),e.jsx("select",{value:$,onChange:S=>y(S.target.value),children:t.floors.map(S=>e.jsx("option",{value:S.id,children:S.name??b("buildings.floorLevel","Floor {level}").replace("{level}",String(S.level))},S.id))})]}),s&&e.jsxs("button",{className:`${E.navBtn} ${De?E.active:""}`,onClick:()=>ve(!De),children:[e.jsx(En,{}),e.jsx("span",{children:b("buildings.navigation","Navigation")})]}),c&&e.jsxs("button",{className:`${E.layersBtn} ${Pe?E.active:""}`,onClick:()=>Fe(!Pe),children:[e.jsx(On,{}),e.jsx("span",{children:b("buildings.layers","Layers")})]}),r&&e.jsxs("button",{className:`${E.legendBtn} ${P?E.active:""}`,onClick:()=>ee(!P),children:[e.jsx(Mn,{}),e.jsx("span",{children:b("buildings.legend","Legend")})]})]}),e.jsxs("div",{className:E.content,children:[De&&e.jsxs("div",{className:E.navPanel,children:[e.jsxs("div",{className:E.navPanelHeader,children:[e.jsx($m,{}),e.jsx("span",{children:b("buildings.routePlanning","Route planning")}),e.jsx("button",{onClick:()=>ve(!1),children:e.jsx(ht,{})})]}),e.jsxs("div",{className:E.routeInputs,children:[e.jsxs("div",{className:E.routeInput,children:[e.jsx("div",{className:E.routeMarker,style:{background:"var(--nice-success, #10b981)"}}),e.jsx("input",{type:"text",placeholder:b("buildings.startPoint","Start point"),value:ne?`${ne.x.toFixed(0)}, ${ne.y.toFixed(0)}`:"",readOnly:!0})]}),e.jsxs("div",{className:E.routeInput,children:[e.jsx("div",{className:E.routeMarker,style:{background:"var(--nice-danger, #ef4444)"}}),e.jsx("input",{type:"text",placeholder:b("buildings.destination","Destination"),value:he?`${he.x.toFixed(0)}, ${he.y.toFixed(0)}`:"",readOnly:!0})]})]}),e.jsx("p",{className:E.routeHint,children:b("buildings.spatial.routeHint","Ctrl-click the map to pick points")}),Ne&&e.jsxs("div",{className:E.routeInfo,children:[e.jsxs("div",{className:E.routeStat,children:[e.jsx("span",{className:E.routeStatLabel,children:b("buildings.distance","Distance")}),e.jsx("span",{className:E.routeStatValue,children:Dm(Ne.totalDistance)})]}),e.jsxs("div",{className:E.routeStat,children:[e.jsx("span",{className:E.routeStatLabel,children:b("buildings.spatial.time","Time")}),e.jsx("span",{className:E.routeStatValue,children:Bm(Ne.estimatedTime)})]})]}),(ne||he)&&e.jsx("button",{className:E.clearRouteBtn,onClick:Ye,children:b("buildings.spatial.clearRoute","Clear the route")}),x.length>0&&e.jsxs("div",{className:E.refPointsList,children:[e.jsx("h4",{children:b("buildings.landmarks","Landmarks")}),x.filter(S=>S.floorId===$).map(S=>e.jsxs("button",{className:E.refPointItem,onClick:()=>{ne?ce(S.position):oe(S.position)},children:[e.jsx("span",{className:E.refPointIcon,children:e.jsx(w.NiceIcon,{name:tn(S),size:16})}),e.jsx("span",{children:S.name})]},S.id))]})]}),Pe&&K&&e.jsxs("div",{className:E.layersPanel,children:[e.jsxs("div",{className:E.layersPanelHeader,children:[e.jsx(On,{}),e.jsx("span",{children:b("buildings.layers","Layers")}),e.jsx("button",{onClick:()=>Fe(!1),children:e.jsx(ht,{})})]}),e.jsx("div",{className:E.layersList,children:K.layers.map(S=>{const z=be(S.id);return e.jsxs("div",{className:E.layerItem,children:[e.jsx("button",{className:E.layerToggle,onClick:()=>Be(S.id),title:z?b("buildings.spatial.hideLayer","Hide layer"):b("buildings.spatial.showLayer","Show layer"),children:z?e.jsx(Em,{}):e.jsx(Om,{})}),e.jsx("span",{className:E.layerName,children:S.name??S.id}),e.jsxs("span",{className:E.layerType,children:["(",S.type,")"]})]},S.id)})})]}),e.jsxs("div",{className:E.canvasWrapper,children:[e.jsx("svg",{ref:Ge,className:E.canvas,onMouseDown:Ve,onMouseMove:yt,onMouseUp:Ue,onMouseLeave:Ue,onWheel:Qe,onClick:xt,children:e.jsxs("g",{transform:`translate(${C.pan.x}, ${C.pan.y}) scale(${C.zoom})`,children:[lt(),qt(),Vt(),wt(),Ht(),et(),Wt()]})}),e.jsxs("div",{className:E.zoomControls,children:[e.jsx("button",{onClick:vt,title:b("buildings.spatial.zoomIn","Zoom in"),children:e.jsx(zm,{})}),e.jsx("button",{onClick:jt,title:b("buildings.spatial.zoomOut","Zoom out"),children:e.jsx(Pm,{})}),e.jsx("button",{onClick:pe,title:b("buildings.spatial.resetView","Reset the view"),children:e.jsx(w.NiceIcon,{name:"refresh",size:16})})]}),o&&e.jsx(ln,{className:E.minimapHost,document:t,activeFloorId:$,viewport:k,onViewportChange:S=>d(z=>({zoom:S.zoom??z.zoom,pan:S.pan??z.pan}))}),P&&xe.length>0&&e.jsxs("div",{className:E.legendPanel,children:[e.jsxs("div",{className:E.legendPanelHeader,children:[e.jsx(Mn,{}),e.jsx("span",{children:b("buildings.legend","Legend")}),e.jsx("button",{onClick:()=>ee(!1),children:e.jsx(ht,{})})]}),e.jsx("div",{className:E.legendList,children:xe.map(S=>e.jsxs("div",{className:E.legendItem,children:[S.icon?e.jsx("span",{className:E.legendIcon,children:e.jsx(w.NiceIcon,{name:S.icon,size:16})}):e.jsx("span",{className:E.legendColor,style:{background:S.color}}),e.jsx("span",{className:E.legendLabel,children:S.label}),e.jsx("span",{className:E.legendType,children:S.type==="zone"?b("buildings.zone","zone"):S.type==="object"?b("buildings.object","object"):b("buildings.referencePoint","reference point")})]},S.id))})]})]})]}),H&&e.jsxs("div",{className:E.objectInfo,children:[e.jsxs("div",{className:E.objectInfoHeader,children:[e.jsx("h4",{children:H.name??H.id}),e.jsx("button",{onClick:()=>se(null),children:e.jsx(ht,{})})]}),H.description&&e.jsx("p",{children:H.description}),l&&e.jsxs("button",{className:E.navigateBtn,onClick:()=>{const S=H.position??{x:0,y:0};ne?ce(S):oe(S)},children:[e.jsx(En,{}),ne?b("buildings.setAsDestination","Set as destination"):b("buildings.setAsStart","Set as start")]})]})]})};function Gm(t={}){var ne;const{initialDocument:n,defaultMode:s="floor-plan",gridSize:o=20,snapEnabled:i=!0,onChange:a}=t,c={mode:s,tool:"select",document:n??null,activeFloorId:((ne=n==null?void 0:n.floors[0])==null?void 0:ne.id)??null,layers:[],selection:{objectIds:[],bounds:null,locked:!1},viewport:{zoom:1,pan:{x:0,y:0},rotation:0,showGrid:!0,gridSize:o,snapEnabled:i,snapModes:["grid","endpoint","midpoint"]},drawing:{active:!1,points:[],preview:null},history:{past:[],future:[]},guides:[],dragging:null,connecting:{active:!1,sourceId:null,sourcePosition:null,previewPosition:null},clipboard:[],ui:{showObjectLibrary:!0,showLayerPanel:!0,showPropertiesPanel:!0,showMinimap:!0}},[r,l]=u.useReducer((oe,he)=>({...oe,...he}),c),x=u.useCallback(oe=>{l({mode:oe})},[]),m=u.useCallback(oe=>{l({tool:oe})},[]),h=u.useCallback((oe="Untitled")=>{var ce;const he=rn(oe,"floor-plan");l({document:he,activeFloorId:((ce=he.floors[0])==null?void 0:ce.id)??null}),a==null||a(he)},[a]),v=u.useCallback(oe=>{var he;l({document:oe,activeFloorId:((he=oe.floors[0])==null?void 0:he.id)??null}),a==null||a(oe)},[a]),_=u.useCallback(oe=>{l({viewport:{...r.viewport,zoom:Math.max(.1,Math.min(10,r.viewport.zoom*(1+oe*.1)))}})},[r.viewport]),p=u.useCallback(oe=>{l({viewport:{...r.viewport,pan:{x:r.viewport.pan.x+oe.x,y:r.viewport.pan.y+oe.y}}})},[r.viewport]),j=u.useCallback(()=>{l({viewport:{...r.viewport,zoom:1,pan:{x:0,y:0}}})},[r.viewport]),f=u.useCallback(()=>{l({viewport:{...r.viewport,showGrid:!r.viewport.showGrid}})},[r.viewport]),I=u.useCallback(()=>{l({viewport:{...r.viewport,snapEnabled:!r.viewport.snapEnabled}})},[r.viewport]),b=u.useCallback(oe=>{l({viewport:{...r.viewport,gridSize:oe}})},[r.viewport]),$=u.useCallback((oe,he)=>{l({layers:r.layers.map(ce=>ce.type===oe?{...ce,visible:he}:ce)})},[r.layers]),y=u.useCallback((oe,he)=>{l({layers:r.layers.map(ce=>ce.type===oe?{...ce,locked:he}:ce)})},[r.layers]),C=u.useCallback(oe=>{l({selection:{objectIds:oe,bounds:null,locked:!1}})},[]),d=u.useCallback(()=>{l({selection:{objectIds:[],bounds:null,locked:!1}})},[]),k=u.useCallback(()=>{},[]),g=u.useCallback(()=>{},[]),G=r.history.past.length>0,T=r.history.future.length>0,R=u.useCallback(()=>{},[]),H=u.useCallback(oe=>{},[]),se=u.useCallback(()=>{},[]);return{state:r,setMode:x,setTool:m,newDocument:h,loadDocument:v,zoom:_,pan:p,resetView:j,toggleGrid:f,toggleSnap:I,setGridSize:b,setLayerVisible:$,setLayerLocked:y,select:C,clearSelection:d,undo:k,redo:g,canUndo:G,canRedo:T,copy:R,paste:H,cut:se}}function qm(t={}){const{gridSize:n=20,enabled:s=!0,snapModes:o=["grid","endpoint","midpoint"],objects:i=[],threshold:a=10}=t,c=u.useMemo(()=>({...fo,cellSize:n,snapModes:o,snapThreshold:a}),[n,o,a]),r=u.useMemo(()=>i.map((_,p)=>({id:`obj-${p}`,bounds:_})),[i]),l=u.useCallback(_=>s?an(_,c):_,[s,c]),x=u.useCallback(_=>s?_o(_,n):_,[s,n]),m=u.useCallback(_=>{if(!s||r.length===0)return[];const p={x:_.x,y:_.y,width:0,height:0};return Hn(p,r,a)},[s,r,a]),h=u.useCallback(_=>{if(!s)return{point:_,snapped:!1,guides:[]};const p=vo(_,r,c);return{point:p.position,snapped:p.snapped,guides:p.guides??[]}},[s,c,r]),v=u.useCallback((_,p)=>{const j=[];for(let f=0;f<=_;f+=n)j.push({x1:f,y1:0,x2:f,y2:p});for(let f=0;f<=p;f+=n)j.push({x1:0,y1:f,x2:_,y2:f});return j},[n]);return{snap:l,snap3D:x,getGuides:m,performAdvancedSnap:h,generateGridLines:v}}function Vm(t={}){const{unitSystem:n="metric",lengthUnit:s="m",areaUnit:o="m2",angleUnit:i="deg",scale:a=100}=t,[c,r]=u.useState(null),[l,x]=u.useState([]),m=u.useCallback(d=>d/a,[a]),h=u.useCallback(d=>{r(d),x([])},[]),v=u.useCallback((d,k=!1)=>{x(g=>[...g,{position:d,snapped:k}])},[]),_=u.useCallback(()=>{r(null),x([])},[]),p=u.useCallback(()=>{if(!c||l.length<2)return null;const d=l.map(k=>k.position);if(c==="distance"&&l.length===2){const k=ft(d[0],d[1]),g=m(k);return{type:"distance",value:g,formatted:Tt(g,n).formatted,points:d}}if(c==="angle"&&l.length===3){const k=Zt(d[0],d[1],d[2]);return{type:"angle",value:k,formatted:Kt(k,i).formatted,points:d}}if(c==="area"&&l.length>=3){const g=Xt(d)/(a*a);return{type:"area",value:g,formatted:Jt(g,n).formatted,points:d}}return null},[c,l,a,n,i,m]),j=l.length>=2&&c==="distance"?Tt(m(ft(l[0].position,l[l.length-1].position)),n).formatted:null,f=l.length>=3&&c==="angle"?Kt(Zt(l[0].position,l[1].position,l[2].position),i).formatted:null,I=l.length>=3&&c==="area"?Jt(Xt(l.map(d=>d.position))/(a*a),n).formatted:null,b=u.useCallback((d,k)=>{const g=ft(d,k),G=m(g);return{value:G,formatted:Tt(G,n).formatted}},[m,n]),$=u.useCallback((d,k,g)=>{const G=Zt(d,k,g);return{value:G,formatted:Kt(G,i).formatted}},[i]),y=u.useCallback(d=>{const g=Xt(d)/(a*a);return{value:g,formatted:Jt(g,n).formatted}},[a,n]),C=u.useCallback(d=>{const k=ko(d),g=m(k);return{value:g,formatted:Tt(g,n).formatted}},[m,n]);return{startMeasurement:h,addPoint:v,clearMeasurement:_,finishMeasurement:p,measurementType:c,points:l,liveDistance:j,liveAngle:f,liveArea:I,getDistance:b,getAngle:$,getArea:y,getLength:C}}const Wm="_root_15owo_3",Hm="_dark_15owo_25",Um="_header_15owo_37",Ym="_buildingInfo_15owo_51",Zm="_buildingName_15owo_59",Xm="_buildingAddress_15owo_81",Km="_modeSelector_15owo_95",Jm="_modeBtn_15owo_107",Qm="_modeBtnActive_15owo_145",ep="_weather_15owo_159",tp="_weatherTemp_15owo_173",np="_weatherDesc_15owo_193",sp="_statsRow_15owo_205",op="_statsCard_15owo_217",ap="_statsHeader_15owo_247",ip="_statsIcon_15owo_261",rp="_statsLabel_15owo_269",cp="_statsValue_15owo_283",lp="_statsSub_15owo_305",dp="_zoneGrid_15owo_319",up="_zoneCard_15owo_333",mp="_zoneOccupied_15owo_381",pp="_zoneCardHeader_15owo_389",hp="_zoneCardIcon_15owo_403",gp="_zoneCardTitles_15owo_411",fp="_zoneCardName_15owo_421",_p="_zoneCardArea_15owo_449",bp="_occupancyBadge_15owo_459",yp="_occupancyBadgeOn_15owo_477",xp="_sensorRow_15owo_489",vp="_sensorChip_15owo_503",jp="_sensorWarn_15owo_521",wp="_deviceList_15owo_535",Np="_deviceChip_15owo_547",Ip="_deviceChipOn_15owo_585",kp="_deviceChipName_15owo_597",Sp="_deviceChipVal_15owo_611",Cp="_moreBtn_15owo_621",Tp="_scenesBar_15owo_651",Lp="_sceneBarLabel_15owo_681",$p="_sceneList_15owo_699",zp="_sceneBtn_15owo_711",Pp="_sceneBtnActive_15owo_741",Q={root:Wm,dark:Hm,header:Um,buildingInfo:Ym,buildingName:Zm,buildingAddress:Xm,modeSelector:Km,modeBtn:Jm,modeBtnActive:Qm,weather:ep,weatherTemp:tp,weatherDesc:np,statsRow:sp,statsCard:op,statsHeader:ap,statsIcon:ip,statsLabel:rp,statsValue:cp,statsSub:lp,zoneGrid:dp,zoneCard:up,zoneOccupied:mp,zoneCardHeader:pp,zoneCardIcon:hp,zoneCardTitles:gp,zoneCardName:fp,zoneCardArea:_p,occupancyBadge:bp,occupancyBadgeOn:yp,sensorRow:xp,sensorChip:vp,sensorWarn:jp,deviceList:wp,deviceChip:Np,deviceChipOn:Ip,deviceChipName:kp,deviceChipVal:Sp,moreBtn:Cp,scenesBar:Tp,sceneBarLabel:Lp,sceneList:$p,sceneBtn:zp,sceneBtnActive:Pp},Ep={living_room:"sofa",bedroom:"bed",master_bedroom:"bed",kids_room:"star",bathroom:"droplet",kitchen:"utensils",dining_room:"utensils",hallway:"door",office:"briefcase",garage:"box",gym:"medal",cinema:"video",balcony:"home",garden:"home",open_office:"briefcase",private_office:"monitor",meeting_room:"clipboard",boardroom:"users",reception:"building",server_room:"server",lobby:"building",corridor:"arrow-right",stairwell:"stairs",parking:"box",break_room:"utensils",it_room:"monitor",cafeteria:"utensils"};function Op(t){return Ep[t]??"home"}function Mp(t,n){if(!n.state)return null;const s=n.state;return typeof s.brightness=="number"?`${s.brightness}%`:typeof s.on=="boolean"?s.on?t("buildings.onShort","On"):t("buildings.offShort","Off"):typeof s.temperature=="number"?`${s.temperature.toFixed(1)}°`:typeof s.locked=="boolean"?e.jsx(w.NiceIcon,{name:"lock",size:14}):null}const es=({zone:t,devices:n=[],expanded:s=!1,onExpand:o,onDeviceControl:i,onClick:a,theme:c="light",className:r,style:l})=>{const{t:x}=w.useNiceTranslation(),m=t.occupancy!=null&&t.occupancy>0,h=s?n:n.slice(0,4);return e.jsxs("div",{role:a?"button":void 0,tabIndex:a?0:void 0,onKeyDown:a?w.clickOnActivationKey:void 0,className:`${Q.zoneCard} ${c==="dark"?Q.dark:""} ${m?Q.zoneOccupied:""} ${r??""}`,style:l,onClick:a,children:[e.jsxs("div",{className:Q.zoneCardHeader,children:[e.jsx("span",{className:Q.zoneCardIcon,children:e.jsx(w.NiceIcon,{name:Op(t.type),size:18})}),e.jsxs("div",{className:Q.zoneCardTitles,children:[e.jsx("span",{className:Q.zoneCardName,children:t.name}),t.area!=null&&e.jsxs("span",{className:Q.zoneCardArea,children:[t.area," m²"]})]}),t.occupancy!=null&&e.jsxs("span",{className:`${Q.occupancyBadge} ${m?Q.occupancyBadgeOn:""}`,children:[e.jsx(w.NiceIcon,{name:"users",size:14})," ",t.occupancy]})]}),(t.temperature!=null||t.humidity!=null||t.co2!=null)&&e.jsxs("div",{className:Q.sensorRow,children:[t.temperature!=null&&e.jsxs("span",{className:Q.sensorChip,children:[e.jsx(w.NiceIcon,{name:"thermometer",size:14})," ",t.temperature.toFixed(1),"°C"]}),t.humidity!=null&&e.jsxs("span",{className:Q.sensorChip,children:[e.jsx(w.NiceIcon,{name:"droplet",size:14})," ",t.humidity,"%"]}),t.co2!=null&&e.jsxs("span",{className:`${Q.sensorChip} ${t.co2>1e3?Q.sensorWarn:""}`,children:["CO₂ ",t.co2]})]}),h.length>0&&e.jsxs("div",{className:Q.deviceList,children:[h.map(v=>{const _=v.state,p=(_==null?void 0:_.on)===!0||(_==null?void 0:_.locked)===!1;return e.jsxs("button",{className:`${Q.deviceChip} ${p?Q.deviceChipOn:""}`,onClick:j=>{j.stopPropagation(),i==null||i(v.id,{on:!p})},title:v.name,children:[e.jsx("span",{children:e.jsx(w.NiceIcon,{name:Vn(v.type),size:14})}),e.jsx("span",{className:Q.deviceChipName,children:v.name}),e.jsx("span",{className:Q.deviceChipVal,children:Mp(x,v)})]},v.id)}),n.length>4&&e.jsx("button",{className:Q.moreBtn,"aria-label":s?x("buildings.showFewer","Show fewer devices"):x("buildings.showAll","Show all devices"),onClick:v=>{v.stopPropagation(),o==null||o()},children:s?e.jsx(w.NiceIcon,{name:"minus",size:12}):`+${n.length-4}`})]})]})},nn={home:"Home",away:"Away",night:"Night",vacation:"Vacation",guest:"Guest",party:"Party",occupied:"Occupied",closed:"Closed",weekend:"Weekend",event:"Event",emergency:"Emergency",maintenance:"Maintenance"},An={home:"home",away:"external-link",night:"eye-off",vacation:"rocket",guest:"user",party:"gift",occupied:"building",closed:"lock",weekend:"calendar",event:"calendar",emergency:"bell",maintenance:"settings"},Ap=({temperature:t,description:n})=>t!=null?e.jsxs("div",{className:Q.weather,children:[e.jsxs("span",{className:Q.weatherTemp,children:[t,"°C"]}),n&&e.jsx("span",{className:Q.weatherDesc,children:n})]}):null,Et=({label:t,value:n,sub:s,icon:o,accent:i})=>e.jsxs("div",{className:Q.statsCard,style:i?{borderTopColor:i}:void 0,children:[e.jsxs("div",{className:Q.statsHeader,children:[o&&e.jsx("span",{className:Q.statsIcon,children:e.jsx(w.NiceIcon,{name:o,size:16})}),e.jsx("span",{className:Q.statsLabel,children:t})]}),e.jsx("div",{className:Q.statsValue,children:n}),s&&e.jsx("div",{className:Q.statsSub,children:s})]}),Dp=({building:t,state:n,onModeChange:s,onDeviceControl:o,onSceneActivate:i,onZoneClick:a,className:c,style:r,theme:l="light",weather:x})=>{var y,C,d;const{t:m}=w.useNiceTranslation(),[h,v]=u.useState(null);t.floors[0];const _=t.floors.flatMap(k=>k.zones??[]).filter(k=>k.type!=="hallway"&&k.type!=="corridor"),p=((y=n==null?void 0:n.activeAlerts)==null?void 0:y.length)??0,j=(C=n==null?void 0:n.energy)==null?void 0:C.currentPowerW,f=(d=n==null?void 0:n.energy)==null?void 0:d.todayKwh,I=n!=null&&n.occupancy?Object.values(n.occupancy).reduce((k,g)=>k+((g==null?void 0:g.occupancy)??0),0):null;t.floors.flatMap(k=>k.zones??[]).flatMap(k=>k.deviceIds??[]).slice(0,8);const b=t.type==="office"||t.type==="retail"?["occupied","closed","weekend","event","emergency","maintenance"]:["home","away","night","vacation","guest","emergency"],$=(n==null?void 0:n.mode)??"home";return e.jsxs("div",{className:`${Q.root} ${l==="dark"?Q.dark:""} ${c??""}`,style:r,children:[e.jsxs("div",{className:Q.header,children:[e.jsxs("div",{className:Q.buildingInfo,children:[e.jsx("h2",{className:Q.buildingName,children:t.name}),t.address&&e.jsx("p",{className:Q.buildingAddress,children:t.address})]}),e.jsx("div",{className:Q.modeSelector,children:b.map(k=>e.jsxs("button",{title:nn[k],className:`${Q.modeBtn} ${$===k?Q.modeBtnActive:""}`,onClick:()=>s==null?void 0:s(k),children:[e.jsx(w.NiceIcon,{name:An[k],size:16}),e.jsx("span",{children:nn[k]})]},k))}),e.jsx(Ap,{temperature:x==null?void 0:x.temperature,description:x==null?void 0:x.description})]}),e.jsxs("div",{className:Q.statsRow,children:[j!=null&&e.jsx(Et,{icon:"zap",label:m("buildings.power","Power"),value:j>=1e3?`${(j/1e3).toFixed(2)} kW`:`${j} W`,sub:f!=null?`${m("buildings.today","Today")}: ${f.toFixed(2)} kWh`:void 0,accent:"var(--nice-warning, #f59e0b)"}),I!=null&&e.jsx(Et,{icon:"users",label:m("buildings.occupancy","Occupancy"),value:`${I}`,sub:`${_.length} ${m("buildings.zones","zones")}`,accent:"var(--nice-success, #22c55e)"}),p>0&&e.jsx(Et,{icon:"bell",label:m("buildings.alerts","Alerts"),value:e.jsx("span",{style:{color:"var(--nice-danger, #ef4444)"},children:p}),sub:m("buildings.active","active"),accent:"var(--nice-danger, #ef4444)"}),e.jsx(Et,{icon:An[$],label:m("buildings.mode","Mode"),value:m(`buildings.mode.${$}`,nn[$]),accent:"var(--nice-accent, #8b5cf6)"})]}),e.jsx("div",{className:Q.zoneGrid,children:_.map(k=>{const g=t.floors.flatMap(G=>(G.zones??[]).find(T=>T.id===k.id)?t.devices??[]:[]).filter(G=>G.zoneId===k.id);return e.jsx(es,{zone:k,devices:g,expanded:h===k.id,onExpand:()=>v(h===k.id?null:k.id),onDeviceControl:o,onClick:()=>a==null?void 0:a(k.id),theme:l},k.id)})}),t.scenes&&t.scenes.length>0&&e.jsxs("div",{className:Q.scenesBar,children:[e.jsx("span",{className:Q.sceneBarLabel,children:m("buildings.scenes","Scenes")}),e.jsx("div",{className:Q.sceneList,children:t.scenes.map(k=>{var g;return e.jsxs("button",{className:`${Q.sceneBtn} ${(g=n==null?void 0:n.activeScenes)!=null&&g.includes(k.id)?Q.sceneBtnActive:""}`,onClick:()=>i==null?void 0:i(k.id),children:[e.jsx(w.NiceIcon,{name:k.icon??"video",size:14})," ",k.name]},k.id)})})]})]})},Bp="_deviceControl_1leqb_3",Rp="_dark_1leqb_23",Fp="_compact_1leqb_35",Gp="_offline_1leqb_43",qp="_offlineBanner_1leqb_51",Vp="_toggleControl_1leqb_75",Wp="_toggleLabel_1leqb_89",Hp="_toggleBtn_1leqb_109",Up="_toggleOn_1leqb_135",Yp="_blindControl_1leqb_149",Zp="_blindLabel_1leqb_159",Xp="_blindActions_1leqb_173",Kp="_blindBtn_1leqb_181",Jp="_blindSlider_1leqb_205",Qp="_blindPct_1leqb_213",eh="_lockControl_1leqb_227",th="_lockLabel_1leqb_239",nh="_lockBtn_1leqb_253",sh="_lockLocked_1leqb_273",oh="_lockUnlocked_1leqb_281",ah="_cameraControl_1leqb_295",ih="_cameraLabel_1leqb_305",rh="_cameraSnapshot_1leqb_319",ch="_cameraPlaceholder_1leqb_331",lh="_cameraStatus_1leqb_355",dh="_cameraDot_1leqb_369",uh="_cameraOnline_1leqb_379",mh="_cameraOffline_1leqb_385",ph="_sensorControl_1leqb_395",hh="_sensorLabel_1leqb_405",gh="_sensorValues_1leqb_419",fh="_sensorRow_1leqb_429",_h="_sensorKey_1leqb_443",bh="_sensorVal_1leqb_419",yh="_thermostat_1leqb_467",xh="_thermostatTitle_1leqb_481",vh="_thermostatDial_1leqb_503",jh="_dialTempCurrent_1leqb_513",wh="_dialTempLabel_1leqb_535",Nh="_dialTempTarget_1leqb_545",Ih="_dialHumidity_1leqb_565",kh="_thermostatAdjust_1leqb_575",Sh="_adjustBtn_1leqb_587",Ch="_adjustTemp_1leqb_633",Th="_hvacModes_1leqb_657",Lh="_hvacModeBtn_1leqb_671",$h="_hvacModeBtnActive_1leqb_699",zh="_hvacAction_1leqb_711",Ph="_hvacActionDot_1leqb_727",Eh="_lightControl_1leqb_741",Oh="_lightHeader_1leqb_753",Mh="_lightIcon_1leqb_765",Ah="_lightName_1leqb_773",Dh="_lightToggle_1leqb_801",Bh="_lightToggleOn_1leqb_829",Rh="_sliderRow_1leqb_841",Fh="_sliderIcon_1leqb_855",Gh="_slider_1leqb_841",qh="_sliderVal_1leqb_879",Vh="_colorRow_1leqb_891",Wh="_colorSwatch_1leqb_905",Hh="_colorPicker_1leqb_921",Uh="_colorPresets_1leqb_937",Yh="_colorPreset_1leqb_937",Zh="_lightOff_1leqb_963",M={deviceControl:Bp,dark:Rp,compact:Fp,offline:Gp,offlineBanner:qp,toggleControl:Vp,toggleLabel:Wp,toggleBtn:Hp,toggleOn:Up,blindControl:Yp,blindLabel:Zp,blindActions:Xp,blindBtn:Kp,blindSlider:Jp,blindPct:Qp,lockControl:eh,lockLabel:th,lockBtn:nh,lockLocked:sh,lockUnlocked:oh,cameraControl:ah,cameraLabel:ih,cameraSnapshot:rh,cameraPlaceholder:ch,cameraStatus:lh,cameraDot:dh,cameraOnline:uh,cameraOffline:mh,sensorControl:ph,sensorLabel:hh,sensorValues:gh,sensorRow:fh,sensorKey:_h,sensorVal:bh,thermostat:yh,thermostatTitle:xh,thermostatDial:vh,dialTempCurrent:jh,dialTempLabel:wh,dialTempTarget:Nh,dialHumidity:Ih,thermostatAdjust:kh,adjustBtn:Sh,adjustTemp:Ch,hvacModes:Th,hvacModeBtn:Lh,hvacModeBtnActive:$h,hvacAction:zh,hvacActionDot:Ph,lightControl:Eh,lightHeader:Oh,lightIcon:Mh,lightName:Ah,lightToggle:Dh,lightToggleOn:Bh,sliderRow:Rh,sliderIcon:Fh,slider:Gh,sliderVal:qh,colorRow:Vh,colorSwatch:Wh,colorPicker:Hh,colorPresets:Uh,colorPreset:Yh,lightOff:Zh};function Dn(t){const n=Math.max(0,Math.min(1,(t-2700)/3800)),s=Math.round(255-n*80),o=Math.round(200+n*30),i=Math.round(100+n*155);return`rgb(${s},${o},${i})`}function Xh(t,n,s){return"#"+[t,n,s].map(o=>o.toString(16).padStart(2,"0")).join("")}const Kh=["#ffffff","#fde68a","#fca5a5","#93c5fd","#86efac","#c4b5fd"];function Bn(t){const n=parseInt(t.slice(1,3),16),s=parseInt(t.slice(3,5),16),o=parseInt(t.slice(5,7),16);return[n,s,o]}const ts=({device:t,onControl:n,compact:s=!1,theme:o="light",className:i,style:a})=>{var $,y,C;const{t:c}=w.useNiceTranslation(),r=t.state,l=(r==null?void 0:r.on)??!1,x=(r==null?void 0:r.brightness)??100,m=(r==null?void 0:r.colorTemperature)??4e3,h=r==null?void 0:r.rgbColor,[v,_]=u.useState(!1),p=u.useCallback(d=>{n==null||n(t.id,d)},[t.id,n]),j=h?Xh(h[0],h[1],h[2]):"#ffffff",f=(($=t.capabilities)==null?void 0:$.includes("dimming"))??x!==void 0,I=(y=t.capabilities)==null?void 0:y.includes("color_temperature"),b=((C=t.capabilities)==null?void 0:C.includes("color"))||t.type==="rgb_light";return e.jsxs("div",{className:`${M.lightControl} ${s?M.compact:""} ${o==="dark"?M.dark:""} ${i??""}`,style:a,children:[e.jsxs("div",{className:M.lightHeader,children:[e.jsx("span",{className:M.lightIcon,style:{opacity:l?1:.4},children:e.jsx(w.NiceIcon,{name:"lightbulb",size:16})}),e.jsx("span",{className:M.lightName,children:t.name}),e.jsx("button",{className:`${M.lightToggle} ${l?M.lightToggleOn:""}`,"aria-label":l?c("buildings.switchedOn","On"):c("buildings.switchedOff","Off"),onClick:()=>p({on:!l}),children:e.jsx(w.NiceIcon,{name:l?"check":"close",size:14})})]}),l&&e.jsxs(e.Fragment,{children:[f&&e.jsxs("div",{className:M.sliderRow,children:[e.jsx("span",{className:M.sliderIcon,children:e.jsx(w.NiceIcon,{name:"lightbulb",size:16})}),e.jsx("input",{type:"range",min:1,max:100,value:x,className:M.slider,style:{"--pct":`${x}%`},onChange:d=>p({brightness:+d.target.value})}),e.jsxs("span",{className:M.sliderVal,children:[x,"%"]})]}),I&&e.jsxs("div",{className:M.sliderRow,children:[e.jsx("span",{className:M.sliderIcon,children:e.jsx(w.NiceIcon,{name:"thermometer",size:16})}),e.jsx("input",{type:"range",min:2700,max:6500,step:100,value:m,className:M.slider,style:{background:`linear-gradient(to right, ${Dn(2700)}, ${Dn(6500)})`},onChange:d=>p({colorTemperature:+d.target.value})}),e.jsxs("span",{className:M.sliderVal,children:[Math.round(m/100)*100,"K"]})]}),b&&e.jsxs("div",{className:M.colorRow,children:[e.jsx("span",{className:M.sliderIcon,children:e.jsx(w.NiceIcon,{name:"palette",size:16})}),e.jsx("button",{className:M.colorSwatch,"aria-label":c("buildings.pickColor","Pick a color"),"aria-expanded":v,style:{background:j},onClick:()=>_(d=>!d)}),v&&e.jsx("input",{type:"color",value:j,className:M.colorPicker,onChange:d=>{const[k,g,G]=Bn(d.target.value);p({rgbColor:[k,g,G]})}}),e.jsx("div",{className:M.colorPresets,children:Kh.map(d=>e.jsx("button",{className:M.colorPreset,"aria-label":d,style:{background:d},onClick:()=>{const[k,g,G]=Bn(d);p({rgbColor:[k,g,G]})}},d))})]})]}),!l&&!s&&e.jsx("div",{className:M.lightOff,children:c("buildings.switchedOff","Off")})]})},Rn={heat:"Heating",cool:"Cooling",auto:"Auto",off:"Off",fan_only:"Fan",dry:"Dry"},Jh={heat:"zap",cool:"thermometer",auto:"refresh",off:"stop",fan_only:"wifi",dry:"droplet"},Qh={heating:"var(--nice-danger, #ef4444)",cooling:"var(--nice-primary, #3b82f6)",fan:"var(--nice-success, #22c55e)",drying:"var(--nice-warning, #f59e0b)",idle:"var(--nice-text-muted, #94a3b8)",off:"var(--nice-border, #e2e8f0)"};function Fn(t,n,s,o,i){const a=h=>(h-90)*(Math.PI/180),c=t+s*Math.cos(a(o)),r=n+s*Math.sin(a(o)),l=t+s*Math.cos(a(i)),x=n+s*Math.sin(a(i)),m=i-o>180?1:0;return`M${c.toFixed(2)},${r.toFixed(2)} A${s},${s} 0 ${m},1 ${l.toFixed(2)},${x.toFixed(2)}`}const _t=5,Ot=35,Bt=-140,ns=140;function Gn(t){return Bt+(t-_t)/(Ot-_t)*(ns-Bt)}const ss=({device:t,onControl:n,compact:s=!1,theme:o="light",className:i,style:a})=>{const{t:c}=w.useNiceTranslation(),r=t.state,l=(r==null?void 0:r.temperature)??20,x=(r==null?void 0:r.targetTemperature)??21,m=r==null?void 0:r.humidity,h=(r==null?void 0:r.mode)??"auto",v=(r==null?void 0:r.hvacAction)??"idle",_=80,p=80,j=60,f=Fn(_,p,j,Bt,ns),I=Gn(Math.min(Math.max(l,_t),Ot)),b=Gn(Math.min(Math.max(x,_t),Ot)),$=Fn(_,p,j,Bt,Math.min(I,b)),y=Qh[v]??"var(--nice-text-muted, #94a3b8)",C=u.useCallback(k=>{const g=Math.round((x+k)*2)/2;g>=_t&&g<=Ot&&(n==null||n(t.id,{targetTemperature:g}))},[x,t.id,n]),d=u.useCallback(k=>{n==null||n(t.id,{mode:k})},[t.id,n]);return e.jsxs("div",{className:`${M.thermostat} ${s?M.compact:""} ${o==="dark"?M.dark:""} ${i??""}`,style:a,children:[e.jsx("div",{className:M.thermostatTitle,children:t.name}),e.jsxs("svg",{width:160,height:160,className:M.thermostatDial,children:[e.jsx("path",{d:f,fill:"none",stroke:"var(--nice-border, #e2e8f0)",strokeWidth:8,strokeLinecap:"round"}),e.jsx("path",{d:$,fill:"none",stroke:y,strokeWidth:8,strokeLinecap:"round",opacity:.4}),e.jsx("circle",{cx:_+j*Math.cos((b-90)*(Math.PI/180)),cy:p+j*Math.sin((b-90)*(Math.PI/180)),r:7,fill:y,stroke:"var(--nice-bg, #fff)",strokeWidth:2}),e.jsxs("text",{x:_,y:p-6,textAnchor:"middle",className:M.dialTempCurrent,children:[l.toFixed(1),"°"]}),e.jsx("text",{x:_,y:p+14,textAnchor:"middle",className:M.dialTempLabel,children:c("buildings.currentTemp","now")}),e.jsxs("text",{x:_,y:p+32,textAnchor:"middle",className:M.dialTempTarget,children:[x.toFixed(1),"°"]}),m!=null&&e.jsxs("text",{x:_,y:p+48,textAnchor:"middle",className:M.dialHumidity,children:[m,"%"]})]}),e.jsxs("div",{className:M.thermostatAdjust,children:[e.jsx("button",{className:M.adjustBtn,"aria-label":c("buildings.lowerTarget","Lower the target temperature"),onClick:()=>C(-.5),children:e.jsx(w.NiceIcon,{name:"minus",size:16})}),e.jsxs("span",{className:M.adjustTemp,children:[x.toFixed(1)," °C"]}),e.jsx("button",{className:M.adjustBtn,"aria-label":c("buildings.raiseTarget","Raise the target temperature"),onClick:()=>C(.5),children:e.jsx(w.NiceIcon,{name:"plus",size:16})})]}),!s&&e.jsx("div",{className:M.hvacModes,children:["heat","cool","auto","fan_only","off"].map(k=>e.jsx("button",{title:Rn[k],"aria-label":Rn[k],className:`${M.hvacModeBtn} ${h===k?M.hvacModeBtnActive:""}`,onClick:()=>d(k),children:e.jsx(w.NiceIcon,{name:Jh[k],size:16})},k))}),e.jsxs("div",{className:M.hvacAction,style:{color:y},children:[e.jsx("span",{className:M.hvacActionDot,style:{background:y}}),v]})]})},eg=({device:t,onControl:n})=>{const{t:s}=w.useNiceTranslation(),o=t.state,i=(o==null?void 0:o.on)===!0;return e.jsxs("div",{className:M.toggleControl,children:[e.jsx("span",{className:M.toggleLabel,children:t.name}),e.jsx("button",{className:`${M.toggleBtn} ${i?M.toggleOn:""}`,onClick:()=>n==null?void 0:n(t.id,{on:!i}),children:i?s("buildings.on","ON"):s("buildings.off","OFF")})]})},tg=({device:t,onControl:n})=>{const{t:s}=w.useNiceTranslation(),o=t.state,i=typeof(o==null?void 0:o.position)=="number"?o.position:50;return e.jsxs("div",{className:M.blindControl,children:[e.jsx("span",{className:M.blindLabel,children:t.name}),e.jsxs("div",{className:M.blindActions,children:[e.jsx("button",{className:M.blindBtn,"aria-label":s("buildings.open","Open"),onClick:()=>n==null?void 0:n(t.id,{command:"open"}),children:e.jsx(w.NiceIcon,{name:"arrow-up",size:16})}),e.jsx("button",{className:M.blindBtn,"aria-label":s("buildings.stop","Stop"),onClick:()=>n==null?void 0:n(t.id,{command:"stop"}),children:e.jsx(w.NiceIcon,{name:"stop",size:16})}),e.jsx("button",{className:M.blindBtn,"aria-label":s("buildings.close","Close"),onClick:()=>n==null?void 0:n(t.id,{command:"close"}),children:e.jsx(w.NiceIcon,{name:"arrow-down",size:16})})]}),e.jsx("input",{type:"range",min:0,max:100,value:i,className:M.blindSlider,onChange:a=>n==null?void 0:n(t.id,{position:+a.target.value})}),e.jsxs("span",{className:M.blindPct,children:[i,"%"]})]})},ng=({device:t,onControl:n})=>{const{t:s}=w.useNiceTranslation(),o=t.state,i=(o==null?void 0:o.locked)!==!1;return e.jsxs("div",{className:M.lockControl,children:[e.jsx("span",{className:M.lockLabel,children:t.name}),e.jsxs("button",{className:`${M.lockBtn} ${i?M.lockLocked:M.lockUnlocked}`,onClick:()=>n==null?void 0:n(t.id,{locked:!i}),children:[e.jsx(w.NiceIcon,{name:"lock",size:14})," ",i?s("buildings.locked","Locked"):s("buildings.unlocked","Unlocked")]})]})},sg=({device:t})=>{const{t:n}=w.useNiceTranslation(),s=t.state;return e.jsxs("div",{className:M.cameraControl,children:[e.jsx("span",{className:M.cameraLabel,children:t.name}),s!=null&&s.snapshotUrl?e.jsx("img",{src:s.snapshotUrl,alt:"snapshot",className:M.cameraSnapshot}):e.jsxs("div",{className:M.cameraPlaceholder,children:[e.jsx(w.NiceIcon,{name:"camera",size:16}),e.jsx("span",{children:s!=null&&s.streaming?n("buildings.streaming","Streaming"):n("buildings.noPreview","No preview")})]}),e.jsxs("div",{className:M.cameraStatus,children:[e.jsx("span",{className:`${M.cameraDot} ${t.status==="online"?M.cameraOnline:M.cameraOffline}`}),t.status]})]})},og=({device:t})=>{const n=t.state;return e.jsxs("div",{className:M.sensorControl,children:[e.jsx("span",{className:M.sensorLabel,children:t.name}),e.jsx("div",{className:M.sensorValues,children:Object.entries(n??{}).map(([s,o])=>o!=null&&e.jsxs("div",{className:M.sensorRow,children:[e.jsx("span",{className:M.sensorKey,children:s}),e.jsx("span",{className:M.sensorVal,children:String(o)})]},s))})]})},ag=({device:t,onControl:n,compact:s=!1,className:o,style:i,theme:a="light"})=>{const{t:c}=w.useNiceTranslation(),r=t.type,l=["light","dimmer","rgb_light","led_strip"].includes(r)?e.jsx(ts,{device:t,onControl:n,compact:s,theme:a}):["thermostat","air_conditioner","heat_pump","floor_heating"].includes(r)?e.jsx(ss,{device:t,onControl:n,compact:s,theme:a}):["blind","shutter","curtain","awning","garage_door"].includes(r)?e.jsx(tg,{device:t,onControl:n}):["lock","door"].includes(r)?e.jsx(ng,{device:t,onControl:n}):["camera","doorbell"].includes(r)?e.jsx(sg,{device:t}):r.endsWith("_sensor")||["motion_sensor","smoke_detector","water_leak_sensor","alarm"].includes(r)?e.jsx(og,{device:t}):e.jsx(eg,{device:t,onControl:n});return e.jsxs("div",{className:`${M.deviceControl} ${a==="dark"?M.dark:""} ${s?M.compact:""} ${t.status==="offline"?M.offline:""} ${o??""}`,style:i,children:[l,t.status==="offline"&&e.jsx("div",{className:M.offlineBanner,children:c("buildings.offline","Offline")})]})},ig="_root_1g2cv_3",rg="_shell_1g2cv_29",cg="_dark_1g2cv_37",lg="_listPanel_1g2cv_51",dg="_listHeader_1g2cv_79",ug="_listTitle_1g2cv_103",mg="_addBtn_1g2cv_121",pg="_list_1g2cv_51",hg="_listItem_1g2cv_159",gg="_listItemActive_1g2cv_199",fg="_listItemName_1g2cv_213",_g="_listItemMeta_1g2cv_241",bg="_enableToggle_1g2cv_255",yg="_enableOn_1g2cv_273",xg="_detailPanel_1g2cv_283",vg="_detailHeader_1g2cv_295",jg="_nameInput_1g2cv_309",wg="_deleteBtn_1g2cv_357",Ng="_section_1g2cv_387",Ig="_rules_1g2cv_397",kg="_sectionHeader_1g2cv_411",Sg="_sectionTitle_1g2cv_425",Cg="_sectionAddBtn_1g2cv_441",Tg="_ruleBlock_1g2cv_471",Lg="_ruleBlockHeader_1g2cv_497",$g="_typeSelect_1g2cv_511",zg="_removeBtn_1g2cv_543",Pg="_ruleFields_1g2cv_581",Eg="_input_1g2cv_617",Og="_textarea_1g2cv_649",Mg="_dayPicker_1g2cv_685",Ag="_dayBtn_1g2cv_697",Dg="_dayBtnActive_1g2cv_717",Bg="_noSelection_1g2cv_731",Rg="_emptyHint_1g2cv_733",O={root:ig,shell:rg,dark:cg,listPanel:lg,listHeader:dg,listTitle:ug,addBtn:mg,list:pg,listItem:hg,listItemActive:gg,listItemName:fg,listItemMeta:_g,enableToggle:bg,enableOn:yg,detailPanel:xg,detailHeader:vg,nameInput:jg,deleteBtn:wg,section:Ng,rules:Ig,sectionHeader:kg,sectionTitle:Sg,sectionAddBtn:Cg,ruleBlock:Tg,ruleBlockHeader:Lg,typeSelect:$g,removeBtn:zg,ruleFields:Pg,input:Eg,textarea:Og,dayPicker:Mg,dayBtn:Ag,dayBtnActive:Dg,noSelection:Bg,emptyHint:Rg},Fg=[{target:".nice-building-automation-editor",titleKey:"tutorial.buildingAutomationEditor.intro.title",title:"Automation editor",contentKey:"tutorial.buildingAutomationEditor.intro.content",content:"Create building automations: pick one from the list, define its triggers, conditions and actions, then save, enable or delete it.",placement:"auto"}],je=(t,n,s="")=>{const o=t[n];return typeof o=="string"?o:s},Mt=(t,n,s=0)=>{const o=t[n];return typeof o=="number"?o:s},Rt=["mon","tue","wed","thu","fri","sat","sun"],Gg=t=>{const n=t.days;return Array.isArray(n)?n.map(s=>typeof s=="number"?Rt[s]:String(s)):[...Rt.slice(0,5)]},Xe={temperature:{name:"Temperature",unit:"°C"},humidity:{name:"Humidity",unit:"%"},pressure:{name:"Pressure",unit:"hPa"},co2:{name:"CO₂",unit:"ppm"},voc:{name:"VOC",unit:"ppb"},pm25:{name:"PM2.5",unit:"µg/m³"},pm10:{name:"PM10",unit:"µg/m³"},noise:{name:"Noise",unit:"dB"},lux:{name:"Light level",unit:"lx"},uv:{name:"UV index",unit:""},motion:{name:"Motion",unit:""},power:{name:"Power",unit:"W"},energy:{name:"Energy",unit:"kWh"},water_flow:{name:"Water flow",unit:"L/min"},gas:{name:"Gas",unit:"ppm"},radon:{name:"Radon",unit:"Bq/m³"}},qg=t=>t in Xe,sn=t=>{const n=je(t,"sensorType",je(t,"attribute"));return qg(n)?n:"temperature"},Vg=(t,n)=>{const s=t[n];return s&&typeof s=="object"?s:{}},Wg=t=>{const n=new Intl.DateTimeFormat(t,{weekday:"short",timeZone:"UTC"});return Array.from({length:7},(s,o)=>n.format(new Date(Date.UTC(2024,0,1+o))))},qn=[["time","buildings.trigger.time","Time"],["sunrise","buildings.trigger.sunrise","Sunrise"],["sunset","buildings.trigger.sunset","Sunset"],["device_state","buildings.trigger.deviceState","Device state"],["sensor_threshold","buildings.trigger.sensorThreshold","Sensor threshold"],["geofence","buildings.trigger.geofence","Geofence"],["scene_activated","buildings.trigger.sceneActivated","Scene activated"],["building_mode","buildings.trigger.buildingMode","Building mode"],["webhook","buildings.trigger.webhook","Webhook"],["manual","buildings.trigger.manual","Manual"]],Hg=[["eq","buildings.operator.equals","equals"],["neq","buildings.operator.neq","is not"],["gt","buildings.operator.gt","greater than"],["gte","buildings.operator.gte","at least"],["lt","buildings.operator.lt","less than"],["lte","buildings.operator.lte","at most"],["changed","buildings.operator.changed","changes"]],Ug=["on","brightness","temperature","targetTemperature","locked","position","state"],Yg=["home","away","night","vacation","guest","party","occupied","closed","weekend","event","emergency","maintenance"],Zg=t=>{switch(t){case"sensor_threshold":return{type:t,deviceId:"",sensorType:"temperature",unit:Xe.temperature.unit,operator:"above",threshold:25};case"device_state":return{type:t,deviceId:"",attribute:"on",operator:"changed"};case"geofence":return{type:t,zone:"home"};case"scene_activated":return{type:t,sceneId:""};case"building_mode":return{type:t,mode:"home"};default:return{type:t}}},Xg=({trigger:t,devices:n,scenes:s,onChange:o,onRemove:i})=>{const{t:a,lang:c}=w.useNiceTranslation(),r=l=>o({...t,...l});return e.jsxs("div",{className:O.ruleBlock,children:[e.jsxs("div",{className:O.ruleBlockHeader,children:[e.jsxs("select",{className:O.typeSelect,value:t.type,onChange:l=>o(Zg(l.target.value)),children:[qn.map(([l,x,m])=>e.jsx("option",{value:l,children:a(x,m)},l)),!qn.some(([l])=>l===t.type)&&e.jsx("option",{value:t.type,disabled:!0,children:t.type})]}),e.jsx("button",{className:O.removeBtn,onClick:i,title:a("buildings.remove","Remove"),"aria-label":a("buildings.remove","Remove"),children:e.jsx(w.NiceIcon,{name:"close",size:14})})]}),t.type==="time"&&e.jsxs("div",{className:O.ruleFields,children:[e.jsxs("label",{children:[a("buildings.field.hour","Hour"),e.jsx("input",{type:"time",className:O.input,value:je(t,"time","08:00"),onChange:l=>r({time:l.target.value})})]}),e.jsxs("label",{children:[a("buildings.field.days","Days"),e.jsx("div",{className:O.dayPicker,children:Wg(c).map((l,x)=>{const m=Gg(t),h=Rt[x],v=m.includes(h);return e.jsx("button",{type:"button","aria-pressed":v,className:`${O.dayBtn} ${v?O.dayBtnActive:""}`,onClick:()=>r({days:v?m.filter(_=>_!==h):Rt.filter(_=>_===h||m.includes(_))}),children:l},h)})})]})]}),(t.type==="sunrise"||t.type==="sunset")&&e.jsx("div",{className:O.ruleFields,children:e.jsxs("label",{children:[a("buildings.field.offsetMinutes","Offset (minutes)"),e.jsx("input",{type:"number",className:O.input,min:-120,max:120,step:5,value:Mt(t,"offsetMinutes",0),onChange:l=>r({offsetMinutes:+l.target.value})})]})}),(t.type==="device_state"||t.type==="sensor_threshold")&&e.jsxs("div",{className:O.ruleFields,children:[e.jsxs("label",{children:[a("buildings.device","Device"),e.jsxs("select",{className:O.input,value:je(t,"deviceId",""),onChange:l=>r({deviceId:l.target.value}),children:[e.jsx("option",{value:"",children:a("buildings.selectPlaceholder","— select —")}),n.map(l=>e.jsx("option",{value:l.id,children:l.name},l.id))]})]}),t.type==="device_state"&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{children:[a("buildings.field.attribute","Attribute"),e.jsx("input",{className:O.input,list:"nice-automation-attributes",value:je(t,"attribute","on"),onChange:l=>r({attribute:l.target.value})}),e.jsx("datalist",{id:"nice-automation-attributes",children:Ug.map(l=>e.jsx("option",{value:l},l))})]}),e.jsxs("label",{children:[a("buildings.field.operator","Operator"),e.jsx("select",{className:O.input,value:je(t,"operator","changed"),onChange:l=>r({operator:l.target.value,value:l.target.value==="changed"?void 0:je(t,"value","")}),children:Hg.map(([l,x,m])=>e.jsx("option",{value:l,children:a(x,m)},l))})]}),je(t,"operator","changed")!=="changed"&&e.jsxs("label",{children:[a("buildings.field.value","Value"),e.jsx("input",{className:O.input,value:je(t,"value",""),onChange:l=>r({value:l.target.value})})]})]}),t.type==="sensor_threshold"&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{children:[a("buildings.field.sensor","Sensor"),e.jsx("select",{className:O.input,value:sn(t),onChange:l=>{const x=l.target.value;r({sensorType:x,unit:Xe[x].unit,attribute:void 0})},children:Object.keys(Xe).map(l=>e.jsx("option",{value:l,children:a(`buildings.sensor.${l}`,Xe[l].name)},l))})]}),e.jsxs("label",{children:[a("buildings.field.operator","Operator"),e.jsxs("select",{className:O.input,value:je(t,"operator","above"),onChange:l=>r({operator:l.target.value}),children:[e.jsx("option",{value:"above",children:a("buildings.operator.above","above")}),e.jsx("option",{value:"below",children:a("buildings.operator.below","below")}),e.jsx("option",{value:"eq",children:a("buildings.operator.equals","equals")})]})]}),e.jsxs("label",{children:[a("buildings.field.threshold","Threshold"),Xe[sn(t)].unit&&` (${Xe[sn(t)].unit})`,e.jsx("input",{type:"number",className:O.input,value:Mt(t,"threshold",0),onChange:l=>r({threshold:+l.target.value})})]})]})]}),t.type==="webhook"&&e.jsx("div",{className:O.ruleFields,children:e.jsxs("label",{children:[a("buildings.field.endpointId","Endpoint ID"),e.jsx("input",{className:O.input,value:je(t,"webhookId",""),onChange:l=>r({webhookId:l.target.value})})]})}),t.type==="geofence"&&e.jsxs("div",{className:O.ruleFields,children:[e.jsxs("label",{children:[a("buildings.field.zone","When"),e.jsxs("select",{className:O.input,value:je(t,"zone","home"),onChange:l=>r({zone:l.target.value}),children:[e.jsx("option",{value:"home",children:a("buildings.geofence.home","Arriving home")}),e.jsx("option",{value:"away",children:a("buildings.geofence.away","Leaving home")})]})]}),e.jsxs("label",{children:[a("buildings.field.radius","Radius (m)"),e.jsx("input",{type:"number",className:O.input,min:50,step:50,value:Mt(t,"radius",200),onChange:l=>r({radius:+l.target.value})})]})]}),t.type==="scene_activated"&&e.jsx("div",{className:O.ruleFields,children:e.jsxs("label",{children:[a("buildings.scene","Scene"),e.jsxs("select",{className:O.input,value:je(t,"sceneId",""),onChange:l=>r({sceneId:l.target.value}),children:[e.jsx("option",{value:"",children:a("buildings.selectPlaceholder","— select —")}),s.map(l=>e.jsx("option",{value:l.id,children:l.name},l.id))]})]})}),t.type==="building_mode"&&e.jsx("div",{className:O.ruleFields,children:e.jsxs("label",{children:[a("buildings.mode","Mode"),e.jsx("select",{className:O.input,value:je(t,"mode","home"),onChange:l=>r({mode:l.target.value}),children:Yg.map(l=>e.jsx("option",{value:l,children:a(`buildings.mode.${l}`,l.charAt(0).toUpperCase()+l.slice(1))},l))})]})}),t.type==="manual"&&e.jsx("div",{className:O.ruleFields,children:e.jsx("span",{children:a("buildings.trigger.manualHint","Runs only when started by hand.")})})]})},Kg=({action:t,devices:n,scenes:s,onChange:o,onRemove:i})=>{const{t:a}=w.useNiceTranslation(),c=r=>o({...t,...r});return e.jsxs("div",{className:O.ruleBlock,children:[e.jsxs("div",{className:O.ruleBlockHeader,children:[e.jsxs("select",{className:O.typeSelect,value:t.type,onChange:r=>o({type:r.target.value}),children:[e.jsx("option",{value:"device_control",children:a("buildings.device","Device")}),e.jsx("option",{value:"scene_activate",children:a("buildings.activateScene","Activate scene")}),e.jsx("option",{value:"notification",children:a("buildings.action.notification","Notification")}),e.jsx("option",{value:"delay",children:a("buildings.action.delay","Delay")}),e.jsx("option",{value:"http_request",children:a("buildings.httpRequest","HTTP Request")})]}),e.jsx("button",{className:O.removeBtn,onClick:i,title:a("buildings.remove","Remove"),"aria-label":a("buildings.remove","Remove"),children:e.jsx(w.NiceIcon,{name:"close",size:14})})]}),t.type==="device_control"&&e.jsxs("div",{className:O.ruleFields,children:[e.jsxs("label",{children:[a("buildings.device","Device"),e.jsxs("select",{className:O.input,value:je(t,"deviceId",""),onChange:r=>c({deviceId:r.target.value}),children:[e.jsx("option",{value:"",children:a("buildings.selectPlaceholder","— select —")}),n.map(r=>e.jsx("option",{value:r.id,children:r.name},r.id))]})]}),e.jsxs("label",{children:[a("buildings.field.stateJson","State (JSON)"),e.jsx("textarea",{className:O.textarea,rows:3,value:JSON.stringify(Vg(t,"state"),null,2),onChange:r=>{try{c({state:JSON.parse(r.target.value)})}catch{}}})]})]}),t.type==="scene_activate"&&e.jsx("div",{className:O.ruleFields,children:e.jsxs("label",{children:[a("buildings.scene","Scene"),e.jsxs("select",{className:O.input,value:je(t,"sceneId",""),onChange:r=>c({sceneId:r.target.value}),children:[e.jsx("option",{value:"",children:a("buildings.selectPlaceholder","— select —")}),s.map(r=>e.jsx("option",{value:r.id,children:r.name},r.id))]})]})}),t.type==="notification"&&e.jsxs("div",{className:O.ruleFields,children:[e.jsxs("label",{children:[a("buildings.field.channel","Channel"),e.jsxs("select",{className:O.input,value:je(t,"channel","push"),onChange:r=>c({channel:r.target.value}),children:[e.jsx("option",{value:"push",children:a("buildings.push","Push")}),e.jsx("option",{value:"email",children:a("buildings.email","Email")}),e.jsx("option",{value:"sms",children:"SMS"}),e.jsx("option",{value:"in_app",children:a("buildings.inApp","In-app")}),e.jsx("option",{value:"teams",children:a("buildings.teams","Teams")}),e.jsx("option",{value:"slack",children:a("buildings.slack","Slack")})]})]}),e.jsxs("label",{children:[a("buildings.field.message","Message"),e.jsx("input",{className:O.input,value:je(t,"message",""),onChange:r=>c({message:r.target.value})})]})]}),t.type==="delay"&&e.jsx("div",{className:O.ruleFields,children:e.jsxs("label",{children:[a("buildings.field.delaySeconds","Delay (seconds)"),e.jsx("input",{type:"number",className:O.input,min:1,value:Mt(t,"delaySeconds",60),onChange:r=>c({delaySeconds:+r.target.value})})]})}),t.type==="http_request"&&e.jsxs("div",{className:O.ruleFields,children:[e.jsxs("label",{children:["URL",e.jsx("input",{className:O.input,value:je(t,"url",""),onChange:r=>c({url:r.target.value})})]}),e.jsxs("label",{children:[a("buildings.field.method","Method"),e.jsxs("select",{className:O.input,value:je(t,"method","POST"),onChange:r=>c({method:r.target.value}),children:[e.jsx("option",{children:"GET"}),e.jsx("option",{children:a("buildings.post","POST")}),e.jsx("option",{children:"PUT"}),e.jsx("option",{children:a("buildings.patch","PATCH")})]})]})]})]})},Jg=({automations:t,defaultAutomations:n,devices:s=[],scenes:o=[],onAutomationsChange:i,onDelete:a,onToggle:c,readOnly:r=!1,className:l,style:x,theme:m="light",tutorial:h})=>{var G;const{t:v}=w.useNiceTranslation(),[_,p]=w.useControllableState({value:t,defaultValue:n,fallbackValue:[],onChange:i,componentName:"NiceAutomationEditor"}),[j,f]=u.useState(null),I=j!==null&&_.some(T=>T.id===j)?j:((G=_[0])==null?void 0:G.id)??null,b=_.find(T=>T.id===I)??null,$=u.useCallback(T=>{b&&p(_.map(R=>R.id===b.id?{...R,...T}:R))},[b,_,p]),y=u.useCallback(()=>{const T={id:`auto-${Date.now()}`,name:"New automation",enabled:!0,triggers:[],conditions:[],actions:[]};p([..._,T]),f(T.id)},[_,p]),C=u.useCallback(T=>{var R;p(_.filter(H=>H.id!==T)),I===T&&f(((R=_.find(H=>H.id!==T))==null?void 0:R.id)??null),a==null||a(T)},[_,I,p,a]),d=u.useCallback((T,R)=>{p(_.map(H=>H.id===T?{...H,enabled:R}:H)),c==null||c(T,R)},[_,p,c]),k=e.jsxs("div",{className:O.listPanel,children:[e.jsxs("div",{className:O.listHeader,children:[e.jsx("span",{className:O.listTitle,children:v("buildings.automations","Automations")}),!r&&e.jsxs("button",{className:O.addBtn,onClick:y,children:[e.jsx(w.NiceIcon,{name:"plus",size:12})," ",v("buildings.add","Add")]})]}),e.jsxs("div",{className:O.list,children:[_.map(T=>e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:w.clickOnActivationKey,className:`${O.listItem} ${I===T.id?O.listItemActive:""}`,onClick:()=>f(T.id),children:[e.jsx("div",{className:O.listItemName,children:T.name}),e.jsxs("div",{className:O.listItemMeta,children:[T.triggers.length," ",v("buildings.triggersShort","triggers")," ·"," ",T.actions.length," ",v("buildings.actionsShort","actions")]}),e.jsx("button",{className:`${O.enableToggle} ${T.enabled?O.enableOn:""}`,disabled:r,onClick:R=>{R.stopPropagation(),d(T.id,!T.enabled)},title:T.enabled?v("buildings.disable","Disable"):v("buildings.enable","Enable"),"aria-label":T.enabled?v("buildings.disable","Disable"):v("buildings.enable","Enable"),children:e.jsx(w.NiceIcon,{name:T.enabled?"check":"close",size:14})})]},T.id)),_.length===0&&e.jsx("div",{className:O.emptyHint,children:v("buildings.noAutomations","No automations")})]})]}),g=e.jsx("div",{className:O.detailPanel,children:b?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:O.detailHeader,children:[e.jsx("input",{className:O.nameInput,value:b.name,onChange:T=>$({name:T.target.value}),readOnly:r}),!r&&e.jsx("button",{className:O.deleteBtn,onClick:()=>C(b.id),children:v("buildings.remove","Remove")})]}),e.jsxs("fieldset",{className:O.rules,disabled:r,children:[e.jsxs("section",{className:O.section,children:[e.jsxs("div",{className:O.sectionHeader,children:[e.jsx("span",{className:O.sectionTitle,children:v("buildings.triggers","Triggers")}),!r&&e.jsxs("button",{className:O.sectionAddBtn,onClick:()=>$({triggers:[...b.triggers,{type:"time"}]}),children:[e.jsx(w.NiceIcon,{name:"plus",size:12})," ",v("buildings.add","Add")]})]}),b.triggers.map((T,R)=>e.jsx(Xg,{trigger:T,devices:s,scenes:o,onChange:H=>$({triggers:b.triggers.map((se,ne)=>ne===R?H:se)}),onRemove:()=>$({triggers:b.triggers.filter((H,se)=>se!==R)})},R)),b.triggers.length===0&&e.jsx("div",{className:O.emptyHint,children:v("buildings.noTriggers","No triggers")})]}),e.jsxs("section",{className:O.section,children:[e.jsxs("div",{className:O.sectionHeader,children:[e.jsx("span",{className:O.sectionTitle,children:v("buildings.actions","Actions")}),!r&&e.jsxs("button",{className:O.sectionAddBtn,onClick:()=>$({actions:[...b.actions,{type:"device_control"}]}),children:[e.jsx(w.NiceIcon,{name:"plus",size:12})," ",v("buildings.add","Add")]})]}),b.actions.map((T,R)=>e.jsx(Kg,{action:T,devices:s,scenes:o,onChange:H=>$({actions:b.actions.map((se,ne)=>ne===R?H:se)}),onRemove:()=>$({actions:b.actions.filter((H,se)=>se!==R)})},R)),b.actions.length===0&&e.jsx("div",{className:O.emptyHint,children:v("buildings.noActions","No actions")})]})]})]}):e.jsx("div",{className:O.noSelection,children:v("buildings.noAutomationSelected","Select an automation or add a new one")})});return e.jsxs("div",{className:`nice-building-automation-editor ${O.root} ${m==="dark"?O.dark:""} ${l??""}`,style:{position:"relative",...x},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:e.jsx(w.NiceTutorialButton,{steps:w.resolveTutorial(h,Fg)})}),e.jsx(w.NiceAppShell,{flush:!0,className:O.shell,sidebar:k,children:g})]})},Qg="_root_o100g_3",ef="_shell_o100g_29",tf="_dark_o100g_37",nf="_gridPanel_o100g_51",sf="_gridHeader_o100g_79",of="_gridTitle_o100g_103",af="_addBtn_o100g_119",rf="_sceneGrid_o100g_147",cf="_sceneCard_o100g_165",lf="_sceneCardActive_o100g_193",df="_sceneCardSelected_o100g_199",uf="_sceneCardIcon_o100g_207",mf="_sceneCardName_o100g_217",pf="_sceneCardDevices_o100g_235",hf="_activeBadge_o100g_253",gf="_activateBtn_o100g_263",ff="_emptyGrid_o100g_307",_f="_detailPanel_o100g_325",bf="_metaRow_o100g_343",yf="_iconPicker_o100g_355",xf="_currentIcon_o100g_363",vf="_iconGrid_o100g_381",jf="_iconOpt_o100g_397",wf="_iconOptActive_o100g_423",Nf="_metaFields_o100g_433",If="_nameInput_o100g_447",kf="_descInput_o100g_481",Sf="_colorPicker_o100g_541",Cf="_colorOpt_o100g_551",Tf="_colorOptActive_o100g_567",Lf="_targetsSection_o100g_577",$f="_targetsSectionHeader_o100g_599",zf="_addTargetBtn_o100g_621",Pf="_targetRow_o100g_649",Ef="_targetSelect_o100g_679",Of="_targetState_o100g_711",Mf="_targetField_o100g_725",Af="_tempInput_o100g_751",Df="_removeTargetBtn_o100g_769",Bf="_noTargets_o100g_809",Rf="_detailActions_o100g_829",Ff="_activateFullBtn_o100g_843",Gf="_deleteBtn_o100g_875",J={root:Qg,shell:ef,dark:tf,gridPanel:nf,gridHeader:sf,gridTitle:of,addBtn:af,sceneGrid:rf,sceneCard:cf,sceneCardActive:lf,sceneCardSelected:df,sceneCardIcon:uf,sceneCardName:mf,sceneCardDevices:pf,activeBadge:hf,activateBtn:gf,emptyGrid:ff,detailPanel:_f,metaRow:bf,iconPicker:yf,currentIcon:xf,iconGrid:vf,iconOpt:jf,iconOptActive:wf,metaFields:Nf,nameInput:If,descInput:kf,colorPicker:Sf,colorOpt:Cf,colorOptActive:Tf,targetsSection:Lf,targetsSectionHeader:$f,addTargetBtn:zf,targetRow:Pf,targetSelect:Ef,targetState:Of,targetField:Mf,tempInput:Af,removeTargetBtn:Df,noTargets:Bf,detailActions:Rf,activateFullBtn:Ff,deleteBtn:Gf},qf=[{target:".nice-scene-editor",titleKey:"tutorial.buildingSceneEditor.intro.title",title:"Scene editor",contentKey:"tutorial.buildingSceneEditor.intro.content",content:"Create scenes that set multiple devices at once: pick a scene, choose device target states, then save or activate it.",placement:"auto"}],at=t=>t&&typeof t=="object"?t:{},Vf=(t,n,s=!1)=>{const o=at(t)[n];return typeof o=="boolean"?o:s},gt=(t,n,s=0)=>{const o=at(t)[n];return typeof o=="number"?o:s},Wf=["video","eye-off","lightbulb","gamepad","briefcase","utensils","music","droplet","rocket","home","thermometer","lock","star","gift","heart","settings"],Hf=["var(--nice-primary-bg, #e0f2fe)","var(--nice-accent-tint-10, #fce7f3)","var(--nice-success-bg, #dcfce7)","var(--nice-warning-bg, #fef9c3)","var(--nice-accent-tint-10, #ede9fe)","var(--nice-danger-bg, #fee2e2)","var(--nice-success-bg, #f0fdf4)","var(--nice-warning-tint-10, #fff7ed)"],Uf=({target:t,devices:n,onChange:s,onRemove:o})=>{const{t:i}=w.useNiceTranslation(),a=n.find(c=>c.id===t.deviceId);return e.jsxs("div",{className:J.targetRow,children:[e.jsxs("select",{className:J.targetSelect,value:t.deviceId,onChange:c=>s({...t,deviceId:c.target.value}),children:[e.jsxs("option",{value:"",children:["— ",i("buildings.device","Device")," —"]}),n.map(c=>e.jsx("option",{value:c.id,children:c.name},c.id))]}),a&&e.jsxs("div",{className:J.targetState,children:[e.jsxs("label",{className:J.targetField,children:[e.jsx("span",{children:i("buildings.onOff","On/Off")}),e.jsx("input",{type:"checkbox",checked:Vf(t.state,"on",!1),onChange:c=>s({...t,state:{...at(t.state),on:c.target.checked}})})]}),(a.type==="dimmer"||a.type==="light"||a.type==="rgb_light"||a.type==="led_strip")&&e.jsxs("label",{className:J.targetField,children:[e.jsx("span",{children:i("buildings.brightness","Brightness")}),e.jsx("input",{type:"range",min:0,max:100,value:gt(t.state,"brightness",100),onChange:c=>s({...t,state:{...at(t.state),brightness:+c.target.value}})}),e.jsxs("span",{children:[gt(t.state,"brightness",100),"%"]})]}),(a.type==="blind"||a.type==="shutter")&&e.jsxs("label",{className:J.targetField,children:[e.jsx("span",{children:i("buildings.position","Position")}),e.jsx("input",{type:"range",min:0,max:100,value:gt(t.state,"position",100),onChange:c=>s({...t,state:{...at(t.state),position:+c.target.value}})}),e.jsxs("span",{children:[gt(t.state,"position",100),"%"]})]}),(a.type==="thermostat"||a.type==="air_conditioner")&&e.jsxs("label",{className:J.targetField,children:[e.jsx("span",{children:i("buildings.temp","Temp.")}),e.jsx("input",{type:"number",className:J.tempInput,min:10,max:30,step:.5,value:gt(t.state,"targetTemperature",20),onChange:c=>s({...t,state:{...at(t.state),targetTemperature:+c.target.value}})}),e.jsx("span",{children:"°C"})]})]}),e.jsx("button",{className:J.removeTargetBtn,onClick:o,title:i("buildings.remove","Remove"),"aria-label":i("buildings.remove","Remove"),children:e.jsx(w.NiceIcon,{name:"close",size:14})})]})},Yf=({scenes:t,defaultScenes:n,devices:s=[],activeSceneIds:o=[],onScenesChange:i,onActivate:a,onDelete:c,readOnly:r=!1,className:l,style:x,theme:m="light",tutorial:h})=>{var G;const{t:v}=w.useNiceTranslation(),[_,p]=w.useControllableState({value:t,defaultValue:n,fallbackValue:[],onChange:i,componentName:"NiceSceneEditor"}),[j,f]=u.useState(null),I=j!==null&&_.some(T=>T.id===j)?j:((G=_[0])==null?void 0:G.id)??null,b=_.find(T=>T.id===I)??null,$=u.useCallback(T=>{b&&p(_.map(R=>R.id===b.id?{...R,...T}:R))},[b,_,p]),y=u.useCallback(()=>{const T={id:`scene-${Date.now()}`,name:"New scene",deviceTargets:[],icon:"video",color:"var(--nice-primary-bg, #e0f2fe)"};p([..._,T]),f(T.id)},[_,p]),C=u.useCallback(T=>{var R;p(_.filter(H=>H.id!==T)),I===T&&f(((R=_.find(H=>H.id!==T))==null?void 0:R.id)??null),c==null||c(T)},[_,I,p,c]),d=()=>{if(!b)return;const T={deviceId:"",state:{on:!0},transitionMs:1e3};$({deviceTargets:[...b.deviceTargets,T]})},k=e.jsxs("div",{className:J.gridPanel,children:[e.jsxs("div",{className:J.gridHeader,children:[e.jsx("span",{className:J.gridTitle,children:v("buildings.scenes","Scenes")}),!r&&e.jsxs("button",{className:J.addBtn,onClick:y,children:[e.jsx(w.NiceIcon,{name:"plus",size:12})," ",v("buildings.new","New")]})]}),e.jsxs("div",{className:J.sceneGrid,children:[_.map(T=>{const R=o.includes(T.id),H=I===T.id;return e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:w.clickOnActivationKey,className:`${J.sceneCard} ${R?J.sceneCardActive:""} ${H?J.sceneCardSelected:""}`,style:{background:T.color??"var(--nice-bg-secondary, #f8fafc)"},onClick:()=>f(T.id),children:[e.jsx("div",{className:J.sceneCardIcon,children:e.jsx(w.NiceIcon,{name:T.icon??"video",size:20})}),e.jsx("div",{className:J.sceneCardName,children:T.name}),e.jsxs("div",{className:J.sceneCardDevices,children:[T.deviceTargets.length," ",v("buildings.devices","devices"),R&&e.jsx("span",{className:J.activeBadge,children:e.jsx(w.NiceIcon,{name:"check",size:12})})]}),e.jsx("button",{className:J.activateBtn,"aria-label":v("buildings.activate","Activate"),onClick:se=>{se.stopPropagation(),a==null||a(T.id)},children:e.jsx(w.NiceIcon,{name:"play",size:14})})]},T.id)}),_.length===0&&e.jsx("div",{className:J.emptyGrid,children:v("buildings.noScenes","No scenes yet. Add the first one!")})]})]}),g=b?e.jsxs("div",{className:J.detailPanel,children:[e.jsxs("div",{className:J.metaRow,children:[e.jsxs("div",{className:J.iconPicker,children:[e.jsx("span",{className:J.currentIcon,children:e.jsx(w.NiceIcon,{name:b.icon??"video",size:20})}),e.jsx("div",{className:J.iconGrid,children:Wf.map(T=>e.jsx("button",{className:`${J.iconOpt} ${b.icon===T?J.iconOptActive:""}`,"aria-label":T,onClick:()=>$({icon:T}),children:e.jsx(w.NiceIcon,{name:T,size:16})},T))})]}),e.jsxs("div",{className:J.metaFields,children:[e.jsx("input",{className:J.nameInput,value:b.name,readOnly:r,onChange:T=>$({name:T.target.value}),placeholder:v("buildings.sceneName","Scene name")}),e.jsx("textarea",{className:J.descInput,value:b.description??"",readOnly:r,onChange:T=>$({description:T.target.value}),placeholder:v("buildings.descriptionOptional","Description (optional)"),rows:2})]})]}),!r&&e.jsx("div",{className:J.colorPicker,children:Hf.map(T=>e.jsx("button",{className:`${J.colorOpt} ${b.color===T?J.colorOptActive:""}`,style:{background:T},onClick:()=>$({color:T})},T))}),e.jsxs("fieldset",{className:J.targetsSection,disabled:r,children:[e.jsxs("div",{className:J.targetsSectionHeader,children:[e.jsx("span",{children:v("buildings.devicesInScene","Devices in this scene")}),!r&&e.jsxs("button",{className:J.addTargetBtn,onClick:d,children:[e.jsx(w.NiceIcon,{name:"plus",size:12})," ",v("buildings.add","Add")]})]}),b.deviceTargets.map((T,R)=>e.jsx(Uf,{target:T,devices:s,onChange:H=>$({deviceTargets:b.deviceTargets.map((se,ne)=>ne===R?H:se)}),onRemove:()=>$({deviceTargets:b.deviceTargets.filter((H,se)=>se!==R)})},R)),b.deviceTargets.length===0&&e.jsx("div",{className:J.noTargets,children:v("buildings.sceneHint","Add the devices this scene should control.")})]}),e.jsxs("div",{className:J.detailActions,children:[e.jsxs("button",{className:J.activateFullBtn,onClick:()=>a==null?void 0:a(b.id),children:[e.jsx(w.NiceIcon,{name:"play",size:14})," ",v("buildings.activateScene","Activate scene")]}),!r&&e.jsx("button",{className:J.deleteBtn,onClick:()=>C(b.id),children:v("buildings.remove","Remove")})]})]}):void 0;return e.jsxs("div",{className:`nice-scene-editor ${J.root} ${m==="dark"?J.dark:""} ${l??""}`,style:{position:"relative",...x},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:e.jsx(w.NiceTutorialButton,{steps:w.resolveTutorial(h,qf)})}),e.jsx(w.NiceAppShell,{flush:!0,className:J.shell,sidebar:k,children:g})]})};exports.LayerPanel=Xn;exports.Minimap=ln;exports.NiceAutomationEditor=Jg;exports.NiceBuildingDashboard=Dp;exports.NiceDeviceControl=ag;exports.NiceFloorPlanEditor=go;exports.NiceLightControl=ts;exports.NiceSceneEditor=Yf;exports.NiceSpatialEditor=iu;exports.NiceSpatialViewer=Fm;exports.NiceThermostatControl=ss;exports.NiceZoneCard=es;exports.ObjectLibrary=Kn;exports.PropertiesPanel=Jn;exports.useMeasurement=Vm;exports.useSnapToGrid=qm;exports.useSpatialEditor=Gm;
139
+ `,x=C=>C.boundary;return y.forEach((C,g)=>{const L=x(C);if(C.type==="wall"&&C.bounds)b.push(e.jsx("rect",{x:C.bounds.x,y:C.bounds.y,width:C.bounds.width,height:C.bounds.height,fill:"var(--nice-text-secondary, #475569)",stroke:"var(--nice-text, #334155)",strokeWidth:"1"},`wall-${g}`));else if(C.type==="zone"&&L){const m=L.map((k,l)=>`${l===0?"M":"L"} ${k.x} ${k.y}`).join(" ")+" Z";b.push(e.jsx("path",{d:m,fill:"var(--nice-primary-tint-20, rgba(59, 130, 246, 0.2))",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:"1"},`zone-${g}`))}else if(C.type==="room"&&L){const m=L.map((k,l)=>`${l===0?"M":"L"} ${k.x} ${k.y}`).join(" ")+" Z";b.push(e.jsx("path",{d:m,fill:"var(--nice-success-tint-15, rgba(34, 197, 94, 0.15))",stroke:"var(--nice-success, #22c55e)",strokeWidth:"1"},`room-${g}`))}else C.bounds&&b.push(e.jsx("rect",{x:C.bounds.x,y:C.bounds.y,width:C.bounds.width,height:C.bounds.height,fill:"var(--nice-accent-tint-30, rgba(99, 102, 241, 0.3))",stroke:"var(--nice-info, #6366f1)",strokeWidth:"0.5",rx:"2"},`obj-${g}`))}),e.jsxs("svg",{viewBox:`${f.x} ${f.y} ${f.width} ${f.height}`,className:Z.previewSvg,preserveAspectRatio:"xMidYMid meet",children:[e.jsx("defs",{dangerouslySetInnerHTML:{__html:w}}),e.jsx("rect",{x:f.x,y:f.y,width:f.width,height:f.height,fill:"url(#grid)"}),b]})},[a,i]),r=u.useRef(null);N.useOverlayFocus(r,{open:!0,onClose:s});const d=u.useCallback(f=>{f.target===f.currentTarget&&s()},[s]),_=t.errors.some(f=>f.fatal),p=t.errors.filter(f=>!f.fatal);return e.jsx("div",{className:Z.overlay,role:"presentation",onMouseDown:d,children:e.jsxs("div",{ref:r,className:Z.dialog,tabIndex:-1,role:"dialog","aria-modal":"true","aria-labelledby":"import-preview-title",children:[e.jsxs("div",{className:Z.header,children:[e.jsx("h2",{id:"import-preview-title",className:Z.title,children:o("importPreviewDialog.importPreview","Import Preview")}),e.jsx("button",{className:Z.closeButton,onClick:s,title:o("importPreviewDialog.close","Close"),"aria-label":o("importPreviewDialog.closeDialog","Close dialog"),children:e.jsx(Ra,{})})]}),e.jsxs("div",{className:Z.content,children:[e.jsx("div",{className:Z.preview,children:c||e.jsx("div",{className:Z.previewCanvas,children:o("importPreviewDialog.noPreviewAvailable","No preview available")})}),e.jsxs("div",{className:Z.info,children:[e.jsxs("div",{className:Z.section,children:[e.jsxs("h3",{className:Z.sectionTitle,children:[e.jsx(Fa,{})," ",o("importPreviewDialog.importStatistics","Import Statistics")]}),e.jsxs("div",{className:Z.statGrid,children:[e.jsxs("div",{className:Z.stat,children:[e.jsx("div",{className:Z.statLabel,children:o("importPreviewDialog.walls","Walls")}),e.jsx("div",{className:Z.statValue,children:t.stats.wallsImported})]}),e.jsxs("div",{className:Z.stat,children:[e.jsx("div",{className:Z.statLabel,children:o("importPreviewDialog.zones","Zones")}),e.jsx("div",{className:Z.statValue,children:t.stats.zonesImported})]}),e.jsxs("div",{className:Z.stat,children:[e.jsx("div",{className:Z.statLabel,children:o("importPreviewDialog.objects","Objects")}),e.jsx("div",{className:Z.statValue,children:t.stats.objectsImported})]}),e.jsxs("div",{className:Z.stat,children:[e.jsx("div",{className:Z.statLabel,children:o("importPreviewDialog.skipped","Skipped")}),e.jsx("div",{className:Z.statValue,children:t.stats.entitiesSkipped})]})]})]}),a&&a.layers.length>0&&e.jsxs("div",{className:Z.section,children:[e.jsxs("h3",{className:Z.sectionTitle,children:[e.jsx(Sn,{})," ",o("importPreviewDialog.layers","Layers ({layers})").replace("{layers}",String(a.layers.length))]}),e.jsxs("ul",{className:Z.layersList,children:[a.layers.slice(0,6).map((f,y)=>{var b;return e.jsxs("li",{className:Z.layer,children:[e.jsx("span",{className:Z.layerIcon,children:e.jsx(Sn,{})}),e.jsx("span",{className:Z.layerName,children:f.name}),e.jsx("span",{className:Z.layerCount,children:((b=f.objects)==null?void 0:b.length)||0})]},f.id||y)}),a.layers.length>6&&e.jsx("li",{className:Z.layer,children:e.jsx("span",{className:Z.layerName,children:o("importPreviewDialog.more","+{layers} more...").replace("{layers}",String(a.layers.length-6))})})]})]}),t.warnings.length>0&&e.jsxs("div",{className:Z.section,children:[e.jsxs("h3",{className:Z.sectionTitle,children:[e.jsx(In,{})," ",o("importPreviewDialog.warnings","Warnings ({warnings})").replace("{warnings}",String(t.warnings.length))]}),e.jsxs("ul",{className:Z.warningsList,children:[t.warnings.slice(0,5).map((f,y)=>e.jsxs("li",{className:Z.warning,children:[e.jsx("span",{className:Z.warningIcon,children:e.jsx(In,{})}),e.jsx("span",{children:f.message})]},y)),t.warnings.length>5&&e.jsx("li",{className:Z.warning,children:o("importPreviewDialog.moreWarnings","+{warnings} more warnings...").replace("{warnings}",String(t.warnings.length-5))})]})]}),p.length>0&&e.jsxs("div",{className:Z.section,children:[e.jsxs("h3",{className:Z.sectionTitle,children:[e.jsx(kn,{})," ",o("importPreviewDialog.errors","Errors ({nonFatalErrors})").replace("{nonFatalErrors}",String(p.length))]}),e.jsx("ul",{className:Z.warningsList,children:p.slice(0,5).map((f,y)=>e.jsxs("li",{className:Z.error,children:[e.jsx("span",{className:Z.errorIcon,children:e.jsx(kn,{})}),e.jsx("span",{children:f.message})]},y))})]}),t.warnings.length===0&&p.length===0&&e.jsx("div",{className:Z.section,children:e.jsxs("p",{className:Z.noWarnings,children:[e.jsx(N.NiceIcon,{name:"check",size:14})," ",o("importPreviewDialog.noWarningsOrErrorsFound","No warnings or errors found")]})})]})]}),e.jsxs("div",{className:Z.footer,children:[e.jsx("button",{className:Z.cancelButton,onClick:s,children:o("importPreviewDialog.cancel","Cancel")}),e.jsx("button",{className:Z.confirmButton,onClick:n,disabled:_,children:_?o("importPreviewDialog.cannotImportFatalErrors","Cannot Import (Fatal Errors)"):o("importPreviewDialog.confirmImport","Confirm Import")})]})]})})}const Va="_overlay_1jmp3_9",qa="_dialog_1jmp3_55",Wa="_header_1jmp3_103",Ha="_title_1jmp3_119",Ua="_closeButton_1jmp3_133",Ya="_content_1jmp3_167",Za="_description_1jmp3_179",Xa="_mappingTable_1jmp3_191",Ka="_sourceLayer_1jmp3_241",Ja="_layerIcon_1jmp3_253",Qa="_layerName_1jmp3_261",ei="_objectCount_1jmp3_273",ti="_targetSelect_1jmp3_285",ni="_skipOption_1jmp3_327",si="_arrowIcon_1jmp3_337",oi="_presets_1jmp3_347",ai="_presetButton_1jmp3_361",ii="_footer_1jmp3_393",ri="_footerLeft_1jmp3_413",ci="_checkbox_1jmp3_425",li="_checkboxLabel_1jmp3_437",di="_footerRight_1jmp3_447",ui="_cancelButton_1jmp3_457",pi="_confirmButton_1jmp3_489",ce={overlay:Va,dialog:qa,header:Wa,title:Ha,closeButton:Ua,content:Ya,description:Za,mappingTable:Xa,sourceLayer:Ka,layerIcon:Ja,layerName:Qa,objectCount:ei,targetSelect:ti,skipOption:ni,arrowIcon:si,presets:oi,presetButton:ai,footer:ii,footerLeft:ri,checkbox:ci,checkboxLabel:li,footerRight:di,cancelButton:ui,confirmButton:pi},Cn=()=>e.jsx(N.NiceIcon,{name:"close",size:20}),mi=()=>e.jsx(N.NiceIcon,{name:"layers",size:14}),hi=()=>e.jsx(N.NiceIcon,{name:"arrow-right",size:16}),Tn={"floor-plan":"Floor plan",walls:"Walls",rooms:"Rooms",zones:"Strefy","doors-windows":"Doors and windows",furniture:"Meble",devices:"Devices",network:"Network",infrastructure:"Infrastruktura",electrical:"Elektryka",plumbing:"Hydraulika",hvac:"HVAC",annotations:"Adnotacje",dimensions:"Wymiary",grid:"Siatka",background:"Background","game-objects":"Obiekty gry",collision:"Kolizje",custom:"Custom"};function gi(t){if(!t.document)return[];const n=[];for(const s of t.document.floors)for(const o of s.layers)n.push({id:o.id,name:o.name,type:o.type,objectCount:o.objects.length});return n}function fi(t){if(!t)return[];const n=[];for(const s of t.floors)for(const o of s.layers)n.find(i=>i.id===o.id)||n.push(o);return n}function Ln(t,n){const s=new Map;for(const o of t){const i=n.find(r=>r.type===o.type);if(i){s.set(o.id,i.id);continue}const a=o.name.toLowerCase(),c=n.find(r=>r.name.toLowerCase()===a);if(c){s.set(o.id,c.id);continue}s.set(o.id,o.id)}return s}const _i=({importResult:t,existingDocument:n,onConfirm:s,onCancel:o})=>{const{t:i}=N.useNiceTranslation(),a=u.useMemo(()=>gi(t),[t]),c=u.useMemo(()=>fi(n),[n]),[r,d]=u.useState(()=>Ln(a,c)),[_,p]=u.useState(!0),f=u.useCallback((x,C)=>{d(g=>{const L=new Map(g);return L.set(x,C),L})},[]),y=u.useCallback(x=>{const C=new Map;switch(x){case"auto":d(Ln(a,c));return;case"skip-all":for(const g of a)C.set(g.id,"skip");break;case"preserve":for(const g of a)C.set(g.id,g.id);break}d(C)},[a,c]),b=u.useCallback(()=>{s(r,_)},[r,_,s]),j=u.useCallback(x=>{x.key==="Escape"?o():x.key==="Enter"&&(x.ctrlKey||x.metaKey)&&b()},[o,b]),w=u.useCallback(x=>{x.target===x.currentTarget&&o()},[o]);return a.length===0?e.jsx("div",{className:ce.overlay,onClick:w,onKeyDown:j,tabIndex:-1,children:e.jsxs("div",{className:ce.dialog,children:[e.jsxs("div",{className:ce.header,children:[e.jsx("h2",{className:ce.title,children:i("buildings.layerMapping","Layer mapping")}),e.jsx("button",{className:ce.closeButton,onClick:o,children:e.jsx(Cn,{})})]}),e.jsx("div",{className:ce.content,children:e.jsx("p",{className:ce.description,children:i("buildings.spatial.noLayersInFile","The imported file contains no layers.")})}),e.jsxs("div",{className:ce.footer,children:[e.jsx("div",{className:ce.footerLeft}),e.jsx("div",{className:ce.footerRight,children:e.jsx("button",{className:ce.cancelButton,onClick:o,children:i("buildings.spatial.close","Close")})})]})]})}):e.jsx("div",{className:ce.overlay,onClick:w,onKeyDown:j,tabIndex:-1,children:e.jsxs("div",{className:ce.dialog,children:[e.jsxs("div",{className:ce.header,children:[e.jsx("h2",{className:ce.title,children:i("buildings.layerMapping","Layer mapping")}),e.jsx("button",{className:ce.closeButton,onClick:o,children:e.jsx(Cn,{})})]}),e.jsxs("div",{className:ce.content,children:[e.jsx("p",{className:ce.description,children:i("buildings.spatial.mappingHint","Choose how the layers from the imported file map onto the editor layers.")}),e.jsxs("table",{className:ce.mappingTable,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:i("buildings.spatial.sourceLayer","Source layer")}),e.jsx("th",{}),e.jsx("th",{children:i("buildings.targetLayer","Target layer")})]})}),e.jsx("tbody",{children:a.map(x=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsxs("div",{className:ce.sourceLayer,children:[e.jsx("span",{className:ce.layerIcon,children:e.jsx(mi,{})}),e.jsx("span",{className:ce.layerName,children:x.name}),e.jsxs("span",{className:ce.objectCount,children:["(",x.objectCount," ",x.objectCount===1?i("buildings.spatial.object","object"):i("buildings.spatial.objects","objects"),")"]})]})}),e.jsx("td",{className:ce.arrowIcon,children:e.jsx(hi,{})}),e.jsx("td",{children:e.jsxs("select",{className:ce.targetSelect,value:r.get(x.id)||x.id,onChange:C=>f(x.id,C.target.value),children:[e.jsxs("option",{value:"skip",className:ce.skipOption,children:["— ",i("buildings.spatial.skipLayer","Skip this layer")," —"]}),e.jsxs("option",{value:x.id,children:[i("buildings.spatial.create","Create"),": ",x.name," (",Tn[x.type],")"]}),c.map(C=>e.jsxs("option",{value:C.id,children:[C.name," (",Tn[C.type],")"]},C.id))]})})]},x.id))})]}),e.jsxs("div",{className:ce.presets,children:[e.jsx("button",{className:ce.presetButton,onClick:()=>y("auto"),children:i("buildings.autoMapping","Auto-mapping")}),e.jsx("button",{className:ce.presetButton,onClick:()=>y("preserve"),children:i("buildings.spatial.keepAll","Keep all")}),e.jsx("button",{className:ce.presetButton,onClick:()=>y("skip-all"),children:i("buildings.spatial.skipAll","Skip all")})]})]}),e.jsxs("div",{className:ce.footer,children:[e.jsxs("div",{className:ce.footerLeft,children:[e.jsx("input",{type:"checkbox",id:"createMissing",className:ce.checkbox,checked:_,onChange:x=>p(x.target.checked)}),e.jsx("label",{htmlFor:"createMissing",className:ce.checkboxLabel,children:i("buildings.spatial.createMissing","Create the missing layers")})]}),e.jsxs("div",{className:ce.footerRight,children:[e.jsx("button",{className:ce.cancelButton,onClick:o,children:i("buildings.spatial.cancel","Cancel")}),e.jsx("button",{className:ce.confirmButton,onClick:b,children:i("buildings.spatial.applyMapping","Apply mapping")})]})]})]})})},bi="_root_1apji_9",yi="_header_1apji_21",xi="_title_1apji_31",vi="_layerList_1apji_45",ji="_layerItem_1apji_55",wi="_hidden_1apji_83",Ni="_locked_1apji_91",Ii="_visibilityBtn_1apji_99",ki="_lockBtn_1apji_101",Si="_layerIcon_1apji_139",Ci="_layerName_1apji_147",Ti="_opacitySlider_1apji_157",Li="_collapseToggle_1apji_173",Le={root:bi,header:yi,title:xi,layerList:vi,layerItem:ji,hidden:wi,locked:Ni,visibilityBtn:Ii,lockBtn:ki,layerIcon:Si,layerName:Ci,opacitySlider:Ti,collapseToggle:Li},$i={"floor-plan":{icon:"home",label:"Floor Plan"},zones:{icon:"hexagon",label:"Zones"},devices:{icon:"wifi",label:"Devices"},furniture:{icon:"sofa",label:"Furniture"},network:{icon:"globe",label:"Network"},infrastructure:{icon:"settings",label:"Infrastructure"},annotations:{icon:"edit",label:"Annotations"},dimensions:{icon:"ruler",label:"Dimensions"},grid:{icon:"grid",label:"Grid"},background:{icon:"image",label:"Background"},"game-objects":{icon:"gamepad",label:"Game Objects"},collision:{icon:"square",label:"Collision"}},Jn=({layers:t,onVisibilityToggle:n,onLockToggle:s,onOpacityChange:o,className:i,collapsed:a=!1,onToggleCollapsed:c})=>{const{t:r}=N.useNiceTranslation(),d=[...t].sort((_,p)=>p.zIndex-_.zIndex);return e.jsxs("div",{className:`${Le.root} ${i??""}`,children:[e.jsx("div",{className:Le.header,children:e.jsx("h3",{className:Le.title,children:c?e.jsxs("button",{type:"button",className:Le.collapseToggle,"aria-expanded":!a,onClick:c,children:[e.jsx(N.NiceIcon,{name:a?"chevron-right":"chevron-down",size:14}),r("layerPanel.layers","Layers")]}):r("layerPanel.layers","Layers")})}),!a&&e.jsx("div",{className:Le.layerList,children:d.map(_=>{const p=$i[_.type]||{icon:"box",label:_.type};return e.jsxs("div",{className:`${Le.layerItem} ${_.visible?"":Le.hidden} ${_.locked?Le.locked:""}`,children:[e.jsx("button",{className:Le.visibilityBtn,onClick:()=>n(_.type),title:_.visible?r("layerPanel.hideLayer","Hide layer"):r("layerPanel.showLayer","Show layer"),children:e.jsx(N.NiceIcon,{name:_.visible?"eye":"eye-off",size:16})}),e.jsx("button",{className:Le.lockBtn,onClick:()=>s(_.type),title:_.locked?r("layerPanel.unlockLayer","Unlock layer"):r("layerPanel.lockLayer","Lock layer"),children:e.jsx(N.NiceIcon,{name:"lock",size:16})}),e.jsx("span",{className:Le.layerIcon,children:e.jsx(N.NiceIcon,{name:p.icon,size:16})}),e.jsx("span",{className:Le.layerName,children:p.label}),e.jsx("input",{type:"range",min:"0",max:"1",step:"0.1",value:_.opacity,onChange:f=>o(_.type,parseFloat(f.target.value)),className:Le.opacitySlider,title:r("layerPanel.opacity","Opacity: {opacity}%").replace("{opacity}",String(Math.round(_.opacity*100)))})]},_.type)})})]})};function it(t){return t.find(n=>n.type==="zones")??t.find(n=>n.name==="zones")}function Ht(t){var o;const n=t,s=n.boundary??((o=t.metadata)==null?void 0:o.points)??n.polygon;return Array.isArray(s)&&s.length>=3?s:null}function Ft(t){var s,o;return t.color??((s=t.metadata)==null?void 0:s.fill)??((o=t.style)==null?void 0:o.fill)}function dn(t){const n=t;return n.start&&n.end?{start:n.start,end:n.end}:null}function zi(t){const n=t.metadata;return t.type==="connection"&&(n!=null&&n.sourcePosition)&&n.targetPosition?{start:n.sourcePosition,end:n.targetPosition}:null}function It(t){var i,a,c;if(t.bounds)return t.bounds;const n=(i=t.transform)==null?void 0:i.position;if(n)return{x:n.x,y:n.y,width:((a=t.size)==null?void 0:a.width)??24,height:((c=t.size)==null?void 0:c.height)??24};const s=Ht(t);if(s)return Gt(s);const o=dn(t);return o?Gt([o.start,o.end]):null}function Pi(t,n,s){const o=c=>({...c,x:c.x+n,y:c.y+s}),i=t,a={};if(t.bounds&&(a.bounds={...t.bounds,x:t.bounds.x+n,y:t.bounds.y+s}),t.transform&&(a.transform={...t.transform,position:o(t.transform.position)}),t.position&&(a.position=o(t.position)),i.start&&(a.start=o(i.start)),i.end&&(a.end=o(i.end)),i.boundary&&(a.boundary=i.boundary.map(o)),i.polygon&&(a.polygon=i.polygon.map(o)),t.metadata){const c={...t.metadata};Array.isArray(c.points)&&(c.points=c.points.map(o));for(const r of["sourcePosition","targetPosition"]){const d=c[r];d&&(c[r]=o(d))}a.metadata=c}return a}function nn(t){if(t.position)return t.position;const n=It(t);return n?{x:n.x+n.width/2,y:n.y+n.height/2}:null}function $n(t){if(t.size)return t.size;const n=It(t);return n?{width:n.width,height:n.height}:{width:20,height:20}}function Gt(t){const n=t.map(a=>a.x),s=t.map(a=>a.y),o=Math.min(...n),i=Math.min(...s);return{x:o,y:i,width:Math.max(...n)-o,height:Math.max(...s)-i}}const Ei="_root_1lufq_9",Oi="_svg_1lufq_31",Mi="_viewportRect_1lufq_41",Ai="_zoomIndicator_1lufq_49",Et={root:Ei,svg:Oi,viewportRect:Mi,zoomIndicator:Ai},un=({document:t,activeFloorId:n,viewport:s,onViewportChange:o,size:i=150,className:a})=>{var L,m;const c=u.useRef(null),r=u.useMemo(()=>t.floors.find(k=>k.id===n)??t.floors[0]??null,[t,n]),d=((L=r==null?void 0:r.dimensions)==null?void 0:L.width)??1e3,_=((m=r==null?void 0:r.dimensions)==null?void 0:m.height)??800,p=Math.min(i/d,i/_)*.9,f=d*p,y=_*p,b=i/s.zoom*p,j=i/s.zoom*p,w=-s.pan.x/s.zoom*p,x=-s.pan.y/s.zoom*p,C=u.useCallback(k=>{var B;const l=(B=c.current)==null?void 0:B.getBoundingClientRect();if(!l)return;const I=(k.clientX-l.left-(i-f)/2)/p,h=(k.clientY-l.top-(i-y)/2)/p,F=-(I-i/s.zoom/2)*s.zoom,T=-(h-i/s.zoom/2)*s.zoom;o({pan:{x:F,y:T}})},[p,i,f,y,s.zoom,o]),g=u.useMemo(()=>{const k=r?it(r.layers):void 0;return k?k.objects.map(l=>{const I=Ht(l);if(!I)return null;const h=I.map((F,T)=>`${T===0?"M":"L"}${F.x*p},${F.y*p}`).join(" ")+" Z";return e.jsx("path",{d:h,fill:Ft(l)??"var(--nice-primary-bg, #dbeafe)",fillOpacity:.6,stroke:"var(--nice-text-muted, #94a3b8)",strokeWidth:.5},l.id)}):null},[r,p]);return r?e.jsxs("div",{className:`${Et.root} ${a??""}`,children:[e.jsxs("svg",{ref:c,width:i,height:i,viewBox:`0 0 ${i} ${i}`,className:Et.svg,onClick:C,children:[e.jsx("rect",{x:(i-f)/2,y:(i-y)/2,width:f,height:y,fill:"var(--nice-bg-secondary, #1e293b)",stroke:"var(--nice-border-color, #475569)",strokeWidth:1}),e.jsx("g",{transform:`translate(${(i-f)/2}, ${(i-y)/2})`,children:g}),e.jsx("rect",{x:(i-f)/2+w,y:(i-y)/2+x,width:Math.min(b,f),height:Math.min(j,y),fill:"var(--nice-primary-tint-20, rgba(59, 130, 246, 0.2))",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:1.5,rx:2,className:Et.viewportRect})]}),e.jsxs("div",{className:Et.zoomIndicator,children:[Math.round(s.zoom*100),"%"]})]}):null},Di="_panel_1jo5f_9",Bi="_header_1jo5f_27",Ri="_title_1jo5f_45",Fi="_closeButton_1jo5f_59",Gi="_content_1jo5f_85",Vi="_endpointSection_1jo5f_99",qi="_endpointLabel_1jo5f_107",Wi="_endpointSelect_1jo5f_123",Hi="_optionsSection_1jo5f_157",Ui="_metricButton_1jo5f_169",Yi="_metricButtonActive_1jo5f_205",Zi="_analyzeButton_1jo5f_219",Xi="_resultsSection_1jo5f_267",Ki="_resultsTitle_1jo5f_277",Ji="_noResults_1jo5f_293",Qi="_pathCard_1jo5f_309",er="_pathCardSelected_1jo5f_333",tr="_pathCardHeader_1jo5f_343",nr="_pathCardTitle_1jo5f_361",sr="_pathBadge_1jo5f_373",or="_badgePrimary_1jo5f_389",ar="_badgeAlternate_1jo5f_399",ir="_pathName_1jo5f_409",rr="_pathStatus_1jo5f_421",cr="_statusDot_1jo5f_435",lr="_statusActive_1jo5f_447",dr="_statusDegraded_1jo5f_453",ur="_statusInactive_1jo5f_459",pr="_statusError_1jo5f_465",mr="_pathStats_1jo5f_475",hr="_statItem_1jo5f_489",gr="_statValue_1jo5f_497",fr="_statLabel_1jo5f_509",_r="_pathVisualization_1jo5f_523",br="_pathDiagram_1jo5f_535",yr="_pathNode_1jo5f_551",xr="_pathNodeStart_1jo5f_583",vr="_pathNodeEnd_1jo5f_585",jr="_pathLink_1jo5f_595",wr="_pathLinkLine_1jo5f_607",Nr="_showOnMapButton_1jo5f_621",Ir="_loading_1jo5f_657",kr="_spinner_1jo5f_671",Sr="_spin_1jo5f_671",Y={panel:Di,header:Bi,title:Ri,closeButton:Fi,content:Gi,endpointSection:Vi,endpointLabel:qi,endpointSelect:Wi,optionsSection:Hi,metricButton:Ui,metricButtonActive:Yi,analyzeButton:Zi,resultsSection:Xi,resultsTitle:Ki,noResults:Ji,pathCard:Qi,pathCardSelected:er,pathCardHeader:tr,pathCardTitle:nr,pathBadge:sr,badgePrimary:or,badgeAlternate:ar,pathName:ir,pathStatus:rr,statusDot:cr,statusActive:lr,statusDegraded:dr,statusInactive:ur,statusError:pr,pathStats:mr,statItem:hr,statValue:gr,statLabel:fr,pathVisualization:_r,pathDiagram:br,pathNode:yr,pathNodeStart:xr,pathNodeEnd:vr,pathLink:jr,pathLinkLine:wr,showOnMapButton:Nr,loading:Ir,spinner:kr,spin:Sr},Cr=()=>e.jsx(N.NiceIcon,{name:"close",size:16}),Tr=()=>e.jsx(N.NiceIcon,{name:"arrow-right",size:16});function Lr(t,n){switch(t){case"active":return n("buildings.connectionStatus.active","Active");case"degraded":return n("buildings.connectionStatus.degraded","Degraded");case"inactive":return n("buildings.connectionStatus.inactive","Inactive");case"error":return n("buildings.connectionStatus.error","Error");default:return n("buildings.connectionStatus.unknown","Unknown")}}function $r(t){return t<1?"<1ms":t<1e3?`${Math.round(t)}ms`:`${(t/1e3).toFixed(1)}s`}function zr(t){return t>=1e3?`${(t/1e3).toFixed(1)} Gbps`:`${Math.round(t)} Mbps`}const Pr=({document:t,connections:n,onHighlightPath:s,onClose:o})=>{const{t:i}=N.useNiceTranslation(),[a,c]=u.useState(""),[r,d]=u.useState(""),[_,p]=u.useState("latency"),[f,y]=u.useState([]),[b,j]=u.useState(null),[w,x]=u.useState(!1),C=u.useMemo(()=>{const l=[];for(const I of t.floors)for(const h of I.layers)if(h.type==="network"||h.type==="devices"||h.type==="infrastructure")for(const F of h.objects)l.push({id:F.id,name:F.name??F.id});return l},[t]),g=u.useCallback(l=>{var I;return((I=C.find(h=>h.id===l))==null?void 0:I.name)??l},[C]),L=u.useCallback(()=>{!a||!r||a===r||(x(!0),y([]),j(null),setTimeout(()=>{const l=Wo(n,a,r,_),I=Ho(n,a,r,5),h=[];l&&h.push(l);for(const F of I)h.some(T=>T.connectionIds.length===F.connectionIds.length&&T.connectionIds.every((B,H)=>F.connectionIds[H]===B))||h.push({...F,isPrimary:!1});y(h),h.length>0&&(j(h[0].id),s==null||s(h[0])),x(!1)},300))},[a,r,_,n,s]),m=u.useCallback(l=>{j(l.id),s==null||s(l)},[s]),k=u.useCallback(l=>{const I=[l.startDeviceId];for(const h of l.connectionIds){const F=n.find(T=>T.id===h);if(F){const T=I[I.length-1],B=F.sourceId===T?F.targetId:F.sourceId;I.includes(B)||I.push(B)}}return I},[n]);return e.jsxs("div",{className:Y.panel,children:[e.jsxs("div",{className:Y.header,children:[e.jsx("h3",{className:Y.title,children:i("buildings.spatial.pathAnalysis","Network path analysis")}),o&&e.jsx("button",{className:Y.closeButton,onClick:o,children:e.jsx(Cr,{})})]}),e.jsxs("div",{className:Y.content,children:[e.jsxs("div",{className:Y.endpointSection,children:[e.jsx("label",{className:Y.endpointLabel,children:i("buildings.spatial.sourceDevice","Source device")}),e.jsxs("select",{className:Y.endpointSelect,value:a,onChange:l=>c(l.target.value),children:[e.jsxs("option",{value:"",children:["— ",i("buildings.spatial.selectDevice","Select a device")," —"]}),C.map(l=>e.jsx("option",{value:l.id,children:l.name},l.id))]})]}),e.jsxs("div",{className:Y.endpointSection,children:[e.jsx("label",{className:Y.endpointLabel,children:i("buildings.spatial.targetDevice","Target device")}),e.jsxs("select",{className:Y.endpointSelect,value:r,onChange:l=>d(l.target.value),children:[e.jsxs("option",{value:"",children:["— ",i("buildings.spatial.selectDevice","Select a device")," —"]}),C.filter(l=>l.id!==a).map(l=>e.jsx("option",{value:l.id,children:l.name},l.id))]})]}),e.jsxs("div",{className:Y.optionsSection,children:[e.jsx("button",{className:`${Y.metricButton} ${_==="latency"?Y.metricButtonActive:""}`,onClick:()=>p("latency"),children:i("buildings.latency","Latency")}),e.jsx("button",{className:`${Y.metricButton} ${_==="hops"?Y.metricButtonActive:""}`,onClick:()=>p("hops"),children:i("buildings.hops","Hops")}),e.jsx("button",{className:`${Y.metricButton} ${_==="bandwidth"?Y.metricButtonActive:""}`,onClick:()=>p("bandwidth"),children:i("buildings.spatial.bandwidth","Bandwidth")})]}),e.jsx("button",{className:Y.analyzeButton,onClick:L,disabled:!a||!r||a===r||w,children:w?i("buildings.spatial.analysing","Analysing…"):i("buildings.spatial.analysePath","Analyse the path")}),w?e.jsx("div",{className:Y.loading,children:e.jsx("div",{className:Y.spinner})}):f.length>0?e.jsxs("div",{className:Y.resultsSection,children:[e.jsxs("div",{className:Y.resultsTitle,children:[i("buildings.spatial.pathsFound","Paths found")," (",f.length,")"]}),f.map((l,I)=>{const h=k(l),F=b===l.id;return e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:N.clickOnActivationKey,className:`${Y.pathCard} ${F?Y.pathCardSelected:""}`,onClick:()=>m(l),children:[e.jsxs("div",{className:Y.pathCardHeader,children:[e.jsxs("div",{className:Y.pathCardTitle,children:[e.jsx("span",{className:`${Y.pathBadge} ${l.isPrimary?Y.badgePrimary:Y.badgeAlternate}`,children:l.isPrimary?i("buildings.optimal","Optimal"):i("buildings.alt","Alt {index}").replace("{index}",String(I))}),e.jsxs("span",{className:Y.pathName,children:[l.connectionIds.length," ",i("buildings.spatial.connections","connections")]})]}),e.jsxs("div",{className:Y.pathStatus,children:[e.jsx("span",{className:`${Y.statusDot} ${Y[`status${l.status.charAt(0).toUpperCase()+l.status.slice(1)}`]??""}`}),e.jsx("span",{children:Lr(l.status,i)})]})]}),e.jsxs("div",{className:Y.pathStats,children:[e.jsxs("div",{className:Y.statItem,children:[e.jsx("div",{className:Y.statValue,children:$r(l.totalLatency)}),e.jsx("div",{className:Y.statLabel,children:i("buildings.latency","Latency")})]}),e.jsxs("div",{className:Y.statItem,children:[e.jsx("div",{className:Y.statValue,children:l.connectionIds.length}),e.jsx("div",{className:Y.statLabel,children:i("buildings.hops","Hops")})]}),e.jsxs("div",{className:Y.statItem,children:[e.jsx("div",{className:Y.statValue,children:l.bottleneckBandwidth>0?zr(l.bottleneckBandwidth):"N/A"}),e.jsx("div",{className:Y.statLabel,children:i("buildings.spatial.bandwidth","Bandwidth")})]})]}),F&&e.jsxs("div",{className:Y.pathVisualization,children:[e.jsx("div",{className:Y.pathDiagram,children:h.map((T,B)=>e.jsxs(u.Fragment,{children:[e.jsx("div",{className:`${Y.pathNode} ${B===0?Y.pathNodeStart:B===h.length-1?Y.pathNodeEnd:""}`,children:g(T).substring(0,8)}),B<h.length-1&&e.jsxs("div",{className:Y.pathLink,children:[e.jsx("div",{className:Y.pathLinkLine}),e.jsx(Tr,{})]})]},T))}),e.jsx("button",{className:Y.showOnMapButton,onClick:T=>{T.stopPropagation(),s==null||s(l)},children:i("buildings.spatial.showOnMap","Show on the map")})]})]},l.id)})]}):a&&r&&a!==r?e.jsx("div",{className:Y.noResults,children:i("buildings.spatial.noResultsHint","Pick two devices and run the analysis")}):e.jsx("div",{className:Y.noResults,children:i("buildings.spatial.pickEndpoints","Pick a source and a target device")})]})]})},Er="_root_6pirz_9",Or="_header_6pirz_27",Mr="_title_6pirz_37",Ar="_search_6pirz_51",Dr="_categories_6pirz_79",Br="_category_6pirz_91",Rr="_categoryHeader_6pirz_107",Fr="_categoryIcon_6pirz_143",Gr="_categoryLabel_6pirz_151",Vr="_categoryCount_6pirz_161",qr="_expandIcon_6pirz_171",Wr="_items_6pirz_181",Hr="_item_6pirz_181",Ur="_itemIcon_6pirz_241",Yr="_itemName_6pirz_249",Zr="_emptyState_6pirz_269",Ie={root:Er,header:Or,title:Mr,search:Ar,categories:Dr,category:Br,categoryHeader:Rr,categoryIcon:Fr,categoryLabel:Gr,categoryCount:Vr,expandIcon:qr,items:Wr,item:Hr,itemIcon:Ur,itemName:Yr,emptyState:Zr},Xr=t=>t&&/^[a-z][a-z0-9-]*$/.test(t)?t:"box",Kr={"floor-plan":["smart-home","building"],"network-topology":["network"],infrastructure:["infrastructure","network"],cad:["building"],interior:["furniture","smart-home","building"],"game-scene":["game"]},Jr=new Set(["bld-wall"]),Qr={"smart-home":{icon:"home",label:"Smart Home"},furniture:{icon:"sofa",label:"Furniture"},network:{icon:"globe",label:"Network"},infrastructure:{icon:"settings",label:"Infrastructure"},building:{icon:"building",label:"Building"},zone:{icon:"map-pin",label:"Zones"},game:{icon:"gamepad",label:"Game Objects"},annotation:{icon:"edit",label:"Annotations"}},Qn=({mode:t,onObjectSelect:n,customObjects:s=[],className:o})=>{const{t:i}=N.useNiceTranslation(),[a,c]=u.useState(""),[r,d]=u.useState(new Set(["smart-home","furniture","network"])),_=u.useMemo(()=>Kr[t]||[],[t]),p=u.useMemo(()=>{const b={},j=To.reduce((w,x)=>{var C;return(w[C=x.category]??(w[C]=[])).push(x),w},{});return Object.entries(j).forEach(([w,x])=>{if(!_.includes(w))return;const C=x.filter(g=>!Jr.has(g.id)&&(!a||g.name.toLowerCase().includes(a.toLowerCase())));C.length>0&&(b[w]=C.map(g=>({id:g.id,name:g.name,category:w,icon:g.icon})))}),s.forEach(w=>{_.includes(w.category)&&(!a||w.name.toLowerCase().includes(a.toLowerCase()))&&(b[w.category]||(b[w.category]=[]),b[w.category].push(w))}),b},[_,a,s]),f=b=>{d(j=>{const w=new Set(j);return w.has(b)?w.delete(b):w.add(b),w})},y=(b,j)=>{b.dataTransfer.setData("application/json",JSON.stringify(j)),b.dataTransfer.effectAllowed="copy"};return e.jsxs("div",{className:`${Ie.root} ${o??""}`,children:[e.jsxs("div",{className:Ie.header,children:[e.jsx("h3",{className:Ie.title,children:i("objectLibrary.toolbox","Toolbox")}),e.jsx("input",{type:"text",className:Ie.search,placeholder:i("objectLibrary.search","Search..."),value:a,onChange:b=>c(b.target.value)})]}),e.jsxs("div",{className:Ie.categories,children:[Object.entries(p).map(([b,j])=>{const w=Qr[b]||{icon:"box",label:b},x=r.has(b);return e.jsxs("div",{className:Ie.category,children:[e.jsxs("button",{className:Ie.categoryHeader,onClick:()=>f(b),children:[e.jsx("span",{className:Ie.categoryIcon,children:e.jsx(N.NiceIcon,{name:w.icon,size:16})}),e.jsx("span",{className:Ie.categoryLabel,children:w.label}),e.jsxs("span",{className:Ie.categoryCount,children:["(",j.length,")"]}),e.jsx("span",{className:Ie.expandIcon,children:e.jsx(N.NiceIcon,{name:x?"chevron-down":"chevron-right",size:14})})]}),x&&e.jsx("div",{className:Ie.items,children:j.map(C=>e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:N.clickOnActivationKey,className:Ie.item,draggable:!0,onDragStart:g=>y(g,C),onClick:()=>n(C),title:C.name,children:[e.jsx("span",{className:Ie.itemIcon,children:e.jsx(N.NiceIcon,{name:Xr(C.icon),size:16})}),e.jsx("span",{className:Ie.itemName,children:C.name})]},C.id))})]},b)}),Object.keys(p).length===0&&e.jsx("div",{className:Ie.emptyState,children:a?i("objectLibrary.noObjectsMatching",'No objects matching "{searchQuery}"').replace("{searchQuery}",String(a)):i("objectLibrary.noObjectsAvailableForThis","No objects available for this mode")})]})]})},ec="_root_140af_9",tc="_header_140af_23",nc="_title_140af_39",sc="_multiSelect_140af_53",oc="_content_140af_63",ac="_section_140af_73",ic="_sectionHeader_140af_89",rc="_sectionContent_140af_127",cc="_fieldRow_140af_135",lc="_fieldLabel_140af_157",dc="_textInput_140af_169",uc="_numberInput_140af_171",pc="_select_140af_173",mc="_checkbox_140af_215",hc="_colorInput_140af_227",gc="_readOnly_140af_245",fc="_emptyState_140af_263",_c="_collapseToggle_140af_285",ae={root:ec,header:tc,title:nc,multiSelect:sc,content:oc,section:ac,sectionHeader:ic,sectionContent:rc,fieldRow:cc,fieldLabel:lc,textInput:dc,numberInput:uc,select:pc,checkbox:mc,colorInput:hc,readOnly:gc,emptyState:fc,collapseToggle:_c},sn=[{key:"name",label:"Name",type:"text"},{key:"position.x",label:"X",type:"number",step:1},{key:"position.y",label:"Y",type:"number",step:1},{key:"rotation",label:"Rotation",type:"number",min:0,max:360,step:1},{key:"visible",label:"Visible",type:"boolean"},{key:"locked",label:"Locked",type:"boolean"}],bc=[{key:"type",label:"Zone Type",type:"select",options:[{value:"living_room",label:"Living Room"},{value:"bedroom",label:"Bedroom"},{value:"bathroom",label:"Bathroom"},{value:"kitchen",label:"Kitchen"},{value:"office",label:"Office"},{value:"hallway",label:"Hallway"},{value:"other",label:"Other"}]},{key:"color",label:"Color",type:"color"},{key:"opacity",label:"Opacity",type:"number",min:0,max:1,step:.1}],yc=[{key:"deviceType",label:"Device Type",type:"text"},{key:"status",label:"Status",type:"select",options:[{value:"online",label:"Online"},{value:"offline",label:"Offline"},{value:"error",label:"Error"}]}],es=({selection:t,document:n,onPropertyChange:s,className:o,collapsed:i=!1,onToggleCollapsed:a})=>{const{t:c}=N.useNiceTranslation(),[r,d]=u.useState(new Set(["general","position","appearance"])),_=t.objectIds.map(g=>{for(const L of n.floors)for(const m of L.layers){const k=m.objects.find(l=>l.id===g);if(k)return k}return null}).filter(Boolean),p=g=>{d(L=>{const m=new Set(L);return m.has(g)?m.delete(g):m.add(g),m})},f=u.useCallback((g,L)=>{if(L==="position.x"||L==="position.y"){const l=It(g);return l?L==="position.x"?l.x:l.y:void 0}const m=L.split(".");let k=g;for(const l of m)if(k&&typeof k=="object"&&l in k)k=k[l];else return;return k},[]),y=u.useCallback((g,L)=>{var k;const m=f(L,g.key);switch(g.type){case"text":return e.jsx("input",{type:"text",value:String(m??""),onChange:l=>s(L.id,g.key,l.target.value),className:ae.textInput});case"number":return e.jsx("input",{type:"number",value:Number(m??0),min:g.min,max:g.max,step:g.step,onChange:l=>s(L.id,g.key,parseFloat(l.target.value)),className:ae.numberInput});case"boolean":return e.jsx("input",{type:"checkbox",checked:!!m,onChange:l=>s(L.id,g.key,l.target.checked),className:ae.checkbox});case"color":return e.jsx("input",{type:"color",value:String(m??"var(--nice-bg, #fff)"),onChange:l=>s(L.id,g.key,l.target.value),className:ae.colorInput});case"select":return e.jsx("select",{value:String(m??""),onChange:l=>s(L.id,g.key,l.target.value),className:ae.select,children:(k=g.options)==null?void 0:k.map(l=>e.jsx("option",{value:l.value,children:l.label},l.value))});default:return e.jsx("span",{children:String(m??"-")})}},[f,s]),b=c("propertiesPanel.properties","Properties"),j=e.jsx("h3",{className:ae.title,children:a?e.jsxs("button",{type:"button",className:ae.collapseToggle,"aria-expanded":!i,onClick:a,children:[e.jsx(N.NiceIcon,{name:i?"chevron-right":"chevron-down",size:14}),b]}):b});if(_.length===0)return e.jsxs("div",{className:`${ae.root} ${o??""}`,children:[e.jsx("div",{className:ae.header,children:j}),!i&&e.jsx("div",{className:ae.emptyState,children:c("propertiesPanel.noObjectSelected","No object selected")})]});const w=_[0],x=_.length>1,C=w.category==="zone"?bc:["smart-home","network","infrastructure"].includes(w.category??"")?yc:[];return e.jsxs("div",{className:`${ae.root} ${o??""}`,children:[e.jsxs("div",{className:ae.header,children:[j,x&&e.jsx("span",{className:ae.multiSelect,children:c("propertiesPanel.selected","{selectedObjects} selected").replace("{selectedObjects}",String(_.length))})]}),!i&&e.jsxs("div",{className:ae.content,children:[e.jsxs("div",{className:ae.section,children:[e.jsxs("button",{className:ae.sectionHeader,onClick:()=>p("general"),children:[e.jsx("span",{children:e.jsx(N.NiceIcon,{name:r.has("general")?"chevron-down":"chevron-right",size:14})}),e.jsx("span",{children:c("propertiesPanel.general","General")})]}),r.has("general")&&e.jsxs("div",{className:ae.sectionContent,children:[sn.slice(0,1).map(g=>e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:g.label}),y(g,w)]},g.key)),e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:"ID"}),e.jsx("span",{className:ae.readOnly,children:w.id})]}),e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:c("propertiesPanel.category","Category")}),e.jsx("span",{className:ae.readOnly,children:w.category})]})]})]}),e.jsxs("div",{className:ae.section,children:[e.jsxs("button",{className:ae.sectionHeader,onClick:()=>p("position"),children:[e.jsx("span",{children:e.jsx(N.NiceIcon,{name:r.has("position")?"chevron-down":"chevron-right",size:14})}),e.jsx("span",{children:c("propertiesPanel.transform","Transform")})]}),r.has("position")&&e.jsx("div",{className:ae.sectionContent,children:sn.slice(1,4).map(g=>e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:g.label}),y(g,w)]},g.key))})]}),C.length>0&&e.jsxs("div",{className:ae.section,children:[e.jsxs("button",{className:ae.sectionHeader,onClick:()=>p("appearance"),children:[e.jsx("span",{children:e.jsx(N.NiceIcon,{name:r.has("appearance")?"chevron-down":"chevron-right",size:14})}),e.jsx("span",{children:c("propertiesPanel.appearance","Appearance")})]}),r.has("appearance")&&e.jsx("div",{className:ae.sectionContent,children:C.map(g=>e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:g.label}),y(g,w)]},g.key))})]}),e.jsxs("div",{className:ae.section,children:[e.jsxs("button",{className:ae.sectionHeader,onClick:()=>p("visibility"),children:[e.jsx("span",{children:e.jsx(N.NiceIcon,{name:r.has("visibility")?"chevron-down":"chevron-right",size:14})}),e.jsx("span",{children:c("propertiesPanel.visibility","Visibility")})]}),r.has("visibility")&&e.jsx("div",{className:ae.sectionContent,children:sn.slice(4).map(g=>e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:g.label}),y(g,w)]},g.key))})]})]})]})},xc="_panel_18mro_9",vc="_header_18mro_33",jc="_headerTitle_18mro_51",wc="_title_18mro_65",Nc="_closeButton_18mro_79",Ic="_summarySection_18mro_111",kc="_summaryStats_18mro_129",Sc="_statBadge_18mro_141",Cc="_statValue_18mro_155",Tc="_statLabel_18mro_167",Lc="_visibilityControls_18mro_183",$c="_visibilityLabel_18mro_201",zc="_visibilityButtons_18mro_211",Pc="_visibilityBtn_18mro_221",Ec="_active_18mro_251",Oc="_content_18mro_265",Mc="_emptyState_18mro_279",Ac="_emptyHint_18mro_325",Dc="_vlanList_18mro_337",Bc="_vlanCard_18mro_351",Rc="_highlighted_18mro_377",Fc="_hidden_18mro_387",Gc="_vlanHeader_18mro_395",Vc="_colorIndicator_18mro_421",qc="_vlanInfo_18mro_435",Wc="_vlanName_18mro_445",Hc="_vlanId_18mro_459",Uc="_vlanNameText_18mro_471",Yc="_vlanSubnet_18mro_487",Zc="_vlanStats_18mro_503",Xc="_chipStat_18mro_515",Kc="_vlanActions_18mro_545",Jc="_iconBtn_18mro_557",Qc="_inactive_18mro_595",el="_expanded_18mro_611",tl="_vlanDetails_18mro_623",nl="_detailRow_18mro_635",sl="_detailLabel_18mro_657",ol="_detailValue_18mro_675",al="_badge_18mro_687",il="_badgeSuccess_18mro_701",rl="_badgeNeutral_18mro_711",cl="_deviceList_18mro_723",ll="_deviceItems_18mro_731",dl="_deviceItem_18mro_731",ul="_deviceDot_18mro_765",pl="_deviceMore_18mro_779",ml="_highlightButton_18mro_795",hl="_footer_18mro_835",gl="_legendTitle_18mro_847",fl="_legend_18mro_847",_l="_legendItem_18mro_875",bl="_legendColor_18mro_887",yl="_legendLabel_18mro_901",A={panel:xc,header:vc,headerTitle:jc,title:wc,closeButton:Nc,summarySection:Ic,summaryStats:kc,statBadge:Sc,statValue:Cc,statLabel:Tc,visibilityControls:Lc,visibilityLabel:$c,visibilityButtons:zc,visibilityBtn:Pc,active:Ec,content:Oc,emptyState:Mc,emptyHint:Ac,vlanList:Dc,vlanCard:Bc,highlighted:Rc,hidden:Fc,vlanHeader:Gc,colorIndicator:Vc,vlanInfo:qc,vlanName:Wc,vlanId:Hc,vlanNameText:Uc,vlanSubnet:Yc,vlanStats:Zc,chipStat:Xc,vlanActions:Kc,iconBtn:Jc,inactive:Qc,expanded:el,vlanDetails:tl,detailRow:nl,detailLabel:sl,detailValue:ol,badge:al,badgeSuccess:il,badgeNeutral:rl,deviceList:cl,deviceItems:ll,deviceItem:dl,deviceDot:ul,deviceMore:pl,highlightButton:ml,footer:hl,legendTitle:gl,legend:fl,legendItem:_l,legendColor:bl,legendLabel:yl},xl=()=>e.jsx(N.NiceIcon,{name:"close",size:16}),vl=()=>e.jsx(N.NiceIcon,{name:"eye",size:16}),jl=()=>e.jsx(N.NiceIcon,{name:"eye-off",size:16}),zn=()=>e.jsx(N.NiceIcon,{name:"git-branch",size:16}),wl=()=>e.jsx(N.NiceIcon,{name:"info",size:14});function Nl(t){var n;return((n=t.deviceIds)==null?void 0:n.length)??0}function Il(t,n){return n.filter(s=>s.vlanId===t.id).length}function kl(t){return t||"—"}const Sl=({document:t,connections:n,vlans:s,visibleVlanIds:o,onVlanVisibilityChange:i,onHighlightVlan:a,onClose:c})=>{const{t:r}=N.useNiceTranslation(),[d,_]=u.useState(null),[p,f]=u.useState(null),y=u.useMemo(()=>[...s].sort((m,k)=>m.id-k.id),[s]),b=u.useMemo(()=>{const m=new Set,k=new Set;for(const l of s)for(const I of l.deviceIds??[])m.add(I);for(const l of n)l.vlanId!==void 0&&k.add(l.id);return{vlanCount:s.length,deviceCount:m.size,connectionCount:k.size}},[s,n]),j=u.useCallback(m=>{const k=o.has(m);i==null||i(m,!k)},[o,i]),w=u.useCallback(m=>{for(const k of s)i==null||i(k.id,m)},[s,i]),x=u.useCallback(m=>{_((m==null?void 0:m.id)??null),a==null||a(m)},[a]),C=u.useCallback(m=>{f(k=>k===m?null:m)},[]),g=u.useCallback(m=>{const k=[];for(const l of m.deviceIds??[])for(const I of t.floors)for(const h of I.layers){const F=h.objects.find(T=>T.id===l);F&&k.push({id:l,name:F.name??l})}return k},[t]),L=u.useMemo(()=>{const m=s.filter(k=>o.has(k.id)).length;return{visible:m,total:s.length,allVisible:m===s.length,noneVisible:m===0}},[s,o]);return e.jsxs("div",{className:A.panel,children:[e.jsxs("div",{className:A.header,children:[e.jsxs("div",{className:A.headerTitle,children:[e.jsx(zn,{}),e.jsx("h3",{className:A.title,children:r("buildings.spatial.vlan.title","VLAN overlay")})]}),c&&e.jsx("button",{className:A.closeButton,onClick:c,title:r("buildings.spatial.close","Close"),children:e.jsx(xl,{})})]}),e.jsx("div",{className:A.summarySection,children:e.jsxs("div",{className:A.summaryStats,children:[e.jsxs("div",{className:A.statBadge,children:[e.jsx("span",{className:A.statValue,children:b.vlanCount}),e.jsx("span",{className:A.statLabel,children:r("buildings.vlan2","VLAN")})]}),e.jsxs("div",{className:A.statBadge,children:[e.jsx("span",{className:A.statValue,children:b.deviceCount}),e.jsx("span",{className:A.statLabel,children:r("buildings.spatial.devices","Devices")})]}),e.jsxs("div",{className:A.statBadge,children:[e.jsx("span",{className:A.statValue,children:b.connectionCount}),e.jsx("span",{className:A.statLabel,children:r("buildings.spatial.connectionsLabel","Connections")})]})]})}),e.jsxs("div",{className:A.visibilityControls,children:[e.jsxs("span",{className:A.visibilityLabel,children:[r("buildings.spatial.vlan.visibility","Visibility"),": ",L.visible,"/",L.total]}),e.jsxs("div",{className:A.visibilityButtons,children:[e.jsx("button",{className:`${A.visibilityBtn} ${L.allVisible?A.active:""}`,onClick:()=>w(!0),title:r("buildings.spatial.vlan.showAll","Show all"),children:r("buildings.spatial.vlan.all","All")}),e.jsx("button",{className:`${A.visibilityBtn} ${L.noneVisible?A.active:""}`,onClick:()=>w(!1),title:r("buildings.spatial.vlan.hideAll","Hide all"),children:r("buildings.spatial.vlan.none","None")})]})]}),e.jsx("div",{className:A.content,children:y.length===0?e.jsxs("div",{className:A.emptyState,children:[e.jsx(zn,{}),e.jsx("p",{children:r("buildings.spatial.vlan.empty","No VLANs defined")}),e.jsx("span",{className:A.emptyHint,children:r("buildings.spatial.vlan.emptyHint","Add a VLAN in network-topology or infrastructure mode")})]}):e.jsx("div",{className:A.vlanList,children:y.map(m=>{const k=o.has(m.id),l=d===m.id,I=p===m.id,h=Nl(m),F=Il(m,n),T=I?g(m):[];return e.jsxs("div",{className:`${A.vlanCard} ${l?A.highlighted:""} ${k?"":A.hidden}`,onMouseEnter:()=>x(m),onMouseLeave:()=>x(null),children:[e.jsxs("div",{className:A.vlanHeader,children:[e.jsx("div",{className:A.colorIndicator,style:{backgroundColor:m.color}}),e.jsxs("div",{className:A.vlanInfo,children:[e.jsxs("div",{className:A.vlanName,children:[e.jsx("span",{className:A.vlanId,children:r("buildings.vlan","VLAN {id}").replace("{id}",String(m.id))}),m.name&&e.jsx("span",{className:A.vlanNameText,children:m.name})]}),m.subnet&&e.jsx("div",{className:A.vlanSubnet,children:kl(m.subnet)})]}),e.jsxs("div",{className:A.vlanStats,children:[e.jsx("span",{className:A.chipStat,title:r("buildings.spatial.devices","Devices"),children:h}),e.jsx("span",{className:A.chipStat,title:r("buildings.spatial.connectionsLabel","Connections"),children:F})]}),e.jsxs("div",{className:A.vlanActions,children:[e.jsx("button",{className:`${A.iconBtn} ${k?"":A.inactive}`,onClick:B=>{B.stopPropagation(),j(m.id)},title:k?r("buildings.spatial.vlan.hide","Hide VLAN"):r("buildings.spatial.vlan.show","Show VLAN"),children:k?e.jsx(vl,{}):e.jsx(jl,{})}),e.jsx("button",{className:`${A.iconBtn} ${I?A.expanded:""}`,onClick:B=>{B.stopPropagation(),C(m.id)},title:r("buildings.spatial.details","Details"),children:e.jsx(wl,{})})]})]}),I&&e.jsxs("div",{className:A.vlanDetails,children:[m.description&&e.jsxs("div",{className:A.detailRow,children:[e.jsxs("span",{className:A.detailLabel,children:[r("buildings.spatial.vlan.description","Description"),":"]}),e.jsx("span",{className:A.detailValue,children:m.description})]}),m.subnet&&e.jsxs("div",{className:A.detailRow,children:[e.jsxs("span",{className:A.detailLabel,children:[r("buildings.spatial.vlan.subnet","Subnet"),":"]}),e.jsx("span",{className:A.detailValue,children:m.subnet})]}),m.gateway&&e.jsxs("div",{className:A.detailRow,children:[e.jsxs("span",{className:A.detailLabel,children:[r("buildings.spatial.vlan.gateway","Gateway"),":"]}),e.jsx("span",{className:A.detailValue,children:m.gateway})]}),e.jsxs("div",{className:A.detailRow,children:[e.jsx("span",{className:A.detailLabel,children:r("buildings.dhcp","DHCP:")}),e.jsx("span",{className:`${A.detailValue} ${A.badge} ${m.dhcpEnabled?A.badgeSuccess:A.badgeNeutral}`,children:m.dhcpEnabled?r("buildings.spatial.enabled","Enabled"):r("buildings.spatial.disabled","Disabled")})]}),T.length>0&&e.jsxs("div",{className:A.deviceList,children:[e.jsxs("span",{className:A.detailLabel,children:[r("buildings.spatial.devices","Devices")," (",T.length,"):"]}),e.jsxs("ul",{className:A.deviceItems,children:[T.slice(0,10).map(B=>e.jsxs("li",{className:A.deviceItem,children:[e.jsx("span",{className:A.deviceDot,style:{backgroundColor:m.color}}),B.name]},B.id)),T.length>10&&e.jsxs("li",{className:A.deviceMore,children:["… ",r("buildings.spatial.andMore","and")," ",T.length-10," ",r("buildings.spatial.more","more")]})]})]}),e.jsx("button",{className:A.highlightButton,onClick:()=>a==null?void 0:a(m),children:r("buildings.spatial.selectOnMap","Select on the map")})]})]},m.id)})})}),y.length>0&&e.jsxs("div",{className:A.footer,children:[e.jsx("div",{className:A.legendTitle,children:r("buildings.spatial.colourLegend","Colour legend")}),e.jsx("div",{className:A.legend,children:y.map(m=>e.jsxs("div",{className:A.legendItem,children:[e.jsx("span",{className:A.legendColor,style:{backgroundColor:m.color}}),e.jsxs("span",{className:A.legendLabel,children:[m.id,m.name?`: ${m.name}`:""]})]},m.id))})]})]})},Cl="_root_13d9j_9",Tl="_shell_13d9j_35",Ll="_dark_13d9j_43",$l="_topBar_13d9j_67",zl="_modeSwitcher_13d9j_85",Pl="_modeBtn_13d9j_95",El="_modeBtnActive_13d9j_131",Ol="_modeIcon_13d9j_143",Ml="_modeLabel_13d9j_151",Al="_floorTabs_13d9j_159",Dl="_floorTab_13d9j_159",Bl="_floorTabActive_13d9j_203",Rl="_viewportControls_13d9j_215",Fl="_active_13d9j_257",Gl="_disabled_13d9j_267",Vl="_separator_13d9j_281",ql="_zoomLevel_13d9j_295",Wl="_exportDropdown_13d9j_313",Hl="_exportMenu_13d9j_361",Ul="_editorContainer_13d9j_435",Yl="_toolbar_13d9j_461",Zl="_toolGroup_13d9j_481",Xl="_toolBtn_13d9j_509",Kl="_toolBtnActive_13d9j_549",Jl="_canvasWrapper_13d9j_573",Ql="_canvas_13d9j_573",ed="_cursor_select_13d9j_601",td="_cursor_multi_select_13d9j_607",nd="_cursor_pan_13d9j_613",sd="_cursor_zoom_13d9j_625",od="_cursor_draw_wall_13d9j_631",ad="_cursor_draw_zone_13d9j_633",id="_cursor_draw_polyline_13d9j_635",rd="_cursor_draw_rectangle_13d9j_637",cd="_cursor_draw_circle_13d9j_639",ld="_cursor_draw_arc_13d9j_641",dd="_cursor_place_device_13d9j_647",ud="_cursor_place_furniture_13d9j_649",pd="_cursor_place_network_13d9j_651",md="_cursor_place_infra_13d9j_653",hd="_cursor_place_door_13d9j_655",gd="_cursor_place_window_13d9j_657",fd="_cursor_place_stairs_13d9j_659",_d="_cursor_connect_13d9j_665",bd="_cursor_route_cable_13d9j_667",yd="_cursor_annotate_13d9j_673",xd="_cursor_dimension_13d9j_675",vd="_cursor_label_13d9j_677",jd="_cursor_measure_distance_13d9j_683",wd="_cursor_measure_angle_13d9j_685",Nd="_cursor_measure_area_13d9j_687",Id="_cursor_move_13d9j_693",kd="_cursor_rotate_13d9j_699",Sd="_cursor_scale_13d9j_705",Cd="_cursor_erase_13d9j_711",Td="_cursor_copy_13d9j_717",Ld="_cursor_paste_13d9j_719",$d="_grid_13d9j_729",zd="_gridLine_13d9j_735",Pd="_zonesLayer_13d9j_747",Ed="_zone_13d9j_747",Od="_zoneLabel_13d9j_763",Md="_objectsLayer_13d9j_777",Ad="_object_13d9j_777",Dd="_wall_13d9j_783",Bd="_objectLabel_13d9j_795",Rd="_connectionsLayer_13d9j_809",Fd="_connection_13d9j_809",Gd="_connectionPreview_13d9j_825",Vd="_guides_13d9j_835",qd="_guideLine_13d9j_841",Wd="_drawingPreview_13d9j_855",Hd="_rightSidebar_13d9j_867",Ud="_statusBar_13d9j_889",Yd="_modeIndicator_13d9j_911",Zd="_toolIndicator_13d9j_913",Xd="_selectionInfo_13d9j_925",Kd="_drawingInfo_13d9j_927",Jd="_connectingInfo_13d9j_941",Qd="_gridInfo_13d9j_955",eu="_emptyState_13d9j_967",tu="_emptyIcon_13d9j_989",nu="_primaryBtn_13d9j_1019",su="_modeActions_13d9j_1053",ou="_actionBtn_13d9j_1071",U={root:Cl,shell:Tl,dark:Ll,topBar:$l,modeSwitcher:zl,modeBtn:Pl,modeBtnActive:El,modeIcon:Ol,modeLabel:Ml,floorTabs:Al,floorTab:Dl,floorTabActive:Bl,viewportControls:Rl,active:Fl,disabled:Gl,separator:Vl,zoomLevel:ql,exportDropdown:Wl,exportMenu:Hl,editorContainer:Ul,toolbar:Yl,toolGroup:Zl,toolBtn:Xl,toolBtnActive:Kl,canvasWrapper:Jl,canvas:Ql,cursor_select:ed,cursor_multi_select:td,cursor_pan:nd,cursor_zoom:sd,cursor_draw_wall:od,cursor_draw_zone:ad,cursor_draw_polyline:id,cursor_draw_rectangle:rd,cursor_draw_circle:cd,cursor_draw_arc:ld,cursor_place_device:dd,cursor_place_furniture:ud,cursor_place_network:pd,cursor_place_infra:md,cursor_place_door:hd,cursor_place_window:gd,cursor_place_stairs:fd,cursor_connect:_d,cursor_route_cable:bd,cursor_annotate:yd,cursor_dimension:xd,cursor_label:vd,cursor_measure_distance:jd,cursor_measure_angle:wd,cursor_measure_area:Nd,cursor_move:Id,cursor_rotate:kd,cursor_scale:Sd,cursor_erase:Cd,cursor_copy:Td,cursor_paste:Ld,grid:$d,gridLine:zd,zonesLayer:Pd,zone:Ed,zoneLabel:Od,objectsLayer:Md,object:Ad,wall:Dd,objectLabel:Bd,connectionsLayer:Rd,connection:Fd,connectionPreview:Gd,guides:Vd,guideLine:qd,drawingPreview:Wd,rightSidebar:Hd,statusBar:Ud,modeIndicator:Yd,toolIndicator:Zd,selectionInfo:Xd,drawingInfo:Kd,connectingInfo:Jd,gridInfo:Qd,emptyState:eu,emptyIcon:tu,primaryBtn:nu,modeActions:su,actionBtn:ou},rt={"floor-plan":{mode:"floor-plan",label:"Floor Plan",icon:"home",tools:["select","pan","draw-zone","draw-wall","place-device","annotate","dimension","measure-distance","measure-area","erase"],layerTypes:["background","floor-plan","zones","devices","annotations","dimensions","grid"],defaultGridSize:20,enable3D:!1},"network-topology":{mode:"network-topology",label:"Network Topology",icon:"globe",tools:["select","pan","place-network","connect","route-cable","annotate","label","measure-distance","erase"],layerTypes:["background","floor-plan","network","annotations","grid"],defaultGridSize:40,enable3D:!1},infrastructure:{mode:"infrastructure",label:"Infrastructure",icon:"building",tools:["select","pan","draw-zone","place-infra","place-network","connect","route-cable","annotate","dimension","measure-distance","measure-area","erase"],layerTypes:["background","floor-plan","zones","infrastructure","network","annotations","dimensions","grid"],defaultGridSize:50,enable3D:!1},cad:{mode:"cad",label:"CAD",icon:"ruler",tools:["select","multi-select","pan","draw-wall","draw-zone","draw-polyline","draw-rectangle","draw-circle","draw-arc","place-stairs","annotate","dimension","measure-distance","measure-angle","measure-area","move","rotate","scale","copy","paste","erase"],layerTypes:["background","floor-plan","zones","annotations","dimensions","grid"],defaultGridSize:10,enable3D:!0},interior:{mode:"interior",label:"Interior Design",icon:"sofa",tools:["select","pan","draw-zone","draw-wall","place-furniture","place-device","annotate","measure-distance","measure-area","move","rotate","erase"],layerTypes:["background","floor-plan","zones","furniture","devices","annotations","grid"],defaultGridSize:25,enable3D:!0},"game-scene":{mode:"game-scene",label:"Game Scene",icon:"gamepad",tools:["select","multi-select","pan","draw-zone","draw-polyline","draw-rectangle","draw-circle","annotate","move","rotate","scale","copy","paste","erase"],layerTypes:["background","floor-plan","zones","game-objects","collision","annotations","grid"],defaultGridSize:32,enable3D:!0}},ct={select:{tool:"select",icon:"cursor",label:"Select",shortcut:"V",group:"select"},"multi-select":{tool:"multi-select",icon:"grid",label:"Multi-Select",shortcut:"M",group:"select"},pan:{tool:"pan",icon:"cursor",label:"Pan",shortcut:"H",group:"select"},zoom:{tool:"zoom",icon:"search",label:"Zoom",shortcut:"Z",group:"select"},"draw-wall":{tool:"draw-wall",icon:"line",label:"Wall",shortcut:"W",group:"draw"},"draw-zone":{tool:"draw-zone",icon:"hexagon",label:"Zone",shortcut:"R",group:"draw"},"draw-polyline":{tool:"draw-polyline",icon:"pen",label:"Polyline",shortcut:"L",group:"draw"},"draw-rectangle":{tool:"draw-rectangle",icon:"square",label:"Rectangle",shortcut:"U",group:"draw"},"draw-circle":{tool:"draw-circle",icon:"circle",label:"Circle",shortcut:"C",group:"draw"},"draw-arc":{tool:"draw-arc",icon:"pen",label:"Arc",shortcut:"A",group:"draw"},"place-device":{tool:"place-device",icon:"wifi",label:"Device",shortcut:"D",group:"place"},"place-furniture":{tool:"place-furniture",icon:"chair",label:"Furniture",shortcut:"F",group:"place"},"place-network":{tool:"place-network",icon:"server",label:"Network",shortcut:"N",group:"place"},"place-infra":{tool:"place-infra",icon:"settings",label:"Infrastructure",shortcut:"I",group:"place"},"place-door":{tool:"place-door",icon:"door",label:"Door",group:"place"},"place-window":{tool:"place-window",icon:"window",label:"Window",group:"place"},"place-stairs":{tool:"place-stairs",icon:"stairs",label:"Stairs",group:"place"},connect:{tool:"connect",icon:"link",label:"Connect",shortcut:"K",group:"connect"},"route-cable":{tool:"route-cable",icon:"plug",label:"Cable Route",group:"connect"},annotate:{tool:"annotate",icon:"edit",label:"Annotate",shortcut:"T",group:"annotate"},dimension:{tool:"dimension",icon:"ruler",label:"Dimension",group:"annotate"},label:{tool:"label",icon:"tag",label:"Label",group:"annotate"},"measure-distance":{tool:"measure-distance",icon:"ruler",label:"Distance",group:"measure"},"measure-angle":{tool:"measure-angle",icon:"triangle",label:"Angle",group:"measure"},"measure-area":{tool:"measure-area",icon:"square",label:"Area",group:"measure"},move:{tool:"move",icon:"move",label:"Move",shortcut:"G",group:"edit"},rotate:{tool:"rotate",icon:"refresh",label:"Rotate",shortcut:"R",group:"edit"},scale:{tool:"scale",icon:"scale",label:"Scale",shortcut:"S",group:"edit"},erase:{tool:"erase",icon:"trash",label:"Delete",shortcut:"Del",group:"edit"},copy:{tool:"copy",icon:"copy",label:"Copy",shortcut:"Ctrl+C",group:"edit"},paste:{tool:"paste",icon:"clipboard",label:"Paste",shortcut:"Ctrl+V",group:"edit"}},Pn=t=>typeof t=="object"&&t!==null&&typeof t.id=="string"&&typeof t.category=="string",au={"smart-home":"devices",furniture:"furniture",network:"network",infrastructure:"infrastructure",building:"floor-plan",game:"game-objects",annotation:"annotations","place-device":"devices","place-furniture":"furniture","place-network":"network","place-infra":"infrastructure","place-door":"floor-plan","place-window":"floor-plan","place-stairs":"floor-plan"},ts={"place-device":"smart-home","place-furniture":"furniture","place-network":"network","place-infra":"infrastructure","place-door":"building","place-window":"building","place-stairs":"building"},yt=28,En=["#93c5fd","#86efac","#fcd34d","#f9a8d4","#c4b5fd","#67e8f9"],cn=t=>`${t}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,7)}`;function iu(t,n,s){const o=n?n.category:ts[s],i=au[n?n.category:s];if(!o||!i)return null;const a=yt/2,c={x:t.x-a,y:t.y-a,width:yt,height:yt};return{id:cn("obj"),type:n?n.id:s.slice(6),category:o,name:n?n.name:ct[s].label,layer:i,transform:{position:{x:c.x,y:c.y},rotation:0,scale:{x:1,y:1}},bounds:c,size:{width:yt,height:yt},visible:!0,locked:!1,childIds:[],metadata:{icon:n?n.icon:ct[s].icon}}}function ru(t,n,s,o){if(t==="draw-zone"&&n.length>=3){const i=En[o%En.length],a=Gt(n);return[{id:cn("zone"),type:"zone",category:"zone",name:`Zone ${o+1}`,layer:"zones",boundary:n,color:i,floorId:s,roomIds:[],bounds:a,transform:{position:{x:a.x,y:a.y},rotation:0,scale:{x:1,y:1}},visible:!0,locked:!1,childIds:[]}]}return(t==="draw-wall"||t==="draw-polyline")&&n.length>=2?n.slice(1).map((i,a)=>{const c=n[a],r=Gt([c,i]);return{id:cn("wall"),type:"wall",category:"building",elementType:"wall",name:"Wall",layer:"floor-plan",start:c,end:i,height:2.7,thickness:.15,material:"drywall",openings:[],bounds:r,transform:{position:{x:r.x,y:r.y},rotation:0,scale:{x:1,y:1}},visible:!0,locked:!1,childIds:[]}}):[]}function cu(t){var a;const n=t.defaultMode??"floor-plan",s=rt[n],o=[{type:"grid",visible:!0,locked:!0,opacity:.3,zIndex:0},{type:"background",visible:!0,locked:!0,opacity:.5,zIndex:1},{type:"floor-plan",visible:!0,locked:!1,opacity:1,zIndex:10},{type:"zones",visible:!0,locked:!1,opacity:.6,zIndex:20},{type:"furniture",visible:!0,locked:!1,opacity:1,zIndex:30},{type:"devices",visible:!0,locked:!1,opacity:1,zIndex:40},{type:"network",visible:!0,locked:!1,opacity:1,zIndex:50},{type:"infrastructure",visible:!0,locked:!1,opacity:1,zIndex:60},{type:"game-objects",visible:!0,locked:!1,opacity:1,zIndex:70},{type:"collision",visible:!1,locked:!1,opacity:.4,zIndex:80},{type:"annotations",visible:!0,locked:!1,opacity:1,zIndex:90},{type:"dimensions",visible:!0,locked:!1,opacity:1,zIndex:100}],i=t.document??t.initialDocument??null;return{mode:n,tool:s.tools[0]??"select",document:i,activeFloorId:((a=i==null?void 0:i.floors[0])==null?void 0:a.id)??null,layers:o,selection:{objectIds:[],bounds:null,locked:!1},viewport:{zoom:1,pan:{x:0,y:0},rotation:0,showGrid:!0,gridSize:t.gridSize??s.defaultGridSize,snapEnabled:t.snapEnabled??!0,snapModes:["grid","endpoint","midpoint"]},drawing:{active:!1,points:[],preview:null},connecting:{active:!1,sourceId:null,sourcePosition:null,previewPosition:null},history:{past:[],future:[]},guides:[],dragging:null,clipboard:[],ui:{showObjectLibrary:t.showObjectLibrary??!0,showLayerPanel:t.showLayerPanel??!0,showPropertiesPanel:t.showPropertiesPanel??!0,showMinimap:t.showMinimap??!0}}}function st(t,n,s,o){return{id:`${Date.now()}-${Math.random().toString(36).slice(2,9)}`,timestamp:Date.now(),type:t,objectIds:n,before:s,after:o}}function ot(t,n){return{history:{past:[...t.history.past.slice(-49),n],future:[]}}}function Ue(t,n){if(t)for(const s of t.floors)for(const o of s.layers){const i=o.objects.find(a=>a.id===n);if(i)return i}}function xt(t,n,s){return{...t,floors:t.floors.map(o=>({...o,layers:o.layers.map(i=>({...i,objects:i.objects.map(a=>a.id===n?{...a,...s}:a)}))})),metadata:{...t.metadata,modified:new Date().toISOString()}}}function Ot(t,n){const s=new Set(n);return{...t,floors:t.floors.map(o=>({...o,layers:o.layers.map(i=>({...i,objects:i.objects.filter(a=>!s.has(a.id))}))})),metadata:{...t.metadata,modified:new Date().toISOString()}}}const lu=new Set(["floor-plan","walls","rooms","zones","doors-windows","furniture","devices","network","infrastructure","electrical","plumbing","hvac","annotations","dimensions","grid","background","game-objects","collision"]);function Mt(t,n,s,o){return{...t,floors:t.floors.map(i=>{if(i.id!==n)return i;let a=i.layers.findIndex(r=>r.name===s);a<0&&(a=i.layers.findIndex(r=>r.type===s));const c=a>=0?i.layers.map((r,d)=>d===a?{...r,objects:[...r.objects,o]}:r):[...i.layers,{id:`layer-${s}-${Date.now().toString(36)}`,name:s,type:lu.has(s)?s:"custom",visible:!0,locked:!1,opacity:1,objects:[o]}];return{...i,layers:c}}),metadata:{...t.metadata,modified:new Date().toISOString()}}}function du(t,n){var s;switch(n.type){case"SET_MODE":{const o=rt[n.mode];return{...t,mode:n.mode,tool:o.tools.includes(t.tool)?t.tool:o.tools[0],viewport:{...t.viewport,gridSize:o.defaultGridSize}}}case"SET_TOOL":return{...t,tool:n.tool,drawing:{active:!1,points:[],preview:null},connecting:{active:!1,sourceId:null,sourcePosition:null,previewPosition:null}};case"SET_DOCUMENT":return{...t,document:n.document,activeFloorId:((s=n.document.floors[0])==null?void 0:s.id)??null};case"SET_ACTIVE_FLOOR":return{...t,activeFloorId:n.floorId};case"SET_SELECTION":return{...t,selection:n.selection};case"CLEAR_SELECTION":return{...t,selection:{objectIds:[],bounds:null,locked:!1}};case"SET_VIEWPORT":return{...t,viewport:{...t.viewport,...n.viewport}};case"ZOOM":{const o=Math.max(.1,Math.min(10,t.viewport.zoom*(1+n.delta*.1)));return{...t,viewport:{...t.viewport,zoom:o}}}case"PAN":return{...t,viewport:{...t.viewport,pan:{x:t.viewport.pan.x+n.delta.x,y:t.viewport.pan.y+n.delta.y}}};case"RESET_VIEW":return{...t,viewport:{...t.viewport,zoom:1,pan:{x:0,y:0}}};case"TOGGLE_GRID":return{...t,viewport:{...t.viewport,showGrid:!t.viewport.showGrid}};case"TOGGLE_SNAP":return{...t,viewport:{...t.viewport,snapEnabled:!t.viewport.snapEnabled}};case"SET_GRID_SIZE":return{...t,viewport:{...t.viewport,gridSize:n.size}};case"SET_SNAP_MODES":return{...t,viewport:{...t.viewport,snapModes:n.modes}};case"SET_LAYER_VISIBILITY":return{...t,layers:t.layers.map(o=>o.type===n.layerType?{...o,visible:n.visible}:o)};case"SET_LAYER_LOCKED":return{...t,layers:t.layers.map(o=>o.type===n.layerType?{...o,locked:n.locked}:o)};case"SET_LAYER_OPACITY":return{...t,layers:t.layers.map(o=>o.type===n.layerType?{...o,opacity:n.opacity}:o)};case"START_DRAWING":return{...t,drawing:{active:!0,points:[n.point],preview:null}};case"ADD_DRAWING_POINT":return{...t,drawing:{...t.drawing,points:[...t.drawing.points,n.point]}};case"UPDATE_DRAWING_PREVIEW":return{...t,drawing:{...t.drawing,preview:n.point}};case"FINISH_DRAWING":return{...t,drawing:{active:!1,points:[],preview:null}};case"CANCEL_DRAWING":return{...t,drawing:{active:!1,points:[],preview:null}};case"START_CONNECTING":return{...t,connecting:{active:!0,sourceId:n.sourceId,sourcePort:n.sourcePort,sourcePosition:n.sourcePosition,previewPosition:n.sourcePosition}};case"UPDATE_CONNECTING_PREVIEW":return{...t,connecting:{...t.connecting,previewPosition:n.position}};case"FINISH_CONNECTING":return{...t,connecting:{active:!1,sourceId:null,sourcePosition:null,previewPosition:null}};case"CANCEL_CONNECTING":return{...t,connecting:{active:!1,sourceId:null,sourcePosition:null,previewPosition:null}};case"SET_GUIDES":return{...t,guides:n.guides};case"TOGGLE_OBJECT_LIBRARY":return{...t,ui:{...t.ui,showObjectLibrary:!t.ui.showObjectLibrary}};case"TOGGLE_LAYER_PANEL":return{...t,ui:{...t.ui,showLayerPanel:!t.ui.showLayerPanel}};case"TOGGLE_PROPERTIES_PANEL":return{...t,ui:{...t.ui,showPropertiesPanel:!t.ui.showPropertiesPanel}};case"TOGGLE_MINIMAP":return{...t,ui:{...t.ui,showMinimap:!t.ui.showMinimap}};case"ADD_OBJECT":{if(!t.document||!t.activeFloorId)return t;const o=n.object.layer||"devices",i=Mt(t.document,t.activeFloorId,o,n.object),a=st("create",[n.object.id],null,n.object);return{...t,document:i,...ot(t,a)}}case"UPDATE_OBJECT":{if(!t.document)return t;const o=Ue(t.document,n.objectId);if(!o)return t;const i=xt(t.document,n.objectId,n.updates),a=st("update",[n.objectId],o,{...o,...n.updates});return{...t,document:i,...ot(t,a)}}case"DELETE_OBJECTS":{if(!t.document||n.objectIds.length===0)return t;const o=n.objectIds.map(c=>Ue(t.document,c)).filter(Boolean),i=Ot(t.document,n.objectIds),a=st("delete",n.objectIds,o,null);return{...t,document:i,selection:{objectIds:[],bounds:null,locked:!1},...ot(t,a)}}case"MOVE_OBJECTS":{if(!t.document||n.objectIds.length===0)return t;const o=n.objectIds.map(p=>Ue(t.document,p)).filter(Boolean),{x:i,y:a}=n.delta,c=new Set(n.objectIds);let r=t.document;for(const p of n.objectIds){const f=Ue(r,p);f&&!f.locked&&(r=xt(r,p,Pi(f,i,a)))}for(const p of r.floors)for(const f of p.layers)for(const y of f.objects){const b=y.metadata;if(y.type!=="connection"||!b||c.has(y.id))continue;const j=b.sourceId&&c.has(b.sourceId)?b.sourcePosition:void 0,w=b.targetId&&c.has(b.targetId)?b.targetPosition:void 0;(j||w)&&(r=xt(r,y.id,{metadata:{...b,...j&&{sourcePosition:{x:j.x+i,y:j.y+a}},...w&&{targetPosition:{x:w.x+i,y:w.y+a}}}}))}const d=n.objectIds.map(p=>Ue(r,p)).filter(Boolean),_=st("move",n.objectIds,o,d);return{...t,document:r,...ot(t,_)}}case"UNDO":{if(t.history.past.length===0||!t.document)return t;const o=t.history.past[t.history.past.length-1];let i=t.document;switch(o.type){case"create":{i=Ot(i,o.objectIds);break}case"delete":{const a=o.before;for(const c of a){const r=c.layer||"devices";i=Mt(i,t.activeFloorId??i.floors[0].id,r,c)}break}case"update":case"move":{const a=o.before;for(const c of a)i=xt(i,c.id,c);break}}return{...t,document:i,history:{past:t.history.past.slice(0,-1),future:[o,...t.history.future]}}}case"REDO":{if(t.history.future.length===0||!t.document)return t;const o=t.history.future[0];let i=t.document;switch(o.type){case"create":{const a=o.after,c=a.layer||"devices";i=Mt(i,t.activeFloorId??i.floors[0].id,c,a);break}case"delete":{i=Ot(i,o.objectIds);break}case"update":case"move":{const a=o.after;for(const c of a)i=xt(i,c.id,c);break}}return{...t,document:i,history:{past:[...t.history.past,o],future:t.history.future.slice(1)}}}case"COPY":{if(!t.document||t.selection.objectIds.length===0)return t;const o=t.selection.objectIds.map(i=>Ue(t.document,i)).filter(Boolean);return{...t,clipboard:o}}case"CUT":{if(!t.document||t.selection.objectIds.length===0)return t;const o=t.selection.objectIds.map(c=>Ue(t.document,c)).filter(Boolean),i=Ot(t.document,t.selection.objectIds),a=st("delete",t.selection.objectIds,o,null);return{...t,document:i,clipboard:o,selection:{objectIds:[],bounds:null,locked:!1},...ot(t,a)}}case"PASTE":{if(!t.document||!t.activeFloorId||t.clipboard.length===0)return t;let o=t.document;const i=[],a=[];for(const r of t.clipboard){const d=`${r.id}-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,_=r.transform,p={position:{x:_.position.x+n.position.x+20,y:_.position.y+n.position.y+20},rotation:_.rotation,scale:_.scale},f={...r,id:d,transform:p},y=f.layer||"devices";o=Mt(o,t.activeFloorId,y,f),i.push(d),a.push(f)}const c=st("create",i,null,a);return{...t,document:o,selection:{objectIds:i,bounds:null,locked:!1},...ot(t,c)}}case"START_DRAG":return{...t,dragging:{objectType:n.objectType,objectData:n.objectData,position:null}};case"UPDATE_DRAG_POSITION":return t.dragging?{...t,dragging:{...t.dragging,position:n.position}}:t;case"END_DRAG":return{...t,dragging:null};case"CANCEL_DRAG":return{...t,dragging:null};default:return t}}const uu=({mode:t,activeTool:n,onToolSelect:s,readOnly:o})=>{const a=rt[t].tools.map(r=>ct[r]).filter(Boolean),c=["select","draw","place","connect","annotate","measure","edit"];return e.jsx("div",{className:U.toolbar,children:c.map(r=>{const d=a.filter(_=>_.group===r);return d.length===0?null:e.jsx("div",{className:U.toolGroup,children:d.map(({tool:_,icon:p,label:f,shortcut:y})=>e.jsx("button",{title:`${f}${y?` (${y})`:""}`,className:`${U.toolBtn} ${n===_?U.toolBtnActive:""}`,onClick:()=>s(_),disabled:o&&!["select","pan","zoom","measure-distance","measure-angle","measure-area"].includes(_),children:e.jsx(N.NiceIcon,{name:p,size:16})},_))},r)})})};function On(t){if(!t)return[];const n=[];for(const s of t.floors)for(const o of s.layers)if(o.type==="network"||o.type==="infrastructure"){for(const i of o.objects)if(i.type==="connection"){const a=i.metadata;a!=null&&a.sourceId&&(a!=null&&a.targetId)&&n.push({id:i.id,sourceId:a.sourceId,sourcePort:a.sourcePort,targetId:a.targetId,targetPort:a.targetPort,medium:a.medium??"ethernet-cat6",status:a.status??"unknown",bandwidth:a.bandwidth,latency:a.latency??1,waypoints:a.waypoints??[]})}}return n}function pu(t){if(!t)return[];const n=[],s=new Set;for(const o of t.floors)for(const i of o.layers)if(i.type==="network"||i.type==="infrastructure")for(const a of i.objects){const c=a.metadata;if((c==null?void 0:c.vlanId)!==void 0&&!s.has(c.vlanId))s.add(c.vlanId),n.push({id:c.vlanId,name:c.vlanName??`VLAN ${c.vlanId}`,color:c.vlanColor??mu(c.vlanId),deviceIds:[a.id],subnet:c.subnet,gateway:c.gateway,dhcpEnabled:c.dhcpEnabled});else if((c==null?void 0:c.vlanId)!==void 0){const r=n.find(d=>d.id===c.vlanId);r&&!r.deviceIds.includes(a.id)&&r.deviceIds.push(a.id)}}return n.sort((o,i)=>o.id-i.id)}function mu(t){const n=["var(--nice-primary, #3b82f6)","var(--nice-success, #22c55e)","var(--nice-warning, #f59e0b)","var(--nice-danger, #ef4444)","var(--nice-accent, #8b5cf6)","var(--nice-color-accent-pink, #ec4899)","var(--nice-info, #06b6d4)","var(--nice-warning, #f97316)","var(--nice-info, #14b8a6)","var(--nice-accent, #a855f7)"];return n[t%n.length]}const hu=[{target:".nice-spatial-editor",titleKey:"tutorial.spatialEditor.intro.title",title:"Spatial editor",contentKey:"tutorial.spatialEditor.intro.content",content:"Lay out floor plans across modes: draw walls, rooms and objects with the tools, manage layers, snap to the grid, then export.",placement:"auto"}],gu=t=>{var pn,mn,hn;const{defaultMode:n="floor-plan",availableModes:s=Object.keys(rt),readOnly:o=!1,theme:i="light",locale:a="en",onDocumentChange:c,onSelectionChange:r,onModeChange:d,onExport:_,onImport:p,tutorial:f,className:y,style:b,cookies:j=!1,localStorage:w=!0,sessionStorage:x=!1,storageMode:C,storageKey:g,persistPreferences:L=!1}=t,{t:m}=N.useNiceTranslation(),k=N.useStorageAdapter(g??"nice-spatial-editor"),[l]=u.useState(()=>L?k.get("prefs")??{}:{}),[I,h]=u.useReducer(du,t,cu),F=u.useRef(null),T=u.useRef(!1),B=u.useRef({x:0,y:0}),H=u.useRef(null),[ne,te]=u.useState(null),[ie,_e]=u.useState(!1),[de,Ne]=u.useState(!1),[Je,Be]=u.useState(null),[xe,ze]=u.useState(null),[Ge,P]=u.useState(!1),[Q,fe]=u.useState(!1),[Se,Oe]=u.useState(!1),[ke,Ve]=u.useState(!1),[Pe,qe]=u.useState(!1),[We,Re]=u.useState(new Set),[$e,lt]=u.useState(null),dt=u.useRef(null),Me=u.useRef(null),Ce=u.useRef(null),{mode:Ee,tool:me,document:q,activeFloorId:Ye,layers:Ae,selection:we,viewport:re,drawing:ye,connecting:pe,guides:ut,ui:He,history:kt,dragging:Qe}=I,et=rt[Ee],pt=kt.past.length>0,mt=kt.future.length>0;u.useEffect(()=>{var v,$,G;!L||!l||((l.zoom||l.pan)&&h({type:"SET_VIEWPORT",viewport:{zoom:l.zoom,pan:l.pan,showGrid:(v=l.gridConfig)==null?void 0:v.visible,gridSize:($=l.gridConfig)==null?void 0:$.size,snapEnabled:(G=l.gridConfig)==null?void 0:G.snapEnabled}}),l.mode&&h({type:"SET_MODE",mode:l.mode}),l.tool&&h({type:"SET_TOOL",tool:l.tool}),l.layerVisibility&&Object.entries(l.layerVisibility).forEach(([W,V])=>{V!==void 0&&h({type:"SET_LAYER_VISIBILITY",layerType:W,visible:V})}))},[]),u.useEffect(()=>{if(!L)return;const v={zoom:re.zoom,pan:re.pan,gridConfig:{size:re.gridSize,visible:re.showGrid,snapEnabled:re.snapEnabled},mode:Ee,tool:me,layerVisibility:Object.fromEntries(Ae.map($=>[$.type,$.visible])),uiPanels:He};k.set("prefs",v)},[L,re,Ee,me,Ae,He,k]);const St=u.useRef({doc:q,selection:we});u.useEffect(()=>{q&&q!==St.current.doc&&(c==null||c(q))},[q,c]),u.useEffect(()=>{we!==St.current.selection&&(r==null||r(we))},[we,r]);const he=u.useMemo(()=>(q==null?void 0:q.floors.find(v=>v.id===Ye))??(q==null?void 0:q.floors[0])??null,[q,Ye]),Fe=u.useCallback((v,$)=>{var W;const G=(W=F.current)==null?void 0:W.getBoundingClientRect();return G?{x:(v-G.left-re.pan.x)/re.zoom,y:($-G.top-re.pan.y)/re.zoom}:{x:0,y:0}},[re.pan,re.zoom]),Ze=u.useCallback(v=>{if(!re.snapEnabled)return v;const $={cellSize:re.gridSize,origin:{x:0,y:0},visible:re.showGrid};return ln(v,$)},[re.snapEnabled,re.gridSize,re.showGrid]),ht=u.useCallback((v,$)=>{const G=o?null:iu(v,$,me);G&&(h({type:"ADD_OBJECT",object:G}),h({type:"SET_SELECTION",selection:{objectIds:[G.id],bounds:null,locked:!1}}),$&&(h({type:"END_DRAG"}),h({type:"SET_TOOL",tool:"select"})))},[o,me]),Ut=u.useCallback(v=>{var V;if(me==="pan"||v.button===1){T.current=!0,B.current={x:v.clientX,y:v.clientY};return}const $=Ze(Fe(v.clientX,v.clientY)),G=Qe==null?void 0:Qe.objectData,W=Pn(G)?G:null;if(W||ts[me]){ht($,W);return}if(me==="draw-zone"||me==="draw-wall"||me==="draw-polyline")ye.active?h({type:"ADD_DRAWING_POINT",point:$}):h({type:"START_DRAWING",point:$});else if(me==="connect"){const D=he==null?void 0:he.layers.flatMap(X=>X.objects).find(X=>{if(!X.bounds)return!1;const le=X.bounds;return $.x>=le.x&&$.x<=le.x+le.width&&$.y>=le.y&&$.y<=le.y+le.height});if(D)if(pe.active){h({type:"FINISH_CONNECTING",targetId:D.id});const X=`conn-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,le=D.bounds?{x:D.bounds.x+D.bounds.width/2,y:D.bounds.y+D.bounds.height/2}:$,be={id:X,type:"connection",category:"network",name:"Connection",transform:{position:{x:0,y:0},rotation:0,scale:{x:1,y:1}},layer:"network",locked:!1,visible:!0,childIds:[],bounds:{x:Math.min(pe.sourcePosition.x,le.x),y:Math.min(pe.sourcePosition.y,le.y),width:Math.abs(le.x-pe.sourcePosition.x),height:Math.abs(le.y-pe.sourcePosition.y)},metadata:{sourceId:pe.sourceId,targetId:D.id,sourcePosition:pe.sourcePosition,targetPosition:le,medium:"ethernet-cat6",status:"active"}};h({type:"ADD_OBJECT",object:be})}else{const X=D.bounds?{x:D.bounds.x+D.bounds.width/2,y:D.bounds.y+D.bounds.height/2}:$;h({type:"START_CONNECTING",sourceId:D.id,sourcePosition:X})}else pe.active&&h({type:"CANCEL_CONNECTING"})}else if(me==="select"){const D=(V=v.target.closest("[data-object-id]"))==null?void 0:V.getAttribute("data-object-id");D?(h({type:"SET_SELECTION",selection:{objectIds:[D],bounds:null,locked:!1}}),o||(H.current=$,te({ids:[D],dx:0,dy:0}))):h({type:"CLEAR_SELECTION"})}},[me,ye.active,pe.active,pe.sourceId,pe.sourcePosition,Ze,Fe,he,Qe,ht,o]),Yt=u.useCallback(v=>{if(T.current){const W=v.clientX-B.current.x,V=v.clientY-B.current.y;h({type:"PAN",delta:{x:W,y:V}}),B.current={x:v.clientX,y:v.clientY};return}const $=Ze(Fe(v.clientX,v.clientY)),G=H.current;if(ne&&G){te({...ne,dx:$.x-G.x,dy:$.y-G.y});return}if(ye.active&&(h({type:"UPDATE_DRAWING_PREVIEW",point:$}),re.snapEnabled&&he)){const W=he.layers.flatMap(X=>X.objects.filter(le=>le.bounds).map(le=>({id:le.id,bounds:le.bounds}))),V={x:$.x,y:$.y,width:1,height:1},D=Yn(V,W,10);h({type:"SET_GUIDES",guides:D})}pe.active&&h({type:"UPDATE_CONNECTING_PREVIEW",position:$})},[ye.active,pe.active,Ze,Fe,re.snapEnabled,he,ne]),gt=u.useCallback(()=>{T.current=!1,H.current=null,ne&&(ne.dx!==0||ne.dy!==0)&&h({type:"MOVE_OBJECTS",objectIds:ne.ids,delta:{x:ne.dx,y:ne.dy}}),te(null)},[ne]),S=u.useCallback(()=>{var W;if(!ye.active)return;const v=ye.points.filter((V,D,X)=>D===0||V.x!==X[D-1].x||V.y!==X[D-1].y),$=he?((W=it(he.layers))==null?void 0:W.objects.length)??0:0,G=he?ru(me,v,he.id,$):[];for(const V of G)h({type:"ADD_OBJECT",object:V});h({type:"FINISH_DRAWING"}),h({type:"SET_GUIDES",guides:[]}),G.length>0&&h({type:"SET_SELECTION",selection:{objectIds:G.map(V=>V.id),bounds:null,locked:!1}})},[ye.active,ye.points,he,me]),z=u.useCallback(v=>{S()},[S]),R=u.useCallback(v=>{v.preventDefault();const $=v.deltaY>0?-1:1;h({type:"ZOOM",delta:$,center:Fe(v.clientX,v.clientY)})},[Fe]),ee=u.useCallback(v=>{v.key==="Enter"&&ye.active&&S(),v.key==="Escape"&&(ye.active?h({type:"CANCEL_DRAWING"}):pe.active?h({type:"CANCEL_CONNECTING"}):h({type:"CLEAR_SELECTION"})),v.key==="Delete"&&we.objectIds.length>0&&h({type:"DELETE_OBJECTS",objectIds:we.objectIds}),(v.ctrlKey||v.metaKey)&&(v.key==="z"&&h({type:"UNDO"}),v.key==="y"&&h({type:"REDO"}),v.key==="c"&&h({type:"COPY"}),v.key==="v"&&h({type:"PASTE",position:{x:0,y:0}}),v.key==="x"&&h({type:"CUT"}))},[ye.active,pe.active,we.objectIds,S]),se=u.useCallback(v=>{h({type:"SET_MODE",mode:v}),d==null||d(v)},[d]),ue=u.useCallback(v=>{h({type:"SET_TOOL",tool:v})},[]),ge=u.useCallback(async v=>{var $;if(q){_e(!1);try{const G={includeGrid:!1,includeDimensions:!0};if(v==="nsp"){const W=Oo(q,G);Pt(W),_==null||_(v,W.data)}else if(v==="svg"){const W=Ao(q,G);Pt(W),_==null||_(v,W.data)}else if(v==="dxf"){const W=Ro(q,G);Pt(W),_==null||_(v,W.data)}else if(v==="png"&&F.current){const W=await qo(F.current,(($=q.metadata)==null?void 0:$.name)||"export");Pt(W),_==null||_(v,W.data)}}catch(G){console.error(`Export to ${v} failed:`,G)}}},[q,_]),Te=u.useCallback(async v=>{var G;const $=(G=v.target.files)==null?void 0:G[0];if($){Ne(!1);try{const V=await na($,{convertClosedPolylinesToZones:!0,minZoneArea:1});V.success&&V.document?ze(V):Be(V),Ce.current&&(Ce.current.value="")}catch(W){console.error("Import failed:",W),Be({success:!1,warnings:[],errors:[{code:"IMPORT_ERROR",message:W instanceof Error?W.message:m("buildings.unknownImportError","Unknown import error"),fatal:!0}],stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:0}})}}},[m]),De=u.useCallback(()=>{xe!=null&&xe.success&&xe.document?P(!0):ze(null)},[xe]),Zt=u.useCallback(()=>{ze(null),P(!1)},[]),is=u.useCallback((v,$)=>{if(!(xe!=null&&xe.document)){P(!1);return}const G=xe.document,W={...G,floors:G.floors.map(V=>({...V,layers:V.layers.filter(D=>v.get(D.id)!=="skip").map(D=>{const X=v.get(D.id);if(X===D.id||!X)return D;const le=q==null?void 0:q.floors.flatMap(be=>be.layers).find(be=>be.id===X);return le?{...D,id:le.id,name:le.name,type:le.type}:D})}))};h({type:"SET_DOCUMENT",document:W}),p==null||p(W),Be(xe),P(!1),ze(null)},[xe,q,p]),rs=u.useCallback(()=>{P(!1)},[]),ft=u.useCallback(v=>{if(Ce.current){let $=".dxf,.svg,.geojson,.json,.ifc";v==="dxf"?$=".dxf":v==="svg"?$=".svg":v==="geojson"?$=".geojson,.json":v==="ifc"&&($=".ifc"),Ce.current.accept=$,Ce.current.click()}Ne(!1)},[]);u.useEffect(()=>{const v=$=>{dt.current&&!dt.current.contains($.target)&&_e(!1),Me.current&&!Me.current.contains($.target)&&Ne(!1)};return(ie||de)&&document.addEventListener("mousedown",v),()=>{document.removeEventListener("mousedown",v)}},[ie,de]);const cs=u.useCallback(()=>{var V,D;if(!re.showGrid||!he)return null;const v=[],$=re.gridSize,G=((V=he.bounds)==null?void 0:V.width)??1e3,W=((D=he.bounds)==null?void 0:D.height)??800;for(let X=0;X<=G;X+=$)v.push(e.jsx("line",{x1:X,y1:0,x2:X,y2:W,className:U.gridLine},`v${X}`));for(let X=0;X<=W;X+=$)v.push(e.jsx("line",{x1:0,y1:X,x2:G,y2:X,className:U.gridLine},`h${X}`));return e.jsx("g",{className:U.grid,children:v})},[re.showGrid,re.gridSize,he]),Ct=u.useCallback(v=>{var $;return(($=Ae.find(G=>G.type===v))==null?void 0:$.visible)!==!1},[Ae]),_t=u.useCallback(v=>ne&&(ne.dx!==0||ne.dy!==0)&&ne.ids.includes(v)?`translate(${ne.dx}, ${ne.dy})`:void 0,[ne]),ls=u.useCallback(()=>{if(!he)return null;const v=it(he.layers);return!v||!Ct("zones")?null:e.jsx("g",{className:U.zonesLayer,children:v.objects.map($=>{const G=Ht($);if(!G)return null;const W=G.map((X,le)=>`${le===0?"M":"L"}${X.x},${X.y}`).join(" ")+" Z",V=we.objectIds.includes($.id),D=G.reduce((X,le)=>({x:X.x+le.x/G.length,y:X.y+le.y/G.length}),{x:0,y:0});return e.jsxs("g",{className:U.zone,"data-object-id":$.id,transform:_t($.id),onClick:X=>{X.stopPropagation(),h({type:"SET_SELECTION",selection:{objectIds:[$.id],bounds:null,locked:!1}})},children:[e.jsx("path",{d:W,fill:Ft($)??"var(--nice-primary-bg, #dbeafe)",fillOpacity:.5,stroke:V?"var(--nice-primary-hover, #2563eb)":"var(--nice-text-muted, #94a3b8)",strokeWidth:V?2:1}),$.name&&e.jsx("text",{x:D.x,y:D.y,textAnchor:"middle",dominantBaseline:"middle",className:U.zoneLabel,children:$.name})]},$.id)})})},[he,we.objectIds,Ct,_t]),ds=u.useCallback(()=>{var G;if(!he)return null;const v=it(he.layers),$=Math.max(3,.15*(((G=q==null?void 0:q.settings)==null?void 0:G.scale)??50));return e.jsx("g",{className:U.objectsLayer,children:he.layers.map(W=>W===v||W.type==="grid"||W.type==="background"||W.visible===!1||!Ct(W.type)?null:W.objects.map(V=>{var gn,fn,_n,bn;if(V.type==="connection"||V.visible===!1)return null;const D=we.objectIds.includes(V.id),X=Tt=>{Tt.stopPropagation(),me==="select"&&h({type:"SET_SELECTION",selection:{objectIds:[V.id],bounds:null,locked:!1}})},le=dn(V);if(le){const Tt=V.thickness;return e.jsx("line",{"data-object-id":V.id,className:U.wall,transform:_t(V.id),x1:le.start.x,y1:le.start.y,x2:le.end.x,y2:le.end.y,stroke:D?"var(--nice-primary-hover, #2563eb)":"var(--nice-text-primary, #334155)",strokeWidth:Tt?Math.max(3,Tt*(((gn=q==null?void 0:q.settings)==null?void 0:gn.scale)??50)):$,strokeLinecap:"round",onClick:X},V.id)}const be=It(V);if(!be)return null;const tt=(fn=V.metadata)==null?void 0:fn.icon,Xe=typeof tt=="string"?tt:void 0,Kt=Math.max(10,Math.min(be.width,be.height)-10);return e.jsxs("g",{"data-object-id":V.id,className:`${U.object} ${D?U.objectSelected:""}`,transform:_t(V.id),onClick:X,children:[e.jsx("rect",{x:be.x,y:be.y,width:be.width,height:be.height,rx:6,fill:((_n=V.style)==null?void 0:_n.fill)??"var(--nice-bg-primary, #ffffff)",stroke:D?"var(--nice-primary-hover, #2563eb)":((bn=V.style)==null?void 0:bn.stroke)??"var(--nice-text-secondary, #64748b)",strokeWidth:D?2.5:1.5}),Xe&&e.jsx("g",{transform:`translate(${be.x+(be.width-Kt)/2}, ${be.y+(be.height-Kt)/2})`,style:{color:"var(--nice-text-primary, #334155)"},"aria-hidden":"true",children:e.jsx(N.NiceIcon,{name:Xe,size:Kt})}),V.name&&e.jsx("text",{x:be.x+be.width/2,y:be.y+be.height+12,textAnchor:"middle",className:U.objectLabel,children:V.name})]},V.id)}))})},[he,we.objectIds,Ct,me,(pn=q==null?void 0:q.settings)==null?void 0:pn.scale,_t]),us=u.useCallback(()=>ut.length===0?null:e.jsx("g",{className:U.guides,children:ut.map((v,$)=>e.jsx("line",{x1:v.start.x,y1:v.start.y,x2:v.end.x,y2:v.end.y,className:U.guideLine},$))}),[ut]),ps=u.useCallback(()=>{if(!ye.active||ye.points.length===0)return null;const v=[...ye.points];ye.preview&&v.push(ye.preview);const $=v.map((W,V)=>`${V===0?"M":"L"}${W.x},${W.y}`).join(" "),G=me==="draw-zone"&&v.length>2;return e.jsxs("g",{className:U.drawingPreview,children:[e.jsx("path",{d:$+(G?" Z":""),fill:G?"var(--nice-primary-tint-10, rgba(37, 99, 235, 0.1))":"none",stroke:"var(--nice-primary-hover, #2563eb)",strokeWidth:2,strokeDasharray:G?"none":"6,3"}),v.map((W,V)=>e.jsx("circle",{cx:W.x,cy:W.y,r:4,fill:"var(--nice-primary-hover, #2563eb)"},V))]})},[ye,me]),ms=u.useCallback(()=>!pe.active||!pe.sourcePosition||!pe.previewPosition?null:e.jsxs("g",{className:U.connectionPreview,children:[e.jsx("line",{x1:pe.sourcePosition.x,y1:pe.sourcePosition.y,x2:pe.previewPosition.x,y2:pe.previewPosition.y,stroke:"var(--nice-success, #10b981)",strokeWidth:2,strokeDasharray:"8,4",markerEnd:"url(#connectionArrow)"}),e.jsx("circle",{cx:pe.sourcePosition.x,cy:pe.sourcePosition.y,r:6,fill:"var(--nice-success, #10b981)"}),e.jsx("circle",{cx:pe.previewPosition.x,cy:pe.previewPosition.y,r:6,fill:"var(--nice-success, #10b981)",fillOpacity:.5,stroke:"var(--nice-success, #10b981)",strokeWidth:2}),e.jsx("defs",{children:e.jsx("marker",{id:"connectionArrow",markerWidth:"10",markerHeight:"10",refX:"9",refY:"3",orient:"auto",markerUnits:"strokeWidth",children:e.jsx("path",{d:"M0,0 L0,6 L9,3 z",fill:"var(--nice-success, #10b981)"})})})]}),[pe]),hs=u.useCallback(()=>{if(!he)return null;const v=he.layers.find(V=>V.type==="network");if(!v)return null;const $=v.objects.filter(V=>V.type==="connection");if($.length===0)return null;const G={"ethernet-cat5":{color:"var(--nice-primary, #3b82f6)",width:2},"ethernet-cat6":{color:"var(--nice-primary-hover, #2563eb)",width:2},"ethernet-cat6a":{color:"var(--nice-primary-dark, #1d4ed8)",width:2},"ethernet-cat7":{color:"var(--nice-primary-dark, #1e40af)",width:3},"fiber-single":{color:"var(--nice-warning, #f59e0b)",width:3},"fiber-multi":{color:"var(--nice-warning-dark, #d97706)",width:3},"wifi-2.4ghz":{color:"var(--nice-accent, #8b5cf6)",dashArray:"6,4",width:2},"wifi-5ghz":{color:"var(--nice-accent, #7c3aed)",dashArray:"6,4",width:2},"wifi-6ghz":{color:"var(--nice-color-accent-hover, #6d28d9)",dashArray:"6,4",width:2},default:{color:"var(--nice-text-secondary, #64748b)",width:2}},W={active:"var(--nice-success, #10b981)",inactive:"var(--nice-text-muted, #94a3b8)",error:"var(--nice-danger, #ef4444)",degraded:"var(--nice-warning, #f59e0b)",unknown:"var(--nice-text-secondary, #64748b)"};return e.jsx("g",{className:U.connectionsLayer,children:$.map(V=>{const D=V.metadata;if(!(D!=null&&D.sourcePosition)||!(D!=null&&D.targetPosition))return null;const X=G[D.medium??"default"]||G.default,le=W[D.status??"unknown"]||W.unknown,be=we.objectIds.includes(V.id);let tt=`M${D.sourcePosition.x},${D.sourcePosition.y}`;if(D.waypoints&&D.waypoints.length>0)for(const Xe of D.waypoints)tt+=` L${Xe.x},${Xe.y}`;return tt+=` L${D.targetPosition.x},${D.targetPosition.y}`,e.jsxs("g",{className:U.connection,onClick:Xe=>{Xe.stopPropagation(),h({type:"SET_SELECTION",selection:{objectIds:[V.id],bounds:null,locked:!1}})},children:[e.jsx("path",{d:tt,fill:"none",stroke:be?"var(--nice-primary-hover, #2563eb)":X.color,strokeWidth:be?X.width+1:X.width,strokeDasharray:X.dashArray,strokeLinecap:"round",strokeLinejoin:"round"}),D.status&&D.status!=="active"&&e.jsx("circle",{cx:(D.sourcePosition.x+D.targetPosition.x)/2,cy:(D.sourcePosition.y+D.targetPosition.y)/2,r:5,fill:le}),e.jsx("circle",{cx:D.sourcePosition.x,cy:D.sourcePosition.y,r:4,fill:X.color,stroke:"white",strokeWidth:1}),e.jsx("circle",{cx:D.targetPosition.x,cy:D.targetPosition.y,r:4,fill:X.color,stroke:"white",strokeWidth:1})]},V.id)})})},[he,we.objectIds]);if(!q&&!he)return e.jsx("div",{className:`${U.root} ${U[i]} ${y??""}`,style:b,children:e.jsxs("div",{className:U.emptyState,children:[e.jsx("div",{className:U.emptyIcon,children:e.jsx(N.NiceIcon,{name:et.icon,size:48})}),e.jsx("h3",{children:m("buildings.noDocumentOpen","No Document Open")}),e.jsx("p",{children:m("buildings.createANewDocumentOr","Create a new document or open an existing .nsp.json file")}),e.jsx("button",{className:U.primaryBtn,onClick:()=>{const v=Rt("New Project","floor-plan");h({type:"SET_DOCUMENT",document:v})},children:m("buildings.createNewDocument","Create New Document")})]})});const gs=e.jsxs("div",{className:U.topBar,children:[q&&q.floors.length>1&&e.jsx("div",{className:U.floorTabs,children:q.floors.map(v=>e.jsx("button",{className:`${U.floorTab} ${Ye===v.id?U.floorTabActive:""}`,onClick:()=>h({type:"SET_ACTIVE_FLOOR",floorId:v.id}),children:v.name},v.id))}),e.jsxs("div",{className:U.viewportControls,children:[!o&&e.jsxs(e.Fragment,{children:[e.jsx("button",{title:m("buildings.undoCtrlZ","Undo (Ctrl+Z)"),onClick:()=>h({type:"UNDO"}),disabled:!pt,className:pt?"":U.disabled,children:e.jsx(N.NiceIcon,{name:"reply",size:16})}),e.jsx("button",{title:m("buildings.redoCtrlY","Redo (Ctrl+Y)"),onClick:()=>h({type:"REDO"}),disabled:!mt,className:mt?"":U.disabled,children:e.jsx(N.NiceIcon,{name:"forward",size:16})}),e.jsx("div",{className:U.separator})]}),e.jsx("button",{title:m("buildings.toggleGrid","Toggle Grid"),onClick:()=>h({type:"TOGGLE_GRID"}),className:re.showGrid?U.active:"",children:e.jsx(N.NiceIcon,{name:"grid",size:16})}),e.jsx("button",{title:m("buildings.toggleSnap","Toggle Snap"),onClick:()=>h({type:"TOGGLE_SNAP"}),className:re.snapEnabled?U.active:"",children:e.jsx(N.NiceIcon,{name:"target",size:16})}),e.jsxs("span",{className:U.zoomLevel,children:[Math.round(re.zoom*100),"%"]}),e.jsx("button",{title:m("buildings.zoomIn","Zoom In"),onClick:()=>h({type:"ZOOM",delta:1}),children:e.jsx(N.NiceIcon,{name:"plus",size:16})}),e.jsx("button",{title:m("buildings.zoomOut","Zoom Out"),onClick:()=>h({type:"ZOOM",delta:-1}),children:e.jsx(N.NiceIcon,{name:"minus",size:16})}),e.jsx("button",{title:m("buildings.resetView2","Reset View"),onClick:()=>h({type:"RESET_VIEW"}),children:e.jsx(N.NiceIcon,{name:"expand",size:16})}),e.jsx("input",{type:"file",ref:Ce,onChange:Te,style:{display:"none"}})]})]}),Xt=v=>v?e.jsx(N.NiceIcon,{name:"check",size:14}):void 0,fs=[{id:"file",label:m("buildings.menu.file","File"),children:[{id:"new",label:m("buildings.menu.new","New document"),icon:e.jsx(N.NiceIcon,{name:"file",size:14}),disabled:o,onClick:()=>h({type:"SET_DOCUMENT",document:Rt("New Project",Ee)})},...o?[]:[{id:"d-import",divider:!0},{id:"import",label:m("buildings.import","Import"),disabled:!0},{id:"import-auto",label:m("buildings.autoDetectFormat","Auto-detect format"),icon:e.jsx(N.NiceIcon,{name:"download",size:14}),onClick:()=>ft()},{id:"import-dxf",label:m("buildings.autocadDxfDxf","AutoCAD DXF (.dxf)"),onClick:()=>ft("dxf")},{id:"import-svg",label:m("buildings.svgVectorGraphicsSvg","SVG Vector Graphics (.svg)"),onClick:()=>ft("svg")},{id:"import-geojson",label:m("buildings.geojsonGeojson","GeoJSON (.geojson)"),onClick:()=>ft("geojson")},{id:"import-ifc",label:m("buildings.ifcBimIfc","IFC (BIM) (.ifc)"),onClick:()=>ft("ifc")}],{id:"d-export",divider:!0},{id:"export",label:m("buildings.export","Export"),disabled:!0},{id:"export-nsp",label:m("buildings.nicetodevSpatialPlanNspJson","NiceToDev Spatial Plan (.nsp.json)"),icon:e.jsx(N.NiceIcon,{name:"upload",size:14}),disabled:!q,onClick:()=>void ge("nsp")},{id:"export-svg",label:m("buildings.svgVectorGraphicsSvg","SVG Vector Graphics (.svg)"),disabled:!q,onClick:()=>void ge("svg")},{id:"export-dxf",label:m("buildings.autocadDxfDxf","AutoCAD DXF (.dxf)"),disabled:!q,onClick:()=>void ge("dxf")},{id:"export-png",label:m("buildings.pngImagePng","PNG Image (.png)"),disabled:!q,onClick:()=>void ge("png")}]},...o?[]:[{id:"edit",label:m("buildings.menu.edit","Edit"),children:[{id:"undo",label:m("buildings.undoCtrlZ","Undo (Ctrl+Z)"),icon:e.jsx(N.NiceIcon,{name:"undo",size:14}),disabled:!pt,onClick:()=>h({type:"UNDO"})},{id:"redo",label:m("buildings.redoCtrlY","Redo (Ctrl+Y)"),icon:e.jsx(N.NiceIcon,{name:"redo",size:14}),disabled:!mt,onClick:()=>h({type:"REDO"})}]}],{id:"view",label:m("buildings.menu.view","View"),children:[{id:"plan",label:m("buildings.menu.plan","Plan type"),disabled:!0},...s.map(v=>({id:"mode-"+v,label:rt[v].label,icon:Xt(Ee===v),onClick:()=>se(v)})),{id:"d-view",divider:!0},{id:"grid",label:m("buildings.toggleGrid","Toggle Grid"),icon:Xt(re.showGrid),onClick:()=>h({type:"TOGGLE_GRID"})},{id:"snap",label:m("buildings.toggleSnap","Toggle Snap"),icon:Xt(re.snapEnabled),onClick:()=>h({type:"TOGGLE_SNAP"})},{id:"d-zoom",divider:!0},{id:"zoom-in",label:m("buildings.zoomIn","Zoom In"),onClick:()=>h({type:"ZOOM",delta:1})},{id:"zoom-out",label:m("buildings.zoomOut","Zoom Out"),onClick:()=>h({type:"ZOOM",delta:-1})},{id:"reset",label:m("buildings.resetView2","Reset View"),onClick:()=>h({type:"RESET_VIEW"})}]},{id:"help",label:m("buildings.menu.help","Help"),children:[{id:"keys",label:m("buildings.menu.shortcuts","Keyboard shortcuts"),disabled:!0},{id:"key-undo",label:m("buildings.undoCtrlZ","Undo (Ctrl+Z)"),disabled:!0},{id:"key-redo",label:m("buildings.redoCtrlY","Redo (Ctrl+Y)"),disabled:!0},{id:"key-delete",label:m("buildings.shortcut.delete","Delete (Del)"),disabled:!0},{id:"key-cancel",label:m("buildings.shortcut.cancel","Cancel (Esc)"),disabled:!0}]}],_s=e.jsx(N.NiceMenu,{items:fs,orientation:"horizontal"}),bs=He.showObjectLibrary&&!o?e.jsx(Qn,{mode:Ee,onObjectSelect:v=>{h({type:"SET_TOOL",tool:`place-${v.category}`}),h({type:"START_DRAG",objectType:v.category,objectData:v})}}):void 0,ys=e.jsxs("div",{className:U.editorContainer,children:[!o&&e.jsx(uu,{mode:Ee,activeTool:me,onToolSelect:ue,readOnly:o}),(Ee==="network-topology"||Ee==="infrastructure")&&e.jsxs("div",{className:U.modeActions,children:[e.jsxs("button",{className:`${U.actionBtn} ${Q?U.active:""}`,onClick:()=>fe(!Q),title:m("buildings.spatial.pathAnalysis","Network path analysis"),children:[e.jsx(N.NiceIcon,{name:"bar-chart",size:14})," ",m("buildings.spatial.path","Path")]}),e.jsxs("button",{className:`${U.actionBtn} ${Pe?U.active:""}`,onClick:()=>qe(!Pe),title:m("buildings.spatial.vlan.title","VLAN overlay"),children:[e.jsx(N.NiceIcon,{name:"globe",size:14})," ",m("buildings.vlanOverlay","VLAN Overlay")]})]}),e.jsxs("div",{className:U.canvasWrapper,onDragOver:v=>{!o&&v.dataTransfer.types.includes("application/json")&&v.preventDefault()},onDrop:v=>{let $=null;try{$=JSON.parse(v.dataTransfer.getData("application/json"))}catch{return}Pn($)&&(v.preventDefault(),ht(Ze(Fe(v.clientX,v.clientY)),$))},children:[e.jsx("svg",{ref:F,className:`${U.canvas} ${U[`cursor_${me.replace("-","_")}`]??""}`,onMouseDown:Ut,onMouseMove:Yt,onMouseUp:gt,onMouseLeave:gt,onDoubleClick:z,onWheel:R,children:e.jsxs("g",{transform:`translate(${re.pan.x}, ${re.pan.y}) scale(${re.zoom})`,children:[cs(),ls(),ds(),hs(),us(),ps(),ms()]})}),He.showMinimap&&e.jsx(un,{document:q,activeFloorId:Ye,viewport:re,onViewportChange:v=>h({type:"SET_VIEWPORT",viewport:v})})]})]}),xs=e.jsxs("div",{className:U.rightSidebar,children:[He.showLayerPanel&&e.jsx(Jn,{collapsed:Se,onToggleCollapsed:()=>Oe(v=>!v),layers:Ae.filter(v=>et.layerTypes.includes(v.type)),onVisibilityToggle:v=>{var $;return h({type:"SET_LAYER_VISIBILITY",layerType:v,visible:!(($=Ae.find(G=>G.type===v))!=null&&$.visible)})},onLockToggle:v=>{var $;return h({type:"SET_LAYER_LOCKED",layerType:v,locked:!(($=Ae.find(G=>G.type===v))!=null&&$.locked)})},onOpacityChange:(v,$)=>h({type:"SET_LAYER_OPACITY",layerType:v,opacity:$})}),He.showPropertiesPanel&&e.jsx(es,{collapsed:ke,onToggleCollapsed:()=>Ve(v=>!v),selection:we,document:q,onPropertyChange:(v,$,G)=>{if($==="position.x"||$==="position.y"){const W=Ue(q,v),V=W?It(W):null;V&&typeof G=="number"&&Number.isFinite(G)&&h({type:"MOVE_OBJECTS",objectIds:[v],delta:$==="position.x"?{x:G-V.x,y:0}:{x:0,y:G-V.y}});return}h({type:"UPDATE_OBJECT",objectId:v,updates:{[$]:G}})}})]}),vs=e.jsxs("div",{className:U.statusBar,children:[e.jsxs("span",{className:U.modeIndicator,children:[e.jsx(N.NiceIcon,{name:et.icon,size:14})," ",et.label]}),e.jsxs("span",{className:U.toolIndicator,children:[((mn=ct[me])==null?void 0:mn.icon)&&e.jsx(N.NiceIcon,{name:ct[me].icon,size:14})," ",(hn=ct[me])==null?void 0:hn.label]}),we.objectIds.length>0&&e.jsx("span",{className:U.selectionInfo,children:m("buildings.selected2","{objectIds} selected").replace("{objectIds}",String(we.objectIds.length))}),ye.active&&e.jsx("span",{className:U.drawingInfo,children:m("buildings.drawingPoints","Drawing: {points} points").replace("{points}",String(ye.points.length))}),pe.active&&e.jsx("span",{className:U.connectingInfo,children:m("buildings.connectingClickTargetDeviceOr","Connecting: click target device or ESC to cancel")}),e.jsx("span",{className:U.gridInfo,children:m("buildings.gridSnap","Grid: {size}px · Snap: {snap}").replace("{size}",String(re.gridSize)).replace("{snap}",re.snapEnabled?m("buildings.on","ON"):m("buildings.off","OFF"))})]});return e.jsxs("div",{className:`nice-spatial-editor ${U.root} ${U[i]} ${y??""}`,style:{position:"relative",...b},tabIndex:0,onKeyDown:ee,children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:e.jsx(N.NiceTutorialButton,{steps:N.resolveTutorial(f,hu)})}),e.jsx(N.NiceAppShell,{flush:!0,className:U.shell,menubar:_s,toolbar:gs,sidebar:bs,rightSidebar:xs,statusBar:vs,children:ys}),xe&&!Ge&&e.jsx(Ga,{result:xe,onConfirm:De,onCancel:Zt}),xe&&Ge&&e.jsx(_i,{importResult:xe,existingDocument:q??void 0,onConfirm:is,onCancel:rs}),Q&&q&&e.jsx(Pr,{document:q,connections:On(q),onHighlightPath:v=>{h(v?{type:"SET_SELECTION",selection:{objectIds:v.connectionIds,bounds:null,locked:!1}}:{type:"SET_SELECTION",selection:{objectIds:[],bounds:null,locked:!1}})},onClose:()=>fe(!1)}),Pe&&q&&e.jsx(Sl,{document:q,connections:On(q),vlans:pu(q),visibleVlanIds:We,onVlanVisibilityChange:(v,$)=>{Re(G=>{const W=new Set(G);return $?W.add(v):W.delete(v),W})},onHighlightVlan:v=>{lt((v==null?void 0:v.id)??null),h(v?{type:"SET_SELECTION",selection:{objectIds:v.deviceIds,bounds:null,locked:!1}}:{type:"SET_SELECTION",selection:{objectIds:[],bounds:null,locked:!1}})},onClose:()=>qe(!1)})]})},fu="_viewer_103dp_13",_u="_theme_light_103dp_37",bu="_theme_dark_103dp_59",yu="_debugOverlay_103dp_85",xu="_topBar_103dp_137",vu="_searchContainer_103dp_159",ju="_searchInput_103dp_171",wu="_clearBtn_103dp_227",Nu="_searchResults_103dp_261",Iu="_searchResultItem_103dp_291",ku="_searchResultInfo_103dp_335",Su="_searchResultName_103dp_347",Cu="_searchResultDesc_103dp_357",Tu="_floorSelector_103dp_371",Lu="_navBtn_103dp_421",$u="_active_103dp_459",zu="_layersBtn_103dp_475",Pu="_legendBtn_103dp_529",Eu="_content_103dp_583",Ou="_navPanel_103dp_599",Mu="_navPanelHeader_103dp_617",Au="_routeInputs_103dp_671",Du="_routeInput_103dp_671",Bu="_routeMarker_103dp_705",Ru="_routeHint_103dp_745",Fu="_routeInfo_103dp_761",Gu="_routeStat_103dp_779",Vu="_routeStatLabel_103dp_791",qu="_routeStatValue_103dp_805",Wu="_clearRouteBtn_103dp_817",Hu="_refPointsList_103dp_851",Uu="_refPointItem_103dp_879",Yu="_refPointIcon_103dp_917",Zu="_layersPanel_103dp_929",Xu="_layersPanelHeader_103dp_947",Ku="_layersList_103dp_1001",Ju="_layerItem_103dp_1015",Qu="_layerToggle_103dp_1039",ep="_layerName_103dp_1075",tp="_layerType_103dp_1087",np="_canvasWrapper_103dp_1101",sp="_canvas_103dp_1101",op="_grid_103dp_1137",ap="_gridLine_103dp_1145",ip="_zonesLayer_103dp_1161",rp="_zone_103dp_1161",cp="_zoneSelected_103dp_1187",lp="_zoneLabel_103dp_1197",dp="_objectsLayer_103dp_1213",up="_object_103dp_1213",pp="_objectSelected_103dp_1237",mp="_objectLabel_103dp_1245",hp="_referencePoints_103dp_1261",gp="_referencePoint_103dp_1261",fp="_refLabel_103dp_1283",_p="_routeLayer_103dp_1299",bp="_routePath_103dp_1305",yp="_routeDash_103dp_1",xp="_routeMarkers_103dp_1331",vp="_currentLocation_103dp_1341",jp="_locationPulse_103dp_1347",wp="_pulse_103dp_1",Np="_zoomControls_103dp_1383",Ip="_minimapHost_103dp_1461",kp="_legendPanel_103dp_1477",Sp="_legendPanelHeader_103dp_1509",Cp="_legendList_103dp_1565",Tp="_legendItem_103dp_1581",Lp="_legendColor_103dp_1605",$p="_legendIcon_103dp_1621",zp="_legendLabel_103dp_1635",Pp="_legendType_103dp_1647",Ep="_objectInfo_103dp_1665",Op="_objectInfoHeader_103dp_1693",Mp="_navigateBtn_103dp_1763",E={viewer:fu,theme_light:_u,theme_dark:bu,debugOverlay:yu,topBar:xu,searchContainer:vu,searchInput:ju,clearBtn:wu,searchResults:Nu,searchResultItem:Iu,searchResultInfo:ku,searchResultName:Su,searchResultDesc:Cu,floorSelector:Tu,navBtn:Lu,active:$u,layersBtn:zu,legendBtn:Pu,content:Eu,navPanel:Ou,navPanelHeader:Mu,routeInputs:Au,routeInput:Du,routeMarker:Bu,routeHint:Ru,routeInfo:Fu,routeStat:Gu,routeStatLabel:Vu,routeStatValue:qu,clearRouteBtn:Wu,refPointsList:Hu,refPointItem:Uu,refPointIcon:Yu,layersPanel:Zu,layersPanelHeader:Xu,layersList:Ku,layerItem:Ju,layerToggle:Qu,layerName:ep,layerType:tp,canvasWrapper:np,canvas:sp,grid:op,gridLine:ap,zonesLayer:ip,zone:rp,zoneSelected:cp,zoneLabel:lp,objectsLayer:dp,object:up,objectSelected:pp,objectLabel:mp,referencePoints:hp,referencePoint:gp,refLabel:fp,routeLayer:_p,routePath:bp,routeDash:yp,routeMarkers:xp,currentLocation:vp,locationPulse:jp,pulse:wp,zoomControls:Np,minimapHost:Ip,legendPanel:kp,legendPanelHeader:Sp,legendList:Cp,legendItem:Tp,legendColor:Lp,legendIcon:$p,legendLabel:zp,legendType:Pp,objectInfo:Ep,objectInfoHeader:Op,navigateBtn:Mp},Ap=()=>e.jsx(N.NiceIcon,{name:"search",size:16}),Mn=()=>e.jsx(N.NiceIcon,{name:"navigation",size:16}),Dp=()=>e.jsx(N.NiceIcon,{name:"map-pin",size:16}),Bp=()=>e.jsx(N.NiceIcon,{name:"building",size:16}),Rp=()=>e.jsx(N.NiceIcon,{name:"git-branch",size:16}),Fp=()=>e.jsx(N.NiceIcon,{name:"zoom-in",size:16}),Gp=()=>e.jsx(N.NiceIcon,{name:"zoom-out",size:16}),vt=()=>e.jsx(N.NiceIcon,{name:"close",size:16}),An=()=>e.jsx(N.NiceIcon,{name:"layers",size:16}),Dn=()=>e.jsx(N.NiceIcon,{name:"list",size:16}),Vp=()=>e.jsx(N.NiceIcon,{name:"eye",size:16}),qp=()=>e.jsx(N.NiceIcon,{name:"eye-off",size:16}),Wp={entrance:"door",elevator:"elevator",stairs:"stairs",exit:"bell",poi:"map-pin",parking:"map-pin"};function on(t){return t.icon??Wp[t.type]??"map-pin"}function Hp(t,n){return Math.sqrt((n.x-t.x)**2+(n.y-t.y)**2)}function Up(t){return t<1?"<1m":t<1e3?`${Math.round(t)}m`:`${(t/1e3).toFixed(1)}km`}function Yp(t){if(t<60)return"<1 min";const n=Math.round(t/60);if(n<60)return`${n} min`;const s=Math.floor(n/60),o=n%60;return`${s}h ${o}min`}const Zp=Rt(""),Xp=({document:t=Zp,initialFloorId:n,showNavigation:s=!0,showMinimap:o=!0,showFloorSelector:i=!0,showSearch:a=!0,showLayersPanel:c=!0,showLegend:r=!0,enableRoutePlanning:d=!0,referencePoints:_=[],onObjectClick:p,onRouteCalculated:f,currentLocation:y,theme:b="light",className:j,virtualRendering:w,virtualRenderingThreshold:x=200,debugVirtualRendering:C=!1})=>{var gt;const{t:g}=N.useNiceTranslation(),[L,m]=u.useState(n??((gt=t.floors[0])==null?void 0:gt.id)??""),[k,l]=u.useState({zoom:1,pan:{x:0,y:0}}),I=u.useMemo(()=>({zoom:k.zoom,pan:k.pan,rotation:0,showGrid:!1,gridSize:20,snapEnabled:!1,snapModes:[]}),[k]),[h,F]=u.useState(""),[T,B]=u.useState([]),[H,ne]=u.useState(null),[te,ie]=u.useState(null),[_e,de]=u.useState(null),[Ne,Je]=u.useState(null),[Be,xe]=u.useState(!1),[ze,Ge]=u.useState(!1),[P,Q]=u.useState(!1),[fe,Se]=u.useState(new Map),[Oe,ke]=u.useState({width:1e3,height:600}),Ve=u.useRef(null),Pe=u.useRef(null),qe=u.useRef(!1),We=u.useRef({x:0,y:0}),Re=u.useMemo(()=>{const S=t.floors.find(z=>z.id===L);return S?S.layers.reduce((z,R)=>{var ee;return z+(((ee=R.objects)==null?void 0:ee.length)??0)},0):0},[t.floors,L]),$e=w??ca(Re,x),lt=u.useMemo(()=>{if(!$e)return null;const S=t.floors.find(R=>R.id===L);if(!S)return null;const z=[];for(const R of S.layers)if(!(R.type==="zones"||R.type==="grid"||R.type==="background"))for(const ee of R.objects??[]){const se=nn(ee)??{x:0,y:0},ue=$n(ee);z.push({id:ee.id,position:se,size:ue,data:{object:ee,layerId:R.id}})}return ia(z)},[t.floors,L,$e]),dt=u.useMemo(()=>ra(k,Oe,100),[k,Oe]),Me=u.useMemo(()=>!$e||!lt?null:lt.query(dt),[$e,lt,dt]),Ce=u.useMemo(()=>!C||!$e?null:la(Re,(Me==null?void 0:Me.length)??Re,k),[C,$e,Re,Me,k]);u.useEffect(()=>{const S=Pe.current;if(!S)return;const z=new ResizeObserver(R=>{for(const ee of R)ke({width:ee.contentRect.width,height:ee.contentRect.height})});return z.observe(S),()=>z.disconnect()},[]),u.useEffect(()=>{const S=t.floors.find(z=>z.id===L);S&&Se(z=>{const R=new Map;for(const ee of S.layers)R.set(ee.id,z.get(ee.id)??!0);return R})},[L,t.floors]);const Ee=u.useCallback(S=>{Se(z=>{const R=new Map(z);return R.set(S,!z.get(S)),R})},[]),me=u.useCallback(S=>fe.get(S)!==!1,[fe]),q=u.useMemo(()=>t.floors.find(S=>S.id===L)??t.floors[0],[t.floors,L]),Ye=u.useMemo(()=>{if(!q)return[];const S=[],z=it(q.layers);if(z){const se=new Map;for(const ue of z.objects){const ge=ue.metadata,Te=(ge==null?void 0:ge.zoneType)??ue.type??"zone";se.has(Te)||se.set(Te,Ft(ue)??"var(--nice-primary, #3b82f6)")}for(const[ue,ge]of se)S.push({id:`zone-${ue}`,label:ue.charAt(0).toUpperCase()+ue.slice(1).replace(/-/g," "),color:ge,type:"zone"})}const R=new Map;for(const se of q.layers)if(!(se.type==="zones"||se.type==="grid"||se.type==="background"))for(const ue of se.objects){const ge=ue.type??"object",Te=R.get(ge);Te?Te.count++:R.set(ge,{count:1,color:"var(--nice-text-secondary, #64748b)"})}for(const[se,ue]of R)S.push({id:`obj-${se}`,label:`${se.charAt(0).toUpperCase()+se.slice(1).replace(/-/g," ")} (${ue.count})`,color:ue.color,type:"object"});const ee=new Map;for(const se of _.filter(ue=>ue.floorId===L))ee.has(se.type)||ee.set(se.type,on(se));for(const[se,ue]of ee)S.push({id:`ref-${se}`,label:se.charAt(0).toUpperCase()+se.slice(1),color:"var(--nice-primary, #3b82f6)",icon:ue,type:"reference"});return S},[q,_,L]),Ae=u.useCallback((S,z)=>{var ee;const R=(ee=Ve.current)==null?void 0:ee.getBoundingClientRect();return R?{x:(S-R.left-k.pan.x)/k.zoom,y:(z-R.top-k.pan.y)/k.zoom}:{x:0,y:0}},[k]);u.useEffect(()=>{if(!h.trim()){B([]);return}const S=h.toLowerCase(),z=[];for(const R of t.floors)for(const ee of R.layers)for(const se of ee.objects){const ue=(se.name??se.id).toLowerCase(),ge=(se.description??"").toLowerCase();(ue.includes(S)||ge.includes(S))&&z.push(se)}B(z.slice(0,10))},[h,t.floors]);const we=u.useCallback((S,z)=>{const R=Hp(S,z);return{id:`route-${Date.now()}`,startPoint:S,endPoint:z,path:[S,z],floorTransitions:[],totalDistance:R,estimatedTime:R/1.4,instructions:[{type:"straight",distance:R,direction:"forward"},{type:"arrive"}]}},[]);u.useEffect(()=>{if(te&&_e){const S=we(te,_e);Je(S),f==null||f(S)}else Je(null),f==null||f(null)},[te,_e,we,f]);const re=u.useCallback(S=>{(S.button===1||S.button===0&&S.altKey)&&(qe.current=!0,We.current={x:S.clientX,y:S.clientY},S.preventDefault())},[]),ye=u.useCallback(S=>{if(qe.current){const z=S.clientX-We.current.x,R=S.clientY-We.current.y;We.current={x:S.clientX,y:S.clientY},l(ee=>({...ee,pan:{x:ee.pan.x+z,y:ee.pan.y+R}}))}},[]),pe=u.useCallback(()=>{qe.current=!1},[]),ut=u.useCallback(S=>{var ue;S.preventDefault();const z=S.deltaY>0?.9:1.1,R=(ue=Ve.current)==null?void 0:ue.getBoundingClientRect();if(!R)return;const ee=S.clientX-R.left,se=S.clientY-R.top;l(ge=>{const Te=Math.min(Math.max(ge.zoom*z,.1),10),De=Te/ge.zoom;return{zoom:Te,pan:{x:ee-(ee-ge.pan.x)*De,y:se-(se-ge.pan.y)*De}}})},[]),He=u.useCallback(S=>{if(d&&S.ctrlKey){const z=Ae(S.clientX,S.clientY);te?_e?(ie(z),de(null)):de(z):ie(z)}},[d,te,_e,Ae]),kt=u.useCallback(()=>{l(S=>({...S,zoom:Math.min(S.zoom*1.25,10)}))},[]),Qe=u.useCallback(()=>{l(S=>({...S,zoom:Math.max(S.zoom/1.25,.1)}))},[]),et=u.useCallback(()=>{l({zoom:1,pan:{x:0,y:0}})},[]),pt=u.useCallback(S=>{ne(S);for(const R of t.floors)for(const ee of R.layers)if(ee.objects.find(se=>se.id===S.id)){m(R.id);break}const z=nn(S)??{x:0,y:0};l(R=>({...R,pan:{x:-(z.x*R.zoom)+400,y:-(z.y*R.zoom)+300}})),F(""),B([]),p==null||p(S)},[t.floors,p]),mt=u.useCallback(()=>{ie(null),de(null),Je(null)},[]),St=u.useCallback(()=>{const z=[];for(let R=-2e3;R<=2e3;R+=50)z.push(e.jsx("line",{x1:R,y1:-2e3,x2:R,y2:2e3,className:E.gridLine},`v-${R}`));for(let R=-2e3;R<=2e3;R+=50)z.push(e.jsx("line",{x1:-2e3,y1:R,x2:2e3,y2:R,className:E.gridLine},`h-${R}`));return e.jsx("g",{className:E.grid,children:z})},[]),he=u.useCallback(()=>{if(!q)return null;const S=it(q.layers);return!S||!me(S.id)?null:e.jsx("g",{className:E.zonesLayer,children:S.objects.map(z=>{const R=Ht(z);if(!R)return null;const ee={points:R,fill:Ft(z)},se=`M${ee.points.map(ge=>`${ge.x},${ge.y}`).join(" L")} Z`,ue=(H==null?void 0:H.id)===z.id;return e.jsxs("g",{className:`${E.zone} ${ue?E.zoneSelected:""}`,onClick:()=>{ne(z),p==null||p(z)},children:[e.jsx("path",{d:se,fill:ee.fill??"var(--nice-primary, #3b82f6)",fillOpacity:.2,stroke:ee.fill??"var(--nice-primary, #3b82f6)",strokeWidth:ue?2:1}),z.name&&e.jsx("text",{x:ee.points[0].x+10,y:ee.points[0].y+20,className:E.zoneLabel,children:z.name})]},z.id)})})},[q,H,p,me]),Fe=u.useCallback(()=>{if(!q)return null;const S=z=>{const R=(H==null?void 0:H.id)===z.id,ee=`${E.object} ${R?E.objectSelected:""}`,se=Zt=>{Zt.stopPropagation(),ne(z),p==null||p(z)},ue=dn(z),ge=ue??zi(z);if(ge)return e.jsx("line",{className:ee,x1:ge.start.x,y1:ge.start.y,x2:ge.end.x,y2:ge.end.y,stroke:R?"var(--nice-primary, #3b82f6)":ue?"var(--nice-text-primary, #334155)":"var(--nice-text-secondary, #64748b)",strokeWidth:ue?6:2,strokeLinecap:"round",onClick:se},z.id);const Te=nn(z)??{x:0,y:0},De=$n(z);return e.jsxs("g",{className:ee,transform:`translate(${Te.x}, ${Te.y})`,onClick:se,children:[e.jsx("rect",{x:-De.width/2,y:-De.height/2,width:De.width,height:De.height,rx:4,fill:R?"var(--nice-primary, #3b82f6)":"var(--nice-text-secondary, #64748b)",fillOpacity:.8,stroke:R?"var(--nice-primary-dark, #1d4ed8)":"transparent",strokeWidth:2}),z.name&&e.jsx("text",{y:De.height/2+14,textAnchor:"middle",className:E.objectLabel,children:z.name})]},z.id)};return $e&&Me?e.jsx("g",{className:E.objectsLayer,children:Me.map(z=>{const{object:R,layerId:ee}=z.data;return me(ee)?S(R):null})}):e.jsx("g",{className:E.objectsLayer,children:q.layers.map(z=>z.type==="zones"||z.type==="grid"||z.type==="background"||!me(z.id)?null:z.objects.map(S))})},[q,H,p,me,$e,Me]),Ze=u.useCallback(()=>{const S=_.filter(z=>z.floorId===L);return e.jsx("g",{className:E.referencePoints,children:S.map(z=>e.jsxs("g",{className:E.referencePoint,transform:`translate(${z.position.x}, ${z.position.y})`,onClick:()=>{d&&(te?de(z.position):ie(z.position))},children:[e.jsx("circle",{r:16,fill:"white",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:2}),e.jsx("g",{transform:"translate(-8, -8)",style:{color:"var(--nice-primary, #3b82f6)"},"aria-hidden":"true",children:e.jsx(N.NiceIcon,{name:on(z),size:16})}),e.jsx("text",{y:30,textAnchor:"middle",className:E.refLabel,children:z.name})]},z.id))})},[_,L,d,te]),ht=u.useCallback(()=>{if(!Ne)return null;const S=`M${Ne.path.map(z=>`${z.x},${z.y}`).join(" L")}`;return e.jsxs("g",{className:E.routeLayer,children:[e.jsx("path",{d:S,fill:"none",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:4,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"12,6",className:E.routePath}),e.jsx("circle",{cx:Ne.startPoint.x,cy:Ne.startPoint.y,r:8,fill:"var(--nice-success, #10b981)",stroke:"white",strokeWidth:2}),e.jsx("circle",{cx:Ne.endPoint.x,cy:Ne.endPoint.y,r:8,fill:"var(--nice-danger, #ef4444)",stroke:"white",strokeWidth:2})]})},[Ne]),Ut=u.useCallback(()=>y?e.jsxs("g",{className:E.currentLocation,children:[e.jsx("circle",{cx:y.x,cy:y.y,r:12,fill:"var(--nice-primary, #3b82f6)",fillOpacity:.3,className:E.locationPulse}),e.jsx("circle",{cx:y.x,cy:y.y,r:6,fill:"var(--nice-primary, #3b82f6)",stroke:"white",strokeWidth:2})]}):null,[y]),Yt=u.useCallback(()=>e.jsx("g",{className:E.routeMarkers,children:te&&!Ne&&e.jsx("circle",{cx:te.x,cy:te.y,r:8,fill:"var(--nice-success, #10b981)",stroke:"white",strokeWidth:2})}),[te,Ne]);return e.jsxs("div",{ref:Pe,className:`${E.viewer} ${E[`theme_${b}`]} ${j??""}`,children:[C&&Ce&&e.jsxs("div",{className:E.debugOverlay,children:[e.jsx("div",{children:g("buildings.virtualOn","Virtual: ON")}),e.jsx("div",{children:g("buildings.total","Total: {total}").replace("{total}",String(Ce.total))}),e.jsx("div",{children:g("buildings.visible","Visible: {visible}").replace("{visible}",String(Ce.visible))}),e.jsx("div",{children:g("buildings.culled","Culled: {culled} ({cullPercentage}%)").replace("{culled}",String(Ce.culled)).replace("{cullPercentage}",String(Ce.cullPercentage))}),e.jsx("div",{children:g("buildings.zoomX","Zoom: {zoom}x").replace("{zoom}",String(Ce.zoom.toFixed(2)))})]}),e.jsxs("div",{className:E.topBar,children:[a&&e.jsxs("div",{className:E.searchContainer,children:[e.jsxs("div",{className:E.searchInput,children:[e.jsx(Ap,{}),e.jsx("input",{type:"text",placeholder:g("buildings.spatial.searchPlaces","Search places…"),value:h,onChange:S=>F(S.target.value)}),h&&e.jsx("button",{className:E.clearBtn,onClick:()=>F(""),children:e.jsx(vt,{})})]}),T.length>0&&e.jsx("div",{className:E.searchResults,children:T.map(S=>e.jsxs("button",{className:E.searchResultItem,onClick:()=>pt(S),children:[e.jsx(Dp,{}),e.jsxs("div",{className:E.searchResultInfo,children:[e.jsx("span",{className:E.searchResultName,children:S.name??S.id}),S.description&&e.jsx("span",{className:E.searchResultDesc,children:S.description})]})]},S.id))})]}),i&&t.floors.length>1&&e.jsxs("div",{className:E.floorSelector,children:[e.jsx(Bp,{}),e.jsx("select",{value:L,onChange:S=>m(S.target.value),children:t.floors.map(S=>e.jsx("option",{value:S.id,children:S.name??g("buildings.floorLevel","Floor {level}").replace("{level}",String(S.level))},S.id))})]}),s&&e.jsxs("button",{className:`${E.navBtn} ${Be?E.active:""}`,onClick:()=>xe(!Be),children:[e.jsx(Mn,{}),e.jsx("span",{children:g("buildings.navigation","Navigation")})]}),c&&e.jsxs("button",{className:`${E.layersBtn} ${ze?E.active:""}`,onClick:()=>Ge(!ze),children:[e.jsx(An,{}),e.jsx("span",{children:g("buildings.layers","Layers")})]}),r&&e.jsxs("button",{className:`${E.legendBtn} ${P?E.active:""}`,onClick:()=>Q(!P),children:[e.jsx(Dn,{}),e.jsx("span",{children:g("buildings.legend","Legend")})]})]}),e.jsxs("div",{className:E.content,children:[Be&&e.jsxs("div",{className:E.navPanel,children:[e.jsxs("div",{className:E.navPanelHeader,children:[e.jsx(Rp,{}),e.jsx("span",{children:g("buildings.routePlanning","Route planning")}),e.jsx("button",{onClick:()=>xe(!1),children:e.jsx(vt,{})})]}),e.jsxs("div",{className:E.routeInputs,children:[e.jsxs("div",{className:E.routeInput,children:[e.jsx("div",{className:E.routeMarker,style:{background:"var(--nice-success, #10b981)"}}),e.jsx("input",{type:"text",placeholder:g("buildings.startPoint","Start point"),value:te?`${te.x.toFixed(0)}, ${te.y.toFixed(0)}`:"",readOnly:!0})]}),e.jsxs("div",{className:E.routeInput,children:[e.jsx("div",{className:E.routeMarker,style:{background:"var(--nice-danger, #ef4444)"}}),e.jsx("input",{type:"text",placeholder:g("buildings.destination","Destination"),value:_e?`${_e.x.toFixed(0)}, ${_e.y.toFixed(0)}`:"",readOnly:!0})]})]}),e.jsx("p",{className:E.routeHint,children:g("buildings.spatial.routeHint","Ctrl-click the map to pick points")}),Ne&&e.jsxs("div",{className:E.routeInfo,children:[e.jsxs("div",{className:E.routeStat,children:[e.jsx("span",{className:E.routeStatLabel,children:g("buildings.distance","Distance")}),e.jsx("span",{className:E.routeStatValue,children:Up(Ne.totalDistance)})]}),e.jsxs("div",{className:E.routeStat,children:[e.jsx("span",{className:E.routeStatLabel,children:g("buildings.spatial.time","Time")}),e.jsx("span",{className:E.routeStatValue,children:Yp(Ne.estimatedTime)})]})]}),(te||_e)&&e.jsx("button",{className:E.clearRouteBtn,onClick:mt,children:g("buildings.spatial.clearRoute","Clear the route")}),_.length>0&&e.jsxs("div",{className:E.refPointsList,children:[e.jsx("h4",{children:g("buildings.landmarks","Landmarks")}),_.filter(S=>S.floorId===L).map(S=>e.jsxs("button",{className:E.refPointItem,onClick:()=>{te?de(S.position):ie(S.position)},children:[e.jsx("span",{className:E.refPointIcon,children:e.jsx(N.NiceIcon,{name:on(S),size:16})}),e.jsx("span",{children:S.name})]},S.id))]})]}),ze&&q&&e.jsxs("div",{className:E.layersPanel,children:[e.jsxs("div",{className:E.layersPanelHeader,children:[e.jsx(An,{}),e.jsx("span",{children:g("buildings.layers","Layers")}),e.jsx("button",{onClick:()=>Ge(!1),children:e.jsx(vt,{})})]}),e.jsx("div",{className:E.layersList,children:q.layers.map(S=>{const z=me(S.id);return e.jsxs("div",{className:E.layerItem,children:[e.jsx("button",{className:E.layerToggle,onClick:()=>Ee(S.id),title:z?g("buildings.spatial.hideLayer","Hide layer"):g("buildings.spatial.showLayer","Show layer"),children:z?e.jsx(Vp,{}):e.jsx(qp,{})}),e.jsx("span",{className:E.layerName,children:S.name??S.id}),e.jsxs("span",{className:E.layerType,children:["(",S.type,")"]})]},S.id)})})]}),e.jsxs("div",{className:E.canvasWrapper,children:[e.jsx("svg",{ref:Ve,className:E.canvas,onMouseDown:re,onMouseMove:ye,onMouseUp:pe,onMouseLeave:pe,onWheel:ut,onClick:He,children:e.jsxs("g",{transform:`translate(${k.pan.x}, ${k.pan.y}) scale(${k.zoom})`,children:[St(),he(),Fe(),Ze(),Yt(),ht(),Ut()]})}),e.jsxs("div",{className:E.zoomControls,children:[e.jsx("button",{onClick:kt,title:g("buildings.spatial.zoomIn","Zoom in"),children:e.jsx(Fp,{})}),e.jsx("button",{onClick:Qe,title:g("buildings.spatial.zoomOut","Zoom out"),children:e.jsx(Gp,{})}),e.jsx("button",{onClick:et,title:g("buildings.spatial.resetView","Reset the view"),children:e.jsx(N.NiceIcon,{name:"refresh",size:16})})]}),o&&e.jsx(un,{className:E.minimapHost,document:t,activeFloorId:L,viewport:I,onViewportChange:S=>l(z=>({zoom:S.zoom??z.zoom,pan:S.pan??z.pan}))}),P&&Ye.length>0&&e.jsxs("div",{className:E.legendPanel,children:[e.jsxs("div",{className:E.legendPanelHeader,children:[e.jsx(Dn,{}),e.jsx("span",{children:g("buildings.legend","Legend")}),e.jsx("button",{onClick:()=>Q(!1),children:e.jsx(vt,{})})]}),e.jsx("div",{className:E.legendList,children:Ye.map(S=>e.jsxs("div",{className:E.legendItem,children:[S.icon?e.jsx("span",{className:E.legendIcon,children:e.jsx(N.NiceIcon,{name:S.icon,size:16})}):e.jsx("span",{className:E.legendColor,style:{background:S.color}}),e.jsx("span",{className:E.legendLabel,children:S.label}),e.jsx("span",{className:E.legendType,children:S.type==="zone"?g("buildings.zone","zone"):S.type==="object"?g("buildings.object","object"):g("buildings.referencePoint","reference point")})]},S.id))})]})]})]}),H&&e.jsxs("div",{className:E.objectInfo,children:[e.jsxs("div",{className:E.objectInfoHeader,children:[e.jsx("h4",{children:H.name??H.id}),e.jsx("button",{onClick:()=>ne(null),children:e.jsx(vt,{})})]}),H.description&&e.jsx("p",{children:H.description}),d&&e.jsxs("button",{className:E.navigateBtn,onClick:()=>{const S=H.position??{x:0,y:0};te?de(S):ie(S)},children:[e.jsx(Mn,{}),te?g("buildings.setAsDestination","Set as destination"):g("buildings.setAsStart","Set as start")]})]})]})};function Kp(t={}){var te;const{initialDocument:n,defaultMode:s="floor-plan",gridSize:o=20,snapEnabled:i=!0,onChange:a}=t,c={mode:s,tool:"select",document:n??null,activeFloorId:((te=n==null?void 0:n.floors[0])==null?void 0:te.id)??null,layers:[],selection:{objectIds:[],bounds:null,locked:!1},viewport:{zoom:1,pan:{x:0,y:0},rotation:0,showGrid:!0,gridSize:o,snapEnabled:i,snapModes:["grid","endpoint","midpoint"]},drawing:{active:!1,points:[],preview:null},history:{past:[],future:[]},guides:[],dragging:null,connecting:{active:!1,sourceId:null,sourcePosition:null,previewPosition:null},clipboard:[],ui:{showObjectLibrary:!0,showLayerPanel:!0,showPropertiesPanel:!0,showMinimap:!0}},[r,d]=u.useReducer((ie,_e)=>({...ie,..._e}),c),_=u.useCallback(ie=>{d({mode:ie})},[]),p=u.useCallback(ie=>{d({tool:ie})},[]),f=u.useCallback((ie="Untitled")=>{var de;const _e=Rt(ie,"floor-plan");d({document:_e,activeFloorId:((de=_e.floors[0])==null?void 0:de.id)??null}),a==null||a(_e)},[a]),y=u.useCallback(ie=>{var _e;d({document:ie,activeFloorId:((_e=ie.floors[0])==null?void 0:_e.id)??null}),a==null||a(ie)},[a]),b=u.useCallback(ie=>{d({viewport:{...r.viewport,zoom:Math.max(.1,Math.min(10,r.viewport.zoom*(1+ie*.1)))}})},[r.viewport]),j=u.useCallback(ie=>{d({viewport:{...r.viewport,pan:{x:r.viewport.pan.x+ie.x,y:r.viewport.pan.y+ie.y}}})},[r.viewport]),w=u.useCallback(()=>{d({viewport:{...r.viewport,zoom:1,pan:{x:0,y:0}}})},[r.viewport]),x=u.useCallback(()=>{d({viewport:{...r.viewport,showGrid:!r.viewport.showGrid}})},[r.viewport]),C=u.useCallback(()=>{d({viewport:{...r.viewport,snapEnabled:!r.viewport.snapEnabled}})},[r.viewport]),g=u.useCallback(ie=>{d({viewport:{...r.viewport,gridSize:ie}})},[r.viewport]),L=u.useCallback((ie,_e)=>{d({layers:r.layers.map(de=>de.type===ie?{...de,visible:_e}:de)})},[r.layers]),m=u.useCallback((ie,_e)=>{d({layers:r.layers.map(de=>de.type===ie?{...de,locked:_e}:de)})},[r.layers]),k=u.useCallback(ie=>{d({selection:{objectIds:ie,bounds:null,locked:!1}})},[]),l=u.useCallback(()=>{d({selection:{objectIds:[],bounds:null,locked:!1}})},[]),I=u.useCallback(()=>{},[]),h=u.useCallback(()=>{},[]),F=r.history.past.length>0,T=r.history.future.length>0,B=u.useCallback(()=>{},[]),H=u.useCallback(ie=>{},[]),ne=u.useCallback(()=>{},[]);return{state:r,setMode:_,setTool:p,newDocument:f,loadDocument:y,zoom:b,pan:j,resetView:w,toggleGrid:x,toggleSnap:C,setGridSize:g,setLayerVisible:L,setLayerLocked:m,select:k,clearSelection:l,undo:I,redo:h,canUndo:F,canRedo:T,copy:B,paste:H,cut:ne}}function Jp(t={}){const{gridSize:n=20,enabled:s=!0,snapModes:o=["grid","endpoint","midpoint"],objects:i=[],threshold:a=10}=t,c=u.useMemo(()=>({...wo,cellSize:n,snapModes:o,snapThreshold:a}),[n,o,a]),r=u.useMemo(()=>i.map((b,j)=>({id:`obj-${j}`,bounds:b})),[i]),d=u.useCallback(b=>s?ln(b,c):b,[s,c]),_=u.useCallback(b=>s?No(b,n):b,[s,n]),p=u.useCallback(b=>{if(!s||r.length===0)return[];const j={x:b.x,y:b.y,width:0,height:0};return Yn(j,r,a)},[s,r,a]),f=u.useCallback(b=>{if(!s)return{point:b,snapped:!1,guides:[]};const j=Co(b,r,c);return{point:j.position,snapped:j.snapped,guides:j.guides??[]}},[s,c,r]),y=u.useCallback((b,j)=>{const w=[];for(let x=0;x<=b;x+=n)w.push({x1:x,y1:0,x2:x,y2:j});for(let x=0;x<=j;x+=n)w.push({x1:0,y1:x,x2:b,y2:x});return w},[n]);return{snap:d,snap3D:_,getGuides:p,performAdvancedSnap:f,generateGridLines:y}}function Qp(t={}){const{unitSystem:n="metric",lengthUnit:s="m",areaUnit:o="m2",angleUnit:i="deg",scale:a=100}=t,[c,r]=u.useState(null),[d,_]=u.useState([]),p=u.useCallback(l=>l/a,[a]),f=u.useCallback(l=>{r(l),_([])},[]),y=u.useCallback((l,I=!1)=>{_(h=>[...h,{position:l,snapped:I}])},[]),b=u.useCallback(()=>{r(null),_([])},[]),j=u.useCallback(()=>{if(!c||d.length<2)return null;const l=d.map(I=>I.position);if(c==="distance"&&d.length===2){const I=wt(l[0],l[1]),h=p(I);return{type:"distance",value:h,formatted:zt(h,n).formatted,points:l}}if(c==="angle"&&d.length===3){const I=Jt(l[0],l[1],l[2]);return{type:"angle",value:I,formatted:en(I,i).formatted,points:l}}if(c==="area"&&d.length>=3){const h=Qt(l)/(a*a);return{type:"area",value:h,formatted:tn(h,n).formatted,points:l}}return null},[c,d,a,n,i,p]),w=d.length>=2&&c==="distance"?zt(p(wt(d[0].position,d[d.length-1].position)),n).formatted:null,x=d.length>=3&&c==="angle"?en(Jt(d[0].position,d[1].position,d[2].position),i).formatted:null,C=d.length>=3&&c==="area"?tn(Qt(d.map(l=>l.position))/(a*a),n).formatted:null,g=u.useCallback((l,I)=>{const h=wt(l,I),F=p(h);return{value:F,formatted:zt(F,n).formatted}},[p,n]),L=u.useCallback((l,I,h)=>{const F=Jt(l,I,h);return{value:F,formatted:en(F,i).formatted}},[i]),m=u.useCallback(l=>{const h=Qt(l)/(a*a);return{value:h,formatted:tn(h,n).formatted}},[a,n]),k=u.useCallback(l=>{const I=Po(l),h=p(I);return{value:h,formatted:zt(h,n).formatted}},[p,n]);return{startMeasurement:f,addPoint:y,clearMeasurement:b,finishMeasurement:j,measurementType:c,points:d,liveDistance:w,liveAngle:x,liveArea:C,getDistance:g,getAngle:L,getArea:m,getLength:k}}const em="_root_15owo_3",tm="_dark_15owo_25",nm="_header_15owo_37",sm="_buildingInfo_15owo_51",om="_buildingName_15owo_59",am="_buildingAddress_15owo_81",im="_modeSelector_15owo_95",rm="_modeBtn_15owo_107",cm="_modeBtnActive_15owo_145",lm="_weather_15owo_159",dm="_weatherTemp_15owo_173",um="_weatherDesc_15owo_193",pm="_statsRow_15owo_205",mm="_statsCard_15owo_217",hm="_statsHeader_15owo_247",gm="_statsIcon_15owo_261",fm="_statsLabel_15owo_269",_m="_statsValue_15owo_283",bm="_statsSub_15owo_305",ym="_zoneGrid_15owo_319",xm="_zoneCard_15owo_333",vm="_zoneOccupied_15owo_381",jm="_zoneCardHeader_15owo_389",wm="_zoneCardIcon_15owo_403",Nm="_zoneCardTitles_15owo_411",Im="_zoneCardName_15owo_421",km="_zoneCardArea_15owo_449",Sm="_occupancyBadge_15owo_459",Cm="_occupancyBadgeOn_15owo_477",Tm="_sensorRow_15owo_489",Lm="_sensorChip_15owo_503",$m="_sensorWarn_15owo_521",zm="_deviceList_15owo_535",Pm="_deviceChip_15owo_547",Em="_deviceChipOn_15owo_585",Om="_deviceChipName_15owo_597",Mm="_deviceChipVal_15owo_611",Am="_moreBtn_15owo_621",Dm="_scenesBar_15owo_651",Bm="_sceneBarLabel_15owo_681",Rm="_sceneList_15owo_699",Fm="_sceneBtn_15owo_711",Gm="_sceneBtnActive_15owo_741",J={root:em,dark:tm,header:nm,buildingInfo:sm,buildingName:om,buildingAddress:am,modeSelector:im,modeBtn:rm,modeBtnActive:cm,weather:lm,weatherTemp:dm,weatherDesc:um,statsRow:pm,statsCard:mm,statsHeader:hm,statsIcon:gm,statsLabel:fm,statsValue:_m,statsSub:bm,zoneGrid:ym,zoneCard:xm,zoneOccupied:vm,zoneCardHeader:jm,zoneCardIcon:wm,zoneCardTitles:Nm,zoneCardName:Im,zoneCardArea:km,occupancyBadge:Sm,occupancyBadgeOn:Cm,sensorRow:Tm,sensorChip:Lm,sensorWarn:$m,deviceList:zm,deviceChip:Pm,deviceChipOn:Em,deviceChipName:Om,deviceChipVal:Mm,moreBtn:Am,scenesBar:Dm,sceneBarLabel:Bm,sceneList:Rm,sceneBtn:Fm,sceneBtnActive:Gm},Vm={living_room:"sofa",bedroom:"bed",master_bedroom:"bed",kids_room:"star",bathroom:"droplet",kitchen:"utensils",dining_room:"utensils",hallway:"door",office:"briefcase",garage:"box",gym:"medal",cinema:"video",balcony:"home",garden:"home",open_office:"briefcase",private_office:"monitor",meeting_room:"clipboard",boardroom:"users",reception:"building",server_room:"server",lobby:"building",corridor:"arrow-right",stairwell:"stairs",parking:"box",break_room:"utensils",it_room:"monitor",cafeteria:"utensils"};function qm(t){return Vm[t]??"home"}function Wm(t,n){if(!n.state)return null;const s=n.state;return typeof s.brightness=="number"?`${s.brightness}%`:typeof s.on=="boolean"?s.on?t("buildings.onShort","On"):t("buildings.offShort","Off"):typeof s.temperature=="number"?`${s.temperature.toFixed(1)}°`:typeof s.locked=="boolean"?e.jsx(N.NiceIcon,{name:"lock",size:14}):null}const ns=({zone:t,devices:n=[],expanded:s=!1,onExpand:o,onDeviceControl:i,onClick:a,theme:c="light",className:r,style:d})=>{const{t:_}=N.useNiceTranslation(),p=t.occupancy!=null&&t.occupancy>0,f=s?n:n.slice(0,4);return e.jsxs("div",{role:a?"button":void 0,tabIndex:a?0:void 0,onKeyDown:a?N.clickOnActivationKey:void 0,className:`${J.zoneCard} ${c==="dark"?J.dark:""} ${p?J.zoneOccupied:""} ${r??""}`,style:d,onClick:a,children:[e.jsxs("div",{className:J.zoneCardHeader,children:[e.jsx("span",{className:J.zoneCardIcon,children:e.jsx(N.NiceIcon,{name:qm(t.type),size:18})}),e.jsxs("div",{className:J.zoneCardTitles,children:[e.jsx("span",{className:J.zoneCardName,children:t.name}),t.area!=null&&e.jsxs("span",{className:J.zoneCardArea,children:[t.area," m²"]})]}),t.occupancy!=null&&e.jsxs("span",{className:`${J.occupancyBadge} ${p?J.occupancyBadgeOn:""}`,children:[e.jsx(N.NiceIcon,{name:"users",size:14})," ",t.occupancy]})]}),(t.temperature!=null||t.humidity!=null||t.co2!=null)&&e.jsxs("div",{className:J.sensorRow,children:[t.temperature!=null&&e.jsxs("span",{className:J.sensorChip,children:[e.jsx(N.NiceIcon,{name:"thermometer",size:14})," ",t.temperature.toFixed(1),"°C"]}),t.humidity!=null&&e.jsxs("span",{className:J.sensorChip,children:[e.jsx(N.NiceIcon,{name:"droplet",size:14})," ",t.humidity,"%"]}),t.co2!=null&&e.jsxs("span",{className:`${J.sensorChip} ${t.co2>1e3?J.sensorWarn:""}`,children:["CO₂ ",t.co2]})]}),f.length>0&&e.jsxs("div",{className:J.deviceList,children:[f.map(y=>{const b=y.state,j=(b==null?void 0:b.on)===!0||(b==null?void 0:b.locked)===!1;return e.jsxs("button",{className:`${J.deviceChip} ${j?J.deviceChipOn:""}`,onClick:w=>{w.stopPropagation(),i==null||i(y.id,{on:!j})},title:y.name,children:[e.jsx("span",{children:e.jsx(N.NiceIcon,{name:Hn(y.type),size:14})}),e.jsx("span",{className:J.deviceChipName,children:y.name}),e.jsx("span",{className:J.deviceChipVal,children:Wm(_,y)})]},y.id)}),n.length>4&&e.jsx("button",{className:J.moreBtn,"aria-label":s?_("buildings.showFewer","Show fewer devices"):_("buildings.showAll","Show all devices"),onClick:y=>{y.stopPropagation(),o==null||o()},children:s?e.jsx(N.NiceIcon,{name:"minus",size:12}):`+${n.length-4}`})]})]})},an={home:"Home",away:"Away",night:"Night",vacation:"Vacation",guest:"Guest",party:"Party",occupied:"Occupied",closed:"Closed",weekend:"Weekend",event:"Event",emergency:"Emergency",maintenance:"Maintenance"},Bn={home:"home",away:"external-link",night:"eye-off",vacation:"rocket",guest:"user",party:"gift",occupied:"building",closed:"lock",weekend:"calendar",event:"calendar",emergency:"bell",maintenance:"settings"},Hm=({temperature:t,description:n})=>t!=null?e.jsxs("div",{className:J.weather,children:[e.jsxs("span",{className:J.weatherTemp,children:[t,"°C"]}),n&&e.jsx("span",{className:J.weatherDesc,children:n})]}):null,At=({label:t,value:n,sub:s,icon:o,accent:i})=>e.jsxs("div",{className:J.statsCard,style:i?{borderTopColor:i}:void 0,children:[e.jsxs("div",{className:J.statsHeader,children:[o&&e.jsx("span",{className:J.statsIcon,children:e.jsx(N.NiceIcon,{name:o,size:16})}),e.jsx("span",{className:J.statsLabel,children:t})]}),e.jsx("div",{className:J.statsValue,children:n}),s&&e.jsx("div",{className:J.statsSub,children:s})]}),Um=({building:t,state:n,onModeChange:s,onDeviceControl:o,onSceneActivate:i,onZoneClick:a,className:c,style:r,theme:d="light",weather:_})=>{var m,k,l;const{t:p}=N.useNiceTranslation(),[f,y]=u.useState(null);t.floors[0];const b=t.floors.flatMap(I=>I.zones??[]).filter(I=>I.type!=="hallway"&&I.type!=="corridor"),j=((m=n==null?void 0:n.activeAlerts)==null?void 0:m.length)??0,w=(k=n==null?void 0:n.energy)==null?void 0:k.currentPowerW,x=(l=n==null?void 0:n.energy)==null?void 0:l.todayKwh,C=n!=null&&n.occupancy?Object.values(n.occupancy).reduce((I,h)=>I+((h==null?void 0:h.occupancy)??0),0):null;t.floors.flatMap(I=>I.zones??[]).flatMap(I=>I.deviceIds??[]).slice(0,8);const g=t.type==="office"||t.type==="retail"?["occupied","closed","weekend","event","emergency","maintenance"]:["home","away","night","vacation","guest","emergency"],L=(n==null?void 0:n.mode)??"home";return e.jsxs("div",{className:`${J.root} ${d==="dark"?J.dark:""} ${c??""}`,style:r,children:[e.jsxs("div",{className:J.header,children:[e.jsxs("div",{className:J.buildingInfo,children:[e.jsx("h2",{className:J.buildingName,children:t.name}),t.address&&e.jsx("p",{className:J.buildingAddress,children:t.address})]}),e.jsx("div",{className:J.modeSelector,children:g.map(I=>e.jsxs("button",{title:an[I],className:`${J.modeBtn} ${L===I?J.modeBtnActive:""}`,onClick:()=>s==null?void 0:s(I),children:[e.jsx(N.NiceIcon,{name:Bn[I],size:16}),e.jsx("span",{children:an[I]})]},I))}),e.jsx(Hm,{temperature:_==null?void 0:_.temperature,description:_==null?void 0:_.description})]}),e.jsxs("div",{className:J.statsRow,children:[w!=null&&e.jsx(At,{icon:"zap",label:p("buildings.power","Power"),value:w>=1e3?`${(w/1e3).toFixed(2)} kW`:`${w} W`,sub:x!=null?`${p("buildings.today","Today")}: ${x.toFixed(2)} kWh`:void 0,accent:"var(--nice-warning, #f59e0b)"}),C!=null&&e.jsx(At,{icon:"users",label:p("buildings.occupancy","Occupancy"),value:`${C}`,sub:`${b.length} ${p("buildings.zones","zones")}`,accent:"var(--nice-success, #22c55e)"}),j>0&&e.jsx(At,{icon:"bell",label:p("buildings.alerts","Alerts"),value:e.jsx("span",{style:{color:"var(--nice-danger, #ef4444)"},children:j}),sub:p("buildings.active","active"),accent:"var(--nice-danger, #ef4444)"}),e.jsx(At,{icon:Bn[L],label:p("buildings.mode","Mode"),value:p(`buildings.mode.${L}`,an[L]),accent:"var(--nice-accent, #8b5cf6)"})]}),e.jsx("div",{className:J.zoneGrid,children:b.map(I=>{const h=t.floors.flatMap(F=>(F.zones??[]).find(T=>T.id===I.id)?t.devices??[]:[]).filter(F=>F.zoneId===I.id);return e.jsx(ns,{zone:I,devices:h,expanded:f===I.id,onExpand:()=>y(f===I.id?null:I.id),onDeviceControl:o,onClick:()=>a==null?void 0:a(I.id),theme:d},I.id)})}),t.scenes&&t.scenes.length>0&&e.jsxs("div",{className:J.scenesBar,children:[e.jsx("span",{className:J.sceneBarLabel,children:p("buildings.scenes","Scenes")}),e.jsx("div",{className:J.sceneList,children:t.scenes.map(I=>{var h;return e.jsxs("button",{className:`${J.sceneBtn} ${(h=n==null?void 0:n.activeScenes)!=null&&h.includes(I.id)?J.sceneBtnActive:""}`,onClick:()=>i==null?void 0:i(I.id),children:[e.jsx(N.NiceIcon,{name:I.icon??"video",size:14})," ",I.name]},I.id)})})]})]})},Ym="_deviceControl_1leqb_3",Zm="_dark_1leqb_23",Xm="_compact_1leqb_35",Km="_offline_1leqb_43",Jm="_offlineBanner_1leqb_51",Qm="_toggleControl_1leqb_75",eh="_toggleLabel_1leqb_89",th="_toggleBtn_1leqb_109",nh="_toggleOn_1leqb_135",sh="_blindControl_1leqb_149",oh="_blindLabel_1leqb_159",ah="_blindActions_1leqb_173",ih="_blindBtn_1leqb_181",rh="_blindSlider_1leqb_205",ch="_blindPct_1leqb_213",lh="_lockControl_1leqb_227",dh="_lockLabel_1leqb_239",uh="_lockBtn_1leqb_253",ph="_lockLocked_1leqb_273",mh="_lockUnlocked_1leqb_281",hh="_cameraControl_1leqb_295",gh="_cameraLabel_1leqb_305",fh="_cameraSnapshot_1leqb_319",_h="_cameraPlaceholder_1leqb_331",bh="_cameraStatus_1leqb_355",yh="_cameraDot_1leqb_369",xh="_cameraOnline_1leqb_379",vh="_cameraOffline_1leqb_385",jh="_sensorControl_1leqb_395",wh="_sensorLabel_1leqb_405",Nh="_sensorValues_1leqb_419",Ih="_sensorRow_1leqb_429",kh="_sensorKey_1leqb_443",Sh="_sensorVal_1leqb_419",Ch="_thermostat_1leqb_467",Th="_thermostatTitle_1leqb_481",Lh="_thermostatDial_1leqb_503",$h="_dialTempCurrent_1leqb_513",zh="_dialTempLabel_1leqb_535",Ph="_dialTempTarget_1leqb_545",Eh="_dialHumidity_1leqb_565",Oh="_thermostatAdjust_1leqb_575",Mh="_adjustBtn_1leqb_587",Ah="_adjustTemp_1leqb_633",Dh="_hvacModes_1leqb_657",Bh="_hvacModeBtn_1leqb_671",Rh="_hvacModeBtnActive_1leqb_699",Fh="_hvacAction_1leqb_711",Gh="_hvacActionDot_1leqb_727",Vh="_lightControl_1leqb_741",qh="_lightHeader_1leqb_753",Wh="_lightIcon_1leqb_765",Hh="_lightName_1leqb_773",Uh="_lightToggle_1leqb_801",Yh="_lightToggleOn_1leqb_829",Zh="_sliderRow_1leqb_841",Xh="_sliderIcon_1leqb_855",Kh="_slider_1leqb_841",Jh="_sliderVal_1leqb_879",Qh="_colorRow_1leqb_891",eg="_colorSwatch_1leqb_905",tg="_colorPicker_1leqb_921",ng="_colorPresets_1leqb_937",sg="_colorPreset_1leqb_937",og="_lightOff_1leqb_963",M={deviceControl:Ym,dark:Zm,compact:Xm,offline:Km,offlineBanner:Jm,toggleControl:Qm,toggleLabel:eh,toggleBtn:th,toggleOn:nh,blindControl:sh,blindLabel:oh,blindActions:ah,blindBtn:ih,blindSlider:rh,blindPct:ch,lockControl:lh,lockLabel:dh,lockBtn:uh,lockLocked:ph,lockUnlocked:mh,cameraControl:hh,cameraLabel:gh,cameraSnapshot:fh,cameraPlaceholder:_h,cameraStatus:bh,cameraDot:yh,cameraOnline:xh,cameraOffline:vh,sensorControl:jh,sensorLabel:wh,sensorValues:Nh,sensorRow:Ih,sensorKey:kh,sensorVal:Sh,thermostat:Ch,thermostatTitle:Th,thermostatDial:Lh,dialTempCurrent:$h,dialTempLabel:zh,dialTempTarget:Ph,dialHumidity:Eh,thermostatAdjust:Oh,adjustBtn:Mh,adjustTemp:Ah,hvacModes:Dh,hvacModeBtn:Bh,hvacModeBtnActive:Rh,hvacAction:Fh,hvacActionDot:Gh,lightControl:Vh,lightHeader:qh,lightIcon:Wh,lightName:Hh,lightToggle:Uh,lightToggleOn:Yh,sliderRow:Zh,sliderIcon:Xh,slider:Kh,sliderVal:Jh,colorRow:Qh,colorSwatch:eg,colorPicker:tg,colorPresets:ng,colorPreset:sg,lightOff:og};function Rn(t){const n=Math.max(0,Math.min(1,(t-2700)/3800)),s=Math.round(255-n*80),o=Math.round(200+n*30),i=Math.round(100+n*155);return`rgb(${s},${o},${i})`}function ag(t,n,s){return"#"+[t,n,s].map(o=>o.toString(16).padStart(2,"0")).join("")}const ig=["#ffffff","#fde68a","#fca5a5","#93c5fd","#86efac","#c4b5fd"];function Fn(t){const n=parseInt(t.slice(1,3),16),s=parseInt(t.slice(3,5),16),o=parseInt(t.slice(5,7),16);return[n,s,o]}const ss=({device:t,onControl:n,compact:s=!1,theme:o="light",className:i,style:a})=>{var L,m,k;const{t:c}=N.useNiceTranslation(),r=t.state,d=(r==null?void 0:r.on)??!1,_=(r==null?void 0:r.brightness)??100,p=(r==null?void 0:r.colorTemperature)??4e3,f=r==null?void 0:r.rgbColor,[y,b]=u.useState(!1),j=u.useCallback(l=>{n==null||n(t.id,l)},[t.id,n]),w=f?ag(f[0],f[1],f[2]):"#ffffff",x=((L=t.capabilities)==null?void 0:L.includes("dimming"))??_!==void 0,C=(m=t.capabilities)==null?void 0:m.includes("color_temperature"),g=((k=t.capabilities)==null?void 0:k.includes("color"))||t.type==="rgb_light";return e.jsxs("div",{className:`${M.lightControl} ${s?M.compact:""} ${o==="dark"?M.dark:""} ${i??""}`,style:a,children:[e.jsxs("div",{className:M.lightHeader,children:[e.jsx("span",{className:M.lightIcon,style:{opacity:d?1:.4},children:e.jsx(N.NiceIcon,{name:"lightbulb",size:16})}),e.jsx("span",{className:M.lightName,children:t.name}),e.jsx("button",{className:`${M.lightToggle} ${d?M.lightToggleOn:""}`,"aria-label":d?c("buildings.switchedOn","On"):c("buildings.switchedOff","Off"),onClick:()=>j({on:!d}),children:e.jsx(N.NiceIcon,{name:d?"check":"close",size:14})})]}),d&&e.jsxs(e.Fragment,{children:[x&&e.jsxs("div",{className:M.sliderRow,children:[e.jsx("span",{className:M.sliderIcon,children:e.jsx(N.NiceIcon,{name:"lightbulb",size:16})}),e.jsx("input",{type:"range",min:1,max:100,value:_,className:M.slider,style:{"--pct":`${_}%`},onChange:l=>j({brightness:+l.target.value})}),e.jsxs("span",{className:M.sliderVal,children:[_,"%"]})]}),C&&e.jsxs("div",{className:M.sliderRow,children:[e.jsx("span",{className:M.sliderIcon,children:e.jsx(N.NiceIcon,{name:"thermometer",size:16})}),e.jsx("input",{type:"range",min:2700,max:6500,step:100,value:p,className:M.slider,style:{background:`linear-gradient(to right, ${Rn(2700)}, ${Rn(6500)})`},onChange:l=>j({colorTemperature:+l.target.value})}),e.jsxs("span",{className:M.sliderVal,children:[Math.round(p/100)*100,"K"]})]}),g&&e.jsxs("div",{className:M.colorRow,children:[e.jsx("span",{className:M.sliderIcon,children:e.jsx(N.NiceIcon,{name:"palette",size:16})}),e.jsx("button",{className:M.colorSwatch,"aria-label":c("buildings.pickColor","Pick a color"),"aria-expanded":y,style:{background:w},onClick:()=>b(l=>!l)}),y&&e.jsx("input",{type:"color",value:w,className:M.colorPicker,onChange:l=>{const[I,h,F]=Fn(l.target.value);j({rgbColor:[I,h,F]})}}),e.jsx("div",{className:M.colorPresets,children:ig.map(l=>e.jsx("button",{className:M.colorPreset,"aria-label":l,style:{background:l},onClick:()=>{const[I,h,F]=Fn(l);j({rgbColor:[I,h,F]})}},l))})]})]}),!d&&!s&&e.jsx("div",{className:M.lightOff,children:c("buildings.switchedOff","Off")})]})},Gn={heat:"Heating",cool:"Cooling",auto:"Auto",off:"Off",fan_only:"Fan",dry:"Dry"},rg={heat:"zap",cool:"thermometer",auto:"refresh",off:"stop",fan_only:"wifi",dry:"droplet"},cg={heating:"var(--nice-danger, #ef4444)",cooling:"var(--nice-primary, #3b82f6)",fan:"var(--nice-success, #22c55e)",drying:"var(--nice-warning, #f59e0b)",idle:"var(--nice-text-muted, #94a3b8)",off:"var(--nice-border, #e2e8f0)"};function Vn(t,n,s,o,i){const a=f=>(f-90)*(Math.PI/180),c=t+s*Math.cos(a(o)),r=n+s*Math.sin(a(o)),d=t+s*Math.cos(a(i)),_=n+s*Math.sin(a(i)),p=i-o>180?1:0;return`M${c.toFixed(2)},${r.toFixed(2)} A${s},${s} 0 ${p},1 ${d.toFixed(2)},${_.toFixed(2)}`}const Nt=5,Dt=35,Vt=-140,os=140;function qn(t){return Vt+(t-Nt)/(Dt-Nt)*(os-Vt)}const as=({device:t,onControl:n,compact:s=!1,theme:o="light",className:i,style:a})=>{const{t:c}=N.useNiceTranslation(),r=t.state,d=(r==null?void 0:r.temperature)??20,_=(r==null?void 0:r.targetTemperature)??21,p=r==null?void 0:r.humidity,f=(r==null?void 0:r.mode)??"auto",y=(r==null?void 0:r.hvacAction)??"idle",b=80,j=80,w=60,x=Vn(b,j,w,Vt,os),C=qn(Math.min(Math.max(d,Nt),Dt)),g=qn(Math.min(Math.max(_,Nt),Dt)),L=Vn(b,j,w,Vt,Math.min(C,g)),m=cg[y]??"var(--nice-text-muted, #94a3b8)",k=u.useCallback(I=>{const h=Math.round((_+I)*2)/2;h>=Nt&&h<=Dt&&(n==null||n(t.id,{targetTemperature:h}))},[_,t.id,n]),l=u.useCallback(I=>{n==null||n(t.id,{mode:I})},[t.id,n]);return e.jsxs("div",{className:`${M.thermostat} ${s?M.compact:""} ${o==="dark"?M.dark:""} ${i??""}`,style:a,children:[e.jsx("div",{className:M.thermostatTitle,children:t.name}),e.jsxs("svg",{width:160,height:160,className:M.thermostatDial,children:[e.jsx("path",{d:x,fill:"none",stroke:"var(--nice-border, #e2e8f0)",strokeWidth:8,strokeLinecap:"round"}),e.jsx("path",{d:L,fill:"none",stroke:m,strokeWidth:8,strokeLinecap:"round",opacity:.4}),e.jsx("circle",{cx:b+w*Math.cos((g-90)*(Math.PI/180)),cy:j+w*Math.sin((g-90)*(Math.PI/180)),r:7,fill:m,stroke:"var(--nice-bg, #fff)",strokeWidth:2}),e.jsxs("text",{x:b,y:j-6,textAnchor:"middle",className:M.dialTempCurrent,children:[d.toFixed(1),"°"]}),e.jsx("text",{x:b,y:j+14,textAnchor:"middle",className:M.dialTempLabel,children:c("buildings.currentTemp","now")}),e.jsxs("text",{x:b,y:j+32,textAnchor:"middle",className:M.dialTempTarget,children:[_.toFixed(1),"°"]}),p!=null&&e.jsxs("text",{x:b,y:j+48,textAnchor:"middle",className:M.dialHumidity,children:[p,"%"]})]}),e.jsxs("div",{className:M.thermostatAdjust,children:[e.jsx("button",{className:M.adjustBtn,"aria-label":c("buildings.lowerTarget","Lower the target temperature"),onClick:()=>k(-.5),children:e.jsx(N.NiceIcon,{name:"minus",size:16})}),e.jsxs("span",{className:M.adjustTemp,children:[_.toFixed(1)," °C"]}),e.jsx("button",{className:M.adjustBtn,"aria-label":c("buildings.raiseTarget","Raise the target temperature"),onClick:()=>k(.5),children:e.jsx(N.NiceIcon,{name:"plus",size:16})})]}),!s&&e.jsx("div",{className:M.hvacModes,children:["heat","cool","auto","fan_only","off"].map(I=>e.jsx("button",{title:Gn[I],"aria-label":Gn[I],className:`${M.hvacModeBtn} ${f===I?M.hvacModeBtnActive:""}`,onClick:()=>l(I),children:e.jsx(N.NiceIcon,{name:rg[I],size:16})},I))}),e.jsxs("div",{className:M.hvacAction,style:{color:m},children:[e.jsx("span",{className:M.hvacActionDot,style:{background:m}}),y]})]})},lg=({device:t,onControl:n})=>{const{t:s}=N.useNiceTranslation(),o=t.state,i=(o==null?void 0:o.on)===!0;return e.jsxs("div",{className:M.toggleControl,children:[e.jsx("span",{className:M.toggleLabel,children:t.name}),e.jsx("button",{className:`${M.toggleBtn} ${i?M.toggleOn:""}`,onClick:()=>n==null?void 0:n(t.id,{on:!i}),children:i?s("buildings.on","ON"):s("buildings.off","OFF")})]})},dg=({device:t,onControl:n})=>{const{t:s}=N.useNiceTranslation(),o=t.state,i=typeof(o==null?void 0:o.position)=="number"?o.position:50;return e.jsxs("div",{className:M.blindControl,children:[e.jsx("span",{className:M.blindLabel,children:t.name}),e.jsxs("div",{className:M.blindActions,children:[e.jsx("button",{className:M.blindBtn,"aria-label":s("buildings.open","Open"),onClick:()=>n==null?void 0:n(t.id,{command:"open"}),children:e.jsx(N.NiceIcon,{name:"arrow-up",size:16})}),e.jsx("button",{className:M.blindBtn,"aria-label":s("buildings.stop","Stop"),onClick:()=>n==null?void 0:n(t.id,{command:"stop"}),children:e.jsx(N.NiceIcon,{name:"stop",size:16})}),e.jsx("button",{className:M.blindBtn,"aria-label":s("buildings.close","Close"),onClick:()=>n==null?void 0:n(t.id,{command:"close"}),children:e.jsx(N.NiceIcon,{name:"arrow-down",size:16})})]}),e.jsx("input",{type:"range",min:0,max:100,value:i,className:M.blindSlider,onChange:a=>n==null?void 0:n(t.id,{position:+a.target.value})}),e.jsxs("span",{className:M.blindPct,children:[i,"%"]})]})},ug=({device:t,onControl:n})=>{const{t:s}=N.useNiceTranslation(),o=t.state,i=(o==null?void 0:o.locked)!==!1;return e.jsxs("div",{className:M.lockControl,children:[e.jsx("span",{className:M.lockLabel,children:t.name}),e.jsxs("button",{className:`${M.lockBtn} ${i?M.lockLocked:M.lockUnlocked}`,onClick:()=>n==null?void 0:n(t.id,{locked:!i}),children:[e.jsx(N.NiceIcon,{name:"lock",size:14})," ",i?s("buildings.locked","Locked"):s("buildings.unlocked","Unlocked")]})]})},pg=({device:t})=>{const{t:n}=N.useNiceTranslation(),s=t.state;return e.jsxs("div",{className:M.cameraControl,children:[e.jsx("span",{className:M.cameraLabel,children:t.name}),s!=null&&s.snapshotUrl?e.jsx("img",{src:s.snapshotUrl,alt:"snapshot",className:M.cameraSnapshot}):e.jsxs("div",{className:M.cameraPlaceholder,children:[e.jsx(N.NiceIcon,{name:"camera",size:16}),e.jsx("span",{children:s!=null&&s.streaming?n("buildings.streaming","Streaming"):n("buildings.noPreview","No preview")})]}),e.jsxs("div",{className:M.cameraStatus,children:[e.jsx("span",{className:`${M.cameraDot} ${t.status==="online"?M.cameraOnline:M.cameraOffline}`}),t.status]})]})},mg=({device:t})=>{const n=t.state;return e.jsxs("div",{className:M.sensorControl,children:[e.jsx("span",{className:M.sensorLabel,children:t.name}),e.jsx("div",{className:M.sensorValues,children:Object.entries(n??{}).map(([s,o])=>o!=null&&e.jsxs("div",{className:M.sensorRow,children:[e.jsx("span",{className:M.sensorKey,children:s}),e.jsx("span",{className:M.sensorVal,children:String(o)})]},s))})]})},hg=({device:t,onControl:n,compact:s=!1,className:o,style:i,theme:a="light"})=>{const{t:c}=N.useNiceTranslation(),r=t.type,d=["light","dimmer","rgb_light","led_strip"].includes(r)?e.jsx(ss,{device:t,onControl:n,compact:s,theme:a}):["thermostat","air_conditioner","heat_pump","floor_heating"].includes(r)?e.jsx(as,{device:t,onControl:n,compact:s,theme:a}):["blind","shutter","curtain","awning","garage_door"].includes(r)?e.jsx(dg,{device:t,onControl:n}):["lock","door"].includes(r)?e.jsx(ug,{device:t,onControl:n}):["camera","doorbell"].includes(r)?e.jsx(pg,{device:t}):r.endsWith("_sensor")||["motion_sensor","smoke_detector","water_leak_sensor","alarm"].includes(r)?e.jsx(mg,{device:t}):e.jsx(lg,{device:t,onControl:n});return e.jsxs("div",{className:`${M.deviceControl} ${a==="dark"?M.dark:""} ${s?M.compact:""} ${t.status==="offline"?M.offline:""} ${o??""}`,style:i,children:[d,t.status==="offline"&&e.jsx("div",{className:M.offlineBanner,children:c("buildings.offline","Offline")})]})},gg="_root_1g2cv_3",fg="_shell_1g2cv_29",_g="_dark_1g2cv_37",bg="_listPanel_1g2cv_51",yg="_listHeader_1g2cv_79",xg="_listTitle_1g2cv_103",vg="_addBtn_1g2cv_121",jg="_list_1g2cv_51",wg="_listItem_1g2cv_159",Ng="_listItemActive_1g2cv_199",Ig="_listItemName_1g2cv_213",kg="_listItemMeta_1g2cv_241",Sg="_enableToggle_1g2cv_255",Cg="_enableOn_1g2cv_273",Tg="_detailPanel_1g2cv_283",Lg="_detailHeader_1g2cv_295",$g="_nameInput_1g2cv_309",zg="_deleteBtn_1g2cv_357",Pg="_section_1g2cv_387",Eg="_rules_1g2cv_397",Og="_sectionHeader_1g2cv_411",Mg="_sectionTitle_1g2cv_425",Ag="_sectionAddBtn_1g2cv_441",Dg="_ruleBlock_1g2cv_471",Bg="_ruleBlockHeader_1g2cv_497",Rg="_typeSelect_1g2cv_511",Fg="_removeBtn_1g2cv_543",Gg="_ruleFields_1g2cv_581",Vg="_input_1g2cv_617",qg="_textarea_1g2cv_649",Wg="_dayPicker_1g2cv_685",Hg="_dayBtn_1g2cv_697",Ug="_dayBtnActive_1g2cv_717",Yg="_noSelection_1g2cv_731",Zg="_emptyHint_1g2cv_733",O={root:gg,shell:fg,dark:_g,listPanel:bg,listHeader:yg,listTitle:xg,addBtn:vg,list:jg,listItem:wg,listItemActive:Ng,listItemName:Ig,listItemMeta:kg,enableToggle:Sg,enableOn:Cg,detailPanel:Tg,detailHeader:Lg,nameInput:$g,deleteBtn:zg,section:Pg,rules:Eg,sectionHeader:Og,sectionTitle:Mg,sectionAddBtn:Ag,ruleBlock:Dg,ruleBlockHeader:Bg,typeSelect:Rg,removeBtn:Fg,ruleFields:Gg,input:Vg,textarea:qg,dayPicker:Wg,dayBtn:Hg,dayBtnActive:Ug,noSelection:Yg,emptyHint:Zg},Xg=[{target:".nice-building-automation-editor",titleKey:"tutorial.buildingAutomationEditor.intro.title",title:"Automation editor",contentKey:"tutorial.buildingAutomationEditor.intro.content",content:"Create building automations: pick one from the list, define its triggers, conditions and actions, then save, enable or delete it.",placement:"auto"}],ve=(t,n,s="")=>{const o=t[n];return typeof o=="string"?o:s},Bt=(t,n,s=0)=>{const o=t[n];return typeof o=="number"?o:s},qt=["mon","tue","wed","thu","fri","sat","sun"],Kg=t=>{const n=t.days;return Array.isArray(n)?n.map(s=>typeof s=="number"?qt[s]:String(s)):[...qt.slice(0,5)]},Ke={temperature:{name:"Temperature",unit:"°C"},humidity:{name:"Humidity",unit:"%"},pressure:{name:"Pressure",unit:"hPa"},co2:{name:"CO₂",unit:"ppm"},voc:{name:"VOC",unit:"ppb"},pm25:{name:"PM2.5",unit:"µg/m³"},pm10:{name:"PM10",unit:"µg/m³"},noise:{name:"Noise",unit:"dB"},lux:{name:"Light level",unit:"lx"},uv:{name:"UV index",unit:""},motion:{name:"Motion",unit:""},power:{name:"Power",unit:"W"},energy:{name:"Energy",unit:"kWh"},water_flow:{name:"Water flow",unit:"L/min"},gas:{name:"Gas",unit:"ppm"},radon:{name:"Radon",unit:"Bq/m³"}},Jg=t=>t in Ke,rn=t=>{const n=ve(t,"sensorType",ve(t,"attribute"));return Jg(n)?n:"temperature"},Qg=(t,n)=>{const s=t[n];return s&&typeof s=="object"?s:{}},ef=t=>{const n=new Intl.DateTimeFormat(t,{weekday:"short",timeZone:"UTC"});return Array.from({length:7},(s,o)=>n.format(new Date(Date.UTC(2024,0,1+o))))},Wn=[["time","buildings.trigger.time","Time"],["sunrise","buildings.trigger.sunrise","Sunrise"],["sunset","buildings.trigger.sunset","Sunset"],["device_state","buildings.trigger.deviceState","Device state"],["sensor_threshold","buildings.trigger.sensorThreshold","Sensor threshold"],["geofence","buildings.trigger.geofence","Geofence"],["scene_activated","buildings.trigger.sceneActivated","Scene activated"],["building_mode","buildings.trigger.buildingMode","Building mode"],["webhook","buildings.trigger.webhook","Webhook"],["manual","buildings.trigger.manual","Manual"]],tf=[["eq","buildings.operator.equals","equals"],["neq","buildings.operator.neq","is not"],["gt","buildings.operator.gt","greater than"],["gte","buildings.operator.gte","at least"],["lt","buildings.operator.lt","less than"],["lte","buildings.operator.lte","at most"],["changed","buildings.operator.changed","changes"]],nf=["on","brightness","temperature","targetTemperature","locked","position","state"],sf=["home","away","night","vacation","guest","party","occupied","closed","weekend","event","emergency","maintenance"],of=t=>{switch(t){case"sensor_threshold":return{type:t,deviceId:"",sensorType:"temperature",unit:Ke.temperature.unit,operator:"above",threshold:25};case"device_state":return{type:t,deviceId:"",attribute:"on",operator:"changed"};case"geofence":return{type:t,zone:"home"};case"scene_activated":return{type:t,sceneId:""};case"building_mode":return{type:t,mode:"home"};default:return{type:t}}},af=({trigger:t,devices:n,scenes:s,onChange:o,onRemove:i})=>{const{t:a,lang:c}=N.useNiceTranslation(),r=d=>o({...t,...d});return e.jsxs("div",{className:O.ruleBlock,children:[e.jsxs("div",{className:O.ruleBlockHeader,children:[e.jsxs("select",{className:O.typeSelect,value:t.type,onChange:d=>o(of(d.target.value)),children:[Wn.map(([d,_,p])=>e.jsx("option",{value:d,children:a(_,p)},d)),!Wn.some(([d])=>d===t.type)&&e.jsx("option",{value:t.type,disabled:!0,children:t.type})]}),e.jsx("button",{className:O.removeBtn,onClick:i,title:a("buildings.remove","Remove"),"aria-label":a("buildings.remove","Remove"),children:e.jsx(N.NiceIcon,{name:"close",size:14})})]}),t.type==="time"&&e.jsxs("div",{className:O.ruleFields,children:[e.jsxs("label",{children:[a("buildings.field.hour","Hour"),e.jsx("input",{type:"time",className:O.input,value:ve(t,"time","08:00"),onChange:d=>r({time:d.target.value})})]}),e.jsxs("label",{children:[a("buildings.field.days","Days"),e.jsx("div",{className:O.dayPicker,children:ef(c).map((d,_)=>{const p=Kg(t),f=qt[_],y=p.includes(f);return e.jsx("button",{type:"button","aria-pressed":y,className:`${O.dayBtn} ${y?O.dayBtnActive:""}`,onClick:()=>r({days:y?p.filter(b=>b!==f):qt.filter(b=>b===f||p.includes(b))}),children:d},f)})})]})]}),(t.type==="sunrise"||t.type==="sunset")&&e.jsx("div",{className:O.ruleFields,children:e.jsxs("label",{children:[a("buildings.field.offsetMinutes","Offset (minutes)"),e.jsx("input",{type:"number",className:O.input,min:-120,max:120,step:5,value:Bt(t,"offsetMinutes",0),onChange:d=>r({offsetMinutes:+d.target.value})})]})}),(t.type==="device_state"||t.type==="sensor_threshold")&&e.jsxs("div",{className:O.ruleFields,children:[e.jsxs("label",{children:[a("buildings.device","Device"),e.jsxs("select",{className:O.input,value:ve(t,"deviceId",""),onChange:d=>r({deviceId:d.target.value}),children:[e.jsx("option",{value:"",children:a("buildings.selectPlaceholder","— select —")}),n.map(d=>e.jsx("option",{value:d.id,children:d.name},d.id))]})]}),t.type==="device_state"&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{children:[a("buildings.field.attribute","Attribute"),e.jsx("input",{className:O.input,list:"nice-automation-attributes",value:ve(t,"attribute","on"),onChange:d=>r({attribute:d.target.value})}),e.jsx("datalist",{id:"nice-automation-attributes",children:nf.map(d=>e.jsx("option",{value:d},d))})]}),e.jsxs("label",{children:[a("buildings.field.operator","Operator"),e.jsx("select",{className:O.input,value:ve(t,"operator","changed"),onChange:d=>r({operator:d.target.value,value:d.target.value==="changed"?void 0:ve(t,"value","")}),children:tf.map(([d,_,p])=>e.jsx("option",{value:d,children:a(_,p)},d))})]}),ve(t,"operator","changed")!=="changed"&&e.jsxs("label",{children:[a("buildings.field.value","Value"),e.jsx("input",{className:O.input,value:ve(t,"value",""),onChange:d=>r({value:d.target.value})})]})]}),t.type==="sensor_threshold"&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{children:[a("buildings.field.sensor","Sensor"),e.jsx("select",{className:O.input,value:rn(t),onChange:d=>{const _=d.target.value;r({sensorType:_,unit:Ke[_].unit,attribute:void 0})},children:Object.keys(Ke).map(d=>e.jsx("option",{value:d,children:a(`buildings.sensor.${d}`,Ke[d].name)},d))})]}),e.jsxs("label",{children:[a("buildings.field.operator","Operator"),e.jsxs("select",{className:O.input,value:ve(t,"operator","above"),onChange:d=>r({operator:d.target.value}),children:[e.jsx("option",{value:"above",children:a("buildings.operator.above","above")}),e.jsx("option",{value:"below",children:a("buildings.operator.below","below")}),e.jsx("option",{value:"eq",children:a("buildings.operator.equals","equals")})]})]}),e.jsxs("label",{children:[a("buildings.field.threshold","Threshold"),Ke[rn(t)].unit&&` (${Ke[rn(t)].unit})`,e.jsx("input",{type:"number",className:O.input,value:Bt(t,"threshold",0),onChange:d=>r({threshold:+d.target.value})})]})]})]}),t.type==="webhook"&&e.jsx("div",{className:O.ruleFields,children:e.jsxs("label",{children:[a("buildings.field.endpointId","Endpoint ID"),e.jsx("input",{className:O.input,value:ve(t,"webhookId",""),onChange:d=>r({webhookId:d.target.value})})]})}),t.type==="geofence"&&e.jsxs("div",{className:O.ruleFields,children:[e.jsxs("label",{children:[a("buildings.field.zone","When"),e.jsxs("select",{className:O.input,value:ve(t,"zone","home"),onChange:d=>r({zone:d.target.value}),children:[e.jsx("option",{value:"home",children:a("buildings.geofence.home","Arriving home")}),e.jsx("option",{value:"away",children:a("buildings.geofence.away","Leaving home")})]})]}),e.jsxs("label",{children:[a("buildings.field.radius","Radius (m)"),e.jsx("input",{type:"number",className:O.input,min:50,step:50,value:Bt(t,"radius",200),onChange:d=>r({radius:+d.target.value})})]})]}),t.type==="scene_activated"&&e.jsx("div",{className:O.ruleFields,children:e.jsxs("label",{children:[a("buildings.scene","Scene"),e.jsxs("select",{className:O.input,value:ve(t,"sceneId",""),onChange:d=>r({sceneId:d.target.value}),children:[e.jsx("option",{value:"",children:a("buildings.selectPlaceholder","— select —")}),s.map(d=>e.jsx("option",{value:d.id,children:d.name},d.id))]})]})}),t.type==="building_mode"&&e.jsx("div",{className:O.ruleFields,children:e.jsxs("label",{children:[a("buildings.mode","Mode"),e.jsx("select",{className:O.input,value:ve(t,"mode","home"),onChange:d=>r({mode:d.target.value}),children:sf.map(d=>e.jsx("option",{value:d,children:a(`buildings.mode.${d}`,d.charAt(0).toUpperCase()+d.slice(1))},d))})]})}),t.type==="manual"&&e.jsx("div",{className:O.ruleFields,children:e.jsx("span",{children:a("buildings.trigger.manualHint","Runs only when started by hand.")})})]})},rf=({action:t,devices:n,scenes:s,onChange:o,onRemove:i})=>{const{t:a}=N.useNiceTranslation(),c=r=>o({...t,...r});return e.jsxs("div",{className:O.ruleBlock,children:[e.jsxs("div",{className:O.ruleBlockHeader,children:[e.jsxs("select",{className:O.typeSelect,value:t.type,onChange:r=>o({type:r.target.value}),children:[e.jsx("option",{value:"device_control",children:a("buildings.device","Device")}),e.jsx("option",{value:"scene_activate",children:a("buildings.activateScene","Activate scene")}),e.jsx("option",{value:"notification",children:a("buildings.action.notification","Notification")}),e.jsx("option",{value:"delay",children:a("buildings.action.delay","Delay")}),e.jsx("option",{value:"http_request",children:a("buildings.httpRequest","HTTP Request")})]}),e.jsx("button",{className:O.removeBtn,onClick:i,title:a("buildings.remove","Remove"),"aria-label":a("buildings.remove","Remove"),children:e.jsx(N.NiceIcon,{name:"close",size:14})})]}),t.type==="device_control"&&e.jsxs("div",{className:O.ruleFields,children:[e.jsxs("label",{children:[a("buildings.device","Device"),e.jsxs("select",{className:O.input,value:ve(t,"deviceId",""),onChange:r=>c({deviceId:r.target.value}),children:[e.jsx("option",{value:"",children:a("buildings.selectPlaceholder","— select —")}),n.map(r=>e.jsx("option",{value:r.id,children:r.name},r.id))]})]}),e.jsxs("label",{children:[a("buildings.field.stateJson","State (JSON)"),e.jsx("textarea",{className:O.textarea,rows:3,value:JSON.stringify(Qg(t,"state"),null,2),onChange:r=>{try{c({state:JSON.parse(r.target.value)})}catch{}}})]})]}),t.type==="scene_activate"&&e.jsx("div",{className:O.ruleFields,children:e.jsxs("label",{children:[a("buildings.scene","Scene"),e.jsxs("select",{className:O.input,value:ve(t,"sceneId",""),onChange:r=>c({sceneId:r.target.value}),children:[e.jsx("option",{value:"",children:a("buildings.selectPlaceholder","— select —")}),s.map(r=>e.jsx("option",{value:r.id,children:r.name},r.id))]})]})}),t.type==="notification"&&e.jsxs("div",{className:O.ruleFields,children:[e.jsxs("label",{children:[a("buildings.field.channel","Channel"),e.jsxs("select",{className:O.input,value:ve(t,"channel","push"),onChange:r=>c({channel:r.target.value}),children:[e.jsx("option",{value:"push",children:a("buildings.push","Push")}),e.jsx("option",{value:"email",children:a("buildings.email","Email")}),e.jsx("option",{value:"sms",children:"SMS"}),e.jsx("option",{value:"in_app",children:a("buildings.inApp","In-app")}),e.jsx("option",{value:"teams",children:a("buildings.teams","Teams")}),e.jsx("option",{value:"slack",children:a("buildings.slack","Slack")})]})]}),e.jsxs("label",{children:[a("buildings.field.message","Message"),e.jsx("input",{className:O.input,value:ve(t,"message",""),onChange:r=>c({message:r.target.value})})]})]}),t.type==="delay"&&e.jsx("div",{className:O.ruleFields,children:e.jsxs("label",{children:[a("buildings.field.delaySeconds","Delay (seconds)"),e.jsx("input",{type:"number",className:O.input,min:1,value:Bt(t,"delaySeconds",60),onChange:r=>c({delaySeconds:+r.target.value})})]})}),t.type==="http_request"&&e.jsxs("div",{className:O.ruleFields,children:[e.jsxs("label",{children:["URL",e.jsx("input",{className:O.input,value:ve(t,"url",""),onChange:r=>c({url:r.target.value})})]}),e.jsxs("label",{children:[a("buildings.field.method","Method"),e.jsxs("select",{className:O.input,value:ve(t,"method","POST"),onChange:r=>c({method:r.target.value}),children:[e.jsx("option",{children:"GET"}),e.jsx("option",{children:a("buildings.post","POST")}),e.jsx("option",{children:"PUT"}),e.jsx("option",{children:a("buildings.patch","PATCH")})]})]})]})]})},cf=({automations:t,defaultAutomations:n,devices:s=[],scenes:o=[],onAutomationsChange:i,onDelete:a,onToggle:c,readOnly:r=!1,className:d,style:_,theme:p="light",tutorial:f})=>{var F;const{t:y}=N.useNiceTranslation(),[b,j]=N.useControllableState({value:t,defaultValue:n,fallbackValue:[],onChange:i,componentName:"NiceAutomationEditor"}),[w,x]=u.useState(null),C=w!==null&&b.some(T=>T.id===w)?w:((F=b[0])==null?void 0:F.id)??null,g=b.find(T=>T.id===C)??null,L=u.useCallback(T=>{g&&j(b.map(B=>B.id===g.id?{...B,...T}:B))},[g,b,j]),m=u.useCallback(()=>{const T={id:`auto-${Date.now()}`,name:"New automation",enabled:!0,triggers:[],conditions:[],actions:[]};j([...b,T]),x(T.id)},[b,j]),k=u.useCallback(T=>{var B;j(b.filter(H=>H.id!==T)),C===T&&x(((B=b.find(H=>H.id!==T))==null?void 0:B.id)??null),a==null||a(T)},[b,C,j,a]),l=u.useCallback((T,B)=>{j(b.map(H=>H.id===T?{...H,enabled:B}:H)),c==null||c(T,B)},[b,j,c]),I=e.jsxs("div",{className:O.listPanel,children:[e.jsxs("div",{className:O.listHeader,children:[e.jsx("span",{className:O.listTitle,children:y("buildings.automations","Automations")}),!r&&e.jsxs("button",{className:O.addBtn,onClick:m,children:[e.jsx(N.NiceIcon,{name:"plus",size:12})," ",y("buildings.add","Add")]})]}),e.jsxs("div",{className:O.list,children:[b.map(T=>e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:N.clickOnActivationKey,className:`${O.listItem} ${C===T.id?O.listItemActive:""}`,onClick:()=>x(T.id),children:[e.jsx("div",{className:O.listItemName,children:T.name}),e.jsxs("div",{className:O.listItemMeta,children:[T.triggers.length," ",y("buildings.triggersShort","triggers")," ·"," ",T.actions.length," ",y("buildings.actionsShort","actions")]}),e.jsx("button",{className:`${O.enableToggle} ${T.enabled?O.enableOn:""}`,disabled:r,onClick:B=>{B.stopPropagation(),l(T.id,!T.enabled)},title:T.enabled?y("buildings.disable","Disable"):y("buildings.enable","Enable"),"aria-label":T.enabled?y("buildings.disable","Disable"):y("buildings.enable","Enable"),children:e.jsx(N.NiceIcon,{name:T.enabled?"check":"close",size:14})})]},T.id)),b.length===0&&e.jsx("div",{className:O.emptyHint,children:y("buildings.noAutomations","No automations")})]})]}),h=e.jsx("div",{className:O.detailPanel,children:g?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:O.detailHeader,children:[e.jsx("input",{className:O.nameInput,value:g.name,onChange:T=>L({name:T.target.value}),readOnly:r}),!r&&e.jsx("button",{className:O.deleteBtn,onClick:()=>k(g.id),children:y("buildings.remove","Remove")})]}),e.jsxs("fieldset",{className:O.rules,disabled:r,children:[e.jsxs("section",{className:O.section,children:[e.jsxs("div",{className:O.sectionHeader,children:[e.jsx("span",{className:O.sectionTitle,children:y("buildings.triggers","Triggers")}),!r&&e.jsxs("button",{className:O.sectionAddBtn,onClick:()=>L({triggers:[...g.triggers,{type:"time"}]}),children:[e.jsx(N.NiceIcon,{name:"plus",size:12})," ",y("buildings.add","Add")]})]}),g.triggers.map((T,B)=>e.jsx(af,{trigger:T,devices:s,scenes:o,onChange:H=>L({triggers:g.triggers.map((ne,te)=>te===B?H:ne)}),onRemove:()=>L({triggers:g.triggers.filter((H,ne)=>ne!==B)})},B)),g.triggers.length===0&&e.jsx("div",{className:O.emptyHint,children:y("buildings.noTriggers","No triggers")})]}),e.jsxs("section",{className:O.section,children:[e.jsxs("div",{className:O.sectionHeader,children:[e.jsx("span",{className:O.sectionTitle,children:y("buildings.actions","Actions")}),!r&&e.jsxs("button",{className:O.sectionAddBtn,onClick:()=>L({actions:[...g.actions,{type:"device_control"}]}),children:[e.jsx(N.NiceIcon,{name:"plus",size:12})," ",y("buildings.add","Add")]})]}),g.actions.map((T,B)=>e.jsx(rf,{action:T,devices:s,scenes:o,onChange:H=>L({actions:g.actions.map((ne,te)=>te===B?H:ne)}),onRemove:()=>L({actions:g.actions.filter((H,ne)=>ne!==B)})},B)),g.actions.length===0&&e.jsx("div",{className:O.emptyHint,children:y("buildings.noActions","No actions")})]})]})]}):e.jsx("div",{className:O.noSelection,children:y("buildings.noAutomationSelected","Select an automation or add a new one")})});return e.jsxs("div",{className:`nice-building-automation-editor ${O.root} ${p==="dark"?O.dark:""} ${d??""}`,style:{position:"relative",..._},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:e.jsx(N.NiceTutorialButton,{steps:N.resolveTutorial(f,Xg)})}),e.jsx(N.NiceAppShell,{flush:!0,className:O.shell,sidebar:I,children:h})]})},lf="_root_o100g_3",df="_shell_o100g_29",uf="_dark_o100g_37",pf="_gridPanel_o100g_51",mf="_gridHeader_o100g_79",hf="_gridTitle_o100g_103",gf="_addBtn_o100g_119",ff="_sceneGrid_o100g_147",_f="_sceneCard_o100g_165",bf="_sceneCardActive_o100g_193",yf="_sceneCardSelected_o100g_199",xf="_sceneCardIcon_o100g_207",vf="_sceneCardName_o100g_217",jf="_sceneCardDevices_o100g_235",wf="_activeBadge_o100g_253",Nf="_activateBtn_o100g_263",If="_emptyGrid_o100g_307",kf="_detailPanel_o100g_325",Sf="_metaRow_o100g_343",Cf="_iconPicker_o100g_355",Tf="_currentIcon_o100g_363",Lf="_iconGrid_o100g_381",$f="_iconOpt_o100g_397",zf="_iconOptActive_o100g_423",Pf="_metaFields_o100g_433",Ef="_nameInput_o100g_447",Of="_descInput_o100g_481",Mf="_colorPicker_o100g_541",Af="_colorOpt_o100g_551",Df="_colorOptActive_o100g_567",Bf="_targetsSection_o100g_577",Rf="_targetsSectionHeader_o100g_599",Ff="_addTargetBtn_o100g_621",Gf="_targetRow_o100g_649",Vf="_targetSelect_o100g_679",qf="_targetState_o100g_711",Wf="_targetField_o100g_725",Hf="_tempInput_o100g_751",Uf="_removeTargetBtn_o100g_769",Yf="_noTargets_o100g_809",Zf="_detailActions_o100g_829",Xf="_activateFullBtn_o100g_843",Kf="_deleteBtn_o100g_875",K={root:lf,shell:df,dark:uf,gridPanel:pf,gridHeader:mf,gridTitle:hf,addBtn:gf,sceneGrid:ff,sceneCard:_f,sceneCardActive:bf,sceneCardSelected:yf,sceneCardIcon:xf,sceneCardName:vf,sceneCardDevices:jf,activeBadge:wf,activateBtn:Nf,emptyGrid:If,detailPanel:kf,metaRow:Sf,iconPicker:Cf,currentIcon:Tf,iconGrid:Lf,iconOpt:$f,iconOptActive:zf,metaFields:Pf,nameInput:Ef,descInput:Of,colorPicker:Mf,colorOpt:Af,colorOptActive:Df,targetsSection:Bf,targetsSectionHeader:Rf,addTargetBtn:Ff,targetRow:Gf,targetSelect:Vf,targetState:qf,targetField:Wf,tempInput:Hf,removeTargetBtn:Uf,noTargets:Yf,detailActions:Zf,activateFullBtn:Xf,deleteBtn:Kf},Jf=[{target:".nice-scene-editor",titleKey:"tutorial.buildingSceneEditor.intro.title",title:"Scene editor",contentKey:"tutorial.buildingSceneEditor.intro.content",content:"Create scenes that set multiple devices at once: pick a scene, choose device target states, then save or activate it.",placement:"auto"}],at=t=>t&&typeof t=="object"?t:{},Qf=(t,n,s=!1)=>{const o=at(t)[n];return typeof o=="boolean"?o:s},jt=(t,n,s=0)=>{const o=at(t)[n];return typeof o=="number"?o:s},e_=["video","eye-off","lightbulb","gamepad","briefcase","utensils","music","droplet","rocket","home","thermometer","lock","star","gift","heart","settings"],t_=["var(--nice-primary-bg, #e0f2fe)","var(--nice-accent-tint-10, #fce7f3)","var(--nice-success-bg, #dcfce7)","var(--nice-warning-bg, #fef9c3)","var(--nice-accent-tint-10, #ede9fe)","var(--nice-danger-bg, #fee2e2)","var(--nice-success-bg, #f0fdf4)","var(--nice-warning-tint-10, #fff7ed)"],n_=({target:t,devices:n,onChange:s,onRemove:o})=>{const{t:i}=N.useNiceTranslation(),a=n.find(c=>c.id===t.deviceId);return e.jsxs("div",{className:K.targetRow,children:[e.jsxs("select",{className:K.targetSelect,value:t.deviceId,onChange:c=>s({...t,deviceId:c.target.value}),children:[e.jsxs("option",{value:"",children:["— ",i("buildings.device","Device")," —"]}),n.map(c=>e.jsx("option",{value:c.id,children:c.name},c.id))]}),a&&e.jsxs("div",{className:K.targetState,children:[e.jsxs("label",{className:K.targetField,children:[e.jsx("span",{children:i("buildings.onOff","On/Off")}),e.jsx("input",{type:"checkbox",checked:Qf(t.state,"on",!1),onChange:c=>s({...t,state:{...at(t.state),on:c.target.checked}})})]}),(a.type==="dimmer"||a.type==="light"||a.type==="rgb_light"||a.type==="led_strip")&&e.jsxs("label",{className:K.targetField,children:[e.jsx("span",{children:i("buildings.brightness","Brightness")}),e.jsx("input",{type:"range",min:0,max:100,value:jt(t.state,"brightness",100),onChange:c=>s({...t,state:{...at(t.state),brightness:+c.target.value}})}),e.jsxs("span",{children:[jt(t.state,"brightness",100),"%"]})]}),(a.type==="blind"||a.type==="shutter")&&e.jsxs("label",{className:K.targetField,children:[e.jsx("span",{children:i("buildings.position","Position")}),e.jsx("input",{type:"range",min:0,max:100,value:jt(t.state,"position",100),onChange:c=>s({...t,state:{...at(t.state),position:+c.target.value}})}),e.jsxs("span",{children:[jt(t.state,"position",100),"%"]})]}),(a.type==="thermostat"||a.type==="air_conditioner")&&e.jsxs("label",{className:K.targetField,children:[e.jsx("span",{children:i("buildings.temp","Temp.")}),e.jsx("input",{type:"number",className:K.tempInput,min:10,max:30,step:.5,value:jt(t.state,"targetTemperature",20),onChange:c=>s({...t,state:{...at(t.state),targetTemperature:+c.target.value}})}),e.jsx("span",{children:"°C"})]})]}),e.jsx("button",{className:K.removeTargetBtn,onClick:o,title:i("buildings.remove","Remove"),"aria-label":i("buildings.remove","Remove"),children:e.jsx(N.NiceIcon,{name:"close",size:14})})]})},s_=({scenes:t,defaultScenes:n,devices:s=[],activeSceneIds:o=[],onScenesChange:i,onActivate:a,onDelete:c,readOnly:r=!1,className:d,style:_,theme:p="light",tutorial:f})=>{var F;const{t:y}=N.useNiceTranslation(),[b,j]=N.useControllableState({value:t,defaultValue:n,fallbackValue:[],onChange:i,componentName:"NiceSceneEditor"}),[w,x]=u.useState(null),C=w!==null&&b.some(T=>T.id===w)?w:((F=b[0])==null?void 0:F.id)??null,g=b.find(T=>T.id===C)??null,L=u.useCallback(T=>{g&&j(b.map(B=>B.id===g.id?{...B,...T}:B))},[g,b,j]),m=u.useCallback(()=>{const T={id:`scene-${Date.now()}`,name:"New scene",deviceTargets:[],icon:"video",color:"var(--nice-primary-bg, #e0f2fe)"};j([...b,T]),x(T.id)},[b,j]),k=u.useCallback(T=>{var B;j(b.filter(H=>H.id!==T)),C===T&&x(((B=b.find(H=>H.id!==T))==null?void 0:B.id)??null),c==null||c(T)},[b,C,j,c]),l=()=>{if(!g)return;const T={deviceId:"",state:{on:!0},transitionMs:1e3};L({deviceTargets:[...g.deviceTargets,T]})},I=e.jsxs("div",{className:K.gridPanel,children:[e.jsxs("div",{className:K.gridHeader,children:[e.jsx("span",{className:K.gridTitle,children:y("buildings.scenes","Scenes")}),!r&&e.jsxs("button",{className:K.addBtn,onClick:m,children:[e.jsx(N.NiceIcon,{name:"plus",size:12})," ",y("buildings.new","New")]})]}),e.jsxs("div",{className:K.sceneGrid,children:[b.map(T=>{const B=o.includes(T.id),H=C===T.id;return e.jsxs("div",{role:"button",tabIndex:0,onKeyDown:N.clickOnActivationKey,className:`${K.sceneCard} ${B?K.sceneCardActive:""} ${H?K.sceneCardSelected:""}`,style:{background:T.color??"var(--nice-bg-secondary, #f8fafc)"},onClick:()=>x(T.id),children:[e.jsx("div",{className:K.sceneCardIcon,children:e.jsx(N.NiceIcon,{name:T.icon??"video",size:20})}),e.jsx("div",{className:K.sceneCardName,children:T.name}),e.jsxs("div",{className:K.sceneCardDevices,children:[T.deviceTargets.length," ",y("buildings.devices","devices"),B&&e.jsx("span",{className:K.activeBadge,children:e.jsx(N.NiceIcon,{name:"check",size:12})})]}),e.jsx("button",{className:K.activateBtn,"aria-label":y("buildings.activate","Activate"),onClick:ne=>{ne.stopPropagation(),a==null||a(T.id)},children:e.jsx(N.NiceIcon,{name:"play",size:14})})]},T.id)}),b.length===0&&e.jsx("div",{className:K.emptyGrid,children:y("buildings.noScenes","No scenes yet. Add the first one!")})]})]}),h=g?e.jsxs("div",{className:K.detailPanel,children:[e.jsxs("div",{className:K.metaRow,children:[e.jsxs("div",{className:K.iconPicker,children:[e.jsx("span",{className:K.currentIcon,children:e.jsx(N.NiceIcon,{name:g.icon??"video",size:20})}),e.jsx("div",{className:K.iconGrid,children:e_.map(T=>e.jsx("button",{className:`${K.iconOpt} ${g.icon===T?K.iconOptActive:""}`,"aria-label":T,onClick:()=>L({icon:T}),children:e.jsx(N.NiceIcon,{name:T,size:16})},T))})]}),e.jsxs("div",{className:K.metaFields,children:[e.jsx("input",{className:K.nameInput,value:g.name,readOnly:r,onChange:T=>L({name:T.target.value}),placeholder:y("buildings.sceneName","Scene name")}),e.jsx("textarea",{className:K.descInput,value:g.description??"",readOnly:r,onChange:T=>L({description:T.target.value}),placeholder:y("buildings.descriptionOptional","Description (optional)"),rows:2})]})]}),!r&&e.jsx("div",{className:K.colorPicker,children:t_.map(T=>e.jsx("button",{className:`${K.colorOpt} ${g.color===T?K.colorOptActive:""}`,style:{background:T},onClick:()=>L({color:T})},T))}),e.jsxs("fieldset",{className:K.targetsSection,disabled:r,children:[e.jsxs("div",{className:K.targetsSectionHeader,children:[e.jsx("span",{children:y("buildings.devicesInScene","Devices in this scene")}),!r&&e.jsxs("button",{className:K.addTargetBtn,onClick:l,children:[e.jsx(N.NiceIcon,{name:"plus",size:12})," ",y("buildings.add","Add")]})]}),g.deviceTargets.map((T,B)=>e.jsx(n_,{target:T,devices:s,onChange:H=>L({deviceTargets:g.deviceTargets.map((ne,te)=>te===B?H:ne)}),onRemove:()=>L({deviceTargets:g.deviceTargets.filter((H,ne)=>ne!==B)})},B)),g.deviceTargets.length===0&&e.jsx("div",{className:K.noTargets,children:y("buildings.sceneHint","Add the devices this scene should control.")})]}),e.jsxs("div",{className:K.detailActions,children:[e.jsxs("button",{className:K.activateFullBtn,onClick:()=>a==null?void 0:a(g.id),children:[e.jsx(N.NiceIcon,{name:"play",size:14})," ",y("buildings.activateScene","Activate scene")]}),!r&&e.jsx("button",{className:K.deleteBtn,onClick:()=>k(g.id),children:y("buildings.remove","Remove")})]})]}):void 0;return e.jsxs("div",{className:`nice-scene-editor ${K.root} ${p==="dark"?K.dark:""} ${d??""}`,style:{position:"relative",..._},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:e.jsx(N.NiceTutorialButton,{steps:N.resolveTutorial(f,Jf)})}),e.jsx(N.NiceAppShell,{flush:!0,className:K.shell,sidebar:I,children:h})]})};exports.LayerPanel=Jn;exports.Minimap=un;exports.NiceAutomationEditor=cf;exports.NiceBuildingDashboard=Um;exports.NiceDeviceControl=hg;exports.NiceFloorPlanEditor=jo;exports.NiceLightControl=ss;exports.NiceSceneEditor=s_;exports.NiceSpatialEditor=gu;exports.NiceSpatialViewer=Xp;exports.NiceThermostatControl=as;exports.NiceZoneCard=ns;exports.ObjectLibrary=Qn;exports.PropertiesPanel=es;exports.useMeasurement=Qp;exports.useSnapToGrid=Jp;exports.useSpatialEditor=Kp;