@nice2dev/ui-buildings 1.2.0 → 1.2.2
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/CHANGELOG.md +146 -0
- package/dist/index.cjs +50 -50
- package/dist/index.mjs +3083 -3310
- package/dist/ui-buildings.css +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";var Os=Object.defineProperty;var Ds=(t,s,n)=>s in t?Os(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var ut=(t,s,n)=>Ds(t,typeof s!="symbol"?s+"":s,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),S=require("@nice2dev/ui"),m=require("react"),Rs={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 bs(t){return Rs[t]??"settings"}const qs="_root_1nq8c_1",Fs="_shell_1nq8c_27",Gs="_dark_1nq8c_35",Ws="_topBar_1nq8c_49",Vs="_floorTabs_1nq8c_79",Hs="_floorTab_1nq8c_79",Us="_floorTabActive_1nq8c_119",Ys="_overlayControls_1nq8c_131",Zs="_overlayBtn_1nq8c_143",Xs="_overlayBtnActive_1nq8c_179",Ks="_zoomBar_1nq8c_191",Js="_toolPalette_1nq8c_245",Qs="_toolBtn_1nq8c_275",en="_toolBtnActive_1nq8c_311",tn="_canvasWrapper_1nq8c_325",sn="_canvas_1nq8c_325",nn="_cur_select_1nq8c_365",on="_cur_drawzone_1nq8c_371",an="_cur_drawwall_1nq8c_377",rn="_cur_placedevice_1nq8c_383",cn="_cur_placedoor_1nq8c_389",ln="_cur_placewindow_1nq8c_395",dn="_cur_pan_1nq8c_401",un="_cur_erase_1nq8c_407",mn="_cur_measure_1nq8c_413",hn="_cur_annotate_1nq8c_419",pn="_gridLine_1nq8c_429",fn="_zoneGroup_1nq8c_447",_n="_zonePath_1nq8c_455",gn="_zoneLabel_1nq8c_463",yn="_climateLabel_1nq8c_485",bn="_occupancyLabel_1nq8c_497",xn="_dimLabel_1nq8c_509",vn="_deviceGroup_1nq8c_521",jn="_devCircle_1nq8c_529",wn="_devOnline_1nq8c_541",Nn="_devOffline_1nq8c_547",kn="_devSelected_1nq8c_553",In="_propPanel_1nq8c_565",Cn="_propTitle_1nq8c_593",Sn="_propRow_1nq8c_615",Ln="_statusBar_1nq8c_655",Tn="_emptyState_1nq8c_687",oe={root:qs,shell:Fs,dark:Gs,topBar:Ws,floorTabs:Vs,floorTab:Hs,floorTabActive:Us,overlayControls:Ys,overlayBtn:Zs,overlayBtnActive:Xs,zoomBar:Ks,toolPalette:Js,toolBtn:Qs,toolBtnActive:en,canvasWrapper:tn,canvas:sn,cur_select:nn,cur_drawzone:on,cur_drawwall:an,cur_placedevice:rn,cur_placedoor:cn,cur_placewindow:ln,cur_pan:dn,cur_erase:un,cur_measure:mn,cur_annotate:hn,gridLine:pn,zoneGroup:fn,zonePath:_n,zoneLabel:gn,climateLabel:yn,occupancyLabel:bn,dimLabel:xn,deviceGroup:vn,devCircle:jn,devOnline:wn,devOffline:Nn,devSelected:kn,propPanel:In,propTitle:Cn,propRow:Sn,statusBar:Ln,emptyState:Tn},$n=[{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"}],zn={living_room:"var(--nice-primary-bg, #dbeafe)",bedroom:"var(--nice-accent-tint-10, #fce7f3)",master_bedroom:"#f3e8ff",kids_room:"var(--nice-warning-bg, #fef3c7)",bathroom:"#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 Mn(t){return zn[t]??"var(--nice-primary-bg, #f0f4ff)"}function xs(t){if(!t.length)return{x:0,y:0};const s=t.reduce((n,o)=>({x:n.x+o.x,y:n.y+o.y}),{x:0,y:0});return{x:s.x/t.length,y:s.y/t.length}}function Zt(t,s=!0){return t.length<2?"":t.map((n,o)=>`${o===0?"M":"L"}${n.x.toFixed(1)},${n.y.toFixed(1)}`).join(" ")+(s?" Z":"")}function Bn(t,s){if(!t)return s?xs(s.polygon):null;if(!s||!s.polygon.length||t.x>1||t.y>1)return t;const n=s.polygon.map(c=>c.x),o=s.polygon.map(c=>c.y),a=Math.min(...n),i=Math.min(...o);return{x:a+t.x*(Math.max(...n)-a),y:i+t.y*(Math.max(...o)-i)}}function En(t,s,n){return n?{x:Math.round(t.x/s)*s,y:Math.round(t.y/s)*s}:t}function Pn(t,s){switch(s.t){case"TOOL":return{...t,tool:s.v,drawing:null,selected:null};case"FLOOR":return{...t,floorId:s.v,drawing:null,selected:null};case"SELECT":return{...t,selected:s.v};case"ZOOM":return{...t,zoom:Math.max(.15,Math.min(5,s.v))};case"PAN":return{...t,pan:s.v};case"DRAW_PT":return{...t,drawing:[...t.drawing??[],s.v]};case"DRAW_END":return{...t,drawing:null};case"TOGGLE":return s.v==="grid"?{...t,showGrid:!t.showGrid}:s.v==="dim"?{...t,showDim:!t.showDim}:s.v==="labels"?{...t,showLabels:!t.showLabels}:s.v==="occupancy"?{...t,showOccupancy:!t.showOccupancy}:{...t,showClimate:!t.showClimate};case"OVERLAYS":return{...t,...s.v};default:return t}}const An=[{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"}],On=({floors:t,defaultFloors:s,devices:n=[],onFloorChange:o,onDeviceMove:a,readOnly:i=!1,initialFloorId:c,showDevices:r=!0,showDimensions:l=!1,showGrid:y=!0,showOccupancy:d=!1,showClimate:x=!0,className:f,style:p,theme:_="light",tutorial:j})=>{var Be,Ee;const{t:h}=S.useNiceTranslation(),[k,C]=S.useControllableState({value:t,defaultValue:s,fallbackValue:[],onChange:o,componentName:"NiceFloorPlanEditor"}),T=m.useRef(null),b=m.useRef(!1),L=m.useRef({x:0,y:0}),[u,v]=m.useReducer(Pn,{floorId:c??((Be=k[0])==null?void 0:Be.id)??"",tool:"select",selected:null,zoom:1,pan:{x:0,y:0},drawing:null,showGrid:y,showDim:l,showLabels:!0,showOccupancy:d,showClimate:x,snapGrid:!0,gridSize:20});m.useEffect(()=>{v({t:"OVERLAYS",v:{showGrid:y,showDim:l,showOccupancy:d,showClimate:x}})},[y,l,d,x]);const g=k.find(M=>M.id===u.floorId)??k[0],q=m.useCallback(M=>{var he;const X=(he=T.current)==null?void 0:he.getBoundingClientRect();return X?{x:(M.clientX-X.left-u.pan.x)/u.zoom,y:(M.clientY-X.top-u.pan.y)/u.zoom}:{x:0,y:0}},[u.pan,u.zoom]),I=m.useCallback(M=>{u.tool==="pan"&&(b.current=!0,L.current={x:M.clientX,y:M.clientY})},[u.tool]),B=m.useCallback(M=>{b.current&&(v({t:"PAN",v:{x:u.pan.x+M.clientX-L.current.x,y:u.pan.y+M.clientY-L.current.y}}),L.current={x:M.clientX,y:M.clientY})},[u.pan]),V=m.useCallback(()=>{b.current=!1},[]),te=m.useCallback(M=>{if(u.tool==="draw_zone"){const X=En(q(M),u.gridSize,u.snapGrid);v({t:"DRAW_PT",v:X})}else u.tool==="select"&&v({t:"SELECT",v:null})},[u.tool,u.gridSize,u.snapGrid,q]),ue=m.useCallback(M=>{if(u.tool==="draw_zone"&&u.drawing&&u.drawing.length>=3&&g){const X={id:`zone-${Date.now()}`,name:"New zone",type:"other",floorId:g.id,polygon:[...u.drawing]};C(k.map(he=>he.id===g.id?{...g,zones:[...g.zones,X]}:he)),v({t:"DRAW_END"})}},[u.tool,u.drawing,g,k,C]),Q=m.useCallback(M=>{M.preventDefault(),v({t:"ZOOM",v:u.zoom*(M.deltaY>0?.9:1.1)})},[u.zoom]),fe=m.useCallback((M,X)=>{M.stopPropagation(),u.tool==="select"?v({t:"SELECT",v:{type:"zone",id:X.id}}):u.tool==="erase"&&!i&&g&&C(k.map(he=>he.id===g.id?{...g,zones:g.zones.filter(ke=>ke.id!==X.id)}:he))},[u.tool,i,g,k,C]);if(!g)return e.jsx("div",{className:oe.emptyState,children:h("buildings.noFloors","No floors.")});const se=((Ee=u.selected)==null?void 0:Ee.type)==="zone"?g.zones.find(M=>{var X;return M.id===((X=u.selected)==null?void 0:X.id)}):null,ge=r?n.filter(M=>g.zones.some(X=>X.id===M.zoneId)||M.floorPlanPosition):[],ze=[{key:"grid",icon:"grid",active:u.showGrid},{key:"dim",icon:"ruler",active:u.showDim},{key:"labels",icon:"tag",active:u.showLabels},{key:"occupancy",icon:"users",active:u.showOccupancy},{key:"climate",icon:"thermometer",active:u.showClimate}],Re=e.jsxs("div",{className:oe.topBar,children:[e.jsx("div",{className:oe.floorTabs,children:[...k].sort((M,X)=>M.level-X.level).map(M=>e.jsx("button",{className:`${oe.floorTab} ${u.floorId===M.id?oe.floorTabActive:""}`,onClick:()=>v({t:"FLOOR",v:M.id}),children:M.name},M.id))}),e.jsx("div",{className:oe.overlayControls,children:ze.map(M=>e.jsx("button",{title:M.key,"aria-label":M.key,className:`${oe.overlayBtn} ${M.active?oe.overlayBtnActive:""}`,onClick:()=>v({t:"TOGGLE",v:M.key}),children:e.jsx(S.NiceIcon,{name:M.icon,size:16})},M.key))}),e.jsxs("div",{className:oe.zoomBar,children:[e.jsx("button",{onClick:()=>v({t:"ZOOM",v:u.zoom*1.2}),children:"+"}),e.jsxs("span",{children:[Math.round(u.zoom*100),"%"]}),e.jsx("button",{onClick:()=>v({t:"ZOOM",v:u.zoom*.8}),children:"−"}),e.jsx("button",{title:h("buildings.resetView","Reset the view"),"aria-label":h("buildings.resetView","Reset the view"),onClick:()=>{v({t:"ZOOM",v:1}),v({t:"PAN",v:{x:0,y:0}})},children:e.jsx(S.NiceIcon,{name:"refresh",size:16})})]})]}),Te=i?void 0:e.jsx("div",{className:oe.toolPalette,children:An.map(({tool:M,icon:X,key:he,label:ke})=>e.jsx("button",{title:h(he,ke),"aria-label":h(he,ke),className:`${oe.toolBtn} ${u.tool===M?oe.toolBtnActive:""}`,onClick:()=>v({t:"TOOL",v:M}),children:e.jsx(S.NiceIcon,{name:X,size:18})},M))});return e.jsxs("div",{className:`nice-floor-plan-editor ${oe.root} ${_==="dark"?oe.dark:""} ${f??""}`,style:{position:"relative",...p},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:e.jsx(S.NiceTutorialButton,{steps:S.resolveTutorial(j,$n)})}),e.jsx(S.NiceAppShell,{flush:!0,className:oe.shell,menubar:Re,sidebar:Te,rightSidebar:se?e.jsxs("div",{className:oe.propPanel,children:[e.jsx("div",{className:oe.propTitle,children:se.name}),e.jsxs("div",{className:oe.propRow,children:[e.jsx("span",{children:h("buildings.type","Type")}),e.jsx("span",{children:se.type})]}),se.area!=null&&e.jsxs("div",{className:oe.propRow,children:[e.jsx("span",{children:"Pow."}),e.jsxs("span",{children:[se.area," m²"]})]}),se.temperature!=null&&e.jsxs("div",{className:oe.propRow,children:[e.jsx("span",{children:"Temp."}),e.jsxs("span",{children:[se.temperature.toFixed(1)," °C"]})]}),se.humidity!=null&&e.jsxs("div",{className:oe.propRow,children:[e.jsx("span",{children:h("buildings.humidity","Humidity")}),e.jsxs("span",{children:[se.humidity," %"]})]}),se.co2!=null&&e.jsxs("div",{className:oe.propRow,children:[e.jsx("span",{children:"CO₂"}),e.jsxs("span",{children:[se.co2," ppm"]})]}),se.occupancy!=null&&e.jsxs("div",{className:oe.propRow,children:[e.jsx("span",{children:h("buildings.occupancy","Occupancy")}),e.jsxs("span",{children:[se.occupancy," os."]})]})]}):void 0,statusBar:e.jsxs("div",{className:oe.statusBar,children:[u.tool==="draw_zone"?h("buildings.drawHint","Click points; double-click to close the zone."):u.selected?`${h("buildings.selected","Selected")}: ${u.selected.type} #${u.selected.id}`:`${g.name} — ${g.zones.length} ${h("buildings.zones","zones")}`,u.tool==="draw_zone"&&u.drawing&&` (${u.drawing.length} pkt)`]}),children:e.jsx("div",{className:oe.canvasWrapper,children:e.jsxs("svg",{ref:T,className:`${oe.canvas} ${oe[`cur_${u.tool.replace("_","")}`]??""}`,onMouseDown:I,onMouseMove:B,onMouseUp:V,onClick:te,onDoubleClick:ue,onWheel:Q,children:[g.backgroundImage&&e.jsx("image",{href:g.backgroundImage,x:u.pan.x,y:u.pan.y,width:g.width*u.zoom,height:g.height*u.zoom,preserveAspectRatio:"xMidYMid meet",opacity:.35}),e.jsxs("g",{transform:`translate(${u.pan.x},${u.pan.y}) scale(${u.zoom})`,children:[u.showGrid&&(()=>{const M=[];for(let X=0;X<=g.width;X+=u.gridSize)M.push(e.jsx("line",{x1:X,y1:0,x2:X,y2:g.height,className:oe.gridLine},`v${X}`));for(let X=0;X<=g.height;X+=u.gridSize)M.push(e.jsx("line",{x1:0,y1:X,x2:g.width,y2:X,className:oe.gridLine},`h${X}`));return e.jsx("g",{children:M})})(),g.zones.map(M=>{var Oe;const X=((Oe=u.selected)==null?void 0:Oe.id)===M.id,he=xs(M.polygon),ke=M.color??Mn(M.type);return e.jsxs("g",{className:oe.zoneGroup,onClick:je=>fe(je,M),children:[e.jsx("path",{d:Zt(M.polygon),fill:ke,fillOpacity:M.opacity??.55,stroke:X?"var(--nice-primary-hover, #2563eb)":"var(--nice-text-muted, #94a3b8)",strokeWidth:X?2.5:1.5,className:oe.zonePath}),u.showLabels&&e.jsx("text",{x:he.x,y:he.y,textAnchor:"middle",dominantBaseline:"middle",className:oe.zoneLabel,children:M.name}),u.showClimate&&M.temperature!=null&&e.jsxs("text",{x:he.x,y:he.y+14,textAnchor:"middle",className:oe.climateLabel,children:[M.temperature.toFixed(1),"°C"," ",M.humidity!=null?`· ${M.humidity}%`:""]}),u.showOccupancy&&M.occupancy!=null&&e.jsxs("text",{x:he.x,y:he.y+26,textAnchor:"middle",className:oe.occupancyLabel,children:[M.occupancy," ",h("buildings.people","people")]}),u.showDim&&M.polygon.length>1&&M.polygon.map((je,Pe)=>{const Se=M.polygon[(Pe+1)%M.polygon.length],Ie=(je.x+Se.x)/2,Ne=(je.y+Se.y)/2,me=Math.sqrt((Se.x-je.x)**2+(Se.y-je.y)**2),ie=g.scale??0;return e.jsx("text",{x:Ie,y:Ne-4,textAnchor:"middle",className:oe.dimLabel,children:ie>0?`${(me/ie).toFixed(1)}m`:`${me.toFixed(0)}px`},Pe)})]},M.id)}),ge.map(M=>{var Oe;const X=g.zones.find(je=>je.id===M.zoneId),he=Bn(M.floorPlanPosition,X);if(!he)return null;const ke=((Oe=u.selected)==null?void 0:Oe.id)===M.id;return e.jsxs("g",{transform:`translate(${he.x},${he.y})`,className:oe.deviceGroup,onClick:je=>{je.stopPropagation(),v({t:"SELECT",v:{type:"device",id:M.id}})},children:[e.jsx("circle",{r:14,className:`${oe.devCircle} ${M.status==="online"?oe.devOnline:oe.devOffline} ${ke?oe.devSelected:""}`}),e.jsx("g",{transform:"translate(-8,-8)",children:e.jsx(S.NiceIcon,{name:bs(M.type),size:16})})]},M.id)}),u.drawing&&u.drawing.length>0&&e.jsxs("g",{children:[e.jsx("path",{d:Zt(u.drawing,!1),fill:"none",stroke:"var(--nice-primary-hover, #2563eb)",strokeWidth:2,strokeDasharray:"6,3"}),u.drawing.map((M,X)=>e.jsx("circle",{cx:M.x,cy:M.y,r:4,fill:"var(--nice-primary-hover, #2563eb)"},X))]})]})]})})})]})},Dn={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 Vt(t,s){const{cellSize:n,origin:o}=s;return{x:Math.round((t.x-o.x)/n)*n+o.x,y:Math.round((t.y-o.y)/n)*n+o.y}}function Rn(t,s){return{x:Math.round(t.x/s)*s,y:Math.round(t.y/s)*s,z:Math.round(t.z/s)*s}}function qn(t){if(t.snapPoints)return t.snapPoints;const{x:s,y:n,width:o,height:a}=t.bounds;return[{x:s,y:n},{x:s+o,y:n},{x:s+o,y:n+a},{x:s,y:n+a},{x:s+o/2,y:n+a/2},{x:s+o/2,y:n},{x:s+o,y:n+a/2},{x:s+o/2,y:n+a},{x:s,y:n+a/2}]}function Fn(t,s,n){let o=null;for(const a of s){const i=qn(a);for(const c of i){const r=at(t,c);r<=n&&(!o||r<o.distance)&&(o={point:c,targetId:a.id,distance:r})}}return o}function at(t,s){return Math.sqrt((s.x-t.x)**2+(s.y-t.y)**2)}function vs(t,s,n){const o=[],a={x:t.x+t.width/2,y:t.y+t.height/2};for(const i of s){const c={x:i.bounds.x+i.bounds.width/2,y:i.bounds.y+i.bounds.height/2};Math.abs(a.y-c.y)<=n&&o.push({type:"horizontal",start:{x:Math.min(t.x,i.bounds.x),y:c.y},end:{x:Math.max(t.x+t.width,i.bounds.x+i.bounds.width),y:c.y},distance:Math.abs(a.y-c.y),sourceObjectId:i.id}),Math.abs(a.x-c.x)<=n&&o.push({type:"vertical",start:{x:c.x,y:Math.min(t.y,i.bounds.y)},end:{x:c.x,y:Math.max(t.y+t.height,i.bounds.y+i.bounds.height)},distance:Math.abs(a.x-c.x),sourceObjectId:i.id});const r=[{dragged:t.y,other:i.bounds.y,axis:"horizontal"},{dragged:t.y+t.height,other:i.bounds.y+i.bounds.height,axis:"horizontal"},{dragged:t.x,other:i.bounds.x,axis:"vertical"},{dragged:t.x+t.width,other:i.bounds.x+i.bounds.width,axis:"vertical"}];for(const l of r)Math.abs(l.dragged-l.other)<=n&&(l.axis==="horizontal"?o.push({type:"horizontal",start:{x:Math.min(t.x,i.bounds.x),y:l.other},end:{x:Math.max(t.x+t.width,i.bounds.x+i.bounds.width),y:l.other},distance:Math.abs(l.dragged-l.other),sourceObjectId:i.id}):o.push({type:"vertical",start:{x:l.other,y:Math.min(t.y,i.bounds.y)},end:{x:l.other,y:Math.max(t.y+t.height,i.bounds.y+i.bounds.height)},distance:Math.abs(l.dragged-l.other),sourceObjectId:i.id}))}return Gn(o)}function Gn(t){const s=new Set;return t.filter(n=>{const o=`${n.type}-${n.start.x.toFixed(1)}-${n.start.y.toFixed(1)}-${n.end.x.toFixed(1)}-${n.end.y.toFixed(1)}`;return s.has(o)?!1:(s.add(o),!0)})}function Wn(t,s,n){const o={position:{...t},snapped:!1,snapMode:null,guides:[]},{snapModes:a,snapThreshold:i}=n;if(a.includes("endpoint")||a.includes("center")||a.includes("midpoint")){const c=Fn(t,s,i);if(c)return o.position=c.point,o.snapped=!0,o.snapMode="endpoint",o.targetObjectId=c.targetId,o}if(a.includes("grid")){const c=Vt(t,n);if(at(t,c)<=i)return o.position=c,o.snapped=!0,o.snapMode="grid",o}return o}const Vn=[{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 Ht(t,s="floor-plan"){const n=new Date().toISOString();return{$schema:"https://nice2dev.com/schemas/nsp-v1.json",version:"1.0.0",type:s,metadata:{id:Hn(),name:t,created:n,modified:n},floors:[],settings:{units:"metric",scale:50,grid:{visible:!0,size:.5,snapEnabled:!0},defaultWallHeight:2.7,defaultWallThickness:.15,precision:2}}}function Hn(){return`${Date.now().toString(36)}-${Math.random().toString(36).substr(2,9)}`}const Xt={ft:3.28084,in:39.3701},Kt={"ft²":.092903,acre:4046.86};function Un(t){return t*(180/Math.PI)}function Yn(t,s){return Math.sqrt((s.x-t.x)**2+(s.y-t.y)**2)}function Zn(t){if(t.length<2)return 0;let s=0;for(let n=1;n<t.length;n++)s+=Yn(t[n-1],t[n]);return s}function At(t,s,n){const o={x:t.x-s.x,y:t.y-s.y},a={x:n.x-s.x,y:n.y-s.y},i=o.x*a.x+o.y*a.y,c=Math.sqrt(o.x**2+o.y**2),r=Math.sqrt(a.x**2+a.y**2);if(c===0||r===0)return 0;const l=i/(c*r);return Math.acos(Math.max(-1,Math.min(1,l)))}function Ot(t){if(t.length<3)return 0;let s=0;const n=t.length;for(let o=0;o<n;o++){const a=(o+1)%n;s+=t[o].x*t[a].y,s-=t[a].x*t[o].y}return Math.abs(s)/2}function st(t,s="m",n=2){const o=`${t.toFixed(n)} ${s}`;return{value:t,unit:s,formatted:o}}function mt(t,s="m²",n=2){const o=`${t.toFixed(n)} ${s}`;return{value:t,unit:s,formatted:o}}function Dt(t,s="deg",n=1){const o=s==="deg"?Un(t):t,a=s==="deg"?"°":" rad",i=`${o.toFixed(n)}${a}`;return{value:o,unit:s,formatted:i}}function ht(t,s="metric",n=2){if(s==="metric")return t<.01?st(t*1e3,"mm",n):t<1?st(t*100,"cm",n):st(t,"m",n);{const o=t*Xt.ft;return o<1?st(t*Xt.in,"in",n):st(o,"ft",n)}}function Rt(t,s="metric",n=2){if(s==="metric")return t>=1e4?mt(t/1e4,"ha",n):mt(t,"m²",n);{const o=t/Kt["ft²"];return o>=43560?mt(t/Kt.acre,"acre",n):mt(o,"ft²",n)}}function Xn(t,s={}){const{pretty:n=!1,includeSchema:o=!0,excludeEmptyLayers:a=!1,includeMetadata:i=!0}=s,c=JSON.parse(JSON.stringify(t));if(o&&!c.$schema&&(c.$schema="https://nice2dev.com/schemas/nsp-v1.json"),i&&(c.metadata=c.metadata??{id:"",name:"",created:new Date().toISOString(),modified:new Date().toISOString()},c.metadata.modified=new Date().toISOString()),a)for(const r of c.floors)r.layers=r.layers.filter(l=>l.objects.length>0);return n?JSON.stringify(c,null,2):JSON.stringify(c)}function Kn(t,s={}){var c;const n=ao(t,s),o=Xn(n),a=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:a,size:a.size}}const Jn="http://www.w3.org/2000/svg";function Qn(t,s={}){var _,j;const{floorIds:n,includeGrid:o=!1,scale:a=1,backgroundColor:i}=s,c=n?t.floors.filter(h=>n.includes(h.id)):t.floors;if(c.length===0)throw new Error("No floors to export");const r=oo(c),l=(r.maxX-r.minX)*a,y=(r.maxY-r.minY)*a,d=((_=t.metadata)==null?void 0:_.name)||"Floor Plan";let x=`<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<svg xmlns="${
|
|
1
|
+
"use strict";var Dn=Object.defineProperty;var Rn=(t,n,s)=>n in t?Dn(t,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[n]=s;var ut=(t,n,s)=>Rn(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"),qn={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 xn(t){return qn[t]??"settings"}const Fn="_root_1nq8c_1",Gn="_shell_1nq8c_27",Vn="_dark_1nq8c_35",Wn="_topBar_1nq8c_49",Hn="_floorTabs_1nq8c_79",Un="_floorTab_1nq8c_79",Yn="_floorTabActive_1nq8c_119",Zn="_overlayControls_1nq8c_131",Xn="_overlayBtn_1nq8c_143",Kn="_overlayBtnActive_1nq8c_179",Jn="_zoomBar_1nq8c_191",Qn="_toolPalette_1nq8c_245",es="_toolBtn_1nq8c_275",ts="_toolBtnActive_1nq8c_311",ns="_canvasWrapper_1nq8c_325",ss="_canvas_1nq8c_325",os="_cur_select_1nq8c_365",as="_cur_drawzone_1nq8c_371",is="_cur_drawwall_1nq8c_377",rs="_cur_placedevice_1nq8c_383",cs="_cur_placedoor_1nq8c_389",ls="_cur_placewindow_1nq8c_395",ds="_cur_pan_1nq8c_401",us="_cur_erase_1nq8c_407",ms="_cur_measure_1nq8c_413",ps="_cur_annotate_1nq8c_419",hs="_gridLine_1nq8c_429",gs="_zoneGroup_1nq8c_447",_s="_zonePath_1nq8c_455",fs="_zoneLabel_1nq8c_463",ys="_climateLabel_1nq8c_485",bs="_occupancyLabel_1nq8c_497",xs="_dimLabel_1nq8c_509",vs="_deviceGroup_1nq8c_521",js="_devCircle_1nq8c_529",Ns="_devOnline_1nq8c_541",ws="_devOffline_1nq8c_547",Is="_devSelected_1nq8c_553",ks="_propPanel_1nq8c_565",Ss="_propTitle_1nq8c_593",Cs="_propRow_1nq8c_615",Ts="_statusBar_1nq8c_655",Ls="_emptyState_1nq8c_687",oe={root:Fn,shell:Gn,dark:Vn,topBar:Wn,floorTabs:Hn,floorTab:Un,floorTabActive:Yn,overlayControls:Zn,overlayBtn:Xn,overlayBtnActive:Kn,zoomBar:Jn,toolPalette:Qn,toolBtn:es,toolBtnActive:ts,canvasWrapper:ns,canvas:ss,cur_select:os,cur_drawzone:as,cur_drawwall:is,cur_placedevice:rs,cur_placedoor:cs,cur_placewindow:ls,cur_pan:ds,cur_erase:us,cur_measure:ms,cur_annotate:ps,gridLine:hs,zoneGroup:gs,zonePath:_s,zoneLabel:fs,climateLabel:ys,occupancyLabel:bs,dimLabel:xs,deviceGroup:vs,devCircle:js,devOnline:Ns,devOffline:ws,devSelected:Is,propPanel:ks,propTitle:Ss,propRow:Cs,statusBar:Ts,emptyState:Ls},$s=[{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"}],zs={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 Ps(t){return zs[t]??"var(--nice-primary-bg, #f0f4ff)"}function vn(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 Zt(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 Ms(t,n){if(!t)return n?vn(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 Es(t,n,s){return s?{x:Math.round(t.x/n)*n,y:Math.round(t.y/n)*n}:t}function Os(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 As=[{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"}],Bs=({floors:t,defaultFloors:n,devices:s=[],onFloorChange:o,onDeviceMove:i,readOnly:a=!1,initialFloorId:c,showDevices:r=!0,showDimensions:l=!1,showGrid:b=!0,showOccupancy:m=!1,showClimate:h=!0,className:v,style:x,theme:p="light",tutorial:j})=>{var Me,Ee;const{t:g}=N.useNiceTranslation(),[I,y]=N.useControllableState({value:t,defaultValue:n,fallbackValue:[],onChange:o,componentName:"NiceFloorPlanEditor"}),L=u.useRef(null),_=u.useRef(!1),C=u.useRef({x:0,y:0}),[d,w]=u.useReducer(Os,{floorId:c??((Me=I[0])==null?void 0:Me.id)??"",tool:"select",selected:null,zoom:1,pan:{x:0,y:0},drawing:null,showGrid:b,showDim:l,showLabels:!0,showOccupancy:m,showClimate:h,snapGrid:!0,gridSize:20});u.useEffect(()=>{w({t:"OVERLAYS",v:{showGrid:b,showDim:l,showOccupancy:m,showClimate:h}})},[b,l,m,h]);const f=I.find(P=>P.id===d.floorId)??I[0],q=u.useCallback(P=>{var pe;const K=(pe=L.current)==null?void 0:pe.getBoundingClientRect();return K?{x:(P.clientX-K.left-d.pan.x)/d.zoom,y:(P.clientY-K.top-d.pan.y)/d.zoom}:{x:0,y:0}},[d.pan,d.zoom]),T=u.useCallback(P=>{d.tool==="pan"&&(_.current=!0,C.current={x:P.clientX,y:P.clientY})},[d.tool]),M=u.useCallback(P=>{_.current&&(w({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]),W=u.useCallback(()=>{_.current=!1},[]),te=u.useCallback(P=>{if(d.tool==="draw_zone"){const K=Es(q(P),d.gridSize,d.snapGrid);w({t:"DRAW_PT",v:K})}else d.tool==="select"&&w({t:"SELECT",v:null})},[d.tool,d.gridSize,d.snapGrid,q]),ue=u.useCallback(P=>{if(d.tool==="draw_zone"&&d.drawing&&d.drawing.length>=3&&f){const K={id:`zone-${Date.now()}`,name:"New zone",type:"other",floorId:f.id,polygon:[...d.drawing]};y(I.map(pe=>pe.id===f.id?{...f,zones:[...f.zones,K]}:pe)),w({t:"DRAW_END"})}},[d.tool,d.drawing,f,I,y]),ee=u.useCallback(P=>{P.preventDefault(),w({t:"ZOOM",v:d.zoom*(P.deltaY>0?.9:1.1)})},[d.zoom]),ge=u.useCallback((P,K)=>{P.stopPropagation(),d.tool==="select"?w({t:"SELECT",v:{type:"zone",id:K.id}}):d.tool==="erase"&&!a&&f&&y(I.map(pe=>pe.id===f.id?{...f,zones:f.zones.filter(Ie=>Ie.id!==K.id)}:pe))},[d.tool,a,f,I,y]);if(!f)return e.jsx("div",{className:oe.emptyState,children:g("buildings.noFloors","No floors.")});const ne=((Ee=d.selected)==null?void 0:Ee.type)==="zone"?f.zones.find(P=>{var K;return P.id===((K=d.selected)==null?void 0:K.id)}):null,fe=r?s.filter(P=>f.zones.some(K=>K.id===P.zoneId)||P.floorPlanPosition):[],ze=[{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}],Re=e.jsxs("div",{className:oe.topBar,children:[e.jsx("div",{className:oe.floorTabs,children:[...I].sort((P,K)=>P.level-K.level).map(P=>e.jsx("button",{className:`${oe.floorTab} ${d.floorId===P.id?oe.floorTabActive:""}`,onClick:()=>w({t:"FLOOR",v:P.id}),children:P.name},P.id))}),e.jsx("div",{className:oe.overlayControls,children:ze.map(P=>e.jsx("button",{title:P.key,"aria-label":P.key,className:`${oe.overlayBtn} ${P.active?oe.overlayBtnActive:""}`,onClick:()=>w({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:()=>w({t:"ZOOM",v:d.zoom*1.2}),children:"+"}),e.jsxs("span",{children:[Math.round(d.zoom*100),"%"]}),e.jsx("button",{onClick:()=>w({t:"ZOOM",v:d.zoom*.8}),children:"−"}),e.jsx("button",{title:g("buildings.resetView","Reset the view"),"aria-label":g("buildings.resetView","Reset the view"),onClick:()=>{w({t:"ZOOM",v:1}),w({t:"PAN",v:{x:0,y:0}})},children:e.jsx(N.NiceIcon,{name:"refresh",size:16})})]})]}),Le=a?void 0:e.jsx("div",{className:oe.toolPalette,children:As.map(({tool:P,icon:K,key:pe,label:Ie})=>e.jsx("button",{title:g(pe,Ie),"aria-label":g(pe,Ie),className:`${oe.toolBtn} ${d.tool===P?oe.toolBtnActive:""}`,onClick:()=>w({t:"TOOL",v:P}),children:e.jsx(N.NiceIcon,{name:K,size:18})},P))});return e.jsxs("div",{className:`nice-floor-plan-editor ${oe.root} ${p==="dark"?oe.dark:""} ${v??""}`,style:{position:"relative",...x},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:e.jsx(N.NiceTutorialButton,{steps:N.resolveTutorial(j,$s)})}),e.jsx(N.NiceAppShell,{flush:!0,className:oe.shell,menubar:Re,sidebar:Le,rightSidebar:ne?e.jsxs("div",{className:oe.propPanel,children:[e.jsx("div",{className:oe.propTitle,children:ne.name}),e.jsxs("div",{className:oe.propRow,children:[e.jsx("span",{children:g("buildings.type","Type")}),e.jsx("span",{children:ne.type})]}),ne.area!=null&&e.jsxs("div",{className:oe.propRow,children:[e.jsx("span",{children:g("buildings.area","Area")}),e.jsxs("span",{children:[ne.area," m²"]})]}),ne.temperature!=null&&e.jsxs("div",{className:oe.propRow,children:[e.jsx("span",{children:g("buildings.temp","Temp.")}),e.jsxs("span",{children:[ne.temperature.toFixed(1)," °C"]})]}),ne.humidity!=null&&e.jsxs("div",{className:oe.propRow,children:[e.jsx("span",{children:g("buildings.humidity","Humidity")}),e.jsxs("span",{children:[ne.humidity," %"]})]}),ne.co2!=null&&e.jsxs("div",{className:oe.propRow,children:[e.jsx("span",{children:"CO₂"}),e.jsxs("span",{children:[ne.co2," ppm"]})]}),ne.occupancy!=null&&e.jsxs("div",{className:oe.propRow,children:[e.jsx("span",{children:g("buildings.occupancy","Occupancy")}),e.jsx("span",{children:g("buildings.people2","{occupancy} people").replace("{occupancy}",String(ne.occupancy))})]})]}):void 0,statusBar:e.jsxs("div",{className:oe.statusBar,children:[d.tool==="draw_zone"?g("buildings.drawHint","Click points; double-click to close the zone."):d.selected?`${g("buildings.selected","Selected")}: ${d.selected.type} #${d.selected.id}`:`${f.name} — ${f.zones.length} ${g("buildings.zones","zones")}`,d.tool==="draw_zone"&&d.drawing&&g("buildings.pts"," ({drawing} pts)").replace("{drawing}",String(d.drawing.length))]}),children:e.jsx("div",{className:oe.canvasWrapper,children:e.jsxs("svg",{ref:L,className:`${oe.canvas} ${oe[`cur_${d.tool.replace("_","")}`]??""}`,onMouseDown:T,onMouseMove:M,onMouseUp:W,onClick:te,onDoubleClick:ue,onWheel:ee,children:[f.backgroundImage&&e.jsx("image",{href:f.backgroundImage,x:d.pan.x,y:d.pan.y,width:f.width*d.zoom,height:f.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 K=0;K<=f.width;K+=d.gridSize)P.push(e.jsx("line",{x1:K,y1:0,x2:K,y2:f.height,className:oe.gridLine},`v${K}`));for(let K=0;K<=f.height;K+=d.gridSize)P.push(e.jsx("line",{x1:0,y1:K,x2:f.width,y2:K,className:oe.gridLine},`h${K}`));return e.jsx("g",{children:P})})(),f.zones.map(P=>{var Be;const K=((Be=d.selected)==null?void 0:Be.id)===P.id,pe=vn(P.polygon),Ie=P.color??Ps(P.type);return e.jsxs("g",{className:oe.zoneGroup,onClick:je=>ge(je,P),children:[e.jsx("path",{d:Zt(P.polygon),fill:Ie,fillOpacity:P.opacity??.55,stroke:K?"var(--nice-primary-hover, #2563eb)":"var(--nice-text-muted, #94a3b8)",strokeWidth:K?2.5:1.5,className:oe.zonePath}),d.showLabels&&e.jsx("text",{x:pe.x,y:pe.y,textAnchor:"middle",dominantBaseline:"middle",className:oe.zoneLabel,children:P.name}),d.showClimate&&P.temperature!=null&&e.jsxs("text",{x:pe.x,y:pe.y+14,textAnchor:"middle",className:oe.climateLabel,children:[P.temperature.toFixed(1),"°C"," ",P.humidity!=null?`· ${P.humidity}%`:""]}),d.showOccupancy&&P.occupancy!=null&&e.jsxs("text",{x:pe.x,y:pe.y+26,textAnchor:"middle",className:oe.occupancyLabel,children:[P.occupancy," ",g("buildings.people","people")]}),d.showDim&&P.polygon.length>1&&P.polygon.map((je,Oe)=>{const Ce=P.polygon[(Oe+1)%P.polygon.length],ke=(je.x+Ce.x)/2,we=(je.y+Ce.y)/2,me=Math.sqrt((Ce.x-je.x)**2+(Ce.y-je.y)**2),ie=f.scale??0;return e.jsx("text",{x:ke,y:we-4,textAnchor:"middle",className:oe.dimLabel,children:ie>0?`${(me/ie).toFixed(1)}m`:`${me.toFixed(0)}px`},Oe)})]},P.id)}),fe.map(P=>{var Be;const K=f.zones.find(je=>je.id===P.zoneId),pe=Ms(P.floorPlanPosition,K);if(!pe)return null;const Ie=((Be=d.selected)==null?void 0:Be.id)===P.id;return e.jsxs("g",{transform:`translate(${pe.x},${pe.y})`,className:oe.deviceGroup,onClick:je=>{je.stopPropagation(),w({t:"SELECT",v:{type:"device",id:P.id}})},children:[e.jsx("circle",{r:14,className:`${oe.devCircle} ${P.status==="online"?oe.devOnline:oe.devOffline} ${Ie?oe.devSelected:""}`}),e.jsx("g",{transform:"translate(-8,-8)",children:e.jsx(N.NiceIcon,{name:xn(P.type),size:16})})]},P.id)}),d.drawing&&d.drawing.length>0&&e.jsxs("g",{children:[e.jsx("path",{d:Zt(d.drawing,!1),fill:"none",stroke:"var(--nice-primary-hover, #2563eb)",strokeWidth:2,strokeDasharray:"6,3"}),d.drawing.map((P,K)=>e.jsx("circle",{cx:P.x,cy:P.y,r:4,fill:"var(--nice-primary-hover, #2563eb)"},K))]})]})]})})})]})},Ds={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 Wt(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 Rs(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 qs(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 Fs(t,n,s){let o=null;for(const i of n){const a=qs(i);for(const c of a){const r=at(t,c);r<=s&&(!o||r<o.distance)&&(o={point:c,targetId:i.id,distance:r})}}return o}function at(t,n){return Math.sqrt((n.x-t.x)**2+(n.y-t.y)**2)}function jn(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 Gs(o)}function Gs(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 Vs(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=Fs(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=Wt(t,s);if(at(t,c)<=a)return o.position=c,o.snapped=!0,o.snapMode="grid",o}return o}const Ws=[{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 Ht(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:Hs(),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 Hs(){return`${Date.now().toString(36)}-${Math.random().toString(36).substr(2,9)}`}const Xt={ft:3.28084,in:39.3701},Kt={"ft²":.092903,acre:4046.86};function Us(t){return t*(180/Math.PI)}function Ys(t,n){return Math.sqrt((n.x-t.x)**2+(n.y-t.y)**2)}function Zs(t){if(t.length<2)return 0;let n=0;for(let s=1;s<t.length;s++)n+=Ys(t[s-1],t[s]);return n}function At(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 Bt(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 nt(t,n="m",s=2){const o=`${t.toFixed(s)} ${n}`;return{value:t,unit:n,formatted:o}}function mt(t,n="m²",s=2){const o=`${t.toFixed(s)} ${n}`;return{value:t,unit:n,formatted:o}}function Dt(t,n="deg",s=1){const o=n==="deg"?Us(t):t,i=n==="deg"?"°":" rad",a=`${o.toFixed(s)}${i}`;return{value:o,unit:n,formatted:a}}function pt(t,n="metric",s=2){if(n==="metric")return t<.01?nt(t*1e3,"mm",s):t<1?nt(t*100,"cm",s):nt(t,"m",s);{const o=t*Xt.ft;return o<1?nt(t*Xt.in,"in",s):nt(o,"ft",s)}}function Rt(t,n="metric",s=2){if(n==="metric")return t>=1e4?mt(t/1e4,"ha",s):mt(t,"m²",s);{const o=t/Kt["ft²"];return o>=43560?mt(t/Kt.acre,"acre",s):mt(o,"ft²",s)}}function Xs(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 Ks(t,n={}){var c;const s=ao(t,n),o=Xs(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 Js="http://www.w3.org/2000/svg";function Qs(t,n={}){var p,j;const{floorIds:s,includeGrid:o=!1,scale:i=1,backgroundColor:a}=n,c=s?t.floors.filter(g=>s.includes(g.id)):t.floors;if(c.length===0)throw new Error("No floors to export");const r=oo(c),l=(r.maxX-r.minX)*i,b=(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="${Js}"
|
|
3
3
|
viewBox="${r.minX} ${r.minY} ${r.maxX-r.minX} ${r.maxY-r.minY}"
|
|
4
4
|
width="${l}"
|
|
5
|
-
height="${
|
|
6
|
-
style="background: ${
|
|
7
|
-
<title>${
|
|
5
|
+
height="${b}"
|
|
6
|
+
style="background: ${a||"transparent"}">
|
|
7
|
+
<title>${m}</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
|
|
22
|
-
`,o&&(
|
|
23
|
-
`;for(const
|
|
24
|
-
`}
|
|
25
|
-
`}
|
|
26
|
-
`;for(let o=Math.floor(t.minX/20)*20;o<=t.maxX;o+=20)
|
|
27
|
-
`;for(let o=Math.floor(t.minY/20)*20;o<=t.maxY;o+=20)
|
|
28
|
-
`;return
|
|
29
|
-
`,
|
|
30
|
-
`;if(
|
|
31
|
-
`;if(t.bounds){const{x:
|
|
32
|
-
`:` <rect x="${
|
|
33
|
-
`}return""}function
|
|
21
|
+
`;for(const g of c){h+=` <g id="${g.id}" class="floor" data-name="${g.name}">
|
|
22
|
+
`,o&&(h+=eo(r));for(const I of g.layers)if(Nn(I.name,n)){h+=` <g id="${I.id}" class="layer-${I.name}">
|
|
23
|
+
`;for(const y of I.objects)h+=to(y);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 eo(t){let s=` <g class="grid">
|
|
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
|
+
`;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
|
+
`;return s+=` </g>
|
|
29
|
+
`,s}function to(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
|
+
`;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
|
+
`;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
|
+
`:` <rect x="${s}" y="${o}" width="${i}" height="${a}" class="${t.category||"object"}" />
|
|
33
|
+
`}return""}function no(t,n={}){var b;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
|
|
34
34
|
SECTION
|
|
35
35
|
2
|
|
36
36
|
HEADER
|
|
@@ -44,7 +44,7 @@ $INSUNITS
|
|
|
44
44
|
4
|
|
45
45
|
0
|
|
46
46
|
ENDSEC
|
|
47
|
-
`,
|
|
47
|
+
`,a+=`0
|
|
48
48
|
SECTION
|
|
49
49
|
2
|
|
50
50
|
TABLES
|
|
@@ -52,88 +52,88 @@ TABLES
|
|
|
52
52
|
TABLE
|
|
53
53
|
2
|
|
54
54
|
LAYER
|
|
55
|
-
`;const c=new Set;for(const
|
|
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
|
|
56
56
|
LAYER
|
|
57
57
|
2
|
|
58
|
-
${
|
|
58
|
+
${m.toUpperCase()}
|
|
59
59
|
70
|
|
60
60
|
0
|
|
61
61
|
62
|
|
62
62
|
7
|
|
63
63
|
6
|
|
64
64
|
CONTINUOUS
|
|
65
|
-
`;
|
|
65
|
+
`;a+=`0
|
|
66
66
|
ENDTAB
|
|
67
67
|
0
|
|
68
68
|
ENDSEC
|
|
69
|
-
`,
|
|
69
|
+
`,a+=`0
|
|
70
70
|
SECTION
|
|
71
71
|
2
|
|
72
72
|
ENTITIES
|
|
73
|
-
`;for(const
|
|
73
|
+
`;for(const m of i)for(const h of m.layers){if(!Nn(h.name,n))continue;const v=h.name.toUpperCase();for(const x of h.objects)a+=so(x,v,o)}a+=`0
|
|
74
74
|
ENDSEC
|
|
75
75
|
0
|
|
76
76
|
EOF
|
|
77
|
-
`;const r=new Blob([
|
|
77
|
+
`;const r=new Blob([a],{type:"application/dxf"});return{format:"dxf",filename:`${((b=t.metadata)==null?void 0:b.name)||"document"}.dxf`,mimeType:"application/dxf",data:r,size:r.size}}function so(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}
|
|
81
81
|
90
|
|
82
82
|
${o.boundary.length}
|
|
83
83
|
70
|
|
84
84
|
1
|
|
85
|
-
`;for(const
|
|
86
|
-
${
|
|
85
|
+
`;for(const a of o.boundary)i+=`10
|
|
86
|
+
${a.x*s}
|
|
87
87
|
20
|
|
88
|
-
${
|
|
89
|
-
`;return
|
|
88
|
+
${a.y*s}
|
|
89
|
+
`;return i}if(o.start&&o.end)return`0
|
|
90
90
|
LINE
|
|
91
91
|
8
|
|
92
|
-
${
|
|
92
|
+
${n}
|
|
93
93
|
10
|
|
94
|
-
${o.start.x*
|
|
94
|
+
${o.start.x*s}
|
|
95
95
|
20
|
|
96
|
-
${o.start.y*
|
|
96
|
+
${o.start.y*s}
|
|
97
97
|
11
|
|
98
|
-
${o.end.x*
|
|
98
|
+
${o.end.x*s}
|
|
99
99
|
21
|
|
100
|
-
${o.end.y*
|
|
101
|
-
`;if(t.bounds){const{x:
|
|
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,b=(a+r/2)*s;if(t.category==="smart-home"){const m=Math.min(c,r)/2*s;return`0
|
|
102
102
|
CIRCLE
|
|
103
103
|
8
|
|
104
|
-
${
|
|
104
|
+
${n}
|
|
105
105
|
10
|
|
106
106
|
${l}
|
|
107
107
|
20
|
|
108
|
-
${
|
|
108
|
+
${b}
|
|
109
109
|
40
|
|
110
|
-
${
|
|
110
|
+
${m}
|
|
111
111
|
`}return`0
|
|
112
112
|
LWPOLYLINE
|
|
113
113
|
8
|
|
114
|
-
${
|
|
114
|
+
${n}
|
|
115
115
|
90
|
|
116
116
|
4
|
|
117
117
|
70
|
|
118
118
|
1
|
|
119
119
|
10
|
|
120
|
-
${
|
|
120
|
+
${i*s}
|
|
121
121
|
20
|
|
122
|
-
${
|
|
122
|
+
${a*s}
|
|
123
123
|
10
|
|
124
|
-
${(
|
|
124
|
+
${(i+c)*s}
|
|
125
125
|
20
|
|
126
|
-
${
|
|
126
|
+
${a*s}
|
|
127
127
|
10
|
|
128
|
-
${(
|
|
128
|
+
${(i+c)*s}
|
|
129
129
|
20
|
|
130
|
-
${(
|
|
130
|
+
${(a+r)*s}
|
|
131
131
|
10
|
|
132
|
-
${
|
|
132
|
+
${i*s}
|
|
133
133
|
20
|
|
134
|
-
${(
|
|
135
|
-
`}return""}function oo(t){let s=1/0,n=1/0,o=-1/0,a=-1/0;for(const i of t){i.bounds&&(s=Math.min(s,i.bounds.x),n=Math.min(n,i.bounds.y),o=Math.max(o,i.bounds.x+i.bounds.width),a=Math.max(a,i.bounds.y+i.bounds.height));for(const c of i.layers)for(const r of c.objects){r.bounds&&(s=Math.min(s,r.bounds.x),n=Math.min(n,r.bounds.y),o=Math.max(o,r.bounds.x+r.bounds.width),a=Math.max(a,r.bounds.y+r.bounds.height));const l=r;if(l.boundary)for(const y of l.boundary)s=Math.min(s,y.x),n=Math.min(n,y.y),o=Math.max(o,y.x),a=Math.max(a,y.y)}}return isFinite(s)||(s=0),isFinite(n)||(n=0),isFinite(o)||(o=1e3),isFinite(a)||(a=800),{minX:s,minY:n,maxX:o,maxY:a}}function ao(t,s){const{floorIds:n,layerNames:o}=s;let a=t.floors;return n&&n.length>0&&(a=a.filter(i=>n.includes(i.id))),o&&o.length>0&&(a=a.map(i=>({...i,layers:i.layers.filter(c=>o.includes(c.name))}))),{...t,floors:a}}function js(t,s){const{layerNames:n,includeGrid:o,includeDimensions:a}=s;return t==="grid"&&!o||(t==="dimensions"||t==="annotations")&&a===!1?!1:n&&n.length>0?n.includes(t):!0}function pt(t){const s=t.data instanceof Blob?t.data:new Blob([t.data],{type:t.mimeType}),n=URL.createObjectURL(s),o=document.createElement("a");o.href=n,o.download=t.filename,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(n)}async function io(t,s,n={}){const{dpi:o=96,backgroundColor:a="#ffffff"}=n,i=new XMLSerializer().serializeToString(t),c=new Blob([i],{type:"image/svg+xml;charset=utf-8"}),r=URL.createObjectURL(c);return new Promise((l,y)=>{const d=new Image;d.onload=()=>{const x=o/96,f=document.createElement("canvas");f.width=d.width*x,f.height=d.height*x;const p=f.getContext("2d");if(!p){y(new Error("Could not get canvas context"));return}p.fillStyle=a,p.fillRect(0,0,f.width,f.height),p.scale(x,x),p.drawImage(d,0,0),f.toBlob(_=>{if(URL.revokeObjectURL(r),!_){y(new Error("Could not create PNG blob"));return}l({format:"png",filename:s.endsWith(".png")?s:`${s}.png`,mimeType:"image/png",data:_,size:_.size})},"image/png")},d.onerror=()=>{URL.revokeObjectURL(r),y(new Error("Failed to load SVG for PNG export"))},d.src=r})}function ws(t){const s=new Map;for(const n of t)n.status!=="error"&&(s.has(n.sourceId)||s.set(n.sourceId,[]),s.get(n.sourceId).push({deviceId:n.targetId,connection:n}),s.has(n.targetId)||s.set(n.targetId,[]),s.get(n.targetId).push({deviceId:n.sourceId,connection:n}));return s}function ro(t,s,n,o="latency"){const a=ws(t);if(!a.has(s)||!a.has(n))return null;const i=new Map,c=new Map,r=new Set,l=[];for(const _ of a.keys())i.set(_,1/0),c.set(_,null);for(i.set(s,0),l.push({deviceId:s,distance:0});l.length>0;){l.sort((h,k)=>h.distance-k.distance);const _=l.shift();if(r.has(_.deviceId))continue;if(r.add(_.deviceId),_.deviceId===n)break;const j=a.get(_.deviceId)??[];for(const h of j){if(r.has(h.deviceId))continue;let k;switch(o){case"latency":k=h.connection.latency??1;break;case"hops":k=1;break;case"bandwidth":k=1/(h.connection.bandwidth??1);break}const C=i.get(_.deviceId)+k;C<i.get(h.deviceId)&&(i.set(h.deviceId,C),c.set(h.deviceId,{deviceId:_.deviceId,connection:h.connection}),l.push({deviceId:h.deviceId,distance:C}))}}if(!c.has(n)||i.get(n)===1/0)return null;const y=[];let d=0,x=1/0,f="active",p=n;for(;p&&c.get(p);){const _=c.get(p);y.unshift(_.connection.id),d+=_.connection.latency??0,_.connection.bandwidth!==void 0&&(x=Math.min(x,_.connection.bandwidth)),_.connection.status==="error"?f="error":_.connection.status==="degraded"&&f!=="error"?f="degraded":_.connection.status==="inactive"&&f==="active"&&(f="inactive"),p=_.deviceId}return{id:`path-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,startDeviceId:s,endDeviceId:n,connectionIds:y,totalLatency:d,bottleneckBandwidth:x===1/0?0:x,status:f,isPrimary:!0}}function co(t,s,n,o=5){const a=[],i=ws(t);function c(r,l,y,d){if(a.length>=o)return;if(r===l&&d.length>0){let f=0,p=1/0,_="active";for(const j of d)f+=j.latency??0,j.bandwidth!==void 0&&(p=Math.min(p,j.bandwidth)),j.status==="error"?_="error":j.status==="degraded"&&_!=="error"&&(_="degraded");a.push({id:`path-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,startDeviceId:s,endDeviceId:n,connectionIds:d.map(j=>j.id),totalLatency:f,bottleneckBandwidth:p===1/0?0:p,status:_,isPrimary:a.length===0});return}y.add(r);const x=i.get(r)??[];for(const f of x)y.has(f.deviceId)||c(f.deviceId,l,new Set(y),[...d,f.connection])}return c(s,n,new Set,[]),a}function lo(t){var l,y;const s=[],n=t.split(/\r?\n/);let o=0,a=!1,i=null,c=[],r=null;for(;o<n.length;){const d=parseInt(((l=n[o])==null?void 0:l.trim())??"",10),x=((y=n[o+1])==null?void 0:y.trim())??"";if(o+=2,d===2&&x==="ENTITIES"){a=!0;continue}if(d===0&&x==="ENDSEC"&&a){i!=null&&i.type&&(c.length>0&&(i.vertices=[...c]),s.push(i)),a=!1;continue}if(a){if(d===0){i!=null&&i.type&&(c.length>0&&(i.vertices=[...c]),s.push(i)),i={type:x,layer:"0"},c=[],r=null;continue}if(i)switch(d){case 8:i.layer=x;break;case 5:i.handle=x;break;case 10:r=parseFloat(x);break;case 20:r!==null&&(c.push({x:r,y:parseFloat(x)}),i.position||(i.position={x:r,y:parseFloat(x)}),r=null);break;case 11:r=parseFloat(x);break;case 21:r!==null&&(c.push({x:r,y:parseFloat(x)}),r=null);break;case 40:(i.type==="CIRCLE"||i.type==="ARC")&&(i.radius=parseFloat(x));break;case 50:i.startAngle=parseFloat(x);break;case 51:i.endAngle=parseFloat(x);break;case 1:i.text=x;break;case 2:i.blockName=x;break;case 70:parseInt(x,10)&1&&(i.closed=!0);break}}}return s}function uo(t,s={}){var r,l;const n=Date.now(),o=[],a=[],i=s.scaleFactor??1,c=s.originOffset??{x:0,y:0};try{const y=lo(t),d=[],x=[],f=[],p=new Set;let _=0;for(const h of y){if(p.add(h.layer),s.includeLayers&&!s.includeLayers.includes(h.layer)){_++;continue}if((r=s.excludeLayers)!=null&&r.includes(h.layer)){_++;continue}const k=((l=s.layerMappings)==null?void 0:l[h.layer])??h.layer;switch(h.type){case"LINE":if(h.vertices&&h.vertices.length>=2){const C=xe(h.vertices[0],i,c),T=xe(h.vertices[1],i,c);d.push({start:C,end:T,layer:k})}break;case"LWPOLYLINE":case"POLYLINE":if(h.vertices&&h.vertices.length>=2){const C=h.vertices.map(b=>xe(b,i,c));if(h.closed&&s.convertClosedPolylinesToZones){const b=Ns(C),L=s.minZoneArea??.1;if(b>=L){x.push({name:k,boundary:C,layer:k});continue}}const T=h.closed?C.length:C.length-1;for(let b=0;b<T;b++){const L=C[b],u=C[(b+1)%C.length];d.push({start:L,end:u,layer:k})}}break;case"CIRCLE":if(h.position&&h.radius){const C=xe(h.position,i,c);f.push({type:"circle",position:C,layer:k,metadata:{radius:h.radius*i}})}break;case"INSERT":if(h.position&&h.blockName){const C=xe(h.position,i,c);f.push({type:"block-reference",position:C,layer:k,metadata:{blockName:h.blockName}})}break;default:_++,o.push({code:"UNSUPPORTED_ENTITY",message:`Unsupported DXF entity type: ${h.type}`,context:{type:h.type,layer:h.layer}})}}return{success:!0,document:kt(d,x,f,p,{name:"Imported DXF",sourceFormat:"dxf",units:s.defaultUnits??"metric"}),warnings:o,errors:a,stats:{wallsImported:d.length,zonesImported:x.length,objectsImported:f.length,layersFound:p.size,entitiesSkipped:_,importTimeMs:Date.now()-n}}}catch(y){return a.push({code:"PARSE_ERROR",message:y instanceof Error?y.message:"Unknown error parsing DXF",fatal:!0}),{success:!1,warnings:o,errors:a,stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:Date.now()-n}}}}function mo(t){const s=[];let n=[],o=0,a=0,i=0,c=0;const r=t.match(/[MmLlHhVvCcSsQqTtAaZz]|[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[];let l=0;for(;l<r.length;){const y=r[l];l++;const d=()=>{const x=parseFloat(r[l]??"0");return l++,x};switch(y){case"M":n.length>0&&(s.push(n),n=[]),o=d(),a=d(),i=o,c=a,n.push({x:o,y:a});break;case"m":n.length>0&&(s.push(n),n=[]),o+=d(),a+=d(),i=o,c=a,n.push({x:o,y:a});break;case"L":o=d(),a=d(),n.push({x:o,y:a});break;case"l":o+=d(),a+=d(),n.push({x:o,y:a});break;case"H":o=d(),n.push({x:o,y:a});break;case"h":o+=d(),n.push({x:o,y:a});break;case"V":a=d(),n.push({x:o,y:a});break;case"v":a+=d(),n.push({x:o,y:a});break;case"Z":case"z":n.length>0&&n.push({x:i,y:c}),o=i,a=c;break;case"C":d(),d(),d(),d(),o=d(),a=d(),n.push({x:o,y:a});break;case"c":d(),d(),d(),d(),o+=d(),a+=d(),n.push({x:o,y:a});break;case"Q":d(),d(),o=d(),a=d(),n.push({x:o,y:a});break;case"q":d(),d(),o+=d(),a+=d(),n.push({x:o,y:a});break}}return n.length>0&&s.push(n),s}function ho(t){let s=0,n=0,o=1;const a=t.match(/translate\s*\(\s*([-\d.]+)(?:\s*,?\s*([-\d.]+))?\s*\)/);a&&(s=parseFloat(a[1]),n=parseFloat(a[2]??"0"));const i=t.match(/scale\s*\(\s*([-\d.]+)(?:\s*,?\s*([-\d.]+))?\s*\)/);return i&&(o=parseFloat(i[1])),{translate:{x:s,y:n},scale:o}}function po(t,s={}){const n=Date.now(),o=[],a=[],i=s.scaleFactor??1,c=s.originOffset??{x:0,y:0};try{const r=[],l=[],y=[],d=new Set,x=/<path[^>]*\bd="([^"]+)"[^>]*>/gi;let f;for(;(f=x.exec(t))!==null;){const b=f[1],L=f[0],u=L.match(/\bid="([^"]+)"/),v=(u==null?void 0:u[1])??"default";d.add(v);const g=L.match(/\btransform="([^"]+)"/),q=g?ho(g[1]):{translate:{x:0,y:0},scale:1},I=mo(b);for(const B of I){if(B.length<2)continue;const V=B.map(ue=>xe({x:ue.x*q.scale+q.translate.x,y:ue.y*q.scale+q.translate.y},i,c));if(Math.abs(V[0].x-V[V.length-1].x)<.1&&Math.abs(V[0].y-V[V.length-1].y)<.1&&s.convertClosedPolylinesToZones&&Ns(V)>=(s.minZoneArea??.1)){l.push({name:v,boundary:V,layer:v});continue}for(let ue=0;ue<V.length-1;ue++)r.push({start:V[ue],end:V[ue+1],layer:v})}}const p=/<line[^>]*\bx1="([^"]+)"[^>]*\by1="([^"]+)"[^>]*\bx2="([^"]+)"[^>]*\by2="([^"]+)"[^>]*>/gi;let _;for(;(_=p.exec(t))!==null;){const b=parseFloat(_[1]),L=parseFloat(_[2]),u=parseFloat(_[3]),v=parseFloat(_[4]),g=xe({x:b,y:L},i,c),q=xe({x:u,y:v},i,c);r.push({start:g,end:q,layer:"default"}),d.add("default")}const j=/<rect[^>]*\bx="([^"]+)"[^>]*\by="([^"]+)"[^>]*\bwidth="([^"]+)"[^>]*\bheight="([^"]+)"[^>]*>/gi;let h;for(;(h=j.exec(t))!==null;){const b=parseFloat(h[1]),L=parseFloat(h[2]),u=parseFloat(h[3]),v=parseFloat(h[4]),g=[xe({x:b,y:L},i,c),xe({x:b+u,y:L},i,c),xe({x:b+u,y:L+v},i,c),xe({x:b,y:L+v},i,c)];s.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"})),d.add("default")}const k=/<circle[^>]*\bcx="([^"]+)"[^>]*\bcy="([^"]+)"[^>]*\br="([^"]+)"[^>]*>/gi;let C;for(;(C=k.exec(t))!==null;){const b=parseFloat(C[1]),L=parseFloat(C[2]),u=parseFloat(C[3]),v=xe({x:b,y:L},i,c);y.push({type:"circle",position:v,layer:"default",metadata:{radius:u*i}}),d.add("default")}return{success:!0,document:kt(r,l,y,d,{name:"Imported SVG",sourceFormat:"svg",units:s.defaultUnits??"metric"}),warnings:o,errors:a,stats:{wallsImported:r.length,zonesImported:l.length,objectsImported:y.length,layersFound:d.size,entitiesSkipped:0,importTimeMs:Date.now()-n}}}catch(r){return a.push({code:"PARSE_ERROR",message:r instanceof Error?r.message:"Unknown error parsing SVG",fatal:!0}),{success:!1,warnings:o,errors:a,stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:Date.now()-n}}}}function fo(t,s={}){var r;const n=Date.now(),o=[],a=[],i=s.scaleFactor??1,c=s.originOffset??{x:0,y:0};try{const l=JSON.parse(t),y=[],d=[],x=[],f=new Set;let p=0;const _=l.type==="FeatureCollection"?l.features:[l];for(const h of _){const k=((r=h.properties)==null?void 0:r.layer)??"default";f.add(k);const C=h.geometry;switch(C.type){case"Point":{const T=C.coordinates,b=xe({x:T[0],y:T[1]},i,c);x.push({type:"marker",position:b,layer:k,metadata:{properties:h.properties}});break}case"LineString":{const T=C.coordinates;for(let b=0;b<T.length-1;b++){const L=xe({x:T[b][0],y:T[b][1]},i,c),u=xe({x:T[b+1][0],y:T[b+1][1]},i,c);y.push({start:L,end:u,layer:k})}break}case"MultiLineString":{const T=C.coordinates;for(const b of T)for(let L=0;L<b.length-1;L++){const u=xe({x:b[L][0],y:b[L][1]},i,c),v=xe({x:b[L+1][0],y:b[L+1][1]},i,c);y.push({start:u,end:v,layer:k})}break}case"Polygon":{const L=C.coordinates[0].map(u=>xe({x:u[0],y:u[1]},i,c));d.push({name:k,boundary:L,layer:k});break}case"MultiPolygon":{const T=C.coordinates;for(const b of T){const u=b[0].map(v=>xe({x:v[0],y:v[1]},i,c));d.push({name:k,boundary:u,layer:k})}break}default:p++,o.push({code:"UNSUPPORTED_GEOMETRY",message:`Unsupported GeoJSON geometry: ${C.type}`})}}return{success:!0,document:kt(y,d,x,f,{name:"Imported GeoJSON",sourceFormat:"geojson",units:s.defaultUnits??"metric"}),warnings:o,errors:a,stats:{wallsImported:y.length,zonesImported:d.length,objectsImported:x.length,layersFound:f.size,entitiesSkipped:p,importTimeMs:Date.now()-n}}}catch(l){return a.push({code:"PARSE_ERROR",message:l instanceof Error?l.message:"Unknown error parsing GeoJSON",fatal:!0}),{success:!1,warnings:o,errors:a,stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:Date.now()-n}}}}function _o(t,s={}){const n=Date.now(),o=[],a=[];o.push({code:"LIMITED_IFC_SUPPORT",message:"IFC import is limited. For full support, use a dedicated IFC library like web-ifc."});try{const i=[],c=[],r=[],l=new Set;let y=0;const d=t.split(/\r?\n/),x=new Map;for(const p of d){const _=p.match(/^#(\d+)\s*=\s*(\w+)\s*\((.+)\)\s*;?$/);_&&x.set(`#${_[1]}`,{type:_[2],params:_[3]})}for(const[p,_]of x)if(_.type==="IFCWALLSTANDARDCASE"||_.type==="IFCWALL"){l.add("Walls");const j=_.params.match(/'([^']+)'/),h=(j==null?void 0:j[1])??"Wall";o.push({code:"IFC_WALL_SIMPLIFIED",message:`Wall "${h}" (${p}) geometry simplified to placeholder`}),y++}else if(_.type==="IFCSPACE"){l.add("Spaces");const j=_.params.match(/'([^']+)'/),h=(j==null?void 0:j[1])??"Space";o.push({code:"IFC_SPACE_SIMPLIFIED",message:`Space "${h}" (${p}) geometry simplified to placeholder`}),y++}return{success:!0,document:kt(i,c,r,l,{name:"Imported IFC",sourceFormat:"ifc",units:s.defaultUnits??"metric"}),warnings:o,errors:a,stats:{wallsImported:i.length,zonesImported:c.length,objectsImported:r.length,layersFound:l.size,entitiesSkipped:y,importTimeMs:Date.now()-n}}}catch(i){return a.push({code:"PARSE_ERROR",message:i instanceof Error?i.message:"Unknown error parsing IFC",fatal:!0}),{success:!1,warnings:o,errors:a,stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:Date.now()-n}}}}function go(t,s,n={}){switch(s){case"dxf":return uo(t,n);case"svg":return po(t,n);case"geojson":return fo(t,n);case"ifc":return _o(t,n);default:return{success:!1,warnings:[],errors:[{code:"UNSUPPORTED_FORMAT",message:`Unsupported import format: ${s}`,fatal:!0}],stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:0}}}}function yo(t,s){const n=t.toLowerCase().split(".").pop();switch(n){case"dxf":return"dxf";case"svg":return"svg";case"geojson":case"json":return s!=null&&s.includes('"type"')&&(s.includes('"Feature"')||s.includes('"FeatureCollection"'))||n==="geojson"?"geojson":null;case"ifc":return"ifc";default:if(s){if(s.includes("ISO-10303-21")||s.includes("IFCPROJECT"))return"ifc";if(s.includes("<?xml")&&s.includes("<svg"))return"svg";if(s.includes("SECTION")&&s.includes("ENTITIES"))return"dxf"}return null}}async function bo(t,s={}){return new Promise(n=>{const o=new FileReader;o.onload=()=>{const a=o.result,i=s.format??yo(t.name,a);if(!i){n({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}n(go(a,i,s))},o.onerror=()=>{n({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 Ze(){return`${Date.now()}-${Math.random().toString(36).slice(2,9)}`}function xe(t,s,n){return{x:t.x*s+n.x,y:t.y*s+n.y}}function Ns(t){let s=0;const n=t.length;for(let o=0;o<n;o++){const a=(o+1)%n;s+=t[o].x*t[a].y,s-=t[a].x*t[o].y}return Math.abs(s/2)}function Jt(t){if(t.length===0)return{x:0,y:0,width:0,height:0};let s=1/0,n=1/0,o=-1/0,a=-1/0;for(const i of t)i.x<s&&(s=i.x),i.y<n&&(n=i.y),i.x>o&&(o=i.x),i.y>a&&(a=i.y);return{x:s,y:n,width:o-s,height:a-n}}function Qt(t){let s=0;for(let o=0;o<t.length;o++)s=t.charCodeAt(o)+((s<<5)-s);return`hsl(${Math.abs(s)%360}, 60%, 50%)`}function es(t){return{position:t,rotation:0,scale:{x:1,y:1}}}function kt(t,s,n,o,a){const i=new Date().toISOString(),c=`floor-${Ze()}`,r=[];for(const j of t)r.push(j.start,j.end);for(const j of s)r.push(...j.boundary);for(const j of n)r.push(j.position);const l=Jt(r),y=t.map(j=>({id:`wall-${Ze()}`,type:"wall",category:"building",name:"Wall",transform:es(j.start),bounds:Jt([j.start,j.end]),layer:j.layer,locked:!1,visible:!0,metadata:{end:j.end,thickness:j.thickness??.15,importedAt:i},childIds:[]})),d=n.map(j=>({id:`obj-${Ze()}`,type:j.type,category:"annotation",name:j.type,transform:es(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:i},childIds:[]})),x=Array.from(o).map(j=>({id:`layer-${Ze()}`,name:j,type:j.toLowerCase().includes("wall")?"walls":"custom",visible:!0,locked:!1,opacity:1,color:Qt(j),objects:[...y.filter(h=>h.layer===j),...d.filter(h=>h.layer===j)]})),f={id:c,name:"Imported Floor",level:0,elevation:0,ceilingHeight:2.7,bounds:l,layers:x},p=s.map(j=>({id:`zone-${Ze()}`,name:j.name,type:"custom",boundary:j.boundary,floorId:c,roomIds:[],color:Qt(j.name)})),_={$schema:"https://nice2dev.com/schemas/nsp-v1.json",version:"1.0.0",type:"floor-plan",metadata:{id:`doc-${Ze()}`,name:a.name,description:`Imported from ${a.sourceFormat.toUpperCase()}`,created:i,modified:i,tags:["imported",a.sourceFormat]},floors:[f],settings:{units:a.units,scale:50,grid:{visible:!0,size:.5,snapEnabled:!0},defaultWallHeight:2.7,defaultWallThickness:.15,precision:2}};return _.zones=p,_}const xo=10,vo=8;class jo{constructor(s,n=xo){ut(this,"root");ut(this,"maxItems");ut(this,"itemMap",new Map);this.root={bounds:s,items:[],children:null},this.maxItems=n}insert(s){this.itemMap.set(s.id,s),this.insertIntoNode(this.root,s,0)}remove(s){const n=this.itemMap.get(s);return n?(this.itemMap.delete(s),this.removeFromNode(this.root,n)):!1}update(s,n){const o=this.itemMap.get(s);return o?(this.remove(s),o.bounds=n,this.insert(o),!0):!1}query(s){const n=[];return this.queryNode(this.root,s,n),n}getAll(){return Array.from(this.itemMap.values())}get(s){return this.itemMap.get(s)}get size(){return this.itemMap.size}clear(){this.itemMap.clear(),this.root.items=[],this.root.children=null}rebuild(){const s=Array.from(this.itemMap.values());this.root.items=[],this.root.children=null;for(const n of s)this.insertIntoNode(this.root,n,0)}insertIntoNode(s,n,o){if(s.children){const a=this.getChildIndex(s,n.bounds);if(a!==-1){this.insertIntoNode(s.children[a],n,o+1);return}s.items.push(n);return}if(s.items.push(n),s.items.length>this.maxItems&&o<vo){this.split(s);const a=[...s.items];s.items=[];for(const i of a)this.insertIntoNode(s,i,o)}}removeFromNode(s,n){const o=s.items.findIndex(a=>a.id===n.id);if(o!==-1)return s.items.splice(o,1),!0;if(s.children){for(const a of s.children)if(this.boundsIntersect(a.bounds,n.bounds)&&this.removeFromNode(a,n))return!0}return!1}queryNode(s,n,o){for(const a of s.items)this.boundsIntersect(a.bounds,n)&&o.push(a);if(s.children)for(const a of s.children)this.boundsIntersect(a.bounds,n)&&this.queryNode(a,n,o)}split(s){const{x:n,y:o,width:a,height:i}=s.bounds,c=a/2,r=i/2;s.children=[{bounds:{x:n,y:o,width:c,height:r},items:[],children:null},{bounds:{x:n+c,y:o,width:c,height:r},items:[],children:null},{bounds:{x:n,y:o+r,width:c,height:r},items:[],children:null},{bounds:{x:n+c,y:o+r,width:c,height:r},items:[],children:null}]}getChildIndex(s,n){if(!s.children)return-1;const o=s.bounds.x+s.bounds.width/2,a=s.bounds.y+s.bounds.height/2,i=n.x+n.width<=o,c=n.x>=o,r=n.y+n.height<=a,l=n.y>=a;return r&&i?0:r&&c?1:l&&i?2:l&&c?3:-1}boundsIntersect(s,n){return s.x<n.x+n.width&&s.x+s.width>n.x&&s.y<n.y+n.height&&s.y+s.height>n.y}}function wo(t,s=100){let n=1/0,o=1/0,a=-1/0,i=-1/0;for(const l of t){const{x:y,y:d}=l.position,{width:x=20,height:f=20}=l.size??{};n=Math.min(n,y-x/2),o=Math.min(o,d-f/2),a=Math.max(a,y+x/2),i=Math.max(i,d+f/2)}Number.isFinite(n)||(n=o=0,a=i=1e3);const c={x:n-s,y:o-s,width:a-n+s*2,height:i-o+s*2},r=new jo(c);for(const l of t){const{x:y,y:d}=l.position,{width:x=20,height:f=20}=l.size??{};r.insert({id:l.id,bounds:{x:y-x/2,y:d-f/2,width:x,height:f},data:l.data})}return r}function No(t,s,n=100){const o=(s.width+n*2)/t.zoom,a=(s.height+n*2)/t.zoom,i=(-t.pan.x-n)/t.zoom,c=(-t.pan.y-n)/t.zoom;return{x:i,y:c,width:o,height:a}}function ko(t,s=200){return t>=s}function Io(t,s,n){const o=t-s;return{total:t,visible:s,culled:o,cullPercentage:t>0?Math.round(o/t*100):0,zoom:n.zoom}}const Co="_overlay_1x0xg_9",So="_dialog_1x0xg_55",Lo="_header_1x0xg_103",To="_title_1x0xg_119",$o="_closeButton_1x0xg_133",zo="_content_1x0xg_167",Mo="_preview_1x0xg_183",Bo="_previewCanvas_1x0xg_203",Eo="_previewSvg_1x0xg_221",Po="_info_1x0xg_231",Ao="_section_1x0xg_241",Oo="_sectionTitle_1x0xg_249",Do="_statGrid_1x0xg_269",Ro="_stat_1x0xg_269",qo="_statLabel_1x0xg_293",Fo="_statValue_1x0xg_305",Go="_warningsList_1x0xg_317",Wo="_warning_1x0xg_317",Vo="_warningIcon_1x0xg_361",Ho="_error_1x0xg_371",Uo="_errorIcon_1x0xg_403",Yo="_footer_1x0xg_413",Zo="_cancelButton_1x0xg_433",Xo="_confirmButton_1x0xg_465",Ko="_noWarnings_1x0xg_507",Jo="_layersList_1x0xg_519",Qo="_layer_1x0xg_519",ea="_layerIcon_1x0xg_561",ta="_layerName_1x0xg_569",sa="_layerCount_1x0xg_579",U={overlay:Co,dialog:So,header:Lo,title:To,closeButton:$o,content:zo,preview:Mo,previewCanvas:Bo,previewSvg:Eo,info:Po,section:Ao,sectionTitle:Oo,statGrid:Do,stat:Ro,statLabel:qo,statValue:Fo,warningsList:Go,warning:Wo,warningIcon:Vo,error:Ho,errorIcon:Uo,footer:Yo,cancelButton:Zo,confirmButton:Xo,noWarnings:Ko,layersList:Jo,layer:Qo,layerIcon:ea,layerName:ta,layerCount:sa},na=()=>e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M15 5L5 15M5 5L15 15",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})}),ts=()=>e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"currentColor",children:e.jsx("path",{d:"M7 0a7 7 0 1 0 0 14A7 7 0 0 0 7 0zm0 12.5a.75.75 0 1 1 0-1.5.75.75 0 0 1 0 1.5zm.75-3.25a.75.75 0 0 1-1.5 0v-4a.75.75 0 0 1 1.5 0v4z"})}),ss=()=>e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"currentColor",children:e.jsx("path",{d:"M7 0a7 7 0 1 0 0 14A7 7 0 0 0 7 0zm2.8 9.15a.5.5 0 0 1-.65.65L7 8.45l-2.15 1.35a.5.5 0 0 1-.65-.65L5.55 7 4.2 4.85a.5.5 0 0 1 .65-.65L7 5.55l2.15-1.35a.5.5 0 0 1 .65.65L8.45 7l1.35 2.15z"})}),ns=()=>e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"currentColor",children:e.jsx("path",{d:"M6 0L0 3l6 3 6-3-6-3zM0 6l6 3 6-3M0 9l6 3 6-3",fill:"none",stroke:"currentColor",strokeWidth:"1.2"})}),oa=()=>e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"currentColor",children:e.jsx("path",{d:"M2 12h2V5H2v7zm4 0h2V2H6v10zm4 0h2V7h-2v5z"})});function aa({result:t,onConfirm:s,onCancel:n}){const o=t.document,a=m.useMemo(()=>{var C,T;if(!((C=o==null?void 0:o.floors)!=null&&C.length))return null;const d=o.floors[0],x=(d==null?void 0:d.layers)||[],f=x.flatMap(b=>b.objects);let p=1/0,_=1/0,j=-1/0,h=-1/0;for(const b of f)b.bounds?(p=Math.min(p,b.bounds.x),_=Math.min(_,b.bounds.y),j=Math.max(j,b.bounds.x+b.bounds.width),h=Math.max(h,b.bounds.y+b.bounds.height)):(T=b.transform)!=null&&T.position&&(p=Math.min(p,b.transform.position.x),_=Math.min(_,b.transform.position.y),j=Math.max(j,b.transform.position.x),h=Math.max(h,b.transform.position.y));isFinite(p)||(d!=null&&d.bounds?(p=d.bounds.x,_=d.bounds.y,j=d.bounds.x+d.bounds.width,h=d.bounds.y+d.bounds.height):(p=0,_=0,j=1e3,h=800));const k=20;return{viewBox:{x:p-k,y:_-k,width:j-p+k*2,height:h-_+k*2},objects:f,layers:x}},[o]),i=m.useMemo(()=>{if(!a||!o)return null;const{viewBox:d,objects:x}=a,f=[],p=50,_=`
|
|
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 b of l.boundary)n=Math.min(n,b.x),s=Math.min(s,b.y),o=Math.max(o,b.x),i=Math.max(i,b.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 ao(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 Nn(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 ht(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 io(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,b)=>{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 x=v.getContext("2d");if(!x){b(new Error("Could not get canvas context"));return}x.fillStyle=i,x.fillRect(0,0,v.width,v.height),x.scale(h,h),x.drawImage(m,0,0),v.toBlob(p=>{if(URL.revokeObjectURL(r),!p){b(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),b(new Error("Failed to load SVG for PNG export"))},m.src=r})}function wn(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 ro(t,n,s,o="latency"){const i=wn(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((g,I)=>g.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 g of j){if(r.has(g.deviceId))continue;let I;switch(o){case"latency":I=g.connection.latency??1;break;case"hops":I=1;break;case"bandwidth":I=1/(g.connection.bandwidth??1);break}const y=a.get(p.deviceId)+I;y<a.get(g.deviceId)&&(a.set(g.deviceId,y),c.set(g.deviceId,{deviceId:p.deviceId,connection:g.connection}),l.push({deviceId:g.deviceId,distance:y}))}}if(!c.has(s)||a.get(s)===1/0)return null;const b=[];let m=0,h=1/0,v="active",x=s;for(;x&&c.get(x);){const p=c.get(x);b.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"),x=p.deviceId}return{id:`path-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,startDeviceId:n,endDeviceId:s,connectionIds:b,totalLatency:m,bottleneckBandwidth:h===1/0?0:h,status:v,isPrimary:!0}}function co(t,n,s,o=5){const i=[],a=wn(t);function c(r,l,b,m){if(i.length>=o)return;if(r===l&&m.length>0){let v=0,x=1/0,p="active";for(const j of m)v+=j.latency??0,j.bandwidth!==void 0&&(x=Math.min(x,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:x===1/0?0:x,status:p,isPrimary:i.length===0});return}b.add(r);const h=a.get(r)??[];for(const v of h)b.has(v.deviceId)||c(v.deviceId,l,new Set(b),[...m,v.connection])}return c(n,s,new Set,[]),i}function lo(t){var l,b;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=((b=s[o+1])==null?void 0:b.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 uo(t,n={}){var r,l;const s=Date.now(),o=[],i=[],a=n.scaleFactor??1,c=n.originOffset??{x:0,y:0};try{const b=lo(t),m=[],h=[],v=[],x=new Set;let p=0;for(const g of b){if(x.add(g.layer),n.includeLayers&&!n.includeLayers.includes(g.layer)){p++;continue}if((r=n.excludeLayers)!=null&&r.includes(g.layer)){p++;continue}const I=((l=n.layerMappings)==null?void 0:l[g.layer])??g.layer;switch(g.type){case"LINE":if(g.vertices&&g.vertices.length>=2){const y=xe(g.vertices[0],a,c),L=xe(g.vertices[1],a,c);m.push({start:y,end:L,layer:I})}break;case"LWPOLYLINE":case"POLYLINE":if(g.vertices&&g.vertices.length>=2){const y=g.vertices.map(_=>xe(_,a,c));if(g.closed&&n.convertClosedPolylinesToZones){const _=In(y),C=n.minZoneArea??.1;if(_>=C){h.push({name:I,boundary:y,layer:I});continue}}const L=g.closed?y.length:y.length-1;for(let _=0;_<L;_++){const C=y[_],d=y[(_+1)%y.length];m.push({start:C,end:d,layer:I})}}break;case"CIRCLE":if(g.position&&g.radius){const y=xe(g.position,a,c);v.push({type:"circle",position:y,layer:I,metadata:{radius:g.radius*a}})}break;case"INSERT":if(g.position&&g.blockName){const y=xe(g.position,a,c);v.push({type:"block-reference",position:y,layer:I,metadata:{blockName:g.blockName}})}break;default:p++,o.push({code:"UNSUPPORTED_ENTITY",message:`Unsupported DXF entity type: ${g.type}`,context:{type:g.type,layer:g.layer}})}}return{success:!0,document:It(m,h,v,x,{name:"Imported DXF",sourceFormat:"dxf",units:n.defaultUnits??"metric"}),warnings:o,errors:i,stats:{wallsImported:m.length,zonesImported:h.length,objectsImported:v.length,layersFound:x.size,entitiesSkipped:p,importTimeMs:Date.now()-s}}}catch(b){return i.push({code:"PARSE_ERROR",message:b instanceof Error?b.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 mo(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 b=r[l];l++;const m=()=>{const h=parseFloat(r[l]??"0");return l++,h};switch(b){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 po(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 ho(t,n={}){const s=Date.now(),o=[],i=[],a=n.scaleFactor??1,c=n.originOffset??{x:0,y:0};try{const r=[],l=[],b=[],m=new Set,h=/<path[^>]*\bd="([^"]+)"[^>]*>/gi;let v;for(;(v=h.exec(t))!==null;){const _=v[1],C=v[0],d=C.match(/\bid="([^"]+)"/),w=(d==null?void 0:d[1])??"default";m.add(w);const f=C.match(/\btransform="([^"]+)"/),q=f?po(f[1]):{translate:{x:0,y:0},scale:1},T=mo(_);for(const M of T){if(M.length<2)continue;const W=M.map(ue=>xe({x:ue.x*q.scale+q.translate.x,y:ue.y*q.scale+q.translate.y},a,c));if(Math.abs(W[0].x-W[W.length-1].x)<.1&&Math.abs(W[0].y-W[W.length-1].y)<.1&&n.convertClosedPolylinesToZones&&In(W)>=(n.minZoneArea??.1)){l.push({name:w,boundary:W,layer:w});continue}for(let ue=0;ue<W.length-1;ue++)r.push({start:W[ue],end:W[ue+1],layer:w})}}const x=/<line[^>]*\bx1="([^"]+)"[^>]*\by1="([^"]+)"[^>]*\bx2="([^"]+)"[^>]*\by2="([^"]+)"[^>]*>/gi;let p;for(;(p=x.exec(t))!==null;){const _=parseFloat(p[1]),C=parseFloat(p[2]),d=parseFloat(p[3]),w=parseFloat(p[4]),f=xe({x:_,y:C},a,c),q=xe({x:d,y:w},a,c);r.push({start:f,end:q,layer:"default"}),m.add("default")}const j=/<rect[^>]*\bx="([^"]+)"[^>]*\by="([^"]+)"[^>]*\bwidth="([^"]+)"[^>]*\bheight="([^"]+)"[^>]*>/gi;let g;for(;(g=j.exec(t))!==null;){const _=parseFloat(g[1]),C=parseFloat(g[2]),d=parseFloat(g[3]),w=parseFloat(g[4]),f=[xe({x:_,y:C},a,c),xe({x:_+d,y:C},a,c),xe({x:_+d,y:C+w},a,c),xe({x:_,y:C+w},a,c)];n.convertClosedPolylinesToZones?l.push({name:"rect",boundary:f,layer:"default"}):(r.push({start:f[0],end:f[1],layer:"default"}),r.push({start:f[1],end:f[2],layer:"default"}),r.push({start:f[2],end:f[3],layer:"default"}),r.push({start:f[3],end:f[0],layer:"default"})),m.add("default")}const I=/<circle[^>]*\bcx="([^"]+)"[^>]*\bcy="([^"]+)"[^>]*\br="([^"]+)"[^>]*>/gi;let y;for(;(y=I.exec(t))!==null;){const _=parseFloat(y[1]),C=parseFloat(y[2]),d=parseFloat(y[3]),w=xe({x:_,y:C},a,c);b.push({type:"circle",position:w,layer:"default",metadata:{radius:d*a}}),m.add("default")}return{success:!0,document:It(r,l,b,m,{name:"Imported SVG",sourceFormat:"svg",units:n.defaultUnits??"metric"}),warnings:o,errors:i,stats:{wallsImported:r.length,zonesImported:l.length,objectsImported:b.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 go(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),b=[],m=[],h=[],v=new Set;let x=0;const p=l.type==="FeatureCollection"?l.features:[l];for(const g of p){const I=((r=g.properties)==null?void 0:r.layer)??"default";v.add(I);const y=g.geometry;switch(y.type){case"Point":{const L=y.coordinates,_=xe({x:L[0],y:L[1]},a,c);h.push({type:"marker",position:_,layer:I,metadata:{properties:g.properties}});break}case"LineString":{const L=y.coordinates;for(let _=0;_<L.length-1;_++){const C=xe({x:L[_][0],y:L[_][1]},a,c),d=xe({x:L[_+1][0],y:L[_+1][1]},a,c);b.push({start:C,end:d,layer:I})}break}case"MultiLineString":{const L=y.coordinates;for(const _ of L)for(let C=0;C<_.length-1;C++){const d=xe({x:_[C][0],y:_[C][1]},a,c),w=xe({x:_[C+1][0],y:_[C+1][1]},a,c);b.push({start:d,end:w,layer:I})}break}case"Polygon":{const C=y.coordinates[0].map(d=>xe({x:d[0],y:d[1]},a,c));m.push({name:I,boundary:C,layer:I});break}case"MultiPolygon":{const L=y.coordinates;for(const _ of L){const d=_[0].map(w=>xe({x:w[0],y:w[1]},a,c));m.push({name:I,boundary:d,layer:I})}break}default:x++,o.push({code:"UNSUPPORTED_GEOMETRY",message:`Unsupported GeoJSON geometry: ${y.type}`})}}return{success:!0,document:It(b,m,h,v,{name:"Imported GeoJSON",sourceFormat:"geojson",units:n.defaultUnits??"metric"}),warnings:o,errors:i,stats:{wallsImported:b.length,zonesImported:m.length,objectsImported:h.length,layersFound:v.size,entitiesSkipped:x,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 _o(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 b=0;const m=t.split(/\r?\n/),h=new Map;for(const x of m){const p=x.match(/^#(\d+)\s*=\s*(\w+)\s*\((.+)\)\s*;?$/);p&&h.set(`#${p[1]}`,{type:p[2],params:p[3]})}for(const[x,p]of h)if(p.type==="IFCWALLSTANDARDCASE"||p.type==="IFCWALL"){l.add("Walls");const j=p.params.match(/'([^']+)'/),g=(j==null?void 0:j[1])??"Wall";o.push({code:"IFC_WALL_SIMPLIFIED",message:`Wall "${g}" (${x}) geometry simplified to placeholder`}),b++}else if(p.type==="IFCSPACE"){l.add("Spaces");const j=p.params.match(/'([^']+)'/),g=(j==null?void 0:j[1])??"Space";o.push({code:"IFC_SPACE_SIMPLIFIED",message:`Space "${g}" (${x}) geometry simplified to placeholder`}),b++}return{success:!0,document:It(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:b,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 fo(t,n,s={}){switch(n){case"dxf":return uo(t,s);case"svg":return ho(t,s);case"geojson":return go(t,s);case"ifc":return _o(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 bo(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(fo(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 Ze(){return`${Date.now()}-${Math.random().toString(36).slice(2,9)}`}function xe(t,n,s){return{x:t.x*n+s.x,y:t.y*n+s.y}}function In(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 Jt(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 Qt(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 en(t){return{position:t,rotation:0,scale:{x:1,y:1}}}function It(t,n,s,o,i){const a=new Date().toISOString(),c=`floor-${Ze()}`,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=Jt(r),b=t.map(j=>({id:`wall-${Ze()}`,type:"wall",category:"building",name:"Wall",transform:en(j.start),bounds:Jt([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-${Ze()}`,type:j.type,category:"annotation",name:j.type,transform:en(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-${Ze()}`,name:j,type:j.toLowerCase().includes("wall")?"walls":"custom",visible:!0,locked:!1,opacity:1,color:Qt(j),objects:[...b.filter(g=>g.layer===j),...m.filter(g=>g.layer===j)]})),v={id:c,name:"Imported Floor",level:0,elevation:0,ceilingHeight:2.7,bounds:l,layers:h},x=n.map(j=>({id:`zone-${Ze()}`,name:j.name,type:"custom",boundary:j.boundary,floorId:c,roomIds:[],color:Qt(j.name)})),p={$schema:"https://nice2dev.com/schemas/nsp-v1.json",version:"1.0.0",type:"floor-plan",metadata:{id:`doc-${Ze()}`,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=x,p}const xo=10,vo=8;class jo{constructor(n,s=xo){ut(this,"root");ut(this,"maxItems");ut(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<vo){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 No(t,n=100){let s=1/0,o=1/0,i=-1/0,a=-1/0;for(const l of t){const{x:b,y:m}=l.position,{width:h=20,height:v=20}=l.size??{};s=Math.min(s,b-h/2),o=Math.min(o,m-v/2),i=Math.max(i,b+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:b,y:m}=l.position,{width:h=20,height:v=20}=l.size??{};r.insert({id:l.id,bounds:{x:b-h/2,y:m-v/2,width:h,height:v},data:l.data})}return r}function wo(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 Io(t,n=200){return t>=n}function ko(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 So="_overlay_1x0xg_9",Co="_dialog_1x0xg_55",To="_header_1x0xg_103",Lo="_title_1x0xg_119",$o="_closeButton_1x0xg_133",zo="_content_1x0xg_167",Po="_preview_1x0xg_183",Mo="_previewCanvas_1x0xg_203",Eo="_previewSvg_1x0xg_221",Oo="_info_1x0xg_231",Ao="_section_1x0xg_241",Bo="_sectionTitle_1x0xg_249",Do="_statGrid_1x0xg_269",Ro="_stat_1x0xg_269",qo="_statLabel_1x0xg_293",Fo="_statValue_1x0xg_305",Go="_warningsList_1x0xg_317",Vo="_warning_1x0xg_317",Wo="_warningIcon_1x0xg_361",Ho="_error_1x0xg_371",Uo="_errorIcon_1x0xg_403",Yo="_footer_1x0xg_413",Zo="_cancelButton_1x0xg_433",Xo="_confirmButton_1x0xg_465",Ko="_noWarnings_1x0xg_507",Jo="_layersList_1x0xg_519",Qo="_layer_1x0xg_519",ea="_layerIcon_1x0xg_561",ta="_layerName_1x0xg_569",na="_layerCount_1x0xg_579",U={overlay:So,dialog:Co,header:To,title:Lo,closeButton:$o,content:zo,preview:Po,previewCanvas:Mo,previewSvg:Eo,info:Oo,section:Ao,sectionTitle:Bo,statGrid:Do,stat:Ro,statLabel:qo,statValue:Fo,warningsList:Go,warning:Vo,warningIcon:Wo,error:Ho,errorIcon:Uo,footer:Yo,cancelButton:Zo,confirmButton:Xo,noWarnings:Ko,layersList:Jo,layer:Qo,layerIcon:ea,layerName:ta,layerCount:na},sa=()=>e.jsx(N.NiceIcon,{name:"close",size:20}),tn=()=>e.jsx(N.NiceIcon,{name:"warning",size:14}),nn=()=>e.jsx(N.NiceIcon,{name:"error",size:14}),sn=()=>e.jsx(N.NiceIcon,{name:"layers",size:12}),oa=()=>e.jsx(N.NiceIcon,{name:"bar-chart",size:14});function aa({result:t,onConfirm:n,onCancel:s}){const{t:o}=N.useNiceTranslation(),i=t.document,a=u.useMemo(()=>{var L,_;if(!((L=i==null?void 0:i.floors)!=null&&L.length))return null;const h=i.floors[0],v=(h==null?void 0:h.layers)||[],x=v.flatMap(C=>C.objects);let p=1/0,j=1/0,g=-1/0,I=-1/0;for(const C of x)C.bounds?(p=Math.min(p,C.bounds.x),j=Math.min(j,C.bounds.y),g=Math.max(g,C.bounds.x+C.bounds.width),I=Math.max(I,C.bounds.y+C.bounds.height)):(_=C.transform)!=null&&_.position&&(p=Math.min(p,C.transform.position.x),j=Math.min(j,C.transform.position.y),g=Math.max(g,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,g=h.bounds.x+h.bounds.width,I=h.bounds.y+h.bounds.height):(p=0,j=0,g=1e3,I=800));const y=20;return{viewBox:{x:p-y,y:j-y,width:g-p+y*2,height:I-j+y*2},objects:x,layers:v}},[i]),c=u.useMemo(()=>{if(!a||!i)return null;const{viewBox:h,objects:v}=a,x=[],p=50,j=`
|
|
136
136
|
<pattern id="grid" width="${p}" height="${p}" patternUnits="userSpaceOnUse">
|
|
137
137
|
<path d="M ${p} 0 L 0 0 0 ${p}" fill="none" stroke="var(--nice-border, #e2e8f0)" strokeWidth="0.5"/>
|
|
138
138
|
</pattern>
|
|
139
|
-
`,j=h=>h.boundary;return x.forEach((h,k)=>{const C=j(h);if(h.type==="wall"&&h.bounds)f.push(e.jsx("rect",{x:h.bounds.x,y:h.bounds.y,width:h.bounds.width,height:h.bounds.height,fill:"var(--nice-text-secondary, #475569)",stroke:"var(--nice-text, #334155)",strokeWidth:"1"},`wall-${k}`));else if(h.type==="zone"&&C){const T=C.map((b,L)=>`${L===0?"M":"L"} ${b.x} ${b.y}`).join(" ")+" Z";f.push(e.jsx("path",{d:T,fill:"var(--nice-primary-tint-20, rgba(59, 130, 246, 0.2))",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:"1"},`zone-${k}`))}else if(h.type==="room"&&C){const T=C.map((b,L)=>`${L===0?"M":"L"} ${b.x} ${b.y}`).join(" ")+" Z";f.push(e.jsx("path",{d:T,fill:"var(--nice-success-tint-15, rgba(34, 197, 94, 0.15))",stroke:"var(--nice-success, #22c55e)",strokeWidth:"1"},`room-${k}`))}else h.bounds&&f.push(e.jsx("rect",{x:h.bounds.x,y:h.bounds.y,width:h.bounds.width,height:h.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-${k}`))}),e.jsxs("svg",{viewBox:`${d.x} ${d.y} ${d.width} ${d.height}`,className:U.previewSvg,preserveAspectRatio:"xMidYMid meet",children:[e.jsx("defs",{dangerouslySetInnerHTML:{__html:_}}),e.jsx("rect",{x:d.x,y:d.y,width:d.width,height:d.height,fill:"url(#grid)"}),f]})},[a,o]),c=m.useCallback(d=>{d.key==="Escape"&&n()},[n]),r=m.useCallback(d=>{d.target===d.currentTarget&&n()},[n]),l=t.errors.some(d=>d.fatal),y=t.errors.filter(d=>!d.fatal);return e.jsx("div",{className:U.overlay,onClick:r,onKeyDown:c,tabIndex:-1,role:"dialog","aria-modal":"true","aria-labelledby":"import-preview-title",children:e.jsxs("div",{className:U.dialog,children:[e.jsxs("div",{className:U.header,children:[e.jsx("h2",{id:"import-preview-title",className:U.title,children:"Import Preview"}),e.jsx("button",{className:U.closeButton,onClick:n,title:"Close","aria-label":"Close dialog",children:e.jsx(na,{})})]}),e.jsxs("div",{className:U.content,children:[e.jsx("div",{className:U.preview,children:i||e.jsx("div",{className:U.previewCanvas,children:"No preview available"})}),e.jsxs("div",{className:U.info,children:[e.jsxs("div",{className:U.section,children:[e.jsxs("h3",{className:U.sectionTitle,children:[e.jsx(oa,{})," Import Statistics"]}),e.jsxs("div",{className:U.statGrid,children:[e.jsxs("div",{className:U.stat,children:[e.jsx("div",{className:U.statLabel,children:"Walls"}),e.jsx("div",{className:U.statValue,children:t.stats.wallsImported})]}),e.jsxs("div",{className:U.stat,children:[e.jsx("div",{className:U.statLabel,children:"Zones"}),e.jsx("div",{className:U.statValue,children:t.stats.zonesImported})]}),e.jsxs("div",{className:U.stat,children:[e.jsx("div",{className:U.statLabel,children:"Objects"}),e.jsx("div",{className:U.statValue,children:t.stats.objectsImported})]}),e.jsxs("div",{className:U.stat,children:[e.jsx("div",{className:U.statLabel,children:"Skipped"}),e.jsx("div",{className:U.statValue,children:t.stats.entitiesSkipped})]})]})]}),a&&a.layers.length>0&&e.jsxs("div",{className:U.section,children:[e.jsxs("h3",{className:U.sectionTitle,children:[e.jsx(ns,{})," Layers (",a.layers.length,")"]}),e.jsxs("ul",{className:U.layersList,children:[a.layers.slice(0,6).map((d,x)=>{var f;return e.jsxs("li",{className:U.layer,children:[e.jsx("span",{className:U.layerIcon,children:e.jsx(ns,{})}),e.jsx("span",{className:U.layerName,children:d.name}),e.jsx("span",{className:U.layerCount,children:((f=d.objects)==null?void 0:f.length)||0})]},d.id||x)}),a.layers.length>6&&e.jsx("li",{className:U.layer,children:e.jsxs("span",{className:U.layerName,children:["+",a.layers.length-6," more..."]})})]})]}),t.warnings.length>0&&e.jsxs("div",{className:U.section,children:[e.jsxs("h3",{className:U.sectionTitle,children:[e.jsx(ts,{})," Warnings (",t.warnings.length,")"]}),e.jsxs("ul",{className:U.warningsList,children:[t.warnings.slice(0,5).map((d,x)=>e.jsxs("li",{className:U.warning,children:[e.jsx("span",{className:U.warningIcon,children:e.jsx(ts,{})}),e.jsx("span",{children:d.message})]},x)),t.warnings.length>5&&e.jsxs("li",{className:U.warning,children:["+",t.warnings.length-5," more warnings..."]})]})]}),y.length>0&&e.jsxs("div",{className:U.section,children:[e.jsxs("h3",{className:U.sectionTitle,children:[e.jsx(ss,{})," Errors (",y.length,")"]}),e.jsx("ul",{className:U.warningsList,children:y.slice(0,5).map((d,x)=>e.jsxs("li",{className:U.error,children:[e.jsx("span",{className:U.errorIcon,children:e.jsx(ss,{})}),e.jsx("span",{children:d.message})]},x))})]}),t.warnings.length===0&&y.length===0&&e.jsx("div",{className:U.section,children:e.jsxs("p",{className:U.noWarnings,children:[e.jsx(S.NiceIcon,{name:"check",size:14})," No warnings or errors found"]})})]})]}),e.jsxs("div",{className:U.footer,children:[e.jsx("button",{className:U.cancelButton,onClick:n,children:"Cancel"}),e.jsx("button",{className:U.confirmButton,onClick:s,disabled:l,children:l?"Cannot Import (Fatal Errors)":"Confirm Import"})]})]})})}const ia="_overlay_1jmp3_9",ra="_dialog_1jmp3_55",ca="_header_1jmp3_103",la="_title_1jmp3_119",da="_closeButton_1jmp3_133",ua="_content_1jmp3_167",ma="_description_1jmp3_179",ha="_mappingTable_1jmp3_191",pa="_sourceLayer_1jmp3_241",fa="_layerIcon_1jmp3_253",_a="_layerName_1jmp3_261",ga="_objectCount_1jmp3_273",ya="_targetSelect_1jmp3_285",ba="_skipOption_1jmp3_327",xa="_arrowIcon_1jmp3_337",va="_presets_1jmp3_347",ja="_presetButton_1jmp3_361",wa="_footer_1jmp3_393",Na="_footerLeft_1jmp3_413",ka="_checkbox_1jmp3_425",Ia="_checkboxLabel_1jmp3_437",Ca="_footerRight_1jmp3_447",Sa="_cancelButton_1jmp3_457",La="_confirmButton_1jmp3_489",re={overlay:ia,dialog:ra,header:ca,title:la,closeButton:da,content:ua,description:ma,mappingTable:ha,sourceLayer:pa,layerIcon:fa,layerName:_a,objectCount:ga,targetSelect:ya,skipOption:ba,arrowIcon:xa,presets:va,presetButton:ja,footer:wa,footerLeft:Na,checkbox:ka,checkboxLabel:Ia,footerRight:Ca,cancelButton:Sa,confirmButton:La},os=()=>e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M15 5L5 15M5 5L15 15",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})}),Ta=()=>e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.2",children:e.jsx("path",{d:"M7 1L1 4l6 3 6-3-6-3zM1 7l6 3 6-3M1 10l6 3 6-3"})}),$a=()=>e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("path",{d:"M4 8h8M9 5l3 3-3 3",strokeLinecap:"round",strokeLinejoin:"round"})}),as={"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 za(t){if(!t.document)return[];const s=[];for(const n of t.document.floors)for(const o of n.layers)s.push({id:o.id,name:o.name,type:o.type,objectCount:o.objects.length});return s}function Ma(t){if(!t)return[];const s=[];for(const n of t.floors)for(const o of n.layers)s.find(a=>a.id===o.id)||s.push(o);return s}function is(t,s){const n=new Map;for(const o of t){const a=s.find(r=>r.type===o.type);if(a){n.set(o.id,a.id);continue}const i=o.name.toLowerCase(),c=s.find(r=>r.name.toLowerCase()===i);if(c){n.set(o.id,c.id);continue}n.set(o.id,o.id)}return n}const Ba=({importResult:t,existingDocument:s,onConfirm:n,onCancel:o})=>{const{t:a}=S.useNiceTranslation(),i=m.useMemo(()=>za(t),[t]),c=m.useMemo(()=>Ma(s),[s]),[r,l]=m.useState(()=>is(i,c)),[y,d]=m.useState(!0),x=m.useCallback((h,k)=>{l(C=>{const T=new Map(C);return T.set(h,k),T})},[]),f=m.useCallback(h=>{const k=new Map;switch(h){case"auto":l(is(i,c));return;case"skip-all":for(const C of i)k.set(C.id,"skip");break;case"preserve":for(const C of i)k.set(C.id,C.id);break}l(k)},[i,c]),p=m.useCallback(()=>{n(r,y)},[r,y,n]),_=m.useCallback(h=>{h.key==="Escape"?o():h.key==="Enter"&&(h.ctrlKey||h.metaKey)&&p()},[o,p]),j=m.useCallback(h=>{h.target===h.currentTarget&&o()},[o]);return i.length===0?e.jsx("div",{className:re.overlay,onClick:j,onKeyDown:_,tabIndex:-1,children:e.jsxs("div",{className:re.dialog,children:[e.jsxs("div",{className:re.header,children:[e.jsx("h2",{className:re.title,children:"Mapowanie warstw"}),e.jsx("button",{className:re.closeButton,onClick:o,children:e.jsx(os,{})})]}),e.jsx("div",{className:re.content,children:e.jsx("p",{className:re.description,children:a("buildings.spatial.noLayersInFile","The imported file contains no layers.")})}),e.jsxs("div",{className:re.footer,children:[e.jsx("div",{className:re.footerLeft}),e.jsx("div",{className:re.footerRight,children:e.jsx("button",{className:re.cancelButton,onClick:o,children:a("buildings.spatial.close","Close")})})]})]})}):e.jsx("div",{className:re.overlay,onClick:j,onKeyDown:_,tabIndex:-1,children:e.jsxs("div",{className:re.dialog,children:[e.jsxs("div",{className:re.header,children:[e.jsx("h2",{className:re.title,children:"Mapowanie warstw"}),e.jsx("button",{className:re.closeButton,onClick:o,children:e.jsx(os,{})})]}),e.jsxs("div",{className:re.content,children:[e.jsx("p",{className:re.description,children:a("buildings.spatial.mappingHint","Choose how the layers from the imported file map onto the editor layers.")}),e.jsxs("table",{className:re.mappingTable,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:a("buildings.spatial.sourceLayer","Source layer")}),e.jsx("th",{}),e.jsx("th",{children:"Warstwa docelowa"})]})}),e.jsx("tbody",{children:i.map(h=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsxs("div",{className:re.sourceLayer,children:[e.jsx("span",{className:re.layerIcon,children:e.jsx(Ta,{})}),e.jsx("span",{className:re.layerName,children:h.name}),e.jsxs("span",{className:re.objectCount,children:["(",h.objectCount," ",h.objectCount===1?a("buildings.spatial.object","object"):a("buildings.spatial.objects","objects"),")"]})]})}),e.jsx("td",{className:re.arrowIcon,children:e.jsx($a,{})}),e.jsx("td",{children:e.jsxs("select",{className:re.targetSelect,value:r.get(h.id)||h.id,onChange:k=>x(h.id,k.target.value),children:[e.jsxs("option",{value:"skip",className:re.skipOption,children:["— ",a("buildings.spatial.skipLayer","Skip this layer")," —"]}),e.jsxs("option",{value:h.id,children:[a("buildings.spatial.create","Create"),": ",h.name," (",as[h.type],")"]}),c.map(k=>e.jsxs("option",{value:k.id,children:[k.name," (",as[k.type],")"]},k.id))]})})]},h.id))})]}),e.jsxs("div",{className:re.presets,children:[e.jsx("button",{className:re.presetButton,onClick:()=>f("auto"),children:"Auto-mapowanie"}),e.jsx("button",{className:re.presetButton,onClick:()=>f("preserve"),children:a("buildings.spatial.keepAll","Keep all")}),e.jsx("button",{className:re.presetButton,onClick:()=>f("skip-all"),children:a("buildings.spatial.skipAll","Skip all")})]})]}),e.jsxs("div",{className:re.footer,children:[e.jsxs("div",{className:re.footerLeft,children:[e.jsx("input",{type:"checkbox",id:"createMissing",className:re.checkbox,checked:y,onChange:h=>d(h.target.checked)}),e.jsx("label",{htmlFor:"createMissing",className:re.checkboxLabel,children:a("buildings.spatial.createMissing","Create the missing layers")})]}),e.jsxs("div",{className:re.footerRight,children:[e.jsx("button",{className:re.cancelButton,onClick:o,children:a("buildings.spatial.cancel","Cancel")}),e.jsx("button",{className:re.confirmButton,onClick:p,children:a("buildings.spatial.applyMapping","Apply mapping")})]})]})]})})},Ea="_root_4ino1_9",Pa="_header_4ino1_21",Aa="_title_4ino1_31",Oa="_layerList_4ino1_45",Da="_layerItem_4ino1_55",Ra="_hidden_4ino1_83",qa="_locked_4ino1_91",Fa="_visibilityBtn_4ino1_99",Ga="_lockBtn_4ino1_101",Wa="_layerIcon_4ino1_139",Va="_layerName_4ino1_147",Ha="_opacitySlider_4ino1_157",Le={root:Ea,header:Pa,title:Aa,layerList:Oa,layerItem:Da,hidden:Ra,locked:qa,visibilityBtn:Fa,lockBtn:Ga,layerIcon:Wa,layerName:Va,opacitySlider:Ha},Ua={"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"}},ks=({layers:t,onVisibilityToggle:s,onLockToggle:n,onOpacityChange:o,className:a})=>{const i=[...t].sort((c,r)=>r.zIndex-c.zIndex);return e.jsxs("div",{className:`${Le.root} ${a??""}`,children:[e.jsx("div",{className:Le.header,children:e.jsx("h3",{className:Le.title,children:"Layers"})}),e.jsx("div",{className:Le.layerList,children:i.map(c=>{const r=Ua[c.type]||{icon:"box",label:c.type};return e.jsxs("div",{className:`${Le.layerItem} ${c.visible?"":Le.hidden} ${c.locked?Le.locked:""}`,children:[e.jsx("button",{className:Le.visibilityBtn,onClick:()=>s(c.type),title:c.visible?"Hide layer":"Show layer",children:e.jsx(S.NiceIcon,{name:c.visible?"eye":"eye-off",size:16})}),e.jsx("button",{className:Le.lockBtn,onClick:()=>n(c.type),title:c.locked?"Unlock layer":"Lock layer",children:e.jsx(S.NiceIcon,{name:"lock",size:16})}),e.jsx("span",{className:Le.layerIcon,children:e.jsx(S.NiceIcon,{name:r.icon,size:16})}),e.jsx("span",{className:Le.layerName,children:r.label}),e.jsx("input",{type:"range",min:"0",max:"1",step:"0.1",value:c.opacity,onChange:l=>o(c.type,parseFloat(l.target.value)),className:Le.opacitySlider,title:`Opacity: ${Math.round(c.opacity*100)}%`})]},c.type)})})]})},Ya="_root_1lufq_9",Za="_svg_1lufq_31",Xa="_viewportRect_1lufq_41",Ka="_zoomIndicator_1lufq_49",ft={root:Ya,svg:Za,viewportRect:Xa,zoomIndicator:Ka},Is=({document:t,activeFloorId:s,viewport:n,onViewportChange:o,size:a=150,className:i})=>{var T,b;const c=m.useRef(null),r=m.useMemo(()=>t.floors.find(L=>L.id===s)??t.floors[0]??null,[t,s]),l=((T=r==null?void 0:r.dimensions)==null?void 0:T.width)??1e3,y=((b=r==null?void 0:r.dimensions)==null?void 0:b.height)??800,d=Math.min(a/l,a/y)*.9,x=l*d,f=y*d,p=a/n.zoom*d,_=a/n.zoom*d,j=-n.pan.x/n.zoom*d,h=-n.pan.y/n.zoom*d,k=m.useCallback(L=>{var B;const u=(B=c.current)==null?void 0:B.getBoundingClientRect();if(!u)return;const v=(L.clientX-u.left-(a-x)/2)/d,g=(L.clientY-u.top-(a-f)/2)/d,q=-(v-a/n.zoom/2)*n.zoom,I=-(g-a/n.zoom/2)*n.zoom;o({pan:{x:q,y:I}})},[d,a,x,f,n.zoom,o]),C=m.useMemo(()=>{const L=r==null?void 0:r.layers.find(u=>u.name==="zones");return L?L.objects.map(u=>{const v=u;if(!v.polygon||v.polygon.length<3)return null;const g=v.polygon.map((q,I)=>`${I===0?"M":"L"}${q.x*d},${q.y*d}`).join(" ")+" Z";return e.jsx("path",{d:g,fill:v.color??"var(--nice-primary-bg, #dbeafe)",fillOpacity:.6,stroke:"var(--nice-text-muted, #94a3b8)",strokeWidth:.5},v.id)}):null},[r,d]);return r?e.jsxs("div",{className:`${ft.root} ${i??""}`,children:[e.jsxs("svg",{ref:c,width:a,height:a,viewBox:`0 0 ${a} ${a}`,className:ft.svg,onClick:k,children:[e.jsx("rect",{x:(a-x)/2,y:(a-f)/2,width:x,height:f,fill:"var(--nice-bg-secondary, #1e293b)",stroke:"var(--nice-border-color, #475569)",strokeWidth:1}),e.jsx("g",{transform:`translate(${(a-x)/2}, ${(a-f)/2})`,children:C}),e.jsx("rect",{x:(a-x)/2+j,y:(a-f)/2+h,width:Math.min(p,x),height:Math.min(_,f),fill:"var(--nice-primary-tint-20, rgba(59, 130, 246, 0.2))",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:1.5,rx:2,className:ft.viewportRect})]}),e.jsxs("div",{className:ft.zoomIndicator,children:[Math.round(n.zoom*100),"%"]})]}):null},Ja="_panel_1jo5f_9",Qa="_header_1jo5f_27",ei="_title_1jo5f_45",ti="_closeButton_1jo5f_59",si="_content_1jo5f_85",ni="_endpointSection_1jo5f_99",oi="_endpointLabel_1jo5f_107",ai="_endpointSelect_1jo5f_123",ii="_optionsSection_1jo5f_157",ri="_metricButton_1jo5f_169",ci="_metricButtonActive_1jo5f_205",li="_analyzeButton_1jo5f_219",di="_resultsSection_1jo5f_267",ui="_resultsTitle_1jo5f_277",mi="_noResults_1jo5f_293",hi="_pathCard_1jo5f_309",pi="_pathCardSelected_1jo5f_333",fi="_pathCardHeader_1jo5f_343",_i="_pathCardTitle_1jo5f_361",gi="_pathBadge_1jo5f_373",yi="_badgePrimary_1jo5f_389",bi="_badgeAlternate_1jo5f_399",xi="_pathName_1jo5f_409",vi="_pathStatus_1jo5f_421",ji="_statusDot_1jo5f_435",wi="_statusActive_1jo5f_447",Ni="_statusDegraded_1jo5f_453",ki="_statusInactive_1jo5f_459",Ii="_statusError_1jo5f_465",Ci="_pathStats_1jo5f_475",Si="_statItem_1jo5f_489",Li="_statValue_1jo5f_497",Ti="_statLabel_1jo5f_509",$i="_pathVisualization_1jo5f_523",zi="_pathDiagram_1jo5f_535",Mi="_pathNode_1jo5f_551",Bi="_pathNodeStart_1jo5f_583",Ei="_pathNodeEnd_1jo5f_585",Pi="_pathLink_1jo5f_595",Ai="_pathLinkLine_1jo5f_607",Oi="_showOnMapButton_1jo5f_621",Di="_loading_1jo5f_657",Ri="_spinner_1jo5f_671",qi="_spin_1jo5f_671",W={panel:Ja,header:Qa,title:ei,closeButton:ti,content:si,endpointSection:ni,endpointLabel:oi,endpointSelect:ai,optionsSection:ii,metricButton:ri,metricButtonActive:ci,analyzeButton:li,resultsSection:di,resultsTitle:ui,noResults:mi,pathCard:hi,pathCardSelected:pi,pathCardHeader:fi,pathCardTitle:_i,pathBadge:gi,badgePrimary:yi,badgeAlternate:bi,pathName:xi,pathStatus:vi,statusDot:ji,statusActive:wi,statusDegraded:Ni,statusInactive:ki,statusError:Ii,pathStats:Ci,statItem:Si,statValue:Li,statLabel:Ti,pathVisualization:$i,pathDiagram:zi,pathNode:Mi,pathNodeStart:Bi,pathNodeEnd:Ei,pathLink:Pi,pathLinkLine:Ai,showOnMapButton:Oi,loading:Di,spinner:Ri,spin:qi},Fi=()=>e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:e.jsx("path",{d:"M12 4L4 12M4 4L12 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})}),Gi=()=>e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("path",{d:"M4 8h8M9 5l3 3-3 3",strokeLinecap:"round",strokeLinejoin:"round"})});function Wi(t){switch(t){case"active":return"Aktywna";case"degraded":return"Degradacja";case"inactive":return"Nieaktywna";case"error":return"Error";default:return"Nieznany"}}function Vi(t){return t<1?"<1ms":t<1e3?`${Math.round(t)}ms`:`${(t/1e3).toFixed(1)}s`}function Hi(t){return t>=1e3?`${(t/1e3).toFixed(1)} Gbps`:`${Math.round(t)} Mbps`}const Ui=({document:t,connections:s,onHighlightPath:n,onClose:o})=>{const{t:a}=S.useNiceTranslation(),[i,c]=m.useState(""),[r,l]=m.useState(""),[y,d]=m.useState("latency"),[x,f]=m.useState([]),[p,_]=m.useState(null),[j,h]=m.useState(!1),k=m.useMemo(()=>{const u=[];for(const v of t.floors)for(const g of v.layers)if(g.type==="network"||g.type==="devices"||g.type==="infrastructure")for(const q of g.objects)u.push({id:q.id,name:q.name??q.id});return u},[t]),C=m.useCallback(u=>{var v;return((v=k.find(g=>g.id===u))==null?void 0:v.name)??u},[k]),T=m.useCallback(()=>{!i||!r||i===r||(h(!0),f([]),_(null),setTimeout(()=>{const u=ro(s,i,r,y),v=co(s,i,r,5),g=[];u&&g.push(u);for(const q of v)g.some(I=>I.connectionIds.length===q.connectionIds.length&&I.connectionIds.every((B,V)=>q.connectionIds[V]===B))||g.push({...q,isPrimary:!1});f(g),g.length>0&&(_(g[0].id),n==null||n(g[0])),h(!1)},300))},[i,r,y,s,n]),b=m.useCallback(u=>{_(u.id),n==null||n(u)},[n]),L=m.useCallback(u=>{const v=[u.startDeviceId];for(const g of u.connectionIds){const q=s.find(I=>I.id===g);if(q){const I=v[v.length-1],B=q.sourceId===I?q.targetId:q.sourceId;v.includes(B)||v.push(B)}}return v},[s]);return e.jsxs("div",{className:W.panel,children:[e.jsxs("div",{className:W.header,children:[e.jsx("h3",{className:W.title,children:a("buildings.spatial.pathAnalysis","Network path analysis")}),o&&e.jsx("button",{className:W.closeButton,onClick:o,children:e.jsx(Fi,{})})]}),e.jsxs("div",{className:W.content,children:[e.jsxs("div",{className:W.endpointSection,children:[e.jsx("label",{className:W.endpointLabel,children:a("buildings.spatial.sourceDevice","Source device")}),e.jsxs("select",{className:W.endpointSelect,value:i,onChange:u=>c(u.target.value),children:[e.jsxs("option",{value:"",children:["— ",a("buildings.spatial.selectDevice","Select a device")," —"]}),k.map(u=>e.jsx("option",{value:u.id,children:u.name},u.id))]})]}),e.jsxs("div",{className:W.endpointSection,children:[e.jsx("label",{className:W.endpointLabel,children:a("buildings.spatial.targetDevice","Target device")}),e.jsxs("select",{className:W.endpointSelect,value:r,onChange:u=>l(u.target.value),children:[e.jsxs("option",{value:"",children:["— ",a("buildings.spatial.selectDevice","Select a device")," —"]}),k.filter(u=>u.id!==i).map(u=>e.jsx("option",{value:u.id,children:u.name},u.id))]})]}),e.jsxs("div",{className:W.optionsSection,children:[e.jsx("button",{className:`${W.metricButton} ${y==="latency"?W.metricButtonActive:""}`,onClick:()=>d("latency"),children:"Latencja"}),e.jsx("button",{className:`${W.metricButton} ${y==="hops"?W.metricButtonActive:""}`,onClick:()=>d("hops"),children:"Hops"}),e.jsx("button",{className:`${W.metricButton} ${y==="bandwidth"?W.metricButtonActive:""}`,onClick:()=>d("bandwidth"),children:a("buildings.spatial.bandwidth","Bandwidth")})]}),e.jsx("button",{className:W.analyzeButton,onClick:T,disabled:!i||!r||i===r||j,children:j?a("buildings.spatial.analysing","Analysing…"):a("buildings.spatial.analysePath","Analyse the path")}),j?e.jsx("div",{className:W.loading,children:e.jsx("div",{className:W.spinner})}):x.length>0?e.jsxs("div",{className:W.resultsSection,children:[e.jsxs("div",{className:W.resultsTitle,children:[a("buildings.spatial.pathsFound","Paths found")," (",x.length,")"]}),x.map((u,v)=>{const g=L(u),q=p===u.id;return e.jsxs("div",{className:`${W.pathCard} ${q?W.pathCardSelected:""}`,onClick:()=>b(u),children:[e.jsxs("div",{className:W.pathCardHeader,children:[e.jsxs("div",{className:W.pathCardTitle,children:[e.jsx("span",{className:`${W.pathBadge} ${u.isPrimary?W.badgePrimary:W.badgeAlternate}`,children:u.isPrimary?"Optymalna":`Alt ${v}`}),e.jsxs("span",{className:W.pathName,children:[u.connectionIds.length," ",a("buildings.spatial.connections","connections")]})]}),e.jsxs("div",{className:W.pathStatus,children:[e.jsx("span",{className:`${W.statusDot} ${W[`status${u.status.charAt(0).toUpperCase()+u.status.slice(1)}`]??""}`}),e.jsx("span",{children:Wi(u.status)})]})]}),e.jsxs("div",{className:W.pathStats,children:[e.jsxs("div",{className:W.statItem,children:[e.jsx("div",{className:W.statValue,children:Vi(u.totalLatency)}),e.jsx("div",{className:W.statLabel,children:"Latencja"})]}),e.jsxs("div",{className:W.statItem,children:[e.jsx("div",{className:W.statValue,children:u.connectionIds.length}),e.jsx("div",{className:W.statLabel,children:"Hops"})]}),e.jsxs("div",{className:W.statItem,children:[e.jsx("div",{className:W.statValue,children:u.bottleneckBandwidth>0?Hi(u.bottleneckBandwidth):"N/A"}),e.jsx("div",{className:W.statLabel,children:a("buildings.spatial.bandwidth","Bandwidth")})]})]}),q&&e.jsxs("div",{className:W.pathVisualization,children:[e.jsx("div",{className:W.pathDiagram,children:g.map((I,B)=>e.jsxs(m.Fragment,{children:[e.jsx("div",{className:`${W.pathNode} ${B===0?W.pathNodeStart:B===g.length-1?W.pathNodeEnd:""}`,children:C(I).substring(0,8)}),B<g.length-1&&e.jsxs("div",{className:W.pathLink,children:[e.jsx("div",{className:W.pathLinkLine}),e.jsx(Gi,{})]})]},I))}),e.jsx("button",{className:W.showOnMapButton,onClick:I=>{I.stopPropagation(),n==null||n(u)},children:a("buildings.spatial.showOnMap","Show on the map")})]})]},u.id)})]}):i&&r&&i!==r?e.jsx("div",{className:W.noResults,children:a("buildings.spatial.noResultsHint","Pick two devices and run the analysis")}):e.jsx("div",{className:W.noResults,children:a("buildings.spatial.pickEndpoints","Pick a source and a target device")})]})]})},Yi="_root_6pirz_9",Zi="_header_6pirz_27",Xi="_title_6pirz_37",Ki="_search_6pirz_51",Ji="_categories_6pirz_79",Qi="_category_6pirz_91",er="_categoryHeader_6pirz_107",tr="_categoryIcon_6pirz_143",sr="_categoryLabel_6pirz_151",nr="_categoryCount_6pirz_161",or="_expandIcon_6pirz_171",ar="_items_6pirz_181",ir="_item_6pirz_181",rr="_itemIcon_6pirz_241",cr="_itemName_6pirz_249",lr="_emptyState_6pirz_269",we={root:Yi,header:Zi,title:Xi,search:Ki,categories:Ji,category:Qi,categoryHeader:er,categoryIcon:tr,categoryLabel:sr,categoryCount:nr,expandIcon:or,items:ar,item:ir,itemIcon:rr,itemName:cr,emptyState:lr},dr=t=>t&&/^[a-z][a-z0-9-]*$/.test(t)?t:"box",ur={"floor-plan":["smart-home","building"],"network-topology":["network"],infrastructure:["infrastructure","network"],cad:["building"],interior:["furniture","smart-home"],"game-scene":["game"]},mr={"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"}},Cs=({mode:t,onObjectSelect:s,customObjects:n=[],className:o})=>{const[a,i]=m.useState(""),[c,r]=m.useState(new Set(["smart-home","furniture","network"])),l=ur[t]||[],y=m.useMemo(()=>{const f={},p=Vn.reduce((_,j)=>{var h;return(_[h=j.category]??(_[h]=[])).push(j),_},{});return Object.entries(p).forEach(([_,j])=>{if(!l.includes(_))return;const h=j.filter(k=>!a||k.name.toLowerCase().includes(a.toLowerCase()));h.length>0&&(f[_]=h.map(k=>({id:k.id,name:k.name,category:_,icon:k.icon})))}),n.forEach(_=>{l.includes(_.category)&&(!a||_.name.toLowerCase().includes(a.toLowerCase()))&&(f[_.category]||(f[_.category]=[]),f[_.category].push(_))}),f},[l,a,n]),d=f=>{r(p=>{const _=new Set(p);return _.has(f)?_.delete(f):_.add(f),_})},x=(f,p)=>{f.dataTransfer.setData("application/json",JSON.stringify(p)),f.dataTransfer.effectAllowed="copy"};return e.jsxs("div",{className:`${we.root} ${o??""}`,children:[e.jsxs("div",{className:we.header,children:[e.jsx("h3",{className:we.title,children:"Objects"}),e.jsx("input",{type:"text",className:we.search,placeholder:"Search...",value:a,onChange:f=>i(f.target.value)})]}),e.jsxs("div",{className:we.categories,children:[Object.entries(y).map(([f,p])=>{const _=mr[f]||{icon:"box",label:f},j=c.has(f);return e.jsxs("div",{className:we.category,children:[e.jsxs("button",{className:we.categoryHeader,onClick:()=>d(f),children:[e.jsx("span",{className:we.categoryIcon,children:e.jsx(S.NiceIcon,{name:_.icon,size:16})}),e.jsx("span",{className:we.categoryLabel,children:_.label}),e.jsxs("span",{className:we.categoryCount,children:["(",p.length,")"]}),e.jsx("span",{className:we.expandIcon,children:e.jsx(S.NiceIcon,{name:j?"chevron-down":"chevron-right",size:14})})]}),j&&e.jsx("div",{className:we.items,children:p.map(h=>e.jsxs("div",{className:we.item,draggable:!0,onDragStart:k=>x(k,h),onClick:()=>s(h),title:h.name,children:[e.jsx("span",{className:we.itemIcon,children:e.jsx(S.NiceIcon,{name:dr(h.icon),size:16})}),e.jsx("span",{className:we.itemName,children:h.name})]},h.id))})]},f)}),Object.keys(y).length===0&&e.jsx("div",{className:we.emptyState,children:a?`No objects matching "${a}"`:"No objects available for this mode"})]})]})},hr="_root_o3eqo_9",pr="_header_o3eqo_23",fr="_title_o3eqo_39",_r="_multiSelect_o3eqo_53",gr="_content_o3eqo_63",yr="_section_o3eqo_73",br="_sectionHeader_o3eqo_89",xr="_sectionContent_o3eqo_127",vr="_fieldRow_o3eqo_135",jr="_fieldLabel_o3eqo_157",wr="_textInput_o3eqo_169",Nr="_numberInput_o3eqo_171",kr="_select_o3eqo_173",Ir="_checkbox_o3eqo_215",Cr="_colorInput_o3eqo_227",Sr="_readOnly_o3eqo_245",Lr="_emptyState_o3eqo_263",ae={root:hr,header:pr,title:fr,multiSelect:_r,content:gr,section:yr,sectionHeader:br,sectionContent:xr,fieldRow:vr,fieldLabel:jr,textInput:wr,numberInput:Nr,select:kr,checkbox:Ir,colorInput:Cr,readOnly:Sr,emptyState:Lr},qt=[{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"}],Tr=[{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}],$r=[{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"}]}],Ss=({selection:t,document:s,onPropertyChange:n,className:o})=>{const[a,i]=m.useState(new Set(["general","position","appearance"])),c=t.objectIds.map(p=>{for(const _ of s.floors)for(const j of _.layers){const h=j.objects.find(k=>k.id===p);if(h)return h}return null}).filter(Boolean),r=p=>{i(_=>{const j=new Set(_);return j.has(p)?j.delete(p):j.add(p),j})},l=m.useCallback((p,_)=>{const j=_.split(".");let h=p;for(const k of j)if(h&&typeof h=="object"&&k in h)h=h[k];else return;return h},[]),y=m.useCallback((p,_)=>{var h;const j=l(_,p.key);switch(p.type){case"text":return e.jsx("input",{type:"text",value:String(j??""),onChange:k=>n(_.id,p.key,k.target.value),className:ae.textInput});case"number":return e.jsx("input",{type:"number",value:Number(j??0),min:p.min,max:p.max,step:p.step,onChange:k=>n(_.id,p.key,parseFloat(k.target.value)),className:ae.numberInput});case"boolean":return e.jsx("input",{type:"checkbox",checked:!!j,onChange:k=>n(_.id,p.key,k.target.checked),className:ae.checkbox});case"color":return e.jsx("input",{type:"color",value:String(j??"var(--nice-bg, #fff)"),onChange:k=>n(_.id,p.key,k.target.value),className:ae.colorInput});case"select":return e.jsx("select",{value:String(j??""),onChange:k=>n(_.id,p.key,k.target.value),className:ae.select,children:(h=p.options)==null?void 0:h.map(k=>e.jsx("option",{value:k.value,children:k.label},k.value))});default:return e.jsx("span",{children:String(j??"-")})}},[l,n]);if(c.length===0)return e.jsxs("div",{className:`${ae.root} ${o??""}`,children:[e.jsx("div",{className:ae.header,children:e.jsx("h3",{className:ae.title,children:"Properties"})}),e.jsx("div",{className:ae.emptyState,children:"No object selected"})]});const d=c[0],x=c.length>1,f=d.category==="zone"?Tr:["smart-home","network","infrastructure"].includes(d.category??"")?$r:[];return e.jsxs("div",{className:`${ae.root} ${o??""}`,children:[e.jsxs("div",{className:ae.header,children:[e.jsx("h3",{className:ae.title,children:"Properties"}),x&&e.jsxs("span",{className:ae.multiSelect,children:[c.length," selected"]})]}),e.jsxs("div",{className:ae.content,children:[e.jsxs("div",{className:ae.section,children:[e.jsxs("button",{className:ae.sectionHeader,onClick:()=>r("general"),children:[e.jsx("span",{children:e.jsx(S.NiceIcon,{name:a.has("general")?"chevron-down":"chevron-right",size:14})}),e.jsx("span",{children:"General"})]}),a.has("general")&&e.jsxs("div",{className:ae.sectionContent,children:[qt.slice(0,1).map(p=>e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:p.label}),y(p,d)]},p.key)),e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:"ID"}),e.jsx("span",{className:ae.readOnly,children:d.id})]}),e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:"Category"}),e.jsx("span",{className:ae.readOnly,children:d.category})]})]})]}),e.jsxs("div",{className:ae.section,children:[e.jsxs("button",{className:ae.sectionHeader,onClick:()=>r("position"),children:[e.jsx("span",{children:e.jsx(S.NiceIcon,{name:a.has("position")?"chevron-down":"chevron-right",size:14})}),e.jsx("span",{children:"Transform"})]}),a.has("position")&&e.jsx("div",{className:ae.sectionContent,children:qt.slice(1,4).map(p=>e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:p.label}),y(p,d)]},p.key))})]}),f.length>0&&e.jsxs("div",{className:ae.section,children:[e.jsxs("button",{className:ae.sectionHeader,onClick:()=>r("appearance"),children:[e.jsx("span",{children:e.jsx(S.NiceIcon,{name:a.has("appearance")?"chevron-down":"chevron-right",size:14})}),e.jsx("span",{children:"Appearance"})]}),a.has("appearance")&&e.jsx("div",{className:ae.sectionContent,children:f.map(p=>e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:p.label}),y(p,d)]},p.key))})]}),e.jsxs("div",{className:ae.section,children:[e.jsxs("button",{className:ae.sectionHeader,onClick:()=>r("visibility"),children:[e.jsx("span",{children:e.jsx(S.NiceIcon,{name:a.has("visibility")?"chevron-down":"chevron-right",size:14})}),e.jsx("span",{children:"Visibility"})]}),a.has("visibility")&&e.jsx("div",{className:ae.sectionContent,children:qt.slice(4).map(p=>e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:p.label}),y(p,d)]},p.key))})]})]})]})},zr="_panel_18mro_9",Mr="_header_18mro_33",Br="_headerTitle_18mro_51",Er="_title_18mro_65",Pr="_closeButton_18mro_79",Ar="_summarySection_18mro_111",Or="_summaryStats_18mro_129",Dr="_statBadge_18mro_141",Rr="_statValue_18mro_155",qr="_statLabel_18mro_167",Fr="_visibilityControls_18mro_183",Gr="_visibilityLabel_18mro_201",Wr="_visibilityButtons_18mro_211",Vr="_visibilityBtn_18mro_221",Hr="_active_18mro_251",Ur="_content_18mro_265",Yr="_emptyState_18mro_279",Zr="_emptyHint_18mro_325",Xr="_vlanList_18mro_337",Kr="_vlanCard_18mro_351",Jr="_highlighted_18mro_377",Qr="_hidden_18mro_387",ec="_vlanHeader_18mro_395",tc="_colorIndicator_18mro_421",sc="_vlanInfo_18mro_435",nc="_vlanName_18mro_445",oc="_vlanId_18mro_459",ac="_vlanNameText_18mro_471",ic="_vlanSubnet_18mro_487",rc="_vlanStats_18mro_503",cc="_chipStat_18mro_515",lc="_vlanActions_18mro_545",dc="_iconBtn_18mro_557",uc="_inactive_18mro_595",mc="_expanded_18mro_611",hc="_vlanDetails_18mro_623",pc="_detailRow_18mro_635",fc="_detailLabel_18mro_657",_c="_detailValue_18mro_675",gc="_badge_18mro_687",yc="_badgeSuccess_18mro_701",bc="_badgeNeutral_18mro_711",xc="_deviceList_18mro_723",vc="_deviceItems_18mro_731",jc="_deviceItem_18mro_731",wc="_deviceDot_18mro_765",Nc="_deviceMore_18mro_779",kc="_highlightButton_18mro_795",Ic="_footer_18mro_835",Cc="_legendTitle_18mro_847",Sc="_legend_18mro_847",Lc="_legendItem_18mro_875",Tc="_legendColor_18mro_887",$c="_legendLabel_18mro_901",O={panel:zr,header:Mr,headerTitle:Br,title:Er,closeButton:Pr,summarySection:Ar,summaryStats:Or,statBadge:Dr,statValue:Rr,statLabel:qr,visibilityControls:Fr,visibilityLabel:Gr,visibilityButtons:Wr,visibilityBtn:Vr,active:Hr,content:Ur,emptyState:Yr,emptyHint:Zr,vlanList:Xr,vlanCard:Kr,highlighted:Jr,hidden:Qr,vlanHeader:ec,colorIndicator:tc,vlanInfo:sc,vlanName:nc,vlanId:oc,vlanNameText:ac,vlanSubnet:ic,vlanStats:rc,chipStat:cc,vlanActions:lc,iconBtn:dc,inactive:uc,expanded:mc,vlanDetails:hc,detailRow:pc,detailLabel:fc,detailValue:_c,badge:gc,badgeSuccess:yc,badgeNeutral:bc,deviceList:xc,deviceItems:vc,deviceItem:jc,deviceDot:wc,deviceMore:Nc,highlightButton:kc,footer:Ic,legendTitle:Cc,legend:Sc,legendItem:Lc,legendColor:Tc,legendLabel:$c},zc=()=>e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:e.jsx("path",{d:"M12 4L4 12M4 4L12 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})}),Mc=()=>e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("ellipse",{cx:"8",cy:"8",rx:"6",ry:"4"}),e.jsx("circle",{cx:"8",cy:"8",r:"2"})]}),Bc=()=>e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("path",{d:"M2 8s2.5-4 6-4 6 4 6 4-2.5 4-6 4-6-4-6-4z"}),e.jsx("path",{d:"M3 13L13 3",strokeLinecap:"round"})]}),rs=()=>e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"2",y:"2",width:"4",height:"4",rx:"1"}),e.jsx("rect",{x:"10",y:"2",width:"4",height:"4",rx:"1"}),e.jsx("rect",{x:"6",y:"10",width:"4",height:"4",rx:"1"}),e.jsx("path",{d:"M4 6v2a2 2 0 002 2h4a2 2 0 002-2V6"}),e.jsx("path",{d:"M8 10V8"})]}),Ec=()=>e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("circle",{cx:"7",cy:"7",r:"6"}),e.jsx("path",{d:"M7 6v4M7 4h0",strokeLinecap:"round"})]});function Pc(t){var s;return((s=t.deviceIds)==null?void 0:s.length)??0}function Ac(t,s){return s.filter(n=>n.vlanId===t.id).length}function Oc(t){return t||"—"}const Dc=({document:t,connections:s,vlans:n,visibleVlanIds:o,onVlanVisibilityChange:a,onHighlightVlan:i,onClose:c})=>{const{t:r}=S.useNiceTranslation(),[l,y]=m.useState(null),[d,x]=m.useState(null),f=m.useMemo(()=>[...n].sort((b,L)=>b.id-L.id),[n]),p=m.useMemo(()=>{const b=new Set,L=new Set;for(const u of n)for(const v of u.deviceIds??[])b.add(v);for(const u of s)u.vlanId!==void 0&&L.add(u.id);return{vlanCount:n.length,deviceCount:b.size,connectionCount:L.size}},[n,s]),_=m.useCallback(b=>{const L=o.has(b);a==null||a(b,!L)},[o,a]),j=m.useCallback(b=>{for(const L of n)a==null||a(L.id,b)},[n,a]),h=m.useCallback(b=>{y((b==null?void 0:b.id)??null),i==null||i(b)},[i]),k=m.useCallback(b=>{x(L=>L===b?null:b)},[]),C=m.useCallback(b=>{const L=[];for(const u of b.deviceIds??[])for(const v of t.floors)for(const g of v.layers){const q=g.objects.find(I=>I.id===u);q&&L.push({id:u,name:q.name??u})}return L},[t]),T=m.useMemo(()=>{const b=n.filter(L=>o.has(L.id)).length;return{visible:b,total:n.length,allVisible:b===n.length,noneVisible:b===0}},[n,o]);return e.jsxs("div",{className:O.panel,children:[e.jsxs("div",{className:O.header,children:[e.jsxs("div",{className:O.headerTitle,children:[e.jsx(rs,{}),e.jsx("h3",{className:O.title,children:r("buildings.spatial.vlan.title","VLAN overlay")})]}),c&&e.jsx("button",{className:O.closeButton,onClick:c,title:r("buildings.spatial.close","Close"),children:e.jsx(zc,{})})]}),e.jsx("div",{className:O.summarySection,children:e.jsxs("div",{className:O.summaryStats,children:[e.jsxs("div",{className:O.statBadge,children:[e.jsx("span",{className:O.statValue,children:p.vlanCount}),e.jsx("span",{className:O.statLabel,children:"VLAN"})]}),e.jsxs("div",{className:O.statBadge,children:[e.jsx("span",{className:O.statValue,children:p.deviceCount}),e.jsx("span",{className:O.statLabel,children:r("buildings.spatial.devices","Devices")})]}),e.jsxs("div",{className:O.statBadge,children:[e.jsx("span",{className:O.statValue,children:p.connectionCount}),e.jsx("span",{className:O.statLabel,children:r("buildings.spatial.connections","Connections")})]})]})}),e.jsxs("div",{className:O.visibilityControls,children:[e.jsxs("span",{className:O.visibilityLabel,children:[r("buildings.spatial.vlan.visibility","Visibility"),": ",T.visible,"/",T.total]}),e.jsxs("div",{className:O.visibilityButtons,children:[e.jsx("button",{className:`${O.visibilityBtn} ${T.allVisible?O.active:""}`,onClick:()=>j(!0),title:r("buildings.spatial.vlan.showAll","Show all"),children:r("buildings.spatial.vlan.all","All")}),e.jsx("button",{className:`${O.visibilityBtn} ${T.noneVisible?O.active:""}`,onClick:()=>j(!1),title:r("buildings.spatial.vlan.hideAll","Hide all"),children:r("buildings.spatial.vlan.none","None")})]})]}),e.jsx("div",{className:O.content,children:f.length===0?e.jsxs("div",{className:O.emptyState,children:[e.jsx(rs,{}),e.jsx("p",{children:r("buildings.spatial.vlan.empty","No VLANs defined")}),e.jsx("span",{className:O.emptyHint,children:r("buildings.spatial.vlan.emptyHint","Add a VLAN in network-topology or infrastructure mode")})]}):e.jsx("div",{className:O.vlanList,children:f.map(b=>{const L=o.has(b.id),u=l===b.id,v=d===b.id,g=Pc(b),q=Ac(b,s),I=v?C(b):[];return e.jsxs("div",{className:`${O.vlanCard} ${u?O.highlighted:""} ${L?"":O.hidden}`,onMouseEnter:()=>h(b),onMouseLeave:()=>h(null),children:[e.jsxs("div",{className:O.vlanHeader,children:[e.jsx("div",{className:O.colorIndicator,style:{backgroundColor:b.color}}),e.jsxs("div",{className:O.vlanInfo,children:[e.jsxs("div",{className:O.vlanName,children:[e.jsxs("span",{className:O.vlanId,children:["VLAN ",b.id]}),b.name&&e.jsx("span",{className:O.vlanNameText,children:b.name})]}),b.subnet&&e.jsx("div",{className:O.vlanSubnet,children:Oc(b.subnet)})]}),e.jsxs("div",{className:O.vlanStats,children:[e.jsx("span",{className:O.chipStat,title:r("buildings.spatial.devices","Devices"),children:g}),e.jsx("span",{className:O.chipStat,title:r("buildings.spatial.connections","Connections"),children:q})]}),e.jsxs("div",{className:O.vlanActions,children:[e.jsx("button",{className:`${O.iconBtn} ${L?"":O.inactive}`,onClick:B=>{B.stopPropagation(),_(b.id)},title:L?r("buildings.spatial.vlan.hide","Hide VLAN"):r("buildings.spatial.vlan.show","Show VLAN"),children:L?e.jsx(Mc,{}):e.jsx(Bc,{})}),e.jsx("button",{className:`${O.iconBtn} ${v?O.expanded:""}`,onClick:B=>{B.stopPropagation(),k(b.id)},title:r("buildings.spatial.details","Details"),children:e.jsx(Ec,{})})]})]}),v&&e.jsxs("div",{className:O.vlanDetails,children:[b.description&&e.jsxs("div",{className:O.detailRow,children:[e.jsxs("span",{className:O.detailLabel,children:[r("buildings.spatial.vlan.description","Description"),":"]}),e.jsx("span",{className:O.detailValue,children:b.description})]}),b.subnet&&e.jsxs("div",{className:O.detailRow,children:[e.jsxs("span",{className:O.detailLabel,children:[r("buildings.spatial.vlan.subnet","Subnet"),":"]}),e.jsx("span",{className:O.detailValue,children:b.subnet})]}),b.gateway&&e.jsxs("div",{className:O.detailRow,children:[e.jsxs("span",{className:O.detailLabel,children:[r("buildings.spatial.vlan.gateway","Gateway"),":"]}),e.jsx("span",{className:O.detailValue,children:b.gateway})]}),e.jsxs("div",{className:O.detailRow,children:[e.jsx("span",{className:O.detailLabel,children:"DHCP:"}),e.jsx("span",{className:`${O.detailValue} ${O.badge} ${b.dhcpEnabled?O.badgeSuccess:O.badgeNeutral}`,children:b.dhcpEnabled?r("buildings.spatial.enabled","Enabled"):r("buildings.spatial.disabled","Disabled")})]}),I.length>0&&e.jsxs("div",{className:O.deviceList,children:[e.jsxs("span",{className:O.detailLabel,children:[r("buildings.spatial.devices","Devices")," (",I.length,"):"]}),e.jsxs("ul",{className:O.deviceItems,children:[I.slice(0,10).map(B=>e.jsxs("li",{className:O.deviceItem,children:[e.jsx("span",{className:O.deviceDot,style:{backgroundColor:b.color}}),B.name]},B.id)),I.length>10&&e.jsxs("li",{className:O.deviceMore,children:["… ",r("buildings.spatial.andMore","and")," ",I.length-10," ",r("buildings.spatial.more","more")]})]})]}),e.jsx("button",{className:O.highlightButton,onClick:()=>i==null?void 0:i(b),children:r("buildings.spatial.selectOnMap","Select on the map")})]})]},b.id)})})}),f.length>0&&e.jsxs("div",{className:O.footer,children:[e.jsx("div",{className:O.legendTitle,children:r("buildings.spatial.colourLegend","Colour legend")}),e.jsx("div",{className:O.legend,children:f.map(b=>e.jsxs("div",{className:O.legendItem,children:[e.jsx("span",{className:O.legendColor,style:{backgroundColor:b.color}}),e.jsxs("span",{className:O.legendLabel,children:[b.id,b.name?`: ${b.name}`:""]})]},b.id))})]})]})},Rc="_root_sniq9_9",qc="_shell_sniq9_35",Fc="_dark_sniq9_43",Gc="_topBar_sniq9_67",Wc="_modeSwitcher_sniq9_85",Vc="_modeBtn_sniq9_95",Hc="_modeBtnActive_sniq9_131",Uc="_modeIcon_sniq9_143",Yc="_modeLabel_sniq9_151",Zc="_floorTabs_sniq9_159",Xc="_floorTab_sniq9_159",Kc="_floorTabActive_sniq9_203",Jc="_viewportControls_sniq9_215",Qc="_active_sniq9_257",el="_disabled_sniq9_267",tl="_separator_sniq9_281",sl="_zoomLevel_sniq9_295",nl="_exportDropdown_sniq9_313",ol="_exportMenu_sniq9_361",al="_editorContainer_sniq9_435",il="_toolbar_sniq9_453",rl="_toolGroup_sniq9_473",cl="_toolBtn_sniq9_501",ll="_toolBtnActive_sniq9_541",dl="_canvasWrapper_sniq9_565",ul="_canvas_sniq9_565",ml="_cursor_select_sniq9_593",hl="_cursor_multi_select_sniq9_599",pl="_cursor_pan_sniq9_605",fl="_cursor_zoom_sniq9_617",_l="_cursor_draw_wall_sniq9_623",gl="_cursor_draw_zone_sniq9_625",yl="_cursor_draw_polyline_sniq9_627",bl="_cursor_draw_rectangle_sniq9_629",xl="_cursor_draw_circle_sniq9_631",vl="_cursor_draw_arc_sniq9_633",jl="_cursor_place_device_sniq9_639",wl="_cursor_place_furniture_sniq9_641",Nl="_cursor_place_network_sniq9_643",kl="_cursor_place_infra_sniq9_645",Il="_cursor_place_door_sniq9_647",Cl="_cursor_place_window_sniq9_649",Sl="_cursor_place_stairs_sniq9_651",Ll="_cursor_connect_sniq9_657",Tl="_cursor_route_cable_sniq9_659",$l="_cursor_annotate_sniq9_665",zl="_cursor_dimension_sniq9_667",Ml="_cursor_label_sniq9_669",Bl="_cursor_measure_distance_sniq9_675",El="_cursor_measure_angle_sniq9_677",Pl="_cursor_measure_area_sniq9_679",Al="_cursor_move_sniq9_685",Ol="_cursor_rotate_sniq9_691",Dl="_cursor_scale_sniq9_697",Rl="_cursor_erase_sniq9_703",ql="_cursor_copy_sniq9_709",Fl="_cursor_paste_sniq9_711",Gl="_grid_sniq9_721",Wl="_gridLine_sniq9_727",Vl="_zonesLayer_sniq9_739",Hl="_zone_sniq9_739",Ul="_zoneLabel_sniq9_755",Yl="_connectionsLayer_sniq9_769",Zl="_connection_sniq9_769",Xl="_connectionPreview_sniq9_785",Kl="_guides_sniq9_795",Jl="_guideLine_sniq9_801",Ql="_drawingPreview_sniq9_815",ed="_rightSidebar_sniq9_827",td="_statusBar_sniq9_849",sd="_modeIndicator_sniq9_871",nd="_toolIndicator_sniq9_873",od="_selectionInfo_sniq9_885",ad="_drawingInfo_sniq9_887",id="_connectingInfo_sniq9_901",rd="_gridInfo_sniq9_915",cd="_emptyState_sniq9_927",ld="_emptyIcon_sniq9_949",dd="_primaryBtn_sniq9_979",ud="_modeActions_sniq9_1013",md="_actionBtn_sniq9_1031",F={root:Rc,shell:qc,dark:Fc,topBar:Gc,modeSwitcher:Wc,modeBtn:Vc,modeBtnActive:Hc,modeIcon:Uc,modeLabel:Yc,floorTabs:Zc,floorTab:Xc,floorTabActive:Kc,viewportControls:Jc,active:Qc,disabled:el,separator:tl,zoomLevel:sl,exportDropdown:nl,exportMenu:ol,editorContainer:al,toolbar:il,toolGroup:rl,toolBtn:cl,toolBtnActive:ll,canvasWrapper:dl,canvas:ul,cursor_select:ml,cursor_multi_select:hl,cursor_pan:pl,cursor_zoom:fl,cursor_draw_wall:_l,cursor_draw_zone:gl,cursor_draw_polyline:yl,cursor_draw_rectangle:bl,cursor_draw_circle:xl,cursor_draw_arc:vl,cursor_place_device:jl,cursor_place_furniture:wl,cursor_place_network:Nl,cursor_place_infra:kl,cursor_place_door:Il,cursor_place_window:Cl,cursor_place_stairs:Sl,cursor_connect:Ll,cursor_route_cable:Tl,cursor_annotate:$l,cursor_dimension:zl,cursor_label:Ml,cursor_measure_distance:Bl,cursor_measure_angle:El,cursor_measure_area:Pl,cursor_move:Al,cursor_rotate:Ol,cursor_scale:Dl,cursor_erase:Rl,cursor_copy:ql,cursor_paste:Fl,grid:Gl,gridLine:Wl,zonesLayer:Vl,zone:Hl,zoneLabel:Ul,connectionsLayer:Yl,connection:Zl,connectionPreview:Xl,guides:Kl,guideLine:Jl,drawingPreview:Ql,rightSidebar:ed,statusBar:td,modeIndicator:sd,toolIndicator:nd,selectionInfo:od,drawingInfo:ad,connectingInfo:id,gridInfo:rd,emptyState:cd,emptyIcon:ld,primaryBtn:dd,modeActions:ud,actionBtn:md},Qe={"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}},xt={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"}};function hd(t){var a,i;const s=t.defaultMode??"floor-plan",n=Qe[s],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}];return{mode:s,tool:n.tools[0]??"select",document:t.document??t.initialDocument??null,activeFloorId:((i=(a=t.document)==null?void 0:a.floors[0])==null?void 0:i.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??n.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 Xe(t,s,n,o){return{id:`${Date.now()}-${Math.random().toString(36).slice(2,9)}`,timestamp:Date.now(),type:t,objectIds:s,before:n,after:o}}function Ke(t,s){return{history:{past:[...t.history.past.slice(-49),s],future:[]}}}function Fe(t,s){if(t)for(const n of t.floors)for(const o of n.layers){const a=o.objects.find(i=>i.id===s);if(a)return a}}function _t(t,s,n){return{...t,floors:t.floors.map(o=>({...o,layers:o.layers.map(a=>({...a,objects:a.objects.map(i=>i.id===s?{...i,...n}:i)}))})),metadata:{...t.metadata,modified:new Date().toISOString()}}}function gt(t,s){const n=new Set(s);return{...t,floors:t.floors.map(o=>({...o,layers:o.layers.map(a=>({...a,objects:a.objects.filter(i=>!n.has(i.id))}))})),metadata:{...t.metadata,modified:new Date().toISOString()}}}function yt(t,s,n,o){return{...t,floors:t.floors.map(a=>a.id!==s?a:{...a,layers:a.layers.map(i=>i.name!==n?i:{...i,objects:[...i.objects,o]})}),metadata:{...t.metadata,modified:new Date().toISOString()}}}function pd(t,s){var n;switch(s.type){case"SET_MODE":{const o=Qe[s.mode];return{...t,mode:s.mode,tool:o.tools.includes(t.tool)?t.tool:o.tools[0],viewport:{...t.viewport,gridSize:o.defaultGridSize}}}case"SET_TOOL":return{...t,tool:s.tool,drawing:{active:!1,points:[],preview:null},connecting:{active:!1,sourceId:null,sourcePosition:null,previewPosition:null}};case"SET_DOCUMENT":return{...t,document:s.document,activeFloorId:((n=s.document.floors[0])==null?void 0:n.id)??null};case"SET_ACTIVE_FLOOR":return{...t,activeFloorId:s.floorId};case"SET_SELECTION":return{...t,selection:s.selection};case"CLEAR_SELECTION":return{...t,selection:{objectIds:[],bounds:null,locked:!1}};case"SET_VIEWPORT":return{...t,viewport:{...t.viewport,...s.viewport}};case"ZOOM":{const o=Math.max(.1,Math.min(10,t.viewport.zoom*(1+s.delta*.1)));return{...t,viewport:{...t.viewport,zoom:o}}}case"PAN":return{...t,viewport:{...t.viewport,pan:{x:t.viewport.pan.x+s.delta.x,y:t.viewport.pan.y+s.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:s.size}};case"SET_SNAP_MODES":return{...t,viewport:{...t.viewport,snapModes:s.modes}};case"SET_LAYER_VISIBILITY":return{...t,layers:t.layers.map(o=>o.type===s.layerType?{...o,visible:s.visible}:o)};case"SET_LAYER_LOCKED":return{...t,layers:t.layers.map(o=>o.type===s.layerType?{...o,locked:s.locked}:o)};case"SET_LAYER_OPACITY":return{...t,layers:t.layers.map(o=>o.type===s.layerType?{...o,opacity:s.opacity}:o)};case"START_DRAWING":return{...t,drawing:{active:!0,points:[s.point],preview:null}};case"ADD_DRAWING_POINT":return{...t,drawing:{...t.drawing,points:[...t.drawing.points,s.point]}};case"UPDATE_DRAWING_PREVIEW":return{...t,drawing:{...t.drawing,preview:s.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:s.sourceId,sourcePort:s.sourcePort,sourcePosition:s.sourcePosition,previewPosition:s.sourcePosition}};case"UPDATE_CONNECTING_PREVIEW":return{...t,connecting:{...t.connecting,previewPosition:s.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:s.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=s.object.layer||"devices",a=yt(t.document,t.activeFloorId,o,s.object),i=Xe("create",[s.object.id],null,s.object);return{...t,document:a,...Ke(t,i)}}case"UPDATE_OBJECT":{if(!t.document)return t;const o=Fe(t.document,s.objectId);if(!o)return t;const a=_t(t.document,s.objectId,s.updates),i=Xe("update",[s.objectId],o,{...o,...s.updates});return{...t,document:a,...Ke(t,i)}}case"DELETE_OBJECTS":{if(!t.document||s.objectIds.length===0)return t;const o=s.objectIds.map(c=>Fe(t.document,c)).filter(Boolean),a=gt(t.document,s.objectIds),i=Xe("delete",s.objectIds,o,null);return{...t,document:a,selection:{objectIds:[],bounds:null,locked:!1},...Ke(t,i)}}case"MOVE_OBJECTS":{if(!t.document||s.objectIds.length===0)return t;const o=s.objectIds.map(r=>Fe(t.document,r)).filter(Boolean);let a=t.document;for(const r of s.objectIds){const l=Fe(a,r);if(l&&"transform"in l&&l.transform&&"position"in l.transform){const y=l.transform.position;a=_t(a,r,{transform:{...l.transform,position:{x:y.x+s.delta.x,y:y.y+s.delta.y}}})}}const i=s.objectIds.map(r=>Fe(a,r)).filter(Boolean),c=Xe("move",s.objectIds,o,i);return{...t,document:a,...Ke(t,c)}}case"UNDO":{if(t.history.past.length===0||!t.document)return t;const o=t.history.past[t.history.past.length-1];let a=t.document;switch(o.type){case"create":{a=gt(a,o.objectIds);break}case"delete":{const i=o.before;for(const c of i){const r=c.layer||"devices";a=yt(a,t.activeFloorId??a.floors[0].id,r,c)}break}case"update":case"move":{const i=o.before;for(const c of i)a=_t(a,c.id,c);break}}return{...t,document:a,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 a=t.document;switch(o.type){case"create":{const i=o.after,c=i.layer||"devices";a=yt(a,t.activeFloorId??a.floors[0].id,c,i);break}case"delete":{a=gt(a,o.objectIds);break}case"update":case"move":{const i=o.after;for(const c of i)a=_t(a,c.id,c);break}}return{...t,document:a,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(a=>Fe(t.document,a)).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=>Fe(t.document,c)).filter(Boolean),a=gt(t.document,t.selection.objectIds),i=Xe("delete",t.selection.objectIds,o,null);return{...t,document:a,clipboard:o,selection:{objectIds:[],bounds:null,locked:!1},...Ke(t,i)}}case"PASTE":{if(!t.document||!t.activeFloorId||t.clipboard.length===0)return t;let o=t.document;const a=[],i=[];for(const r of t.clipboard){const l=`${r.id}-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,y=r.transform,d={position:{x:y.position.x+s.position.x+20,y:y.position.y+s.position.y+20},rotation:y.rotation,scale:y.scale},x={...r,id:l,transform:d},f=x.layer||"devices";o=yt(o,t.activeFloorId,f,x),a.push(l),i.push(x)}const c=Xe("create",a,null,i);return{...t,document:o,selection:{objectIds:a,bounds:null,locked:!1},...Ke(t,c)}}case"START_DRAG":return{...t,dragging:{objectType:s.objectType,objectData:s.objectData,position:null}};case"UPDATE_DRAG_POSITION":return t.dragging?{...t,dragging:{...t.dragging,position:s.position}}:t;case"END_DRAG":return{...t,dragging:null};case"CANCEL_DRAG":return{...t,dragging:null};default:return t}}const fd=({mode:t,activeTool:s,onToolSelect:n,readOnly:o})=>{const i=Qe[t].tools.map(r=>xt[r]).filter(Boolean),c=["select","draw","place","connect","annotate","measure","edit"];return e.jsx("div",{className:F.toolbar,children:c.map(r=>{const l=i.filter(y=>y.group===r);return l.length===0?null:e.jsx("div",{className:F.toolGroup,children:l.map(({tool:y,icon:d,label:x,shortcut:f})=>e.jsx("button",{title:`${x}${f?` (${f})`:""}`,className:`${F.toolBtn} ${s===y?F.toolBtnActive:""}`,onClick:()=>n(y),disabled:o&&!["select","pan","zoom","measure-distance","measure-angle","measure-area"].includes(y),children:e.jsx(S.NiceIcon,{name:d,size:16})},y))},r)})})},_d=({currentMode:t,availableModes:s,onModeChange:n})=>e.jsx("div",{className:F.modeSwitcher,children:s.map(o=>{const a=Qe[o];return e.jsxs("button",{title:a.label,className:`${F.modeBtn} ${t===o?F.modeBtnActive:""}`,onClick:()=>n(o),children:[e.jsx("span",{className:F.modeIcon,children:e.jsx(S.NiceIcon,{name:a.icon,size:16})}),e.jsx("span",{className:F.modeLabel,children:a.label})]},o)})});function cs(t){if(!t)return[];const s=[];for(const n of t.floors)for(const o of n.layers)if(o.type==="network"||o.type==="infrastructure"){for(const a of o.objects)if(a.type==="connection"){const i=a.metadata;i!=null&&i.sourceId&&(i!=null&&i.targetId)&&s.push({id:a.id,sourceId:i.sourceId,sourcePort:i.sourcePort,targetId:i.targetId,targetPort:i.targetPort,medium:i.medium??"ethernet-cat6",status:i.status??"unknown",bandwidth:i.bandwidth,latency:i.latency??1,waypoints:i.waypoints??[]})}}return s}function gd(t){if(!t)return[];const s=[],n=new Set;for(const o of t.floors)for(const a of o.layers)if(a.type==="network"||a.type==="infrastructure")for(const i of a.objects){const c=i.metadata;if((c==null?void 0:c.vlanId)!==void 0&&!n.has(c.vlanId))n.add(c.vlanId),s.push({id:c.vlanId,name:c.vlanName??`VLAN ${c.vlanId}`,color:c.vlanColor??yd(c.vlanId),deviceIds:[i.id],subnet:c.subnet,gateway:c.gateway,dhcpEnabled:c.dhcpEnabled});else if((c==null?void 0:c.vlanId)!==void 0){const r=s.find(l=>l.id===c.vlanId);r&&!r.deviceIds.includes(i.id)&&r.deviceIds.push(i.id)}}return s.sort((o,a)=>o.id-a.id)}function yd(t){const s=["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 s[t%s.length]}const bd=[{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"}],xd=t=>{var Ut,Yt;const{defaultMode:s="floor-plan",availableModes:n=Object.keys(Qe),readOnly:o=!1,theme:a="light",locale:i="en",onDocumentChange:c,onSelectionChange:r,onModeChange:l,onExport:y,onImport:d,tutorial:x,className:f,style:p,cookies:_=!1,localStorage:j=!0,sessionStorage:h=!1,storageMode:k,storageKey:C,persistPreferences:T=!1}=t,{t:b}=S.useNiceTranslation(),L=S.useStorageAdapter(C??"nice-spatial-editor"),[u]=m.useState(()=>T?L.get("prefs")??{}:{}),[v,g]=m.useReducer(pd,t,hd),q=m.useRef(null),I=m.useRef(!1),B=m.useRef({x:0,y:0}),[V,te]=m.useState(!1),[ue,Q]=m.useState(!1),[fe,se]=m.useState(null),[ge,ze]=m.useState(null),[Re,Te]=m.useState(!1),[Be,Ee]=m.useState(!1),[M,X]=m.useState(!1),[he,ke]=m.useState(new Set),[Oe,je]=m.useState(null),Pe=m.useRef(null),Se=m.useRef(null),Ie=m.useRef(null),{mode:Ne,tool:me,document:ie,activeFloorId:qe,layers:Ce,selection:ve,viewport:ce,drawing:pe,connecting:ne,guides:We,ui:Ae,history:et}=v,Ve=Qe[Ne],rt=et.past.length>0,tt=et.future.length>0;m.useEffect(()=>{var N,R,D;!T||!u||((u.zoom||u.pan)&&g({type:"SET_VIEWPORT",viewport:{zoom:u.zoom,pan:u.pan,showGrid:(N=u.gridConfig)==null?void 0:N.visible,gridSize:(R=u.gridConfig)==null?void 0:R.size,snapEnabled:(D=u.gridConfig)==null?void 0:D.snapEnabled}}),u.mode&&g({type:"SET_MODE",mode:u.mode}),u.tool&&g({type:"SET_TOOL",tool:u.tool}),u.layerVisibility&&Object.entries(u.layerVisibility).forEach(([G,K])=>{K!==void 0&&g({type:"SET_LAYER_VISIBILITY",layerType:G,visible:K})}))},[]),m.useEffect(()=>{if(!T)return;const N={zoom:ce.zoom,pan:ce.pan,gridConfig:{size:ce.gridSize,visible:ce.showGrid,snapEnabled:ce.snapEnabled},mode:Ne,tool:me,layerVisibility:Object.fromEntries(Ce.map(R=>[R.type,R.visible])),uiPanels:Ae};L.set("prefs",N)},[T,ce,Ne,me,Ce,Ae,L]);const ye=m.useMemo(()=>(ie==null?void 0:ie.floors.find(N=>N.id===qe))??(ie==null?void 0:ie.floors[0])??null,[ie,qe]),De=m.useCallback((N,R)=>{var G;const D=(G=q.current)==null?void 0:G.getBoundingClientRect();return D?{x:(N-D.left-ce.pan.x)/ce.zoom,y:(R-D.top-ce.pan.y)/ce.zoom}:{x:0,y:0}},[ce.pan,ce.zoom]),He=m.useCallback(N=>{if(!ce.snapEnabled)return N;const R={cellSize:ce.gridSize,origin:{x:0,y:0},visible:ce.showGrid};return Vt(N,R)},[ce.snapEnabled,ce.gridSize,ce.showGrid]),It=m.useCallback(N=>{if(me==="pan"||N.button===1){I.current=!0,B.current={x:N.clientX,y:N.clientY};return}const R=He(De(N.clientX,N.clientY));if(me==="draw-zone"||me==="draw-wall"||me==="draw-polyline")pe.active?g({type:"ADD_DRAWING_POINT",point:R}):g({type:"START_DRAWING",point:R});else if(me==="connect"){const D=ye==null?void 0:ye.layers.flatMap(G=>G.objects).find(G=>{if(!G.bounds)return!1;const K=G.bounds;return R.x>=K.x&&R.x<=K.x+K.width&&R.y>=K.y&&R.y<=K.y+K.height});if(D)if(ne.active){g({type:"FINISH_CONNECTING",targetId:D.id});const G=`conn-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,K=D.bounds?{x:D.bounds.x+D.bounds.width/2,y:D.bounds.y+D.bounds.height/2}:R,J={id:G,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(ne.sourcePosition.x,K.x),y:Math.min(ne.sourcePosition.y,K.y),width:Math.abs(K.x-ne.sourcePosition.x),height:Math.abs(K.y-ne.sourcePosition.y)},metadata:{sourceId:ne.sourceId,targetId:D.id,sourcePosition:ne.sourcePosition,targetPosition:K,medium:"ethernet-cat6",status:"active"}};g({type:"ADD_OBJECT",object:J})}else{const G=D.bounds?{x:D.bounds.x+D.bounds.width/2,y:D.bounds.y+D.bounds.height/2}:R;g({type:"START_CONNECTING",sourceId:D.id,sourcePosition:G})}else ne.active&&g({type:"CANCEL_CONNECTING"})}else me==="select"&&g({type:"CLEAR_SELECTION"})},[me,pe.active,ne.active,ne.sourceId,ne.sourcePosition,He,De,ye]),Ct=m.useCallback(N=>{if(I.current){const D=N.clientX-B.current.x,G=N.clientY-B.current.y;g({type:"PAN",delta:{x:D,y:G}}),B.current={x:N.clientX,y:N.clientY};return}const R=He(De(N.clientX,N.clientY));if(pe.active&&(g({type:"UPDATE_DRAWING_PREVIEW",point:R}),ce.snapEnabled&&ye)){const D=ye.layers.flatMap(J=>J.objects.filter(le=>le.bounds).map(le=>({id:le.id,bounds:le.bounds}))),G={x:R.x,y:R.y,width:1,height:1},K=vs(G,D,10);g({type:"SET_GUIDES",guides:K})}ne.active&&g({type:"UPDATE_CONNECTING_PREVIEW",position:R})},[pe.active,ne.active,He,De,ce.snapEnabled,ye]),St=m.useCallback(()=>{I.current=!1},[]),Lt=m.useCallback(N=>{pe.active&&pe.points.length>=2&&g({type:"FINISH_DRAWING"})},[pe.active,pe.points.length]),Tt=m.useCallback(N=>{N.preventDefault();const R=N.deltaY>0?-1:1;g({type:"ZOOM",delta:R,center:De(N.clientX,N.clientY)})},[De]),$t=m.useCallback(N=>{N.key==="Escape"&&(pe.active?g({type:"CANCEL_DRAWING"}):ne.active?g({type:"CANCEL_CONNECTING"}):g({type:"CLEAR_SELECTION"})),N.key==="Delete"&&ve.objectIds.length>0&&g({type:"DELETE_OBJECTS",objectIds:ve.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"}))},[pe.active,ne.active,ve.objectIds]),zt=m.useCallback(N=>{g({type:"SET_MODE",mode:N}),l==null||l(N)},[l]),Mt=m.useCallback(N=>{g({type:"SET_TOOL",tool:N})},[]),Ue=m.useCallback(async N=>{var R;if(ie){te(!1);try{const D={includeGrid:!1,includeDimensions:!0};if(N==="nsp"){const G=Kn(ie,D);pt(G),y==null||y(N,G.data)}else if(N==="svg"){const G=Qn(ie,D);pt(G),y==null||y(N,G.data)}else if(N==="dxf"){const G=so(ie,D);pt(G),y==null||y(N,G.data)}else if(N==="png"&&q.current){const G=await io(q.current,((R=ie.metadata)==null?void 0:R.name)||"export");pt(G),y==null||y(N,G.data)}}catch(D){console.error(`Export to ${N} failed:`,D)}}},[ie,y]),Bt=m.useCallback(async N=>{var D;const R=(D=N.target.files)==null?void 0:D[0];if(R){Q(!1);try{const K=await bo(R,{convertClosedPolylinesToZones:!0,minZoneArea:1});K.success&&K.document?ze(K):se(K),Ie.current&&(Ie.current.value="")}catch(G){console.error("Import failed:",G),se({success:!1,warnings:[],errors:[{code:"IMPORT_ERROR",message:G instanceof Error?G.message:"Unknown import error",fatal:!0}],stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:0}})}}},[]),Et=m.useCallback(()=>{ge!=null&&ge.success&&ge.document?Te(!0):ze(null)},[ge]),ct=m.useCallback(()=>{ze(null),Te(!1)},[]),w=m.useCallback((N,R)=>{if(!(ge!=null&&ge.document)){Te(!1);return}const D=ge.document,G={...D,floors:D.floors.map(K=>({...K,layers:K.layers.filter(J=>N.get(J.id)!=="skip").map(J=>{const le=N.get(J.id);if(le===J.id||!le)return J;const $e=ie==null?void 0:ie.floors.flatMap(Ye=>Ye.layers).find(Ye=>Ye.id===le);return $e?{...J,id:$e.id,name:$e.name,type:$e.type}:J})}))};g({type:"SET_DOCUMENT",document:G}),d==null||d(G),se(ge),Te(!1),ze(null)},[ge,ie,d]),$=m.useCallback(()=>{Te(!1)},[]),E=m.useCallback(N=>{if(Ie.current){let R=".dxf,.svg,.geojson,.json,.ifc";N==="dxf"?R=".dxf":N==="svg"?R=".svg":N==="geojson"?R=".geojson,.json":N==="ifc"&&(R=".ifc"),Ie.current.accept=R,Ie.current.click()}Q(!1)},[]);m.useEffect(()=>{const N=R=>{Pe.current&&!Pe.current.contains(R.target)&&te(!1),Se.current&&!Se.current.contains(R.target)&&Q(!1)};return(V||ue)&&document.addEventListener("mousedown",N),()=>{document.removeEventListener("mousedown",N)}},[V,ue]);const ee=m.useCallback(()=>{var K,J;if(!ce.showGrid||!ye)return null;const N=[],{gridSize:R}=ce,D=((K=ye.bounds)==null?void 0:K.width)??1e3,G=((J=ye.bounds)==null?void 0:J.height)??800;for(let le=0;le<=D;le+=R)N.push(e.jsx("line",{x1:le,y1:0,x2:le,y2:G,className:F.gridLine},`v${le}`));for(let le=0;le<=G;le+=R)N.push(e.jsx("line",{x1:0,y1:le,x2:D,y2:le,className:F.gridLine},`h${le}`));return e.jsx("g",{className:F.grid,children:N})},[ce.showGrid,ce.gridSize,ye]),H=m.useCallback(()=>{if(!ye)return null;const N=ye.layers.find(R=>R.name==="zones");return N?e.jsx("g",{className:F.zonesLayer,children:N.objects.map(R=>{const D=R;if(!D.boundary||D.boundary.length<3)return null;const G=D.boundary.map((le,$e)=>`${$e===0?"M":"L"}${le.x},${le.y}`).join(" ")+" Z",K=ve.objectIds.includes(D.id),J=D.boundary.reduce((le,$e)=>({x:le.x+$e.x/D.boundary.length,y:le.y+$e.y/D.boundary.length}),{x:0,y:0});return e.jsxs("g",{className:F.zone,onClick:le=>{le.stopPropagation(),g({type:"SET_SELECTION",selection:{objectIds:[D.id],bounds:null,locked:!1}})},children:[e.jsx("path",{d:G,fill:D.color??"var(--nice-primary-bg, #dbeafe)",fillOpacity:.5,stroke:K?"var(--nice-primary-hover, #2563eb)":"var(--nice-text-muted, #94a3b8)",strokeWidth:K?2:1}),D.name&&e.jsx("text",{x:J.x,y:J.y,textAnchor:"middle",dominantBaseline:"middle",className:F.zoneLabel,children:D.name})]},D.id)})}):null},[ye,ve.objectIds]),de=m.useCallback(()=>We.length===0?null:e.jsx("g",{className:F.guides,children:We.map((N,R)=>e.jsx("line",{x1:N.start.x,y1:N.start.y,x2:N.end.x,y2:N.end.y,className:F.guideLine},R))}),[We]),_e=m.useCallback(()=>{if(!pe.active||pe.points.length===0)return null;const N=[...pe.points];pe.preview&&N.push(pe.preview);const R=N.map((G,K)=>`${K===0?"M":"L"}${G.x},${G.y}`).join(" "),D=me==="draw-zone"&&N.length>2;return e.jsxs("g",{className:F.drawingPreview,children:[e.jsx("path",{d:R+(D?" Z":""),fill:D?"var(--nice-primary-tint-10, rgba(37, 99, 235, 0.1))":"none",stroke:"var(--nice-primary-hover, #2563eb)",strokeWidth:2,strokeDasharray:D?"none":"6,3"}),N.map((G,K)=>e.jsx("circle",{cx:G.x,cy:G.y,r:4,fill:"var(--nice-primary-hover, #2563eb)"},K))]})},[pe,me]),Me=m.useCallback(()=>!ne.active||!ne.sourcePosition||!ne.previewPosition?null:e.jsxs("g",{className:F.connectionPreview,children:[e.jsx("line",{x1:ne.sourcePosition.x,y1:ne.sourcePosition.y,x2:ne.previewPosition.x,y2:ne.previewPosition.y,stroke:"var(--nice-success, #10b981)",strokeWidth:2,strokeDasharray:"8,4",markerEnd:"url(#connectionArrow)"}),e.jsx("circle",{cx:ne.sourcePosition.x,cy:ne.sourcePosition.y,r:6,fill:"var(--nice-success, #10b981)"}),e.jsx("circle",{cx:ne.previewPosition.x,cy:ne.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)"})})})]}),[ne]),lt=m.useCallback(()=>{if(!ye)return null;const N=ye.layers.find(K=>K.type==="network");if(!N)return null;const R=N.objects.filter(K=>K.type==="connection");if(R.length===0)return null;const D={"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}},G={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:R.map(K=>{const J=K.metadata;if(!(J!=null&&J.sourcePosition)||!(J!=null&&J.targetPosition))return null;const le=D[J.medium??"default"]||D.default,$e=G[J.status??"unknown"]||G.unknown,Ye=ve.objectIds.includes(K.id);let Pt=`M${J.sourcePosition.x},${J.sourcePosition.y}`;if(J.waypoints&&J.waypoints.length>0)for(const dt of J.waypoints)Pt+=` L${dt.x},${dt.y}`;return Pt+=` L${J.targetPosition.x},${J.targetPosition.y}`,e.jsxs("g",{className:F.connection,onClick:dt=>{dt.stopPropagation(),g({type:"SET_SELECTION",selection:{objectIds:[K.id],bounds:null,locked:!1}})},children:[e.jsx("path",{d:Pt,fill:"none",stroke:Ye?"var(--nice-primary-hover, #2563eb)":le.color,strokeWidth:Ye?le.width+1:le.width,strokeDasharray:le.dashArray,strokeLinecap:"round",strokeLinejoin:"round"}),J.status&&J.status!=="active"&&e.jsx("circle",{cx:(J.sourcePosition.x+J.targetPosition.x)/2,cy:(J.sourcePosition.y+J.targetPosition.y)/2,r:5,fill:$e}),e.jsx("circle",{cx:J.sourcePosition.x,cy:J.sourcePosition.y,r:4,fill:le.color,stroke:"white",strokeWidth:1}),e.jsx("circle",{cx:J.targetPosition.x,cy:J.targetPosition.y,r:4,fill:le.color,stroke:"white",strokeWidth:1})]},K.id)})})},[ye,ve.objectIds]);if(!ie&&!ye)return e.jsx("div",{className:`${F.root} ${F[a]} ${f??""}`,style:p,children:e.jsxs("div",{className:F.emptyState,children:[e.jsx("div",{className:F.emptyIcon,children:e.jsx(S.NiceIcon,{name:Ve.icon,size:48})}),e.jsx("h3",{children:"No Document Open"}),e.jsx("p",{children:"Create a new document or open an existing .nsp.json file"}),e.jsx("button",{className:F.primaryBtn,onClick:()=>{const N=Ht("New Project","floor-plan");g({type:"SET_DOCUMENT",document:N})},children:"Create New Document"})]})});const Ms=e.jsxs("div",{className:F.topBar,children:[e.jsx(_d,{currentMode:Ne,availableModes:n,onModeChange:zt}),ie&&ie.floors.length>1&&e.jsx("div",{className:F.floorTabs,children:ie.floors.map(N=>e.jsx("button",{className:`${F.floorTab} ${qe===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:"Undo (Ctrl+Z)",onClick:()=>g({type:"UNDO"}),disabled:!rt,className:rt?"":F.disabled,children:e.jsx(S.NiceIcon,{name:"reply",size:16})}),e.jsx("button",{title:"Redo (Ctrl+Y)",onClick:()=>g({type:"REDO"}),disabled:!tt,className:tt?"":F.disabled,children:e.jsx(S.NiceIcon,{name:"forward",size:16})}),e.jsx("div",{className:F.separator})]}),e.jsx("button",{title:"Toggle Grid",onClick:()=>g({type:"TOGGLE_GRID"}),className:ce.showGrid?F.active:"",children:e.jsx(S.NiceIcon,{name:"grid",size:16})}),e.jsx("button",{title:"Toggle Snap",onClick:()=>g({type:"TOGGLE_SNAP"}),className:ce.snapEnabled?F.active:"",children:e.jsx(S.NiceIcon,{name:"target",size:16})}),e.jsxs("span",{className:F.zoomLevel,children:[Math.round(ce.zoom*100),"%"]}),e.jsx("button",{title:"Zoom In",onClick:()=>g({type:"ZOOM",delta:1}),children:e.jsx(S.NiceIcon,{name:"plus",size:16})}),e.jsx("button",{title:"Zoom Out",onClick:()=>g({type:"ZOOM",delta:-1}),children:e.jsx(S.NiceIcon,{name:"minus",size:16})}),e.jsx("button",{title:"Reset View",onClick:()=>g({type:"RESET_VIEW"}),children:e.jsx(S.NiceIcon,{name:"expand",size:16})}),!o&&e.jsxs("div",{className:F.exportDropdown,ref:Se,children:[e.jsx("input",{type:"file",ref:Ie,onChange:Bt,style:{display:"none"}}),e.jsxs("button",{title:"Import",onClick:()=>Q(!ue),className:ue?F.active:"",children:[e.jsx(S.NiceIcon,{name:"download",size:14})," Import"]}),ue&&e.jsxs("div",{className:F.exportMenu,children:[e.jsxs("button",{onClick:()=>E(),children:[e.jsx(S.NiceIcon,{name:"file",size:14})," Auto-detect format"]}),e.jsxs("button",{onClick:()=>E("dxf"),children:[e.jsx(S.NiceIcon,{name:"ruler",size:14})," AutoCAD DXF (.dxf)"]}),e.jsxs("button",{onClick:()=>E("svg"),children:[e.jsx(S.NiceIcon,{name:"image",size:14})," SVG Vector Graphics (.svg)"]}),e.jsxs("button",{onClick:()=>E("geojson"),children:[e.jsx(S.NiceIcon,{name:"globe",size:14})," GeoJSON (.geojson)"]}),e.jsxs("button",{onClick:()=>E("ifc"),children:[e.jsx(S.NiceIcon,{name:"building",size:14})," IFC (BIM) (.ifc)"]})]})]}),ie&&e.jsxs("div",{className:F.exportDropdown,ref:Pe,children:[e.jsxs("button",{title:"Export",onClick:()=>te(!V),className:V?F.active:"",children:[e.jsx(S.NiceIcon,{name:"upload",size:14})," Export"]}),V&&e.jsxs("div",{className:F.exportMenu,children:[e.jsxs("button",{onClick:()=>Ue("nsp"),children:[e.jsx(S.NiceIcon,{name:"file",size:14})," NiceToDev Spatial Plan (.nsp.json)"]}),e.jsxs("button",{onClick:()=>Ue("svg"),children:[e.jsx(S.NiceIcon,{name:"image",size:14})," SVG Vector Graphics (.svg)"]}),e.jsxs("button",{onClick:()=>Ue("dxf"),children:[e.jsx(S.NiceIcon,{name:"ruler",size:14})," AutoCAD DXF (.dxf)"]}),e.jsxs("button",{onClick:()=>Ue("png"),children:[e.jsx(S.NiceIcon,{name:"image",size:14})," PNG Image (.png)"]})]})]})]})]}),Bs=Ae.showObjectLibrary&&!o?e.jsx(Cs,{mode:Ne,onObjectSelect:N=>{g({type:"SET_TOOL",tool:`place-${N.category}`}),g({type:"START_DRAG",objectType:N.category,objectData:N})}}):void 0,Es=e.jsxs("div",{className:F.editorContainer,children:[!o&&e.jsx(fd,{mode:Ne,activeTool:me,onToolSelect:Mt,readOnly:o}),(Ne==="network-topology"||Ne==="infrastructure")&&e.jsxs("div",{className:F.modeActions,children:[e.jsxs("button",{className:`${F.actionBtn} ${Be?F.active:""}`,onClick:()=>Ee(!Be),title:b("buildings.spatial.pathAnalysis","Network path analysis"),children:[e.jsx(S.NiceIcon,{name:"bar-chart",size:14})," ",b("buildings.spatial.path","Path")]}),e.jsxs("button",{className:`${F.actionBtn} ${M?F.active:""}`,onClick:()=>X(!M),title:b("buildings.spatial.vlan.title","VLAN overlay"),children:[e.jsx(S.NiceIcon,{name:"globe",size:14})," VLAN Overlay"]})]}),e.jsxs("div",{className:F.canvasWrapper,children:[e.jsx("svg",{ref:q,className:`${F.canvas} ${F[`cursor_${me.replace("-","_")}`]??""}`,onMouseDown:It,onMouseMove:Ct,onMouseUp:St,onDoubleClick:Lt,onWheel:Tt,children:e.jsxs("g",{transform:`translate(${ce.pan.x}, ${ce.pan.y}) scale(${ce.zoom})`,children:[ee(),H(),lt(),de(),_e(),Me()]})}),Ae.showMinimap&&e.jsx(Is,{document:ie,activeFloorId:qe,viewport:ce,onViewportChange:N=>g({type:"SET_VIEWPORT",viewport:N})})]})]}),Ps=e.jsxs("div",{className:F.rightSidebar,children:[Ae.showLayerPanel&&e.jsx(ks,{layers:Ce.filter(N=>Ve.layerTypes.includes(N.type)),onVisibilityToggle:N=>{var R;return g({type:"SET_LAYER_VISIBILITY",layerType:N,visible:!((R=Ce.find(D=>D.type===N))!=null&&R.visible)})},onLockToggle:N=>{var R;return g({type:"SET_LAYER_LOCKED",layerType:N,locked:!((R=Ce.find(D=>D.type===N))!=null&&R.locked)})},onOpacityChange:(N,R)=>g({type:"SET_LAYER_OPACITY",layerType:N,opacity:R})}),Ae.showPropertiesPanel&&ve.objectIds.length>0&&e.jsx(Ss,{selection:ve,document:ie,onPropertyChange:(N,R,D)=>{g({type:"UPDATE_OBJECT",objectId:N,updates:{[R]:D}})}})]}),As=e.jsxs("div",{className:F.statusBar,children:[e.jsxs("span",{className:F.modeIndicator,children:[e.jsx(S.NiceIcon,{name:Ve.icon,size:14})," ",Ve.label]}),e.jsxs("span",{className:F.toolIndicator,children:[((Ut=xt[me])==null?void 0:Ut.icon)&&e.jsx(S.NiceIcon,{name:xt[me].icon,size:14})," ",(Yt=xt[me])==null?void 0:Yt.label]}),ve.objectIds.length>0&&e.jsxs("span",{className:F.selectionInfo,children:[ve.objectIds.length," selected"]}),pe.active&&e.jsxs("span",{className:F.drawingInfo,children:["Drawing: ",pe.points.length," points"]}),ne.active&&e.jsx("span",{className:F.connectingInfo,children:"Connecting: click target device or ESC to cancel"}),e.jsxs("span",{className:F.gridInfo,children:["Grid: ",ce.gridSize,"px | Snap: ",ce.snapEnabled?"ON":"OFF"]})]});return e.jsxs("div",{className:`nice-spatial-editor ${F.root} ${F[a]} ${f??""}`,style:{position:"relative",...p},tabIndex:0,onKeyDown:$t,children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:e.jsx(S.NiceTutorialButton,{steps:S.resolveTutorial(x,bd)})}),e.jsx(S.NiceAppShell,{flush:!0,className:F.shell,menubar:Ms,sidebar:Bs,rightSidebar:Ps,statusBar:As,children:Es}),ge&&!Re&&e.jsx(aa,{result:ge,onConfirm:Et,onCancel:ct}),ge&&Re&&e.jsx(Ba,{importResult:ge,existingDocument:ie??void 0,onConfirm:w,onCancel:$}),Be&&ie&&e.jsx(Ui,{document:ie,connections:cs(ie),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:()=>Ee(!1)}),M&&ie&&e.jsx(Dc,{document:ie,connections:cs(ie),vlans:gd(ie),visibleVlanIds:he,onVlanVisibilityChange:(N,R)=>{ke(D=>{const G=new Set(D);return R?G.add(N):G.delete(N),G})},onHighlightVlan:N=>{je((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:()=>X(!1)})]})},vd="_viewer_nyfnl_13",jd="_theme_light_nyfnl_37",wd="_theme_dark_nyfnl_59",Nd="_debugOverlay_nyfnl_85",kd="_topBar_nyfnl_137",Id="_searchContainer_nyfnl_159",Cd="_searchInput_nyfnl_171",Sd="_clearBtn_nyfnl_227",Ld="_searchResults_nyfnl_261",Td="_searchResultItem_nyfnl_291",$d="_searchResultInfo_nyfnl_335",zd="_searchResultName_nyfnl_347",Md="_searchResultDesc_nyfnl_357",Bd="_floorSelector_nyfnl_371",Ed="_navBtn_nyfnl_421",Pd="_active_nyfnl_459",Ad="_layersBtn_nyfnl_475",Od="_legendBtn_nyfnl_529",Dd="_content_nyfnl_583",Rd="_navPanel_nyfnl_599",qd="_navPanelHeader_nyfnl_617",Fd="_routeInputs_nyfnl_671",Gd="_routeInput_nyfnl_671",Wd="_routeMarker_nyfnl_705",Vd="_routeHint_nyfnl_745",Hd="_routeInfo_nyfnl_761",Ud="_routeStat_nyfnl_779",Yd="_routeStatLabel_nyfnl_791",Zd="_routeStatValue_nyfnl_805",Xd="_clearRouteBtn_nyfnl_817",Kd="_refPointsList_nyfnl_851",Jd="_refPointItem_nyfnl_879",Qd="_refPointIcon_nyfnl_917",eu="_layersPanel_nyfnl_929",tu="_layersPanelHeader_nyfnl_947",su="_layersList_nyfnl_1001",nu="_layerItem_nyfnl_1015",ou="_layerToggle_nyfnl_1039",au="_layerName_nyfnl_1075",iu="_layerType_nyfnl_1087",ru="_canvasWrapper_nyfnl_1101",cu="_canvas_nyfnl_1101",lu="_grid_nyfnl_1137",du="_gridLine_nyfnl_1145",uu="_zonesLayer_nyfnl_1161",mu="_zone_nyfnl_1161",hu="_zoneSelected_nyfnl_1187",pu="_zoneLabel_nyfnl_1197",fu="_objectsLayer_nyfnl_1213",_u="_object_nyfnl_1213",gu="_objectSelected_nyfnl_1237",yu="_objectLabel_nyfnl_1245",bu="_referencePoints_nyfnl_1261",xu="_referencePoint_nyfnl_1261",vu="_refLabel_nyfnl_1283",ju="_routeLayer_nyfnl_1299",wu="_routePath_nyfnl_1305",Nu="_routeDash_nyfnl_1",ku="_routeMarkers_nyfnl_1331",Iu="_currentLocation_nyfnl_1341",Cu="_locationPulse_nyfnl_1347",Su="_pulse_nyfnl_1",Lu="_zoomControls_nyfnl_1383",Tu="_minimap_nyfnl_1459",$u="_minimapContent_nyfnl_1485",zu="_minimapViewport_nyfnl_1499",Mu="_legendPanel_nyfnl_1519",Bu="_legendPanelHeader_nyfnl_1551",Eu="_legendList_nyfnl_1607",Pu="_legendItem_nyfnl_1623",Au="_legendColor_nyfnl_1647",Ou="_legendIcon_nyfnl_1663",Du="_legendLabel_nyfnl_1677",Ru="_legendType_nyfnl_1689",qu="_objectInfo_nyfnl_1707",Fu="_objectInfoHeader_nyfnl_1735",Gu="_navigateBtn_nyfnl_1805",z={viewer:vd,theme_light:jd,theme_dark:wd,debugOverlay:Nd,topBar:kd,searchContainer:Id,searchInput:Cd,clearBtn:Sd,searchResults:Ld,searchResultItem:Td,searchResultInfo:$d,searchResultName:zd,searchResultDesc:Md,floorSelector:Bd,navBtn:Ed,active:Pd,layersBtn:Ad,legendBtn:Od,content:Dd,navPanel:Rd,navPanelHeader:qd,routeInputs:Fd,routeInput:Gd,routeMarker:Wd,routeHint:Vd,routeInfo:Hd,routeStat:Ud,routeStatLabel:Yd,routeStatValue:Zd,clearRouteBtn:Xd,refPointsList:Kd,refPointItem:Jd,refPointIcon:Qd,layersPanel:eu,layersPanelHeader:tu,layersList:su,layerItem:nu,layerToggle:ou,layerName:au,layerType:iu,canvasWrapper:ru,canvas:cu,grid:lu,gridLine:du,zonesLayer:uu,zone:mu,zoneSelected:hu,zoneLabel:pu,objectsLayer:fu,object:_u,objectSelected:gu,objectLabel:yu,referencePoints:bu,referencePoint:xu,refLabel:vu,routeLayer:ju,routePath:wu,routeDash:Nu,routeMarkers:ku,currentLocation:Iu,locationPulse:Cu,pulse:Su,zoomControls:Lu,minimap:Tu,minimapContent:$u,minimapViewport:zu,legendPanel:Mu,legendPanelHeader:Bu,legendList:Eu,legendItem:Pu,legendColor:Au,legendIcon:Ou,legendLabel:Du,legendType:Ru,objectInfo:qu,objectInfoHeader:Fu,navigateBtn:Gu},Wu=()=>e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("circle",{cx:"7",cy:"7",r:"5"}),e.jsx("path",{d:"M11 11l3 3",strokeLinecap:"round"})]}),ls=()=>e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("path",{d:"M8 1l6 14-6-4-6 4 6-14z"})}),Vu=()=>e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("circle",{cx:"8",cy:"6",r:"3"}),e.jsx("path",{d:"M8 15c4-4 6-6.7 6-9a6 6 0 10-12 0c0 2.3 2 5 6 9z"})]}),Hu=()=>e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"2",y:"2",width:"12",height:"12",rx:"1"}),e.jsx("line",{x1:"2",y1:"6",x2:"14",y2:"6"}),e.jsx("line",{x1:"2",y1:"10",x2:"14",y2:"10"})]}),Uu=()=>e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("circle",{cx:"4",cy:"4",r:"2"}),e.jsx("circle",{cx:"12",cy:"12",r:"2"}),e.jsx("path",{d:"M6 4h4a2 2 0 012 2v4",strokeLinecap:"round"})]}),Yu=()=>e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("circle",{cx:"7",cy:"7",r:"5"}),e.jsx("path",{d:"M11 11l3 3M7 5v4M5 7h4",strokeLinecap:"round"})]}),Zu=()=>e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("circle",{cx:"7",cy:"7",r:"5"}),e.jsx("path",{d:"M11 11l3 3M5 7h4",strokeLinecap:"round"})]}),nt=()=>e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("path",{d:"M12 4L4 12M4 4l8 8",strokeLinecap:"round"})}),ds=()=>e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("path",{d:"M2 6l6-4 6 4-6 4-6-4z"}),e.jsx("path",{d:"M2 10l6 4 6-4"}),e.jsx("path",{d:"M2 8l6 4 6-4",opacity:"0.5"})]}),us=()=>e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"2",y:"3",width:"4",height:"3",rx:"0.5",fill:"currentColor",opacity:"0.3"}),e.jsx("rect",{x:"2",y:"8",width:"4",height:"3",rx:"0.5",fill:"currentColor",opacity:"0.3"}),e.jsx("line",{x1:"8",y1:"4.5",x2:"14",y2:"4.5"}),e.jsx("line",{x1:"8",y1:"9.5",x2:"14",y2:"9.5"})]}),Xu=()=>e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("path",{d:"M1 8c1.5-3 4-5 7-5s5.5 2 7 5c-1.5 3-4 5-7 5s-5.5-2-7-5z"}),e.jsx("circle",{cx:"8",cy:"8",r:"2"})]}),Ku=()=>e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("path",{d:"M6.5 6.5a2 2 0 012.8 2.8M3 3l10 10",strokeLinecap:"round"}),e.jsx("path",{d:"M4.5 5.5C2.8 6.8 1.5 8 1 8c1.5 3 4 5 7 5 1 0 2-.3 3-.7"}),e.jsx("path",{d:"M12.5 9.5c1-.9 2-2 2.5-3-1.5-3-4-5-7-5-.6 0-1.2.1-1.8.2"})]}),Ju={entrance:"door",elevator:"elevator",stairs:"stairs",exit:"bell",poi:"map-pin",parking:"map-pin"};function Ft(t){return t.icon??Ju[t.type]??"map-pin"}function Qu(t,s){return Math.sqrt((s.x-t.x)**2+(s.y-t.y)**2)}function em(t){return t<1?"<1m":t<1e3?`${Math.round(t)}m`:`${(t/1e3).toFixed(1)}km`}function tm(t){if(t<60)return"<1 min";const s=Math.round(t/60);if(s<60)return`${s} min`;const n=Math.floor(s/60),o=s%60;return`${n}h ${o}min`}const sm=Ht(""),nm=({document:t=sm,initialFloorId:s,showNavigation:n=!0,showMinimap:o=!0,showFloorSelector:a=!0,showSearch:i=!0,showLayersPanel:c=!0,showLegend:r=!0,enableRoutePlanning:l=!0,referencePoints:y=[],onObjectClick:d,onRouteCalculated:x,currentLocation:f,theme:p="light",className:_,virtualRendering:j,virtualRenderingThreshold:h=200,debugVirtualRendering:k=!1})=>{var ct;const{t:C}=S.useNiceTranslation(),[T,b]=m.useState(s??((ct=t.floors[0])==null?void 0:ct.id)??""),[L,u]=m.useState({zoom:1,pan:{x:0,y:0}}),[v,g]=m.useState(""),[q,I]=m.useState([]),[B,V]=m.useState(null),[te,ue]=m.useState(null),[Q,fe]=m.useState(null),[se,ge]=m.useState(null),[ze,Re]=m.useState(!1),[Te,Be]=m.useState(!1),[Ee,M]=m.useState(!1),[X,he]=m.useState(new Map),[ke,Oe]=m.useState({width:1e3,height:600}),je=m.useRef(null),Pe=m.useRef(null),Se=m.useRef(!1),Ie=m.useRef({x:0,y:0}),Ne=m.useMemo(()=>{const w=t.floors.find($=>$.id===T);return w?w.layers.reduce(($,E)=>{var ee;return $+(((ee=E.objects)==null?void 0:ee.length)??0)},0):0},[t.floors,T]),me=j??ko(Ne,h),ie=m.useMemo(()=>{if(!me)return null;const w=t.floors.find(E=>E.id===T);if(!w)return null;const $=[];for(const E of w.layers)if(!(E.type==="zones"||E.type==="grid"||E.type==="background"))for(const ee of E.objects??[]){const H=ee.position??{x:0,y:0},de=ee.size??{width:20,height:20};$.push({id:ee.id,position:H,size:de,data:{object:ee,layerId:E.id}})}return wo($)},[t.floors,T,me]),qe=m.useMemo(()=>No(L,ke,100),[L,ke]),Ce=m.useMemo(()=>!me||!ie?null:ie.query(qe),[me,ie,qe]),ve=m.useMemo(()=>!k||!me?null:Io(Ne,(Ce==null?void 0:Ce.length)??Ne,L),[k,me,Ne,Ce,L]);m.useEffect(()=>{const w=Pe.current;if(!w)return;const $=new ResizeObserver(E=>{for(const ee of E)Oe({width:ee.contentRect.width,height:ee.contentRect.height})});return $.observe(w),()=>$.disconnect()},[]),m.useEffect(()=>{const w=t.floors.find($=>$.id===T);if(w){const $=new Map;for(const E of w.layers)$.set(E.id,X.get(E.id)??!0);he($)}},[T,t.floors]);const ce=m.useCallback(w=>{he($=>{const E=new Map($);return E.set(w,!$.get(w)),E})},[]),pe=m.useCallback(w=>X.get(w)!==!1,[X]),ne=m.useMemo(()=>t.floors.find(w=>w.id===T)??t.floors[0],[t.floors,T]),We=m.useMemo(()=>{if(!ne)return[];const w=[],$=ne.layers.find(H=>H.type==="zones");if($){const H=new Map;for(const de of $.objects){const _e=de.metadata,Me=(_e==null?void 0:_e.zoneType)??de.type??"zone";H.has(Me)||H.set(Me,(_e==null?void 0:_e.fill)??"var(--nice-primary, #3b82f6)")}for(const[de,_e]of H)w.push({id:`zone-${de}`,label:de.charAt(0).toUpperCase()+de.slice(1).replace(/-/g," "),color:_e,type:"zone"})}const E=new Map;for(const H of ne.layers)if(!(H.type==="zones"||H.type==="grid"||H.type==="background"))for(const de of H.objects){const _e=de.type??"object",Me=E.get(_e);Me?Me.count++:E.set(_e,{count:1,color:"var(--nice-text-secondary, #64748b)"})}for(const[H,de]of E)w.push({id:`obj-${H}`,label:`${H.charAt(0).toUpperCase()+H.slice(1).replace(/-/g," ")} (${de.count})`,color:de.color,type:"object"});const ee=new Map;for(const H of y.filter(de=>de.floorId===T))ee.has(H.type)||ee.set(H.type,Ft(H));for(const[H,de]of ee)w.push({id:`ref-${H}`,label:H.charAt(0).toUpperCase()+H.slice(1),color:"var(--nice-primary, #3b82f6)",icon:de,type:"reference"});return w},[ne,y,T]),Ae=m.useCallback((w,$)=>{var ee;const E=(ee=je.current)==null?void 0:ee.getBoundingClientRect();return E?{x:(w-E.left-L.pan.x)/L.zoom,y:($-E.top-L.pan.y)/L.zoom}:{x:0,y:0}},[L]);m.useEffect(()=>{if(!v.trim()){I([]);return}const w=v.toLowerCase(),$=[];for(const E of t.floors)for(const ee of E.layers)for(const H of ee.objects){const de=(H.name??H.id).toLowerCase(),_e=(H.description??"").toLowerCase();(de.includes(w)||_e.includes(w))&&$.push(H)}I($.slice(0,10))},[v,t.floors]);const et=m.useCallback((w,$)=>{const E=Qu(w,$);return{id:`route-${Date.now()}`,startPoint:w,endPoint:$,path:[w,$],floorTransitions:[],totalDistance:E,estimatedTime:E/1.4,instructions:[{type:"straight",distance:E,direction:"forward"},{type:"arrive"}]}},[]);m.useEffect(()=>{if(te&&Q){const w=et(te,Q);ge(w),x==null||x(w)}else ge(null),x==null||x(null)},[te,Q,et,x]);const Ve=m.useCallback(w=>{(w.button===1||w.button===0&&w.altKey)&&(Se.current=!0,Ie.current={x:w.clientX,y:w.clientY},w.preventDefault())},[]),rt=m.useCallback(w=>{if(Se.current){const $=w.clientX-Ie.current.x,E=w.clientY-Ie.current.y;Ie.current={x:w.clientX,y:w.clientY},u(ee=>({...ee,pan:{x:ee.pan.x+$,y:ee.pan.y+E}}))}},[]),tt=m.useCallback(()=>{Se.current=!1},[]),ye=m.useCallback(w=>{var de;w.preventDefault();const $=w.deltaY>0?.9:1.1,E=(de=je.current)==null?void 0:de.getBoundingClientRect();if(!E)return;const ee=w.clientX-E.left,H=w.clientY-E.top;u(_e=>{const Me=Math.min(Math.max(_e.zoom*$,.1),10),lt=Me/_e.zoom;return{zoom:Me,pan:{x:ee-(ee-_e.pan.x)*lt,y:H-(H-_e.pan.y)*lt}}})},[]),De=m.useCallback(w=>{if(l&&w.ctrlKey){const $=Ae(w.clientX,w.clientY);te?Q?(ue($),fe(null)):fe($):ue($)}},[l,te,Q,Ae]),He=m.useCallback(()=>{u(w=>({...w,zoom:Math.min(w.zoom*1.25,10)}))},[]),It=m.useCallback(()=>{u(w=>({...w,zoom:Math.max(w.zoom/1.25,.1)}))},[]),Ct=m.useCallback(()=>{u({zoom:1,pan:{x:0,y:0}})},[]),St=m.useCallback(w=>{V(w);for(const E of t.floors)for(const ee of E.layers)if(ee.objects.find(H=>H.id===w.id)){b(E.id);break}const $=w.position??{x:0,y:0};u(E=>({...E,pan:{x:-($.x*E.zoom)+400,y:-($.y*E.zoom)+300}})),g(""),I([]),d==null||d(w)},[t.floors,d]),Lt=m.useCallback(()=>{ue(null),fe(null),ge(null)},[]),Tt=m.useCallback(()=>{const $=[];for(let E=-2e3;E<=2e3;E+=50)$.push(e.jsx("line",{x1:E,y1:-2e3,x2:E,y2:2e3,className:z.gridLine},`v-${E}`));for(let E=-2e3;E<=2e3;E+=50)$.push(e.jsx("line",{x1:-2e3,y1:E,x2:2e3,y2:E,className:z.gridLine},`h-${E}`));return e.jsx("g",{className:z.grid,children:$})},[]),$t=m.useCallback(()=>{if(!ne)return null;const w=ne.layers.find($=>$.type==="zones");return!w||!pe(w.id)?null:e.jsx("g",{className:z.zonesLayer,children:w.objects.map($=>{const E=$.metadata;if(!(E!=null&&E.points)||E.points.length<3)return null;const ee=`M${E.points.map(de=>`${de.x},${de.y}`).join(" L")} Z`,H=(B==null?void 0:B.id)===$.id;return e.jsxs("g",{className:`${z.zone} ${H?z.zoneSelected:""}`,onClick:()=>{V($),d==null||d($)},children:[e.jsx("path",{d:ee,fill:E.fill??"var(--nice-primary, #3b82f6)",fillOpacity:.2,stroke:E.fill??"var(--nice-primary, #3b82f6)",strokeWidth:H?2:1}),$.name&&e.jsx("text",{x:E.points[0].x+10,y:E.points[0].y+20,className:z.zoneLabel,children:$.name})]},$.id)})})},[ne,B,d,pe]),zt=m.useCallback(()=>ne?me&&Ce?e.jsx("g",{className:z.objectsLayer,children:Ce.map(w=>{const{object:$,layerId:E}=w.data;if(!pe(E))return null;const ee=$.position??{x:0,y:0},H=$.size??{width:20,height:20},de=(B==null?void 0:B.id)===$.id;return e.jsxs("g",{className:`${z.object} ${de?z.objectSelected:""}`,transform:`translate(${ee.x}, ${ee.y})`,onClick:_e=>{_e.stopPropagation(),V($),d==null||d($)},children:[e.jsx("rect",{x:-H.width/2,y:-H.height/2,width:H.width,height:H.height,rx:4,fill:de?"var(--nice-primary, #3b82f6)":"var(--nice-text-secondary, #64748b)",fillOpacity:.8,stroke:de?"var(--nice-primary-dark, #1d4ed8)":"transparent",strokeWidth:2}),$.name&&e.jsx("text",{y:H.height/2+14,textAnchor:"middle",className:z.objectLabel,children:$.name})]},$.id)})}):e.jsx("g",{className:z.objectsLayer,children:ne.layers.map(w=>w.type==="zones"||w.type==="grid"||w.type==="background"||!pe(w.id)?null:w.objects.map($=>{const E=$.position??{x:0,y:0},ee=$.size??{width:20,height:20},H=(B==null?void 0:B.id)===$.id;return e.jsxs("g",{className:`${z.object} ${H?z.objectSelected:""}`,transform:`translate(${E.x}, ${E.y})`,onClick:de=>{de.stopPropagation(),V($),d==null||d($)},children:[e.jsx("rect",{x:-ee.width/2,y:-ee.height/2,width:ee.width,height:ee.height,rx:4,fill:H?"var(--nice-primary, #3b82f6)":"var(--nice-text-secondary, #64748b)",fillOpacity:.8,stroke:H?"var(--nice-primary-dark, #1d4ed8)":"transparent",strokeWidth:2}),$.name&&e.jsx("text",{y:ee.height/2+14,textAnchor:"middle",className:z.objectLabel,children:$.name})]},$.id)}))}):null,[ne,B,d,pe,me,Ce]),Mt=m.useCallback(()=>{const w=y.filter($=>$.floorId===T);return e.jsx("g",{className:z.referencePoints,children:w.map($=>e.jsxs("g",{className:z.referencePoint,transform:`translate(${$.position.x}, ${$.position.y})`,onClick:()=>{l&&(te?fe($.position):ue($.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(S.NiceIcon,{name:Ft($),size:16})}),e.jsx("text",{y:30,textAnchor:"middle",className:z.refLabel,children:$.name})]},$.id))})},[y,T,l,te]),Ue=m.useCallback(()=>{if(!se)return null;const w=`M${se.path.map($=>`${$.x},${$.y}`).join(" L")}`;return e.jsxs("g",{className:z.routeLayer,children:[e.jsx("path",{d:w,fill:"none",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:4,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"12,6",className:z.routePath}),e.jsx("circle",{cx:se.startPoint.x,cy:se.startPoint.y,r:8,fill:"var(--nice-success, #10b981)",stroke:"white",strokeWidth:2}),e.jsx("circle",{cx:se.endPoint.x,cy:se.endPoint.y,r:8,fill:"var(--nice-danger, #ef4444)",stroke:"white",strokeWidth:2})]})},[se]),Bt=m.useCallback(()=>f?e.jsxs("g",{className:z.currentLocation,children:[e.jsx("circle",{cx:f.x,cy:f.y,r:12,fill:"var(--nice-primary, #3b82f6)",fillOpacity:.3,className:z.locationPulse}),e.jsx("circle",{cx:f.x,cy:f.y,r:6,fill:"var(--nice-primary, #3b82f6)",stroke:"white",strokeWidth:2})]}):null,[f]),Et=m.useCallback(()=>e.jsx("g",{className:z.routeMarkers,children:te&&!se&&e.jsx("circle",{cx:te.x,cy:te.y,r:8,fill:"var(--nice-success, #10b981)",stroke:"white",strokeWidth:2})}),[te,se]);return e.jsxs("div",{ref:Pe,className:`${z.viewer} ${z[`theme_${p}`]} ${_??""}`,children:[k&&ve&&e.jsxs("div",{className:z.debugOverlay,children:[e.jsx("div",{children:"Virtual: ON"}),e.jsxs("div",{children:["Total: ",ve.total]}),e.jsxs("div",{children:["Visible: ",ve.visible]}),e.jsxs("div",{children:["Culled: ",ve.culled," (",ve.cullPercentage,"%)"]}),e.jsxs("div",{children:["Zoom: ",ve.zoom.toFixed(2),"x"]})]}),e.jsxs("div",{className:z.topBar,children:[i&&e.jsxs("div",{className:z.searchContainer,children:[e.jsxs("div",{className:z.searchInput,children:[e.jsx(Wu,{}),e.jsx("input",{type:"text",placeholder:C("buildings.spatial.searchPlaces","Search places…"),value:v,onChange:w=>g(w.target.value)}),v&&e.jsx("button",{className:z.clearBtn,onClick:()=>g(""),children:e.jsx(nt,{})})]}),q.length>0&&e.jsx("div",{className:z.searchResults,children:q.map(w=>e.jsxs("button",{className:z.searchResultItem,onClick:()=>St(w),children:[e.jsx(Vu,{}),e.jsxs("div",{className:z.searchResultInfo,children:[e.jsx("span",{className:z.searchResultName,children:w.name??w.id}),w.description&&e.jsx("span",{className:z.searchResultDesc,children:w.description})]})]},w.id))})]}),a&&t.floors.length>1&&e.jsxs("div",{className:z.floorSelector,children:[e.jsx(Hu,{}),e.jsx("select",{value:T,onChange:w=>b(w.target.value),children:t.floors.map(w=>e.jsx("option",{value:w.id,children:w.name??`Piętro ${w.level}`},w.id))})]}),n&&e.jsxs("button",{className:`${z.navBtn} ${ze?z.active:""}`,onClick:()=>Re(!ze),children:[e.jsx(ls,{}),e.jsx("span",{children:"Nawigacja"})]}),c&&e.jsxs("button",{className:`${z.layersBtn} ${Te?z.active:""}`,onClick:()=>Be(!Te),children:[e.jsx(ds,{}),e.jsx("span",{children:"Warstwy"})]}),r&&e.jsxs("button",{className:`${z.legendBtn} ${Ee?z.active:""}`,onClick:()=>M(!Ee),children:[e.jsx(us,{}),e.jsx("span",{children:"Legenda"})]})]}),e.jsxs("div",{className:z.content,children:[ze&&e.jsxs("div",{className:z.navPanel,children:[e.jsxs("div",{className:z.navPanelHeader,children:[e.jsx(Uu,{}),e.jsx("span",{children:"Planowanie trasy"}),e.jsx("button",{onClick:()=>Re(!1),children:e.jsx(nt,{})})]}),e.jsxs("div",{className:z.routeInputs,children:[e.jsxs("div",{className:z.routeInput,children:[e.jsx("div",{className:z.routeMarker,style:{background:"var(--nice-success, #10b981)"}}),e.jsx("input",{type:"text",placeholder:"Punkt startowy",value:te?`${te.x.toFixed(0)}, ${te.y.toFixed(0)}`:"",readOnly:!0})]}),e.jsxs("div",{className:z.routeInput,children:[e.jsx("div",{className:z.routeMarker,style:{background:"var(--nice-danger, #ef4444)"}}),e.jsx("input",{type:"text",placeholder:"Punkt docelowy",value:Q?`${Q.x.toFixed(0)}, ${Q.y.toFixed(0)}`:"",readOnly:!0})]})]}),e.jsx("p",{className:z.routeHint,children:C("buildings.spatial.routeHint","Ctrl-click the map to pick points")}),se&&e.jsxs("div",{className:z.routeInfo,children:[e.jsxs("div",{className:z.routeStat,children:[e.jsx("span",{className:z.routeStatLabel,children:"Dystans"}),e.jsx("span",{className:z.routeStatValue,children:em(se.totalDistance)})]}),e.jsxs("div",{className:z.routeStat,children:[e.jsx("span",{className:z.routeStatLabel,children:C("buildings.spatial.time","Time")}),e.jsx("span",{className:z.routeStatValue,children:tm(se.estimatedTime)})]})]}),(te||Q)&&e.jsx("button",{className:z.clearRouteBtn,onClick:Lt,children:C("buildings.spatial.clearRoute","Clear the route")}),y.length>0&&e.jsxs("div",{className:z.refPointsList,children:[e.jsx("h4",{children:"Punkty odniesienia"}),y.filter(w=>w.floorId===T).map(w=>e.jsxs("button",{className:z.refPointItem,onClick:()=>{te?fe(w.position):ue(w.position)},children:[e.jsx("span",{className:z.refPointIcon,children:e.jsx(S.NiceIcon,{name:Ft(w),size:16})}),e.jsx("span",{children:w.name})]},w.id))]})]}),Te&&ne&&e.jsxs("div",{className:z.layersPanel,children:[e.jsxs("div",{className:z.layersPanelHeader,children:[e.jsx(ds,{}),e.jsx("span",{children:"Warstwy"}),e.jsx("button",{onClick:()=>Be(!1),children:e.jsx(nt,{})})]}),e.jsx("div",{className:z.layersList,children:ne.layers.map(w=>{const $=pe(w.id);return e.jsxs("div",{className:z.layerItem,children:[e.jsx("button",{className:z.layerToggle,onClick:()=>ce(w.id),title:$?C("buildings.spatial.hideLayer","Hide layer"):C("buildings.spatial.showLayer","Show layer"),children:$?e.jsx(Xu,{}):e.jsx(Ku,{})}),e.jsx("span",{className:z.layerName,children:w.name??w.id}),e.jsxs("span",{className:z.layerType,children:["(",w.type,")"]})]},w.id)})})]}),e.jsxs("div",{className:z.canvasWrapper,children:[e.jsx("svg",{ref:je,className:z.canvas,onMouseDown:Ve,onMouseMove:rt,onMouseUp:tt,onMouseLeave:tt,onWheel:ye,onClick:De,children:e.jsxs("g",{transform:`translate(${L.pan.x}, ${L.pan.y}) scale(${L.zoom})`,children:[Tt(),$t(),zt(),Mt(),Et(),Ue(),Bt()]})}),e.jsxs("div",{className:z.zoomControls,children:[e.jsx("button",{onClick:He,title:C("buildings.spatial.zoomIn","Zoom in"),children:e.jsx(Yu,{})}),e.jsx("button",{onClick:It,title:C("buildings.spatial.zoomOut","Zoom out"),children:e.jsx(Zu,{})}),e.jsx("button",{onClick:Ct,title:C("buildings.spatial.resetView","Reset the view"),children:e.jsx(S.NiceIcon,{name:"refresh",size:16})})]}),o&&e.jsx("div",{className:z.minimap,children:e.jsx("div",{className:z.minimapContent,children:e.jsx("div",{className:z.minimapViewport})})}),Ee&&We.length>0&&e.jsxs("div",{className:z.legendPanel,children:[e.jsxs("div",{className:z.legendPanelHeader,children:[e.jsx(us,{}),e.jsx("span",{children:"Legenda"}),e.jsx("button",{onClick:()=>M(!1),children:e.jsx(nt,{})})]}),e.jsx("div",{className:z.legendList,children:We.map(w=>e.jsxs("div",{className:z.legendItem,children:[w.icon?e.jsx("span",{className:z.legendIcon,children:e.jsx(S.NiceIcon,{name:w.icon,size:16})}):e.jsx("span",{className:z.legendColor,style:{background:w.color}}),e.jsx("span",{className:z.legendLabel,children:w.label}),e.jsx("span",{className:z.legendType,children:w.type==="zone"?"strefa":w.type==="object"?"obiekt":"punkt ref."})]},w.id))})]})]})]}),B&&e.jsxs("div",{className:z.objectInfo,children:[e.jsxs("div",{className:z.objectInfoHeader,children:[e.jsx("h4",{children:B.name??B.id}),e.jsx("button",{onClick:()=>V(null),children:e.jsx(nt,{})})]}),B.description&&e.jsx("p",{children:B.description}),l&&e.jsxs("button",{className:z.navigateBtn,onClick:()=>{const w=B.position??{x:0,y:0};te?fe(w):ue(w)},children:[e.jsx(ls,{}),te?"Ustaw jako cel":"Ustaw jako start"]})]})]})};function om(t={}){var ue;const{initialDocument:s,defaultMode:n="floor-plan",gridSize:o=20,snapEnabled:a=!0,onChange:i}=t,c={mode:n,tool:"select",document:s??null,activeFloorId:((ue=s==null?void 0:s.floors[0])==null?void 0:ue.id)??null,layers:[],selection:{objectIds:[],bounds:null,locked:!1},viewport:{zoom:1,pan:{x:0,y:0},rotation:0,showGrid:!0,gridSize:o,snapEnabled:a,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]=m.useReducer((Q,fe)=>({...Q,...fe}),c),y=m.useCallback(Q=>{l({mode:Q})},[]),d=m.useCallback(Q=>{l({tool:Q})},[]),x=m.useCallback((Q="Untitled")=>{var se;const fe=Ht(Q,"floor-plan");l({document:fe,activeFloorId:((se=fe.floors[0])==null?void 0:se.id)??null}),i==null||i(fe)},[i]),f=m.useCallback(Q=>{var fe;l({document:Q,activeFloorId:((fe=Q.floors[0])==null?void 0:fe.id)??null}),i==null||i(Q)},[i]),p=m.useCallback(Q=>{l({viewport:{...r.viewport,zoom:Math.max(.1,Math.min(10,r.viewport.zoom*(1+Q*.1)))}})},[r.viewport]),_=m.useCallback(Q=>{l({viewport:{...r.viewport,pan:{x:r.viewport.pan.x+Q.x,y:r.viewport.pan.y+Q.y}}})},[r.viewport]),j=m.useCallback(()=>{l({viewport:{...r.viewport,zoom:1,pan:{x:0,y:0}}})},[r.viewport]),h=m.useCallback(()=>{l({viewport:{...r.viewport,showGrid:!r.viewport.showGrid}})},[r.viewport]),k=m.useCallback(()=>{l({viewport:{...r.viewport,snapEnabled:!r.viewport.snapEnabled}})},[r.viewport]),C=m.useCallback(Q=>{l({viewport:{...r.viewport,gridSize:Q}})},[r.viewport]),T=m.useCallback((Q,fe)=>{l({layers:r.layers.map(se=>se.type===Q?{...se,visible:fe}:se)})},[r.layers]),b=m.useCallback((Q,fe)=>{l({layers:r.layers.map(se=>se.type===Q?{...se,locked:fe}:se)})},[r.layers]),L=m.useCallback(Q=>{l({selection:{objectIds:Q,bounds:null,locked:!1}})},[]),u=m.useCallback(()=>{l({selection:{objectIds:[],bounds:null,locked:!1}})},[]),v=m.useCallback(()=>{},[]),g=m.useCallback(()=>{},[]),q=r.history.past.length>0,I=r.history.future.length>0,B=m.useCallback(()=>{},[]),V=m.useCallback(Q=>{},[]),te=m.useCallback(()=>{},[]);return{state:r,setMode:y,setTool:d,newDocument:x,loadDocument:f,zoom:p,pan:_,resetView:j,toggleGrid:h,toggleSnap:k,setGridSize:C,setLayerVisible:T,setLayerLocked:b,select:L,clearSelection:u,undo:v,redo:g,canUndo:q,canRedo:I,copy:B,paste:V,cut:te}}function am(t={}){const{gridSize:s=20,enabled:n=!0,snapModes:o=["grid","endpoint","midpoint"],objects:a=[],threshold:i=10}=t,c=m.useMemo(()=>({...Dn,cellSize:s,snapModes:o,snapThreshold:i}),[s,o,i]),r=m.useMemo(()=>a.map((p,_)=>({id:`obj-${_}`,bounds:p})),[a]),l=m.useCallback(p=>n?Vt(p,c):p,[n,c]),y=m.useCallback(p=>n?Rn(p,s):p,[n,s]),d=m.useCallback(p=>{if(!n||r.length===0)return[];const _={x:p.x,y:p.y,width:0,height:0};return vs(_,r,i)},[n,r,i]),x=m.useCallback(p=>{if(!n)return{point:p,snapped:!1,guides:[]};const _=Wn(p,r,c);return{point:_.position,snapped:_.snapped,guides:_.guides??[]}},[n,c,r]),f=m.useCallback((p,_)=>{const j=[];for(let h=0;h<=p;h+=s)j.push({x1:h,y1:0,x2:h,y2:_});for(let h=0;h<=_;h+=s)j.push({x1:0,y1:h,x2:p,y2:h});return j},[s]);return{snap:l,snap3D:y,getGuides:d,performAdvancedSnap:x,generateGridLines:f}}function im(t={}){const{unitSystem:s="metric",lengthUnit:n="m",areaUnit:o="m2",angleUnit:a="deg",scale:i=100}=t,[c,r]=m.useState(null),[l,y]=m.useState([]),d=m.useCallback(u=>u/i,[i]),x=m.useCallback(u=>{r(u),y([])},[]),f=m.useCallback((u,v=!1)=>{y(g=>[...g,{position:u,snapped:v}])},[]),p=m.useCallback(()=>{r(null),y([])},[]),_=m.useCallback(()=>{if(!c||l.length<2)return null;const u=l.map(v=>v.position);if(c==="distance"&&l.length===2){const v=at(u[0],u[1]),g=d(v);return{type:"distance",value:g,formatted:ht(g,s).formatted,points:u}}if(c==="angle"&&l.length===3){const v=At(u[0],u[1],u[2]);return{type:"angle",value:v,formatted:Dt(v,a).formatted,points:u}}if(c==="area"&&l.length>=3){const g=Ot(u)/(i*i);return{type:"area",value:g,formatted:Rt(g,s).formatted,points:u}}return null},[c,l,i,s,a,d]),j=l.length>=2&&c==="distance"?ht(d(at(l[0].position,l[l.length-1].position)),s).formatted:null,h=l.length>=3&&c==="angle"?Dt(At(l[0].position,l[1].position,l[2].position),a).formatted:null,k=l.length>=3&&c==="area"?Rt(Ot(l.map(u=>u.position))/(i*i),s).formatted:null,C=m.useCallback((u,v)=>{const g=at(u,v),q=d(g);return{value:q,formatted:ht(q,s).formatted}},[d,s]),T=m.useCallback((u,v,g)=>{const q=At(u,v,g);return{value:q,formatted:Dt(q,a).formatted}},[a]),b=m.useCallback(u=>{const g=Ot(u)/(i*i);return{value:g,formatted:Rt(g,s).formatted}},[i,s]),L=m.useCallback(u=>{const v=Zn(u),g=d(v);return{value:g,formatted:ht(g,s).formatted}},[d,s]);return{startMeasurement:x,addPoint:f,clearMeasurement:p,finishMeasurement:_,measurementType:c,points:l,liveDistance:j,liveAngle:h,liveArea:k,getDistance:C,getAngle:T,getArea:b,getLength:L}}const rm="_root_15owo_3",cm="_dark_15owo_25",lm="_header_15owo_37",dm="_buildingInfo_15owo_51",um="_buildingName_15owo_59",mm="_buildingAddress_15owo_81",hm="_modeSelector_15owo_95",pm="_modeBtn_15owo_107",fm="_modeBtnActive_15owo_145",_m="_weather_15owo_159",gm="_weatherTemp_15owo_173",ym="_weatherDesc_15owo_193",bm="_statsRow_15owo_205",xm="_statsCard_15owo_217",vm="_statsHeader_15owo_247",jm="_statsIcon_15owo_261",wm="_statsLabel_15owo_269",Nm="_statsValue_15owo_283",km="_statsSub_15owo_305",Im="_zoneGrid_15owo_319",Cm="_zoneCard_15owo_333",Sm="_zoneOccupied_15owo_381",Lm="_zoneCardHeader_15owo_389",Tm="_zoneCardIcon_15owo_403",$m="_zoneCardTitles_15owo_411",zm="_zoneCardName_15owo_421",Mm="_zoneCardArea_15owo_449",Bm="_occupancyBadge_15owo_459",Em="_occupancyBadgeOn_15owo_477",Pm="_sensorRow_15owo_489",Am="_sensorChip_15owo_503",Om="_sensorWarn_15owo_521",Dm="_deviceList_15owo_535",Rm="_deviceChip_15owo_547",qm="_deviceChipOn_15owo_585",Fm="_deviceChipName_15owo_597",Gm="_deviceChipVal_15owo_611",Wm="_moreBtn_15owo_621",Vm="_scenesBar_15owo_651",Hm="_sceneBarLabel_15owo_681",Um="_sceneList_15owo_699",Ym="_sceneBtn_15owo_711",Zm="_sceneBtnActive_15owo_741",Z={root:rm,dark:cm,header:lm,buildingInfo:dm,buildingName:um,buildingAddress:mm,modeSelector:hm,modeBtn:pm,modeBtnActive:fm,weather:_m,weatherTemp:gm,weatherDesc:ym,statsRow:bm,statsCard:xm,statsHeader:vm,statsIcon:jm,statsLabel:wm,statsValue:Nm,statsSub:km,zoneGrid:Im,zoneCard:Cm,zoneOccupied:Sm,zoneCardHeader:Lm,zoneCardIcon:Tm,zoneCardTitles:$m,zoneCardName:zm,zoneCardArea:Mm,occupancyBadge:Bm,occupancyBadgeOn:Em,sensorRow:Pm,sensorChip:Am,sensorWarn:Om,deviceList:Dm,deviceChip:Rm,deviceChipOn:qm,deviceChipName:Fm,deviceChipVal:Gm,moreBtn:Wm,scenesBar:Vm,sceneBarLabel:Hm,sceneList:Um,sceneBtn:Ym,sceneBtnActive:Zm},Xm={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 Km(t){return Xm[t]??"home"}function Jm(t,s){if(!s.state)return null;const n=s.state;return typeof n.brightness=="number"?`${n.brightness}%`:typeof n.on=="boolean"?n.on?t("buildings.onShort","On"):t("buildings.offShort","Off"):typeof n.temperature=="number"?`${n.temperature.toFixed(1)}°`:typeof n.locked=="boolean"?e.jsx(S.NiceIcon,{name:"lock",size:14}):null}const Ls=({zone:t,devices:s=[],expanded:n=!1,onExpand:o,onDeviceControl:a,onClick:i,theme:c="light",className:r,style:l})=>{const{t:y}=S.useNiceTranslation(),d=t.occupancy!=null&&t.occupancy>0,x=n?s:s.slice(0,4);return e.jsxs("div",{className:`${Z.zoneCard} ${c==="dark"?Z.dark:""} ${d?Z.zoneOccupied:""} ${r??""}`,style:l,onClick:i,children:[e.jsxs("div",{className:Z.zoneCardHeader,children:[e.jsx("span",{className:Z.zoneCardIcon,children:e.jsx(S.NiceIcon,{name:Km(t.type),size:18})}),e.jsxs("div",{className:Z.zoneCardTitles,children:[e.jsx("span",{className:Z.zoneCardName,children:t.name}),t.area!=null&&e.jsxs("span",{className:Z.zoneCardArea,children:[t.area," m²"]})]}),t.occupancy!=null&&e.jsxs("span",{className:`${Z.occupancyBadge} ${d?Z.occupancyBadgeOn:""}`,children:[e.jsx(S.NiceIcon,{name:"users",size:14})," ",t.occupancy]})]}),(t.temperature!=null||t.humidity!=null||t.co2!=null)&&e.jsxs("div",{className:Z.sensorRow,children:[t.temperature!=null&&e.jsxs("span",{className:Z.sensorChip,children:[e.jsx(S.NiceIcon,{name:"thermometer",size:14})," ",t.temperature.toFixed(1),"°C"]}),t.humidity!=null&&e.jsxs("span",{className:Z.sensorChip,children:[e.jsx(S.NiceIcon,{name:"droplet",size:14})," ",t.humidity,"%"]}),t.co2!=null&&e.jsxs("span",{className:`${Z.sensorChip} ${t.co2>1e3?Z.sensorWarn:""}`,children:["CO₂ ",t.co2]})]}),x.length>0&&e.jsxs("div",{className:Z.deviceList,children:[x.map(f=>{const p=f.state,_=(p==null?void 0:p.on)===!0||(p==null?void 0:p.locked)===!1;return e.jsxs("button",{className:`${Z.deviceChip} ${_?Z.deviceChipOn:""}`,onClick:j=>{j.stopPropagation(),a==null||a(f.id,{on:!_})},title:f.name,children:[e.jsx("span",{children:e.jsx(S.NiceIcon,{name:bs(f.type),size:14})}),e.jsx("span",{className:Z.deviceChipName,children:f.name}),e.jsx("span",{className:Z.deviceChipVal,children:Jm(y,f)})]},f.id)}),s.length>4&&e.jsx("button",{className:Z.moreBtn,"aria-label":n?y("buildings.showFewer","Show fewer devices"):y("buildings.showAll","Show all devices"),onClick:f=>{f.stopPropagation(),o==null||o()},children:n?e.jsx(S.NiceIcon,{name:"minus",size:12}):`+${s.length-4}`})]})]})},Gt={home:"Home",away:"Away",night:"Night",vacation:"Vacation",guest:"Guest",party:"Party",occupied:"Occupied",closed:"Closed",weekend:"Weekend",event:"Event",emergency:"Emergency",maintenance:"Maintenance"},ms={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"},Qm=({temperature:t,description:s})=>t!=null?e.jsxs("div",{className:Z.weather,children:[e.jsxs("span",{className:Z.weatherTemp,children:[t,"°C"]}),s&&e.jsx("span",{className:Z.weatherDesc,children:s})]}):null,bt=({label:t,value:s,sub:n,icon:o,accent:a})=>e.jsxs("div",{className:Z.statsCard,style:a?{borderTopColor:a}:void 0,children:[e.jsxs("div",{className:Z.statsHeader,children:[o&&e.jsx("span",{className:Z.statsIcon,children:e.jsx(S.NiceIcon,{name:o,size:16})}),e.jsx("span",{className:Z.statsLabel,children:t})]}),e.jsx("div",{className:Z.statsValue,children:s}),n&&e.jsx("div",{className:Z.statsSub,children:n})]}),eh=({building:t,state:s,onModeChange:n,onDeviceControl:o,onSceneActivate:a,onZoneClick:i,className:c,style:r,theme:l="light",weather:y})=>{var b,L,u;const{t:d}=S.useNiceTranslation(),[x,f]=m.useState(null);t.floors[0];const p=t.floors.flatMap(v=>v.zones??[]).filter(v=>v.type!=="hallway"&&v.type!=="corridor"),_=((b=s==null?void 0:s.activeAlerts)==null?void 0:b.length)??0,j=(L=s==null?void 0:s.energy)==null?void 0:L.currentPowerW,h=(u=s==null?void 0:s.energy)==null?void 0:u.todayKwh,k=s!=null&&s.occupancy?Object.values(s.occupancy).reduce((v,g)=>v+((g==null?void 0:g.occupancy)??0),0):null;t.floors.flatMap(v=>v.zones??[]).flatMap(v=>v.deviceIds??[]).slice(0,8);const C=t.type==="office"||t.type==="retail"?["occupied","closed","weekend","event","emergency","maintenance"]:["home","away","night","vacation","guest","emergency"],T=(s==null?void 0:s.mode)??"home";return e.jsxs("div",{className:`${Z.root} ${l==="dark"?Z.dark:""} ${c??""}`,style:r,children:[e.jsxs("div",{className:Z.header,children:[e.jsxs("div",{className:Z.buildingInfo,children:[e.jsx("h2",{className:Z.buildingName,children:t.name}),t.address&&e.jsx("p",{className:Z.buildingAddress,children:t.address})]}),e.jsx("div",{className:Z.modeSelector,children:C.map(v=>e.jsxs("button",{title:Gt[v],className:`${Z.modeBtn} ${T===v?Z.modeBtnActive:""}`,onClick:()=>n==null?void 0:n(v),children:[e.jsx(S.NiceIcon,{name:ms[v],size:16}),e.jsx("span",{children:Gt[v]})]},v))}),e.jsx(Qm,{temperature:y==null?void 0:y.temperature,description:y==null?void 0:y.description})]}),e.jsxs("div",{className:Z.statsRow,children:[j!=null&&e.jsx(bt,{icon:"zap",label:d("buildings.power","Power"),value:j>=1e3?`${(j/1e3).toFixed(2)} kW`:`${j} W`,sub:h!=null?`${d("buildings.today","Today")}: ${h.toFixed(2)} kWh`:void 0,accent:"var(--nice-warning, #f59e0b)"}),k!=null&&e.jsx(bt,{icon:"users",label:d("buildings.occupancy","Occupancy"),value:`${k}`,sub:`${p.length} ${d("buildings.zones","zones")}`,accent:"var(--nice-success, #22c55e)"}),_>0&&e.jsx(bt,{icon:"bell",label:d("buildings.alerts","Alerts"),value:e.jsx("span",{style:{color:"var(--nice-danger, #ef4444)"},children:_}),sub:d("buildings.active","active"),accent:"var(--nice-danger, #ef4444)"}),e.jsx(bt,{icon:ms[T],label:d("buildings.mode","Mode"),value:d(`buildings.mode.${T}`,Gt[T]),accent:"var(--nice-accent, #8b5cf6)"})]}),e.jsx("div",{className:Z.zoneGrid,children:p.map(v=>{const g=t.floors.flatMap(q=>(q.zones??[]).find(I=>I.id===v.id)?t.devices??[]:[]).filter(q=>q.zoneId===v.id);return e.jsx(Ls,{zone:v,devices:g,expanded:x===v.id,onExpand:()=>f(x===v.id?null:v.id),onDeviceControl:o,onClick:()=>i==null?void 0:i(v.id),theme:l},v.id)})}),t.scenes&&t.scenes.length>0&&e.jsxs("div",{className:Z.scenesBar,children:[e.jsx("span",{className:Z.sceneBarLabel,children:d("buildings.scenes","Scenes")}),e.jsx("div",{className:Z.sceneList,children:t.scenes.map(v=>{var g;return e.jsxs("button",{className:`${Z.sceneBtn} ${(g=s==null?void 0:s.activeScenes)!=null&&g.includes(v.id)?Z.sceneBtnActive:""}`,onClick:()=>a==null?void 0:a(v.id),children:[e.jsx(S.NiceIcon,{name:v.icon??"video",size:14})," ",v.name]},v.id)})})]})]})},th="_deviceControl_1leqb_3",sh="_dark_1leqb_23",nh="_compact_1leqb_35",oh="_offline_1leqb_43",ah="_offlineBanner_1leqb_51",ih="_toggleControl_1leqb_75",rh="_toggleLabel_1leqb_89",ch="_toggleBtn_1leqb_109",lh="_toggleOn_1leqb_135",dh="_blindControl_1leqb_149",uh="_blindLabel_1leqb_159",mh="_blindActions_1leqb_173",hh="_blindBtn_1leqb_181",ph="_blindSlider_1leqb_205",fh="_blindPct_1leqb_213",_h="_lockControl_1leqb_227",gh="_lockLabel_1leqb_239",yh="_lockBtn_1leqb_253",bh="_lockLocked_1leqb_273",xh="_lockUnlocked_1leqb_281",vh="_cameraControl_1leqb_295",jh="_cameraLabel_1leqb_305",wh="_cameraSnapshot_1leqb_319",Nh="_cameraPlaceholder_1leqb_331",kh="_cameraStatus_1leqb_355",Ih="_cameraDot_1leqb_369",Ch="_cameraOnline_1leqb_379",Sh="_cameraOffline_1leqb_385",Lh="_sensorControl_1leqb_395",Th="_sensorLabel_1leqb_405",$h="_sensorValues_1leqb_419",zh="_sensorRow_1leqb_429",Mh="_sensorKey_1leqb_443",Bh="_sensorVal_1leqb_419",Eh="_thermostat_1leqb_467",Ph="_thermostatTitle_1leqb_481",Ah="_thermostatDial_1leqb_503",Oh="_dialTempCurrent_1leqb_513",Dh="_dialTempLabel_1leqb_535",Rh="_dialTempTarget_1leqb_545",qh="_dialHumidity_1leqb_565",Fh="_thermostatAdjust_1leqb_575",Gh="_adjustBtn_1leqb_587",Wh="_adjustTemp_1leqb_633",Vh="_hvacModes_1leqb_657",Hh="_hvacModeBtn_1leqb_671",Uh="_hvacModeBtnActive_1leqb_699",Yh="_hvacAction_1leqb_711",Zh="_hvacActionDot_1leqb_727",Xh="_lightControl_1leqb_741",Kh="_lightHeader_1leqb_753",Jh="_lightIcon_1leqb_765",Qh="_lightName_1leqb_773",ep="_lightToggle_1leqb_801",tp="_lightToggleOn_1leqb_829",sp="_sliderRow_1leqb_841",np="_sliderIcon_1leqb_855",op="_slider_1leqb_841",ap="_sliderVal_1leqb_879",ip="_colorRow_1leqb_891",rp="_colorSwatch_1leqb_905",cp="_colorPicker_1leqb_921",lp="_colorPresets_1leqb_937",dp="_colorPreset_1leqb_937",up="_lightOff_1leqb_963",A={deviceControl:th,dark:sh,compact:nh,offline:oh,offlineBanner:ah,toggleControl:ih,toggleLabel:rh,toggleBtn:ch,toggleOn:lh,blindControl:dh,blindLabel:uh,blindActions:mh,blindBtn:hh,blindSlider:ph,blindPct:fh,lockControl:_h,lockLabel:gh,lockBtn:yh,lockLocked:bh,lockUnlocked:xh,cameraControl:vh,cameraLabel:jh,cameraSnapshot:wh,cameraPlaceholder:Nh,cameraStatus:kh,cameraDot:Ih,cameraOnline:Ch,cameraOffline:Sh,sensorControl:Lh,sensorLabel:Th,sensorValues:$h,sensorRow:zh,sensorKey:Mh,sensorVal:Bh,thermostat:Eh,thermostatTitle:Ph,thermostatDial:Ah,dialTempCurrent:Oh,dialTempLabel:Dh,dialTempTarget:Rh,dialHumidity:qh,thermostatAdjust:Fh,adjustBtn:Gh,adjustTemp:Wh,hvacModes:Vh,hvacModeBtn:Hh,hvacModeBtnActive:Uh,hvacAction:Yh,hvacActionDot:Zh,lightControl:Xh,lightHeader:Kh,lightIcon:Jh,lightName:Qh,lightToggle:ep,lightToggleOn:tp,sliderRow:sp,sliderIcon:np,slider:op,sliderVal:ap,colorRow:ip,colorSwatch:rp,colorPicker:cp,colorPresets:lp,colorPreset:dp,lightOff:up};function hs(t){const s=Math.max(0,Math.min(1,(t-2700)/3800)),n=Math.round(255-s*80),o=Math.round(200+s*30),a=Math.round(100+s*155);return`rgb(${n},${o},${a})`}function mp(t,s,n){return"#"+[t,s,n].map(o=>o.toString(16).padStart(2,"0")).join("")}const hp=["#ffffff","#fde68a","#fca5a5","#93c5fd","#86efac","#c4b5fd"];function ps(t){const s=parseInt(t.slice(1,3),16),n=parseInt(t.slice(3,5),16),o=parseInt(t.slice(5,7),16);return[s,n,o]}const Ts=({device:t,onControl:s,compact:n=!1,theme:o="light",className:a,style:i})=>{var T,b,L;const{t:c}=S.useNiceTranslation(),r=t.state,l=(r==null?void 0:r.on)??!1,y=(r==null?void 0:r.brightness)??100,d=(r==null?void 0:r.colorTemperature)??4e3,x=r==null?void 0:r.rgbColor,[f,p]=m.useState(!1),_=m.useCallback(u=>{s==null||s(t.id,u)},[t.id,s]),j=x?mp(x[0],x[1],x[2]):"#ffffff",h=((T=t.capabilities)==null?void 0:T.includes("dimming"))??y!==void 0,k=(b=t.capabilities)==null?void 0:b.includes("color_temperature"),C=((L=t.capabilities)==null?void 0:L.includes("color"))||t.type==="rgb_light";return e.jsxs("div",{className:`${A.lightControl} ${n?A.compact:""} ${o==="dark"?A.dark:""} ${a??""}`,style:i,children:[e.jsxs("div",{className:A.lightHeader,children:[e.jsx("span",{className:A.lightIcon,style:{opacity:l?1:.4},children:e.jsx(S.NiceIcon,{name:"lightbulb",size:16})}),e.jsx("span",{className:A.lightName,children:t.name}),e.jsx("button",{className:`${A.lightToggle} ${l?A.lightToggleOn:""}`,"aria-label":l?c("buildings.switchedOn","On"):c("buildings.switchedOff","Off"),onClick:()=>_({on:!l}),children:e.jsx(S.NiceIcon,{name:l?"check":"close",size:14})})]}),l&&e.jsxs(e.Fragment,{children:[h&&e.jsxs("div",{className:A.sliderRow,children:[e.jsx("span",{className:A.sliderIcon,children:e.jsx(S.NiceIcon,{name:"lightbulb",size:16})}),e.jsx("input",{type:"range",min:1,max:100,value:y,className:A.slider,style:{"--pct":`${y}%`},onChange:u=>_({brightness:+u.target.value})}),e.jsxs("span",{className:A.sliderVal,children:[y,"%"]})]}),k&&e.jsxs("div",{className:A.sliderRow,children:[e.jsx("span",{className:A.sliderIcon,children:e.jsx(S.NiceIcon,{name:"thermometer",size:16})}),e.jsx("input",{type:"range",min:2700,max:6500,step:100,value:d,className:A.slider,style:{background:`linear-gradient(to right, ${hs(2700)}, ${hs(6500)})`},onChange:u=>_({colorTemperature:+u.target.value})}),e.jsxs("span",{className:A.sliderVal,children:[Math.round(d/100)*100,"K"]})]}),C&&e.jsxs("div",{className:A.colorRow,children:[e.jsx("span",{className:A.sliderIcon,children:e.jsx(S.NiceIcon,{name:"palette",size:16})}),e.jsx("button",{className:A.colorSwatch,"aria-label":c("buildings.pickColor","Pick a color"),"aria-expanded":f,style:{background:j},onClick:()=>p(u=>!u)}),f&&e.jsx("input",{type:"color",value:j,className:A.colorPicker,onChange:u=>{const[v,g,q]=ps(u.target.value);_({rgbColor:[v,g,q]})}}),e.jsx("div",{className:A.colorPresets,children:hp.map(u=>e.jsx("button",{className:A.colorPreset,"aria-label":u,style:{background:u},onClick:()=>{const[v,g,q]=ps(u);_({rgbColor:[v,g,q]})}},u))})]})]}),!l&&!n&&e.jsx("div",{className:A.lightOff,children:c("buildings.switchedOff","Off")})]})},fs={heat:"Heating",cool:"Cooling",auto:"Auto",off:"Off",fan_only:"Fan",dry:"Dry"},pp={heat:"zap",cool:"thermometer",auto:"refresh",off:"stop",fan_only:"wifi",dry:"droplet"},fp={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 _s(t,s,n,o,a){const i=x=>(x-90)*(Math.PI/180),c=t+n*Math.cos(i(o)),r=s+n*Math.sin(i(o)),l=t+n*Math.cos(i(a)),y=s+n*Math.sin(i(a)),d=a-o>180?1:0;return`M${c.toFixed(2)},${r.toFixed(2)} A${n},${n} 0 ${d},1 ${l.toFixed(2)},${y.toFixed(2)}`}const it=5,vt=35,wt=-140,$s=140;function gs(t){return wt+(t-it)/(vt-it)*($s-wt)}const zs=({device:t,onControl:s,compact:n=!1,theme:o="light",className:a,style:i})=>{const{t:c}=S.useNiceTranslation(),r=t.state,l=(r==null?void 0:r.temperature)??20,y=(r==null?void 0:r.targetTemperature)??21,d=r==null?void 0:r.humidity,x=(r==null?void 0:r.mode)??"auto",f=(r==null?void 0:r.hvacAction)??"idle",p=80,_=80,j=60,h=_s(p,_,j,wt,$s),k=gs(Math.min(Math.max(l,it),vt)),C=gs(Math.min(Math.max(y,it),vt)),T=_s(p,_,j,wt,Math.min(k,C)),b=fp[f]??"var(--nice-text-muted, #94a3b8)",L=m.useCallback(v=>{const g=Math.round((y+v)*2)/2;g>=it&&g<=vt&&(s==null||s(t.id,{targetTemperature:g}))},[y,t.id,s]),u=m.useCallback(v=>{s==null||s(t.id,{mode:v})},[t.id,s]);return e.jsxs("div",{className:`${A.thermostat} ${n?A.compact:""} ${o==="dark"?A.dark:""} ${a??""}`,style:i,children:[e.jsx("div",{className:A.thermostatTitle,children:t.name}),e.jsxs("svg",{width:160,height:160,className:A.thermostatDial,children:[e.jsx("path",{d:h,fill:"none",stroke:"var(--nice-border, #e2e8f0)",strokeWidth:8,strokeLinecap:"round"}),e.jsx("path",{d:T,fill:"none",stroke:b,strokeWidth:8,strokeLinecap:"round",opacity:.4}),e.jsx("circle",{cx:p+j*Math.cos((C-90)*(Math.PI/180)),cy:_+j*Math.sin((C-90)*(Math.PI/180)),r:7,fill:b,stroke:"var(--nice-bg, #fff)",strokeWidth:2}),e.jsxs("text",{x:p,y:_-6,textAnchor:"middle",className:A.dialTempCurrent,children:[l.toFixed(1),"°"]}),e.jsx("text",{x:p,y:_+14,textAnchor:"middle",className:A.dialTempLabel,children:c("buildings.currentTemp","now")}),e.jsxs("text",{x:p,y:_+32,textAnchor:"middle",className:A.dialTempTarget,children:[y.toFixed(1),"°"]}),d!=null&&e.jsxs("text",{x:p,y:_+48,textAnchor:"middle",className:A.dialHumidity,children:[d,"%"]})]}),e.jsxs("div",{className:A.thermostatAdjust,children:[e.jsx("button",{className:A.adjustBtn,"aria-label":c("buildings.lowerTarget","Lower the target temperature"),onClick:()=>L(-.5),children:e.jsx(S.NiceIcon,{name:"minus",size:16})}),e.jsxs("span",{className:A.adjustTemp,children:[y.toFixed(1)," °C"]}),e.jsx("button",{className:A.adjustBtn,"aria-label":c("buildings.raiseTarget","Raise the target temperature"),onClick:()=>L(.5),children:e.jsx(S.NiceIcon,{name:"plus",size:16})})]}),!n&&e.jsx("div",{className:A.hvacModes,children:["heat","cool","auto","fan_only","off"].map(v=>e.jsx("button",{title:fs[v],"aria-label":fs[v],className:`${A.hvacModeBtn} ${x===v?A.hvacModeBtnActive:""}`,onClick:()=>u(v),children:e.jsx(S.NiceIcon,{name:pp[v],size:16})},v))}),e.jsxs("div",{className:A.hvacAction,style:{color:b},children:[e.jsx("span",{className:A.hvacActionDot,style:{background:b}}),f]})]})},_p=({device:t,onControl:s})=>{const{t:n}=S.useNiceTranslation(),o=t.state,a=(o==null?void 0:o.on)===!0;return e.jsxs("div",{className:A.toggleControl,children:[e.jsx("span",{className:A.toggleLabel,children:t.name}),e.jsx("button",{className:`${A.toggleBtn} ${a?A.toggleOn:""}`,onClick:()=>s==null?void 0:s(t.id,{on:!a}),children:a?n("buildings.on","ON"):n("buildings.off","OFF")})]})},gp=({device:t,onControl:s})=>{const{t:n}=S.useNiceTranslation(),o=t.state,a=typeof(o==null?void 0:o.position)=="number"?o.position:50;return e.jsxs("div",{className:A.blindControl,children:[e.jsx("span",{className:A.blindLabel,children:t.name}),e.jsxs("div",{className:A.blindActions,children:[e.jsx("button",{className:A.blindBtn,"aria-label":n("buildings.open","Open"),onClick:()=>s==null?void 0:s(t.id,{command:"open"}),children:e.jsx(S.NiceIcon,{name:"arrow-up",size:16})}),e.jsx("button",{className:A.blindBtn,"aria-label":n("buildings.stop","Stop"),onClick:()=>s==null?void 0:s(t.id,{command:"stop"}),children:e.jsx(S.NiceIcon,{name:"stop",size:16})}),e.jsx("button",{className:A.blindBtn,"aria-label":n("buildings.close","Close"),onClick:()=>s==null?void 0:s(t.id,{command:"close"}),children:e.jsx(S.NiceIcon,{name:"arrow-down",size:16})})]}),e.jsx("input",{type:"range",min:0,max:100,value:a,className:A.blindSlider,onChange:i=>s==null?void 0:s(t.id,{position:+i.target.value})}),e.jsxs("span",{className:A.blindPct,children:[a,"%"]})]})},yp=({device:t,onControl:s})=>{const{t:n}=S.useNiceTranslation(),o=t.state,a=(o==null?void 0:o.locked)!==!1;return e.jsxs("div",{className:A.lockControl,children:[e.jsx("span",{className:A.lockLabel,children:t.name}),e.jsxs("button",{className:`${A.lockBtn} ${a?A.lockLocked:A.lockUnlocked}`,onClick:()=>s==null?void 0:s(t.id,{locked:!a}),children:[e.jsx(S.NiceIcon,{name:"lock",size:14})," ",a?n("buildings.locked","Locked"):n("buildings.unlocked","Unlocked")]})]})},bp=({device:t})=>{const{t:s}=S.useNiceTranslation(),n=t.state;return e.jsxs("div",{className:A.cameraControl,children:[e.jsx("span",{className:A.cameraLabel,children:t.name}),n!=null&&n.snapshotUrl?e.jsx("img",{src:n.snapshotUrl,alt:"snapshot",className:A.cameraSnapshot}):e.jsxs("div",{className:A.cameraPlaceholder,children:[e.jsx(S.NiceIcon,{name:"camera",size:16}),e.jsx("span",{children:n!=null&&n.streaming?"Streaming":s("buildings.noPreview","No preview")})]}),e.jsxs("div",{className:A.cameraStatus,children:[e.jsx("span",{className:`${A.cameraDot} ${t.status==="online"?A.cameraOnline:A.cameraOffline}`}),t.status]})]})},xp=({device:t})=>{const s=t.state;return e.jsxs("div",{className:A.sensorControl,children:[e.jsx("span",{className:A.sensorLabel,children:t.name}),e.jsx("div",{className:A.sensorValues,children:Object.entries(s??{}).map(([n,o])=>o!=null&&e.jsxs("div",{className:A.sensorRow,children:[e.jsx("span",{className:A.sensorKey,children:n}),e.jsx("span",{className:A.sensorVal,children:String(o)})]},n))})]})},vp=({device:t,onControl:s,compact:n=!1,className:o,style:a,theme:i="light"})=>{const c=t.type,r=["light","dimmer","rgb_light","led_strip"].includes(c)?e.jsx(Ts,{device:t,onControl:s,compact:n,theme:i}):["thermostat","air_conditioner","heat_pump","floor_heating"].includes(c)?e.jsx(zs,{device:t,onControl:s,compact:n,theme:i}):["blind","shutter","curtain","awning","garage_door"].includes(c)?e.jsx(gp,{device:t,onControl:s}):["lock","door"].includes(c)?e.jsx(yp,{device:t,onControl:s}):["camera","doorbell"].includes(c)?e.jsx(bp,{device:t}):c.endsWith("_sensor")||["motion_sensor","smoke_detector","water_leak_sensor","alarm"].includes(c)?e.jsx(xp,{device:t}):e.jsx(_p,{device:t,onControl:s});return e.jsxs("div",{className:`${A.deviceControl} ${i==="dark"?A.dark:""} ${n?A.compact:""} ${t.status==="offline"?A.offline:""} ${o??""}`,style:a,children:[r,t.status==="offline"&&e.jsx("div",{className:A.offlineBanner,children:"Offline"})]})},jp="_root_ft98s_3",wp="_shell_ft98s_29",Np="_dark_ft98s_37",kp="_listPanel_ft98s_51",Ip="_listHeader_ft98s_79",Cp="_listTitle_ft98s_103",Sp="_addBtn_ft98s_121",Lp="_list_ft98s_51",Tp="_listItem_ft98s_159",$p="_listItemActive_ft98s_199",zp="_listItemName_ft98s_213",Mp="_listItemMeta_ft98s_241",Bp="_enableToggle_ft98s_255",Ep="_enableOn_ft98s_273",Pp="_detailPanel_ft98s_283",Ap="_detailHeader_ft98s_295",Op="_nameInput_ft98s_309",Dp="_deleteBtn_ft98s_343",Rp="_section_ft98s_373",qp="_rules_ft98s_383",Fp="_sectionHeader_ft98s_397",Gp="_sectionTitle_ft98s_411",Wp="_sectionAddBtn_ft98s_427",Vp="_ruleBlock_ft98s_457",Hp="_ruleBlockHeader_ft98s_483",Up="_typeSelect_ft98s_497",Yp="_removeBtn_ft98s_529",Zp="_ruleFields_ft98s_567",Xp="_input_ft98s_603",Kp="_textarea_ft98s_635",Jp="_dayPicker_ft98s_671",Qp="_dayBtn_ft98s_683",ef="_dayBtnActive_ft98s_703",tf="_noSelection_ft98s_717",sf="_emptyHint_ft98s_719",P={root:jp,shell:wp,dark:Np,listPanel:kp,listHeader:Ip,listTitle:Cp,addBtn:Sp,list:Lp,listItem:Tp,listItemActive:$p,listItemName:zp,listItemMeta:Mp,enableToggle:Bp,enableOn:Ep,detailPanel:Pp,detailHeader:Ap,nameInput:Op,deleteBtn:Dp,section:Rp,rules:qp,sectionHeader:Fp,sectionTitle:Gp,sectionAddBtn:Wp,ruleBlock:Vp,ruleBlockHeader:Hp,typeSelect:Up,removeBtn:Yp,ruleFields:Zp,input:Xp,textarea:Kp,dayPicker:Jp,dayBtn:Qp,dayBtnActive:ef,noSelection:tf,emptyHint:sf},nf=[{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"}],be=(t,s,n="")=>{const o=t[s];return typeof o=="string"?o:n},jt=(t,s,n=0)=>{const o=t[s];return typeof o=="number"?o:n},Nt=["mon","tue","wed","thu","fri","sat","sun"],of=t=>{const s=t.days;return Array.isArray(s)?s.map(n=>typeof n=="number"?Nt[n]:String(n)):[...Nt.slice(0,5)]},Ge={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³"}},af=t=>t in Ge,Wt=t=>{const s=be(t,"sensorType",be(t,"attribute"));return af(s)?s:"temperature"},rf=(t,s)=>{const n=t[s];return n&&typeof n=="object"?n:{}},cf=t=>{const s=new Intl.DateTimeFormat(t,{weekday:"short",timeZone:"UTC"});return Array.from({length:7},(n,o)=>s.format(new Date(Date.UTC(2024,0,1+o))))},ys=[["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"]],lf=[["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"]],df=["on","brightness","temperature","targetTemperature","locked","position","state"],uf=["home","away","night","vacation","guest","party","occupied","closed","weekend","event","emergency","maintenance"],mf=t=>{switch(t){case"sensor_threshold":return{type:t,deviceId:"",sensorType:"temperature",unit:Ge.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}}},hf=({trigger:t,devices:s,scenes:n,onChange:o,onRemove:a})=>{const{t:i,lang:c}=S.useNiceTranslation(),r=l=>o({...t,...l});return e.jsxs("div",{className:P.ruleBlock,children:[e.jsxs("div",{className:P.ruleBlockHeader,children:[e.jsxs("select",{className:P.typeSelect,value:t.type,onChange:l=>o(mf(l.target.value)),children:[ys.map(([l,y,d])=>e.jsx("option",{value:l,children:i(y,d)},l)),!ys.some(([l])=>l===t.type)&&e.jsx("option",{value:t.type,disabled:!0,children:t.type})]}),e.jsx("button",{className:P.removeBtn,onClick:a,title:i("buildings.remove","Remove"),"aria-label":i("buildings.remove","Remove"),children:e.jsx(S.NiceIcon,{name:"close",size:14})})]}),t.type==="time"&&e.jsxs("div",{className:P.ruleFields,children:[e.jsxs("label",{children:[i("buildings.field.hour","Hour"),e.jsx("input",{type:"time",className:P.input,value:be(t,"time","08:00"),onChange:l=>r({time:l.target.value})})]}),e.jsxs("label",{children:[i("buildings.field.days","Days"),e.jsx("div",{className:P.dayPicker,children:cf(c).map((l,y)=>{const d=of(t),x=Nt[y],f=d.includes(x);return e.jsx("button",{type:"button","aria-pressed":f,className:`${P.dayBtn} ${f?P.dayBtnActive:""}`,onClick:()=>r({days:f?d.filter(p=>p!==x):Nt.filter(p=>p===x||d.includes(p))}),children:l},x)})})]})]}),(t.type==="sunrise"||t.type==="sunset")&&e.jsx("div",{className:P.ruleFields,children:e.jsxs("label",{children:[i("buildings.field.offsetMinutes","Offset (minutes)"),e.jsx("input",{type:"number",className:P.input,min:-120,max:120,step:5,value:jt(t,"offsetMinutes",0),onChange:l=>r({offsetMinutes:+l.target.value})})]})}),(t.type==="device_state"||t.type==="sensor_threshold")&&e.jsxs("div",{className:P.ruleFields,children:[e.jsxs("label",{children:[i("buildings.device","Device"),e.jsxs("select",{className:P.input,value:be(t,"deviceId",""),onChange:l=>r({deviceId:l.target.value}),children:[e.jsx("option",{value:"",children:i("buildings.selectPlaceholder","— select —")}),s.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:[i("buildings.field.attribute","Attribute"),e.jsx("input",{className:P.input,list:"nice-automation-attributes",value:be(t,"attribute","on"),onChange:l=>r({attribute:l.target.value})}),e.jsx("datalist",{id:"nice-automation-attributes",children:df.map(l=>e.jsx("option",{value:l},l))})]}),e.jsxs("label",{children:[i("buildings.field.operator","Operator"),e.jsx("select",{className:P.input,value:be(t,"operator","changed"),onChange:l=>r({operator:l.target.value,value:l.target.value==="changed"?void 0:be(t,"value","")}),children:lf.map(([l,y,d])=>e.jsx("option",{value:l,children:i(y,d)},l))})]}),be(t,"operator","changed")!=="changed"&&e.jsxs("label",{children:[i("buildings.field.value","Value"),e.jsx("input",{className:P.input,value:be(t,"value",""),onChange:l=>r({value:l.target.value})})]})]}),t.type==="sensor_threshold"&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{children:[i("buildings.field.sensor","Sensor"),e.jsx("select",{className:P.input,value:Wt(t),onChange:l=>{const y=l.target.value;r({sensorType:y,unit:Ge[y].unit,attribute:void 0})},children:Object.keys(Ge).map(l=>e.jsx("option",{value:l,children:i(`buildings.sensor.${l}`,Ge[l].name)},l))})]}),e.jsxs("label",{children:[i("buildings.field.operator","Operator"),e.jsxs("select",{className:P.input,value:be(t,"operator","above"),onChange:l=>r({operator:l.target.value}),children:[e.jsx("option",{value:"above",children:i("buildings.operator.above","above")}),e.jsx("option",{value:"below",children:i("buildings.operator.below","below")}),e.jsx("option",{value:"eq",children:i("buildings.operator.equals","equals")})]})]}),e.jsxs("label",{children:[i("buildings.field.threshold","Threshold"),Ge[Wt(t)].unit&&` (${Ge[Wt(t)].unit})`,e.jsx("input",{type:"number",className:P.input,value:jt(t,"threshold",0),onChange:l=>r({threshold:+l.target.value})})]})]})]}),t.type==="webhook"&&e.jsx("div",{className:P.ruleFields,children:e.jsxs("label",{children:[i("buildings.field.endpointId","Endpoint ID"),e.jsx("input",{className:P.input,value:be(t,"webhookId",""),onChange:l=>r({webhookId:l.target.value})})]})}),t.type==="geofence"&&e.jsxs("div",{className:P.ruleFields,children:[e.jsxs("label",{children:[i("buildings.field.zone","When"),e.jsxs("select",{className:P.input,value:be(t,"zone","home"),onChange:l=>r({zone:l.target.value}),children:[e.jsx("option",{value:"home",children:i("buildings.geofence.home","Arriving home")}),e.jsx("option",{value:"away",children:i("buildings.geofence.away","Leaving home")})]})]}),e.jsxs("label",{children:[i("buildings.field.radius","Radius (m)"),e.jsx("input",{type:"number",className:P.input,min:50,step:50,value:jt(t,"radius",200),onChange:l=>r({radius:+l.target.value})})]})]}),t.type==="scene_activated"&&e.jsx("div",{className:P.ruleFields,children:e.jsxs("label",{children:[i("buildings.scene","Scene"),e.jsxs("select",{className:P.input,value:be(t,"sceneId",""),onChange:l=>r({sceneId:l.target.value}),children:[e.jsx("option",{value:"",children:i("buildings.selectPlaceholder","— select —")}),n.map(l=>e.jsx("option",{value:l.id,children:l.name},l.id))]})]})}),t.type==="building_mode"&&e.jsx("div",{className:P.ruleFields,children:e.jsxs("label",{children:[i("buildings.mode","Mode"),e.jsx("select",{className:P.input,value:be(t,"mode","home"),onChange:l=>r({mode:l.target.value}),children:uf.map(l=>e.jsx("option",{value:l,children:i(`buildings.mode.${l}`,l.charAt(0).toUpperCase()+l.slice(1))},l))})]})}),t.type==="manual"&&e.jsx("div",{className:P.ruleFields,children:e.jsx("span",{children:i("buildings.trigger.manualHint","Runs only when started by hand.")})})]})},pf=({action:t,devices:s,scenes:n,onChange:o,onRemove:a})=>{const{t:i}=S.useNiceTranslation(),c=r=>o({...t,...r});return e.jsxs("div",{className:P.ruleBlock,children:[e.jsxs("div",{className:P.ruleBlockHeader,children:[e.jsxs("select",{className:P.typeSelect,value:t.type,onChange:r=>o({type:r.target.value}),children:[e.jsx("option",{value:"device_control",children:i("buildings.device","Device")}),e.jsx("option",{value:"scene_activate",children:i("buildings.activateScene","Activate scene")}),e.jsx("option",{value:"notification",children:i("buildings.action.notification","Notification")}),e.jsx("option",{value:"delay",children:i("buildings.action.delay","Delay")}),e.jsx("option",{value:"http_request",children:"HTTP Request"})]}),e.jsx("button",{className:P.removeBtn,onClick:a,title:i("buildings.remove","Remove"),"aria-label":i("buildings.remove","Remove"),children:e.jsx(S.NiceIcon,{name:"close",size:14})})]}),t.type==="device_control"&&e.jsxs("div",{className:P.ruleFields,children:[e.jsxs("label",{children:[i("buildings.device","Device"),e.jsxs("select",{className:P.input,value:be(t,"deviceId",""),onChange:r=>c({deviceId:r.target.value}),children:[e.jsx("option",{value:"",children:i("buildings.selectPlaceholder","— select —")}),s.map(r=>e.jsx("option",{value:r.id,children:r.name},r.id))]})]}),e.jsxs("label",{children:[i("buildings.field.stateJson","State (JSON)"),e.jsx("textarea",{className:P.textarea,rows:3,value:JSON.stringify(rf(t,"state"),null,2),onChange:r=>{try{c({state:JSON.parse(r.target.value)})}catch{}}})]})]}),t.type==="scene_activate"&&e.jsx("div",{className:P.ruleFields,children:e.jsxs("label",{children:[i("buildings.scene","Scene"),e.jsxs("select",{className:P.input,value:be(t,"sceneId",""),onChange:r=>c({sceneId:r.target.value}),children:[e.jsx("option",{value:"",children:i("buildings.selectPlaceholder","— select —")}),n.map(r=>e.jsx("option",{value:r.id,children:r.name},r.id))]})]})}),t.type==="notification"&&e.jsxs("div",{className:P.ruleFields,children:[e.jsxs("label",{children:[i("buildings.field.channel","Channel"),e.jsxs("select",{className:P.input,value:be(t,"channel","push"),onChange:r=>c({channel:r.target.value}),children:[e.jsx("option",{value:"push",children:"Push"}),e.jsx("option",{value:"email",children:"Email"}),e.jsx("option",{value:"sms",children:"SMS"}),e.jsx("option",{value:"in_app",children:"In-app"}),e.jsx("option",{value:"teams",children:"Teams"}),e.jsx("option",{value:"slack",children:"Slack"})]})]}),e.jsxs("label",{children:[i("buildings.field.message","Message"),e.jsx("input",{className:P.input,value:be(t,"message",""),onChange:r=>c({message:r.target.value})})]})]}),t.type==="delay"&&e.jsx("div",{className:P.ruleFields,children:e.jsxs("label",{children:[i("buildings.field.delaySeconds","Delay (seconds)"),e.jsx("input",{type:"number",className:P.input,min:1,value:jt(t,"delaySeconds",60),onChange:r=>c({delaySeconds:+r.target.value})})]})}),t.type==="http_request"&&e.jsxs("div",{className:P.ruleFields,children:[e.jsxs("label",{children:["URL",e.jsx("input",{className:P.input,value:be(t,"url",""),onChange:r=>c({url:r.target.value})})]}),e.jsxs("label",{children:[i("buildings.field.method","Method"),e.jsxs("select",{className:P.input,value:be(t,"method","POST"),onChange:r=>c({method:r.target.value}),children:[e.jsx("option",{children:"GET"}),e.jsx("option",{children:"POST"}),e.jsx("option",{children:"PUT"}),e.jsx("option",{children:"PATCH"})]})]})]})]})},ff=({automations:t,defaultAutomations:s,devices:n=[],scenes:o=[],onAutomationsChange:a,onDelete:i,onToggle:c,readOnly:r=!1,className:l,style:y,theme:d="light",tutorial:x})=>{var q;const{t:f}=S.useNiceTranslation(),[p,_]=S.useControllableState({value:t,defaultValue:s,fallbackValue:[],onChange:a,componentName:"NiceAutomationEditor"}),[j,h]=m.useState(null),k=j!==null&&p.some(I=>I.id===j)?j:((q=p[0])==null?void 0:q.id)??null,C=p.find(I=>I.id===k)??null,T=m.useCallback(I=>{C&&_(p.map(B=>B.id===C.id?{...B,...I}:B))},[C,p,_]),b=m.useCallback(()=>{const I={id:`auto-${Date.now()}`,name:"New automation",enabled:!0,triggers:[],conditions:[],actions:[]};_([...p,I]),h(I.id)},[p,_]),L=m.useCallback(I=>{var B;_(p.filter(V=>V.id!==I)),k===I&&h(((B=p.find(V=>V.id!==I))==null?void 0:B.id)??null),i==null||i(I)},[p,k,_,i]),u=m.useCallback((I,B)=>{_(p.map(V=>V.id===I?{...V,enabled:B}:V)),c==null||c(I,B)},[p,_,c]),v=e.jsxs("div",{className:P.listPanel,children:[e.jsxs("div",{className:P.listHeader,children:[e.jsx("span",{className:P.listTitle,children:f("buildings.automations","Automations")}),!r&&e.jsxs("button",{className:P.addBtn,onClick:b,children:[e.jsx(S.NiceIcon,{name:"plus",size:12})," ",f("buildings.add","Add")]})]}),e.jsxs("div",{className:P.list,children:[p.map(I=>e.jsxs("div",{className:`${P.listItem} ${k===I.id?P.listItemActive:""}`,onClick:()=>h(I.id),children:[e.jsx("div",{className:P.listItemName,children:I.name}),e.jsxs("div",{className:P.listItemMeta,children:[I.triggers.length," ",f("buildings.triggersShort","triggers")," ·"," ",I.actions.length," ",f("buildings.actionsShort","actions")]}),e.jsx("button",{className:`${P.enableToggle} ${I.enabled?P.enableOn:""}`,disabled:r,onClick:B=>{B.stopPropagation(),u(I.id,!I.enabled)},title:I.enabled?f("buildings.disable","Disable"):f("buildings.enable","Enable"),"aria-label":I.enabled?f("buildings.disable","Disable"):f("buildings.enable","Enable"),children:e.jsx(S.NiceIcon,{name:I.enabled?"check":"close",size:14})})]},I.id)),p.length===0&&e.jsx("div",{className:P.emptyHint,children:f("buildings.noAutomations","No automations")})]})]}),g=e.jsx("div",{className:P.detailPanel,children:C?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:P.detailHeader,children:[e.jsx("input",{className:P.nameInput,value:C.name,onChange:I=>T({name:I.target.value}),readOnly:r}),!r&&e.jsx("button",{className:P.deleteBtn,onClick:()=>L(C.id),children:f("buildings.remove","Remove")})]}),e.jsxs("fieldset",{className:P.rules,disabled:r,children:[e.jsxs("section",{className:P.section,children:[e.jsxs("div",{className:P.sectionHeader,children:[e.jsx("span",{className:P.sectionTitle,children:f("buildings.triggers","Triggers")}),!r&&e.jsxs("button",{className:P.sectionAddBtn,onClick:()=>T({triggers:[...C.triggers,{type:"time"}]}),children:[e.jsx(S.NiceIcon,{name:"plus",size:12})," ",f("buildings.add","Add")]})]}),C.triggers.map((I,B)=>e.jsx(hf,{trigger:I,devices:n,scenes:o,onChange:V=>T({triggers:C.triggers.map((te,ue)=>ue===B?V:te)}),onRemove:()=>T({triggers:C.triggers.filter((V,te)=>te!==B)})},B)),C.triggers.length===0&&e.jsx("div",{className:P.emptyHint,children:f("buildings.noTriggers","No triggers")})]}),e.jsxs("section",{className:P.section,children:[e.jsxs("div",{className:P.sectionHeader,children:[e.jsx("span",{className:P.sectionTitle,children:f("buildings.actions","Actions")}),!r&&e.jsxs("button",{className:P.sectionAddBtn,onClick:()=>T({actions:[...C.actions,{type:"device_control"}]}),children:[e.jsx(S.NiceIcon,{name:"plus",size:12})," ",f("buildings.add","Add")]})]}),C.actions.map((I,B)=>e.jsx(pf,{action:I,devices:n,scenes:o,onChange:V=>T({actions:C.actions.map((te,ue)=>ue===B?V:te)}),onRemove:()=>T({actions:C.actions.filter((V,te)=>te!==B)})},B)),C.actions.length===0&&e.jsx("div",{className:P.emptyHint,children:f("buildings.noActions","No actions")})]})]})]}):e.jsx("div",{className:P.noSelection,children:f("buildings.noAutomationSelected","Select an automation or add a new one")})});return e.jsxs("div",{className:`nice-building-automation-editor ${P.root} ${d==="dark"?P.dark:""} ${l??""}`,style:{position:"relative",...y},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:e.jsx(S.NiceTutorialButton,{steps:S.resolveTutorial(x,nf)})}),e.jsx(S.NiceAppShell,{flush:!0,className:P.shell,sidebar:v,children:g})]})},_f="_root_2mz7s_3",gf="_shell_2mz7s_29",yf="_dark_2mz7s_37",bf="_gridPanel_2mz7s_51",xf="_gridHeader_2mz7s_79",vf="_gridTitle_2mz7s_103",jf="_addBtn_2mz7s_119",wf="_sceneGrid_2mz7s_147",Nf="_sceneCard_2mz7s_165",kf="_sceneCardActive_2mz7s_193",If="_sceneCardSelected_2mz7s_199",Cf="_sceneCardIcon_2mz7s_207",Sf="_sceneCardName_2mz7s_217",Lf="_sceneCardDevices_2mz7s_235",Tf="_activeBadge_2mz7s_253",$f="_activateBtn_2mz7s_263",zf="_emptyGrid_2mz7s_307",Mf="_detailPanel_2mz7s_325",Bf="_metaRow_2mz7s_343",Ef="_iconPicker_2mz7s_355",Pf="_currentIcon_2mz7s_363",Af="_iconGrid_2mz7s_381",Of="_iconOpt_2mz7s_397",Df="_iconOptActive_2mz7s_423",Rf="_metaFields_2mz7s_433",qf="_nameInput_2mz7s_447",Ff="_descInput_2mz7s_481",Gf="_colorPicker_2mz7s_517",Wf="_colorOpt_2mz7s_527",Vf="_colorOptActive_2mz7s_543",Hf="_targetsSection_2mz7s_553",Uf="_targetsSectionHeader_2mz7s_575",Yf="_addTargetBtn_2mz7s_597",Zf="_targetRow_2mz7s_625",Xf="_targetSelect_2mz7s_655",Kf="_targetState_2mz7s_687",Jf="_targetField_2mz7s_701",Qf="_tempInput_2mz7s_727",e_="_removeTargetBtn_2mz7s_745",t_="_noTargets_2mz7s_785",s_="_detailActions_2mz7s_805",n_="_activateFullBtn_2mz7s_819",o_="_deleteBtn_2mz7s_851",Y={root:_f,shell:gf,dark:yf,gridPanel:bf,gridHeader:xf,gridTitle:vf,addBtn:jf,sceneGrid:wf,sceneCard:Nf,sceneCardActive:kf,sceneCardSelected:If,sceneCardIcon:Cf,sceneCardName:Sf,sceneCardDevices:Lf,activeBadge:Tf,activateBtn:$f,emptyGrid:zf,detailPanel:Mf,metaRow:Bf,iconPicker:Ef,currentIcon:Pf,iconGrid:Af,iconOpt:Of,iconOptActive:Df,metaFields:Rf,nameInput:qf,descInput:Ff,colorPicker:Gf,colorOpt:Wf,colorOptActive:Vf,targetsSection:Hf,targetsSectionHeader:Uf,addTargetBtn:Yf,targetRow:Zf,targetSelect:Xf,targetState:Kf,targetField:Jf,tempInput:Qf,removeTargetBtn:e_,noTargets:t_,detailActions:s_,activateFullBtn:n_,deleteBtn:o_},a_=[{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"}],Je=t=>t&&typeof t=="object"?t:{},i_=(t,s,n=!1)=>{const o=Je(t)[s];return typeof o=="boolean"?o:n},ot=(t,s,n=0)=>{const o=Je(t)[s];return typeof o=="number"?o:n},r_=["video","eye-off","lightbulb","gamepad","briefcase","utensils","music","droplet","rocket","home","thermometer","lock","star","gift","heart","settings"],c_=["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)","#fff7ed"],l_=({target:t,devices:s,onChange:n,onRemove:o})=>{const{t:a}=S.useNiceTranslation(),i=s.find(c=>c.id===t.deviceId);return e.jsxs("div",{className:Y.targetRow,children:[e.jsxs("select",{className:Y.targetSelect,value:t.deviceId,onChange:c=>n({...t,deviceId:c.target.value}),children:[e.jsxs("option",{value:"",children:["— ",a("buildings.device","device")," —"]}),s.map(c=>e.jsx("option",{value:c.id,children:c.name},c.id))]}),i&&e.jsxs("div",{className:Y.targetState,children:[e.jsxs("label",{className:Y.targetField,children:[e.jsx("span",{children:a("buildings.onOff","On/Off")}),e.jsx("input",{type:"checkbox",checked:i_(t.state,"on",!1),onChange:c=>n({...t,state:{...Je(t.state),on:c.target.checked}})})]}),(i.type==="dimmer"||i.type==="light"||i.type==="rgb_light"||i.type==="led_strip")&&e.jsxs("label",{className:Y.targetField,children:[e.jsx("span",{children:a("buildings.brightness","Brightness")}),e.jsx("input",{type:"range",min:0,max:100,value:ot(t.state,"brightness",100),onChange:c=>n({...t,state:{...Je(t.state),brightness:+c.target.value}})}),e.jsxs("span",{children:[ot(t.state,"brightness",100),"%"]})]}),(i.type==="blind"||i.type==="shutter")&&e.jsxs("label",{className:Y.targetField,children:[e.jsx("span",{children:a("buildings.position","Position")}),e.jsx("input",{type:"range",min:0,max:100,value:ot(t.state,"position",100),onChange:c=>n({...t,state:{...Je(t.state),position:+c.target.value}})}),e.jsxs("span",{children:[ot(t.state,"position",100),"%"]})]}),(i.type==="thermostat"||i.type==="air_conditioner")&&e.jsxs("label",{className:Y.targetField,children:[e.jsx("span",{children:"Temp."}),e.jsx("input",{type:"number",className:Y.tempInput,min:10,max:30,step:.5,value:ot(t.state,"targetTemperature",20),onChange:c=>n({...t,state:{...Je(t.state),targetTemperature:+c.target.value}})}),e.jsx("span",{children:"°C"})]})]}),e.jsx("button",{className:Y.removeTargetBtn,onClick:o,title:a("buildings.remove","Remove"),"aria-label":a("buildings.remove","Remove"),children:e.jsx(S.NiceIcon,{name:"close",size:14})})]})},d_=({scenes:t,defaultScenes:s,devices:n=[],activeSceneIds:o=[],onScenesChange:a,onActivate:i,onDelete:c,readOnly:r=!1,className:l,style:y,theme:d="light",tutorial:x})=>{var q;const{t:f}=S.useNiceTranslation(),[p,_]=S.useControllableState({value:t,defaultValue:s,fallbackValue:[],onChange:a,componentName:"NiceSceneEditor"}),[j,h]=m.useState(null),k=j!==null&&p.some(I=>I.id===j)?j:((q=p[0])==null?void 0:q.id)??null,C=p.find(I=>I.id===k)??null,T=m.useCallback(I=>{C&&_(p.map(B=>B.id===C.id?{...B,...I}:B))},[C,p,_]),b=m.useCallback(()=>{const I={id:`scene-${Date.now()}`,name:"New scene",deviceTargets:[],icon:"video",color:"var(--nice-primary-bg, #e0f2fe)"};_([...p,I]),h(I.id)},[p,_]),L=m.useCallback(I=>{var B;_(p.filter(V=>V.id!==I)),k===I&&h(((B=p.find(V=>V.id!==I))==null?void 0:B.id)??null),c==null||c(I)},[p,k,_,c]),u=()=>{if(!C)return;const I={deviceId:"",state:{on:!0},transitionMs:1e3};T({deviceTargets:[...C.deviceTargets,I]})},v=e.jsxs("div",{className:Y.gridPanel,children:[e.jsxs("div",{className:Y.gridHeader,children:[e.jsx("span",{className:Y.gridTitle,children:f("buildings.scenes","Scenes")}),!r&&e.jsxs("button",{className:Y.addBtn,onClick:b,children:[e.jsx(S.NiceIcon,{name:"plus",size:12})," ",f("buildings.new","New")]})]}),e.jsxs("div",{className:Y.sceneGrid,children:[p.map(I=>{const B=o.includes(I.id),V=k===I.id;return e.jsxs("div",{className:`${Y.sceneCard} ${B?Y.sceneCardActive:""} ${V?Y.sceneCardSelected:""}`,style:{background:I.color??"var(--nice-bg-secondary, #f8fafc)"},onClick:()=>h(I.id),children:[e.jsx("div",{className:Y.sceneCardIcon,children:e.jsx(S.NiceIcon,{name:I.icon??"video",size:20})}),e.jsx("div",{className:Y.sceneCardName,children:I.name}),e.jsxs("div",{className:Y.sceneCardDevices,children:[I.deviceTargets.length," ",f("buildings.devices","devices"),B&&e.jsx("span",{className:Y.activeBadge,children:e.jsx(S.NiceIcon,{name:"check",size:12})})]}),e.jsx("button",{className:Y.activateBtn,"aria-label":f("buildings.activate","Activate"),onClick:te=>{te.stopPropagation(),i==null||i(I.id)},children:e.jsx(S.NiceIcon,{name:"play",size:14})})]},I.id)}),p.length===0&&e.jsx("div",{className:Y.emptyGrid,children:f("buildings.noScenes","No scenes yet. Add the first one!")})]})]}),g=C?e.jsxs("div",{className:Y.detailPanel,children:[e.jsxs("div",{className:Y.metaRow,children:[e.jsxs("div",{className:Y.iconPicker,children:[e.jsx("span",{className:Y.currentIcon,children:e.jsx(S.NiceIcon,{name:C.icon??"video",size:20})}),e.jsx("div",{className:Y.iconGrid,children:r_.map(I=>e.jsx("button",{className:`${Y.iconOpt} ${C.icon===I?Y.iconOptActive:""}`,"aria-label":I,onClick:()=>T({icon:I}),children:e.jsx(S.NiceIcon,{name:I,size:16})},I))})]}),e.jsxs("div",{className:Y.metaFields,children:[e.jsx("input",{className:Y.nameInput,value:C.name,readOnly:r,onChange:I=>T({name:I.target.value}),placeholder:f("buildings.sceneName","Scene name")}),e.jsx("textarea",{className:Y.descInput,value:C.description??"",readOnly:r,onChange:I=>T({description:I.target.value}),placeholder:f("buildings.descriptionOptional","Description (optional)"),rows:2})]})]}),!r&&e.jsx("div",{className:Y.colorPicker,children:c_.map(I=>e.jsx("button",{className:`${Y.colorOpt} ${C.color===I?Y.colorOptActive:""}`,style:{background:I},onClick:()=>T({color:I})},I))}),e.jsxs("fieldset",{className:Y.targetsSection,disabled:r,children:[e.jsxs("div",{className:Y.targetsSectionHeader,children:[e.jsx("span",{children:f("buildings.devicesInScene","Devices in this scene")}),!r&&e.jsxs("button",{className:Y.addTargetBtn,onClick:u,children:[e.jsx(S.NiceIcon,{name:"plus",size:12})," ",f("buildings.add","Add")]})]}),C.deviceTargets.map((I,B)=>e.jsx(l_,{target:I,devices:n,onChange:V=>T({deviceTargets:C.deviceTargets.map((te,ue)=>ue===B?V:te)}),onRemove:()=>T({deviceTargets:C.deviceTargets.filter((V,te)=>te!==B)})},B)),C.deviceTargets.length===0&&e.jsx("div",{className:Y.noTargets,children:f("buildings.sceneHint","Add the devices this scene should control.")})]}),e.jsxs("div",{className:Y.detailActions,children:[e.jsxs("button",{className:Y.activateFullBtn,onClick:()=>i==null?void 0:i(C.id),children:[e.jsx(S.NiceIcon,{name:"play",size:14})," ",f("buildings.activateScene","Activate scene")]}),!r&&e.jsx("button",{className:Y.deleteBtn,onClick:()=>L(C.id),children:f("buildings.remove","Remove")})]})]}):void 0;return e.jsxs("div",{className:`nice-scene-editor ${Y.root} ${d==="dark"?Y.dark:""} ${l??""}`,style:{position:"relative",...y},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:e.jsx(S.NiceTutorialButton,{steps:S.resolveTutorial(x,a_)})}),e.jsx(S.NiceAppShell,{flush:!0,className:Y.shell,sidebar:v,children:g})]})};exports.LayerPanel=ks;exports.Minimap=Is;exports.NiceAutomationEditor=ff;exports.NiceBuildingDashboard=eh;exports.NiceDeviceControl=vp;exports.NiceFloorPlanEditor=On;exports.NiceLightControl=Ts;exports.NiceSceneEditor=d_;exports.NiceSpatialEditor=xd;exports.NiceSpatialViewer=nm;exports.NiceThermostatControl=zs;exports.NiceZoneCard=Ls;exports.ObjectLibrary=Cs;exports.PropertiesPanel=Ss;exports.useMeasurement=im;exports.useSnapToGrid=am;exports.useSpatialEditor=om;
|
|
139
|
+
`,g=I=>I.boundary;return v.forEach((I,y)=>{const L=g(I);if(I.type==="wall"&&I.bounds)x.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-${y}`));else if(I.type==="zone"&&L){const _=L.map((C,d)=>`${d===0?"M":"L"} ${C.x} ${C.y}`).join(" ")+" Z";x.push(e.jsx("path",{d:_,fill:"var(--nice-primary-tint-20, rgba(59, 130, 246, 0.2))",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:"1"},`zone-${y}`))}else if(I.type==="room"&&L){const _=L.map((C,d)=>`${d===0?"M":"L"} ${C.x} ${C.y}`).join(" ")+" Z";x.push(e.jsx("path",{d:_,fill:"var(--nice-success-tint-15, rgba(34, 197, 94, 0.15))",stroke:"var(--nice-success, #22c55e)",strokeWidth:"1"},`room-${y}`))}else I.bounds&&x.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-${y}`))}),e.jsxs("svg",{viewBox:`${h.x} ${h.y} ${h.width} ${h.height}`,className:U.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)"}),x]})},[a,i]),r=u.useCallback(h=>{h.key==="Escape"&&s()},[s]),l=u.useCallback(h=>{h.target===h.currentTarget&&s()},[s]),b=t.errors.some(h=>h.fatal),m=t.errors.filter(h=>!h.fatal);return e.jsx("div",{className:U.overlay,onClick:l,onKeyDown:r,tabIndex:-1,role:"dialog","aria-modal":"true","aria-labelledby":"import-preview-title",children:e.jsxs("div",{className:U.dialog,children:[e.jsxs("div",{className:U.header,children:[e.jsx("h2",{id:"import-preview-title",className:U.title,children:o("importPreviewDialog.importPreview","Import Preview")}),e.jsx("button",{className:U.closeButton,onClick:s,title:o("importPreviewDialog.close","Close"),"aria-label":o("importPreviewDialog.closeDialog","Close dialog"),children:e.jsx(sa,{})})]}),e.jsxs("div",{className:U.content,children:[e.jsx("div",{className:U.preview,children:c||e.jsx("div",{className:U.previewCanvas,children:o("importPreviewDialog.noPreviewAvailable","No preview available")})}),e.jsxs("div",{className:U.info,children:[e.jsxs("div",{className:U.section,children:[e.jsxs("h3",{className:U.sectionTitle,children:[e.jsx(oa,{})," ",o("importPreviewDialog.importStatistics","Import Statistics")]}),e.jsxs("div",{className:U.statGrid,children:[e.jsxs("div",{className:U.stat,children:[e.jsx("div",{className:U.statLabel,children:o("importPreviewDialog.walls","Walls")}),e.jsx("div",{className:U.statValue,children:t.stats.wallsImported})]}),e.jsxs("div",{className:U.stat,children:[e.jsx("div",{className:U.statLabel,children:o("importPreviewDialog.zones","Zones")}),e.jsx("div",{className:U.statValue,children:t.stats.zonesImported})]}),e.jsxs("div",{className:U.stat,children:[e.jsx("div",{className:U.statLabel,children:o("importPreviewDialog.objects","Objects")}),e.jsx("div",{className:U.statValue,children:t.stats.objectsImported})]}),e.jsxs("div",{className:U.stat,children:[e.jsx("div",{className:U.statLabel,children:o("importPreviewDialog.skipped","Skipped")}),e.jsx("div",{className:U.statValue,children:t.stats.entitiesSkipped})]})]})]}),a&&a.layers.length>0&&e.jsxs("div",{className:U.section,children:[e.jsxs("h3",{className:U.sectionTitle,children:[e.jsx(sn,{})," ",o("importPreviewDialog.layers","Layers ({layers})").replace("{layers}",String(a.layers.length))]}),e.jsxs("ul",{className:U.layersList,children:[a.layers.slice(0,6).map((h,v)=>{var x;return e.jsxs("li",{className:U.layer,children:[e.jsx("span",{className:U.layerIcon,children:e.jsx(sn,{})}),e.jsx("span",{className:U.layerName,children:h.name}),e.jsx("span",{className:U.layerCount,children:((x=h.objects)==null?void 0:x.length)||0})]},h.id||v)}),a.layers.length>6&&e.jsx("li",{className:U.layer,children:e.jsx("span",{className:U.layerName,children:o("importPreviewDialog.more","+{layers} more...").replace("{layers}",String(a.layers.length-6))})})]})]}),t.warnings.length>0&&e.jsxs("div",{className:U.section,children:[e.jsxs("h3",{className:U.sectionTitle,children:[e.jsx(tn,{})," ",o("importPreviewDialog.warnings","Warnings ({warnings})").replace("{warnings}",String(t.warnings.length))]}),e.jsxs("ul",{className:U.warningsList,children:[t.warnings.slice(0,5).map((h,v)=>e.jsxs("li",{className:U.warning,children:[e.jsx("span",{className:U.warningIcon,children:e.jsx(tn,{})}),e.jsx("span",{children:h.message})]},v)),t.warnings.length>5&&e.jsx("li",{className:U.warning,children:o("importPreviewDialog.moreWarnings","+{warnings} more warnings...").replace("{warnings}",String(t.warnings.length-5))})]})]}),m.length>0&&e.jsxs("div",{className:U.section,children:[e.jsxs("h3",{className:U.sectionTitle,children:[e.jsx(nn,{})," ",o("importPreviewDialog.errors","Errors ({nonFatalErrors})").replace("{nonFatalErrors}",String(m.length))]}),e.jsx("ul",{className:U.warningsList,children:m.slice(0,5).map((h,v)=>e.jsxs("li",{className:U.error,children:[e.jsx("span",{className:U.errorIcon,children:e.jsx(nn,{})}),e.jsx("span",{children:h.message})]},v))})]}),t.warnings.length===0&&m.length===0&&e.jsx("div",{className:U.section,children:e.jsxs("p",{className:U.noWarnings,children:[e.jsx(N.NiceIcon,{name:"check",size:14})," ",o("importPreviewDialog.noWarningsOrErrorsFound","No warnings or errors found")]})})]})]}),e.jsxs("div",{className:U.footer,children:[e.jsx("button",{className:U.cancelButton,onClick:s,children:o("importPreviewDialog.cancel","Cancel")}),e.jsx("button",{className:U.confirmButton,onClick:n,disabled:b,children:b?o("importPreviewDialog.cannotImportFatalErrors","Cannot Import (Fatal Errors)"):o("importPreviewDialog.confirmImport","Confirm Import")})]})]})})}const ia="_overlay_1jmp3_9",ra="_dialog_1jmp3_55",ca="_header_1jmp3_103",la="_title_1jmp3_119",da="_closeButton_1jmp3_133",ua="_content_1jmp3_167",ma="_description_1jmp3_179",pa="_mappingTable_1jmp3_191",ha="_sourceLayer_1jmp3_241",ga="_layerIcon_1jmp3_253",_a="_layerName_1jmp3_261",fa="_objectCount_1jmp3_273",ya="_targetSelect_1jmp3_285",ba="_skipOption_1jmp3_327",xa="_arrowIcon_1jmp3_337",va="_presets_1jmp3_347",ja="_presetButton_1jmp3_361",Na="_footer_1jmp3_393",wa="_footerLeft_1jmp3_413",Ia="_checkbox_1jmp3_425",ka="_checkboxLabel_1jmp3_437",Sa="_footerRight_1jmp3_447",Ca="_cancelButton_1jmp3_457",Ta="_confirmButton_1jmp3_489",re={overlay:ia,dialog:ra,header:ca,title:la,closeButton:da,content:ua,description:ma,mappingTable:pa,sourceLayer:ha,layerIcon:ga,layerName:_a,objectCount:fa,targetSelect:ya,skipOption:ba,arrowIcon:xa,presets:va,presetButton:ja,footer:Na,footerLeft:wa,checkbox:Ia,checkboxLabel:ka,footerRight:Sa,cancelButton:Ca,confirmButton:Ta},on=()=>e.jsx(N.NiceIcon,{name:"close",size:20}),La=()=>e.jsx(N.NiceIcon,{name:"layers",size:14}),$a=()=>e.jsx(N.NiceIcon,{name:"arrow-right",size:16}),an={"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 za(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 Pa(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 rn(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 Ma=({importResult:t,existingDocument:n,onConfirm:s,onCancel:o})=>{const{t:i}=N.useNiceTranslation(),a=u.useMemo(()=>za(t),[t]),c=u.useMemo(()=>Pa(n),[n]),[r,l]=u.useState(()=>rn(a,c)),[b,m]=u.useState(!0),h=u.useCallback((g,I)=>{l(y=>{const L=new Map(y);return L.set(g,I),L})},[]),v=u.useCallback(g=>{const I=new Map;switch(g){case"auto":l(rn(a,c));return;case"skip-all":for(const y of a)I.set(y.id,"skip");break;case"preserve":for(const y of a)I.set(y.id,y.id);break}l(I)},[a,c]),x=u.useCallback(()=>{s(r,b)},[r,b,s]),p=u.useCallback(g=>{g.key==="Escape"?o():g.key==="Enter"&&(g.ctrlKey||g.metaKey)&&x()},[o,x]),j=u.useCallback(g=>{g.target===g.currentTarget&&o()},[o]);return a.length===0?e.jsx("div",{className:re.overlay,onClick:j,onKeyDown:p,tabIndex:-1,children:e.jsxs("div",{className:re.dialog,children:[e.jsxs("div",{className:re.header,children:[e.jsx("h2",{className:re.title,children:i("buildings.layerMapping","Layer mapping")}),e.jsx("button",{className:re.closeButton,onClick:o,children:e.jsx(on,{})})]}),e.jsx("div",{className:re.content,children:e.jsx("p",{className:re.description,children:i("buildings.spatial.noLayersInFile","The imported file contains no layers.")})}),e.jsxs("div",{className:re.footer,children:[e.jsx("div",{className:re.footerLeft}),e.jsx("div",{className:re.footerRight,children:e.jsx("button",{className:re.cancelButton,onClick:o,children:i("buildings.spatial.close","Close")})})]})]})}):e.jsx("div",{className:re.overlay,onClick:j,onKeyDown:p,tabIndex:-1,children:e.jsxs("div",{className:re.dialog,children:[e.jsxs("div",{className:re.header,children:[e.jsx("h2",{className:re.title,children:i("buildings.layerMapping","Layer mapping")}),e.jsx("button",{className:re.closeButton,onClick:o,children:e.jsx(on,{})})]}),e.jsxs("div",{className:re.content,children:[e.jsx("p",{className:re.description,children:i("buildings.spatial.mappingHint","Choose how the layers from the imported file map onto the editor layers.")}),e.jsxs("table",{className:re.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(g=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsxs("div",{className:re.sourceLayer,children:[e.jsx("span",{className:re.layerIcon,children:e.jsx(La,{})}),e.jsx("span",{className:re.layerName,children:g.name}),e.jsxs("span",{className:re.objectCount,children:["(",g.objectCount," ",g.objectCount===1?i("buildings.spatial.object","object"):i("buildings.spatial.objects","objects"),")"]})]})}),e.jsx("td",{className:re.arrowIcon,children:e.jsx($a,{})}),e.jsx("td",{children:e.jsxs("select",{className:re.targetSelect,value:r.get(g.id)||g.id,onChange:I=>h(g.id,I.target.value),children:[e.jsxs("option",{value:"skip",className:re.skipOption,children:["— ",i("buildings.spatial.skipLayer","Skip this layer")," —"]}),e.jsxs("option",{value:g.id,children:[i("buildings.spatial.create","Create"),": ",g.name," (",an[g.type],")"]}),c.map(I=>e.jsxs("option",{value:I.id,children:[I.name," (",an[I.type],")"]},I.id))]})})]},g.id))})]}),e.jsxs("div",{className:re.presets,children:[e.jsx("button",{className:re.presetButton,onClick:()=>v("auto"),children:i("buildings.autoMapping","Auto-mapping")}),e.jsx("button",{className:re.presetButton,onClick:()=>v("preserve"),children:i("buildings.spatial.keepAll","Keep all")}),e.jsx("button",{className:re.presetButton,onClick:()=>v("skip-all"),children:i("buildings.spatial.skipAll","Skip all")})]})]}),e.jsxs("div",{className:re.footer,children:[e.jsxs("div",{className:re.footerLeft,children:[e.jsx("input",{type:"checkbox",id:"createMissing",className:re.checkbox,checked:b,onChange:g=>m(g.target.checked)}),e.jsx("label",{htmlFor:"createMissing",className:re.checkboxLabel,children:i("buildings.spatial.createMissing","Create the missing layers")})]}),e.jsxs("div",{className:re.footerRight,children:[e.jsx("button",{className:re.cancelButton,onClick:o,children:i("buildings.spatial.cancel","Cancel")}),e.jsx("button",{className:re.confirmButton,onClick:x,children:i("buildings.spatial.applyMapping","Apply mapping")})]})]})]})})},Ea="_root_4ino1_9",Oa="_header_4ino1_21",Aa="_title_4ino1_31",Ba="_layerList_4ino1_45",Da="_layerItem_4ino1_55",Ra="_hidden_4ino1_83",qa="_locked_4ino1_91",Fa="_visibilityBtn_4ino1_99",Ga="_lockBtn_4ino1_101",Va="_layerIcon_4ino1_139",Wa="_layerName_4ino1_147",Ha="_opacitySlider_4ino1_157",Te={root:Ea,header:Oa,title:Aa,layerList:Ba,layerItem:Da,hidden:Ra,locked:qa,visibilityBtn:Fa,lockBtn:Ga,layerIcon:Va,layerName:Wa,opacitySlider:Ha},Ua={"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"}},kn=({layers:t,onVisibilityToggle:n,onLockToggle:s,onOpacityChange:o,className:i})=>{const{t:a}=N.useNiceTranslation(),c=[...t].sort((r,l)=>l.zIndex-r.zIndex);return e.jsxs("div",{className:`${Te.root} ${i??""}`,children:[e.jsx("div",{className:Te.header,children:e.jsx("h3",{className:Te.title,children:a("layerPanel.layers","Layers")})}),e.jsx("div",{className:Te.layerList,children:c.map(r=>{const l=Ua[r.type]||{icon:"box",label:r.type};return e.jsxs("div",{className:`${Te.layerItem} ${r.visible?"":Te.hidden} ${r.locked?Te.locked:""}`,children:[e.jsx("button",{className:Te.visibilityBtn,onClick:()=>n(r.type),title:r.visible?a("layerPanel.hideLayer","Hide layer"):a("layerPanel.showLayer","Show layer"),children:e.jsx(N.NiceIcon,{name:r.visible?"eye":"eye-off",size:16})}),e.jsx("button",{className:Te.lockBtn,onClick:()=>s(r.type),title:r.locked?a("layerPanel.unlockLayer","Unlock layer"):a("layerPanel.lockLayer","Lock layer"),children:e.jsx(N.NiceIcon,{name:"lock",size:16})}),e.jsx("span",{className:Te.layerIcon,children:e.jsx(N.NiceIcon,{name:l.icon,size:16})}),e.jsx("span",{className:Te.layerName,children:l.label}),e.jsx("input",{type:"range",min:"0",max:"1",step:"0.1",value:r.opacity,onChange:b=>o(r.type,parseFloat(b.target.value)),className:Te.opacitySlider,title:a("layerPanel.opacity","Opacity: {opacity}%").replace("{opacity}",String(Math.round(r.opacity*100)))})]},r.type)})})]})},Ya="_root_1lufq_9",Za="_svg_1lufq_31",Xa="_viewportRect_1lufq_41",Ka="_zoomIndicator_1lufq_49",gt={root:Ya,svg:Za,viewportRect:Xa,zoomIndicator:Ka},Sn=({document:t,activeFloorId:n,viewport:s,onViewportChange:o,size:i=150,className:a})=>{var L,_;const c=u.useRef(null),r=u.useMemo(()=>t.floors.find(C=>C.id===n)??t.floors[0]??null,[t,n]),l=((L=r==null?void 0:r.dimensions)==null?void 0:L.width)??1e3,b=((_=r==null?void 0:r.dimensions)==null?void 0:_.height)??800,m=Math.min(i/l,i/b)*.9,h=l*m,v=b*m,x=i/s.zoom*m,p=i/s.zoom*m,j=-s.pan.x/s.zoom*m,g=-s.pan.y/s.zoom*m,I=u.useCallback(C=>{var M;const d=(M=c.current)==null?void 0:M.getBoundingClientRect();if(!d)return;const w=(C.clientX-d.left-(i-h)/2)/m,f=(C.clientY-d.top-(i-v)/2)/m,q=-(w-i/s.zoom/2)*s.zoom,T=-(f-i/s.zoom/2)*s.zoom;o({pan:{x:q,y:T}})},[m,i,h,v,s.zoom,o]),y=u.useMemo(()=>{const C=r==null?void 0:r.layers.find(d=>d.name==="zones");return C?C.objects.map(d=>{const w=d;if(!w.polygon||w.polygon.length<3)return null;const f=w.polygon.map((q,T)=>`${T===0?"M":"L"}${q.x*m},${q.y*m}`).join(" ")+" Z";return e.jsx("path",{d:f,fill:w.color??"var(--nice-primary-bg, #dbeafe)",fillOpacity:.6,stroke:"var(--nice-text-muted, #94a3b8)",strokeWidth:.5},w.id)}):null},[r,m]);return r?e.jsxs("div",{className:`${gt.root} ${a??""}`,children:[e.jsxs("svg",{ref:c,width:i,height:i,viewBox:`0 0 ${i} ${i}`,className:gt.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:y}),e.jsx("rect",{x:(i-h)/2+j,y:(i-v)/2+g,width:Math.min(x,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:gt.viewportRect})]}),e.jsxs("div",{className:gt.zoomIndicator,children:[Math.round(s.zoom*100),"%"]})]}):null},Ja="_panel_1jo5f_9",Qa="_header_1jo5f_27",ei="_title_1jo5f_45",ti="_closeButton_1jo5f_59",ni="_content_1jo5f_85",si="_endpointSection_1jo5f_99",oi="_endpointLabel_1jo5f_107",ai="_endpointSelect_1jo5f_123",ii="_optionsSection_1jo5f_157",ri="_metricButton_1jo5f_169",ci="_metricButtonActive_1jo5f_205",li="_analyzeButton_1jo5f_219",di="_resultsSection_1jo5f_267",ui="_resultsTitle_1jo5f_277",mi="_noResults_1jo5f_293",pi="_pathCard_1jo5f_309",hi="_pathCardSelected_1jo5f_333",gi="_pathCardHeader_1jo5f_343",_i="_pathCardTitle_1jo5f_361",fi="_pathBadge_1jo5f_373",yi="_badgePrimary_1jo5f_389",bi="_badgeAlternate_1jo5f_399",xi="_pathName_1jo5f_409",vi="_pathStatus_1jo5f_421",ji="_statusDot_1jo5f_435",Ni="_statusActive_1jo5f_447",wi="_statusDegraded_1jo5f_453",Ii="_statusInactive_1jo5f_459",ki="_statusError_1jo5f_465",Si="_pathStats_1jo5f_475",Ci="_statItem_1jo5f_489",Ti="_statValue_1jo5f_497",Li="_statLabel_1jo5f_509",$i="_pathVisualization_1jo5f_523",zi="_pathDiagram_1jo5f_535",Pi="_pathNode_1jo5f_551",Mi="_pathNodeStart_1jo5f_583",Ei="_pathNodeEnd_1jo5f_585",Oi="_pathLink_1jo5f_595",Ai="_pathLinkLine_1jo5f_607",Bi="_showOnMapButton_1jo5f_621",Di="_loading_1jo5f_657",Ri="_spinner_1jo5f_671",qi="_spin_1jo5f_671",V={panel:Ja,header:Qa,title:ei,closeButton:ti,content:ni,endpointSection:si,endpointLabel:oi,endpointSelect:ai,optionsSection:ii,metricButton:ri,metricButtonActive:ci,analyzeButton:li,resultsSection:di,resultsTitle:ui,noResults:mi,pathCard:pi,pathCardSelected:hi,pathCardHeader:gi,pathCardTitle:_i,pathBadge:fi,badgePrimary:yi,badgeAlternate:bi,pathName:xi,pathStatus:vi,statusDot:ji,statusActive:Ni,statusDegraded:wi,statusInactive:Ii,statusError:ki,pathStats:Si,statItem:Ci,statValue:Ti,statLabel:Li,pathVisualization:$i,pathDiagram:zi,pathNode:Pi,pathNodeStart:Mi,pathNodeEnd:Ei,pathLink:Oi,pathLinkLine:Ai,showOnMapButton:Bi,loading:Di,spinner:Ri,spin:qi},Fi=()=>e.jsx(N.NiceIcon,{name:"close",size:16}),Gi=()=>e.jsx(N.NiceIcon,{name:"arrow-right",size:16});function Vi(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 Wi(t){return t<1?"<1ms":t<1e3?`${Math.round(t)}ms`:`${(t/1e3).toFixed(1)}s`}function Hi(t){return t>=1e3?`${(t/1e3).toFixed(1)} Gbps`:`${Math.round(t)} Mbps`}const Ui=({document:t,connections:n,onHighlightPath:s,onClose:o})=>{const{t:i}=N.useNiceTranslation(),[a,c]=u.useState(""),[r,l]=u.useState(""),[b,m]=u.useState("latency"),[h,v]=u.useState([]),[x,p]=u.useState(null),[j,g]=u.useState(!1),I=u.useMemo(()=>{const d=[];for(const w of t.floors)for(const f of w.layers)if(f.type==="network"||f.type==="devices"||f.type==="infrastructure")for(const q of f.objects)d.push({id:q.id,name:q.name??q.id});return d},[t]),y=u.useCallback(d=>{var w;return((w=I.find(f=>f.id===d))==null?void 0:w.name)??d},[I]),L=u.useCallback(()=>{!a||!r||a===r||(g(!0),v([]),p(null),setTimeout(()=>{const d=ro(n,a,r,b),w=co(n,a,r,5),f=[];d&&f.push(d);for(const q of w)f.some(T=>T.connectionIds.length===q.connectionIds.length&&T.connectionIds.every((M,W)=>q.connectionIds[W]===M))||f.push({...q,isPrimary:!1});v(f),f.length>0&&(p(f[0].id),s==null||s(f[0])),g(!1)},300))},[a,r,b,n,s]),_=u.useCallback(d=>{p(d.id),s==null||s(d)},[s]),C=u.useCallback(d=>{const w=[d.startDeviceId];for(const f of d.connectionIds){const q=n.find(T=>T.id===f);if(q){const T=w[w.length-1],M=q.sourceId===T?q.targetId:q.sourceId;w.includes(M)||w.push(M)}}return w},[n]);return e.jsxs("div",{className:V.panel,children:[e.jsxs("div",{className:V.header,children:[e.jsx("h3",{className:V.title,children:i("buildings.spatial.pathAnalysis","Network path analysis")}),o&&e.jsx("button",{className:V.closeButton,onClick:o,children:e.jsx(Fi,{})})]}),e.jsxs("div",{className:V.content,children:[e.jsxs("div",{className:V.endpointSection,children:[e.jsx("label",{className:V.endpointLabel,children:i("buildings.spatial.sourceDevice","Source device")}),e.jsxs("select",{className:V.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:V.endpointSection,children:[e.jsx("label",{className:V.endpointLabel,children:i("buildings.spatial.targetDevice","Target device")}),e.jsxs("select",{className:V.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:V.optionsSection,children:[e.jsx("button",{className:`${V.metricButton} ${b==="latency"?V.metricButtonActive:""}`,onClick:()=>m("latency"),children:i("buildings.latency","Latency")}),e.jsx("button",{className:`${V.metricButton} ${b==="hops"?V.metricButtonActive:""}`,onClick:()=>m("hops"),children:i("buildings.hops","Hops")}),e.jsx("button",{className:`${V.metricButton} ${b==="bandwidth"?V.metricButtonActive:""}`,onClick:()=>m("bandwidth"),children:i("buildings.spatial.bandwidth","Bandwidth")})]}),e.jsx("button",{className:V.analyzeButton,onClick:L,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:V.loading,children:e.jsx("div",{className:V.spinner})}):h.length>0?e.jsxs("div",{className:V.resultsSection,children:[e.jsxs("div",{className:V.resultsTitle,children:[i("buildings.spatial.pathsFound","Paths found")," (",h.length,")"]}),h.map((d,w)=>{const f=C(d),q=x===d.id;return e.jsxs("div",{className:`${V.pathCard} ${q?V.pathCardSelected:""}`,onClick:()=>_(d),children:[e.jsxs("div",{className:V.pathCardHeader,children:[e.jsxs("div",{className:V.pathCardTitle,children:[e.jsx("span",{className:`${V.pathBadge} ${d.isPrimary?V.badgePrimary:V.badgeAlternate}`,children:d.isPrimary?i("buildings.optimal","Optimal"):i("buildings.alt","Alt {index}").replace("{index}",String(w))}),e.jsxs("span",{className:V.pathName,children:[d.connectionIds.length," ",i("buildings.spatial.connections","connections")]})]}),e.jsxs("div",{className:V.pathStatus,children:[e.jsx("span",{className:`${V.statusDot} ${V[`status${d.status.charAt(0).toUpperCase()+d.status.slice(1)}`]??""}`}),e.jsx("span",{children:Vi(d.status,i)})]})]}),e.jsxs("div",{className:V.pathStats,children:[e.jsxs("div",{className:V.statItem,children:[e.jsx("div",{className:V.statValue,children:Wi(d.totalLatency)}),e.jsx("div",{className:V.statLabel,children:i("buildings.latency","Latency")})]}),e.jsxs("div",{className:V.statItem,children:[e.jsx("div",{className:V.statValue,children:d.connectionIds.length}),e.jsx("div",{className:V.statLabel,children:i("buildings.hops","Hops")})]}),e.jsxs("div",{className:V.statItem,children:[e.jsx("div",{className:V.statValue,children:d.bottleneckBandwidth>0?Hi(d.bottleneckBandwidth):"N/A"}),e.jsx("div",{className:V.statLabel,children:i("buildings.spatial.bandwidth","Bandwidth")})]})]}),q&&e.jsxs("div",{className:V.pathVisualization,children:[e.jsx("div",{className:V.pathDiagram,children:f.map((T,M)=>e.jsxs(u.Fragment,{children:[e.jsx("div",{className:`${V.pathNode} ${M===0?V.pathNodeStart:M===f.length-1?V.pathNodeEnd:""}`,children:y(T).substring(0,8)}),M<f.length-1&&e.jsxs("div",{className:V.pathLink,children:[e.jsx("div",{className:V.pathLinkLine}),e.jsx(Gi,{})]})]},T))}),e.jsx("button",{className:V.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:V.noResults,children:i("buildings.spatial.noResultsHint","Pick two devices and run the analysis")}):e.jsx("div",{className:V.noResults,children:i("buildings.spatial.pickEndpoints","Pick a source and a target device")})]})]})},Yi="_root_6pirz_9",Zi="_header_6pirz_27",Xi="_title_6pirz_37",Ki="_search_6pirz_51",Ji="_categories_6pirz_79",Qi="_category_6pirz_91",er="_categoryHeader_6pirz_107",tr="_categoryIcon_6pirz_143",nr="_categoryLabel_6pirz_151",sr="_categoryCount_6pirz_161",or="_expandIcon_6pirz_171",ar="_items_6pirz_181",ir="_item_6pirz_181",rr="_itemIcon_6pirz_241",cr="_itemName_6pirz_249",lr="_emptyState_6pirz_269",Ne={root:Yi,header:Zi,title:Xi,search:Ki,categories:Ji,category:Qi,categoryHeader:er,categoryIcon:tr,categoryLabel:nr,categoryCount:sr,expandIcon:or,items:ar,item:ir,itemIcon:rr,itemName:cr,emptyState:lr},dr=t=>t&&/^[a-z][a-z0-9-]*$/.test(t)?t:"box",ur={"floor-plan":["smart-home","building"],"network-topology":["network"],infrastructure:["infrastructure","network"],cad:["building"],interior:["furniture","smart-home"],"game-scene":["game"]},mr={"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"}},Cn=({mode:t,onObjectSelect:n,customObjects:s=[],className:o})=>{const{t:i}=N.useNiceTranslation(),[a,c]=u.useState(""),[r,l]=u.useState(new Set(["smart-home","furniture","network"])),b=u.useMemo(()=>ur[t]||[],[t]),m=u.useMemo(()=>{const x={},p=Ws.reduce((j,g)=>{var I;return(j[I=g.category]??(j[I]=[])).push(g),j},{});return Object.entries(p).forEach(([j,g])=>{if(!b.includes(j))return;const I=g.filter(y=>!a||y.name.toLowerCase().includes(a.toLowerCase()));I.length>0&&(x[j]=I.map(y=>({id:y.id,name:y.name,category:j,icon:y.icon})))}),s.forEach(j=>{b.includes(j.category)&&(!a||j.name.toLowerCase().includes(a.toLowerCase()))&&(x[j.category]||(x[j.category]=[]),x[j.category].push(j))}),x},[b,a,s]),h=x=>{l(p=>{const j=new Set(p);return j.has(x)?j.delete(x):j.add(x),j})},v=(x,p)=>{x.dataTransfer.setData("application/json",JSON.stringify(p)),x.dataTransfer.effectAllowed="copy"};return e.jsxs("div",{className:`${Ne.root} ${o??""}`,children:[e.jsxs("div",{className:Ne.header,children:[e.jsx("h3",{className:Ne.title,children:i("objectLibrary.objects","Objects")}),e.jsx("input",{type:"text",className:Ne.search,placeholder:i("objectLibrary.search","Search..."),value:a,onChange:x=>c(x.target.value)})]}),e.jsxs("div",{className:Ne.categories,children:[Object.entries(m).map(([x,p])=>{const j=mr[x]||{icon:"box",label:x},g=r.has(x);return e.jsxs("div",{className:Ne.category,children:[e.jsxs("button",{className:Ne.categoryHeader,onClick:()=>h(x),children:[e.jsx("span",{className:Ne.categoryIcon,children:e.jsx(N.NiceIcon,{name:j.icon,size:16})}),e.jsx("span",{className:Ne.categoryLabel,children:j.label}),e.jsxs("span",{className:Ne.categoryCount,children:["(",p.length,")"]}),e.jsx("span",{className:Ne.expandIcon,children:e.jsx(N.NiceIcon,{name:g?"chevron-down":"chevron-right",size:14})})]}),g&&e.jsx("div",{className:Ne.items,children:p.map(I=>e.jsxs("div",{className:Ne.item,draggable:!0,onDragStart:y=>v(y,I),onClick:()=>n(I),title:I.name,children:[e.jsx("span",{className:Ne.itemIcon,children:e.jsx(N.NiceIcon,{name:dr(I.icon),size:16})}),e.jsx("span",{className:Ne.itemName,children:I.name})]},I.id))})]},x)}),Object.keys(m).length===0&&e.jsx("div",{className:Ne.emptyState,children:a?i("objectLibrary.noObjectsMatching",'No objects matching "{searchQuery}"').replace("{searchQuery}",String(a)):i("objectLibrary.noObjectsAvailableForThis","No objects available for this mode")})]})]})},pr="_root_o3eqo_9",hr="_header_o3eqo_23",gr="_title_o3eqo_39",_r="_multiSelect_o3eqo_53",fr="_content_o3eqo_63",yr="_section_o3eqo_73",br="_sectionHeader_o3eqo_89",xr="_sectionContent_o3eqo_127",vr="_fieldRow_o3eqo_135",jr="_fieldLabel_o3eqo_157",Nr="_textInput_o3eqo_169",wr="_numberInput_o3eqo_171",Ir="_select_o3eqo_173",kr="_checkbox_o3eqo_215",Sr="_colorInput_o3eqo_227",Cr="_readOnly_o3eqo_245",Tr="_emptyState_o3eqo_263",ae={root:pr,header:hr,title:gr,multiSelect:_r,content:fr,section:yr,sectionHeader:br,sectionContent:xr,fieldRow:vr,fieldLabel:jr,textInput:Nr,numberInput:wr,select:Ir,checkbox:kr,colorInput:Sr,readOnly:Cr,emptyState:Tr},qt=[{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"}],Lr=[{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}],$r=[{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"}]}],Tn=({selection:t,document:n,onPropertyChange:s,className:o})=>{const{t:i}=N.useNiceTranslation(),[a,c]=u.useState(new Set(["general","position","appearance"])),r=t.objectIds.map(p=>{for(const j of n.floors)for(const g of j.layers){const I=g.objects.find(y=>y.id===p);if(I)return I}return null}).filter(Boolean),l=p=>{c(j=>{const g=new Set(j);return g.has(p)?g.delete(p):g.add(p),g})},b=u.useCallback((p,j)=>{const g=j.split(".");let I=p;for(const y of g)if(I&&typeof I=="object"&&y in I)I=I[y];else return;return I},[]),m=u.useCallback((p,j)=>{var I;const g=b(j,p.key);switch(p.type){case"text":return e.jsx("input",{type:"text",value:String(g??""),onChange:y=>s(j.id,p.key,y.target.value),className:ae.textInput});case"number":return e.jsx("input",{type:"number",value:Number(g??0),min:p.min,max:p.max,step:p.step,onChange:y=>s(j.id,p.key,parseFloat(y.target.value)),className:ae.numberInput});case"boolean":return e.jsx("input",{type:"checkbox",checked:!!g,onChange:y=>s(j.id,p.key,y.target.checked),className:ae.checkbox});case"color":return e.jsx("input",{type:"color",value:String(g??"var(--nice-bg, #fff)"),onChange:y=>s(j.id,p.key,y.target.value),className:ae.colorInput});case"select":return e.jsx("select",{value:String(g??""),onChange:y=>s(j.id,p.key,y.target.value),className:ae.select,children:(I=p.options)==null?void 0:I.map(y=>e.jsx("option",{value:y.value,children:y.label},y.value))});default:return e.jsx("span",{children:String(g??"-")})}},[b,s]);if(r.length===0)return e.jsxs("div",{className:`${ae.root} ${o??""}`,children:[e.jsx("div",{className:ae.header,children:e.jsx("h3",{className:ae.title,children:i("propertiesPanel.properties","Properties")})}),e.jsx("div",{className:ae.emptyState,children:i("propertiesPanel.noObjectSelected","No object selected")})]});const h=r[0],v=r.length>1,x=h.category==="zone"?Lr:["smart-home","network","infrastructure"].includes(h.category??"")?$r:[];return e.jsxs("div",{className:`${ae.root} ${o??""}`,children:[e.jsxs("div",{className:ae.header,children:[e.jsx("h3",{className:ae.title,children:i("propertiesPanel.properties","Properties")}),v&&e.jsx("span",{className:ae.multiSelect,children:i("propertiesPanel.selected","{selectedObjects} selected").replace("{selectedObjects}",String(r.length))})]}),e.jsxs("div",{className:ae.content,children:[e.jsxs("div",{className:ae.section,children:[e.jsxs("button",{className:ae.sectionHeader,onClick:()=>l("general"),children:[e.jsx("span",{children:e.jsx(N.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:ae.sectionContent,children:[qt.slice(0,1).map(p=>e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:p.label}),m(p,h)]},p.key)),e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:"ID"}),e.jsx("span",{className:ae.readOnly,children:h.id})]}),e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:i("propertiesPanel.category","Category")}),e.jsx("span",{className:ae.readOnly,children:h.category})]})]})]}),e.jsxs("div",{className:ae.section,children:[e.jsxs("button",{className:ae.sectionHeader,onClick:()=>l("position"),children:[e.jsx("span",{children:e.jsx(N.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:ae.sectionContent,children:qt.slice(1,4).map(p=>e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:p.label}),m(p,h)]},p.key))})]}),x.length>0&&e.jsxs("div",{className:ae.section,children:[e.jsxs("button",{className:ae.sectionHeader,onClick:()=>l("appearance"),children:[e.jsx("span",{children:e.jsx(N.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:ae.sectionContent,children:x.map(p=>e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:p.label}),m(p,h)]},p.key))})]}),e.jsxs("div",{className:ae.section,children:[e.jsxs("button",{className:ae.sectionHeader,onClick:()=>l("visibility"),children:[e.jsx("span",{children:e.jsx(N.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:ae.sectionContent,children:qt.slice(4).map(p=>e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:p.label}),m(p,h)]},p.key))})]})]})]})},zr="_panel_18mro_9",Pr="_header_18mro_33",Mr="_headerTitle_18mro_51",Er="_title_18mro_65",Or="_closeButton_18mro_79",Ar="_summarySection_18mro_111",Br="_summaryStats_18mro_129",Dr="_statBadge_18mro_141",Rr="_statValue_18mro_155",qr="_statLabel_18mro_167",Fr="_visibilityControls_18mro_183",Gr="_visibilityLabel_18mro_201",Vr="_visibilityButtons_18mro_211",Wr="_visibilityBtn_18mro_221",Hr="_active_18mro_251",Ur="_content_18mro_265",Yr="_emptyState_18mro_279",Zr="_emptyHint_18mro_325",Xr="_vlanList_18mro_337",Kr="_vlanCard_18mro_351",Jr="_highlighted_18mro_377",Qr="_hidden_18mro_387",ec="_vlanHeader_18mro_395",tc="_colorIndicator_18mro_421",nc="_vlanInfo_18mro_435",sc="_vlanName_18mro_445",oc="_vlanId_18mro_459",ac="_vlanNameText_18mro_471",ic="_vlanSubnet_18mro_487",rc="_vlanStats_18mro_503",cc="_chipStat_18mro_515",lc="_vlanActions_18mro_545",dc="_iconBtn_18mro_557",uc="_inactive_18mro_595",mc="_expanded_18mro_611",pc="_vlanDetails_18mro_623",hc="_detailRow_18mro_635",gc="_detailLabel_18mro_657",_c="_detailValue_18mro_675",fc="_badge_18mro_687",yc="_badgeSuccess_18mro_701",bc="_badgeNeutral_18mro_711",xc="_deviceList_18mro_723",vc="_deviceItems_18mro_731",jc="_deviceItem_18mro_731",Nc="_deviceDot_18mro_765",wc="_deviceMore_18mro_779",Ic="_highlightButton_18mro_795",kc="_footer_18mro_835",Sc="_legendTitle_18mro_847",Cc="_legend_18mro_847",Tc="_legendItem_18mro_875",Lc="_legendColor_18mro_887",$c="_legendLabel_18mro_901",B={panel:zr,header:Pr,headerTitle:Mr,title:Er,closeButton:Or,summarySection:Ar,summaryStats:Br,statBadge:Dr,statValue:Rr,statLabel:qr,visibilityControls:Fr,visibilityLabel:Gr,visibilityButtons:Vr,visibilityBtn:Wr,active:Hr,content:Ur,emptyState:Yr,emptyHint:Zr,vlanList:Xr,vlanCard:Kr,highlighted:Jr,hidden:Qr,vlanHeader:ec,colorIndicator:tc,vlanInfo:nc,vlanName:sc,vlanId:oc,vlanNameText:ac,vlanSubnet:ic,vlanStats:rc,chipStat:cc,vlanActions:lc,iconBtn:dc,inactive:uc,expanded:mc,vlanDetails:pc,detailRow:hc,detailLabel:gc,detailValue:_c,badge:fc,badgeSuccess:yc,badgeNeutral:bc,deviceList:xc,deviceItems:vc,deviceItem:jc,deviceDot:Nc,deviceMore:wc,highlightButton:Ic,footer:kc,legendTitle:Sc,legend:Cc,legendItem:Tc,legendColor:Lc,legendLabel:$c},zc=()=>e.jsx(N.NiceIcon,{name:"close",size:16}),Pc=()=>e.jsx(N.NiceIcon,{name:"eye",size:16}),Mc=()=>e.jsx(N.NiceIcon,{name:"eye-off",size:16}),cn=()=>e.jsx(N.NiceIcon,{name:"git-branch",size:16}),Ec=()=>e.jsx(N.NiceIcon,{name:"info",size:14});function Oc(t){var n;return((n=t.deviceIds)==null?void 0:n.length)??0}function Ac(t,n){return n.filter(s=>s.vlanId===t.id).length}function Bc(t){return t||"—"}const Dc=({document:t,connections:n,vlans:s,visibleVlanIds:o,onVlanVisibilityChange:i,onHighlightVlan:a,onClose:c})=>{const{t:r}=N.useNiceTranslation(),[l,b]=u.useState(null),[m,h]=u.useState(null),v=u.useMemo(()=>[...s].sort((_,C)=>_.id-C.id),[s]),x=u.useMemo(()=>{const _=new Set,C=new Set;for(const d of s)for(const w of d.deviceIds??[])_.add(w);for(const d of n)d.vlanId!==void 0&&C.add(d.id);return{vlanCount:s.length,deviceCount:_.size,connectionCount:C.size}},[s,n]),p=u.useCallback(_=>{const C=o.has(_);i==null||i(_,!C)},[o,i]),j=u.useCallback(_=>{for(const C of s)i==null||i(C.id,_)},[s,i]),g=u.useCallback(_=>{b((_==null?void 0:_.id)??null),a==null||a(_)},[a]),I=u.useCallback(_=>{h(C=>C===_?null:_)},[]),y=u.useCallback(_=>{const C=[];for(const d of _.deviceIds??[])for(const w of t.floors)for(const f of w.layers){const q=f.objects.find(T=>T.id===d);q&&C.push({id:d,name:q.name??d})}return C},[t]),L=u.useMemo(()=>{const _=s.filter(C=>o.has(C.id)).length;return{visible:_,total:s.length,allVisible:_===s.length,noneVisible:_===0}},[s,o]);return e.jsxs("div",{className:B.panel,children:[e.jsxs("div",{className:B.header,children:[e.jsxs("div",{className:B.headerTitle,children:[e.jsx(cn,{}),e.jsx("h3",{className:B.title,children:r("buildings.spatial.vlan.title","VLAN overlay")})]}),c&&e.jsx("button",{className:B.closeButton,onClick:c,title:r("buildings.spatial.close","Close"),children:e.jsx(zc,{})})]}),e.jsx("div",{className:B.summarySection,children:e.jsxs("div",{className:B.summaryStats,children:[e.jsxs("div",{className:B.statBadge,children:[e.jsx("span",{className:B.statValue,children:x.vlanCount}),e.jsx("span",{className:B.statLabel,children:r("buildings.vlan2","VLAN")})]}),e.jsxs("div",{className:B.statBadge,children:[e.jsx("span",{className:B.statValue,children:x.deviceCount}),e.jsx("span",{className:B.statLabel,children:r("buildings.spatial.devices","Devices")})]}),e.jsxs("div",{className:B.statBadge,children:[e.jsx("span",{className:B.statValue,children:x.connectionCount}),e.jsx("span",{className:B.statLabel,children:r("buildings.spatial.connections","Connections")})]})]})}),e.jsxs("div",{className:B.visibilityControls,children:[e.jsxs("span",{className:B.visibilityLabel,children:[r("buildings.spatial.vlan.visibility","Visibility"),": ",L.visible,"/",L.total]}),e.jsxs("div",{className:B.visibilityButtons,children:[e.jsx("button",{className:`${B.visibilityBtn} ${L.allVisible?B.active:""}`,onClick:()=>j(!0),title:r("buildings.spatial.vlan.showAll","Show all"),children:r("buildings.spatial.vlan.all","All")}),e.jsx("button",{className:`${B.visibilityBtn} ${L.noneVisible?B.active:""}`,onClick:()=>j(!1),title:r("buildings.spatial.vlan.hideAll","Hide all"),children:r("buildings.spatial.vlan.none","None")})]})]}),e.jsx("div",{className:B.content,children:v.length===0?e.jsxs("div",{className:B.emptyState,children:[e.jsx(cn,{}),e.jsx("p",{children:r("buildings.spatial.vlan.empty","No VLANs defined")}),e.jsx("span",{className:B.emptyHint,children:r("buildings.spatial.vlan.emptyHint","Add a VLAN in network-topology or infrastructure mode")})]}):e.jsx("div",{className:B.vlanList,children:v.map(_=>{const C=o.has(_.id),d=l===_.id,w=m===_.id,f=Oc(_),q=Ac(_,n),T=w?y(_):[];return e.jsxs("div",{className:`${B.vlanCard} ${d?B.highlighted:""} ${C?"":B.hidden}`,onMouseEnter:()=>g(_),onMouseLeave:()=>g(null),children:[e.jsxs("div",{className:B.vlanHeader,children:[e.jsx("div",{className:B.colorIndicator,style:{backgroundColor:_.color}}),e.jsxs("div",{className:B.vlanInfo,children:[e.jsxs("div",{className:B.vlanName,children:[e.jsx("span",{className:B.vlanId,children:r("buildings.vlan","VLAN {id}").replace("{id}",String(_.id))}),_.name&&e.jsx("span",{className:B.vlanNameText,children:_.name})]}),_.subnet&&e.jsx("div",{className:B.vlanSubnet,children:Bc(_.subnet)})]}),e.jsxs("div",{className:B.vlanStats,children:[e.jsx("span",{className:B.chipStat,title:r("buildings.spatial.devices","Devices"),children:f}),e.jsx("span",{className:B.chipStat,title:r("buildings.spatial.connections","Connections"),children:q})]}),e.jsxs("div",{className:B.vlanActions,children:[e.jsx("button",{className:`${B.iconBtn} ${C?"":B.inactive}`,onClick:M=>{M.stopPropagation(),p(_.id)},title:C?r("buildings.spatial.vlan.hide","Hide VLAN"):r("buildings.spatial.vlan.show","Show VLAN"),children:C?e.jsx(Pc,{}):e.jsx(Mc,{})}),e.jsx("button",{className:`${B.iconBtn} ${w?B.expanded:""}`,onClick:M=>{M.stopPropagation(),I(_.id)},title:r("buildings.spatial.details","Details"),children:e.jsx(Ec,{})})]})]}),w&&e.jsxs("div",{className:B.vlanDetails,children:[_.description&&e.jsxs("div",{className:B.detailRow,children:[e.jsxs("span",{className:B.detailLabel,children:[r("buildings.spatial.vlan.description","Description"),":"]}),e.jsx("span",{className:B.detailValue,children:_.description})]}),_.subnet&&e.jsxs("div",{className:B.detailRow,children:[e.jsxs("span",{className:B.detailLabel,children:[r("buildings.spatial.vlan.subnet","Subnet"),":"]}),e.jsx("span",{className:B.detailValue,children:_.subnet})]}),_.gateway&&e.jsxs("div",{className:B.detailRow,children:[e.jsxs("span",{className:B.detailLabel,children:[r("buildings.spatial.vlan.gateway","Gateway"),":"]}),e.jsx("span",{className:B.detailValue,children:_.gateway})]}),e.jsxs("div",{className:B.detailRow,children:[e.jsx("span",{className:B.detailLabel,children:r("buildings.dhcp","DHCP:")}),e.jsx("span",{className:`${B.detailValue} ${B.badge} ${_.dhcpEnabled?B.badgeSuccess:B.badgeNeutral}`,children:_.dhcpEnabled?r("buildings.spatial.enabled","Enabled"):r("buildings.spatial.disabled","Disabled")})]}),T.length>0&&e.jsxs("div",{className:B.deviceList,children:[e.jsxs("span",{className:B.detailLabel,children:[r("buildings.spatial.devices","Devices")," (",T.length,"):"]}),e.jsxs("ul",{className:B.deviceItems,children:[T.slice(0,10).map(M=>e.jsxs("li",{className:B.deviceItem,children:[e.jsx("span",{className:B.deviceDot,style:{backgroundColor:_.color}}),M.name]},M.id)),T.length>10&&e.jsxs("li",{className:B.deviceMore,children:["… ",r("buildings.spatial.andMore","and")," ",T.length-10," ",r("buildings.spatial.more","more")]})]})]}),e.jsx("button",{className:B.highlightButton,onClick:()=>a==null?void 0:a(_),children:r("buildings.spatial.selectOnMap","Select on the map")})]})]},_.id)})})}),v.length>0&&e.jsxs("div",{className:B.footer,children:[e.jsx("div",{className:B.legendTitle,children:r("buildings.spatial.colourLegend","Colour legend")}),e.jsx("div",{className:B.legend,children:v.map(_=>e.jsxs("div",{className:B.legendItem,children:[e.jsx("span",{className:B.legendColor,style:{backgroundColor:_.color}}),e.jsxs("span",{className:B.legendLabel,children:[_.id,_.name?`: ${_.name}`:""]})]},_.id))})]})]})},Rc="_root_sniq9_9",qc="_shell_sniq9_35",Fc="_dark_sniq9_43",Gc="_topBar_sniq9_67",Vc="_modeSwitcher_sniq9_85",Wc="_modeBtn_sniq9_95",Hc="_modeBtnActive_sniq9_131",Uc="_modeIcon_sniq9_143",Yc="_modeLabel_sniq9_151",Zc="_floorTabs_sniq9_159",Xc="_floorTab_sniq9_159",Kc="_floorTabActive_sniq9_203",Jc="_viewportControls_sniq9_215",Qc="_active_sniq9_257",el="_disabled_sniq9_267",tl="_separator_sniq9_281",nl="_zoomLevel_sniq9_295",sl="_exportDropdown_sniq9_313",ol="_exportMenu_sniq9_361",al="_editorContainer_sniq9_435",il="_toolbar_sniq9_453",rl="_toolGroup_sniq9_473",cl="_toolBtn_sniq9_501",ll="_toolBtnActive_sniq9_541",dl="_canvasWrapper_sniq9_565",ul="_canvas_sniq9_565",ml="_cursor_select_sniq9_593",pl="_cursor_multi_select_sniq9_599",hl="_cursor_pan_sniq9_605",gl="_cursor_zoom_sniq9_617",_l="_cursor_draw_wall_sniq9_623",fl="_cursor_draw_zone_sniq9_625",yl="_cursor_draw_polyline_sniq9_627",bl="_cursor_draw_rectangle_sniq9_629",xl="_cursor_draw_circle_sniq9_631",vl="_cursor_draw_arc_sniq9_633",jl="_cursor_place_device_sniq9_639",Nl="_cursor_place_furniture_sniq9_641",wl="_cursor_place_network_sniq9_643",Il="_cursor_place_infra_sniq9_645",kl="_cursor_place_door_sniq9_647",Sl="_cursor_place_window_sniq9_649",Cl="_cursor_place_stairs_sniq9_651",Tl="_cursor_connect_sniq9_657",Ll="_cursor_route_cable_sniq9_659",$l="_cursor_annotate_sniq9_665",zl="_cursor_dimension_sniq9_667",Pl="_cursor_label_sniq9_669",Ml="_cursor_measure_distance_sniq9_675",El="_cursor_measure_angle_sniq9_677",Ol="_cursor_measure_area_sniq9_679",Al="_cursor_move_sniq9_685",Bl="_cursor_rotate_sniq9_691",Dl="_cursor_scale_sniq9_697",Rl="_cursor_erase_sniq9_703",ql="_cursor_copy_sniq9_709",Fl="_cursor_paste_sniq9_711",Gl="_grid_sniq9_721",Vl="_gridLine_sniq9_727",Wl="_zonesLayer_sniq9_739",Hl="_zone_sniq9_739",Ul="_zoneLabel_sniq9_755",Yl="_connectionsLayer_sniq9_769",Zl="_connection_sniq9_769",Xl="_connectionPreview_sniq9_785",Kl="_guides_sniq9_795",Jl="_guideLine_sniq9_801",Ql="_drawingPreview_sniq9_815",ed="_rightSidebar_sniq9_827",td="_statusBar_sniq9_849",nd="_modeIndicator_sniq9_871",sd="_toolIndicator_sniq9_873",od="_selectionInfo_sniq9_885",ad="_drawingInfo_sniq9_887",id="_connectingInfo_sniq9_901",rd="_gridInfo_sniq9_915",cd="_emptyState_sniq9_927",ld="_emptyIcon_sniq9_949",dd="_primaryBtn_sniq9_979",ud="_modeActions_sniq9_1013",md="_actionBtn_sniq9_1031",F={root:Rc,shell:qc,dark:Fc,topBar:Gc,modeSwitcher:Vc,modeBtn:Wc,modeBtnActive:Hc,modeIcon:Uc,modeLabel:Yc,floorTabs:Zc,floorTab:Xc,floorTabActive:Kc,viewportControls:Jc,active:Qc,disabled:el,separator:tl,zoomLevel:nl,exportDropdown:sl,exportMenu:ol,editorContainer:al,toolbar:il,toolGroup:rl,toolBtn:cl,toolBtnActive:ll,canvasWrapper:dl,canvas:ul,cursor_select:ml,cursor_multi_select:pl,cursor_pan:hl,cursor_zoom:gl,cursor_draw_wall:_l,cursor_draw_zone:fl,cursor_draw_polyline:yl,cursor_draw_rectangle:bl,cursor_draw_circle:xl,cursor_draw_arc:vl,cursor_place_device:jl,cursor_place_furniture:Nl,cursor_place_network:wl,cursor_place_infra:Il,cursor_place_door:kl,cursor_place_window:Sl,cursor_place_stairs:Cl,cursor_connect:Tl,cursor_route_cable:Ll,cursor_annotate:$l,cursor_dimension:zl,cursor_label:Pl,cursor_measure_distance:Ml,cursor_measure_angle:El,cursor_measure_area:Ol,cursor_move:Al,cursor_rotate:Bl,cursor_scale:Dl,cursor_erase:Rl,cursor_copy:ql,cursor_paste:Fl,grid:Gl,gridLine:Vl,zonesLayer:Wl,zone:Hl,zoneLabel:Ul,connectionsLayer:Yl,connection:Zl,connectionPreview:Xl,guides:Kl,guideLine:Jl,drawingPreview:Ql,rightSidebar:ed,statusBar:td,modeIndicator:nd,toolIndicator:sd,selectionInfo:od,drawingInfo:ad,connectingInfo:id,gridInfo:rd,emptyState:cd,emptyIcon:ld,primaryBtn:dd,modeActions:ud,actionBtn:md},Qe={"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}},xt={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"}};function pd(t){var i,a;const n=t.defaultMode??"floor-plan",s=Qe[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}];return{mode:n,tool:s.tools[0]??"select",document:t.document??t.initialDocument??null,activeFloorId:((a=(i=t.document)==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 Xe(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 Ke(t,n){return{history:{past:[...t.history.past.slice(-49),n],future:[]}}}function Fe(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 _t(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 ft(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()}}}function yt(t,n,s,o){return{...t,floors:t.floors.map(i=>i.id!==n?i:{...i,layers:i.layers.map(a=>a.name!==s?a:{...a,objects:[...a.objects,o]})}),metadata:{...t.metadata,modified:new Date().toISOString()}}}function hd(t,n){var s;switch(n.type){case"SET_MODE":{const o=Qe[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=yt(t.document,t.activeFloorId,o,n.object),a=Xe("create",[n.object.id],null,n.object);return{...t,document:i,...Ke(t,a)}}case"UPDATE_OBJECT":{if(!t.document)return t;const o=Fe(t.document,n.objectId);if(!o)return t;const i=_t(t.document,n.objectId,n.updates),a=Xe("update",[n.objectId],o,{...o,...n.updates});return{...t,document:i,...Ke(t,a)}}case"DELETE_OBJECTS":{if(!t.document||n.objectIds.length===0)return t;const o=n.objectIds.map(c=>Fe(t.document,c)).filter(Boolean),i=ft(t.document,n.objectIds),a=Xe("delete",n.objectIds,o,null);return{...t,document:i,selection:{objectIds:[],bounds:null,locked:!1},...Ke(t,a)}}case"MOVE_OBJECTS":{if(!t.document||n.objectIds.length===0)return t;const o=n.objectIds.map(r=>Fe(t.document,r)).filter(Boolean);let i=t.document;for(const r of n.objectIds){const l=Fe(i,r);if(l&&"transform"in l&&l.transform&&"position"in l.transform){const b=l.transform.position;i=_t(i,r,{transform:{...l.transform,position:{x:b.x+n.delta.x,y:b.y+n.delta.y}}})}}const a=n.objectIds.map(r=>Fe(i,r)).filter(Boolean),c=Xe("move",n.objectIds,o,a);return{...t,document:i,...Ke(t,c)}}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=ft(i,o.objectIds);break}case"delete":{const a=o.before;for(const c of a){const r=c.layer||"devices";i=yt(i,t.activeFloorId??i.floors[0].id,r,c)}break}case"update":case"move":{const a=o.before;for(const c of a)i=_t(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=yt(i,t.activeFloorId??i.floors[0].id,c,a);break}case"delete":{i=ft(i,o.objectIds);break}case"update":case"move":{const a=o.after;for(const c of a)i=_t(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=>Fe(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=>Fe(t.document,c)).filter(Boolean),i=ft(t.document,t.selection.objectIds),a=Xe("delete",t.selection.objectIds,o,null);return{...t,document:i,clipboard:o,selection:{objectIds:[],bounds:null,locked:!1},...Ke(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)}`,b=r.transform,m={position:{x:b.position.x+n.position.x+20,y:b.position.y+n.position.y+20},rotation:b.rotation,scale:b.scale},h={...r,id:l,transform:m},v=h.layer||"devices";o=yt(o,t.activeFloorId,v,h),i.push(l),a.push(h)}const c=Xe("create",i,null,a);return{...t,document:o,selection:{objectIds:i,bounds:null,locked:!1},...Ke(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 gd=({mode:t,activeTool:n,onToolSelect:s,readOnly:o})=>{const a=Qe[t].tools.map(r=>xt[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(b=>b.group===r);return l.length===0?null:e.jsx("div",{className:F.toolGroup,children:l.map(({tool:b,icon:m,label:h,shortcut:v})=>e.jsx("button",{title:`${h}${v?` (${v})`:""}`,className:`${F.toolBtn} ${n===b?F.toolBtnActive:""}`,onClick:()=>s(b),disabled:o&&!["select","pan","zoom","measure-distance","measure-angle","measure-area"].includes(b),children:e.jsx(N.NiceIcon,{name:m,size:16})},b))},r)})})},_d=({currentMode:t,availableModes:n,onModeChange:s})=>e.jsx("div",{className:F.modeSwitcher,children:n.map(o=>{const i=Qe[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(N.NiceIcon,{name:i.icon,size:16})}),e.jsx("span",{className:F.modeLabel,children:i.label})]},o)})});function ln(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 fd(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??yd(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 yd(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 bd=[{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"}],xd=t=>{var Ut,Yt;const{defaultMode:n="floor-plan",availableModes:s=Object.keys(Qe),readOnly:o=!1,theme:i="light",locale:a="en",onDocumentChange:c,onSelectionChange:r,onModeChange:l,onExport:b,onImport:m,tutorial:h,className:v,style:x,cookies:p=!1,localStorage:j=!0,sessionStorage:g=!1,storageMode:I,storageKey:y,persistPreferences:L=!1}=t,{t:_}=N.useNiceTranslation(),C=N.useStorageAdapter(y??"nice-spatial-editor"),[d]=u.useState(()=>L?C.get("prefs")??{}:{}),[w,f]=u.useReducer(hd,t,pd),q=u.useRef(null),T=u.useRef(!1),M=u.useRef({x:0,y:0}),[W,te]=u.useState(!1),[ue,ee]=u.useState(!1),[ge,ne]=u.useState(null),[fe,ze]=u.useState(null),[Re,Le]=u.useState(!1),[Me,Ee]=u.useState(!1),[P,K]=u.useState(!1),[pe,Ie]=u.useState(new Set),[Be,je]=u.useState(null),Oe=u.useRef(null),Ce=u.useRef(null),ke=u.useRef(null),{mode:we,tool:me,document:ie,activeFloorId:qe,layers:Se,selection:ve,viewport:ce,drawing:he,connecting:se,guides:Ve,ui:Ae,history:et}=w,We=Qe[we],rt=et.past.length>0,tt=et.future.length>0;u.useEffect(()=>{var S,R,D;!L||!d||((d.zoom||d.pan)&&f({type:"SET_VIEWPORT",viewport:{zoom:d.zoom,pan:d.pan,showGrid:(S=d.gridConfig)==null?void 0:S.visible,gridSize:(R=d.gridConfig)==null?void 0:R.size,snapEnabled:(D=d.gridConfig)==null?void 0:D.snapEnabled}}),d.mode&&f({type:"SET_MODE",mode:d.mode}),d.tool&&f({type:"SET_TOOL",tool:d.tool}),d.layerVisibility&&Object.entries(d.layerVisibility).forEach(([G,J])=>{J!==void 0&&f({type:"SET_LAYER_VISIBILITY",layerType:G,visible:J})}))},[]),u.useEffect(()=>{if(!L)return;const S={zoom:ce.zoom,pan:ce.pan,gridConfig:{size:ce.gridSize,visible:ce.showGrid,snapEnabled:ce.snapEnabled},mode:we,tool:me,layerVisibility:Object.fromEntries(Se.map(R=>[R.type,R.visible])),uiPanels:Ae};C.set("prefs",S)},[L,ce,we,me,Se,Ae,C]);const ye=u.useMemo(()=>(ie==null?void 0:ie.floors.find(S=>S.id===qe))??(ie==null?void 0:ie.floors[0])??null,[ie,qe]),De=u.useCallback((S,R)=>{var G;const D=(G=q.current)==null?void 0:G.getBoundingClientRect();return D?{x:(S-D.left-ce.pan.x)/ce.zoom,y:(R-D.top-ce.pan.y)/ce.zoom}:{x:0,y:0}},[ce.pan,ce.zoom]),He=u.useCallback(S=>{if(!ce.snapEnabled)return S;const R={cellSize:ce.gridSize,origin:{x:0,y:0},visible:ce.showGrid};return Wt(S,R)},[ce.snapEnabled,ce.gridSize,ce.showGrid]),kt=u.useCallback(S=>{if(me==="pan"||S.button===1){T.current=!0,M.current={x:S.clientX,y:S.clientY};return}const R=He(De(S.clientX,S.clientY));if(me==="draw-zone"||me==="draw-wall"||me==="draw-polyline")he.active?f({type:"ADD_DRAWING_POINT",point:R}):f({type:"START_DRAWING",point:R});else if(me==="connect"){const D=ye==null?void 0:ye.layers.flatMap(G=>G.objects).find(G=>{if(!G.bounds)return!1;const J=G.bounds;return R.x>=J.x&&R.x<=J.x+J.width&&R.y>=J.y&&R.y<=J.y+J.height});if(D)if(se.active){f({type:"FINISH_CONNECTING",targetId:D.id});const G=`conn-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,J=D.bounds?{x:D.bounds.x+D.bounds.width/2,y:D.bounds.y+D.bounds.height/2}:R,Q={id:G,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(se.sourcePosition.x,J.x),y:Math.min(se.sourcePosition.y,J.y),width:Math.abs(J.x-se.sourcePosition.x),height:Math.abs(J.y-se.sourcePosition.y)},metadata:{sourceId:se.sourceId,targetId:D.id,sourcePosition:se.sourcePosition,targetPosition:J,medium:"ethernet-cat6",status:"active"}};f({type:"ADD_OBJECT",object:Q})}else{const G=D.bounds?{x:D.bounds.x+D.bounds.width/2,y:D.bounds.y+D.bounds.height/2}:R;f({type:"START_CONNECTING",sourceId:D.id,sourcePosition:G})}else se.active&&f({type:"CANCEL_CONNECTING"})}else me==="select"&&f({type:"CLEAR_SELECTION"})},[me,he.active,se.active,se.sourceId,se.sourcePosition,He,De,ye]),St=u.useCallback(S=>{if(T.current){const D=S.clientX-M.current.x,G=S.clientY-M.current.y;f({type:"PAN",delta:{x:D,y:G}}),M.current={x:S.clientX,y:S.clientY};return}const R=He(De(S.clientX,S.clientY));if(he.active&&(f({type:"UPDATE_DRAWING_PREVIEW",point:R}),ce.snapEnabled&&ye)){const D=ye.layers.flatMap(Q=>Q.objects.filter(le=>le.bounds).map(le=>({id:le.id,bounds:le.bounds}))),G={x:R.x,y:R.y,width:1,height:1},J=jn(G,D,10);f({type:"SET_GUIDES",guides:J})}se.active&&f({type:"UPDATE_CONNECTING_PREVIEW",position:R})},[he.active,se.active,He,De,ce.snapEnabled,ye]),Ct=u.useCallback(()=>{T.current=!1},[]),Tt=u.useCallback(S=>{he.active&&he.points.length>=2&&f({type:"FINISH_DRAWING"})},[he.active,he.points.length]),Lt=u.useCallback(S=>{S.preventDefault();const R=S.deltaY>0?-1:1;f({type:"ZOOM",delta:R,center:De(S.clientX,S.clientY)})},[De]),$t=u.useCallback(S=>{S.key==="Escape"&&(he.active?f({type:"CANCEL_DRAWING"}):se.active?f({type:"CANCEL_CONNECTING"}):f({type:"CLEAR_SELECTION"})),S.key==="Delete"&&ve.objectIds.length>0&&f({type:"DELETE_OBJECTS",objectIds:ve.objectIds}),(S.ctrlKey||S.metaKey)&&(S.key==="z"&&f({type:"UNDO"}),S.key==="y"&&f({type:"REDO"}),S.key==="c"&&f({type:"COPY"}),S.key==="v"&&f({type:"PASTE",position:{x:0,y:0}}),S.key==="x"&&f({type:"CUT"}))},[he.active,se.active,ve.objectIds]),zt=u.useCallback(S=>{f({type:"SET_MODE",mode:S}),l==null||l(S)},[l]),Pt=u.useCallback(S=>{f({type:"SET_TOOL",tool:S})},[]),Ue=u.useCallback(async S=>{var R;if(ie){te(!1);try{const D={includeGrid:!1,includeDimensions:!0};if(S==="nsp"){const G=Ks(ie,D);ht(G),b==null||b(S,G.data)}else if(S==="svg"){const G=Qs(ie,D);ht(G),b==null||b(S,G.data)}else if(S==="dxf"){const G=no(ie,D);ht(G),b==null||b(S,G.data)}else if(S==="png"&&q.current){const G=await io(q.current,((R=ie.metadata)==null?void 0:R.name)||"export");ht(G),b==null||b(S,G.data)}}catch(D){console.error(`Export to ${S} failed:`,D)}}},[ie,b]),Mt=u.useCallback(async S=>{var D;const R=(D=S.target.files)==null?void 0:D[0];if(R){ee(!1);try{const J=await bo(R,{convertClosedPolylinesToZones:!0,minZoneArea:1});J.success&&J.document?ze(J):ne(J),ke.current&&(ke.current.value="")}catch(G){console.error("Import failed:",G),ne({success:!1,warnings:[],errors:[{code:"IMPORT_ERROR",message:G instanceof Error?G.message:_("buildings.unknownImportError","Unknown import error"),fatal:!0}],stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:0}})}}},[_]),Et=u.useCallback(()=>{fe!=null&&fe.success&&fe.document?Le(!0):ze(null)},[fe]),ct=u.useCallback(()=>{ze(null),Le(!1)},[]),k=u.useCallback((S,R)=>{if(!(fe!=null&&fe.document)){Le(!1);return}const D=fe.document,G={...D,floors:D.floors.map(J=>({...J,layers:J.layers.filter(Q=>S.get(Q.id)!=="skip").map(Q=>{const le=S.get(Q.id);if(le===Q.id||!le)return Q;const $e=ie==null?void 0:ie.floors.flatMap(Ye=>Ye.layers).find(Ye=>Ye.id===le);return $e?{...Q,id:$e.id,name:$e.name,type:$e.type}:Q})}))};f({type:"SET_DOCUMENT",document:G}),m==null||m(G),ne(fe),Le(!1),ze(null)},[fe,ie,m]),$=u.useCallback(()=>{Le(!1)},[]),E=u.useCallback(S=>{if(ke.current){let R=".dxf,.svg,.geojson,.json,.ifc";S==="dxf"?R=".dxf":S==="svg"?R=".svg":S==="geojson"?R=".geojson,.json":S==="ifc"&&(R=".ifc"),ke.current.accept=R,ke.current.click()}ee(!1)},[]);u.useEffect(()=>{const S=R=>{Oe.current&&!Oe.current.contains(R.target)&&te(!1),Ce.current&&!Ce.current.contains(R.target)&&ee(!1)};return(W||ue)&&document.addEventListener("mousedown",S),()=>{document.removeEventListener("mousedown",S)}},[W,ue]);const X=u.useCallback(()=>{var J,Q;if(!ce.showGrid||!ye)return null;const S=[],R=ce.gridSize,D=((J=ye.bounds)==null?void 0:J.width)??1e3,G=((Q=ye.bounds)==null?void 0:Q.height)??800;for(let le=0;le<=D;le+=R)S.push(e.jsx("line",{x1:le,y1:0,x2:le,y2:G,className:F.gridLine},`v${le}`));for(let le=0;le<=G;le+=R)S.push(e.jsx("line",{x1:0,y1:le,x2:D,y2:le,className:F.gridLine},`h${le}`));return e.jsx("g",{className:F.grid,children:S})},[ce.showGrid,ce.gridSize,ye]),H=u.useCallback(()=>{if(!ye)return null;const S=ye.layers.find(R=>R.name==="zones");return S?e.jsx("g",{className:F.zonesLayer,children:S.objects.map(R=>{const D=R;if(!D.boundary||D.boundary.length<3)return null;const G=D.boundary.map((le,$e)=>`${$e===0?"M":"L"}${le.x},${le.y}`).join(" ")+" Z",J=ve.objectIds.includes(D.id),Q=D.boundary.reduce((le,$e)=>({x:le.x+$e.x/D.boundary.length,y:le.y+$e.y/D.boundary.length}),{x:0,y:0});return e.jsxs("g",{className:F.zone,onClick:le=>{le.stopPropagation(),f({type:"SET_SELECTION",selection:{objectIds:[D.id],bounds:null,locked:!1}})},children:[e.jsx("path",{d:G,fill:D.color??"var(--nice-primary-bg, #dbeafe)",fillOpacity:.5,stroke:J?"var(--nice-primary-hover, #2563eb)":"var(--nice-text-muted, #94a3b8)",strokeWidth:J?2:1}),D.name&&e.jsx("text",{x:Q.x,y:Q.y,textAnchor:"middle",dominantBaseline:"middle",className:F.zoneLabel,children:D.name})]},D.id)})}):null},[ye,ve.objectIds]),de=u.useCallback(()=>Ve.length===0?null:e.jsx("g",{className:F.guides,children:Ve.map((S,R)=>e.jsx("line",{x1:S.start.x,y1:S.start.y,x2:S.end.x,y2:S.end.y,className:F.guideLine},R))}),[Ve]),_e=u.useCallback(()=>{if(!he.active||he.points.length===0)return null;const S=[...he.points];he.preview&&S.push(he.preview);const R=S.map((G,J)=>`${J===0?"M":"L"}${G.x},${G.y}`).join(" "),D=me==="draw-zone"&&S.length>2;return e.jsxs("g",{className:F.drawingPreview,children:[e.jsx("path",{d:R+(D?" Z":""),fill:D?"var(--nice-primary-tint-10, rgba(37, 99, 235, 0.1))":"none",stroke:"var(--nice-primary-hover, #2563eb)",strokeWidth:2,strokeDasharray:D?"none":"6,3"}),S.map((G,J)=>e.jsx("circle",{cx:G.x,cy:G.y,r:4,fill:"var(--nice-primary-hover, #2563eb)"},J))]})},[he,me]),Pe=u.useCallback(()=>!se.active||!se.sourcePosition||!se.previewPosition?null:e.jsxs("g",{className:F.connectionPreview,children:[e.jsx("line",{x1:se.sourcePosition.x,y1:se.sourcePosition.y,x2:se.previewPosition.x,y2:se.previewPosition.y,stroke:"var(--nice-success, #10b981)",strokeWidth:2,strokeDasharray:"8,4",markerEnd:"url(#connectionArrow)"}),e.jsx("circle",{cx:se.sourcePosition.x,cy:se.sourcePosition.y,r:6,fill:"var(--nice-success, #10b981)"}),e.jsx("circle",{cx:se.previewPosition.x,cy:se.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)"})})})]}),[se]),lt=u.useCallback(()=>{if(!ye)return null;const S=ye.layers.find(J=>J.type==="network");if(!S)return null;const R=S.objects.filter(J=>J.type==="connection");if(R.length===0)return null;const D={"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}},G={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:R.map(J=>{const Q=J.metadata;if(!(Q!=null&&Q.sourcePosition)||!(Q!=null&&Q.targetPosition))return null;const le=D[Q.medium??"default"]||D.default,$e=G[Q.status??"unknown"]||G.unknown,Ye=ve.objectIds.includes(J.id);let Ot=`M${Q.sourcePosition.x},${Q.sourcePosition.y}`;if(Q.waypoints&&Q.waypoints.length>0)for(const dt of Q.waypoints)Ot+=` L${dt.x},${dt.y}`;return Ot+=` L${Q.targetPosition.x},${Q.targetPosition.y}`,e.jsxs("g",{className:F.connection,onClick:dt=>{dt.stopPropagation(),f({type:"SET_SELECTION",selection:{objectIds:[J.id],bounds:null,locked:!1}})},children:[e.jsx("path",{d:Ot,fill:"none",stroke:Ye?"var(--nice-primary-hover, #2563eb)":le.color,strokeWidth:Ye?le.width+1:le.width,strokeDasharray:le.dashArray,strokeLinecap:"round",strokeLinejoin:"round"}),Q.status&&Q.status!=="active"&&e.jsx("circle",{cx:(Q.sourcePosition.x+Q.targetPosition.x)/2,cy:(Q.sourcePosition.y+Q.targetPosition.y)/2,r:5,fill:$e}),e.jsx("circle",{cx:Q.sourcePosition.x,cy:Q.sourcePosition.y,r:4,fill:le.color,stroke:"white",strokeWidth:1}),e.jsx("circle",{cx:Q.targetPosition.x,cy:Q.targetPosition.y,r:4,fill:le.color,stroke:"white",strokeWidth:1})]},J.id)})})},[ye,ve.objectIds]);if(!ie&&!ye)return e.jsx("div",{className:`${F.root} ${F[i]} ${v??""}`,style:x,children:e.jsxs("div",{className:F.emptyState,children:[e.jsx("div",{className:F.emptyIcon,children:e.jsx(N.NiceIcon,{name:We.icon,size:48})}),e.jsx("h3",{children:_("buildings.noDocumentOpen","No Document Open")}),e.jsx("p",{children:_("buildings.createANewDocumentOr","Create a new document or open an existing .nsp.json file")}),e.jsx("button",{className:F.primaryBtn,onClick:()=>{const S=Ht("New Project","floor-plan");f({type:"SET_DOCUMENT",document:S})},children:_("buildings.createNewDocument","Create New Document")})]})});const Mn=e.jsxs("div",{className:F.topBar,children:[e.jsx(_d,{currentMode:we,availableModes:s,onModeChange:zt}),ie&&ie.floors.length>1&&e.jsx("div",{className:F.floorTabs,children:ie.floors.map(S=>e.jsx("button",{className:`${F.floorTab} ${qe===S.id?F.floorTabActive:""}`,onClick:()=>f({type:"SET_ACTIVE_FLOOR",floorId:S.id}),children:S.name},S.id))}),e.jsxs("div",{className:F.viewportControls,children:[!o&&e.jsxs(e.Fragment,{children:[e.jsx("button",{title:_("buildings.undoCtrlZ","Undo (Ctrl+Z)"),onClick:()=>f({type:"UNDO"}),disabled:!rt,className:rt?"":F.disabled,children:e.jsx(N.NiceIcon,{name:"reply",size:16})}),e.jsx("button",{title:_("buildings.redoCtrlY","Redo (Ctrl+Y)"),onClick:()=>f({type:"REDO"}),disabled:!tt,className:tt?"":F.disabled,children:e.jsx(N.NiceIcon,{name:"forward",size:16})}),e.jsx("div",{className:F.separator})]}),e.jsx("button",{title:_("buildings.toggleGrid","Toggle Grid"),onClick:()=>f({type:"TOGGLE_GRID"}),className:ce.showGrid?F.active:"",children:e.jsx(N.NiceIcon,{name:"grid",size:16})}),e.jsx("button",{title:_("buildings.toggleSnap","Toggle Snap"),onClick:()=>f({type:"TOGGLE_SNAP"}),className:ce.snapEnabled?F.active:"",children:e.jsx(N.NiceIcon,{name:"target",size:16})}),e.jsxs("span",{className:F.zoomLevel,children:[Math.round(ce.zoom*100),"%"]}),e.jsx("button",{title:_("buildings.zoomIn","Zoom In"),onClick:()=>f({type:"ZOOM",delta:1}),children:e.jsx(N.NiceIcon,{name:"plus",size:16})}),e.jsx("button",{title:_("buildings.zoomOut","Zoom Out"),onClick:()=>f({type:"ZOOM",delta:-1}),children:e.jsx(N.NiceIcon,{name:"minus",size:16})}),e.jsx("button",{title:_("buildings.resetView2","Reset View"),onClick:()=>f({type:"RESET_VIEW"}),children:e.jsx(N.NiceIcon,{name:"expand",size:16})}),!o&&e.jsxs("div",{className:F.exportDropdown,ref:Ce,children:[e.jsx("input",{type:"file",ref:ke,onChange:Mt,style:{display:"none"}}),e.jsxs("button",{title:_("buildings.import","Import"),onClick:()=>ee(!ue),className:ue?F.active:"",children:[e.jsx(N.NiceIcon,{name:"download",size:14})," ",_("buildings.import","Import")]}),ue&&e.jsxs("div",{className:F.exportMenu,children:[e.jsxs("button",{onClick:()=>E(),children:[e.jsx(N.NiceIcon,{name:"file",size:14})," ",_("buildings.autoDetectFormat","Auto-detect format")]}),e.jsxs("button",{onClick:()=>E("dxf"),children:[e.jsx(N.NiceIcon,{name:"ruler",size:14})," ",_("buildings.autocadDxfDxf","AutoCAD DXF (.dxf)")]}),e.jsxs("button",{onClick:()=>E("svg"),children:[e.jsx(N.NiceIcon,{name:"image",size:14})," ",_("buildings.svgVectorGraphicsSvg","SVG Vector Graphics (.svg)")]}),e.jsxs("button",{onClick:()=>E("geojson"),children:[e.jsx(N.NiceIcon,{name:"globe",size:14})," ",_("buildings.geojsonGeojson","GeoJSON (.geojson)")]}),e.jsxs("button",{onClick:()=>E("ifc"),children:[e.jsx(N.NiceIcon,{name:"building",size:14})," ",_("buildings.ifcBimIfc","IFC (BIM) (.ifc)")]})]})]}),ie&&e.jsxs("div",{className:F.exportDropdown,ref:Oe,children:[e.jsxs("button",{title:_("buildings.export","Export"),onClick:()=>te(!W),className:W?F.active:"",children:[e.jsx(N.NiceIcon,{name:"upload",size:14})," ",_("buildings.export","Export")]}),W&&e.jsxs("div",{className:F.exportMenu,children:[e.jsxs("button",{onClick:()=>Ue("nsp"),children:[e.jsx(N.NiceIcon,{name:"file",size:14})," ",_("buildings.nicetodevSpatialPlanNspJson","NiceToDev Spatial Plan (.nsp.json)")]}),e.jsxs("button",{onClick:()=>Ue("svg"),children:[e.jsx(N.NiceIcon,{name:"image",size:14})," ",_("buildings.svgVectorGraphicsSvg","SVG Vector Graphics (.svg)")]}),e.jsxs("button",{onClick:()=>Ue("dxf"),children:[e.jsx(N.NiceIcon,{name:"ruler",size:14})," ",_("buildings.autocadDxfDxf","AutoCAD DXF (.dxf)")]}),e.jsxs("button",{onClick:()=>Ue("png"),children:[e.jsx(N.NiceIcon,{name:"image",size:14})," ",_("buildings.pngImagePng","PNG Image (.png)")]})]})]})]})]}),En=Ae.showObjectLibrary&&!o?e.jsx(Cn,{mode:we,onObjectSelect:S=>{f({type:"SET_TOOL",tool:`place-${S.category}`}),f({type:"START_DRAG",objectType:S.category,objectData:S})}}):void 0,On=e.jsxs("div",{className:F.editorContainer,children:[!o&&e.jsx(gd,{mode:we,activeTool:me,onToolSelect:Pt,readOnly:o}),(we==="network-topology"||we==="infrastructure")&&e.jsxs("div",{className:F.modeActions,children:[e.jsxs("button",{className:`${F.actionBtn} ${Me?F.active:""}`,onClick:()=>Ee(!Me),title:_("buildings.spatial.pathAnalysis","Network path analysis"),children:[e.jsx(N.NiceIcon,{name:"bar-chart",size:14})," ",_("buildings.spatial.path","Path")]}),e.jsxs("button",{className:`${F.actionBtn} ${P?F.active:""}`,onClick:()=>K(!P),title:_("buildings.spatial.vlan.title","VLAN overlay"),children:[e.jsx(N.NiceIcon,{name:"globe",size:14})," ",_("buildings.vlanOverlay","VLAN Overlay")]})]}),e.jsxs("div",{className:F.canvasWrapper,children:[e.jsx("svg",{ref:q,className:`${F.canvas} ${F[`cursor_${me.replace("-","_")}`]??""}`,onMouseDown:kt,onMouseMove:St,onMouseUp:Ct,onDoubleClick:Tt,onWheel:Lt,children:e.jsxs("g",{transform:`translate(${ce.pan.x}, ${ce.pan.y}) scale(${ce.zoom})`,children:[X(),H(),lt(),de(),_e(),Pe()]})}),Ae.showMinimap&&e.jsx(Sn,{document:ie,activeFloorId:qe,viewport:ce,onViewportChange:S=>f({type:"SET_VIEWPORT",viewport:S})})]})]}),An=e.jsxs("div",{className:F.rightSidebar,children:[Ae.showLayerPanel&&e.jsx(kn,{layers:Se.filter(S=>We.layerTypes.includes(S.type)),onVisibilityToggle:S=>{var R;return f({type:"SET_LAYER_VISIBILITY",layerType:S,visible:!((R=Se.find(D=>D.type===S))!=null&&R.visible)})},onLockToggle:S=>{var R;return f({type:"SET_LAYER_LOCKED",layerType:S,locked:!((R=Se.find(D=>D.type===S))!=null&&R.locked)})},onOpacityChange:(S,R)=>f({type:"SET_LAYER_OPACITY",layerType:S,opacity:R})}),Ae.showPropertiesPanel&&ve.objectIds.length>0&&e.jsx(Tn,{selection:ve,document:ie,onPropertyChange:(S,R,D)=>{f({type:"UPDATE_OBJECT",objectId:S,updates:{[R]:D}})}})]}),Bn=e.jsxs("div",{className:F.statusBar,children:[e.jsxs("span",{className:F.modeIndicator,children:[e.jsx(N.NiceIcon,{name:We.icon,size:14})," ",We.label]}),e.jsxs("span",{className:F.toolIndicator,children:[((Ut=xt[me])==null?void 0:Ut.icon)&&e.jsx(N.NiceIcon,{name:xt[me].icon,size:14})," ",(Yt=xt[me])==null?void 0:Yt.label]}),ve.objectIds.length>0&&e.jsx("span",{className:F.selectionInfo,children:_("buildings.selected2","{objectIds} selected").replace("{objectIds}",String(ve.objectIds.length))}),he.active&&e.jsx("span",{className:F.drawingInfo,children:_("buildings.drawingPoints","Drawing: {points} points").replace("{points}",String(he.points.length))}),se.active&&e.jsx("span",{className:F.connectingInfo,children:_("buildings.connectingClickTargetDeviceOr","Connecting: click target device or ESC to cancel")}),e.jsx("span",{className:F.gridInfo,children:_("buildings.gridSnap","Grid: {size}px · Snap: {snap}").replace("{size}",String(ce.gridSize)).replace("{snap}",ce.snapEnabled?_("buildings.on","ON"):_("buildings.off","OFF"))})]});return e.jsxs("div",{className:`nice-spatial-editor ${F.root} ${F[i]} ${v??""}`,style:{position:"relative",...x},tabIndex:0,onKeyDown:$t,children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:e.jsx(N.NiceTutorialButton,{steps:N.resolveTutorial(h,bd)})}),e.jsx(N.NiceAppShell,{flush:!0,className:F.shell,menubar:Mn,sidebar:En,rightSidebar:An,statusBar:Bn,children:On}),fe&&!Re&&e.jsx(aa,{result:fe,onConfirm:Et,onCancel:ct}),fe&&Re&&e.jsx(Ma,{importResult:fe,existingDocument:ie??void 0,onConfirm:k,onCancel:$}),Me&&ie&&e.jsx(Ui,{document:ie,connections:ln(ie),onHighlightPath:S=>{f(S?{type:"SET_SELECTION",selection:{objectIds:S.connectionIds,bounds:null,locked:!1}}:{type:"SET_SELECTION",selection:{objectIds:[],bounds:null,locked:!1}})},onClose:()=>Ee(!1)}),P&&ie&&e.jsx(Dc,{document:ie,connections:ln(ie),vlans:fd(ie),visibleVlanIds:pe,onVlanVisibilityChange:(S,R)=>{Ie(D=>{const G=new Set(D);return R?G.add(S):G.delete(S),G})},onHighlightVlan:S=>{je((S==null?void 0:S.id)??null),f(S?{type:"SET_SELECTION",selection:{objectIds:S.deviceIds,bounds:null,locked:!1}}:{type:"SET_SELECTION",selection:{objectIds:[],bounds:null,locked:!1}})},onClose:()=>K(!1)})]})},vd="_viewer_nyfnl_13",jd="_theme_light_nyfnl_37",Nd="_theme_dark_nyfnl_59",wd="_debugOverlay_nyfnl_85",Id="_topBar_nyfnl_137",kd="_searchContainer_nyfnl_159",Sd="_searchInput_nyfnl_171",Cd="_clearBtn_nyfnl_227",Td="_searchResults_nyfnl_261",Ld="_searchResultItem_nyfnl_291",$d="_searchResultInfo_nyfnl_335",zd="_searchResultName_nyfnl_347",Pd="_searchResultDesc_nyfnl_357",Md="_floorSelector_nyfnl_371",Ed="_navBtn_nyfnl_421",Od="_active_nyfnl_459",Ad="_layersBtn_nyfnl_475",Bd="_legendBtn_nyfnl_529",Dd="_content_nyfnl_583",Rd="_navPanel_nyfnl_599",qd="_navPanelHeader_nyfnl_617",Fd="_routeInputs_nyfnl_671",Gd="_routeInput_nyfnl_671",Vd="_routeMarker_nyfnl_705",Wd="_routeHint_nyfnl_745",Hd="_routeInfo_nyfnl_761",Ud="_routeStat_nyfnl_779",Yd="_routeStatLabel_nyfnl_791",Zd="_routeStatValue_nyfnl_805",Xd="_clearRouteBtn_nyfnl_817",Kd="_refPointsList_nyfnl_851",Jd="_refPointItem_nyfnl_879",Qd="_refPointIcon_nyfnl_917",eu="_layersPanel_nyfnl_929",tu="_layersPanelHeader_nyfnl_947",nu="_layersList_nyfnl_1001",su="_layerItem_nyfnl_1015",ou="_layerToggle_nyfnl_1039",au="_layerName_nyfnl_1075",iu="_layerType_nyfnl_1087",ru="_canvasWrapper_nyfnl_1101",cu="_canvas_nyfnl_1101",lu="_grid_nyfnl_1137",du="_gridLine_nyfnl_1145",uu="_zonesLayer_nyfnl_1161",mu="_zone_nyfnl_1161",pu="_zoneSelected_nyfnl_1187",hu="_zoneLabel_nyfnl_1197",gu="_objectsLayer_nyfnl_1213",_u="_object_nyfnl_1213",fu="_objectSelected_nyfnl_1237",yu="_objectLabel_nyfnl_1245",bu="_referencePoints_nyfnl_1261",xu="_referencePoint_nyfnl_1261",vu="_refLabel_nyfnl_1283",ju="_routeLayer_nyfnl_1299",Nu="_routePath_nyfnl_1305",wu="_routeDash_nyfnl_1",Iu="_routeMarkers_nyfnl_1331",ku="_currentLocation_nyfnl_1341",Su="_locationPulse_nyfnl_1347",Cu="_pulse_nyfnl_1",Tu="_zoomControls_nyfnl_1383",Lu="_minimap_nyfnl_1459",$u="_minimapContent_nyfnl_1485",zu="_minimapViewport_nyfnl_1499",Pu="_legendPanel_nyfnl_1519",Mu="_legendPanelHeader_nyfnl_1551",Eu="_legendList_nyfnl_1607",Ou="_legendItem_nyfnl_1623",Au="_legendColor_nyfnl_1647",Bu="_legendIcon_nyfnl_1663",Du="_legendLabel_nyfnl_1677",Ru="_legendType_nyfnl_1689",qu="_objectInfo_nyfnl_1707",Fu="_objectInfoHeader_nyfnl_1735",Gu="_navigateBtn_nyfnl_1805",z={viewer:vd,theme_light:jd,theme_dark:Nd,debugOverlay:wd,topBar:Id,searchContainer:kd,searchInput:Sd,clearBtn:Cd,searchResults:Td,searchResultItem:Ld,searchResultInfo:$d,searchResultName:zd,searchResultDesc:Pd,floorSelector:Md,navBtn:Ed,active:Od,layersBtn:Ad,legendBtn:Bd,content:Dd,navPanel:Rd,navPanelHeader:qd,routeInputs:Fd,routeInput:Gd,routeMarker:Vd,routeHint:Wd,routeInfo:Hd,routeStat:Ud,routeStatLabel:Yd,routeStatValue:Zd,clearRouteBtn:Xd,refPointsList:Kd,refPointItem:Jd,refPointIcon:Qd,layersPanel:eu,layersPanelHeader:tu,layersList:nu,layerItem:su,layerToggle:ou,layerName:au,layerType:iu,canvasWrapper:ru,canvas:cu,grid:lu,gridLine:du,zonesLayer:uu,zone:mu,zoneSelected:pu,zoneLabel:hu,objectsLayer:gu,object:_u,objectSelected:fu,objectLabel:yu,referencePoints:bu,referencePoint:xu,refLabel:vu,routeLayer:ju,routePath:Nu,routeDash:wu,routeMarkers:Iu,currentLocation:ku,locationPulse:Su,pulse:Cu,zoomControls:Tu,minimap:Lu,minimapContent:$u,minimapViewport:zu,legendPanel:Pu,legendPanelHeader:Mu,legendList:Eu,legendItem:Ou,legendColor:Au,legendIcon:Bu,legendLabel:Du,legendType:Ru,objectInfo:qu,objectInfoHeader:Fu,navigateBtn:Gu},Vu=()=>e.jsx(N.NiceIcon,{name:"search",size:16}),dn=()=>e.jsx(N.NiceIcon,{name:"navigation",size:16}),Wu=()=>e.jsx(N.NiceIcon,{name:"map-pin",size:16}),Hu=()=>e.jsx(N.NiceIcon,{name:"building",size:16}),Uu=()=>e.jsx(N.NiceIcon,{name:"git-branch",size:16}),Yu=()=>e.jsx(N.NiceIcon,{name:"zoom-in",size:16}),Zu=()=>e.jsx(N.NiceIcon,{name:"zoom-out",size:16}),st=()=>e.jsx(N.NiceIcon,{name:"close",size:16}),un=()=>e.jsx(N.NiceIcon,{name:"layers",size:16}),mn=()=>e.jsx(N.NiceIcon,{name:"list",size:16}),Xu=()=>e.jsx(N.NiceIcon,{name:"eye",size:16}),Ku=()=>e.jsx(N.NiceIcon,{name:"eye-off",size:16}),Ju={entrance:"door",elevator:"elevator",stairs:"stairs",exit:"bell",poi:"map-pin",parking:"map-pin"};function Ft(t){return t.icon??Ju[t.type]??"map-pin"}function Qu(t,n){return Math.sqrt((n.x-t.x)**2+(n.y-t.y)**2)}function em(t){return t<1?"<1m":t<1e3?`${Math.round(t)}m`:`${(t/1e3).toFixed(1)}km`}function tm(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 nm=Ht(""),sm=({document:t=nm,initialFloorId:n,showNavigation:s=!0,showMinimap:o=!0,showFloorSelector:i=!0,showSearch:a=!0,showLayersPanel:c=!0,showLegend:r=!0,enableRoutePlanning:l=!0,referencePoints:b=[],onObjectClick:m,onRouteCalculated:h,currentLocation:v,theme:x="light",className:p,virtualRendering:j,virtualRenderingThreshold:g=200,debugVirtualRendering:I=!1})=>{var ct;const{t:y}=N.useNiceTranslation(),[L,_]=u.useState(n??((ct=t.floors[0])==null?void 0:ct.id)??""),[C,d]=u.useState({zoom:1,pan:{x:0,y:0}}),[w,f]=u.useState(""),[q,T]=u.useState([]),[M,W]=u.useState(null),[te,ue]=u.useState(null),[ee,ge]=u.useState(null),[ne,fe]=u.useState(null),[ze,Re]=u.useState(!1),[Le,Me]=u.useState(!1),[Ee,P]=u.useState(!1),[K,pe]=u.useState(new Map),[Ie,Be]=u.useState({width:1e3,height:600}),je=u.useRef(null),Oe=u.useRef(null),Ce=u.useRef(!1),ke=u.useRef({x:0,y:0}),we=u.useMemo(()=>{const k=t.floors.find($=>$.id===L);return k?k.layers.reduce(($,E)=>{var X;return $+(((X=E.objects)==null?void 0:X.length)??0)},0):0},[t.floors,L]),me=j??Io(we,g),ie=u.useMemo(()=>{if(!me)return null;const k=t.floors.find(E=>E.id===L);if(!k)return null;const $=[];for(const E of k.layers)if(!(E.type==="zones"||E.type==="grid"||E.type==="background"))for(const X of E.objects??[]){const H=X.position??{x:0,y:0},de=X.size??{width:20,height:20};$.push({id:X.id,position:H,size:de,data:{object:X,layerId:E.id}})}return No($)},[t.floors,L,me]),qe=u.useMemo(()=>wo(C,Ie,100),[C,Ie]),Se=u.useMemo(()=>!me||!ie?null:ie.query(qe),[me,ie,qe]),ve=u.useMemo(()=>!I||!me?null:ko(we,(Se==null?void 0:Se.length)??we,C),[I,me,we,Se,C]);u.useEffect(()=>{const k=Oe.current;if(!k)return;const $=new ResizeObserver(E=>{for(const X of E)Be({width:X.contentRect.width,height:X.contentRect.height})});return $.observe(k),()=>$.disconnect()},[]),u.useEffect(()=>{const k=t.floors.find($=>$.id===L);k&&pe($=>{const E=new Map;for(const X of k.layers)E.set(X.id,$.get(X.id)??!0);return E})},[L,t.floors]);const ce=u.useCallback(k=>{pe($=>{const E=new Map($);return E.set(k,!$.get(k)),E})},[]),he=u.useCallback(k=>K.get(k)!==!1,[K]),se=u.useMemo(()=>t.floors.find(k=>k.id===L)??t.floors[0],[t.floors,L]),Ve=u.useMemo(()=>{if(!se)return[];const k=[],$=se.layers.find(H=>H.type==="zones");if($){const H=new Map;for(const de of $.objects){const _e=de.metadata,Pe=(_e==null?void 0:_e.zoneType)??de.type??"zone";H.has(Pe)||H.set(Pe,(_e==null?void 0:_e.fill)??"var(--nice-primary, #3b82f6)")}for(const[de,_e]of H)k.push({id:`zone-${de}`,label:de.charAt(0).toUpperCase()+de.slice(1).replace(/-/g," "),color:_e,type:"zone"})}const E=new Map;for(const H of se.layers)if(!(H.type==="zones"||H.type==="grid"||H.type==="background"))for(const de of H.objects){const _e=de.type??"object",Pe=E.get(_e);Pe?Pe.count++:E.set(_e,{count:1,color:"var(--nice-text-secondary, #64748b)"})}for(const[H,de]of E)k.push({id:`obj-${H}`,label:`${H.charAt(0).toUpperCase()+H.slice(1).replace(/-/g," ")} (${de.count})`,color:de.color,type:"object"});const X=new Map;for(const H of b.filter(de=>de.floorId===L))X.has(H.type)||X.set(H.type,Ft(H));for(const[H,de]of X)k.push({id:`ref-${H}`,label:H.charAt(0).toUpperCase()+H.slice(1),color:"var(--nice-primary, #3b82f6)",icon:de,type:"reference"});return k},[se,b,L]),Ae=u.useCallback((k,$)=>{var X;const E=(X=je.current)==null?void 0:X.getBoundingClientRect();return E?{x:(k-E.left-C.pan.x)/C.zoom,y:($-E.top-C.pan.y)/C.zoom}:{x:0,y:0}},[C]);u.useEffect(()=>{if(!w.trim()){T([]);return}const k=w.toLowerCase(),$=[];for(const E of t.floors)for(const X of E.layers)for(const H of X.objects){const de=(H.name??H.id).toLowerCase(),_e=(H.description??"").toLowerCase();(de.includes(k)||_e.includes(k))&&$.push(H)}T($.slice(0,10))},[w,t.floors]);const et=u.useCallback((k,$)=>{const E=Qu(k,$);return{id:`route-${Date.now()}`,startPoint:k,endPoint:$,path:[k,$],floorTransitions:[],totalDistance:E,estimatedTime:E/1.4,instructions:[{type:"straight",distance:E,direction:"forward"},{type:"arrive"}]}},[]);u.useEffect(()=>{if(te&&ee){const k=et(te,ee);fe(k),h==null||h(k)}else fe(null),h==null||h(null)},[te,ee,et,h]);const We=u.useCallback(k=>{(k.button===1||k.button===0&&k.altKey)&&(Ce.current=!0,ke.current={x:k.clientX,y:k.clientY},k.preventDefault())},[]),rt=u.useCallback(k=>{if(Ce.current){const $=k.clientX-ke.current.x,E=k.clientY-ke.current.y;ke.current={x:k.clientX,y:k.clientY},d(X=>({...X,pan:{x:X.pan.x+$,y:X.pan.y+E}}))}},[]),tt=u.useCallback(()=>{Ce.current=!1},[]),ye=u.useCallback(k=>{var de;k.preventDefault();const $=k.deltaY>0?.9:1.1,E=(de=je.current)==null?void 0:de.getBoundingClientRect();if(!E)return;const X=k.clientX-E.left,H=k.clientY-E.top;d(_e=>{const Pe=Math.min(Math.max(_e.zoom*$,.1),10),lt=Pe/_e.zoom;return{zoom:Pe,pan:{x:X-(X-_e.pan.x)*lt,y:H-(H-_e.pan.y)*lt}}})},[]),De=u.useCallback(k=>{if(l&&k.ctrlKey){const $=Ae(k.clientX,k.clientY);te?ee?(ue($),ge(null)):ge($):ue($)}},[l,te,ee,Ae]),He=u.useCallback(()=>{d(k=>({...k,zoom:Math.min(k.zoom*1.25,10)}))},[]),kt=u.useCallback(()=>{d(k=>({...k,zoom:Math.max(k.zoom/1.25,.1)}))},[]),St=u.useCallback(()=>{d({zoom:1,pan:{x:0,y:0}})},[]),Ct=u.useCallback(k=>{W(k);for(const E of t.floors)for(const X of E.layers)if(X.objects.find(H=>H.id===k.id)){_(E.id);break}const $=k.position??{x:0,y:0};d(E=>({...E,pan:{x:-($.x*E.zoom)+400,y:-($.y*E.zoom)+300}})),f(""),T([]),m==null||m(k)},[t.floors,m]),Tt=u.useCallback(()=>{ue(null),ge(null),fe(null)},[]),Lt=u.useCallback(()=>{const $=[];for(let E=-2e3;E<=2e3;E+=50)$.push(e.jsx("line",{x1:E,y1:-2e3,x2:E,y2:2e3,className:z.gridLine},`v-${E}`));for(let E=-2e3;E<=2e3;E+=50)$.push(e.jsx("line",{x1:-2e3,y1:E,x2:2e3,y2:E,className:z.gridLine},`h-${E}`));return e.jsx("g",{className:z.grid,children:$})},[]),$t=u.useCallback(()=>{if(!se)return null;const k=se.layers.find($=>$.type==="zones");return!k||!he(k.id)?null:e.jsx("g",{className:z.zonesLayer,children:k.objects.map($=>{const E=$.metadata;if(!(E!=null&&E.points)||E.points.length<3)return null;const X=`M${E.points.map(de=>`${de.x},${de.y}`).join(" L")} Z`,H=(M==null?void 0:M.id)===$.id;return e.jsxs("g",{className:`${z.zone} ${H?z.zoneSelected:""}`,onClick:()=>{W($),m==null||m($)},children:[e.jsx("path",{d:X,fill:E.fill??"var(--nice-primary, #3b82f6)",fillOpacity:.2,stroke:E.fill??"var(--nice-primary, #3b82f6)",strokeWidth:H?2:1}),$.name&&e.jsx("text",{x:E.points[0].x+10,y:E.points[0].y+20,className:z.zoneLabel,children:$.name})]},$.id)})})},[se,M,m,he]),zt=u.useCallback(()=>se?me&&Se?e.jsx("g",{className:z.objectsLayer,children:Se.map(k=>{const{object:$,layerId:E}=k.data;if(!he(E))return null;const X=$.position??{x:0,y:0},H=$.size??{width:20,height:20},de=(M==null?void 0:M.id)===$.id;return e.jsxs("g",{className:`${z.object} ${de?z.objectSelected:""}`,transform:`translate(${X.x}, ${X.y})`,onClick:_e=>{_e.stopPropagation(),W($),m==null||m($)},children:[e.jsx("rect",{x:-H.width/2,y:-H.height/2,width:H.width,height:H.height,rx:4,fill:de?"var(--nice-primary, #3b82f6)":"var(--nice-text-secondary, #64748b)",fillOpacity:.8,stroke:de?"var(--nice-primary-dark, #1d4ed8)":"transparent",strokeWidth:2}),$.name&&e.jsx("text",{y:H.height/2+14,textAnchor:"middle",className:z.objectLabel,children:$.name})]},$.id)})}):e.jsx("g",{className:z.objectsLayer,children:se.layers.map(k=>k.type==="zones"||k.type==="grid"||k.type==="background"||!he(k.id)?null:k.objects.map($=>{const E=$.position??{x:0,y:0},X=$.size??{width:20,height:20},H=(M==null?void 0:M.id)===$.id;return e.jsxs("g",{className:`${z.object} ${H?z.objectSelected:""}`,transform:`translate(${E.x}, ${E.y})`,onClick:de=>{de.stopPropagation(),W($),m==null||m($)},children:[e.jsx("rect",{x:-X.width/2,y:-X.height/2,width:X.width,height:X.height,rx:4,fill:H?"var(--nice-primary, #3b82f6)":"var(--nice-text-secondary, #64748b)",fillOpacity:.8,stroke:H?"var(--nice-primary-dark, #1d4ed8)":"transparent",strokeWidth:2}),$.name&&e.jsx("text",{y:X.height/2+14,textAnchor:"middle",className:z.objectLabel,children:$.name})]},$.id)}))}):null,[se,M,m,he,me,Se]),Pt=u.useCallback(()=>{const k=b.filter($=>$.floorId===L);return e.jsx("g",{className:z.referencePoints,children:k.map($=>e.jsxs("g",{className:z.referencePoint,transform:`translate(${$.position.x}, ${$.position.y})`,onClick:()=>{l&&(te?ge($.position):ue($.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:Ft($),size:16})}),e.jsx("text",{y:30,textAnchor:"middle",className:z.refLabel,children:$.name})]},$.id))})},[b,L,l,te]),Ue=u.useCallback(()=>{if(!ne)return null;const k=`M${ne.path.map($=>`${$.x},${$.y}`).join(" L")}`;return e.jsxs("g",{className:z.routeLayer,children:[e.jsx("path",{d:k,fill:"none",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:4,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"12,6",className:z.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]),Mt=u.useCallback(()=>v?e.jsxs("g",{className:z.currentLocation,children:[e.jsx("circle",{cx:v.x,cy:v.y,r:12,fill:"var(--nice-primary, #3b82f6)",fillOpacity:.3,className:z.locationPulse}),e.jsx("circle",{cx:v.x,cy:v.y,r:6,fill:"var(--nice-primary, #3b82f6)",stroke:"white",strokeWidth:2})]}):null,[v]),Et=u.useCallback(()=>e.jsx("g",{className:z.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:Oe,className:`${z.viewer} ${z[`theme_${x}`]} ${p??""}`,children:[I&&ve&&e.jsxs("div",{className:z.debugOverlay,children:[e.jsx("div",{children:y("buildings.virtualOn","Virtual: ON")}),e.jsx("div",{children:y("buildings.total","Total: {total}").replace("{total}",String(ve.total))}),e.jsx("div",{children:y("buildings.visible","Visible: {visible}").replace("{visible}",String(ve.visible))}),e.jsx("div",{children:y("buildings.culled","Culled: {culled} ({cullPercentage}%)").replace("{culled}",String(ve.culled)).replace("{cullPercentage}",String(ve.cullPercentage))}),e.jsx("div",{children:y("buildings.zoomX","Zoom: {zoom}x").replace("{zoom}",String(ve.zoom.toFixed(2)))})]}),e.jsxs("div",{className:z.topBar,children:[a&&e.jsxs("div",{className:z.searchContainer,children:[e.jsxs("div",{className:z.searchInput,children:[e.jsx(Vu,{}),e.jsx("input",{type:"text",placeholder:y("buildings.spatial.searchPlaces","Search places…"),value:w,onChange:k=>f(k.target.value)}),w&&e.jsx("button",{className:z.clearBtn,onClick:()=>f(""),children:e.jsx(st,{})})]}),q.length>0&&e.jsx("div",{className:z.searchResults,children:q.map(k=>e.jsxs("button",{className:z.searchResultItem,onClick:()=>Ct(k),children:[e.jsx(Wu,{}),e.jsxs("div",{className:z.searchResultInfo,children:[e.jsx("span",{className:z.searchResultName,children:k.name??k.id}),k.description&&e.jsx("span",{className:z.searchResultDesc,children:k.description})]})]},k.id))})]}),i&&t.floors.length>1&&e.jsxs("div",{className:z.floorSelector,children:[e.jsx(Hu,{}),e.jsx("select",{value:L,onChange:k=>_(k.target.value),children:t.floors.map(k=>e.jsx("option",{value:k.id,children:k.name??y("buildings.floorLevel","Floor {level}").replace("{level}",String(k.level))},k.id))})]}),s&&e.jsxs("button",{className:`${z.navBtn} ${ze?z.active:""}`,onClick:()=>Re(!ze),children:[e.jsx(dn,{}),e.jsx("span",{children:y("buildings.navigation","Navigation")})]}),c&&e.jsxs("button",{className:`${z.layersBtn} ${Le?z.active:""}`,onClick:()=>Me(!Le),children:[e.jsx(un,{}),e.jsx("span",{children:y("buildings.layers","Layers")})]}),r&&e.jsxs("button",{className:`${z.legendBtn} ${Ee?z.active:""}`,onClick:()=>P(!Ee),children:[e.jsx(mn,{}),e.jsx("span",{children:y("buildings.legend","Legend")})]})]}),e.jsxs("div",{className:z.content,children:[ze&&e.jsxs("div",{className:z.navPanel,children:[e.jsxs("div",{className:z.navPanelHeader,children:[e.jsx(Uu,{}),e.jsx("span",{children:y("buildings.routePlanning","Route planning")}),e.jsx("button",{onClick:()=>Re(!1),children:e.jsx(st,{})})]}),e.jsxs("div",{className:z.routeInputs,children:[e.jsxs("div",{className:z.routeInput,children:[e.jsx("div",{className:z.routeMarker,style:{background:"var(--nice-success, #10b981)"}}),e.jsx("input",{type:"text",placeholder:y("buildings.startPoint","Start point"),value:te?`${te.x.toFixed(0)}, ${te.y.toFixed(0)}`:"",readOnly:!0})]}),e.jsxs("div",{className:z.routeInput,children:[e.jsx("div",{className:z.routeMarker,style:{background:"var(--nice-danger, #ef4444)"}}),e.jsx("input",{type:"text",placeholder:y("buildings.destination","Destination"),value:ee?`${ee.x.toFixed(0)}, ${ee.y.toFixed(0)}`:"",readOnly:!0})]})]}),e.jsx("p",{className:z.routeHint,children:y("buildings.spatial.routeHint","Ctrl-click the map to pick points")}),ne&&e.jsxs("div",{className:z.routeInfo,children:[e.jsxs("div",{className:z.routeStat,children:[e.jsx("span",{className:z.routeStatLabel,children:y("buildings.distance","Distance")}),e.jsx("span",{className:z.routeStatValue,children:em(ne.totalDistance)})]}),e.jsxs("div",{className:z.routeStat,children:[e.jsx("span",{className:z.routeStatLabel,children:y("buildings.spatial.time","Time")}),e.jsx("span",{className:z.routeStatValue,children:tm(ne.estimatedTime)})]})]}),(te||ee)&&e.jsx("button",{className:z.clearRouteBtn,onClick:Tt,children:y("buildings.spatial.clearRoute","Clear the route")}),b.length>0&&e.jsxs("div",{className:z.refPointsList,children:[e.jsx("h4",{children:y("buildings.landmarks","Landmarks")}),b.filter(k=>k.floorId===L).map(k=>e.jsxs("button",{className:z.refPointItem,onClick:()=>{te?ge(k.position):ue(k.position)},children:[e.jsx("span",{className:z.refPointIcon,children:e.jsx(N.NiceIcon,{name:Ft(k),size:16})}),e.jsx("span",{children:k.name})]},k.id))]})]}),Le&&se&&e.jsxs("div",{className:z.layersPanel,children:[e.jsxs("div",{className:z.layersPanelHeader,children:[e.jsx(un,{}),e.jsx("span",{children:y("buildings.layers","Layers")}),e.jsx("button",{onClick:()=>Me(!1),children:e.jsx(st,{})})]}),e.jsx("div",{className:z.layersList,children:se.layers.map(k=>{const $=he(k.id);return e.jsxs("div",{className:z.layerItem,children:[e.jsx("button",{className:z.layerToggle,onClick:()=>ce(k.id),title:$?y("buildings.spatial.hideLayer","Hide layer"):y("buildings.spatial.showLayer","Show layer"),children:$?e.jsx(Xu,{}):e.jsx(Ku,{})}),e.jsx("span",{className:z.layerName,children:k.name??k.id}),e.jsxs("span",{className:z.layerType,children:["(",k.type,")"]})]},k.id)})})]}),e.jsxs("div",{className:z.canvasWrapper,children:[e.jsx("svg",{ref:je,className:z.canvas,onMouseDown:We,onMouseMove:rt,onMouseUp:tt,onMouseLeave:tt,onWheel:ye,onClick:De,children:e.jsxs("g",{transform:`translate(${C.pan.x}, ${C.pan.y}) scale(${C.zoom})`,children:[Lt(),$t(),zt(),Pt(),Et(),Ue(),Mt()]})}),e.jsxs("div",{className:z.zoomControls,children:[e.jsx("button",{onClick:He,title:y("buildings.spatial.zoomIn","Zoom in"),children:e.jsx(Yu,{})}),e.jsx("button",{onClick:kt,title:y("buildings.spatial.zoomOut","Zoom out"),children:e.jsx(Zu,{})}),e.jsx("button",{onClick:St,title:y("buildings.spatial.resetView","Reset the view"),children:e.jsx(N.NiceIcon,{name:"refresh",size:16})})]}),o&&e.jsx("div",{className:z.minimap,children:e.jsx("div",{className:z.minimapContent,children:e.jsx("div",{className:z.minimapViewport})})}),Ee&&Ve.length>0&&e.jsxs("div",{className:z.legendPanel,children:[e.jsxs("div",{className:z.legendPanelHeader,children:[e.jsx(mn,{}),e.jsx("span",{children:y("buildings.legend","Legend")}),e.jsx("button",{onClick:()=>P(!1),children:e.jsx(st,{})})]}),e.jsx("div",{className:z.legendList,children:Ve.map(k=>e.jsxs("div",{className:z.legendItem,children:[k.icon?e.jsx("span",{className:z.legendIcon,children:e.jsx(N.NiceIcon,{name:k.icon,size:16})}):e.jsx("span",{className:z.legendColor,style:{background:k.color}}),e.jsx("span",{className:z.legendLabel,children:k.label}),e.jsx("span",{className:z.legendType,children:k.type==="zone"?y("buildings.zone","zone"):k.type==="object"?y("buildings.object","object"):y("buildings.referencePoint","reference point")})]},k.id))})]})]})]}),M&&e.jsxs("div",{className:z.objectInfo,children:[e.jsxs("div",{className:z.objectInfoHeader,children:[e.jsx("h4",{children:M.name??M.id}),e.jsx("button",{onClick:()=>W(null),children:e.jsx(st,{})})]}),M.description&&e.jsx("p",{children:M.description}),l&&e.jsxs("button",{className:z.navigateBtn,onClick:()=>{const k=M.position??{x:0,y:0};te?ge(k):ue(k)},children:[e.jsx(dn,{}),te?y("buildings.setAsDestination","Set as destination"):y("buildings.setAsStart","Set as start")]})]})]})};function om(t={}){var ue;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:((ue=n==null?void 0:n.floors[0])==null?void 0:ue.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((ee,ge)=>({...ee,...ge}),c),b=u.useCallback(ee=>{l({mode:ee})},[]),m=u.useCallback(ee=>{l({tool:ee})},[]),h=u.useCallback((ee="Untitled")=>{var ne;const ge=Ht(ee,"floor-plan");l({document:ge,activeFloorId:((ne=ge.floors[0])==null?void 0:ne.id)??null}),a==null||a(ge)},[a]),v=u.useCallback(ee=>{var ge;l({document:ee,activeFloorId:((ge=ee.floors[0])==null?void 0:ge.id)??null}),a==null||a(ee)},[a]),x=u.useCallback(ee=>{l({viewport:{...r.viewport,zoom:Math.max(.1,Math.min(10,r.viewport.zoom*(1+ee*.1)))}})},[r.viewport]),p=u.useCallback(ee=>{l({viewport:{...r.viewport,pan:{x:r.viewport.pan.x+ee.x,y:r.viewport.pan.y+ee.y}}})},[r.viewport]),j=u.useCallback(()=>{l({viewport:{...r.viewport,zoom:1,pan:{x:0,y:0}}})},[r.viewport]),g=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]),y=u.useCallback(ee=>{l({viewport:{...r.viewport,gridSize:ee}})},[r.viewport]),L=u.useCallback((ee,ge)=>{l({layers:r.layers.map(ne=>ne.type===ee?{...ne,visible:ge}:ne)})},[r.layers]),_=u.useCallback((ee,ge)=>{l({layers:r.layers.map(ne=>ne.type===ee?{...ne,locked:ge}:ne)})},[r.layers]),C=u.useCallback(ee=>{l({selection:{objectIds:ee,bounds:null,locked:!1}})},[]),d=u.useCallback(()=>{l({selection:{objectIds:[],bounds:null,locked:!1}})},[]),w=u.useCallback(()=>{},[]),f=u.useCallback(()=>{},[]),q=r.history.past.length>0,T=r.history.future.length>0,M=u.useCallback(()=>{},[]),W=u.useCallback(ee=>{},[]),te=u.useCallback(()=>{},[]);return{state:r,setMode:b,setTool:m,newDocument:h,loadDocument:v,zoom:x,pan:p,resetView:j,toggleGrid:g,toggleSnap:I,setGridSize:y,setLayerVisible:L,setLayerLocked:_,select:C,clearSelection:d,undo:w,redo:f,canUndo:q,canRedo:T,copy:M,paste:W,cut:te}}function am(t={}){const{gridSize:n=20,enabled:s=!0,snapModes:o=["grid","endpoint","midpoint"],objects:i=[],threshold:a=10}=t,c=u.useMemo(()=>({...Ds,cellSize:n,snapModes:o,snapThreshold:a}),[n,o,a]),r=u.useMemo(()=>i.map((x,p)=>({id:`obj-${p}`,bounds:x})),[i]),l=u.useCallback(x=>s?Wt(x,c):x,[s,c]),b=u.useCallback(x=>s?Rs(x,n):x,[s,n]),m=u.useCallback(x=>{if(!s||r.length===0)return[];const p={x:x.x,y:x.y,width:0,height:0};return jn(p,r,a)},[s,r,a]),h=u.useCallback(x=>{if(!s)return{point:x,snapped:!1,guides:[]};const p=Vs(x,r,c);return{point:p.position,snapped:p.snapped,guides:p.guides??[]}},[s,c,r]),v=u.useCallback((x,p)=>{const j=[];for(let g=0;g<=x;g+=n)j.push({x1:g,y1:0,x2:g,y2:p});for(let g=0;g<=p;g+=n)j.push({x1:0,y1:g,x2:x,y2:g});return j},[n]);return{snap:l,snap3D:b,getGuides:m,performAdvancedSnap:h,generateGridLines:v}}function im(t={}){const{unitSystem:n="metric",lengthUnit:s="m",areaUnit:o="m2",angleUnit:i="deg",scale:a=100}=t,[c,r]=u.useState(null),[l,b]=u.useState([]),m=u.useCallback(d=>d/a,[a]),h=u.useCallback(d=>{r(d),b([])},[]),v=u.useCallback((d,w=!1)=>{b(f=>[...f,{position:d,snapped:w}])},[]),x=u.useCallback(()=>{r(null),b([])},[]),p=u.useCallback(()=>{if(!c||l.length<2)return null;const d=l.map(w=>w.position);if(c==="distance"&&l.length===2){const w=at(d[0],d[1]),f=m(w);return{type:"distance",value:f,formatted:pt(f,n).formatted,points:d}}if(c==="angle"&&l.length===3){const w=At(d[0],d[1],d[2]);return{type:"angle",value:w,formatted:Dt(w,i).formatted,points:d}}if(c==="area"&&l.length>=3){const f=Bt(d)/(a*a);return{type:"area",value:f,formatted:Rt(f,n).formatted,points:d}}return null},[c,l,a,n,i,m]),j=l.length>=2&&c==="distance"?pt(m(at(l[0].position,l[l.length-1].position)),n).formatted:null,g=l.length>=3&&c==="angle"?Dt(At(l[0].position,l[1].position,l[2].position),i).formatted:null,I=l.length>=3&&c==="area"?Rt(Bt(l.map(d=>d.position))/(a*a),n).formatted:null,y=u.useCallback((d,w)=>{const f=at(d,w),q=m(f);return{value:q,formatted:pt(q,n).formatted}},[m,n]),L=u.useCallback((d,w,f)=>{const q=At(d,w,f);return{value:q,formatted:Dt(q,i).formatted}},[i]),_=u.useCallback(d=>{const f=Bt(d)/(a*a);return{value:f,formatted:Rt(f,n).formatted}},[a,n]),C=u.useCallback(d=>{const w=Zs(d),f=m(w);return{value:f,formatted:pt(f,n).formatted}},[m,n]);return{startMeasurement:h,addPoint:v,clearMeasurement:x,finishMeasurement:p,measurementType:c,points:l,liveDistance:j,liveAngle:g,liveArea:I,getDistance:y,getAngle:L,getArea:_,getLength:C}}const rm="_root_15owo_3",cm="_dark_15owo_25",lm="_header_15owo_37",dm="_buildingInfo_15owo_51",um="_buildingName_15owo_59",mm="_buildingAddress_15owo_81",pm="_modeSelector_15owo_95",hm="_modeBtn_15owo_107",gm="_modeBtnActive_15owo_145",_m="_weather_15owo_159",fm="_weatherTemp_15owo_173",ym="_weatherDesc_15owo_193",bm="_statsRow_15owo_205",xm="_statsCard_15owo_217",vm="_statsHeader_15owo_247",jm="_statsIcon_15owo_261",Nm="_statsLabel_15owo_269",wm="_statsValue_15owo_283",Im="_statsSub_15owo_305",km="_zoneGrid_15owo_319",Sm="_zoneCard_15owo_333",Cm="_zoneOccupied_15owo_381",Tm="_zoneCardHeader_15owo_389",Lm="_zoneCardIcon_15owo_403",$m="_zoneCardTitles_15owo_411",zm="_zoneCardName_15owo_421",Pm="_zoneCardArea_15owo_449",Mm="_occupancyBadge_15owo_459",Em="_occupancyBadgeOn_15owo_477",Om="_sensorRow_15owo_489",Am="_sensorChip_15owo_503",Bm="_sensorWarn_15owo_521",Dm="_deviceList_15owo_535",Rm="_deviceChip_15owo_547",qm="_deviceChipOn_15owo_585",Fm="_deviceChipName_15owo_597",Gm="_deviceChipVal_15owo_611",Vm="_moreBtn_15owo_621",Wm="_scenesBar_15owo_651",Hm="_sceneBarLabel_15owo_681",Um="_sceneList_15owo_699",Ym="_sceneBtn_15owo_711",Zm="_sceneBtnActive_15owo_741",Z={root:rm,dark:cm,header:lm,buildingInfo:dm,buildingName:um,buildingAddress:mm,modeSelector:pm,modeBtn:hm,modeBtnActive:gm,weather:_m,weatherTemp:fm,weatherDesc:ym,statsRow:bm,statsCard:xm,statsHeader:vm,statsIcon:jm,statsLabel:Nm,statsValue:wm,statsSub:Im,zoneGrid:km,zoneCard:Sm,zoneOccupied:Cm,zoneCardHeader:Tm,zoneCardIcon:Lm,zoneCardTitles:$m,zoneCardName:zm,zoneCardArea:Pm,occupancyBadge:Mm,occupancyBadgeOn:Em,sensorRow:Om,sensorChip:Am,sensorWarn:Bm,deviceList:Dm,deviceChip:Rm,deviceChipOn:qm,deviceChipName:Fm,deviceChipVal:Gm,moreBtn:Vm,scenesBar:Wm,sceneBarLabel:Hm,sceneList:Um,sceneBtn:Ym,sceneBtnActive:Zm},Xm={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 Km(t){return Xm[t]??"home"}function Jm(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 Ln=({zone:t,devices:n=[],expanded:s=!1,onExpand:o,onDeviceControl:i,onClick:a,theme:c="light",className:r,style:l})=>{const{t:b}=N.useNiceTranslation(),m=t.occupancy!=null&&t.occupancy>0,h=s?n:n.slice(0,4);return e.jsxs("div",{className:`${Z.zoneCard} ${c==="dark"?Z.dark:""} ${m?Z.zoneOccupied:""} ${r??""}`,style:l,onClick:a,children:[e.jsxs("div",{className:Z.zoneCardHeader,children:[e.jsx("span",{className:Z.zoneCardIcon,children:e.jsx(N.NiceIcon,{name:Km(t.type),size:18})}),e.jsxs("div",{className:Z.zoneCardTitles,children:[e.jsx("span",{className:Z.zoneCardName,children:t.name}),t.area!=null&&e.jsxs("span",{className:Z.zoneCardArea,children:[t.area," m²"]})]}),t.occupancy!=null&&e.jsxs("span",{className:`${Z.occupancyBadge} ${m?Z.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:Z.sensorRow,children:[t.temperature!=null&&e.jsxs("span",{className:Z.sensorChip,children:[e.jsx(N.NiceIcon,{name:"thermometer",size:14})," ",t.temperature.toFixed(1),"°C"]}),t.humidity!=null&&e.jsxs("span",{className:Z.sensorChip,children:[e.jsx(N.NiceIcon,{name:"droplet",size:14})," ",t.humidity,"%"]}),t.co2!=null&&e.jsxs("span",{className:`${Z.sensorChip} ${t.co2>1e3?Z.sensorWarn:""}`,children:["CO₂ ",t.co2]})]}),h.length>0&&e.jsxs("div",{className:Z.deviceList,children:[h.map(v=>{const x=v.state,p=(x==null?void 0:x.on)===!0||(x==null?void 0:x.locked)===!1;return e.jsxs("button",{className:`${Z.deviceChip} ${p?Z.deviceChipOn:""}`,onClick:j=>{j.stopPropagation(),i==null||i(v.id,{on:!p})},title:v.name,children:[e.jsx("span",{children:e.jsx(N.NiceIcon,{name:xn(v.type),size:14})}),e.jsx("span",{className:Z.deviceChipName,children:v.name}),e.jsx("span",{className:Z.deviceChipVal,children:Jm(b,v)})]},v.id)}),n.length>4&&e.jsx("button",{className:Z.moreBtn,"aria-label":s?b("buildings.showFewer","Show fewer devices"):b("buildings.showAll","Show all devices"),onClick:v=>{v.stopPropagation(),o==null||o()},children:s?e.jsx(N.NiceIcon,{name:"minus",size:12}):`+${n.length-4}`})]})]})},Gt={home:"Home",away:"Away",night:"Night",vacation:"Vacation",guest:"Guest",party:"Party",occupied:"Occupied",closed:"Closed",weekend:"Weekend",event:"Event",emergency:"Emergency",maintenance:"Maintenance"},pn={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"},Qm=({temperature:t,description:n})=>t!=null?e.jsxs("div",{className:Z.weather,children:[e.jsxs("span",{className:Z.weatherTemp,children:[t,"°C"]}),n&&e.jsx("span",{className:Z.weatherDesc,children:n})]}):null,bt=({label:t,value:n,sub:s,icon:o,accent:i})=>e.jsxs("div",{className:Z.statsCard,style:i?{borderTopColor:i}:void 0,children:[e.jsxs("div",{className:Z.statsHeader,children:[o&&e.jsx("span",{className:Z.statsIcon,children:e.jsx(N.NiceIcon,{name:o,size:16})}),e.jsx("span",{className:Z.statsLabel,children:t})]}),e.jsx("div",{className:Z.statsValue,children:n}),s&&e.jsx("div",{className:Z.statsSub,children:s})]}),ep=({building:t,state:n,onModeChange:s,onDeviceControl:o,onSceneActivate:i,onZoneClick:a,className:c,style:r,theme:l="light",weather:b})=>{var _,C,d;const{t:m}=N.useNiceTranslation(),[h,v]=u.useState(null);t.floors[0];const x=t.floors.flatMap(w=>w.zones??[]).filter(w=>w.type!=="hallway"&&w.type!=="corridor"),p=((_=n==null?void 0:n.activeAlerts)==null?void 0:_.length)??0,j=(C=n==null?void 0:n.energy)==null?void 0:C.currentPowerW,g=(d=n==null?void 0:n.energy)==null?void 0:d.todayKwh,I=n!=null&&n.occupancy?Object.values(n.occupancy).reduce((w,f)=>w+((f==null?void 0:f.occupancy)??0),0):null;t.floors.flatMap(w=>w.zones??[]).flatMap(w=>w.deviceIds??[]).slice(0,8);const y=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:`${Z.root} ${l==="dark"?Z.dark:""} ${c??""}`,style:r,children:[e.jsxs("div",{className:Z.header,children:[e.jsxs("div",{className:Z.buildingInfo,children:[e.jsx("h2",{className:Z.buildingName,children:t.name}),t.address&&e.jsx("p",{className:Z.buildingAddress,children:t.address})]}),e.jsx("div",{className:Z.modeSelector,children:y.map(w=>e.jsxs("button",{title:Gt[w],className:`${Z.modeBtn} ${L===w?Z.modeBtnActive:""}`,onClick:()=>s==null?void 0:s(w),children:[e.jsx(N.NiceIcon,{name:pn[w],size:16}),e.jsx("span",{children:Gt[w]})]},w))}),e.jsx(Qm,{temperature:b==null?void 0:b.temperature,description:b==null?void 0:b.description})]}),e.jsxs("div",{className:Z.statsRow,children:[j!=null&&e.jsx(bt,{icon:"zap",label:m("buildings.power","Power"),value:j>=1e3?`${(j/1e3).toFixed(2)} kW`:`${j} W`,sub:g!=null?`${m("buildings.today","Today")}: ${g.toFixed(2)} kWh`:void 0,accent:"var(--nice-warning, #f59e0b)"}),I!=null&&e.jsx(bt,{icon:"users",label:m("buildings.occupancy","Occupancy"),value:`${I}`,sub:`${x.length} ${m("buildings.zones","zones")}`,accent:"var(--nice-success, #22c55e)"}),p>0&&e.jsx(bt,{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(bt,{icon:pn[L],label:m("buildings.mode","Mode"),value:m(`buildings.mode.${L}`,Gt[L]),accent:"var(--nice-accent, #8b5cf6)"})]}),e.jsx("div",{className:Z.zoneGrid,children:x.map(w=>{const f=t.floors.flatMap(q=>(q.zones??[]).find(T=>T.id===w.id)?t.devices??[]:[]).filter(q=>q.zoneId===w.id);return e.jsx(Ln,{zone:w,devices:f,expanded:h===w.id,onExpand:()=>v(h===w.id?null:w.id),onDeviceControl:o,onClick:()=>a==null?void 0:a(w.id),theme:l},w.id)})}),t.scenes&&t.scenes.length>0&&e.jsxs("div",{className:Z.scenesBar,children:[e.jsx("span",{className:Z.sceneBarLabel,children:m("buildings.scenes","Scenes")}),e.jsx("div",{className:Z.sceneList,children:t.scenes.map(w=>{var f;return e.jsxs("button",{className:`${Z.sceneBtn} ${(f=n==null?void 0:n.activeScenes)!=null&&f.includes(w.id)?Z.sceneBtnActive:""}`,onClick:()=>i==null?void 0:i(w.id),children:[e.jsx(N.NiceIcon,{name:w.icon??"video",size:14})," ",w.name]},w.id)})})]})]})},tp="_deviceControl_1leqb_3",np="_dark_1leqb_23",sp="_compact_1leqb_35",op="_offline_1leqb_43",ap="_offlineBanner_1leqb_51",ip="_toggleControl_1leqb_75",rp="_toggleLabel_1leqb_89",cp="_toggleBtn_1leqb_109",lp="_toggleOn_1leqb_135",dp="_blindControl_1leqb_149",up="_blindLabel_1leqb_159",mp="_blindActions_1leqb_173",pp="_blindBtn_1leqb_181",hp="_blindSlider_1leqb_205",gp="_blindPct_1leqb_213",_p="_lockControl_1leqb_227",fp="_lockLabel_1leqb_239",yp="_lockBtn_1leqb_253",bp="_lockLocked_1leqb_273",xp="_lockUnlocked_1leqb_281",vp="_cameraControl_1leqb_295",jp="_cameraLabel_1leqb_305",Np="_cameraSnapshot_1leqb_319",wp="_cameraPlaceholder_1leqb_331",Ip="_cameraStatus_1leqb_355",kp="_cameraDot_1leqb_369",Sp="_cameraOnline_1leqb_379",Cp="_cameraOffline_1leqb_385",Tp="_sensorControl_1leqb_395",Lp="_sensorLabel_1leqb_405",$p="_sensorValues_1leqb_419",zp="_sensorRow_1leqb_429",Pp="_sensorKey_1leqb_443",Mp="_sensorVal_1leqb_419",Ep="_thermostat_1leqb_467",Op="_thermostatTitle_1leqb_481",Ap="_thermostatDial_1leqb_503",Bp="_dialTempCurrent_1leqb_513",Dp="_dialTempLabel_1leqb_535",Rp="_dialTempTarget_1leqb_545",qp="_dialHumidity_1leqb_565",Fp="_thermostatAdjust_1leqb_575",Gp="_adjustBtn_1leqb_587",Vp="_adjustTemp_1leqb_633",Wp="_hvacModes_1leqb_657",Hp="_hvacModeBtn_1leqb_671",Up="_hvacModeBtnActive_1leqb_699",Yp="_hvacAction_1leqb_711",Zp="_hvacActionDot_1leqb_727",Xp="_lightControl_1leqb_741",Kp="_lightHeader_1leqb_753",Jp="_lightIcon_1leqb_765",Qp="_lightName_1leqb_773",eh="_lightToggle_1leqb_801",th="_lightToggleOn_1leqb_829",nh="_sliderRow_1leqb_841",sh="_sliderIcon_1leqb_855",oh="_slider_1leqb_841",ah="_sliderVal_1leqb_879",ih="_colorRow_1leqb_891",rh="_colorSwatch_1leqb_905",ch="_colorPicker_1leqb_921",lh="_colorPresets_1leqb_937",dh="_colorPreset_1leqb_937",uh="_lightOff_1leqb_963",A={deviceControl:tp,dark:np,compact:sp,offline:op,offlineBanner:ap,toggleControl:ip,toggleLabel:rp,toggleBtn:cp,toggleOn:lp,blindControl:dp,blindLabel:up,blindActions:mp,blindBtn:pp,blindSlider:hp,blindPct:gp,lockControl:_p,lockLabel:fp,lockBtn:yp,lockLocked:bp,lockUnlocked:xp,cameraControl:vp,cameraLabel:jp,cameraSnapshot:Np,cameraPlaceholder:wp,cameraStatus:Ip,cameraDot:kp,cameraOnline:Sp,cameraOffline:Cp,sensorControl:Tp,sensorLabel:Lp,sensorValues:$p,sensorRow:zp,sensorKey:Pp,sensorVal:Mp,thermostat:Ep,thermostatTitle:Op,thermostatDial:Ap,dialTempCurrent:Bp,dialTempLabel:Dp,dialTempTarget:Rp,dialHumidity:qp,thermostatAdjust:Fp,adjustBtn:Gp,adjustTemp:Vp,hvacModes:Wp,hvacModeBtn:Hp,hvacModeBtnActive:Up,hvacAction:Yp,hvacActionDot:Zp,lightControl:Xp,lightHeader:Kp,lightIcon:Jp,lightName:Qp,lightToggle:eh,lightToggleOn:th,sliderRow:nh,sliderIcon:sh,slider:oh,sliderVal:ah,colorRow:ih,colorSwatch:rh,colorPicker:ch,colorPresets:lh,colorPreset:dh,lightOff:uh};function hn(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 mh(t,n,s){return"#"+[t,n,s].map(o=>o.toString(16).padStart(2,"0")).join("")}const ph=["#ffffff","#fde68a","#fca5a5","#93c5fd","#86efac","#c4b5fd"];function gn(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 $n=({device:t,onControl:n,compact:s=!1,theme:o="light",className:i,style:a})=>{var L,_,C;const{t:c}=N.useNiceTranslation(),r=t.state,l=(r==null?void 0:r.on)??!1,b=(r==null?void 0:r.brightness)??100,m=(r==null?void 0:r.colorTemperature)??4e3,h=r==null?void 0:r.rgbColor,[v,x]=u.useState(!1),p=u.useCallback(d=>{n==null||n(t.id,d)},[t.id,n]),j=h?mh(h[0],h[1],h[2]):"#ffffff",g=((L=t.capabilities)==null?void 0:L.includes("dimming"))??b!==void 0,I=(_=t.capabilities)==null?void 0:_.includes("color_temperature"),y=((C=t.capabilities)==null?void 0:C.includes("color"))||t.type==="rgb_light";return e.jsxs("div",{className:`${A.lightControl} ${s?A.compact:""} ${o==="dark"?A.dark:""} ${i??""}`,style:a,children:[e.jsxs("div",{className:A.lightHeader,children:[e.jsx("span",{className:A.lightIcon,style:{opacity:l?1:.4},children:e.jsx(N.NiceIcon,{name:"lightbulb",size:16})}),e.jsx("span",{className:A.lightName,children:t.name}),e.jsx("button",{className:`${A.lightToggle} ${l?A.lightToggleOn:""}`,"aria-label":l?c("buildings.switchedOn","On"):c("buildings.switchedOff","Off"),onClick:()=>p({on:!l}),children:e.jsx(N.NiceIcon,{name:l?"check":"close",size:14})})]}),l&&e.jsxs(e.Fragment,{children:[g&&e.jsxs("div",{className:A.sliderRow,children:[e.jsx("span",{className:A.sliderIcon,children:e.jsx(N.NiceIcon,{name:"lightbulb",size:16})}),e.jsx("input",{type:"range",min:1,max:100,value:b,className:A.slider,style:{"--pct":`${b}%`},onChange:d=>p({brightness:+d.target.value})}),e.jsxs("span",{className:A.sliderVal,children:[b,"%"]})]}),I&&e.jsxs("div",{className:A.sliderRow,children:[e.jsx("span",{className:A.sliderIcon,children:e.jsx(N.NiceIcon,{name:"thermometer",size:16})}),e.jsx("input",{type:"range",min:2700,max:6500,step:100,value:m,className:A.slider,style:{background:`linear-gradient(to right, ${hn(2700)}, ${hn(6500)})`},onChange:d=>p({colorTemperature:+d.target.value})}),e.jsxs("span",{className:A.sliderVal,children:[Math.round(m/100)*100,"K"]})]}),y&&e.jsxs("div",{className:A.colorRow,children:[e.jsx("span",{className:A.sliderIcon,children:e.jsx(N.NiceIcon,{name:"palette",size:16})}),e.jsx("button",{className:A.colorSwatch,"aria-label":c("buildings.pickColor","Pick a color"),"aria-expanded":v,style:{background:j},onClick:()=>x(d=>!d)}),v&&e.jsx("input",{type:"color",value:j,className:A.colorPicker,onChange:d=>{const[w,f,q]=gn(d.target.value);p({rgbColor:[w,f,q]})}}),e.jsx("div",{className:A.colorPresets,children:ph.map(d=>e.jsx("button",{className:A.colorPreset,"aria-label":d,style:{background:d},onClick:()=>{const[w,f,q]=gn(d);p({rgbColor:[w,f,q]})}},d))})]})]}),!l&&!s&&e.jsx("div",{className:A.lightOff,children:c("buildings.switchedOff","Off")})]})},_n={heat:"Heating",cool:"Cooling",auto:"Auto",off:"Off",fan_only:"Fan",dry:"Dry"},hh={heat:"zap",cool:"thermometer",auto:"refresh",off:"stop",fan_only:"wifi",dry:"droplet"},gh={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)),b=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)},${b.toFixed(2)}`}const it=5,vt=35,Nt=-140,zn=140;function yn(t){return Nt+(t-it)/(vt-it)*(zn-Nt)}const Pn=({device:t,onControl:n,compact:s=!1,theme:o="light",className:i,style:a})=>{const{t:c}=N.useNiceTranslation(),r=t.state,l=(r==null?void 0:r.temperature)??20,b=(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",x=80,p=80,j=60,g=fn(x,p,j,Nt,zn),I=yn(Math.min(Math.max(l,it),vt)),y=yn(Math.min(Math.max(b,it),vt)),L=fn(x,p,j,Nt,Math.min(I,y)),_=gh[v]??"var(--nice-text-muted, #94a3b8)",C=u.useCallback(w=>{const f=Math.round((b+w)*2)/2;f>=it&&f<=vt&&(n==null||n(t.id,{targetTemperature:f}))},[b,t.id,n]),d=u.useCallback(w=>{n==null||n(t.id,{mode:w})},[t.id,n]);return e.jsxs("div",{className:`${A.thermostat} ${s?A.compact:""} ${o==="dark"?A.dark:""} ${i??""}`,style:a,children:[e.jsx("div",{className:A.thermostatTitle,children:t.name}),e.jsxs("svg",{width:160,height:160,className:A.thermostatDial,children:[e.jsx("path",{d:g,fill:"none",stroke:"var(--nice-border, #e2e8f0)",strokeWidth:8,strokeLinecap:"round"}),e.jsx("path",{d:L,fill:"none",stroke:_,strokeWidth:8,strokeLinecap:"round",opacity:.4}),e.jsx("circle",{cx:x+j*Math.cos((y-90)*(Math.PI/180)),cy:p+j*Math.sin((y-90)*(Math.PI/180)),r:7,fill:_,stroke:"var(--nice-bg, #fff)",strokeWidth:2}),e.jsxs("text",{x,y:p-6,textAnchor:"middle",className:A.dialTempCurrent,children:[l.toFixed(1),"°"]}),e.jsx("text",{x,y:p+14,textAnchor:"middle",className:A.dialTempLabel,children:c("buildings.currentTemp","now")}),e.jsxs("text",{x,y:p+32,textAnchor:"middle",className:A.dialTempTarget,children:[b.toFixed(1),"°"]}),m!=null&&e.jsxs("text",{x,y:p+48,textAnchor:"middle",className:A.dialHumidity,children:[m,"%"]})]}),e.jsxs("div",{className:A.thermostatAdjust,children:[e.jsx("button",{className:A.adjustBtn,"aria-label":c("buildings.lowerTarget","Lower the target temperature"),onClick:()=>C(-.5),children:e.jsx(N.NiceIcon,{name:"minus",size:16})}),e.jsxs("span",{className:A.adjustTemp,children:[b.toFixed(1)," °C"]}),e.jsx("button",{className:A.adjustBtn,"aria-label":c("buildings.raiseTarget","Raise the target temperature"),onClick:()=>C(.5),children:e.jsx(N.NiceIcon,{name:"plus",size:16})})]}),!s&&e.jsx("div",{className:A.hvacModes,children:["heat","cool","auto","fan_only","off"].map(w=>e.jsx("button",{title:_n[w],"aria-label":_n[w],className:`${A.hvacModeBtn} ${h===w?A.hvacModeBtnActive:""}`,onClick:()=>d(w),children:e.jsx(N.NiceIcon,{name:hh[w],size:16})},w))}),e.jsxs("div",{className:A.hvacAction,style:{color:_},children:[e.jsx("span",{className:A.hvacActionDot,style:{background:_}}),v]})]})},_h=({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:A.toggleControl,children:[e.jsx("span",{className:A.toggleLabel,children:t.name}),e.jsx("button",{className:`${A.toggleBtn} ${i?A.toggleOn:""}`,onClick:()=>n==null?void 0:n(t.id,{on:!i}),children:i?s("buildings.on","ON"):s("buildings.off","OFF")})]})},fh=({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:A.blindControl,children:[e.jsx("span",{className:A.blindLabel,children:t.name}),e.jsxs("div",{className:A.blindActions,children:[e.jsx("button",{className:A.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:A.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:A.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:A.blindSlider,onChange:a=>n==null?void 0:n(t.id,{position:+a.target.value})}),e.jsxs("span",{className:A.blindPct,children:[i,"%"]})]})},yh=({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:A.lockControl,children:[e.jsx("span",{className:A.lockLabel,children:t.name}),e.jsxs("button",{className:`${A.lockBtn} ${i?A.lockLocked:A.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")]})]})},bh=({device:t})=>{const{t:n}=N.useNiceTranslation(),s=t.state;return e.jsxs("div",{className:A.cameraControl,children:[e.jsx("span",{className:A.cameraLabel,children:t.name}),s!=null&&s.snapshotUrl?e.jsx("img",{src:s.snapshotUrl,alt:"snapshot",className:A.cameraSnapshot}):e.jsxs("div",{className:A.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:A.cameraStatus,children:[e.jsx("span",{className:`${A.cameraDot} ${t.status==="online"?A.cameraOnline:A.cameraOffline}`}),t.status]})]})},xh=({device:t})=>{const n=t.state;return e.jsxs("div",{className:A.sensorControl,children:[e.jsx("span",{className:A.sensorLabel,children:t.name}),e.jsx("div",{className:A.sensorValues,children:Object.entries(n??{}).map(([s,o])=>o!=null&&e.jsxs("div",{className:A.sensorRow,children:[e.jsx("span",{className:A.sensorKey,children:s}),e.jsx("span",{className:A.sensorVal,children:String(o)})]},s))})]})},vh=({device:t,onControl:n,compact:s=!1,className:o,style:i,theme:a="light"})=>{const{t:c}=N.useNiceTranslation(),r=t.type,l=["light","dimmer","rgb_light","led_strip"].includes(r)?e.jsx($n,{device:t,onControl:n,compact:s,theme:a}):["thermostat","air_conditioner","heat_pump","floor_heating"].includes(r)?e.jsx(Pn,{device:t,onControl:n,compact:s,theme:a}):["blind","shutter","curtain","awning","garage_door"].includes(r)?e.jsx(fh,{device:t,onControl:n}):["lock","door"].includes(r)?e.jsx(yh,{device:t,onControl:n}):["camera","doorbell"].includes(r)?e.jsx(bh,{device:t}):r.endsWith("_sensor")||["motion_sensor","smoke_detector","water_leak_sensor","alarm"].includes(r)?e.jsx(xh,{device:t}):e.jsx(_h,{device:t,onControl:n});return e.jsxs("div",{className:`${A.deviceControl} ${a==="dark"?A.dark:""} ${s?A.compact:""} ${t.status==="offline"?A.offline:""} ${o??""}`,style:i,children:[l,t.status==="offline"&&e.jsx("div",{className:A.offlineBanner,children:c("buildings.offline","Offline")})]})},jh="_root_ft98s_3",Nh="_shell_ft98s_29",wh="_dark_ft98s_37",Ih="_listPanel_ft98s_51",kh="_listHeader_ft98s_79",Sh="_listTitle_ft98s_103",Ch="_addBtn_ft98s_121",Th="_list_ft98s_51",Lh="_listItem_ft98s_159",$h="_listItemActive_ft98s_199",zh="_listItemName_ft98s_213",Ph="_listItemMeta_ft98s_241",Mh="_enableToggle_ft98s_255",Eh="_enableOn_ft98s_273",Oh="_detailPanel_ft98s_283",Ah="_detailHeader_ft98s_295",Bh="_nameInput_ft98s_309",Dh="_deleteBtn_ft98s_343",Rh="_section_ft98s_373",qh="_rules_ft98s_383",Fh="_sectionHeader_ft98s_397",Gh="_sectionTitle_ft98s_411",Vh="_sectionAddBtn_ft98s_427",Wh="_ruleBlock_ft98s_457",Hh="_ruleBlockHeader_ft98s_483",Uh="_typeSelect_ft98s_497",Yh="_removeBtn_ft98s_529",Zh="_ruleFields_ft98s_567",Xh="_input_ft98s_603",Kh="_textarea_ft98s_635",Jh="_dayPicker_ft98s_671",Qh="_dayBtn_ft98s_683",eg="_dayBtnActive_ft98s_703",tg="_noSelection_ft98s_717",ng="_emptyHint_ft98s_719",O={root:jh,shell:Nh,dark:wh,listPanel:Ih,listHeader:kh,listTitle:Sh,addBtn:Ch,list:Th,listItem:Lh,listItemActive:$h,listItemName:zh,listItemMeta:Ph,enableToggle:Mh,enableOn:Eh,detailPanel:Oh,detailHeader:Ah,nameInput:Bh,deleteBtn:Dh,section:Rh,rules:qh,sectionHeader:Fh,sectionTitle:Gh,sectionAddBtn:Vh,ruleBlock:Wh,ruleBlockHeader:Hh,typeSelect:Uh,removeBtn:Yh,ruleFields:Zh,input:Xh,textarea:Kh,dayPicker:Jh,dayBtn:Qh,dayBtnActive:eg,noSelection:tg,emptyHint:ng},sg=[{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"}],be=(t,n,s="")=>{const o=t[n];return typeof o=="string"?o:s},jt=(t,n,s=0)=>{const o=t[n];return typeof o=="number"?o:s},wt=["mon","tue","wed","thu","fri","sat","sun"],og=t=>{const n=t.days;return Array.isArray(n)?n.map(s=>typeof s=="number"?wt[s]:String(s)):[...wt.slice(0,5)]},Ge={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³"}},ag=t=>t in Ge,Vt=t=>{const n=be(t,"sensorType",be(t,"attribute"));return ag(n)?n:"temperature"},ig=(t,n)=>{const s=t[n];return s&&typeof s=="object"?s:{}},rg=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))))},bn=[["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"]],cg=[["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"]],lg=["on","brightness","temperature","targetTemperature","locked","position","state"],dg=["home","away","night","vacation","guest","party","occupied","closed","weekend","event","emergency","maintenance"],ug=t=>{switch(t){case"sensor_threshold":return{type:t,deviceId:"",sensorType:"temperature",unit:Ge.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}}},mg=({trigger:t,devices:n,scenes:s,onChange:o,onRemove:i})=>{const{t:a,lang:c}=N.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(ug(l.target.value)),children:[bn.map(([l,b,m])=>e.jsx("option",{value:l,children:a(b,m)},l)),!bn.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(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:be(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:rg(c).map((l,b)=>{const m=og(t),h=wt[b],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(x=>x!==h):wt.filter(x=>x===h||m.includes(x))}),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:jt(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:be(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:be(t,"attribute","on"),onChange:l=>r({attribute:l.target.value})}),e.jsx("datalist",{id:"nice-automation-attributes",children:lg.map(l=>e.jsx("option",{value:l},l))})]}),e.jsxs("label",{children:[a("buildings.field.operator","Operator"),e.jsx("select",{className:O.input,value:be(t,"operator","changed"),onChange:l=>r({operator:l.target.value,value:l.target.value==="changed"?void 0:be(t,"value","")}),children:cg.map(([l,b,m])=>e.jsx("option",{value:l,children:a(b,m)},l))})]}),be(t,"operator","changed")!=="changed"&&e.jsxs("label",{children:[a("buildings.field.value","Value"),e.jsx("input",{className:O.input,value:be(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:Vt(t),onChange:l=>{const b=l.target.value;r({sensorType:b,unit:Ge[b].unit,attribute:void 0})},children:Object.keys(Ge).map(l=>e.jsx("option",{value:l,children:a(`buildings.sensor.${l}`,Ge[l].name)},l))})]}),e.jsxs("label",{children:[a("buildings.field.operator","Operator"),e.jsxs("select",{className:O.input,value:be(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"),Ge[Vt(t)].unit&&` (${Ge[Vt(t)].unit})`,e.jsx("input",{type:"number",className:O.input,value:jt(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:be(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:be(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:jt(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:be(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:be(t,"mode","home"),onChange:l=>r({mode:l.target.value}),children:dg.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.")})})]})},pg=({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:be(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(ig(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:be(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:be(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:be(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:jt(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:be(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:be(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")})]})]})]})]})},hg=({automations:t,defaultAutomations:n,devices:s=[],scenes:o=[],onAutomationsChange:i,onDelete:a,onToggle:c,readOnly:r=!1,className:l,style:b,theme:m="light",tutorial:h})=>{var q;const{t:v}=N.useNiceTranslation(),[x,p]=N.useControllableState({value:t,defaultValue:n,fallbackValue:[],onChange:i,componentName:"NiceAutomationEditor"}),[j,g]=u.useState(null),I=j!==null&&x.some(T=>T.id===j)?j:((q=x[0])==null?void 0:q.id)??null,y=x.find(T=>T.id===I)??null,L=u.useCallback(T=>{y&&p(x.map(M=>M.id===y.id?{...M,...T}:M))},[y,x,p]),_=u.useCallback(()=>{const T={id:`auto-${Date.now()}`,name:"New automation",enabled:!0,triggers:[],conditions:[],actions:[]};p([...x,T]),g(T.id)},[x,p]),C=u.useCallback(T=>{var M;p(x.filter(W=>W.id!==T)),I===T&&g(((M=x.find(W=>W.id!==T))==null?void 0:M.id)??null),a==null||a(T)},[x,I,p,a]),d=u.useCallback((T,M)=>{p(x.map(W=>W.id===T?{...W,enabled:M}:W)),c==null||c(T,M)},[x,p,c]),w=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:_,children:[e.jsx(N.NiceIcon,{name:"plus",size:12})," ",v("buildings.add","Add")]})]}),e.jsxs("div",{className:O.list,children:[x.map(T=>e.jsxs("div",{className:`${O.listItem} ${I===T.id?O.listItemActive:""}`,onClick:()=>g(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:M=>{M.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(N.NiceIcon,{name:T.enabled?"check":"close",size:14})})]},T.id)),x.length===0&&e.jsx("div",{className:O.emptyHint,children:v("buildings.noAutomations","No automations")})]})]}),f=e.jsx("div",{className:O.detailPanel,children:y?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:O.detailHeader,children:[e.jsx("input",{className:O.nameInput,value:y.name,onChange:T=>L({name:T.target.value}),readOnly:r}),!r&&e.jsx("button",{className:O.deleteBtn,onClick:()=>C(y.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:()=>L({triggers:[...y.triggers,{type:"time"}]}),children:[e.jsx(N.NiceIcon,{name:"plus",size:12})," ",v("buildings.add","Add")]})]}),y.triggers.map((T,M)=>e.jsx(mg,{trigger:T,devices:s,scenes:o,onChange:W=>L({triggers:y.triggers.map((te,ue)=>ue===M?W:te)}),onRemove:()=>L({triggers:y.triggers.filter((W,te)=>te!==M)})},M)),y.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:()=>L({actions:[...y.actions,{type:"device_control"}]}),children:[e.jsx(N.NiceIcon,{name:"plus",size:12})," ",v("buildings.add","Add")]})]}),y.actions.map((T,M)=>e.jsx(pg,{action:T,devices:s,scenes:o,onChange:W=>L({actions:y.actions.map((te,ue)=>ue===M?W:te)}),onRemove:()=>L({actions:y.actions.filter((W,te)=>te!==M)})},M)),y.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",...b},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:e.jsx(N.NiceTutorialButton,{steps:N.resolveTutorial(h,sg)})}),e.jsx(N.NiceAppShell,{flush:!0,className:O.shell,sidebar:w,children:f})]})},gg="_root_ucyos_3",_g="_shell_ucyos_29",fg="_dark_ucyos_37",yg="_gridPanel_ucyos_51",bg="_gridHeader_ucyos_79",xg="_gridTitle_ucyos_103",vg="_addBtn_ucyos_119",jg="_sceneGrid_ucyos_147",Ng="_sceneCard_ucyos_165",wg="_sceneCardActive_ucyos_193",Ig="_sceneCardSelected_ucyos_199",kg="_sceneCardIcon_ucyos_207",Sg="_sceneCardName_ucyos_217",Cg="_sceneCardDevices_ucyos_235",Tg="_activeBadge_ucyos_253",Lg="_activateBtn_ucyos_263",$g="_emptyGrid_ucyos_307",zg="_detailPanel_ucyos_325",Pg="_metaRow_ucyos_343",Mg="_iconPicker_ucyos_355",Eg="_currentIcon_ucyos_363",Og="_iconGrid_ucyos_381",Ag="_iconOpt_ucyos_397",Bg="_iconOptActive_ucyos_423",Dg="_metaFields_ucyos_433",Rg="_nameInput_ucyos_447",qg="_descInput_ucyos_481",Fg="_colorPicker_ucyos_517",Gg="_colorOpt_ucyos_527",Vg="_colorOptActive_ucyos_543",Wg="_targetsSection_ucyos_553",Hg="_targetsSectionHeader_ucyos_575",Ug="_addTargetBtn_ucyos_597",Yg="_targetRow_ucyos_625",Zg="_targetSelect_ucyos_655",Xg="_targetState_ucyos_687",Kg="_targetField_ucyos_701",Jg="_tempInput_ucyos_727",Qg="_removeTargetBtn_ucyos_745",e_="_noTargets_ucyos_785",t_="_detailActions_ucyos_805",n_="_activateFullBtn_ucyos_819",s_="_deleteBtn_ucyos_851",Y={root:gg,shell:_g,dark:fg,gridPanel:yg,gridHeader:bg,gridTitle:xg,addBtn:vg,sceneGrid:jg,sceneCard:Ng,sceneCardActive:wg,sceneCardSelected:Ig,sceneCardIcon:kg,sceneCardName:Sg,sceneCardDevices:Cg,activeBadge:Tg,activateBtn:Lg,emptyGrid:$g,detailPanel:zg,metaRow:Pg,iconPicker:Mg,currentIcon:Eg,iconGrid:Og,iconOpt:Ag,iconOptActive:Bg,metaFields:Dg,nameInput:Rg,descInput:qg,colorPicker:Fg,colorOpt:Gg,colorOptActive:Vg,targetsSection:Wg,targetsSectionHeader:Hg,addTargetBtn:Ug,targetRow:Yg,targetSelect:Zg,targetState:Xg,targetField:Kg,tempInput:Jg,removeTargetBtn:Qg,noTargets:e_,detailActions:t_,activateFullBtn:n_,deleteBtn:s_},o_=[{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"}],Je=t=>t&&typeof t=="object"?t:{},a_=(t,n,s=!1)=>{const o=Je(t)[n];return typeof o=="boolean"?o:s},ot=(t,n,s=0)=>{const o=Je(t)[n];return typeof o=="number"?o:s},i_=["video","eye-off","lightbulb","gamepad","briefcase","utensils","music","droplet","rocket","home","thermometer","lock","star","gift","heart","settings"],r_=["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)"],c_=({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:Y.targetRow,children:[e.jsxs("select",{className:Y.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:Y.targetState,children:[e.jsxs("label",{className:Y.targetField,children:[e.jsx("span",{children:i("buildings.onOff","On/Off")}),e.jsx("input",{type:"checkbox",checked:a_(t.state,"on",!1),onChange:c=>s({...t,state:{...Je(t.state),on:c.target.checked}})})]}),(a.type==="dimmer"||a.type==="light"||a.type==="rgb_light"||a.type==="led_strip")&&e.jsxs("label",{className:Y.targetField,children:[e.jsx("span",{children:i("buildings.brightness","Brightness")}),e.jsx("input",{type:"range",min:0,max:100,value:ot(t.state,"brightness",100),onChange:c=>s({...t,state:{...Je(t.state),brightness:+c.target.value}})}),e.jsxs("span",{children:[ot(t.state,"brightness",100),"%"]})]}),(a.type==="blind"||a.type==="shutter")&&e.jsxs("label",{className:Y.targetField,children:[e.jsx("span",{children:i("buildings.position","Position")}),e.jsx("input",{type:"range",min:0,max:100,value:ot(t.state,"position",100),onChange:c=>s({...t,state:{...Je(t.state),position:+c.target.value}})}),e.jsxs("span",{children:[ot(t.state,"position",100),"%"]})]}),(a.type==="thermostat"||a.type==="air_conditioner")&&e.jsxs("label",{className:Y.targetField,children:[e.jsx("span",{children:i("buildings.temp","Temp.")}),e.jsx("input",{type:"number",className:Y.tempInput,min:10,max:30,step:.5,value:ot(t.state,"targetTemperature",20),onChange:c=>s({...t,state:{...Je(t.state),targetTemperature:+c.target.value}})}),e.jsx("span",{children:"°C"})]})]}),e.jsx("button",{className:Y.removeTargetBtn,onClick:o,title:i("buildings.remove","Remove"),"aria-label":i("buildings.remove","Remove"),children:e.jsx(N.NiceIcon,{name:"close",size:14})})]})},l_=({scenes:t,defaultScenes:n,devices:s=[],activeSceneIds:o=[],onScenesChange:i,onActivate:a,onDelete:c,readOnly:r=!1,className:l,style:b,theme:m="light",tutorial:h})=>{var q;const{t:v}=N.useNiceTranslation(),[x,p]=N.useControllableState({value:t,defaultValue:n,fallbackValue:[],onChange:i,componentName:"NiceSceneEditor"}),[j,g]=u.useState(null),I=j!==null&&x.some(T=>T.id===j)?j:((q=x[0])==null?void 0:q.id)??null,y=x.find(T=>T.id===I)??null,L=u.useCallback(T=>{y&&p(x.map(M=>M.id===y.id?{...M,...T}:M))},[y,x,p]),_=u.useCallback(()=>{const T={id:`scene-${Date.now()}`,name:"New scene",deviceTargets:[],icon:"video",color:"var(--nice-primary-bg, #e0f2fe)"};p([...x,T]),g(T.id)},[x,p]),C=u.useCallback(T=>{var M;p(x.filter(W=>W.id!==T)),I===T&&g(((M=x.find(W=>W.id!==T))==null?void 0:M.id)??null),c==null||c(T)},[x,I,p,c]),d=()=>{if(!y)return;const T={deviceId:"",state:{on:!0},transitionMs:1e3};L({deviceTargets:[...y.deviceTargets,T]})},w=e.jsxs("div",{className:Y.gridPanel,children:[e.jsxs("div",{className:Y.gridHeader,children:[e.jsx("span",{className:Y.gridTitle,children:v("buildings.scenes","Scenes")}),!r&&e.jsxs("button",{className:Y.addBtn,onClick:_,children:[e.jsx(N.NiceIcon,{name:"plus",size:12})," ",v("buildings.new","New")]})]}),e.jsxs("div",{className:Y.sceneGrid,children:[x.map(T=>{const M=o.includes(T.id),W=I===T.id;return e.jsxs("div",{className:`${Y.sceneCard} ${M?Y.sceneCardActive:""} ${W?Y.sceneCardSelected:""}`,style:{background:T.color??"var(--nice-bg-secondary, #f8fafc)"},onClick:()=>g(T.id),children:[e.jsx("div",{className:Y.sceneCardIcon,children:e.jsx(N.NiceIcon,{name:T.icon??"video",size:20})}),e.jsx("div",{className:Y.sceneCardName,children:T.name}),e.jsxs("div",{className:Y.sceneCardDevices,children:[T.deviceTargets.length," ",v("buildings.devices","devices"),M&&e.jsx("span",{className:Y.activeBadge,children:e.jsx(N.NiceIcon,{name:"check",size:12})})]}),e.jsx("button",{className:Y.activateBtn,"aria-label":v("buildings.activate","Activate"),onClick:te=>{te.stopPropagation(),a==null||a(T.id)},children:e.jsx(N.NiceIcon,{name:"play",size:14})})]},T.id)}),x.length===0&&e.jsx("div",{className:Y.emptyGrid,children:v("buildings.noScenes","No scenes yet. Add the first one!")})]})]}),f=y?e.jsxs("div",{className:Y.detailPanel,children:[e.jsxs("div",{className:Y.metaRow,children:[e.jsxs("div",{className:Y.iconPicker,children:[e.jsx("span",{className:Y.currentIcon,children:e.jsx(N.NiceIcon,{name:y.icon??"video",size:20})}),e.jsx("div",{className:Y.iconGrid,children:i_.map(T=>e.jsx("button",{className:`${Y.iconOpt} ${y.icon===T?Y.iconOptActive:""}`,"aria-label":T,onClick:()=>L({icon:T}),children:e.jsx(N.NiceIcon,{name:T,size:16})},T))})]}),e.jsxs("div",{className:Y.metaFields,children:[e.jsx("input",{className:Y.nameInput,value:y.name,readOnly:r,onChange:T=>L({name:T.target.value}),placeholder:v("buildings.sceneName","Scene name")}),e.jsx("textarea",{className:Y.descInput,value:y.description??"",readOnly:r,onChange:T=>L({description:T.target.value}),placeholder:v("buildings.descriptionOptional","Description (optional)"),rows:2})]})]}),!r&&e.jsx("div",{className:Y.colorPicker,children:r_.map(T=>e.jsx("button",{className:`${Y.colorOpt} ${y.color===T?Y.colorOptActive:""}`,style:{background:T},onClick:()=>L({color:T})},T))}),e.jsxs("fieldset",{className:Y.targetsSection,disabled:r,children:[e.jsxs("div",{className:Y.targetsSectionHeader,children:[e.jsx("span",{children:v("buildings.devicesInScene","Devices in this scene")}),!r&&e.jsxs("button",{className:Y.addTargetBtn,onClick:d,children:[e.jsx(N.NiceIcon,{name:"plus",size:12})," ",v("buildings.add","Add")]})]}),y.deviceTargets.map((T,M)=>e.jsx(c_,{target:T,devices:s,onChange:W=>L({deviceTargets:y.deviceTargets.map((te,ue)=>ue===M?W:te)}),onRemove:()=>L({deviceTargets:y.deviceTargets.filter((W,te)=>te!==M)})},M)),y.deviceTargets.length===0&&e.jsx("div",{className:Y.noTargets,children:v("buildings.sceneHint","Add the devices this scene should control.")})]}),e.jsxs("div",{className:Y.detailActions,children:[e.jsxs("button",{className:Y.activateFullBtn,onClick:()=>a==null?void 0:a(y.id),children:[e.jsx(N.NiceIcon,{name:"play",size:14})," ",v("buildings.activateScene","Activate scene")]}),!r&&e.jsx("button",{className:Y.deleteBtn,onClick:()=>C(y.id),children:v("buildings.remove","Remove")})]})]}):void 0;return e.jsxs("div",{className:`nice-scene-editor ${Y.root} ${m==="dark"?Y.dark:""} ${l??""}`,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(h,o_)})}),e.jsx(N.NiceAppShell,{flush:!0,className:Y.shell,sidebar:w,children:f})]})};exports.LayerPanel=kn;exports.Minimap=Sn;exports.NiceAutomationEditor=hg;exports.NiceBuildingDashboard=ep;exports.NiceDeviceControl=vh;exports.NiceFloorPlanEditor=Bs;exports.NiceLightControl=$n;exports.NiceSceneEditor=l_;exports.NiceSpatialEditor=xd;exports.NiceSpatialViewer=sm;exports.NiceThermostatControl=Pn;exports.NiceZoneCard=Ln;exports.ObjectLibrary=Cn;exports.PropertiesPanel=Tn;exports.useMeasurement=im;exports.useSnapToGrid=am;exports.useSpatialEditor=om;
|