@nice2dev/ui-buildings 1.1.7 → 1.1.10
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 +152 -0
- package/dist/index.cjs +37 -37
- package/dist/index.d.ts +17 -10
- package/dist/index.mjs +4400 -4137
- package/dist/ui-buildings.css +1 -1
- package/package.json +5 -4
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";var Ms=Object.defineProperty;var Bs=(t,s,n)=>s in t?Ms(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var ct=(t,s,n)=>Bs(t,typeof s!="symbol"?s+"":s,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),z=require("@nice2dev/ui"),u=require("react"),Ps="_root_1qthv_1",Es="_shell_1qthv_27",Os="_dark_1qthv_35",As="_topBar_1qthv_49",Ds="_floorTabs_1qthv_79",Rs="_floorTab_1qthv_79",Fs="_floorTabActive_1qthv_119",Ws="_overlayControls_1qthv_131",Gs="_overlayBtn_1qthv_143",qs="_overlayBtnActive_1qthv_179",Vs="_zoomBar_1qthv_191",Us="_toolPalette_1qthv_245",Hs="_toolBtn_1qthv_275",Ys="_toolBtnActive_1qthv_311",Zs="_canvasWrapper_1qthv_325",Xs="_canvas_1qthv_325",Ks="_cur_select_1qthv_365",Js="_cur_drawzone_1qthv_371",Qs="_cur_drawwall_1qthv_377",en="_cur_placedevice_1qthv_383",tn="_cur_placedoor_1qthv_389",sn="_cur_placewindow_1qthv_395",nn="_cur_pan_1qthv_401",on="_cur_erase_1qthv_407",an="_cur_measure_1qthv_413",rn="_cur_annotate_1qthv_419",cn="_gridLine_1qthv_429",ln="_zoneGroup_1qthv_447",dn="_zonePath_1qthv_455",un="_zoneLabel_1qthv_463",hn="_climateLabel_1qthv_485",mn="_occupancyLabel_1qthv_497",pn="_dimLabel_1qthv_509",_n="_deviceGroup_1qthv_521",fn="_devCircle_1qthv_529",gn="_devOnline_1qthv_541",yn="_devOffline_1qthv_547",xn="_devSelected_1qthv_553",bn="_propPanel_1qthv_565",vn="_propTitle_1qthv_593",jn="_propRow_1qthv_615",wn="_statusBar_1qthv_655",Nn="_emptyState_1qthv_687",te={root:Ps,shell:Es,dark:Os,topBar:As,floorTabs:Ds,floorTab:Rs,floorTabActive:Fs,overlayControls:Ws,overlayBtn:Gs,overlayBtnActive:qs,zoomBar:Vs,toolPalette:Us,toolBtn:Hs,toolBtnActive:Ys,canvasWrapper:Zs,canvas:Xs,cur_select:Ks,cur_drawzone:Js,cur_drawwall:Qs,cur_placedevice:en,cur_placedoor:tn,cur_placewindow:sn,cur_pan:nn,cur_erase:on,cur_measure:an,cur_annotate:rn,gridLine:cn,zoneGroup:ln,zonePath:dn,zoneLabel:un,climateLabel:hn,occupancyLabel:mn,dimLabel:pn,deviceGroup:_n,devCircle:fn,devOnline:gn,devOffline:yn,devSelected:xn,propPanel:bn,propTitle:vn,propRow:jn,statusBar:wn,emptyState:Nn},kn=[{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"}],In={living_room:"var(--nice-primary-bg, #dbeafe)",bedroom:"var(--nice-accent-bg, #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-bg, #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-bg, #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-bg, #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 Cn(t){return In[t]??"var(--nice-primary-bg, #f0f4ff)"}function qt(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 Vt(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 Sn(t,s,n){return n?{x:Math.round(t.x/s)*s,y:Math.round(t.y/s)*s}:t}function zn(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};default:return t}}const Ln=[{tool:"select",icon:"cursor",label:"Zaznaczenie"},{tool:"draw_zone",icon:"hexagon",label:"Rysuj strefę"},{tool:"draw_wall",icon:"line",label:"Rysuj ścianę"},{tool:"place_device",icon:"wifi",label:"Urządzenie"},{tool:"place_door",icon:"door",label:"Drzwi"},{tool:"place_window",icon:"window",label:"Okno"},{tool:"annotate",icon:"edit",label:"Adnotacja"},{tool:"measure",icon:"ruler",label:"Miarka"},{tool:"erase",icon:"trash",label:"Usuń"},{tool:"pan",icon:"move",label:"Przesuń"}],$n={light:"lightbulb",dimmer:"lightbulb",rgb_light:"lightbulb",led_strip:"lightbulb",thermostat:"thermometer",air_conditioner:"thermometer",fan:"wifi",heat_pump:"thermometer",lock:"lock",door:"door",window:"window",blind:"columns",camera:"camera",doorbell:"bell",alarm:"bell",motion_sensor:"eye",smoke_detector:"warning",temperature_sensor:"thermometer",humidity_sensor:"droplet",switch:"plug",outlet:"plug",speaker:"music",tv:"monitor",vacuum:"refresh",ev_charger:"zap",solar_panel:"zap",energy_meter:"zap",hub:"wifi",router:"wifi"},Tn=({floors:t,defaultFloors:s,devices:n=[],onFloorChange:o,onDeviceMove:a,readOnly:r=!1,initialFloorId:i,showDevices:l=!0,showDimensions:h=!1,showGrid:b=!0,showOccupancy:d=!1,showClimate:x=!0,className:v,style:y,theme:_="light",tutorial:f})=>{var Me,Be;const[p,C]=z.useControllableState({value:t,defaultValue:s,fallbackValue:[],onChange:o,componentName:"NiceFloorPlanEditor"}),L=u.useRef(null),I=u.useRef(!1),k=u.useRef({x:0,y:0}),[c,g]=u.useReducer(zn,{floorId:i??((Me=p[0])==null?void 0:Me.id)??"",tool:"select",selected:null,zoom:1,pan:{x:0,y:0},drawing:null,showGrid:b,showDim:h,showLabels:!0,showOccupancy:d,showClimate:x,snapGrid:!0,gridSize:20}),m=p.find(T=>T.id===c.floorId)??p[0],j=u.useCallback(T=>{var me;const U=(me=L.current)==null?void 0:me.getBoundingClientRect();return U?{x:(T.clientX-U.left-c.pan.x)/c.zoom,y:(T.clientY-U.top-c.pan.y)/c.zoom}:{x:0,y:0}},[c.pan,c.zoom]),E=u.useCallback(T=>{c.tool==="pan"&&(I.current=!0,k.current={x:T.clientX,y:T.clientY})},[c.tool]),F=u.useCallback(T=>{I.current&&(g({t:"PAN",v:{x:c.pan.x+T.clientX-k.current.x,y:c.pan.y+T.clientY-k.current.y}}),k.current={x:T.clientX,y:T.clientY})},[c.pan]),de=u.useCallback(()=>{I.current=!1},[]),ee=u.useCallback(T=>{if(c.tool==="draw_zone"){const U=Sn(j(T),c.gridSize,c.snapGrid);g({t:"DRAW_PT",v:U})}else c.tool==="select"&&g({t:"SELECT",v:null})},[c.tool,c.gridSize,c.snapGrid,j]),xe=u.useCallback(T=>{if(c.tool==="draw_zone"&&c.drawing&&c.drawing.length>=3&&m){const U={id:`zone-${Date.now()}`,name:"Nowa strefa",type:"other",floorId:m.id,polygon:[...c.drawing]};C(p.map(me=>me.id===m.id?{...m,zones:[...m.zones,U]}:me)),g({t:"DRAW_END"})}},[c.tool,c.drawing,m,p,C]),ue=u.useCallback(T=>{T.preventDefault(),g({t:"ZOOM",v:c.zoom*(T.deltaY>0?.9:1.1)})},[c.zoom]),ae=u.useCallback((T,U)=>{T.stopPropagation(),c.tool==="select"?g({t:"SELECT",v:{type:"zone",id:U.id}}):c.tool==="erase"&&!r&&m&&C(p.map(me=>me.id===m.id?{...m,zones:m.zones.filter(Le=>Le.id!==U.id)}:me))},[c.tool,r,m,p,C]);if(!m)return e.jsx("div",{className:te.emptyState,children:"Brak kondygnacji."});const X=((Be=c.selected)==null?void 0:Be.type)==="zone"?m.zones.find(T=>{var U;return T.id===((U=c.selected)==null?void 0:U.id)}):null,le=l?n.filter(T=>m.zones.some(U=>U.id===T.zoneId)||T.floorPlanPosition):[],ze=[{key:"grid",icon:"grid",active:c.showGrid},{key:"dim",icon:"ruler",active:c.showDim},{key:"labels",icon:"tag",active:c.showLabels},{key:"occupancy",icon:"users",active:c.showOccupancy},{key:"climate",icon:"thermometer",active:c.showClimate}],De=e.jsxs("div",{className:te.topBar,children:[e.jsx("div",{className:te.floorTabs,children:[...p].sort((T,U)=>T.level-U.level).map(T=>e.jsx("button",{className:`${te.floorTab} ${c.floorId===T.id?te.floorTabActive:""}`,onClick:()=>g({t:"FLOOR",v:T.id}),children:T.name},T.id))}),e.jsx("div",{className:te.overlayControls,children:ze.map(T=>e.jsx("button",{title:T.key,"aria-label":T.key,className:`${te.overlayBtn} ${T.active?te.overlayBtnActive:""}`,onClick:()=>g({t:"TOGGLE",v:T.key}),children:e.jsx(z.NiceIcon,{name:T.icon,size:16})},T.key))}),e.jsxs("div",{className:te.zoomBar,children:[e.jsx("button",{onClick:()=>g({t:"ZOOM",v:c.zoom*1.2}),children:"+"}),e.jsxs("span",{children:[Math.round(c.zoom*100),"%"]}),e.jsx("button",{onClick:()=>g({t:"ZOOM",v:c.zoom*.8}),children:"−"}),e.jsx("button",{title:"Resetuj widok","aria-label":"Resetuj widok",onClick:()=>{g({t:"ZOOM",v:1}),g({t:"PAN",v:{x:0,y:0}})},children:e.jsx(z.NiceIcon,{name:"refresh",size:16})})]})]}),Ce=r?void 0:e.jsx("div",{className:te.toolPalette,children:Ln.map(({tool:T,icon:U,label:me})=>e.jsx("button",{title:me,"aria-label":me,className:`${te.toolBtn} ${c.tool===T?te.toolBtnActive:""}`,onClick:()=>g({t:"TOOL",v:T}),children:e.jsx(z.NiceIcon,{name:U,size:18})},T))});return e.jsxs("div",{className:`nice-floor-plan-editor ${te.root} ${_==="dark"?te.dark:""} ${v??""}`,style:{position:"relative",...y},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:e.jsx(z.NiceTutorialButton,{steps:z.resolveTutorial(f,kn)})}),e.jsx(z.NiceAppShell,{flush:!0,className:te.shell,menubar:De,sidebar:Ce,rightSidebar:X?e.jsxs("div",{className:te.propPanel,children:[e.jsx("div",{className:te.propTitle,children:X.name}),e.jsxs("div",{className:te.propRow,children:[e.jsx("span",{children:"Typ"}),e.jsx("span",{children:X.type})]}),X.area!=null&&e.jsxs("div",{className:te.propRow,children:[e.jsx("span",{children:"Pow."}),e.jsxs("span",{children:[X.area," m²"]})]}),X.temperature!=null&&e.jsxs("div",{className:te.propRow,children:[e.jsx("span",{children:"Temp."}),e.jsxs("span",{children:[X.temperature.toFixed(1)," °C"]})]}),X.humidity!=null&&e.jsxs("div",{className:te.propRow,children:[e.jsx("span",{children:"Wilgotność"}),e.jsxs("span",{children:[X.humidity," %"]})]}),X.co2!=null&&e.jsxs("div",{className:te.propRow,children:[e.jsx("span",{children:"CO₂"}),e.jsxs("span",{children:[X.co2," ppm"]})]}),X.occupancy!=null&&e.jsxs("div",{className:te.propRow,children:[e.jsx("span",{children:"Obecność"}),e.jsxs("span",{children:[X.occupancy," os."]})]})]}):void 0,statusBar:e.jsxs("div",{className:te.statusBar,children:[c.tool==="draw_zone"?"Klikaj punkty, dwa kliknięcia by zamknąć strefę.":c.selected?`Zaznaczono: ${c.selected.type} #${c.selected.id}`:`${m.name} — ${m.zones.length} strefa(y)`,c.tool==="draw_zone"&&c.drawing&&` (${c.drawing.length} pkt)`]}),children:e.jsx("div",{className:te.canvasWrapper,children:e.jsxs("svg",{ref:L,className:`${te.canvas} ${te[`cur_${c.tool.replace("_","")}`]??""}`,onMouseDown:E,onMouseMove:F,onMouseUp:de,onClick:ee,onDoubleClick:xe,onWheel:ue,children:[m.backgroundImage&&e.jsx("image",{href:m.backgroundImage,x:c.pan.x,y:c.pan.y,width:m.width*c.zoom,height:m.height*c.zoom,preserveAspectRatio:"xMidYMid meet",opacity:.35}),e.jsxs("g",{transform:`translate(${c.pan.x},${c.pan.y}) scale(${c.zoom})`,children:[c.showGrid&&(()=>{const T=[];for(let U=0;U<=m.width;U+=c.gridSize)T.push(e.jsx("line",{x1:U,y1:0,x2:U,y2:m.height,className:te.gridLine},`v${U}`));for(let U=0;U<=m.height;U+=c.gridSize)T.push(e.jsx("line",{x1:0,y1:U,x2:m.width,y2:U,className:te.gridLine},`h${U}`));return e.jsx("g",{children:T})})(),m.zones.map(T=>{var Oe;const U=((Oe=c.selected)==null?void 0:Oe.id)===T.id,me=qt(T.polygon),Le=T.color??Cn(T.type);return e.jsxs("g",{className:te.zoneGroup,onClick:be=>ae(be,T),children:[e.jsx("path",{d:Vt(T.polygon),fill:Le,fillOpacity:T.opacity??.55,stroke:U?"var(--nice-primary-hover, #2563eb)":"var(--nice-text-muted, #94a3b8)",strokeWidth:U?2.5:1.5,className:te.zonePath}),c.showLabels&&e.jsx("text",{x:me.x,y:me.y,textAnchor:"middle",dominantBaseline:"middle",className:te.zoneLabel,children:T.name}),c.showClimate&&T.temperature!=null&&e.jsxs("text",{x:me.x,y:me.y+14,textAnchor:"middle",className:te.climateLabel,children:[T.temperature.toFixed(1),"°C"," ",T.humidity!=null?`· ${T.humidity}%`:""]}),c.showOccupancy&&T.occupancy!=null&&e.jsxs("text",{x:me.x,y:me.y+26,textAnchor:"middle",className:te.occupancyLabel,children:[T.occupancy," os."]}),c.showDim&&T.polygon.length>1&&T.polygon.map((be,Pe)=>{const ke=T.polygon[(Pe+1)%T.polygon.length],we=(be.x+ke.x)/2,je=(be.y+ke.y)/2,he=Math.sqrt((ke.x-be.x)**2+(ke.y-be.y)**2),ne=m.scale??0;return e.jsx("text",{x:we,y:je-4,textAnchor:"middle",className:te.dimLabel,children:ne>0?`${(he/ne).toFixed(1)}m`:`${he.toFixed(0)}px`},Pe)})]},T.id)}),le.map(T=>{var Oe;const U=m.zones.find(be=>be.id===T.zoneId),me=T.floorPlanPosition??(U?qt(U.polygon):null);if(!me)return null;const Le=((Oe=c.selected)==null?void 0:Oe.id)===T.id;return e.jsxs("g",{transform:`translate(${me.x},${me.y})`,className:te.deviceGroup,onClick:be=>{be.stopPropagation(),g({t:"SELECT",v:{type:"device",id:T.id}})},children:[e.jsx("circle",{r:14,className:`${te.devCircle} ${T.status==="online"?te.devOnline:te.devOffline} ${Le?te.devSelected:""}`}),e.jsx("g",{transform:"translate(-8,-8)",children:e.jsx(z.NiceIcon,{name:$n[T.type]??"monitor",size:16})})]},T.id)}),c.drawing&&c.drawing.length>0&&e.jsxs("g",{children:[e.jsx("path",{d:Vt(c.drawing,!1),fill:"none",stroke:"var(--nice-primary-hover, #2563eb)",strokeWidth:2,strokeDasharray:"6,3"}),c.drawing.map((T,U)=>e.jsx("circle",{cx:T.x,cy:T.y,r:4,fill:"var(--nice-primary-hover, #2563eb)"},U))]})]})]})})})]})},Mn={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 Ft(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 Bn(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 Pn(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 En(t,s,n){let o=null;for(const a of s){const r=Pn(a);for(const i of r){const l=tt(t,i);l<=n&&(!o||l<o.distance)&&(o={point:i,targetId:a.id,distance:l})}}return o}function tt(t,s){return Math.sqrt((s.x-t.x)**2+(s.y-t.y)**2)}function ps(t,s,n){const o=[],a={x:t.x+t.width/2,y:t.y+t.height/2};for(const r of s){const i={x:r.bounds.x+r.bounds.width/2,y:r.bounds.y+r.bounds.height/2};Math.abs(a.y-i.y)<=n&&o.push({type:"horizontal",start:{x:Math.min(t.x,r.bounds.x),y:i.y},end:{x:Math.max(t.x+t.width,r.bounds.x+r.bounds.width),y:i.y},distance:Math.abs(a.y-i.y),sourceObjectId:r.id}),Math.abs(a.x-i.x)<=n&&o.push({type:"vertical",start:{x:i.x,y:Math.min(t.y,r.bounds.y)},end:{x:i.x,y:Math.max(t.y+t.height,r.bounds.y+r.bounds.height)},distance:Math.abs(a.x-i.x),sourceObjectId:r.id});const l=[{dragged:t.y,other:r.bounds.y,axis:"horizontal"},{dragged:t.y+t.height,other:r.bounds.y+r.bounds.height,axis:"horizontal"},{dragged:t.x,other:r.bounds.x,axis:"vertical"},{dragged:t.x+t.width,other:r.bounds.x+r.bounds.width,axis:"vertical"}];for(const h of l)Math.abs(h.dragged-h.other)<=n&&(h.axis==="horizontal"?o.push({type:"horizontal",start:{x:Math.min(t.x,r.bounds.x),y:h.other},end:{x:Math.max(t.x+t.width,r.bounds.x+r.bounds.width),y:h.other},distance:Math.abs(h.dragged-h.other),sourceObjectId:r.id}):o.push({type:"vertical",start:{x:h.other,y:Math.min(t.y,r.bounds.y)},end:{x:h.other,y:Math.max(t.y+t.height,r.bounds.y+r.bounds.height)},distance:Math.abs(h.dragged-h.other),sourceObjectId:r.id}))}return On(o)}function On(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 An(t,s,n){const o={position:{...t},snapped:!1,snapMode:null,guides:[]},{snapModes:a,snapThreshold:r}=n;if(a.includes("endpoint")||a.includes("center")||a.includes("midpoint")){const i=En(t,s,r);if(i)return o.position=i.point,o.snapped=!0,o.snapMode="endpoint",o.targetObjectId=i.targetId,o}if(a.includes("grid")){const i=Ft(t,n);if(tt(t,i)<=r)return o.position=i,o.snapped=!0,o.snapMode="grid",o}return o}const Dn=[{id:"sh-light-bulb",name:"Smart Bulb",category:"smart-home",type:"light",icon:"💡",tags:["lighting","bulb"]},{id:"sh-light-dimmer",name:"Dimmer Switch",category:"smart-home",type:"light-dimmer",icon:"🔆",tags:["lighting","switch"]},{id:"sh-light-rgb",name:"RGB Light",category:"smart-home",type:"light-rgb",icon:"🌈",tags:["lighting","color"]},{id:"sh-light-strip",name:"LED Strip",category:"smart-home",type:"light-strip",icon:"💡",tags:["lighting","strip"]},{id:"sh-thermostat",name:"Thermostat",category:"smart-home",type:"thermostat",icon:"🌡️",tags:["climate","temperature"]},{id:"sh-hvac",name:"HVAC Unit",category:"smart-home",type:"hvac",icon:"❄️",tags:["climate","cooling","heating"]},{id:"sh-fan",name:"Smart Fan",category:"smart-home",type:"fan",icon:"💨",tags:["climate","fan"]},{id:"sh-camera",name:"Security Camera",category:"smart-home",type:"camera",icon:"📷",tags:["security","camera"]},{id:"sh-doorbell",name:"Video Doorbell",category:"smart-home",type:"camera-doorbell",icon:"🔔",tags:["security","doorbell"]},{id:"sh-lock",name:"Smart Lock",category:"smart-home",type:"lock",icon:"🔒",tags:["security","lock"]},{id:"sh-sensor-motion",name:"Motion Sensor",category:"smart-home",type:"sensor-motion",icon:"👁️",tags:["security","sensor"]},{id:"sh-sensor-door",name:"Door Sensor",category:"smart-home",type:"sensor-door",icon:"🚪",tags:["security","sensor"]},{id:"sh-speaker",name:"Smart Speaker",category:"smart-home",type:"speaker",icon:"🔊",tags:["audio","speaker"]},{id:"sh-voice-assistant",name:"Voice Assistant",category:"smart-home",type:"voice-assistant",icon:"🗣️",tags:["audio","assistant"]},{id:"sh-tv",name:"Smart TV",category:"smart-home",type:"tv",icon:"📺",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:"📡",tags:["network","router"]},{id:"net-switch-24",name:"24-Port Switch",category:"network",type:"switch",icon:"🔌",tags:["network","switch"]},{id:"net-switch-48",name:"48-Port Switch",category:"network",type:"switch",icon:"🔌",tags:["network","switch"]},{id:"net-firewall",name:"Firewall",category:"network",type:"firewall",icon:"🛡️",tags:["network","security"]},{id:"net-access-point",name:"WiFi Access Point",category:"network",type:"access-point",icon:"📶",tags:["network","wifi"]},{id:"net-server",name:"Server",category:"network",type:"server",icon:"🖥️",tags:["network","server"]},{id:"net-storage",name:"NAS Storage",category:"network",type:"nas",icon:"💾",tags:["network","storage"]},{id:"infra-rack-42u",name:"42U Rack",category:"infrastructure",type:"rack-42u",icon:"🗄️",defaultSize:{x:.6,y:1,z:2},tags:["datacenter","rack"]},{id:"infra-rack-24u",name:"24U Rack",category:"infrastructure",type:"rack-24u",icon:"🗄️",defaultSize:{x:.6,y:1,z:1.2},tags:["datacenter","rack"]},{id:"infra-ups",name:"UPS",category:"infrastructure",type:"ups-floor",icon:"🔋",tags:["datacenter","power"]},{id:"infra-pdu",name:"PDU",category:"infrastructure",type:"pdu-vertical",icon:"⚡",tags:["datacenter","power"]},{id:"infra-cooling",name:"CRAC Unit",category:"infrastructure",type:"cooling-crac",icon:"❄️",tags:["datacenter","cooling"]},{id:"bld-wall",name:"Wall",category:"building",type:"wall",icon:"🧱",tags:["building","wall"]},{id:"bld-door",name:"Door",category:"building",type:"door",icon:"🚪",tags:["building","door"]},{id:"bld-window",name:"Window",category:"building",type:"window",icon:"🪟",tags:["building","window"]},{id:"bld-stair",name:"Staircase",category:"building",type:"stair",icon:"🪜",tags:["building","stair"]},{id:"game-spawn",name:"Spawn Point",category:"game",type:"spawn-point",icon:"🎯",tags:["game","spawn"]},{id:"game-checkpoint",name:"Checkpoint",category:"game",type:"checkpoint",icon:"🏁",tags:["game","checkpoint"]},{id:"game-trigger",name:"Trigger Zone",category:"game",type:"trigger-zone",icon:"⚡",tags:["game","trigger"]},{id:"game-item",name:"Item Pickup",category:"game",type:"item-pickup",icon:"📦",tags:["game","item"]},{id:"game-enemy",name:"Enemy Spawner",category:"game",type:"enemy-spawner",icon:"👾",tags:["game","enemy"]}];function _s(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:Rn(),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 Rn(){return`${Date.now().toString(36)}-${Math.random().toString(36).substr(2,9)}`}const Ut={ft:3.28084,in:39.3701},Ht={"ft²":.092903,acre:4046.86};function Fn(t){return t*(180/Math.PI)}function Wn(t,s){return Math.sqrt((s.x-t.x)**2+(s.y-t.y)**2)}function Gn(t){if(t.length<2)return 0;let s=0;for(let n=1;n<t.length;n++)s+=Wn(t[n-1],t[n]);return s}function Tt(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},r=o.x*a.x+o.y*a.y,i=Math.sqrt(o.x**2+o.y**2),l=Math.sqrt(a.x**2+a.y**2);if(i===0||l===0)return 0;const h=r/(i*l);return Math.acos(Math.max(-1,Math.min(1,h)))}function Mt(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 Qe(t,s="m",n=2){const o=`${t.toFixed(n)} ${s}`;return{value:t,unit:s,formatted:o}}function lt(t,s="m²",n=2){const o=`${t.toFixed(n)} ${s}`;return{value:t,unit:s,formatted:o}}function Bt(t,s="deg",n=1){const o=s==="deg"?Fn(t):t,a=s==="deg"?"°":" rad",r=`${o.toFixed(n)}${a}`;return{value:o,unit:s,formatted:r}}function dt(t,s="metric",n=2){if(s==="metric")return t<.01?Qe(t*1e3,"mm",n):t<1?Qe(t*100,"cm",n):Qe(t,"m",n);{const o=t*Ut.ft;return o<1?Qe(t*Ut.in,"in",n):Qe(o,"ft",n)}}function Pt(t,s="metric",n=2){if(s==="metric")return t>=1e4?lt(t/1e4,"ha",n):lt(t,"m²",n);{const o=t/Ht["ft²"];return o>=43560?lt(t/Ht.acre,"acre",n):lt(o,"ft²",n)}}function qn(t,s={}){const{pretty:n=!1,includeSchema:o=!0,excludeEmptyLayers:a=!1,includeMetadata:r=!0}=s,i=JSON.parse(JSON.stringify(t));if(o&&!i.$schema&&(i.$schema="https://nice2dev.com/schemas/nsp-v1.json"),r&&(i.metadata=i.metadata??{id:"",name:"",created:new Date().toISOString(),modified:new Date().toISOString()},i.metadata.modified=new Date().toISOString()),a)for(const l of i.floors)l.layers=l.layers.filter(h=>h.objects.length>0);return n?JSON.stringify(i,null,2):JSON.stringify(i)}function Vn(t,s={}){var i;const n=Qn(t,s),o=qn(n),a=new Blob([o],{type:"application/json"});return{format:"nsp",filename:`${((i=t.metadata)==null?void 0:i.name)||"document"}.nsp.json`,mimeType:"application/json",data:a,size:a.size}}const Un="http://www.w3.org/2000/svg";function Hn(t,s={}){var _,f;const{floorIds:n,includeGrid:o=!1,scale:a=1,backgroundColor:r}=s,i=n?t.floors.filter(p=>n.includes(p.id)):t.floors;if(i.length===0)throw new Error("No floors to export");const l=Jn(i),h=(l.maxX-l.minX)*a,b=(l.maxY-l.minY)*a,d=((_=t.metadata)==null?void 0:_.name)||"Floor Plan";let x=`<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<svg xmlns="${
|
|
3
|
-
viewBox="${
|
|
1
|
+
"use strict";var Bs=Object.defineProperty;var Es=(t,s,n)=>s in t?Bs(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var dt=(t,s,n)=>Es(t,typeof s!="symbol"?s+"":s,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),S=require("@nice2dev/ui"),u=require("react"),Ps="_root_1nq8c_1",As="_shell_1nq8c_27",Os="_dark_1nq8c_35",Ds="_topBar_1nq8c_49",Rs="_floorTabs_1nq8c_79",qs="_floorTab_1nq8c_79",Fs="_floorTabActive_1nq8c_119",Gs="_overlayControls_1nq8c_131",Vs="_overlayBtn_1nq8c_143",Ws="_overlayBtnActive_1nq8c_179",Hs="_zoomBar_1nq8c_191",Us="_toolPalette_1nq8c_245",Ys="_toolBtn_1nq8c_275",Zs="_toolBtnActive_1nq8c_311",Xs="_canvasWrapper_1nq8c_325",Ks="_canvas_1nq8c_325",Js="_cur_select_1nq8c_365",Qs="_cur_drawzone_1nq8c_371",en="_cur_drawwall_1nq8c_377",tn="_cur_placedevice_1nq8c_383",sn="_cur_placedoor_1nq8c_389",nn="_cur_placewindow_1nq8c_395",on="_cur_pan_1nq8c_401",an="_cur_erase_1nq8c_407",rn="_cur_measure_1nq8c_413",cn="_cur_annotate_1nq8c_419",ln="_gridLine_1nq8c_429",dn="_zoneGroup_1nq8c_447",un="_zonePath_1nq8c_455",mn="_zoneLabel_1nq8c_463",hn="_climateLabel_1nq8c_485",pn="_occupancyLabel_1nq8c_497",_n="_dimLabel_1nq8c_509",fn="_deviceGroup_1nq8c_521",gn="_devCircle_1nq8c_529",yn="_devOnline_1nq8c_541",bn="_devOffline_1nq8c_547",xn="_devSelected_1nq8c_553",vn="_propPanel_1nq8c_565",jn="_propTitle_1nq8c_593",wn="_propRow_1nq8c_615",Nn="_statusBar_1nq8c_655",kn="_emptyState_1nq8c_687",oe={root:Ps,shell:As,dark:Os,topBar:Ds,floorTabs:Rs,floorTab:qs,floorTabActive:Fs,overlayControls:Gs,overlayBtn:Vs,overlayBtnActive:Ws,zoomBar:Hs,toolPalette:Us,toolBtn:Ys,toolBtnActive:Zs,canvasWrapper:Xs,canvas:Ks,cur_select:Js,cur_drawzone:Qs,cur_drawwall:en,cur_placedevice:tn,cur_placedoor:sn,cur_placewindow:nn,cur_pan:on,cur_erase:an,cur_measure:rn,cur_annotate:cn,gridLine:ln,zoneGroup:dn,zonePath:un,zoneLabel:mn,climateLabel:hn,occupancyLabel:pn,dimLabel:_n,deviceGroup:fn,devCircle:gn,devOnline:yn,devOffline:bn,devSelected:xn,propPanel:vn,propTitle:jn,propRow:wn,statusBar:Nn,emptyState:kn},In=[{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"}],Cn={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 Sn(t){return Cn[t]??"var(--nice-primary-bg, #f0f4ff)"}function fs(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 Ut(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 Ln(t,s){if(!t)return s?fs(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 Tn(t,s,n){return n?{x:Math.round(t.x/s)*s,y:Math.round(t.y/s)*s}:t}function $n(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 zn=[{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"}],Mn={light:"lightbulb",dimmer:"lightbulb",rgb_light:"lightbulb",led_strip:"lightbulb",thermostat:"thermometer",air_conditioner:"thermometer",fan:"wifi",heat_pump:"thermometer",lock:"lock",door:"door",window:"window",blind:"columns",camera:"camera",doorbell:"bell",alarm:"bell",motion_sensor:"eye",smoke_detector:"warning",temperature_sensor:"thermometer",humidity_sensor:"droplet",switch:"plug",outlet:"plug",speaker:"music",tv:"monitor",vacuum:"refresh",ev_charger:"zap",solar_panel:"zap",energy_meter:"zap",hub:"wifi",router:"wifi"},Bn=({floors:t,defaultFloors:s,devices:n=[],onFloorChange:o,onDeviceMove:a,readOnly:i=!1,initialFloorId:c,showDevices:r=!0,showDimensions:h=!1,showGrid:y=!0,showOccupancy:l=!1,showClimate:x=!0,className:_,style:p,theme:f="light",tutorial:j})=>{var Be,Ee;const{t:m}=S.useNiceTranslation(),[k,C]=S.useControllableState({value:t,defaultValue:s,fallbackValue:[],onChange:o,componentName:"NiceFloorPlanEditor"}),T=u.useRef(null),b=u.useRef(!1),L=u.useRef({x:0,y:0}),[d,v]=u.useReducer($n,{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:h,showLabels:!0,showOccupancy:l,showClimate:x,snapGrid:!0,gridSize:20});u.useEffect(()=>{v({t:"OVERLAYS",v:{showGrid:y,showDim:h,showOccupancy:l,showClimate:x}})},[y,h,l,x]);const g=k.find(M=>M.id===d.floorId)??k[0],q=u.useCallback(M=>{var he;const X=(he=T.current)==null?void 0:he.getBoundingClientRect();return X?{x:(M.clientX-X.left-d.pan.x)/d.zoom,y:(M.clientY-X.top-d.pan.y)/d.zoom}:{x:0,y:0}},[d.pan,d.zoom]),I=u.useCallback(M=>{d.tool==="pan"&&(b.current=!0,L.current={x:M.clientX,y:M.clientY})},[d.tool]),B=u.useCallback(M=>{b.current&&(v({t:"PAN",v:{x:d.pan.x+M.clientX-L.current.x,y:d.pan.y+M.clientY-L.current.y}}),L.current={x:M.clientX,y:M.clientY})},[d.pan]),W=u.useCallback(()=>{b.current=!1},[]),te=u.useCallback(M=>{if(d.tool==="draw_zone"){const X=Tn(q(M),d.gridSize,d.snapGrid);v({t:"DRAW_PT",v:X})}else d.tool==="select"&&v({t:"SELECT",v:null})},[d.tool,d.gridSize,d.snapGrid,q]),ue=u.useCallback(M=>{if(d.tool==="draw_zone"&&d.drawing&&d.drawing.length>=3&&g){const X={id:`zone-${Date.now()}`,name:"New zone",type:"other",floorId:g.id,polygon:[...d.drawing]};C(k.map(he=>he.id===g.id?{...g,zones:[...g.zones,X]}:he)),v({t:"DRAW_END"})}},[d.tool,d.drawing,g,k,C]),Q=u.useCallback(M=>{M.preventDefault(),v({t:"ZOOM",v:d.zoom*(M.deltaY>0?.9:1.1)})},[d.zoom]),_e=u.useCallback((M,X)=>{M.stopPropagation(),d.tool==="select"?v({t:"SELECT",v:{type:"zone",id:X.id}}):d.tool==="erase"&&!i&&g&&C(k.map(he=>he.id===g.id?{...g,zones:g.zones.filter(Ne=>Ne.id!==X.id)}:he))},[d.tool,i,g,k,C]);if(!g)return e.jsx("div",{className:oe.emptyState,children:m("buildings.noFloors","No floors.")});const se=((Ee=d.selected)==null?void 0:Ee.type)==="zone"?g.zones.find(M=>{var X;return M.id===((X=d.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: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:[...k].sort((M,X)=>M.level-X.level).map(M=>e.jsx("button",{className:`${oe.floorTab} ${d.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:d.zoom*1.2}),children:"+"}),e.jsxs("span",{children:[Math.round(d.zoom*100),"%"]}),e.jsx("button",{onClick:()=>v({t:"ZOOM",v:d.zoom*.8}),children:"−"}),e.jsx("button",{title:m("buildings.resetView","Reset the view"),"aria-label":m("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})})]})]}),Le=i?void 0:e.jsx("div",{className:oe.toolPalette,children:zn.map(({tool:M,icon:X,key:he,label:Ne})=>e.jsx("button",{title:m(he,Ne),"aria-label":m(he,Ne),className:`${oe.toolBtn} ${d.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} ${f==="dark"?oe.dark:""} ${_??""}`,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,In)})}),e.jsx(S.NiceAppShell,{flush:!0,className:oe.shell,menubar:Re,sidebar:Le,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:m("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:m("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:m("buildings.occupancy","Occupancy")}),e.jsxs("span",{children:[se.occupancy," os."]})]})]}):void 0,statusBar:e.jsxs("div",{className:oe.statusBar,children:[d.tool==="draw_zone"?m("buildings.drawHint","Click points; double-click to close the zone."):d.selected?`${m("buildings.selected","Selected")}: ${d.selected.type} #${d.selected.id}`:`${g.name} — ${g.zones.length} ${m("buildings.zones","zones")}`,d.tool==="draw_zone"&&d.drawing&&` (${d.drawing.length} pkt)`]}),children:e.jsx("div",{className:oe.canvasWrapper,children:e.jsxs("svg",{ref:T,className:`${oe.canvas} ${oe[`cur_${d.tool.replace("_","")}`]??""}`,onMouseDown:I,onMouseMove:B,onMouseUp:W,onClick:te,onDoubleClick:ue,onWheel:Q,children:[g.backgroundImage&&e.jsx("image",{href:g.backgroundImage,x:d.pan.x,y:d.pan.y,width:g.width*d.zoom,height:g.height*d.zoom,preserveAspectRatio:"xMidYMid meet",opacity:.35}),e.jsxs("g",{transform:`translate(${d.pan.x},${d.pan.y}) scale(${d.zoom})`,children:[d.showGrid&&(()=>{const M=[];for(let X=0;X<=g.width;X+=d.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+=d.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=d.selected)==null?void 0:Oe.id)===M.id,he=fs(M.polygon),Ne=M.color??Sn(M.type);return e.jsxs("g",{className:oe.zoneGroup,onClick:ve=>_e(ve,M),children:[e.jsx("path",{d:Ut(M.polygon),fill:Ne,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}),d.showLabels&&e.jsx("text",{x:he.x,y:he.y,textAnchor:"middle",dominantBaseline:"middle",className:oe.zoneLabel,children:M.name}),d.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}%`:""]}),d.showOccupancy&&M.occupancy!=null&&e.jsxs("text",{x:he.x,y:he.y+26,textAnchor:"middle",className:oe.occupancyLabel,children:[M.occupancy," ",m("buildings.people","people")]}),d.showDim&&M.polygon.length>1&&M.polygon.map((ve,Pe)=>{const Ce=M.polygon[(Pe+1)%M.polygon.length],ke=(ve.x+Ce.x)/2,we=(ve.y+Ce.y)/2,me=Math.sqrt((Ce.x-ve.x)**2+(Ce.y-ve.y)**2),ie=g.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`},Pe)})]},M.id)}),ge.map(M=>{var Oe;const X=g.zones.find(ve=>ve.id===M.zoneId),he=Ln(M.floorPlanPosition,X);if(!he)return null;const Ne=((Oe=d.selected)==null?void 0:Oe.id)===M.id;return e.jsxs("g",{transform:`translate(${he.x},${he.y})`,className:oe.deviceGroup,onClick:ve=>{ve.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} ${Ne?oe.devSelected:""}`}),e.jsx("g",{transform:"translate(-8,-8)",children:e.jsx(S.NiceIcon,{name:Mn[M.type]??"monitor",size:16})})]},M.id)}),d.drawing&&d.drawing.length>0&&e.jsxs("g",{children:[e.jsx("path",{d:Ut(d.drawing,!1),fill:"none",stroke:"var(--nice-primary-hover, #2563eb)",strokeWidth:2,strokeDasharray:"6,3"}),d.drawing.map((M,X)=>e.jsx("circle",{cx:M.x,cy:M.y,r:4,fill:"var(--nice-primary-hover, #2563eb)"},X))]})]})]})})})]})},En={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 Gt(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 Pn(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 An(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 On(t,s,n){let o=null;for(const a of s){const i=An(a);for(const c of i){const r=ot(t,c);r<=n&&(!o||r<o.distance)&&(o={point:c,targetId:a.id,distance:r})}}return o}function ot(t,s){return Math.sqrt((s.x-t.x)**2+(s.y-t.y)**2)}function gs(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 h of r)Math.abs(h.dragged-h.other)<=n&&(h.axis==="horizontal"?o.push({type:"horizontal",start:{x:Math.min(t.x,i.bounds.x),y:h.other},end:{x:Math.max(t.x+t.width,i.bounds.x+i.bounds.width),y:h.other},distance:Math.abs(h.dragged-h.other),sourceObjectId:i.id}):o.push({type:"vertical",start:{x:h.other,y:Math.min(t.y,i.bounds.y)},end:{x:h.other,y:Math.max(t.y+t.height,i.bounds.y+i.bounds.height)},distance:Math.abs(h.dragged-h.other),sourceObjectId:i.id}))}return Dn(o)}function Dn(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 Rn(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=On(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=Gt(t,n);if(ot(t,c)<=i)return o.position=c,o.snapped=!0,o.snapMode="grid",o}return o}const qn=[{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 Vt(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:Fn(),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 Fn(){return`${Date.now().toString(36)}-${Math.random().toString(36).substr(2,9)}`}const Yt={ft:3.28084,in:39.3701},Zt={"ft²":.092903,acre:4046.86};function Gn(t){return t*(180/Math.PI)}function Vn(t,s){return Math.sqrt((s.x-t.x)**2+(s.y-t.y)**2)}function Wn(t){if(t.length<2)return 0;let s=0;for(let n=1;n<t.length;n++)s+=Vn(t[n-1],t[n]);return s}function Et(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 h=i/(c*r);return Math.acos(Math.max(-1,Math.min(1,h)))}function Pt(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 tt(t,s="m",n=2){const o=`${t.toFixed(n)} ${s}`;return{value:t,unit:s,formatted:o}}function ut(t,s="m²",n=2){const o=`${t.toFixed(n)} ${s}`;return{value:t,unit:s,formatted:o}}function At(t,s="deg",n=1){const o=s==="deg"?Gn(t):t,a=s==="deg"?"°":" rad",i=`${o.toFixed(n)}${a}`;return{value:o,unit:s,formatted:i}}function mt(t,s="metric",n=2){if(s==="metric")return t<.01?tt(t*1e3,"mm",n):t<1?tt(t*100,"cm",n):tt(t,"m",n);{const o=t*Yt.ft;return o<1?tt(t*Yt.in,"in",n):tt(o,"ft",n)}}function Ot(t,s="metric",n=2){if(s==="metric")return t>=1e4?ut(t/1e4,"ha",n):ut(t,"m²",n);{const o=t/Zt["ft²"];return o>=43560?ut(t/Zt.acre,"acre",n):ut(o,"ft²",n)}}function Hn(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(h=>h.objects.length>0);return n?JSON.stringify(c,null,2):JSON.stringify(c)}function Un(t,s={}){var c;const n=to(t,s),o=Hn(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 Yn="http://www.w3.org/2000/svg";function Zn(t,s={}){var f,j;const{floorIds:n,includeGrid:o=!1,scale:a=1,backgroundColor:i}=s,c=n?t.floors.filter(m=>n.includes(m.id)):t.floors;if(c.length===0)throw new Error("No floors to export");const r=eo(c),h=(r.maxX-r.minX)*a,y=(r.maxY-r.minY)*a,l=((f=t.metadata)==null?void 0:f.name)||"Floor Plan";let x=`<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<svg xmlns="${Yn}"
|
|
3
|
+
viewBox="${r.minX} ${r.minY} ${r.maxX-r.minX} ${r.maxY-r.minY}"
|
|
4
4
|
width="${h}"
|
|
5
|
-
height="${
|
|
6
|
-
style="background: ${
|
|
7
|
-
<title>${
|
|
5
|
+
height="${y}"
|
|
6
|
+
style="background: ${i||"transparent"}">
|
|
7
|
+
<title>${l}</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&&(x+=
|
|
23
|
-
`;for(const
|
|
21
|
+
`;for(const m of c){x+=` <g id="${m.id}" class="floor" data-name="${m.name}">
|
|
22
|
+
`,o&&(x+=Xn(r));for(const k of m.layers)if(ys(k.name,s)){x+=` <g id="${k.id}" class="layer-${k.name}">
|
|
23
|
+
`;for(const C of k.objects)x+=Kn(C);x+=` </g>
|
|
24
24
|
`}x+=` </g>
|
|
25
|
-
`}x+="</svg>";const
|
|
25
|
+
`}x+="</svg>";const _=new Blob([x],{type:"image/svg+xml"});return{format:"svg",filename:`${((j=t.metadata)==null?void 0:j.name)||"document"}.svg`,mimeType:"image/svg+xml",data:_,size:_.size}}function Xn(t){let n=` <g class="grid">
|
|
26
26
|
`;for(let o=Math.floor(t.minX/20)*20;o<=t.maxX;o+=20)n+=` <line x1="${o}" y1="${t.minY}" x2="${o}" y2="${t.maxY}" />
|
|
27
27
|
`;for(let o=Math.floor(t.minY/20)*20;o<=t.maxY;o+=20)n+=` <line x1="${t.minX}" y1="${o}" x2="${t.maxX}" y2="${o}" />
|
|
28
28
|
`;return n+=` </g>
|
|
29
|
-
`,n}function
|
|
29
|
+
`,n}function Kn(t){const s=t;if(s.boundary&&Array.isArray(s.boundary)&&s.boundary.length>=3)return` <path d="${s.boundary.map((o,a)=>`${a===0?"M":"L"}${o.x},${o.y}`).join(" ")+" Z"}" class="zone" fill="${s.color||"#dbeafe"}" stroke="${s.color||"#3b82f6"}" />
|
|
30
30
|
`;if(s.start&&s.end)return` <line x1="${s.start.x}" y1="${s.start.y}" x2="${s.end.x}" y2="${s.end.y}" class="wall" stroke-width="${s.thickness||3}" />
|
|
31
|
-
`;if(t.bounds){const{x:n,y:o,width:a,height:
|
|
32
|
-
`:` <rect x="${n}" y="${o}" width="${a}" height="${
|
|
33
|
-
`}return""}function
|
|
31
|
+
`;if(t.bounds){const{x:n,y:o,width:a,height:i}=t.bounds,c=n+a/2,r=o+i/2;return t.category==="smart-home"?` <circle cx="${c}" cy="${r}" r="${Math.min(a,i)/2}" class="device" />
|
|
32
|
+
`:` <rect x="${n}" y="${o}" width="${a}" height="${i}" class="${t.category||"object"}" />
|
|
33
|
+
`}return""}function Jn(t,s={}){var y;const{floorIds:n,scale:o=1}=s,a=n?t.floors.filter(l=>n.includes(l.id)):t.floors;if(a.length===0)throw new Error("No floors to export");let i="";i+=`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
|
+
`,i+=`0
|
|
48
48
|
SECTION
|
|
49
49
|
2
|
|
50
50
|
TABLES
|
|
@@ -52,29 +52,29 @@ TABLES
|
|
|
52
52
|
TABLE
|
|
53
53
|
2
|
|
54
54
|
LAYER
|
|
55
|
-
`;const
|
|
55
|
+
`;const c=new Set;for(const l of a)for(const x of l.layers)c.add(x.name);for(const l of c)i+=`0
|
|
56
56
|
LAYER
|
|
57
57
|
2
|
|
58
|
-
${
|
|
58
|
+
${l.toUpperCase()}
|
|
59
59
|
70
|
|
60
60
|
0
|
|
61
61
|
62
|
|
62
62
|
7
|
|
63
63
|
6
|
|
64
64
|
CONTINUOUS
|
|
65
|
-
`;
|
|
65
|
+
`;i+=`0
|
|
66
66
|
ENDTAB
|
|
67
67
|
0
|
|
68
68
|
ENDSEC
|
|
69
|
-
`,
|
|
69
|
+
`,i+=`0
|
|
70
70
|
SECTION
|
|
71
71
|
2
|
|
72
72
|
ENTITIES
|
|
73
|
-
`;for(const
|
|
73
|
+
`;for(const l of a)for(const x of l.layers){if(!ys(x.name,s))continue;const _=x.name.toUpperCase();for(const p of x.objects)i+=Qn(p,_,o)}i+=`0
|
|
74
74
|
ENDSEC
|
|
75
75
|
0
|
|
76
76
|
EOF
|
|
77
|
-
`;const
|
|
77
|
+
`;const r=new Blob([i],{type:"application/dxf"});return{format:"dxf",filename:`${((y=t.metadata)==null?void 0:y.name)||"document"}.dxf`,mimeType:"application/dxf",data:r,size:r.size}}function Qn(t,s,n){const o=t;if(o.boundary&&Array.isArray(o.boundary)&&o.boundary.length>=3){let a=`0
|
|
78
78
|
LWPOLYLINE
|
|
79
79
|
8
|
|
80
80
|
${s}
|
|
@@ -82,10 +82,10 @@ ${s}
|
|
|
82
82
|
${o.boundary.length}
|
|
83
83
|
70
|
|
84
84
|
1
|
|
85
|
-
`;for(const
|
|
86
|
-
${
|
|
85
|
+
`;for(const i of o.boundary)a+=`10
|
|
86
|
+
${i.x*n}
|
|
87
87
|
20
|
|
88
|
-
${
|
|
88
|
+
${i.y*n}
|
|
89
89
|
`;return a}if(o.start&&o.end)return`0
|
|
90
90
|
LINE
|
|
91
91
|
8
|
|
@@ -98,16 +98,16 @@ ${o.start.y*n}
|
|
|
98
98
|
${o.end.x*n}
|
|
99
99
|
21
|
|
100
100
|
${o.end.y*n}
|
|
101
|
-
`;if(t.bounds){const{x:a,y:
|
|
101
|
+
`;if(t.bounds){const{x:a,y:i,width:c,height:r}=t.bounds,h=(a+c/2)*n,y=(i+r/2)*n;if(t.category==="smart-home"){const l=Math.min(c,r)/2*n;return`0
|
|
102
102
|
CIRCLE
|
|
103
103
|
8
|
|
104
104
|
${s}
|
|
105
105
|
10
|
|
106
106
|
${h}
|
|
107
107
|
20
|
|
108
|
-
${
|
|
108
|
+
${y}
|
|
109
109
|
40
|
|
110
|
-
${
|
|
110
|
+
${l}
|
|
111
111
|
`}return`0
|
|
112
112
|
LWPOLYLINE
|
|
113
113
|
8
|
|
@@ -119,21 +119,21 @@ ${s}
|
|
|
119
119
|
10
|
|
120
120
|
${a*n}
|
|
121
121
|
20
|
|
122
|
-
${
|
|
122
|
+
${i*n}
|
|
123
123
|
10
|
|
124
|
-
${(a+
|
|
124
|
+
${(a+c)*n}
|
|
125
125
|
20
|
|
126
|
-
${
|
|
126
|
+
${i*n}
|
|
127
127
|
10
|
|
128
|
-
${(a+
|
|
128
|
+
${(a+c)*n}
|
|
129
129
|
20
|
|
130
|
-
${(r
|
|
130
|
+
${(i+r)*n}
|
|
131
131
|
10
|
|
132
132
|
${a*n}
|
|
133
133
|
20
|
|
134
|
-
${(r
|
|
135
|
-
`}return""}function Jn(t){let s=1/0,n=1/0,o=-1/0,a=-1/0;for(const r of t){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));for(const i of r.layers)for(const l of i.objects){l.bounds&&(s=Math.min(s,l.bounds.x),n=Math.min(n,l.bounds.y),o=Math.max(o,l.bounds.x+l.bounds.width),a=Math.max(a,l.bounds.y+l.bounds.height));const h=l;if(h.boundary)for(const b of h.boundary)s=Math.min(s,b.x),n=Math.min(n,b.y),o=Math.max(o,b.x),a=Math.max(a,b.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 Qn(t,s){const{floorIds:n,layerNames:o}=s;let a=t.floors;return n&&n.length>0&&(a=a.filter(r=>n.includes(r.id))),o&&o.length>0&&(a=a.map(r=>({...r,layers:r.layers.filter(i=>o.includes(i.name))}))),{...t,floors:a}}function fs(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 ut(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 eo(t,s,n={}){const{dpi:o=96,backgroundColor:a="#ffffff"}=n,r=new XMLSerializer().serializeToString(t),i=new Blob([r],{type:"image/svg+xml;charset=utf-8"}),l=URL.createObjectURL(i);return new Promise((h,b)=>{const d=new Image;d.onload=()=>{const x=o/96,v=document.createElement("canvas");v.width=d.width*x,v.height=d.height*x;const y=v.getContext("2d");if(!y){b(new Error("Could not get canvas context"));return}y.fillStyle=a,y.fillRect(0,0,v.width,v.height),y.scale(x,x),y.drawImage(d,0,0),v.toBlob(_=>{if(URL.revokeObjectURL(l),!_){b(new Error("Could not create PNG blob"));return}h({format:"png",filename:s.endsWith(".png")?s:`${s}.png`,mimeType:"image/png",data:_,size:_.size})},"image/png")},d.onerror=()=>{URL.revokeObjectURL(l),b(new Error("Failed to load SVG for PNG export"))},d.src=l})}function gs(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 to(t,s,n,o="latency"){const a=gs(t);if(!a.has(s)||!a.has(n))return null;const r=new Map,i=new Map,l=new Set,h=[];for(const _ of a.keys())r.set(_,1/0),i.set(_,null);for(r.set(s,0),h.push({deviceId:s,distance:0});h.length>0;){h.sort((p,C)=>p.distance-C.distance);const _=h.shift();if(l.has(_.deviceId))continue;if(l.add(_.deviceId),_.deviceId===n)break;const f=a.get(_.deviceId)??[];for(const p of f){if(l.has(p.deviceId))continue;let C;switch(o){case"latency":C=p.connection.latency??1;break;case"hops":C=1;break;case"bandwidth":C=1/(p.connection.bandwidth??1);break}const L=r.get(_.deviceId)+C;L<r.get(p.deviceId)&&(r.set(p.deviceId,L),i.set(p.deviceId,{deviceId:_.deviceId,connection:p.connection}),h.push({deviceId:p.deviceId,distance:L}))}}if(!i.has(n)||r.get(n)===1/0)return null;const b=[];let d=0,x=1/0,v="active",y=n;for(;y&&i.get(y);){const _=i.get(y);b.unshift(_.connection.id),d+=_.connection.latency??0,_.connection.bandwidth!==void 0&&(x=Math.min(x,_.connection.bandwidth)),_.connection.status==="error"?v="error":_.connection.status==="degraded"&&v!=="error"?v="degraded":_.connection.status==="inactive"&&v==="active"&&(v="inactive"),y=_.deviceId}return{id:`path-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,startDeviceId:s,endDeviceId:n,connectionIds:b,totalLatency:d,bottleneckBandwidth:x===1/0?0:x,status:v,isPrimary:!0}}function so(t,s,n,o=5){const a=[],r=gs(t);function i(l,h,b,d){if(a.length>=o)return;if(l===h&&d.length>0){let v=0,y=1/0,_="active";for(const f of d)v+=f.latency??0,f.bandwidth!==void 0&&(y=Math.min(y,f.bandwidth)),f.status==="error"?_="error":f.status==="degraded"&&_!=="error"&&(_="degraded");a.push({id:`path-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,startDeviceId:s,endDeviceId:n,connectionIds:d.map(f=>f.id),totalLatency:v,bottleneckBandwidth:y===1/0?0:y,status:_,isPrimary:a.length===0});return}b.add(l);const x=r.get(l)??[];for(const v of x)b.has(v.deviceId)||i(v.deviceId,h,new Set(b),[...d,v.connection])}return i(s,n,new Set,[]),a}function no(t){var h,b;const s=[],n=t.split(/\r?\n/);let o=0,a=!1,r=null,i=[],l=null;for(;o<n.length;){const d=parseInt(((h=n[o])==null?void 0:h.trim())??"",10),x=((b=n[o+1])==null?void 0:b.trim())??"";if(o+=2,d===2&&x==="ENTITIES"){a=!0;continue}if(d===0&&x==="ENDSEC"&&a){r!=null&&r.type&&(i.length>0&&(r.vertices=[...i]),s.push(r)),a=!1;continue}if(a){if(d===0){r!=null&&r.type&&(i.length>0&&(r.vertices=[...i]),s.push(r)),r={type:x,layer:"0"},i=[],l=null;continue}if(r)switch(d){case 8:r.layer=x;break;case 5:r.handle=x;break;case 10:l=parseFloat(x);break;case 20:l!==null&&(i.push({x:l,y:parseFloat(x)}),r.position||(r.position={x:l,y:parseFloat(x)}),l=null);break;case 11:l=parseFloat(x);break;case 21:l!==null&&(i.push({x:l,y:parseFloat(x)}),l=null);break;case 40:(r.type==="CIRCLE"||r.type==="ARC")&&(r.radius=parseFloat(x));break;case 50:r.startAngle=parseFloat(x);break;case 51:r.endAngle=parseFloat(x);break;case 1:r.text=x;break;case 2:r.blockName=x;break;case 70:parseInt(x,10)&1&&(r.closed=!0);break}}}return s}function oo(t,s={}){var l,h;const n=Date.now(),o=[],a=[],r=s.scaleFactor??1,i=s.originOffset??{x:0,y:0};try{const b=no(t),d=[],x=[],v=[],y=new Set;let _=0;for(const p of b){if(y.add(p.layer),s.includeLayers&&!s.includeLayers.includes(p.layer)){_++;continue}if((l=s.excludeLayers)!=null&&l.includes(p.layer)){_++;continue}const C=((h=s.layerMappings)==null?void 0:h[p.layer])??p.layer;switch(p.type){case"LINE":if(p.vertices&&p.vertices.length>=2){const L=ge(p.vertices[0],r,i),I=ge(p.vertices[1],r,i);d.push({start:L,end:I,layer:C})}break;case"LWPOLYLINE":case"POLYLINE":if(p.vertices&&p.vertices.length>=2){const L=p.vertices.map(k=>ge(k,r,i));if(p.closed&&s.convertClosedPolylinesToZones){const k=ys(L),c=s.minZoneArea??.1;if(k>=c){x.push({name:C,boundary:L,layer:C});continue}}const I=p.closed?L.length:L.length-1;for(let k=0;k<I;k++){const c=L[k],g=L[(k+1)%L.length];d.push({start:c,end:g,layer:C})}}break;case"CIRCLE":if(p.position&&p.radius){const L=ge(p.position,r,i);v.push({type:"circle",position:L,layer:C,metadata:{radius:p.radius*r}})}break;case"INSERT":if(p.position&&p.blockName){const L=ge(p.position,r,i);v.push({type:"block-reference",position:L,layer:C,metadata:{blockName:p.blockName}})}break;default:_++,o.push({code:"UNSUPPORTED_ENTITY",message:`Unsupported DXF entity type: ${p.type}`,context:{type:p.type,layer:p.layer}})}}return{success:!0,document:bt(d,x,v,y,{name:"Imported DXF",sourceFormat:"dxf",units:s.defaultUnits??"metric"}),warnings:o,errors:a,stats:{wallsImported:d.length,zonesImported:x.length,objectsImported:v.length,layersFound:y.size,entitiesSkipped:_,importTimeMs:Date.now()-n}}}catch(b){return a.push({code:"PARSE_ERROR",message:b instanceof Error?b.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 ao(t){const s=[];let n=[],o=0,a=0,r=0,i=0;const l=t.match(/[MmLlHhVvCcSsQqTtAaZz]|[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/g)??[];let h=0;for(;h<l.length;){const b=l[h];h++;const d=()=>{const x=parseFloat(l[h]??"0");return h++,x};switch(b){case"M":n.length>0&&(s.push(n),n=[]),o=d(),a=d(),r=o,i=a,n.push({x:o,y:a});break;case"m":n.length>0&&(s.push(n),n=[]),o+=d(),a+=d(),r=o,i=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:r,y:i}),o=r,a=i;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 ro(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 r=t.match(/scale\s*\(\s*([-\d.]+)(?:\s*,?\s*([-\d.]+))?\s*\)/);return r&&(o=parseFloat(r[1])),{translate:{x:s,y:n},scale:o}}function io(t,s={}){const n=Date.now(),o=[],a=[],r=s.scaleFactor??1,i=s.originOffset??{x:0,y:0};try{const l=[],h=[],b=[],d=new Set,x=/<path[^>]*\bd="([^"]+)"[^>]*>/gi;let v;for(;(v=x.exec(t))!==null;){const k=v[1],c=v[0],g=c.match(/\bid="([^"]+)"/),m=(g==null?void 0:g[1])??"default";d.add(m);const j=c.match(/\btransform="([^"]+)"/),E=j?ro(j[1]):{translate:{x:0,y:0},scale:1},F=ao(k);for(const de of F){if(de.length<2)continue;const ee=de.map(ue=>ge({x:ue.x*E.scale+E.translate.x,y:ue.y*E.scale+E.translate.y},r,i));if(Math.abs(ee[0].x-ee[ee.length-1].x)<.1&&Math.abs(ee[0].y-ee[ee.length-1].y)<.1&&s.convertClosedPolylinesToZones&&ys(ee)>=(s.minZoneArea??.1)){h.push({name:m,boundary:ee,layer:m});continue}for(let ue=0;ue<ee.length-1;ue++)l.push({start:ee[ue],end:ee[ue+1],layer:m})}}const y=/<line[^>]*\bx1="([^"]+)"[^>]*\by1="([^"]+)"[^>]*\bx2="([^"]+)"[^>]*\by2="([^"]+)"[^>]*>/gi;let _;for(;(_=y.exec(t))!==null;){const k=parseFloat(_[1]),c=parseFloat(_[2]),g=parseFloat(_[3]),m=parseFloat(_[4]),j=ge({x:k,y:c},r,i),E=ge({x:g,y:m},r,i);l.push({start:j,end:E,layer:"default"}),d.add("default")}const f=/<rect[^>]*\bx="([^"]+)"[^>]*\by="([^"]+)"[^>]*\bwidth="([^"]+)"[^>]*\bheight="([^"]+)"[^>]*>/gi;let p;for(;(p=f.exec(t))!==null;){const k=parseFloat(p[1]),c=parseFloat(p[2]),g=parseFloat(p[3]),m=parseFloat(p[4]),j=[ge({x:k,y:c},r,i),ge({x:k+g,y:c},r,i),ge({x:k+g,y:c+m},r,i),ge({x:k,y:c+m},r,i)];s.convertClosedPolylinesToZones?h.push({name:"rect",boundary:j,layer:"default"}):(l.push({start:j[0],end:j[1],layer:"default"}),l.push({start:j[1],end:j[2],layer:"default"}),l.push({start:j[2],end:j[3],layer:"default"}),l.push({start:j[3],end:j[0],layer:"default"})),d.add("default")}const C=/<circle[^>]*\bcx="([^"]+)"[^>]*\bcy="([^"]+)"[^>]*\br="([^"]+)"[^>]*>/gi;let L;for(;(L=C.exec(t))!==null;){const k=parseFloat(L[1]),c=parseFloat(L[2]),g=parseFloat(L[3]),m=ge({x:k,y:c},r,i);b.push({type:"circle",position:m,layer:"default",metadata:{radius:g*r}}),d.add("default")}return{success:!0,document:bt(l,h,b,d,{name:"Imported SVG",sourceFormat:"svg",units:s.defaultUnits??"metric"}),warnings:o,errors:a,stats:{wallsImported:l.length,zonesImported:h.length,objectsImported:b.length,layersFound:d.size,entitiesSkipped:0,importTimeMs:Date.now()-n}}}catch(l){return a.push({code:"PARSE_ERROR",message:l instanceof Error?l.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 co(t,s={}){var l;const n=Date.now(),o=[],a=[],r=s.scaleFactor??1,i=s.originOffset??{x:0,y:0};try{const h=JSON.parse(t),b=[],d=[],x=[],v=new Set;let y=0;const _=h.type==="FeatureCollection"?h.features:[h];for(const p of _){const C=((l=p.properties)==null?void 0:l.layer)??"default";v.add(C);const L=p.geometry;switch(L.type){case"Point":{const I=L.coordinates,k=ge({x:I[0],y:I[1]},r,i);x.push({type:"marker",position:k,layer:C,metadata:{properties:p.properties}});break}case"LineString":{const I=L.coordinates;for(let k=0;k<I.length-1;k++){const c=ge({x:I[k][0],y:I[k][1]},r,i),g=ge({x:I[k+1][0],y:I[k+1][1]},r,i);b.push({start:c,end:g,layer:C})}break}case"MultiLineString":{const I=L.coordinates;for(const k of I)for(let c=0;c<k.length-1;c++){const g=ge({x:k[c][0],y:k[c][1]},r,i),m=ge({x:k[c+1][0],y:k[c+1][1]},r,i);b.push({start:g,end:m,layer:C})}break}case"Polygon":{const c=L.coordinates[0].map(g=>ge({x:g[0],y:g[1]},r,i));d.push({name:C,boundary:c,layer:C});break}case"MultiPolygon":{const I=L.coordinates;for(const k of I){const g=k[0].map(m=>ge({x:m[0],y:m[1]},r,i));d.push({name:C,boundary:g,layer:C})}break}default:y++,o.push({code:"UNSUPPORTED_GEOMETRY",message:`Unsupported GeoJSON geometry: ${L.type}`})}}return{success:!0,document:bt(b,d,x,v,{name:"Imported GeoJSON",sourceFormat:"geojson",units:s.defaultUnits??"metric"}),warnings:o,errors:a,stats:{wallsImported:b.length,zonesImported:d.length,objectsImported:x.length,layersFound:v.size,entitiesSkipped:y,importTimeMs:Date.now()-n}}}catch(h){return a.push({code:"PARSE_ERROR",message:h instanceof Error?h.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 lo(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 r=[],i=[],l=[],h=new Set;let b=0;const d=t.split(/\r?\n/),x=new Map;for(const y of d){const _=y.match(/^#(\d+)\s*=\s*(\w+)\s*\((.+)\)\s*;?$/);_&&x.set(`#${_[1]}`,{type:_[2],params:_[3]})}for(const[y,_]of x)if(_.type==="IFCWALLSTANDARDCASE"||_.type==="IFCWALL"){h.add("Walls");const f=_.params.match(/'([^']+)'/),p=(f==null?void 0:f[1])??"Wall";o.push({code:"IFC_WALL_SIMPLIFIED",message:`Wall "${p}" (${y}) geometry simplified to placeholder`}),b++}else if(_.type==="IFCSPACE"){h.add("Spaces");const f=_.params.match(/'([^']+)'/),p=(f==null?void 0:f[1])??"Space";o.push({code:"IFC_SPACE_SIMPLIFIED",message:`Space "${p}" (${y}) geometry simplified to placeholder`}),b++}return{success:!0,document:bt(r,i,l,h,{name:"Imported IFC",sourceFormat:"ifc",units:s.defaultUnits??"metric"}),warnings:o,errors:a,stats:{wallsImported:r.length,zonesImported:i.length,objectsImported:l.length,layersFound:h.size,entitiesSkipped:b,importTimeMs:Date.now()-n}}}catch(r){return a.push({code:"PARSE_ERROR",message:r instanceof Error?r.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 uo(t,s,n={}){switch(s){case"dxf":return oo(t,n);case"svg":return io(t,n);case"geojson":return co(t,n);case"ifc":return lo(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 ho(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 mo(t,s={}){return new Promise(n=>{const o=new FileReader;o.onload=()=>{const a=o.result,r=s.format??ho(t.name,a);if(!r){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(uo(a,r,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 He(){return`${Date.now()}-${Math.random().toString(36).slice(2,9)}`}function ge(t,s,n){return{x:t.x*s+n.x,y:t.y*s+n.y}}function ys(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 Yt(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 r of t)r.x<s&&(s=r.x),r.y<n&&(n=r.y),r.x>o&&(o=r.x),r.y>a&&(a=r.y);return{x:s,y:n,width:o-s,height:a-n}}function Zt(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 Xt(t){return{position:t,rotation:0,scale:{x:1,y:1}}}function bt(t,s,n,o,a){const r=new Date().toISOString(),i=`floor-${He()}`,l=[];for(const f of t)l.push(f.start,f.end);for(const f of s)l.push(...f.boundary);for(const f of n)l.push(f.position);const h=Yt(l),b=t.map(f=>({id:`wall-${He()}`,type:"wall",category:"building",name:"Wall",transform:Xt(f.start),bounds:Yt([f.start,f.end]),layer:f.layer,locked:!1,visible:!0,metadata:{end:f.end,thickness:f.thickness??.15,importedAt:r},childIds:[]})),d=n.map(f=>({id:`obj-${He()}`,type:f.type,category:"annotation",name:f.type,transform:Xt(f.position),bounds:{x:f.position.x-10,y:f.position.y-10,width:20,height:20},layer:f.layer,locked:!1,visible:!0,metadata:{...f.metadata,importedAt:r},childIds:[]})),x=Array.from(o).map(f=>({id:`layer-${He()}`,name:f,type:f.toLowerCase().includes("wall")?"walls":"custom",visible:!0,locked:!1,opacity:1,color:Zt(f),objects:[...b.filter(p=>p.layer===f),...d.filter(p=>p.layer===f)]})),v={id:i,name:"Imported Floor",level:0,elevation:0,ceilingHeight:2.7,bounds:h,layers:x},y=s.map(f=>({id:`zone-${He()}`,name:f.name,type:"custom",boundary:f.boundary,floorId:i,roomIds:[],color:Zt(f.name)})),_={$schema:"https://nice2dev.com/schemas/nsp-v1.json",version:"1.0.0",type:"floor-plan",metadata:{id:`doc-${He()}`,name:a.name,description:`Imported from ${a.sourceFormat.toUpperCase()}`,created:r,modified:r,tags:["imported",a.sourceFormat]},floors:[v],settings:{units:a.units,scale:50,grid:{visible:!0,size:.5,snapEnabled:!0},defaultWallHeight:2.7,defaultWallThickness:.15,precision:2}};return _.zones=y,_}const po=10,_o=8;class fo{constructor(s,n=po){ct(this,"root");ct(this,"maxItems");ct(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<_o){this.split(s);const a=[...s.items];s.items=[];for(const r of a)this.insertIntoNode(s,r,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:r}=s.bounds,i=a/2,l=r/2;s.children=[{bounds:{x:n,y:o,width:i,height:l},items:[],children:null},{bounds:{x:n+i,y:o,width:i,height:l},items:[],children:null},{bounds:{x:n,y:o+l,width:i,height:l},items:[],children:null},{bounds:{x:n+i,y:o+l,width:i,height:l},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,r=n.x+n.width<=o,i=n.x>=o,l=n.y+n.height<=a,h=n.y>=a;return l&&r?0:l&&i?1:h&&r?2:h&&i?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 go(t,s=100){let n=1/0,o=1/0,a=-1/0,r=-1/0;for(const h of t){const{x:b,y:d}=h.position,{width:x=20,height:v=20}=h.size??{};n=Math.min(n,b-x/2),o=Math.min(o,d-v/2),a=Math.max(a,b+x/2),r=Math.max(r,d+v/2)}Number.isFinite(n)||(n=o=0,a=r=1e3);const i={x:n-s,y:o-s,width:a-n+s*2,height:r-o+s*2},l=new fo(i);for(const h of t){const{x:b,y:d}=h.position,{width:x=20,height:v=20}=h.size??{};l.insert({id:h.id,bounds:{x:b-x/2,y:d-v/2,width:x,height:v},data:h.data})}return l}function yo(t,s,n=100){const o=(s.width+n*2)/t.zoom,a=(s.height+n*2)/t.zoom,r=(-t.pan.x-n)/t.zoom,i=(-t.pan.y-n)/t.zoom;return{x:r,y:i,width:o,height:a}}function xo(t,s=200){return t>=s}function bo(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 vo="_overlay_18dh4_9",jo="_dialog_18dh4_55",wo="_header_18dh4_103",No="_title_18dh4_119",ko="_closeButton_18dh4_133",Io="_content_18dh4_167",Co="_preview_18dh4_183",So="_previewCanvas_18dh4_203",zo="_previewSvg_18dh4_221",Lo="_info_18dh4_231",$o="_section_18dh4_241",To="_sectionTitle_18dh4_249",Mo="_statGrid_18dh4_269",Bo="_stat_18dh4_269",Po="_statLabel_18dh4_293",Eo="_statValue_18dh4_305",Oo="_warningsList_18dh4_317",Ao="_warning_18dh4_317",Do="_warningIcon_18dh4_361",Ro="_error_18dh4_371",Fo="_errorIcon_18dh4_403",Wo="_footer_18dh4_413",Go="_cancelButton_18dh4_433",qo="_confirmButton_18dh4_465",Vo="_noWarnings_18dh4_507",Uo="_layersList_18dh4_519",Ho="_layer_18dh4_519",Yo="_layerIcon_18dh4_561",Zo="_layerName_18dh4_569",Xo="_layerCount_18dh4_579",V={overlay:vo,dialog:jo,header:wo,title:No,closeButton:ko,content:Io,preview:Co,previewCanvas:So,previewSvg:zo,info:Lo,section:$o,sectionTitle:To,statGrid:Mo,stat:Bo,statLabel:Po,statValue:Eo,warningsList:Oo,warning:Ao,warningIcon:Do,error:Ro,errorIcon:Fo,footer:Wo,cancelButton:Go,confirmButton:qo,noWarnings:Vo,layersList:Uo,layer:Ho,layerIcon:Yo,layerName:Zo,layerCount:Xo},Ko=()=>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"})}),Kt=()=>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"})}),Jt=()=>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"})}),Qt=()=>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"})}),Jo=()=>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 Qo({result:t,onConfirm:s,onCancel:n}){const o=t.document,a=u.useMemo(()=>{var L,I;if(!((L=o==null?void 0:o.floors)!=null&&L.length))return null;const d=o.floors[0],x=(d==null?void 0:d.layers)||[],v=x.flatMap(k=>k.objects);let y=1/0,_=1/0,f=-1/0,p=-1/0;for(const k of v)k.bounds?(y=Math.min(y,k.bounds.x),_=Math.min(_,k.bounds.y),f=Math.max(f,k.bounds.x+k.bounds.width),p=Math.max(p,k.bounds.y+k.bounds.height)):(I=k.transform)!=null&&I.position&&(y=Math.min(y,k.transform.position.x),_=Math.min(_,k.transform.position.y),f=Math.max(f,k.transform.position.x),p=Math.max(p,k.transform.position.y));isFinite(y)||(d!=null&&d.bounds?(y=d.bounds.x,_=d.bounds.y,f=d.bounds.x+d.bounds.width,p=d.bounds.y+d.bounds.height):(y=0,_=0,f=1e3,p=800));const C=20;return{viewBox:{x:y-C,y:_-C,width:f-y+C*2,height:p-_+C*2},objects:v,layers:x}},[o]),r=u.useMemo(()=>{if(!a||!o)return null;const{viewBox:d,objects:x}=a,v=[],y=50,_=`
|
|
136
|
-
<pattern id="grid" width="${
|
|
137
|
-
<path d="M ${
|
|
134
|
+
${(i+r)*n}
|
|
135
|
+
`}return""}function eo(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 h=r;if(h.boundary)for(const y of h.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 to(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 ys(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 ht(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 so(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((h,y)=>{const l=new Image;l.onload=()=>{const x=o/96,_=document.createElement("canvas");_.width=l.width*x,_.height=l.height*x;const p=_.getContext("2d");if(!p){y(new Error("Could not get canvas context"));return}p.fillStyle=a,p.fillRect(0,0,_.width,_.height),p.scale(x,x),p.drawImage(l,0,0),_.toBlob(f=>{if(URL.revokeObjectURL(r),!f){y(new Error("Could not create PNG blob"));return}h({format:"png",filename:s.endsWith(".png")?s:`${s}.png`,mimeType:"image/png",data:f,size:f.size})},"image/png")},l.onerror=()=>{URL.revokeObjectURL(r),y(new Error("Failed to load SVG for PNG export"))},l.src=r})}function bs(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 no(t,s,n,o="latency"){const a=bs(t);if(!a.has(s)||!a.has(n))return null;const i=new Map,c=new Map,r=new Set,h=[];for(const f of a.keys())i.set(f,1/0),c.set(f,null);for(i.set(s,0),h.push({deviceId:s,distance:0});h.length>0;){h.sort((m,k)=>m.distance-k.distance);const f=h.shift();if(r.has(f.deviceId))continue;if(r.add(f.deviceId),f.deviceId===n)break;const j=a.get(f.deviceId)??[];for(const m of j){if(r.has(m.deviceId))continue;let k;switch(o){case"latency":k=m.connection.latency??1;break;case"hops":k=1;break;case"bandwidth":k=1/(m.connection.bandwidth??1);break}const C=i.get(f.deviceId)+k;C<i.get(m.deviceId)&&(i.set(m.deviceId,C),c.set(m.deviceId,{deviceId:f.deviceId,connection:m.connection}),h.push({deviceId:m.deviceId,distance:C}))}}if(!c.has(n)||i.get(n)===1/0)return null;const y=[];let l=0,x=1/0,_="active",p=n;for(;p&&c.get(p);){const f=c.get(p);y.unshift(f.connection.id),l+=f.connection.latency??0,f.connection.bandwidth!==void 0&&(x=Math.min(x,f.connection.bandwidth)),f.connection.status==="error"?_="error":f.connection.status==="degraded"&&_!=="error"?_="degraded":f.connection.status==="inactive"&&_==="active"&&(_="inactive"),p=f.deviceId}return{id:`path-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,startDeviceId:s,endDeviceId:n,connectionIds:y,totalLatency:l,bottleneckBandwidth:x===1/0?0:x,status:_,isPrimary:!0}}function oo(t,s,n,o=5){const a=[],i=bs(t);function c(r,h,y,l){if(a.length>=o)return;if(r===h&&l.length>0){let _=0,p=1/0,f="active";for(const j of l)_+=j.latency??0,j.bandwidth!==void 0&&(p=Math.min(p,j.bandwidth)),j.status==="error"?f="error":j.status==="degraded"&&f!=="error"&&(f="degraded");a.push({id:`path-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,startDeviceId:s,endDeviceId:n,connectionIds:l.map(j=>j.id),totalLatency:_,bottleneckBandwidth:p===1/0?0:p,status:f,isPrimary:a.length===0});return}y.add(r);const x=i.get(r)??[];for(const _ of x)y.has(_.deviceId)||c(_.deviceId,h,new Set(y),[...l,_.connection])}return c(s,n,new Set,[]),a}function ao(t){var h,y;const s=[],n=t.split(/\r?\n/);let o=0,a=!1,i=null,c=[],r=null;for(;o<n.length;){const l=parseInt(((h=n[o])==null?void 0:h.trim())??"",10),x=((y=n[o+1])==null?void 0:y.trim())??"";if(o+=2,l===2&&x==="ENTITIES"){a=!0;continue}if(l===0&&x==="ENDSEC"&&a){i!=null&&i.type&&(c.length>0&&(i.vertices=[...c]),s.push(i)),a=!1;continue}if(a){if(l===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(l){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 io(t,s={}){var r,h;const n=Date.now(),o=[],a=[],i=s.scaleFactor??1,c=s.originOffset??{x:0,y:0};try{const y=ao(t),l=[],x=[],_=[],p=new Set;let f=0;for(const m of y){if(p.add(m.layer),s.includeLayers&&!s.includeLayers.includes(m.layer)){f++;continue}if((r=s.excludeLayers)!=null&&r.includes(m.layer)){f++;continue}const k=((h=s.layerMappings)==null?void 0:h[m.layer])??m.layer;switch(m.type){case"LINE":if(m.vertices&&m.vertices.length>=2){const C=be(m.vertices[0],i,c),T=be(m.vertices[1],i,c);l.push({start:C,end:T,layer:k})}break;case"LWPOLYLINE":case"POLYLINE":if(m.vertices&&m.vertices.length>=2){const C=m.vertices.map(b=>be(b,i,c));if(m.closed&&s.convertClosedPolylinesToZones){const b=xs(C),L=s.minZoneArea??.1;if(b>=L){x.push({name:k,boundary:C,layer:k});continue}}const T=m.closed?C.length:C.length-1;for(let b=0;b<T;b++){const L=C[b],d=C[(b+1)%C.length];l.push({start:L,end:d,layer:k})}}break;case"CIRCLE":if(m.position&&m.radius){const C=be(m.position,i,c);_.push({type:"circle",position:C,layer:k,metadata:{radius:m.radius*i}})}break;case"INSERT":if(m.position&&m.blockName){const C=be(m.position,i,c);_.push({type:"block-reference",position:C,layer:k,metadata:{blockName:m.blockName}})}break;default:f++,o.push({code:"UNSUPPORTED_ENTITY",message:`Unsupported DXF entity type: ${m.type}`,context:{type:m.type,layer:m.layer}})}}return{success:!0,document:wt(l,x,_,p,{name:"Imported DXF",sourceFormat:"dxf",units:s.defaultUnits??"metric"}),warnings:o,errors:a,stats:{wallsImported:l.length,zonesImported:x.length,objectsImported:_.length,layersFound:p.size,entitiesSkipped:f,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 ro(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 h=0;for(;h<r.length;){const y=r[h];h++;const l=()=>{const x=parseFloat(r[h]??"0");return h++,x};switch(y){case"M":n.length>0&&(s.push(n),n=[]),o=l(),a=l(),i=o,c=a,n.push({x:o,y:a});break;case"m":n.length>0&&(s.push(n),n=[]),o+=l(),a+=l(),i=o,c=a,n.push({x:o,y:a});break;case"L":o=l(),a=l(),n.push({x:o,y:a});break;case"l":o+=l(),a+=l(),n.push({x:o,y:a});break;case"H":o=l(),n.push({x:o,y:a});break;case"h":o+=l(),n.push({x:o,y:a});break;case"V":a=l(),n.push({x:o,y:a});break;case"v":a+=l(),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":l(),l(),l(),l(),o=l(),a=l(),n.push({x:o,y:a});break;case"c":l(),l(),l(),l(),o+=l(),a+=l(),n.push({x:o,y:a});break;case"Q":l(),l(),o=l(),a=l(),n.push({x:o,y:a});break;case"q":l(),l(),o+=l(),a+=l(),n.push({x:o,y:a});break}}return n.length>0&&s.push(n),s}function co(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 lo(t,s={}){const n=Date.now(),o=[],a=[],i=s.scaleFactor??1,c=s.originOffset??{x:0,y:0};try{const r=[],h=[],y=[],l=new Set,x=/<path[^>]*\bd="([^"]+)"[^>]*>/gi;let _;for(;(_=x.exec(t))!==null;){const b=_[1],L=_[0],d=L.match(/\bid="([^"]+)"/),v=(d==null?void 0:d[1])??"default";l.add(v);const g=L.match(/\btransform="([^"]+)"/),q=g?co(g[1]):{translate:{x:0,y:0},scale:1},I=ro(b);for(const B of I){if(B.length<2)continue;const W=B.map(ue=>be({x:ue.x*q.scale+q.translate.x,y:ue.y*q.scale+q.translate.y},i,c));if(Math.abs(W[0].x-W[W.length-1].x)<.1&&Math.abs(W[0].y-W[W.length-1].y)<.1&&s.convertClosedPolylinesToZones&&xs(W)>=(s.minZoneArea??.1)){h.push({name:v,boundary:W,layer:v});continue}for(let ue=0;ue<W.length-1;ue++)r.push({start:W[ue],end:W[ue+1],layer:v})}}const p=/<line[^>]*\bx1="([^"]+)"[^>]*\by1="([^"]+)"[^>]*\bx2="([^"]+)"[^>]*\by2="([^"]+)"[^>]*>/gi;let f;for(;(f=p.exec(t))!==null;){const b=parseFloat(f[1]),L=parseFloat(f[2]),d=parseFloat(f[3]),v=parseFloat(f[4]),g=be({x:b,y:L},i,c),q=be({x:d,y:v},i,c);r.push({start:g,end:q,layer:"default"}),l.add("default")}const j=/<rect[^>]*\bx="([^"]+)"[^>]*\by="([^"]+)"[^>]*\bwidth="([^"]+)"[^>]*\bheight="([^"]+)"[^>]*>/gi;let m;for(;(m=j.exec(t))!==null;){const b=parseFloat(m[1]),L=parseFloat(m[2]),d=parseFloat(m[3]),v=parseFloat(m[4]),g=[be({x:b,y:L},i,c),be({x:b+d,y:L},i,c),be({x:b+d,y:L+v},i,c),be({x:b,y:L+v},i,c)];s.convertClosedPolylinesToZones?h.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"})),l.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]),d=parseFloat(C[3]),v=be({x:b,y:L},i,c);y.push({type:"circle",position:v,layer:"default",metadata:{radius:d*i}}),l.add("default")}return{success:!0,document:wt(r,h,y,l,{name:"Imported SVG",sourceFormat:"svg",units:s.defaultUnits??"metric"}),warnings:o,errors:a,stats:{wallsImported:r.length,zonesImported:h.length,objectsImported:y.length,layersFound:l.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 uo(t,s={}){var r;const n=Date.now(),o=[],a=[],i=s.scaleFactor??1,c=s.originOffset??{x:0,y:0};try{const h=JSON.parse(t),y=[],l=[],x=[],_=new Set;let p=0;const f=h.type==="FeatureCollection"?h.features:[h];for(const m of f){const k=((r=m.properties)==null?void 0:r.layer)??"default";_.add(k);const C=m.geometry;switch(C.type){case"Point":{const T=C.coordinates,b=be({x:T[0],y:T[1]},i,c);x.push({type:"marker",position:b,layer:k,metadata:{properties:m.properties}});break}case"LineString":{const T=C.coordinates;for(let b=0;b<T.length-1;b++){const L=be({x:T[b][0],y:T[b][1]},i,c),d=be({x:T[b+1][0],y:T[b+1][1]},i,c);y.push({start:L,end:d,layer:k})}break}case"MultiLineString":{const T=C.coordinates;for(const b of T)for(let L=0;L<b.length-1;L++){const d=be({x:b[L][0],y:b[L][1]},i,c),v=be({x:b[L+1][0],y:b[L+1][1]},i,c);y.push({start:d,end:v,layer:k})}break}case"Polygon":{const L=C.coordinates[0].map(d=>be({x:d[0],y:d[1]},i,c));l.push({name:k,boundary:L,layer:k});break}case"MultiPolygon":{const T=C.coordinates;for(const b of T){const d=b[0].map(v=>be({x:v[0],y:v[1]},i,c));l.push({name:k,boundary:d,layer:k})}break}default:p++,o.push({code:"UNSUPPORTED_GEOMETRY",message:`Unsupported GeoJSON geometry: ${C.type}`})}}return{success:!0,document:wt(y,l,x,_,{name:"Imported GeoJSON",sourceFormat:"geojson",units:s.defaultUnits??"metric"}),warnings:o,errors:a,stats:{wallsImported:y.length,zonesImported:l.length,objectsImported:x.length,layersFound:_.size,entitiesSkipped:p,importTimeMs:Date.now()-n}}}catch(h){return a.push({code:"PARSE_ERROR",message:h instanceof Error?h.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 mo(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=[],h=new Set;let y=0;const l=t.split(/\r?\n/),x=new Map;for(const p of l){const f=p.match(/^#(\d+)\s*=\s*(\w+)\s*\((.+)\)\s*;?$/);f&&x.set(`#${f[1]}`,{type:f[2],params:f[3]})}for(const[p,f]of x)if(f.type==="IFCWALLSTANDARDCASE"||f.type==="IFCWALL"){h.add("Walls");const j=f.params.match(/'([^']+)'/),m=(j==null?void 0:j[1])??"Wall";o.push({code:"IFC_WALL_SIMPLIFIED",message:`Wall "${m}" (${p}) geometry simplified to placeholder`}),y++}else if(f.type==="IFCSPACE"){h.add("Spaces");const j=f.params.match(/'([^']+)'/),m=(j==null?void 0:j[1])??"Space";o.push({code:"IFC_SPACE_SIMPLIFIED",message:`Space "${m}" (${p}) geometry simplified to placeholder`}),y++}return{success:!0,document:wt(i,c,r,h,{name:"Imported IFC",sourceFormat:"ifc",units:s.defaultUnits??"metric"}),warnings:o,errors:a,stats:{wallsImported:i.length,zonesImported:c.length,objectsImported:r.length,layersFound:h.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 ho(t,s,n={}){switch(s){case"dxf":return io(t,n);case"svg":return lo(t,n);case"geojson":return uo(t,n);case"ifc":return mo(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 po(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 _o(t,s={}){return new Promise(n=>{const o=new FileReader;o.onload=()=>{const a=o.result,i=s.format??po(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(ho(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 Ye(){return`${Date.now()}-${Math.random().toString(36).slice(2,9)}`}function be(t,s,n){return{x:t.x*s+n.x,y:t.y*s+n.y}}function xs(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 Xt(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 Kt(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 Jt(t){return{position:t,rotation:0,scale:{x:1,y:1}}}function wt(t,s,n,o,a){const i=new Date().toISOString(),c=`floor-${Ye()}`,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 h=Xt(r),y=t.map(j=>({id:`wall-${Ye()}`,type:"wall",category:"building",name:"Wall",transform:Jt(j.start),bounds:Xt([j.start,j.end]),layer:j.layer,locked:!1,visible:!0,metadata:{end:j.end,thickness:j.thickness??.15,importedAt:i},childIds:[]})),l=n.map(j=>({id:`obj-${Ye()}`,type:j.type,category:"annotation",name:j.type,transform:Jt(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-${Ye()}`,name:j,type:j.toLowerCase().includes("wall")?"walls":"custom",visible:!0,locked:!1,opacity:1,color:Kt(j),objects:[...y.filter(m=>m.layer===j),...l.filter(m=>m.layer===j)]})),_={id:c,name:"Imported Floor",level:0,elevation:0,ceilingHeight:2.7,bounds:h,layers:x},p=s.map(j=>({id:`zone-${Ye()}`,name:j.name,type:"custom",boundary:j.boundary,floorId:c,roomIds:[],color:Kt(j.name)})),f={$schema:"https://nice2dev.com/schemas/nsp-v1.json",version:"1.0.0",type:"floor-plan",metadata:{id:`doc-${Ye()}`,name:a.name,description:`Imported from ${a.sourceFormat.toUpperCase()}`,created:i,modified:i,tags:["imported",a.sourceFormat]},floors:[_],settings:{units:a.units,scale:50,grid:{visible:!0,size:.5,snapEnabled:!0},defaultWallHeight:2.7,defaultWallThickness:.15,precision:2}};return f.zones=p,f}const fo=10,go=8;class yo{constructor(s,n=fo){dt(this,"root");dt(this,"maxItems");dt(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<go){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,h=n.y>=a;return r&&i?0:r&&c?1:h&&i?2:h&&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 bo(t,s=100){let n=1/0,o=1/0,a=-1/0,i=-1/0;for(const h of t){const{x:y,y:l}=h.position,{width:x=20,height:_=20}=h.size??{};n=Math.min(n,y-x/2),o=Math.min(o,l-_/2),a=Math.max(a,y+x/2),i=Math.max(i,l+_/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 yo(c);for(const h of t){const{x:y,y:l}=h.position,{width:x=20,height:_=20}=h.size??{};r.insert({id:h.id,bounds:{x:y-x/2,y:l-_/2,width:x,height:_},data:h.data})}return r}function xo(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 vo(t,s=200){return t>=s}function jo(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 wo="_overlay_1x0xg_9",No="_dialog_1x0xg_55",ko="_header_1x0xg_103",Io="_title_1x0xg_119",Co="_closeButton_1x0xg_133",So="_content_1x0xg_167",Lo="_preview_1x0xg_183",To="_previewCanvas_1x0xg_203",$o="_previewSvg_1x0xg_221",zo="_info_1x0xg_231",Mo="_section_1x0xg_241",Bo="_sectionTitle_1x0xg_249",Eo="_statGrid_1x0xg_269",Po="_stat_1x0xg_269",Ao="_statLabel_1x0xg_293",Oo="_statValue_1x0xg_305",Do="_warningsList_1x0xg_317",Ro="_warning_1x0xg_317",qo="_warningIcon_1x0xg_361",Fo="_error_1x0xg_371",Go="_errorIcon_1x0xg_403",Vo="_footer_1x0xg_413",Wo="_cancelButton_1x0xg_433",Ho="_confirmButton_1x0xg_465",Uo="_noWarnings_1x0xg_507",Yo="_layersList_1x0xg_519",Zo="_layer_1x0xg_519",Xo="_layerIcon_1x0xg_561",Ko="_layerName_1x0xg_569",Jo="_layerCount_1x0xg_579",U={overlay:wo,dialog:No,header:ko,title:Io,closeButton:Co,content:So,preview:Lo,previewCanvas:To,previewSvg:$o,info:zo,section:Mo,sectionTitle:Bo,statGrid:Eo,stat:Po,statLabel:Ao,statValue:Oo,warningsList:Do,warning:Ro,warningIcon:qo,error:Fo,errorIcon:Go,footer:Vo,cancelButton:Wo,confirmButton:Ho,noWarnings:Uo,layersList:Yo,layer:Zo,layerIcon:Xo,layerName:Ko,layerCount:Jo},Qo=()=>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"})}),Qt=()=>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"})}),es=()=>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"})}),ts=()=>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"})}),ea=()=>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 ta({result:t,onConfirm:s,onCancel:n}){const o=t.document,a=u.useMemo(()=>{var C,T;if(!((C=o==null?void 0:o.floors)!=null&&C.length))return null;const l=o.floors[0],x=(l==null?void 0:l.layers)||[],_=x.flatMap(b=>b.objects);let p=1/0,f=1/0,j=-1/0,m=-1/0;for(const b of _)b.bounds?(p=Math.min(p,b.bounds.x),f=Math.min(f,b.bounds.y),j=Math.max(j,b.bounds.x+b.bounds.width),m=Math.max(m,b.bounds.y+b.bounds.height)):(T=b.transform)!=null&&T.position&&(p=Math.min(p,b.transform.position.x),f=Math.min(f,b.transform.position.y),j=Math.max(j,b.transform.position.x),m=Math.max(m,b.transform.position.y));isFinite(p)||(l!=null&&l.bounds?(p=l.bounds.x,f=l.bounds.y,j=l.bounds.x+l.bounds.width,m=l.bounds.y+l.bounds.height):(p=0,f=0,j=1e3,m=800));const k=20;return{viewBox:{x:p-k,y:f-k,width:j-p+k*2,height:m-f+k*2},objects:_,layers:x}},[o]),i=u.useMemo(()=>{if(!a||!o)return null;const{viewBox:l,objects:x}=a,_=[],p=50,f=`
|
|
136
|
+
<pattern id="grid" width="${p}" height="${p}" patternUnits="userSpaceOnUse">
|
|
137
|
+
<path d="M ${p} 0 L 0 0 0 ${p}" fill="none" stroke="var(--nice-border, #e2e8f0)" strokeWidth="0.5"/>
|
|
138
138
|
</pattern>
|
|
139
|
-
`;return x.forEach((f,p)=>{if(f.type==="wall"&&f.bounds)v.push(e.jsx("rect",{x:f.bounds.x,y:f.bounds.y,width:f.bounds.width,height:f.bounds.height,fill:"var(--nice-text-secondary, #475569)",stroke:"var(--nice-text, #334155)",strokeWidth:"1"},`wall-${p}`));else if(f.type==="zone"&&f.boundary){const L=f.boundary.map((I,k)=>`${k===0?"M":"L"} ${I.x} ${I.y}`).join(" ")+" Z";v.push(e.jsx("path",{d:L,fill:"var(--nice-primary-tint-20, rgba(59, 130, 246, 0.2))",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:"1"},`zone-${p}`))}else if(f.type==="room"&&f.boundary){const L=f.boundary.map((I,k)=>`${k===0?"M":"L"} ${I.x} ${I.y}`).join(" ")+" Z";v.push(e.jsx("path",{d:L,fill:"var(--nice-success-tint-15, rgba(34, 197, 94, 0.15))",stroke:"var(--nice-success, #22c55e)",strokeWidth:"1"},`room-${p}`))}else f.bounds&&v.push(e.jsx("rect",{x:f.bounds.x,y:f.bounds.y,width:f.bounds.width,height:f.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-${p}`))}),e.jsxs("svg",{viewBox:`${d.x} ${d.y} ${d.width} ${d.height}`,className:V.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)"}),v]})},[a,o]),i=u.useCallback(d=>{d.key==="Escape"&&n()},[n]),l=u.useCallback(d=>{d.target===d.currentTarget&&n()},[n]),h=t.errors.some(d=>d.fatal),b=t.errors.filter(d=>!d.fatal);return e.jsx("div",{className:V.overlay,onClick:l,onKeyDown:i,tabIndex:-1,role:"dialog","aria-modal":"true","aria-labelledby":"import-preview-title",children:e.jsxs("div",{className:V.dialog,children:[e.jsxs("div",{className:V.header,children:[e.jsx("h2",{id:"import-preview-title",className:V.title,children:"Import Preview"}),e.jsx("button",{className:V.closeButton,onClick:n,title:"Close","aria-label":"Close dialog",children:e.jsx(Ko,{})})]}),e.jsxs("div",{className:V.content,children:[e.jsx("div",{className:V.preview,children:r||e.jsx("div",{className:V.previewCanvas,children:"No preview available"})}),e.jsxs("div",{className:V.info,children:[e.jsxs("div",{className:V.section,children:[e.jsxs("h3",{className:V.sectionTitle,children:[e.jsx(Jo,{})," Import Statistics"]}),e.jsxs("div",{className:V.statGrid,children:[e.jsxs("div",{className:V.stat,children:[e.jsx("div",{className:V.statLabel,children:"Walls"}),e.jsx("div",{className:V.statValue,children:t.stats.wallsImported})]}),e.jsxs("div",{className:V.stat,children:[e.jsx("div",{className:V.statLabel,children:"Zones"}),e.jsx("div",{className:V.statValue,children:t.stats.zonesImported})]}),e.jsxs("div",{className:V.stat,children:[e.jsx("div",{className:V.statLabel,children:"Objects"}),e.jsx("div",{className:V.statValue,children:t.stats.objectsImported})]}),e.jsxs("div",{className:V.stat,children:[e.jsx("div",{className:V.statLabel,children:"Skipped"}),e.jsx("div",{className:V.statValue,children:t.stats.entitiesSkipped})]})]})]}),a&&a.layers.length>0&&e.jsxs("div",{className:V.section,children:[e.jsxs("h3",{className:V.sectionTitle,children:[e.jsx(Qt,{})," Layers (",a.layers.length,")"]}),e.jsxs("ul",{className:V.layersList,children:[a.layers.slice(0,6).map((d,x)=>{var v;return e.jsxs("li",{className:V.layer,children:[e.jsx("span",{className:V.layerIcon,children:e.jsx(Qt,{})}),e.jsx("span",{className:V.layerName,children:d.name}),e.jsx("span",{className:V.layerCount,children:((v=d.objects)==null?void 0:v.length)||0})]},d.id||x)}),a.layers.length>6&&e.jsx("li",{className:V.layer,children:e.jsxs("span",{className:V.layerName,children:["+",a.layers.length-6," more..."]})})]})]}),t.warnings.length>0&&e.jsxs("div",{className:V.section,children:[e.jsxs("h3",{className:V.sectionTitle,children:[e.jsx(Kt,{})," Warnings (",t.warnings.length,")"]}),e.jsxs("ul",{className:V.warningsList,children:[t.warnings.slice(0,5).map((d,x)=>e.jsxs("li",{className:V.warning,children:[e.jsx("span",{className:V.warningIcon,children:e.jsx(Kt,{})}),e.jsx("span",{children:d.message})]},x)),t.warnings.length>5&&e.jsxs("li",{className:V.warning,children:["+",t.warnings.length-5," more warnings..."]})]})]}),b.length>0&&e.jsxs("div",{className:V.section,children:[e.jsxs("h3",{className:V.sectionTitle,children:[e.jsx(Jt,{})," Errors (",b.length,")"]}),e.jsx("ul",{className:V.warningsList,children:b.slice(0,5).map((d,x)=>e.jsxs("li",{className:V.error,children:[e.jsx("span",{className:V.errorIcon,children:e.jsx(Jt,{})}),e.jsx("span",{children:d.message})]},x))})]}),t.warnings.length===0&&b.length===0&&e.jsx("div",{className:V.section,children:e.jsxs("p",{className:V.noWarnings,children:[e.jsx(z.NiceIcon,{name:"check",size:14})," No warnings or errors found"]})})]})]}),e.jsxs("div",{className:V.footer,children:[e.jsx("button",{className:V.cancelButton,onClick:n,children:"Cancel"}),e.jsx("button",{className:V.confirmButton,onClick:s,disabled:h,children:h?"Cannot Import (Fatal Errors)":"Confirm Import"})]})]})})}const ea="_overlay_332j1_9",ta="_dialog_332j1_55",sa="_header_332j1_103",na="_title_332j1_119",oa="_closeButton_332j1_133",aa="_content_332j1_167",ra="_description_332j1_179",ia="_mappingTable_332j1_191",ca="_sourceLayer_332j1_241",la="_layerIcon_332j1_253",da="_layerName_332j1_261",ua="_objectCount_332j1_273",ha="_targetSelect_332j1_285",ma="_skipOption_332j1_327",pa="_arrowIcon_332j1_337",_a="_presets_332j1_347",fa="_presetButton_332j1_361",ga="_footer_332j1_393",ya="_footerLeft_332j1_413",xa="_checkbox_332j1_425",ba="_checkboxLabel_332j1_437",va="_footerRight_332j1_447",ja="_cancelButton_332j1_457",wa="_confirmButton_332j1_489",oe={overlay:ea,dialog:ta,header:sa,title:na,closeButton:oa,content:aa,description:ra,mappingTable:ia,sourceLayer:ca,layerIcon:la,layerName:da,objectCount:ua,targetSelect:ha,skipOption:ma,arrowIcon:pa,presets:_a,presetButton:fa,footer:ga,footerLeft:ya,checkbox:xa,checkboxLabel:ba,footerRight:va,cancelButton:ja,confirmButton:wa},es=()=>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"})}),Na=()=>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"})}),ka=()=>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"})}),ts={"floor-plan":"Plan piętra",walls:"Ściany",rooms:"Pomieszczenia",zones:"Strefy","doors-windows":"Drzwi i okna",furniture:"Meble",devices:"Urządzenia",network:"Sieć",infrastructure:"Infrastruktura",electrical:"Elektryka",plumbing:"Hydraulika",hvac:"HVAC",annotations:"Adnotacje",dimensions:"Wymiary",grid:"Siatka",background:"Tło","game-objects":"Obiekty gry",collision:"Kolizje",custom:"Własne"};function Ia(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 Ca(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 ss(t,s){const n=new Map;for(const o of t){const a=s.find(l=>l.type===o.type);if(a){n.set(o.id,a.id);continue}const r=o.name.toLowerCase(),i=s.find(l=>l.name.toLowerCase()===r);if(i){n.set(o.id,i.id);continue}n.set(o.id,o.id)}return n}const Sa=({importResult:t,existingDocument:s,onConfirm:n,onCancel:o})=>{const a=u.useMemo(()=>Ia(t),[t]),r=u.useMemo(()=>Ca(s),[s]),[i,l]=u.useState(()=>ss(a,r)),[h,b]=u.useState(!0),d=u.useCallback((f,p)=>{l(C=>{const L=new Map(C);return L.set(f,p),L})},[]),x=u.useCallback(f=>{const p=new Map;switch(f){case"auto":l(ss(a,r));return;case"skip-all":for(const C of a)p.set(C.id,"skip");break;case"preserve":for(const C of a)p.set(C.id,C.id);break}l(p)},[a,r]),v=u.useCallback(()=>{n(i,h)},[i,h,n]),y=u.useCallback(f=>{f.key==="Escape"?o():f.key==="Enter"&&(f.ctrlKey||f.metaKey)&&v()},[o,v]),_=u.useCallback(f=>{f.target===f.currentTarget&&o()},[o]);return a.length===0?e.jsx("div",{className:oe.overlay,onClick:_,onKeyDown:y,tabIndex:-1,children:e.jsxs("div",{className:oe.dialog,children:[e.jsxs("div",{className:oe.header,children:[e.jsx("h2",{className:oe.title,children:"Mapowanie warstw"}),e.jsx("button",{className:oe.closeButton,onClick:o,children:e.jsx(es,{})})]}),e.jsx("div",{className:oe.content,children:e.jsx("p",{className:oe.description,children:"Importowany plik nie zawiera żadnych warstw."})}),e.jsxs("div",{className:oe.footer,children:[e.jsx("div",{className:oe.footerLeft}),e.jsx("div",{className:oe.footerRight,children:e.jsx("button",{className:oe.cancelButton,onClick:o,children:"Zamknij"})})]})]})}):e.jsx("div",{className:oe.overlay,onClick:_,onKeyDown:y,tabIndex:-1,children:e.jsxs("div",{className:oe.dialog,children:[e.jsxs("div",{className:oe.header,children:[e.jsx("h2",{className:oe.title,children:"Mapowanie warstw"}),e.jsx("button",{className:oe.closeButton,onClick:o,children:e.jsx(es,{})})]}),e.jsxs("div",{className:oe.content,children:[e.jsx("p",{className:oe.description,children:"Wybierz jak warstwy z importowanego pliku mają być przypisane do warstw w edytorze."}),e.jsxs("table",{className:oe.mappingTable,children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Warstwa źródłowa"}),e.jsx("th",{}),e.jsx("th",{children:"Warstwa docelowa"})]})}),e.jsx("tbody",{children:a.map(f=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsxs("div",{className:oe.sourceLayer,children:[e.jsx("span",{className:oe.layerIcon,children:e.jsx(Na,{})}),e.jsx("span",{className:oe.layerName,children:f.name}),e.jsxs("span",{className:oe.objectCount,children:["(",f.objectCount," ",f.objectCount===1?"obiekt":"obiektów",")"]})]})}),e.jsx("td",{className:oe.arrowIcon,children:e.jsx(ka,{})}),e.jsx("td",{children:e.jsxs("select",{className:oe.targetSelect,value:i.get(f.id)||f.id,onChange:p=>d(f.id,p.target.value),children:[e.jsx("option",{value:"skip",className:oe.skipOption,children:"— Pomiń tę warstwę —"}),e.jsxs("option",{value:f.id,children:["Utwórz: ",f.name," (",ts[f.type],")"]}),r.map(p=>e.jsxs("option",{value:p.id,children:[p.name," (",ts[p.type],")"]},p.id))]})})]},f.id))})]}),e.jsxs("div",{className:oe.presets,children:[e.jsx("button",{className:oe.presetButton,onClick:()=>x("auto"),children:"Auto-mapowanie"}),e.jsx("button",{className:oe.presetButton,onClick:()=>x("preserve"),children:"Zachowaj wszystkie"}),e.jsx("button",{className:oe.presetButton,onClick:()=>x("skip-all"),children:"Pomiń wszystkie"})]})]}),e.jsxs("div",{className:oe.footer,children:[e.jsxs("div",{className:oe.footerLeft,children:[e.jsx("input",{type:"checkbox",id:"createMissing",className:oe.checkbox,checked:h,onChange:f=>b(f.target.checked)}),e.jsx("label",{htmlFor:"createMissing",className:oe.checkboxLabel,children:"Utwórz brakujące warstwy"})]}),e.jsxs("div",{className:oe.footerRight,children:[e.jsx("button",{className:oe.cancelButton,onClick:o,children:"Anuluj"}),e.jsx("button",{className:oe.confirmButton,onClick:v,children:"Zastosuj mapowanie"})]})]})]})})},za="_root_4ino1_9",La="_header_4ino1_21",$a="_title_4ino1_31",Ta="_layerList_4ino1_45",Ma="_layerItem_4ino1_55",Ba="_hidden_4ino1_83",Pa="_locked_4ino1_91",Ea="_visibilityBtn_4ino1_99",Oa="_lockBtn_4ino1_101",Aa="_layerIcon_4ino1_139",Da="_layerName_4ino1_147",Ra="_opacitySlider_4ino1_157",Ie={root:za,header:La,title:$a,layerList:Ta,layerItem:Ma,hidden:Ba,locked:Pa,visibilityBtn:Ea,lockBtn:Oa,layerIcon:Aa,layerName:Da,opacitySlider:Ra},Fa={"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"}},xs=({layers:t,onVisibilityToggle:s,onLockToggle:n,onOpacityChange:o,className:a})=>{const r=[...t].sort((i,l)=>l.zIndex-i.zIndex);return e.jsxs("div",{className:`${Ie.root} ${a??""}`,children:[e.jsx("div",{className:Ie.header,children:e.jsx("h3",{className:Ie.title,children:"Layers"})}),e.jsx("div",{className:Ie.layerList,children:r.map(i=>{const l=Fa[i.type]||{icon:"box",label:i.type};return e.jsxs("div",{className:`${Ie.layerItem} ${i.visible?"":Ie.hidden} ${i.locked?Ie.locked:""}`,children:[e.jsx("button",{className:Ie.visibilityBtn,onClick:()=>s(i.type),title:i.visible?"Hide layer":"Show layer",children:e.jsx(z.NiceIcon,{name:i.visible?"eye":"eye-off",size:16})}),e.jsx("button",{className:Ie.lockBtn,onClick:()=>n(i.type),title:i.locked?"Unlock layer":"Lock layer",children:e.jsx(z.NiceIcon,{name:"lock",size:16})}),e.jsx("span",{className:Ie.layerIcon,children:e.jsx(z.NiceIcon,{name:l.icon,size:16})}),e.jsx("span",{className:Ie.layerName,children:l.label}),e.jsx("input",{type:"range",min:"0",max:"1",step:"0.1",value:i.opacity,onChange:h=>o(i.type,parseFloat(h.target.value)),className:Ie.opacitySlider,title:`Opacity: ${Math.round(i.opacity*100)}%`})]},i.type)})})]})},Wa="_root_1lufq_9",Ga="_svg_1lufq_31",qa="_viewportRect_1lufq_41",Va="_zoomIndicator_1lufq_49",ht={root:Wa,svg:Ga,viewportRect:qa,zoomIndicator:Va},bs=({document:t,activeFloorId:s,viewport:n,onViewportChange:o,size:a=150,className:r})=>{var I,k;const i=u.useRef(null),l=u.useMemo(()=>t.floors.find(c=>c.id===s)??t.floors[0]??null,[t,s]);if(!l)return null;const h=((I=l.dimensions)==null?void 0:I.width)??1e3,b=((k=l.dimensions)==null?void 0:k.height)??800,d=Math.min(a/h,a/b)*.9,x=h*d,v=b*d,y=a/n.zoom*d,_=a/n.zoom*d,f=-n.pan.x/n.zoom*d,p=-n.pan.y/n.zoom*d,C=u.useCallback(c=>{var de;const g=(de=i.current)==null?void 0:de.getBoundingClientRect();if(!g)return;const m=(c.clientX-g.left-(a-x)/2)/d,j=(c.clientY-g.top-(a-v)/2)/d,E=-(m-a/n.zoom/2)*n.zoom,F=-(j-a/n.zoom/2)*n.zoom;o({pan:{x:E,y:F}})},[d,a,x,v,n.zoom,o]),L=u.useMemo(()=>{const c=l.layers.find(g=>g.name==="zones");return c?c.objects.map(g=>{const m=g;if(!m.polygon||m.polygon.length<3)return null;const j=m.polygon.map((E,F)=>`${F===0?"M":"L"}${E.x*d},${E.y*d}`).join(" ")+" Z";return e.jsx("path",{d:j,fill:m.color??"var(--nice-primary-bg, #dbeafe)",fillOpacity:.6,stroke:"var(--nice-text-muted, #94a3b8)",strokeWidth:.5},m.id)}):null},[l,d]);return e.jsxs("div",{className:`${ht.root} ${r??""}`,children:[e.jsxs("svg",{ref:i,width:a,height:a,viewBox:`0 0 ${a} ${a}`,className:ht.svg,onClick:C,children:[e.jsx("rect",{x:(a-x)/2,y:(a-v)/2,width:x,height:v,fill:"var(--nice-text, #1e293b)",stroke:"var(--nice-text-secondary, #475569)",strokeWidth:1}),e.jsx("g",{transform:`translate(${(a-x)/2}, ${(a-v)/2})`,children:L}),e.jsx("rect",{x:(a-x)/2+f,y:(a-v)/2+p,width:Math.min(y,x),height:Math.min(_,v),fill:"var(--nice-primary-tint-20, rgba(59, 130, 246, 0.2))",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:1.5,rx:2,className:ht.viewportRect})]}),e.jsxs("div",{className:ht.zoomIndicator,children:[Math.round(n.zoom*100),"%"]})]})},Ua="_panel_716sa_9",Ha="_header_716sa_27",Ya="_title_716sa_45",Za="_closeButton_716sa_59",Xa="_content_716sa_85",Ka="_endpointSection_716sa_99",Ja="_endpointLabel_716sa_107",Qa="_endpointSelect_716sa_123",er="_optionsSection_716sa_157",tr="_metricButton_716sa_169",sr="_metricButtonActive_716sa_205",nr="_analyzeButton_716sa_219",or="_resultsSection_716sa_267",ar="_resultsTitle_716sa_277",rr="_noResults_716sa_293",ir="_pathCard_716sa_309",cr="_pathCardSelected_716sa_333",lr="_pathCardHeader_716sa_343",dr="_pathCardTitle_716sa_361",ur="_pathBadge_716sa_373",hr="_badgePrimary_716sa_389",mr="_badgeAlternate_716sa_399",pr="_pathName_716sa_409",_r="_pathStatus_716sa_421",fr="_statusDot_716sa_435",gr="_statusActive_716sa_447",yr="_statusDegraded_716sa_453",xr="_statusInactive_716sa_459",br="_statusError_716sa_465",vr="_pathStats_716sa_475",jr="_statItem_716sa_489",wr="_statValue_716sa_497",Nr="_statLabel_716sa_509",kr="_pathVisualization_716sa_523",Ir="_pathDiagram_716sa_535",Cr="_pathNode_716sa_551",Sr="_pathNodeStart_716sa_583",zr="_pathNodeEnd_716sa_585",Lr="_pathLink_716sa_595",$r="_pathLinkLine_716sa_607",Tr="_showOnMapButton_716sa_621",Mr="_loading_716sa_657",Br="_spinner_716sa_671",Pr="_spin_716sa_671",G={panel:Ua,header:Ha,title:Ya,closeButton:Za,content:Xa,endpointSection:Ka,endpointLabel:Ja,endpointSelect:Qa,optionsSection:er,metricButton:tr,metricButtonActive:sr,analyzeButton:nr,resultsSection:or,resultsTitle:ar,noResults:rr,pathCard:ir,pathCardSelected:cr,pathCardHeader:lr,pathCardTitle:dr,pathBadge:ur,badgePrimary:hr,badgeAlternate:mr,pathName:pr,pathStatus:_r,statusDot:fr,statusActive:gr,statusDegraded:yr,statusInactive:xr,statusError:br,pathStats:vr,statItem:jr,statValue:wr,statLabel:Nr,pathVisualization:kr,pathDiagram:Ir,pathNode:Cr,pathNodeStart:Sr,pathNodeEnd:zr,pathLink:Lr,pathLinkLine:$r,showOnMapButton:Tr,loading:Mr,spinner:Br,spin:Pr},Er=()=>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"})}),Or=()=>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 Ar(t){switch(t){case"active":return"Aktywna";case"degraded":return"Degradacja";case"inactive":return"Nieaktywna";case"error":return"Błąd";default:return"Nieznany"}}function Dr(t){return t<1?"<1ms":t<1e3?`${Math.round(t)}ms`:`${(t/1e3).toFixed(1)}s`}function Rr(t){return t>=1e3?`${(t/1e3).toFixed(1)} Gbps`:`${Math.round(t)} Mbps`}const Fr=({document:t,connections:s,onHighlightPath:n,onClose:o})=>{const[a,r]=u.useState(""),[i,l]=u.useState(""),[h,b]=u.useState("latency"),[d,x]=u.useState([]),[v,y]=u.useState(null),[_,f]=u.useState(!1),p=u.useMemo(()=>{const c=[];for(const g of t.floors)for(const m of g.layers)if(m.type==="network"||m.type==="devices"||m.type==="infrastructure")for(const j of m.objects)c.push({id:j.id,name:j.name??j.id});return c},[t]),C=u.useCallback(c=>{var g;return((g=p.find(m=>m.id===c))==null?void 0:g.name)??c},[p]),L=u.useCallback(()=>{!a||!i||a===i||(f(!0),x([]),y(null),setTimeout(()=>{const c=to(s,a,i,h),g=so(s,a,i,5),m=[];c&&m.push(c);for(const j of g)m.some(E=>E.connectionIds.length===j.connectionIds.length&&E.connectionIds.every((F,de)=>j.connectionIds[de]===F))||m.push({...j,isPrimary:!1});x(m),m.length>0&&(y(m[0].id),n==null||n(m[0])),f(!1)},300))},[a,i,h,s,n]),I=u.useCallback(c=>{y(c.id),n==null||n(c)},[n]),k=u.useCallback(c=>{const g=[c.startDeviceId];for(const m of c.connectionIds){const j=s.find(E=>E.id===m);if(j){const E=g[g.length-1],F=j.sourceId===E?j.targetId:j.sourceId;g.includes(F)||g.push(F)}}return g},[s]);return e.jsxs("div",{className:G.panel,children:[e.jsxs("div",{className:G.header,children:[e.jsx("h3",{className:G.title,children:"Analiza ścieżki sieciowej"}),o&&e.jsx("button",{className:G.closeButton,onClick:o,children:e.jsx(Er,{})})]}),e.jsxs("div",{className:G.content,children:[e.jsxs("div",{className:G.endpointSection,children:[e.jsx("label",{className:G.endpointLabel,children:"Urządzenie źródłowe"}),e.jsxs("select",{className:G.endpointSelect,value:a,onChange:c=>r(c.target.value),children:[e.jsx("option",{value:"",children:"— Wybierz urządzenie —"}),p.map(c=>e.jsx("option",{value:c.id,children:c.name},c.id))]})]}),e.jsxs("div",{className:G.endpointSection,children:[e.jsx("label",{className:G.endpointLabel,children:"Urządzenie docelowe"}),e.jsxs("select",{className:G.endpointSelect,value:i,onChange:c=>l(c.target.value),children:[e.jsx("option",{value:"",children:"— Wybierz urządzenie —"}),p.filter(c=>c.id!==a).map(c=>e.jsx("option",{value:c.id,children:c.name},c.id))]})]}),e.jsxs("div",{className:G.optionsSection,children:[e.jsx("button",{className:`${G.metricButton} ${h==="latency"?G.metricButtonActive:""}`,onClick:()=>b("latency"),children:"Latencja"}),e.jsx("button",{className:`${G.metricButton} ${h==="hops"?G.metricButtonActive:""}`,onClick:()=>b("hops"),children:"Hops"}),e.jsx("button",{className:`${G.metricButton} ${h==="bandwidth"?G.metricButtonActive:""}`,onClick:()=>b("bandwidth"),children:"Przepustowość"})]}),e.jsx("button",{className:G.analyzeButton,onClick:L,disabled:!a||!i||a===i||_,children:_?"Analizowanie...":"Analizuj ścieżkę"}),_?e.jsx("div",{className:G.loading,children:e.jsx("div",{className:G.spinner})}):d.length>0?e.jsxs("div",{className:G.resultsSection,children:[e.jsxs("div",{className:G.resultsTitle,children:["Znalezione ścieżki (",d.length,")"]}),d.map((c,g)=>{const m=k(c),j=v===c.id;return e.jsxs("div",{className:`${G.pathCard} ${j?G.pathCardSelected:""}`,onClick:()=>I(c),children:[e.jsxs("div",{className:G.pathCardHeader,children:[e.jsxs("div",{className:G.pathCardTitle,children:[e.jsx("span",{className:`${G.pathBadge} ${c.isPrimary?G.badgePrimary:G.badgeAlternate}`,children:c.isPrimary?"Optymalna":`Alt ${g}`}),e.jsxs("span",{className:G.pathName,children:[c.connectionIds.length," połączeń"]})]}),e.jsxs("div",{className:G.pathStatus,children:[e.jsx("span",{className:`${G.statusDot} ${G[`status${c.status.charAt(0).toUpperCase()+c.status.slice(1)}`]??""}`}),e.jsx("span",{children:Ar(c.status)})]})]}),e.jsxs("div",{className:G.pathStats,children:[e.jsxs("div",{className:G.statItem,children:[e.jsx("div",{className:G.statValue,children:Dr(c.totalLatency)}),e.jsx("div",{className:G.statLabel,children:"Latencja"})]}),e.jsxs("div",{className:G.statItem,children:[e.jsx("div",{className:G.statValue,children:c.connectionIds.length}),e.jsx("div",{className:G.statLabel,children:"Hops"})]}),e.jsxs("div",{className:G.statItem,children:[e.jsx("div",{className:G.statValue,children:c.bottleneckBandwidth>0?Rr(c.bottleneckBandwidth):"N/A"}),e.jsx("div",{className:G.statLabel,children:"Przepustowość"})]})]}),j&&e.jsxs("div",{className:G.pathVisualization,children:[e.jsx("div",{className:G.pathDiagram,children:m.map((E,F)=>e.jsxs(u.Fragment,{children:[e.jsx("div",{className:`${G.pathNode} ${F===0?G.pathNodeStart:F===m.length-1?G.pathNodeEnd:""}`,children:C(E).substring(0,8)}),F<m.length-1&&e.jsxs("div",{className:G.pathLink,children:[e.jsx("div",{className:G.pathLinkLine}),e.jsx(Or,{})]})]},E))}),e.jsx("button",{className:G.showOnMapButton,onClick:E=>{E.stopPropagation(),n==null||n(c)},children:"Pokaż na mapie"})]})]},c.id)})]}):a&&i&&a!==i?e.jsx("div",{className:G.noResults,children:'Wybierz urządzenia i kliknij „Analizuj ścieżkę"'}):e.jsx("div",{className:G.noResults,children:"Wybierz urządzenie źródłowe i docelowe"})]})]})},Wr="_root_6pirz_9",Gr="_header_6pirz_27",qr="_title_6pirz_37",Vr="_search_6pirz_51",Ur="_categories_6pirz_79",Hr="_category_6pirz_91",Yr="_categoryHeader_6pirz_107",Zr="_categoryIcon_6pirz_143",Xr="_categoryLabel_6pirz_151",Kr="_categoryCount_6pirz_161",Jr="_expandIcon_6pirz_171",Qr="_items_6pirz_181",ei="_item_6pirz_181",ti="_itemIcon_6pirz_241",si="_itemName_6pirz_249",ni="_emptyState_6pirz_269",ve={root:Wr,header:Gr,title:qr,search:Vr,categories:Ur,category:Hr,categoryHeader:Yr,categoryIcon:Zr,categoryLabel:Xr,categoryCount:Kr,expandIcon:Jr,items:Qr,item:ei,itemIcon:ti,itemName:si,emptyState:ni},oi={"💡":"lightbulb","🔆":"lightbulb","🌈":"lightbulb","🌡️":"thermometer","❄️":"thermometer","💨":"wifi","📷":"camera","🔔":"bell","🔒":"lock","👁️":"eye","🚪":"door","🔊":"wifi","🗣️":"mic","📺":"monitor","📡":"wifi","🔌":"plug","🛡️":"lock","📶":"wifi","🖥️":"monitor","💾":"database","🗄️":"server","🔋":"zap","⚡":"zap","🧱":"square","🪟":"window","🪜":"stairs","🎯":"target","🏁":"target","📦":"box","👾":"gamepad","🛗":"elevator","🛏️":"bed","🛏":"bed","🛋️":"sofa","🛋":"sofa","🪑":"chair","🍽️":"utensils","🍽":"utensils"},ai=t=>t&&oi[t]||"box",ri={"floor-plan":["smart-home","building"],"network-topology":["network"],infrastructure:["infrastructure","network"],cad:["building"],interior:["furniture","smart-home"],"game-scene":["game"]},ii={"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"}},vs=({mode:t,onObjectSelect:s,customObjects:n=[],className:o})=>{const[a,r]=u.useState(""),[i,l]=u.useState(new Set(["smart-home","furniture","network"])),h=ri[t]||[],b=u.useMemo(()=>{const v={},y=Dn.reduce((_,f)=>{var p;return(_[p=f.category]??(_[p]=[])).push(f),_},{});return Object.entries(y).forEach(([_,f])=>{if(!h.includes(_))return;const p=f.filter(C=>!a||C.name.toLowerCase().includes(a.toLowerCase()));p.length>0&&(v[_]=p.map(C=>({id:C.id,name:C.name,category:_,icon:C.icon})))}),n.forEach(_=>{h.includes(_.category)&&(!a||_.name.toLowerCase().includes(a.toLowerCase()))&&(v[_.category]||(v[_.category]=[]),v[_.category].push(_))}),v},[h,a,n]),d=v=>{l(y=>{const _=new Set(y);return _.has(v)?_.delete(v):_.add(v),_})},x=(v,y)=>{v.dataTransfer.setData("application/json",JSON.stringify(y)),v.dataTransfer.effectAllowed="copy"};return e.jsxs("div",{className:`${ve.root} ${o??""}`,children:[e.jsxs("div",{className:ve.header,children:[e.jsx("h3",{className:ve.title,children:"Objects"}),e.jsx("input",{type:"text",className:ve.search,placeholder:"Search...",value:a,onChange:v=>r(v.target.value)})]}),e.jsxs("div",{className:ve.categories,children:[Object.entries(b).map(([v,y])=>{const _=ii[v]||{icon:"box",label:v},f=i.has(v);return e.jsxs("div",{className:ve.category,children:[e.jsxs("button",{className:ve.categoryHeader,onClick:()=>d(v),children:[e.jsx("span",{className:ve.categoryIcon,children:e.jsx(z.NiceIcon,{name:_.icon,size:16})}),e.jsx("span",{className:ve.categoryLabel,children:_.label}),e.jsxs("span",{className:ve.categoryCount,children:["(",y.length,")"]}),e.jsx("span",{className:ve.expandIcon,children:e.jsx(z.NiceIcon,{name:f?"chevron-down":"chevron-right",size:14})})]}),f&&e.jsx("div",{className:ve.items,children:y.map(p=>e.jsxs("div",{className:ve.item,draggable:!0,onDragStart:C=>x(C,p),onClick:()=>s(p),title:p.name,children:[e.jsx("span",{className:ve.itemIcon,children:e.jsx(z.NiceIcon,{name:ai(p.icon),size:16})}),e.jsx("span",{className:ve.itemName,children:p.name})]},p.id))})]},v)}),Object.keys(b).length===0&&e.jsx("div",{className:ve.emptyState,children:a?`No objects matching "${a}"`:"No objects available for this mode"})]})]})},ci="_root_o3eqo_9",li="_header_o3eqo_23",di="_title_o3eqo_39",ui="_multiSelect_o3eqo_53",hi="_content_o3eqo_63",mi="_section_o3eqo_73",pi="_sectionHeader_o3eqo_89",_i="_sectionContent_o3eqo_127",fi="_fieldRow_o3eqo_135",gi="_fieldLabel_o3eqo_157",yi="_textInput_o3eqo_169",xi="_numberInput_o3eqo_171",bi="_select_o3eqo_173",vi="_checkbox_o3eqo_215",ji="_colorInput_o3eqo_227",wi="_readOnly_o3eqo_245",Ni="_emptyState_o3eqo_263",se={root:ci,header:li,title:di,multiSelect:ui,content:hi,section:mi,sectionHeader:pi,sectionContent:_i,fieldRow:fi,fieldLabel:gi,textInput:yi,numberInput:xi,select:bi,checkbox:vi,colorInput:ji,readOnly:wi,emptyState:Ni},Et=[{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"}],ki=[{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}],Ii=[{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"}]}],js=({selection:t,document:s,onPropertyChange:n,className:o})=>{const[a,r]=u.useState(new Set(["general","position","appearance"])),i=t.objectIds.map(y=>{for(const _ of s.floors)for(const f of _.layers){const p=f.objects.find(C=>C.id===y);if(p)return p}return null}).filter(Boolean),l=y=>{r(_=>{const f=new Set(_);return f.has(y)?f.delete(y):f.add(y),f})},h=u.useCallback((y,_)=>{const f=_.split(".");let p=y;for(const C of f)if(p&&typeof p=="object"&&C in p)p=p[C];else return;return p},[]),b=u.useCallback((y,_)=>{var p;const f=h(_,y.key);switch(y.type){case"text":return e.jsx("input",{type:"text",value:String(f??""),onChange:C=>n(_.id,y.key,C.target.value),className:se.textInput});case"number":return e.jsx("input",{type:"number",value:Number(f??0),min:y.min,max:y.max,step:y.step,onChange:C=>n(_.id,y.key,parseFloat(C.target.value)),className:se.numberInput});case"boolean":return e.jsx("input",{type:"checkbox",checked:!!f,onChange:C=>n(_.id,y.key,C.target.checked),className:se.checkbox});case"color":return e.jsx("input",{type:"color",value:String(f??"var(--nice-bg, #fff)"),onChange:C=>n(_.id,y.key,C.target.value),className:se.colorInput});case"select":return e.jsx("select",{value:String(f??""),onChange:C=>n(_.id,y.key,C.target.value),className:se.select,children:(p=y.options)==null?void 0:p.map(C=>e.jsx("option",{value:C.value,children:C.label},C.value))});default:return e.jsx("span",{children:String(f??"-")})}},[h,n]);if(i.length===0)return e.jsxs("div",{className:`${se.root} ${o??""}`,children:[e.jsx("div",{className:se.header,children:e.jsx("h3",{className:se.title,children:"Properties"})}),e.jsx("div",{className:se.emptyState,children:"No object selected"})]});const d=i[0],x=i.length>1,v=d.category==="zone"?ki:["smart-home","network","infrastructure"].includes(d.category??"")?Ii:[];return e.jsxs("div",{className:`${se.root} ${o??""}`,children:[e.jsxs("div",{className:se.header,children:[e.jsx("h3",{className:se.title,children:"Properties"}),x&&e.jsxs("span",{className:se.multiSelect,children:[i.length," selected"]})]}),e.jsxs("div",{className:se.content,children:[e.jsxs("div",{className:se.section,children:[e.jsxs("button",{className:se.sectionHeader,onClick:()=>l("general"),children:[e.jsx("span",{children:e.jsx(z.NiceIcon,{name:a.has("general")?"chevron-down":"chevron-right",size:14})}),e.jsx("span",{children:"General"})]}),a.has("general")&&e.jsxs("div",{className:se.sectionContent,children:[Et.slice(0,1).map(y=>e.jsxs("div",{className:se.fieldRow,children:[e.jsx("label",{className:se.fieldLabel,children:y.label}),b(y,d)]},y.key)),e.jsxs("div",{className:se.fieldRow,children:[e.jsx("label",{className:se.fieldLabel,children:"ID"}),e.jsx("span",{className:se.readOnly,children:d.id})]}),e.jsxs("div",{className:se.fieldRow,children:[e.jsx("label",{className:se.fieldLabel,children:"Category"}),e.jsx("span",{className:se.readOnly,children:d.category})]})]})]}),e.jsxs("div",{className:se.section,children:[e.jsxs("button",{className:se.sectionHeader,onClick:()=>l("position"),children:[e.jsx("span",{children:e.jsx(z.NiceIcon,{name:a.has("position")?"chevron-down":"chevron-right",size:14})}),e.jsx("span",{children:"Transform"})]}),a.has("position")&&e.jsx("div",{className:se.sectionContent,children:Et.slice(1,4).map(y=>e.jsxs("div",{className:se.fieldRow,children:[e.jsx("label",{className:se.fieldLabel,children:y.label}),b(y,d)]},y.key))})]}),v.length>0&&e.jsxs("div",{className:se.section,children:[e.jsxs("button",{className:se.sectionHeader,onClick:()=>l("appearance"),children:[e.jsx("span",{children:e.jsx(z.NiceIcon,{name:a.has("appearance")?"chevron-down":"chevron-right",size:14})}),e.jsx("span",{children:"Appearance"})]}),a.has("appearance")&&e.jsx("div",{className:se.sectionContent,children:v.map(y=>e.jsxs("div",{className:se.fieldRow,children:[e.jsx("label",{className:se.fieldLabel,children:y.label}),b(y,d)]},y.key))})]}),e.jsxs("div",{className:se.section,children:[e.jsxs("button",{className:se.sectionHeader,onClick:()=>l("visibility"),children:[e.jsx("span",{children:e.jsx(z.NiceIcon,{name:a.has("visibility")?"chevron-down":"chevron-right",size:14})}),e.jsx("span",{children:"Visibility"})]}),a.has("visibility")&&e.jsx("div",{className:se.sectionContent,children:Et.slice(4).map(y=>e.jsxs("div",{className:se.fieldRow,children:[e.jsx("label",{className:se.fieldLabel,children:y.label}),b(y,d)]},y.key))})]})]})]})},Ci="_panel_62set_9",Si="_header_62set_33",zi="_headerTitle_62set_51",Li="_title_62set_65",$i="_closeButton_62set_79",Ti="_summarySection_62set_111",Mi="_summaryStats_62set_129",Bi="_statBadge_62set_141",Pi="_statValue_62set_155",Ei="_statLabel_62set_167",Oi="_visibilityControls_62set_183",Ai="_visibilityLabel_62set_201",Di="_visibilityButtons_62set_211",Ri="_visibilityBtn_62set_221",Fi="_active_62set_251",Wi="_content_62set_265",Gi="_emptyState_62set_279",qi="_emptyHint_62set_325",Vi="_vlanList_62set_337",Ui="_vlanCard_62set_351",Hi="_highlighted_62set_377",Yi="_hidden_62set_387",Zi="_vlanHeader_62set_395",Xi="_colorIndicator_62set_421",Ki="_vlanInfo_62set_435",Ji="_vlanName_62set_445",Qi="_vlanId_62set_459",ec="_vlanNameText_62set_471",tc="_vlanSubnet_62set_487",sc="_vlanStats_62set_503",nc="_chipStat_62set_515",oc="_vlanActions_62set_545",ac="_iconBtn_62set_557",rc="_inactive_62set_595",ic="_expanded_62set_611",cc="_vlanDetails_62set_623",lc="_detailRow_62set_635",dc="_detailLabel_62set_657",uc="_detailValue_62set_675",hc="_badge_62set_687",mc="_badgeSuccess_62set_701",pc="_badgeNeutral_62set_711",_c="_deviceList_62set_723",fc="_deviceItems_62set_731",gc="_deviceItem_62set_731",yc="_deviceDot_62set_765",xc="_deviceMore_62set_779",bc="_highlightButton_62set_795",vc="_footer_62set_835",jc="_legendTitle_62set_847",wc="_legend_62set_847",Nc="_legendItem_62set_875",kc="_legendColor_62set_887",Ic="_legendLabel_62set_901",P={panel:Ci,header:Si,headerTitle:zi,title:Li,closeButton:$i,summarySection:Ti,summaryStats:Mi,statBadge:Bi,statValue:Pi,statLabel:Ei,visibilityControls:Oi,visibilityLabel:Ai,visibilityButtons:Di,visibilityBtn:Ri,active:Fi,content:Wi,emptyState:Gi,emptyHint:qi,vlanList:Vi,vlanCard:Ui,highlighted:Hi,hidden:Yi,vlanHeader:Zi,colorIndicator:Xi,vlanInfo:Ki,vlanName:Ji,vlanId:Qi,vlanNameText:ec,vlanSubnet:tc,vlanStats:sc,chipStat:nc,vlanActions:oc,iconBtn:ac,inactive:rc,expanded:ic,vlanDetails:cc,detailRow:lc,detailLabel:dc,detailValue:uc,badge:hc,badgeSuccess:mc,badgeNeutral:pc,deviceList:_c,deviceItems:fc,deviceItem:gc,deviceDot:yc,deviceMore:xc,highlightButton:bc,footer:vc,legendTitle:jc,legend:wc,legendItem:Nc,legendColor:kc,legendLabel:Ic},Cc=()=>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"})}),Sc=()=>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"})]}),zc=()=>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"})]}),ns=()=>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"})]}),Lc=()=>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 $c(t){var s;return((s=t.deviceIds)==null?void 0:s.length)??0}function Tc(t,s){return s.filter(n=>n.vlanId===t.id).length}function Mc(t){return t||"—"}const Bc=({document:t,connections:s,vlans:n,visibleVlanIds:o,onVlanVisibilityChange:a,onHighlightVlan:r,onClose:i})=>{const[l,h]=u.useState(null),[b,d]=u.useState(null),x=u.useMemo(()=>[...n].sort((I,k)=>I.id-k.id),[n]),v=u.useMemo(()=>{const I=new Set,k=new Set;for(const c of n)for(const g of c.deviceIds??[])I.add(g);for(const c of s)c.vlanId!==void 0&&k.add(c.id);return{vlanCount:n.length,deviceCount:I.size,connectionCount:k.size}},[n,s]),y=u.useCallback(I=>{const k=o.has(I);a==null||a(I,!k)},[o,a]),_=u.useCallback(I=>{for(const k of n)a==null||a(k.id,I)},[n,a]),f=u.useCallback(I=>{h((I==null?void 0:I.id)??null),r==null||r(I)},[r]),p=u.useCallback(I=>{d(k=>k===I?null:I)},[]),C=u.useCallback(I=>{const k=[];for(const c of I.deviceIds??[])for(const g of t.floors)for(const m of g.layers){const j=m.objects.find(E=>E.id===c);j&&k.push({id:c,name:j.name??c})}return k},[t]),L=u.useMemo(()=>{const I=n.filter(k=>o.has(k.id)).length;return{visible:I,total:n.length,allVisible:I===n.length,noneVisible:I===0}},[n,o]);return e.jsxs("div",{className:P.panel,children:[e.jsxs("div",{className:P.header,children:[e.jsxs("div",{className:P.headerTitle,children:[e.jsx(ns,{}),e.jsx("h3",{className:P.title,children:"Nakładka VLAN"})]}),i&&e.jsx("button",{className:P.closeButton,onClick:i,title:"Zamknij",children:e.jsx(Cc,{})})]}),e.jsx("div",{className:P.summarySection,children:e.jsxs("div",{className:P.summaryStats,children:[e.jsxs("div",{className:P.statBadge,children:[e.jsx("span",{className:P.statValue,children:v.vlanCount}),e.jsx("span",{className:P.statLabel,children:"VLAN"})]}),e.jsxs("div",{className:P.statBadge,children:[e.jsx("span",{className:P.statValue,children:v.deviceCount}),e.jsx("span",{className:P.statLabel,children:"Urządzeń"})]}),e.jsxs("div",{className:P.statBadge,children:[e.jsx("span",{className:P.statValue,children:v.connectionCount}),e.jsx("span",{className:P.statLabel,children:"Połączeń"})]})]})}),e.jsxs("div",{className:P.visibilityControls,children:[e.jsxs("span",{className:P.visibilityLabel,children:["Widoczność: ",L.visible,"/",L.total]}),e.jsxs("div",{className:P.visibilityButtons,children:[e.jsx("button",{className:`${P.visibilityBtn} ${L.allVisible?P.active:""}`,onClick:()=>_(!0),title:"Pokaż wszystkie",children:"Wszystkie"}),e.jsx("button",{className:`${P.visibilityBtn} ${L.noneVisible?P.active:""}`,onClick:()=>_(!1),title:"Ukryj wszystkie",children:"Żaden"})]})]}),e.jsx("div",{className:P.content,children:x.length===0?e.jsxs("div",{className:P.emptyState,children:[e.jsx(ns,{}),e.jsx("p",{children:"Brak zdefiniowanych VLAN-ów"}),e.jsx("span",{className:P.emptyHint,children:"Dodaj VLAN w trybie network-topology lub infrastructure"})]}):e.jsx("div",{className:P.vlanList,children:x.map(I=>{const k=o.has(I.id),c=l===I.id,g=b===I.id,m=$c(I),j=Tc(I,s),E=g?C(I):[];return e.jsxs("div",{className:`${P.vlanCard} ${c?P.highlighted:""} ${k?"":P.hidden}`,onMouseEnter:()=>f(I),onMouseLeave:()=>f(null),children:[e.jsxs("div",{className:P.vlanHeader,children:[e.jsx("div",{className:P.colorIndicator,style:{backgroundColor:I.color}}),e.jsxs("div",{className:P.vlanInfo,children:[e.jsxs("div",{className:P.vlanName,children:[e.jsxs("span",{className:P.vlanId,children:["VLAN ",I.id]}),I.name&&e.jsx("span",{className:P.vlanNameText,children:I.name})]}),I.subnet&&e.jsx("div",{className:P.vlanSubnet,children:Mc(I.subnet)})]}),e.jsxs("div",{className:P.vlanStats,children:[e.jsx("span",{className:P.chipStat,title:"Urządzenia",children:m}),e.jsx("span",{className:P.chipStat,title:"Połączenia",children:j})]}),e.jsxs("div",{className:P.vlanActions,children:[e.jsx("button",{className:`${P.iconBtn} ${k?"":P.inactive}`,onClick:F=>{F.stopPropagation(),y(I.id)},title:k?"Ukryj VLAN":"Pokaż VLAN",children:k?e.jsx(Sc,{}):e.jsx(zc,{})}),e.jsx("button",{className:`${P.iconBtn} ${g?P.expanded:""}`,onClick:F=>{F.stopPropagation(),p(I.id)},title:"Szczegóły",children:e.jsx(Lc,{})})]})]}),g&&e.jsxs("div",{className:P.vlanDetails,children:[I.description&&e.jsxs("div",{className:P.detailRow,children:[e.jsx("span",{className:P.detailLabel,children:"Opis:"}),e.jsx("span",{className:P.detailValue,children:I.description})]}),I.subnet&&e.jsxs("div",{className:P.detailRow,children:[e.jsx("span",{className:P.detailLabel,children:"Podsieć:"}),e.jsx("span",{className:P.detailValue,children:I.subnet})]}),I.gateway&&e.jsxs("div",{className:P.detailRow,children:[e.jsx("span",{className:P.detailLabel,children:"Brama:"}),e.jsx("span",{className:P.detailValue,children:I.gateway})]}),e.jsxs("div",{className:P.detailRow,children:[e.jsx("span",{className:P.detailLabel,children:"DHCP:"}),e.jsx("span",{className:`${P.detailValue} ${P.badge} ${I.dhcpEnabled?P.badgeSuccess:P.badgeNeutral}`,children:I.dhcpEnabled?"Włączone":"Wyłączone"})]}),E.length>0&&e.jsxs("div",{className:P.deviceList,children:[e.jsxs("span",{className:P.detailLabel,children:["Urządzenia (",E.length,"):"]}),e.jsxs("ul",{className:P.deviceItems,children:[E.slice(0,10).map(F=>e.jsxs("li",{className:P.deviceItem,children:[e.jsx("span",{className:P.deviceDot,style:{backgroundColor:I.color}}),F.name]},F.id)),E.length>10&&e.jsxs("li",{className:P.deviceMore,children:["... i ",E.length-10," więcej"]})]})]}),e.jsx("button",{className:P.highlightButton,onClick:()=>r==null?void 0:r(I),children:"Zaznacz na mapie"})]})]},I.id)})})}),x.length>0&&e.jsxs("div",{className:P.footer,children:[e.jsx("div",{className:P.legendTitle,children:"Legenda kolorów"}),e.jsx("div",{className:P.legend,children:x.map(I=>e.jsxs("div",{className:P.legendItem,children:[e.jsx("span",{className:P.legendColor,style:{backgroundColor:I.color}}),e.jsxs("span",{className:P.legendLabel,children:[I.id,I.name?`: ${I.name}`:""]})]},I.id))})]})]})},Pc="_root_16w3g_9",Ec="_shell_16w3g_35",Oc="_dark_16w3g_43",Ac="_topBar_16w3g_67",Dc="_modeSwitcher_16w3g_85",Rc="_modeBtn_16w3g_95",Fc="_modeBtnActive_16w3g_131",Wc="_modeIcon_16w3g_143",Gc="_modeLabel_16w3g_151",qc="_floorTabs_16w3g_159",Vc="_floorTab_16w3g_159",Uc="_floorTabActive_16w3g_203",Hc="_viewportControls_16w3g_215",Yc="_active_16w3g_257",Zc="_disabled_16w3g_267",Xc="_separator_16w3g_281",Kc="_zoomLevel_16w3g_295",Jc="_exportDropdown_16w3g_313",Qc="_exportMenu_16w3g_361",el="_editorContainer_16w3g_435",tl="_toolbar_16w3g_453",sl="_toolGroup_16w3g_473",nl="_toolBtn_16w3g_501",ol="_toolBtnActive_16w3g_541",al="_canvasWrapper_16w3g_565",rl="_canvas_16w3g_565",il="_cursor_select_16w3g_593",cl="_cursor_multi_select_16w3g_599",ll="_cursor_pan_16w3g_605",dl="_cursor_zoom_16w3g_617",ul="_cursor_draw_wall_16w3g_623",hl="_cursor_draw_zone_16w3g_625",ml="_cursor_draw_polyline_16w3g_627",pl="_cursor_draw_rectangle_16w3g_629",_l="_cursor_draw_circle_16w3g_631",fl="_cursor_draw_arc_16w3g_633",gl="_cursor_place_device_16w3g_639",yl="_cursor_place_furniture_16w3g_641",xl="_cursor_place_network_16w3g_643",bl="_cursor_place_infra_16w3g_645",vl="_cursor_place_door_16w3g_647",jl="_cursor_place_window_16w3g_649",wl="_cursor_place_stairs_16w3g_651",Nl="_cursor_connect_16w3g_657",kl="_cursor_route_cable_16w3g_659",Il="_cursor_annotate_16w3g_665",Cl="_cursor_dimension_16w3g_667",Sl="_cursor_label_16w3g_669",zl="_cursor_measure_distance_16w3g_675",Ll="_cursor_measure_angle_16w3g_677",$l="_cursor_measure_area_16w3g_679",Tl="_cursor_move_16w3g_685",Ml="_cursor_rotate_16w3g_691",Bl="_cursor_scale_16w3g_697",Pl="_cursor_erase_16w3g_703",El="_cursor_copy_16w3g_709",Ol="_cursor_paste_16w3g_711",Al="_grid_16w3g_721",Dl="_gridLine_16w3g_727",Rl="_zonesLayer_16w3g_739",Fl="_zone_16w3g_739",Wl="_zoneLabel_16w3g_755",Gl="_connectionsLayer_16w3g_769",ql="_connection_16w3g_769",Vl="_connectionPreview_16w3g_785",Ul="_guides_16w3g_795",Hl="_guideLine_16w3g_801",Yl="_drawingPreview_16w3g_815",Zl="_rightSidebar_16w3g_827",Xl="_statusBar_16w3g_849",Kl="_modeIndicator_16w3g_871",Jl="_toolIndicator_16w3g_873",Ql="_selectionInfo_16w3g_885",ed="_drawingInfo_16w3g_887",td="_connectingInfo_16w3g_901",sd="_gridInfo_16w3g_915",nd="_emptyState_16w3g_927",od="_emptyIcon_16w3g_949",ad="_primaryBtn_16w3g_979",rd="_modeActions_16w3g_1013",id="_actionBtn_16w3g_1031",D={root:Pc,shell:Ec,dark:Oc,topBar:Ac,modeSwitcher:Dc,modeBtn:Rc,modeBtnActive:Fc,modeIcon:Wc,modeLabel:Gc,floorTabs:qc,floorTab:Vc,floorTabActive:Uc,viewportControls:Hc,active:Yc,disabled:Zc,separator:Xc,zoomLevel:Kc,exportDropdown:Jc,exportMenu:Qc,editorContainer:el,toolbar:tl,toolGroup:sl,toolBtn:nl,toolBtnActive:ol,canvasWrapper:al,canvas:rl,cursor_select:il,cursor_multi_select:cl,cursor_pan:ll,cursor_zoom:dl,cursor_draw_wall:ul,cursor_draw_zone:hl,cursor_draw_polyline:ml,cursor_draw_rectangle:pl,cursor_draw_circle:_l,cursor_draw_arc:fl,cursor_place_device:gl,cursor_place_furniture:yl,cursor_place_network:xl,cursor_place_infra:bl,cursor_place_door:vl,cursor_place_window:jl,cursor_place_stairs:wl,cursor_connect:Nl,cursor_route_cable:kl,cursor_annotate:Il,cursor_dimension:Cl,cursor_label:Sl,cursor_measure_distance:zl,cursor_measure_angle:Ll,cursor_measure_area:$l,cursor_move:Tl,cursor_rotate:Ml,cursor_scale:Bl,cursor_erase:Pl,cursor_copy:El,cursor_paste:Ol,grid:Al,gridLine:Dl,zonesLayer:Rl,zone:Fl,zoneLabel:Wl,connectionsLayer:Gl,connection:ql,connectionPreview:Vl,guides:Ul,guideLine:Hl,drawingPreview:Yl,rightSidebar:Zl,statusBar:Xl,modeIndicator:Kl,toolIndicator:Jl,selectionInfo:Ql,drawingInfo:ed,connectingInfo:td,gridInfo:sd,emptyState:nd,emptyIcon:od,primaryBtn:ad,modeActions:rd,actionBtn:id},Xe={"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}},gt={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 cd(t){var a,r;const s=t.defaultMode??"floor-plan",n=Xe[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:((r=(a=t.document)==null?void 0:a.floors[0])==null?void 0:r.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 Ye(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 Ze(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(r=>r.id===s);if(a)return a}}function mt(t,s,n){return{...t,floors:t.floors.map(o=>({...o,layers:o.layers.map(a=>({...a,objects:a.objects.map(r=>r.id===s?{...r,...n}:r)}))})),metadata:{...t.metadata,modified:new Date().toISOString()}}}function pt(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(r=>!n.has(r.id))}))})),metadata:{...t.metadata,modified:new Date().toISOString()}}}function _t(t,s,n,o){return{...t,floors:t.floors.map(a=>a.id!==s?a:{...a,layers:a.layers.map(r=>r.name!==n?r:{...r,objects:[...r.objects,o]})}),metadata:{...t.metadata,modified:new Date().toISOString()}}}function ld(t,s){var n;switch(s.type){case"SET_MODE":{const o=Xe[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=_t(t.document,t.activeFloorId,o,s.object),r=Ye("create",[s.object.id],null,s.object);return{...t,document:a,...Ze(t,r)}}case"UPDATE_OBJECT":{if(!t.document)return t;const o=Fe(t.document,s.objectId);if(!o)return t;const a=mt(t.document,s.objectId,s.updates),r=Ye("update",[s.objectId],o,{...o,...s.updates});return{...t,document:a,...Ze(t,r)}}case"DELETE_OBJECTS":{if(!t.document||s.objectIds.length===0)return t;const o=s.objectIds.map(i=>Fe(t.document,i)).filter(Boolean),a=pt(t.document,s.objectIds),r=Ye("delete",s.objectIds,o,null);return{...t,document:a,selection:{objectIds:[],bounds:null,locked:!1},...Ze(t,r)}}case"MOVE_OBJECTS":{if(!t.document||s.objectIds.length===0)return t;const o=s.objectIds.map(l=>Fe(t.document,l)).filter(Boolean);let a=t.document;for(const l of s.objectIds){const h=Fe(a,l);if(h&&"transform"in h&&h.transform&&"position"in h.transform){const b=h.transform.position;a=mt(a,l,{transform:{...h.transform,position:{x:b.x+s.delta.x,y:b.y+s.delta.y}}})}}const r=s.objectIds.map(l=>Fe(a,l)).filter(Boolean),i=Ye("move",s.objectIds,o,r);return{...t,document:a,...Ze(t,i)}}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=pt(a,o.objectIds);break}case"delete":{const r=o.before;for(const i of r){const l=i.layer||"devices";a=_t(a,t.activeFloorId??a.floors[0].id,l,i)}break}case"update":case"move":{const r=o.before;for(const i of r)a=mt(a,i.id,i);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 r=o.after,i=r.layer||"devices";a=_t(a,t.activeFloorId??a.floors[0].id,i,r);break}case"delete":{a=pt(a,o.objectIds);break}case"update":case"move":{const r=o.after;for(const i of r)a=mt(a,i.id,i);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(i=>Fe(t.document,i)).filter(Boolean),a=pt(t.document,t.selection.objectIds),r=Ye("delete",t.selection.objectIds,o,null);return{...t,document:a,clipboard:o,selection:{objectIds:[],bounds:null,locked:!1},...Ze(t,r)}}case"PASTE":{if(!t.document||!t.activeFloorId||t.clipboard.length===0)return t;let o=t.document;const a=[],r=[];for(const l of t.clipboard){const h=`${l.id}-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,b=l.transform,d={position:{x:b.position.x+s.position.x+20,y:b.position.y+s.position.y+20},rotation:b.rotation,scale:b.scale},x={...l,id:h,transform:d},v=x.layer||"devices";o=_t(o,t.activeFloorId,v,x),a.push(h),r.push(x)}const i=Ye("create",a,null,r);return{...t,document:o,selection:{objectIds:a,bounds:null,locked:!1},...Ze(t,i)}}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 dd=({mode:t,activeTool:s,onToolSelect:n,readOnly:o})=>{const r=Xe[t].tools.map(l=>gt[l]).filter(Boolean),i=["select","draw","place","connect","annotate","measure","edit"];return e.jsx("div",{className:D.toolbar,children:i.map(l=>{const h=r.filter(b=>b.group===l);return h.length===0?null:e.jsx("div",{className:D.toolGroup,children:h.map(({tool:b,icon:d,label:x,shortcut:v})=>e.jsx("button",{title:`${x}${v?` (${v})`:""}`,className:`${D.toolBtn} ${s===b?D.toolBtnActive:""}`,onClick:()=>n(b),disabled:o&&!["select","pan","zoom","measure-distance","measure-angle","measure-area"].includes(b),children:e.jsx(z.NiceIcon,{name:d,size:16})},b))},l)})})},ud=({currentMode:t,availableModes:s,onModeChange:n})=>e.jsx("div",{className:D.modeSwitcher,children:s.map(o=>{const a=Xe[o];return e.jsxs("button",{title:a.label,className:`${D.modeBtn} ${t===o?D.modeBtnActive:""}`,onClick:()=>n(o),children:[e.jsx("span",{className:D.modeIcon,children:e.jsx(z.NiceIcon,{name:a.icon,size:16})}),e.jsx("span",{className:D.modeLabel,children:a.label})]},o)})});function os(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 r=a.metadata;r!=null&&r.sourceId&&(r!=null&&r.targetId)&&s.push({id:a.id,sourceId:r.sourceId,sourcePort:r.sourcePort,targetId:r.targetId,targetPort:r.targetPort,medium:r.medium??"ethernet-cat6",status:r.status??"unknown",bandwidth:r.bandwidth,latency:r.latency??1,waypoints:r.waypoints??[]})}}return s}function hd(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 r of a.objects){const i=r.metadata;if((i==null?void 0:i.vlanId)!==void 0&&!n.has(i.vlanId))n.add(i.vlanId),s.push({id:i.vlanId,name:i.vlanName??`VLAN ${i.vlanId}`,color:i.vlanColor??md(i.vlanId),deviceIds:[r.id],subnet:i.subnet,gateway:i.gateway,dhcpEnabled:i.dhcpEnabled});else if((i==null?void 0:i.vlanId)!==void 0){const l=s.find(h=>h.id===i.vlanId);l&&!l.deviceIds.includes(r.id)&&l.deviceIds.push(r.id)}}return s.sort((o,a)=>o.id-a.id)}function md(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-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 pd=[{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"}],_d=t=>{var Wt,Gt;const{defaultMode:s="floor-plan",availableModes:n=Object.keys(Xe),readOnly:o=!1,theme:a="light",locale:r="en",onDocumentChange:i,onSelectionChange:l,onModeChange:h,onExport:b,onImport:d,tutorial:x,className:v,style:y,cookies:_=!1,localStorage:f=!0,sessionStorage:p=!1,storageMode:C,storageKey:L,persistPreferences:I=!1}=t,k=z.useStorageAdapter(L??"nice-spatial-editor"),[c]=u.useState(()=>I?k.get("prefs")??{}:{}),[g,m]=u.useReducer(ld,t,cd),j=u.useRef(null),E=u.useRef(!1),F=u.useRef({x:0,y:0}),[de,ee]=u.useState(!1),[xe,ue]=u.useState(!1),[ae,X]=u.useState(null),[le,ze]=u.useState(null),[De,Ce]=u.useState(!1),[Me,Be]=u.useState(!1),[T,U]=u.useState(!1),[me,Le]=u.useState(new Set),[Oe,be]=u.useState(null),Pe=u.useRef(null),ke=u.useRef(null),we=u.useRef(null),{mode:je,tool:he,document:ne,activeFloorId:Re,layers:Ne,selection:ye,viewport:re,drawing:pe,connecting:Q,guides:We,ui:Ee,history:Ke}=g,Ge=Xe[je],ot=Ke.past.length>0,Je=Ke.future.length>0;u.useEffect(()=>{var N,A,O;!I||!c||((c.zoom||c.pan)&&m({type:"SET_VIEWPORT",viewport:{zoom:c.zoom,pan:c.pan,showGrid:(N=c.gridConfig)==null?void 0:N.visible,gridSize:(A=c.gridConfig)==null?void 0:A.size,snapEnabled:(O=c.gridConfig)==null?void 0:O.snapEnabled}}),c.mode&&m({type:"SET_MODE",mode:c.mode}),c.tool&&m({type:"SET_TOOL",tool:c.tool}),c.layerVisibility&&Object.entries(c.layerVisibility).forEach(([W,Z])=>{Z!==void 0&&m({type:"SET_LAYER_VISIBILITY",layerType:W,visible:Z})}))},[]),u.useEffect(()=>{if(!I)return;const N={zoom:re.zoom,pan:re.pan,gridConfig:{size:re.gridSize,visible:re.showGrid,snapEnabled:re.snapEnabled},mode:je,tool:he,layerVisibility:Object.fromEntries(Ne.map(A=>[A.type,A.visible])),uiPanels:Ee};k.set("prefs",N)},[I,re,je,he,Ne,Ee,k]);const fe=u.useMemo(()=>(ne==null?void 0:ne.floors.find(N=>N.id===Re))??(ne==null?void 0:ne.floors[0])??null,[ne,Re]),Ae=u.useCallback((N,A)=>{var W;const O=(W=j.current)==null?void 0:W.getBoundingClientRect();return O?{x:(N-O.left-re.pan.x)/re.zoom,y:(A-O.top-re.pan.y)/re.zoom}:{x:0,y:0}},[re.pan,re.zoom]),qe=u.useCallback(N=>{if(!re.snapEnabled)return N;const A={cellSize:re.gridSize,origin:{x:0,y:0},visible:re.showGrid};return Ft(N,A)},[re.snapEnabled,re.gridSize,re.showGrid]),vt=u.useCallback(N=>{if(he==="pan"||N.button===1){E.current=!0,F.current={x:N.clientX,y:N.clientY};return}const A=qe(Ae(N.clientX,N.clientY));if(he==="draw-zone"||he==="draw-wall"||he==="draw-polyline")pe.active?m({type:"ADD_DRAWING_POINT",point:A}):m({type:"START_DRAWING",point:A});else if(he==="connect"){const O=fe==null?void 0:fe.layers.flatMap(W=>W.objects).find(W=>{if(!W.bounds)return!1;const Z=W.bounds;return A.x>=Z.x&&A.x<=Z.x+Z.width&&A.y>=Z.y&&A.y<=Z.y+Z.height});if(O)if(Q.active){m({type:"FINISH_CONNECTING",targetId:O.id});const W=`conn-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,Z=O.bounds?{x:O.bounds.x+O.bounds.width/2,y:O.bounds.y+O.bounds.height/2}:A,K={id:W,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(Q.sourcePosition.x,Z.x),y:Math.min(Q.sourcePosition.y,Z.y),width:Math.abs(Z.x-Q.sourcePosition.x),height:Math.abs(Z.y-Q.sourcePosition.y)},metadata:{sourceId:Q.sourceId,targetId:O.id,sourcePosition:Q.sourcePosition,targetPosition:Z,medium:"ethernet-cat6",status:"active"}};m({type:"ADD_OBJECT",object:K})}else{const W=O.bounds?{x:O.bounds.x+O.bounds.width/2,y:O.bounds.y+O.bounds.height/2}:A;m({type:"START_CONNECTING",sourceId:O.id,sourcePosition:W})}else Q.active&&m({type:"CANCEL_CONNECTING"})}else he==="select"&&m({type:"CLEAR_SELECTION"})},[he,pe.active,Q.active,Q.sourceId,Q.sourcePosition,qe,Ae,fe]),jt=u.useCallback(N=>{if(E.current){const O=N.clientX-F.current.x,W=N.clientY-F.current.y;m({type:"PAN",delta:{x:O,y:W}}),F.current={x:N.clientX,y:N.clientY};return}const A=qe(Ae(N.clientX,N.clientY));if(pe.active&&(m({type:"UPDATE_DRAWING_PREVIEW",point:A}),re.snapEnabled&&fe)){const O=fe.layers.flatMap(K=>K.objects.filter(ie=>ie.bounds).map(ie=>({id:ie.id,bounds:ie.bounds}))),W={x:A.x,y:A.y,width:1,height:1},Z=ps(W,O,10);m({type:"SET_GUIDES",guides:Z})}Q.active&&m({type:"UPDATE_CONNECTING_PREVIEW",position:A})},[pe.active,Q.active,qe,Ae,re.snapEnabled,fe]),wt=u.useCallback(()=>{E.current=!1},[]),Nt=u.useCallback(N=>{pe.active&&pe.points.length>=2&&m({type:"FINISH_DRAWING"})},[pe.active,pe.points.length]),kt=u.useCallback(N=>{N.preventDefault();const A=N.deltaY>0?-1:1;m({type:"ZOOM",delta:A,center:Ae(N.clientX,N.clientY)})},[Ae]),It=u.useCallback(N=>{N.key==="Escape"&&(pe.active?m({type:"CANCEL_DRAWING"}):Q.active?m({type:"CANCEL_CONNECTING"}):m({type:"CLEAR_SELECTION"})),N.key==="Delete"&&ye.objectIds.length>0&&m({type:"DELETE_OBJECTS",objectIds:ye.objectIds}),(N.ctrlKey||N.metaKey)&&(N.key==="z"&&m({type:"UNDO"}),N.key==="y"&&m({type:"REDO"}),N.key==="c"&&m({type:"COPY"}),N.key==="v"&&m({type:"PASTE",position:{x:0,y:0}}),N.key==="x"&&m({type:"CUT"}))},[pe.active,Q.active,ye.objectIds]),Ct=u.useCallback(N=>{m({type:"SET_MODE",mode:N}),h==null||h(N)},[h]),St=u.useCallback(N=>{m({type:"SET_TOOL",tool:N})},[]),Ve=u.useCallback(async N=>{var A;if(ne){ee(!1);try{const O={includeGrid:!1,includeDimensions:!0};if(N==="nsp"){const W=Vn(ne,O);ut(W),b==null||b(N,W.data)}else if(N==="svg"){const W=Hn(ne,O);ut(W),b==null||b(N,W.data)}else if(N==="dxf"){const W=Xn(ne,O);ut(W),b==null||b(N,W.data)}else if(N==="png"&&j.current){const W=await eo(j.current,((A=ne.metadata)==null?void 0:A.name)||"export");ut(W),b==null||b(N,W.data)}}catch(O){console.error(`Export to ${N} failed:`,O)}}},[ne,b]),zt=u.useCallback(async N=>{var O;const A=(O=N.target.files)==null?void 0:O[0];if(A){ue(!1);try{const Z=await mo(A,{convertClosedPolylinesToZones:!0,minZoneArea:1});Z.success&&Z.document?ze(Z):X(Z),we.current&&(we.current.value="")}catch(W){console.error("Import failed:",W),X({success:!1,warnings:[],errors:[{code:"IMPORT_ERROR",message:W instanceof Error?W.message:"Unknown import error",fatal:!0}],stats:{wallsImported:0,zonesImported:0,objectsImported:0,layersFound:0,entitiesSkipped:0,importTimeMs:0}})}}},[]),Lt=u.useCallback(()=>{le!=null&&le.success&&le.document?Ce(!0):ze(null)},[le]),at=u.useCallback(()=>{ze(null),Ce(!1)},[]),w=u.useCallback((N,A)=>{if(!(le!=null&&le.document)){Ce(!1);return}const O=le.document,W={...O,floors:O.floors.map(Z=>({...Z,layers:Z.layers.filter(K=>N.get(K.id)!=="skip").map(K=>{const ie=N.get(K.id);if(ie===K.id||!ie)return K;const Se=ne==null?void 0:ne.floors.flatMap(Ue=>Ue.layers).find(Ue=>Ue.id===ie);return Se?{...K,id:Se.id,name:Se.name,type:Se.type}:K})}))};m({type:"SET_DOCUMENT",document:W}),d==null||d(W),X(le),Ce(!1),ze(null)},[le,ne,d]),S=u.useCallback(()=>{Ce(!1)},[]),M=u.useCallback(N=>{if(we.current){let A=".dxf,.svg,.geojson,.json,.ifc";N==="dxf"?A=".dxf":N==="svg"?A=".svg":N==="geojson"?A=".geojson,.json":N==="ifc"&&(A=".ifc"),we.current.accept=A,we.current.click()}ue(!1)},[]);u.useEffect(()=>{const N=A=>{Pe.current&&!Pe.current.contains(A.target)&&ee(!1),ke.current&&!ke.current.contains(A.target)&&ue(!1)};return(de||xe)&&document.addEventListener("mousedown",N),()=>{document.removeEventListener("mousedown",N)}},[de,xe]);const J=u.useCallback(()=>{var Z,K;if(!re.showGrid||!fe)return null;const N=[],{gridSize:A}=re,O=((Z=fe.bounds)==null?void 0:Z.width)??1e3,W=((K=fe.bounds)==null?void 0:K.height)??800;for(let ie=0;ie<=O;ie+=A)N.push(e.jsx("line",{x1:ie,y1:0,x2:ie,y2:W,className:D.gridLine},`v${ie}`));for(let ie=0;ie<=W;ie+=A)N.push(e.jsx("line",{x1:0,y1:ie,x2:O,y2:ie,className:D.gridLine},`h${ie}`));return e.jsx("g",{className:D.grid,children:N})},[re.showGrid,re.gridSize,fe]),q=u.useCallback(()=>{if(!fe)return null;const N=fe.layers.find(A=>A.name==="zones");return N?e.jsx("g",{className:D.zonesLayer,children:N.objects.map(A=>{const O=A;if(!O.boundary||O.boundary.length<3)return null;const W=O.boundary.map((ie,Se)=>`${Se===0?"M":"L"}${ie.x},${ie.y}`).join(" ")+" Z",Z=ye.objectIds.includes(O.id),K=O.boundary.reduce((ie,Se)=>({x:ie.x+Se.x/O.boundary.length,y:ie.y+Se.y/O.boundary.length}),{x:0,y:0});return e.jsxs("g",{className:D.zone,onClick:ie=>{ie.stopPropagation(),m({type:"SET_SELECTION",selection:{objectIds:[O.id],bounds:null,locked:!1}})},children:[e.jsx("path",{d:W,fill:O.color??"var(--nice-primary-bg, #dbeafe)",fillOpacity:.5,stroke:Z?"var(--nice-primary-hover, #2563eb)":"var(--nice-text-muted, #94a3b8)",strokeWidth:Z?2:1}),O.name&&e.jsx("text",{x:K.x,y:K.y,textAnchor:"middle",dominantBaseline:"middle",className:D.zoneLabel,children:O.name})]},O.id)})}):null},[fe,ye.objectIds]),ce=u.useCallback(()=>We.length===0?null:e.jsx("g",{className:D.guides,children:We.map((N,A)=>e.jsx("line",{x1:N.start.x,y1:N.start.y,x2:N.end.x,y2:N.end.y,className:D.guideLine},A))}),[We]),_e=u.useCallback(()=>{if(!pe.active||pe.points.length===0)return null;const N=[...pe.points];pe.preview&&N.push(pe.preview);const A=N.map((W,Z)=>`${Z===0?"M":"L"}${W.x},${W.y}`).join(" "),O=he==="draw-zone"&&N.length>2;return e.jsxs("g",{className:D.drawingPreview,children:[e.jsx("path",{d:A+(O?" Z":""),fill:O?"var(--nice-primary-tint-10, rgba(37, 99, 235, 0.1))":"none",stroke:"var(--nice-primary-hover, #2563eb)",strokeWidth:2,strokeDasharray:O?"none":"6,3"}),N.map((W,Z)=>e.jsx("circle",{cx:W.x,cy:W.y,r:4,fill:"var(--nice-primary-hover, #2563eb)"},Z))]})},[pe,he]),$e=u.useCallback(()=>!Q.active||!Q.sourcePosition||!Q.previewPosition?null:e.jsxs("g",{className:D.connectionPreview,children:[e.jsx("line",{x1:Q.sourcePosition.x,y1:Q.sourcePosition.y,x2:Q.previewPosition.x,y2:Q.previewPosition.y,stroke:"var(--nice-success, #10b981)",strokeWidth:2,strokeDasharray:"8,4",markerEnd:"url(#connectionArrow)"}),e.jsx("circle",{cx:Q.sourcePosition.x,cy:Q.sourcePosition.y,r:6,fill:"var(--nice-success, #10b981)"}),e.jsx("circle",{cx:Q.previewPosition.x,cy:Q.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)"})})})]}),[Q]),rt=u.useCallback(()=>{if(!fe)return null;const N=fe.layers.find(Z=>Z.type==="network");if(!N)return null;const A=N.objects.filter(Z=>Z.type==="connection");if(A.length===0)return null;const O={"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-accent-dark, #6d28d9)",dashArray:"6,4",width:2},default:{color:"var(--nice-text-secondary, #64748b)",width:2}},W={active:"var(--nice-success, #10b981)",inactive:"var(--nice-text-muted, #94a3b8)",error:"var(--nice-danger, #ef4444)",degraded:"var(--nice-warning, #f59e0b)",unknown:"var(--nice-text-secondary, #64748b)"};return e.jsx("g",{className:D.connectionsLayer,children:A.map(Z=>{const K=Z.metadata;if(!(K!=null&&K.sourcePosition)||!(K!=null&&K.targetPosition))return null;const ie=O[K.medium??"default"]||O.default,Se=W[K.status??"unknown"]||W.unknown,Ue=ye.objectIds.includes(Z.id);let $t=`M${K.sourcePosition.x},${K.sourcePosition.y}`;if(K.waypoints&&K.waypoints.length>0)for(const it of K.waypoints)$t+=` L${it.x},${it.y}`;return $t+=` L${K.targetPosition.x},${K.targetPosition.y}`,e.jsxs("g",{className:D.connection,onClick:it=>{it.stopPropagation(),m({type:"SET_SELECTION",selection:{objectIds:[Z.id],bounds:null,locked:!1}})},children:[e.jsx("path",{d:$t,fill:"none",stroke:Ue?"var(--nice-primary-hover, #2563eb)":ie.color,strokeWidth:Ue?ie.width+1:ie.width,strokeDasharray:ie.dashArray,strokeLinecap:"round",strokeLinejoin:"round"}),K.status&&K.status!=="active"&&e.jsx("circle",{cx:(K.sourcePosition.x+K.targetPosition.x)/2,cy:(K.sourcePosition.y+K.targetPosition.y)/2,r:5,fill:Se}),e.jsx("circle",{cx:K.sourcePosition.x,cy:K.sourcePosition.y,r:4,fill:ie.color,stroke:"white",strokeWidth:1}),e.jsx("circle",{cx:K.targetPosition.x,cy:K.targetPosition.y,r:4,fill:ie.color,stroke:"white",strokeWidth:1})]},Z.id)})})},[fe,ye.objectIds]);if(!ne&&!fe)return e.jsx("div",{className:`${D.root} ${D[a]} ${v??""}`,style:y,children:e.jsxs("div",{className:D.emptyState,children:[e.jsx("div",{className:D.emptyIcon,children:e.jsx(z.NiceIcon,{name:Ge.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:D.primaryBtn,onClick:()=>{const N=_s("New Project","floor-plan");m({type:"SET_DOCUMENT",document:N})},children:"Create New Document"})]})});const Ss=e.jsxs("div",{className:D.topBar,children:[e.jsx(ud,{currentMode:je,availableModes:n,onModeChange:Ct}),ne&&ne.floors.length>1&&e.jsx("div",{className:D.floorTabs,children:ne.floors.map(N=>e.jsx("button",{className:`${D.floorTab} ${Re===N.id?D.floorTabActive:""}`,onClick:()=>m({type:"SET_ACTIVE_FLOOR",floorId:N.id}),children:N.name},N.id))}),e.jsxs("div",{className:D.viewportControls,children:[!o&&e.jsxs(e.Fragment,{children:[e.jsx("button",{title:"Undo (Ctrl+Z)",onClick:()=>m({type:"UNDO"}),disabled:!ot,className:ot?"":D.disabled,children:e.jsx(z.NiceIcon,{name:"reply",size:16})}),e.jsx("button",{title:"Redo (Ctrl+Y)",onClick:()=>m({type:"REDO"}),disabled:!Je,className:Je?"":D.disabled,children:e.jsx(z.NiceIcon,{name:"forward",size:16})}),e.jsx("div",{className:D.separator})]}),e.jsx("button",{title:"Toggle Grid",onClick:()=>m({type:"TOGGLE_GRID"}),className:re.showGrid?D.active:"",children:e.jsx(z.NiceIcon,{name:"grid",size:16})}),e.jsx("button",{title:"Toggle Snap",onClick:()=>m({type:"TOGGLE_SNAP"}),className:re.snapEnabled?D.active:"",children:e.jsx(z.NiceIcon,{name:"target",size:16})}),e.jsxs("span",{className:D.zoomLevel,children:[Math.round(re.zoom*100),"%"]}),e.jsx("button",{title:"Zoom In",onClick:()=>m({type:"ZOOM",delta:1}),children:e.jsx(z.NiceIcon,{name:"plus",size:16})}),e.jsx("button",{title:"Zoom Out",onClick:()=>m({type:"ZOOM",delta:-1}),children:e.jsx(z.NiceIcon,{name:"minus",size:16})}),e.jsx("button",{title:"Reset View",onClick:()=>m({type:"RESET_VIEW"}),children:e.jsx(z.NiceIcon,{name:"expand",size:16})}),!o&&e.jsxs("div",{className:D.exportDropdown,ref:ke,children:[e.jsx("input",{type:"file",ref:we,onChange:zt,style:{display:"none"}}),e.jsxs("button",{title:"Import",onClick:()=>ue(!xe),className:xe?D.active:"",children:[e.jsx(z.NiceIcon,{name:"download",size:14})," Import"]}),xe&&e.jsxs("div",{className:D.exportMenu,children:[e.jsxs("button",{onClick:()=>M(),children:[e.jsx(z.NiceIcon,{name:"file",size:14})," Auto-detect format"]}),e.jsxs("button",{onClick:()=>M("dxf"),children:[e.jsx(z.NiceIcon,{name:"ruler",size:14})," AutoCAD DXF (.dxf)"]}),e.jsxs("button",{onClick:()=>M("svg"),children:[e.jsx(z.NiceIcon,{name:"image",size:14})," SVG Vector Graphics (.svg)"]}),e.jsxs("button",{onClick:()=>M("geojson"),children:[e.jsx(z.NiceIcon,{name:"globe",size:14})," GeoJSON (.geojson)"]}),e.jsxs("button",{onClick:()=>M("ifc"),children:[e.jsx(z.NiceIcon,{name:"building",size:14})," IFC (BIM) (.ifc)"]})]})]}),ne&&e.jsxs("div",{className:D.exportDropdown,ref:Pe,children:[e.jsxs("button",{title:"Export",onClick:()=>ee(!de),className:de?D.active:"",children:[e.jsx(z.NiceIcon,{name:"upload",size:14})," Export"]}),de&&e.jsxs("div",{className:D.exportMenu,children:[e.jsxs("button",{onClick:()=>Ve("nsp"),children:[e.jsx(z.NiceIcon,{name:"file",size:14})," NiceToDev Spatial Plan (.nsp.json)"]}),e.jsxs("button",{onClick:()=>Ve("svg"),children:[e.jsx(z.NiceIcon,{name:"image",size:14})," SVG Vector Graphics (.svg)"]}),e.jsxs("button",{onClick:()=>Ve("dxf"),children:[e.jsx(z.NiceIcon,{name:"ruler",size:14})," AutoCAD DXF (.dxf)"]}),e.jsxs("button",{onClick:()=>Ve("png"),children:[e.jsx(z.NiceIcon,{name:"image",size:14})," PNG Image (.png)"]})]})]})]})]}),zs=Ee.showObjectLibrary&&!o?e.jsx(vs,{mode:je,onObjectSelect:N=>{m({type:"SET_TOOL",tool:`place-${N.category}`}),m({type:"START_DRAG",objectType:N.category,objectData:N})}}):void 0,Ls=e.jsxs("div",{className:D.editorContainer,children:[!o&&e.jsx(dd,{mode:je,activeTool:he,onToolSelect:St,readOnly:o}),(je==="network-topology"||je==="infrastructure")&&e.jsxs("div",{className:D.modeActions,children:[e.jsxs("button",{className:`${D.actionBtn} ${Me?D.active:""}`,onClick:()=>Be(!Me),title:"Analiza ścieżki sieciowej",children:[e.jsx(z.NiceIcon,{name:"bar-chart",size:14})," Analiza ścieżki"]}),e.jsxs("button",{className:`${D.actionBtn} ${T?D.active:""}`,onClick:()=>U(!T),title:"Nakładka VLAN",children:[e.jsx(z.NiceIcon,{name:"globe",size:14})," VLAN Overlay"]})]}),e.jsxs("div",{className:D.canvasWrapper,children:[e.jsx("svg",{ref:j,className:`${D.canvas} ${D[`cursor_${he.replace("-","_")}`]??""}`,onMouseDown:vt,onMouseMove:jt,onMouseUp:wt,onDoubleClick:Nt,onWheel:kt,children:e.jsxs("g",{transform:`translate(${re.pan.x}, ${re.pan.y}) scale(${re.zoom})`,children:[J(),q(),rt(),ce(),_e(),$e()]})}),Ee.showMinimap&&e.jsx(bs,{document:ne,activeFloorId:Re,viewport:re,onViewportChange:N=>m({type:"SET_VIEWPORT",viewport:N})})]})]}),$s=e.jsxs("div",{className:D.rightSidebar,children:[Ee.showLayerPanel&&e.jsx(xs,{layers:Ne.filter(N=>Ge.layerTypes.includes(N.type)),onVisibilityToggle:N=>{var A;return m({type:"SET_LAYER_VISIBILITY",layerType:N,visible:!((A=Ne.find(O=>O.type===N))!=null&&A.visible)})},onLockToggle:N=>{var A;return m({type:"SET_LAYER_LOCKED",layerType:N,locked:!((A=Ne.find(O=>O.type===N))!=null&&A.locked)})},onOpacityChange:(N,A)=>m({type:"SET_LAYER_OPACITY",layerType:N,opacity:A})}),Ee.showPropertiesPanel&&ye.objectIds.length>0&&e.jsx(js,{selection:ye,document:ne,onPropertyChange:(N,A,O)=>{m({type:"UPDATE_OBJECT",objectId:N,updates:{[A]:O}})}})]}),Ts=e.jsxs("div",{className:D.statusBar,children:[e.jsxs("span",{className:D.modeIndicator,children:[e.jsx(z.NiceIcon,{name:Ge.icon,size:14})," ",Ge.label]}),e.jsxs("span",{className:D.toolIndicator,children:[((Wt=gt[he])==null?void 0:Wt.icon)&&e.jsx(z.NiceIcon,{name:gt[he].icon,size:14})," ",(Gt=gt[he])==null?void 0:Gt.label]}),ye.objectIds.length>0&&e.jsxs("span",{className:D.selectionInfo,children:[ye.objectIds.length," selected"]}),pe.active&&e.jsxs("span",{className:D.drawingInfo,children:["Drawing: ",pe.points.length," points"]}),Q.active&&e.jsx("span",{className:D.connectingInfo,children:"Connecting: click target device or ESC to cancel"}),e.jsxs("span",{className:D.gridInfo,children:["Grid: ",re.gridSize,"px | Snap: ",re.snapEnabled?"ON":"OFF"]})]});return e.jsxs("div",{className:`nice-spatial-editor ${D.root} ${D[a]} ${v??""}`,style:{position:"relative",...y},tabIndex:0,onKeyDown:It,children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:e.jsx(z.NiceTutorialButton,{steps:z.resolveTutorial(x,pd)})}),e.jsx(z.NiceAppShell,{flush:!0,className:D.shell,menubar:Ss,sidebar:zs,rightSidebar:$s,statusBar:Ts,children:Ls}),le&&!De&&e.jsx(Qo,{result:le,onConfirm:Lt,onCancel:at}),le&&De&&e.jsx(Sa,{importResult:le,existingDocument:ne??void 0,onConfirm:w,onCancel:S}),Me&&ne&&e.jsx(Fr,{document:ne,connections:os(ne),onHighlightPath:N=>{m(N?{type:"SET_SELECTION",selection:{objectIds:N.connectionIds,bounds:null,locked:!1}}:{type:"SET_SELECTION",selection:{objectIds:[],bounds:null,locked:!1}})},onClose:()=>Be(!1)}),T&&ne&&e.jsx(Bc,{document:ne,connections:os(ne),vlans:hd(ne),visibleVlanIds:me,onVlanVisibilityChange:(N,A)=>{Le(O=>{const W=new Set(O);return A?W.add(N):W.delete(N),W})},onHighlightVlan:N=>{be((N==null?void 0:N.id)??null),m(N?{type:"SET_SELECTION",selection:{objectIds:N.deviceIds,bounds:null,locked:!1}}:{type:"SET_SELECTION",selection:{objectIds:[],bounds:null,locked:!1}})},onClose:()=>U(!1)})]})},fd="_viewer_nyfnl_13",gd="_theme_light_nyfnl_37",yd="_theme_dark_nyfnl_59",xd="_debugOverlay_nyfnl_85",bd="_topBar_nyfnl_137",vd="_searchContainer_nyfnl_159",jd="_searchInput_nyfnl_171",wd="_clearBtn_nyfnl_227",Nd="_searchResults_nyfnl_261",kd="_searchResultItem_nyfnl_291",Id="_searchResultInfo_nyfnl_335",Cd="_searchResultName_nyfnl_347",Sd="_searchResultDesc_nyfnl_357",zd="_floorSelector_nyfnl_371",Ld="_navBtn_nyfnl_421",$d="_active_nyfnl_459",Td="_layersBtn_nyfnl_475",Md="_legendBtn_nyfnl_529",Bd="_content_nyfnl_583",Pd="_navPanel_nyfnl_599",Ed="_navPanelHeader_nyfnl_617",Od="_routeInputs_nyfnl_671",Ad="_routeInput_nyfnl_671",Dd="_routeMarker_nyfnl_705",Rd="_routeHint_nyfnl_745",Fd="_routeInfo_nyfnl_761",Wd="_routeStat_nyfnl_779",Gd="_routeStatLabel_nyfnl_791",qd="_routeStatValue_nyfnl_805",Vd="_clearRouteBtn_nyfnl_817",Ud="_refPointsList_nyfnl_851",Hd="_refPointItem_nyfnl_879",Yd="_refPointIcon_nyfnl_917",Zd="_layersPanel_nyfnl_929",Xd="_layersPanelHeader_nyfnl_947",Kd="_layersList_nyfnl_1001",Jd="_layerItem_nyfnl_1015",Qd="_layerToggle_nyfnl_1039",eu="_layerName_nyfnl_1075",tu="_layerType_nyfnl_1087",su="_canvasWrapper_nyfnl_1101",nu="_canvas_nyfnl_1101",ou="_grid_nyfnl_1137",au="_gridLine_nyfnl_1145",ru="_zonesLayer_nyfnl_1161",iu="_zone_nyfnl_1161",cu="_zoneSelected_nyfnl_1187",lu="_zoneLabel_nyfnl_1197",du="_objectsLayer_nyfnl_1213",uu="_object_nyfnl_1213",hu="_objectSelected_nyfnl_1237",mu="_objectLabel_nyfnl_1245",pu="_referencePoints_nyfnl_1261",_u="_referencePoint_nyfnl_1261",fu="_refLabel_nyfnl_1283",gu="_routeLayer_nyfnl_1299",yu="_routePath_nyfnl_1305",xu="_routeDash_nyfnl_1",bu="_routeMarkers_nyfnl_1331",vu="_currentLocation_nyfnl_1341",ju="_locationPulse_nyfnl_1347",wu="_pulse_nyfnl_1",Nu="_zoomControls_nyfnl_1383",ku="_minimap_nyfnl_1459",Iu="_minimapContent_nyfnl_1485",Cu="_minimapViewport_nyfnl_1499",Su="_legendPanel_nyfnl_1519",zu="_legendPanelHeader_nyfnl_1551",Lu="_legendList_nyfnl_1607",$u="_legendItem_nyfnl_1623",Tu="_legendColor_nyfnl_1647",Mu="_legendIcon_nyfnl_1663",Bu="_legendLabel_nyfnl_1677",Pu="_legendType_nyfnl_1689",Eu="_objectInfo_nyfnl_1707",Ou="_objectInfoHeader_nyfnl_1735",Au="_navigateBtn_nyfnl_1805",$={viewer:fd,theme_light:gd,theme_dark:yd,debugOverlay:xd,topBar:bd,searchContainer:vd,searchInput:jd,clearBtn:wd,searchResults:Nd,searchResultItem:kd,searchResultInfo:Id,searchResultName:Cd,searchResultDesc:Sd,floorSelector:zd,navBtn:Ld,active:$d,layersBtn:Td,legendBtn:Md,content:Bd,navPanel:Pd,navPanelHeader:Ed,routeInputs:Od,routeInput:Ad,routeMarker:Dd,routeHint:Rd,routeInfo:Fd,routeStat:Wd,routeStatLabel:Gd,routeStatValue:qd,clearRouteBtn:Vd,refPointsList:Ud,refPointItem:Hd,refPointIcon:Yd,layersPanel:Zd,layersPanelHeader:Xd,layersList:Kd,layerItem:Jd,layerToggle:Qd,layerName:eu,layerType:tu,canvasWrapper:su,canvas:nu,grid:ou,gridLine:au,zonesLayer:ru,zone:iu,zoneSelected:cu,zoneLabel:lu,objectsLayer:du,object:uu,objectSelected:hu,objectLabel:mu,referencePoints:pu,referencePoint:_u,refLabel:fu,routeLayer:gu,routePath:yu,routeDash:xu,routeMarkers:bu,currentLocation:vu,locationPulse:ju,pulse:wu,zoomControls:Nu,minimap:ku,minimapContent:Iu,minimapViewport:Cu,legendPanel:Su,legendPanelHeader:zu,legendList:Lu,legendItem:$u,legendColor:Tu,legendIcon:Mu,legendLabel:Bu,legendType:Pu,objectInfo:Eu,objectInfoHeader:Ou,navigateBtn:Au},Du=()=>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"})]}),as=()=>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"})}),Ru=()=>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"})]}),Fu=()=>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"})]}),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:"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"})]}),Gu=()=>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"})]}),qu=()=>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"})]}),et=()=>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"})}),rs=()=>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"})]}),is=()=>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"})]}),Vu=()=>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"})]}),Uu=()=>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"})]}),Hu={entrance:"door",elevator:"elevator",stairs:"stairs",exit:"bell",poi:"map-pin",parking:"map-pin"};function Ot(t){return t.icon??Hu[t.type]??"map-pin"}function Yu(t,s){return Math.sqrt((s.x-t.x)**2+(s.y-t.y)**2)}function Zu(t){return t<1?"<1m":t<1e3?`${Math.round(t)}m`:`${(t/1e3).toFixed(1)}km`}function Xu(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 Ku=({document:t,initialFloorId:s,showNavigation:n=!0,showMinimap:o=!0,showFloorSelector:a=!0,showSearch:r=!0,showLayersPanel:i=!0,showLegend:l=!0,enableRoutePlanning:h=!0,referencePoints:b=[],onObjectClick:d,onRouteCalculated:x,currentLocation:v,theme:y="light",className:_,virtualRendering:f,virtualRenderingThreshold:p=200,debugVirtualRendering:C=!1})=>{var at;const[L,I]=u.useState(s??((at=t.floors[0])==null?void 0:at.id)??""),[k,c]=u.useState({zoom:1,pan:{x:0,y:0}}),[g,m]=u.useState(""),[j,E]=u.useState([]),[F,de]=u.useState(null),[ee,xe]=u.useState(null),[ue,ae]=u.useState(null),[X,le]=u.useState(null),[ze,De]=u.useState(!1),[Ce,Me]=u.useState(!1),[Be,T]=u.useState(!1),[U,me]=u.useState(new Map),[Le,Oe]=u.useState({width:1e3,height:600}),be=u.useRef(null),Pe=u.useRef(null),ke=u.useRef(!1),we=u.useRef({x:0,y:0}),je=u.useMemo(()=>{const w=t.floors.find(S=>S.id===L);return w?w.layers.reduce((S,M)=>{var J;return S+(((J=M.objects)==null?void 0:J.length)??0)},0):0},[t.floors,L]),he=f??xo(je,p),ne=u.useMemo(()=>{if(!he)return null;const w=t.floors.find(M=>M.id===L);if(!w)return null;const S=[];for(const M of w.layers)if(!(M.type==="zones"||M.type==="grid"||M.type==="background"))for(const J of M.objects??[]){const q=J.position??{x:0,y:0},ce=J.size??{width:20,height:20};S.push({id:J.id,position:q,size:ce,data:{object:J,layerId:M.id}})}return go(S)},[t.floors,L,he]),Re=u.useMemo(()=>yo(k,Le,100),[k,Le]),Ne=u.useMemo(()=>!he||!ne?null:ne.query(Re),[he,ne,Re]),ye=u.useMemo(()=>!C||!he?null:bo(je,(Ne==null?void 0:Ne.length)??je,k),[C,he,je,Ne,k]);u.useEffect(()=>{const w=Pe.current;if(!w)return;const S=new ResizeObserver(M=>{for(const J of M)Oe({width:J.contentRect.width,height:J.contentRect.height})});return S.observe(w),()=>S.disconnect()},[]),u.useEffect(()=>{const w=t.floors.find(S=>S.id===L);if(w){const S=new Map;for(const M of w.layers)S.set(M.id,U.get(M.id)??!0);me(S)}},[L,t.floors]);const re=u.useCallback(w=>{me(S=>{const M=new Map(S);return M.set(w,!S.get(w)),M})},[]),pe=u.useCallback(w=>U.get(w)!==!1,[U]),Q=u.useMemo(()=>t.floors.find(w=>w.id===L)??t.floors[0],[t.floors,L]),We=u.useMemo(()=>{if(!Q)return[];const w=[],S=Q.layers.find(q=>q.type==="zones");if(S){const q=new Map;for(const ce of S.objects){const _e=ce.metadata,$e=(_e==null?void 0:_e.zoneType)??ce.type??"zone";q.has($e)||q.set($e,(_e==null?void 0:_e.fill)??"var(--nice-primary, #3b82f6)")}for(const[ce,_e]of q)w.push({id:`zone-${ce}`,label:ce.charAt(0).toUpperCase()+ce.slice(1).replace(/-/g," "),color:_e,type:"zone"})}const M=new Map;for(const q of Q.layers)if(!(q.type==="zones"||q.type==="grid"||q.type==="background"))for(const ce of q.objects){const _e=ce.type??"object",$e=M.get(_e);$e?$e.count++:M.set(_e,{count:1,color:"var(--nice-text-secondary, #64748b)"})}for(const[q,ce]of M)w.push({id:`obj-${q}`,label:`${q.charAt(0).toUpperCase()+q.slice(1).replace(/-/g," ")} (${ce.count})`,color:ce.color,type:"object"});const J=new Map;for(const q of b.filter(ce=>ce.floorId===L))J.has(q.type)||J.set(q.type,Ot(q));for(const[q,ce]of J)w.push({id:`ref-${q}`,label:q.charAt(0).toUpperCase()+q.slice(1),color:"var(--nice-primary, #3b82f6)",icon:ce,type:"reference"});return w},[Q,b,L]),Ee=u.useCallback((w,S)=>{var J;const M=(J=be.current)==null?void 0:J.getBoundingClientRect();return M?{x:(w-M.left-k.pan.x)/k.zoom,y:(S-M.top-k.pan.y)/k.zoom}:{x:0,y:0}},[k]);u.useEffect(()=>{if(!g.trim()){E([]);return}const w=g.toLowerCase(),S=[];for(const M of t.floors)for(const J of M.layers)for(const q of J.objects){const ce=(q.name??q.id).toLowerCase(),_e=(q.description??"").toLowerCase();(ce.includes(w)||_e.includes(w))&&S.push(q)}E(S.slice(0,10))},[g,t.floors]);const Ke=u.useCallback((w,S)=>{const M=Yu(w,S);return{id:`route-${Date.now()}`,startPoint:w,endPoint:S,path:[w,S],floorTransitions:[],totalDistance:M,estimatedTime:M/1.4,instructions:[{type:"straight",distance:M,direction:"forward"},{type:"arrive"}]}},[]);u.useEffect(()=>{if(ee&&ue){const w=Ke(ee,ue);le(w),x==null||x(w)}else le(null),x==null||x(null)},[ee,ue,Ke,x]);const Ge=u.useCallback(w=>{(w.button===1||w.button===0&&w.altKey)&&(ke.current=!0,we.current={x:w.clientX,y:w.clientY},w.preventDefault())},[]),ot=u.useCallback(w=>{if(ke.current){const S=w.clientX-we.current.x,M=w.clientY-we.current.y;we.current={x:w.clientX,y:w.clientY},c(J=>({...J,pan:{x:J.pan.x+S,y:J.pan.y+M}}))}},[]),Je=u.useCallback(()=>{ke.current=!1},[]),fe=u.useCallback(w=>{var ce;w.preventDefault();const S=w.deltaY>0?.9:1.1,M=(ce=be.current)==null?void 0:ce.getBoundingClientRect();if(!M)return;const J=w.clientX-M.left,q=w.clientY-M.top;c(_e=>{const $e=Math.min(Math.max(_e.zoom*S,.1),10),rt=$e/_e.zoom;return{zoom:$e,pan:{x:J-(J-_e.pan.x)*rt,y:q-(q-_e.pan.y)*rt}}})},[]),Ae=u.useCallback(w=>{if(h&&w.ctrlKey){const S=Ee(w.clientX,w.clientY);ee?ue?(xe(S),ae(null)):ae(S):xe(S)}},[h,ee,ue,Ee]),qe=u.useCallback(()=>{c(w=>({...w,zoom:Math.min(w.zoom*1.25,10)}))},[]),vt=u.useCallback(()=>{c(w=>({...w,zoom:Math.max(w.zoom/1.25,.1)}))},[]),jt=u.useCallback(()=>{c({zoom:1,pan:{x:0,y:0}})},[]),wt=u.useCallback(w=>{de(w);for(const M of t.floors)for(const J of M.layers)if(J.objects.find(q=>q.id===w.id)){I(M.id);break}const S=w.position??{x:0,y:0};c(M=>({...M,pan:{x:-(S.x*M.zoom)+400,y:-(S.y*M.zoom)+300}})),m(""),E([]),d==null||d(w)},[t.floors,d]),Nt=u.useCallback(()=>{xe(null),ae(null),le(null)},[]),kt=u.useCallback(()=>{const S=[];for(let M=-2e3;M<=2e3;M+=50)S.push(e.jsx("line",{x1:M,y1:-2e3,x2:M,y2:2e3,className:$.gridLine},`v-${M}`));for(let M=-2e3;M<=2e3;M+=50)S.push(e.jsx("line",{x1:-2e3,y1:M,x2:2e3,y2:M,className:$.gridLine},`h-${M}`));return e.jsx("g",{className:$.grid,children:S})},[]),It=u.useCallback(()=>{if(!Q)return null;const w=Q.layers.find(S=>S.type==="zones");return!w||!pe(w.id)?null:e.jsx("g",{className:$.zonesLayer,children:w.objects.map(S=>{const M=S.metadata;if(!(M!=null&&M.points)||M.points.length<3)return null;const J=`M${M.points.map(ce=>`${ce.x},${ce.y}`).join(" L")} Z`,q=(F==null?void 0:F.id)===S.id;return e.jsxs("g",{className:`${$.zone} ${q?$.zoneSelected:""}`,onClick:()=>{de(S),d==null||d(S)},children:[e.jsx("path",{d:J,fill:M.fill??"var(--nice-primary, #3b82f6)",fillOpacity:.2,stroke:M.fill??"var(--nice-primary, #3b82f6)",strokeWidth:q?2:1}),S.name&&e.jsx("text",{x:M.points[0].x+10,y:M.points[0].y+20,className:$.zoneLabel,children:S.name})]},S.id)})})},[Q,F,d,pe]),Ct=u.useCallback(()=>Q?he&&Ne?e.jsx("g",{className:$.objectsLayer,children:Ne.map(w=>{const{object:S,layerId:M}=w.data;if(!pe(M))return null;const J=S.position??{x:0,y:0},q=S.size??{width:20,height:20},ce=(F==null?void 0:F.id)===S.id;return e.jsxs("g",{className:`${$.object} ${ce?$.objectSelected:""}`,transform:`translate(${J.x}, ${J.y})`,onClick:_e=>{_e.stopPropagation(),de(S),d==null||d(S)},children:[e.jsx("rect",{x:-q.width/2,y:-q.height/2,width:q.width,height:q.height,rx:4,fill:ce?"var(--nice-primary, #3b82f6)":"var(--nice-text-secondary, #64748b)",fillOpacity:.8,stroke:ce?"var(--nice-primary-dark, #1d4ed8)":"transparent",strokeWidth:2}),S.name&&e.jsx("text",{y:q.height/2+14,textAnchor:"middle",className:$.objectLabel,children:S.name})]},S.id)})}):e.jsx("g",{className:$.objectsLayer,children:Q.layers.map(w=>w.type==="zones"||w.type==="grid"||w.type==="background"||!pe(w.id)?null:w.objects.map(S=>{const M=S.position??{x:0,y:0},J=S.size??{width:20,height:20},q=(F==null?void 0:F.id)===S.id;return e.jsxs("g",{className:`${$.object} ${q?$.objectSelected:""}`,transform:`translate(${M.x}, ${M.y})`,onClick:ce=>{ce.stopPropagation(),de(S),d==null||d(S)},children:[e.jsx("rect",{x:-J.width/2,y:-J.height/2,width:J.width,height:J.height,rx:4,fill:q?"var(--nice-primary, #3b82f6)":"var(--nice-text-secondary, #64748b)",fillOpacity:.8,stroke:q?"var(--nice-primary-dark, #1d4ed8)":"transparent",strokeWidth:2}),S.name&&e.jsx("text",{y:J.height/2+14,textAnchor:"middle",className:$.objectLabel,children:S.name})]},S.id)}))}):null,[Q,F,d,pe,he,Ne]),St=u.useCallback(()=>{const w=b.filter(S=>S.floorId===L);return e.jsx("g",{className:$.referencePoints,children:w.map(S=>e.jsxs("g",{className:$.referencePoint,transform:`translate(${S.position.x}, ${S.position.y})`,onClick:()=>{h&&(ee?ae(S.position):xe(S.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(z.NiceIcon,{name:Ot(S),size:16})}),e.jsx("text",{y:30,textAnchor:"middle",className:$.refLabel,children:S.name})]},S.id))})},[b,L,h,ee]),Ve=u.useCallback(()=>{if(!X)return null;const w=`M${X.path.map(S=>`${S.x},${S.y}`).join(" L")}`;return e.jsxs("g",{className:$.routeLayer,children:[e.jsx("path",{d:w,fill:"none",stroke:"var(--nice-primary, #3b82f6)",strokeWidth:4,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"12,6",className:$.routePath}),e.jsx("circle",{cx:X.startPoint.x,cy:X.startPoint.y,r:8,fill:"var(--nice-success, #10b981)",stroke:"white",strokeWidth:2}),e.jsx("circle",{cx:X.endPoint.x,cy:X.endPoint.y,r:8,fill:"var(--nice-danger, #ef4444)",stroke:"white",strokeWidth:2})]})},[X]),zt=u.useCallback(()=>v?e.jsxs("g",{className:$.currentLocation,children:[e.jsx("circle",{cx:v.x,cy:v.y,r:12,fill:"var(--nice-primary, #3b82f6)",fillOpacity:.3,className:$.locationPulse}),e.jsx("circle",{cx:v.x,cy:v.y,r:6,fill:"var(--nice-primary, #3b82f6)",stroke:"white",strokeWidth:2})]}):null,[v]),Lt=u.useCallback(()=>e.jsx("g",{className:$.routeMarkers,children:ee&&!X&&e.jsx("circle",{cx:ee.x,cy:ee.y,r:8,fill:"var(--nice-success, #10b981)",stroke:"white",strokeWidth:2})}),[ee,X]);return e.jsxs("div",{ref:Pe,className:`${$.viewer} ${$[`theme_${y}`]} ${_??""}`,children:[C&&ye&&e.jsxs("div",{className:$.debugOverlay,children:[e.jsx("div",{children:"Virtual: ON"}),e.jsxs("div",{children:["Total: ",ye.total]}),e.jsxs("div",{children:["Visible: ",ye.visible]}),e.jsxs("div",{children:["Culled: ",ye.culled," (",ye.cullPercentage,"%)"]}),e.jsxs("div",{children:["Zoom: ",ye.zoom.toFixed(2),"x"]})]}),e.jsxs("div",{className:$.topBar,children:[r&&e.jsxs("div",{className:$.searchContainer,children:[e.jsxs("div",{className:$.searchInput,children:[e.jsx(Du,{}),e.jsx("input",{type:"text",placeholder:"Szukaj lokalizacji...",value:g,onChange:w=>m(w.target.value)}),g&&e.jsx("button",{className:$.clearBtn,onClick:()=>m(""),children:e.jsx(et,{})})]}),j.length>0&&e.jsx("div",{className:$.searchResults,children:j.map(w=>e.jsxs("button",{className:$.searchResultItem,onClick:()=>wt(w),children:[e.jsx(Ru,{}),e.jsxs("div",{className:$.searchResultInfo,children:[e.jsx("span",{className:$.searchResultName,children:w.name??w.id}),w.description&&e.jsx("span",{className:$.searchResultDesc,children:w.description})]})]},w.id))})]}),a&&t.floors.length>1&&e.jsxs("div",{className:$.floorSelector,children:[e.jsx(Fu,{}),e.jsx("select",{value:L,onChange:w=>I(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:`${$.navBtn} ${ze?$.active:""}`,onClick:()=>De(!ze),children:[e.jsx(as,{}),e.jsx("span",{children:"Nawigacja"})]}),i&&e.jsxs("button",{className:`${$.layersBtn} ${Ce?$.active:""}`,onClick:()=>Me(!Ce),children:[e.jsx(rs,{}),e.jsx("span",{children:"Warstwy"})]}),l&&e.jsxs("button",{className:`${$.legendBtn} ${Be?$.active:""}`,onClick:()=>T(!Be),children:[e.jsx(is,{}),e.jsx("span",{children:"Legenda"})]})]}),e.jsxs("div",{className:$.content,children:[ze&&e.jsxs("div",{className:$.navPanel,children:[e.jsxs("div",{className:$.navPanelHeader,children:[e.jsx(Wu,{}),e.jsx("span",{children:"Planowanie trasy"}),e.jsx("button",{onClick:()=>De(!1),children:e.jsx(et,{})})]}),e.jsxs("div",{className:$.routeInputs,children:[e.jsxs("div",{className:$.routeInput,children:[e.jsx("div",{className:$.routeMarker,style:{background:"var(--nice-success, #10b981)"}}),e.jsx("input",{type:"text",placeholder:"Punkt startowy",value:ee?`${ee.x.toFixed(0)}, ${ee.y.toFixed(0)}`:"",readOnly:!0})]}),e.jsxs("div",{className:$.routeInput,children:[e.jsx("div",{className:$.routeMarker,style:{background:"var(--nice-danger, #ef4444)"}}),e.jsx("input",{type:"text",placeholder:"Punkt docelowy",value:ue?`${ue.x.toFixed(0)}, ${ue.y.toFixed(0)}`:"",readOnly:!0})]})]}),e.jsx("p",{className:$.routeHint,children:"Ctrl+kliknięcie na mapie, aby wybrać punkty"}),X&&e.jsxs("div",{className:$.routeInfo,children:[e.jsxs("div",{className:$.routeStat,children:[e.jsx("span",{className:$.routeStatLabel,children:"Dystans"}),e.jsx("span",{className:$.routeStatValue,children:Zu(X.totalDistance)})]}),e.jsxs("div",{className:$.routeStat,children:[e.jsx("span",{className:$.routeStatLabel,children:"Czas"}),e.jsx("span",{className:$.routeStatValue,children:Xu(X.estimatedTime)})]})]}),(ee||ue)&&e.jsx("button",{className:$.clearRouteBtn,onClick:Nt,children:"Wyczyść trasę"}),b.length>0&&e.jsxs("div",{className:$.refPointsList,children:[e.jsx("h4",{children:"Punkty odniesienia"}),b.filter(w=>w.floorId===L).map(w=>e.jsxs("button",{className:$.refPointItem,onClick:()=>{ee?ae(w.position):xe(w.position)},children:[e.jsx("span",{className:$.refPointIcon,children:e.jsx(z.NiceIcon,{name:Ot(w),size:16})}),e.jsx("span",{children:w.name})]},w.id))]})]}),Ce&&Q&&e.jsxs("div",{className:$.layersPanel,children:[e.jsxs("div",{className:$.layersPanelHeader,children:[e.jsx(rs,{}),e.jsx("span",{children:"Warstwy"}),e.jsx("button",{onClick:()=>Me(!1),children:e.jsx(et,{})})]}),e.jsx("div",{className:$.layersList,children:Q.layers.map(w=>{const S=pe(w.id);return e.jsxs("div",{className:$.layerItem,children:[e.jsx("button",{className:$.layerToggle,onClick:()=>re(w.id),title:S?"Ukryj warstwę":"Pokaż warstwę",children:S?e.jsx(Vu,{}):e.jsx(Uu,{})}),e.jsx("span",{className:$.layerName,children:w.name??w.id}),e.jsxs("span",{className:$.layerType,children:["(",w.type,")"]})]},w.id)})})]}),e.jsxs("div",{className:$.canvasWrapper,children:[e.jsx("svg",{ref:be,className:$.canvas,onMouseDown:Ge,onMouseMove:ot,onMouseUp:Je,onMouseLeave:Je,onWheel:fe,onClick:Ae,children:e.jsxs("g",{transform:`translate(${k.pan.x}, ${k.pan.y}) scale(${k.zoom})`,children:[kt(),It(),Ct(),St(),Lt(),Ve(),zt()]})}),e.jsxs("div",{className:$.zoomControls,children:[e.jsx("button",{onClick:qe,title:"Powiększ",children:e.jsx(Gu,{})}),e.jsx("button",{onClick:vt,title:"Pomniejsz",children:e.jsx(qu,{})}),e.jsx("button",{onClick:jt,title:"Resetuj widok",children:e.jsx(z.NiceIcon,{name:"refresh",size:16})})]}),o&&e.jsx("div",{className:$.minimap,children:e.jsx("div",{className:$.minimapContent,children:e.jsx("div",{className:$.minimapViewport})})}),Be&&We.length>0&&e.jsxs("div",{className:$.legendPanel,children:[e.jsxs("div",{className:$.legendPanelHeader,children:[e.jsx(is,{}),e.jsx("span",{children:"Legenda"}),e.jsx("button",{onClick:()=>T(!1),children:e.jsx(et,{})})]}),e.jsx("div",{className:$.legendList,children:We.map(w=>e.jsxs("div",{className:$.legendItem,children:[w.icon?e.jsx("span",{className:$.legendIcon,children:e.jsx(z.NiceIcon,{name:w.icon,size:16})}):e.jsx("span",{className:$.legendColor,style:{background:w.color}}),e.jsx("span",{className:$.legendLabel,children:w.label}),e.jsx("span",{className:$.legendType,children:w.type==="zone"?"strefa":w.type==="object"?"obiekt":"punkt ref."})]},w.id))})]})]})]}),F&&e.jsxs("div",{className:$.objectInfo,children:[e.jsxs("div",{className:$.objectInfoHeader,children:[e.jsx("h4",{children:F.name??F.id}),e.jsx("button",{onClick:()=>de(null),children:e.jsx(et,{})})]}),F.description&&e.jsx("p",{children:F.description}),h&&e.jsxs("button",{className:$.navigateBtn,onClick:()=>{const w=F.position??{x:0,y:0};ee?ae(w):xe(w)},children:[e.jsx(as,{}),ee?"Ustaw jako cel":"Ustaw jako start"]})]})]})};function Ju(t={}){var ue;const{initialDocument:s,defaultMode:n="floor-plan",gridSize:o=20,snapEnabled:a=!0,onChange:r}=t,i={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}},[l,h]=u.useReducer((ae,X)=>({...ae,...X}),i),b=u.useCallback(ae=>{h({mode:ae})},[]),d=u.useCallback(ae=>{h({tool:ae})},[]),x=u.useCallback((ae="Untitled")=>{var le;const X=_s(ae,"floor-plan");h({document:X,activeFloorId:((le=X.floors[0])==null?void 0:le.id)??null}),r==null||r(X)},[r]),v=u.useCallback(ae=>{var X;h({document:ae,activeFloorId:((X=ae.floors[0])==null?void 0:X.id)??null}),r==null||r(ae)},[r]),y=u.useCallback(ae=>{h({viewport:{...l.viewport,zoom:Math.max(.1,Math.min(10,l.viewport.zoom*(1+ae*.1)))}})},[l.viewport]),_=u.useCallback(ae=>{h({viewport:{...l.viewport,pan:{x:l.viewport.pan.x+ae.x,y:l.viewport.pan.y+ae.y}}})},[l.viewport]),f=u.useCallback(()=>{h({viewport:{...l.viewport,zoom:1,pan:{x:0,y:0}}})},[l.viewport]),p=u.useCallback(()=>{h({viewport:{...l.viewport,showGrid:!l.viewport.showGrid}})},[l.viewport]),C=u.useCallback(()=>{h({viewport:{...l.viewport,snapEnabled:!l.viewport.snapEnabled}})},[l.viewport]),L=u.useCallback(ae=>{h({viewport:{...l.viewport,gridSize:ae}})},[l.viewport]),I=u.useCallback((ae,X)=>{h({layers:l.layers.map(le=>le.type===ae?{...le,visible:X}:le)})},[l.layers]),k=u.useCallback((ae,X)=>{h({layers:l.layers.map(le=>le.type===ae?{...le,locked:X}:le)})},[l.layers]),c=u.useCallback(ae=>{h({selection:{objectIds:ae,bounds:null,locked:!1}})},[]),g=u.useCallback(()=>{h({selection:{objectIds:[],bounds:null,locked:!1}})},[]),m=u.useCallback(()=>{},[]),j=u.useCallback(()=>{},[]),E=l.history.past.length>0,F=l.history.future.length>0,de=u.useCallback(()=>{},[]),ee=u.useCallback(ae=>{},[]),xe=u.useCallback(()=>{},[]);return{state:l,setMode:b,setTool:d,newDocument:x,loadDocument:v,zoom:y,pan:_,resetView:f,toggleGrid:p,toggleSnap:C,setGridSize:L,setLayerVisible:I,setLayerLocked:k,select:c,clearSelection:g,undo:m,redo:j,canUndo:E,canRedo:F,copy:de,paste:ee,cut:xe}}function Qu(t={}){const{gridSize:s=20,enabled:n=!0,snapModes:o=["grid","endpoint","midpoint"],objects:a=[],threshold:r=10}=t,i=u.useMemo(()=>({...Mn,cellSize:s,snapModes:o,snapThreshold:r}),[s,o,r]),l=u.useMemo(()=>a.map((y,_)=>({id:`obj-${_}`,bounds:y})),[a]),h=u.useCallback(y=>n?Ft(y,i):y,[n,i]),b=u.useCallback(y=>n?Bn(y,s):y,[n,s]),d=u.useCallback(y=>{if(!n||l.length===0)return[];const _={x:y.x,y:y.y,width:0,height:0};return ps(_,l,r)},[n,l,r]),x=u.useCallback(y=>{if(!n)return{point:y,snapped:!1,guides:[]};const _=An(y,l,i);return{point:_.position,snapped:_.snapped,guides:_.guides??[]}},[n,i,l]),v=u.useCallback((y,_)=>{const f=[];for(let p=0;p<=y;p+=s)f.push({x1:p,y1:0,x2:p,y2:_});for(let p=0;p<=_;p+=s)f.push({x1:0,y1:p,x2:y,y2:p});return f},[s]);return{snap:h,snap3D:b,getGuides:d,performAdvancedSnap:x,generateGridLines:v}}function eh(t={}){const{unitSystem:s="metric",lengthUnit:n="m",areaUnit:o="m2",angleUnit:a="deg",scale:r=100}=t,[i,l]=u.useState(null),[h,b]=u.useState([]),d=u.useCallback(g=>g/r,[r]),x=u.useCallback(g=>{l(g),b([])},[]),v=u.useCallback((g,m=!1)=>{b(j=>[...j,{position:g,snapped:m}])},[]),y=u.useCallback(()=>{l(null),b([])},[]),_=u.useCallback(()=>{if(!i||h.length<2)return null;const g=h.map(m=>m.position);if(i==="distance"&&h.length===2){const m=tt(g[0],g[1]),j=d(m);return{type:"distance",value:j,formatted:dt(j,s).formatted,points:g}}if(i==="angle"&&h.length===3){const m=Tt(g[0],g[1],g[2]);return{type:"angle",value:m,formatted:Bt(m,a).formatted,points:g}}if(i==="area"&&h.length>=3){const j=Mt(g)/(r*r);return{type:"area",value:j,formatted:Pt(j,s).formatted,points:g}}return null},[i,h,r,s,a,d]),f=h.length>=2&&i==="distance"?dt(d(tt(h[0].position,h[h.length-1].position)),s).formatted:null,p=h.length>=3&&i==="angle"?Bt(Tt(h[0].position,h[1].position,h[2].position),a).formatted:null,C=h.length>=3&&i==="area"?Pt(Mt(h.map(g=>g.position))/(r*r),s).formatted:null,L=u.useCallback((g,m)=>{const j=tt(g,m),E=d(j);return{value:E,formatted:dt(E,s).formatted}},[d,s]),I=u.useCallback((g,m,j)=>{const E=Tt(g,m,j);return{value:E,formatted:Bt(E,a).formatted}},[a]),k=u.useCallback(g=>{const j=Mt(g)/(r*r);return{value:j,formatted:Pt(j,s).formatted}},[r,s]),c=u.useCallback(g=>{const m=Gn(g),j=d(m);return{value:j,formatted:dt(j,s).formatted}},[d,s]);return{startMeasurement:x,addPoint:v,clearMeasurement:y,finishMeasurement:_,measurementType:i,points:h,liveDistance:f,liveAngle:p,liveArea:C,getDistance:L,getAngle:I,getArea:k,getLength:c}}const th="_root_1rgf7_3",sh="_dark_1rgf7_25",nh="_header_1rgf7_37",oh="_buildingInfo_1rgf7_51",ah="_buildingName_1rgf7_59",rh="_buildingAddress_1rgf7_81",ih="_modeSelector_1rgf7_95",ch="_modeBtn_1rgf7_107",lh="_modeBtnActive_1rgf7_145",dh="_weather_1rgf7_159",uh="_weatherTemp_1rgf7_173",hh="_weatherDesc_1rgf7_193",mh="_statsRow_1rgf7_205",ph="_statsCard_1rgf7_217",_h="_statsHeader_1rgf7_247",fh="_statsIcon_1rgf7_261",gh="_statsLabel_1rgf7_269",yh="_statsValue_1rgf7_283",xh="_statsSub_1rgf7_305",bh="_zoneGrid_1rgf7_319",vh="_zoneCard_1rgf7_333",jh="_zoneOccupied_1rgf7_381",wh="_zoneCardHeader_1rgf7_389",Nh="_zoneCardIcon_1rgf7_403",kh="_zoneCardTitles_1rgf7_411",Ih="_zoneCardName_1rgf7_421",Ch="_zoneCardArea_1rgf7_449",Sh="_occupancyBadge_1rgf7_459",zh="_occupancyBadgeOn_1rgf7_477",Lh="_sensorRow_1rgf7_489",$h="_sensorChip_1rgf7_503",Th="_sensorWarn_1rgf7_521",Mh="_deviceList_1rgf7_535",Bh="_deviceChip_1rgf7_547",Ph="_deviceChipOn_1rgf7_585",Eh="_deviceChipName_1rgf7_597",Oh="_deviceChipVal_1rgf7_611",Ah="_moreBtn_1rgf7_621",Dh="_scenesBar_1rgf7_651",Rh="_sceneBarLabel_1rgf7_681",Fh="_sceneList_1rgf7_699",Wh="_sceneBtn_1rgf7_711",Gh="_sceneBtnActive_1rgf7_741",H={root:th,dark:sh,header:nh,buildingInfo:oh,buildingName:ah,buildingAddress:rh,modeSelector:ih,modeBtn:ch,modeBtnActive:lh,weather:dh,weatherTemp:uh,weatherDesc:hh,statsRow:mh,statsCard:ph,statsHeader:_h,statsIcon:fh,statsLabel:gh,statsValue:yh,statsSub:xh,zoneGrid:bh,zoneCard:vh,zoneOccupied:jh,zoneCardHeader:wh,zoneCardIcon:Nh,zoneCardTitles:kh,zoneCardName:Ih,zoneCardArea:Ch,occupancyBadge:Sh,occupancyBadgeOn:zh,sensorRow:Lh,sensorChip:$h,sensorWarn:Th,deviceList:Mh,deviceChip:Bh,deviceChipOn:Ph,deviceChipName:Eh,deviceChipVal:Oh,moreBtn:Ah,scenesBar:Dh,sceneBarLabel:Rh,sceneList:Fh,sceneBtn:Wh,sceneBtnActive:Gh},ws={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 qh(t){return ws[t]??"home"}function Vh(t){if(!t.state)return null;const s=t.state;return typeof s.brightness=="number"?`${s.brightness}%`:typeof s.on=="boolean"?s.on?"Wł":"Wył":typeof s.temperature=="number"?`${s.temperature.toFixed(1)}°`:typeof s.locked=="boolean"?e.jsx(z.NiceIcon,{name:"lock",size:14}):null}const Ns=({zone:t,devices:s=[],expanded:n=!1,onExpand:o,onDeviceControl:a,onClick:r,theme:i="light",className:l,style:h})=>{const b=t.occupancy!=null&&t.occupancy>0,d=n?s:s.slice(0,4);return e.jsxs("div",{className:`${H.zoneCard} ${i==="dark"?H.dark:""} ${b?H.zoneOccupied:""} ${l??""}`,style:h,onClick:r,children:[e.jsxs("div",{className:H.zoneCardHeader,children:[e.jsx("span",{className:H.zoneCardIcon,children:e.jsx(z.NiceIcon,{name:qh(t.type),size:18})}),e.jsxs("div",{className:H.zoneCardTitles,children:[e.jsx("span",{className:H.zoneCardName,children:t.name}),t.area!=null&&e.jsxs("span",{className:H.zoneCardArea,children:[t.area," m²"]})]}),t.occupancy!=null&&e.jsxs("span",{className:`${H.occupancyBadge} ${b?H.occupancyBadgeOn:""}`,children:[e.jsx(z.NiceIcon,{name:"users",size:14})," ",t.occupancy]})]}),(t.temperature!=null||t.humidity!=null||t.co2!=null)&&e.jsxs("div",{className:H.sensorRow,children:[t.temperature!=null&&e.jsxs("span",{className:H.sensorChip,children:[e.jsx(z.NiceIcon,{name:"thermometer",size:14})," ",t.temperature.toFixed(1),"°C"]}),t.humidity!=null&&e.jsxs("span",{className:H.sensorChip,children:[e.jsx(z.NiceIcon,{name:"droplet",size:14})," ",t.humidity,"%"]}),t.co2!=null&&e.jsxs("span",{className:`${H.sensorChip} ${t.co2>1e3?H.sensorWarn:""}`,children:["CO₂ ",t.co2]})]}),d.length>0&&e.jsxs("div",{className:H.deviceList,children:[d.map(x=>{const v=x.state,y=(v==null?void 0:v.on)===!0||(v==null?void 0:v.locked)===!1;return e.jsxs("button",{className:`${H.deviceChip} ${y?H.deviceChipOn:""}`,onClick:_=>{_.stopPropagation(),a==null||a(x.id,{on:!y})},title:x.name,children:[e.jsx("span",{children:e.jsx(z.NiceIcon,{name:ws[x.type]??"monitor",size:14})}),e.jsx("span",{className:H.deviceChipName,children:x.name}),e.jsx("span",{className:H.deviceChipVal,children:Vh(x)})]},x.id)}),s.length>4&&e.jsx("button",{className:H.moreBtn,onClick:x=>{x.stopPropagation(),o==null||o()},children:n?"−":`+${s.length-4}`})]})]})},At={home:"Dom",away:"Wyjazd",night:"Noc",vacation:"Urlop",guest:"Gość",party:"Impreza",occupied:"Zajęty",closed:"Zamknięty",weekend:"Weekend",event:"Wydarzenie",emergency:"Alarm",maintenance:"Serwis"},cs={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"},Uh=({temperature:t,description:s})=>t!=null?e.jsxs("div",{className:H.weather,children:[e.jsxs("span",{className:H.weatherTemp,children:[t,"°C"]}),s&&e.jsx("span",{className:H.weatherDesc,children:s})]}):null,ft=({label:t,value:s,sub:n,icon:o,accent:a})=>e.jsxs("div",{className:H.statsCard,style:a?{borderTopColor:a}:void 0,children:[e.jsxs("div",{className:H.statsHeader,children:[o&&e.jsx("span",{className:H.statsIcon,children:e.jsx(z.NiceIcon,{name:o,size:16})}),e.jsx("span",{className:H.statsLabel,children:t})]}),e.jsx("div",{className:H.statsValue,children:s}),n&&e.jsx("div",{className:H.statsSub,children:n})]}),Hh=({building:t,state:s,onModeChange:n,onDeviceControl:o,onSceneActivate:a,onZoneClick:r,className:i,style:l,theme:h="light",weather:b})=>{var I,k,c;const[d,x]=u.useState(null);t.floors[0];const v=t.floors.flatMap(g=>g.zones??[]).filter(g=>g.type!=="hallway"&&g.type!=="corridor"),y=((I=s==null?void 0:s.activeAlerts)==null?void 0:I.length)??0,_=(k=s==null?void 0:s.energy)==null?void 0:k.currentPowerW,f=(c=s==null?void 0:s.energy)==null?void 0:c.todayKwh,p=s!=null&&s.occupancy?Object.values(s.occupancy).reduce((g,m)=>g+((m==null?void 0:m.occupancy)??0),0):null;t.floors.flatMap(g=>g.zones??[]).flatMap(g=>g.deviceIds??[]).slice(0,8);const C=t.type==="office"||t.type==="retail"?["occupied","closed","weekend","event","emergency","maintenance"]:["home","away","night","vacation","guest","emergency"],L=(s==null?void 0:s.mode)??"home";return e.jsxs("div",{className:`${H.root} ${h==="dark"?H.dark:""} ${i??""}`,style:l,children:[e.jsxs("div",{className:H.header,children:[e.jsxs("div",{className:H.buildingInfo,children:[e.jsx("h2",{className:H.buildingName,children:t.name}),t.address&&e.jsx("p",{className:H.buildingAddress,children:t.address})]}),e.jsx("div",{className:H.modeSelector,children:C.map(g=>e.jsxs("button",{title:At[g],className:`${H.modeBtn} ${L===g?H.modeBtnActive:""}`,onClick:()=>n==null?void 0:n(g),children:[e.jsx(z.NiceIcon,{name:cs[g],size:16}),e.jsx("span",{children:At[g]})]},g))}),e.jsx(Uh,{temperature:b==null?void 0:b.temperature,description:b==null?void 0:b.description})]}),e.jsxs("div",{className:H.statsRow,children:[_!=null&&e.jsx(ft,{icon:"zap",label:"Moc",value:_>=1e3?`${(_/1e3).toFixed(2)} kW`:`${_} W`,sub:f!=null?`Dziś: ${f.toFixed(2)} kWh`:void 0,accent:"var(--nice-warning, #f59e0b)"}),p!=null&&e.jsx(ft,{icon:"users",label:"Obecność",value:`${p} os.`,sub:`${v.length} stref`,accent:"var(--nice-success, #22c55e)"}),y>0&&e.jsx(ft,{icon:"bell",label:"Alarmy",value:e.jsx("span",{style:{color:"var(--nice-danger, #ef4444)"},children:y}),sub:"aktywnych",accent:"var(--nice-danger, #ef4444)"}),e.jsx(ft,{icon:cs[L],label:"Tryb",value:At[L],accent:"var(--nice-accent, #8b5cf6)"})]}),e.jsx("div",{className:H.zoneGrid,children:v.map(g=>{const m=t.floors.flatMap(j=>(j.zones??[]).find(E=>E.id===g.id)?t.devices??[]:[]).filter(j=>j.zoneId===g.id);return e.jsx(Ns,{zone:g,devices:m,expanded:d===g.id,onExpand:()=>x(d===g.id?null:g.id),onDeviceControl:o,onClick:()=>r==null?void 0:r(g.id),theme:h},g.id)})}),t.scenes&&t.scenes.length>0&&e.jsxs("div",{className:H.scenesBar,children:[e.jsx("span",{className:H.sceneBarLabel,children:"Sceny"}),e.jsx("div",{className:H.sceneList,children:t.scenes.map(g=>{var m;return e.jsxs("button",{className:`${H.sceneBtn} ${(m=s==null?void 0:s.activeScenes)!=null&&m.includes(g.id)?H.sceneBtnActive:""}`,onClick:()=>a==null?void 0:a(g.id),children:[e.jsx(z.NiceIcon,{name:g.icon??"video",size:14})," ",g.name]},g.id)})})]})]})},Yh="_deviceControl_9sx64_3",Zh="_dark_9sx64_23",Xh="_compact_9sx64_35",Kh="_offline_9sx64_43",Jh="_offlineBanner_9sx64_51",Qh="_toggleControl_9sx64_75",em="_toggleLabel_9sx64_89",tm="_toggleBtn_9sx64_109",sm="_toggleOn_9sx64_135",nm="_blindControl_9sx64_149",om="_blindLabel_9sx64_159",am="_blindActions_9sx64_173",rm="_blindBtn_9sx64_181",im="_blindSlider_9sx64_205",cm="_blindPct_9sx64_213",lm="_lockControl_9sx64_227",dm="_lockLabel_9sx64_239",um="_lockBtn_9sx64_253",hm="_lockLocked_9sx64_273",mm="_lockUnlocked_9sx64_281",pm="_cameraControl_9sx64_295",_m="_cameraLabel_9sx64_305",fm="_cameraSnapshot_9sx64_319",gm="_cameraPlaceholder_9sx64_331",ym="_cameraStatus_9sx64_355",xm="_cameraDot_9sx64_369",bm="_cameraOnline_9sx64_379",vm="_cameraOffline_9sx64_385",jm="_sensorControl_9sx64_395",wm="_sensorLabel_9sx64_405",Nm="_sensorValues_9sx64_419",km="_sensorRow_9sx64_429",Im="_sensorKey_9sx64_443",Cm="_sensorVal_9sx64_419",Sm="_thermostat_9sx64_467",zm="_thermostatTitle_9sx64_481",Lm="_thermostatDial_9sx64_503",$m="_dialTempCurrent_9sx64_513",Tm="_dialTempLabel_9sx64_533",Mm="_dialTempTarget_9sx64_543",Bm="_dialHumidity_9sx64_563",Pm="_thermostatAdjust_9sx64_573",Em="_adjustBtn_9sx64_585",Om="_adjustTemp_9sx64_631",Am="_hvacModes_9sx64_655",Dm="_hvacModeBtn_9sx64_669",Rm="_hvacModeBtnActive_9sx64_697",Fm="_hvacAction_9sx64_709",Wm="_hvacActionDot_9sx64_725",Gm="_lightControl_9sx64_739",qm="_lightHeader_9sx64_751",Vm="_lightIcon_9sx64_763",Um="_lightName_9sx64_771",Hm="_lightToggle_9sx64_799",Ym="_lightToggleOn_9sx64_827",Zm="_sliderRow_9sx64_839",Xm="_sliderIcon_9sx64_853",Km="_slider_9sx64_839",Jm="_sliderVal_9sx64_877",Qm="_colorRow_9sx64_889",ep="_colorSwatch_9sx64_903",tp="_colorPicker_9sx64_919",sp="_colorPresets_9sx64_935",np="_colorPreset_9sx64_935",op="_lightOff_9sx64_961",B={deviceControl:Yh,dark:Zh,compact:Xh,offline:Kh,offlineBanner:Jh,toggleControl:Qh,toggleLabel:em,toggleBtn:tm,toggleOn:sm,blindControl:nm,blindLabel:om,blindActions:am,blindBtn:rm,blindSlider:im,blindPct:cm,lockControl:lm,lockLabel:dm,lockBtn:um,lockLocked:hm,lockUnlocked:mm,cameraControl:pm,cameraLabel:_m,cameraSnapshot:fm,cameraPlaceholder:gm,cameraStatus:ym,cameraDot:xm,cameraOnline:bm,cameraOffline:vm,sensorControl:jm,sensorLabel:wm,sensorValues:Nm,sensorRow:km,sensorKey:Im,sensorVal:Cm,thermostat:Sm,thermostatTitle:zm,thermostatDial:Lm,dialTempCurrent:$m,dialTempLabel:Tm,dialTempTarget:Mm,dialHumidity:Bm,thermostatAdjust:Pm,adjustBtn:Em,adjustTemp:Om,hvacModes:Am,hvacModeBtn:Dm,hvacModeBtnActive:Rm,hvacAction:Fm,hvacActionDot:Wm,lightControl:Gm,lightHeader:qm,lightIcon:Vm,lightName:Um,lightToggle:Hm,lightToggleOn:Ym,sliderRow:Zm,sliderIcon:Xm,slider:Km,sliderVal:Jm,colorRow:Qm,colorSwatch:ep,colorPicker:tp,colorPresets:sp,colorPreset:np,lightOff:op};function ls(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 ap(t,s,n){return"#"+[t,s,n].map(o=>o.toString(16).padStart(2,"0")).join("")}function ds(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 ks=({device:t,onControl:s,compact:n=!1,theme:o="light",className:a,style:r})=>{var L,I,k;const i=t.state,l=(i==null?void 0:i.on)??!1,h=(i==null?void 0:i.brightness)??100,b=(i==null?void 0:i.colorTemperature)??4e3,d=i==null?void 0:i.rgbColor,[x,v]=u.useState(!1),y=u.useCallback(c=>{s==null||s(t.id,c)},[t.id,s]),_=d?ap(d[0],d[1],d[2]):"var(--nice-bg, #fff)",f=((L=t.capabilities)==null?void 0:L.includes("dimming"))??h!==void 0,p=(I=t.capabilities)==null?void 0:I.includes("color_temperature"),C=((k=t.capabilities)==null?void 0:k.includes("color"))||t.type==="rgb_light";return e.jsxs("div",{className:`${B.lightControl} ${n?B.compact:""} ${o==="dark"?B.dark:""} ${a??""}`,style:r,children:[e.jsxs("div",{className:B.lightHeader,children:[e.jsx("span",{className:B.lightIcon,style:{opacity:l?1:.4},children:e.jsx(z.NiceIcon,{name:"lightbulb",size:16})}),e.jsx("span",{className:B.lightName,children:t.name}),e.jsx("button",{className:`${B.lightToggle} ${l?B.lightToggleOn:""}`,"aria-label":l?"Włączone":"Wyłączone",onClick:()=>y({on:!l}),children:e.jsx(z.NiceIcon,{name:l?"check":"close",size:14})})]}),l&&e.jsxs(e.Fragment,{children:[f&&e.jsxs("div",{className:B.sliderRow,children:[e.jsx("span",{className:B.sliderIcon,children:e.jsx(z.NiceIcon,{name:"lightbulb",size:16})}),e.jsx("input",{type:"range",min:1,max:100,value:h,className:B.slider,style:{"--pct":`${h}%`},onChange:c=>y({brightness:+c.target.value})}),e.jsxs("span",{className:B.sliderVal,children:[h,"%"]})]}),p&&e.jsxs("div",{className:B.sliderRow,children:[e.jsx("span",{className:B.sliderIcon,children:e.jsx(z.NiceIcon,{name:"thermometer",size:16})}),e.jsx("input",{type:"range",min:2700,max:6500,step:100,value:b,className:B.slider,style:{background:`linear-gradient(to right, ${ls(2700)}, ${ls(6500)})`},onChange:c=>y({colorTemperature:+c.target.value})}),e.jsxs("span",{className:B.sliderVal,children:[Math.round(b/100)*100,"K"]})]}),C&&e.jsxs("div",{className:B.colorRow,children:[e.jsx("span",{className:B.sliderIcon,children:e.jsx(z.NiceIcon,{name:"palette",size:16})}),e.jsx("button",{className:B.colorSwatch,style:{background:_},onClick:()=>v(c=>!c)}),x&&e.jsx("input",{type:"color",value:_,className:B.colorPicker,onChange:c=>{const[g,m,j]=ds(c.target.value);y({rgbColor:[g,m,j]})}}),e.jsx("div",{className:B.colorPresets,children:["var(--nice-bg, #fff)","var(--nice-warning-bg, #fde68a)","var(--nice-danger-bg, #fca5a5)","var(--nice-primary-light, #93c5fd)","var(--nice-success-light, #86efac)","var(--nice-accent, #c4b5fd)"].map(c=>e.jsx("button",{className:B.colorPreset,style:{background:c},onClick:()=>{const[g,m,j]=ds(c);y({rgbColor:[g,m,j]})}},c))})]})]}),!l&&!n&&e.jsx("div",{className:B.lightOff,children:"Wyłączone"})]})},us={heat:"Grzanie",cool:"Chłodzenie",auto:"Auto",off:"Wyłącz",fan_only:"Wentylacja",dry:"Osuszanie"},rp={heat:"zap",cool:"thermometer",auto:"refresh",off:"stop",fan_only:"wifi",dry:"droplet"},ip={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 hs(t,s,n,o,a){const r=x=>(x-90)*(Math.PI/180),i=t+n*Math.cos(r(o)),l=s+n*Math.sin(r(o)),h=t+n*Math.cos(r(a)),b=s+n*Math.sin(r(a)),d=a-o>180?1:0;return`M${i.toFixed(2)},${l.toFixed(2)} A${n},${n} 0 ${d},1 ${h.toFixed(2)},${b.toFixed(2)}`}const st=5,yt=35,xt=-140,Is=140;function ms(t){return xt+(t-st)/(yt-st)*(Is-xt)}const Cs=({device:t,onControl:s,compact:n=!1,theme:o="light",className:a,style:r})=>{const i=t.state,l=(i==null?void 0:i.temperature)??20,h=(i==null?void 0:i.targetTemperature)??21,b=i==null?void 0:i.humidity,d=(i==null?void 0:i.mode)??"auto",x=(i==null?void 0:i.hvacAction)??"idle",v=80,y=80,_=60,f=hs(v,y,_,xt,Is),p=ms(Math.min(Math.max(l,st),yt)),C=ms(Math.min(Math.max(h,st),yt)),L=hs(v,y,_,xt,Math.min(p,C)),I=ip[x]??"var(--nice-text-muted, #94a3b8)",k=u.useCallback(g=>{const m=Math.round((h+g)*2)/2;m>=st&&m<=yt&&(s==null||s(t.id,{targetTemperature:m}))},[h,t.id,s]),c=u.useCallback(g=>{s==null||s(t.id,{mode:g})},[t.id,s]);return e.jsxs("div",{className:`${B.thermostat} ${n?B.compact:""} ${o==="dark"?B.dark:""} ${a??""}`,style:r,children:[e.jsx("div",{className:B.thermostatTitle,children:t.name}),e.jsxs("svg",{width:160,height:160,className:B.thermostatDial,children:[e.jsx("path",{d:f,fill:"none",stroke:"var(--nice-border, #e2e8f0)",strokeWidth:8,strokeLinecap:"round"}),e.jsx("path",{d:L,fill:"none",stroke:I,strokeWidth:8,strokeLinecap:"round",opacity:.4}),e.jsx("circle",{cx:v+_*Math.cos((C-90)*(Math.PI/180)),cy:y+_*Math.sin((C-90)*(Math.PI/180)),r:7,fill:I,stroke:"var(--nice-bg, #fff)",strokeWidth:2}),e.jsxs("text",{x:v,y:y-6,textAnchor:"middle",className:B.dialTempCurrent,children:[l.toFixed(1),"°"]}),e.jsx("text",{x:v,y:y+14,textAnchor:"middle",className:B.dialTempLabel,children:"aktualnie"}),e.jsxs("text",{x:v,y:y+32,textAnchor:"middle",className:B.dialTempTarget,children:[h.toFixed(1),"°"]}),b!=null&&e.jsxs("text",{x:v,y:y+48,textAnchor:"middle",className:B.dialHumidity,children:[b,"%"]})]}),e.jsxs("div",{className:B.thermostatAdjust,children:[e.jsx("button",{className:B.adjustBtn,onClick:()=>k(-.5),children:"−"}),e.jsxs("span",{className:B.adjustTemp,children:[h.toFixed(1)," °C"]}),e.jsx("button",{className:B.adjustBtn,onClick:()=>k(.5),children:"+"})]}),!n&&e.jsx("div",{className:B.hvacModes,children:["heat","cool","auto","fan_only","off"].map(g=>e.jsx("button",{title:us[g],"aria-label":us[g],className:`${B.hvacModeBtn} ${d===g?B.hvacModeBtnActive:""}`,onClick:()=>c(g),children:e.jsx(z.NiceIcon,{name:rp[g],size:16})},g))}),e.jsxs("div",{className:B.hvacAction,style:{color:I},children:[e.jsx("span",{className:B.hvacActionDot,style:{background:I}}),x]})]})},cp=({device:t,onControl:s})=>{const n=t.state,o=(n==null?void 0:n.on)===!0;return e.jsxs("div",{className:B.toggleControl,children:[e.jsx("span",{className:B.toggleLabel,children:t.name}),e.jsx("button",{className:`${B.toggleBtn} ${o?B.toggleOn:""}`,onClick:()=>s==null?void 0:s(t.id,{on:!o}),children:o?"WŁĄCZONE":"WYŁĄCZONE"})]})},lp=({device:t,onControl:s})=>{const n=t.state,o=typeof(n==null?void 0:n.position)=="number"?n.position:50;return e.jsxs("div",{className:B.blindControl,children:[e.jsx("span",{className:B.blindLabel,children:t.name}),e.jsxs("div",{className:B.blindActions,children:[e.jsx("button",{className:B.blindBtn,"aria-label":"Otwórz",onClick:()=>s==null?void 0:s(t.id,{command:"open"}),children:e.jsx(z.NiceIcon,{name:"arrow-up",size:16})}),e.jsx("button",{className:B.blindBtn,"aria-label":"Zatrzymaj",onClick:()=>s==null?void 0:s(t.id,{command:"stop"}),children:e.jsx(z.NiceIcon,{name:"stop",size:16})}),e.jsx("button",{className:B.blindBtn,"aria-label":"Zamknij",onClick:()=>s==null?void 0:s(t.id,{command:"close"}),children:e.jsx(z.NiceIcon,{name:"arrow-down",size:16})})]}),e.jsx("input",{type:"range",min:0,max:100,value:o,className:B.blindSlider,onChange:a=>s==null?void 0:s(t.id,{position:+a.target.value})}),e.jsxs("span",{className:B.blindPct,children:[o,"%"]})]})},dp=({device:t,onControl:s})=>{const n=t.state,o=(n==null?void 0:n.locked)!==!1;return e.jsxs("div",{className:B.lockControl,children:[e.jsx("span",{className:B.lockLabel,children:t.name}),e.jsxs("button",{className:`${B.lockBtn} ${o?B.lockLocked:B.lockUnlocked}`,onClick:()=>s==null?void 0:s(t.id,{locked:!o}),children:[e.jsx(z.NiceIcon,{name:"lock",size:14})," ",o?"Zablokowany":"Odblokowany"]})]})},up=({device:t})=>{const s=t.state;return e.jsxs("div",{className:B.cameraControl,children:[e.jsx("span",{className:B.cameraLabel,children:t.name}),s!=null&&s.snapshotUrl?e.jsx("img",{src:s.snapshotUrl,alt:"snapshot",className:B.cameraSnapshot}):e.jsxs("div",{className:B.cameraPlaceholder,children:[e.jsx(z.NiceIcon,{name:"camera",size:16}),e.jsx("span",{children:s!=null&&s.streaming?"Streaming":"Brak podglądu"})]}),e.jsxs("div",{className:B.cameraStatus,children:[e.jsx("span",{className:`${B.cameraDot} ${t.status==="online"?B.cameraOnline:B.cameraOffline}`}),t.status]})]})},hp=({device:t})=>{const s=t.state;return e.jsxs("div",{className:B.sensorControl,children:[e.jsx("span",{className:B.sensorLabel,children:t.name}),e.jsx("div",{className:B.sensorValues,children:Object.entries(s??{}).map(([n,o])=>o!=null&&e.jsxs("div",{className:B.sensorRow,children:[e.jsx("span",{className:B.sensorKey,children:n}),e.jsx("span",{className:B.sensorVal,children:String(o)})]},n))})]})},mp=({device:t,onControl:s,compact:n=!1,className:o,style:a,theme:r="light"})=>{const i=t.type,l=["light","dimmer","rgb_light","led_strip"].includes(i)?e.jsx(ks,{device:t,onControl:s,compact:n,theme:r}):["thermostat","air_conditioner","heat_pump","floor_heating"].includes(i)?e.jsx(Cs,{device:t,onControl:s,compact:n,theme:r}):["blind","shutter","curtain","awning","garage_door"].includes(i)?e.jsx(lp,{device:t,onControl:s}):["lock","door"].includes(i)?e.jsx(dp,{device:t,onControl:s}):["camera","doorbell"].includes(i)?e.jsx(up,{device:t}):i.endsWith("_sensor")||["motion_sensor","smoke_detector","water_leak_sensor","alarm"].includes(i)?e.jsx(hp,{device:t}):e.jsx(cp,{device:t,onControl:s});return e.jsxs("div",{className:`${B.deviceControl} ${r==="dark"?B.dark:""} ${n?B.compact:""} ${t.status==="offline"?B.offline:""} ${o??""}`,style:a,children:[l,t.status==="offline"&&e.jsx("div",{className:B.offlineBanner,children:"Offline"})]})},pp="_root_1aqqe_3",_p="_shell_1aqqe_29",fp="_dark_1aqqe_37",gp="_listPanel_1aqqe_51",yp="_listHeader_1aqqe_79",xp="_listTitle_1aqqe_103",bp="_addBtn_1aqqe_121",vp="_list_1aqqe_51",jp="_listItem_1aqqe_159",wp="_listItemActive_1aqqe_199",Np="_listItemName_1aqqe_213",kp="_listItemMeta_1aqqe_241",Ip="_enableToggle_1aqqe_255",Cp="_enableOn_1aqqe_273",Sp="_detailPanel_1aqqe_283",zp="_detailHeader_1aqqe_295",Lp="_nameInput_1aqqe_309",$p="_deleteBtn_1aqqe_343",Tp="_section_1aqqe_373",Mp="_sectionHeader_1aqqe_381",Bp="_sectionTitle_1aqqe_395",Pp="_sectionAddBtn_1aqqe_411",Ep="_ruleBlock_1aqqe_441",Op="_ruleBlockHeader_1aqqe_467",Ap="_typeSelect_1aqqe_481",Dp="_removeBtn_1aqqe_513",Rp="_ruleFields_1aqqe_551",Fp="_input_1aqqe_587",Wp="_textarea_1aqqe_619",Gp="_dayPicker_1aqqe_655",qp="_dayBtn_1aqqe_667",Vp="_dayBtnActive_1aqqe_687",Up="_noSelection_1aqqe_701",Hp="_emptyHint_1aqqe_703",R={root:pp,shell:_p,dark:fp,listPanel:gp,listHeader:yp,listTitle:xp,addBtn:bp,list:vp,listItem:jp,listItemActive:wp,listItemName:Np,listItemMeta:kp,enableToggle:Ip,enableOn:Cp,detailPanel:Sp,detailHeader:zp,nameInput:Lp,deleteBtn:$p,section:Tp,sectionHeader:Mp,sectionTitle:Bp,sectionAddBtn:Pp,ruleBlock:Ep,ruleBlockHeader:Op,typeSelect:Ap,removeBtn:Dp,ruleFields:Rp,input:Fp,textarea:Wp,dayPicker:Gp,dayBtn:qp,dayBtnActive:Vp,noSelection:Up,emptyHint:Hp},Yp=[{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"}],Te=(t,s,n="")=>{const o=t[s];return typeof o=="string"?o:n},Rt=(t,s,n=0)=>{const o=t[s];return typeof o=="number"?o:n},Zp=(t,s,n)=>{const o=t[s];return Array.isArray(o)?o:n},Xp=(t,s)=>{const n=t[s];return n&&typeof n=="object"?n:{}},Kp=({trigger:t,devices:s,onChange:n,onRemove:o})=>{const a=r=>n({...t,...r});return e.jsxs("div",{className:R.ruleBlock,children:[e.jsxs("div",{className:R.ruleBlockHeader,children:[e.jsxs("select",{className:R.typeSelect,value:t.type,onChange:r=>n({type:r.target.value}),children:[e.jsx("option",{value:"time",children:"Czas"}),e.jsx("option",{value:"sunrise",children:"Wschód słońca"}),e.jsx("option",{value:"sunset",children:"Zachód słońca"}),e.jsx("option",{value:"device_state",children:"Stan urządzenia"}),e.jsx("option",{value:"sensor_threshold",children:"Próg sensora"}),e.jsx("option",{value:"occupancy",children:"Obecność"}),e.jsx("option",{value:"webhook",children:"Webhook"}),e.jsx("option",{value:"calendar",children:"Kalendarz"})]}),e.jsx("button",{className:R.removeBtn,onClick:o,title:"Usuń","aria-label":"Usuń",children:e.jsx(z.NiceIcon,{name:"close",size:14})})]}),t.type==="time"&&e.jsxs("div",{className:R.ruleFields,children:[e.jsxs("label",{children:["Godzina",e.jsx("input",{type:"time",className:R.input,value:Te(t,"time","08:00"),onChange:r=>a({time:r.target.value})})]}),e.jsxs("label",{children:["Dni",e.jsx("div",{className:R.dayPicker,children:["Pon","Wt","Śr","Czw","Pt","Sob","Nd"].map((r,i)=>{const l=Zp(t,"days",[0,1,2,3,4]),h=l.includes(i);return e.jsx("button",{className:`${R.dayBtn} ${h?R.dayBtnActive:""}`,onClick:()=>a({days:h?l.filter(b=>b!==i):[...l,i]}),children:r},i)})})]})]}),(t.type==="sunrise"||t.type==="sunset")&&e.jsx("div",{className:R.ruleFields,children:e.jsxs("label",{children:["Offset (minuty)",e.jsx("input",{type:"number",className:R.input,min:-120,max:120,step:5,value:Rt(t,"offsetMinutes",0),onChange:r=>a({offsetMinutes:+r.target.value})})]})}),(t.type==="device_state"||t.type==="sensor_threshold")&&e.jsxs("div",{className:R.ruleFields,children:[e.jsxs("label",{children:["Urządzenie",e.jsxs("select",{className:R.input,value:Te(t,"deviceId",""),onChange:r=>a({deviceId:r.target.value}),children:[e.jsx("option",{value:"",children:"— wybierz —"}),s.map(r=>e.jsx("option",{value:r.id,children:r.name},r.id))]})]}),t.type==="sensor_threshold"&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{children:["Atrybut",e.jsx("input",{className:R.input,value:Te(t,"attribute",""),onChange:r=>a({attribute:r.target.value})})]}),e.jsxs("label",{children:["Operator",e.jsxs("select",{className:R.input,value:Te(t,"operator","above"),onChange:r=>a({operator:r.target.value}),children:[e.jsx("option",{value:"above",children:"powyżej"}),e.jsx("option",{value:"below",children:"poniżej"}),e.jsx("option",{value:"equals",children:"równe"})]})]}),e.jsxs("label",{children:["Próg",e.jsx("input",{type:"number",className:R.input,value:Rt(t,"threshold",0),onChange:r=>a({threshold:+r.target.value})})]})]})]}),t.type==="webhook"&&e.jsx("div",{className:R.ruleFields,children:e.jsxs("label",{children:["Endpoint ID",e.jsx("input",{className:R.input,value:Te(t,"webhookId",""),onChange:r=>a({webhookId:r.target.value})})]})})]})},Jp=({action:t,devices:s,onChange:n,onRemove:o})=>{const a=r=>n({...t,...r});return e.jsxs("div",{className:R.ruleBlock,children:[e.jsxs("div",{className:R.ruleBlockHeader,children:[e.jsxs("select",{className:R.typeSelect,value:t.type,onChange:r=>n({type:r.target.value}),children:[e.jsx("option",{value:"device_control",children:"Urządzenie"}),e.jsx("option",{value:"scene_activate",children:"Aktywuj scenę"}),e.jsx("option",{value:"notification",children:"Powiadomienie"}),e.jsx("option",{value:"delay",children:"Opóźnienie"}),e.jsx("option",{value:"http_request",children:"HTTP Request"})]}),e.jsx("button",{className:R.removeBtn,onClick:o,title:"Usuń","aria-label":"Usuń",children:e.jsx(z.NiceIcon,{name:"close",size:14})})]}),t.type==="device_control"&&e.jsxs("div",{className:R.ruleFields,children:[e.jsxs("label",{children:["Urządzenie",e.jsxs("select",{className:R.input,value:Te(t,"deviceId",""),onChange:r=>a({deviceId:r.target.value}),children:[e.jsx("option",{value:"",children:"— wybierz —"}),s.map(r=>e.jsx("option",{value:r.id,children:r.name},r.id))]})]}),e.jsxs("label",{children:["Stan (JSON)",e.jsx("textarea",{className:R.textarea,rows:3,value:JSON.stringify(Xp(t,"state"),null,2),onChange:r=>{try{a({state:JSON.parse(r.target.value)})}catch{}}})]})]}),t.type==="notification"&&e.jsxs("div",{className:R.ruleFields,children:[e.jsxs("label",{children:["Kanał",e.jsxs("select",{className:R.input,value:Te(t,"channel","push"),onChange:r=>a({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:["Wiadomość",e.jsx("input",{className:R.input,value:Te(t,"message",""),onChange:r=>a({message:r.target.value})})]})]}),t.type==="delay"&&e.jsx("div",{className:R.ruleFields,children:e.jsxs("label",{children:["Opóźnienie (sekundy)",e.jsx("input",{type:"number",className:R.input,min:1,value:Rt(t,"delaySeconds",60),onChange:r=>a({delaySeconds:+r.target.value})})]})}),t.type==="http_request"&&e.jsxs("div",{className:R.ruleFields,children:[e.jsxs("label",{children:["URL",e.jsx("input",{className:R.input,value:Te(t,"url",""),onChange:r=>a({url:r.target.value})})]}),e.jsxs("label",{children:["Metoda",e.jsxs("select",{className:R.input,value:Te(t,"method","POST"),onChange:r=>a({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"})]})]})]})]})},Qp=({automations:t,defaultAutomations:s,devices:n=[],onAutomationsChange:o,readOnly:a=!1,className:r,style:i,theme:l="light",tutorial:h})=>{var k;const[b,d]=z.useControllableState({value:t,defaultValue:s,fallbackValue:[],onChange:o,componentName:"NiceAutomationEditor"}),[x,v]=u.useState(null),y=x!==null&&b.some(c=>c.id===x)?x:((k=b[0])==null?void 0:k.id)??null,_=b.find(c=>c.id===y)??null,f=u.useCallback(c=>{_&&d(b.map(g=>g.id===_.id?{...g,...c}:g))},[_,b,d]),p=u.useCallback(()=>{const c={id:`auto-${Date.now()}`,name:"Nowa automatyzacja",enabled:!0,triggers:[],conditions:[],actions:[]};d([...b,c]),v(c.id)},[b,d]),C=u.useCallback(c=>{var g;d(b.filter(m=>m.id!==c)),y===c&&v(((g=b.find(m=>m.id!==c))==null?void 0:g.id)??null)},[b,y,d]),L=e.jsxs("div",{className:R.listPanel,children:[e.jsxs("div",{className:R.listHeader,children:[e.jsx("span",{className:R.listTitle,children:"Automatyzacje"}),!a&&e.jsx("button",{className:R.addBtn,onClick:p,children:"+ Dodaj"})]}),e.jsxs("div",{className:R.list,children:[b.map(c=>e.jsxs("div",{className:`${R.listItem} ${y===c.id?R.listItemActive:""}`,onClick:()=>v(c.id),children:[e.jsx("div",{className:R.listItemName,children:c.name}),e.jsxs("div",{className:R.listItemMeta,children:[c.triggers.length," wyzw · ",c.actions.length," akcji"]}),e.jsx("button",{className:`${R.enableToggle} ${c.enabled?R.enableOn:""}`,onClick:g=>{g.stopPropagation(),f({enabled:!c.enabled})},title:c.enabled?"Wyłącz":"Włącz","aria-label":c.enabled?"Wyłącz":"Włącz",children:e.jsx(z.NiceIcon,{name:c.enabled?"check":"close",size:14})})]},c.id)),b.length===0&&e.jsx("div",{className:R.emptyHint,children:"Brak automatyzacji"})]})]}),I=e.jsx("div",{className:R.detailPanel,children:_?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:R.detailHeader,children:[e.jsx("input",{className:R.nameInput,value:_.name,onChange:c=>f({name:c.target.value}),readOnly:a}),!a&&e.jsx("button",{className:R.deleteBtn,onClick:()=>C(_.id),children:"Usuń"})]}),e.jsxs("section",{className:R.section,children:[e.jsxs("div",{className:R.sectionHeader,children:[e.jsx("span",{className:R.sectionTitle,children:"Wyzwalacze"}),!a&&e.jsx("button",{className:R.sectionAddBtn,onClick:()=>f({triggers:[..._.triggers,{type:"time"}]}),children:"+ Dodaj"})]}),_.triggers.map((c,g)=>e.jsx(Kp,{trigger:c,devices:n,onChange:m=>f({triggers:_.triggers.map((j,E)=>E===g?m:j)}),onRemove:()=>f({triggers:_.triggers.filter((m,j)=>j!==g)})},g)),_.triggers.length===0&&e.jsx("div",{className:R.emptyHint,children:"Brak wyzwalaczy"})]}),e.jsxs("section",{className:R.section,children:[e.jsxs("div",{className:R.sectionHeader,children:[e.jsx("span",{className:R.sectionTitle,children:"Akcje"}),!a&&e.jsx("button",{className:R.sectionAddBtn,onClick:()=>f({actions:[..._.actions,{type:"device_control"}]}),children:"+ Dodaj"})]}),_.actions.map((c,g)=>e.jsx(Jp,{action:c,devices:n,onChange:m=>f({actions:_.actions.map((j,E)=>E===g?m:j)}),onRemove:()=>f({actions:_.actions.filter((m,j)=>j!==g)})},g)),_.actions.length===0&&e.jsx("div",{className:R.emptyHint,children:"Brak akcji"})]})]}):e.jsx("div",{className:R.noSelection,children:"Wybierz automatyzację lub dodaj nową"})});return e.jsxs("div",{className:`nice-building-automation-editor ${R.root} ${l==="dark"?R.dark:""} ${r??""}`,style:{position:"relative",...i},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:e.jsx(z.NiceTutorialButton,{steps:z.resolveTutorial(h,Yp)})}),e.jsx(z.NiceAppShell,{flush:!0,className:R.shell,sidebar:L,children:I})]})},e_="_root_iuuw6_3",t_="_shell_iuuw6_29",s_="_dark_iuuw6_37",n_="_gridPanel_iuuw6_51",o_="_gridHeader_iuuw6_79",a_="_gridTitle_iuuw6_103",r_="_addBtn_iuuw6_119",i_="_sceneGrid_iuuw6_147",c_="_sceneCard_iuuw6_165",l_="_sceneCardActive_iuuw6_193",d_="_sceneCardSelected_iuuw6_199",u_="_sceneCardIcon_iuuw6_207",h_="_sceneCardName_iuuw6_217",m_="_sceneCardDevices_iuuw6_235",p_="_activeBadge_iuuw6_253",__="_activateBtn_iuuw6_263",f_="_emptyGrid_iuuw6_307",g_="_detailPanel_iuuw6_325",y_="_metaRow_iuuw6_343",x_="_iconPicker_iuuw6_355",b_="_currentIcon_iuuw6_363",v_="_iconGrid_iuuw6_381",j_="_iconOpt_iuuw6_397",w_="_iconOptActive_iuuw6_423",N_="_metaFields_iuuw6_433",k_="_nameInput_iuuw6_447",I_="_descInput_iuuw6_481",C_="_colorPicker_iuuw6_517",S_="_colorOpt_iuuw6_527",z_="_colorOptActive_iuuw6_543",L_="_targetsSection_iuuw6_553",$_="_targetsSectionHeader_iuuw6_565",T_="_addTargetBtn_iuuw6_587",M_="_targetRow_iuuw6_615",B_="_targetSelect_iuuw6_645",P_="_targetState_iuuw6_677",E_="_targetField_iuuw6_691",O_="_tempInput_iuuw6_717",A_="_removeTargetBtn_iuuw6_735",D_="_noTargets_iuuw6_775",R_="_detailActions_iuuw6_795",F_="_activateFullBtn_iuuw6_809",W_="_deleteBtn_iuuw6_841",Y={root:e_,shell:t_,dark:s_,gridPanel:n_,gridHeader:o_,gridTitle:a_,addBtn:r_,sceneGrid:i_,sceneCard:c_,sceneCardActive:l_,sceneCardSelected:d_,sceneCardIcon:u_,sceneCardName:h_,sceneCardDevices:m_,activeBadge:p_,activateBtn:__,emptyGrid:f_,detailPanel:g_,metaRow:y_,iconPicker:x_,currentIcon:b_,iconGrid:v_,iconOpt:j_,iconOptActive:w_,metaFields:N_,nameInput:k_,descInput:I_,colorPicker:C_,colorOpt:S_,colorOptActive:z_,targetsSection:L_,targetsSectionHeader:$_,addTargetBtn:T_,targetRow:M_,targetSelect:B_,targetState:P_,targetField:E_,tempInput:O_,removeTargetBtn:A_,noTargets:D_,detailActions:R_,activateFullBtn:F_,deleteBtn:W_},G_=[{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"}],nt=t=>t&&typeof t=="object"?t:{},q_=(t,s,n=!1)=>{const o=nt(t)[s];return typeof o=="boolean"?o:n},Dt=(t,s,n=0)=>{const o=nt(t)[s];return typeof o=="number"?o:n},V_=["video","eye-off","lightbulb","gamepad","briefcase","utensils","music","droplet","rocket","home","thermometer","lock","star","gift","heart","settings"],U_=["var(--nice-primary-bg, #e0f2fe)","var(--nice-accent-bg, #fce7f3)","var(--nice-success-bg, #dcfce7)","var(--nice-warning-bg, #fef9c3)","var(--nice-accent-bg, #ede9fe)","var(--nice-danger-bg, #fee2e2)","var(--nice-success-bg, #f0fdf4)","#fff7ed"],H_=({target:t,devices:s,onChange:n,onRemove:o})=>{const a=s.find(r=>r.id===t.deviceId);return e.jsxs("div",{className:Y.targetRow,children:[e.jsxs("select",{className:Y.targetSelect,value:t.deviceId,onChange:r=>n({...t,deviceId:r.target.value}),children:[e.jsx("option",{value:"",children:"— urządzenie —"}),s.map(r=>e.jsx("option",{value:r.id,children:r.name},r.id))]}),a&&e.jsxs("div",{className:Y.targetState,children:[e.jsxs("label",{className:Y.targetField,children:[e.jsx("span",{children:"Wł/Wył"}),e.jsx("input",{type:"checkbox",checked:q_(t.state,"on",!1),onChange:r=>n({...t,state:{...nt(t.state),on:r.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:"Jasność"}),e.jsx("input",{type:"range",min:0,max:100,value:Dt(t.state,"brightness",100),onChange:r=>n({...t,state:{...nt(t.state),brightness:+r.target.value}})}),e.jsxs("span",{children:[Dt(t.state,"brightness",100),"%"]})]}),(a.type==="thermostat"||a.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:Dt(t.state,"targetTemperature",20),onChange:r=>n({...t,state:{...nt(t.state),targetTemperature:+r.target.value}})}),e.jsx("span",{children:"°C"})]})]}),e.jsx("button",{className:Y.removeTargetBtn,onClick:o,title:"Usuń","aria-label":"Usuń",children:e.jsx(z.NiceIcon,{name:"close",size:14})})]})},Y_=({scenes:t,defaultScenes:s,devices:n=[],activeSceneIds:o=[],onScenesChange:a,onActivate:r,readOnly:i=!1,className:l,style:h,theme:b="light",tutorial:d})=>{var m;const[x,v]=z.useControllableState({value:t,defaultValue:s,fallbackValue:[],onChange:a,componentName:"NiceSceneEditor"}),[y,_]=u.useState(null),f=y!==null&&x.some(j=>j.id===y)?y:((m=x[0])==null?void 0:m.id)??null,p=x.find(j=>j.id===f)??null,C=u.useCallback(j=>{p&&v(x.map(E=>E.id===p.id?{...E,...j}:E))},[p,x,v]),L=u.useCallback(()=>{const j={id:`scene-${Date.now()}`,name:"Nowa scena",deviceTargets:[],icon:"video",color:"var(--nice-primary-bg, #e0f2fe)"};v([...x,j]),_(j.id)},[x,v]),I=u.useCallback(j=>{var E;v(x.filter(F=>F.id!==j)),f===j&&_(((E=x.find(F=>F.id!==j))==null?void 0:E.id)??null)},[x,f,v]),k=()=>{if(!p)return;const j={deviceId:"",state:{on:!0},transitionMs:1e3};C({deviceTargets:[...p.deviceTargets,j]})},c=e.jsxs("div",{className:Y.gridPanel,children:[e.jsxs("div",{className:Y.gridHeader,children:[e.jsx("span",{className:Y.gridTitle,children:"Sceny"}),!i&&e.jsx("button",{className:Y.addBtn,onClick:L,children:"+ Nowa"})]}),e.jsxs("div",{className:Y.sceneGrid,children:[x.map(j=>{const E=o.includes(j.id),F=f===j.id;return e.jsxs("div",{className:`${Y.sceneCard} ${E?Y.sceneCardActive:""} ${F?Y.sceneCardSelected:""}`,style:{background:j.color??"var(--nice-bg-secondary, #f8fafc)"},onClick:()=>_(j.id),children:[e.jsx("div",{className:Y.sceneCardIcon,children:e.jsx(z.NiceIcon,{name:j.icon??"video",size:20})}),e.jsx("div",{className:Y.sceneCardName,children:j.name}),e.jsxs("div",{className:Y.sceneCardDevices,children:[j.deviceTargets.length," urządzeń",E&&e.jsx("span",{className:Y.activeBadge,children:e.jsx(z.NiceIcon,{name:"check",size:12})})]}),e.jsx("button",{className:Y.activateBtn,"aria-label":"Aktywuj",onClick:de=>{de.stopPropagation(),r==null||r(j.id)},children:e.jsx(z.NiceIcon,{name:"play",size:14})})]},j.id)}),x.length===0&&e.jsx("div",{className:Y.emptyGrid,children:"Brak scen. Dodaj pierwszą!"})]})]}),g=p?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(z.NiceIcon,{name:p.icon??"video",size:20})}),e.jsx("div",{className:Y.iconGrid,children:V_.map(j=>e.jsx("button",{className:`${Y.iconOpt} ${p.icon===j?Y.iconOptActive:""}`,"aria-label":j,onClick:()=>C({icon:j}),children:e.jsx(z.NiceIcon,{name:j,size:16})},j))})]}),e.jsxs("div",{className:Y.metaFields,children:[e.jsx("input",{className:Y.nameInput,value:p.name,readOnly:i,onChange:j=>C({name:j.target.value}),placeholder:"Nazwa sceny"}),e.jsx("textarea",{className:Y.descInput,value:p.description??"",readOnly:i,onChange:j=>C({description:j.target.value}),placeholder:"Opis (opcjonalny)",rows:2})]})]}),!i&&e.jsx("div",{className:Y.colorPicker,children:U_.map(j=>e.jsx("button",{className:`${Y.colorOpt} ${p.color===j?Y.colorOptActive:""}`,style:{background:j},onClick:()=>C({color:j})},j))}),e.jsxs("div",{className:Y.targetsSection,children:[e.jsxs("div",{className:Y.targetsSectionHeader,children:[e.jsx("span",{children:"Urządzenia w scenie"}),!i&&e.jsx("button",{className:Y.addTargetBtn,onClick:k,children:"+ Dodaj"})]}),p.deviceTargets.map((j,E)=>e.jsx(H_,{target:j,devices:n,onChange:F=>C({deviceTargets:p.deviceTargets.map((de,ee)=>ee===E?F:de)}),onRemove:()=>C({deviceTargets:p.deviceTargets.filter((F,de)=>de!==E)})},E)),p.deviceTargets.length===0&&e.jsx("div",{className:Y.noTargets,children:"Dodaj urządzenia, które powinna kontrolować ta scena."})]}),e.jsxs("div",{className:Y.detailActions,children:[e.jsxs("button",{className:Y.activateFullBtn,onClick:()=>r==null?void 0:r(p.id),children:[e.jsx(z.NiceIcon,{name:"play",size:14})," Aktywuj scenę"]}),!i&&e.jsx("button",{className:Y.deleteBtn,onClick:()=>I(p.id),children:"Usuń"})]})]}):void 0;return e.jsxs("div",{className:`nice-scene-editor ${Y.root} ${b==="dark"?Y.dark:""} ${l??""}`,style:{position:"relative",...h},children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:e.jsx(z.NiceTutorialButton,{steps:z.resolveTutorial(d,G_)})}),e.jsx(z.NiceAppShell,{flush:!0,className:Y.shell,sidebar:c,children:g})]})};exports.LayerPanel=xs;exports.Minimap=bs;exports.NiceAutomationEditor=Qp;exports.NiceBuildingDashboard=Hh;exports.NiceDeviceControl=mp;exports.NiceFloorPlanEditor=Tn;exports.NiceLightControl=ks;exports.NiceSceneEditor=Y_;exports.NiceSpatialEditor=_d;exports.NiceSpatialViewer=Ku;exports.NiceThermostatControl=Cs;exports.NiceZoneCard=Ns;exports.ObjectLibrary=vs;exports.PropertiesPanel=js;exports.useMeasurement=eh;exports.useSnapToGrid=Qu;exports.useSpatialEditor=Ju;
|
|
139
|
+
`,j=m=>m.boundary;return x.forEach((m,k)=>{const C=j(m);if(m.type==="wall"&&m.bounds)_.push(e.jsx("rect",{x:m.bounds.x,y:m.bounds.y,width:m.bounds.width,height:m.bounds.height,fill:"var(--nice-text-secondary, #475569)",stroke:"var(--nice-text, #334155)",strokeWidth:"1"},`wall-${k}`));else if(m.type==="zone"&&C){const T=C.map((b,L)=>`${L===0?"M":"L"} ${b.x} ${b.y}`).join(" ")+" Z";_.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(m.type==="room"&&C){const T=C.map((b,L)=>`${L===0?"M":"L"} ${b.x} ${b.y}`).join(" ")+" Z";_.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 m.bounds&&_.push(e.jsx("rect",{x:m.bounds.x,y:m.bounds.y,width:m.bounds.width,height:m.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:`${l.x} ${l.y} ${l.width} ${l.height}`,className:U.previewSvg,preserveAspectRatio:"xMidYMid meet",children:[e.jsx("defs",{dangerouslySetInnerHTML:{__html:f}}),e.jsx("rect",{x:l.x,y:l.y,width:l.width,height:l.height,fill:"url(#grid)"}),_]})},[a,o]),c=u.useCallback(l=>{l.key==="Escape"&&n()},[n]),r=u.useCallback(l=>{l.target===l.currentTarget&&n()},[n]),h=t.errors.some(l=>l.fatal),y=t.errors.filter(l=>!l.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(Qo,{})})]}),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(ea,{})," 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(ts,{})," Layers (",a.layers.length,")"]}),e.jsxs("ul",{className:U.layersList,children:[a.layers.slice(0,6).map((l,x)=>{var _;return e.jsxs("li",{className:U.layer,children:[e.jsx("span",{className:U.layerIcon,children:e.jsx(ts,{})}),e.jsx("span",{className:U.layerName,children:l.name}),e.jsx("span",{className:U.layerCount,children:((_=l.objects)==null?void 0:_.length)||0})]},l.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(Qt,{})," Warnings (",t.warnings.length,")"]}),e.jsxs("ul",{className:U.warningsList,children:[t.warnings.slice(0,5).map((l,x)=>e.jsxs("li",{className:U.warning,children:[e.jsx("span",{className:U.warningIcon,children:e.jsx(Qt,{})}),e.jsx("span",{children:l.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(es,{})," Errors (",y.length,")"]}),e.jsx("ul",{className:U.warningsList,children:y.slice(0,5).map((l,x)=>e.jsxs("li",{className:U.error,children:[e.jsx("span",{className:U.errorIcon,children:e.jsx(es,{})}),e.jsx("span",{children:l.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:h,children:h?"Cannot Import (Fatal Errors)":"Confirm Import"})]})]})})}const sa="_overlay_1jmp3_9",na="_dialog_1jmp3_55",oa="_header_1jmp3_103",aa="_title_1jmp3_119",ia="_closeButton_1jmp3_133",ra="_content_1jmp3_167",ca="_description_1jmp3_179",la="_mappingTable_1jmp3_191",da="_sourceLayer_1jmp3_241",ua="_layerIcon_1jmp3_253",ma="_layerName_1jmp3_261",ha="_objectCount_1jmp3_273",pa="_targetSelect_1jmp3_285",_a="_skipOption_1jmp3_327",fa="_arrowIcon_1jmp3_337",ga="_presets_1jmp3_347",ya="_presetButton_1jmp3_361",ba="_footer_1jmp3_393",xa="_footerLeft_1jmp3_413",va="_checkbox_1jmp3_425",ja="_checkboxLabel_1jmp3_437",wa="_footerRight_1jmp3_447",Na="_cancelButton_1jmp3_457",ka="_confirmButton_1jmp3_489",re={overlay:sa,dialog:na,header:oa,title:aa,closeButton:ia,content:ra,description:ca,mappingTable:la,sourceLayer:da,layerIcon:ua,layerName:ma,objectCount:ha,targetSelect:pa,skipOption:_a,arrowIcon:fa,presets:ga,presetButton:ya,footer:ba,footerLeft:xa,checkbox:va,checkboxLabel:ja,footerRight:wa,cancelButton:Na,confirmButton:ka},ss=()=>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"})}),Ia=()=>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"})}),Ca=()=>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"})}),ns={"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 Sa(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 La(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 os(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 Ta=({importResult:t,existingDocument:s,onConfirm:n,onCancel:o})=>{const{t:a}=S.useNiceTranslation(),i=u.useMemo(()=>Sa(t),[t]),c=u.useMemo(()=>La(s),[s]),[r,h]=u.useState(()=>os(i,c)),[y,l]=u.useState(!0),x=u.useCallback((m,k)=>{h(C=>{const T=new Map(C);return T.set(m,k),T})},[]),_=u.useCallback(m=>{const k=new Map;switch(m){case"auto":h(os(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}h(k)},[i,c]),p=u.useCallback(()=>{n(r,y)},[r,y,n]),f=u.useCallback(m=>{m.key==="Escape"?o():m.key==="Enter"&&(m.ctrlKey||m.metaKey)&&p()},[o,p]),j=u.useCallback(m=>{m.target===m.currentTarget&&o()},[o]);return i.length===0?e.jsx("div",{className:re.overlay,onClick:j,onKeyDown:f,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(ss,{})})]}),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:f,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(ss,{})})]}),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(m=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsxs("div",{className:re.sourceLayer,children:[e.jsx("span",{className:re.layerIcon,children:e.jsx(Ia,{})}),e.jsx("span",{className:re.layerName,children:m.name}),e.jsxs("span",{className:re.objectCount,children:["(",m.objectCount," ",m.objectCount===1?a("buildings.spatial.object","object"):a("buildings.spatial.objects","objects"),")"]})]})}),e.jsx("td",{className:re.arrowIcon,children:e.jsx(Ca,{})}),e.jsx("td",{children:e.jsxs("select",{className:re.targetSelect,value:r.get(m.id)||m.id,onChange:k=>x(m.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:m.id,children:[a("buildings.spatial.create","Create"),": ",m.name," (",ns[m.type],")"]}),c.map(k=>e.jsxs("option",{value:k.id,children:[k.name," (",ns[k.type],")"]},k.id))]})})]},m.id))})]}),e.jsxs("div",{className:re.presets,children:[e.jsx("button",{className:re.presetButton,onClick:()=>_("auto"),children:"Auto-mapowanie"}),e.jsx("button",{className:re.presetButton,onClick:()=>_("preserve"),children:a("buildings.spatial.keepAll","Keep all")}),e.jsx("button",{className:re.presetButton,onClick:()=>_("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:m=>l(m.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")})]})]})]})})},$a="_root_4ino1_9",za="_header_4ino1_21",Ma="_title_4ino1_31",Ba="_layerList_4ino1_45",Ea="_layerItem_4ino1_55",Pa="_hidden_4ino1_83",Aa="_locked_4ino1_91",Oa="_visibilityBtn_4ino1_99",Da="_lockBtn_4ino1_101",Ra="_layerIcon_4ino1_139",qa="_layerName_4ino1_147",Fa="_opacitySlider_4ino1_157",Se={root:$a,header:za,title:Ma,layerList:Ba,layerItem:Ea,hidden:Pa,locked:Aa,visibilityBtn:Oa,lockBtn:Da,layerIcon:Ra,layerName:qa,opacitySlider:Fa},Ga={"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"}},vs=({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:`${Se.root} ${a??""}`,children:[e.jsx("div",{className:Se.header,children:e.jsx("h3",{className:Se.title,children:"Layers"})}),e.jsx("div",{className:Se.layerList,children:i.map(c=>{const r=Ga[c.type]||{icon:"box",label:c.type};return e.jsxs("div",{className:`${Se.layerItem} ${c.visible?"":Se.hidden} ${c.locked?Se.locked:""}`,children:[e.jsx("button",{className:Se.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:Se.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:Se.layerIcon,children:e.jsx(S.NiceIcon,{name:r.icon,size:16})}),e.jsx("span",{className:Se.layerName,children:r.label}),e.jsx("input",{type:"range",min:"0",max:"1",step:"0.1",value:c.opacity,onChange:h=>o(c.type,parseFloat(h.target.value)),className:Se.opacitySlider,title:`Opacity: ${Math.round(c.opacity*100)}%`})]},c.type)})})]})},Va="_root_1lufq_9",Wa="_svg_1lufq_31",Ha="_viewportRect_1lufq_41",Ua="_zoomIndicator_1lufq_49",pt={root:Va,svg:Wa,viewportRect:Ha,zoomIndicator:Ua},js=({document:t,activeFloorId:s,viewport:n,onViewportChange:o,size:a=150,className:i})=>{var T,b;const c=u.useRef(null),r=u.useMemo(()=>t.floors.find(L=>L.id===s)??t.floors[0]??null,[t,s]);if(!r)return null;const h=((T=r.dimensions)==null?void 0:T.width)??1e3,y=((b=r.dimensions)==null?void 0:b.height)??800,l=Math.min(a/h,a/y)*.9,x=h*l,_=y*l,p=a/n.zoom*l,f=a/n.zoom*l,j=-n.pan.x/n.zoom*l,m=-n.pan.y/n.zoom*l,k=u.useCallback(L=>{var B;const d=(B=c.current)==null?void 0:B.getBoundingClientRect();if(!d)return;const v=(L.clientX-d.left-(a-x)/2)/l,g=(L.clientY-d.top-(a-_)/2)/l,q=-(v-a/n.zoom/2)*n.zoom,I=-(g-a/n.zoom/2)*n.zoom;o({pan:{x:q,y:I}})},[l,a,x,_,n.zoom,o]),C=u.useMemo(()=>{const L=r.layers.find(d=>d.name==="zones");return L?L.objects.map(d=>{const v=d;if(!v.polygon||v.polygon.length<3)return null;const g=v.polygon.map((q,I)=>`${I===0?"M":"L"}${q.x*l},${q.y*l}`).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,l]);return e.jsxs("div",{className:`${pt.root} ${i??""}`,children:[e.jsxs("svg",{ref:c,width:a,height:a,viewBox:`0 0 ${a} ${a}`,className:pt.svg,onClick:k,children:[e.jsx("rect",{x:(a-x)/2,y:(a-_)/2,width:x,height:_,fill:"var(--nice-bg-secondary, #1e293b)",stroke:"var(--nice-border-color, #475569)",strokeWidth:1}),e.jsx("g",{transform:`translate(${(a-x)/2}, ${(a-_)/2})`,children:C}),e.jsx("rect",{x:(a-x)/2+j,y:(a-_)/2+m,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:pt.viewportRect})]}),e.jsxs("div",{className:pt.zoomIndicator,children:[Math.round(n.zoom*100),"%"]})]})},Ya="_panel_1jo5f_9",Za="_header_1jo5f_27",Xa="_title_1jo5f_45",Ka="_closeButton_1jo5f_59",Ja="_content_1jo5f_85",Qa="_endpointSection_1jo5f_99",ei="_endpointLabel_1jo5f_107",ti="_endpointSelect_1jo5f_123",si="_optionsSection_1jo5f_157",ni="_metricButton_1jo5f_169",oi="_metricButtonActive_1jo5f_205",ai="_analyzeButton_1jo5f_219",ii="_resultsSection_1jo5f_267",ri="_resultsTitle_1jo5f_277",ci="_noResults_1jo5f_293",li="_pathCard_1jo5f_309",di="_pathCardSelected_1jo5f_333",ui="_pathCardHeader_1jo5f_343",mi="_pathCardTitle_1jo5f_361",hi="_pathBadge_1jo5f_373",pi="_badgePrimary_1jo5f_389",_i="_badgeAlternate_1jo5f_399",fi="_pathName_1jo5f_409",gi="_pathStatus_1jo5f_421",yi="_statusDot_1jo5f_435",bi="_statusActive_1jo5f_447",xi="_statusDegraded_1jo5f_453",vi="_statusInactive_1jo5f_459",ji="_statusError_1jo5f_465",wi="_pathStats_1jo5f_475",Ni="_statItem_1jo5f_489",ki="_statValue_1jo5f_497",Ii="_statLabel_1jo5f_509",Ci="_pathVisualization_1jo5f_523",Si="_pathDiagram_1jo5f_535",Li="_pathNode_1jo5f_551",Ti="_pathNodeStart_1jo5f_583",$i="_pathNodeEnd_1jo5f_585",zi="_pathLink_1jo5f_595",Mi="_pathLinkLine_1jo5f_607",Bi="_showOnMapButton_1jo5f_621",Ei="_loading_1jo5f_657",Pi="_spinner_1jo5f_671",Ai="_spin_1jo5f_671",V={panel:Ya,header:Za,title:Xa,closeButton:Ka,content:Ja,endpointSection:Qa,endpointLabel:ei,endpointSelect:ti,optionsSection:si,metricButton:ni,metricButtonActive:oi,analyzeButton:ai,resultsSection:ii,resultsTitle:ri,noResults:ci,pathCard:li,pathCardSelected:di,pathCardHeader:ui,pathCardTitle:mi,pathBadge:hi,badgePrimary:pi,badgeAlternate:_i,pathName:fi,pathStatus:gi,statusDot:yi,statusActive:bi,statusDegraded:xi,statusInactive:vi,statusError:ji,pathStats:wi,statItem:Ni,statValue:ki,statLabel:Ii,pathVisualization:Ci,pathDiagram:Si,pathNode:Li,pathNodeStart:Ti,pathNodeEnd:$i,pathLink:zi,pathLinkLine:Mi,showOnMapButton:Bi,loading:Ei,spinner:Pi,spin:Ai},Oi=()=>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"})}),Di=()=>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 Ri(t){switch(t){case"active":return"Aktywna";case"degraded":return"Degradacja";case"inactive":return"Nieaktywna";case"error":return"Error";default:return"Nieznany"}}function qi(t){return t<1?"<1ms":t<1e3?`${Math.round(t)}ms`:`${(t/1e3).toFixed(1)}s`}function Fi(t){return t>=1e3?`${(t/1e3).toFixed(1)} Gbps`:`${Math.round(t)} Mbps`}const Gi=({document:t,connections:s,onHighlightPath:n,onClose:o})=>{const{t:a}=S.useNiceTranslation(),[i,c]=u.useState(""),[r,h]=u.useState(""),[y,l]=u.useState("latency"),[x,_]=u.useState([]),[p,f]=u.useState(null),[j,m]=u.useState(!1),k=u.useMemo(()=>{const d=[];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)d.push({id:q.id,name:q.name??q.id});return d},[t]),C=u.useCallback(d=>{var v;return((v=k.find(g=>g.id===d))==null?void 0:v.name)??d},[k]),T=u.useCallback(()=>{!i||!r||i===r||(m(!0),_([]),f(null),setTimeout(()=>{const d=no(s,i,r,y),v=oo(s,i,r,5),g=[];d&&g.push(d);for(const q of v)g.some(I=>I.connectionIds.length===q.connectionIds.length&&I.connectionIds.every((B,W)=>q.connectionIds[W]===B))||g.push({...q,isPrimary:!1});_(g),g.length>0&&(f(g[0].id),n==null||n(g[0])),m(!1)},300))},[i,r,y,s,n]),b=u.useCallback(d=>{f(d.id),n==null||n(d)},[n]),L=u.useCallback(d=>{const v=[d.startDeviceId];for(const g of d.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:V.panel,children:[e.jsxs("div",{className:V.header,children:[e.jsx("h3",{className:V.title,children:a("buildings.spatial.pathAnalysis","Network path analysis")}),o&&e.jsx("button",{className:V.closeButton,onClick:o,children:e.jsx(Oi,{})})]}),e.jsxs("div",{className:V.content,children:[e.jsxs("div",{className:V.endpointSection,children:[e.jsx("label",{className:V.endpointLabel,children:a("buildings.spatial.sourceDevice","Source device")}),e.jsxs("select",{className:V.endpointSelect,value:i,onChange:d=>c(d.target.value),children:[e.jsxs("option",{value:"",children:["— ",a("buildings.spatial.selectDevice","Select a device")," —"]}),k.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:a("buildings.spatial.targetDevice","Target device")}),e.jsxs("select",{className:V.endpointSelect,value:r,onChange:d=>h(d.target.value),children:[e.jsxs("option",{value:"",children:["— ",a("buildings.spatial.selectDevice","Select a device")," —"]}),k.filter(d=>d.id!==i).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} ${y==="latency"?V.metricButtonActive:""}`,onClick:()=>l("latency"),children:"Latencja"}),e.jsx("button",{className:`${V.metricButton} ${y==="hops"?V.metricButtonActive:""}`,onClick:()=>l("hops"),children:"Hops"}),e.jsx("button",{className:`${V.metricButton} ${y==="bandwidth"?V.metricButtonActive:""}`,onClick:()=>l("bandwidth"),children:a("buildings.spatial.bandwidth","Bandwidth")})]}),e.jsx("button",{className:V.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:V.loading,children:e.jsx("div",{className:V.spinner})}):x.length>0?e.jsxs("div",{className:V.resultsSection,children:[e.jsxs("div",{className:V.resultsTitle,children:[a("buildings.spatial.pathsFound","Paths found")," (",x.length,")"]}),x.map((d,v)=>{const g=L(d),q=p===d.id;return e.jsxs("div",{className:`${V.pathCard} ${q?V.pathCardSelected:""}`,onClick:()=>b(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?"Optymalna":`Alt ${v}`}),e.jsxs("span",{className:V.pathName,children:[d.connectionIds.length," ",a("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:Ri(d.status)})]})]}),e.jsxs("div",{className:V.pathStats,children:[e.jsxs("div",{className:V.statItem,children:[e.jsx("div",{className:V.statValue,children:qi(d.totalLatency)}),e.jsx("div",{className:V.statLabel,children:"Latencja"})]}),e.jsxs("div",{className:V.statItem,children:[e.jsx("div",{className:V.statValue,children:d.connectionIds.length}),e.jsx("div",{className:V.statLabel,children:"Hops"})]}),e.jsxs("div",{className:V.statItem,children:[e.jsx("div",{className:V.statValue,children:d.bottleneckBandwidth>0?Fi(d.bottleneckBandwidth):"N/A"}),e.jsx("div",{className:V.statLabel,children:a("buildings.spatial.bandwidth","Bandwidth")})]})]}),q&&e.jsxs("div",{className:V.pathVisualization,children:[e.jsx("div",{className:V.pathDiagram,children:g.map((I,B)=>e.jsxs(u.Fragment,{children:[e.jsx("div",{className:`${V.pathNode} ${B===0?V.pathNodeStart:B===g.length-1?V.pathNodeEnd:""}`,children:C(I).substring(0,8)}),B<g.length-1&&e.jsxs("div",{className:V.pathLink,children:[e.jsx("div",{className:V.pathLinkLine}),e.jsx(Di,{})]})]},I))}),e.jsx("button",{className:V.showOnMapButton,onClick:I=>{I.stopPropagation(),n==null||n(d)},children:a("buildings.spatial.showOnMap","Show on the map")})]})]},d.id)})]}):i&&r&&i!==r?e.jsx("div",{className:V.noResults,children:a("buildings.spatial.noResultsHint","Pick two devices and run the analysis")}):e.jsx("div",{className:V.noResults,children:a("buildings.spatial.pickEndpoints","Pick a source and a target device")})]})]})},Vi="_root_6pirz_9",Wi="_header_6pirz_27",Hi="_title_6pirz_37",Ui="_search_6pirz_51",Yi="_categories_6pirz_79",Zi="_category_6pirz_91",Xi="_categoryHeader_6pirz_107",Ki="_categoryIcon_6pirz_143",Ji="_categoryLabel_6pirz_151",Qi="_categoryCount_6pirz_161",er="_expandIcon_6pirz_171",tr="_items_6pirz_181",sr="_item_6pirz_181",nr="_itemIcon_6pirz_241",or="_itemName_6pirz_249",ar="_emptyState_6pirz_269",je={root:Vi,header:Wi,title:Hi,search:Ui,categories:Yi,category:Zi,categoryHeader:Xi,categoryIcon:Ki,categoryLabel:Ji,categoryCount:Qi,expandIcon:er,items:tr,item:sr,itemIcon:nr,itemName:or,emptyState:ar},ir={"💡":"lightbulb","🔆":"lightbulb","🌈":"lightbulb","🌡️":"thermometer","❄️":"thermometer","💨":"wifi","📷":"camera","🔔":"bell","🔒":"lock","👁️":"eye","🚪":"door","🔊":"wifi","🗣️":"mic","📺":"monitor","📡":"wifi","🔌":"plug","🛡️":"lock","📶":"wifi","🖥️":"monitor","💾":"database","🗄️":"server","🔋":"zap","⚡":"zap","🧱":"square","🪟":"window","🪜":"stairs","🎯":"target","🏁":"target","📦":"box","👾":"gamepad","🛗":"elevator","🛏️":"bed","🛏":"bed","🛋️":"sofa","🛋":"sofa","🪑":"chair","🍽️":"utensils","🍽":"utensils"},rr=t=>t?ir[t]??(/^[a-z][a-z0-9-]*$/.test(t)?t:"box"):"box",cr={"floor-plan":["smart-home","building"],"network-topology":["network"],infrastructure:["infrastructure","network"],cad:["building"],interior:["furniture","smart-home"],"game-scene":["game"]},lr={"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"}},ws=({mode:t,onObjectSelect:s,customObjects:n=[],className:o})=>{const[a,i]=u.useState(""),[c,r]=u.useState(new Set(["smart-home","furniture","network"])),h=cr[t]||[],y=u.useMemo(()=>{const _={},p=qn.reduce((f,j)=>{var m;return(f[m=j.category]??(f[m]=[])).push(j),f},{});return Object.entries(p).forEach(([f,j])=>{if(!h.includes(f))return;const m=j.filter(k=>!a||k.name.toLowerCase().includes(a.toLowerCase()));m.length>0&&(_[f]=m.map(k=>({id:k.id,name:k.name,category:f,icon:k.icon})))}),n.forEach(f=>{h.includes(f.category)&&(!a||f.name.toLowerCase().includes(a.toLowerCase()))&&(_[f.category]||(_[f.category]=[]),_[f.category].push(f))}),_},[h,a,n]),l=_=>{r(p=>{const f=new Set(p);return f.has(_)?f.delete(_):f.add(_),f})},x=(_,p)=>{_.dataTransfer.setData("application/json",JSON.stringify(p)),_.dataTransfer.effectAllowed="copy"};return e.jsxs("div",{className:`${je.root} ${o??""}`,children:[e.jsxs("div",{className:je.header,children:[e.jsx("h3",{className:je.title,children:"Objects"}),e.jsx("input",{type:"text",className:je.search,placeholder:"Search...",value:a,onChange:_=>i(_.target.value)})]}),e.jsxs("div",{className:je.categories,children:[Object.entries(y).map(([_,p])=>{const f=lr[_]||{icon:"box",label:_},j=c.has(_);return e.jsxs("div",{className:je.category,children:[e.jsxs("button",{className:je.categoryHeader,onClick:()=>l(_),children:[e.jsx("span",{className:je.categoryIcon,children:e.jsx(S.NiceIcon,{name:f.icon,size:16})}),e.jsx("span",{className:je.categoryLabel,children:f.label}),e.jsxs("span",{className:je.categoryCount,children:["(",p.length,")"]}),e.jsx("span",{className:je.expandIcon,children:e.jsx(S.NiceIcon,{name:j?"chevron-down":"chevron-right",size:14})})]}),j&&e.jsx("div",{className:je.items,children:p.map(m=>e.jsxs("div",{className:je.item,draggable:!0,onDragStart:k=>x(k,m),onClick:()=>s(m),title:m.name,children:[e.jsx("span",{className:je.itemIcon,children:e.jsx(S.NiceIcon,{name:rr(m.icon),size:16})}),e.jsx("span",{className:je.itemName,children:m.name})]},m.id))})]},_)}),Object.keys(y).length===0&&e.jsx("div",{className:je.emptyState,children:a?`No objects matching "${a}"`:"No objects available for this mode"})]})]})},dr="_root_o3eqo_9",ur="_header_o3eqo_23",mr="_title_o3eqo_39",hr="_multiSelect_o3eqo_53",pr="_content_o3eqo_63",_r="_section_o3eqo_73",fr="_sectionHeader_o3eqo_89",gr="_sectionContent_o3eqo_127",yr="_fieldRow_o3eqo_135",br="_fieldLabel_o3eqo_157",xr="_textInput_o3eqo_169",vr="_numberInput_o3eqo_171",jr="_select_o3eqo_173",wr="_checkbox_o3eqo_215",Nr="_colorInput_o3eqo_227",kr="_readOnly_o3eqo_245",Ir="_emptyState_o3eqo_263",ae={root:dr,header:ur,title:mr,multiSelect:hr,content:pr,section:_r,sectionHeader:fr,sectionContent:gr,fieldRow:yr,fieldLabel:br,textInput:xr,numberInput:vr,select:jr,checkbox:wr,colorInput:Nr,readOnly:kr,emptyState:Ir},Dt=[{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"}],Cr=[{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}],Sr=[{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"}]}],Ns=({selection:t,document:s,onPropertyChange:n,className:o})=>{const[a,i]=u.useState(new Set(["general","position","appearance"])),c=t.objectIds.map(p=>{for(const f of s.floors)for(const j of f.layers){const m=j.objects.find(k=>k.id===p);if(m)return m}return null}).filter(Boolean),r=p=>{i(f=>{const j=new Set(f);return j.has(p)?j.delete(p):j.add(p),j})},h=u.useCallback((p,f)=>{const j=f.split(".");let m=p;for(const k of j)if(m&&typeof m=="object"&&k in m)m=m[k];else return;return m},[]),y=u.useCallback((p,f)=>{var m;const j=h(f,p.key);switch(p.type){case"text":return e.jsx("input",{type:"text",value:String(j??""),onChange:k=>n(f.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(f.id,p.key,parseFloat(k.target.value)),className:ae.numberInput});case"boolean":return e.jsx("input",{type:"checkbox",checked:!!j,onChange:k=>n(f.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(f.id,p.key,k.target.value),className:ae.colorInput});case"select":return e.jsx("select",{value:String(j??""),onChange:k=>n(f.id,p.key,k.target.value),className:ae.select,children:(m=p.options)==null?void 0:m.map(k=>e.jsx("option",{value:k.value,children:k.label},k.value))});default:return e.jsx("span",{children:String(j??"-")})}},[h,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 l=c[0],x=c.length>1,_=l.category==="zone"?Cr:["smart-home","network","infrastructure"].includes(l.category??"")?Sr:[];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:[Dt.slice(0,1).map(p=>e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:p.label}),y(p,l)]},p.key)),e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:"ID"}),e.jsx("span",{className:ae.readOnly,children:l.id})]}),e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:"Category"}),e.jsx("span",{className:ae.readOnly,children:l.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:Dt.slice(1,4).map(p=>e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:p.label}),y(p,l)]},p.key))})]}),_.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:_.map(p=>e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:p.label}),y(p,l)]},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:Dt.slice(4).map(p=>e.jsxs("div",{className:ae.fieldRow,children:[e.jsx("label",{className:ae.fieldLabel,children:p.label}),y(p,l)]},p.key))})]})]})]})},Lr="_panel_1qr4k_9",Tr="_header_1qr4k_33",$r="_headerTitle_1qr4k_51",zr="_title_1qr4k_65",Mr="_closeButton_1qr4k_79",Br="_summarySection_1qr4k_111",Er="_summaryStats_1qr4k_129",Pr="_statBadge_1qr4k_141",Ar="_statValue_1qr4k_155",Or="_statLabel_1qr4k_167",Dr="_visibilityControls_1qr4k_183",Rr="_visibilityLabel_1qr4k_201",qr="_visibilityButtons_1qr4k_211",Fr="_visibilityBtn_1qr4k_221",Gr="_active_1qr4k_251",Vr="_content_1qr4k_265",Wr="_emptyState_1qr4k_279",Hr="_emptyHint_1qr4k_325",Ur="_vlanList_1qr4k_337",Yr="_vlanCard_1qr4k_351",Zr="_highlighted_1qr4k_377",Xr="_hidden_1qr4k_387",Kr="_vlanHeader_1qr4k_395",Jr="_colorIndicator_1qr4k_421",Qr="_vlanInfo_1qr4k_435",ec="_vlanName_1qr4k_445",tc="_vlanId_1qr4k_459",sc="_vlanNameText_1qr4k_471",nc="_vlanSubnet_1qr4k_487",oc="_vlanStats_1qr4k_503",ac="_chipStat_1qr4k_515",ic="_vlanActions_1qr4k_545",rc="_iconBtn_1qr4k_557",cc="_inactive_1qr4k_595",lc="_expanded_1qr4k_611",dc="_vlanDetails_1qr4k_623",uc="_detailRow_1qr4k_635",mc="_detailLabel_1qr4k_657",hc="_detailValue_1qr4k_675",pc="_badge_1qr4k_687",_c="_badgeSuccess_1qr4k_701",fc="_badgeNeutral_1qr4k_711",gc="_deviceList_1qr4k_723",yc="_deviceItems_1qr4k_731",bc="_deviceItem_1qr4k_731",xc="_deviceDot_1qr4k_765",vc="_deviceMore_1qr4k_779",jc="_highlightButton_1qr4k_795",wc="_footer_1qr4k_835",Nc="_legendTitle_1qr4k_847",kc="_legend_1qr4k_847",Ic="_legendItem_1qr4k_875",Cc="_legendColor_1qr4k_887",Sc="_legendLabel_1qr4k_901",A={panel:Lr,header:Tr,headerTitle:$r,title:zr,closeButton:Mr,summarySection:Br,summaryStats:Er,statBadge:Pr,statValue:Ar,statLabel:Or,visibilityControls:Dr,visibilityLabel:Rr,visibilityButtons:qr,visibilityBtn:Fr,active:Gr,content:Vr,emptyState:Wr,emptyHint:Hr,vlanList:Ur,vlanCard:Yr,highlighted:Zr,hidden:Xr,vlanHeader:Kr,colorIndicator:Jr,vlanInfo:Qr,vlanName:ec,vlanId:tc,vlanNameText:sc,vlanSubnet:nc,vlanStats:oc,chipStat:ac,vlanActions:ic,iconBtn:rc,inactive:cc,expanded:lc,vlanDetails:dc,detailRow:uc,detailLabel:mc,detailValue:hc,badge:pc,badgeSuccess:_c,badgeNeutral:fc,deviceList:gc,deviceItems:yc,deviceItem:bc,deviceDot:xc,deviceMore:vc,highlightButton:jc,footer:wc,legendTitle:Nc,legend:kc,legendItem:Ic,legendColor:Cc,legendLabel:Sc},Lc=()=>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"})}),Tc=()=>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"})]}),$c=()=>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"})]}),as=()=>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"})]}),zc=()=>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 Mc(t){var s;return((s=t.deviceIds)==null?void 0:s.length)??0}function Bc(t,s){return s.filter(n=>n.vlanId===t.id).length}function Ec(t){return t||"—"}const Pc=({document:t,connections:s,vlans:n,visibleVlanIds:o,onVlanVisibilityChange:a,onHighlightVlan:i,onClose:c})=>{const{t:r}=S.useNiceTranslation(),[h,y]=u.useState(null),[l,x]=u.useState(null),_=u.useMemo(()=>[...n].sort((b,L)=>b.id-L.id),[n]),p=u.useMemo(()=>{const b=new Set,L=new Set;for(const d of n)for(const v of d.deviceIds??[])b.add(v);for(const d of s)d.vlanId!==void 0&&L.add(d.id);return{vlanCount:n.length,deviceCount:b.size,connectionCount:L.size}},[n,s]),f=u.useCallback(b=>{const L=o.has(b);a==null||a(b,!L)},[o,a]),j=u.useCallback(b=>{for(const L of n)a==null||a(L.id,b)},[n,a]),m=u.useCallback(b=>{y((b==null?void 0:b.id)??null),i==null||i(b)},[i]),k=u.useCallback(b=>{x(L=>L===b?null:b)},[]),C=u.useCallback(b=>{const L=[];for(const d of b.deviceIds??[])for(const v of t.floors)for(const g of v.layers){const q=g.objects.find(I=>I.id===d);q&&L.push({id:d,name:q.name??d})}return L},[t]),T=u.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:A.panel,children:[e.jsxs("div",{className:A.header,children:[e.jsxs("div",{className:A.headerTitle,children:[e.jsx(as,{}),e.jsx("h3",{className:A.title,children:r("buildings.spatial.vlan.title","VLAN overlay")})]}),c&&e.jsx("button",{className:A.closeButton,onClick:c,title:r("buildings.spatial.close","Close"),children:e.jsx(Lc,{})})]}),e.jsx("div",{className:A.summarySection,children:e.jsxs("div",{className:A.summaryStats,children:[e.jsxs("div",{className:A.statBadge,children:[e.jsx("span",{className:A.statValue,children:p.vlanCount}),e.jsx("span",{className:A.statLabel,children:"VLAN"})]}),e.jsxs("div",{className:A.statBadge,children:[e.jsx("span",{className:A.statValue,children:p.deviceCount}),e.jsx("span",{className:A.statLabel,children:r("buildings.spatial.devices","Devices")})]}),e.jsxs("div",{className:A.statBadge,children:[e.jsx("span",{className:A.statValue,children:p.connectionCount}),e.jsx("span",{className:A.statLabel,children:r("buildings.spatial.connections","Connections")})]})]})}),e.jsxs("div",{className:A.visibilityControls,children:[e.jsxs("span",{className:A.visibilityLabel,children:[r("buildings.spatial.vlan.visibility","Visibility"),": ",T.visible,"/",T.total]}),e.jsxs("div",{className:A.visibilityButtons,children:[e.jsx("button",{className:`${A.visibilityBtn} ${T.allVisible?A.active:""}`,onClick:()=>j(!0),title:r("buildings.spatial.vlan.showAll","Show all"),children:r("buildings.spatial.vlan.all","All")}),e.jsx("button",{className:`${A.visibilityBtn} ${T.noneVisible?A.active:""}`,onClick:()=>j(!1),title:r("buildings.spatial.vlan.hideAll","Hide all"),children:r("buildings.spatial.vlan.none","None")})]})]}),e.jsx("div",{className:A.content,children:_.length===0?e.jsxs("div",{className:A.emptyState,children:[e.jsx(as,{}),e.jsx("p",{children:r("buildings.spatial.vlan.empty","No VLANs defined")}),e.jsx("span",{className:A.emptyHint,children:r("buildings.spatial.vlan.emptyHint","Add a VLAN in network-topology or infrastructure mode")})]}):e.jsx("div",{className:A.vlanList,children:_.map(b=>{const L=o.has(b.id),d=h===b.id,v=l===b.id,g=Mc(b),q=Bc(b,s),I=v?C(b):[];return e.jsxs("div",{className:`${A.vlanCard} ${d?A.highlighted:""} ${L?"":A.hidden}`,onMouseEnter:()=>m(b),onMouseLeave:()=>m(null),children:[e.jsxs("div",{className:A.vlanHeader,children:[e.jsx("div",{className:A.colorIndicator,style:{backgroundColor:b.color}}),e.jsxs("div",{className:A.vlanInfo,children:[e.jsxs("div",{className:A.vlanName,children:[e.jsxs("span",{className:A.vlanId,children:["VLAN ",b.id]}),b.name&&e.jsx("span",{className:A.vlanNameText,children:b.name})]}),b.subnet&&e.jsx("div",{className:A.vlanSubnet,children:Ec(b.subnet)})]}),e.jsxs("div",{className:A.vlanStats,children:[e.jsx("span",{className:A.chipStat,title:r("buildings.spatial.devices","Devices"),children:g}),e.jsx("span",{className:A.chipStat,title:r("buildings.spatial.connections","Connections"),children:q})]}),e.jsxs("div",{className:A.vlanActions,children:[e.jsx("button",{className:`${A.iconBtn} ${L?"":A.inactive}`,onClick:B=>{B.stopPropagation(),f(b.id)},title:L?r("buildings.spatial.vlan.hide","Hide VLAN"):r("buildings.spatial.vlan.show","Show VLAN"),children:L?e.jsx(Tc,{}):e.jsx($c,{})}),e.jsx("button",{className:`${A.iconBtn} ${v?A.expanded:""}`,onClick:B=>{B.stopPropagation(),k(b.id)},title:r("buildings.spatial.details","Details"),children:e.jsx(zc,{})})]})]}),v&&e.jsxs("div",{className:A.vlanDetails,children:[b.description&&e.jsxs("div",{className:A.detailRow,children:[e.jsxs("span",{className:A.detailLabel,children:[r("buildings.spatial.vlan.description","Description"),":"]}),e.jsx("span",{className:A.detailValue,children:b.description})]}),b.subnet&&e.jsxs("div",{className:A.detailRow,children:[e.jsxs("span",{className:A.detailLabel,children:[r("buildings.spatial.vlan.subnet","Subnet"),":"]}),e.jsx("span",{className:A.detailValue,children:b.subnet})]}),b.gateway&&e.jsxs("div",{className:A.detailRow,children:[e.jsxs("span",{className:A.detailLabel,children:[r("buildings.spatial.vlan.gateway","Gateway"),":"]}),e.jsx("span",{className:A.detailValue,children:b.gateway})]}),e.jsxs("div",{className:A.detailRow,children:[e.jsx("span",{className:A.detailLabel,children:"DHCP:"}),e.jsx("span",{className:`${A.detailValue} ${A.badge} ${b.dhcpEnabled?A.badgeSuccess:A.badgeNeutral}`,children:b.dhcpEnabled?r("buildings.spatial.enabled","Enabled"):r("buildings.spatial.disabled","Disabled")})]}),I.length>0&&e.jsxs("div",{className:A.deviceList,children:[e.jsxs("span",{className:A.detailLabel,children:[r("buildings.spatial.devices","Devices")," (",I.length,"):"]}),e.jsxs("ul",{className:A.deviceItems,children:[I.slice(0,10).map(B=>e.jsxs("li",{className:A.deviceItem,children:[e.jsx("span",{className:A.deviceDot,style:{backgroundColor:b.color}}),B.name]},B.id)),I.length>10&&e.jsxs("li",{className:A.deviceMore,children:["… ",r("buildings.spatial.andMore","and")," ",I.length-10," ",r("buildings.spatial.more","more")]})]})]}),e.jsx("button",{className:A.highlightButton,onClick:()=>i==null?void 0:i(b),children:r("buildings.spatial.selectOnMap","Select on the map")})]})]},b.id)})})}),_.length>0&&e.jsxs("div",{className:A.footer,children:[e.jsx("div",{className:A.legendTitle,children:r("buildings.spatial.colourLegend","Colour legend")}),e.jsx("div",{className:A.legend,children:_.map(b=>e.jsxs("div",{className:A.legendItem,children:[e.jsx("span",{className:A.legendColor,style:{backgroundColor:b.color}}),e.jsxs("span",{className:A.legendLabel,children:[b.id,b.name?`: ${b.name}`:""]})]},b.id))})]})]})},Ac="_root_sniq9_9",Oc="_shell_sniq9_35",Dc="_dark_sniq9_43",Rc="_topBar_sniq9_67",qc="_modeSwitcher_sniq9_85",Fc="_modeBtn_sniq9_95",Gc="_modeBtnActive_sniq9_131",Vc="_modeIcon_sniq9_143",Wc="_modeLabel_sniq9_151",Hc="_floorTabs_sniq9_159",Uc="_floorTab_sniq9_159",Yc="_floorTabActive_sniq9_203",Zc="_viewportControls_sniq9_215",Xc="_active_sniq9_257",Kc="_disabled_sniq9_267",Jc="_separator_sniq9_281",Qc="_zoomLevel_sniq9_295",el="_exportDropdown_sniq9_313",tl="_exportMenu_sniq9_361",sl="_editorContainer_sniq9_435",nl="_toolbar_sniq9_453",ol="_toolGroup_sniq9_473",al="_toolBtn_sniq9_501",il="_toolBtnActive_sniq9_541",rl="_canvasWrapper_sniq9_565",cl="_canvas_sniq9_565",ll="_cursor_select_sniq9_593",dl="_cursor_multi_select_sniq9_599",ul="_cursor_pan_sniq9_605",ml="_cursor_zoom_sniq9_617",hl="_cursor_draw_wall_sniq9_623",pl="_cursor_draw_zone_sniq9_625",_l="_cursor_draw_polyline_sniq9_627",fl="_cursor_draw_rectangle_sniq9_629",gl="_cursor_draw_circle_sniq9_631",yl="_cursor_draw_arc_sniq9_633",bl="_cursor_place_device_sniq9_639",xl="_cursor_place_furniture_sniq9_641",vl="_cursor_place_network_sniq9_643",jl="_cursor_place_infra_sniq9_645",wl="_cursor_place_door_sniq9_647",Nl="_cursor_place_window_sniq9_649",kl="_cursor_place_stairs_sniq9_651",Il="_cursor_connect_sniq9_657",Cl="_cursor_route_cable_sniq9_659",Sl="_cursor_annotate_sniq9_665",Ll="_cursor_dimension_sniq9_667",Tl="_cursor_label_sniq9_669",$l="_cursor_measure_distance_sniq9_675",zl="_cursor_measure_angle_sniq9_677",Ml="_cursor_measure_area_sniq9_679",Bl="_cursor_move_sniq9_685",El="_cursor_rotate_sniq9_691",Pl="_cursor_scale_sniq9_697",Al="_cursor_erase_sniq9_703",Ol="_cursor_copy_sniq9_709",Dl="_cursor_paste_sniq9_711",Rl="_grid_sniq9_721",ql="_gridLine_sniq9_727",Fl="_zonesLayer_sniq9_739",Gl="_zone_sniq9_739",Vl="_zoneLabel_sniq9_755",Wl="_connectionsLayer_sniq9_769",Hl="_connection_sniq9_769",Ul="_connectionPreview_sniq9_785",Yl="_guides_sniq9_795",Zl="_guideLine_sniq9_801",Xl="_drawingPreview_sniq9_815",Kl="_rightSidebar_sniq9_827",Jl="_statusBar_sniq9_849",Ql="_modeIndicator_sniq9_871",ed="_toolIndicator_sniq9_873",td="_selectionInfo_sniq9_885",sd="_drawingInfo_sniq9_887",nd="_connectingInfo_sniq9_901",od="_gridInfo_sniq9_915",ad="_emptyState_sniq9_927",id="_emptyIcon_sniq9_949",rd="_primaryBtn_sniq9_979",cd="_modeActions_sniq9_1013",ld="_actionBtn_sniq9_1031",F={root:Ac,shell:Oc,dark:Dc,topBar:Rc,modeSwitcher:qc,modeBtn:Fc,modeBtnActive:Gc,modeIcon:Vc,modeLabel:Wc,floorTabs:Hc,floorTab:Uc,floorTabActive:Yc,viewportControls:Zc,active:Xc,disabled:Kc,separator:Jc,zoomLevel:Qc,exportDropdown:el,exportMenu:tl,editorContainer:sl,toolbar:nl,toolGroup:ol,toolBtn:al,toolBtnActive:il,canvasWrapper:rl,canvas:cl,cursor_select:ll,cursor_multi_select:dl,cursor_pan:ul,cursor_zoom:ml,cursor_draw_wall:hl,cursor_draw_zone:pl,cursor_draw_polyline:_l,cursor_draw_rectangle:fl,cursor_draw_circle:gl,cursor_draw_arc:yl,cursor_place_device:bl,cursor_place_furniture:xl,cursor_place_network:vl,cursor_place_infra:jl,cursor_place_door:wl,cursor_place_window:Nl,cursor_place_stairs:kl,cursor_connect:Il,cursor_route_cable:Cl,cursor_annotate:Sl,cursor_dimension:Ll,cursor_label:Tl,cursor_measure_distance:$l,cursor_measure_angle:zl,cursor_measure_area:Ml,cursor_move:Bl,cursor_rotate:El,cursor_scale:Pl,cursor_erase:Al,cursor_copy:Ol,cursor_paste:Dl,grid:Rl,gridLine:ql,zonesLayer:Fl,zone:Gl,zoneLabel:Vl,connectionsLayer:Wl,connection:Hl,connectionPreview:Ul,guides:Yl,guideLine:Zl,drawingPreview:Xl,rightSidebar:Kl,statusBar:Jl,modeIndicator:Ql,toolIndicator:ed,selectionInfo:td,drawingInfo:sd,connectingInfo:nd,gridInfo:od,emptyState:ad,emptyIcon:id,primaryBtn:rd,modeActions:cd,actionBtn:ld},Je={"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}},bt={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 dd(t){var a,i;const s=t.defaultMode??"floor-plan",n=Je[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 Ze(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 Xe(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 ft(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 gt(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 ud(t,s){var n;switch(s.type){case"SET_MODE":{const o=Je[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=gt(t.document,t.activeFloorId,o,s.object),i=Ze("create",[s.object.id],null,s.object);return{...t,document:a,...Xe(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=Ze("update",[s.objectId],o,{...o,...s.updates});return{...t,document:a,...Xe(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=ft(t.document,s.objectIds),i=Ze("delete",s.objectIds,o,null);return{...t,document:a,selection:{objectIds:[],bounds:null,locked:!1},...Xe(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 h=Fe(a,r);if(h&&"transform"in h&&h.transform&&"position"in h.transform){const y=h.transform.position;a=_t(a,r,{transform:{...h.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=Ze("move",s.objectIds,o,i);return{...t,document:a,...Xe(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=ft(a,o.objectIds);break}case"delete":{const i=o.before;for(const c of i){const r=c.layer||"devices";a=gt(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=gt(a,t.activeFloorId??a.floors[0].id,c,i);break}case"delete":{a=ft(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=ft(t.document,t.selection.objectIds),i=Ze("delete",t.selection.objectIds,o,null);return{...t,document:a,clipboard:o,selection:{objectIds:[],bounds:null,locked:!1},...Xe(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 h=`${r.id}-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,y=r.transform,l={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:h,transform:l},_=x.layer||"devices";o=gt(o,t.activeFloorId,_,x),a.push(h),i.push(x)}const c=Ze("create",a,null,i);return{...t,document:o,selection:{objectIds:a,bounds:null,locked:!1},...Xe(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 md=({mode:t,activeTool:s,onToolSelect:n,readOnly:o})=>{const i=Je[t].tools.map(r=>bt[r]).filter(Boolean),c=["select","draw","place","connect","annotate","measure","edit"];return e.jsx("div",{className:F.toolbar,children:c.map(r=>{const h=i.filter(y=>y.group===r);return h.length===0?null:e.jsx("div",{className:F.toolGroup,children:h.map(({tool:y,icon:l,label:x,shortcut:_})=>e.jsx("button",{title:`${x}${_?` (${_})`:""}`,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:l,size:16})},y))},r)})})},hd=({currentMode:t,availableModes:s,onModeChange:n})=>e.jsx("div",{className:F.modeSwitcher,children:s.map(o=>{const a=Je[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 is(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 pd(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??_d(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(h=>h.id===c.vlanId);r&&!r.deviceIds.includes(i.id)&&r.deviceIds.push(i.id)}}return s.sort((o,a)=>o.id-a.id)}function _d(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 fd=[{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"}],gd=t=>{var Wt,Ht;const{defaultMode:s="floor-plan",availableModes:n=Object.keys(Je),readOnly:o=!1,theme:a="light",locale:i="en",onDocumentChange:c,onSelectionChange:r,onModeChange:h,onExport:y,onImport:l,tutorial:x,className:_,style:p,cookies:f=!1,localStorage:j=!0,sessionStorage:m=!1,storageMode:k,storageKey:C,persistPreferences:T=!1}=t,{t:b}=S.useNiceTranslation(),L=S.useStorageAdapter(C??"nice-spatial-editor"),[d]=u.useState(()=>T?L.get("prefs")??{}:{}),[v,g]=u.useReducer(ud,t,dd),q=u.useRef(null),I=u.useRef(!1),B=u.useRef({x:0,y:0}),[W,te]=u.useState(!1),[ue,Q]=u.useState(!1),[_e,se]=u.useState(null),[ge,ze]=u.useState(null),[Re,Le]=u.useState(!1),[Be,Ee]=u.useState(!1),[M,X]=u.useState(!1),[he,Ne]=u.useState(new Set),[Oe,ve]=u.useState(null),Pe=u.useRef(null),Ce=u.useRef(null),ke=u.useRef(null),{mode:we,tool:me,document:ie,activeFloorId:qe,layers:Ie,selection:xe,viewport:ce,drawing:pe,connecting:ne,guides:Ge,ui:Ae,history:Qe}=v,Ve=Je[we],it=Qe.past.length>0,et=Qe.future.length>0;u.useEffect(()=>{var N,D,O;!T||!d||((d.zoom||d.pan)&&g({type:"SET_VIEWPORT",viewport:{zoom:d.zoom,pan:d.pan,showGrid:(N=d.gridConfig)==null?void 0:N.visible,gridSize:(D=d.gridConfig)==null?void 0:D.size,snapEnabled:(O=d.gridConfig)==null?void 0:O.snapEnabled}}),d.mode&&g({type:"SET_MODE",mode:d.mode}),d.tool&&g({type:"SET_TOOL",tool:d.tool}),d.layerVisibility&&Object.entries(d.layerVisibility).forEach(([G,K])=>{K!==void 0&&g({type:"SET_LAYER_VISIBILITY",layerType:G,visible:K})}))},[]),u.useEffect(()=>{if(!T)return;const N={zoom:ce.zoom,pan:ce.pan,gridConfig:{size:ce.gridSize,visible:ce.showGrid,snapEnabled:ce.snapEnabled},mode:we,tool:me,layerVisibility:Object.fromEntries(Ie.map(D=>[D.type,D.visible])),uiPanels:Ae};L.set("prefs",N)},[T,ce,we,me,Ie,Ae,L]);const ye=u.useMemo(()=>(ie==null?void 0:ie.floors.find(N=>N.id===qe))??(ie==null?void 0:ie.floors[0])??null,[ie,qe]),De=u.useCallback((N,D)=>{var G;const O=(G=q.current)==null?void 0:G.getBoundingClientRect();return O?{x:(N-O.left-ce.pan.x)/ce.zoom,y:(D-O.top-ce.pan.y)/ce.zoom}:{x:0,y:0}},[ce.pan,ce.zoom]),We=u.useCallback(N=>{if(!ce.snapEnabled)return N;const D={cellSize:ce.gridSize,origin:{x:0,y:0},visible:ce.showGrid};return Gt(N,D)},[ce.snapEnabled,ce.gridSize,ce.showGrid]),Nt=u.useCallback(N=>{if(me==="pan"||N.button===1){I.current=!0,B.current={x:N.clientX,y:N.clientY};return}const D=We(De(N.clientX,N.clientY));if(me==="draw-zone"||me==="draw-wall"||me==="draw-polyline")pe.active?g({type:"ADD_DRAWING_POINT",point:D}):g({type:"START_DRAWING",point:D});else if(me==="connect"){const O=ye==null?void 0:ye.layers.flatMap(G=>G.objects).find(G=>{if(!G.bounds)return!1;const K=G.bounds;return D.x>=K.x&&D.x<=K.x+K.width&&D.y>=K.y&&D.y<=K.y+K.height});if(O)if(ne.active){g({type:"FINISH_CONNECTING",targetId:O.id});const G=`conn-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,K=O.bounds?{x:O.bounds.x+O.bounds.width/2,y:O.bounds.y+O.bounds.height/2}:D,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:O.id,sourcePosition:ne.sourcePosition,targetPosition:K,medium:"ethernet-cat6",status:"active"}};g({type:"ADD_OBJECT",object:J})}else{const G=O.bounds?{x:O.bounds.x+O.bounds.width/2,y:O.bounds.y+O.bounds.height/2}:D;g({type:"START_CONNECTING",sourceId:O.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,We,De,ye]),kt=u.useCallback(N=>{if(I.current){const O=N.clientX-B.current.x,G=N.clientY-B.current.y;g({type:"PAN",delta:{x:O,y:G}}),B.current={x:N.clientX,y:N.clientY};return}const D=We(De(N.clientX,N.clientY));if(pe.active&&(g({type:"UPDATE_DRAWING_PREVIEW",point:D}),ce.snapEnabled&&ye)){const O=ye.layers.flatMap(J=>J.objects.filter(le=>le.bounds).map(le=>({id:le.id,bounds:le.bounds}))),G={x:D.x,y:D.y,width:1,height:1},K=gs(G,O,10);g({type:"SET_GUIDES",guides:K})}ne.active&&g({type:"UPDATE_CONNECTING_PREVIEW",position:D})},[pe.active,ne.active,We,De,ce.snapEnabled,ye]),It=u.useCallback(()=>{I.current=!1},[]),Ct=u.useCallback(N=>{pe.active&&pe.points.length>=2&&g({type:"FINISH_DRAWING"})},[pe.active,pe.points.length]),St=u.useCallback(N=>{N.preventDefault();const D=N.deltaY>0?-1:1;g({type:"ZOOM",delta:D,center:De(N.clientX,N.clientY)})},[De]),Lt=u.useCallback(N=>{N.key==="Escape"&&(pe.active?g({type:"CANCEL_DRAWING"}):ne.active?g({type:"CANCEL_CONNECTING"}):g({type:"CLEAR_SELECTION"})),N.key==="Delete"&&xe.objectIds.length>0&&g({type:"DELETE_OBJECTS",objectIds:xe.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,xe.objectIds]),Tt=u.useCallback(N=>{g({type:"SET_MODE",mode:N}),h==null||h(N)},[h]),$t=u.useCallback(N=>{g({type:"SET_TOOL",tool:N})},[]),He=u.useCallback(async N=>{var D;if(ie){te(!1);try{const O={includeGrid:!1,includeDimensions:!0};if(N==="nsp"){const G=Un(ie,O);ht(G),y==null||y(N,G.data)}else if(N==="svg"){const G=Zn(ie,O);ht(G),y==null||y(N,G.data)}else if(N==="dxf"){const G=Jn(ie,O);ht(G),y==null||y(N,G.data)}else if(N==="png"&&q.current){const G=await so(q.current,((D=ie.metadata)==null?void 0:D.name)||"export");ht(G),y==null||y(N,G.data)}}catch(O){console.error(`Export to ${N} failed:`,O)}}},[ie,y]),zt=u.useCallback(async N=>{var O;const D=(O=N.target.files)==null?void 0:O[0];if(D){Q(!1);try{const K=await _o(D,{convertClosedPolylinesToZones:!0,minZoneArea:1});K.success&&K.document?ze(K):se(K),ke.current&&(ke.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}})}}},[]),Mt=u.useCallback(()=>{ge!=null&&ge.success&&ge.document?Le(!0):ze(null)},[ge]),rt=u.useCallback(()=>{ze(null),Le(!1)},[]),w=u.useCallback((N,D)=>{if(!(ge!=null&&ge.document)){Le(!1);return}const O=ge.document,G={...O,floors:O.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 Te=ie==null?void 0:ie.floors.flatMap(Ue=>Ue.layers).find(Ue=>Ue.id===le);return Te?{...J,id:Te.id,name:Te.name,type:Te.type}:J})}))};g({type:"SET_DOCUMENT",document:G}),l==null||l(G),se(ge),Le(!1),ze(null)},[ge,ie,l]),$=u.useCallback(()=>{Le(!1)},[]),E=u.useCallback(N=>{if(ke.current){let D=".dxf,.svg,.geojson,.json,.ifc";N==="dxf"?D=".dxf":N==="svg"?D=".svg":N==="geojson"?D=".geojson,.json":N==="ifc"&&(D=".ifc"),ke.current.accept=D,ke.current.click()}Q(!1)},[]);u.useEffect(()=>{const N=D=>{Pe.current&&!Pe.current.contains(D.target)&&te(!1),Ce.current&&!Ce.current.contains(D.target)&&Q(!1)};return(W||ue)&&document.addEventListener("mousedown",N),()=>{document.removeEventListener("mousedown",N)}},[W,ue]);const ee=u.useCallback(()=>{var K,J;if(!ce.showGrid||!ye)return null;const N=[],{gridSize:D}=ce,O=((K=ye.bounds)==null?void 0:K.width)??1e3,G=((J=ye.bounds)==null?void 0:J.height)??800;for(let le=0;le<=O;le+=D)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+=D)N.push(e.jsx("line",{x1:0,y1:le,x2:O,y2:le,className:F.gridLine},`h${le}`));return e.jsx("g",{className:F.grid,children:N})},[ce.showGrid,ce.gridSize,ye]),H=u.useCallback(()=>{if(!ye)return null;const N=ye.layers.find(D=>D.name==="zones");return N?e.jsx("g",{className:F.zonesLayer,children:N.objects.map(D=>{const O=D;if(!O.boundary||O.boundary.length<3)return null;const G=O.boundary.map((le,Te)=>`${Te===0?"M":"L"}${le.x},${le.y}`).join(" ")+" Z",K=xe.objectIds.includes(O.id),J=O.boundary.reduce((le,Te)=>({x:le.x+Te.x/O.boundary.length,y:le.y+Te.y/O.boundary.length}),{x:0,y:0});return e.jsxs("g",{className:F.zone,onClick:le=>{le.stopPropagation(),g({type:"SET_SELECTION",selection:{objectIds:[O.id],bounds:null,locked:!1}})},children:[e.jsx("path",{d:G,fill:O.color??"var(--nice-primary-bg, #dbeafe)",fillOpacity:.5,stroke:K?"var(--nice-primary-hover, #2563eb)":"var(--nice-text-muted, #94a3b8)",strokeWidth:K?2:1}),O.name&&e.jsx("text",{x:J.x,y:J.y,textAnchor:"middle",dominantBaseline:"middle",className:F.zoneLabel,children:O.name})]},O.id)})}):null},[ye,xe.objectIds]),de=u.useCallback(()=>Ge.length===0?null:e.jsx("g",{className:F.guides,children:Ge.map((N,D)=>e.jsx("line",{x1:N.start.x,y1:N.start.y,x2:N.end.x,y2:N.end.y,className:F.guideLine},D))}),[Ge]),fe=u.useCallback(()=>{if(!pe.active||pe.points.length===0)return null;const N=[...pe.points];pe.preview&&N.push(pe.preview);const D=N.map((G,K)=>`${K===0?"M":"L"}${G.x},${G.y}`).join(" "),O=me==="draw-zone"&&N.length>2;return e.jsxs("g",{className:F.drawingPreview,children:[e.jsx("path",{d:D+(O?" Z":""),fill:O?"var(--nice-primary-tint-10, rgba(37, 99, 235, 0.1))":"none",stroke:"var(--nice-primary-hover, #2563eb)",strokeWidth:2,strokeDasharray:O?"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=u.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]),ct=u.useCallback(()=>{if(!ye)return null;const N=ye.layers.find(K=>K.type==="network");if(!N)return null;const D=N.objects.filter(K=>K.type==="connection");if(D.length===0)return null;const O={"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:D.map(K=>{const J=K.metadata;if(!(J!=null&&J.sourcePosition)||!(J!=null&&J.targetPosition))return null;const le=O[J.medium??"default"]||O.default,Te=G[J.status??"unknown"]||G.unknown,Ue=xe.objectIds.includes(K.id);let Bt=`M${J.sourcePosition.x},${J.sourcePosition.y}`;if(J.waypoints&&J.waypoints.length>0)for(const lt of J.waypoints)Bt+=` L${lt.x},${lt.y}`;return Bt+=` L${J.targetPosition.x},${J.targetPosition.y}`,e.jsxs("g",{className:F.connection,onClick:lt=>{lt.stopPropagation(),g({type:"SET_SELECTION",selection:{objectIds:[K.id],bounds:null,locked:!1}})},children:[e.jsx("path",{d:Bt,fill:"none",stroke:Ue?"var(--nice-primary-hover, #2563eb)":le.color,strokeWidth:Ue?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:Te}),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,xe.objectIds]);if(!ie&&!ye)return e.jsx("div",{className:`${F.root} ${F[a]} ${_??""}`,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=Vt("New Project","floor-plan");g({type:"SET_DOCUMENT",document:N})},children:"Create New Document"})]})});const Ls=e.jsxs("div",{className:F.topBar,children:[e.jsx(hd,{currentMode:we,availableModes:n,onModeChange:Tt}),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:!it,className:it?"":F.disabled,children:e.jsx(S.NiceIcon,{name:"reply",size:16})}),e.jsx("button",{title:"Redo (Ctrl+Y)",onClick:()=>g({type:"REDO"}),disabled:!et,className:et?"":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:Ce,children:[e.jsx("input",{type:"file",ref:ke,onChange:zt,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(!W),className:W?F.active:"",children:[e.jsx(S.NiceIcon,{name:"upload",size:14})," Export"]}),W&&e.jsxs("div",{className:F.exportMenu,children:[e.jsxs("button",{onClick:()=>He("nsp"),children:[e.jsx(S.NiceIcon,{name:"file",size:14})," NiceToDev Spatial Plan (.nsp.json)"]}),e.jsxs("button",{onClick:()=>He("svg"),children:[e.jsx(S.NiceIcon,{name:"image",size:14})," SVG Vector Graphics (.svg)"]}),e.jsxs("button",{onClick:()=>He("dxf"),children:[e.jsx(S.NiceIcon,{name:"ruler",size:14})," AutoCAD DXF (.dxf)"]}),e.jsxs("button",{onClick:()=>He("png"),children:[e.jsx(S.NiceIcon,{name:"image",size:14})," PNG Image (.png)"]})]})]})]})]}),Ts=Ae.showObjectLibrary&&!o?e.jsx(ws,{mode:we,onObjectSelect:N=>{g({type:"SET_TOOL",tool:`place-${N.category}`}),g({type:"START_DRAG",objectType:N.category,objectData:N})}}):void 0,$s=e.jsxs("div",{className:F.editorContainer,children:[!o&&e.jsx(md,{mode:we,activeTool:me,onToolSelect:$t,readOnly:o}),(we==="network-topology"||we==="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:Nt,onMouseMove:kt,onMouseUp:It,onDoubleClick:Ct,onWheel:St,children:e.jsxs("g",{transform:`translate(${ce.pan.x}, ${ce.pan.y}) scale(${ce.zoom})`,children:[ee(),H(),ct(),de(),fe(),Me()]})}),Ae.showMinimap&&e.jsx(js,{document:ie,activeFloorId:qe,viewport:ce,onViewportChange:N=>g({type:"SET_VIEWPORT",viewport:N})})]})]}),zs=e.jsxs("div",{className:F.rightSidebar,children:[Ae.showLayerPanel&&e.jsx(vs,{layers:Ie.filter(N=>Ve.layerTypes.includes(N.type)),onVisibilityToggle:N=>{var D;return g({type:"SET_LAYER_VISIBILITY",layerType:N,visible:!((D=Ie.find(O=>O.type===N))!=null&&D.visible)})},onLockToggle:N=>{var D;return g({type:"SET_LAYER_LOCKED",layerType:N,locked:!((D=Ie.find(O=>O.type===N))!=null&&D.locked)})},onOpacityChange:(N,D)=>g({type:"SET_LAYER_OPACITY",layerType:N,opacity:D})}),Ae.showPropertiesPanel&&xe.objectIds.length>0&&e.jsx(Ns,{selection:xe,document:ie,onPropertyChange:(N,D,O)=>{g({type:"UPDATE_OBJECT",objectId:N,updates:{[D]:O}})}})]}),Ms=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:[((Wt=bt[me])==null?void 0:Wt.icon)&&e.jsx(S.NiceIcon,{name:bt[me].icon,size:14})," ",(Ht=bt[me])==null?void 0:Ht.label]}),xe.objectIds.length>0&&e.jsxs("span",{className:F.selectionInfo,children:[xe.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]} ${_??""}`,style:{position:"relative",...p},tabIndex:0,onKeyDown:Lt,children:[e.jsx("span",{style:{position:"absolute",top:6,right:6,zIndex:30},children:e.jsx(S.NiceTutorialButton,{steps:S.resolveTutorial(x,fd)})}),e.jsx(S.NiceAppShell,{flush:!0,className:F.shell,menubar:Ls,sidebar:Ts,rightSidebar:zs,statusBar:Ms,children:$s}),ge&&!Re&&e.jsx(ta,{result:ge,onConfirm:Mt,onCancel:rt}),ge&&Re&&e.jsx(Ta,{importResult:ge,existingDocument:ie??void 0,onConfirm:w,onCancel:$}),Be&&ie&&e.jsx(Gi,{document:ie,connections:is(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(Pc,{document:ie,connections:is(ie),vlans:pd(ie),visibleVlanIds:he,onVlanVisibilityChange:(N,D)=>{Ne(O=>{const G=new Set(O);return D?G.add(N):G.delete(N),G})},onHighlightVlan:N=>{ve((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)})]})},yd="_viewer_nyfnl_13",bd="_theme_light_nyfnl_37",xd="_theme_dark_nyfnl_59",vd="_debugOverlay_nyfnl_85",jd="_topBar_nyfnl_137",wd="_searchContainer_nyfnl_159",Nd="_searchInput_nyfnl_171",kd="_clearBtn_nyfnl_227",Id="_searchResults_nyfnl_261",Cd="_searchResultItem_nyfnl_291",Sd="_searchResultInfo_nyfnl_335",Ld="_searchResultName_nyfnl_347",Td="_searchResultDesc_nyfnl_357",$d="_floorSelector_nyfnl_371",zd="_navBtn_nyfnl_421",Md="_active_nyfnl_459",Bd="_layersBtn_nyfnl_475",Ed="_legendBtn_nyfnl_529",Pd="_content_nyfnl_583",Ad="_navPanel_nyfnl_599",Od="_navPanelHeader_nyfnl_617",Dd="_routeInputs_nyfnl_671",Rd="_routeInput_nyfnl_671",qd="_routeMarker_nyfnl_705",Fd="_routeHint_nyfnl_745",Gd="_routeInfo_nyfnl_761",Vd="_routeStat_nyfnl_779",Wd="_routeStatLabel_nyfnl_791",Hd="_routeStatValue_nyfnl_805",Ud="_clearRouteBtn_nyfnl_817",Yd="_refPointsList_nyfnl_851",Zd="_refPointItem_nyfnl_879",Xd="_refPointIcon_nyfnl_917",Kd="_layersPanel_nyfnl_929",Jd="_layersPanelHeader_nyfnl_947",Qd="_layersList_nyfnl_1001",eu="_layerItem_nyfnl_1015",tu="_layerToggle_nyfnl_1039",su="_layerName_nyfnl_1075",nu="_layerType_nyfnl_1087",ou="_canvasWrapper_nyfnl_1101",au="_canvas_nyfnl_1101",iu="_grid_nyfnl_1137",ru="_gridLine_nyfnl_1145",cu="_zonesLayer_nyfnl_1161",lu="_zone_nyfnl_1161",du="_zoneSelected_nyfnl_1187",uu="_zoneLabel_nyfnl_1197",mu="_objectsLayer_nyfnl_1213",hu="_object_nyfnl_1213",pu="_objectSelected_nyfnl_1237",_u="_objectLabel_nyfnl_1245",fu="_referencePoints_nyfnl_1261",gu="_referencePoint_nyfnl_1261",yu="_refLabel_nyfnl_1283",bu="_routeLayer_nyfnl_1299",xu="_routePath_nyfnl_1305",vu="_routeDash_nyfnl_1",ju="_routeMarkers_nyfnl_1331",wu="_currentLocation_nyfnl_1341",Nu="_locationPulse_nyfnl_1347",ku="_pulse_nyfnl_1",Iu="_zoomControls_nyfnl_1383",Cu="_minimap_nyfnl_1459",Su="_minimapContent_nyfnl_1485",Lu="_minimapViewport_nyfnl_1499",Tu="_legendPanel_nyfnl_1519",$u="_legendPanelHeader_nyfnl_1551",zu="_legendList_nyfnl_1607",Mu="_legendItem_nyfnl_1623",Bu="_legendColor_nyfnl_1647",Eu="_legendIcon_nyfnl_1663",Pu="_legendLabel_nyfnl_1677",Au="_legendType_nyfnl_1689",Ou="_objectInfo_nyfnl_1707",Du="_objectInfoHeader_nyfnl_1735",Ru="_navigateBtn_nyfnl_1805",z={viewer:yd,theme_light:bd,theme_dark:xd,debugOverlay:vd,topBar:jd,searchContainer:wd,searchInput:Nd,clearBtn:kd,searchResults:Id,searchResultItem:Cd,searchResultInfo:Sd,searchResultName:Ld,searchResultDesc:Td,floorSelector:$d,navBtn:zd,active:Md,layersBtn:Bd,legendBtn:Ed,content:Pd,navPanel:Ad,navPanelHeader:Od,routeInputs:Dd,routeInput:Rd,routeMarker:qd,routeHint:Fd,routeInfo:Gd,routeStat:Vd,routeStatLabel:Wd,routeStatValue:Hd,clearRouteBtn:Ud,refPointsList:Yd,refPointItem:Zd,refPointIcon:Xd,layersPanel:Kd,layersPanelHeader:Jd,layersList:Qd,layerItem:eu,layerToggle:tu,layerName:su,layerType:nu,canvasWrapper:ou,canvas:au,grid:iu,gridLine:ru,zonesLayer:cu,zone:lu,zoneSelected:du,zoneLabel:uu,objectsLayer:mu,object:hu,objectSelected:pu,objectLabel:_u,referencePoints:fu,referencePoint:gu,refLabel:yu,routeLayer:bu,routePath:xu,routeDash:vu,routeMarkers:ju,currentLocation:wu,locationPulse:Nu,pulse:ku,zoomControls:Iu,minimap:Cu,minimapContent:Su,minimapViewport:Lu,legendPanel:Tu,legendPanelHeader:$u,legendList:zu,legendItem:Mu,legendColor:Bu,legendIcon:Eu,legendLabel:Pu,legendType:Au,objectInfo:Ou,objectInfoHeader:Du,navigateBtn:Ru},qu=()=>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"})]}),rs=()=>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"})}),Fu=()=>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"})]}),Gu=()=>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"})]}),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:"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"})]}),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 3M7 5v4M5 7h4",strokeLinecap:"round"})]}),Hu=()=>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"})]}),st=()=>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"})}),cs=()=>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"})]}),ls=()=>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"})]}),Uu=()=>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"})]}),Yu=()=>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"})]}),Zu={entrance:"door",elevator:"elevator",stairs:"stairs",exit:"bell",poi:"map-pin",parking:"map-pin"};function Rt(t){return t.icon??Zu[t.type]??"map-pin"}function Xu(t,s){return Math.sqrt((s.x-t.x)**2+(s.y-t.y)**2)}function Ku(t){return t<1?"<1m":t<1e3?`${Math.round(t)}m`:`${(t/1e3).toFixed(1)}km`}function Ju(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 Qu=Vt(""),em=({document:t=Qu,initialFloorId:s,showNavigation:n=!0,showMinimap:o=!0,showFloorSelector:a=!0,showSearch:i=!0,showLayersPanel:c=!0,showLegend:r=!0,enableRoutePlanning:h=!0,referencePoints:y=[],onObjectClick:l,onRouteCalculated:x,currentLocation:_,theme:p="light",className:f,virtualRendering:j,virtualRenderingThreshold:m=200,debugVirtualRendering:k=!1})=>{var rt;const{t:C}=S.useNiceTranslation(),[T,b]=u.useState(s??((rt=t.floors[0])==null?void 0:rt.id)??""),[L,d]=u.useState({zoom:1,pan:{x:0,y:0}}),[v,g]=u.useState(""),[q,I]=u.useState([]),[B,W]=u.useState(null),[te,ue]=u.useState(null),[Q,_e]=u.useState(null),[se,ge]=u.useState(null),[ze,Re]=u.useState(!1),[Le,Be]=u.useState(!1),[Ee,M]=u.useState(!1),[X,he]=u.useState(new Map),[Ne,Oe]=u.useState({width:1e3,height:600}),ve=u.useRef(null),Pe=u.useRef(null),Ce=u.useRef(!1),ke=u.useRef({x:0,y:0}),we=u.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??vo(we,m),ie=u.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 bo($)},[t.floors,T,me]),qe=u.useMemo(()=>xo(L,Ne,100),[L,Ne]),Ie=u.useMemo(()=>!me||!ie?null:ie.query(qe),[me,ie,qe]),xe=u.useMemo(()=>!k||!me?null:jo(we,(Ie==null?void 0:Ie.length)??we,L),[k,me,we,Ie,L]);u.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()},[]),u.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=u.useCallback(w=>{he($=>{const E=new Map($);return E.set(w,!$.get(w)),E})},[]),pe=u.useCallback(w=>X.get(w)!==!1,[X]),ne=u.useMemo(()=>t.floors.find(w=>w.id===T)??t.floors[0],[t.floors,T]),Ge=u.useMemo(()=>{if(!ne)return[];const w=[],$=ne.layers.find(H=>H.type==="zones");if($){const H=new Map;for(const de of $.objects){const fe=de.metadata,Me=(fe==null?void 0:fe.zoneType)??de.type??"zone";H.has(Me)||H.set(Me,(fe==null?void 0:fe.fill)??"var(--nice-primary, #3b82f6)")}for(const[de,fe]of H)w.push({id:`zone-${de}`,label:de.charAt(0).toUpperCase()+de.slice(1).replace(/-/g," "),color:fe,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 fe=de.type??"object",Me=E.get(fe);Me?Me.count++:E.set(fe,{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,Rt(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=u.useCallback((w,$)=>{var ee;const E=(ee=ve.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]);u.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(),fe=(H.description??"").toLowerCase();(de.includes(w)||fe.includes(w))&&$.push(H)}I($.slice(0,10))},[v,t.floors]);const Qe=u.useCallback((w,$)=>{const E=Xu(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"}]}},[]);u.useEffect(()=>{if(te&&Q){const w=Qe(te,Q);ge(w),x==null||x(w)}else ge(null),x==null||x(null)},[te,Q,Qe,x]);const Ve=u.useCallback(w=>{(w.button===1||w.button===0&&w.altKey)&&(Ce.current=!0,ke.current={x:w.clientX,y:w.clientY},w.preventDefault())},[]),it=u.useCallback(w=>{if(Ce.current){const $=w.clientX-ke.current.x,E=w.clientY-ke.current.y;ke.current={x:w.clientX,y:w.clientY},d(ee=>({...ee,pan:{x:ee.pan.x+$,y:ee.pan.y+E}}))}},[]),et=u.useCallback(()=>{Ce.current=!1},[]),ye=u.useCallback(w=>{var de;w.preventDefault();const $=w.deltaY>0?.9:1.1,E=(de=ve.current)==null?void 0:de.getBoundingClientRect();if(!E)return;const ee=w.clientX-E.left,H=w.clientY-E.top;d(fe=>{const Me=Math.min(Math.max(fe.zoom*$,.1),10),ct=Me/fe.zoom;return{zoom:Me,pan:{x:ee-(ee-fe.pan.x)*ct,y:H-(H-fe.pan.y)*ct}}})},[]),De=u.useCallback(w=>{if(h&&w.ctrlKey){const $=Ae(w.clientX,w.clientY);te?Q?(ue($),_e(null)):_e($):ue($)}},[h,te,Q,Ae]),We=u.useCallback(()=>{d(w=>({...w,zoom:Math.min(w.zoom*1.25,10)}))},[]),Nt=u.useCallback(()=>{d(w=>({...w,zoom:Math.max(w.zoom/1.25,.1)}))},[]),kt=u.useCallback(()=>{d({zoom:1,pan:{x:0,y:0}})},[]),It=u.useCallback(w=>{W(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};d(E=>({...E,pan:{x:-($.x*E.zoom)+400,y:-($.y*E.zoom)+300}})),g(""),I([]),l==null||l(w)},[t.floors,l]),Ct=u.useCallback(()=>{ue(null),_e(null),ge(null)},[]),St=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:$})},[]),Lt=u.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:()=>{W($),l==null||l($)},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,l,pe]),Tt=u.useCallback(()=>ne?me&&Ie?e.jsx("g",{className:z.objectsLayer,children:Ie.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:fe=>{fe.stopPropagation(),W($),l==null||l($)},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(),W($),l==null||l($)},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,l,pe,me,Ie]),$t=u.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:()=>{h&&(te?_e($.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:Rt($),size:16})}),e.jsx("text",{y:30,textAnchor:"middle",className:z.refLabel,children:$.name})]},$.id))})},[y,T,h,te]),He=u.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]),zt=u.useCallback(()=>_?e.jsxs("g",{className:z.currentLocation,children:[e.jsx("circle",{cx:_.x,cy:_.y,r:12,fill:"var(--nice-primary, #3b82f6)",fillOpacity:.3,className:z.locationPulse}),e.jsx("circle",{cx:_.x,cy:_.y,r:6,fill:"var(--nice-primary, #3b82f6)",stroke:"white",strokeWidth:2})]}):null,[_]),Mt=u.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}`]} ${f??""}`,children:[k&&xe&&e.jsxs("div",{className:z.debugOverlay,children:[e.jsx("div",{children:"Virtual: ON"}),e.jsxs("div",{children:["Total: ",xe.total]}),e.jsxs("div",{children:["Visible: ",xe.visible]}),e.jsxs("div",{children:["Culled: ",xe.culled," (",xe.cullPercentage,"%)"]}),e.jsxs("div",{children:["Zoom: ",xe.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(qu,{}),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(st,{})})]}),q.length>0&&e.jsx("div",{className:z.searchResults,children:q.map(w=>e.jsxs("button",{className:z.searchResultItem,onClick:()=>It(w),children:[e.jsx(Fu,{}),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(Gu,{}),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(rs,{}),e.jsx("span",{children:"Nawigacja"})]}),c&&e.jsxs("button",{className:`${z.layersBtn} ${Le?z.active:""}`,onClick:()=>Be(!Le),children:[e.jsx(cs,{}),e.jsx("span",{children:"Warstwy"})]}),r&&e.jsxs("button",{className:`${z.legendBtn} ${Ee?z.active:""}`,onClick:()=>M(!Ee),children:[e.jsx(ls,{}),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(Vu,{}),e.jsx("span",{children:"Planowanie trasy"}),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:"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:Ku(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:Ju(se.estimatedTime)})]})]}),(te||Q)&&e.jsx("button",{className:z.clearRouteBtn,onClick:Ct,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?_e(w.position):ue(w.position)},children:[e.jsx("span",{className:z.refPointIcon,children:e.jsx(S.NiceIcon,{name:Rt(w),size:16})}),e.jsx("span",{children:w.name})]},w.id))]})]}),Le&&ne&&e.jsxs("div",{className:z.layersPanel,children:[e.jsxs("div",{className:z.layersPanelHeader,children:[e.jsx(cs,{}),e.jsx("span",{children:"Warstwy"}),e.jsx("button",{onClick:()=>Be(!1),children:e.jsx(st,{})})]}),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(Uu,{}):e.jsx(Yu,{})}),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:ve,className:z.canvas,onMouseDown:Ve,onMouseMove:it,onMouseUp:et,onMouseLeave:et,onWheel:ye,onClick:De,children:e.jsxs("g",{transform:`translate(${L.pan.x}, ${L.pan.y}) scale(${L.zoom})`,children:[St(),Lt(),Tt(),$t(),Mt(),He(),zt()]})}),e.jsxs("div",{className:z.zoomControls,children:[e.jsx("button",{onClick:We,title:C("buildings.spatial.zoomIn","Zoom in"),children:e.jsx(Wu,{})}),e.jsx("button",{onClick:Nt,title:C("buildings.spatial.zoomOut","Zoom out"),children:e.jsx(Hu,{})}),e.jsx("button",{onClick:kt,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&&Ge.length>0&&e.jsxs("div",{className:z.legendPanel,children:[e.jsxs("div",{className:z.legendPanelHeader,children:[e.jsx(ls,{}),e.jsx("span",{children:"Legenda"}),e.jsx("button",{onClick:()=>M(!1),children:e.jsx(st,{})})]}),e.jsx("div",{className:z.legendList,children:Ge.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:()=>W(null),children:e.jsx(st,{})})]}),B.description&&e.jsx("p",{children:B.description}),h&&e.jsxs("button",{className:z.navigateBtn,onClick:()=>{const w=B.position??{x:0,y:0};te?_e(w):ue(w)},children:[e.jsx(rs,{}),te?"Ustaw jako cel":"Ustaw jako start"]})]})]})};function tm(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,h]=u.useReducer((Q,_e)=>({...Q,..._e}),c),y=u.useCallback(Q=>{h({mode:Q})},[]),l=u.useCallback(Q=>{h({tool:Q})},[]),x=u.useCallback((Q="Untitled")=>{var se;const _e=Vt(Q,"floor-plan");h({document:_e,activeFloorId:((se=_e.floors[0])==null?void 0:se.id)??null}),i==null||i(_e)},[i]),_=u.useCallback(Q=>{var _e;h({document:Q,activeFloorId:((_e=Q.floors[0])==null?void 0:_e.id)??null}),i==null||i(Q)},[i]),p=u.useCallback(Q=>{h({viewport:{...r.viewport,zoom:Math.max(.1,Math.min(10,r.viewport.zoom*(1+Q*.1)))}})},[r.viewport]),f=u.useCallback(Q=>{h({viewport:{...r.viewport,pan:{x:r.viewport.pan.x+Q.x,y:r.viewport.pan.y+Q.y}}})},[r.viewport]),j=u.useCallback(()=>{h({viewport:{...r.viewport,zoom:1,pan:{x:0,y:0}}})},[r.viewport]),m=u.useCallback(()=>{h({viewport:{...r.viewport,showGrid:!r.viewport.showGrid}})},[r.viewport]),k=u.useCallback(()=>{h({viewport:{...r.viewport,snapEnabled:!r.viewport.snapEnabled}})},[r.viewport]),C=u.useCallback(Q=>{h({viewport:{...r.viewport,gridSize:Q}})},[r.viewport]),T=u.useCallback((Q,_e)=>{h({layers:r.layers.map(se=>se.type===Q?{...se,visible:_e}:se)})},[r.layers]),b=u.useCallback((Q,_e)=>{h({layers:r.layers.map(se=>se.type===Q?{...se,locked:_e}:se)})},[r.layers]),L=u.useCallback(Q=>{h({selection:{objectIds:Q,bounds:null,locked:!1}})},[]),d=u.useCallback(()=>{h({selection:{objectIds:[],bounds:null,locked:!1}})},[]),v=u.useCallback(()=>{},[]),g=u.useCallback(()=>{},[]),q=r.history.past.length>0,I=r.history.future.length>0,B=u.useCallback(()=>{},[]),W=u.useCallback(Q=>{},[]),te=u.useCallback(()=>{},[]);return{state:r,setMode:y,setTool:l,newDocument:x,loadDocument:_,zoom:p,pan:f,resetView:j,toggleGrid:m,toggleSnap:k,setGridSize:C,setLayerVisible:T,setLayerLocked:b,select:L,clearSelection:d,undo:v,redo:g,canUndo:q,canRedo:I,copy:B,paste:W,cut:te}}function sm(t={}){const{gridSize:s=20,enabled:n=!0,snapModes:o=["grid","endpoint","midpoint"],objects:a=[],threshold:i=10}=t,c=u.useMemo(()=>({...En,cellSize:s,snapModes:o,snapThreshold:i}),[s,o,i]),r=u.useMemo(()=>a.map((p,f)=>({id:`obj-${f}`,bounds:p})),[a]),h=u.useCallback(p=>n?Gt(p,c):p,[n,c]),y=u.useCallback(p=>n?Pn(p,s):p,[n,s]),l=u.useCallback(p=>{if(!n||r.length===0)return[];const f={x:p.x,y:p.y,width:0,height:0};return gs(f,r,i)},[n,r,i]),x=u.useCallback(p=>{if(!n)return{point:p,snapped:!1,guides:[]};const f=Rn(p,r,c);return{point:f.position,snapped:f.snapped,guides:f.guides??[]}},[n,c,r]),_=u.useCallback((p,f)=>{const j=[];for(let m=0;m<=p;m+=s)j.push({x1:m,y1:0,x2:m,y2:f});for(let m=0;m<=f;m+=s)j.push({x1:0,y1:m,x2:p,y2:m});return j},[s]);return{snap:h,snap3D:y,getGuides:l,performAdvancedSnap:x,generateGridLines:_}}function nm(t={}){const{unitSystem:s="metric",lengthUnit:n="m",areaUnit:o="m2",angleUnit:a="deg",scale:i=100}=t,[c,r]=u.useState(null),[h,y]=u.useState([]),l=u.useCallback(d=>d/i,[i]),x=u.useCallback(d=>{r(d),y([])},[]),_=u.useCallback((d,v=!1)=>{y(g=>[...g,{position:d,snapped:v}])},[]),p=u.useCallback(()=>{r(null),y([])},[]),f=u.useCallback(()=>{if(!c||h.length<2)return null;const d=h.map(v=>v.position);if(c==="distance"&&h.length===2){const v=ot(d[0],d[1]),g=l(v);return{type:"distance",value:g,formatted:mt(g,s).formatted,points:d}}if(c==="angle"&&h.length===3){const v=Et(d[0],d[1],d[2]);return{type:"angle",value:v,formatted:At(v,a).formatted,points:d}}if(c==="area"&&h.length>=3){const g=Pt(d)/(i*i);return{type:"area",value:g,formatted:Ot(g,s).formatted,points:d}}return null},[c,h,i,s,a,l]),j=h.length>=2&&c==="distance"?mt(l(ot(h[0].position,h[h.length-1].position)),s).formatted:null,m=h.length>=3&&c==="angle"?At(Et(h[0].position,h[1].position,h[2].position),a).formatted:null,k=h.length>=3&&c==="area"?Ot(Pt(h.map(d=>d.position))/(i*i),s).formatted:null,C=u.useCallback((d,v)=>{const g=ot(d,v),q=l(g);return{value:q,formatted:mt(q,s).formatted}},[l,s]),T=u.useCallback((d,v,g)=>{const q=Et(d,v,g);return{value:q,formatted:At(q,a).formatted}},[a]),b=u.useCallback(d=>{const g=Pt(d)/(i*i);return{value:g,formatted:Ot(g,s).formatted}},[i,s]),L=u.useCallback(d=>{const v=Wn(d),g=l(v);return{value:g,formatted:mt(g,s).formatted}},[l,s]);return{startMeasurement:x,addPoint:_,clearMeasurement:p,finishMeasurement:f,measurementType:c,points:h,liveDistance:j,liveAngle:m,liveArea:k,getDistance:C,getAngle:T,getArea:b,getLength:L}}const om="_root_15owo_3",am="_dark_15owo_25",im="_header_15owo_37",rm="_buildingInfo_15owo_51",cm="_buildingName_15owo_59",lm="_buildingAddress_15owo_81",dm="_modeSelector_15owo_95",um="_modeBtn_15owo_107",mm="_modeBtnActive_15owo_145",hm="_weather_15owo_159",pm="_weatherTemp_15owo_173",_m="_weatherDesc_15owo_193",fm="_statsRow_15owo_205",gm="_statsCard_15owo_217",ym="_statsHeader_15owo_247",bm="_statsIcon_15owo_261",xm="_statsLabel_15owo_269",vm="_statsValue_15owo_283",jm="_statsSub_15owo_305",wm="_zoneGrid_15owo_319",Nm="_zoneCard_15owo_333",km="_zoneOccupied_15owo_381",Im="_zoneCardHeader_15owo_389",Cm="_zoneCardIcon_15owo_403",Sm="_zoneCardTitles_15owo_411",Lm="_zoneCardName_15owo_421",Tm="_zoneCardArea_15owo_449",$m="_occupancyBadge_15owo_459",zm="_occupancyBadgeOn_15owo_477",Mm="_sensorRow_15owo_489",Bm="_sensorChip_15owo_503",Em="_sensorWarn_15owo_521",Pm="_deviceList_15owo_535",Am="_deviceChip_15owo_547",Om="_deviceChipOn_15owo_585",Dm="_deviceChipName_15owo_597",Rm="_deviceChipVal_15owo_611",qm="_moreBtn_15owo_621",Fm="_scenesBar_15owo_651",Gm="_sceneBarLabel_15owo_681",Vm="_sceneList_15owo_699",Wm="_sceneBtn_15owo_711",Hm="_sceneBtnActive_15owo_741",Z={root:om,dark:am,header:im,buildingInfo:rm,buildingName:cm,buildingAddress:lm,modeSelector:dm,modeBtn:um,modeBtnActive:mm,weather:hm,weatherTemp:pm,weatherDesc:_m,statsRow:fm,statsCard:gm,statsHeader:ym,statsIcon:bm,statsLabel:xm,statsValue:vm,statsSub:jm,zoneGrid:wm,zoneCard:Nm,zoneOccupied:km,zoneCardHeader:Im,zoneCardIcon:Cm,zoneCardTitles:Sm,zoneCardName:Lm,zoneCardArea:Tm,occupancyBadge:$m,occupancyBadgeOn:zm,sensorRow:Mm,sensorChip:Bm,sensorWarn:Em,deviceList:Pm,deviceChip:Am,deviceChipOn:Om,deviceChipName:Dm,deviceChipVal:Rm,moreBtn:qm,scenesBar:Fm,sceneBarLabel:Gm,sceneList:Vm,sceneBtn:Wm,sceneBtnActive:Hm},Um={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 Ym(t){return Um[t]??"home"}const Zm={light:"lightbulb",dimmer:"lightbulb",rgb_light:"lightbulb",led_strip:"lightbulb",thermostat:"thermometer",heater:"thermometer",air_conditioner:"thermometer",heat_pump:"thermometer",temperature_sensor:"thermometer",lock:"lock",door:"door",door_sensor:"door",window:"window",window_sensor:"window",blind:"window",shutter:"window",camera:"camera",doorbell:"camera",switch:"plug",outlet:"plug",smart_plug:"plug",power_strip:"plug",energy_meter:"zap",solar_panel:"zap",battery:"zap",ev_charger:"zap",speaker:"volume",media_player:"volume",tv:"monitor",alarm:"bell",siren:"bell",smoke_detector:"bell",co_detector:"bell",gas_detector:"bell",motion_sensor:"eye",presence_sensor:"eye",water_leak:"droplet",humidity_sensor:"droplet",irrigation:"droplet",hub:"wifi",router:"wifi"};function Xm(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 ks=({zone:t,devices:s=[],expanded:n=!1,onExpand:o,onDeviceControl:a,onClick:i,theme:c="light",className:r,style:h})=>{const{t:y}=S.useNiceTranslation(),l=t.occupancy!=null&&t.occupancy>0,x=n?s:s.slice(0,4);return e.jsxs("div",{className:`${Z.zoneCard} ${c==="dark"?Z.dark:""} ${l?Z.zoneOccupied:""} ${r??""}`,style:h,onClick:i,children:[e.jsxs("div",{className:Z.zoneCardHeader,children:[e.jsx("span",{className:Z.zoneCardIcon,children:e.jsx(S.NiceIcon,{name:Ym(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} ${l?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(_=>{const p=_.state,f=(p==null?void 0:p.on)===!0||(p==null?void 0:p.locked)===!1;return e.jsxs("button",{className:`${Z.deviceChip} ${f?Z.deviceChipOn:""}`,onClick:j=>{j.stopPropagation(),a==null||a(_.id,{on:!f})},title:_.name,children:[e.jsx("span",{children:e.jsx(S.NiceIcon,{name:Zm[_.type]??"monitor",size:14})}),e.jsx("span",{className:Z.deviceChipName,children:_.name}),e.jsx("span",{className:Z.deviceChipVal,children:Xm(y,_)})]},_.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:_=>{_.stopPropagation(),o==null||o()},children:n?e.jsx(S.NiceIcon,{name:"minus",size:12}):`+${s.length-4}`})]})]})},qt={home:"Home",away:"Away",night:"Night",vacation:"Vacation",guest:"Guest",party:"Party",occupied:"Occupied",closed:"Closed",weekend:"Weekend",event:"Event",emergency:"Emergency",maintenance:"Maintenance"},ds={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"},Km=({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,yt=({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})]}),Jm=({building:t,state:s,onModeChange:n,onDeviceControl:o,onSceneActivate:a,onZoneClick:i,className:c,style:r,theme:h="light",weather:y})=>{var b,L,d;const{t:l}=S.useNiceTranslation(),[x,_]=u.useState(null);t.floors[0];const p=t.floors.flatMap(v=>v.zones??[]).filter(v=>v.type!=="hallway"&&v.type!=="corridor"),f=((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,m=(d=s==null?void 0:s.energy)==null?void 0:d.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} ${h==="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:qt[v],className:`${Z.modeBtn} ${T===v?Z.modeBtnActive:""}`,onClick:()=>n==null?void 0:n(v),children:[e.jsx(S.NiceIcon,{name:ds[v],size:16}),e.jsx("span",{children:qt[v]})]},v))}),e.jsx(Km,{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(yt,{icon:"zap",label:l("buildings.power","Power"),value:j>=1e3?`${(j/1e3).toFixed(2)} kW`:`${j} W`,sub:m!=null?`${l("buildings.today","Today")}: ${m.toFixed(2)} kWh`:void 0,accent:"var(--nice-warning, #f59e0b)"}),k!=null&&e.jsx(yt,{icon:"users",label:l("buildings.occupancy","Occupancy"),value:`${k}`,sub:`${p.length} ${l("buildings.zones","zones")}`,accent:"var(--nice-success, #22c55e)"}),f>0&&e.jsx(yt,{icon:"bell",label:l("buildings.alerts","Alerts"),value:e.jsx("span",{style:{color:"var(--nice-danger, #ef4444)"},children:f}),sub:l("buildings.active","active"),accent:"var(--nice-danger, #ef4444)"}),e.jsx(yt,{icon:ds[T],label:l("buildings.mode","Mode"),value:l(`buildings.mode.${T}`,qt[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(ks,{zone:v,devices:g,expanded:x===v.id,onExpand:()=>_(x===v.id?null:v.id),onDeviceControl:o,onClick:()=>i==null?void 0:i(v.id),theme:h},v.id)})}),t.scenes&&t.scenes.length>0&&e.jsxs("div",{className:Z.scenesBar,children:[e.jsx("span",{className:Z.sceneBarLabel,children:l("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)})})]})]})},Qm="_deviceControl_1leqb_3",eh="_dark_1leqb_23",th="_compact_1leqb_35",sh="_offline_1leqb_43",nh="_offlineBanner_1leqb_51",oh="_toggleControl_1leqb_75",ah="_toggleLabel_1leqb_89",ih="_toggleBtn_1leqb_109",rh="_toggleOn_1leqb_135",ch="_blindControl_1leqb_149",lh="_blindLabel_1leqb_159",dh="_blindActions_1leqb_173",uh="_blindBtn_1leqb_181",mh="_blindSlider_1leqb_205",hh="_blindPct_1leqb_213",ph="_lockControl_1leqb_227",_h="_lockLabel_1leqb_239",fh="_lockBtn_1leqb_253",gh="_lockLocked_1leqb_273",yh="_lockUnlocked_1leqb_281",bh="_cameraControl_1leqb_295",xh="_cameraLabel_1leqb_305",vh="_cameraSnapshot_1leqb_319",jh="_cameraPlaceholder_1leqb_331",wh="_cameraStatus_1leqb_355",Nh="_cameraDot_1leqb_369",kh="_cameraOnline_1leqb_379",Ih="_cameraOffline_1leqb_385",Ch="_sensorControl_1leqb_395",Sh="_sensorLabel_1leqb_405",Lh="_sensorValues_1leqb_419",Th="_sensorRow_1leqb_429",$h="_sensorKey_1leqb_443",zh="_sensorVal_1leqb_419",Mh="_thermostat_1leqb_467",Bh="_thermostatTitle_1leqb_481",Eh="_thermostatDial_1leqb_503",Ph="_dialTempCurrent_1leqb_513",Ah="_dialTempLabel_1leqb_535",Oh="_dialTempTarget_1leqb_545",Dh="_dialHumidity_1leqb_565",Rh="_thermostatAdjust_1leqb_575",qh="_adjustBtn_1leqb_587",Fh="_adjustTemp_1leqb_633",Gh="_hvacModes_1leqb_657",Vh="_hvacModeBtn_1leqb_671",Wh="_hvacModeBtnActive_1leqb_699",Hh="_hvacAction_1leqb_711",Uh="_hvacActionDot_1leqb_727",Yh="_lightControl_1leqb_741",Zh="_lightHeader_1leqb_753",Xh="_lightIcon_1leqb_765",Kh="_lightName_1leqb_773",Jh="_lightToggle_1leqb_801",Qh="_lightToggleOn_1leqb_829",ep="_sliderRow_1leqb_841",tp="_sliderIcon_1leqb_855",sp="_slider_1leqb_841",np="_sliderVal_1leqb_879",op="_colorRow_1leqb_891",ap="_colorSwatch_1leqb_905",ip="_colorPicker_1leqb_921",rp="_colorPresets_1leqb_937",cp="_colorPreset_1leqb_937",lp="_lightOff_1leqb_963",P={deviceControl:Qm,dark:eh,compact:th,offline:sh,offlineBanner:nh,toggleControl:oh,toggleLabel:ah,toggleBtn:ih,toggleOn:rh,blindControl:ch,blindLabel:lh,blindActions:dh,blindBtn:uh,blindSlider:mh,blindPct:hh,lockControl:ph,lockLabel:_h,lockBtn:fh,lockLocked:gh,lockUnlocked:yh,cameraControl:bh,cameraLabel:xh,cameraSnapshot:vh,cameraPlaceholder:jh,cameraStatus:wh,cameraDot:Nh,cameraOnline:kh,cameraOffline:Ih,sensorControl:Ch,sensorLabel:Sh,sensorValues:Lh,sensorRow:Th,sensorKey:$h,sensorVal:zh,thermostat:Mh,thermostatTitle:Bh,thermostatDial:Eh,dialTempCurrent:Ph,dialTempLabel:Ah,dialTempTarget:Oh,dialHumidity:Dh,thermostatAdjust:Rh,adjustBtn:qh,adjustTemp:Fh,hvacModes:Gh,hvacModeBtn:Vh,hvacModeBtnActive:Wh,hvacAction:Hh,hvacActionDot:Uh,lightControl:Yh,lightHeader:Zh,lightIcon:Xh,lightName:Kh,lightToggle:Jh,lightToggleOn:Qh,sliderRow:ep,sliderIcon:tp,slider:sp,sliderVal:np,colorRow:op,colorSwatch:ap,colorPicker:ip,colorPresets:rp,colorPreset:cp,lightOff:lp};function us(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 dp(t,s,n){return"#"+[t,s,n].map(o=>o.toString(16).padStart(2,"0")).join("")}const up=["#ffffff","#fde68a","#fca5a5","#93c5fd","#86efac","#c4b5fd"];function ms(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 Is=({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,h=(r==null?void 0:r.on)??!1,y=(r==null?void 0:r.brightness)??100,l=(r==null?void 0:r.colorTemperature)??4e3,x=r==null?void 0:r.rgbColor,[_,p]=u.useState(!1),f=u.useCallback(d=>{s==null||s(t.id,d)},[t.id,s]),j=x?dp(x[0],x[1],x[2]):"#ffffff",m=((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:`${P.lightControl} ${n?P.compact:""} ${o==="dark"?P.dark:""} ${a??""}`,style:i,children:[e.jsxs("div",{className:P.lightHeader,children:[e.jsx("span",{className:P.lightIcon,style:{opacity:h?1:.4},children:e.jsx(S.NiceIcon,{name:"lightbulb",size:16})}),e.jsx("span",{className:P.lightName,children:t.name}),e.jsx("button",{className:`${P.lightToggle} ${h?P.lightToggleOn:""}`,"aria-label":h?c("buildings.switchedOn","On"):c("buildings.switchedOff","Off"),onClick:()=>f({on:!h}),children:e.jsx(S.NiceIcon,{name:h?"check":"close",size:14})})]}),h&&e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:P.sliderRow,children:[e.jsx("span",{className:P.sliderIcon,children:e.jsx(S.NiceIcon,{name:"lightbulb",size:16})}),e.jsx("input",{type:"range",min:1,max:100,value:y,className:P.slider,style:{"--pct":`${y}%`},onChange:d=>f({brightness:+d.target.value})}),e.jsxs("span",{className:P.sliderVal,children:[y,"%"]})]}),k&&e.jsxs("div",{className:P.sliderRow,children:[e.jsx("span",{className:P.sliderIcon,children:e.jsx(S.NiceIcon,{name:"thermometer",size:16})}),e.jsx("input",{type:"range",min:2700,max:6500,step:100,value:l,className:P.slider,style:{background:`linear-gradient(to right, ${us(2700)}, ${us(6500)})`},onChange:d=>f({colorTemperature:+d.target.value})}),e.jsxs("span",{className:P.sliderVal,children:[Math.round(l/100)*100,"K"]})]}),C&&e.jsxs("div",{className:P.colorRow,children:[e.jsx("span",{className:P.sliderIcon,children:e.jsx(S.NiceIcon,{name:"palette",size:16})}),e.jsx("button",{className:P.colorSwatch,"aria-label":c("buildings.pickColor","Pick a color"),"aria-expanded":_,style:{background:j},onClick:()=>p(d=>!d)}),_&&e.jsx("input",{type:"color",value:j,className:P.colorPicker,onChange:d=>{const[v,g,q]=ms(d.target.value);f({rgbColor:[v,g,q]})}}),e.jsx("div",{className:P.colorPresets,children:up.map(d=>e.jsx("button",{className:P.colorPreset,"aria-label":d,style:{background:d},onClick:()=>{const[v,g,q]=ms(d);f({rgbColor:[v,g,q]})}},d))})]})]}),!h&&!n&&e.jsx("div",{className:P.lightOff,children:c("buildings.switchedOff","Off")})]})},hs={heat:"Heating",cool:"Cooling",auto:"Auto",off:"Off",fan_only:"Fan",dry:"Dry"},mp={heat:"zap",cool:"thermometer",auto:"refresh",off:"stop",fan_only:"wifi",dry:"droplet"},hp={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 ps(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)),h=t+n*Math.cos(i(a)),y=s+n*Math.sin(i(a)),l=a-o>180?1:0;return`M${c.toFixed(2)},${r.toFixed(2)} A${n},${n} 0 ${l},1 ${h.toFixed(2)},${y.toFixed(2)}`}const at=5,xt=35,vt=-140,Cs=140;function _s(t){return vt+(t-at)/(xt-at)*(Cs-vt)}const Ss=({device:t,onControl:s,compact:n=!1,theme:o="light",className:a,style:i})=>{const{t:c}=S.useNiceTranslation(),r=t.state,h=(r==null?void 0:r.temperature)??20,y=(r==null?void 0:r.targetTemperature)??21,l=r==null?void 0:r.humidity,x=(r==null?void 0:r.mode)??"auto",_=(r==null?void 0:r.hvacAction)??"idle",p=80,f=80,j=60,m=ps(p,f,j,vt,Cs),k=_s(Math.min(Math.max(h,at),xt)),C=_s(Math.min(Math.max(y,at),xt)),T=ps(p,f,j,vt,Math.min(k,C)),b=hp[_]??"var(--nice-text-muted, #94a3b8)",L=u.useCallback(v=>{const g=Math.round((y+v)*2)/2;g>=at&&g<=xt&&(s==null||s(t.id,{targetTemperature:g}))},[y,t.id,s]),d=u.useCallback(v=>{s==null||s(t.id,{mode:v})},[t.id,s]);return e.jsxs("div",{className:`${P.thermostat} ${n?P.compact:""} ${o==="dark"?P.dark:""} ${a??""}`,style:i,children:[e.jsx("div",{className:P.thermostatTitle,children:t.name}),e.jsxs("svg",{width:160,height:160,className:P.thermostatDial,children:[e.jsx("path",{d:m,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:f+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:f-6,textAnchor:"middle",className:P.dialTempCurrent,children:[h.toFixed(1),"°"]}),e.jsx("text",{x:p,y:f+14,textAnchor:"middle",className:P.dialTempLabel,children:c("buildings.currentTemp","now")}),e.jsxs("text",{x:p,y:f+32,textAnchor:"middle",className:P.dialTempTarget,children:[y.toFixed(1),"°"]}),l!=null&&e.jsxs("text",{x:p,y:f+48,textAnchor:"middle",className:P.dialHumidity,children:[l,"%"]})]}),e.jsxs("div",{className:P.thermostatAdjust,children:[e.jsx("button",{className:P.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:P.adjustTemp,children:[y.toFixed(1)," °C"]}),e.jsx("button",{className:P.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:P.hvacModes,children:["heat","cool","auto","fan_only","off"].map(v=>e.jsx("button",{title:hs[v],"aria-label":hs[v],className:`${P.hvacModeBtn} ${x===v?P.hvacModeBtnActive:""}`,onClick:()=>d(v),children:e.jsx(S.NiceIcon,{name:mp[v],size:16})},v))}),e.jsxs("div",{className:P.hvacAction,style:{color:b},children:[e.jsx("span",{className:P.hvacActionDot,style:{background:b}}),_]})]})},pp=({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:P.toggleControl,children:[e.jsx("span",{className:P.toggleLabel,children:t.name}),e.jsx("button",{className:`${P.toggleBtn} ${a?P.toggleOn:""}`,onClick:()=>s==null?void 0:s(t.id,{on:!a}),children:a?n("buildings.on","ON"):n("buildings.off","OFF")})]})},_p=({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:P.blindControl,children:[e.jsx("span",{className:P.blindLabel,children:t.name}),e.jsxs("div",{className:P.blindActions,children:[e.jsx("button",{className:P.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:P.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:P.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:P.blindSlider,onChange:i=>s==null?void 0:s(t.id,{position:+i.target.value})}),e.jsxs("span",{className:P.blindPct,children:[a,"%"]})]})},fp=({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:P.lockControl,children:[e.jsx("span",{className:P.lockLabel,children:t.name}),e.jsxs("button",{className:`${P.lockBtn} ${a?P.lockLocked:P.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")]})]})},gp=({device:t})=>{const{t:s}=S.useNiceTranslation(),n=t.state;return e.jsxs("div",{className:P.cameraControl,children:[e.jsx("span",{className:P.cameraLabel,children:t.name}),n!=null&&n.snapshotUrl?e.jsx("img",{src:n.snapshotUrl,alt:"snapshot",className:P.cameraSnapshot}):e.jsxs("div",{className:P.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:P.cameraStatus,children:[e.jsx("span",{className:`${P.cameraDot} ${t.status==="online"?P.cameraOnline:P.cameraOffline}`}),t.status]})]})},yp=({device:t})=>{const s=t.state;return e.jsxs("div",{className:P.sensorControl,children:[e.jsx("span",{className:P.sensorLabel,children:t.name}),e.jsx("div",{className:P.sensorValues,children:Object.entries(s??{}).map(([n,o])=>o!=null&&e.jsxs("div",{className:P.sensorRow,children:[e.jsx("span",{className:P.sensorKey,children:n}),e.jsx("span",{className:P.sensorVal,children:String(o)})]},n))})]})},bp=({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(Is,{device:t,onControl:s,compact:n,theme:i}):["thermostat","air_conditioner","heat_pump","floor_heating"].includes(c)?e.jsx(Ss,{device:t,onControl:s,compact:n,theme:i}):["blind","shutter","curtain","awning","garage_door"].includes(c)?e.jsx(_p,{device:t,onControl:s}):["lock","door"].includes(c)?e.jsx(fp,{device:t,onControl:s}):["camera","doorbell"].includes(c)?e.jsx(gp,{device:t}):c.endsWith("_sensor")||["motion_sensor","smoke_detector","water_leak_sensor","alarm"].includes(c)?e.jsx(yp,{device:t}):e.jsx(pp,{device:t,onControl:s});return e.jsxs("div",{className:`${P.deviceControl} ${i==="dark"?P.dark:""} ${n?P.compact:""} ${t.status==="offline"?P.offline:""} ${o??""}`,style:a,children:[r,t.status==="offline"&&e.jsx("div",{className:P.offlineBanner,children:"Offline"})]})},xp="_root_ft98s_3",vp="_shell_ft98s_29",jp="_dark_ft98s_37",wp="_listPanel_ft98s_51",Np="_listHeader_ft98s_79",kp="_listTitle_ft98s_103",Ip="_addBtn_ft98s_121",Cp="_list_ft98s_51",Sp="_listItem_ft98s_159",Lp="_listItemActive_ft98s_199",Tp="_listItemName_ft98s_213",$p="_listItemMeta_ft98s_241",zp="_enableToggle_ft98s_255",Mp="_enableOn_ft98s_273",Bp="_detailPanel_ft98s_283",Ep="_detailHeader_ft98s_295",Pp="_nameInput_ft98s_309",Ap="_deleteBtn_ft98s_343",Op="_section_ft98s_373",Dp="_rules_ft98s_383",Rp="_sectionHeader_ft98s_397",qp="_sectionTitle_ft98s_411",Fp="_sectionAddBtn_ft98s_427",Gp="_ruleBlock_ft98s_457",Vp="_ruleBlockHeader_ft98s_483",Wp="_typeSelect_ft98s_497",Hp="_removeBtn_ft98s_529",Up="_ruleFields_ft98s_567",Yp="_input_ft98s_603",Zp="_textarea_ft98s_635",Xp="_dayPicker_ft98s_671",Kp="_dayBtn_ft98s_683",Jp="_dayBtnActive_ft98s_703",Qp="_noSelection_ft98s_717",e_="_emptyHint_ft98s_719",R={root:xp,shell:vp,dark:jp,listPanel:wp,listHeader:Np,listTitle:kp,addBtn:Ip,list:Cp,listItem:Sp,listItemActive:Lp,listItemName:Tp,listItemMeta:$p,enableToggle:zp,enableOn:Mp,detailPanel:Bp,detailHeader:Ep,nameInput:Pp,deleteBtn:Ap,section:Op,rules:Dp,sectionHeader:Rp,sectionTitle:qp,sectionAddBtn:Fp,ruleBlock:Gp,ruleBlockHeader:Vp,typeSelect:Wp,removeBtn:Hp,ruleFields:Up,input:Yp,textarea:Zp,dayPicker:Xp,dayBtn:Kp,dayBtnActive:Jp,noSelection:Qp,emptyHint:e_},t_=[{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"}],$e=(t,s,n="")=>{const o=t[s];return typeof o=="string"?o:n},Ft=(t,s,n=0)=>{const o=t[s];return typeof o=="number"?o:n},jt=["mon","tue","wed","thu","fri","sat","sun"],s_=t=>{const s=t.days;return Array.isArray(s)?s.map(n=>typeof n=="number"?jt[n]:String(n)):[...jt.slice(0,5)]},n_=(t,s)=>{const n=t[s];return n&&typeof n=="object"?n:{}},o_=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))))},a_=({trigger:t,devices:s,onChange:n,onRemove:o})=>{const{t:a,lang:i}=S.useNiceTranslation(),c=r=>n({...t,...r});return e.jsxs("div",{className:R.ruleBlock,children:[e.jsxs("div",{className:R.ruleBlockHeader,children:[e.jsxs("select",{className:R.typeSelect,value:t.type,onChange:r=>n({type:r.target.value}),children:[e.jsx("option",{value:"time",children:a("buildings.trigger.time","Time")}),e.jsx("option",{value:"sunrise",children:a("buildings.trigger.sunrise","Sunrise")}),e.jsx("option",{value:"sunset",children:a("buildings.trigger.sunset","Sunset")}),e.jsx("option",{value:"device_state",children:a("buildings.trigger.deviceState","Device state")}),e.jsx("option",{value:"sensor_threshold",children:a("buildings.trigger.sensorThreshold","Sensor threshold")}),e.jsx("option",{value:"occupancy",children:a("buildings.occupancy","Occupancy")}),e.jsx("option",{value:"webhook",children:"Webhook"}),e.jsx("option",{value:"calendar",children:a("buildings.trigger.calendar","Calendar")})]}),e.jsx("button",{className:R.removeBtn,onClick:o,title:a("buildings.remove","Remove"),"aria-label":a("buildings.remove","Remove"),children:e.jsx(S.NiceIcon,{name:"close",size:14})})]}),t.type==="time"&&e.jsxs("div",{className:R.ruleFields,children:[e.jsxs("label",{children:[a("buildings.field.hour","Hour"),e.jsx("input",{type:"time",className:R.input,value:$e(t,"time","08:00"),onChange:r=>c({time:r.target.value})})]}),e.jsxs("label",{children:[a("buildings.field.days","Days"),e.jsx("div",{className:R.dayPicker,children:o_(i).map((r,h)=>{const y=s_(t),l=jt[h],x=y.includes(l);return e.jsx("button",{type:"button","aria-pressed":x,className:`${R.dayBtn} ${x?R.dayBtnActive:""}`,onClick:()=>c({days:x?y.filter(_=>_!==l):jt.filter(_=>_===l||y.includes(_))}),children:r},l)})})]})]}),(t.type==="sunrise"||t.type==="sunset")&&e.jsx("div",{className:R.ruleFields,children:e.jsxs("label",{children:[a("buildings.field.offsetMinutes","Offset (minutes)"),e.jsx("input",{type:"number",className:R.input,min:-120,max:120,step:5,value:Ft(t,"offsetMinutes",0),onChange:r=>c({offsetMinutes:+r.target.value})})]})}),(t.type==="device_state"||t.type==="sensor_threshold")&&e.jsxs("div",{className:R.ruleFields,children:[e.jsxs("label",{children:[a("buildings.device","Device"),e.jsxs("select",{className:R.input,value:$e(t,"deviceId",""),onChange:r=>c({deviceId: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==="sensor_threshold"&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{children:[a("buildings.field.attribute","Attribute"),e.jsx("input",{className:R.input,value:$e(t,"attribute",""),onChange:r=>c({attribute:r.target.value})})]}),e.jsxs("label",{children:[a("buildings.field.operator","Operator"),e.jsxs("select",{className:R.input,value:$e(t,"operator","above"),onChange:r=>c({operator:r.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"),e.jsx("input",{type:"number",className:R.input,value:Ft(t,"threshold",0),onChange:r=>c({threshold:+r.target.value})})]})]})]}),t.type==="webhook"&&e.jsx("div",{className:R.ruleFields,children:e.jsxs("label",{children:["Endpoint ID",e.jsx("input",{className:R.input,value:$e(t,"webhookId",""),onChange:r=>c({webhookId:r.target.value})})]})})]})},i_=({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:R.ruleBlock,children:[e.jsxs("div",{className:R.ruleBlockHeader,children:[e.jsxs("select",{className:R.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:R.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:R.ruleFields,children:[e.jsxs("label",{children:[i("buildings.device","Device"),e.jsxs("select",{className:R.input,value:$e(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:R.textarea,rows:3,value:JSON.stringify(n_(t,"state"),null,2),onChange:r=>{try{c({state:JSON.parse(r.target.value)})}catch{}}})]})]}),t.type==="scene_activate"&&e.jsx("div",{className:R.ruleFields,children:e.jsxs("label",{children:[i("buildings.scene","Scene"),e.jsxs("select",{className:R.input,value:$e(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:R.ruleFields,children:[e.jsxs("label",{children:[i("buildings.field.channel","Channel"),e.jsxs("select",{className:R.input,value:$e(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:R.input,value:$e(t,"message",""),onChange:r=>c({message:r.target.value})})]})]}),t.type==="delay"&&e.jsx("div",{className:R.ruleFields,children:e.jsxs("label",{children:[i("buildings.field.delaySeconds","Delay (seconds)"),e.jsx("input",{type:"number",className:R.input,min:1,value:Ft(t,"delaySeconds",60),onChange:r=>c({delaySeconds:+r.target.value})})]})}),t.type==="http_request"&&e.jsxs("div",{className:R.ruleFields,children:[e.jsxs("label",{children:["URL",e.jsx("input",{className:R.input,value:$e(t,"url",""),onChange:r=>c({url:r.target.value})})]}),e.jsxs("label",{children:[i("buildings.field.method","Method"),e.jsxs("select",{className:R.input,value:$e(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"})]})]})]})]})},r_=({automations:t,defaultAutomations:s,devices:n=[],scenes:o=[],onAutomationsChange:a,onDelete:i,onToggle:c,readOnly:r=!1,className:h,style:y,theme:l="light",tutorial:x})=>{var q;const{t:_}=S.useNiceTranslation(),[p,f]=S.useControllableState({value:t,defaultValue:s,fallbackValue:[],onChange:a,componentName:"NiceAutomationEditor"}),[j,m]=u.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=u.useCallback(I=>{C&&f(p.map(B=>B.id===C.id?{...B,...I}:B))},[C,p,f]),b=u.useCallback(()=>{const I={id:`auto-${Date.now()}`,name:"New automation",enabled:!0,triggers:[],conditions:[],actions:[]};f([...p,I]),m(I.id)},[p,f]),L=u.useCallback(I=>{var B;f(p.filter(W=>W.id!==I)),k===I&&m(((B=p.find(W=>W.id!==I))==null?void 0:B.id)??null),i==null||i(I)},[p,k,f,i]),d=u.useCallback((I,B)=>{f(p.map(W=>W.id===I?{...W,enabled:B}:W)),c==null||c(I,B)},[p,f,c]),v=e.jsxs("div",{className:R.listPanel,children:[e.jsxs("div",{className:R.listHeader,children:[e.jsx("span",{className:R.listTitle,children:_("buildings.automations","Automations")}),!r&&e.jsxs("button",{className:R.addBtn,onClick:b,children:[e.jsx(S.NiceIcon,{name:"plus",size:12})," ",_("buildings.add","Add")]})]}),e.jsxs("div",{className:R.list,children:[p.map(I=>e.jsxs("div",{className:`${R.listItem} ${k===I.id?R.listItemActive:""}`,onClick:()=>m(I.id),children:[e.jsx("div",{className:R.listItemName,children:I.name}),e.jsxs("div",{className:R.listItemMeta,children:[I.triggers.length," ",_("buildings.triggersShort","triggers")," ·"," ",I.actions.length," ",_("buildings.actionsShort","actions")]}),e.jsx("button",{className:`${R.enableToggle} ${I.enabled?R.enableOn:""}`,disabled:r,onClick:B=>{B.stopPropagation(),d(I.id,!I.enabled)},title:I.enabled?_("buildings.disable","Disable"):_("buildings.enable","Enable"),"aria-label":I.enabled?_("buildings.disable","Disable"):_("buildings.enable","Enable"),children:e.jsx(S.NiceIcon,{name:I.enabled?"check":"close",size:14})})]},I.id)),p.length===0&&e.jsx("div",{className:R.emptyHint,children:_("buildings.noAutomations","No automations")})]})]}),g=e.jsx("div",{className:R.detailPanel,children:C?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:R.detailHeader,children:[e.jsx("input",{className:R.nameInput,value:C.name,onChange:I=>T({name:I.target.value}),readOnly:r}),!r&&e.jsx("button",{className:R.deleteBtn,onClick:()=>L(C.id),children:_("buildings.remove","Remove")})]}),e.jsxs("fieldset",{className:R.rules,disabled:r,children:[e.jsxs("section",{className:R.section,children:[e.jsxs("div",{className:R.sectionHeader,children:[e.jsx("span",{className:R.sectionTitle,children:_("buildings.triggers","Triggers")}),!r&&e.jsxs("button",{className:R.sectionAddBtn,onClick:()=>T({triggers:[...C.triggers,{type:"time"}]}),children:[e.jsx(S.NiceIcon,{name:"plus",size:12})," ",_("buildings.add","Add")]})]}),C.triggers.map((I,B)=>e.jsx(a_,{trigger:I,devices:n,onChange:W=>T({triggers:C.triggers.map((te,ue)=>ue===B?W:te)}),onRemove:()=>T({triggers:C.triggers.filter((W,te)=>te!==B)})},B)),C.triggers.length===0&&e.jsx("div",{className:R.emptyHint,children:_("buildings.noTriggers","No triggers")})]}),e.jsxs("section",{className:R.section,children:[e.jsxs("div",{className:R.sectionHeader,children:[e.jsx("span",{className:R.sectionTitle,children:_("buildings.actions","Actions")}),!r&&e.jsxs("button",{className:R.sectionAddBtn,onClick:()=>T({actions:[...C.actions,{type:"device_control"}]}),children:[e.jsx(S.NiceIcon,{name:"plus",size:12})," ",_("buildings.add","Add")]})]}),C.actions.map((I,B)=>e.jsx(i_,{action:I,devices:n,scenes:o,onChange:W=>T({actions:C.actions.map((te,ue)=>ue===B?W:te)}),onRemove:()=>T({actions:C.actions.filter((W,te)=>te!==B)})},B)),C.actions.length===0&&e.jsx("div",{className:R.emptyHint,children:_("buildings.noActions","No actions")})]})]})]}):e.jsx("div",{className:R.noSelection,children:_("buildings.noAutomationSelected","Select an automation or add a new one")})});return e.jsxs("div",{className:`nice-building-automation-editor ${R.root} ${l==="dark"?R.dark:""} ${h??""}`,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,t_)})}),e.jsx(S.NiceAppShell,{flush:!0,className:R.shell,sidebar:v,children:g})]})},c_="_root_2mz7s_3",l_="_shell_2mz7s_29",d_="_dark_2mz7s_37",u_="_gridPanel_2mz7s_51",m_="_gridHeader_2mz7s_79",h_="_gridTitle_2mz7s_103",p_="_addBtn_2mz7s_119",__="_sceneGrid_2mz7s_147",f_="_sceneCard_2mz7s_165",g_="_sceneCardActive_2mz7s_193",y_="_sceneCardSelected_2mz7s_199",b_="_sceneCardIcon_2mz7s_207",x_="_sceneCardName_2mz7s_217",v_="_sceneCardDevices_2mz7s_235",j_="_activeBadge_2mz7s_253",w_="_activateBtn_2mz7s_263",N_="_emptyGrid_2mz7s_307",k_="_detailPanel_2mz7s_325",I_="_metaRow_2mz7s_343",C_="_iconPicker_2mz7s_355",S_="_currentIcon_2mz7s_363",L_="_iconGrid_2mz7s_381",T_="_iconOpt_2mz7s_397",$_="_iconOptActive_2mz7s_423",z_="_metaFields_2mz7s_433",M_="_nameInput_2mz7s_447",B_="_descInput_2mz7s_481",E_="_colorPicker_2mz7s_517",P_="_colorOpt_2mz7s_527",A_="_colorOptActive_2mz7s_543",O_="_targetsSection_2mz7s_553",D_="_targetsSectionHeader_2mz7s_575",R_="_addTargetBtn_2mz7s_597",q_="_targetRow_2mz7s_625",F_="_targetSelect_2mz7s_655",G_="_targetState_2mz7s_687",V_="_targetField_2mz7s_701",W_="_tempInput_2mz7s_727",H_="_removeTargetBtn_2mz7s_745",U_="_noTargets_2mz7s_785",Y_="_detailActions_2mz7s_805",Z_="_activateFullBtn_2mz7s_819",X_="_deleteBtn_2mz7s_851",Y={root:c_,shell:l_,dark:d_,gridPanel:u_,gridHeader:m_,gridTitle:h_,addBtn:p_,sceneGrid:__,sceneCard:f_,sceneCardActive:g_,sceneCardSelected:y_,sceneCardIcon:b_,sceneCardName:x_,sceneCardDevices:v_,activeBadge:j_,activateBtn:w_,emptyGrid:N_,detailPanel:k_,metaRow:I_,iconPicker:C_,currentIcon:S_,iconGrid:L_,iconOpt:T_,iconOptActive:$_,metaFields:z_,nameInput:M_,descInput:B_,colorPicker:E_,colorOpt:P_,colorOptActive:A_,targetsSection:O_,targetsSectionHeader:D_,addTargetBtn:R_,targetRow:q_,targetSelect:F_,targetState:G_,targetField:V_,tempInput:W_,removeTargetBtn:H_,noTargets:U_,detailActions:Y_,activateFullBtn:Z_,deleteBtn:X_},K_=[{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"}],Ke=t=>t&&typeof t=="object"?t:{},J_=(t,s,n=!1)=>{const o=Ke(t)[s];return typeof o=="boolean"?o:n},nt=(t,s,n=0)=>{const o=Ke(t)[s];return typeof o=="number"?o:n},Q_=["video","eye-off","lightbulb","gamepad","briefcase","utensils","music","droplet","rocket","home","thermometer","lock","star","gift","heart","settings"],ef=["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"],tf=({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:J_(t.state,"on",!1),onChange:c=>n({...t,state:{...Ke(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:nt(t.state,"brightness",100),onChange:c=>n({...t,state:{...Ke(t.state),brightness:+c.target.value}})}),e.jsxs("span",{children:[nt(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:nt(t.state,"position",100),onChange:c=>n({...t,state:{...Ke(t.state),position:+c.target.value}})}),e.jsxs("span",{children:[nt(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:nt(t.state,"targetTemperature",20),onChange:c=>n({...t,state:{...Ke(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})})]})},sf=({scenes:t,defaultScenes:s,devices:n=[],activeSceneIds:o=[],onScenesChange:a,onActivate:i,onDelete:c,readOnly:r=!1,className:h,style:y,theme:l="light",tutorial:x})=>{var q;const{t:_}=S.useNiceTranslation(),[p,f]=S.useControllableState({value:t,defaultValue:s,fallbackValue:[],onChange:a,componentName:"NiceSceneEditor"}),[j,m]=u.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=u.useCallback(I=>{C&&f(p.map(B=>B.id===C.id?{...B,...I}:B))},[C,p,f]),b=u.useCallback(()=>{const I={id:`scene-${Date.now()}`,name:"New scene",deviceTargets:[],icon:"video",color:"var(--nice-primary-bg, #e0f2fe)"};f([...p,I]),m(I.id)},[p,f]),L=u.useCallback(I=>{var B;f(p.filter(W=>W.id!==I)),k===I&&m(((B=p.find(W=>W.id!==I))==null?void 0:B.id)??null),c==null||c(I)},[p,k,f,c]),d=()=>{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:_("buildings.scenes","Scenes")}),!r&&e.jsxs("button",{className:Y.addBtn,onClick:b,children:[e.jsx(S.NiceIcon,{name:"plus",size:12})," ",_("buildings.new","New")]})]}),e.jsxs("div",{className:Y.sceneGrid,children:[p.map(I=>{const B=o.includes(I.id),W=k===I.id;return e.jsxs("div",{className:`${Y.sceneCard} ${B?Y.sceneCardActive:""} ${W?Y.sceneCardSelected:""}`,style:{background:I.color??"var(--nice-bg-secondary, #f8fafc)"},onClick:()=>m(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," ",_("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":_("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:_("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:Q_.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:_("buildings.sceneName","Scene name")}),e.jsx("textarea",{className:Y.descInput,value:C.description??"",readOnly:r,onChange:I=>T({description:I.target.value}),placeholder:_("buildings.descriptionOptional","Description (optional)"),rows:2})]})]}),!r&&e.jsx("div",{className:Y.colorPicker,children:ef.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:_("buildings.devicesInScene","Devices in this scene")}),!r&&e.jsxs("button",{className:Y.addTargetBtn,onClick:d,children:[e.jsx(S.NiceIcon,{name:"plus",size:12})," ",_("buildings.add","Add")]})]}),C.deviceTargets.map((I,B)=>e.jsx(tf,{target:I,devices:n,onChange:W=>T({deviceTargets:C.deviceTargets.map((te,ue)=>ue===B?W:te)}),onRemove:()=>T({deviceTargets:C.deviceTargets.filter((W,te)=>te!==B)})},B)),C.deviceTargets.length===0&&e.jsx("div",{className:Y.noTargets,children:_("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})," ",_("buildings.activateScene","Activate scene")]}),!r&&e.jsx("button",{className:Y.deleteBtn,onClick:()=>L(C.id),children:_("buildings.remove","Remove")})]})]}):void 0;return e.jsxs("div",{className:`nice-scene-editor ${Y.root} ${l==="dark"?Y.dark:""} ${h??""}`,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,K_)})}),e.jsx(S.NiceAppShell,{flush:!0,className:Y.shell,sidebar:v,children:g})]})};exports.LayerPanel=vs;exports.Minimap=js;exports.NiceAutomationEditor=r_;exports.NiceBuildingDashboard=Jm;exports.NiceDeviceControl=bp;exports.NiceFloorPlanEditor=Bn;exports.NiceLightControl=Is;exports.NiceSceneEditor=sf;exports.NiceSpatialEditor=gd;exports.NiceSpatialViewer=em;exports.NiceThermostatControl=Ss;exports.NiceZoneCard=ks;exports.ObjectLibrary=ws;exports.PropertiesPanel=Ns;exports.useMeasurement=nm;exports.useSnapToGrid=sm;exports.useSpatialEditor=tm;
|