PageSourceSearch

https://boardspace.ai/assets/FloorplanEditor-BSRd8yaP.js

js boardspace.ai collected 2026-10-05 11:51:24 UTC 1,592,879 bytes, 447 lines download raw bytes

1var uN=Object.defineProperty;var hN=(t,e,s)=>e in t?uN(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var UM=(t,e,s)=>hN(t,typeof e!="symbol"?e+"":e,s);import{j as n}from"./ui-DKb32DiD.js";import{c as Fo,o as jw,cd as mN,ce as fN,b7 as xN,n as Ys,x as O,V as Ey,X as Gr,l as zl,I as Ok,ax as __,F as pN,an as gi,a as Yd,s as Bo,bU as _w,a3 as fc,f as ln,L as np,am as Pf,$ as Xa,au as gN,a4 as Hd,a1 as pm,C as Hk,cf as E_,al as Yc,cg as D_,as as F_,H as w1,h as Ew,R as hp,M as Bk,b9 as Dw,aG as C_,a0 as Gc,cc as k1,Z as Dy,aR as v1,ch as Fw,ci as bN,cj as Cw,ck as Nw,cl as Iw,cm as Tw,cn as Sw,co as Pw,cp as Aw,k as MN,b1 as yN,b4 as qu,aq as Yl,ar as Gl,at as Ul,b6 as Ju,cq as wN,b5 as Qu,ap as N_,c6 as kN,aS as Lw,a_ as op,c9 as I_,aH as vN,aV as T_,aW as S_,aY as P_,aZ as A_,cr as jN,aB as _N,B as Vk,J as L_,K as W_,O as R_,W as j1,u as Ww,cs as EN,ct as DN,cu as KM,cv as FN,cw as CN,cx as NN,cy as IN,aQ as _1,cz as TN,cA as SN,cB as PN,cC as AN,cD as LN,cE as WN,cF as RN,N as ON,Q as HN,_ as BN,bV as VN,j as zN,bl as $N,aF as O_,ak as XN,aM as YN,b as GN}from"./index-oNwIZiHT.js";import{r as m,a as H_}from"./vendor-DCFBENKy.js";import{b as Vo,f as ka,E as xo,g as Ya,L as Jn,H as Uu,d as Rw,h as Ow,S as UN,i as Fy,C as KN,j as ZN,O as qN}from"./r3f-BN6X73lm.js";import{c as le,aw as cr,a5 as Uc,aZ as gm,b7 as $l,b8 as Gd,b9 as dm,D as kn,s as Ga,R as Ea,d as Po,ae as Ua,aG as Ur,l as Sp,E as B_,Z as cb,ab as Vu,$ as V_,a3 as z_,w as Do,ba as db,ac as Jg,aa as Cy,ag as zk,aM as $k,M as E1,ay as Hw,K as JN,k as QN,m as tI,bb as Xk,bc as ub,bd as eI,ah as $_,r as nI,Q as Bw,be as hb,al as Ru,a as oI,b as sI,A as rI,aj as iI,p as ZM,S as aI,b6 as lI,z as Yk,P as cI,W as dI}from"./three-Dv4K_qkO.js";import{e as mb,g as Gk,d as qM,u as Uk,s as Kk,n as uI,l as hI,a as J0,b as mI,m as Zk,c as fI,f as xI,h as pI,i as qk,r as gI}from"./blenderImport-BZvr9lWN.js";import{M as bI,A as MI,u as yI}from"./useSubscriptionAccess-BNHCMZSj.js";import{P as mp}from"./pencil-DUmInc3t.js";import{M as D1,g as Gx,R as X_,C as wI,F as Jk,A as kI,a as Y_,S as vI,u as jI}from"./useMyFloorTextures-Bbofh8VT.js";import{M as G_}from"./minimize-2-COuWOHHN.js";import{u as U_,a as K_,g as Z_,b as _I}from"./useSystemFurniture-DsShbL-i.js";import{G as EI,H as DI,a as Af,A as wf,S as FI,T as Q0,c as q_,b as CI,d as NI,r as II,C as TI,I as SI,F as PI,B as AI}from"./meshy3dClient-B24NeEwy.js";import{S as um}from"./sofa-D3dBjIFo.js";import{B as F1}from"./bot-BcJDFjeG.js";import{M as LI}from"./move-D7VyDvJr.js";import{R as zu}from"./rotate-ccw-hUuExNCy.js";import{M as Pp,L as fp,H as WI}from"./minus-Bs132Pro.js";import{A as J_}from"./arrow-down-DGHAAABk.js";import{S as Ny}from"./save-elU05o7Y.js";import{M as RI}from"./maximize-2-DZ41IwX_.js";import{B as Qk}from"./book-open-B9QzYANu.js";import{D as Cf}from"./door-open-DD1dOZq5.js";import{B as Jh}from"./bath-B7OoUnyQ.js";import{H as $u}from"./house-DHu8AHIy.js";import{u as fb}from"./useTokenGuard-0fj-tWV0.js";import{I as C1}from"./image-jYsTE5eT.js";import{G as OI}from"./gem-DUIt9yJk.js";import{U as Ap}from"./upload-C8djh6xk.js";import{P as Vw}from"./package-Cs2TzaVy.js";import{D as xp}from"./download-BpYWTfzd.js";import{P as HI}from"./paintbrush-2vVP907W.js";import{S as Q_,e as t5,F as BI,b as e5,d as VI}from"./contextMenuViewport-8_ElpN4s.js";import{T as zI}from"./triangle-alert-DTJwGi0l.js";import{B as Iy}from"./boxes-DRoLSX17.js";import{U as tE,R as eE}from"./undo-2-BxAkZh0W.js";import{S as $I}from"./square-CcUF8c_D.js";import{S as XI}from"./shield-check-DECexS1w.js";import{C as YI,a as GI,b as UI}from"./collapsible-BgSvoJyU.js";import{P as KI}from"./panel-right-open-C3w0KbMN.js";import{L as ZI}from"./lightbulb-XyckiZoQ.js";import{I as n5}from"./image-plus-BSlRWsdz.js";import{H as qI}from"./hand-B8XweHat.js";import"./motion-BrksToHf.js";import"./konva-L1CHpTsF.js";import"./generationFailure-C4el59cC.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const JI=Fo("AlignCenterHorizontal",[["path",{d:"M2 12h20",key:"9i4pu4"}],["path",{d:"M10 16v4a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-4",key:"11f1s0"}],["path",{d:"M10 8V4a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v4",key:"t14dx9"}],["path",{d:"M20 16v1a2 2 0 0 1-2 2h-2a2 2 0 0 1-2-2v-1",key:"1w07xs"}],["path",{d:"M14 8V7c0-1.1.9-2 2-2h2a2 2 0 0 1 2 2v1",key:"1apec2"}]]);/**
7 * @license lucide-react v0.462.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const QI=Fo("AlignCenter",[["path",{d:"M17 12H7",key:"16if0g"}],["path",{d:"M19 18H5",key:"18s9l3"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);/**
12 * @license lucide-react v0.462.0 - ISC
13 *
14 * This source code is licensed under the ISC license.
15 * See the LICENSE file in the root directory of this source tree.
16 */const tT=Fo("AlignLeft",[["path",{d:"M15 12H3",key:"6jk70r"}],["path",{d:"M17 18H3",key:"1amg6g"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);/**
17 * @license lucide-react v0.462.0 - ISC
18 *
19 * This source code is licensed under the ISC license.
20 * See the LICENSE file in the root directory of this source tree.
21 */const eT=Fo("AlignRight",[["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M21 18H7",key:"1ygte8"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);/**
22 * @license lucide-react v0.462.0 - ISC
23 *
24 * This source code is licensed under the ISC license.
25 * See the LICENSE file in the root directory of this source tree.
26 */const Ux=Fo("Archive",[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]]);/**
27 * @license lucide-react v0.462.0 - ISC
28 *
29 * This source code is licensed under the ISC license.
30 * See the LICENSE file in the root directory of this source tree.
31 */const o5=Fo("ArrowLeftFromLine",[["path",{d:"m9 6-6 6 6 6",key:"7v63n9"}],["path",{d:"M3 12h14",key:"13k4hi"}],["path",{d:"M21 19V5",key:"b4bplr"}]]);/**
32 * @license lucide-react v0.462.0 - ISC
33 *
34 * This source code is licensed under the ISC license.
35 * See the LICENSE file in the root directory of this source tree.
36 */const s5=Fo("ArrowRightFromLine",[["path",{d:"M3 5v14",key:"1nt18q"}],["path",{d:"M21 12H7",key:"13ipq5"}],["path",{d:"m15 18 6-6-6-6",key:"6tx3qv"}]]);/**
37 * @license lucide-react v0.462.0 - ISC
38 *
39 * This source code is licensed under the ISC license.
40 * See the LICENSE file in the root directory of this source tree.
41 */const nT=Fo("ArrowUpLeft",[["path",{d:"M7 17V7h10",key:"11bw93"}],["path",{d:"M17 17 7 7",key:"2786uv"}]]);/**
42 * @license lucide-react v0.462.0 - ISC
43 *
44 * This source code is licensed under the ISC license.
45 * See the LICENSE file in the root directory of this source tree.
46 */const oT=Fo("Baby",[["path",{d:"M9 12h.01",key:"157uk2"}],["path",{d:"M15 12h.01",key:"1k8ypt"}],["path",{d:"M10 16c.5.3 1.2.5 2 .5s1.5-.2 2-.5",key:"1u7htd"}],["path",{d:"M19 6.3a9 9 0 0 1 1.8 3.9 2 2 0 0 1 0 3.6 9 9 0 0 1-17.6 0 2 2 0 0 1 0-3.6A9 9 0 0 1 12 3c2 0 3.5 1.1 3.5 2.5s-.9 2.5-2 2.5c-.8 0-1.5-.4-1.5-1",key:"5yv0yz"}]]);/**
47 * @license lucide-react v0.462.0 - ISC
48 *
49 * This source code is licensed under the ISC license.
50 * See the LICENSE file in the root directory of this source tree.
51 */const sT=Fo("Bed",[["path",{d:"M2 4v16",key:"vw9hq8"}],["path",{d:"M2 8h18a2 2 0 0 1 2 2v10",key:"1dgv2r"}],["path",{d:"M2 17h20",key:"18nfp3"}],["path",{d:"M6 8v9",key:"1yriud"}]]);/**
52 * @license lucide-react v0.462.0 - ISC
53 *
54 * This source code is licensed under the ISC license.
55 * See the LICENSE file in the root directory of this source tree.
56 */const rT=Fo("BetweenHorizontalStart",[["rect",{width:"13",height:"7",x:"8",y:"3",rx:"1",key:"pkso9a"}],["path",{d:"m2 9 3 3-3 3",key:"1agib5"}],["rect",{width:"13",height:"7",x:"8",y:"14",rx:"1",key:"1q5fc1"}]]);/**
57 * @license lucide-react v0.462.0 - ISC
58 *
59 * This source code is licensed under the ISC license.
60 * See the LICENSE file in the root directory of this source tree.
61 */const iT=Fo("Bold",[["path",{d:"M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8",key:"mg9rjx"}]]);/**
62 * @license lucide-react v0.462.0 - ISC
63 *
64 * This source code is licensed under the ISC license.
65 * See the LICENSE file in the root directory of this source tree.
66 */const aT=Fo("Briefcase",[["path",{d:"M16 20V4a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v16",key:"jecpp"}],["rect",{width:"20",height:"14",x:"2",y:"6",rx:"2",key:"i6l2r4"}]]);/**
67 * @license lucide-react v0.462.0 - ISC
68 *
69 * This source code is licensed under the ISC license.
70 * See the LICENSE file in the root directory of this source tree.
71 */const lT=Fo("CircleStop",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["rect",{x:"9",y:"9",width:"6",height:"6",rx:"1",key:"1ssd4o"}]]);/**
72 * @license lucide-react v0.462.0 - ISC
73 *
74 * This source code is licensed under the ISC license.
75 * See the LICENSE file in the root directory of this source tree.
76 */const r5=Fo("ClipboardList",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}],["path",{d:"M12 11h4",key:"1jrz19"}],["path",{d:"M12 16h4",key:"n85exb"}],["path",{d:"M8 11h.01",key:"1dfujw"}],["path",{d:"M8 16h.01",key:"18s6g9"}]]);/**
77 * @license lucide-react v0.462.0 - ISC
78 *
79 * This source code is licensed under the ISC license.
80 * See the LICENSE file in the root directory of this source tree.
81 */const cT=Fo("CloudDownload",[["path",{d:"M12 13v8l-4-4",key:"1f5nwf"}],["path",{d:"m12 21 4-4",key:"1lfcce"}],["path",{d:"M4.393 15.269A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.436 8.284",key:"ui1hmy"}]]);/**
82 * @license lucide-react v0.462.0 - ISC
83 *
84 * This source code is licensed under the ISC license.
85 * See the LICENSE file in the root directory of this source tree.
86 */const nE=Fo("CookingPot",[["path",{d:"M2 12h20",key:"9i4pu4"}],["path",{d:"M20 12v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8",key:"u0tga0"}],["path",{d:"m4 8 16-4",key:"16g0ng"}],["path",{d:"m8.86 6.78-.45-1.81a2 2 0 0 1 1.45-2.43l1.94-.48a2 2 0 0 1 2.43 1.46l.45 1.8",key:"12cejc"}]]);/**
87 * @license lucide-react v0.462.0 - ISC
88 *
89 * This source code is licensed under the ISC license.
90 * See the LICENSE file in the root directory of this source tree.
91 */const N1=Fo("FlipHorizontal2",[["path",{d:"m3 7 5 5-5 5V7",key:"couhi7"}],["path",{d:"m21 7-5 5 5 5V7",key:"6ouia7"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"M12 14v2",key:"8jcxud"}],["path",{d:"M12 8v2",key:"1woqiv"}],["path",{d:"M12 2v2",key:"tus03m"}]]);/**
92 * @license lucide-react v0.462.0 - ISC
93 *
94 * This source code is licensed under the ISC license.
95 * See the LICENSE file in the root directory of this source tree.
96 */const dT=Fo("Flower2",[["path",{d:"M12 5a3 3 0 1 1 3 3m-3-3a3 3 0 1 0-3 3m3-3v1M9 8a3 3 0 1 0 3 3M9 8h1m5 0a3 3 0 1 1-3 3m3-3h-1m-2 3v-1",key:"3pnvol"}],["circle",{cx:"12",cy:"8",r:"2",key:"1822b1"}
96],["path",{d:"M12 10v12",key:"6ubwww"}],["path",{d:"M12 22c4.2 0 7-1.667 7-5-4.2 0-7 1.667-7 5Z",key:"9hd38g"}],["path",{d:"M12 22c-4.2 0-7-1.667-7-5 4.2 0 7 1.667 7 5Z",key:"ufn41s"}]]);/**
97 * @license lucide-react v0.462.0 - ISC
98 *
99 * This source code is licensed under the ISC license.
100 * See the LICENSE file in the root directory of this source tree.
101 */const uT=Fo("Lamp",[["path",{d:"M8 2h8l4 10H4L8 2Z",key:"9dma5w"}],["path",{d:"M12 12v6",key:"3ahymv"}],["path",{d:"M8 22v-2c0-1.1.9-2 2-2h4a2 2 0 0 1 2 2v2H8Z",key:"mwf4oh"}]]);/**
102 * @license lucide-react v0.462.0 - ISC
103 *
104 * This source code is licensed under the ISC license.
105 * See the LICENSE file in the root directory of this source tree.
106 */const oE=Fo("LayoutList",[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}],["path",{d:"M14 4h7",key:"3xa0d5"}],["path",{d:"M14 9h7",key:"1icrd9"}],["path",{d:"M14 15h7",key:"1mj8o2"}],["path",{d:"M14 20h7",key:"11slyb"}]]);/**
107 * @license lucide-react v0.462.0 - ISC
108 *
109 * This source code is licensed under the ISC license.
110 * See the LICENSE file in the root directory of this source tree.
111 */const i5=Fo("LayoutTemplate",[["rect",{width:"18",height:"7",x:"3",y:"3",rx:"1",key:"f1a2em"}],["rect",{width:"9",height:"7",x:"3",y:"14",rx:"1",key:"jqznyg"}],["rect",{width:"5",height:"7",x:"16",y:"14",rx:"1",key:"q5h2i8"}]]);/**
112 * @license lucide-react v0.462.0 - ISC
113 *
114 * This source code is licensed under the ISC license.
115 * See the LICENSE file in the root directory of this source tree.
116 */const hT=Fo("ListChecks",[["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["path",{d:"m3 7 2 2 4-4",key:"1obspn"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}]]);/**
117 * @license lucide-react v0.462.0 - ISC
118 *
119 * This source code is licensed under the ISC license.
120 * See the LICENSE file in the root directory of this source tree.
121 */const mT=Fo("Magnet",[["path",{d:"m6 15-4-4 6.75-6.77a7.79 7.79 0 0 1 11 11L13 22l-4-4 6.39-6.36a2.14 2.14 0 0 0-3-3L6 15",key:"1i3lhw"}],["path",{d:"m5 8 4 4",key:"j6kj7e"}],["path",{d:"m12 15 4 4",key:"lnac28"}]]);/**
122 * @license lucide-react v0.462.0 - ISC
123 *
124 * This source code is licensed under the ISC license.
125 * See the LICENSE file in the root directory of this source tree.
126 */const a5=Fo("MoveHorizontal",[["path",{d:"m18 8 4 4-4 4",key:"1ak13k"}],["path",{d:"M2 12h20",key:"9i4pu4"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}]]);/**
127 * @license lucide-react v0.462.0 - ISC
128 *
129 * This source code is licensed under the ISC license.
130 * See the LICENSE file in the root directory of this source tree.
131 */const l5=Fo("MoveVertical",[["path",{d:"M12 2v20",key:"t6zp3m"}],["path",{d:"m8 18 4 4 4-4",key:"bh5tu3"}],["path",{d:"m8 6 4-4 4 4",key:"ybng9g"}]]);/**
132 * @license lucide-react v0.462.0 - ISC
133 *
134 * This source code is licensed under the ISC license.
135 * See the LICENSE file in the root directory of this source tree.
136 */const fT=Fo("PanelTopDashed",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M14 9h1",key:"l0svgy"}],["path",{d:"M19 9h2",key:"te2zfg"}],["path",{d:"M3 9h2",key:"1h4ldw"}],["path",{d:"M9 9h1",key:"15jzuz"}]]);/**
137 * @license lucide-react v0.462.0 - ISC
138 *
139 * This source code is licensed under the ISC license.
140 * See the LICENSE file in the root directory of this source tree.
141 */const xT=Fo("Refrigerator",[["path",{d:"M5 6a4 4 0 0 1 4-4h6a4 4 0 0 1 4 4v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6Z",key:"fpq118"}],["path",{d:"M5 10h14",key:"elsbfy"}],["path",{d:"M15 7v6",key:"1nx30x"}]]);/**
142 * @license lucide-react v0.462.0 - ISC
143 *
144 * This source code is licensed under the ISC license.
145 * See the LICENSE file in the root directory of this source tree.
146 */const pT=Fo("Shirt",[["path",{d:"M20.38 3.46 16 2a4 4 0 0 1-8 0L3.62 3.46a2 2 0 0 0-1.34 2.23l.58 3.47a1 1 0 0 0 .99.84H6v10c0 1.1.9 2 2 2h8a2 2 0 0 0 2-2V10h2.15a1 1 0 0 0 .99-.84l.58-3.47a2 2 0 0 0-1.34-2.23z",key:"1wgbhj"}]]);/**
147 * @license lucide-react v0.462.0 - ISC
148 *
149 * This source code is licensed under the ISC license.
150 * See the LICENSE file in the root directory of this source tree.
151 */const gT=Fo("Spline",[["circle",{cx:"19",cy:"5",r:"2",key:"mhkx31"}],["circle",{cx:"5",cy:"19",r:"2",key:"v8kfzx"}],["path",{d:"M5 17A12 12 0 0 1 17 5",key:"1okkup"}]]);/**
152 * @license lucide-react v0.462.0 - ISC
153 *
154 * This source code is licensed under the ISC license.
155 * See the LICENSE file in the root directory of this source tree.
156 */const bT=Fo("SquareDashedMousePointer",[["path",{d:"M12.034 12.681a.498.498 0 0 1 .647-.647l9 3.5a.5.5 0 0 1-.033.943l-3.444 1.068a1 1 0 0 0-.66.66l-1.
156067 3.443a.5.5 0 0 1-.943.033z",key:"xwnzip"}],["path",{d:"M5 3a2 2 0 0 0-2 2",key:"y57alp"}],["path",{d:"M19 3a2 2 0 0 1 2 2",key:"18rm91"}],["path",{d:"M5 21a2 2 0 0 1-2-2",key:"sbafld"}],["path",{d:"M9 3h1",key:"1yesri"}],["path",{d:"M9 21h2",key:"1qve2z"}],["path",{d:"M14 3h1",key:"1ec4yj"}],["path",{d:"M3 9v1",key:"1r0deq"}],["path",{d:"M21 9v2",key:"p14lih"}],["path",{d:"M3 14v1",key:"vnatye"}]]);/**
157 * @license lucide-react v0.462.0 - ISC
158 *
159 * This source code is licensed under the ISC license.
160 * See the LICENSE file in the root directory of this source tree.
161 */const MT=Fo("Sunrise",[["path",{d:"M12 2v8",key:"1q4o3n"}],["path",{d:"m4.93 10.93 1.41 1.41",key:"2a7f42"}],["path",{d:"M2 18h2",key:"j10viu"}],["path",{d:"M20 18h2",key:"wocana"}],["path",{d:"m19.07 10.93-1.41 1.41",key:"15zs5n"}],["path",{d:"M22 22H2",key:"19qnx5"}],["path",{d:"m8 6 4-4 4 4",key:"ybng9g"}],["path",{d:"M16 18a4 4 0 0 0-8 0",key:"1lzouq"}]]);/**
162 * @license lucide-react v0.462.0 - ISC
163 *
164 * This source code is licensed under the ISC license.
165 * See the LICENSE file in the root directory of this source tree.
166 */const sE=Fo("TreePine",[["path",{d:"m17 14 3 3.3a1 1 0 0 1-.7 1.7H4.7a1 1 0 0 1-.7-1.7L7 14h-.3a1 1 0 0 1-.7-1.7L9 9h-.2A1 1 0 0 1 8 7.3L12 3l4 4.3a1 1 0 0 1-.8 1.7H15l3 3.3a1 1 0 0 1-.7 1.7H17Z",key:"cpyugq"}],["path",{d:"M12 22v-3",key:"kmzjlo"}]]);/**
167 * @license lucide-react v0.462.0 - ISC
168 *
169 * This source code is licensed under the ISC license.
170 * See the LICENSE file in the root directory of this source tree.
171 */const zw=Fo("UtensilsCrossed",[["path",{d:"m16 2-2.3 2.3a3 3 0 0 0 0 4.2l1.8 1.8a3 3 0 0 0 4.2 0L22 8",key:"n7qcjb"}],["path",{d:"M15 15 3.3 3.3a4.2 4.2 0 0 0 0 6l7.3 7.3c.7.7 2 .7 2.8 0L15 15Zm0 0 7 7",key:"d0u48b"}],["path",{d:"m2.1 21.8 6.4-6.3",key:"yn04lh"}],["path",{d:"m19 5-7 7",key:"194lzd"}]]);/**
172 * @license lucide-react v0.462.0 - ISC
173 *
174 * This source code is licensed under the ISC license.
175 * See the LICENSE file in the root directory of this source tree.
176 */const Gh=Fo("Wallpaper",[["circle",{cx:"8",cy:"9",r:"2",key:"gjzl9d"}],["path",{d:"m9 17 6.1-6.1a2 2 0 0 1 2.81.01L22 15V5a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2",key:"69xh40"}],["path",{d:"M8 21h8",key:"1ev6f3"}],["path",{d:"M12 17v4",key:"1riwvh"}]]);/**
177 * @license lucide-react v0.462.0 - ISC
178 *
179 * This source code is licensed under the ISC license.
180 * See the LICENSE file in the root directory of this source tree.
181 */const c5=Fo("WashingMachine",[["path",{d:"M3 6h3",key:"155dbl"}],["path",{d:"M17 6h.01",key:"e2y6kg"}],["rect",{width:"18",height:"20",x:"3",y:"2",rx:"2",key:"od3kk9"}],["circle",{cx:"12",cy:"13",r:"5",key:"nlbqau"}],["path",{d:"M12 18a2.5 2.5 0 0 0 0-5 2.5 2.5 0 0 1 0-5",key:"17lach"}]]);function yn(){const t=jw("floorplan"),e=m.useCallback((s,o)=>t.t(s,{...o,fallbackLng:!1}),[t.t]);return{...t,t:e}}const Ty=mN("boardspace-floorplan-audio"),rE=fN(()=>Ty.getState()),Pr=rE.playSfx,yT=rE.preloadSfx,wT=.1;function kT({coords:t,gridSnapActive:e,gridStep:s,freeStep:o=wT}){const r=o;return t.map(i=>Math.round(i/r)).join(",")}function xc(){const{theme:t}=xN();return m.useMemo(()=>t==="dark"||t==="system"&&typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches,[t])}function vT({isDark:t}){const e=t?"rgba(255,255,255,0.5)":"rgba(24,33,55,0.55)",s="#EC7357";return n.jsxs("svg",{viewBox:"0 0 200 120",className:"h-full w-full",fill:"none",children:[n.jsx("rect",{x:"18",y:"26",width:"60",height:"70",stroke:e,strokeWidth:"1.5"}),n.jsx("line",{x1:"18",y1:"60",x2:"78",y2:"60",stroke:e,strokeWidth:"1"}),n.jsx("line",{x1:"48",y1:"26",x2:"48",y2:"60",stroke:e,strokeWidth:"1"}),n.jsx("line",{x1:"18",y1:"82",x2:"30",y2:"82",stroke:e,strokeWidth:"1"}),n.jsx("path",{d:"M 55 96 A 10 10 0 0 1 65 86",stroke:e,strokeWidth:"1",fill:"none"}),n.jsx("path",{d:"M 92 61 L 112 61 M 105 54 L 112 61 L 105 68",stroke:s,strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"}),n.jsx("path",{d:"M 130 45 L 155 32 L 186 47 L 161 60 Z",fill:s,opacity:"0.25"}),n.jsx("path",{d:"M 130 45 L 130 88 L 161 103 L 161 60 Z",fill:s,opacity:"0.55"}),n.jsx("path",{d:"M 161 60 L 186 47 L 186 90 L 161 103 Z",fill:s,opacity:"0.85"})]})}function jT(t,e){const s=e.get(t);let o=t;for(;o;){const r=e.get(o);
181if(typeof(r==null?void 0:r.nodes)=="number")return{...s,nodes:r.nodes};o=o.parent}return s}function _T(t,e){var l,c,d,u;const s=(l=e.materialAssociation)==null?void 0:l.materials,o=(c=e.meshAssociation)==null?void 0:c.nodes,r=(d=e.meshAssociation)==null?void 0:d.meshes,i=(u=e.meshAssociation)==null?void 0:u.primitives,a=e.materialName??"";return t.find(h=>{var f,p,b;if(h.source==="node")return typeof o=="number"&&!!((f=h.match.nodeIndices)!=null&&f.includes(o))&&typeof r=="number"&&h.match.meshIndices.includes(r)&&typeof i=="number"&&!!((p=h.match.primitiveIndices)!=null&&p.includes(i));const x=typeof r=="number"&&h.match.meshIndices.includes(r)&&(!((b=h.match.primitiveIndices)!=null&&b.length)||typeof i=="number"&&h.match.primitiveIndices.includes(i));return h.source==="mesh"?x:typeof s=="number"&&h.match.materialIndices.includes(s)||a&&h.match.materialNames.includes(a)?!0:x&&h.match.materialIndices.length===0&&h.match.materialNames.length===0})}function ET(t,e){if(t.length===0)return null;if(typeof e=="number"&&e>=0)return t[e]??null;if(t.length===1)return t[0]??null;const s=Array.from(new Set(t.filter(o=>!!o)));return s.length===1?s[0]:null}function DT(t,e,s){const o={...t??{}};return s?o[e]=s:delete o[e],Object.keys(o).length>0?o:void 0}const $w=["exterior","interior","mamad","free"],Ld=2700,br={exterior:{thicknessMm:250,heightMm:Ld},interior:{thicknessMm:120,heightMm:Ld},mamad:{thicknessMm:500,heightMm:Ld},free:{thicknessMm:100,heightMm:1e3}},iE={exterior:{thickness:br.exterior.thicknessMm,label:"חיצוני",color:"#1a5bb5"},interior:{thickness:br.interior.thicknessMm,label:"פנימי",color:"#F5B800"},mamad:{thickness:br.mamad.thicknessMm,label:"ממ״ד",color:"#D84B2E"},free:{thickness:br.free.thicknessMm,label:"חופשי",color:"#2A9D8F"}},d5={exterior:"קיר חיצוני",interior:"קיר פנימי",mamad:"קיר ממ״ד",free:"קיר חופשי"};function Uh(){return{exterior:{...br.exterior},interior:{...br.interior},mamad:{...br.mamad},free:{...br.free}}}function JM(t){const e=Uh();if(!t||typeof t!="object")return e;const s=t;for(const o of $w){const r=s[o];if(!r||typeof r!="object")continue;const i=r,a=Number(i.thicknessMm??i.thickness),l=Number(i.heightMm??i.height);e[o]={thicknessMm:Number.isFinite(a)&&a>0?Math.round(a):e[o].thicknessMm,heightMm:Number.isFinite(l)&&l>0?Math.round(l):e[o].heightMm}}return e}const Hf="vertical";function ei(t){return t==="horizontal"?"horizontal":Hf}function Xw(t,e=Hf){return e==="horizontal"?[t[1],t[0]]:t}function tg(t,e){return typeof t=="number"&&Number.isFinite(t)&&t>0?Math.round(t):e}function aE(t,e=br){if(t.wallType!=="free")return t;const s=e.free??br.free,o=tg(s.thicknessMm,br.free.thicknessMm),r=tg(s.heightMm,br.free.heightMm),i=tg(t.thicknessMm,o),a=tg(t.heightMm,r);return t.thicknessMm===i&&t.heightMm===a?t:{...t,thicknessMm:i,heightMm:a}}function Qg(t,e=br){let s=!1;const o=t.map(r=>{const i=aE(r,e);return i!==r&&(s=!0),i});return s?o:t}const qs={single_door:{label:"דלת רגילה",category:"door",width:900,height:2100,sillHeight:0,hasSwing:!0,symbol:"arc"},single_door_glass:{label:"דלת זכוכית",category:"door",width:900,height:2100,sillHeight:0,hasSwing:!0,symbol:"arc"},flush_door:{label:"דלת קו 0",category:"door",width:900,height:2100,sillHeight:0,hasSwing:!0,symbol:"arc"},double_door:{label:"דלת כפולה",category:"door",width:1600,height:2100,sillHeight:0,hasSwing:!0,symbol:"double_arc"},sliding_door:{label:"דלת הזזה",category:"door",width:1800,height:2100,sillHeight:0,hasSwing:!1,symbol:"slide"},corner_glass_door:{label:"דלת זכוכית פינתית",category:"door",width:1200,height:2600,sillHeight:0,hasSwing:!1,symbol:"corner_line"},arched_door:{label:"דלת קשתית",category:"door",width:900,height:2400,sillHeight:0,hasSwing:!0,symbol:"arc"},arched_door_glass:{label:"קשתית זכוכית",category:"door",width:900,height:2400,sillHeight:0,hasSwing:!0,symbol:"arc"},wide_doorway:{label:"פתח רחב",category:"door",width:1800,height:2100,sillHeight:0,hasSwing:!1,symbol:"gap"},garage_door:{label:"דלת מוסך",category:"door",width:2600,height:2200,sillHeight:0,hasSwing:!1,symbol:"rollup"},fixed_window:{label:"חלון קבוע",category:"window",width:900,height:1400,sillHeight:900,hasSwing:!1,symbol:"line"}
181,casement_window:{label:"חלון ציר",category:"window",width:1e3,height:1200,sillHeight:900,hasSwing:!0,symbol:"casement"},awning_window:{label:"חלון גג (Awning)",category:"window",width:1e3,height:900,sillHeight:1200,hasSwing:!0,symbol:"awning"},sliding_window:{label:"חלון הזזה",category:"window",width:1600,height:1200,sillHeight:900,hasSwing:!1,symbol:"slide"},bay_window:{label:"חלון בליטה (Bay)",category:"window",width:2e3,height:1400,sillHeight:600,hasSwing:!1,symbol:"bay"},wide_window:{label:"חלון רחב",category:"window",width:2e3,height:1200,sillHeight:900,hasSwing:!1,symbol:"line"},arched_window:{label:"חלון קשתי",category:"window",width:1200,height:1500,sillHeight:800,hasSwing:!1,symbol:"line"},floor_to_ceiling:{label:"רצפה עד תקרה",category:"window",width:2400,height:2600,sillHeight:0,hasSwing:!1,symbol:"line"},floor_to_ceiling_vertical:{label:"דלת סלייד מינימל",category:"window",width:2400,height:2600,sillHeight:0,hasSwing:!1,symbol:"line"},passage:{label:"מעבר",category:"door",width:900,height:2100,sillHeight:0,hasSwing:!1,symbol:"gap"}};function Yw(t){return t==="passage"||t==="wide_doorway"}const Kc={door:{width:900,height:2100,sillHeight:0},window:{width:1200,height:1200,sillHeight:900}},pi={sofa:{width:2200,depth:900,height:850,label:"ספה קלאסית"},sofa_2:{width:2200,depth:900,height:850,label:"ספה מודרנית"},sofa_corner:{width:2800,depth:2e3,height:850,label:"ספה פינתית"},sofa_3seat:{width:2400,depth:950,height:850,label:"ספה תלת"},loveseat:{width:1600,depth:850,height:850,label:"ספה דו מושבית"},armchair:{width:900,depth:900,height:850,label:"כורסה קלאסית"},armchair_2:{width:900,depth:900,height:850,label:"כורסה מודרנית"},armchair_wing:{width:850,depth:850,height:1e3,label:"כורסת אוזניים"},recliner:{width:900,depth:950,height:1e3,label:"כורסת הרגעה"},pouf:{width:600,depth:600,height:400,label:"פוף"},table:{width:1600,depth:900,height:750,label:"שולחן סלון"},coffee_table:{width:1200,depth:600,height:450,label:"שולחן קפה"},side_table:{width:500,depth:500,height:550,label:"שולחן צד"},console_table:{width:1200,depth:350,height:800,label:"קונסולה"},tv_unit:{width:1600,depth:400,height:500,label:"מזנון"},tv_wall_unit:{width:2400,depth:400,height:1800,label:"קיר טלוויזיה"},bookcase:{width:800,depth:350,height:1800,label:"ספריה"},shelf_wall:{width:1200,depth:250,height:300,label:"מדף קיר"},display_cabinet:{width:900,depth:400,height:1800,label:"ויטרינה"},rug_rect:{width:2e3,depth:1400,height:10,label:"שטיח מלבני"},rug_round:{width:1800,depth:1800,height:10,label:"שטיח עגול"},bed:{width:2e3,depth:1600,height:550,label:"מיטה זוגית"},bed_single:{width:2e3,depth:900,height:550,label:"מיטה יחיד"},bed_king:{width:2200,depth:2e3,height:550,label:"מיטת קינג"},bed_bunk:{width:2e3,depth:900,height:1700,label:"מיטת קומתיים"},nightstand:{width:500,depth:400,height:550,label:"שידת לילה"},nightstand_wide:{width:600,depth:450,height:500,label:"שידת לילה רחבה"},dresser:{width:1200,depth:500,height:800,label:"שידת מגירות"},dresser_tall:{width:800,depth:450,height:1200,label:"שידה גבוהה"},vanity_table:{width:1e3,depth:450,height:750,label:"שולחן איפור"},wardrobe:{width:1800,depth:600,height:2200,label:"ארון בגדים"},wardrobe_sliding:{width:2400,depth:650,height:2200,label:"ארון הזזה"},wardrobe_corner:{width:1200,depth:1200,height:2200,label:"ארון פינתי"},wardrobe_open:{width:1600,depth:500,height:2e3,label:"ארון פתוח"},mirror_standing:{width:600,depth:50,height:1700,label:"מראה עומדת"},mirror_wall:{width:800,depth:50,height:1200,label:"מראת קיר"},dining_table:{width:1800,depth:900,height:750,label:"שולחן אוכל"},dining_table_round:{width:1200,depth:1200,height:750,label:"שולחן אוכל עגול"},dining_table_ext:{width:2200,depth:1e3,height:750,label:"שולחן אוכל נפתח"},chair:{width:500,depth:500,height:900,label:"כיסא"},dining_chair_up:{width:500,depth:550,height:900,label:"כיסא מרופד"},bench_dining:{width:1400,depth:400,height:450,label:"ספסל אוכל"},sideboard:{width:1600,depth:450,height:850,label:"מזנון אוכל"},buffet:{width:1400,depth:500,height:900,label:"בופט"},bar_stool:{width:400,depth:400,height:750,label:"כיסא בר"},bar_table:{width:1200,depth:500,height:1050,label:"שולחן בר"},cabinet_lower:{width:600,depth:600,height:850,label:"ארון תחתון"},cabinet_upper:{width:600,depth:350,height:700,label:"ארון עליון"},cabinet_tall:{width:600,depth:600,height:2100,label:"ארון גבוה"},cabinet_corner:{width:900,depth:900,height:850,label:"ארון פינתי"},kitchen_island:{width:1800,depth:900,height:900,label:"אי מטבח"},kitchen_island_l:{width:2400,depth:1200,height:900,label:"אי מטבח גדול"},fridge:{width:700,depth:700,height:1800,label:"מקרר"},fridge_double:{width:900,depth:700,height:1800,label:"מקרר דו דלתי"},stove:{width:600,depth:600,height:900,label:"כיריים"},oven_builtin:{width:600,depth:550,height:600,label:"תנור בנוי"},range_hood:{width:600,depth:500,height:400,label:"קולט אדים"},microwave:{width:500,depth:400,height:300,label:"מיקרוגל"},dishwasher:{width:600,depth:600,height:850,label:"מדיח כלים"},kitchen_sink:{width:600,depth:500,height:900,label:"כיור מטבח"},kitchen_sink_dbl:{width:800,depth:500,height:900,label:"כיור כפול"},bathtub:{width:1700,depth:750,height:600,label:"אמבטיה"},bathtub_corner:{width:1500,depth:1500,height:600,label:"אמבטיה פינתית"},bathtub_freestand:{width:1700,depth:800,height:650,label:"אמבטיה עומדת"},shower:{width:900,depth:900,height:2100,label:"מקלחון"},shower_walk_in:{width:1400,depth:900,height:2100,label:"מקלחון ווק-אין"},toilet:{width:400,depth:650,height:400,label:"אסלה"},toilet_wall:{width:400,depth:550,height:400,label:"אסלה תלויה"},bidet:{width:400,depth:600,height:400,label:"בידה"},bathroom_sink:{width:500,depth:400,height:850,label:"כיור רחצה"},vanity:{width:800,depth:500,height:850,label:"ארון כיור"},vanity_double:{width:1200,depth:500,height:850,label:"ארון כיור כפול"},washer:{width:600,depth:600,height:850,label:"מכונת כביסה"},dryer:{width:600,depth:600,height:850,label:"מייבש כביסה"},desk:{width:1200,depth:600,height:750,label:"שולחן כתיבה"},desk_l_shape:{width:1600,depth:1400,height:750,label:"שולחן L"}
181,desk_standing:{width:1400,depth:700,height:1100,label:"שולחן עמידה"},office_chair:{width:650,depth:650,height:1100,label:"כיסא משרדי"},office_chair_ex:{width:700,depth:700,height:1200,label:"כיסא מנהלים"},filing_cabinet:{width:450,depth:600,height:1300,label:"ארון תיקים"},shelf_unit:{width:800,depth:350,height:1800,label:"יחידת מדפים"},closet_tall:{width:800,depth:600,height:2200,label:"ארון גבוה"},closet_wide:{width:1600,depth:600,height:2200,label:"ארון רחב"},closet_shoe:{width:900,depth:350,height:1200,label:"ארון נעליים"},storage_shelf:{width:900,depth:400,height:1800,label:"מדף אחסון"},cube_shelf:{width:1200,depth:350,height:1200,label:"מדף קוביות"},bench_outdoor:{width:1500,depth:500,height:450,label:"ספסל גינה"},lounge_chair:{width:700,depth:1600,height:800,label:"כיסא נוח"},planter:{width:500,depth:500,height:600,label:"עציץ"},planter_tall:{width:400,depth:400,height:1200,label:"עציץ גבוה"}};function FT(t){return t==="right"?"back":"front"}function CT(t){return t==="back"?"right":"left"}function Wd(t){return{hingeSide:t.hingeSide==="right"?"right":"left",swingFace:t.swingFace==="back"?"back":FT(t.swingSide)}}function rm(t){return{hingeSide:t.hingeSide,swingFace:t.swingFace,swingSide:CT(t.swingFace)}}function hm(t){return t.preset?qs[t.preset].hasSwing:t.type==="door"}function Lf(t){return t.type==="door"&&t.preset==="flush_door"}function xb(t){return t.flushFace==="back"?"back":"front"}function lE(t){return t==="flush_door"?{flushFace:"front"}:{}}function Gw(t){return{flushFace:t}}function pb(t){return[...t].sort().join("|")}function gb(t){if(!t||t.length<3)return"";const e=[],s=t.length,o=(r,i)=>`${Math.round(r)},${Math.round(i)}`;for(let r=0;r<s;r++){const i=t[r],a=t[(r+1)%s],l=i.x??0,c=i.y??0,d=a.x??0,u=a.y??0,h=o(l,c),x=o(d,u);e.push(h<x?`${h}~${x}`:`${x}~${h}`)}return e.sort(),`poly:${e.join(";")}`}function la(t){if(t.polygonKey&&t.polygonKey.length>0)return t.polygonKey;const e=gb(t.vertices);return e||pb(t.wallIds??[])}const u5=150,NT=300,cE=2700,I1=100,IT=50,TT=2e3,ST=50,PT=1500;function dE(){return`beam_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function uE(t){return Math.hypot(t.end.x-t.start.x,t.end.y-t.start.y)}function t1(t,e){return uE(t)*e}function Lp(t){return{x:(t.start.x+t.end.x)/2,y:(t.start.y+t.end.y)/2}}function Uw(t){return Number.isFinite(t)?(t%360+360)%360:0}function AT(t){return Uw(Math.atan2(t.end.y-t.start.y,t.end.x-t.start.x)*180/Math.PI)}function LT(t,e){const s=t.end.x-t.start.x,o=t.end.y-t.start.y,r=Math.hypot(s,o)||1,i=Math.max(1,t.widthMm/Math.max(e,.001)/2),a=-o/r*i,l=s/r*i;return[{x:t.start.x+a,y:t.start.y+l},{x:t.end.x+a,y:t.end.y+l},{x:t.end.x-a,y:t.end.y-l},{x:t.start.x-a,y:t.start.y-l}]}function hE(t,e,s,o=8){const r=Lp(e),i=e.end.x-e.start.x,a=e.end.y-e.start.y,l=Math.hypot(i,a);if(l<=0)return!1;const c=-Math.atan2(a,i),d=t.x-r.x,u=t.y-r.y,h=d*Math.cos(c)-u*Math.sin(c),x=d*Math.sin(c)+u*Math.cos(c),f=e.widthMm/Math.max(s,.001)/2;return Math.abs(h)<=l/2+o&&Math.abs(x)<=f+o}function mE(t,e){return{...t,start:{x:t.start.x+e.x,y:t.start.y+e.y},end:{x:t.end.x+e.x,y:t.end.y+e.y}}}function WT(t,e,s){const o=Lp(t),r=Math.atan2(t.end.y-t.start.y,t.end.x-t.start.x),i=Math.max(I1,e)/Math.max(s,.001)/2,a=Math.cos(r)*i,l=Math.sin(r)*i;return{...t,start:{x:o.x-a,y:o.y-l},end:{x:o.x+a,y:o.y+l}}}function fE(t,e){const s=Lp(t),o=uE(t)/2,r=Uw(e)*Math.PI/180,i=Math.cos(r)*o,a=Math.sin(r)*o;return{...t,start:{x:s.x-i,y:s.y-a},end:{x:s.x+i,y:s.y+a}}}function RT(t,e){const s=t.end.x-t.start.x,o=t.end.y-t.start.y,r=Math.hypot(s,o)||1,i=(t.widthMm+100)/Math.max(e,.001),a={x:-o/r*i,y:s/r*i};return{...mE(t,a),id:dE()}}function OT(t){return t.walls.length===0?cE:Math.max(...t.walls.map(e=>e.height))}function HT(t,e){const s=t.end.x-t.start.x,o=t.end.y-t.start.y,r=Math.max(10,Math.hypot(s,o)),i=Math.max(10,Math.min(t.height,e));return{position:[(t.start.x+t.end.x)/2e3,(e-i/2)/1e3,(t.start.y+t.end.y)/2e3],rotationY:-Math.atan2(o,s),size:[r/1e3,i/1e3,Math.max(10,t.width)/1e3]}}const rt=1/1e3,Sy=8,eg=1,xE=.008,BT=-.02;function mm(t){return Math.max(t.span,Sy)}function VT(t){const e=Number.isFinite(t)?Math.max(t,Sy):Sy,s=Math.max(e*20,eg*2),r=Math.max(1,Math.ceil(s/eg/2))*2;return{sizeM:r*eg,divisions:r,stepM:eg}}const T1={x:.42498159310831163,z:.5733269333317521},pE=2.77806091649678,zT={x:.5018923934449641,z:1.0746204996238076},$T=-2.7031291102530695;function Py(t=[]){return t.reduce((e,s)=>s.type.startsWith("blender_")?Math.max(e,s.height*rt):e,0)}function XT(t,e){const s=Kw(t.flatMap(r=>r.walls??[]),t.flatMap(r=>r.beams??[]),t.flatMap(r=>r.furniture??[]));let o=0;return t.forEach((r,i)=>{var u,h;const a=r.walls??[],l=Py(r.furniture);if(a.length===0&&(((u=r.beams)==null?void 0:u.length)??0)===0&&l===0)return;const c=a.length>0?a.reduce((x,f)=>
181Math.max(x,(f.height??0)*rt),0):(((h=r.beams)==null?void 0:h.length)??0)>0?cE*rt:0,d=(e[i]??0)+Math.max(c,l);d>o&&(o=d)}),{...s,maxY:o}}function Kw(t,e=[],s=[]){let o=1/0,r=-1/0,i=1/0,a=-1/0;for(const l of t)for(const c of[l.start,l.end]){const d=c.x*rt,u=c.y*rt;d<o&&(o=d),d>r&&(r=d),u<i&&(i=u),u>a&&(a=u)}for(const l of e)for(const c of[l.start,l.end]){const d=Math.max(0,l.width*rt/2),u=c.x*rt,h=c.y*rt;o=Math.min(o,u-d),r=Math.max(r,u+d),i=Math.min(i,h-d),a=Math.max(a,h+d)}for(const l of s){if(!l.type.startsWith("blender_"))continue;const c=l.rotation*Math.PI/180,d=Math.abs(Math.cos(c)),u=Math.abs(Math.sin(c)),h=(l.width*d+l.depth*u)*rt/2,x=(l.width*u+l.depth*d)*rt/2,f=l.position.x*rt,p=l.position.y*rt;o=Math.min(o,f-h),r=Math.max(r,f+h),i=Math.min(i,p-x),a=Math.max(a,p+x)}return isFinite(o)||(o=r=i=a=0),{minX:o,maxX:r,minZ:i,maxZ:a,centerX:(o+r)/2,centerZ:(i+a)/2,span:Math.max(r-o,a-i,.1)}}const gE=1e3,bE=400,YT=220,GT=2200;function UT(){return gE}function KT(){return bE}function Zw(){return gE/2}function ME(t,e){const s=bE/2,o=Math.max(s+50,400),r=Math.max(o,e-s-50);return Math.max(o,Math.min(r,Math.round(t)))}const yE=86,ZT=60,qT=8,JT=1100;function QT(t){return yE+(t-1)*ZT}function wE(t){return yE/2}function kE(t,e){const s=Math.max(300,e-50);return Math.max(300,Math.min(s,Math.round(t)))}const vE=86,tS=60,eS=8,nS=350;function jE(t){return vE+(t-1)*tS}function oS(t){return vE}function qw(t){return jE(t)/2}function _E(t,e){const s=Math.max(150,e-50);return Math.max(150,Math.min(s,Math.round(t)))}function sS(t){return t===1?"שקע יחיד":"שקע כפול"}const rS=25.4,Ay=16,Ly=9,h5=Math.sqrt(Ay*Ay+Ly*Ly),EE={60:12,10:6},iS={60:40,10:25},aS={60:1100,10:1450};function DE(t){const e=t*rS,s=e*Ay/h5,o=e*Ly/h5;return{widthMm:s,heightMm:o}}function Jw(t){const{widthMm:e}=DE(t);return Math.round(e+EE[t]*2)}function Qw(t){const{heightMm:e}=DE(t);return Math.round(e+EE[t]*2)}function lS(t){return iS[t]}function t3(t){return Jw(t)/2}function cS(t){return aS[t]}function FE(t,e,s){const o=Qw(e)/2,r=Math.max(o+80,300),i=Math.max(r,s-o-50);return Math.max(r,Math.min(i,Math.round(t)))}function m5(t){const e=Math.round(Jw(t)/10),s=Math.round(Qw(t)/10);return`${e} ס״מ רוחב · ${s} ס״מ גובה`}function CE(t){const e=t.start.x*rt,s=t.start.y*rt,o=t.end.x*rt,r=t.end.y*rt,i=o-e,a=r-s,l=Math.sqrt(i*i+a*a);if(l<1e-6)return null;const c=Math.atan2(a,i);return{sx:e,sz:s,ex:o,ez:r,wallLen:l,heightMm:t.height,thicknessM:t.thickness*rt,angle:c,fnx:-Math.sin(c),fnz:Math.cos(c)}}function dS(t,e,s,o,r){const i=e*rt,a=s*rt,l=o==="front"?1:-1,c=(t.thicknessM/2+r*rt)*l,d=Math.cos(t.angle),u=Math.sin(t.angle);return{x:t.sx+i*d+t.fnx*c,y:a,z:t.sz+i*u+t.fnz*c}}function uS(t){return t.type==="switch"?{widthMm:86,heightMm:QT(t.gangs),depthMm:qT}:t.type==="socket"?{widthMm:jE(t.outlets),heightMm:oS(t.outlets),depthMm:eS}:t.type==="tv"?{widthMm:Jw(t.inches),heightMm:Qw(t.inches),depthMm:lS(t.inches)}:{widthMm:UT(),heightMm:KT(),depthMm:YT}}function hS(t,e){const s=CE(t);if(!s)return null;const{widthMm:o,heightMm:r,depthMm:i}=uS(e),a=o*rt,l=r*rt,c=i*rt,d=dS(s,e.positionAlongWallMm,e.centerHeightMm,e.wallSide,i/2+1),u=e.wallSide==="front"?-s.angle:-s.angle+Math.PI;return{position:[d.x,d.y,d.z],rotation:[0,u,0],widthM:a,heightM:l,depthM:c}}function mS(t,e){const s=CE(t);if(!s)return null;const o=e==="front"?1:-1;return[s.fnx*o,0,s.fnz*o]}function fS({outwardNormal:t,position:e,rotation:s,onPick:o,children:r}){const i=m.useRef(null),{camera:a}=Vo(),l=m.useMemo(()=>new le(...t).normalize(),[t]),c=m.useMemo(()=>new le,[]),d=m.useMemo(()=>new le,[]);return ka(()=>{const u=i.current;u&&(u.getWorldPosition(d),c.subVectors(a.position,d),u.visible=c.dot(l)>0)}),n.jsx("group",{ref:i,position:e,rotation:s,onClick:o,onContextMenu:o,children:r})}function xS({gangs:t,transform:e}){const s=e.depthM/2+.002;return n.jsx("group",{position:[0,0,s],children:Array.from({length:t}).map((o,r)=>{const i=Math.min(e.widthM/Math.max(t,1),.05),a=(r-(t-1)/2)*i;return n.jsxs("mesh",{position:[a,0,0],children:[n.jsx("boxGeometry",{args:[.012,e.heightM*.34,.0015]}),n.jsx("meshBasicMaterial",{color:"#18181b",side:cr})]},r)})})}function pS({outlets:t,transform:e}){const s=e.depthM/2+.002,o=e.heightM*.09,r=e.heightM*.14,i=t===1?0:e.widthM*.28,a=(l,c)=>n.jsxs("group",{position:[l,0,0],children:[n.jsxs("mesh",{position:[-r/2,0,0],children:[n.jsx("circleGeometry",{args:[o,16]}),n.jsx("meshBasicMaterial",{color:"#18181b",side:cr})]}),n.jsxs("mesh",{position:[r/2,0,0],children:[n.jsx("circleGeometry",{args:[o,16]}),n.jsx("meshBasicMaterial",{color:"#18181b",side:cr})]})]},c);return n.jsx("group",{position:[0,0,s],children:t===1?a(0,"single"):n.jsxs(n.Fragment,{children:[a(-i/2,"left"),a(i/2,"right")]})})}function gS({transform:t,isSelected:e}){const{widthM:s,heightM:o,depthM:r}=t,i=r/2+.006,a=o*.28,l=-o/2+a/2+o*.06,c=o*.12,d=o/2-c/2-o*.05,u=6,h=a/(u+1),x={polygonOffset:!0,polygonOffsetFactor:-2,polygonOffsetUnits:-2,side:cr};return n.jsxs(n.Fragment,{children:[n.jsxs("mesh",{children:[n.jsx("boxGeometry",{args:[s,o,r]}),n.jsx("meshStandardMaterial",{color:"#f7f7f3",roughness:.32,metalness:.04,side:cr}),n.jsx(xo,{color:"#1a1a1a",threshold:20})]}),n.jsxs("mesh",{position:[0,d,i],children:[n.jsx("boxGeometry",{args:[s*.94,c,.008]}),n.jsx("meshStandardMaterial",{color:"#ececea",roughness:.28,metalness:.06,...x})]}),Array.from({length:u}).map((f,p)=>{const b=l-a/2+h*(p+1);return n.jsxs("mesh",{position:[0,b,i+.003],children:[n.jsx("boxGeometry",{args:[s*.9,h*.42,.006]}),n.jsx("meshStandardMaterial",{color:"#b8b8b2",roughness:.5,metalness:.1,...x})]},p)}),n.jsxs("mesh",{position:[s*.36,d,i+.004],children:[n.jsx("boxGeometry",{args:[s*.07,c*.32,.004]}),n.jsx("meshBasicMaterial",{color:"#3a9ad9",side:cr})]}),e&&n.jsx("group",{scale:[1.02,1.02,1.02],children:n.jsxs("mesh",{children:[n.jsx("boxGeometry",{args:[s,o,r]}),n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthWrite:!1}),n.jsx(xo,{color:"#D84B2E",threshold:20})]})})]})}function bS({inches:t,transform:e,isSelected:s}){const{widthM:o,heightM:r,depthM:i}=e,a=i/2+.004,l=t===60?.012:.006,c=o-l*2,d=r-l*2,u=t===10;return n.jsxs(n.Fragment,{children:[n.jsxs("mesh",{children:[n.jsx("boxGeometry",{args:[o,r,i]}),n.jsx("meshStandardMaterial",{color:"#1c1c1c",roughness:.45,metalness:.12,side:cr}),n.jsx(xo,{color:"#111111",threshold:20})]}),n.jsxs("mesh",{position:[0,0,a],children:[n.jsx("boxGeometry",{args:[c,d,.004]}),n.jsx("meshStandardMaterial",{color:"#080808",roughness:.15,metalness:.05,side:cr})]}),n.jsxs("mesh",{position:[0,d*.38,a+.002],children:[n.jsx("boxGeometry",{args:[c*.92,d*.04,.001]}),n.jsx("meshBasicMaterial",{color:"#ffffff",transparent:!0,opacity:.06,side:cr})]}),!u&&n.jsxs("mesh",{position:[0,-r/2-.012,-i*.15],children:[n.jsx("boxGeometry",{args:[o*.18,.024,i*.35]}),n.jsx("meshStandardMaterial",{color:"#2a2a2a",roughness:.6,metalness:.2,side:cr})]}),u&&n.jsxs(n.Fragment,{children:[n.jsxs("mesh",{position:[0,r/2+.01,a+.003],children:[n.jsx("circleGeometry",{args:[.008,16]}),n.jsx("meshStandardMaterial",{color:"#222",roughness:.35,metalness:.4,side:cr})]}),n.jsxs("mesh",{position:[0,r/2+.01,a+.005],children:[n.jsx("circleGeometry",{args:[.004,16]}),n.jsx("meshBasicMaterial",{color:"#1a3a5c",side:cr})]})]}),s&&n.jsx("group",{scale:[1.01,1.01,1.01],children:n.jsxs("mesh",{children:[n.jsx("boxGeometry",{args:[o,r,i]}),n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthWrite:!1}),n.jsx(xo,{color:"#D84B2E",threshold:20})]})})]})}function MS({fixture:t,transform:e,isSelected:s}
181){const o=t.type==="socket"?"#f0f0eb":"#f5f5f0";return n.jsxs(n.Fragment,{children:[n.jsxs("mesh",{children:[n.jsx("boxGeometry",{args:[e.widthM,e.heightM,e.depthM]}),n.jsx("meshStandardMaterial",{color:o,roughness:.45,metalness:0,side:cr}),n.jsx(xo,{color:"#111111",threshold:15})]}),s&&n.jsx("group",{scale:[1.04,1.04,1.04],children:n.jsxs("mesh",{children:[n.jsx("boxGeometry",{args:[e.widthM,e.heightM,e.depthM]}),n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthWrite:!1}),n.jsx(xo,{color:"#D84B2E",threshold:20})]})}),t.type==="switch"&&n.jsx(xS,{gangs:t.gangs,transform:e}),t.type==="socket"&&n.jsx(pS,{outlets:t.outlets,transform:e})]})}function yS(t,e,s){return t.type==="ac"?n.jsx(gS,{transform:e,isSelected:s}):t.type==="tv"?n.jsx(bS,{inches:t.inches,transform:e,isSelected:s}):n.jsx(MS,{fixture:t,transform:e,isSelected:s})}function wS({fixtures:t,walls:e,selectedSwitchId:s,onSwitchClick:o}){const r=m.useMemo(()=>new Map(e.map(i=>[i.id,i])),[e]);return n.jsx("group",{name:"electrical-fixtures",children:t.map(i=>{const a=r.get(i.wallId);if(!a)return null;const l=hS(a,i),c=mS(a,i.wallSide);if(!l||!c)return null;const d=s===i.id,u=h=>{o&&(h.stopPropagation(),o(i.id,{x:h.clientX,y:h.clientY}))};return n.jsx(fS,{outwardNormal:c,position:l.position,rotation:l.rotation,onPick:u,children:yS(i,l,d)},i.id)})})}const NE=90,IE=90,f5=4,kS=1200,bb=[{id:"yellow",hex:"#FFF9C4",label:"צהוב"},{id:"pink",hex:"#F8BBD9",label:"ורוד"},{id:"mint",hex:"#C8E6C9",label:"מנטה"},{id:"blue",hex:"#BBDEFB",label:"תכלת"},{id:"lavender",hex:"#E1BEE7",label:"סגול"},{id:"peach",hex:"#FFCCBC",label:"אפרסק"}];function Ku(t){var e;return((e=bb.find(s=>s.id===t))==null?void 0:e.hex)??"#FFF9C4"}function Mb(){return NE/2}function Wy(t,e){const s=IE/2,o=Math.max(s+80,200),r=Math.max(o,e-s-50);return Math.max(o,Math.min(r,Math.round(t)))}function TE(t){const e=t.start.x*rt,s=t.start.y*rt,o=t.end.x*rt,r=t.end.y*rt,i=o-e,a=r-s,l=Math.sqrt(i*i+a*a);if(l<1e-6)return null;const c=Math.atan2(a,i);return{sx:e,sz:s,ex:o,ez:r,wallLen:l,angle:c,fnx:-Math.sin(c),fnz:Math.cos(c),thicknessM:t.thickness*rt}}function vS(t,e,s,o,r){const i=e*rt,a=s*rt,l=o==="front"?1:-1,c=(t.thicknessM/2+r*rt)*l,d=Math.cos(t.angle),u=Math.sin(t.angle);return{x:t.sx+i*d+t.fnx*c,y:a,z:t.sz+i*u+t.fnz*c}}function jS(t,e){const s=TE(t);if(!s)return null;const o=NE*rt,r=IE*rt,i=f5*rt,a=vS(s,e.positionAlongWallMm,e.centerHeightMm,e.wallSide,f5/2+1),l=e.wallSide==="front"?-s.angle:-s.angle+Math.PI;return{position:[a.x,a.y,a.z],rotation:[0,l,.06],widthM:o,heightM:r,depthM:i}}function _S(t,e){const s=TE(t);if(!s)return null;const o=e==="front"?1:-1;return[s.fnx*o,0,s.fnz*o]}function ES({outwardNormal:t,position:e,rotation:s,onPick:o,children:r}){const i=m.useRef(null),{camera:a}=Vo(),l=m.useMemo(()=>new le(...t).normalize(),[t]),c=m.useMemo(()=>new le,[]),d=m.useMemo(()=>new le,[]);return ka(()=>{const u=i.current;u&&(u.getWorldPosition(d),c.subVectors(a.position,d),u.visible=c.dot(l)>0)}),n.jsx("group",{ref:i,position:e,rotation:s,onClick:o,onContextMenu:o,children:r})}function DS(t,e=.82){const s=Math.round(parseInt(t.slice(1,3),16)*e),o=Math.round(parseInt(t.slice(3,5),16)*e),r=Math.round(parseInt(t.slice(5,7),16)*e);return`#${[s,o,r].map(i=>i.toString(16).padStart(2,"0")).join("")}`}function FS({colorHex:t,widthM:e,heightM:s,depthM:o,isSelected:r}){const i=Math.min(e,s)*.22,a=e/2-i/2,l=s/2-i/2,c=o/2+.001,d=e*.62,u=.002,h=[-e*.04,-e*.04,-e*.04],x=[s*.12,-s*.02,-s*.16];return n.jsxs("group",{children:[n.jsxs("mesh",{children:[n.jsx("boxGeometry",{args:[e,s,o]}),n.jsx("meshStandardMaterial",{color:t,roughness:.92,metalness:0}),r&&n.jsx(xo,{color:"#D85D43",threshold:15})]}),n.jsxs("mesh",{position:[a,l,c],children:[n.jsx("boxGeometry",{args:[i,i,.001]}),n.jsx("meshBasicMaterial",{color:DS(t),side:cr})]}),x.map((f,p)=>n.jsxs("mesh",{position:[h[p],f,c],children:[n.jsx("boxGeometry",{args:[d,u,.001]}),n.jsx("meshBasicMaterial",{color:"#3f3f46",transparent:!0,opacity:.35,side:cr})]},p))]})}function CS({notes:t,walls:e,selectedNoteId:s,onNoteClick:o}){const r=m.useMemo(()=>new Map(e.map(i=>[i.id,i])),[e]);return n.jsx("group",{name:"wall-notes",children:t.map(i=>{const a=r.get(i.wallId);if(!a)return null;const l=jS(a,i),c=_S(a,i.wallSide);if(!l||!c)return null;const d=u=>{o&&(u.stopPropagation(),o(i.id,{x:u.nativeEvent.clientX,y:u.nativeEvent.clientY}))};return n.jsx(ES,{outwardNormal:c,position:l.position,rotation:l.rotation,onPick:d,children:n.jsx(FS,{colorHex:Ku(i.colorId),widthM:l.widthM,heightM:l.heightM,depthM:l.depthM,isSelected:s===i.id})},i.id)})})}const kf=50*rt,yb=.985,e3=.15,n3=2.5;function Zc(t,e,s,o){return t*s+e*o}function x5(t,e,s,o){return t*o-e*s}function SE(t,e){const s=t.x-e.x,o=t.z-e.z;return s*s+o*o}function NS(t){const e=t.start.x*rt,s=t.start.y*rt,o=t.end.x*rt,r=t.end.y*rt,i=o-e,a=r-s,l=Math.hypot(i,a);if(l<1e-6)return null;const c=i/l,d=a/l;return{wall:t,sx:e,sz:s,ex:o,ez:r,len:l,ux:c,uz:d,nx:-d,nz:c,halfT:t.thickness*rt/2}}function PE(t,e){return Zc(e.x-t.sx,e.z-t.sz,t.ux,t.uz)}function IS(t){return{start:{front:0,back:0},end:{front:t.len,back:t.len}}}function AE(t,e){const s=t.get(e.frame.wall.id);s&&(s[e.endpoint]={front:e.baseDist,back:e.baseDist})}function TS(t,e,s,o){const r=x5(e.x,e.z,o.x,o.z);
181if(Math.abs(r)<1e-7)return null;const i=s.x-t.x,a=s.z-t.z,l=x5(i,a,o.x,o.z)/r;return{x:t.x+e.x*l,z:t.z+e.z*l}}function p5(t,e,s){const o=t.get(e.frame.wall.id);if(!o)return;const r=Zc(s.awayX,s.awayZ,e.frame.nx,e.frame.nz);if(Math.abs(r)<e3){AE(t,e);return}const i=r>0?1:-1,a=Math.max(e.frame.halfT,s.frame.halfT)*n3,l={front:e.baseDist,back:e.baseDist};for(const[c,d]of[["front",1],["back",-1]]){const u={x:e.joint.x+e.frame.nx*e.frame.halfT*d,z:e.joint.z+e.frame.nz*e.frame.halfT*d},h=e.localIntoSign*i*d;let x=null;for(const f of[1,-1]){const p={x:s.joint.x+s.frame.nx*s.frame.halfT*f,z:s.joint.z+s.frame.nz*s.frame.halfT*f},b=TS(u,{x:e.frame.ux,z:e.frame.uz},p,{x:s.frame.ux,z:s.frame.uz});if(!b)continue;const M=b.x-e.joint.x,g=b.z-e.joint.z;if(Math.hypot(M,g)>a)continue;const k=Zc(M,g,e.frame.ux,e.frame.uz),j=(k*h>=-1e-4?0:100)+Math.abs(k-h*e.frame.halfT);(!x||j<x.score)&&(x={dist:e.baseDist+k,score:j})}x&&(l[c]=x.dist)}o[e.endpoint]=l}function SS(t,e){return e.some(s=>s!==t&&Zc(t.awayX,t.awayZ,s.awayX,s.awayZ)<-yb)}function PS(t,e){const s=e.filter(i=>i!==t);let o=null,r=-1/0;for(let i=0;i<s.length;i+=1)for(let a=i+1;a<s.length;a+=1){const l=s[i],c=s[a],d=-Zc(l.awayX,l.awayZ,c.awayX,c.awayZ);if(d<yb)continue;const u=Math.abs(Zc(t.awayX,t.awayZ,-l.awayZ,l.awayX)),h=d+u;h>r&&(r=h,o=[l,c])}return o}function AS(t,e,s){const o=t.get(e.frame.wall.id);if(!o)return;const r=s[0],i={x:-r.awayZ,z:r.awayX},a=Zc(e.awayX,e.awayZ,i.x,i.z);if(Math.abs(a)<e3)return;const l=Math.max(s[0].frame.halfT,s[1].frame.halfT),c=l/Math.abs(a),d=Math.min(e.frame.len*.45,Math.max(e.frame.halfT,l)*n3),u=Math.max(0,Math.min(c,d)),h=e.baseDist+e.localIntoSign*u;o[e.endpoint]={front:h,back:h}}function LS(t,e,s){const o=t.get(e.frame.wall.id);if(!o)return;const r=Zc(e.awayX,e.awayZ,s.nx,s.nz);if(Math.abs(r)<e3)return;const i=s.halfT/Math.abs(r),a=Math.min(e.frame.len*.45,Math.max(e.frame.halfT,s.halfT)*n3),l=Math.max(0,Math.min(i,a)),c=e.baseDist+e.localIntoSign*l;o[e.endpoint]={front:c,back:c}}function WS(t){const e=[],s=kf*kf;for(const o of t)for(const r of["start","end"]){const i=r==="start"?{x:o.sx,z:o.sz}:{x:o.ex,z:o.ez};let a=e.find(c=>SE(c.center,i)<=s);a||(a={center:{...i},entries:[]},e.push(a)),a.entries.push({frame:o,endpoint:r,point:i});const l=a.entries.length;a.center={x:(a.center.x*(l-1)+i.x)/l,z:(a.center.z*(l-1)+i.z)/l}}return e}function LE(t,e){return{...t,joint:e,baseDist:PE(t.frame,e),localIntoSign:t.endpoint==="start"?1:-1,awayX:t.endpoint==="start"?t.frame.ux:-t.frame.ux,awayZ:t.endpoint==="start"?t.frame.uz:-t.frame.uz}}function RS(t,e){const s=kf*kf;for(const o of e)for(const r of["start","end"]){const i=r==="start"?{x:o.sx,z:o.sz}:{x:o.ex,z:o.ez};for(const a of e){if(a.wall.id===o.wall.id)continue;const l=PE(a,i);if(l<=kf||l>=a.len-kf)continue;const c={x:a.sx+a.ux*l,z:a.sz+a.uz*l};if(SE(i,c)>s)continue;const d=r==="start"?o.ux:-o.ux,u=r==="start"?o.uz:-o.uz;Math.abs(Zc(d,u,a.ux,a.uz))>yb||LS(t,LE({frame:o,endpoint:r,point:i},c),a)}}}function OS(t,e){const s=t.filter(r=>!(e!=null&&e.has(r.id))).map(NS).filter(r=>!!r),o=new Map;for(const r of s)o.set(r.wall.id,IS(r));for(const r of WS(s)){const i=r.entries.map(a=>LE(a,r.center));for(const a of i)AE(o,a);if(i.length===2){const[a,l]=i;Math.abs(Zc(a.awayX,a.awayZ,l.awayX,l.awayZ))>yb||(p5(o,a,l),p5(o,l,a));continue}if(i.length>=3)for(const a of i){if(SS(a,i))continue;const l=PS(a,i);l&&AS(o,a,l)}}return RS(o,s),o}const WE={shadowStrength:.65,fillLight:.9,lightWarmth:.58,lineStrength:.92,modelEdgesEnabled:!1};function HS({preset:t,compact:e}){return e?"standard":t==="inside"||t==="orbit"||t==="top"?"sketchup":"standard"}function o3(t){return{x:Math.round(t.x*1e3),y:Math.round(t.z*1e3)}}class BS extends m.Component{constructor(){super(...arguments);UM(this,"state",{hasError:!1})}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(s){Ys.warn("[floorplan] texture failed to load",s)}render(){return this.state.hasError?this.props.fallback:this.props.children}}function ml({fallback:t,children:e}){return n.jsx(BS,{fallback:t,children:n.jsx(m.Suspense,{fallback:t,children:e})})}function RE(t,e,s,o=0,r=0){const i=Ya(t),a=m.useMemo(()=>i.clone(),[i]);return m.useEffect(()=>()=>a.dispose(),[a]),m.useLayoutEffect(()=>{a.wrapS=Uc,a.wrapT=Uc,a.repeat.set(e,s),a.offset.set(o,r),a.colorSpace
181=gm,a.needsUpdate=!0},[o,r,e,s,a]),a}const OE=.4,HE=m.createContext(OE);function Wp(){return m.useContext(HE)}function VS({outdoor:t,children:e}){const s=m.useMemo(()=>t?0:OE,[t]);return n.jsx(HE.Provider,{value:s,children:e})}const BE="floorplan.measurementUnit.v1",QM="cm",VE={cm:10,mm:1};function zS(t){return t==="cm"||t==="mm"}function $S(){if(typeof window>"u")return QM;try{const t=window.localStorage.getItem(BE);return zS(t)?t:QM}catch{return QM}}function XS(t){if(!(typeof window>"u"))try{window.localStorage.setItem(BE,t)}catch{}}function Ka(t){return t==="mm"?"מ״מ":"ס״מ"}function YS(t,e){return t/VE[e]}function GS(t,e){return Math.round(t*VE[e])}function De(t,e){if(!Number.isFinite(t))return"";const s=YS(Math.round(t),e);return e==="mm"?String(Math.round(s)):KS(s.toFixed(1))}function $i(t,e){return`${De(t,e)} ${Ka(e)}`}function ni(t,e){const s=zE(t);if(!s||s==="-"||s==="."||s==="-.")return null;const o=Number(s);return Number.isFinite(o)?GS(o,e):null}function US(t){return zE(t)}function zE(t){const e=t.replace(/,/g,"."),s=e.trimStart().startsWith("-")?"-":"",o=e.replace(/[^\d.]/g,""),r=o.split("."),i=r.length<=1?o:`${r[0]}.${r.slice(1).join("")}`;return`${s}${i}`}function KS(t){return t.includes(".")?t.replace(/\.?0+$/,""):t}const ul={wall:"#ffffff",door:"#a0522d",doorPanel:"#e8e0d4",windowFrame:"#e8e8e8",glass:"#b8e0f8",furniture:"#7a8b6e"},g5=ul.wall,ZS=.04,th="#111111",bm=1,Bf="#3B82F6",Vf=3,Rd=.012,qS=.004,b5=1,JS=.26,QS=.65,tP=.36;function pp(t,e){return Math.max(.08,e-t/2)}function M5(t,e){const s=Math.max(.08,t),o=Math.max(s/2+.08,e),r=s/2,i=pp(s,o),a=new $l;return a.moveTo(-r,0),a.lineTo(r,0),a.lineTo(r,i),a.absarc(0,i,r,0,Math.PI,!1),a.lineTo(-r,0),a}function ng(t,e,s=0){const o=Math.max(.08,t),r=Math.max(o/2+.08,e),i=o/2,a=pp(o,r),l=28;return Array.from({length:l+1},(c,d)=>{const u=d/l,h=Math.PI-Math.PI*u;return[Math.cos(h)*i,a+Math.sin(h)*i,s]})}function y5(t,e,s,o){const r=Math.max(.08,t),i=Math.max(.16,e),a=Math.min(Math.max(.08,s),r),l=Math.min(Math.max(a/2+.08,o),i),c=r/2,d=a/2,u=pp(a,l),h=new $l;h.moveTo(-c,0),h.lineTo(c,0),h.lineTo(c,i),h.lineTo(-c,i),h.lineTo(-c,0);const x=new Gd;return x.moveTo(-d,0),x.lineTo(-d,u),x.absarc(0,u,d,Math.PI,0,!0),x.lineTo(d,0),x.lineTo(-d,0),h.holes.push(x),h}function Rp(t,e){const s=e.capabilities.getMaxAnisotropy();t.anisotropy=Math.min(16,s),t.minFilter=V_,t.magFilter=z_,t.generateMipmaps=!0,t.needsUpdate=!0}function s3(t,e=Hf){if(e==="horizontal"){t.rotation=Math.PI/2,t.center.set(.5,.5);return}t.rotation=0,t.center.set(0,0)}function eP(t,e){return`${t}__${e}`}function S1(t,e){let s=!1;for(let o=0,r=e.length-1;o<e.length;r=o++){const i=e[o].x,a=e[o].y,l=e[r].x,c=e[r].y;a>t.y!=c>t.y&&t.x<(l-i)*(t.y-a)/(c-a||1e-9)+i&&(s=!s)}return s}function w5(t){if(t.length<3)return 0;let e=0;for(let s=0,o=t.length-1;s<t.length;o=s++)e+=(t[o].x+t[s].x)*(t[o].y-t[s].y);return e/2}function r3(t){const e=t.start.x*rt,s=t.start.y*rt,o=t.end.x*rt,r=t.end.y*rt,i=o-e,a=r-s,l=Math.sqrt(i*i+a*a);if(l<1e-6)return null;const c=Math.atan2(a,i);return{sx:e,sz:s,ex:o,ez:r,wallLen:l,wallLenMm:l/rt,heightM:t.height*rt,heightMm:t.height,thicknessM:t.thickness*rt,angle:c,fnx:-Math.sin(c),fnz:Math.cos(c)}}function nP(t,e,s,o){const r=s==="front"?1:-1,i=(t.thicknessM/2+o)*r,a=e.x-t.sx-t.fnx*i,l=e.z-t.sz-t.fnz*i,c=Math.cos(t.angle),d=Math.sin(t.angle),u=a*c+l*d,h=e.y;return{u:u/rt,v:h/rt}}function t2(t,e){if(!t)return;if(e.polygonKey&&t[e.polygonKey]!==void 0)return t[e.polygonKey];const s=gb(e.vertices);if(s&&t[s]!==void 0)return t[s];const o=pb(e.wallIds??[]);if(o&&t[o]!==void 0)return t[o]}function $E(t,e){const s=new Set(t),o=new Set(e);let r=0;for(const a of s)o.has(a)&&r++;const i=s.size+o.size-r;return i===0?0:r/i}const XE=.45;function YE(t,e){if(!e.length)return{};const s={},o=Object.keys(t),r=new Set;for(const i of e){const a=la(i),l=pb(i.wallIds??[]);if(a in t&&!r.has(a)){s[a]=t[a],r.add(a);continue}if(l in t&&!r.has(l)){s[a]=t[l],r.add(l);continue}const c=i.wallIds??[];let d=null,u=0;
181for(const h of o){if(r.has(h)||h.startsWith("poly:"))continue;const x=h.split("|").filter(Boolean),f=$E(x,c);f>u&&(u=f,d=h)}d!==null&&u>=XE&&(s[a]=t[d],r.add(d))}return s}function k5(t,e){if(!t||!e.length)return t;for(const i of e)if(la(i)===t)return t;if(t.startsWith("poly:"))return null;for(const i of e)if(pb(i.wallIds??[])===t)return la(i);const s=t.split("|").filter(Boolean);let o=null,r=0;for(const i of e){const a=i.wallIds??[],l=$E(s,a);l>r&&(r=l,o=i)}return r>=XE&&o?la(o):null}const zf=m.createContext(0),og=["#d6d3ce","#e8dcc8","#deb887","#f0ece4","#bfbdb6","#c4956b","#f5e6c8","#a09e99"];function oP(t,e){let s=2166136261;for(let o=0;o<t.length;o++)s^=t.charCodeAt(o),s=Math.imul(s,16777619)>>>0;return e>0?s%e:0}function e2(t){return t===0?{polygonOffset:!1,polygonOffsetFactor:0,polygonOffsetUnits:0}:{polygonOffset:!0,polygonOffsetFactor:-1-t*.8,polygonOffsetUnits:-1-t*.5}}function sP({bounds:t,onPlaceFurniture:e}){const s=mm(t)*20,o=m.useCallback(r=>{r.stopPropagation(),e({x:r.point.x,z:r.point.z})},[e]);return n.jsxs("mesh",{position:[t.centerX,-.002,t.centerZ],rotation:[-Math.PI/2,0,0],onClick:o,children:[n.jsx("planeGeometry",{args:[s,s]}),n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthWrite:!1})]})}function v5(t){return{polygonOffset:!0,polygonOffsetFactor:-2-t*2,polygonOffsetUnits:-2-t*2}}function rP({beam:t,ceilingHeightMm:e,color:s,selected:o,interactive:r,castShadow:i,onClick:a}){const l=HT(t,e);return n.jsxs("mesh",{name:`beam-${t.id}`,position:l.position,rotation:[0,l.rotationY,0],castShadow:i,receiveShadow:i,onClick:r&&a?c=>{c.stopPropagation(),a(t.id)}:void 0,children:[n.jsx("boxGeometry",{args:l.size}),n.jsx("meshStandardMaterial",{color:s,roughness:.88,metalness:0}),n.jsx(xo,{threshold:15,color:o?Bf:th,lineWidth:o?Vf:bm})]})}function j5({level:t,bounds:e,visualStyle:s="standard",outdoorShadowsEnabled:o=!1,sketchupVisualSettings:r=WE,onVisualStyleStatsChange:i,materials:a,customModelUrls:l,customModelMaterialSlots:c,floorTextureUrl:d,roomFloorOverrides:u,roomFloorRegions:h,selectedRegionId:x,onRegionClick:f,onRegionDoubleClick:p,onRemainderClick:b,onRegionPolygonChange:M,onFloorTileOriginChange:g,selectedRoomSig:w,onRoomFloorClick:k,onRoomFloorDoubleClick:_,tileSizeM:j,grout:v,wallTextures:C,selectedWallId:N,selectedBeamId:P,onBeamClick:L,selectedWallSide:A,wallFaceRegions:W,selectedWallRegionId:S,onWallRegionClick:B,onWallRemainderClick:R,onWallRegionPolygonChange:z,wallSelectMode:X,onWallClick:ft,onWallContextMenu:tt,hiddenWallIds:G,onWallDoubleClick:Y,showWallDimensions:J=!1,measurementUnit:Mt="cm",floorSelected:Rt,onFloorClick:it,onRoomFloorContextMenu:st,openingPlaceMode:ct,onWallPlaceClick:pt,wallElectricalFixtures:xt=[],selectedSwitchId:_t=null,onSwitchClick:Ft,electricalPlaceMode:Vt,onWallElectricalPlace:vt,wallNotes:Ht=[],selectedNoteId:Tt=null,onNoteClick:Zt,notePlaceMode:At,onWallNotePlace:ut,onOpeningClick:kt,onOpeningContextMenu:Et,selectedOpeningId:ht,selectedOpeningGroupId:gt,selectedFurnitureIds:Pt,furnitureRotateModeId:U,onFurnitureClick:mt,selectedSmartGlbPart:Nt,smartGlbEditFurnitureId:Lt,onSmartGlbPartSelect:oe,onFurnitureContextMenu:he,furniturePlaceMode:pe,onFloorFurniturePlace:Ge,onFurnitureDeselectClick:Qt,templatePlaceMode:te,onFloorTemplatePlace:Be,onFurnitureMove:wt,onFurnitureGroupMove:ve,onFurnitureRotate:Ne,onFurnitureDuplicate:Le,onFurnitureFlip:is,onFurnitureDelete:Fe,onFurnitureResize:bn,interactionDisabled:Ve,interactionMode:en="edit",furnitureSelectionEnabled:on,furnitureTransformEnabled:Qs,furnitureSelectOnDoubleClick:sn,showCeiling:vn,roomCeilingOverrides:Ot,selectedCeilingRoomSig:so,onCeilingClick:Ue,nightStrength:hs=0,simulateOpenings:Qn=!1,openOpeningIds:Lr,levelElevationM:bi=0,collisionGroupName:Ps="walls"}){const In=en==="activate-only",Rn=en==="none",fe=Ve||Rn,Gs=s==="sketchup",zo=Gs||o,js=Gs&&r.modelEdgesEnabled&&r.lineStrength>.01,co=!Rn&&!!ct,ze=!Rn&&!!Vt,Un=!Rn&&!!At,uo=OT(t),[dn,$o]=m.useState(null),Te=m.useRef(null);m.useEffect(()=>(J||(Te.current!==null&&window.clearTimeout(Te.current),$o(null),document.body.style.cursor=""),()=>{Te.current!==null&&window.clearTimeout(Te.current),document.body.style.cursor=""}),[J]);const po=fe&&Pt.size>0&&Qt,ho=te?Be:pe?Ge:po?ne=>Qt():void 0,go=!!ho,Kl=!!(te||pe),da=fe&&!Rn&&Pt.size>0&&Qt?(ne,Re,Dn)=>Qt():void 0,As=m.useMemo(()=>{const ne=new Map;for(const Re of a)ne.set(Re.id,Re.color);return ne},[a]),ua=m.useMemo(()=>OS(t.walls,G),[t.walls,G]),Gi=m.useMemo(()=>t.walls.filter(ne=>!(G!=null&&G.has(ne.id))),[t.walls,G]),On=m.useMemo(()=>{const ne=new Map;for(const Re of t.walls)ne.set(Re.id,Re);return ne},[t.walls]),to=m.useMemo(()=>{const ne=new Map;for(const Re of t.walls){const Dn=r3(Re);Dn&&ne.set(Re.id,Dn)}return ne},[t.walls]),Wt=m.useMemo(()=>{const ne=new Map;for(const Re of t.walls)ne.set(Re.id,[]);for(const Re of t.openings){const Dn=ne.get(Re.wallId);Dn?Dn.push(Re):ne.set(Re.wallId,[Re])}return ne},[t.walls,t.openings]),qe=m.useMemo(()=>[...t.rooms].filter(ne=>ne.vertices&&ne.vertices.length>=3).sort((ne,Re)=>(Re.area??0)-(ne.area??0)),[t.rooms]),Se=m.useMemo(()=>{const ne=new Map;for(const Re of t.rooms){const Dn=Re.wallIds??[],ge=t.walls.filter(ie=>Dn.includes(ie.id));ne.set(Re.id,{ceilingHeight:Math.max(...ge.map(ie=>ie.height*rt)),avgThicknessM:ge.length>0?ge.reduce((ie,Ze)=>ie+Ze.thickness*rt,0)/ge.length:.1})}return ne},[t.rooms,t.walls]),jn=m.useRef({}),je=m.useCallback((ne,Re)=>{jn.current={...jn.current,[ne]:Re};const Dn=Object.values(jn.current).reduce((ge,ie)=>ge+ie,0);i==null||i({edgeOverlayCount:Dn})},[i]);return m.useEffect(()=>{Gs||(jn.current={},i==null||i({edgeOverlayCount:0}))},[i,Gs]),n.jsx(zf.Provider,{value:bi,children:n.jsxs("group",{children:[Kl&&go&&!fe&&ho?n.jsx(sP,{bounds:e,onPlaceFurniture:ho}):null,qe.map((ne,Re,Dn)=>{const ge=la(ne),ie=t2(u,ne),Ze=(ie==null?void 0:ie.textureUrl)??d,as=oP(ne.id,og.length),Pe=(ie==null?void 0:ie.color)??og[as],Ao=ie&&(ie.tileWidthCm||ie.tileHeightCm)?[(ie.tileWidthCm??100)/100,(ie.tileHeightCm??100)/100]:j??[1,1],Lo=ie&&(ie.groutWidthMm!==void 0||ie.groutColor)?{widthMm:ie.groutWidthMm??5,color:ie.groutColor??"#c8c4bc"}:v,Gt=w===ge,Co=fe&&!In||go?void 0:()=>{k?k(ge):it&&it({x:0,y:0})},Xo=fe&&!In||go||!_?void 0:()=>_(ge),pn=(h==null?void 0:h[ge])??[],Kn=pn.length>0,tr=ne.vertices,ro=ne.holes;if(!Kn)return n.jsxs("group",{children:[n.jsx(n2,{vertices:tr,holes:ro,color:Ze&&!Ze.startsWith("#")?"#ffffff"
181:Ze||Pe,textureUrl:Ze,tileSizeM:Ao,tileOrigin:{xMm:(ie==null?void 0:ie.tileOriginXMm)??0,yMm:(ie==null?void 0:ie.tileOriginYMm)??0},grout:Lo,isSelected:!fe&&Gt,onClick:Co?()=>Co():void 0,onDoubleClick:Xo?()=>Xo():void 0,onContextMenu:!Rn&&st?(Qe,Go)=>st(ge,Qe,Go):void 0,onPlaceFurniture:ho,stackIndex:Re,floorDrawOrderProps:e2(Re),sketchupLookEnabled:zo}),!fe&&Gt&&g&&!go&&n.jsx(r2,{polygon:tr,tileOrigin:{xMm:(ie==null?void 0:ie.tileOriginXMm)??0,yMm:(ie==null?void 0:ie.tileOriginYMm)??0},tileSizeM:Ao,stackIndex:Re,onCommit:Qe=>g(ge,null,Qe)})]},ge);const ls=Math.abs(w5(tr)),Qo=pn.reduce((Qe,Go)=>Qe+Math.abs(w5(Go.polygon)),0),ms=ls>0&&Qo>=ls*.995,Yo=[...ro??[],...pn.map(Qe=>Qe.polygon)];return n.jsxs("group",{children:[!ms&&n.jsx(n2,{vertices:tr,holes:Yo,color:ie!=null&&ie.textureUrl&&!ie.textureUrl.startsWith("#")?"#ffffff":(ie==null?void 0:ie.textureUrl)??(ie==null?void 0:ie.color)??"#eceae4",textureUrl:ie==null?void 0:ie.textureUrl,tileSizeM:ie&&(ie.tileWidthCm||ie.tileHeightCm)?Ao:[1,1],tileOrigin:{xMm:(ie==null?void 0:ie.tileOriginXMm)??0,yMm:(ie==null?void 0:ie.tileOriginYMm)??0},grout:ie?Lo:void 0,isSelected:!fe&&Gt&&x==null,onClick:(!fe||In)&&!go&&b?()=>b(ge):void 0,onContextMenu:!Rn&&st?(Qe,Go)=>st(ge,Qe,Go,null):void 0,onPlaceFurniture:ho,stackIndex:Re,floorDrawOrderProps:e2(Re),sketchupLookEnabled:zo},`remainder-${ge}`),!ms&&!fe&&Gt&&x==null&&g&&!go&&n.jsx(r2,{polygon:tr,tileOrigin:{xMm:(ie==null?void 0:ie.tileOriginXMm)??0,yMm:(ie==null?void 0:ie.tileOriginYMm)??0},tileSizeM:ie&&(ie.tileWidthCm||ie.tileHeightCm)?Ao:j??[1,1],stackIndex:Re,onCommit:Qe=>g(ge,null,Qe)}),pn.map((Qe,Go)=>{const er=Qe.textureUrl,Vn=Qe.color??og[(as+Go+1)%og.length],dr=Qe.tileWidthCm||Qe.tileHeightCm?[(Qe.tileWidthCm??100)/100,(Qe.tileHeightCm??100)/100]:[1,1],Ii=Qe.groutWidthMm!==void 0||Qe.groutColor?{widthMm:Qe.groutWidthMm??5,color:Qe.groutColor??"#c8c4bc"}:void 0,fs=x===Qe.id,Uo=Gt&&!x&&pn.length===1,Hn=fs||Uo,ur=Dn.length*2+Re*10+Go+1;return n.jsxs("group",{children:[n.jsx(n2,{vertices:Qe.polygon,color:er&&!er.startsWith("#")?"#ffffff":er||Vn,textureUrl:er,tileSizeM:dr,tileOrigin:{xMm:Qe.tileOriginXMm??0,yMm:Qe.tileOriginYMm??0},grout:Ii,isSelected:!fe&&fs,onClick:(!fe||In)&&!go&&f?()=>f(ge,Qe.id):void 0,onDoubleClick:(!fe||In)&&!go&&p?()=>p(ge,Qe.id):void 0,onContextMenu:!Rn&&st?(oi,Je)=>st(ge,oi,Je,Qe.id):void 0,onPlaceFurniture:ho,stackIndex:ur,floorDrawOrderProps:e2(ur),sketchupLookEnabled:zo}),!fe&&!go&&Hn&&M&&n.jsx(_P,{polygon:Qe.polygon,roomPolygon:tr,onCommit:oi=>M(ge,Qe.id,oi)}),!fe&&!go&&Hn&&g&&n.jsx(r2,{polygon:Qe.polygon,tileOrigin:{xMm:Qe.tileOriginXMm??0,yMm:Qe.tileOriginYMm??0},tileSizeM:dr,stackIndex:ur,onCommit:oi=>g(ge,Qe.id,oi)})]},Qe.id)})]},`regions-${ge}`)}),hs>.001&&n.jsx(iP,{level:t,bounds:e,intensityScale:hs}),vn&&t.rooms.map(ne=>{var pn;if(!ne.vertices||ne.vertices.length<3)return null;const Re=la(ne),Dn=((pn=Se.get(ne.id))==null?void 0:pn.ceilingHeight)??-1/0,ge=t2(Ot,ne),ie=(ge==null?void 0:ge.color)??g5,Ze=ge==null?void 0:ge.textureUrl,as=ge&&(ge.tileWidthCm||ge.tileHeightCm)?[(ge.tileWidthCm??100)/100,(ge.tileHeightCm??100)/100]:[1,1],Pe=ge&&(ge.groutWidthMm!==void 0||ge.groutColor)?{widthMm:ge.groutWidthMm??5,color:ge.groutColor??"#c8c4bc"}:void 0,Ao=ne.vertices,Lo=(ge==null?void 0:ge.ceilingStyle)??"flat",Gt=(ge==null?void 0:ge.coveWidth)??.3,Co=(ge==null?void 0:ge.coveDepth)??.1,Xo=(ge==null?void 0:ge.gapWidth)??.02;return n.jsx("group",{children:Lo==="step"?n.jsx(cP,{vertices:Ao,wallHeight:Dn,coveWidth:Gt,coveDepth:Co,color:Ze&&!Ze.startsWith("#")?"#ffffff":ie,textureUrl:Ze,tileSizeM:as,grout:Pe,isSelected:so===Re,onClick:Ue?()=>Ue(Re):void 0}):n.jsx(n.Fragment,{children:(()=>{var ro;const Kn=((ro=Se.get(ne.id))==null?void 0:ro.avgThicknessM)??.1,tr=Lo==="gap"?Kn/2+Xo:0;return n.jsxs(n.Fragment,{children:[n.jsx(aP,{vertices:Ao,holes:ne.holes,height:Dn,inset:tr,color:Ze&&!Ze.startsWith("#")?"#ffffff":ie,textureUrl:Ze,tileSizeM:as,grout:Pe,isSelected:so===Re,onClick:Ue?()=>Ue(Re):void 0}),Lo==="gap"&&n.jsx(lP,{vertices:Ao,height:Dn,innerInset:Kn/2+Xo,outerInset:Kn/2})]})})()})},`ceiling-${Re}`)}),n.jsx("group",{name:`beams-${t.id}`,children:t.beams.map(ne=>{const Re={x:(ne.start.x+ne.end.x)/2,y:(ne.start.y+ne.end.y)/2},Dn=t.rooms.find(Ze=>!!Ze.vertices&&Ze.vertices.length>=3&&S1(Re,Ze.vertices)),ge=Dn?t2(Ot,Dn):void 0,ie=(ge==null?void 0:ge.color)??g5;return n.jsx(rP,{beam:ne,ceilingHeightMm:uo,color:ie,selected:!Rn&&P===ne.id,interactive:!Rn,castShadow:zo,onClick:L},ne.id)})}),n.jsx("group",{name:Ps,children:t.walls.map(ne=>{if(G!=null&&G.has(ne.id))return null;const Re=Wt.get(ne.id)??[],Dn=As.get(ne.materialId??"")??ul.wall,ge=C==null?void 0:C[ne.id];return n.jsx(gP,{wall:ne,openings:Re,color:Dn,wallConfig:ge,isSelected:!Rn&&(N===ne.id||X&&!N&&Ve),onWallClick:fe&&!In?da:ft,onWallContextMenu:Rn?void 0:tt,onWallDoubleClick:Rn?void 0:Y,onWallHover:J?(ie,Ze)=>{Te.current!==null&&(window.clearTimeout(Te.current),Te.current=null),$o(as=>(as==null?void 0:as.wallId)===ie&&as.side===Ze?as:{wallId:ie,side:Ze})}:void 0,onWallHoverEnd:J?ie=>{Te.current!==null&&window.clearTimeout(Te.current),Te.current=window.setTimeout(()=>{Te.current=null,$o(Ze=>(Ze==null?void 0:Ze.wallId)===ie?null:Ze)},35)}:void 0,openingPlaceMode:co,onWallPlaceClick:co?pt:void 0,electricalPlaceMode:ze,onWallElectricalPlace:ze?vt:void 0,notePlaceMode:Un,onWallNotePlace:Un?ut:void 0,joinCaps:ua.get(ne.id),sketchupLookEnabled:zo},ne.id)})}),J&&dn&&(()=>{const ne=On.get(dn.wallId);return!ne||G!=null&&G.has(ne.id)?null:n.jsx(xP,{wall:ne,side:dn.side,measurementUnit:Mt})})(),(xt.length>0||Ft)&&n.jsx(wS,{fixtures:xt,walls:Gi,selectedSwitchId:_t,onSwitchClick:Rn?void 0:Ft}),(Ht.length>0||Zt)&&n.jsx(CS,{notes:Ht,walls:Gi,selectedNoteId:Tt,onNoteClick:Rn?void 0:Zt}),W&&n.jsx("group",{name:"wall-regions",children:Gi.flatMap(ne=>{const Re=to.get(ne.id);return Re?["front","back"].map(ge=>{const ie=W[eP(ne.id,ge)];return!ie||ie.length===0?null:n.jsx(EP,{wallId:ne.id,side:ge,frame:Re,regions:ie,selectedWallRegionId:N===ne.id&&A===ge?S??null:null,onRegionClick:B,onRemainderClick:R,onRegionPolygonChange:z},`${ne.id}-${ge}`)}):[]})}),t.openings.map(ne=>{const Re=On.get(ne.wallId);if(!Re||G!=null&&G.has(Re.id))return null;const Dn=As.get(Re.materialId??"")??ul.wall;return n.jsx(MP,{opening:ne,wall:Re,wallColor:Dn,onClick:(!fe||co||In)&&kt?()=>kt(ne.id):void 0,onContextMenu:!Rn&&Et?(ge,ie,Ze)=>
181Et(ne.id,ge,ie,Ze):void 0,isSelected:(!fe||co)&&(ht===ne.id||!!gt&&ne.cornerGroupId===gt),sketchupLookEnabled:zo,targetOpen:Qn||((Lr==null?void 0:Lr.has(ne.id))??!1)},ne.id)}),t.furniture.map(ne=>{const Re=!Rn&&(on??!fe),Dn=!Rn&&!(ne.type.startsWith("blender_")&&Lt===ne.id)&&(Qs??!fe),ge=Re&&((Pt==null?void 0:Pt.has(ne.id))??!1),ie=((Pt==null?void 0:Pt.size)??0)>1,Ze=c==null?void 0:c[ne.type],as=Lt===ne.id&&!!(Ze!=null&&Ze.length),Pe=Re&&as&&!!(Ze!=null&&Ze.length)&&!!oe,Ao=(Nt==null?void 0:Nt.furnitureId)===ne.id&&(Ze!=null&&Ze.some(Lo=>Lo.id===Nt.slotId))?Nt.slotId:null;return n.jsx(wP,{furn:ne,customModelUrls:l,materialSlots:Ze,isSelected:ge,isMulti:ie,rotateDialActive:ge&&U===ne.id,selectedSmartSlotId:Ao,selectOnDoubleClick:!!sn,smartPartPickingActive:as,canSelect:Re,canTransform:Dn,canPickSmartPart:Pe,onFurnitureClick:mt,onSmartGlbPartSelect:oe,onFurnitureContextMenu:he,onFurnitureMove:wt,onFurnitureGroupMove:ve,onFurnitureRotate:Ne,onFurnitureDuplicate:Le,onFurnitureFlip:is,onFurnitureDelete:Fe,onFurnitureResize:bn,sketchupLookEnabled:zo,sketchupModelEdgesEnabled:js,sketchupEdgeOpacity:r.lineStrength,onSketchupEdgeCountChange:je},ne.id)})]})})}function iP({level:t,bounds:e,intensityScale:s}){const o=Math.min(1,Math.max(0,s)),r=m.useMemo(()=>{const i=[],a=(t.rooms??[]).filter(l=>l.vertices&&l.vertices.length>=3);for(const l of a){const c=l.vertices;let d=0,u=0,h=1/0,x=-1/0,f=1/0,p=-1/0;for(const _ of c)d+=_.x,u+=_.y,_.x<h&&(h=_.x),_.x>x&&(x=_.x),_.y<f&&(f=_.y),_.y>p&&(p=_.y);const b=d/c.length*rt,M=u/c.length*rt,g=Math.max((x-h)*rt,(p-f)*rt,1),w=t.walls.filter(_=>{var j;return(j=l.wallIds)==null?void 0:j.includes(_.id)}),k=w.length?Math.max(...w.map(_=>_.height*rt)):2.5;i.push({key:la(l),pos:[b,Math.max(k-.15,.5),M],intensity:Math.min(Math.max(Math.pow(g,1.1)*1.8,6),36),distance:g*3.2})}if(i.length===0&&t.walls.length>0){const l=Math.max(e.span,3),c=Math.max(...t.walls.map(d=>d.height*rt),2.5);i.push({key:"night-fallback",pos:[e.centerX,Math.max(c-.15,.5),e.centerZ],intensity:Math.min(Math.max(Math.pow(l,1.1)*1.8,8),48),distance:l*3.2})}return i},[t,e]);return n.jsx(n.Fragment,{children:r.map(i=>n.jsx("pointLight",{position:i.pos,color:"#fff0e6",intensity:i.intensity*o,distance:i.distance,decay:1.1},`night-${i.key}`))})}function n2({vertices:t,holes:e,color:s,textureUrl:o,tileSizeM:r,tileOrigin:i,grout:a,isSelected:l,onClick:c,onDoubleClick:d,onContextMenu:u,onPlaceFurniture:h,stackIndex:x=0,floorDrawOrderProps:f,sketchupLookEnabled:p=!1}){const b=o&&!o.startsWith("#"),M=m.useMemo(()=>{const v=new $l;v.moveTo(t[0].x*rt,-t[0].y*rt);for(let C=1;C<t.length;C++)v.lineTo(t[C].x*rt,-t[C].y*rt);if(v.closePath(),e&&e.length>0)for(const C of e){if(!C||C.length<3)continue;const N=new Gd;N.moveTo(C[0].x*rt,-C[0].y*rt);for(let P=1;P<C.length;P++)N.lineTo(C[P].x*rt,-C[P].y*rt);N.closePath(),v.holes.push(N)}return new dm(v)},[t,e]),g=r||[1,1],w=m.useCallback(v=>{if(!(!c&&!h)){if(v.stopPropagation(),h){h({x:v.point.x,z:v.point.z});return}c&&c({x:v.clientX,y:v.clientY})}},[c,h]),k=m.useCallback(v=>{!d||h||(v.stopPropagation(),d({x:v.clientX,y:v.clientY}))},[d,h]),_=m.useCallback(v=>{var N,P;if(!u)return;v.stopPropagation(),(P=(N=v.nativeEvent).preventDefault)==null||P.call(N);const C=o3(v.point);u({xMm:C.x,yMm:C.y},{x:v.nativeEvent.clientX,y:v.nativeEvent.clientY})},[u]),j=x*1e-4;return n.jsxs("mesh",{rotation:[-Math.PI/2,0,0],position:[0,j,0],renderOrder:x,onClick:c||h?w:void 0,onDoubleClick:d&&!h?k:void 0,onContextMenu:u?_:void 0,receiveShadow:p,children:[n.jsx("primitive",{object:M,attach:"geometry"}),b?n.jsx(ml,{fallback:n.jsx("meshStandardMaterial",{color:s,roughness:.8,metalness:.02,side:kn,...f??{}}),children:n.jsx(A1,{url:o,tileSizeM:g,tileOrigin:i,grout:a,doubleSide:!0,depthSolve:f})}):n.jsx("meshStandardMaterial",{color:s,roughness:.8,metalness:.02,side:kn,...f??{}}),l&&n.jsx(xo,{scale:1,threshold:15,color:"#3B82F6",lineWidth:3})]})}function aP({vertices:t,holes:e,height:s,inset:o=0,color:r,textureUrl:i,tileSizeM:a,grout:l,isSelected:c,onClick:d}){const u=m.useMemo(()=>{const f=t.map(M=>({x:M.x*rt,y:M.y*rt})),p=o>0?P1(f,o):f,b=new $l;b.moveTo(p[0].x,-p[0].y);for(let M=1;M<p.length;M++)b.lineTo(p[M].x,-p[M].y);if(b.closePath(),e&&e.length>0)for(const M of e){if(!M||M.length<3)continue;const g=new Gd;g.moveTo(M[0].x*rt,-M[0].y*rt);for(let w=1;w<M.length;w++)g.lineTo(M[w].x*rt,-M[w].y*rt);g.closePath(),b.holes.push(g)}return new dm(b)},[t,e,o]),h=i&&!i.startsWith("#"),x=a||[1,1];return n.jsxs("mesh",{rotation:[-Math.PI/2,0,0],position:[0,s,0],onClick:d?f=>{f.stopPropagation(),d()}:void 0,children:[n.jsx("primitive",{object:u,attach:"geometry"}),h?n.jsx(ml,{fallback:n.jsx("meshStandardMaterial",{color:r,roughness:.9,metalness:0,side:kn}),children:n.jsx(A1,{url:i,tileSizeM:x,grout:l,doubleSide:!0})}):n.jsx("meshStandardMaterial",{color:r,roughness:.9,metalness:0,side:kn}),c&&n.jsx(xo,{scale:1,threshold:15,color:"#3B82F6",lineWidth:3})]})}function lP({vertices:t,height:e,innerInset:s,outerInset:o}){const r=m.useMemo(()=>{const i=t.map(u=>({x:u.x*rt,y:u.y*rt})),a=P1(i,o),l=P1(i,s),c=new $l;c.moveTo(a[0].x,-a[0].y);for(let u=1;u<a.length;u++)c.lineTo(a[u].x,-a[u].y);c.closePath();const d=new Gd;d.moveTo(l[0].x,-l[0].y);for(let u=1;u<l.length;u++)d.lineTo(l[u].x,-l[u].y);return d.closePath(),c.holes=[d],new dm(c)},[t,s,o]);return n.jsxs("mesh",{rotation:[-Math.PI/2,0,0],position:[0,e,0],children:[n.jsx("primitive",{object:r,attach:"geometry"}),n.jsx("meshBasicMaterial",{color:"#000000",side:Sp})]})}function P1(t,e){const s=t.length;if(s<3)return t;let o=0;for(let a=0;a<s;a++){const l=t[a],c=t[(a+1)%s];o+=l.x*c.y-c.x*l.y}const r=o>0,i=[];for(let a=0;a<s;a++){const l=t[(a-1+s)%s],c=t[a],d=t[(a+1)%s],u=c.x-l.x,h=c.y-l.y,x=d.x-c.x,f=d.y-c.y,p=Math.hypot(u,h)||1,b=Math.hypot(x,f)||1,M=(r?-h:h)/p,g=(r?u:-u)/p,w=(r?-f:f)/b,k=(r?x:-x)/b,_=M+w,j=g+k,v=
181Math.hypot(_,j)||1,C=_/v,N=j/v,P=M*C+g*N,L=e/Math.max(.2,P);i.push({x:c.x+C*L,y:c.y+N*L})}return i}function cP({vertices:t,wallHeight:e,coveWidth:s,coveDepth:o,color:r,textureUrl:i,tileSizeM:a,grout:l,isSelected:c,onClick:d}){const u=m.useMemo(()=>t.map(w=>({x:w.x*rt,y:w.y*rt})),[t]),h=m.useMemo(()=>P1(u,s),[u,s]),x=m.useMemo(()=>{const w=new $l;w.moveTo(u[0].x,-u[0].y);for(let _=1;_<u.length;_++)w.lineTo(u[_].x,-u[_].y);w.closePath();const k=new Gd;k.moveTo(h[0].x,-h[0].y);for(let _=1;_<h.length;_++)k.lineTo(h[_].x,-h[_].y);return k.closePath(),w.holes=[k],new dm(w)},[u,h]),f=m.useMemo(()=>{const w=new $l;w.moveTo(h[0].x,-h[0].y);for(let k=1;k<h.length;k++)w.lineTo(h[k].x,-h[k].y);return w.closePath(),new dm(w)},[h]),p=m.useMemo(()=>{const w=[],k=[],_=[],j=h.length;for(let C=0;C<j;C++){const N=h[C],P=h[(C+1)%j],L=N.x,A=N.y,W=P.x,S=P.y,B=W-L,R=S-A,z=Math.hypot(B,R)||1,X=R/z,ft=-B/z,tt=e,G=e+o;w.push(L,tt,A,W,tt,S,W,G,S),k.push(X,0,ft,X,0,ft,X,0,ft),_.push(0,0,1,0,1,1),w.push(L,tt,A,W,G,S,L,G,A),k.push(X,0,ft,X,0,ft,X,0,ft),_.push(0,0,1,1,0,1)}const v=new Ua;return v.setAttribute("position",new Ur(w,3)),v.setAttribute("normal",new Ur(k,3)),v.setAttribute("uv",new Ur(_,2)),v},[h,e,o]),b=i&&!i.startsWith("#"),M=a||[1,1],g=d?w=>{w.stopPropagation(),d()}:void 0;return n.jsxs("group",{children:[n.jsxs("mesh",{geometry:x,rotation:[-Math.PI/2,0,0],position:[0,e,0],onClick:g,children:[b?n.jsx(ml,{fallback:n.jsx("meshStandardMaterial",{color:r,roughness:.9,metalness:0,side:kn}),children:n.jsx(A1,{url:i,tileSizeM:M,grout:l,doubleSide:!0})}):n.jsx("meshStandardMaterial",{color:r,roughness:.9,metalness:0,side:kn}),c&&n.jsx(xo,{scale:1,threshold:15,color:"#3B82F6",lineWidth:3})]}),n.jsx("mesh",{geometry:f,rotation:[-Math.PI/2,0,0],position:[0,e+o,0],onClick:g,children:b?n.jsx(ml,{fallback:n.jsx("meshStandardMaterial",{color:r,roughness:.9,metalness:0,side:kn}),children:n.jsx(A1,{url:i,tileSizeM:M,grout:l,doubleSide:!0})}):n.jsx("meshStandardMaterial",{color:r,roughness:.9,metalness:0,side:kn})}),n.jsx("mesh",{geometry:p,children:n.jsx("meshStandardMaterial",{color:r,roughness:.95,metalness:0,side:kn})})]})}function A1({url:t,tileSizeM:e,tileOrigin:s,grout:o,doubleSide:r,depthSolve:i}){const{gl:a}=Vo(),l=RE(t,1/e[0],1/e[1],-(((s==null?void 0:s.xMm)??0)*rt)/e[0],((s==null?void 0:s.yMm)??0)*rt/e[1]);if(m.useLayoutEffect(()=>{Rp(l,a)},[l,a]),o&&o.widthMm>0){const c=o.widthMm/(e[0]*1e3),d=o.widthMm/(e[1]*1e3);return n.jsx(UE,{texture:l,groutFraction:[c,d],groutColor:o.color,doubleSide:r,depthSolve:i})}return n.jsx("meshStandardMaterial",{map:l,roughness:.8,metalness:.02,side:r?kn:cr,...i??{}})}const GE=`
182#ifdef USE_MAP
183  vec4 sampledDiffuseColor = texture2D(map, vMapUv);
184  vec2 tilePos = fract(vMapUv);
185  vec2 gw = u_groutWidth;
186  float aa = max(max(fwidth(vMapUv.x), fwidth(vMapUv.y)), 1e-5);
187  float insX = smoothstep(gw.x, gw.x + aa, tilePos.x) * (1.0 - smoothstep(1.0 - gw.x - aa, 1.0 - gw.x, tilePos.x));
188  float insY = smoothstep(gw.y, gw.y + aa, tilePos.y) * (1.0 - smoothstep(1.0 - gw.y - aa, 1.0 - gw.y, tilePos.y));
189  float insideTile = insX * insY;
190  vec3 tileRgb = diffuseColor.rgb * sampledDiffuseColor.rgb;
191  float tileA = diffuseColor.a * sampledDiffuseColor.a;
192  diffuseColor.rgb = mix(u_groutColor, tileRgb, insideTile);
193  diffuseColor.a = mix(1.0, tileA, insideTile);
194#endif
195`;function UE({texture:t,groutFraction:e,groutColor:s,doubleSide:o,depthSolve:r}){const{gl:i}=Vo();m.useLayoutEffect(()=>{Rp(t,i)},[t,i]);const a=m.useMemo(()=>new Do(s),[s]),l=m.useMemo(()=>new Po(e[0],e[1]),[e]),c=d=>{d.uniforms.u_groutWidth={value:l},d.uniforms.u_groutColor={value:a},d.fragmentShader=`uniform vec2 u_groutWidth;
196uniform vec3 u_groutColor;
197`+d.fragmentShader,d.fragmentShader=d.fragmentShader.replace("#include <map_fragment>",GE)};return n.jsx("meshStandardMaterial",{map:t,roughness:.8,metalness:.02,onBeforeCompile:c,side:o?kn:cr,...r??{}},`grout-${e[0]}-${e[1]}-${s}`)}function Od(t,e,s,o,r,i,a=Hf){const l=ei(a),c=Xw(o,l),d=t.clone();d.needsUpdate=!0,d.wrapS=Uc,d.wrapT=Uc,d.repeat.set(e/c[0],s/c[1]),s3(d,l),d.colorSpace=gm,i&&Rp(d,i);const u=new Vu({map:d,roughness:.6,metalness:.02});if(r&&r.widthMm>0){const h=r.widthMm/(c[0]*1e3),x=r.widthMm/(c[1]*1e3),f=new Po(h,x),p=new Do(r.color);u.onBeforeCompile=b=>{b.uniforms.u_groutWidth={value:f},b.uniforms.u_groutColor={value:p},b.fragmentShader=`uniform vec2 u_groutWidth;
198uniform vec3 u_groutColor;
199`+b.fragmentShader,b.fragmentShader=b.fragmentShader.replace("#include <map_fragment>",GE)}}return u}function KE({segW:t,segH:e,wallConfig:s,baseColor:o}){var p,b,M;
199const r=(p=s.front)==null?void 0:p.url,i=(b=s.back)==null?void 0:b.url,a=(M=s.edge)==null?void 0:M.url,l="/textures/floors/tiles-white.jpg",c=Ya(r||l),d=Ya(i||r||l),u=Ya(a||l),{gl:h}=Vo(),x=Wp(),f=m.useMemo(()=>{const g=s.frontColor||o,w=s.backColor||g,k=s.edgeColor||g;let _;a&&s.edge?_=Od(u,t,e,s.edge.tileSizeM,s.edge.grout,h,s.edge.orientation):_=new Vu({color:k,roughness:.4,emissive:k,emissiveIntensity:x});let j;r&&s.front?j=Od(c,t,e,s.front.tileSizeM,s.front.grout,h,s.front.orientation):j=new Vu({color:g,roughness:.4,emissive:g,emissiveIntensity:x});let v;return i&&s.back?v=Od(d,t,e,s.back.tileSizeM,s.back.grout,h,s.back.orientation):v=new Vu({color:w,roughness:.4,emissive:w,emissiveIntensity:x}),[_,_,_,_,j,v]},[c,d,u,t,e,s,o,r,i,a,h,x]);return m.useEffect(()=>()=>{for(const g of new Set(f)){const w=g.map;w&&w!==c&&w!==d&&w!==u&&w.dispose(),g.dispose()}},[f,c,d,u]),{materials:f}}const zi={edge:0,front:4,back:5},Zs=.001;function ZE(t){return{start:{front:0,back:0},end:{front:t.wallLen,back:t.wallLen}}}function dP(t,e,s){const o=s??ZE(e),r=t.fromY<=Zs?-Rd:t.fromY,i=t.toY,a=e.thicknessM/2,l=t.fromDist<=Zs,c=t.toDist>=e.wallLen-Zs;let d=l?o.start.front:t.fromDist,u=l?o.start.back:t.fromDist,h=c?o.end.front:t.toDist,x=c?o.end.back:t.toDist;d>h-Zs&&(d=t.fromDist,h=t.toDist),u>x-Zs&&(u=t.fromDist,x=t.toDist);const f=[d,r,a],p=[h,r,a],b=[x,r,-a],M=[u,r,-a],g=[d,i,a],w=[h,i,a],k=[x,i,-a],_=[u,i,-a],j=[],v=[],C=[],N=Math.max(t.toDist-t.fromDist,Zs),P=Math.max(i-r,Zs),L=B=>[(B[0]-t.fromDist)/N,(B[1]-r)/P],A=[[0,0],[1,0],[1,1],[0,1]],W=(B,R,z,X,ft,tt=A)=>{const G=j.length/3,Y=[R,z,X,R,X,ft],J=[tt[0],tt[1],tt[2],tt[0],tt[2],tt[3]];for(let Mt=0;Mt<Y.length;Mt+=1)j.push(...Y[Mt]),v.push(...J[Mt]);C.push({start:G,count:6,materialIndex:B})};W(zi.front,f,p,w,g,[L(f),L(p),L(w),L(g)]),W(zi.back,b,M,_,k,[L(b),L(M),L(_),L(k)]),W(zi.edge,M,f,g,_),W(zi.edge,p,b,k,w),W(zi.edge,g,w,k,_),W(zi.edge,M,b,p,f);const S=new Ua;S.setAttribute("position",new Ur(j,3)),S.setAttribute("uv",new Ur(v,2)),S.clearGroups();for(const B of C)S.addGroup(B.start,B.count,B.materialIndex);return S.computeVertexNormals(),S.computeBoundingSphere(),S}function uP(t,e){return t<=Zs?e:t}function hP(t,e,s){const o=e??ZE(t),r=-Rd,i=t.heightM,a=t.thicknessM/2,l=t.wallLen,c=o.start.front,d=o.start.back,u=o.end.front,h=o.end.back,x=[],f=[],p=[],b=Math.max(i-r,Zs),M=(z,X)=>[z/Math.max(l,Zs),(X-r)/b],g=[[0,0],[1,0],[1,1],[0,1]],w=(z,X,ft,tt,G,Y=g)=>{const J=x.length/3,Mt=[X,ft,tt,X,tt,G],Rt=[Y[0],Y[1],Y[2],Y[0],Y[2],Y[3]];for(let it=0;it<Mt.length;it+=1)x.push(...Mt[it]),f.push(...Rt[it]);p.push({start:J,count:6,materialIndex:z})},k=s.map(z=>({x0:z.x0,x1:z.x1,y0:uP(z.y0,r),y1:z.y1,omitTopCap:z.omitTopCap})),_=(z,X,ft,tt,G)=>{const Y=(X+ft)/2,J=(tt+G)/2;for(const Mt of z)if(Y>Mt.x0+Zs&&Y<Mt.x1-Zs&&J>Mt.y0+Zs&&J<Mt.y1-Zs)return!1;return!0},j=(z,X)=>{const ft=Math.min(z,X),tt=Math.max(z,X);return k.map(G=>({x0:Math.max(G.x0,ft),x1:Math.min(G.x1,tt),y0:G.y0,y1:G.y1})).filter(G=>G.x1-G.x0>=Zs)},v=(z,X,ft,tt,G)=>{let Y=ft,J=tt;J-Y<Zs&&(Y=0,J=l);const Mt=j(Y,J),Rt=new Set([Y,J]),it=new Set([r,i]);for(const pt of Mt)Rt.add(pt.x0),Rt.add(pt.x1),it.add(pt.y0),it.add(pt.y1);const st=[...Rt].sort((pt,xt)=>pt-xt),ct=[...it].sort((pt,xt)=>pt-xt);for(let pt=0;pt<st.length-1;pt+=1)for(let xt=0;xt<ct.length-1;xt+=1){const _t=st[pt],Ft=st[pt+1],Vt=ct[xt],vt=ct[xt+1];if(Ft-_t<Zs||vt-Vt<Zs||!_(Mt,_t,Ft,Vt,vt))continue;const Ht=[_t,Vt,X],Tt=[Ft,Vt,X],Zt=[Ft,vt,X],At=[_t,vt,X];G>0?w(z,Ht,Tt,Zt,At,[M(_t,Vt),M(Ft,Vt),M(Ft,vt),M(_t,vt)]):w(z,Tt,Ht,At,Zt,[M(Ft,Vt),M(_t,Vt),M(_t,vt),M(Ft,vt)])}};v(zi.front,a,c,u,1),v(zi.back,-a,d,h,-1);for(const z of k){const{x0:X,x1:ft,y0:tt,y1:G}=z;X>Zs&&w(zi.edge,[X,tt,a],[X,tt,-a],[X,G,-a],[X,G,a]),ft<l-Zs&&w(zi.edge,[ft,tt,-a],[ft,tt,a],[ft,G,a],[ft,G,-a]),!z.omitTopCap&&G<i-Zs&&w(zi.edge,[X,G,-a],[ft,G,-a],[ft,G,a],[X,G,a])}const C=[c,r,a],N=[u,r,a],P=[h,r,-a],L=[d,r,-a],A=[c,i,a],W=[u,i,a],S=[h,i,-a],B=[d,i,-a];w(zi.edge,L,C,A,B),w(zi.edge,N,P,S,W),w(zi.edge,A,W,S,B),w(zi.edge,L,P,N,C);const R=new Ua;R.setAttribute("position",new Ur(x,3)),R.setAttribute("uv",new Ur(f,2)),R.clearGroups();for(const z of p)R.addGroup(z.start,z.count,z.materialIndex);return R.computeVertexNormals(),R.computeBoundingSphere(),R}function qE(t,e,s){const o=m.useMemo(()=>hP(t,e,s),[t,e,s]);return m.useEffect(()=>()=>o.dispose(),[o]),o}function _5({voids:t,frame:e,joinCaps:s,color:o,isSelected:r,sketchupLookEnabled:i=!1}){const a=qE(e,s,t),l=Wp();return n.jsxs("mesh",{position:[e.sx,0,e.sz],rotation:[0,-e.angle,0],geometry:a,castShadow:i,receiveShadow:i,children:[n.jsx("meshStandardMaterial",{color:o,metalness:0,roughness:.4,emissive:o,emissiveIntensity:l}),n.jsx(xo,{scale:1,threshold:15,color:th,lineWidth:bm}),r&&n.jsx(xo,{scale:1,threshold:15,color:Bf,lineWidth:Vf})]})}function mP({voids:t,frame:e,joinCaps:s,wallConfig:o,baseColor:r,isSelected:i,sketchupLookEnabled:a=!1}){const l=qE(e,s,t),c=Math.max(e.wallLen,Zs),d=Math.max(e.heightM+Rd,Zs),{materials:u}=KE({segW:c,segH:d,wallConfig:o,baseColor:r});return n.jsxs("mesh",{position:[e.sx,0,e.sz],rotation:[0,-e.angle,0],geometry:l,material:u,castShadow:a,receiveShadow:a,children:[n.jsx(xo,{scale:1,threshold:15,color:th,lineWidth:bm}),i&&n.jsx(xo,{scale:1,threshold:15,color:Bf,lineWidth:Vf})]})}function JE(t,e,s){const o=m.useMemo(()=>dP(t,e,s),[t,e,s]);return m.useEffect(()=>()=>o.dispose(),[o]),o}function fP({segment:t,frame:e,joinCaps:s,wallConfig:o,baseColor:r,isSelected:i,sketchupLookEnabled:a=!1}){const l=JE(t,e,s),c=Math.max(t.toDist-t.fromDist,Zs),d=t.fromY<=Zs?-Rd:t.fromY,u=Math.max(t.toY-d,Zs),{materials:h}=KE({segW:c,segH:u,wallConfig:o,baseColor:r});return n.jsxs("mesh",{position:[e.sx,0,e.sz],rotation:[0,-e.angle,0],geometry:l,material:h,castShadow:a,receiveShadow:a,children:[n.jsx(xo,{scale:1,threshold:15,color:th,lineWidth:bm}),i&&n.jsx(xo,{scale:1,threshold:15,color:Bf,lineWidth:Vf})]})}function E5({segment:t,frame:e,joinCaps:s,isSelected:o,sketchupLookEnabled:r=!1}){const i=JE(t,e,s),a=Wp();return n.jsxs("mesh",{position:[e.sx,0,e.sz],rotation:[0,-e.angle,0],geometry:i,castShadow:r,receiveShadow:r,children:[n.jsx("meshStandardMaterial",{color:t.color,metalness:0,roughness:.4,emissive:t.color,emissiveIntensity:a}),n.jsx(xo,{scale:1,threshold:15,color:th,lineWidth:bm}),o&&n.jsx(xo,{scale:1,threshold:15,color:Bf,lineWidth:Vf})]})}function xP({wall:t,side:e,measurementUnit:s}){const o=m.useMemo(()=>r3(t),[t]);if(!o)return null;const r=e==="back"?-1:1,i=(o.thicknessM/2+.045)*r,a=o.heightM+.13,l=o.wallLen+.
19914,c=Math.min(.11,Math.max(.065,o.wallLen*.045)),d=c*.34,u="#D85D43",h=10.5,x="pointer-events-none whitespace-nowrap rounded-[10px] border border-[#D85D43]/30 bg-[#F7F4EF]/95 px-3 py-2 font-heebo text-[15px] font-black leading-none tabular-nums text-[#182137] shadow-[0_6px_16px_rgba(24,33,55,0.2)]",f=(p,b,M)=>n.jsxs("mesh",{position:b,rotation:M,raycast:()=>{},renderOrder:10002,children:[n.jsx("coneGeometry",{args:[d,c,18]}),n.jsx("meshBasicMaterial",{color:u,depthTest:!1,depthWrite:!1})]},p);return n.jsxs("group",{position:[o.sx,0,o.sz],rotation:[0,-o.angle,0],renderOrder:1e4,children:[n.jsx(Jn,{raycast:()=>{},points:[[0,a,i],[o.wallLen,a,i]],color:u,lineWidth:2.2,depthTest:!1,renderOrder:10001}),n.jsx(Jn,{raycast:()=>{},points:[[0,o.heightM+.035,i],[0,a+.035,i]],color:u,lineWidth:1.1,depthTest:!1,renderOrder:10001}),n.jsx(Jn,{raycast:()=>{},points:[[o.wallLen,o.heightM+.035,i],[o.wallLen,a+.035,i]],color:u,lineWidth:1.1,depthTest:!1,renderOrder:10001}),f("length-start",[c/2,a,i],[0,0,-Math.PI/2]),f("length-end",[o.wallLen-c/2,a,i],[0,0,Math.PI/2]),n.jsx(Uu,{position:[o.wallLen/2,a+.055,i],center:!0,distanceFactor:h,zIndexRange:[75,0],style:{pointerEvents:"none"},children:n.jsx("span",{className:x,children:$i(o.wallLenMm,s)})}),n.jsx(Jn,{raycast:()=>{},points:[[l,0,i],[l,o.heightM,i]],color:u,lineWidth:2.2,depthTest:!1,renderOrder:10001}),n.jsx(Jn,{raycast:()=>{},points:[[o.wallLen+.035,0,i],[l+.035,0,i]],color:u,lineWidth:1.1,depthTest:!1,renderOrder:10001}),n.jsx(Jn,{raycast:()=>{},points:[[o.wallLen+.035,o.heightM,i],[l+.035,o.heightM,i]],color:u,lineWidth:1.1,depthTest:!1,renderOrder:10001}),f("height-bottom",[l,c/2,i],[0,0,0]),f("height-top",[l,o.heightM-c/2,i],[Math.PI,0,0]),n.jsx(Uu,{position:[l+.07,o.heightM/2,i],center:!0,distanceFactor:h,zIndexRange:[75,0],style:{pointerEvents:"none"},children:n.jsx("span",{className:x,children:$i(o.heightMm,s)})})]})}function pP({frame:t,wallType:e,onShellClick:s,onShellContextMenu:o,onShellDoubleClick:r}){const i=t.wallLen,a=t.thicknessM/2,l=-Rd,c=t.heightM+Rd,d=e==="free"?Math.max(c,Ld*rt+Rd):c,u=i/2,h=l+d/2,x=qS,f=[{side:"front",position:[u,h,a+x],rotation:[0,0,0]},{side:"back",position:[u,h,-a-x],rotation:[0,Math.PI,0]}];return n.jsx("group",{position:[t.sx,0,t.sz],rotation:[0,-t.angle,0],children:f.map(({side:p,position:b,rotation:M})=>n.jsxs("mesh",{position:b,rotation:M,userData:{wallPickSide:p},onPointerDown:s?g=>{g.button===0&&s(g,p)}:void 0,onContextMenu:o?g=>o(g,p):void 0,onDoubleClick:r?g=>r(g,p):void 0,onClick:g=>g.stopPropagation(),children:[n.jsx("planeGeometry",{args:[i,d]}),n.jsx("meshBasicMaterial",{visible:!1,side:cr,depthWrite:!1})]},p))})}function gP({wall:t,openings:e,color:s,wallConfig:o,isSelected:r,onWallClick:i,onWallContextMenu:a,onWallDoubleClick:l,onWallHover:c,onWallHoverEnd:d,openingPlaceMode:u,onWallPlaceClick:h,electricalPlaceMode:x,onWallElectricalPlace:f,notePlaceMode:p,onWallNotePlace:b,joinCaps:M,sketchupLookEnabled:g=!1}){const w=m.useMemo(()=>r3(t),[t]),k=Wp(),_=m.useMemo(()=>{if(!w)return[];const z=w.sx,X=w.sz,ft=w.ex-w.sx,tt=w.ez-w.sz,G=w.wallLen,Y=w.heightM,J=w.thicknessM,Mt=new B_(0,-w.angle,0),Rt=[...e].sort((pt,xt)=>pt.position-xt.position),it=[],st=(pt,xt,_t,Ft,Vt)=>{if(xt-pt<.001)return;const Ht=-Rd;Ft-Ht<.001||it.push({kind:"surface",fromDist:pt,toDist:xt,fromY:_t,toY:Ft,color:Vt})},ct=(pt,xt,_t,Ft,Vt,vt)=>{const Ht=z+ft/G*pt,Tt=X+tt/G*pt;it.push({kind:"box",pos:new le(Ht,xt,Tt),rot:Mt,w:_t,h:Ft,t:Vt,color:vt})};if(Rt.length>0){const pt=[];for(const xt of Rt){const _t=xt.preset==="arched_door"||xt.preset==="arched_door_glass"||xt.preset==="arched_window",Ft=xt.position*rt,Vt=xt.width*rt/2,vt=Math.max(0,Ft-Vt),Ht=Math.min(G,Ft+Vt),Tt=xt.sillHeight*rt,Zt=xt.height*rt,At=Tt+Zt;pt.push({x0:vt,x1:Ht,y0:xt.type==="door"?0:Tt,y1:At,omitTopCap:_t})}it.push({kind:"solidWithVoids",voids:pt,color:s});for(const xt of Rt){if(xt.type!=="window")continue;const _t=xt.position*rt,Ft=xt.width*rt/2,Vt=Math.max(0,_t-Ft),vt=Math.min(G,_t+Ft),Ht=xt.sillHeight*rt,Tt=xt.height*rt,Zt=vt-Vt,At=(Vt+vt)/2,ut=ZS;ct(At,Ht,Zt,ut,J*.6,ul.windowFrame),ct(At,Ht+Tt,Zt,ut,J*.6,ul.window
199Frame);const kt=Vt+ut/2,Et=vt-ut/2;ct(kt,Ht+Tt/2,ut,Tt,J*.6,ul.windowFrame),ct(Et,Ht+Tt/2,ut,Tt,J*.6,ul.windowFrame)}return it}return st(0,G,0,Y,s),it},[w,e,s]),j=!!o&&(!!o.front||!!o.back||!!o.edge||!!o.frontColor||!!o.backColor||!!o.edgeColor),v=!!(i||l||a||u&&h||x&&f||p&&b),C=z=>{if(!z)return"front";const X=z.materialIndex;return X===zi.back?"back":X===zi.front?"front":z.normal.z<-.5?"back":z.normal.z>.5?"front":typeof X=="number"&&X>=0&&X<=3?"edge":z.normal.z<0?"back":"front"},N=m.useCallback(z=>{a&&(z.stopPropagation(),a(t.id,{x:z.clientX,y:z.clientY},C(z.face)))},[a,t.id]),P=m.useCallback(z=>{if(t.id,x&&f){z.stopPropagation(),f(t.id,{x:z.point.x,y:z.point.y,z:z.point.z},C(z.face));return}if(p&&b){z.stopPropagation(),b(t.id,{x:z.point.x,y:z.point.y,z:z.point.z},C(z.face),{x:z.nativeEvent.clientX,y:z.nativeEvent.clientY});return}if(!(!i&&!(u&&h))){if(z.stopPropagation(),u&&h){h(t.id,{x:z.point.x,z:z.point.z});return}i&&i(t.id,{x:z.clientX,y:z.clientY},C(z.face))}},[i,t.id,u,h,x,f,p,b]),L=m.useCallback(z=>{l&&(z.stopPropagation(),l(t.id,{x:z.clientX,y:z.clientY},C(z.face)))},[l,t.id]),A=m.useCallback((z,X)=>{if(x&&f){z.stopPropagation(),f(t.id,{x:z.point.x,y:z.point.y,z:z.point.z},X);return}if(p&&b){z.stopPropagation(),b(t.id,{x:z.point.x,y:z.point.y,z:z.point.z},X,{x:z.nativeEvent.clientX,y:z.nativeEvent.clientY});return}if(!(!i&&!(u&&h))){if(z.stopPropagation(),u&&h){h(t.id,{x:z.point.x,z:z.point.z});return}i&&i(t.id,{x:z.clientX,y:z.clientY},X)}},[i,t.id,u,h,x,f,p,b]),W=m.useCallback((z,X)=>{a&&(z.stopPropagation(),a(t.id,{x:z.clientX,y:z.clientY},X))},[a,t.id]),S=m.useCallback((z,X)=>{l&&(z.stopPropagation(),l(t.id,{x:z.clientX,y:z.clientY},X))},[l,t.id]),B=m.useCallback(z=>{if(!c)return;z.stopPropagation();const X=z.object.userData.wallPickSide,ft=X==="front"||X==="back"?X:C(z.face);c(t.id,ft),document.body.style.cursor="pointer"},[c,t.id]),R=m.useCallback(z=>{d&&(z.stopPropagation(),d(t.id),document.body.style.cursor="")},[d,t.id]);return w?n.jsxs("group",{onClick:v?P:void 0,onDoubleClick:v?L:void 0,onContextMenu:a?N:void 0,onPointerOver:c?B:void 0,onPointerOut:d?R:void 0,userData:{wallId:t.id},children:[_.map((z,X)=>{if(z.kind==="solidWithVoids"){if(j){const Y=n.jsx(_5,{voids:z.voids,frame:w,joinCaps:M,color:z.color,isSelected:r,sketchupLookEnabled:g});return n.jsx(ml,{fallback:Y,children:n.jsx(mP,{voids:z.voids,frame:w,joinCaps:M,wallConfig:o,baseColor:z.color,isSelected:r,sketchupLookEnabled:g})},X)}return n.jsx(_5,{voids:z.voids,frame:w,joinCaps:M,color:z.color,isSelected:r,sketchupLookEnabled:g},X)}if(z.kind==="surface"){if(j){const Y=n.jsx(E5,{segment:{...z,color:s},frame:w,joinCaps:M,isSelected:r,sketchupLookEnabled:g});return n.jsx(ml,{fallback:Y,children:n.jsx(fP,{segment:z,frame:w,joinCaps:M,wallConfig:o,baseColor:s,isSelected:r,sketchupLookEnabled:g})},X)}return n.jsx(E5,{segment:z,frame:w,joinCaps:M,isSelected:r,sketchupLookEnabled:g},X)}const ft=z.color===ul.glass,tt=z.color===ul.doorPanel||z.color===ul.door,G=z.color===ul.windowFrame;return n.jsxs("mesh",{position:z.pos,rotation:z.rot,castShadow:g,receiveShadow:g,children:[n.jsx("boxGeometry",{args:[z.w,z.h,z.t]}),n.jsx("meshStandardMaterial",{color:z.color,transparent:ft,opacity:ft?.25:1,side:ft?kn:cr,metalness:tt?.1:0,roughness:tt?.7:ft?.1:.4,emissive:ft||tt?void 0:z.color,emissiveIntensity:ft||tt?0:k,depthWrite:!ft}),!ft&&n.jsx(xo,{scale:1,threshold:15,color:th,lineWidth:bm}),r&&!tt&&!G&&n.jsx(xo,{scale:1,threshold:15,color:Bf,lineWidth:Vf})]},X)}),e.length===0&&v&&n.jsx(pP,{frame:w,wallType:t.wallType,onShellClick:A,onShellContextMenu:W,onShellDoubleClick:S})]}):null}const Qr="#1a1a1a",Sr="#050505",Sc="#c8dce8",bP="#e8e0d4",Lh="#050505",D5=Math.PI/2*.98,F5=Math.PI/180*38;function oc({open:t=!1,pivotX:e=0,pivotY:s=0,pivotZ:o=0,rotAxis:r=null,openAngle:i=0,slideX:a=0,slideY:l=0,slideZ:c=0,children:d}){const u=m.useRef(null),h=m.useRef(0),x=m.useCallback((f,p)=>{r==="x"?f.rotation.x=i*p:r==="y"?f.rotation.y=i*p:r==="z"&&(f.rotation.z=i*p),f.position.set(e+a*p,s+l*p,o+c*p)},[r,i,e,s,o,a,l,c]);return ka((f,p)=>{const b=u.current;if(!b)return;const M=t?1:0;let g=h.current;if(Math.abs(g-M)<=6e-4){g!==M&&(g=M,h.current=g,x(b,g));return}g+=(M-g)*(1-Math.exp(-9*Math.min(p,.05))),Math.abs(g-M)<=6e-4&&(g=M),h.current=g,x(b,g)}),n.jsx("group",{ref:u,position:[e,s,o],children:n.jsx("group",{position:[-e,-s,-o],children:d})})}function MP({opening:t,wall:e,wallColor:s=ul.wall,onClick:o,onContextMenu:r,isSelected:i,sketchupLookEnabled:a=!1,targetOpen:l=!1}){var Tt,Zt,At,ut;const c=Wp(),d=m.useMemo(()=>{const kt=e.start.x*rt,Et=e.start.y*rt,ht=e.end.x*rt,gt=e.end.y*rt,Pt=ht-kt,U=gt-Et,mt=Math.sqrt(Pt*Pt+U*U);if(mt===0)return null;const Nt=Math.atan2(U,Pt),Lt=Pt/mt,oe=U/mt,he=t.position*rt;return{x:kt+Lt*he,y:t.sillHeight*rt,z:Et+oe*he,angle:Nt,w:t.width*rt,h:t.height*rt,t:e.thickness*rt,dist:he,wallLen:mt}},[t,e]),{gl:u}=Vo(),h=m.useCallback(kt=>{o&&(kt.stopPropagation(),o())},[o]),x=m.useCallback(kt=>{var Pt;if(kt.stopPropagation(),!r)return;let Et="front";const ht=(Pt=kt.face)==null?void 0:Pt.normal.z;if(ht!==void 0&&Math.abs(ht)>.5)Et=ht<0?"back":"front";else if(kt.camera&&kt.point){const U=e.start.x*rt,mt=e.start.y*rt,Nt=e.end.x*rt,Lt=e.end.y*rt,oe=Math.atan2(Lt-mt,Nt-U),he
199=new le(-Math.sin(oe),0,Math.cos(oe));Et=kt.point.clone().sub(kt.camera.position).dot(he)<0?"front":"back"}let gt;if(d&&kt.camera){const U=u.domElement.getBoundingClientRect(),mt=d.w/2,Nt=Math.max(d.t/2,.04),Lt=new B_(0,-d.angle,0),oe=new le(d.x,d.y,d.z),he=[[-mt,0,-Nt],[mt,0,-Nt],[-mt,d.h,-Nt],[mt,d.h,-Nt],[-mt,0,Nt],[mt,0,Nt],[-mt,d.h,Nt],[mt,d.h,Nt]];let pe=-1/0,Ge=1/0,Qt=-1/0;for(const[te,Be,wt]of he){const ve=new le(te,Be,wt).applyEuler(Lt).add(oe).project(kt.camera),Ne=U.left+(ve.x+1)/2*U.width,Le=U.top+(1-ve.y)/2*U.height;pe=Math.max(pe,Ne),Ge=Math.min(Ge,Le),Qt=Math.max(Qt,Le)}Number.isFinite(pe)&&Number.isFinite(Ge)&&Number.isFinite(Qt)&&(gt={x:pe,y:(Ge+Qt)/2})}r({x:kt.clientX,y:kt.clientY},Et,gt)},[u,r,d,e.start.x,e.start.y,e.end.x,e.end.y]);if(!d)return null;const{x:f,y:p,z:b,angle:M,w:g,h:w,t:k,dist:_,wallLen:j}=d,v=.035,C=t.type==="door"&&t.sillHeight*rt<1e-4?Rd:0,N=a?{castShadow:!0,receiveShadow:!0}:{},P=a?{receiveShadow:!0}:{},L=t.type==="window"&&t.preset==="fixed_window",A=t.type==="window"&&t.preset==="wide_window",W=t.type==="window"&&t.preset==="casement_window",S=t.type==="window"&&t.preset==="awning_window",B=t.type==="window"&&t.preset==="sliding_window",R=t.type==="window"&&t.preset==="bay_window",z=t.type==="window"&&t.preset==="floor_to_ceiling_vertical";if(t.type==="window"&&t.preset==="arched_window"){const kt=pp(g,w),Et=M5(Math.max(.08,g-v*2),Math.max(.16,w-v*2)),ht=y5(g+.024,w+.024,Math.max(.08,g-v*.35),Math.max(.16,w+.006)),gt=Math.max(.08,g-v),Pt=Math.max(.16,w-v/2),U=k/2+.012,mt=ng(gt,Pt,U),Nt=ng(gt,Pt,-U);return n.jsxs("group",{position:[f,p,b],rotation:[0,-M,0],onClick:h,onContextMenu:r?x:void 0,children:[[1,-1].map(Lt=>n.jsxs("mesh",{position:[0,0,Lt*(k/2+.003)],renderOrder:2,children:[n.jsx("shapeGeometry",{args:[ht]}),n.jsx("meshStandardMaterial",{color:s,roughness:.4,metalness:0,emissive:s,emissiveIntensity:c,side:kn,polygonOffset:!0,polygonOffsetFactor:-4})]},`arched-window-wall-infill-${Lt}`)),n.jsxs("mesh",{position:[0,v,0],...P,children:[n.jsx("shapeGeometry",{args:[Et]}),n.jsx("meshPhysicalMaterial",{color:Sc,transparent:!0,opacity:.2,roughness:.02,metalness:0,transmission:.95,thickness:.02,ior:1.45,side:kn,depthWrite:!1,polygonOffset:!0,polygonOffsetFactor:-1})]}),n.jsxs("mesh",{position:[0,v/2,0],...N,children:[n.jsx("boxGeometry",{args:[g,v,v]}),n.jsx("meshStandardMaterial",{color:Sr,metalness:.45,roughness:.34})]}),n.jsxs("mesh",{position:[-g/2+v/2,kt/2,0],...N,children:[n.jsx("boxGeometry",{args:[v,kt,v]}),n.jsx("meshStandardMaterial",{color:Sr,metalness:.45,roughness:.34})]}),n.jsxs("mesh",{position:[g/2-v/2,kt/2,0],...N,children:[n.jsx("boxGeometry",{args:[v,kt,v]}),n.jsx("meshStandardMaterial",{color:Sr,metalness:.45,roughness:.34})]}),n.jsx(Jn,{points:mt,color:Sr,lineWidth:6,renderOrder:4}),n.jsx(Jn,{points:Nt,color:Sr,lineWidth:6,renderOrder:4}),i&&n.jsxs("mesh",{position:[0,w/2,0],children:[n.jsx("boxGeometry",{args:[g+.04,w+.04,k+.04]}),n.jsx(xo,{color:"#3B82F6",lineWidth:3}),n.jsx("meshBasicMaterial",{visible:!1})]})]})}if(R){const Et=(Wd(t).swingFace==="back"?-1:1)*Math.min(.6,Math.max(.25,g*.32)),ht=g*.5,gt=[[-g/2,0],[-ht/2,Et],[ht/2,Et],[g/2,0]],Pt=[0,1,2].map(U=>{const[mt,Nt]=gt[U],[Lt,oe]=gt[U+1];return{len:Math.hypot(Lt-mt,oe-Nt),midX:(mt+Lt)/2,midZ:(Nt+oe)/2,rotY:-Math.atan2(oe-Nt,Lt-mt)}});return n.jsxs("group",{position:[f,p,b],rotation:[0,-M,0],onClick:h,onContextMenu:r?x:void 0,children:[Pt.map((U,mt)=>n.jsxs("group",{position:[U.midX,0,U.midZ],rotation:[0,U.rotY,0],children:[n.jsxs("mesh",{position:[0,w/2,0],...P,children:[n.jsx("boxGeometry",{args:[Math.max(.04,U.len-v),w-v*2,.006]}),n.jsx("meshPhysicalMaterial",{color:Sc,transparent:!0,opacity:.2,roughness:.05,metalness:.1,side:kn,depthWrite:!1,polygonOffset:!0,polygonOffsetFactor:-1})]}),n.jsxs("mesh",{position:[0,v/2,0],...N,children:[n.jsx("boxGeometry",{args:[U.len,v,v]}),n.jsx("meshStandardMaterial",{color:Sr,metalness:.45,roughness:.34})]}),n.jsxs("mesh",{position:[0,w-v/2,0],...N,children:[n.jsx("boxGeometry",{args:[U.len,v,v]}),n.jsx("meshStandardMaterial",{color:Sr,metalness:.45,roughness:.34})]})]},`bay-seg-${mt}`)),gt.map(([U,mt],Nt)=>n.jsxs("mesh",{position:[U,w/2,mt],...N,children:[n.jsx("boxGeometry",{args:[v,w,v]}),n.jsx("meshStandardMaterial",{color:Sr,metalness:.45,roughness:.34})]},`bay-post-${Nt}
199`)),i&&n.jsxs("mesh",{position:[0,w/2,Et/2],children:[n.jsx("boxGeometry",{args:[g+.04,w+.04,Math.abs(Et)+k+.04]}),n.jsx(xo,{color:"#3B82F6",lineWidth:3}),n.jsx("meshBasicMaterial",{visible:!1})]})]})}if(t.type==="window"){const kt=v*.75,Et=Math.max(.08,g-v*2),ht=Math.max(.08,w-v*2),gt=Wd(t),Pt=gt.swingFace==="back"?-1:1,U=gt.hingeSide==="right"?1:-1,mt=Pt*U*F5,Nt=-Pt*F5,Lt=Math.max(.04,Et-kt*2),oe=Math.max(.04,ht-kt*2),he=n.jsxs("group",{position:[0,v,0],children:[n.jsxs("mesh",{position:[0,ht/2,0],...P,children:[n.jsx("boxGeometry",{args:[Lt,oe,.006]}),n.jsx("meshPhysicalMaterial",{color:Sc,transparent:!0,opacity:.24,roughness:.05,metalness:.1,side:kn,depthWrite:!1,polygonOffset:!0,polygonOffsetFactor:-1})]}),n.jsxs("mesh",{position:[0,kt/2,0],...N,children:[n.jsx("boxGeometry",{args:[Et,kt,kt]}),n.jsx("meshStandardMaterial",{color:Sr,metalness:.45,roughness:.34})]}),n.jsxs("mesh",{position:[0,ht-kt/2,0],...N,children:[n.jsx("boxGeometry",{args:[Et,kt,kt]}),n.jsx("meshStandardMaterial",{color:Sr,metalness:.45,roughness:.34})]}),n.jsxs("mesh",{position:[-Et/2+kt/2,ht/2,0],...N,children:[n.jsx("boxGeometry",{args:[kt,ht,kt]}),n.jsx("meshStandardMaterial",{color:Sr,metalness:.45,roughness:.34})]}),n.jsxs("mesh",{position:[Et/2-kt/2,ht/2,0],...N,children:[n.jsx("boxGeometry",{args:[kt,ht,kt]}),n.jsx("meshStandardMaterial",{color:Sr,metalness:.45,roughness:.34})]})]});return n.jsxs("group",{position:[f,p,b],rotation:[0,-M,0],onClick:h,onContextMenu:r?x:void 0,children:[!W&&!S&&!B&&n.jsxs("mesh",{position:[0,w/2,0],...P,children:[n.jsx("boxGeometry",{args:[g-v*2,w-v*2,.006]}),n.jsx("meshPhysicalMaterial",{color:Sc,transparent:!0,opacity:.2,roughness:.05,metalness:.1,side:kn,depthWrite:!1,polygonOffset:!0,polygonOffsetFactor:-1})]}),n.jsxs("mesh",{position:[0,v/2,0],...N,children:[n.jsx("boxGeometry",{args:[g,v,v]}),n.jsx("meshStandardMaterial",{color:Sr,metalness:.45,roughness:.34})]}),n.jsxs("mesh",{position:[0,w-v/2,0],...N,children:[n.jsx("boxGeometry",{args:[g,v,v]}),n.jsx("meshStandardMaterial",{color:Sr,metalness:.45,roughness:.34})]}),n.jsxs("mesh",{position:[-g/2+v/2,w/2,0],...N,children:[n.jsx("boxGeometry",{args:[v,w,v]}),n.jsx("meshStandardMaterial",{color:Sr,metalness:.45,roughness:.34})]}),n.jsxs("mesh",{position:[g/2-v/2,w/2,0],...N,children:[n.jsx("boxGeometry",{args:[v,w,v]}),n.jsx("meshStandardMaterial",{color:Sr,metalness:.45,roughness:.34})]}),(L||z)&&g>.35&&n.jsxs("mesh",{position:[0,w/2,0],...N,children:[n.jsx("boxGeometry",{args:[v*1.25,w-v*2,v*.85]}),n.jsx("meshStandardMaterial",{color:Sr,metalness:.45,roughness:.34})]}),A&&g>1.1&&[-1,1].map(pe=>n.jsxs("mesh",{position:[pe*g/6,w/2,0],...N,children:[n.jsx("boxGeometry",{args:[v*.55,w-v*2,v*.6]}),n.jsx("meshStandardMaterial",{color:Sr,metalness:.45,roughness:.34})]},pe)),!L&&!z&&!A&&!W&&!S&&!B&&w>.8&&n.jsxs("mesh",{position:[0,w/2,0],...N,children:[n.jsx("boxGeometry",{args:[g-v*2,v*.6,v*.6]}),n.jsx("meshStandardMaterial",{color:Sr,metalness:.45,roughness:.34})]}),W&&n.jsx(oc,{open:l,pivotX:U*(Et/2),rotAxis:"y",openAngle:mt,children:he}),S&&n.jsx(oc,{open:l,pivotY:v+ht,rotAxis:"x",openAngle:Nt,children:he}),B&&(()=>{const pe=Math.max(.1,g/2-v*.5),Ge=Math.max(.04,pe-kt*2),Qt=Math.max(.04,w-v*2-kt*2),te=U,Be=({zOff:wt})=>n.jsxs(n.Fragment,{children:[n.jsxs("mesh",{position:[0,w/2,wt],...P,children:[n.jsx("boxGeometry",{args:[Ge,Qt,.006]}),n.jsx("meshPhysicalMaterial",{color:Sc,transparent:!0,opacity:.24,roughness:.05,metalness:.1,side:kn,depthWrite:!1,polygonOffset:!0,polygonOffsetFactor:-1})]}),n.jsxs("mesh",{position:[-pe/2+kt/2,w/2,wt],...N,children:[n.jsx("boxGeometry",{args:[kt,w-v*2,kt]}),n.jsx("meshStandardMaterial",{color:Sr,metalness:.45,roughness:.34})]}),n.jsxs("mesh",{position:[pe/2-kt/2,w/2,wt],...N,children:[n.jsx("boxGeometry",{args:[kt,w-v*2,kt]}),n.jsx("meshStandardMaterial",{color:Sr,metalness:.45,roughness:.34})]})]});return n.jsxs(n.Fragment,{children:[n.jsx("group",{position:[-te*(g/4),0,-.012],children:n.jsx(Be,{zOff:0})}),n.jsx(oc,{open:l,slideX:-te*(g/2-v),children:n.jsx("group",{position:[te*(g/4),0,.012],children:n.jsx(Be,{zOff:0})})})]})})(),(W||S)&&n.jsxs("mesh",{position:[g/2-v*2.5,w*.45,Pt*(v/2+.005)],...N,children:[n.jsx("boxGeometry",{args:[.01,.08,.015]}),n.jsx("meshStandardMaterial",{color:Sr,metalness:.65,roughness:.22})]}),i&&n.jsxs("mesh",{position:[0,w/2,0],children:[n.jsx("boxGeometry",{args:[g+.04,w+.04,k+.04]}),n.jsx(xo,{color:"#3B82F6",lineWidth:3}),n.jsx("meshBasicMaterial",{visible:!1})]})]})}const ft=t.preset==="corner_glass_door",tt=t.style==="glass"||ft,G=t.preset==="flush_door",Y=t.preset==="arched_door"||t.preset==="arched_door_glass",J=Yw(t.preset),Mt=t.panelColor||bP,Rt=hm(t),it=Wd(t),st=it.hingeSide==="right"?1:-1,ct=-st*(g/2-v*3),pt=it.hingeSide==="left"?-1:1,xt=it.swingFace==="front"?1:-1,_t=st*(g/2-v),Ft=xt*st*D5,Vt=t.preset==="sliding_door",vt=t.preset==="double_door",Ht=t.preset==="garage_door";if(J){const kt=Math.max(k,.08);return n.jsxs("group",{position:[f,p,b],rotation:[0,-M,0],onClick:h,onContextMenu:r?x:void 0,children:[n.jsxs("mesh",{position:[0,w/2-C/2,0],children:[n.jsx("boxGeometry",{args:[g,w+C,kt]}),n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthWrite:!1})]}),i&&n.jsxs("mesh",{position:[0,w/2-C/2,0],children:[n.jsx("boxGeometry",{args:[g+.04,w+C+.04,kt+.04]}),n.jsx(xo,{color:"#3B82F6",lineWidth:3}),n.jsx("meshBasicMaterial",{visible:!1})]})]})}if(Ht){const kt=w+C,Et=w/2-C/2,ht=Math.max(3,Math.round(kt/.45)),gt=kt/ht,Pt=Math.max(.2,g-v);return n.jsxs("group",{position:[f,p,b],rotation:[0,-M,0],onClick:h,onContextMenu:r?x:void 0,children:[n.jsxs("mesh",{position:[0,w-v/2,0],...N,children:[n.jsx("boxGeometry",{args:[g,v,k*.8]}),n.jsx("meshStandardMaterial",{color:Qr,metalness:.6,roughness:.3})]}),n.jsxs("mesh",{position:[-g/2+v/2,Et,0],...N,children:[n.jsx("boxGeometry",{args:[v,kt,k*.8]}),n.jsx("meshStandardMaterial",{color:Qr,metalness:.6,roughness:.3})]}),n.jsxs("mesh",{position:[g/2-v/2,Et,0],...N,children:[n.jsx("boxGeometry",{args:[v,kt,k*.8]}),n.jsx("meshStandardMaterial",{color:Qr,metalness:.6,roughness:.3})]}),n.jsx(oc,{open:l,slideY:kt-gt,children:Array.from({length:ht},(U,mt)=>n.jsxs("mesh",{position:[0,gt/2+mt*gt-C/2,0],...N,children:[n.jsx("boxGeometry",{args:[Pt,gt*.9,.05]}),n.jsx("meshStandardMaterial",{color:Mt,roughness:.55,metalness:.08})]},mt))}),i&&n.jsxs("mesh",{position:[0,w/2,0],children:[n.jsx("boxGeometry",{args:[g+.04,w+.04,k+.04]}),n.jsx(xo,{color:"#3B82F6",lineWidth:3}),n.jsx("meshBasicMaterial",{visible:!1})]})]})}if(Vt){const kt=w+C,Et=w/2-C/2,ht=Math.max(.2,g/2-v*.5),gt=st,Pt=()=>tt?n.jsxs("mesh",{position:[0,Et,0],...P,children:[n.jsx("boxGeometry",{args:[ht,kt,.014]}),n.jsx("meshPhysicalMaterial",{color:Sc,transparent:!0,opacity:.18,roughness:.02,metalness:0,transmission:.95,thickness:.02,ior:1.45,side:kn,depthWrite:!1,polygonOffset:!0,polygonOffsetFactor:-1})]}):n.jsxs("mesh",{position:[0,Et,0],...N,children:[n.jsx("boxGeometry",{args:[ht,kt,.04]}),n.jsx("meshStandardMaterial",{color:Mt,roughness:.6,metalness:.05})]}),U=({zOff:mt})=>n.jsxs(n.Fragment,{children:[n.jsxs("mesh",{position:[-ht/2+v/2,Et,mt],...N,children:[n.jsx("boxGeometry",{args:[v,kt,v*.7]}),n.jsx("meshStandardMaterial",{color:Qr,metalness:.6,roughness:.3})]}),n.jsxs("mesh",{position:[ht/2-v/2,Et,mt],...N,children:[n.jsx("boxGeometry",{args:[v,kt,v*.7]}),n.jsx("meshStandardMaterial",{color:Qr,metalness:.6,roughness:.3})]})]});return n.jsxs("group",{position:[f,p,b],rotation:[0,-M,0],onClick:h,onContextMenu:r?x:void 0,children:[n.jsxs("mesh",{position:[0,w-v/2,0],...N,children:[n.jsx("boxGeometry",{args:[g,v,k*.9]}
199),n.jsx("meshStandardMaterial",{color:Qr,metalness:.6,roughness:.3})]}),n.jsxs("group",{position:[-gt*(g/4),0,-.02],children:[n.jsx(Pt,{}),n.jsx(U,{zOff:0})]}),n.jsx(oc,{open:l,slideX:-gt*(g/2-v*2),children:n.jsxs("group",{position:[gt*(g/4),0,.02],children:[n.jsx(Pt,{}),n.jsx(U,{zOff:0})]})}),i&&n.jsxs("mesh",{position:[0,w/2,0],children:[n.jsx("boxGeometry",{args:[g+.04,w+.04,k+.04]}),n.jsx(xo,{color:"#3B82F6",lineWidth:3}),n.jsx("meshBasicMaterial",{visible:!1})]})]})}if(ft){const kt=_<=j-_?"left":"right",Et=Math.max(v*1.8,k*.52),ht=Math.max(k*1.45,v*3),gt=Math.max(v*.85,.028),Pt=Math.max(k*1.08,v*2),U=Math.max(.04,g-v*2),mt=Math.max(.04,w-v*2+C),Nt=Lt=>{const oe=Lt===kt,he=oe?t.cornerArm==="return"?gt:Et:v,pe=oe?t.cornerArm==="return"?Pt:ht:k*.7,Ge=Lt==="left"?-g/2+he/2:g/2-he/2;return n.jsxs("mesh",{position:[Ge,w/2-C/2,0],...N,children:[n.jsx("boxGeometry",{args:[he,w+C,pe]}),n.jsx("meshStandardMaterial",{color:Qr,metalness:.72,roughness:.24})]},Lt)};return n.jsxs("group",{position:[f,p,b],rotation:[0,-M,0],onClick:h,onContextMenu:r?x:void 0,children:[n.jsxs("mesh",{position:[0,w/2-C/2,0],...P,children:[n.jsx("boxGeometry",{args:[U,mt,.014]}),n.jsx("meshPhysicalMaterial",{color:Sc,transparent:!0,opacity:.18,roughness:.02,metalness:0,transmission:.95,thickness:.02,ior:1.45,side:kn,depthWrite:!1,polygonOffset:!0,polygonOffsetFactor:-1})]}),n.jsxs("mesh",{position:[0,v/2-C,0],...N,children:[n.jsx("boxGeometry",{args:[g,v,k*.7]}),n.jsx("meshStandardMaterial",{color:Qr,metalness:.72,roughness:.24})]}),n.jsxs("mesh",{position:[0,w-v/2,0],...N,children:[n.jsx("boxGeometry",{args:[g,v,k*.7]}),n.jsx("meshStandardMaterial",{color:Qr,metalness:.72,roughness:.24})]}),Nt("left"),Nt("right"),i&&n.jsxs("mesh",{position:[0,w/2,0],children:[n.jsx("boxGeometry",{args:[g+.04,w+.04,k+.04]}),n.jsx(xo,{color:"#3B82F6",lineWidth:3}),n.jsx("meshBasicMaterial",{visible:!1})]})]})}if(Y){const kt=pp(g,w),Et=Math.max(.08,g-v*2),ht=Math.max(.16,w-v+C),gt=M5(Et,ht),Pt=y5(g+.024,w+.024,Math.max(.08,g-v*.35),Math.max(.16,w+.006)),U=Math.max(.08,g-v),mt=Math.max(.16,w-v/2),Nt=k/2+.012,Lt=ng(U,mt,Nt),oe=ng(U,mt,-Nt);return n.jsxs("group",{position:[f,p,b],rotation:[0,-M,0],onClick:h,onContextMenu:r?x:void 0,children:[Rt&&i&&n.jsx(o2,{w:g,h:w,f:v,direction:it,sketchupLookEnabled:a}),[1,-1].map(he=>n.jsxs("mesh",{position:[0,-C,he*(k/2+.003)],renderOrder:2,children:[n.jsx("shapeGeometry",{args:[Pt]}),n.jsx("meshStandardMaterial",{color:s,roughness:.4,metalness:0,emissive:s,emissiveIntensity:c,side:kn,polygonOffset:!0,polygonOffsetFactor:-4})]},`arched-wall-infill-${he}`)),n.jsx(oc,{open:l,pivotX:_t,rotAxis:"y",openAngle:Ft,children:tt?n.jsxs("mesh",{position:[0,-C,0],...P,children:[n.jsx("shapeGeometry",{args:[gt]}),n.jsx("meshPhysicalMaterial",{color:Sc,transparent:!0,opacity:.2,roughness:.02,metalness:0,transmission:.95,thickness:.02,ior:1.45,side:kn,depthWrite:!1,polygonOffset:!0,polygonOffsetFactor:-1})]}):n.jsxs("mesh",{position:[0,-C,0],...N,children:[n.jsx("shapeGeometry",{args:[gt]}),n.jsx("meshStandardMaterial",{color:Mt,roughness:.64,metalness:.04,side:kn})]})}),n.jsxs("mesh",{position:[0,v/2-C,0],...N,children:[n.jsx("boxGeometry",{args:[g,v,k*.7]}),n.jsx("meshStandardMaterial",{color:Qr,metalness:.6,roughness:.3})]}),n.jsxs("mesh",{position:[-g/2+v/2,kt/2-C/2,0],...N,children:[n.jsx("boxGeometry",{args:[v,kt+C,k*.7]}),n.jsx("meshStandardMaterial",{color:Qr,metalness:.6,roughness:.3})]}),n.jsxs("mesh",{position:[g/2-v/2,kt/2-C/2,0],...N,children:[n.jsx("boxGeometry",{args:[v,kt+C,k*.7]}),n.jsx("meshStandardMaterial",{color:Qr,metalness:.6,roughness:.3})]}),n.jsx(Jn,{points:Lt,color:Qr,lineWidth:6,renderOrder:4}),n.jsx(Jn,{points:oe,color:Qr,lineWidth:6,renderOrder:4}),Rt&&n.jsx(C5,{hingeSign:st,w:g,h:w,f:v,sketchupLookEnabled:a}),n.jsx(oc,{open:l,pivotX:_t,rotAxis:"y",openAngle:Ft,children:[1,-1].map(he=>n.jsxs("group",{position:[ct,w*.42,he*.033],children:[n.jsxs("mesh",{...N,children:[n.jsx("boxGeometry",{args:[.014,.11,.018]}),n.jsx("meshStandardMaterial",{color:Lh,metalness:.85,roughness:.18})]}),n.jsxs("mesh",{position:[pt*.035,.012,0],...N,children:[n.jsx("boxGeometry",{args:[.075,.016,.018]}),n.jsx("meshStandardMaterial",{color:Lh,metalness:.85,roughness:.18})]})]},he))}),i&&n.jsxs("mesh",{position:[0,w/2,0],children:[n.jsx("boxGeometry",{args:[g+.04,w+.04,k+.04]}),n.jsx(xo,{color:"#3B82F6",lineWidth:3}),n.jsx("meshBasicMaterial",{visible:!1})]})]})}if(G){const kt=Math.max(.02,k-.005),Et=Math.max(.006,Math.min(.012,g*.018)),ht=k/2+.0015;return n.jsxs("group",{position:[f,p,b],rotation:[0,-M,0],onClick:h,onContextMenu:r?x:void 0,children:[n.jsx(oc,{open:l,pivotX:st*(g/2),rotAxis:"y",openAngle:Ft,children:n.jsx(ml,{fallback:n.jsxs("mesh",{position:[0,w/2-C/2,0],...N,children:[n.jsx("boxGeometry",{args:[g,w+C,kt]}),n.jsx("meshStandardMaterial",{color:Mt,roughness:.72,metalness:.03})]}),children:n.jsx(s2,{w:g,h:w+C,yCenter:w/2-C/2,color:Mt,front:(Tt=t.panelCladding)==null?void 0:Tt.front,back:(Zt=t.panelCladding)==null?void 0:Zt.back,depth:kt,zCenter:0,sketchupLookEnabled:a})})}),[1,-1].map(gt=>n.jsxs("group",{children:[n.jsxs("mesh",{position:[0,w-Et/2,gt*ht],...N,children:[n.jsx("boxGeometry",{args:[g,Et,.004]}),n.jsx("meshStandardMaterial",{color:"#171717",roughness:.55})]}),n.jsxs("mesh",{position:[-g/2+Et/2,w/2-C/2,gt*ht],...N,children:[n.jsx("boxGeometry",{args:[Et,w+C,.004]}),n.jsx("meshStandardMaterial",{color:"#171717",roughness:.55})]}),n.jsxs("mesh",{position:[g/2-Et/2,w/2-C/2,gt*ht],...N,children:[n.jsx("boxGeometry",{args:[Et,w+C,.004]}),n.jsx("meshStandardMaterial",{color:"#171717",roughness:.55})]})]},gt)),n.jsx(oc,{open:l,pivotX:st*(g/2),rotAxis:"y",openAngle:Ft,children:[1,-1].map(gt=>n.jsxs("group",{position:[ct,w*.42,gt*(k/2+.009)],children:[n.jsxs("mesh",{...N,children:[n.jsx("boxGeometry",{args:[.014,.11,.018]}
199),n.jsx("meshStandardMaterial",{color:Lh,metalness:.85,roughness:.18})]}),n.jsxs("mesh",{position:[pt*.035,.012,0],...N,children:[n.jsx("boxGeometry",{args:[.075,.016,.018]}),n.jsx("meshStandardMaterial",{color:Lh,metalness:.85,roughness:.18})]})]},`handle-${gt}`))}),i&&n.jsxs("mesh",{position:[0,w/2,0],children:[n.jsx("boxGeometry",{args:[g+.04,w+.04,k+.04]}),n.jsx(xo,{color:"#3B82F6",lineWidth:3}),n.jsx("meshBasicMaterial",{visible:!1})]})]})}if(vt){const kt=w-v+C,Et=w/2-C/2,ht=g/2-v,gt=Math.max(.1,ht-v),Pt=U=>{var pe,Ge;const mt=U*(g/4),Nt=U*(g/2-v),Lt=U,oe=xt*Lt*D5,he=mt-Lt*(gt/2-v*1.5);return n.jsxs(oc,{open:l,pivotX:Nt,rotAxis:"y",openAngle:oe,children:[tt?n.jsxs("mesh",{position:[mt,Et,0],...P,children:[n.jsx("boxGeometry",{args:[gt,kt,.012]}),n.jsx("meshPhysicalMaterial",{color:Sc,transparent:!0,opacity:.18,roughness:.02,metalness:0,transmission:.95,thickness:.02,ior:1.45,side:kn,depthWrite:!1,polygonOffset:!0,polygonOffsetFactor:-1})]}):n.jsx(ml,{fallback:n.jsxs("mesh",{position:[mt,Et,0],...N,children:[n.jsx("boxGeometry",{args:[gt,kt,.04]}),n.jsx("meshStandardMaterial",{color:Mt,roughness:.6,metalness:.05})]}),children:n.jsx("group",{position:[mt,0,0],children:n.jsx(s2,{w:gt,h:kt,yCenter:Et,color:Mt,front:(pe=t.panelCladding)==null?void 0:pe.front,back:(Ge=t.panelCladding)==null?void 0:Ge.back,sketchupLookEnabled:a})})}),[1,-1].map(Qt=>n.jsxs("mesh",{position:[he,w*.45,Qt*.033],...N,children:[n.jsx("boxGeometry",{args:[.014,.11,.018]}),n.jsx("meshStandardMaterial",{color:Lh,metalness:.85,roughness:.18})]},Qt))]},U)};return n.jsxs("group",{position:[f,p,b],rotation:[0,-M,0],onClick:h,onContextMenu:r?x:void 0,children:[Rt&&i&&n.jsx(o2,{w:g,h:w,f:v,direction:it,sketchupLookEnabled:a}),n.jsxs("mesh",{position:[0,w-v/2,0],...N,children:[n.jsx("boxGeometry",{args:[g,v,k*.7]}),n.jsx("meshStandardMaterial",{color:Qr,metalness:.6,roughness:.3})]}),n.jsxs("mesh",{position:[-g/2+v/2,w/2-C/2,0],...N,children:[n.jsx("boxGeometry",{args:[v,w+C,k*.7]}),n.jsx("meshStandardMaterial",{color:Qr,metalness:.6,roughness:.3})]}),n.jsxs("mesh",{position:[g/2-v/2,w/2-C/2,0],...N,children:[n.jsx("boxGeometry",{args:[v,w+C,k*.7]}),n.jsx("meshStandardMaterial",{color:Qr,metalness:.6,roughness:.3})]}),Pt(-1),Pt(1),i&&n.jsxs("mesh",{position:[0,w/2,0],children:[n.jsx("boxGeometry",{args:[g+.04,w+.04,k+.04]}),n.jsx(xo,{color:"#3B82F6",lineWidth:3}),n.jsx("meshBasicMaterial",{visible:!1})]})]})}return n.jsxs("group",{position:[f,p,b],rotation:[0,-M,0],onClick:h,onContextMenu:r?x:void 0,children:[Rt&&i&&n.jsx(o2,{w:g,h:w,f:v,direction:it,sketchupLookEnabled:a}),n.jsxs(oc,{open:l,pivotX:_t,rotAxis:"y",openAngle:Ft,children:[tt?n.jsxs("mesh",{position:[0,w/2-C/2,0],...P,children:[n.jsx("boxGeometry",{args:[g-v*2,w-v+C,.012]}),n.jsx("meshPhysicalMaterial",{color:Sc,transparent:!0,opacity:.18,roughness:.02,metalness:0,transmission:.95,thickness:.02,ior:1.45,side:kn,depthWrite:!1,polygonOffset:!0,polygonOffsetFactor:-1})]}):n.jsx(ml,{fallback:n.jsxs("mesh",{position:[0,w/2-C/2,0],...N,children:[n.jsx("boxGeometry",{args:[g-v*2,w-v+C,.04]}),n.jsx("meshStandardMaterial",{color:Mt,roughness:.6,metalness:.05})]}),children:n.jsx(s2,{w:g-v*2,h:w-v+C,yCenter:w/2-C/2,color:Mt,front:(At=t.panelCladding)==null?void 0:At.front,back:(ut=t.panelCladding)==null?void 0:ut.back,sketchupLookEnabled:a})}),[1,-1].map(kt=>n.jsxs("group",{position:[ct,w*.45,kt*.033],children:[n.jsxs("mesh",{...N,children:[n.jsx("boxGeometry",{args:[.014,.11,.018]}),n.jsx("meshStandardMaterial",{color:Lh,metalness:.85,roughness:.18})]}),n.jsxs("mesh",{position:[pt*.035,.012,0],...N,children:[n.jsx("boxGeometry",{args:[.075,.016,.018]}),n.jsx("meshStandardMaterial",{color:Lh,metalness:.85,roughness:.18})]})]},kt))]}),n.jsxs("mesh",{position:[0,w-v/2,0],...N,children:[n.jsx("boxGeometry",{args:[g,v,k*.7]}),n.jsx("meshStandardMaterial",{color:Qr,metalness:.6,roughness:.3})]}),n.jsxs("mesh",{position:[-g/2+v/2,w/2-C/2,0],...N,children:[n.jsx("boxGeometry",{args:[v,w+C,k*.7]}),n.jsx("meshStandardMaterial",{color:Qr,metalness:.6,roughness:.3})]}),n.jsxs("mesh",{position:[g/2-v/2,w/2-C/2,0],...N,children:[n.jsx("boxGeometry",{args:[v,w+C,k*.7]}),n.jsx("meshStandardMaterial",{color:Qr,metalness:.6,roughness:.3})]}),Rt&&n.jsx(C5,{hingeSign:st,w:g,h:w,f:v,sketchupLookEnabled:a}),i&&n.jsxs("mesh",{position:[0,w/2,0],children:[n.jsx("boxGeometry",{args:[g+.04,w+.04,k+.04]}),n.jsx(xo,{color:"#3B82F6",lineWidth:3}),n.jsx("meshBasicMaterial",{visible:!1})]})]})}function C5({hingeSign:t,w:e,h:s,f:o,z:r=.038,sketchupLookEnabled:i=!1}){const a=i?{castShadow:!0,receiveShadow:!0}
199:{},l=t*(e/2-o*.5);return n.jsx(n.Fragment,{children:[.28,.5,.72].map(c=>n.jsxs("mesh",{position:[l,s*c,r],...a,children:[n.jsx("boxGeometry",{args:[.022,.12,.022]}),n.jsx("meshStandardMaterial",{color:"#2a2522",metalness:.7,roughness:.24})]},c))})}function o2({w:t,h:e,f:s,direction:o,sketchupLookEnabled:r=!1}){const i=o.hingeSide==="right"?t/2-s:-t/2+s,a=Math.max(.35,t-s*2),l=o.swingFace==="front"?1:-1,c=o.hingeSide==="right"?Math.PI:0,d=o.hingeSide==="right"?Math.PI-l*Math.PI/2:l*Math.PI/2,u=24,h=Array.from({length:u+1},(v,C)=>{const N=C/u,P=c+(d-c)*N;return[i+Math.cos(P)*a,.024,Math.sin(P)*a]}),x=[i+Math.cos(d)*a/2,e/2,Math.sin(d)*a/2],f=h[h.length-1],p=h[Math.max(0,h.length-4)],b=Math.atan2(f[2]-p[2],f[0]-p[0]),M=.11,g=b+Math.PI*.78,w=b-Math.PI*.78,k=[f[0]+Math.cos(g)*M,.024,f[2]+Math.sin(g)*M],_=[f[0]+Math.cos(w)*M,.024,f[2]+Math.sin(w)*M],j=r?{receiveShadow:!0}:{};return n.jsxs(n.Fragment,{children:[n.jsx(Jn,{points:h,color:"#D84B2E",lineWidth:2.5,transparent:!0,opacity:.9}),n.jsx(Jn,{points:[k,f,_],color:"#D84B2E",lineWidth:2.5,transparent:!0,opacity:.9}),n.jsxs("mesh",{position:x,rotation:[0,-d,0],...j,children:[n.jsx("boxGeometry",{args:[a,Math.max(.4,e-s),.018]}),n.jsx("meshStandardMaterial",{color:"#F4A99A",transparent:!0,opacity:.28,roughness:.35,depthWrite:!1})]})]})}function s2({w:t,h:e,yCenter:s,color:o,front:r,back:i,depth:a=.04,zCenter:l=0,sketchupLookEnabled:c=!1}){const d="/textures/floors/tiles-white.jpg",u=!!(r!=null&&r.url&&(r!=null&&r.tileSizeM)),h=!!(i!=null&&i.url&&(i!=null&&i.tileSizeM)),x=Ya((r==null?void 0:r.url)||d),f=Ya((i==null?void 0:i.url)||(r==null?void 0:r.url)||d),{gl:p}=Vo(),b=m.useMemo(()=>{const M=new Vu({color:o,roughness:.6,metalness:.05}),g=u?Od(x,t,e,[Number(r.tileSizeM[0]),Number(r.tileSizeM[1])],void 0,p,r.orientation):new Vu({color:o,roughness:.6,metalness:.05}),w=h?Od(f,t,e,[Number(i.tileSizeM[0]),Number(i.tileSizeM[1])],void 0,p,i.orientation):new Vu({color:o,roughness:.6,metalness:.05});return[M,M,M,M,g,w]},[x,f,t,e,o,r,i,u,h,p]);return n.jsx("mesh",{position:[0,s,l],material:b,castShadow:c,receiveShadow:c,children:n.jsx("boxGeometry",{args:[t,e,a]})})}const i3={sofa:"/models/furniture/sofa.glb",sofa_2:"/models/furniture/sofa_2.glb",sofa_corner:"/models/furniture/sofa_corner.glb",sofa_3seat:"/models/furniture/sofa_3seat.glb",loveseat:"/models/furniture/loveseat.glb",armchair:"/models/furniture/armchair.glb",armchair_2:"/models/furniture/armchair_2.glb",armchair_wing:"/models/furniture/armchair_wing.glb",recliner:"/models/furniture/recliner.glb",pouf:"/models/furniture/pouf.glb",table:"/models/furniture/table.glb",coffee_table:"/models/furniture/coffee_table.glb",side_table:"/models/furniture/side_table.glb",console_table:"/models/furniture/console_table.glb",tv_unit:"/models/furniture/tv_unit.glb",tv_wall_unit:"/models/furniture/tv_wall_unit.glb",bookcase:"/models/furniture/bookcase.glb",shelf_wall:"/models/furniture/shelf_wall.glb",display_cabinet:"/models/furniture/display_cabinet.glb",rug_rect:"/models/furniture/rug_rect.glb",rug_round:"/models/furniture/rug_round.glb",bed:"/models/furniture/bed.glb",bed_single:"/models/furniture/bed_single.glb",bed_king:"/models/furniture/bed_king.glb",bed_bunk:"/models/furniture/bed_bunk.glb",nightstand:"/models/furniture/nightstand.glb",nightstand_wide:"/models/furniture/nightstand_wide.glb",dresser:"/models/furniture/dresser.glb",dresser_tall:"/models/furniture/dresser_tall.glb",vanity_table:"/models/furniture/vanity_table.glb",wardrobe:"/models/furniture/wardrobe.glb",mirror_wall:"/models/furniture/mirror_wall.glb",dining_table:"/models/furniture/dining_table.glb",dining_table_round:"/models/furniture/dining_table_round.glb",dining_table_ext:"/models/furniture/dining_table_ext.glb",chair:"/models/furniture/chair.glb",dining_chair_up:"/models/furniture/chair_2.glb",bench_dining:"/models/furniture/bench_dining.glb",sideboard:"/models/furniture/sideboard.glb",bar_stool:"/models/furniture/bar_stool.glb",bar_table:"/models/furniture/bar_table.glb",cabinet_lower:"/models/furniture/cabinet_lower.glb",cabinet_upper:"/models/furniture/cabinet_upper.glb",cabinet_tall:"/models/furniture/cabinet_tall.glb",cabinet_corner:"/models/furniture/cabinet_corner.glb",kitchen_island:"/models/furniture/kitchen_island.glb",kitchen_island_l:"/models/furniture/kitchen_island_l.glb",fridge:"/models/furniture/fridge.glb",fridge_double:"/models/furniture/fridge_double.glb",stove:"/models/furniture/stove.glb",oven_builtin:"/models/furniture/oven_builtin.glb",range_hood:"/models/furniture/range_hood.glb",microwave:"/models/furniture/microwave.glb",dishwasher:"/models/furniture/dishwasher.glb",kitchen_sink:"/models/furniture/kitchen_sink.glb",bathtub:"/models/furniture/bathtub.glb",shower:"/models/furniture/shower.glb",shower_walk_in:"/models/furniture/shower_walk_in.glb",toilet:"/models/furniture/toilet.glb",toilet_wall:"/models/furniture/toilet_wall.glb",bathroom_sink:"/models/furniture/bathroom_sink.glb",vanity:"/models/furniture/vanity.glb",vanity_double:"/models/furniture/vanity_double.glb",washer:"/models/furniture/washer.glb",dryer:"/models/furniture/dryer.glb",desk:"/models/furniture/desk.glb",desk_l_shape:"/models/furniture/desk_l_shape.glb",office_chair:"/models/furniture/office_chair.glb",office_chair_ex:"/models/furniture/office_chair_ex.glb",shelf_unit:"/models/furniture/shelf_unit.glb",closet_wide:"/models/furniture/closet_wide.glb",closet_shoe:"/models/furniture/closet_shoe.glb"},sc={active:!1,x:0,z:0};function yP({furniture:t,customModelUrls:e,materialSlots:s,isSelected:o,rotateDialActive:r,selectedSmartSlotId:i,selectOnDoubleClick:a,smartPartPickingActive:l,onClick:c,onSmartPartClick:d,onContextMenu:u,onDrag:h,onDragDelta:x,onRotate:f,onDuplicate:p,onFlip:b,onDelete:M,onResize:g,sketchupLookEnabled:w=!1,sketchupModelEdgesEnabled:k=w,sketchupEdgeOpacity:_=.92,onSketchupEdgeCountChange:j}){const v=t.position.x*rt,C=t.position.y*rt,[N,P]=m.useState(null),L=m.useRef(null),A=N??t.rotation,W=-(A*Math.PI)/180,[S,B]=m.useState(null),R=(S==null?void 0:S.w)??t.width*rt,z=(S==null?void 0:S.d)??t.depth*rt,X=(S==null?void 0:S.h)??t.height*rt,ft=m.useRef(!1),tt=m.useRef({x:0,z:0}),G=m.useRef({x:0,z:0}),Y=m.useRef(0),J=m.useRef(h),Mt=m.useRef(x);J.current=h,Mt.current=x;const Rt=m.useRef(null),it=m.useRef(!1),st=m.useRef(null);ka(()=>{const te=Rt.current;te&&(sc.active&&o?te.position.set(sc.x,0,sc.z):!it.current&&(te.position.x!==0||te.position.z!==0)&&te.position.set(0,0,0))});const{camera:ct,gl:pt}=Vo(),xt=m.useContext(zf),_t=m.useRef(new Ga(new le(0,1,0),0)),Ft=m.useRef(new Ea),Vt=m.useRef(new Po),vt=m.useRef(new le),Ht=m.useCallback((te,Be)=>{const wt=pt.domElement.getBoundingClientRect();return Vt.current.set((te-wt.left)/wt.width*2-1,-((Be-wt.top)/wt.height)*2+1),_t.current.constant=-xt,Ft.current.setFromCamera(Vt.current,ct),Ft.current.ray.intersectPlane(_t.current,vt.current),{x:vt.current.x,z:vt.current.z}},[ct,pt,xt]),Tt=m.useRef(!1),Zt=m.useRef(0),At=m.useCallback(te=>{!a||!c||(te.stopPropagation(),Zt.current=performance.now(),c(te.nativeEvent.metaKey||te.nativeEvent.ctrlKey))},[a,c]),ut=m.useCallback(te=>
199{if(performance.now()-Zt.current<450){te.stopPropagation();return}if(!(a&&!o&&!Tt.current)&&!(!c||ft.current)){if(te.stopPropagation(),Tt.current){Tt.current=!1;return}c(te.nativeEvent.metaKey||te.nativeEvent.ctrlKey)}},[c,a,o]),kt=m.useCallback(te=>{const Be=te.nativeEvent.metaKey||te.nativeEvent.ctrlKey;if(a&&!o){if(Be&&c){te.stopPropagation(),c(Be),Tt.current=!0;return}return}if(te.stopPropagation(),!o&&c&&(c(Be),Tt.current=!0),!h&&!x)return;ft.current=!1,Y.current=Date.now(),tt.current={x:te.point.x-v,z:te.point.z-C},G.current={x:v,z:C},st.current=null;const wt=()=>{window.removeEventListener("pointermove",Ne),window.removeEventListener("pointerup",Le),window.removeEventListener("keydown",is)},ve=()=>{var Fe;it.current=!1,sc.active=!1,sc.x=0,sc.z=0,(Fe=Rt.current)==null||Fe.position.set(0,0,0)},Ne=Fe=>{var en;if(Y.current===0||Date.now()-Y.current<100)return;ft.current=!0;const bn=Ht(Fe.clientX,Fe.clientY),Ve={x:bn.x-tt.current.x,z:bn.z-tt.current.z};st.current=Ve,Mt.current?(sc.active=!0,sc.x=Ve.x-G.current.x,sc.z=Ve.z-G.current.z):J.current&&(it.current=!0,(en=Rt.current)==null||en.position.set(Ve.x-v,0,Ve.z-C))},Le=()=>{if(Y.current=0,wt(),ft.current&&st.current)if(Mt.current){const Fe={x:sc.x,z:sc.z};(Fe.x!==0||Fe.z!==0)&&Mt.current(Fe)}else J.current&&J.current(st.current);st.current=null,ve(),setTimeout(()=>{ft.current=!1},50)},is=Fe=>{Fe.key==="Escape"&&(Y.current=0,wt(),st.current=null,ve(),setTimeout(()=>{ft.current=!1},50))};window.addEventListener("pointermove",Ne),window.addEventListener("pointerup",Le),window.addEventListener("keydown",is)},[h,x,o,c,a,v,C,Ht]),Et=(e==null?void 0:e[t.type])||i3[t.type],ht=m.useCallback(te=>{u&&(te.stopPropagation(),te.nativeEvent.preventDefault(),u({x:te.nativeEvent.clientX,y:te.nativeEvent.clientY}))},[u]),gt=!!(c||u||h||x),Pt=gt?{onClick:ut,onPointerDown:kt,...u?{onContextMenu:ht}:{},...a?{onDoubleClick:At}:{}}:{},U=m.useCallback((te,Be)=>{ft.current||(Tt.current||c==null||c(Be),Tt.current=!1,d==null||d(te,Be))},[c,d]),mt=!!i,Nt=mt?"#93C5FD":"#3B82F6",Lt=mt?1.5:3,oe=m.useCallback(te=>{j==null||j(t.id,te)},[t.id,j]),he=o&&!l&&n.jsxs(n.Fragment,{children:[n.jsxs("mesh",{position:[v,X/2,C],rotation:[0,W,0],children:[n.jsx("boxGeometry",{args:[R+.04,X+.
19904,z+.04]}),n.jsx(xo,{color:Nt,lineWidth:Lt}),n.jsx("meshBasicMaterial",{visible:!1})]}),r&&f&&n.jsx(kP,{x:v,z:C,w:R,d:z,h:X,rotationDeg:A,onRotate:te=>{L.current=te,P(te)},onRotateEnd:()=>{L.current!=null&&f(L.current),L.current=null,P(null)}}),g&&n.jsx("group",{position:[v,0,C],rotation:[0,W,0],children:[[1,1],[-1,1],[1,-1],[-1,-1]].map(([te,Be],wt)=>n.jsx(NP,{sx:te,sz:Be,w:R,d:z,h:X,cx:v,cz:C,rad:W,onResize:(ve,Ne,Le)=>{g(ve,Ne,Le),B(null)},onResizeLive:(ve,Ne,Le)=>B({w:ve,d:Ne,h:Le}),onResizeCancel:()=>B(null)},wt))})]}),pe=t.flipped?-1:1,Ge=!!(s!=null&&s.length&&d),Qt=gt&&!Ge&&n.jsxs("mesh",{...Pt,position:[v,X/2,C],rotation:[0,W,0],children:[n.jsx("boxGeometry",{args:[Math.max(R,.25),Math.max(X,.25),Math.max(z,.25)]}),n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthWrite:!1})]});return Et?n.jsxs("group",{ref:Rt,...Pt,children:[Qt,n.jsx(m.Suspense,{fallback:n.jsx(S5,{x:v,z:C,w:R,d:z,h:X,rad:W,isSelected:o,sketchupLookEnabled:w,sketchupModelEdgesEnabled:k}),children:n.jsx(SP,{url:Et,preserveSourceMaterials:t.type.startsWith("blender_"),x:v,z:C,w:R,d:z,h:X,rad:W,flipX:pe,materialSlots:s,materialOverrides:t.materialOverrides,selectedSlotId:i,showPartGuides:l,onPartClick:d?U:void 0,onContextMenu:u,sketchupLookEnabled:w,sketchupModelEdgesEnabled:k,sketchupEdgeOpacity:_,onSketchupEdgeCountChange:oe})}),he]}):n.jsxs("group",{ref:Rt,...Pt,children:[Qt,n.jsx(S5,{x:v,z:C,w:R,d:z,h:X,rad:W,isSelected:o,sketchupLookEnabled:w,sketchupModelEdgesEnabled:k}),he]})}const wP=m.memo(function({furn:e,customModelUrls:s,materialSlots:o,isSelected:r,isMulti:i,rotateDialActive:a,selectedSmartSlotId:l,selectOnDoubleClick:c,smartPartPickingActive:d,canSelect:u,canTransform:h,canPickSmartPart:x,onFurnitureClick:f,onSmartGlbPartSelect:p,onFurnitureContextMenu:b,onFurnitureMove:M,onFurnitureGroupMove:g,onFurnitureRotate:w,onFurnitureDuplicate:k,onFurnitureFlip:_,onFurnitureDelete:j,onFurnitureResize:v,sketchupLookEnabled:C,sketchupModelEdgesEnabled:N,sketchupEdgeOpacity:P,onSketchupEdgeCountChange:L}){const A=e.id,W=m.useCallback(Y=>f==null?void 0:f(A,Y),[A,f]),S=m.useCallback(Y=>p==null?void 0:p(A,Y),[A,p]),B=m.useCallback(Y=>b==null?void 0:b(A,Y),[A,b]),R=m.useCallback(Y=>M==null?void 0:M(A,Y),[A,M]),z=m.useCallback(Y=>w==null?void 0:w(A,Y),[A,w]),X=m.useCallback(()=>k==null?void 0:k(A),[A,k]),ft=m.useCallback(()=>_==null?void 0:_(A),[A,_]),tt=m.useCallback(()=>j==null?void 0:j(A),[A,j]),G=m.useCallback((Y,J,Mt)=>v==null?void 0:v(A,Y,J,Mt),[A,v]);return n.jsx(yP,{furniture:e,customModelUrls:s,materialSlots:o,isSelected:r,rotateDialActive:a,selectedSmartSlotId:l,selectOnDoubleClick:c,smartPartPickingActive:d,onClick:u&&f?W:void 0,onSmartPartClick:x?S:void 0,onContextMenu:u&&b?B:void 0,onDrag:h&&!(r&&i)&&M?R:void 0,onDragDelta:h&&r&&i&&g?g:void 0,onRotate:h&&w?z:void 0,onDuplicate:h&&k?X:void 0,onFlip:h&&_?ft:void 0,onDelete:h&&j?tt:void 0,onResize:h&&v?G:void 0,sketchupLookEnabled:C,sketchupModelEdgesEnabled:N,sketchupEdgeOpacity:P,onSketchupEdgeCountChange:L})});function kP({x:t,z:e,w:s,d:o,h:r,rotationDeg:i,onRotate:a,onRotateEnd:l}){const{camera:c,gl:d}=Vo(),u=Math.max(r+JS,QS),h=Math.max(Math.max(s,o)*.58+tP,.85),x=Math.max(.08,h-.028),f=h+.028,p=h+.24,b=Math.max(0,h-.22),M=N5(i),g=-M*Math.PI/180,w=Math.cos(g)*h,k=Math.sin(g)*h,_=36,j=m.useMemo(()=>Array.from({length:_},(W,S)=>S),[_]),v=m.useRef(null);v.current||(v.current={ndc:new Po,raycaster:new Ea,plane:new Ga(new le(0,1,0),0),hit:new le});const C=m.useContext(zf),N=m.useCallback((W,S)=>{const B=d.domElement.getBoundingClientRect();if(B.width<=0||B.height<=0)return;const{ndc:R,raycaster:z,plane:X,hit:ft}=v.current;if(X.constant=-C,R.set((W-B.left)/B.width*2-1,-((S-B.top)/B.height)*2+1),z.setFromCamera(R,c),!z.ray.intersectPlane(X,ft))return;const tt=Math.atan2(ft.z-e,ft.x-t)*180/Math.PI;a(N5(-tt))},[c,d.domElement,C,a,t,e]),P=m.useCallback(W=>{W.stopPropagation(),N(W.nativeEvent.clientX,W.nativeEvent.clientY),document.body.style.cursor="grabbing";const S=R=>{N(R.clientX,R.clientY)},B=()=>{document.body.style.cursor="",window.removeEventListener("pointermove",S),window.removeEventListener("pointerup",B),l==null||l()};window.addEventListener("pointermove",S),window.addEventListener("pointerup",B)},[N,l]),L=()=>{document.body.style.cursor="grab"},A=()=>{document.body.style.cursor=""};return n.jsxs("group",{position:[t,u,e],renderOrder:9999,children:[n.jsx(Uu,{position:[0,.16,0],center:!0,distanceFactor:8,zIndexRange:[70,0],children:n.jsxs("span",{className:"pointer-events-none whitespace-nowrap rounded-[4px] border border-[#336CFF]/20 bg-white/90 px-1.5 py-0.5 font-heebo text-[10px] font-bold leading-none tabular-nums text-[#182137] shadow-sm",children:[vP(M),"°"]})}),n.jsxs("mesh",{rotation:[-Math.PI/2,0,0],raycast:()=>{},renderOrder:9999,children:[n.jsx("ringGeometry",{args:[x,f,96]}),n.jsx("meshBasicMaterial",{color:"#336CFF",transparent:!0,opacity:.82,depthTest:!1,depthWrite:!1,side:kn})]}),j.map(W=>{const S=W/_*Math.PI*2,B=W%4===0,R=B?.155:.095,z=B?.155:.08,X=Math.cos(S)*(h-R),ft=Math.sin(S)*(h-R),tt=M
199ath.cos(S)*(h+z),G=Math.sin(S)*(h+z);return n.jsx(Jn,{raycast:()=>{},points:[[X,.012,ft],[tt,.012,G]],color:B?"#182137":"#336CFF",lineWidth:B?2.25:1.2,depthTest:!1,renderOrder:9999},W)}),n.jsx(Jn,{raycast:()=>{},points:[[0,.018,0],[w,.018,k]],color:"#D85D43",lineWidth:1.35,depthTest:!1,renderOrder:1e4}),n.jsxs("mesh",{position:[w,.045,k],onPointerDown:P,onPointerOver:L,onPointerOut:A,renderOrder:10001,children:[n.jsx("sphereGeometry",{args:[.085,24,16]}),n.jsx("meshBasicMaterial",{color:"#D85D43",depthTest:!1,depthWrite:!1})]}),n.jsxs("mesh",{rotation:[-Math.PI/2,0,0],onPointerDown:P,onPointerOver:L,onPointerOut:A,renderOrder:1e4,children:[n.jsx("ringGeometry",{args:[b,p,48]}),n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthTest:!1,depthWrite:!1,side:kn})]})]})}function N5(t){return(Math.round(t/b5)*b5%360+360)%360}function vP(t){return Number.isInteger(t)?String(t):t.toFixed(1)}function r2({polygon:t,tileOrigin:e,tileSizeM:s,stackIndex:o,onCommit:r}){const{camera:i,gl:a}=Vo(),l=m.useContext(zf),c=m.useMemo(()=>QE(t),[t]),d=m.useMemo(()=>jP(t,e,s),[t,e,s]),u=m.useCallback(()=>{const x=a.domElement;if(!x)return;const f=x.getBoundingClientRect(),p=new Ga(new le(0,1,0),-l),b=new Ea,M=new Po,g=new le,w=_=>{if(M.x=(_.clientX-f.left)/f.width*2-1,M.y=-((_.clientY-f.top)/f.height)*2+1,b.setFromCamera(M,i),!b.ray.intersectPlane(p,g))return;const j=L1(g.x/rt,c.minX,c.maxX),v=L1(g.z/rt,c.minY,c.maxY);r({xMm:Math.round(j),yMm:Math.round(v)})},k=()=>{document.body.style.cursor="",window.removeEventListener("pointermove",w),window.removeEventListener("pointerup",k)};document.body.style.cursor="grab",window.addEventListener("pointermove",w),window.addEventListener("pointerup",k)},[c,i,a,l,r]);if(!d)return null;const h=.42+o*1e-4;return n.jsxs("group",{position:[d.x*rt,h,d.y*rt],children:[n.jsxs("mesh",{onPointerDown:x=>{x.stopPropagation(),u()},onPointerOver:x=>{x.stopPropagation(),document.body.style.cursor="grab"},onPointerOut:()=>{document.body.style.cursor=""},children:[n.jsx("sphereGeometry",{args:[.26,16,16]}),n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthWrite:!1,depthTest:!1})]}),n.jsxs("mesh",{renderOrder:10020,onPointerDown:x=>{x.stopPropagation(),u()},onPointerOver:x=>{x.stopPropagation(),document.body.style.cursor="grab"},onPointerOut:()=>{document.body.style.cursor=""},children:[n.jsx("sphereGeometry",{args:[.16,24,24]}),n.jsx("meshBasicMaterial",{color:"#ffffff",depthTest:!1})]}),n.jsxs("mesh",{renderOrder:10021,onPointerDown:x=>{x.stopPropagation(),u()},onPointerOver:x=>{x.stopPropagation(),document.body.style.cursor="grab"},onPointerOut:()=>{document.body.style.cursor=""},children:[n.jsx("sphereGeometry",{args:[.11,24,24]}),n.jsx("meshBasicMaterial",{color:"#ff3b30",depthTest:!1})]}),n.jsxs("mesh",{rotation:[-Math.PI/2,0,0],renderOrder:10019,onPointerDown:x=>{x.stopPropagation(),u()},onPointerOver:x=>{x.stopPropagation(),document.body.style.cursor="grab"},onPointerOut:()=>{document.body.style.cursor=""},children:[n.jsx("ringGeometry",{args:[.2,.26,32]}),n.jsx("meshBasicMaterial",{color:"#ff3b30",transparent:!0,opacity:.25,depthTest:!1,side:kn})]})]})}function jP(t,e,s){if(t.length<3)return null;const o=QE(t),r=Math.max(s[0]*1e3,1),i=Math.max(s[1]*1e3,1),a=Number.isFinite(e.xMm)?e.xMm:0,l=Number.isFinite(e.yMm)?e.yMm:0;if(a>=o.minX&&a<=o.maxX&&l>=o.minY&&l<=o.maxY&&S1({x:a,y:l},t))return{x:a,y:l};const d=a+Math.ceil((o.minX-a)/r)*r,u=l+Math.ceil((o.minY-l)/i)*i,h=120;let x=0;for(let f=d;f<=o.maxX&&x<h;f+=r)for(let p=u;p<=o.maxY&&x<h;p+=i)if(x++,S1({x:f,y:p},t))return{x:f,y:p};return{x:L1(a,o.minX,o.maxX),y:L1(l,o.minY,o.maxY)}}function QE(t){let e=1/0,s=-1/0,o=1/0,r=-1/0;for(const i of t)i.x<e&&(e=i.x),i.x>s&&(s=i.x),i.y<o&&(o=i.y),i.y>r&&(r=i.y);return{minX:e,maxX:s,minY:o,maxY:r}}function L1(t,e,s){return Math.min(s,Math.max(e,t))}function _P({polygon:t,roomPolygon:e,onCommit:s}){const{camera:o,gl:r}=Vo(),i=m.useContext(zf),a=m.useMemo(()=>{let d=1/0,u=-1/0,h=1/0,x=-1/0;for(const f of t)f.x<d&&(d=f.x),f.x>u&&(u=f.x),f.y<h&&(h=f.y),f.y>x&&(x=f.y);return[{x:d,y:h},{x:u,y:h},{x:u,y:x},{x:d,y:x}]},[t]),l=m.useMemo(()=>{let d=1/0,u=-1/0,h=1/0,x=-1/0;for(const f of e)f.x<d&&(d=f.x),f.x>u&&(u=f.x),f.y<h&&(h=f.y),f.y>x&&(x=f.y);return{minX:d,maxX:u,minY:h,maxY:x}},[e]),c=m.useCallback(d=>{const u=r.domElement;if(!u)return;const h=u.getBoundingClientRect(),x=new Ga(new le(0,1,0),-i),f=new Ea,p=new Po,b=new le,M={...a[(d+2)%4]},g={...a[d]};let w=null;
199const k=100,_=v=>{if(p.x=(v.clientX-h.left)/h.width*2-1,p.y=-((v.clientY-h.top)/h.height)*2+1,f.setFromCamera(p,o),!f.ray.intersectPlane(x,b))return;const C=b.x/rt,N=b.z/rt;if(!w){w={x:C,y:N};return}const P=C-w.x,L=N-w.y;let A=Math.max(l.minX,Math.min(l.maxX,g.x+P)),W=Math.max(l.minY,Math.min(l.maxY,g.y+L));Math.abs(A-M.x)<k&&(A=M.x+Math.sign(A-M.x||1)*k),Math.abs(W-M.y)<k&&(W=M.y+Math.sign(W-M.y||1)*k);const S=Math.min(A,M.x),B=Math.max(A,M.x),R=Math.min(W,M.y),z=Math.max(W,M.y);s([{x:S,y:R},{x:B,y:R},{x:B,y:z},{x:S,y:z}])},j=()=>{window.removeEventListener("pointermove",_),window.removeEventListener("pointerup",j)};window.addEventListener("pointermove",_),window.addEventListener("pointerup",j)},[o,r,i,s,a,l]);return n.jsx("group",{children:a.map((d,u)=>n.jsxs("group",{position:[d.x*rt,.2,d.y*rt],children:[n.jsxs("mesh",{onPointerDown:h=>{h.stopPropagation(),c(u)},onPointerOver:h=>{h.stopPropagation(),document.body.style.cursor="grab"},onPointerOut:()=>{document.body.style.cursor=""},children:[n.jsx("sphereGeometry",{args:[.5,12,12]}),n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthWrite:!1,depthTest:!1})]}),n.jsxs("mesh",{renderOrder:9998,onPointerDown:h=>{h.stopPropagation(),c(u)},onPointerOver:h=>{h.stopPropagation(),document.body.style.cursor="grab"},onPointerOut:()=>{document.body.style.cursor=""},children:[n.jsx("sphereGeometry",{args:[.23,24,24]}),n.jsx("meshBasicMaterial",{color:"#ffffff",depthTest:!1})]}),n.jsxs("mesh",{renderOrder:9999,onPointerDown:h=>{h.stopPropagation(),c(u)},onPointerOver:h=>{h.stopPropagation(),document.body.style.cursor="grab"},onPointerOut:()=>{document.body.style.cursor=""},children:[n.jsx("sphereGeometry",{args:[.18,24,24]}),n.jsx("meshBasicMaterial",{color:"#2563eb",depthTest:!1})]})]},`v-${u}`))})}function EP({wallId:t,side:e,frame:s,regions:o,selectedWallRegionId:r,onRegionClick:i,onRemainderClick:a,onRegionPolygonChange:l}){const c=m.useMemo(()=>[{u:0,v:0},{u:s.wallLenMm,v:0},{u:s.wallLenMm,v:s.heightMm},{u:0,v:s.heightMm}],[s.wallLenMm,s.heightMm]),d=s.wallLenMm*s.heightMm,u=m.useMemo(()=>o.reduce((g,w)=>g+Math.abs(DP(w.polygon)),0),[o]),h=d>0&&u>=d*.995,x=[s.sx,0,s.sz],f=[0,-s.angle,0],p=.005,b=e==="front"?1:-1,M=(s.thicknessM/2+p)*b;return n.jsxs("group",{position:x,rotation:f,children:[!h&&a&&n.jsx(I5,{shapePolygon:c,holes:o.map(g=>g.polygon),zOffset:M,color:"#eceae4",dashed:!0,onClick:()=>a(t,e),drawOrder:v5(0)}),o.map((g,w)=>{const k=r===g.id,_=M+b*(.002+w*.002);return n.jsxs("group",{children:[n.jsx(I5,{shapePolygon:g.polygon,zOffset:_,color:g.color??(g.textureUrl&&g.textureUrl.startsWith("#")?g.textureUrl:"#cbc8c2"),textureUrl:g.textureUrl&&!g.textureUrl.startsWith("#")?g.textureUrl:void 0,tileSizeM:g.tileWidthCm||g.tileHeightCm?[(g.tileWidthCm??100)/100,(g.tileHeightCm??270)/100]:[1,2.7],orientation:g.orientation,grout:g.groutWidthMm!==void 0||g.groutColor?{widthMm:g.groutWidthMm??3,color:g.groutColor??"#c8c4bc"}:void 0,isSelected:k,onClick:i?()=>i(t,e,g.id):void 0,drawOrder:v5(w+1)}),k&&l&&n.jsx(CP,{polygon:g.polygon,frame:s,side:e,onCommit:j=>l(t,e,g.id,j)})]},g.id)})]})}function DP(t){if(t.length<3)return 0;let e=0;for(let s=0,o=t.length-1;s<t.length;o=s++)e+=(t[o].u+t[s].u)*(t[o].v-t[s].v);return e/2}function I5({shapePolygon:t,holes:e,zOffset:s,color:o,textureUrl:r,tileSizeM:i,orientation:a,grout:l,isSelected:c,dashed:d,onClick:u,drawOrder:h}){const{gl:x}=Vo(),{geometry:f,minU:p,minV:b,spanU:M,spanV:g}=m.useMemo(()=>{if(t.length<3)return{geometry:null,minU:0,minV:0,spanU:0,spanV:0};const k=new $l;k.moveTo(t[0].u*rt,t[0].v*rt);for(let P=1;P<t.length;P++)k.lineTo(t[P].u*rt,t[P].v*rt);if(e&&e.length)for(const P of e){if(P.length<3)continue;const L=new Gd;L.moveTo(P[0].u*rt,P[0].v*rt);for(let A=1;A<P.length;A++)L.lineTo(P[A].u*rt,P[A].v*rt);k.holes.push(L)}const _=new dm(k);let j=1/0,v=-1/0,C=1/0,N=-1/0;for(const P of t)P.u<j&&(j=P.u),P.u>v&&(v=P.u),P.v<C&&(C=P.v),P.v>N&&(N=P.v);return{geometry:_,minU:j*rt,minV:C*rt,spanU:(v-j)*rt,spanV:(N-C)*rt}},[t,e]);m.useLayoutEffect(()=>{if(!f||!r||M<=0||g<=0||!i)return;const k=f.attributes.position,_=new Float32Array(k.count*2),j=Xw(i,ei(a)),v=M/j[0],C=g/j[1];for(let N=0;N<k.count;N++){const P=k.getX(N),L=k.getY(N);_[N*2+0]=(P-p)/M*v,_[N*2+1]=(L-b)/g*C}f.setAttribute("uv",new cb(_,2)),f.attributes.uv.needsUpdate=!0},[f,r,i,a,p,b,M,g]);const w=!!r;return n.jsx("group",{position:[0,0,s],children:f&&n.jsxs("mesh",{geometry:f,onDoubleClick:u?k=>{k.stopPropagation(),u()}:void 0,children:[w?n.jsx(ml,{fallback:n.jsx("meshStandardMaterial",{color:o,side:kn}),children:n.jsx(FP,{url:r,spanU:M,spanV:g,tileSizeM:i??[1,2.7],orientation:a,grout:l,drawOrder:h})}):n.jsx("meshStandardMaterial",{color:o,roughness:.6,side:kn,polygonOffset:(h==null?void 0:h.polygonOffset)??!0,polygonOffsetFactor:(h==null?void 0:h.polygonOffsetFactor)??-2,polygonOffsetUnits:(h==null?void 0:h.polygonOffsetUnits)??-2,transparent:d,opacity:d?.92:1}),c&&n.jsx(xo,{scale:1,color:"#1d4ed8",lineWidth:2})]})})}function FP({url:t,spanU:e,spanV:s,tileSizeM:o,orientation:r,grout:i,drawOrder:a}){const l=Ya(t),{gl:c}=Vo(),d=m.useMemo(()=>{const u=l.clone();
199return u.needsUpdate=!0,u.wrapS=Uc,u.wrapT=Uc,u.colorSpace=gm,u.repeat.set(1,1),s3(u,ei(r)),u},[l,r]);if(m.useEffect(()=>()=>d.dispose(),[d]),m.useLayoutEffect(()=>{Rp(d,c)},[d,c]),i&&i.widthMm>0&&e>0&&s>0){const u=Xw(o,ei(r)),h=i.widthMm/(u[0]*1e3),x=i.widthMm/(u[1]*1e3);return n.jsx(UE,{texture:d,groutFraction:[h,x],groutColor:i.color,doubleSide:!0,depthSolve:a})}return n.jsx("meshStandardMaterial",{map:d,roughness:.6,metalness:.02,side:kn,polygonOffset:(a==null?void 0:a.polygonOffset)??!0,polygonOffsetFactor:(a==null?void 0:a.polygonOffsetFactor)??-2,polygonOffsetUnits:(a==null?void 0:a.polygonOffsetUnits)??-2})}const T5=.05;function CP({polygon:t,frame:e,side:s,onCommit:o}){const{camera:r,gl:i}=Vo(),a=s==="front"?1:-1,l=(e.thicknessM/2+T5)*a,c=m.useMemo(()=>{let u=1/0,h=-1/0,x=1/0,f=-1/0;for(const p of t)p.u<u&&(u=p.u),p.u>h&&(h=p.u),p.v<x&&(x=p.v),p.v>f&&(f=p.v);return[{u,v:x},{u:h,v:x},{u:h,v:f},{u,v:f}]},[t]),d=m.useCallback(u=>{const h=i.domElement;if(!h)return;const x=h.getBoundingClientRect(),f=T5,p=new le(e.fnx*a,0,e.fnz*a),b=new le((e.sx+e.ex)/2+e.fnx*(e.thicknessM/2+f)*a,e.heightM/2,(e.sz+e.ez)/2+e.fnz*(e.thicknessM/2+f)*a),M=new Ga().setFromNormalAndCoplanarPoint(p,b),g=new Ea,w=new Po,k=new le,_={...c[(u+2)%4]},j={...c[u]};let v=null;const C=50,N=L=>{if(w.x=(L.clientX-x.left)/x.width*2-1,w.y=-((L.clientY-x.top)/x.height)*2+1,g.setFromCamera(w,r),!g.ray.intersectPlane(M,k))return;const A=nP(e,{x:k.x,y:k.y,z:k.z},s,f);if(!v){v={u:A.u,v:A.v};return}const W=A.u-v.u,S=A.v-v.v;let B=Math.max(0,Math.min(e.wallLenMm,j.u+W)),R=Math.max(0,Math.min(e.heightMm,j.v+S));Math.abs(B-_.u)<C&&(B=_.u+Math.sign(B-_.u||1)*C),Math.abs(R-_.v)<C&&(R=_.v+Math.sign(R-_.v||1)*C);const z=Math.min(B,_.u),X=Math.max(B,_.u),ft=Math.min(R,_.v),tt=Math.max(R,_.v);o([{u:z,v:ft},{u:X,v:ft},{u:X,v:tt},{u:z,v:tt}])},P=()=>{window.removeEventListener("pointermove",N),window.removeEventListener("pointerup",P)};window.addEventListener("pointermove",N),window.addEventListener("pointerup",P)},[r,i,o,e,s,a,c]);return n.jsx("group",{position:[0,0,l],children:c.map((u,h)=>n.jsxs("group",{position:[u.u*rt,u.v*rt,0],children:[n.jsxs("mesh",{onPointerDown:x=>{x.stopPropagation(),d(h)},onPointerOver:x=>{x.stopPropagation(),document.body.style.cursor="grab"},onPointerOut:()=>{document.body.style.cursor=""},children:[n.jsx("sphereGeometry",{args:[.5,12,12]}),n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthWrite:!1,depthTest:!1})]}),n.jsxs("mesh",{renderOrder:9998,onPointerDown:x=>{x.stopPropagation(),d(h)},onPointerOver:x=>{x.stopPropagation(),document.body.style.cursor="grab"},onPointerOut:()=>{document.body.style.cursor=""},children:[n.jsx("sphereGeometry",{args:[.23,24,24]}),n.jsx("meshBasicMaterial",{color:"#ffffff",depthTest:!1})]}),n.jsxs("mesh",{renderOrder:9999,onPointerDown:x=>{x.stopPropagation(),d(h)},onPointerOver:x=>{x.stopPropagation(),document.body.style.cursor="grab"},onPointerOut:()=>{document.body.style.cursor=""},children:[n.jsx("sphereGeometry",{args:[.18,24,24]}),n.jsx("meshBasicMaterial",{color:"#ff3b30",depthTest:!1})]})]},`wv-${h}`))})}function NP({sx:t,sz:e,w:s,d:o,h:r,cx:i,cz:a,rad:l,onResize:c,onResizeLive:d,onResizeCancel:u}){const{camera:h,gl:x}=Vo(),f=m.useContext(zf),p=m.useCallback(b=>{b.stopPropagation();const M=x.domElement;if(!M)return;const g=M.getBoundingClientRect(),w=new Ga(new le(0,1,0),-f),k=new Ea,_=new Po,j=new le,v=Math.cos(l),C=Math.sin(l);let N=s,P=o,L=!1;const A=()=>{window.removeEventListener("pointermove",W),window.removeEventListener("pointerup",S),window.removeEventListener("keydown",B)},W=R=>{if(_.x=(R.clientX-g.left)/g.width*2-1,_.y=-((R.clientY-g.top)/g.height)*2+1,k.setFromCamera(_,h),!k.ray.intersectPlane(w,j))return;const z=j.x-i,X=j.z-a,ft=v*z-C*X,tt=C*z+v*X,G=Math.max(.1,Math.abs(ft)*2),Y=Math.max(.1,Math.abs(tt)*2);N=G,P=Y,L=!0,(d??c)(G,Y,r)},S=()=>{A(),L&&d&&c(N,P,r)},B=R=>{R.key==="Escape"&&(A(),u==null||u())};window.addEventListener("pointermove",W),window.addEventListener("pointerup",S),window.addEventListener("keydown",B)},[h,x,i,a,f,l,s,o,r,c,d,u]);return n.jsxs("mesh",{position:[t*s/2,r+.08,e*o/2],onPointerDown:p,onPointerOver:b=>{b.stopPropagation(),document.body.style.cursor="nwse-resize"},onPointerOut:()=>{document.body.style.cursor=""},children:[n.jsx("sphereGeometry",{args:[.09,20,20]}),n.jsx("meshBasicMaterial",{color:"#3B82F6"})]})}function S5({x:t,z:e,w:s,d:o,h:r,rad:i,isSelected:a,sketchupLookEnabled:l=!1,sketchupModelEdgesEnabled:c=l}){return n.jsxs("mesh",{position:[t,r/2,e],rotation:[0,i,0],castShadow:l,receiveShadow:l,children:[n.jsx("boxGeometry",{args:[s,r,o]}),n.jsx("meshStandardMaterial",{color:l?"#d8d6cf":ul.furniture,roughness:.72,metalness:.02}),c&&n.jsx(xo,{color:th,lineWidth:bm,threshold:15}),a&&n.jsx(xo,{color:"#3B82F6",lineWidth:3})]})}const IP="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=";function TP(t){const e=t.getAttribute("uv");if(e&&e.count>0)return t;const s=t.clone();s.computeBoundingBox();const o=s.boundingBox,r=s.getAttribute("position");if(!o||!r)return s;const i=s.getAttribute("normal"),a=o.getSize(new le),l=d=>Math.max(d,.001),c=new Float32Array(r.count*2);for(let d=0;d<r.count;d+=1){const u=r.getX(d),h=r.getY(d),x=r.getZ(d),f=(i==null?void 0:i.getX(d))??0,p=(i==null?void 0:i.getY(d))??0,b=(i==null?void 0:i.getZ(d))??1,M=Math.abs(f),g=Math.abs(p),w=Math.abs(b);let k,_;g>=M&&g>=w?(k=(u-o.min.x)/l(a.x),_=(x-o.min.z)/l(a.z)):M>=w?(k=(x-o.min.z)/l(a.z),_=(h-o.min.y)/l(a.y)):(k=(u-o.min.x)/l(a.x),_=(h-o.min.y)/l(a.y)),c[d*2]=Number.isFinite(k)?k:0,c[d*2+1]=Number.isFinite(_)?_:0}return s.setAttribute("uv",new cb(c,2)),s}function SP({preserveSourceMaterials:t=!1,url:e,x:s,z:o,w:r,d:i,h:a,rad:l,flipX:c=1,materialSlots:d,materialOverrides:u,selectedSlotId:h,showPartGuides:x=!1,onPartClick:f,onContextMenu:p,sketchupLookEnabled:b=!1,sketchupModelEdgesEnabled:M=b,sketchupEdgeOpacity:g=.92,onSketchupEdgeCountChange:w}){const k=Rw(db,e,mb),{gl:_}=Vo(),j=m.useMemo(()=>Array.from(new Set(Object.values(u??{}).map(X=>X.url).filter(X=>!!X&&!X.startsWith("#")))),[u]),v=Ya(j.length>0?j:[IP]),C=m.useMemo(()=>{const X=Array.isArray(v)?v:[v],ft=new Map;
199return j.forEach((tt,G)=>{const Y=X[G];Y&&ft.set(tt,Y)}),ft},[v,j]),N=m.useMemo(()=>{var Ht;const X=(Ht=k.parser)==null?void 0:Ht.associations,ft=k.scene.clone(!0),tt=d??[],G=tt.length>0,Y=new Map;if(G){const Tt=[],Zt=[];k.scene.traverse(At=>Tt.push(At)),ft.traverse(At=>Zt.push(At)),Zt.forEach((At,ut)=>{const kt=Tt[ut]&&X?jT(Tt[ut],X):void 0;kt&&Y.set(At,kt)})}const J=new Jg({color:"#3B82F6",transparent:!0,opacity:.18,depthTest:!1,depthWrite:!1,side:kn}),Mt=new Jg({color:"#1D4ED8",transparent:!0,opacity:.95,wireframe:!0,depthTest:!1,depthWrite:!1,side:kn}),Rt=new Cy({color:"#3B82F6",transparent:!0,opacity:h?.32:.82,depthTest:!1,depthWrite:!1}),it=new Jg({visible:!1}),st=new Set([J,Mt,Rt,it]),ct=[],pt=[],xt=(Tt,Zt)=>_T(tt,{materialAssociation:X==null?void 0:X.get(Tt),meshAssociation:Y.get(Zt),materialName:Tt.name}),_t=(Tt,Zt)=>Tt.length===1?Tt[0]===h?Zt:it:Tt.map(At=>At===h?Zt:it);ft.traverse(Tt=>{if(Tt.isMesh&&Tt.material){const Zt=Array.isArray(Tt.material)?Tt.material:[Tt.material],At=G?Zt.map(ht=>{var gt;return((gt=xt(ht,Tt))==null?void 0:gt.id)??null}):Zt.map(()=>null);Tt.userData.smartGlbSlotIdsByMaterialIndex=At;let ut=!1;const kt=Zt.map(ht=>{const gt=ht.clone();if(st.add(gt),gt.isMeshStandardMaterial||gt.isMeshPhysicalMaterial){const Pt=G?xt(ht,Tt):void 0,U=Pt?u==null?void 0:u[Pt.id]:void 0;if(U!=null&&U.url)if(U.url.startsWith("#"))gt.color=new Do(U.url),gt.map=null;else{const mt=C.get(U.url);if(mt){if((Pt==null?void 0:Pt.uvMode)!=="model"&&!ut){const Lt=Tt.geometry;Tt.geometry=TP(Lt),Tt.geometry!==Lt&&st.add(Tt.geometry),ut=!0}const Nt=mt.clone();st.add(Nt),t&&(Nt.flipY=!1,Nt.colorSpace=gm),Nt.wrapS=Uc,Nt.wrapT=Uc,s3(Nt,ei(U.orientation)),Rp(Nt,_),gt.map=Nt,gt.color=new Do("#ffffff")}}if(!t){const mt=gt.color;(mt?.2126*mt.r+.7152*mt.g+.0722*mt.b:1)<.2?(gt.metalness=0,gt.roughness<.6&&(gt.roughness=.6),gt.envMapIntensity=2.5):(gt.metalness>.6&&(gt.metalness=.6),gt.roughness<.15&&(gt.roughness=.15),gt.envMapIntensity=1.5)}gt.needsUpdate=!0}return gt});Tt.material=Array.isArray(Tt.material)?kt:kt[0];const Et=At.some(Boolean);if(x&&Et){const ht=Tt,gt=new zk(new $k(ht.geometry),Rt);st.add(gt.geometry),gt.name=`${ht.name||"mesh"}__smart-glb-editable-guides`,gt.renderOrder=9999,gt.raycast=()=>{},pt.push({mesh:ht,line:gt})}if(h&&At.includes(h)){const ht=Tt,gt=new E1(ht.geometry,_t(At,J)),Pt=new E1(ht.geometry,_t(At,Mt));for(const U of[gt,Pt])U.name=`${ht.name||"mesh"}__smart-glb-selected-part`,U.renderOrder=1e4,U.raycast=()=>{},ct.push({mesh:ht,overlay:U})}}});for(const{mesh:Tt,line:Zt}of pt)Tt.add(Zt);for(const{mesh:Tt,overlay:Zt}of ct)Tt.add(Zt);const Ft=new Hw().setFromObject(t?k.scene:ft,t),Vt=Ft.getSize(new le),vt=Ft.getCenter(new le);return{scene:ft,size:Vt,center:vt,minY:Ft.min.y,dispose:()=>st.forEach(Tt=>Tt.dispose())}},[k,d,u,h,x,C,_,f,t]),P=N.size.x>.001?r/N.size.x:1,L=N.size.y>.001?a/N.size.y:1,A=N.size.z>.001?i/N.size.z:1;m.useEffect(()=>()=>N.dispose(),[N]),m.useEffect(()=>{N.scene.traverse(X=>{X.isMesh&&(X.castShadow=b,X.receiveShadow=b)}),b||w==null||w(0)},[N.scene,w,b]),m.useEffect(()=>{if(w==null||w(0),!M)return;const X=[];N.scene.traverse(it=>{it.isMesh&&it.geometry&&X.push(it)});let ft=!1,tt=0,G=0,Y;const J=[],Mt=()=>{var it,st;for(const ct of J){(it=ct.parent)==null||it.remove(ct),(st=ct.geometry)==null||st.dispose();const pt=ct.material;Array.isArray(pt)?pt.forEach(xt=>xt.dispose()):pt==null||pt.dispose()}J.length=0},Rt=()=>{if(ft)return;const it=Math.min(tt+3,X.length),st=Math.min(1,Math.max(0,g)),ct=Math.min(1,Math.max(.01,Math.pow(st,1.35))),pt=48-st*38;for(;tt<it;tt+=1){const xt=X[tt],_t=new zk(new $k(xt.geometry,pt),new Cy({color:th,transparent:!0,opacity:ct,depthTest:!0,depthWrite:!1}));_t.name=`${xt.name||"mesh"}__sketchup-visual-edges`,_t.renderOrder=Math.max(xt.renderOrder??0,2),_t.scale.setScalar(1.0015),_t.raycast=()=>{},_t.userData.floorplanSketchupEdgeOverlay=!0,xt.add(_t),J.push(_t),G+=1}w==null||w(G),tt<X.length&&(Y=window.setTimeout(Rt,16))};return Y=window.setTimeout(Rt,80),()=>{ft=!0,Y!==void 0&&window.clearTimeout(Y),Mt(),w==null||w(0)}},[N.scene,w,g,M]);const W=m.useCallback((X,ft)=>
199{const tt=X.userData.smartGlbSlotIdsByMaterialIndex;return ET(tt??[],ft)},[]),S=m.useCallback(X=>{var tt;if(!f)return;const ft=W(X.object,(tt=X.face)==null?void 0:tt.materialIndex);ft&&(X.stopPropagation(),f(ft,X.nativeEvent.metaKey||X.nativeEvent.ctrlKey))},[f,W]),B=m.useCallback(X=>{var tt;!f||!W(X.object,(tt=X.face)==null?void 0:tt.materialIndex)||(X.stopPropagation(),document.body.style.cursor="pointer")},[f,W]),R=m.useCallback(()=>{f&&(document.body.style.cursor="")},[f]),z=m.useCallback(X=>{p&&(X.stopPropagation(),X.nativeEvent.preventDefault(),p({x:X.nativeEvent.clientX,y:X.nativeEvent.clientY}))},[p]);return n.jsx("group",{position:[s,0,o],rotation:[0,l,0],scale:[c,1,1],children:n.jsx("group",{scale:[P,L,A],position:[-N.center.x*P,-N.minY*L,-N.center.z*A],children:n.jsx("primitive",{object:N.scene,onClick:f?S:void 0,onContextMenu:p?z:void 0,onPointerOver:f?B:void 0,onPointerOut:f?R:void 0})})})}const PP=["grass","dirt"],gp={grass:"#6f8f4e",dirt:"#9b7b52"},i2="/textures/site";function P5(t){return{diffuse:`${i2}/${t}_diff.webp`,normal:`${i2}/${t}_nor.webp`,roughness:`${i2}/${t}_rough.webp`}}const Ry={grass:{labelHe:"דשא",tint:"#eef3e2",...P5("grass"),tileSizeM:6,roughnessScalar:1,normalScale:1.1},dirt:{labelHe:"אדמה",tint:"#ffffff",...P5("dirt"),tileSizeM:3,roughnessScalar:1,normalScale:1}},tD=2,eD=4*60,nD=23*60,Oy=5,wb=12*60,AP=3e3,W1=1e3,R1=5e5,Bc={centerXMm:0,centerYMm:0,widthMm:2e4,depthMm:2e4};function LP(t){return t.centerXMm===Bc.centerXMm&&t.centerYMm===Bc.centerYMm&&t.widthMm===Bc.widthMm&&t.depthMm===Bc.depthMm}const e1={version:tD,enabled:!1,sky:{timeOfDayMinutes:wb},ground:{material:"grass"},lot:{...Bc}};function sg(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function Mf(t,e){const s=Number(t);return Number.isFinite(s)?s:e}function im(t,e,s){return Math.min(s,Math.max(e,t))}function fm(t){const e=im(Mf(t,wb),eD,nD);return Math.round(e/Oy)*Oy}function WP(t){return t==="grass"||t==="dirt"}function RP(t){const e=sg(t);if(!e)return{...e1,sky:{timeOfDayMinutes:wb},ground:{material:"grass"},lot:{...Bc}};const s=sg(e.sky),o=sg(e.ground),r=sg(e.lot),i=o==null?void 0:o.material,a=im(Mf(s==null?void 0:s.timeOfDay01,.5),0,1),l=6*60+a*12*60,c=(s==null?void 0:s.timeOfDayMinutes)===void 0?fm(l):fm(s.timeOfDayMinutes);return{version:tD,enabled:e.enabled===!0,sky:{timeOfDayMinutes:c},ground:{material:WP(i)?i:"grass"},lot:{centerXMm:Mf(r==null?void 0:r.centerXMm,Bc.centerXMm),centerYMm:Mf(r==null?void 0:r.centerYMm,Bc.centerYMm),widthMm:im(Mf(r==null?void 0:r.widthMm,Bc.widthMm),W1,R1),depthMm:im(Mf(r==null?void 0:r.depthMm,Bc.depthMm),W1,R1)}}}const Hy=Math.PI/180,A5=5*60+30,L5=7*60,W5=17*60,R5=19*60,O5=8,oD=72,OP=Math.sin(oD*Hy),HP=1.7;function sD(t){const e=im((fm(t)-360)/720,0,1),s=O5+(oD-O5)*Math.sin(e*Math.PI)**HP,o=-90+180*e,r=s*Hy,i=o*Hy,a=Math.cos(r);return new le(a*Math.sin(i),Math.sin(r),-a*Math.cos(i)).normalize()}function H5(t,e,s){const o=im((s-t)/(e-t),0,1);return o*o*(3-2*o)}function kb(t){const e=fm(t),s=H5(A5,L5,e),o=1-H5(W5,R5,e),r=Math.min(s,o),i=e<A5||e>=R5?"night":e<L5?"dawn":e<11*60+30?"morning":e<13*60?"noon":e<W5?"afternoon":"goldenHour";return{timeOfDayMinutes:e,phase:i,daylightStrength:r,nightStrength:1-r}}function BP(t){const e=fm(t),s=Math.floor(e/60),o=e%60;return`${String(s).padStart(2,"0")}:${String(o).padStart(2,"0")}`}function VP(t){const e=im(t.y/OP,0,1),s=1-e,o=new Do("#f7c88f").lerp(new Do("#bcd6f2"),e).getStyle(),r=new Do("#6b5a45").lerp(new Do("#7f8b6e"),e).getStyle(),i=new Do("#ffb066").lerp(new Do("#fff6e8"),e).getStyle();return{skyColor:o,groundColor:r,sunColor:i,ambientIntensity:.28+.12*e,sunIntensity:1.35+.4*e,hemisphereIntensity:.35+.15*e,iblIntensity:.18+.37*s,turbidity:2.5+6*s,rayleigh:2.6+.8*s,mieCoefficient:.004+.008*s}}function a3(t){const e=kb(t),s=e.daylightStrength,o=e.nightStrength,r=VP(sD(e.timeOfDayMinutes)),i=(a,l)=>new Do(a).lerp(new Do(l),s).getStyle();return{...r,skyColor:i("#0b1020",r.skyColor),groundColor:i("#05070d",r.groundColor),sunColor:r.sunColor,ambientColor:i("#2a3550","#ffffff"),ambientIntensity:.09*o+r.ambientIntensity*s,sunIntensity:r.sunIntensity*s,hemisphereIntensity:.16*o+r.hemisphereIntensity*s,iblIntensity:.015*o+r.iblIntensity*s,daylightStrength:s,nightStrength:o,backgroundColor:i("#0b0c10",r.skyColor)}}const zP=128,$P=450,XP=.45,YP=.55,GP=.48,UP=.8,KP=(()=>{const t=Fy.material.fragmentShader,e="gl_FragColor = vec4( retColor, 1.0 );";return t.includes(e)?`uniform float uSkyExposure;
200uniform float uDaylightStrength;
201uniform vec3 uNightSkyColor;
202${t.replace(e,"gl_FragColor = vec4( mix( uNightSkyColor, retColor * uSkyExposure, uDaylightStrength ), 1.0 );")}`:(console.warn("[outdoor-sky] SkyShader output line not found — sky exposure control is inactive"),t)})();function ZP({sunPosition:t,turbidity:e,rayleigh:s,mieCoefficient:o,mieDirectionalG:r,daylightStrength:i}){const a=m.useRef(null),l=m.useMemo(()=>new QN({name:"OutdoorSkyShader",vertexShader:Fy.material.vertexShader,fragmentShader:KP,uniforms:{...tI.clone(Fy.material.uniforms),uSkyExposure:{value:GP},uDaylightStrength:{value:1},uNightSkyColor:{value:new Do("#0b1020")}},side:Sp,depthWrite:!1}),[]);m.useEffect(()=>()=>
202l.dispose(),[l]);const c=l.uniforms;return c.turbidity.value=e,c.rayleigh.value=s,c.mieCoefficient.value=o,c.mieDirectionalG.value=r,c.uDaylightStrength.value=i,c.sunPosition.value.set(...t),ka(({camera:d})=>{const u=a.current;if(!u)return;u.position.copy(d.position);const h=d.far;u.scale.setScalar(Math.max((Number.isFinite(h)?h:1e3)*UP,1))}),n.jsx("mesh",{ref:a,material:l,frustumCulled:!1,renderOrder:-1e3,children:n.jsx("boxGeometry",{args:[1,1,1]})})}function qP({bounds:t,wallHeight:e,timeOfDayMinutes:s}){const o=Math.max(mm(t),4),r=o*.75,{sunPos:i,skySunPosition:a,camFar:l,tint:c}=m.useMemo(()=>{const u=sD(s),h=a3(s),x=Math.max(o*2.2,e*3,12),f=new le(u.x,Math.max(u.y,.35),u.z).multiplyScalar(x);return{sunPos:[t.centerX+f.x,f.y,t.centerZ+f.z],skySunPosition:[u.x,Math.max(u.y,.05),u.z],camFar:f.length()+o*4,tint:h}},[s,o,e,t.centerX,t.centerZ]),d=m.useMemo(()=>new JN,[]);return n.jsxs(n.Fragment,{children:[n.jsx(Ow,{frames:1,resolution:zP,background:!1,environmentIntensity:c.iblIntensity,children:n.jsx(UN,{sunPosition:a,turbidity:c.turbidity,rayleigh:c.rayleigh,mieCoefficient:c.mieCoefficient,mieDirectionalG:.8,distance:$P})}),n.jsx("ambientLight",{color:c.ambientColor,intensity:c.ambientIntensity*(1-c.daylightStrength*(1-XP))}),n.jsx("hemisphereLight",{args:[c.skyColor,c.groundColor,c.hemisphereIntensity*(1-c.daylightStrength*(1-YP))]}),n.jsx("primitive",{object:d,position:[t.centerX,0,t.centerZ]}),n.jsx("directionalLight",{castShadow:!0,color:c.sunColor,position:i,target:d,intensity:c.sunIntensity,"shadow-mapSize-width":2048,"shadow-mapSize-height":2048,"shadow-camera-near":.1,"shadow-camera-far":l,"shadow-camera-left":-r,"shadow-camera-right":r,"shadow-camera-top":r,"shadow-camera-bottom":-r,"shadow-bias":-12e-5,"shadow-normalBias":.018}),n.jsx(ZP,{sunPosition:a,turbidity:c.turbidity,rayleigh:c.rayleigh,mieCoefficient:c.mieCoefficient,mieDirectionalG:.8,daylightStrength:c.daylightStrength})]})}function rD(t,e,s){const o=Vo(u=>u.gl),[r,i,a]=Ya([t.diffuse,t.normal,t.roughness]),l=m.useMemo(()=>r.clone(),[r]),c=m.useMemo(()=>i.clone(),[i]),d=m.useMemo(()=>a.clone(),[a]);return m.useEffect(()=>()=>{l.dispose(),c.dispose(),d.dispose()},[l,c,d]),m.useLayoutEffect(()=>{const u=Math.min(16,o.capabilities.getMaxAnisotropy()),h=[[l,gm],[c,Xk],[d,Xk]];for(const[x,f]of h)x.wrapS=Uc,x.wrapT=Uc,x.repeat.set(e,s),x.colorSpace=f,x.anisotropy=u,x.minFilter=V_,x.magFilter=z_,x.generateMipmaps=!0,x.needsUpdate=!0},[o,l,c,e,s,d]),{map:l,normalMap:c,roughnessMap:d}}const JP=`
203#ifdef USE_MAP
204  vec4 sampledDiffuseColor = texture2D( map, vMapUv );
205
206  vec3 macroRgb = texture2D( map, vMapUv * u_macroScale ).rgb;
207  float macroLum = dot( macroRgb, vec3( 0.2126, 0.7152, 0.0722 ) );
208  sampledDiffuseColor.rgb *= mix( 1.0, 0.5 + macroLum, u_macroStrength );
209
210  float viewDist = length( vViewPosition );
211  float distFade = smoothstep( u_fadeStart, u_fadeEnd, viewDist );
212  sampledDiffuseColor.rgb = mix( sampledDiffuseColor.rgb, macroRgb, distFade * 0.85 );
213
214  diffuseColor *= sampledDiffuseColor;
215#endif
216`,QP=`
217#include <normal_fragment_maps>
218  normal = normalize( mix( normal, nonPerturbedNormal, smoothstep( u_fadeStart, u_fadeEnd, length( vViewPosition ) ) ) );
219`,tA=.035,eA=.55;function nA({materialKey:t,widthM:e,depthM:s,nightStrength:o=0}){const r=Ry[t],{map:i,normalMap:a,roughnessMap:l}=rD(r,e/r.tileSizeM,s/r.tileSizeM),c=Math.max(e,s),d=Math.max(25,c*.05),u=Math.max(d*4,c*.35),h=m.useMemo(()=>new Po(r.normalScale,r.normalScale),[r.normalScale]),x=m.useMemo(()=>new Do(r.tint).lerp(new Do("#263042"),Math.min(1,Math.max(0,o))*.78).getStyle(),[r.tint,o]),f=p=>{p.uniforms.u_macroScale={value:tA},p.uniforms.u_macroStrength={value:eA},p.uniforms.u_fadeStart={value:d},p.uniforms.u_fadeEnd={value:u},p.fragmentShader=`uniform float u_macroScale;
220uniform float u_macroStrength;
221uniform float u_fadeStart;
222uniform float u_fadeEnd;
223`+p.fragmentShader,p.fragmentShader=p.fragmentShader.replace("#include <map_fragment>",JP).replace("#include <normal_fragment_maps>",QP)};return n.jsx("meshStandardMaterial",{map:i,normalMap:a,normalScale:h,roughnessMap:l,roughness:r.roughnessScalar,metalness:0,
223color:x,onBeforeCompile:f},`ground-${t}-${Math.round(d)}-${Math.round(u)}`)}function oA({materialKey:t,widthM:e,depthM:s,nightStrength:o=0}){const r=gp[t]??gp.grass,i=m.useMemo(()=>new Do(r).lerp(new Do("#182137"),Math.min(1,Math.max(0,o))*.72).getStyle(),[r,o]);return n.jsx(ml,{fallback:n.jsx("meshStandardMaterial",{color:i,roughness:.97,metalness:0}),children:n.jsx(nA,{materialKey:t,widthM:e,depthM:s,nightStrength:o})})}function sA(t){let e=1/0,s=-1/0,o=1/0,r=-1/0;for(const i of t)for(const a of[i==null?void 0:i.start,i==null?void 0:i.end]){const l=a==null?void 0:a.x,c=a==null?void 0:a.y;typeof l!="number"||typeof c!="number"||!Number.isFinite(l)||!Number.isFinite(c)||(l<e&&(e=l),l>s&&(s=l),c<o&&(o=c),c>r&&(r=c))}return Number.isFinite(e)?{minX:e,maxX:s,minY:o,maxY:r}:null}function B5(t,e=AP){const s=sA(t);if(!s)return null;const o=s.maxX-s.minX,r=s.maxY-s.minY;return{centerXMm:(s.minX+s.maxX)/2,centerYMm:(s.minY+s.maxY)/2,widthMm:Math.max(o+e*2,4e3),depthMm:Math.max(r+e*2,4e3)}}function rA(t){const e=t.centerXMm*rt,s=t.centerYMm*rt,o=t.widthMm*rt/2,r=t.depthMm*rt/2;return[{x:e-o,z:s-r},{x:e+o,z:s-r},{x:e+o,z:s+r},{x:e-o,z:s+r}]}const iA=-.03,aA=-.018,lA=-.05,cA="#D85D43",By=()=>null,dA=`
224varying vec2 vLocal;
225void main() {
226  vLocal = position.xy;
227  gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
228}
229`,uA=`
230uniform vec3 uNear;
231uniform vec3 uFar;
232uniform float uHazeStart;
233uniform float uHazeEnd;
234uniform float uFadeStart;
235uniform float uFadeEnd;
236varying vec2 vLocal;
237void main() {
238  // Radial, so the fade has no seam or corner regardless of which way the camera orbits.
239  float d = length( vLocal );
240  float alpha = 1.0 - smoothstep( uFadeStart, uFadeEnd, d );
241  if ( alpha < 0.002 ) discard;
242  gl_FragColor = vec4( mix( uNear, uFar, smoothstep( uHazeStart, uHazeEnd, d ) ), alpha );
243  #include <tonemapping_fragment>
244  #include <colorspace_fragment>
245}
246`,hA=1,mA=6,fA=10,xA=16,V5=17,pA=25,a2=new Do;function gA({centerX:t,centerZ:e,reachM:s,material:o,timeOfDayMinutes:r}){const i=m.useMemo(()=>({uNear:{value:new Do("#8a9a7a")},uFar:{value:new Do("#bcd6f2")},uHazeStart:{value:0},uHazeEnd:{value:0},uFadeStart:{value:0},uFadeEnd:{value:0}}),[]),a=a3(r);return a2.set(a.skyColor),i.uFar.value.copy(a2),i.uNear.value.set(gp[o]??gp.grass).multiplyScalar(.62*(1-a.nightStrength*.68)).lerp(a2,.22),i.uHazeStart.value=s*hA,i.uHazeEnd.value=s*mA,i.uFadeStart.value=s*fA,i.uFadeEnd.value=s*xA,n.jsxs("mesh",{raycast:By,position:[t,lA,e],rotation:[-Math.PI/2,0,0],renderOrder:-1,children:[n.jsx("planeGeometry",{args:[s*V5*2,s*V5*2]}),n.jsx("shaderMaterial",{transparent:!0,depthWrite:!1,uniforms:i,vertexShader:dA,fragmentShader:uA})]})}function bA({environment:t,bounds:e}){const{lot:s,ground:o}=t,r=kb(t.sky.timeOfDayMinutes),i=s.centerXMm*rt,a=s.centerYMm*rt,l=s.widthMm*rt,c=s.depthMm*rt,d=Math.max(l,c,e.span,pA),u=m.useMemo(()=>{const h=rA(s);return[...h,h[0]].map(x=>[x.x,aA,x.z])},[s]);return n.jsxs("group",{children:[n.jsx(gA,{centerX:i,centerZ:a,reachM:d,material:o.material,timeOfDayMinutes:t.sky.timeOfDayMinutes}),n.jsxs("mesh",{raycast:By,position:[i,iA,a],rotation:[-Math.PI/2,0,0],receiveShadow:!0,children:[n.jsx("planeGeometry",{args:[l,c]}),n.jsx(oA,{materialKey:o.material,widthM:l,depthM:c,nightStrength:r.nightStrength})]}),n.jsx(Jn,{raycast:By,points:u,color:cA,lineWidth:2.4})]})}function MA({envelope:t,thicknessMm:e}){const s=m.useMemo(()=>{const o=new $l;o.moveTo(t[0].x*rt,-t[0].y*rt);for(let r=1;r<t.length;r++)o.lineTo(t[r].x*rt,-t[r].y*rt);return o.closePath(),new ub(o,{depth:e*rt,bevelEnabled:!1})},[t,e]);return m.useEffect(()=>()=>s.dispose(),[s]),n.jsx("mesh",{geometry:s,rotation:[-Math.PI/2,0,0],position:[0,-e*rt,0],castShadow:!0,receiveShadow:!0,children:n.jsx("meshStandardMaterial",{color:"#cfc9bf",roughness:.9})})}const yA=50,Vc=100,wA=20,dl=1e-6;function Pu(t){return{openEndpoints:[],problematicWallIds:[],wallTopHeightsMm:[],manualOverrideStale:!1,manualOverrideInvalid:!1,...t}}function qc(t){let e=0;for(let s=0;s<t.length;s+=1){const o=t[s],r=t[(s+1)%t.length];e+=o.x*r.y-r.x*o.y}return e/2}function bp(t,e){let s=!1;for(let o=0,r=e.length-1;o<e.length;r=o,o+=1){const i=e[o],a=e[r];i.y>t.y!=a.y>t.y&&t.x<(a.x-i.x)*(t.y-i.y)/(a.y-i.y||dl)+i.x&&(s=!s)}return s}function rg(t,e,s){return(e.x-t.x)*(s.y-t.y)-(e.y-t.y)*(s.x-t.x)}function l3(t,e,s,o){const r=rg(t,e,s),i=rg(t,e,o),a=rg(s,o,t),l=rg(s,o,e);if(r*i<-dl&&a*l<-dl)return!0;const c=(d,u,h)=>d.x>=Math.min(u.x,h.x)-dl&&d.x<=Math.max(u.x,h.x)+dl&&d.y>=Math.min(u.y,h.y)-dl&&d.y<=Math.max(u.y,h.y)+dl;return Math.abs(r)<=dl&&c(s,t,e)||Math.abs(i)<=dl&&c(o,t,e)||Math.abs(a)<=dl&&c(t,s,o)||Math.abs(l)<=dl&&c(e,s,o)}function Mp(t){for(let e=0;e<t.length;e+=1){const s=t[e],o=t[(e+1)%t.length];for(let r=e+1;r<t.length;r+=1){if(Math.abs(e-r)<=1||e===0&&r===t.length-1)continue;const i=t[r],a=t[(r+1)%t.length];if(l3(s,o,i,a))return!0}}return!1}function iD(t,e){for(let s=0;s<t.length;s+=1)for(let o=0;o<e.length;o+=1)if(l3(t[s],t[(s+1)%t.length],e[o],e[(o+1)%e.length]))return!0;return!1}function kA(t,e){return iD(t,e)?!0:bp(t[0],e)||bp(e[0],t)}function O1(t,e){const s=t.map(r=>({...r}));qc(s)<0!==e&&s.reverse();const o=s.reduce((r,i,a)=>i.x<s[r].x||i.x===s[r].x&&i.y<s[r].y?a:r,0);return[...s.slice(o),...s.slice(0,o)]}function z5(t,e,s){let o=t.map(a=>({...a})),r=[...e];qc(o)<0!==s&&(o=[o[0],...o.slice(1).reverse()],r=[...r].reverse());const i=o.reduce((a,l,c)=>l.x<o[a].x||l.x===o[a].x&&l.y<o[a].y?c:a,0);return o=[...o.slice(i),...o.slice(0,i)],r=[...r.slice(i),...r.slice(0,i)],{points:o,walls:r}}function vb(t){let e=[...t],s=!0;for(;s&&e.length>3;)s=!1,e=e.filter((o,r)=>{const i=e[(r-1+e.length)%e.length],a=e[(r+1)%e.length],l=o.x-i.x,c=o.y-i.y,d=a.x-o.x,u=a.y-o.y,h=Math.hypot(l,c)*Math.hypot(d,u);return h<=dl||Math.abs(l*u-c*d)/h<.0025&&l*d+c*u>0?(s=!0,!1):!0});return e}function jb(t){if(t.length!==4)return null;const e=t.map((a,l)=>{const c=t[(l+1)%t.length],d=c.x-a.x,u=c.y-a.y;return{dx:d,dy:u,length:Math.hypot(d,u)}});if(e.some(a=>a.length<Vc))return null;for(let a=0;a<4;a+=1){const l=e[a],c=e[(a+1)%4];
246if(Math.abs((l.dx*c.dx+l.dy*c.dy)/(l.length*c.length))>.025)return null}const s=Math.max(20,Math.max(...e.map(a=>a.length))*.01);if(Math.abs(e[0].length-e[2].length)>s||Math.abs(e[1].length-e[3].length)>s)return null;const o=e[0].length>=e[1].length,r=o?e[0]:e[1],i=o?e[1]:e[0];return{corners:[t[0],t[1],t[2],t[3]],center:{x:t.reduce((a,l)=>a+l.x,0)/4,y:t.reduce((a,l)=>a+l.y,0)/4},longAxis:{x:r.dx/r.length,y:r.dy/r.length},shortAxis:{x:i.dx/i.length,y:i.dy/i.length},longLengthMm:r.length,shortLengthMm:i.length}}function aD(t,e,s,o){const r=e.x*o.y-e.y*o.x;if(Math.abs(r)<dl)return null;const i=s.x-t.x,a=s.y-t.y,l=(i*o.y-a*o.x)/r;return{x:t.x+e.x*l,y:t.y+e.y*l}}function Bd(t,e){if(t.length<3||!Number.isFinite(e))return null;if(e===0)return t.map(c=>({...c}));const s=qc(t);if(Math.abs(s)<Vc*Vc)return null;const o=t.map((c,d)=>{const u=t[(d+1)%t.length],h=u.x-c.x,x=u.y-c.y,f=Math.hypot(h,x);if(f<Vc)return null;const p={x:x/f,y:-h/f};return{point:{x:c.x+p.x*e,y:c.y+p.y*e},direction:{x:h/f,y:x/f}}});if(o.some(c=>c===null))return null;const r=o,i=r.map((c,d)=>{const u=r[(d-1+r.length)%r.length],h=aD(u.point,u.direction,c.point,c.direction);if(!h)return{x:(u.point.x+c.point.x)/2,y:(u.point.y+c.point.y)/2};const x=t[d];return Math.hypot(h.x-x.x,h.y-x.y)<=Math.max(2e3,Math.abs(e)*8)?h:null});if(i.some(c=>c===null))return null;const a=vb(i),l=qc(a);return a.length<3||s*l<=0||Math.abs(l)<Vc*Vc||Mp(a)?null:a}function $5(t){const e=t.points.map((r,i)=>{var x;const a=t.points[(i+1)%t.points.length],l=a.x-r.x,c=a.y-r.y,d=Math.hypot(l,c);if(d<Vc)return null;const u=Number((x=t.walls[i])==null?void 0:x.thickness)/2;if(!Number.isFinite(u)||u<=0)return null;const h={x:c/d,y:-l/d};return{point:{x:r.x+h.x*u,y:r.y+h.y*u},direction:{x:l/d,y:c/d},distance:u}});if(e.some(r=>r===null))return null;const s=e,o=s.map((r,i)=>{const a=s[(i-1+s.length)%s.length],l=aD(a.point,a.direction,r.point,r.direction);if(!l)return{x:(a.point.x+r.point.x)/2,y:(a.point.y+r.point.y)/2};const c=t.points[i],d=Math.hypot(l.x-c.x,l.y-c.y),u=Math.max(2e3,Math.max(a.distance,r.distance)*8);return d<=u?l:null});return o.some(r=>r===null)?null:vb(o)}function vA(t,e,s){const o=[t.map(l=>`${Math.round(l.x)},${Math.round(l.y)}`).join(";"),...e.map(l=>l.map(c=>`${Math.round(c.x)},${Math.round(c.y)}`).join(";")).sort()].join("|"),r=s.map(l=>{const c=`${Math.round(l.start.x)},${Math.round(l.start.y)}`,d=`${Math.round(l.end.x)},${Math.round(l.end.y)}`;return`${c<d?`${c}>${d}`:`${d}>${c}`}:${Math.round(l.thickness)}`}).sort().join("|"),i=`${o}#${r}`;let a=2166136261;for(let l=0;l<i.length;l+=1)a^=i.charCodeAt(l),a=Math.imul(a,16777619);return`roof-${(a>>>0).toString(36)}`}function X5(t,e){const s=t.findIndex(r=>Math.hypot(r.point.x-e.x,r.point.y-e.y)<=yA);if(s<0)return t.push({point:{...e},samples:1}),t.length-1;const o=t[s];return o.point={x:(o.point.x*o.samples+e.x)/(o.samples+1),y:(o.point.y*o.samples+e.y)/(o.samples+1)},o.samples+=1,s}function jA(t,e,s,o){const r=[...t].sort((d,u)=>{const h=o[d].point,x=o[u].point;return h.x-x.x||h.y-x.y})[0],i=[],a=[];let l=r,c=-1;for(let d=0;d<=t.size+1;d+=1){i.push({...o[l].point});const u=(e.get(l)??[]).filter(p=>p!==c);if(u.length!==1&&c!==-1)return null;const h=c===-1?(e.get(l)??[])[0]:u[0];if(h===void 0)return null;const x=s[h];a.push(x.wall);const f=x.a===l?x.b:x.a;if(c=h,l=f,l===r)return i.length>=3?{points:i,walls:a}:null}return null}function _A(t){var w,k,_,j;const e=(t==null?void 0:t.walls.filter(v=>v.wallType==="exterior"))??[];if(e.length<3)return{valid:!1,reason:"no-walls",diagnostics:Pu()};const s=[],o=[],r=new Map;for(const v of e){const C={x:Number((w=v.start)==null?void 0:w.x),y:Number((k=v.start)==null?void 0:k.y)},N={x:Number((_=v.end)==null?void 0:_.x),y:Number((j=v.end)==null?void 0:j.y)};if(![C.x,C.y,N.x,N.y].every(Number.isFinite))continue;const P=X5(s,C),L=X5(s,N);if(P===L)continue;const A=o.length;o.push({a:P,b:L,wall:v}),r.set(P,[...r.get(P)??[],A]),r.set(L,[...r.get(L)??[],A])}const i=[...r.entries()].filter(([,v])=>v.length!==2);if(i.length>0)return{valid:!1,reason:"open-envelope",diagnostics:Pu({openEndpoints:i.map(([v])=>s[v].point),problematicWallIds:[...new Set(i.flatMap(([,v])=>v.map(C=>o[C].wall.id)))]})};for(let v=0;v<o.length;v+=1){const C=o[v];for(let N=v+1;N<o.length;N+=1){const P=o[N];if(![C.a,C.b].some(L=>L===P.a||L===P.b)&&l3(s[C.a].point,s[C.b].point,s[P.a].point,s[P.b].point))return{valid:!1,reason:"self-intersection",diagnostics:Pu({problematicWallIds:[C.wall.id,P.wall.id]})}}}const a=new Set(r.keys()),l=[];for(;a.size>0;
246){const v=a.values().next().value,C=new Set,N=[v];for(a.delete(v);N.length>0;){const P=N.shift();C.add(P);for(const L of r.get(P)??[]){const A=o[L],W=A.a===P?A.b:A.a;a.has(W)&&(a.delete(W),N.push(W))}}l.push(C)}const c=l.map(v=>jA(v,r,o,s)).filter(v=>v!==null).sort((v,C)=>Math.abs(qc(C.points))-Math.abs(qc(v.points)));if(c.length===0)return{valid:!1,reason:"invalid-envelope",diagnostics:Pu()};const d=z5(c[0].points,c[0].walls,!1),u=$5(d);if(!u||Mp(u))return{valid:!1,reason:u?"self-intersection":"offset-failed",diagnostics:Pu({problematicWallIds:d.walls.map(v=>v.id)})};const h=[],x=[];for(const v of c.slice(1)){if(!bp(v.points[0],d.points))return{valid:!1,reason:"multiple-shells",diagnostics:Pu({problematicWallIds:v.walls.map(P=>P.id)})};const C=z5(v.points,v.walls,!0),N=$5(C);if(!N||Mp(N)||!N.every(P=>bp(P,u)))return{valid:!1,reason:N?"self-intersection":"offset-failed",diagnostics:Pu({problematicWallIds:C.walls.map(P=>P.id)})};h.push(C),x.push(N)}const f=[...new Map([d,...h].flatMap(v=>v.walls).map(v=>[v.id,v])).values()],p=f.map(v=>Number(v.height)).filter(Number.isFinite),b=O1(u,!1),M=x.map(v=>O1(v,!0)),g=vA(b,M,f);return{valid:!0,outer:b,holes:M,rectangle:jb(vb(u)),sourceFootprintSignature:g,bearingWallIds:f.map(v=>v.id),bearingWallTopHeightsMm:p}}function yp(t){const e=O1(t.outer,!1),s=t.holes.map(r=>O1(r,!0));if([e,...s].some(r=>r.length<3||Math.abs(qc(r))<Vc*Vc||Mp(r)||r.some((i,a)=>{const l=r[(a+1)%r.length];return Math.hypot(l.x-i.x,l.y-i.y)<Vc})))return{valid:!1};if(s.some(r=>!r.every(i=>bp(i,e))||iD(r,e)))return{valid:!1};for(let r=0;r<s.length;r+=1)for(let i=r+1;i<s.length;i+=1)if(kA(s[r],s[i]))return{valid:!1};return{valid:!0,outer:e,holes:s}}function c3(t,e){return e!=="short-axis"?{ridgeAxis:t.longAxis,runAxis:t.shortAxis,runLengthMm:t.shortLengthMm,ridgeLengthMm:t.longLengthMm}:{ridgeAxis:t.shortAxis,runAxis:t.longAxis,runLengthMm:t.longLengthMm,ridgeLengthMm:t.shortLengthMm}}function EA(t){const e=[...t].sort((o,r)=>o-r);if(e.length===0)return 0;const s=Math.floor(e.length/2);return e.length%2===0?(e[s-1]+e[s])/2:e[s]}function DA(t,e,s){return t.footprintMode!=="manual"||!t.footprintOverride||!s?{footprint:e,stale:!1}:!t.footprintOverride.sourceFootprintSignature.startsWith("drawn:")&&e&&t.footprintOverride.sourceFootprintSignature!==e.sourceFootprintSignature?{footprint:e,stale:!0}:{footprint:s,stale:!1}}function FA(t,e,s="not_required",o=!0){const r=_A(t),i=r.valid?r:null,a=(t==null?void 0:t.walls.filter(N=>N.wallType==="exterior").map(N=>Number(N.height)).filter(Number.isFinite))??[],l=(i==null?void 0:i.bearingWallTopHeightsMm)??a,c=EA(l),d=((t==null?void 0:t.elevation)??0)+c,u=(e==null?void 0:e.footprintMode)==="manual"&&e.footprintOverride?yp(e.footprintOverride):null,h=u!=null&&u.valid&&(e!=null&&e.footprintOverride)?{valid:!0,outer:u.outer,holes:u.holes,rectangle:jb(vb(u.outer)),sourceFootprintSignature:e.footprintOverride.sourceFootprintSignature,bearingWallIds:(i==null?void 0:i.bearingWallIds)??(t==null?void 0:t.walls.filter(N=>N.wallType==="exterior").map(N=>N.id))??[],bearingWallTopHeightsMm:l}:null,x=(e==null?void 0:e.footprintMode)==="manual"&&!!e.footprintOverride,f=h??i,b={...r.valid===!1?{...r.diagnostics,wallTopHeightsMm:l}:Pu({wallTopHeightsMm:l}),manualOverrideInvalid:x&&!h},M={hostLevelId:(t==null?void 0:t.id)??null,canRender:!1,reason:f?null:r.valid===!1?r.reason:null,autoFootprint:i,effectiveFootprint:f,footprint:f,sourceFootprintSignature:(h==null?void 0:h.sourceFootprintSignature)??(i==null?void 0:i.sourceFootprintSignature)??null,baseElevationMm:d,maxElevationMm:d,storyHeightMm:c,diagnostics:b};if(s==="pending")return{...M,reason:"pending-alignment"};if(!o)return{...M,reason:"host-hidden"};if(l.length===0||Math.max(...l)-Math.min(...l)>wA)return{...M,reason:"non-coplanar-wall-tops"};if(!e)return M;const g=DA(e,i,h),w={...b,manualOverrideStale:g.stale};if(!g.footprint)return{...M,effectiveFootprint:null,footprint:null,reason:r.valid===!1?r.reason:"invalid-envelope",diagnostics:w};const k=g.footprint,_=Bd(k.outer,e.overhangMm),j=k.holes.map(N=>Bd(N,e.overhangMm));if(!_||j.some(N=>N===null)||!yp({outer:_,holes:j}).valid)return{...M,effectiveFootprint:k,footprint:k,reason:"offset-failed",diagnostics:w};if(e.type!=="flat"&&k.holes.length>0)return{...M,effectiveFootprint:k,footprint:k,reason:"pitched-does-not-support-courtyard",diagnostics:w};if(e.type!=="flat"&&!k.rectangle)return{...M,effectiveFootprint:k,footprint:k,reason:"pitched-requires-rectangle",diagnostics:w};const v=e.type==="flat"||!k.rectangle?0:Math.tan(e.pitchDeg*Math.PI/180)*(c3(k.rectangle,e.ridgeDirection).runLengthMm/2+e.overhangMm),C=d+e.thicknessMm+(e.type==="flat"?e.parapetHeightMm:v);return{...M,canRender:!0,reason:null,effectiveFootprint:k,footprint:k,maxElevationMm:C,diagnostics:w}}function Y5(t,e,s){const o=t==null?void 0:t.levels[t.levels.length-1],r=e.find(i=>i.id===(o==null?void 0:o.id))??e[e.length-1];return FA(o,s,(r==null?void 0:r.alignmentStatus)??"not_required",(r==null?void 0:r.visible)!==!1)}const CA=["tiles","slate","membrane","metal"],l2="/textures/site";function ig(t){return{diffuse:`${l2}/${t}_diff.webp`,normal:`${l2}/${t}_nor.webp`,roughness:`${l2}/${t}_rough.webp`}}const d3={tiles:{labelHe:"רעפים",hintHe:"רעפי חרס בגוון טרהקוטה",...ig("roof-tiles"),acrossSlopeM:2.5,alongSlopeM:2.5,tint:"#ffffff",roughnessScalar:.88,metalness:0,trimBase:"#B4643C"},slate:{labelHe:"צפחה",hintHe:"רעפי צפחה אפורים, שכבות דקות",...ig("roof-slate"),acrossSlopeM:3,alongSlopeM:3,tint:"#ffffff",roughnessScalar:.9,metalness:0,trimBase:"#9A948A"},membrane:{labelHe:"איטום",hintHe:"יריעות ביטומן לגג שטוח",...ig("roof-membrane"),acrossSlopeM:20,alongSlopeM:20,tint:"#ffffff",roughnessScalar:.95,metalness:0,trimBase:"#5A564F"},metal:{labelHe:"פאנל מתכת",hintHe:"פאנל מגולוון, גלים לאורך השיפוע",...ig("roof-metal"),acrossSlopeM:2.7,alongSlopeM:2.7,tint:"#ffffff",roughnessScalar:.55,metalness:.65,trimBase:"#7C7F82"}};function NA(t){return t==="tiles"||t==="slate"||t==="membrane"||t==="metal"}function IA(t,e){return e==="underside"?G5(t.trimBase,"#2A2622",.45):G5(t.trimBase,"#EFE9E0",.55)}function G5(t,e,s){const o=U5(t),r=U5(e),i=a=>Math.round(o[a]+(r[a]-o[a])*s);return`#${[0,1,2].map(a=>i(a).toString(16).padStart(2,"0")).join("")}`}function U5(t){const e=t.replace("#",""),s=e.length===3?e.split("").map(o=>o+o).join(""):e;return[parseInt(s.slice(0,2),16)||0,parseInt(s.slice(2,4),16)||0,parseInt(s.slice(4,6),16)||0]}const TA=200,Ts=.001;function K5(t,e,s){return{x:t.x+e.x*s,y:t.y+e.y*s}}function Fi(t,e,s,o,r){return K5(K5(t.center,o,e),r,s)}function Bn(t,e){return{x:t.x*Ts,y:e*Ts,z:t.y*Ts}}function uc(t,e,s){const o=new Ua;return o.setAttribute("position",new Ur(t.flatMap(r=>[r.x,r.y,r.z]),3)),o.setAttribute("uv",new Ur(t.flatMap(r=>s(r)),2)),o.setIndex(e),o.computeVertexNormals(),o.computeBoundingBox(),o.computeBoundingSphere(),o}function vf(t,e,s,o,r,i,a){const l=Math.hypot(1,r);return c=>{const d=c.x/Ts-t.x,u=c.z/Ts-t.y,h=c.y/Ts-e,x=(d*s.x+u*s.y)*Ts/i,b=(d*o.x+u*o.y+h*r)/l*Ts/a;return[x,b]}}function SA(t,e,s){const o=t.getAttribute("position"),r=[];for(let i=0;i<o.count;i+=1)r.push(o.getX(i)/e,o.getY(i)/s);t.setAttribute("uv",new Ur(r,2))}function Z5(t,e){const s=t.map(o=>({...o}));return qc(s)<0!==e&&s.reverse(),s}function q5(t,e){t.moveTo(e[0].x*Ts,-e[0].y*Ts);for(const s of e.slice(1))t.lineTo(s.x*Ts,-s.y*Ts);t.closePath()}function PA(t,e,s,o){const r=e/2,i=Bd(t,r),a=Bd(t,-r);if(!i||!a)return null;const l=Math.abs(qc(i)),c=Math.abs(qc(a)),d=Z5(l>=c?i:a,!1),u=Z5(l>=c?a:i,!0),h=new $l;q5(h,d);const x=new Gd;q5(x,u),h.holes.push(x);const f=new ub(h,{depth:s*Ts,bevelEnabled:!1,curveSegments:1,steps:1});return f.rotateX(-Math.PI/2),f.translate(0,o*Ts,0),f.computeVertexNormals(),f.computeBoundingBox(),f.computeBoundingSphere(),f}function u3(t){var r,i;const e=t.material.preset?d3[t.material.preset]:void 0,s=e?e.acrossSlopeM*100:((r=t.material.texture)==null?void 0:r.tileWidthCm)??100,o=e?e.alongSlopeM*100:((i=t.material.texture)==null?void 0:i.tileHeightCm)??100;return{tileWidthM:Math.max(.05,s/100),tileHeightM:Math.max(.05,o/100)}}function AA(t,e){if(!e.effectiveFootprint)return[];const{tileWidthM:s,tileHeightM:o}=u3(t),r=Bd(e.effectiveFootprint.outer,t.overhangMm),i=e.effectiveFootprint.holes.map(h=>Bd(h,t.overhangMm));if(!r||i.some(h=>h===null))return[];const a=i,l=new $l;l.moveTo(r[0].x*Ts,-r[0].y*Ts);for(const h of r.slice(1))l.lineTo(h.x*Ts,-h.y*Ts);l.closePath();for(const h of a){const x=new Gd;x.moveTo(h[0].x*Ts,-h[0].y*Ts);for(const f of h.slice(1))x.lineTo(f.x*Ts,-f.y*Ts);x.closePath(),l.holes.push(x)}const c=new ub(l,{depth:t.thicknessMm*Ts,bevelEnabled:!1,curveSegments:1,steps:1});SA(c,s,o),c.rotateX(-Math.PI/2),c.translate(0,e.baseElevationMm*Ts,0),c.computeVertexNormals();const d=[{id:"roof:face:flat",geometry:c,surface:"roof"}];if(t.parapetHeightMm<=0)return d;const u=(h,x)=>{const f=PA(h,Math.max(80,t.thicknessMm),t.parapetHeightMm,e.baseElevationMm+t.thicknessMm);f&&d.push({id:`roof:parapet:${x}:0`,geometry:f,surface:"parapet"})};return u(r,"outer"),a.forEach((h,x)=>u(h,`hole-${x}`)),d}function LA(t,e,s){const{ridgeAxis:o,runAxis:r,runLengthMm:i,ridgeLengthMm:a}=c3(s,t.ridgeDirection),l=a/2+t.overhangMm,c=i/2+t.overhangMm,d=Math.tan(t.pitchDeg*Math.PI/180)*c,u=e.baseElevationMm+t.thicknessMm,h=u+d,x=e.baseElevationMm,f=x+d,p=Fi(s,-l,-c,o,r),b=Fi(s,l,-c,o,r),M=Fi(s,l,c,o,r),g=Fi(s,-l,c,o,r),w=Fi(s,-l,0,o,r),k=Fi(s,l,0,o,r),{tileWidthM:_,tileHeightM:j}=u3(t),v=Math.tan(t.pitchDeg*Math.PI/180),C=vf(p,u,o,r,v,_,j),N=vf(g,u,o,{x:-r.x,y:-r.y},v,_,j),P=[{id:"roof:face:north",geometry:uc([Bn(p,u),Bn(w,h),Bn(k,h),Bn(b,u)],[0,1,2,0,2,3],C),surface:"roof"},{id:"roof:face:south",geometry:uc([Bn(g,u),Bn(M,u),Bn(k,h),Bn(w,h)],[0,1,2,0,2,3],N),surface:"roof"},{id:"roof:underside:north",geometry:uc([Bn(p,x),Bn(b,x),Bn(k,f),Bn(w,f)],[0,1,2,0,2,3],C),surface:"underside"},{id:"roof:underside:south",geometry:uc([Bn(g,x),Bn(w,f),Bn(k,f),Bn(M,x)],[0,1,2,0,2,3],N),surface:"underside"}],L=[["north",p,b,u,x],["south",M,g,u,x]];for(const[A,W,S,B,R]of L)P.push({id:`roof:fascia:${A}`,geometry:uc([Bn(W,R),Bn(W,B),Bn(S,B),Bn(S,R)],[0,1,2,0,2,3],C),surface:"fascia"});for(const[A,W,S,B]of[["west",p,w,g],["east",b,k,M]])P.push({id:`roof:fascia:${A}`,geometry:uc([Bn(W,x),Bn(W,u),Bn(S,h),Bn(B,u),Bn(B,x),Bn(S,f)],[0,1,2,0,2,5,5,2,3,5,3,4],C),surface:"fascia"});return P.push(...WA(s,o,r,a,i,t.overhangMm,x,f,v)),P}function WA(t,e,s,o,r,i,a,l,c){const d=o/2,u=r/2;if(d<10||u<10)return[];const h=Math.min(TA,d*.45),x=l-1,f=a+c*i,p=f-a>1,b=g=>w=>{const k=w.x/Ts-g.x,_=w.z/Ts-g.y,j=(k*s.x+_*s.y)*Ts,v=w.y-a*Ts;return[j,v]},M=[];for(const[g,w]of[["west",-1],["east",1]]){const k=w*d,_=w*(d-h),j=Fi(t,k,-u,e,s),v=Fi(t,k,u,e,s),
246C=Fi(t,k,0,e,s),N=Fi(t,_,-u,e,s),P=Fi(t,_,u,e,s),L=Fi(t,_,0,e,s),A=b(j),W=p?[Bn(j,a),Bn(j,f),Bn(C,x),Bn(v,f),Bn(v,a)]:[Bn(j,a),Bn(C,x),Bn(v,a)],S=p?w>0?[0,1,2,0,2,4,4,2,3]:[0,2,1,0,4,2,4,3,2]:w>0?[0,1,2]:[0,2,1],B=p?[Bn(N,a),Bn(N,f),Bn(L,x),Bn(P,f),Bn(P,a)]:[Bn(N,a),Bn(L,x),Bn(P,a)],R=p?w>0?[0,2,1,0,4,2,4,3,2]:[0,1,2,0,2,4,4,2,3]:w>0?[0,2,1]:[0,1,2];M.push({id:`roof:gable-wall:${g}:outer`,geometry:uc(W,S,A),surface:"gable-wall"}),M.push({id:`roof:gable-wall:${g}:inner`,geometry:uc(B,R,A),surface:"gable-wall"})}return M}function RA(t,e,s){const{ridgeAxis:o,runAxis:r,runLengthMm:i,ridgeLengthMm:a}=c3(s,t.ridgeDirection),l=a/2+t.overhangMm,c=i/2+t.overhangMm,d=Math.max(0,(a-i)/2),u=Math.tan(t.pitchDeg*Math.PI/180)*c,h=e.baseElevationMm+t.thicknessMm,x=h+u,f=e.baseElevationMm,p=f+u,b=Fi(s,-l,-c,o,r),M=Fi(s,l,-c,o,r),g=Fi(s,l,c,o,r),w=Fi(s,-l,c,o,r),k=Fi(s,-d,0,o,r),_=Fi(s,d,0,o,r),{tileWidthM:j,tileHeightM:v}=u3(t),C=Math.tan(t.pitchDeg*Math.PI/180),N={north:vf(b,h,o,r,C,j,v),south:vf(w,h,o,{x:-r.x,y:-r.y},C,j,v),west:vf(b,h,r,o,C,j,v),east:vf(M,h,r,{x:-o.x,y:-o.y},C,j,v)},L=[["north",[b,k,_,M],[h,x,x,h]],["south",[w,g,_,k],[h,h,x,x]],["west",[b,w,k],[h,h,x]],["east",[M,_,g],[h,x,h]]].map(([W,S,B])=>({id:`roof:face:${W}`,geometry:uc(S.map((R,z)=>Bn(R,B[z])),S.length===4?[0,1,2,0,2,3]:[0,1,2],N[W]),surface:"roof"})),A=[["north",[b,M,_,k],[f,f,p,p]],["south",[w,k,_,g],[f,p,p,f]],["west",[b,k,w],[f,p,f]],["east",[M,g,_],[f,f,p]]];L.push(...A.map(([W,S,B])=>({id:`roof:underside:${W}`,geometry:uc(S.map((R,z)=>Bn(R,B[z])),S.length===4?[0,1,2,0,2,3]:[0,1,2],N[W]),surface:"underside"})));for(const[W,S,B]of[["north",b,M],["east",M,g],["south",g,w],["west",w,b]])L.push({id:`roof:fascia:${W}`,geometry:uc([Bn(S,f),Bn(S,h),Bn(B,h),Bn(B,f)],[0,1,2,0,2,3],N.north),surface:"fascia"});return L}function OA(t,e){if(!e.canRender||!e.effectiveFootprint)return null;const s=t.type==="flat"?AA(t,e):t.type==="gable"&&e.effectiveFootprint.rectangle?LA(t,e,e.effectiveFootprint.rectangle):t.type==="hip"&&e.effectiveFootprint.rectangle?RA(t,e,e.effectiveFootprint.rectangle):[];return s.length===0?null:{parts:s,maxElevationM:e.maxElevationMm*Ts}}const h3="#E98269",m3=.22;function HA({url:t,color:e,selected:s}){const o=RE(t,1,1);return n.jsx("meshStandardMaterial",{map:o,color:e,roughness:.82,metalness:.02,emissive:h3,emissiveIntensity:s?m3:0})}function BA({preset:t,selected:e}){const{map:s,normalMap:o,roughnessMap:r}=rD(t,1,1);return n.jsx("meshStandardMaterial",{map:s,normalMap:o,roughnessMap:r,color:t.tint,roughness:t.roughnessScalar,metalness:t.metalness,emissive:h3,emissiveIntensity:e?m3:0})}function VA({part:t,config:e,selected:s}){var h;const o=e.material.preset?d3[e.material.preset]:void 0,r=t.surface==="roof",i=t.surface==="gable-wall",a=t.surface==="underside"||t.surface==="fascia"||t.surface==="parapet",l=t.surface==="underside"?"#B8AFA2":"#C8BEB1",c=i?"#ffffff":a?o?IA(o,t.surface):l:e.material.color??"#D8D2C6",d=n.jsx("meshStandardMaterial",{color:o&&r?o.trimBase:c,roughness:i?.92:.86,metalness:.01,emissive:h3,emissiveIntensity:s?m3:0});if(i)return d;if(o&&r)return n.jsx(ml,{fallback:d,children:n.jsx(BA,{preset:o,selected:s})},`preset-${e.material.preset}`);const u=r&&e.finish==="tiles"?(h=e.material.texture)==null?void 0:h.url:void 0;return u?n.jsx(ml,{fallback:d,children:n.jsx(HA,{url:u,color:c,selected:s})},u):d}function zA({config:t,host:e,selected:s=!1,onSelect:o,onFocus:r}){const i=m.useMemo(()=>OA(t,e),[t,e]);if(m.useEffect(()=>()=>{i==null||i.parts.forEach(d=>d.geometry.dispose())},[i]),!i)return null;const a=d=>{d.stopPropagation()},l=d=>{d.stopPropagation(),o==null||o()},c=d=>{d.stopPropagation(),r==null||r()};return n.jsx("group",{name:"roof:building",onPointerDown:a,onClick:l,onDoubleClick:c,children:i.parts.map(d=>n.jsx("mesh",{name:d.id,geometry:d.geometry,castShadow:!0,receiveShadow:!0,children:n.jsx(VA,{part:d,config:t,selected:s})},d.id))})}function $A(t){const e=t.footprint.outer.map(f=>f.x*rt),s=t.footprint.outer.map(f=>f.y*rt),o=t.overhangMm*rt,r=Math.min(...e)-o,i=Math.max(...e)+o,a=Math.min(...s)-o,l=Math.max(...s)+o,c=(r+i)/2,d=(a+l)/2,u=t.planRotationDeg*Math.PI/180,h=c-t.rotationCenter.x,x=d-t.rotationCenter.z;return{requestId:t.requestId,centerX:t.rotationCenter.x+h*Math.cos(u)-x*Math.sin(u),centerZ:t.rotationCenter.z+h*Math.sin(u)+x*Math.cos(u),baseY:t.baseElevationMm*rt,maxY:t.maxElevationMm*rt,span:Math.max(Math.hypot(i-r,l-a),.5)}}function c2(t){return{outer:t.outer.map(e=>({...e})),holes:t.holes.map(e=>e.map(s=>({...s})))}}function d2(t,e){if(!yp(t).valid)return!1;const s=Bd(t.outer,e),o=t.holes.map(r=>Bd(r,e));return!!s&&o.every(r=>r!==null)&&yp({outer:s,holes:o}).valid}
246function J5(t,e){return e===0?t.outer:t.holes[e-1]}function u2(t,e,s){return e===0?{...t,outer:s}:{...t,holes:t.holes.map((o,r)=>r===e-1?s:o)}}function Q5(t,e,s,o,r){const i=o/2,a=r/2;return[{x:t.x-e.x*i-s.x*a,y:t.y-e.y*i-s.y*a},{x:t.x+e.x*i-s.x*a,y:t.y+e.y*i-s.y*a},{x:t.x+e.x*i+s.x*a,y:t.y+e.y*i+s.y*a},{x:t.x-e.x*i+s.x*a,y:t.y-e.y*i+s.y*a}]}function tv({points:t,elevationMm:e,color:s,dashed:o=!1}){const r=m.useMemo(()=>new Ua().setFromPoints([...t,t[0]].map(a=>new le(a.x*rt,e*rt,a.y*rt))),[e,t]),i=m.useMemo(()=>{const a=o?new eI({color:s,dashSize:.22,gapSize:.12,depthTest:!1}):new Cy({color:s,depthTest:!1}),l=new $_(r,a);return l.renderOrder=10030,o&&l.computeLineDistances(),l},[s,o,r]);return m.useEffect(()=>()=>{r.dispose(),i.material.dispose()},[r,i]),n.jsx("primitive",{object:i})}function ag({point:t,elevationMm:e,color:s,size:o=.12,onPointerDown:r,onClick:i}){return n.jsxs("group",{position:[t.x*rt,e*rt,t.y*rt],children:[n.jsxs("mesh",{onPointerDown:r,onClick:i,onPointerOver:a=>{a.stopPropagation(),document.body.style.cursor="grab"},onPointerOut:()=>{document.body.style.cursor=""},children:[n.jsx("sphereGeometry",{args:[o*2.2,12,12]}),n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthTest:!1,depthWrite:!1})]}),n.jsxs("mesh",{renderOrder:10031,children:[n.jsx("sphereGeometry",{args:[o,20,20]}),n.jsx("meshBasicMaterial",{color:"#FFFDFC",depthTest:!1})]}),n.jsxs("mesh",{renderOrder:10032,children:[n.jsx("sphereGeometry",{args:[o*.66,20,20]}),n.jsx("meshBasicMaterial",{color:s,depthTest:!1})]})]})}function XA({roofType:t,footprint:e,baseElevationMm:s,overlayElevationMm:o,overhangMm:r,planRotationDeg:i,rotationCenter:a,onPreviewChange:l,onCommit:c}){const{camera:d,gl:u}=Vo(),h=m.useMemo(()=>({outer:e.outer.map(B=>({...B})),holes:e.holes.map(B=>B.map(R=>({...R})))}),[e]),[x,f]=m.useState(h),[p,b]=m.useState(!0),[M,g]=m.useState(null),w=m.useRef(null),k=m.useRef(x);k.current=x,m.useEffect(()=>{f(h),k.current=h,b(!0),g(null),l(h)},[l,h]),m.useEffect(()=>()=>l(null),[l]);const _=m.useCallback((B,R)=>{const z=u.domElement.getBoundingClientRect(),X=new Po((B-z.left)/z.width*2-1,-((R-z.top)/z.height)*2+1),ft=new Ea;ft.setFromCamera(X,d);const tt=new le,G=new Ga(new le(0,1,0),-s*rt);if(!ft.ray.intersectPlane(G,tt))return null;const Y=-(i*Math.PI)/180,J=tt.x-a.x,Mt=tt.z-a.z;return{x:(a.x+J*Math.cos(Y)-Mt*Math.sin(Y))/rt,y:(a.z+J*Math.sin(Y)+Mt*Math.cos(Y))/rt}},[s,d,u,i,a]),j=m.useCallback(B=>{const R=d2(B,r);k.current=B,f(B),b(R),R&&l(B)},[l,r]),v=m.useCallback(B=>{const R=w.current;if(!R)return;if(w.current=null,document.body.style.cursor="",B){k.current=R.rollback,f(R.rollback),b(!0),l(R.rollback);return}const z=k.current;d2(z,r)?c(z):(k.current=R.rollback,f(R.rollback),b(!0),l(R.rollback))},[c,l,r]),C=m.useCallback((B,R,z)=>{B.stopPropagation();const X=_(B.nativeEvent.clientX,B.nativeEvent.clientY);X&&(w.current={...R,pointerId:B.pointerId,initial:c2(k.current),rollback:c2(z??k.current),startPoint:X},document.body.style.cursor="grabbing")},[_]);m.useEffect(()=>{const B=ft=>{const tt=w.current;if(!tt||tt.pointerId!==ft.pointerId)return;const G=_(ft.clientX,ft.clientY);if(!G)return;if(tt.kind==="move"){const _t=G.x-tt.startPoint.x,Ft=G.y-tt.startPoint.y;j({outer:tt.initial.outer.map(Vt=>({x:Vt.x+_t,y:Vt.y+Ft})),holes:tt.initial.holes.map(Vt=>Vt.map(vt=>({x:vt.x+_t,y:vt.y+Ft})))});return}if(tt.kind==="rotate"&&tt.initialRectangle){const _t=tt.initialRectangle,Ft=Math.atan2(tt.startPoint.y-_t.center.y,tt.startPoint.x-_t.center.x),vt=Math.atan2(G.y-_t.center.y,G.x-_t.center.x)-Ft,Ht=Tt=>({x:Tt.x*Math.cos(vt)-Tt.y*Math.sin(vt),y:Tt.x*Math.sin(vt)+Tt.y*Math.cos(vt)});j({outer:Q5(_t.center,Ht(_t.longAxis),Ht(_t.shortAxis),_t.longLengthMm,_t.shortLengthMm),holes:[]});return}if(!tt.selected)return;if(t==="flat"){const _t=[...J5(tt.initial,tt.selected.ringIndex)];_t[tt.selected.vertexIndex]=G,j(u2(tt.initial,tt.selected.ringIndex,_t));return}const Y=tt.initialRectangle;if(!Y)return;const J=Y.corners[(tt.selected.vertexIndex+2)%4],Mt=G.x-J.x,Rt=G.y-J.y,it=Mt*Y.longAxis.x+Rt*Y.longAxis.y,st=Mt*Y.shortAxis.x+Rt*Y.shortAxis.y,ct=Math.max(100,Math.abs(it)),pt=Math.max(100,Math.abs(st)),xt={x:J.x+Y.longAxis.x*it+Y.shortAxis.x*st,y:J.y+Y.longAxis.y*it+Y.shortAxis.y*st};j({outer:Q5({x:(J.x+xt.x)/2,y:(J.y+xt.y)/2},Y.longAxis,Y.shortAxis,ct,pt),holes:[]})},R=ft=>{var tt;((tt=w.current)==null?void 0:tt.pointerId)===ft.pointerId&&v(!1)},z=ft=>{var tt;((tt=w.current)==null?void 0:tt.pointerId)===ft.pointerId&&v(!0)},X=ft=>{if(ft.key==="Escape"&&w.current){v(!0);return}
246if((ft.key==="Delete"||ft.key==="Backspace")&&M&&t==="flat"){const tt=J5(k.current,M.ringIndex);if(tt.length<=3)return;const G=tt.filter((J,Mt)=>Mt!==M.vertexIndex),Y=u2(k.current,M.ringIndex,G);if(!d2(Y,r))return;j(Y),c(Y),g(null)}};return window.addEventListener("pointermove",B),window.addEventListener("pointerup",R),window.addEventListener("pointercancel",z),window.addEventListener("keydown",X),()=>{window.removeEventListener("pointermove",B),window.removeEventListener("pointerup",R),window.removeEventListener("pointercancel",z),window.removeEventListener("keydown",X)}},[v,c,r,j,t,_,M]);const N=[x.outer,...x.holes],P=N.map(B=>Bd(B,r)),L=o+35,A=jb(x.outer),W=(A==null?void 0:A.center)??{x:x.outer.reduce((B,R)=>B+R.x,0)/x.outer.length,y:x.outer.reduce((B,R)=>B+R.y,0)/x.outer.length},S=A?{x:A.center.x+A.longAxis.x*(A.longLengthMm/2+500),y:A.center.y+A.longAxis.y*(A.longLengthMm/2+500)}:null;return n.jsxs("group",{name:"roof:contour-editor",children:[N.map((B,R)=>n.jsxs("group",{children:[n.jsx(tv,{points:B,elevationMm:L,color:p?"#D85D43":"#DC2626"}),P[R]&&n.jsx(tv,{points:P[R],elevationMm:L+18,color:"#336CFF",dashed:!0}),B.map((z,X)=>n.jsx(ag,{point:z,elevationMm:L+35,color:(M==null?void 0:M.ringIndex)===R&&M.vertexIndex===X?"#182137":"#D85D43",onPointerDown:ft=>{g({ringIndex:R,vertexIndex:X}),C(ft,{kind:"vertex",selected:{ringIndex:R,vertexIndex:X},initialRectangle:R===0?A??void 0:void 0})}},`vertex-${X}`)),t==="flat"&&B.map((z,X)=>{const ft=B[(X+1)%B.length],tt={x:(z.x+ft.x)/2,y:(z.y+ft.y)/2};return n.jsx(ag,{point:tt,elevationMm:L+25,color:"#336CFF",size:.075,onPointerDown:G=>{const Y=c2(k.current),J=[...B];J.splice(X+1,0,tt);const Mt=u2(k.current,R,J);j(Mt),g({ringIndex:R,vertexIndex:X+1}),C(G,{kind:"vertex",selected:{ringIndex:R,vertexIndex:X+1}},Y)}},`midpoint-${X}`)})]},`ring-${R}`)),n.jsx(ag,{point:W,elevationMm:L+70,color:"#182137",size:.14,onPointerDown:B=>C(B,{kind:"move"})}),t!=="flat"&&S&&A&&n.jsx(ag,{point:S,elevationMm:L+70,color:"#336CFF",size:.13,onPointerDown:B=>C(B,{kind:"rotate",initialRectangle:A})})]})}function YA({diagnostics:t,elevationMm:e}){return t.openEndpoints.length===0?null:n.jsx("group",{name:"roof:attachment-diagnostics",children:t.openEndpoints.map((s,o)=>n.jsxs("group",{position:[s.x*rt,(e+80)*rt,s.y*rt],children:[n.jsxs("mesh",{renderOrder:10040,children:[n.jsx("sphereGeometry",{args:[.16,20,20]}),n.jsx("meshBasicMaterial",{color:"#DC2626",depthTest:!1})]}),n.jsx("pointLight",{color:"#DC2626",intensity:.4,distance:1.5})]},`${Math.round(s.x)}:${Math.round(s.y)}:${o}`))})}const h2=50;function GA(t){var r,i,a,l;const e=[];for(const c of t){const d=(r=c.start)==null?void 0:r.x,u=(i=c.start)==null?void 0:i.y,h=(a=c.end)==null?void 0:a.x,x=(l=c.end)==null?void 0:l.y;[d,u,h,x].every(f=>typeof f=="number"&&Number.isFinite(f))&&e.push({startX:d,startY:u,endX:h,endY:x})}if(e.length===0)return null;const s=UA(e);if(s&&s.length>=3)return s;const o=[];for(const c of e)o.push({x:c.startX,y:c.startY},{x:c.endX,y:c.endY});return qA(o)}function UA(t){const e=KA(t,h2),s=[],o=(b,M)=>{for(let g=0;g<s.length;g++){const w=s[g].x-b,k=s[g].y-M;if(w*w+k*k<=h2*h2)return g}return s.push({x:b,y:M}),s.length-1},r=new Set,i=[];for(const b of e){const M=o(b.startX,b.startY),g=o(b.endX,b.endY);if(M!==g)for(const[w,k]of[[M,g],[g,M]]){const _=`${w},${k}`;r.has(_)||(r.add(_),i.push([w,k]))}}if(s.length<3)return null;const a=s.map(()=>[]);for(const[b,M]of i){const g=s[b],w=s[M];a[b].push({from:b,to:M,angle:Math.atan2(w.y-g.y,w.x-g.x)})}for(let b=0;b<64;b++){let M=!1;for(let g=0;g<a.length;g++){if(a[g].length!==1)continue;const w=a[g][0];a[g]=[],a[w.to]=a[w.to].filter(k=>k.to!==g),M=!0}if(!M)break}for(const b of a)b.sort((M,g)=>M.angle-g.angle);const l=b=>`${b.from}-${b.to}`,c=new Set,d=i.length,u=Math.max(d*8+64,256),h=b=>{const M=a[b.to];if(!M||M.length===0)return null;const g=M.findIndex(w=>w.to===b.from);return g===-1?null:M[(g+1)%M.length]};let x=null,f=0;for(const b of a)for(const M of b){if(c.has(l(M)))continue;const g=[];let w=M,k=0;for(;w&&!c.has(l(w));){if(k++>u){g.length=0;break}
246c.add(l(w)),g.push(s[w.from]),w=h(w)}if(g.length<3)continue;const _=Vy(g);Math.abs(_)<=f||(f=Math.abs(_),x=g)}if(!x||f<1)return null;const p=ZA(x);return p.length<3?null:Vy(p)>0?p.slice().reverse():p}function KA(t,e){const s=[];for(const i of t)s.push({x:i.startX,y:i.startY},{x:i.endX,y:i.endY});const o=[],r=e*e;for(const i of t){const a=i.endX-i.startX,l=i.endY-i.startY,c=a*a+l*l;if(c<1){o.push(i);continue}const d=[];for(const x of s){if(Math.abs(x.x-i.startX)<1&&Math.abs(x.y-i.startY)<1||Math.abs(x.x-i.endX)<1&&Math.abs(x.y-i.endY)<1)continue;const f=((x.x-i.startX)*a+(x.y-i.startY)*l)/c;if(f<=.01||f>=.99)continue;const p=i.startX+f*a,b=i.startY+f*l;(p-x.x)*(p-x.x)+(b-x.y)*(b-x.y)>r||d.push({t:f,x:x.x,y:x.y})}if(d.length===0){o.push(i);continue}d.sort((x,f)=>x.t-f.t);let u=i.startX,h=i.startY;for(const x of d)o.push({startX:u,startY:h,endX:x.x,endY:x.y}),u=x.x,h=x.y;o.push({startX:u,startY:h,endX:i.endX,endY:i.endY})}return o}function ZA(t){const e=[];for(const s of t){const o=e[e.length-1];o&&Math.abs(o.x-s.x)<1&&Math.abs(o.y-s.y)<1||e.push({x:s.x,y:s.y})}for(;e.length>=2;){const s=e[0],o=e[e.length-1];if(Math.abs(s.x-o.x)<1&&Math.abs(s.y-o.y)<1)e.pop();else break}return e}function Vy(t){const e=t.length;if(e<3)return 0;let s=0;for(let o=0;o<e;o++){const r=t[o],i=t[(o+1)%e];s+=r.x*i.y-i.x*r.y}return s/2}function qA(t){const e=[];for(const a of t)e.some(l=>Math.abs(l.x-a.x)<1&&Math.abs(l.y-a.y)<1)||e.push({x:a.x,y:a.y});if(e.length<3)return null;e.sort((a,l)=>a.x!==l.x?a.x-l.x:a.y-l.y);const s=(a,l,c)=>(l.x-a.x)*(c.y-a.y)-(l.y-a.y)*(c.x-a.x),o=[];for(const a of e){for(;o.length>=2&&s(o[o.length-2],o[o.length-1],a)<=0;)o.pop();o.push(a)}const r=[];for(let a=e.length-1;a>=0;a--){const l=e[a];for(;r.length>=2&&s(r[r.length-2],r[r.length-1],l)<=0;)r.pop();r.push(l)}o.pop(),r.pop();const i=o.concat(r);return i.length<3?null:Vy(i)>0?i.reverse():i}const Nf="level_001",Op=250;function JA(){return`level_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}const zy={type:"flat",finish:"smooth",footprintMode:"auto",pitchDeg:30,overhangMm:0,parapetHeightMm:1e3,thicknessMm:200,ridgeDirection:"auto",material:{color:"#d8d2c6"}},QA={...zy,type:"gable",pitchDeg:30,overhangMm:300,parapetHeightMm:0,thicknessMm:180};function Eu(t){return{walls:[],beams:[],openings:[],furniture:[],calibration:t?{...t}:{scale:1,calibrated:!1,planRotationDeg:0},traceRoomLabels:{},roomFloorOverrides:{},roomFloorRegions:{},wallFaceRegions:{},roomCeilingOverrides:{},wallElectricalFixtures:[],wallNotes:[],viewportNotes:[],sketchEntities:[],sketchFurnitureGroups:[]}}function $y(t){return{id:Nf,name:"קומת קרקע",visible:!0,slabThicknessMm:Op,imageStoragePath:null,imageFilename:null,imageAlign:null,alignmentStatus:"not_required",...t}}function lD(t){return t===0?"קומת קרקע":`קומה ${t}`}const wo="select";function Rl(t){return t===null||t===wo}function Xy(t){return t!==null&&t!==wo}const tL=48,wp=4,_b="#3F3A34",Vd="#ffffff",_a=.006,ev=.18,eL=4,nL=15,oL=50,sL=80,Kh=120,lg=20,cD=20,rL=340,iL=120,aL=240,Eb=180,lL=320,nv=Eb*2,Gn=1e-6,cL=new Set(["#336CFF"]),dL=new Set(["#706A60"]),ov=Math.cos(nL*Math.PI/180);function Zn(t){const e=Math.round(t);return Object.is(e,-0)?0:e}function sv(t){if(!(t===void 0||!Number.isFinite(t)))return Zn(t)}const dD=["minX","maxX","minY","maxY"],uL=180,hL=65;function be(t="fps"){return`${t}_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function rv(t){return{x:Math.round(t.x/rt),y:Math.round(t.z/rt)}}function Ar(t){return{x:t.x*rt,z:t.y*rt}}function Hp(t,e){return[{x:t.x,y:t.y},{x:e.x,y:t.y},{x:e.x,y:e.y},{x:t.x,y:e.y}]}function hl(t){const e=Math.hypot(t.x,t.y);return e<=Gn?null:{x:t.x/e,y:t.y/e}}function Pd(t,e,s){return{x:Math.round(t.x+e.x*s),y:Math.round(t.y+e.y*s)}}function va(t,e){return{x:e.x-t.x,y:e.y-t.y}}function Ad(t,e){return t.x*e.x+t.y*e.y}function iv(t,e){return t.x*e.y-t.y*e.x}function mL(t){const e=t.reduce((s,o)=>({x:s.x+o.x,y:s.y+o.y}),{x:0,y:0});return{x:Math.round(e.x/t.length),y:Math.round(e.y/t.length)}}function _e(t,e,s,o){return[{x:Math.round(t),y:Math.round(e)},{x:Math.round(s),y:Math.round(e)},{x:Math.round(s),y:Math.round(o)},{x:Math.round(t),y:Math.round(o)}]}function Yi(t){const e=Js(t);if(e.length!==4)return null;const s=[...new Set(e.map(u=>u.x))].sort((u,h)=>u-h),o=[...new Set(e.map(u=>u.y))].sort((u,h)=>u-h);if(s.length!==2||o.length!==2)return null;const[r,i]=s,[a,l]=o,c=i-r,d=l-a;return c<=Gn||d<=Gn?null:{minX:r,maxX:i,minY:a,maxY:l,center:{x:Math.round((r+i)/2),y:Math.round((a+l)/2)},lengthMm:c,widthMm:d,vertices:_e(r,a,i,l)}}function fL(t){const e=Yi(t.moving.vertices);if(!e)return null;const s=new Set(t.excludeEntityIds??[t.moving.id]);s.add(t.moving.id);const o=t.moving.groupId??null,r=Math.max(0,t.toleranceXMm),i=Math.max(0,t.toleranceYMm);let a=null;const l=(x,f,p,b,M)=>Math.min(f,b)-Math.max(x,p)>=-M,c=(x,f,p,b,M,g)=>{const w=Math.abs(p);if(w>g)return;const k=g>
2460?w/g:w===0?0:1/0;(!a||k<a.score||k===a.score&&w<a.gapMm)&&(a={delta:f,targetEntityId:x,movingSide:b,targetSide:M,gapMm:w,score:k})},d=(x,f,p,b,M)=>{const g=p-x,w=b-f,k=Math.abs(g)<=Math.abs(w)?g:w;return Math.abs(k)<=M?k:0};for(const x of t.entities){if(x.kind!=="polygon"||s.has(x.id)||o&&x.groupId===o)continue;const f=Yi(x.vertices);if(f){if(l(e.minY,e.maxY,f.minY,f.maxY,i)){const p=d(e.minY,e.maxY,f.minY,f.maxY,i),b=f.maxX-e.minX,M=f.minX-e.maxX;c(x.id,{x:b,y:p},b,"minX","maxX",r),c(x.id,{x:M,y:p},M,"maxX","minX",r)}if(l(e.minX,e.maxX,f.minX,f.maxX,r)){const p=d(e.minX,e.maxX,f.minX,f.maxX,r),b=f.maxY-e.minY,M=f.minY-e.maxY;c(x.id,{x:p,y:b},b,"minY","maxY",i),c(x.id,{x:p,y:M},M,"maxY","minY",i)}}}if(!a||!Number.isFinite(a.score))return null;const{score:u,...h}=a;return h}function Xr(t){const e=Yi(t);if(e){const w=Js(t);if(w.length===4){const k=va(w[0],w[1]),_=va(w[1],w[2]),j=Math.hypot(k.x,k.y),v=Math.hypot(_.x,_.y),C=hl(k),N=hl(_);if(C&&N&&j>Gn&&v>Gn&&Math.abs(C.y)>Math.abs(C.x))return{center:e.center,lengthMm:j,widthMm:v,vertices:w,uAxis:C,vAxis:N,oriented:!0}}return{center:e.center,lengthMm:e.lengthMm,widthMm:e.widthMm,vertices:e.vertices,uAxis:{x:1,y:0},vAxis:{x:0,y:1},oriented:!1}}const s=Js(t);if(s.length!==4)return null;const o=va(s[0],s[1]),r=va(s[1],s[2]),i=va(s[2],s[3]),a=va(s[3],s[0]),l=Math.hypot(o.x,o.y),c=Math.hypot(r.x,r.y),d=Math.hypot(i.x,i.y),u=Math.hypot(a.x,a.y);if(l<=Gn||c<=Gn)return null;const h=hl(o),x=hl(r),f=hl(i),p=hl(a);if(!h||!x||!f||!p)return null;const b=3,M=.015,g=.015;return Math.abs(l-d)>b||Math.abs(c-u)>b||Math.abs(Ad(h,x))>M||Math.abs(iv(h,f))>g||Math.abs(iv(x,p))>g?null:{center:mL(s),lengthMm:l,widthMm:c,vertices:s,uAxis:h,vAxis:x,oriented:!0}}function Bp(t){const e=Js(t);return e.length!==4||!Xr(e)?[]:[0,1,2,3].map(s=>{const o=e[s],r=e[(s+1)%4];return{index:s,a:o,b:r,midpoint:{x:Math.round((o.x+r.x)/2),y:Math.round((o.y+r.y)/2)},lengthMm:Nn(o,r),dimension:s%2===0?"length":"width"}})}function av(t,e,s=[]){if(t.sourceTool!=="rectangle")return null;const o=Xr(t.vertices);if(!o)return null;let r=o.uAxis,i=o.lengthMm;if(t.rectangleWallAnchor){const c=Bp(t.vertices).find(x=>{var f;return x.index===((f=t.rectangleWallAnchor)==null?void 0:f.anchorEdgeIndex)}),d=c?hl(va(c.a,c.b)):null,u=s.find(x=>{var f,p;return x.wallId===((f=t.rectangleWallAnchor)==null?void 0:f.wallId)&&x.side===((p=t.rectangleWallAnchor)==null?void 0:p.side)}),h=u?hl(va(u.a,u.b)):null;d?(r=d,i=(c==null?void 0:c.lengthMm)??i):h&&(r=h)}const a=e==="right"?1:-1;return{x:Math.round(r.x*i*a),y:Math.round(r.y*i*a)}}function xL(t,e){switch(e){case"ne":return{x:t.maxX,y:t.maxY};case"nw":return{x:t.minX,y:t.maxY};case"se":return{x:t.maxX,y:t.minY};default:return{x:t.minX,y:t.minY}}}function pL(t,e,s,o=3){const r=xL(e,s);let i=null,a=1/0;for(let l=0;l<t.length;l++){const c=Nn(t[l],r);c<=a&&(a=c,i=l)}return i!==null&&a<=o?i:null}function gL(t,e,s){const o=(t-1+e)%e,r=t;return s===o?"apexAtMaxU":s===r?"apexAtMinU":null}function bL(t,e,s=15){if(t.kind!=="side"||e.length===0)return null;const o=Math.round(t.widthMm),r=Math.round(t.heightMm);let i=0,a=o;for(const l of e){const c=Math.round(l.rMm);if(c<20)return null;const d=Math.min(c,Math.max(0,o-s));l.kind==="apexAtMaxU"?a=Math.min(a,o-d):i=Math.max(i,d)}return a-i<s?null:_e(i,0,a,r)}function ML(t,e){const s=e.x-t.x,o=e.z-t.z;return s*s+o*o<1e-14?null:Math.atan2(s,o)-Math.PI/4}function yL(t,e,s,o,r=20,i){const a=Math.max(r,Math.round(s)),l=Math.max(r,Math.round(o));if(i){const u=va(t,e),h=Ad(u,i.tangent)<0?-1:1,x=Ad(u,i.normal)<0?-1:1;return Pd(Pd(t,i.tangent,h*a),i.normal,x*l)}const c=e.x<t.x?-1:1,d=e.y<t.y?-1:1;return{x:t.x+c*a,y:t.y+d*l}}function Xl(t,e,s=tL){const o=Math.max(0,e),r=Math.max(8,Math.round(s));return Array.from({length:r},(i,a)=>{const l=Math.PI*2*a/r;return{x:Math.round(t.x+Math.cos(l)*o),y:Math.round(t.y+Math.sin(l)*o)}})}function Nn(t,e){return Math.hypot(e.x-t.x,e.y-t.y)}function $c(t,e){const s=e.x-t.x,o=e.y-t.y,r=Math.hypot(s,o);if(r<oL)return{point:e,axis:null};const i=Math.abs(s)/r,a=Math.abs(o)/r;return i>=ov&&i>=a?{point:{x:e.x,y:t.y},axis:"x"}:a>=ov?{point:{x:t.x,y:e.y},axis:"y"}:{point:e,axis:null}}function wL(t,e){return $c(t,e).point}function kL(t){const e=[{x:0,y:0}];
246for(const o of t)if(o.kind==="polygon")for(const r of o.vertices)e.push(r);else o.kind==="segment"?e.push(o.a,o.b):o.kind==="measure"&&e.push(o.start,o.end);const s=[];for(const o of e)s.some(r=>Nn(r,o)<=2)||s.push(o);return s}function vL(t){const e=[];for(const s of t){if(s.kind==="polygon"){for(let o=0;o<s.vertices.length;o+=1)e.push({a:s.vertices[o],b:s.vertices[(o+1)%s.vertices.length]});continue}s.kind==="segment"&&e.push({a:s.a,b:s.b}),s.kind==="measure"&&e.push({a:s.start,b:s.end})}return e}function jL(t,e,s){const o=s.x-e.x,r=s.y-e.y,i=o*o+r*r;if(i<=Gn)return e;const a=Math.max(0,Math.min(1,((t.x-e.x)*o+(t.y-e.y)*r)/i));return{x:Zn(e.x+o*a),y:Zn(e.y+r*a)}}function uD(t,e,s={}){const o=kL(e),r=s.vertexToleranceMm??rL,i=s.includeWorldAxes??!0;let a=null,l=1/0;for(const p of o){const b=Nn(t,p);b<=r&&b<l&&(a=p,l=b)}if(a){const p={x:Math.round(a.x),y:Math.round(a.y)},b=Math.abs(p.x)<=2&&Math.abs(p.y)<=2;return{point:p,kind:b?"origin":"vertex"}}let c=null,d=1/0;for(const p of vL(e)){const b=jL(t,p.a,p.b),M=Nn(t,b);M<=r&&M<d&&(c=b,d=M)}if(c)return{point:c,kind:"edge"};if(!i)return{point:t,kind:"none"};const u=aL;let h=t.x,x=t.y,f=!1;return Math.abs(t.x)<=u&&(h=0,f=!0),Math.abs(t.y)<=u&&(x=0,f=!0),f?{point:{x:Math.round(h),y:Math.round(x)},kind:"worldAxis"}:{point:t,kind:"none"}}function _L(t){const e=uD(t.candidate,t.entities,{vertexToleranceMm:iL,includeWorldAxes:!1});return{point:e.point,inferenceSnapKind:e.kind}}function lv(t){const{candidate:e,entities:s,draft:o,tapeAnchor:r=null}=t,i=uD(e,s);let a=i.point;const l=i.kind;if((o==null?void 0:o.tool)==="polygon"&&o.polygonPoints&&o.polygonPoints.length>0){const c=o.polygonPoints[0];if(c&&o.polygonPoints.length>=3&&Nn(c,a)<=sL)return{point:c,isPolygonCloseGesture:!0,inferenceSnapKind:l};const d=o.polygonPoints[o.polygonPoints.length-1];a=$c(d,a).point}else(o==null?void 0:o.tool)==="line"&&o.start||((o==null?void 0:o.tool)==="rectangle"||(o==null?void 0:o.tool)==="circle")&&o.start?a=$c(o.start,a).point:r&&(a=$c(r,a).point);return{point:a,isPolygonCloseGesture:!1,inferenceSnapKind:l}}function If(t,e,s=Eb){let o=null;for(const r of e){const i=va(r.a,r.b),a=i.x*i.x+i.y*i.y;if(a<=Gn)continue;const l=((t.x-r.a.x)*i.x+(t.y-r.a.y)*i.y)/a,c=Math.max(0,Math.min(1,l)),d={x:r.a.x+i.x*c,y:r.a.y+i.y*c},u=Math.hypot(t.x-d.x,t.y-d.y);if(u>s||o&&u>=o.distanceMm)continue;const h=hl(i);h&&(o={segment:r,point:{x:Math.round(d.x),y:Math.round(d.y)},tangent:h,normal:{x:-h.y,y:h.x},distanceMm:u,t:c})}return o}function EL(t,e,s=!1,o=Eb){return s?null:If(t,e,o)}function f3(t,e,s,o=20){const r=va(t,e),i=Ad(r,s.tangent),a=Ad(r,s.normal);if(Math.abs(i)<o||Math.abs(a)<o)return null;const l=Pd(t,s.tangent,i),c=Pd(l,s.normal,a),d=Pd(t,s.normal,a);return[t,l,c,d]}function DL(t,e,s={}){var C;if(t.sourceTool!=="rectangle"||e.length===0)return null;const o=typeof s=="number"?s:s.toleranceMm??Eb,r=typeof s=="number"?null:s.stickySnap??null,i=typeof s=="number"?nv:s.releaseToleranceMm??nv,a=Js(t.vertices);if(!Xr(a)||a.length!==4)return null;const c=Bp(a);let d=null;if(r){const N=c.find(L=>L.index===r.anchorEdgeIndex),P=e.find(L=>L.wallId===r.wallId&&L.side===r.side);if(N&&P){const L=If(N.midpoint,[P],Math.max(o,i));L&&(d={edge:N,wallSnap:L})}}for(const N of d?[]:c){const P=If(N.midpoint,e,o);P&&(!d||P.distanceMm<d.wallSnap.distanceMm)&&(d={edge:N,wallSnap:P})}if(!d)return null;const{edge:u,wallSnap:h}=d,x=hl(va(u.a,u.b)),f=a[(u.index+2)%4],p=a[(u.index+3)%4],b=u.midpoint,M={x:(f.x+p.x)/2,y:(f.y+p.y)/2},g=hl(va(b,M));if(!x||!g)return null;const w=Ad(x,h.tangent)<0?-1:1,k={x:h.tangent.x*w,y:h.tangent.y*w},_=Ad(g,h.normal)<0?-1:1,j={x:h.normal.x*_,y:h.normal.y*_},v=N=>{const P=va(b,N),L=Ad(P,x),A=Ad(P,g);return{x:Math.round(h.point.x+k.x*L+j.x*A),y:Math.round(h.point.y+k.y*L+j.y*A)}};return{polygon:{...t,vertices:a.map(v),holes:(C=t.holes)==null?void 0:C.map(N=>N.map(v)),rectangleWallAnchor:{wallId:h.segment.wallId,side:h.segment.side,anchorEdgeIndex:u.index}},wallSnap:h,anchorEdgeIndex:u.index}}function FL(t,e,s=eL){return Math.hypot(e.x-t.x,e.y-t.y)>=s}function CL(t,e,s,o,r={}){if(t==="line"){const a=$c(e,s).point;return Nn(e,a)<20?null:WL(e,a,o)}if(t==="rectangle"){const a=r.rectangleWallSnap?f3(e,s,r.rectangleWallSnap):Hp(e,s);if(!a)return null;const l=Xr(a);if(!l||l.lengthMm<20||l.widthMm<20)return null;const c=Ae(r.rectangleWallSnap?a:l.vertices,"rectangle",o);
246return!r.rectangleWallSnap||c.kind!=="polygon"?c:{...c,rectangleWallAnchor:{wallId:r.rectangleWallSnap.segment.wallId,side:r.rectangleWallSnap.segment.side,anchorEdgeIndex:0}}}const i=Nn(e,s);return i<20?null:Ae(Xl(e,i),"circle",o)}function cg(t,e){const s=Js(t.points);switch(e.type){case"click":{if(e.isCloseGesture&&s.length>=3)return{next:{points:s},commitPoints:s};const o={x:Math.round(e.point.x),y:Math.round(e.point.y)};return{next:{points:Js([...s,o])},commitPoints:null}}case"close":return{next:{points:s},commitPoints:s.length>=3?s:null};case"backspace":return{next:{points:s.slice(0,-1)},commitPoints:null};case"abort":return{next:{points:[]},commitPoints:null}}}function NL(t,e,s){const o=Js(t);return e?s&&o.length>=3?[...o,o[0]]:[...o,{x:Math.round(e.x),y:Math.round(e.y)}]:o}function cv(t,e,s=10){const o=Js(t);if(!Xi(o))return null;const r={x:Math.round(e.x),y:Math.round(e.y)};if(!z1(r,o))return null;const i=fv(r,o),a=fv(pW(o),o),l=Math.max(1,a-Math.max(0,s));return Math.round(Math.min(Math.max(1,i),l))}function m2(t,e,s,o){const r=Math.max(1,Math.round(o)),i=s.x-e.x,a=s.y-e.y,l=Math.hypot(i,a)<=Gn?{x:e.x,y:e.y+r}:kp(e,s,r);return ko(t,l)}function kp(t,e,s){const o=Math.max(0,Math.round(s)),r=e.x-t.x,i=e.y-t.y,a=Math.hypot(r,i);return a<=Gn?{x:t.x+o,y:t.y}:{x:Math.round(t.x+r/a*o),y:Math.round(t.y+i/a*o)}}function IL(t,e,s=20){const o=Math.max(s,Math.round(e));return{...t,b:kp(t.a,t.b,o)}}function TL(t,e,s,o=20){const r=Yi(t.vertices);if(!r)return t;const i=Math.max(o,Math.round(e)),a=Math.max(o,Math.round(s)),l=i/2,c=a/2;return AL(t,r.center.x-l,r.center.y-c,r.center.x+l,r.center.y+c,o)}function hD(t,e,s,o=20){const r=Xr(t.vertices);if(!r)return t;if(!r.oriented)return TL(t,e,s,o);const i=Math.max(o,Math.round(e)),a=Math.max(o,Math.round(s)),l=i/2,c=a/2,d=r.center,u=(h,x)=>({x:Math.round(d.x+r.uAxis.x*h+r.vAxis.x*x),y:Math.round(d.y+r.uAxis.y*h+r.vAxis.y*x)});return{...t,vertices:[u(-l,-c),u(l,-c),u(l,c),u(-l,c)]}}function SL(t,e,s,o,r=20){const i=Js(t.vertices);if(!Xr(i)||i.length!==4)return t;const l=Bp(i).find(v=>v.index===o);if(!l)return hD(t,e,s,r);const c=hl(va(l.a,l.b)),d=i[(o+2)%4],u=i[(o+3)%4],h={x:(d.x+u.x)/2,y:(d.y+u.y)/2},x=hl({x:h.x-l.midpoint.x,y:h.y-l.midpoint.y});if(!c||!x)return t;const f=Math.max(r,Math.round(e)),p=Math.max(r,Math.round(s)),b=(l.dimension==="length"?f:p)/2,M=l.dimension==="length"?p:f,g=Pd(l.midpoint,c,-b),w=Pd(l.midpoint,c,b),k=Pd(w,x,M),_=Pd(g,x,M),j=[...i];return j[o]=g,j[(o+1)%4]=w,j[(o+2)%4]=k,j[(o+3)%4]=_,{...t,vertices:j}}function PL(t,e,s,o=20){var w;const r=Xr(t.vertices);if(!r)return t;const i=Math.max(1,Math.round(o)),a=-r.lengthMm/2,l=r.lengthMm/2,c=-r.widthMm/2,d=r.widthMm/2;let u=a,h=l,x=c,f=d;const p=k=>{const _=k.x-r.center.x,j=k.y-r.center.y;return{u:_*r.uAxis.x+j*r.uAxis.y,v:_*r.vAxis.x+j*r.vAxis.y}},b=p({x:Math.round(s.x),y:Math.round(s.y)});e.includes("w")&&(u=Math.min(b.u,h-i)),e.includes("e")&&(h=Math.max(b.u,u+i)),e.includes("n")&&(x=Math.min(b.v,f-i)),e.includes("s")&&(f=Math.max(b.v,x+i));const M=(k,_)=>({x:Math.round(r.center.x+r.uAxis.x*k+r.vAxis.x*_),y:Math.round(r.center.y+r.uAxis.y*k+r.vAxis.y*_)}),g=k=>{const _=p(k),j=(_.u-a)/r.lengthMm,v=(_.v-c)/r.widthMm;return M(u+j*(h-u),x+v*(f-x))};return{...t,vertices:[M(u,x),M(h,x),M(h,f),M(u,f)],holes:(w=t.holes)==null?void 0:w.map(k=>k.map(g))}}function H1(t,e){var o;const s=r=>({x:Math.round(r.x+e.x),y:Math.round(r.y+e.y)});return{...t,vertices:t.vertices.map(s),holes:(o=t.holes)==null?void 0:o.map(r=>r.map(s))}}function AL(t,e,s,o,r,i){var b;const a=Yi(t.vertices);if(!a)return t;const l=Math.max(1,Math.round(i)),c=Math.round(Math.min(e,o-l)),d=Math.round(Math.min(s,r-l)),u=Math.round(Math.max(o,c+l)),h=Math.round(Math.max(r,d+l)),x=u-c,f=h-d,p=M=>({x:Math.round(c+(M.x-a.minX)/a.lengthMm*x),y:Math.round(d+(M.y-a.minY)/a.widthMm*f)});return{...t,vertices:_e(c,d,u,h),holes:(b=t.holes)==null?void 0:b.map(M=>M.map(p))}}function LL(t,e,s,o=20){return e==="a"?{...t,a:pv(t.b,s,t.a,o)}:{...t,b:pv(t.a,s,t.b,o)}}function WL(t,e,s=be("fps_line")){return{id:s,kind:"segment",sourceTool:"line",a:t,b:e,color:_b,createdAt:Date.now()}}function Me(){return be("fps_group")}function Ae(t,e,s=be(`fps_${e}`)){return{id:s,kind:"polygon",sourceTool:e,vertices:Js(t),holes:[],heightMm:0,color:Vd,createdAt:Date.now()}}function RL(t,e,s,o,r,i=be("fps_patch")){const a=Yi(Hp(s,o));
246return!a||a.lengthMm<20||a.widthMm<20?null:{id:i,kind:"facePatch",sourceTool:"faceRectangle",hostEntityId:t,hostFaceId:e,shape:"rectangle",points2D:a.vertices,depthMm:0,groupId:r,color:Vd,createdAt:Date.now()}}function lo(t,e,s,o,r=be("fps_patch"),i="faceRectangle",a,l){const c=Js(s);if(!Xi(c))return null;const d=Yi(c),u=l!=null&&l.length?l.map(h=>Js(h)).filter(h=>Xi(h)):void 0;return{id:r,kind:"facePatch",sourceTool:i,hostEntityId:t,hostFaceId:e,shape:d?"rectangle":"polygon",promotedRegionKey:a,points2D:(d==null?void 0:d.vertices)??c,...u!=null&&u.length?{holes2D:u}:{},depthMm:0,groupId:o,color:Vd,createdAt:Date.now()}}function OL(t,e){const s=hc(t),o=hc(e);return s===0||o===0?e:Math.sign(s)===Math.sign(o)?[...e].reverse():e}function HL(t,e,s,o=Kh,r,i=be("fps_face_offset"),a=0){const l=Js(s);if(!Xi(l))return null;const c=$1(l,o);if(!c)return null;const d=Yi(l),u=Yi(c),h=(d==null?void 0:d.vertices)??l,x=(u==null?void 0:u.vertices)??c,f=OL(h,x),p=lo(t,e,h,r,i,"faceOffset",void 0,[f]);return p?a?{...p,depthMm:a}:p:null}function Tf(t,e,s=1){const o=ko(t,e),r=[];return o.x<=s&&r.push("minX"),t.widthMm-o.x<=s&&r.push("maxX"),o.y<=s&&r.push("minY"),t.heightMm-o.y<=s&&r.push("maxY"),r}function sp(t,e,s,o,r=be("fps_face_split")){const i=ko(t,e),a=ko(t,s);if(Nn(i,a)<20)return null;const l=Tf(t,i),c=Tf(t,a);return!l.length||!c.length||l.some(d=>c.includes(d))?null:{id:r,kind:"faceSplit",hostEntityId:t.hostEntityId,hostFaceId:t.faceId,a2D:i,b2D:a,groupId:o,color:_b,createdAt:Date.now()}}function BL(t,e,s,o,r,i=be("fps_face_measure")){const a={x:Zn(s.x),y:Zn(s.y)},l={x:Zn(o.x),y:Zn(o.y)};
246return!t||Nn(a,l)<=Gn?null:{id:i,kind:"faceMeasure",hostEntityId:t,hostFaceId:e,start2D:a,end2D:l,groupId:r,createdAt:Date.now()}}function VL(t,e,s,o=be("fps_measure"),r,i){const a={x:Zn(t.x),y:Zn(t.y)},l={x:Zn(e.x),y:Zn(e.y)};return Nn(a,l)<=Gn?null:{id:o,kind:"measure",start:a,end:l,startElevationMm:sv(r),endElevationMm:sv(i),groupId:s,createdAt:Date.now()}}function zL(t,e,s){switch(s){case"minX":return{x:t.widthMm,y:e.y};case"maxX":return{x:0,y:e.y};case"minY":return{x:e.x,y:t.heightMm};case"maxY":return{x:e.x,y:0}}}function $L(t,e,s){const o=ko(t,e),r=ko(t,s);if(Nn(o,r)<20)return null;const i=Math.round(t.widthMm),a=Math.round(t.heightMm),l=[{a:{x:0,y:0},b:{x:i,y:0}},{a:{x:i,y:0},b:{x:i,y:a}},{a:{x:i,y:a},b:{x:0,y:a}},{a:{x:0,y:a},b:{x:0,y:0}}],c=[];for(const u of l){const h=y3(o,r,u.a,u.b);if(!h||!jf(u.a,h,u.b))continue;const x={x:Zn(h.x),y:Zn(h.y)};Tf(t,x).length&&(c.some(f=>Nn(f,x)<=1)||c.push(x))}let d=null;for(let u=0;u<c.length;u++)for(let h=u+1;h<c.length;h++){const x=c[u],f=c[h],p=sp(t,x,f,void 0,"preview");if(!p)continue;const b=Nn(x,f);(!d||b>d.distance)&&(d={a:p.a2D,b:p.b2D,distance:b})}return d?{a:d.a,b:d.b}:null}const mD={ne:["maxY","maxX"],nw:["maxY","minX"],se:["minY","maxX"],sw:["minY","minX"]};function $f(t,e,s){const o=Math.round(e),r=Math.round(s);switch(t){case"ne":return{x:o,y:r};case"nw":return{x:0,y:r};case"se":return{x:o,y:0};default:return{x:0,y:0}}}function XL(t,e,s,o){const r=Math.round(o),i=Math.round(e),a=Math.round(s);switch(t){case"ne":return{x:i-r,y:a-r};case"nw":return{x:r,y:a-r};case"sw":return{x:r,y:r};default:return{x:i-r,y:r}}}function fD(t,e){const[s,o]=mD[t];return e===s?o:e===o?s:null}function YL(t,e,s){const o=t.widthMm,r=t.heightMm,i=ko(t,s);return e==="maxY"?i.x<=o/2?"nw":"ne":e==="minY"?i.x<=o/2?"sw":"se":e==="minX"?i.y<=r/2?"sw":"nw":i.y<=r/2?"se":"ne"}function n1(t,e,s,o){const r=Math.round(t.widthMm),i=Math.round(t.heightMm);if(r<=60||i<=60||!fD(e,s))return null;const a=ko(t,o);let l;switch(e){case"ne":l=s==="maxY"?r-a.x:i-a.y;break;case"nw":l=s==="maxY"?a.x:i-a.y;break;case"sw":l=s==="minY"?a.x:a.y;break;default:l=s==="minY"?r-a.x:a.y;break}const c=Zn(l);return c<20||c>r-20||c>i-20?null:c}function GL(t,e,s,o,r=be("fps_corner_arc")){const i=Math.round(t.widthMm),a=Math.round(t.heightMm),l=Math.round(s);return!Number.isFinite(l)||l<20||l>i-20||l>a-20?null:{id:r,kind:"faceCornerArc",hostEntityId:t.hostEntityId,hostFaceId:t.faceId,corner:e,radiusMm:l,groupId:o,color:_b,createdAt:Date.now()}}function x3(t,e,s,o=cD){const i=Math.round(t.widthMm),a=0,l=Math.round(t.heightMm),c=Math.round(s),d=Math.max(8,Math.round(o)),u=(h,x,f,p)=>{const b=[];for(let M=1;M<d;M++){const g=p(M);b.push({x:Zn(h+f*Math.cos(g)),y:Zn(x+f*Math.sin(g))})}return b};switch(e){case"ne":{const h=Math.min(c,Math.min(i-0,l-a)-20);if(h<20)return[];const x=i-h,f=l-h,p={x:i,y:l-h},b={x:i-h,y:l},M=u(x,f,h,g=>Math.PI/2*(g/d));return[p,...M,b]}case"nw":{const h=Math.min(c,Math.min(i-0,l-a)-20);if(h<20)return[];const x=0+h,f=l-h,p={x:0+h,y:l},b={x:0,y:l-h},M=u(x,f,h,g=>Math.PI/2+Math.PI/2*(g/d));return[p,...M,b]}case"sw":{const h=Math.min(c,Math.min(i-0,l-a)-20);if(h<20)return[];const x=0+h,f=a+h,p={x:0+h,y:a},b={x:0,y:a+h},M=u(x,f,h,g=>Math.PI+Math.PI/2*(g/d));return[p,...M,b]}default:{const h=Math.min(c,Math.min(i-0,l-a)-20);if(h<20)return[];const x=i-h,f=a+h,p={x:i-h,y:a},b={x:i,y:a+h},M=u(x,f,h,g=>-(Math.PI/2)*(g/d));return[b,...M,p]}}}function dg(t,e,s){const o=Js(t),r=Js(e);if(!Xi(o)||!Xi(r))return null;const i=vp(o),a=vp(r);return!i||!a?null:{main:{role:s,bounds:i,points2D:o},chip:{role:"split",bounds:a,points2D:r}}}function UL(t,e,s,o,r,i){const a=t.minX,l=t.maxX,c=t.minY,d=t.maxY,u=l-a,h=d-c,x=Math.min(u-20,h-20),f=Math.min(Math.round(r),x);if(f<20||x<20)return null;const p=Math.max(8,cD);switch(o){case"ne":{if(Math.round(t.maxX)!==e||Math.round(t.maxY)!==s)return null;const b=l-f,M=d-f,g={x:l,y:d-f},w={x:l-f,y:d},k=[];for(let C=1;C<p;C++){const N=Math.PI/2*(C/p);k.push({x:Zn(b+f*Math.cos(N)),y:Zn(M+f*Math.sin(N))})}const _=[];for(let C=p-1;C>=1;C--){const N=Math.PI/2*(C/p);_.push({x:Zn(b+f*Math.cos(N)),y:Zn(M+f*Math.sin(N))})}const j=[{x:a,y:c},{x:l,y:c},g,...k,w,{x:a,y:d}],v=[g,{x:l,y:d},w,..._];return dg(j,v,i)}case"nw":{if(Math.round(t.minX)!==0||Math.round(t.maxY)!==s)return null;const b=a+f,M=d-f,g=[];for(let N=1;N<p;N++){const P=Math.PI/2+Math.PI/2*(N/p);g.push({x:Zn(b+f*Math.cos(P)),y:Zn(M+f*Math.sin(P))})}const w=[];for(let N=p-1;N>=1;N--){const P=Math.PI/2+Math.PI/2*(N/p);w.push({x:Zn(b+f*Math.cos(P)),y:Zn(M+f*Math.sin(P))})}const k={x:a,y:d-f},_={x:a+f,y:d},v=[{x:a,y:c},{x:l,y:c},{x:l,y:d},_,...g,k],C=[k,{x:a,y:d},_,...w];return dg(v,C,i)}case"sw":{if(Math.round(t.minX)!==0||Math.round(t.minY)!==0)return null;const b=a+f,M=c+f,g=[];for(let C=1;C<p;C++){const N=Math.PI+Math.PI/2*(C/p);g.push({x:Zn(b+f*Math.cos(N)),y:Zn(M+f*Math.sin(N))})}const w=[];for(let C=p-1;C>=1;C--){const N=Math.PI+Math.PI/2*(C/p);w.push({x:Zn(b+f*Math.cos(N)),y:Zn(M+f*Math.sin(N))})}const k={x:a,y:c+f},_={x:a+f,y:c},j=l>a+f+1?[{x:a,y:d},{x:l,y:d},{x:l,y:c},_,...g,k]:[{x:a,y:d},{x:l,y:d},_,...g,k],v=[k,{x:a,y:c},_,...w];return dg(j,v,i)}
246default:{if(Math.round(t.maxX)!==e||Math.round(t.minY)!==0)return null;const b=l-f,M=c+f,g=[];for(let C=1;C<p;C++){const N=-(Math.PI/2)*(C/p);g.push({x:Zn(b+f*Math.cos(N)),y:Zn(M+f*Math.sin(N))})}const w=[];for(let C=p-1;C>=1;C--){const N=-(Math.PI/2)*(C/p);w.push({x:Zn(b+f*Math.cos(N)),y:Zn(M+f*Math.sin(N))})}const k={x:l-f,y:c},_={x:l,y:c+f},j=d>c+f+1?[{x:a,y:d},{x:l,y:d},_,...g,k,{x:a,y:c}]:[{x:a,y:d},_,...g,k,{x:a,y:c}],v=[_,{x:l,y:c},k,...w];return dg(j,v,i)}}}function KL(t,e,s){if(s.hostEntityId!==t.hostEntityId||s.hostFaceId!==t.faceId)return null;const o=Yi(e.points2D);if(!o||o.vertices.length!==4)return null;const r=Math.round(t.widthMm),i=Math.round(t.heightMm),a=UL(o,r,i,s.corner,s.radiusMm,e.role);return a?s.verticalThroughCut?[a.main]:[a.main,a.chip]:null}function ZL(t,e,s){let o=t;const r=[...s].sort((i,a)=>(i.createdAt??0)-(a.createdAt??0)||i.id.localeCompare(a.id));for(const i of r){const a=[];for(const l of o){const c=KL(e,l,i);c?a.push(...c):a.push(l)}o=a}return o}function B1(t,e=1){const s=Zn(Math.min(t.minX,t.maxX)),o=Zn(Math.max(t.minX,t.maxX)),r=Zn(Math.min(t.minY,t.maxY)),i=Zn(Math.max(t.minY,t.maxY));return o-s<e||i-r<e?null:{minX:s,minY:r,maxX:o,maxY:i}}function xD(t,e=1){const s=Zn(t.minX),o=Zn(t.minY),r=Zn(t.maxX),i=Zn(t.maxY);return r-s<e||i-o<e?null:{minX:s,minY:o,maxX:r,maxY:i}}function qL(t,e){return xD({minX:Math.max(t.minX,e.minX),minY:Math.max(t.minY,e.minY),maxX:Math.min(t.maxX,e.maxX),maxY:Math.min(t.maxY,e.maxY)})}function p3(t,e){if(e.hostEntityId!==t.hostEntityId||e.hostFaceId!==t.faceId||e.shape!=="rectangle")return null;const s=Yi(e.points2D.map(o=>ko(t,o)));return s?B1({minX:Math.max(0,s.minX),minY:Math.max(0,s.minY),maxX:Math.min(t.widthMm,s.maxX),maxY:Math.min(t.heightMm,s.maxY)}):null}function JL(t,e,s=1){return{touchesMinX:e.minX<=s,touchesMaxX:t.widthMm-e.maxX<=s,touchesMinY:e.minY<=s,touchesMaxY:t.heightMm-e.maxY<=s}}function QL(t){const e=[];return t.touchesMinX||e.push("minX"),t.touchesMaxX||e.push("maxX"),t.touchesMinY||e.push("minY"),t.touchesMaxY||e.push("maxY"),e}function dv(t,e,s){if(!e||!t.startsWith("side-"))return null;const o=Number(t.slice(5));if(!Number.isInteger(o)||e.vertices.length<3)return null;const r=e.vertices.length;return`side-${s==="previous"?(o-1+r)%r:(o+1)%r}`}function g3(t,e,s={}){const o=p3(t,e);if(!o)return null;const r=JL(t,o,s.boundaryToleranceMm),i=new Set;if(t.kind==="side"){r.touchesMinY&&i.add("bottom"),r.touchesMaxY&&i.add("top");const c=dv(t.faceId,s.host,"previous"),d=dv(t.faceId,s.host,"next");r.touchesMinX&&c&&i.add(c),r.touchesMaxX&&d&&i.add(d)}const a=Math.round(s.depthMm??e.depthMm??0),l=[];return t.kind==="side"&&a<-.5&&(r.touchesMinY&&l.push({faceId:"bottom",sideFaceId:t.faceId,minU:o.minX,maxU:o.maxX,depthMm:Math.abs(a)}),r.touchesMaxY&&l.push({faceId:"top",sideFaceId:t.faceId,minU:o.minX,maxU:o.maxX,depthMm:Math.abs(a)})),{id:e.id,hostEntityId:e.hostEntityId,hostFaceId:e.hostFaceId,bounds:o,boundary:r,recessSideWalls:QL(r),affectedAdjacentFaces:Array.from(i).sort(),capCuts:l}}function uv(t,e){const s=qL(t,e);if(!s)return null;const o=[],r=(i,a)=>{const l=xD(a);l&&o.push({role:i,bounds:l,points2D:_e(l.minX,l.minY,l.maxX,l.maxY)})};return r("below",{minX:t.minX,minY:t.minY,maxX:t.maxX,maxY:s.minY}),r("above",{minX:t.minX,minY:s.maxY,maxX:t.maxX,maxY:t.maxY}),r("left",{minX:t.minX,minY:s.minY,maxX:s.minX,maxY:s.maxY}),r("right",{minX:s.maxX,minY:s.minY,maxX:t.maxX,maxY:s.maxY}),o}function vp(t){if(!t.length)return null;const e=t.reduce((s,o)=>({minX:Math.min(s.minX,o.x),minY:Math.min(s.minY,o.y),maxX:Math.max(s.maxX,o.x),maxY:Math.max(s.maxY,o.y)}),{minX:Number.POSITIVE_INFINITY,minY:Number.POSITIVE_INFINITY,maxX:Number.NEGATIVE_INFINITY,maxY:Number.NEGATIVE_INFINITY});return B1(e)}function tW(t,e){if(e.hostEntityId!==t.hostEntityId||e.hostFaceId!==t.faceId)return null;const s=ko(t,e.a2D),o=ko(t,e.b2D),r=sp(t,s,o,e.groupId,e.id);return r?{a:r.a2D,b:r.b2D}:null}function hv(t,e,s,o){const r=Js(t);if(r.length<3)return[];const i=[],a=c=>Zx(e,s,c)*o>=-Gn,l=(c,d)=>{const u=y3(c,d,e,s);return!u||!jf(c,u,d)?null:{x:Zn(u.x),y:Zn(u.y)}};for(let c=0;c<r.length;c++){const d=r[c],u=r[(c-1+r.length)%r.length],h=a(d),x=a(u);if(h){if(!x){const f=l(u,d);f&&i.push(f)}i.push(d)}else if(x){const f=l(u,d);f&&i.push(f)}}return Js(i)}function eW(t,e,s=1){return Math.abs(t.minX-e.minX)<=s&&Math.abs(t.minY-e.minY)<=s&&Math.abs(t.maxX-e.maxX)<=s&&Math.abs(t.maxY-e.maxY)<=s}function pD(t,e){var o;const s=[];for(const r of e){if(r.hostEntityId!==t.hostEntityId||r.hostFaceId!==t.faceId)continue;if(r.sourceTool==="faceOffset"&&((o=r.holes2D)!=null&&o.length)){const a=Yi(r.points2D.map(u=>ko(t,u))),l=Yi(r.holes2D[0].map(u=>ko(t,u)));if(!a||!l)continue;const c=B1({minX:Math.max(0,a.minX),minY:Math.max(0,a.minY),maxX:Math.min(t.widthMm,a.maxX),maxY:Math.min(t.heightMm,a.maxY)}),d=B1({minX:Math.max(0,l.minX),minY:Math.max(0,l.minY),maxX:Math.min(t.widthMm,l.maxX),maxY:Math.min(t.heightMm,l.maxY)});if(!c||!d)continue;s.push({kind:"ring",innerBounds:d,outerBounds:c,outerPoints2D:_e(c.minX,c.minY,c.maxX,c.maxY),holes2D:r.holes2D.map(u=>u.map(h=>ko(t,h)))});continue}const i=p3(t,r);i&&s.push({kind:"subtract",bounds:i})}return s.sort((r,i)=>{const a=r.kind==="subtract"?r.bounds:r.innerBounds,l=i.kind==="subtract"?i.bounds:i.innerBounds;return a.minY-l.minY||a.minX-l.minX||a.maxY-l.maxY||a.maxX-l.maxX}),s}function gD(t,e){let s=t;for(const o of e){const r=[];for(const i of s){if(o.kind==="ring"&&eW(i.bounds,o.outerBounds)){r.push({role:i.role,bounds:o.outerBounds,points2D:o.outerPoints2D,holes2D:o.holes2D}),r.push({role:"remaining",bounds:o.innerBounds,points2D:_e(o.innerBounds.minX,o.innerBounds.minY,o.innerBounds.maxX,o.innerBounds.maxY),holes2D:void 0});continue}if(o.kind==="subtract"){const l=uv(i.bounds,o.bounds);if(!l){r.push(i);continue}r.push(...l.map(({role:c,bounds:d})=>({role:c,bounds:d,points2D:_e(d.minX,d.minY,d.maxX,d.maxY),holes2D:void 0})));continue}const a=uv(i.bounds,o.innerBounds);if(!a){r.push(i);continue}r.push(...a.map(({role:l,bounds:c})=>({role:l,bounds:c,points2D:_e(c.minX,c.minY,c.maxX,c.maxY),holes2D:void 0})))}s=r}return s}function nW(t,e){const s=hv(t.points2D,e.a,e.b,1),o=hv(t.points2D,e.a,e.b,-1);
246if(!Xi(s)||!Xi(o))return null;const r=vp(s),i=vp(o);if(!r||!i)return null;const a=Math.abs(hc(t.points2D)),l=Math.abs(hc(s)),c=Math.abs(hc(o));return l<1||c<1||Math.abs(l-a)<1||Math.abs(c-a)<1?null:[{role:"split",bounds:r,points2D:s},{role:"split",bounds:i,points2D:o}]}function oW(t,e){const s=pD(t,e);return s.length?gD([{role:"remaining",bounds:{minX:0,minY:0,maxX:Math.round(t.widthMm),maxY:Math.round(t.heightMm)},points2D:_e(0,0,Math.round(t.widthMm),Math.round(t.heightMm))}],s).sort((r,i)=>r.bounds.minY-i.bounds.minY||r.bounds.minX-i.bounds.minX||r.bounds.maxY-i.bounds.maxY||r.bounds.maxX-i.bounds.maxX||r.role.localeCompare(i.role)).map((r,i)=>{var a;return{regionId:`${t.hostEntityId}:${t.faceId}:region-${i}-${r.role}`,hostEntityId:t.hostEntityId,hostFaceId:t.faceId,role:r.role,bounds:r.bounds,points2D:r.points2D,...(a=r.holes2D)!=null&&a.length?{holes2D:r.holes2D}:{}}}):[]}function V1(t,e,s=[],o=[]){const r=o.filter(c=>c.hostEntityId===t.hostEntityId&&c.hostFaceId===t.faceId);if(!s.length&&!r.length)return oW(t,e);const i=pD(t,e),a=s.map(c=>tW(t,c)).filter(c=>c!==null);if(!i.length&&!a.length&&!r.length)return[];let l=[{role:"remaining",bounds:{minX:0,minY:0,maxX:Math.round(t.widthMm),maxY:Math.round(t.heightMm)},points2D:_e(0,0,Math.round(t.widthMm),Math.round(t.heightMm))}];l=gD(l,i);for(const c of a){const d=[];for(const u of l){const h=nW(u,c);if(!h){d.push(u);continue}d.push(...h.map(x=>({role:x.role,bounds:x.bounds,points2D:x.points2D,holes2D:void 0})))}l=d}return l=ZL(l,t,r),l.sort((c,d)=>c.bounds.minY-d.bounds.minY||c.bounds.minX-d.bounds.minX||c.bounds.maxY-d.bounds.maxY||c.bounds.maxX-d.bounds.maxX||c.role.localeCompare(d.role)).map((c,d)=>{var u;return{hostEntityId:t.hostEntityId,hostFaceId:t.faceId,regionId:`${t.hostEntityId}:${t.faceId}:region-${d}-${c.role}`,role:c.role,bounds:c.bounds,points2D:c.points2D,...(u=c.holes2D)!=null&&u.length?{holes2D:c.holes2D}:{}}})}function ug(t){return`${Math.round(t.x)},${Math.round(t.y)}`}function bD(t){var s;const e=(s=t.holes2D)!=null&&s.length?t.holes2D.map(o=>o.map(ug).join(";")).join("||"):"";return[t.hostEntityId,t.hostFaceId,t.role,ug({x:t.bounds.minX,y:t.bounds.minY}),ug({x:t.bounds.maxX,y:t.bounds.maxY}),t.points2D.map(ug).join(";"),e].join("|")}function b3(t,e,s=be("fps_region")){var x;const o=bD(e),r=t.find(f=>f.kind==="facePatch"&&f.hostEntityId===e.hostEntityId&&f.hostFaceId===e.hostFaceId&&f.promotedRegionKey===o);if(r)return{entities:t,patch:r,created:!1};const i=t.find(f=>f.kind==="polygon"&&f.id===e.hostEntityId);if(!i)return null;const a=An(i,e.hostFaceId);if(!a)return null;const l=i.groupId??Me(),c=lo(i.id,e.hostFaceId,e.points2D.map(f=>ko(a,f)),l,s,"faceSplitRegion",o,(x=e.holes2D)==null?void 0:x.map(f=>f.map(p=>ko(a,p))));if(!c)return null;const d=t.filter(f=>f.kind==="faceCornerArc"&&f.hostEntityId===i.id&&f.hostFaceId===e.hostFaceId).filter(f=>{const p=$f(f.corner,a.widthMm,a.heightMm),b=1;return p.x>=e.bounds.minX-b&&p.x<=e.bounds.maxX+b&&p.y>=e.bounds.minY-b&&p.y<=e.bounds.maxY+b}).map(f=>f.id),u=d.length?{...c,containedArcIds:d}:c;return{entities:t.map(f=>f.id===i.id&&f.kind==="polygon"&&!f.groupId?{...f,groupId:l}:f).concat(u),patch:u,created:!0}}function sW(t,e,s,o=be("fps_xpush")){const r=t.find(x=>x.kind==="polygon"&&x.id===e);if(!r)return null;const i=An(r,s);if(!i)return null;const a=r.groupId??Me(),l=_e(0,0,i.widthMm,i.heightMm),c=lo(r.id,s,l,a,o,"faceRectangle");if(!c)return null;const d=t.filter(x=>x.kind==="faceCornerArc"&&x.hostEntityId===r.id&&x.hostFaceId===s).map(x=>x.id),u=d.length?{...c,containedArcIds:d}:c;return{entities:t.map(x=>x.id===r.id&&x.kind==="polygon"&&!x.groupId?{...x,groupId:a}:x).concat(u),patch:u,created:!0}}const rW="fps_xpush_";function iW(t){return typeof t=="string"&&t.startsWith(rW)}function An(t,e){const s=Math.max(0,Math.round(t.heightMm??0)),o=wD(t.vertices);if(!o)return null;if(e==="top"||e==="bottom"){const f=e==="top";if(t.sourceTool==="rectangle"&&t.vertices.length===4){const p=t.vertices[0],b=t.vertices[1],M=t.vertices[3],g=b.x-p.x,w=b.y-p.y,k=M.x-p.x,_=M.y-p.y,j=Math.hypot(g,w),v=Math.hypot(k,_);if(j>Gn&&v>
246Gn)return{hostEntityId:t.id,faceId:e,kind:f?"top":"bottom",widthMm:j,heightMm:v,minX:0,minY:0,originLocal:new le(p.x*rt,_a+(f?s*rt:0),p.y*rt),uAxisLocal:new le(g/j,0,w/j),vAxisLocal:new le(k/v,0,_/v),normalLocal:new le(0,f?1:-1,0)}}return{hostEntityId:t.id,faceId:e,kind:f?"top":"bottom",widthMm:Math.max(0,o.maxX-o.minX),heightMm:Math.max(0,o.maxY-o.minY),minX:o.minX,minY:o.minY,originLocal:new le(o.minX*rt,_a+(f?s*rt:0),o.minY*rt),uAxisLocal:new le(1,0,0),vAxisLocal:new le(0,0,1),normalLocal:new le(0,f?1:-1,0)}}if(e==="side"||t.sourceTool==="circle"||s<=Gn)return null;const r=Number(e.slice(5));if(!Number.isInteger(r)||r<0||r>=t.vertices.length)return null;const i=t.vertices[r],a=t.vertices[(r+1)%t.vertices.length],l=a.x-i.x,c=a.y-i.y,d=Math.hypot(l,c);if(d<=Gn)return null;const u=new le(l/d,0,c/d),h=hc(t.vertices)>=0?1:-1,x=new le(h*c/d,0,-h*l/d).normalize();return{hostEntityId:t.id,faceId:e,kind:"side",widthMm:d,heightMm:s,minX:0,minY:0,originLocal:new le(i.x*rt,_a,i.y*rt),uAxisLocal:u,vAxisLocal:new le(0,1,0),normalLocal:x}}function Zh(t,e){const s=An(e,t.hostFaceId);if(!s)return null;const o=wD(t.points2D);if(!o)return null;
246const r=o.maxX-o.minX,i=o.maxY-o.minY;if(r<=Gn||i<=Gn)return null;const a=t.depthMm??0,l=s.uAxisLocal.clone(),c=s.vAxisLocal.clone(),d=s.normalLocal.clone(),u=s.originLocal.clone().addScaledVector(l,o.minX*rt).addScaledVector(c,o.minY*rt).addScaledVector(d,a*rt);return{hostEntityId:t.id,faceId:"front",kind:s.kind,widthMm:r,heightMm:i,minX:0,minY:0,originLocal:u,uAxisLocal:l,vAxisLocal:c,normalLocal:d}}function mv(t,e,s){if(t.kind==="polygon")return e?An(t,e):null;if(t.kind==="facePatch"){const o=s(t.hostEntityId);return o?Zh(t,o):null}return null}function Ln(t,e,s=0){const o=ko(t,e);return t.originLocal.clone().addScaledVector(t.uAxisLocal,o.x*rt).addScaledVector(t.vAxisLocal,o.y*rt).addScaledVector(t.normalLocal,s*rt)}function Bl(t,e){const s=e.clone().sub(t.originLocal);return ko(t,{x:Math.round(s.dot(t.uAxisLocal)/rt),y:Math.round(s.dot(t.vAxisLocal)/rt)})}function aW(t,e){const s=new Ga().setFromNormalAndCoplanarPoint(t.normalLocal,t.originLocal),o=new le;return e.intersectPlane(s,o)?Bl(t,o):null}function ko(t,e){return{x:Math.round(Math.max(0,Math.min(t.widthMm,e.x))),y:Math.round(Math.max(0,Math.min(t.heightMm,e.y)))}}function lW(t,e,s){const o=[];for(const r of t)r.kind==="faceMeasure"&&(r.hostEntityId!==e||r.hostFaceId!==s||o.push(r.end2D,r.start2D));return o}function Ol(t,e,s,o=65){const r=typeof o=="number"?{keypointSnapToleranceMm:o,edgeSnapToleranceMm:o,axisSnap:!0}:o,i=r.keypointSnapToleranceMm??65,a=r.edgeSnapToleranceMm??i,l=r.axisSnap??!0,c=ko(t,e),d=r.measureMarkerSnapPoints??[];if(d.length>0){const b=rp(c,d,r.measureMarkerSnapToleranceMm??34);if(b)return{point:b,kind:"endpoint",labelHebrew:"סימון מדידה"}}const u=[{x:0,y:0},{x:t.widthMm,y:0},{x:t.widthMm,y:t.heightMm},{x:0,y:t.heightMm}],h=[{x:t.widthMm/2,y:0},{x:t.widthMm,y:t.heightMm/2},{x:t.widthMm/2,y:t.heightMm},{x:0,y:t.heightMm/2}],x=rp(c,u,i);if(x)return{point:x,kind:"endpoint",labelHebrew:"נקודת קצה"};const f=rp(c,h,i);if(f)return{point:f,kind:"midpoint",labelHebrew:"אמצע"};const p=MW(t,c,a);if(p)return{point:p,kind:"on-edge",labelHebrew:"על קצה"};if(s&&l){const b=$c(s,c);if(b.axis)return{point:ko(t,b.point),kind:"axis",labelHebrew:"נעול ציר"}}return{point:c,kind:"on-face",labelHebrew:"על פאה"}}function cW(t,e,s,o=65){const r=ko(t,e),i=$c(s,r);return i.axis?{point:kW(t,i.point,i.axis,o),kind:"axis",axis:i.axis,labelHebrew:i.axis==="x"?"נעול ציר אופקי":"נעול ציר אנכי"}:Ol(t,e,s,o)}function hg(t,e,s={}){const o=typeof s=="number"?{edgeToleranceMm:s,keypointToleranceMm:s}:s,r=o.edgeToleranceMm??uL,i=o.keypointToleranceMm??hL,a=[{x:0,y:0},{x:t.widthMm,y:0},{x:t.widthMm,y:t.heightMm},{x:0,y:t.heightMm}],l=[{x:t.widthMm/2,y:0},{x:t.widthMm,y:t.heightMm/2},{x:t.widthMm/2,y:t.heightMm},{x:0,y:t.heightMm/2}],c=yW(e,o.allowedEdges,o.referencePoint,o.referenceEdges),d=wW(t,e,r,c);if(!d)return null;const u=rp(d.point,a,i);if(u)return{point:u,kind:"endpoint",edge:d.edge,edges:Tf(t,u),labelHebrew:"נקודת קצה"};const h=rp(d.point,l,i);if(h){const x=Tf(t,h);return{point:h,kind:"midpoint",edge:x[0]??d.edge,edges:x,labelHebrew:"אמצע"}}return{point:d.point,kind:"on-edge",edge:d.edge,edges:Tf(t,d.point),labelHebrew:"על קצה"}}function Xu(t,e,s){return t.map(o=>{var r;if(o.id===s.id)return s;if(e.sourceTool==="offset"&&o.kind==="polygon"&&((r=o.holes)!=null&&r.length)){const i=o.holes.map(a=>jp(a,e.vertices)?s.vertices:a);return i.some((a,l)=>!jp(a,o.holes[l]))?{...o,holes:i}:o}if(_D(o)){const i=IW(e,s,o.vertices);if(i)return{...o,vertices:i,groupId:s.groupId??o.groupId}}return o.kind!=="facePatch"||o.hostEntityId!==e.id?o:kD(o,e,s)})}function hc(t){const e=Js(t);if(e.length<3)return 0;let s=0;for(let o=0;o<e.length;o++){const r=e[o],i=e[(o+1)%e.length];s+=r.x*i.y-i.x*r.y}return s/2}function z1(t,e){const s=Js(e);if(s.length<3)return!1;let o=!1;for(let r=0,i=s.length-1;r<s.length;i=r++){const a=s[r],l=s[i];if(!(a.y>t.y!=l.y>t.y))continue;const d=(l.x-a.x)*(t.y-a.y)/(l.y-a.y+Gn)+a.x;t.x<d&&(o=!o)}return o}function Xi(t){const e=Js(t);if(e.length<3||Math.abs(hc(e))<Gn)return!1;for(let s=0;s<e.length;s++){const o=e[s],r=e[(s+1)%e.length];if(Nn(o,r)<=Gn)return!1;for(let i=s+1;i<e.length;i++){const a=e[i],l=e[(i+1)%e.length];if(!(Math.abs(s-i)<=1)&&!(s===0&&i===e.length-1)&&SW(o,r,a,l))return!1}}return!0}function $1(t,e){const s=Js(t),o=Math.abs(e);if(!Xi(s)||o<=Gn)return null;const r=hc(s),i=r>=0?1:-1,a=s.map((c,d)=>{const u=s[(d+1)%s.length],h=u.x-c.x,x=u.y-c.y,f=Math.hypot(h,x);if(f<=Gn)return null;const p=i>=0?{x:-x/f,y:h/f}:{x:x/f,y:-h/f};return{a:{x:c.x+p.x*o,y:c.y+p.y*o},b:{x:u.x+p.x*o,y:u.y+p.y*o}}});if(a.some(c=>!c))return null;const l=[];for(let c=0;c<s.length;c++){const d=a[(c-1+s.length)%s.length],u=a[c];if(!d||!u)return null;const h=y3(d.a,d.b,u.a,u.b);if(!h)return null;l.push({x:Math.round(h.x),y:Math.round(h.y)})}return!Xi(l)||Math.abs(hc(l))>=Math.abs(r)?null:l}function dW(t,e,s){if(!e)return t;const o=t.find(c=>c.id===e&&c.kind==="polygon");
246if(!o)return t;const r=$1(o.vertices,s);if(!r)return t;const i=o.groupId??Me(),a={...o,groupId:i,holes:[...o.holes??[],r]},l={...Ae(r,"offset"),groupId:i,heightMm:0,color:o.color??Vd};return t.map(c=>c.id===o.id?a:c).concat(l)}function uW(t,e){if(e.kind==="top"||e.kind==="bottom")return Math.max(0,Math.round(t.heightMm??0));const s=-e.normalLocal.x,o=-e.normalLocal.z,r=e.originLocal.x/rt,i=e.originLocal.z/rt;let a=0;for(const l of t.vertices){const c=l.x-r,d=l.y-i,u=c*s+d*o;u>a&&(a=u)}return Math.max(0,Math.round(a))}function Yy(t,e,s){if(!e)return t;const o=t.find(a=>a.id===e);if(!o)return t;if(o.kind==="facePatch"){let a=Math.max(-5e4,Math.min(5e4,Math.round(s)));const l=t.find(c=>c.kind==="polygon"&&c.id===o.hostEntityId);if(l&&a<0){const c=An(l,o.hostFaceId),d=c?uW(l,c):0;if(d>0&&a<=-d)return mW(t,o,l);d>0&&(a=Math.max(a,-d))}return t.map(c=>c.id===e&&c.kind==="facePatch"?{...c,depthMm:a}:c)}if(o.kind!=="polygon")return t;const r=Math.max(0,Math.min(5e4,Math.round(s))),i={...o,heightMm:r};return Xu(t,o,i)}function hW(t,e,s,o=1){var u;const r=t.filter(h=>h.kind==="faceCornerArc"&&h.hostEntityId===s.id&&h.hostFaceId===e.hostFaceId);if(!r.length)return[];const i=(u=e.containedArcIds)!=null&&u.length?r.filter(h=>e.containedArcIds.includes(h.id)):[];if(i.length)return i;const a=An(s,e.hostFaceId);if(!a)return[];let l=p3(a,e);const c=e.shape==="polygon"?e.points2D.map(h=>ko(a,h)):null;if(!l&&(c!=null&&c.length)&&(l=vp(c)),!l)return[];const d=h=>h.x>=l.minX-o&&h.x<=l.maxX+o&&h.y>=l.minY-o&&h.y<=l.maxY+o;return r.filter(h=>{const x=$f(h.corner,a.widthMm,a.heightMm);return(c==null?void 0:c.length)>=3&&z1(x,c)?!0:d(x)})}function mW(t,e,s){const o=hW(t,e,s),r=new Set(o.map(a=>a.id)),i=t.filter(a=>a.id!==e.id);return r.size?i.map(a=>a.kind==="faceCornerArc"&&r.has(a.id)?{...a,verticalThroughCut:!0}:a):i}function M3(t,e){if(!e)return t;const s=t.find(a=>a.id===e);if(!s)return t;const o=s.kind==="polygon"?s.holes??[]:[],r=s.kind==="polygon"?new Set(t.filter(a=>a.kind==="facePatch"&&a.hostEntityId===s.id).map(a=>a.id)):new Set,i=t.filter(a=>a.id!==e&&!(s.kind==="polygon"&&a.kind==="facePatch"&&a.hostEntityId===s.id)&&!(s.kind==="polygon"&&a.kind==="faceSplit"&&a.hostEntityId===s.id)&&!(s.kind==="polygon"&&a.kind==="faceCornerArc"&&a.hostEntityId===s.id)&&!(s.kind==="polygon"&&a.kind==="faceMeasure"&&(a.hostEntityId===s.id||r.has(a.hostEntityId)))&&!(s.kind==="facePatch"&&a.kind==="faceMeasure"&&a.hostEntityId===s.id)&&!(s.kind==="polygon"&&_D(a)&&o.some(l=>jp(l,a.vertices))));return s.kind!=="polygon"?i:i.map(a=>{var c;if(a.kind!=="polygon"||!((c=a.holes)!=null&&c.length))return a;const l=a.holes.filter(d=>!jp(d,s.vertices));return l.length===a.holes.length?a:{...a,holes:l}})}function fW(t,e){if(!e)return null;const s=t.find(r=>r.id===e);if(!s)return null;const o=s.groupId;if(o)return o;if(s.kind==="facePatch"||s.kind==="faceSplit"||s.kind==="faceCornerArc"||s.kind==="faceMeasure"){const r=t.find(i=>i.id===s.hostEntityId);return(r==null?void 0:r.groupId)??null}return null}function xW(t,e,s=[]){const o=new Set(s);for(const i of t)i.groupId===e&&o.add(i.id);let r=t;for(const i of o)r=M3(r,i);return r}function MD(t,e){const s=yD(t);return{version:wp,entities:s,furnitureGroups:jD(e,s)}}function Db(t){if(!t||typeof t!="object")return{version:wp,entities:[],furnitureGroups:[]};const e=t,s=yD(e.entities);return{version:wp,entities:s,furnitureGroups:jD(e.furnitureGroups,s)}}function yD(t){if(!Array.isArray(t))return[];const e=[];for(const s of t){if(!s||typeof s!="object")continue;const o=s,r=typeof o.id=="string"&&o.id?o.id:be(),i=Di(o.createdAt,Date.now()),a=typeof o.color=="string"?o.color:void 0,l=typeof o.groupId=="string"&&o.groupId?o.groupId:void 0;if(o.kind==="segment"){const c=Rc(o.a),d=Rc(o.b);if(!c||!d||Nn(c,d)<=Gn)continue;e.push({id:r,kind:"segment",sourceTool:"line",a:c,b:d,groupId:l,color:Cx("segment",a),createdAt:i});continue}if(o.kind==="measure"){const c=Rc(o.start),d=Rc(o.end);if(!c||!d||Nn(c,d)<=Gn)continue;e.push({id:r,kind:"measure",start:c,end:d,startElevationMm:o.startElevationMm!==void 0?Math.round(Di(o.startElevationMm,0)):void 0,endElevationMm:o.endElevationMm!==void 0?Math.round(Di(o.endElevationMm,0)):void 0,groupId:l,createdAt:i});continue}if(o.kind==="polygon"){const c=mg(o.vertices);if(!Xi(c))continue;const d=Array.isArray(o.holes)?o.holes.map(w=>mg(w)).filter(w=>Xi(w)):[],u=DW(o.sourceTool)?o.sourceTool:"polygon",h=FW(o.rectangleWallAnchor,u),x=o.baseHeightMm!==void 0?Math.max(0,Math.round(Di(o.baseHeightMm,0))):void 0,f=w=>{if(w==null)return;const k=Di(w,1);if(!(!Number.isFinite(k)||k===1))return Math.max(.05,Math.min(3,k))},p=f(o.topScaleX),b=f(o.topScaleY),M=f(o.bottomScaleX),g=f(o.bottomScaleY);e.push({id:r,kind:"polygon",sourceTool:u,vertices:c,holes:d,heightMm:Math.max(0,Math.round(Di(o.heightMm,0))),...x&&x>0?{baseHeightMm:x}:{},...p!==void 0?{topScaleX:p}:{},...b!==void 0?{topScaleY:b}:{},...M!==void 0?{bottomScaleX:M}:{},...g!==void 0?{bottomScaleY:g}:{},groupId:l,...h?{rectangleWallAnchor:h}:{},color:Cx("polygon",a),...f2(o.faces),createdAt:i});continue}if(o.kind==="facePatch"){const c=typeof o.hostEntityId=="string"?o.hostEntityId:"",d=typeof o.hostFaceId=="string"&&Kx(o.hostFaceId)?o.hostFaceId:null,u=mg(o.points2D);if(!c||!d||!Xi(u))continue;const h=Array.isArray(o.holes2D)?o.holes2D.map(b=>mg(b)).filter(b=>Xi(b)):[],x=o.containedArcIds,f=Array.isArray(x)?x:null,p=f?[...new Set(f.filter(b=>typeof b=="string"&&b.length>0))]:[];e.push({id:r,kind:"facePatch",sourceTool:CW(o.sourceTool)?o.sourceTool:"faceRectangle",hostEntityId:c,hostFaceId:d,shape:o.shape==="polygon"?"polygon":"rectangle",promotedRegionKey:typeof o.promotedRegionKey=="string"&&o.promotedRegionKey?o.promotedRegionKey:void 0,points2D:u,...h.length?{holes2D:h}:{},...p.length?{containedArcIds:p}:{},depthMm:Math.max(-5e4,Math.min(5e4,Math.round(Di(o.depthMm,0)))),groupId:l,color:Cx("facePatch",a),...f2(o.faces),createdAt:i});continue}if(o.kind==="faceSplit"){const c=typeof o.hostEntityId=="string"?o.hostEntityId:"",d=typeof o.hostFaceId=="string"&&Kx(o.hostFaceId)?o.hostFaceId:null,u=Rc(o.a2D),h=Rc(o.b2D);if(!c||!d||!u||!h||Nn(u,h)<=Gn)continue;e.push({id:r,kind:"faceSplit",hostEntityId:c,hostFaceId:d,a2D:u,b2D:h,groupId:l,color:Cx("faceSplit",a),createdAt:i});continue}if(o.kind==="faceCornerArc"){const c=typeof o.hostEntityId=="string"?o.hostEntityId:"",d=typeof o.hostFaceId=="string"&&Kx(o.hostFaceId)?o.hostFaceId:null,u=o.corner==="sw"||o.corner==="se"||o.corner==="ne"||o.corner==="nw"?o.corner:null,h=Math.round(Di(o.radiusMm,0));if(!c||!d||!u||h<20)continue;const x=o.verticalThroughCut===!0,f=x?f2(o.faces).faces:void 0;e.push({id:r,kind:"faceCornerArc",hostEntityId:c,hostFaceId:d,corner:u,radiusMm:h,...x?{verticalThroughCut:!0}:{},...x&&(f!=null&&f.side)?{faces:{side:f.side}}:{},groupId:l,color:Cx("faceCornerArc",a),createdAt:i});continue}if(o.kind==="faceMeasure"){const c=typeof o.hostEntityId=="string"?o.hostEntityId:"",d=typeof o.hostFaceId=="string"&&Kx(o.hostFaceId)?o.hostFaceId:null,u=Rc(o.start2D),h=Rc(o.end2D);if(!c||!d||!u||!h||Nn(u,h)<=Gn)continue;e.push({id:r,kind:"faceMeasure",hostEntityId:c,hostFaceId:d,start2D:u,end2D:h,groupId:l,createdAt:i});continue}}return e}function Js(t){const e=[];for(const s of t){const o=Rc(s);if(!o)continue;const r=e[e.length-1];r&&Nn(r,o)<=Gn||e.push(o)}return e.length>2&&Nn(e[0],e[e.length-1])<=Gn&&e.pop(),e}function pW(t){if(t.length===0)return{x:0,y:0};const e=t.reduce((s,o)=>({x:s.x+o.x,y:s.y+o.y}),{x:0,y:0});return{x:e.x/t.length,y:e.y/t.length}}function fv(t,e){let s=1/0;for(let o=0;o<e.length;o++)s=Math.min(s,gW(t,e[o],e[(o+1)%e.length]));return Number.isFinite(s)?s:0}function gW(t,e,s){const o=s.x-e.x,r=s.y-e.y,i=t.x-e.x,a=t.y-e.y,l=o*o+r*r;if(l<=Gn)return Math.hypot(i,a);const c=Math.max(0,Math.min(1,(i*o+a*r)/l));return Math.hypot(t.x-(e.x+o*c),t.y-(e.y+r*c))}function Di(t,e){const s=Number(t);return Number.isFinite(s)?s:e}function bW(t,e=0){const s=(Di(t,e)%360+360)%360;return Math.round(s*10)/10}function wD(t){const e=Js(t);if(!e.length)return null;let s=1/0,o=-1/0,r=1/0,i=-1/0;
246for(const a of e)s=Math.min(s,a.x),o=Math.max(o,a.x),r=Math.min(r,a.y),i=Math.max(i,a.y);return[s,o,r,i].every(Number.isFinite)?{minX:s,maxX:o,minY:r,maxY:i}:null}function rp(t,e,s){let o=null;for(const r of e){const i={x:Math.round(r.x),y:Math.round(r.y)},a=Nn(t,i);a>s||(!o||a<o.distance)&&(o={point:i,distance:a})}return(o==null?void 0:o.point)??null}function MW(t,e,s){const o=[{distance:Math.abs(e.x),point:{x:0,y:e.y}},{distance:Math.abs(t.widthMm-e.x),point:{x:t.widthMm,y:e.y}},{distance:Math.abs(e.y),point:{x:e.x,y:0}},{distance:Math.abs(t.heightMm-e.y),point:{x:e.x,y:t.heightMm}}].filter(r=>r.distance<=s);return o.length?(o.sort((r,i)=>r.distance-i.distance),ko(t,o[0].point)):null}function yW(t,e=dD,s,o=e){const r=[...new Set(e)];if(!s||o.length<2)return r;const i=new Set(o),a=r.find(u=>(u==="minY"||u==="maxY")&&i.has(u)),l=r.find(u=>(u==="minX"||u==="maxX")&&i.has(u));if(!a||!l)return r;const c=Math.abs(t.x-s.x),d=Math.abs(t.y-s.y);return c<1&&d<1?r:c>=d?[a]:[l]}function wW(t,e,s,o=dD){const r=ko(t,e),i=new Set(o),l=[{distance:Math.abs(e.x),edge:"minX",point:{x:0,y:r.y}},{distance:Math.abs(t.widthMm-e.x),edge:"maxX",point:{x:t.widthMm,y:r.y}},{distance:Math.abs(e.y),edge:"minY",point:{x:r.x,y:0}},{distance:Math.abs(t.heightMm-e.y),edge:"maxY",point:{x:r.x,y:t.heightMm}}].filter(c=>i.has(c.edge)&&c.distance<=s);return l.length?(l.sort((c,d)=>c.distance-d.distance),l[0]):null}function kW(t,e,s,o){const r=ko(t,e);return s==="x"?r.x<=o?{x:0,y:r.y}:t.widthMm-r.x<=o?{x:t.widthMm,y:r.y}:r:r.y<=o?{x:r.x,y:0}:t.heightMm-r.y<=o?{x:r.x,y:t.heightMm}:r}function kD(t,e,s){var l;const o=An(e,t.hostFaceId),r=An(s,t.hostFaceId);if(!o||!r||o.widthMm<=Gn||o.heightMm<=Gn)return t;const i=r.widthMm/o.widthMm,a=r.heightMm/o.heightMm;return{...t,points2D:t.points2D.map(c=>ko(r,{x:c.x*i,y:c.y*a})),...(l=t.holes2D)!=null&&l.length?{holes2D:t.holes2D.map(c=>c.map(d=>ko(r,{x:d.x*i,y:d.y*a})))}:{}}}function xv(t,e,s,o){const r=An(e,t.hostFaceId);if(!r||t.points2D.length<3)return t;const i=t.points2D.map(f=>f.x),a=t.points2D.map(f=>f.y),l=Math.min(...i),c=Math.min(...a),d=Math.max(lg,Math.round(r.widthMm-l)),u=Math.max(lg,Math.round(r.heightMm-c)),h=Math.min(d,Math.max(lg,Math.round(s))),x=Math.min(u,Math.max(lg,Math.round(o)));return{...t,shape:"rectangle",points2D:_e(l,c,l+h,c+x)}}function vW(t,e,s,o){var b;const r=An(e,t.hostFaceId);if(!r||t.points2D.length<3)return t;const i=t.points2D.map(M=>M.x),a=t.points2D.map(M=>M.y),l=Math.min(...i),c=Math.max(...i),d=Math.min(...a),u=Math.max(...a),h=Math.max(-l,Math.min(r.widthMm-c,s)),x=Math.max(-d,Math.min(r.heightMm-u,o)),f=M=>({x:Math.round(M.x+h),y:Math.round(M.y+x)}),p=(b=t.holes2D)==null?void 0:b.map(M=>M.map(f));return{...t,points2D:t.points2D.map(f),...p!=null&&p.length?{holes2D:p}:{}}}function jW(t){const e=new Map;for(const s of t){const o=s.groupId;if(!o)continue;const r=e.get(o)??[];r.push(s.id),e.set(o,r)}return Array.from(e.entries()).filter(([,s])=>s.length>1).map(([s,o])=>({id:s,entityIds:o,createdAt:0}))}function _W(t,e,s){const o=s.filter(a=>e.includes(a.id)),r=o.find(a=>a.kind==="polygon"&&a.sourceTool==="rectangle"&&a.groupId===t&&typeof a.heightMm=="number"&&a.heightMm>0&&o.some(l=>l.kind==="facePatch"&&l.hostEntityId===a.id));if(!r)return null;const i=Xr(r.vertices);return i?{name:"רהיט ידני",widthMm:Math.max(1,Math.round(i.lengthMm)),depthMm:Math.max(1,Math.round(i.widthMm)),heightMm:Math.max(1,Math.round(r.heightMm??0))}:null}function vD(t,e){const s=new Set(e.map(r=>r.id)),o=new Map;for(const r of t??[]){if(!r.id)continue;const i=r.entityIds.filter(a=>s.has(a));i.length<2&&!r.presetKind&&!r.templateId||o.set(r.id,{...r,entityIds:i})}for(const r of jW(e)){const i=o.get(r.id);o.set(r.id,i?{...i,entityIds:r.entityIds}:r)}return Array.from(o.values()).map(r=>{const i=_W(r.id,r.entityIds,e);if(!i)return r;const a=!!(r.name||r.templateId||r.presetKind||r.sourceJobId);return{...r,name:a?r.name:i.name,widthMm:i.widthMm,depthMm:i.depthMm,heightMm:i.heightMm}})}const EW=new Set(["lighting.recessed","lighting.panel","lighting.wall","lighting.floor","living.glassRailing","living.railingHorizontal","living.railingVertical","railings.glassFrameless"]);function jD(t,e){const s=new Set(e.map(r=>r.id)),o=[];if(Array.isArray(t))for(const r of t){if(!r||typeof r!="object")continue;const i=r,a=typeof i.id=="string"&&i.id?i.id:"",l=Array.isArray(i.entity
246Ids)?i.entityIds.filter(f=>typeof f=="string"&&s.has(f)):[],c=i.presetKind==="base"||i.presetKind==="wall"||i.presetKind==="tall"||i.presetKind==="sinkBase"||i.presetKind==="ovenTall"||i.presetKind==="hoodWall"?i.presetKind:void 0,d=typeof i.templateId=="string"&&i.templateId?i.templateId:void 0,u=typeof i.sourceJobId=="string"&&i.sourceJobId?i.sourceJobId:void 0;if(!a||l.length<2&&!c&&!d)continue;const h=typeof i.wallId=="string"&&i.wallId?i.wallId:void 0,x=i.wallSide==="front"||i.wallSide==="back"?i.wallSide:void 0;o.push({id:a,entityIds:l,name:typeof i.name=="string"&&i.name?i.name:void 0,presetKind:c,templateId:d,widthMm:i.widthMm!==void 0?Math.max(1,Math.round(Di(i.widthMm,0))):void 0,heightMm:i.heightMm!==void 0?Math.max(1,Math.round(Di(i.heightMm,0))):void 0,depthMm:i.depthMm!==void 0?Math.max(1,Math.round(Di(i.depthMm,0))):void 0,drawerCount:i.drawerCount!==void 0?Math.max(0,Math.round(Di(i.drawerCount,0))):void 0,sourceJobId:u,...h?{wallId:h}:{},...x?{wallSide:x}:{},...i.wallPositionMm!==void 0?{wallPositionMm:Math.round(Di(i.wallPositionMm,0))}:{},...i.rotationDeg!==void 0?{rotationDeg:bW(i.rotationDeg)}:{},...(typeof i.rigid=="boolean"?i.rigid:d&&EW.has(d))?{rigid:!0}:{},createdAt:Di(i.createdAt,0)})}return vD(o,e)}function pv(t,e,s,o){const r={x:Math.round(e.x),y:Math.round(e.y)},i=Math.max(0,Math.round(o)),a=Nn(t,r);return a>=i||i<=Gn?r:a>Gn?kp(t,r,i):kp(t,s,i)}function Rc(t){if(!t||typeof t!="object")return null;const e=t,s=Number(e.x),o=Number(e.y);return!Number.isFinite(s)||!Number.isFinite(o)?null:{x:Zn(s),y:Zn(o)}}function mg(t){return Array.isArray(t)?Js(t.map(Rc).filter(e=>!!e)):[]}function DW(t){return t==="rectangle"||t==="polygon"||t==="circle"||t==="offset"}function FW(t,e){if(e!=="rectangle"||!t||typeof t!="object"||Array.isArray(t))return;const s=t;if(typeof s.wallId!="string"||!s.wallId||s.side!=="front"&&s.side!=="back")return;const o=Number(s.anchorEdgeIndex);if([0,1,2,3].includes(o))return{wallId:s.wallId,side:s.side,anchorEdgeIndex:o}}function CW(t){return t==="faceRectangle"||t==="faceOffset"||t==="faceSplitRegion"}function Cx(t,e){const s=e==null?void 0:e.toUpperCase();return!e||s&&cL.has(s)||t==="polygon"&&s&&dL.has(s)?t==="segment"||t==="faceSplit"||t==="faceCornerArc"?_b:Vd:e}function f2(t){if(!t||typeof t!="object"||Array.isArray(t))return{};const e={};for(const[s,o]of Object.entries(t)){if(!Kx(s)||!o||typeof o!="object"||Array.isArray(o))continue;const r=o,i={};typeof r.color=="string"&&r.color&&(i.color=r.color);const a=NW(r.texture);a&&(i.texture=a),(i.color||i.texture)&&(e[s]=i)}return Object.keys(e).length?{faces:e}:{}}function NW(t){if(!t||typeof t!="object"||Array.isArray(t))return;const e=t;if(!(typeof e.url!="string"||!e.url))return{url:e.url,tileWidthCm:Math.max(1,Math.round(Di(e.tileWidthCm,100))),tileHeightCm:Math.max(1,Math.round(Di(e.tileHeightCm,100))),groutWidthMm:Math.max(0,Math.round(Di(e.groutWidthMm,0))),groutColor:typeof e.groutColor=="string"&&e.groutColor?e.groutColor:"#cccccc",orientation:ei(e.orientation)}}function Kx(t){if(t==="top"||t==="bottom"||t==="side"||t==="front")return!0;if(!t.startsWith("side-"))return!1;const e=Number(t.slice(5));return Number.isInteger(e)&&e>=0}function _D(t){return t.kind==="polygon"&&t.sourceTool==="offset"}function IW(t,e,s){const o=t.holes??[],r=e.holes??[],i=o.findIndex(a=>jp(a,s));return i>=0?r[i]??null:null}function TW(t,e,s=1){return Math.abs(t.x-e.x)<=s&&Math.abs(t.y-e.y)<=s}function jp(t,e,s=1){const o=Js(t),r=Js(e);if(o.length!==r.length)return!1;const i=a=>{for(let l=0;l<a.length;l++)if(o.every((c,d)=>TW(c,a[(d+l)%a.length],s)))return!0;return!1};return i(r)||i([...r].reverse())}function SW(t,e,s,o){const r=Zx(t,e,s),i=Zx(t,e,o),a=Zx(s,o,t),l=Zx(s,o,e);return Math.abs(r)<=Gn&&jf(t,s,e)||Math.abs(i)<=Gn&&jf(t,o,e)||Math.abs(a)<=Gn&&jf(s,t,o)||Math.abs(l)<=Gn&&jf(s,e,o)?!0:r>0!=i>0&&a>0!=l>0}function Zx(t,e,s){return(e.x-t.x)*(s.y-t.y)-(e.y-t.y)*(s.x-t.x)}function jf(t,e,s){return e.x>=Math.min(t.x,s.x)-Gn&&e.x<=Math.max(t.x,s.x)+Gn&&e.y>=Math.min(t.y,s.y)-Gn&&e.y<=Math.max(t.y,s.y)+Gn}function y3(t,e,s,o){const r=t.x,i=t.y,a=e.x,l=e.y,c=s.x,d=s.y,u=o.x,h=o.y,x=(r-a)*(d-h)-(i-l)*(c-u);if(Math.abs(x)<=Gn)return null;const f=((r*l-i*a)*(c-u)-(r-a)*(c*h-d*u))/x,p=((r*l-i*a)*(d-h)-(i-l)*(c*h-d*u))/x;return!Number.isFinite(f)||!Number.isFinite(p)?null:{x:f,y:p}}const Nd=1,gv=Nd;function Ou(t,e){return{x:Math.round(t.x+e.x),y:Math.round(t.y+e.y)}}function w3(t,e){return e.get(t)??t}function PW(t,e,s){const o=be("fps_line");
246return e.set(t.id,o),{...t,id:o,a:Ou(t.a,s),b:Ou(t.b,s),createdAt:Date.now()}}function AW(t,e,s,o){const r=be(`fps_${t.sourceTool}`);return e.set(t.id,r),{...H1(t,s),id:r,groupId:o??t.groupId,createdAt:Date.now()}}function LW(t,e,s,o,r=!0){var l;const i=be("fps_patch");e.set(t.id,i);const a=c=>r?Ou(c,s):{x:c.x,y:c.y};return{...t,id:i,hostEntityId:w3(t.hostEntityId,e),groupId:o??t.groupId,points2D:t.points2D.map(a),holes2D:(l=t.holes2D)==null?void 0:l.map(c=>c.map(a)),createdAt:Date.now()}}function WW(t,e,s,o,r=!0){const i=be("fps_face_split");e.set(t.id,i);const a=l=>r?Ou(l,s):{x:l.x,y:l.y};return{...t,id:i,hostEntityId:w3(t.hostEntityId,e),groupId:o??t.groupId,a2D:a(t.a2D),b2D:a(t.b2D),createdAt:Date.now()}}function RW(t,e,s){const o=be("fps_corner_arc");return e.set(t.id,o),{...t,id:o,hostEntityId:w3(t.hostEntityId,e),groupId:s??t.groupId,createdAt:Date.now()}}function Fb(t,e){const s=new Set;for(const r of t)r.groupId===e&&s.add(r.id);const o=new Set(t.filter(r=>r.kind==="polygon"&&s.has(r.id)).map(r=>r.id));for(const r of t)(r.kind==="facePatch"||r.kind==="faceSplit"||r.kind==="faceCornerArc")&&(o.has(r.hostEntityId)||s.has(r.hostEntityId))&&s.add(r.id);return s}function ED(t,e){return t.kind!=="facePatch"&&t.kind!=="faceSplit"&&t.kind!=="faceCornerArc"?!1:e.has(t.hostEntityId)}function x2(t,e,s,o){if(!e.length)return{entities:t,createdIds:[]};const r=new Set(e),i=t.find(f=>r.has(f.id)),a=i==null?void 0:i.groupId,l=a?Fb(t,a):new Set(e);for(const f of t)(f.kind==="facePatch"||f.kind==="faceSplit"||f.kind==="faceCornerArc")&&l.has(f.hostEntityId)&&l.add(f.id);const c=new Set(t.filter(f=>f.kind==="polygon"&&l.has(f.id)).map(f=>f.id)),d=new Map,u=(o==null?void 0:o.newGroupId)===!1?(o==null?void 0:o.groupId)??a:Me(),h=[],x=[];for(const f of t)if(l.has(f.id)){if(f.kind==="segment"){const p=PW(f,d,s);x.push(p),h.push(p.id);continue}if(f.kind==="polygon"){const p=AW(f,d,s,u);x.push(p),h.push(p.id);continue}if(f.kind==="facePatch"){const p=LW(f,d,s,u,!c.has(f.hostEntityId));x.push(p),h.push(p.id);continue}if(f.kind==="faceSplit"){const p=WW(f,d,s,u,!c.has(f.hostEntityId));x.push(p),h.push(p.id);continue}if(f.kind==="faceCornerArc"){const p=RW(f,d,u);x.push(p),h.push(p.id)}}return{entities:[...t,...x],createdIds:h}}function OW(t,e){const s=Fb(t,e);if(!s.size)return t;const o=t.filter(g=>g.kind==="polygon"&&s.has(g.id));if(!o.length)return t;const r=new Map;for(const g of t)s.has(g.id)&&(g.kind==="facePatch"||g.kind==="faceSplit"||g.kind==="faceCornerArc")&&r.set(g.hostEntityId,(r.get(g.hostEntityId)??0)+1);let i=o[0],a=-1;for(const g of o){const w=r.get(g.id)??0;w>a&&(a=w,i=g)}const l=i.vertices[0],c=i.vertices[1],d=Math.hypot(c.x-l.x,c.y-l.y);if(d<=1e-6)return t;const u=(c.x-l.x)/d,h=(c.y-l.y)/d,x=g=>{const w=g.x-l.x,k=g.y-l.y,_=w*u+k*h,j=d-_,v=w-_*u,C=k-_*h;return{x:Math.round(l.x+j*u+v),y:Math.round(l.y+j*h+C)}},f=new Map(o.map(g=>[g.id,g])),p=(g,w)=>{var k;return((k=An(g,w))==null?void 0:k.widthMm)??0},b=(g,w)=>g.map(k=>({x:Math.round(w-k.x),y:Math.round(k.y)})).reverse(),M=g=>g==="sw"?"se":g==="se"?"sw":g==="nw"?"ne":"nw";return t.map(g=>{var w;if(!s.has(g.id))return g;if(g.kind==="polygon")return g.id===i.id?g:{...g,vertices:g.vertices.map(x).reverse()};if(g.kind==="facePatch"){const k=f.get(g.hostEntityId),_=k?p(k,g.hostFaceId):0;return _<=0?g:{...g,points2D:b(g.points2D,_),holes2D:(w=g.holes2D)==null?void 0:w.map(j=>b(j,_))}}if(g.kind==="faceSplit"){const k=f.get(g.hostEntityId),_=k?p(k,g.hostFaceId):0;return _<=0?g:{...g,a2D:{x:Math.round(_-g.a2D.x),y:g.a2D.y},b2D:{x:Math.round(_-g.b2D.x),y:g.b2D.y}}}return g.kind==="faceCornerArc"?{...g,corner:M(g.corner)}:g})}function tm(t,e,s){if(!e.length||s.x===0&&s.y===0)return t;const o=t.find(l=>e.includes(l.id)),r=o==null?void 0:o.groupId,i=r?Fb(t,r):new Set(e);let a=t;for(const l of t)if(i.has(l.id)){if(l.kind==="polygon"){const c=H1(l,s);a=Xu(a,l,c);continue}if(l.kind==="segment"){a=a.map(c=>c.id===l.id&&c.kind==="segment"?{...c,a:Ou(c.a,s),b:Ou(c.b,s)}:c);continue}if(l.kind==="facePatch"){if(i.has(l.hostEntityId))continue;const c=d=>Ou(d,s);a=a.map(d=>{var u;return d.id===l.id&&d.kind==="facePatch"?{...d,points2D:d.points2D.map(c),holes2D:(u=d.holes2D)==null?void 0:u.map(h=>h.map(c))}:d});continue}if(l.kind==="faceSplit"){if(i.has(l.hostEntityId))continue;const c=d=>Ou(d,s);a=a.map(d=>d.id===l.id&&d.kind==="faceSplit"?{...d,a2D:c(d.a2D),b2D:c(d.b2D)}:d)}}return a}function Nx(t){if(!t.length)return{x:0,y:0};const e=t.reduce((s,o)=>({x:s.x+o.x,y:s.y+o.y}),{x:0,y:0});return{x:e.x/t.length,y:e.y/t.length}}function Du(t,e,s){const o=t.x-e.x,r=t.y-e.y,i=Math.cos(s),a=Math.sin(s);return{x:Math.round(e.x+o*i-r*a),y:Math.round(e.y+o*a+r*i)}}function Yu(t){return(Math.round(t/gv)*gv%360+360)%360}function k3(t,e,s,o){var u;const r=Yu(o);if(r===0)return t;const i=r*Math.PI/180,a=t.find(h=>e.includes(h.id)),l=a==null?void 0:a.groupId,c=l?Fb(t,l):new Set(e);let d=t;for(const h of t)if(c.has(h.id)&&!ED(h,c)){if(h.kind==="polygon"){const x={...h,vertices:h.vertices.map(f=>Du(f,s,i)),holes:(u=h.holes)==null?void 0:u.map(f=>f.map(p=>Du(p,s,i)))};d=Xu(d,h,x);continue}if(h.kind==="segment"){d=d.map(x=>x.id===h.id&&x.kind==="segment"?{...x,a:Du(x.a,s,i),b:Du(x.b,s,i)}:x);continue}if(h.kind==="facePatch"){d=d.map(x=>{var f;return x.id===h.id&&x.kind==="facePatch"?{...x,points2D:x.points2D.map(p=>Du(p,s,i)),holes2D:(f=x.holes2D)==null?void 0:f.map(p=>p.map(b=>Du(b,s,i)))}:x});continue}h.kind==="faceSplit"&&(d=d.map(x=>x.id===h.id&&x.kind==="faceSplit"?{...x,a2D:Du(x.a2D,s,i),b2D:Du(x.b2D,s,i)}:x))}return d}function em(t,e){const s=[],o=new Set(e);
246for(const r of t)o.has(r.id)&&(ED(r,o)||(r.kind==="polygon"?s.push(Nx(r.vertices)):r.kind==="segment"?s.push(Nx([r.a,r.b])):r.kind==="facePatch"?s.push(Nx(r.points2D)):r.kind==="faceSplit"&&s.push(Nx([r.a2D,r.b2D]))));return s.length?Nx(s):null}function Wl(t,e){return{x:Math.round(t.x*e),y:Math.round(t.y*e)}}function Lu(t,e){return t===void 0?void 0:Math.round(t*e)}function HW(t,e){return!Number.isFinite(e)||e===1?t:t.map(s=>{var o,r;switch(s.kind){case"segment":return{...s,a:Wl(s.a,e),b:Wl(s.b,e)};case"measure":return{...s,start:Wl(s.start,e),end:Wl(s.end,e),startElevationMm:Lu(s.startElevationMm,e),endElevationMm:Lu(s.endElevationMm,e)};case"polygon":return{...s,vertices:s.vertices.map(i=>Wl(i,e)),holes:(o=s.holes)==null?void 0:o.map(i=>i.map(a=>Wl(a,e))),heightMm:Lu(s.heightMm,e),baseHeightMm:Lu(s.baseHeightMm,e)};case"facePatch":return{...s,points2D:s.points2D.map(i=>Wl(i,e)),holes2D:(r=s.holes2D)==null?void 0:r.map(i=>i.map(a=>Wl(a,e))),depthMm:Lu(s.depthMm,e)};case"faceSplit":return{...s,a2D:Wl(s.a2D,e),b2D:Wl(s.b2D,e)};case"faceCornerArc":return{...s,radiusMm:Math.round(s.radiusMm*e)};case"faceMeasure":return{...s,start2D:Wl(s.start2D,e),end2D:Wl(s.end2D,e)};default:return s}})}function BW(t,e){return!Number.isFinite(e)||e===1?t:t.map(s=>({...s,widthMm:Lu(s.widthMm,e),heightMm:Lu(s.heightMm,e),depthMm:Lu(s.depthMm,e)}))}function VW(t,e,s,o,r,i,a,l){const c=e.groupId;if(!c||Math.abs(i-1)<1e-4&&Math.abs(a-1)<1e-4&&Math.abs(l-1)<1e-4)return t;const d=u=>{const h=u.x-s.x,x=u.y-s.y,f=h*o.x+x*o.y,p=h*r.x+x*r.y,b=f*i,M=p*a;return{x:Math.round(s.x+b*o.x+M*r.x),y:Math.round(s.y+b*o.y+M*r.y)}};return t.map(u=>{var h;return u.id===e.id||u.groupId!==c||u.kind!=="polygon"?u:{...u,vertices:u.vertices.map(d),holes:(h=u.holes)==null?void 0:h.map(x=>x.map(d)),heightMm:u.heightMm!==void 0?Math.max(1,Math.round(u.heightMm*l)):u.heightMm,baseHeightMm:u.baseHeightMm!==void 0?Math.max(0,Math.round(u.baseHeightMm*l)):u.baseHeightMm}})}const jd={flat:"#C9C7C1",top:"#B8B6AF",bottom:"#E6E4DE",side:"#F4F3EF",sideShadeA:"#FFFFFF",sideShadeB:"#D8D6D0",sideShadeC:"#ECEAE4"};function zW(t,e,s){var u,h;const o=t.groups;if(o.length<2)return;const r=((u=o[0])==null?void 0:u.count)??0,i=r/2,a=r,l=((h=o[1])==null?void 0:h.count)??6*e;if(t.clearGroups(),t.addGroup(0,i,0),t.addGroup(i,i,1),s){t.addGroup(a,l,2);return}const c=6,d=Math.ceil(l/c);for(let x=0;x<d;x++){const f=a+x*c;if(f>=a+l)break;const p=Math.min(c,a+l-f),b=x<e?e-1-x:(x-e)%e;t.addGroup(f,p,2+b)}}function am(t,e,s,o){if(o)return"top";if(t===0)return"bottom";if(t===1)return"top";if(s)return"side";const r=t-2;return`side-${Math.max(0,Math.min(e-1,r))}`}function Vp(t,e,s){if(s||t==="bottom")return 0;if(t==="top")return 1;if(e||t==="side")return 2;const o=Number(t.slice(5));return 2+(Number.isFinite(o)?o:0)}function Xf(t,e,s){if(s)return["top"];if(e)return["top","bottom","side"];const o=[];for(let r=0;r<t;r++)o.push(`side-${r}`);return["top","bottom",...o]}function $W(t,e,s,o,r){if(r)return t.clone();const i=Vp(e,o,r),a=t.groups.find(x=>x.materialIndex===i);if(!a)return null;const l=new Ua,c=t.getAttribute("position"),d=t.getAttribute("normal"),u=t.getAttribute("uv");if(!c)return null;const h=(x,f,p)=>{const b=x.itemSize,M=new Float32Array(p*b),g=x.array;return M.set(g.subarray(f*b,(f+p)*b)),new cb(M,b)};return l.setAttribute("position",h(c,a.start,a.count)),d&&l.setAttribute("normal",h(d,a.start,a.count)),u&&l.setAttribute("uv",h(u,a.start,a.count)),l.computeBoundingBox(),l.computeBoundingSphere(),l}function DD(t){return(t.heightMm??0)<.001}function XW(t){return!t||t.toUpperCase()===Vd.toUpperCase()}function YW(t,e){if(e.kind==="polygon"&&DD(e))return jd.flat;if(t==="top")return jd.top;if(t==="bottom")return jd.bottom;if(t==="side")return jd.side;const s=Number(t.slice(5));if(!Number.isFinite(s))return jd.side;const o=[jd.sideShadeA,jd.sideShadeB,jd.sideShadeC,jd.side];return o[Math.abs(s)%o.length]}function Mm(t,e){var a,l;const s=t.kind==="faceCornerArc"?e==="side"?(a=t.faces)==null?void 0:a.side:void 0:(l=t.faces)==null?void 0:l[e],o=s==null?void 0:s.texture,r=t.kind==="faceCornerArc"?Vd:t.color;return{color:(s==null?void 0:s.color)??(XW(r)?YW(e,t):r??Vd),texture:o}}const GW=4,UW=5,KW=.004,Ix=new le,bv=new le,Mv=new le;function ZW(t){var s;let e=t;for(;e;){const o=(s=e.userData)==null?void 0:s.wallId;
246if(typeof o=="string")return o;e=e.parent}return null}function FD(t){var s;let e=t;for(;e;){const o=(s=e.userData)==null?void 0:s.wallPickSide;if(o==="front"||o==="back"||o==="edge")return o;e=e.parent}return null}function qW(t){if(!t)return"front";const e=t.materialIndex;return e===UW?"back":e===GW?"front":t.normal.z<-.5?"back":t.normal.z>.5?"front":typeof e=="number"&&e>=0&&e<=3?"edge":t.normal.z<0?"back":"front"}function JW(t){return FD(t.object)??qW(t.face)}function QW(t,e){if(!t.ray)return null;const s=[];if(e.traverse(a=>{(a.name==="walls"||a.name.startsWith("walls-"))&&s.push(a)}),s.length===0)return null;const o=new Ea;o.ray.copy(t.ray);const r=o.intersectObjects(s,!0);let i=null;for(const a of r){const l=ZW(a.object);l&&(!i||a.distance<i.distance)&&(i={wallId:l,side:JW(a),distance:a.distance,point:a.point,object:a.object,face:a.face})}return i}function tR(t,e,s){if(!(e!=null&&e.length))return null;if(t.kind==="polygon"&&t.groupId)return e.find(o=>o.id===t.groupId)??null;if((t.kind==="facePatch"||t.kind==="faceCornerArc")&&t.hostEntityId&&s){const o=s.find(r=>r.id===t.hostEntityId&&r.kind==="polygon");if(o!=null&&o.groupId)return e.find(r=>r.id===o.groupId)??null}return null}function eR(t,e){return!t.wallId||t.wallId!==e.wallId||!t.wallSide?!1:t.wallSide==="back"&&e.side==="front"||t.wallSide==="front"&&e.side==="back"}function nR(t,e){if(!e.face||!t.ray||(Ix.copy(e.face.normal).transformDirection(e.object.matrixWorld),Ix.lengthSq()<1e-10))return!1;Ix.normalize(),bv.copy(t.ray.origin).sub(e.point),Mv.copy(t.point).sub(e.point);const s=Ix.dot(bv),o=Ix.dot(Mv),r=1e-4;return Math.abs(s)<r||Math.abs(o)<r?!1:Math.sign(s)!==Math.sign(o)}function oR(t,e,s){const o=(s==null?void 0:s.epsilonM)??KW,r=t.distance,i=QW(t,e);if(!i)return null;if(i.distance<r-o)return{wallId:i.wallId,side:i.side};if(!(s!=null&&s.entity))return null;const a=tR(s.entity,s.furnitureGroups,s.entities);if(!(a!=null&&a.wallId)||a.wallId!==i.wallId)return null;if(eR(a,i))return{wallId:i.wallId,side:i.side};if(nR(t,i)){const l=FD(i.object)??i.side;return{wallId:i.wallId,side:l}}return null}function CD(t,e){if(!t.groupId||t.sourceTool!=="rectangle")return new Set;const s=e==null?void 0:e.find(r=>r.id===t.groupId);if(!(s!=null&&s.wallId))return new Set;const o=Xf(t.vertices.length,!1,!1);return new Set(o.filter(r=>r!=="side-0"))}function Gy(t,e){return!t.groupId||!(e!=null&&e.length)?!1:e.some(s=>s.id===t.groupId&&!!s.wallId)}const sR=150,yv=Math.cos(2*Math.PI/180);function rR(t){const e=t.endMm.x-t.startMm.x,s=t.endMm.y-t.startMm.y,o=Math.hypot(e,s);if(!Number.isFinite(o)||o<1)return null;const r={x:e/o,y:s/o},i=t.side==="back"?{x:r.y,y:-r.x}:{x:-r.y,y:r.x};return{startMm:t.startMm,d:r,n:i,flushOutMm:t.thicknessMm/2}}function iR(t){const e=t.b.x-t.a.x,s=t.b.y-t.a.y,o=Math.hypot(e,s);if(!Number.isFinite(o)||o<1)return null;const r={x:e/o,y:s/o},i=t.side==="back"?{x:r.y,y:-r.x}:{x:-r.y,y:r.x};return{startMm:t.a,d:r,n:i,flushOutMm:0}}function aR(t,e){return e?{uAxis:e.d,vAxis:{x:-e.n.x,y:-e.n.y}}:{uAxis:t.uAxis,vAxis:t.vAxis}}function lR(t,e,s,o){const{uAxis:r,vAxis:i}=aR(t,e);return{x:Math.round(s*r.x+o*i.x),y:Math.round(s*r.y+o*i.y)}}function ND(t,e){const s=new Set;let o=null;for(const r of t)r.kind==="polygon"&&r.groupId===e&&(s.add(r.id),o===null&&(o=r.id));for(const r of t)if((r.kind==="facePatch"||r.kind==="faceSplit"||r.kind==="faceCornerArc")&&s.has(r.hostEntityId))return r.hostEntityId;return o}function p2(t,e,s,o){const r=o??ND(t,e);let i=1/0,a=1/0,l=1/0,c=null;for(const d of t){if(d.kind!=="polygon"||d.groupId!==e)continue;const u=d,h=u.id===r;for(const x of u.vertices){const f=x.x-s.startMm.x,p=x.y-s.startMm.y,b=f*s.d.x+p*s.d.y;a=Math.min(a,b),l=Math.min(l,f*s.n.x+p*s.n.y),h&&(i=Math.min(i,b))}if(h&&u.vertices.length>=2){const x=u.vertices[0],f=u.vertices[1],p=Math.hypot(f.x-x.x,f.y-x.y);p>1&&(c={x:(f.x-x.x)/p,y:(f.y-x.y)/p})}}return!Number.isFinite(a)||!Number.isFinite(l)?null:(Number.isFinite(i)||(i=a),{hostAlongMm:i,groupAlongMm:a,outMm:l,hostDir:c})}function cR(t,e){return Math.abs(t-e.flushOutMm)>sR}function o1(t){const{group:e,prevEntities:s,nextEntities:o,frame:r,reanchor:i,hostId:a}=t,l=!!i&&i.wallId===e.wallId&&i.wallSide===e.wallSide;if(i&&!(l&&e.wallPositionMm!==void 0)){const u=p2(o,e.id,i.frame,a);return u?{kind:"attach",wallId:i.wallId,wallSide:i.wallSide,wallPositionMm:Math.round(u.groupAlongMm)}:{kind:"keep"}}if(!e.wallId||!e.wallSide||!r)return{kind:"keep"};const c=p2(s,e.id,r,a),d=p2(o,e.id,r,a);if(!c||!d)return{kind:"keep"};if(c.hostDir&&d.hostDir){const u=Math.abs(c.hostDir.x*r.d.x+c.hostDir.y*r.d.y),h=Math.abs(d.hostDir.x*r.d.x+d.hostDir.y*r.d.y);if(u>=yv&&h<yv)return{kind:"detach"}}return cR(d.outMm,r)?{kind:"detach"}:{kind:"attach",wallId:e.wallId,wallSide:e.wallSide,wallPositionMm:Math.round((e.wallPositionMm??0)+(d.hostAlongMm-c.hostAlongMm))}}function s1(t,e,s){return s.kind==="keep"?t:t.map(o=>{if(o.id!==e)return o;if(s.kind==="detach"){const{wallId:r,wallSide:i,wallPositionMm:a,...l}=o;return l}return{...o,wallId:s.wallId,wallSide:s.wallSide,wallPositionMm:s.wallPositionMm}})}function r1(t,e){let s=!1;const o=t.map(r=>r.kind==="polygon"&&r.groupId===e&&r.rectangleWallAnchor?(s=!0,{...r,rectangleWallAnchor:void 0}):r);return s?o:t}const Ni="#111111",v3="#F7F4EF",j3="#111111",ID="#3F3A34",TD="#F7F4EF",Cb="#111111",Nb=1.35,dR=1,g2={roughness:.55,metalness:0,emissiveIntensity:.12},wv=["minX","maxX","minY","maxY"];function SD({selected:t=!1,selectionVisualDepthMode:e="overlay"}={}){return!t||e==="scene"}
246function Jc(t="overlay"){return t==="scene"}function ym(t,e={}){const s=new Vu({color:t,roughness:g2.roughness,metalness:g2.metalness,emissive:t,emissiveIntensity:g2.emissiveIntensity,side:e.side??cr});return e.transparent!==void 0&&(s.transparent=e.transparent),e.opacity!==void 0&&(s.opacity=e.opacity),e.depthTest!==void 0&&(s.depthTest=e.depthTest),e.depthWrite!==void 0&&(s.depthWrite=e.depthWrite),e.isFlat&&(s.transparent=!1,s.opacity=1,s.side=kn,s.emissiveIntensity=.18,s.polygonOffset=!0,s.polygonOffsetFactor=-1),e.polygonOffset&&(s.polygonOffset=!0,s.polygonOffsetFactor=e.polygonOffsetFactor??-1,s.polygonOffsetUnits=e.polygonOffsetUnits??-1),s}function _3(t,e={}){return t.side=e.side??t.side,e.polygonOffset&&(t.polygonOffset=!0,t.polygonOffsetFactor=e.polygonOffsetFactor??-1,t.polygonOffsetUnits=e.polygonOffsetUnits??-1),t}function PD(t,e,s){return xm(e.flatMap(o=>{const r=o.points2D.map(a=>ko(t,a)),i=[];for(let a=0;a<r.length;a++){const l=r[a],c=r[(a+1)%r.length],d=HD(t,l,c);if(!d)continue;const u=Ln(t,l,s),h=Ln(t,c,s);i.push({role:"host-frame",boundaryEdge:d,points:[[u.x,u.y,u.z],[h.x,h.y,h.z]]})}return i}))}function uR(t,e,s){return xm(e.flatMap(o=>{if(o.hostEntityId!==t.hostEntityId||o.hostFaceId!==t.faceId)return[];const r=OD(o.points2D,t);if(r.length<2)return[];const i=E3(r),a=[];for(let l=0;l<r.length;l++){const c=r[l],d=r[(l+1)%r.length];if(HD(t,c,d))continue;const u=Ln(t,c,s),h=Ln(t,d,s);a.push({role:"cut-boundary",boundaryEdge:D3(c,d,i),points:[[u.x,u.y,u.z],[h.x,h.y,h.z]]})}return a}))}function AD(t,e,s){return xm(e.flatMap(o=>{if(o.hostEntityId!==t.hostEntityId||o.hostFaceId!==t.faceId)return[];const r=Ln(t,o.a2D,s),i=Ln(t,o.b2D,s);return[{role:"cut-boundary",points:[[r.x,r.y,r.z],[i.x,i.y,i.z]]}]}))}const LD=2.5;function Uy(t,e,s=LD){return Nn(t,e)<=s}function hR(t,e,s,o=2){const r=Nn(e,s);if(r<=o)return!1;const i=Nn(e,t),a=Nn(t,s);return i>o&&a>o&&Math.abs(i+a-r)<=3}function mR(t,e,s){const o=s.x-e.x,r=s.y-e.y,i=o*o+r*r;return i<1?Nn(t,e):Math.abs(r*t.x-o*t.y+s.x*e.y-s.y*e.x)/Math.sqrt(i)}function kv(t,e,s,o=LD){for(const r of s)if(!(mR(r,t,e)>o)&&hR(r,t,e))return r;return null}function vv(t,e,s){if(!(s!=null&&s.length))return[[t,e]];let o=[[t,e]];const r=2;for(const i of s){const a=[];for(const l of o){const[c,d]=l;if(Uy(c,i.apex)){const u=kv(d,i.apex,i.tangents);u&&Nn(u,d)>=r&&a.push([u,d]);continue}if(Uy(d,i.apex)){const u=kv(c,i.apex,i.tangents);u&&Nn(c,u)>=r&&a.push([c,u]);continue}a.push([c,d])}o=a.length?a:[[t,e]]}return o}function fR(t,e){return e!=null&&e.length?e.some(s=>Uy(t,s.apex)):!1}function WD(t,e,s){return xm(e.flatMap(o=>{if(o.hostEntityId!==t.hostEntityId||o.hostFaceId!==t.faceId)return[];if(o.verticalThroughCut)return[];const r=x3(t,o.corner,o.radiusMm);if(r.length<2)return[];const i=r.map(l=>Ln(t,l,s)),a=[];for(let l=0;l<i.length-1;l++){const c=i[l],d=i[l+1];a.push({role:"cut-boundary",points:[[c.x,c.y,c.z],[d.x,d.y,d.z]]})}return a}))}function xR({vertices:t,heightMm:e,hiddenFaceIds:s=new Set,topCornerThroughRounding:o}){if(t.length<2)return[];const r=Math.max(0,Math.round(e))*rt,i=_a,a=_a+r,l=h=>s.has(`side-${h}`),c=(h,x)=>[h.x*rt,x,h.y*rt],d=[],u=(h,x,f)=>{d.push({role:"host-edge",vertexIndex:f,points:[h,x]})};for(let h=0;h<t.length;h++){const x=(h+1)%t.length,f=(h-1+t.length)%t.length,p=t[h],b=t[x];if(!l(h)){for(const[M,g]of vv(p,b,o))u(c(M,i),c(g,i),h);if(r>0)for(const[M,g]of vv(p,b,o))u(c(M,a),c(g,a),h)}r>0&&(!l(h)||!l(f))&&(fR(p,o)||u(c(p,i),c(p,a),h))}return xm(d)}function RD({frame:t,points2D:e,depthMm:s,recessSideWalls:o=wv,surfaceOffsetMm:r=3,hostOffsetMm:i=4}){const a=OD(e,t);if(a.length<2)return[];if(s>.5)return xm([...Tx(t,a,i,"host-rim"),...Tx(t,a,s+r,"front-rim"),...jv(t,a,i,s+r)]);if(s<-.5){const l=wv.filter(h=>!o.includes(h)),c=new Set(o),d=1,u=s+dR+r;return xm([...Tx(t,a,i,"opening-rim",l),...Tx(t,a,u,"back-rim",l,d),...jv(t,a,i,u,c,d)])}return Tx(t,a,r,"surface-rim")}function OD(t,e){const s=[];for(const o of t){const r=ko(e,o),i=s[s.length-1];i&&Nn(i,r)<1||s.push(r)}return s.length>2&&Nn(s[0],s[s.length-1])<1&&s.pop(),Xi(s)?s:[]}function E3(t){return t.reduce((e,s)=>({minX:Math.min(e.minX,s.x),minY:Math.min(e.minY,s.y),maxX:Math.max(e.maxX,s.x),maxY:Math.max(e.maxY,s.y)}),{minX:Number.POSITIVE_INFINITY,minY:Number.POSITIVE_INFINITY,maxX:Number.NEGATIVE_INFINITY,maxY:Number.NEGATIVE_INFINITY})}function D3(t,e,s,o=1){if(Math.abs(t.x-s.minX)<=o&&Math.abs(e.x-s.minX)<=o)return"minX";if(Math.abs(t.x-s.maxX)<=o&&Math.abs(e.x-s.maxX)<=o)return"maxX";if(Math.abs(t.y-s.minY)<=o&&Math.abs(e.y-s.minY)<=o)return"minY";if(Math.abs(t.y-s.maxY)<=o&&Math.abs(e.y-s.maxY)<=o)return"maxY"}function HD(t,e,s,o=1){if(Math.abs(e.x)<=o&&Math.abs(s.x)<=o)return"minX";if(Math.abs(t.widthMm-e.x)<=o&&Math.abs(t.widthMm-s.x)<=o)return"maxX";if(Math.abs(e.y)<=o&&Math.abs(s.y)<=o)return"minY";if(Math.abs(t.heightMm-e.y)<=o&&Math.abs(t.heightMm-s.y)<=o)return"maxY"}function BD(t,e){if(e<=0||t.length<3)return t;let s=0,o=0;for(const r of t)s+=r.x,o+=r.y;return s/=t.length,o/=t.length,t.map(r=>{const i=s-r.x,a=o-r.y,l=Math.hypot(i,a);if(l<.001)return r;const c=e/l;return{x:r.x+i*c,y:r.y+a*c}})}function Tx(t,e,s,o,r=[],i=0){const a=E3(e),l=new Set(r),c=[],d=i>0?BD(e,i):e;for(let u=0;u<e.length;u++){const h=e[u],x=e[(u+1)%e.length],f=D3(h,x,a);if(f&&l.has(f))continue;const p=d[u],b=d[(u+1)%e.length],M=Ln(t,p,s),g=Ln(t,b,s);c.push({role:o,boundaryEdge:f,points:[[M.x,M.y,M.z],[g.x,g.y,g.z]]})}return c}function jv(t,e,s,o,r,i=0){const a=E3(e),l=new Set,c=i>0?BD(e,i):e;for(let d=0;d<e.length;d++){const u=D3(e[d],e[(d+1)%e.length],a);(!r||u&&r.has(u))&&(l.add(d),l.add((d+1)%e.length))}return Array.from(l).sort((d,u)=>d-u).map(d=>{const u=c[d],h=Ln(t,u,s),x=Ln(t,u,o);return{role:"depth-edge",vertexIndex:d,points:[[h.x,h.y,h.z],[x.x,x.y,x.z]]}})}function VD(t){const e=new Set,s=[];for(const o of t){const r=pR(o.points);e.has(r)||(e.add(r),s.push(o))}return s}const xm=VD;function pR(t){return t.map(s=>s.map(o=>o.toFixed(6)).join(",")).sort().join("|")}const Ib=2,_p=Ib+1,X1=Ib+8,gR=[],bR=[],MR=[];function yR(t){const e=[],s=[];
246for(const o of t){if(o.kind!=="polygon")continue;const r=t.filter(x=>x.kind==="facePatch"&&x.hostEntityId===o.id),i=t.filter(x=>x.kind==="faceSplit"&&x.hostEntityId===o.id),a=t.filter(x=>x.kind==="faceCornerArc"&&x.hostEntityId===o.id);if(!r.length&&!i.length&&!a.length)continue;const l=new Map,c=new Map,d=new Map,u=new Map;for(const x of r){const f=An(o,x.hostFaceId);if(!f)continue;const p=g3(f,x,{host:o,depthMm:Math.round(x.depthMm??0)});if(!p)continue;const b=Math.round(x.depthMm??0),M=RD({frame:f,points2D:x.points2D,depthMm:b,recessSideWalls:p.recessSideWalls});e.push({id:p.id,hostEntityId:p.hostEntityId,hostFaceId:p.hostFaceId,bounds:p.bounds,boundary:p.boundary,recessSideWalls:p.recessSideWalls,affectedAdjacentFaces:p.affectedAdjacentFaces,outlineSegments:M.map(k=>({role:k.role,boundaryEdge:k.boundaryEdge}))});const g=l.get(x.hostFaceId);g?g.push(x):l.set(x.hostFaceId,[x]);const w=u.get(x.hostFaceId);w?w.push(p):u.set(x.hostFaceId,[p])}for(const x of i){const f=c.get(x.hostFaceId);f?f.push(x):c.set(x.hostFaceId,[x])}for(const x of a){const f=d.get(x.hostFaceId);f?f.push(x):d.set(x.hostFaceId,[x])}const h=new Set([...l.keys(),...c.keys(),...d.keys()]);for(const x of h){const f=l.get(x)??[],p=c.get(x)??[],b=An(o,x);if(!b)continue;const M=d.get(x)??[],g=V1(b,f,p,M),w=Array.from(new Set((u.get(x)??[]).flatMap(k=>k.affectedAdjacentFaces))).sort();s.push({hostEntityId:o.id,hostFaceId:x,suppressedOriginalFace:!0,suppressOriginalEdges:!0,outlineSegments:[...PD(b,g,_p),...AD(b,p,X1),...WD(b,M,X1)].map(k=>({role:k.role,boundaryEdge:k.boundaryEdge})),regions:g.map(k=>({role:k.role,bounds:k.bounds})),affectedAdjacentFaces:w})}}return{facePatchTopology:e,hostFaceTopology:s}}const wR=Ib+6,kR=6,_v=8,vR=1,jR=16,_R=60,ip=18,zD=14,ER=.048,$D=42,DR=34,FR=.055,CR=.032,Ev=8,Sx={keypointSnapToleranceMm:Ev,edgeSnapToleranceMm:Ev,axisSnap:!1},fg={keypointSnapToleranceMm:65,edgeSnapToleranceMm:65,axisSnap:!1};function rf(t,e,s,o){const r=lW(s,t,e);return r.length===0?o:{...o??{},measureMarkerSnapPoints:r,measureMarkerSnapToleranceMm:DR}}const NR=["minX","maxX","minY","maxY"],Ss=()=>{},qx=xE,Dv=5,Fv=_a+.004,XD=_a+.006,IR=XD+.018,TR=_a+.001,b2=_a+.002,M2=.006,SR=600,PR=260,AR=650,LR=360;function Cv(t){return t?t.tool==="polygon"?{tool:"polygon",polygonPoints:t.points}:t.tool==="measure"?null:{tool:t.tool,start:t.start}:null}function Nv(t){return!t||Rl(t)?!1:t!=="pushPull"&&t!=="rotate"&&t!=="offset"&&t!=="faceOffset"&&t!=="faceLine"&&t!=="faceCornerArc"&&t!=="faceRectangle"&&t!=="faceMeasure"}function WR({point:t,kind:e}){const s=Ar(t),o=e==="origin"?"#336CFF":e==="worldAxis"?"#15803d":"#ea580c";return n.jsxs("mesh",{position:[s.x,qx,s.z],renderOrder:55,children:[n.jsx("sphereGeometry",{args:[.024,16,12]}),n.jsx("meshBasicMaterial",{color:o,depthTest:!0,depthWrite:!1})]})}function RR({snap:t}){const e=Fv+.18,s=[t.segment.a,t.segment.b].map(l=>{const c=Ar(l);return[c.x,e,c.z]}),o=Ar(t.point),r=[o.x,e+.01,o.z],i=[[o.x,Fv,o.z],r],a=t.t<=.04?Ar(t.segment.a):t.t>=.96?Ar(t.segment.b):null;return n.jsxs("group",{children:[n.jsx(Jn,{raycast:Ss,renderOrder:58,points:s,color:"#336CFF",lineWidth:3,depthTest:!1,dashed:!0,dashSize:.18,gapSize:.08}),n.jsx(Jn,{raycast:Ss,renderOrder:59,points:i,color:"#336CFF",lineWidth:2,depthTest:!1}),a?n.jsxs("mesh",{position:[a.x,e+.02,a.z],renderOrder:61,children:[n.jsx("sphereGeometry",{args:[.06,24,24]}),n.jsx("meshBasicMaterial",{color:"#FFB000",depthTest:!1,depthWrite:!1})]}):null,n.jsxs("mesh",{position:r,renderOrder:60,children:[n.jsx("sphereGeometry",{args:[.046,24,24]}),n.jsx("meshBasicMaterial",{color:"#336CFF",depthTest:!1,depthWrite:!1})]})]})}function OR(t){return t==="line"||t==="rectangle"||t==="circle"}function xg(t){return t==="line"||t==="rectangle"||t==="circle"||t==="polygon"||t==="measure"}const y2=8;function w2(t){return t==="faceOffset"}function pg(t){return t==="faceLine"||t==="faceRectangle"||t==="faceOffset"||t==="faceCornerArc"||t==="faceMeasure"}function gg(t){return t==="faceLine"||t==="faceRectangle"||t==="faceCornerArc"}function HR(t){return t==="faceMeasure"}function BR(t){var e;return(e=t.edges)!=null&&e.length?t.edges:t.edge?[t.edge]:[]}function VR(t,e){var r;return e.kind!=="endpoint"||(((r=e.edges)==null?void 0:r.length)??0)<2?null:["sw","
246se","ne","nw"].find(i=>{const a=$f(i,t.widthMm,t.heightMm);return Math.abs(e.point.x-a.x)<=1&&Math.abs(e.point.y-a.y)<=1})??null}function k2(t){return t==="minX"||t==="maxX"?"height":t==="minY"||t==="maxY"?"width":null}function v2(t){var s;const e=t.hover.edge;return e&&t.allowedEdges.includes(e)?e:((s=t.hover.edges)==null?void 0:s.find(o=>t.allowedEdges.includes(o)))??null}function zR(t,e,s){const o=t.frame,r=t.start.point,i=Math.max(0,Math.round(s));if(e==="minX"||e==="maxX"){const c=Math.round(o.heightMm),d=r.y<=c/2?Math.min(c,r.y+i):Math.max(0,r.y-i);return{x:e==="minX"?0:Math.round(o.widthMm),y:d}}const a=Math.round(o.widthMm);return{x:r.x<=a/2?Math.min(a,r.x+i):Math.max(0,r.x-i),y:e==="minY"?0:Math.round(o.heightMm)}}function Fu(t,e){return t.hostEntityId===e.hostEntityId&&t.hostFaceId===e.faceId}function Iv({bounds:t,activeTool:e,entities:s,furnitureGroups:o=[],onFurnitureGroupsChange:r,selectedEntityId:i,selectionVisualDepthMode:a="overlay",selectedFaceId:l=null,selectedRectangleEdgeIndex:c=null,onEntitiesChange:d,onSelectedEntityChange:u,onSelectedFaceChange:h,onSelectedRectangleEdgeChange:x,onElementMoveActiveChange:f,onActiveToolChange:p,lineLengthRequest:b=null,commitLineRequestId:M=0,onLineDraftLengthChange:g,rectangleDimensionsRequest:w=null,onRectangleDraftDimensionsChange:k,onPushPullHeightChange:_,onFaceLineMeasurementChange:j,onFaceMeasureMeasurementChange:v,onFaceMeasureMarkerPointerDown:C,faceMeasureLengthRequest:N=null,commitFaceMeasureRequest:P=null,updateFaceMeasureRequest:L=null,onFaceOffsetPreviewChange:A,faceOffsetDistanceRequest:W=null,commitFaceOffsetRequest:S=null,sketchOffsetDistanceRequest:B=null,commitSketchOffsetRequest:R=null,onSketchOffsetPreviewChange:z,onSelectedHostFaceRegionChange:X,floorplanSketchAxesVisible:ft=!0,measurementUnit:tt="cm",wallSnapSegments:G=[],onSketchRightClickConsumed:Y,onDeferContextMenuToWall:J,onDeferClickToWall:Mt,onRequestContextMenu:Rt,activeCladdingPaintAssignment:it=null,onCladdingPaintTarget:st,onCladdingPaintExit:ct}){const[pt,xt]=m.useState(null),_t=m.useRef(null),Ft=m.useCallback(I=>{_t.current=I,xt(I)},[]),Vt=m.useCallback(()=>{const I=_t.current;return _t.current=null,xt(null),I},[]),vt=pt??s,Ht=m.useRef(null),{camera:Tt,gl:Zt,scene:At}=Vo(),[ut,kt]=m.useState(null),[Et,ht]=m.useState(null),[gt,Pt]=m.useState(void 0),[U,mt]=m.useState(null),[Nt,Lt]=m.useState(null),[oe,he]=m.useState(null),[pe,Ge]=m.useState(null),[Qt,te]=m.useState(null),[Be,wt]=m.useState(null),[ve,Ne]=m.useState(null),[Le,is]=m.useState(null),[Fe,bn]=m.useState(null),[Ve,en]=m.useState(null);m.useEffect(()=>{X==null||X(Ve)},[X,Ve]);const[on,Qs]=m.useState(null),[sn,vn]=m.useState(null),[Ot,so]=m.useState(null),[Ue,hs]=m.useState(null),[Qn,Lr]=m.useState(null),[bi,Ps]=m.useState(!1),[In,Rn]=m.useState(Kh),[fe,Gs]=m.useState(null),[zo,js]=m.useState(null),[co,ze]=m.useState(null),Un=!!it&&!!st,[uo,dn]=m.useState(null),[$o,Te]=m.useState(null),po=m.useRef(null),ho=m.useRef(null),go=m.useRef(null),Kl=m.useRef(null),da=m.useRef(null),As=m.useRef(null),ua=m.useRef(null),Gi=m.useRef(null),On=m.useRef(null),to=m.useRef(null),Wt=m.useRef(null),qe=m.useRef(null),Se=m.useRef(!1),jn=m.useRef(null),je=m.useRef(vt),ne=m.useRef(d),Re=m.useRef(u),Dn=m.useRef(p),ge=m.useRef(g),ie=m.useRef(k),Ze=m.useRef(_),as=m.useRef(j),Pe=m.useRef(v),Ao=m.useRef(A),Lo=m.useRef(z),Gt=m.useRef(null),Co=m.useRef(null),Xo=m.useRef(null),pn=m.useRef(null),Kn=m.useRef(null),tr=m.useRef(null),ro=m.useRef(null),ls=m.useRef(null),Qo=m.useRef(null),ms=m.useRef(null),Yo=m.useRef(null),Qe=m.useRef(null),Go=m.useRef(null),er=m.useCallback(I=>{const H=je.current.find(K=>K.id===I);if(!H)return null;if(H.kind==="polygon"){const K=H.groupId;if(!K)return H.id;let nt=null;const Q=new Set;for(const dt of je.current)dt.kind==="polygon"&&dt.groupId===K&&(Q.add(dt.id),nt===null&&(nt=dt.id));for(const dt of je.current)if((dt.kind==="facePatch"||dt.kind==="faceSplit"||dt.kind==="faceCornerArc")&&Q.has(dt.hostEntityId))return dt.hostEntityId;return nt??H.id}return H.kind==="facePatch"||H.kind==="faceSplit"||H.kind==="faceCornerArc"?H.hostEntityId:null},[]),Vn=m.useCallback(()=>{dn(null),Te(null),Qe.current=null,Se.current&&(Se.current=!1,f==null||f(!1))},[f]),dr=m.useCallback(I=>{const H=er(I);H&&(p(wo),ze(null),en(null),x==null||x(null),u(H),h==null||h("top"),dn(H),Te(null),Se.current||(Se.current=!0,f==null||f(!0)))},[p,f,u,h,x,er]),Ii=m.useCallback(I=>{const H=er(I);H&&(p(wo),ze(null),en(null),x==null||x(null),u(H),h==null||h("top"),dn(H),Te(H),Se.current||(Se.current=!0,f==null||f(!0)))},[p,f,u,h,x,er]),fs=m.useCallback((I,H,K,nt)=>{Y==null||Y(),Vn(),en(null),x==null||x(null);const Q=nt??(()=>{if(I.kind==="facePatch")return"top";if(I.kind==="polygon"&&I.id===i)return l??void 0;if(I.kind==="faceCornerArc"&&I.verticalThroughCut)return"side"})(),dt=I.kind==="polygon"||I.kind==="facePatch"?Q:I.kind==="faceCornerArc"&&I.verticalThroughCut&&Q==="side"?"side":void 0;
246u(I.id,dt?{suppressDetailsPanelAutoOpen:!0}:void 0),I.kind==="polygon"||I.kind==="facePatch"?h==null||h(Q??null):I.kind==="faceCornerArc"&&I.verticalThroughCut&&Q==="side"?h==null||h("side"):I.kind==="faceMeasure"?h==null||h(I.hostFaceId):h==null||h(null),ze({entityId:I.id,x:H,y:K,faceId:dt})},[Vn,u,h,x,Y,i,l]),Uo=m.useCallback((I,H)=>{const K=oR(I,At,{entity:H,furnitureGroups:o,entities:je.current});if(!K)return!1;const nt={x:I.nativeEvent.clientX,y:I.nativeEvent.clientY};return I.button===2&&J?(J(K.wallId,nt,K.side),Y==null||Y(),ze(null),I.stopPropagation(),!0):I.button===0&&Mt?(Mt(K.wallId,nt,K.side),I.stopPropagation(),!0):!1},[o,Mt,J,Y,At]),Hn=m.useCallback(I=>{I==null||I.stopPropagation(),I==null||I.nativeEvent.preventDefault(),Y==null||Y(),ze(null),ct==null||ct()},[ct,Y]),ur=m.useCallback((I,H)=>H?I.kind==="polygon"||I.kind==="facePatch"?{entityId:I.id,faceId:H}:I.kind==="faceCornerArc"&&I.verticalThroughCut&&H==="side"?{entityId:I.id,faceId:"side"}:null:null,[]),oi=m.useCallback((I,H,K)=>{if(!Un)return!1;const nt=ur(I,K);return nt?(H.stopPropagation(),ze(null),st==null||st(nt),!0):!1},[Un,ur,st]),Je=m.useMemo(()=>vt.find(I=>I.id===i&&I.kind==="polygon")??null,[vt,i]),rn=m.useMemo(()=>vt.find(I=>I.id===i&&I.kind==="facePatch")??null,[vt,i]),xs=m.useMemo(()=>vt.find(I=>I.id===i&&I.kind==="faceMeasure")??null,[vt,i]),vo=rn??Je,Ui=m.useCallback((I,H=je.current)=>H.find(K=>K.id===I&&K.kind==="polygon")??null,[]),It=m.useCallback((I,H)=>mv(I,H,Ui),[Ui]),_s=m.useCallback((I,H=je.current)=>{const K=H.find(nt=>nt.id===I.hostEntityId&&(nt.kind==="polygon"||nt.kind==="facePatch"));return K?mv(K,I.hostFaceId,nt=>Ui(nt,H)):null},[Ui]),ha=m.useRef(new Map),Mi=m.useMemo(()=>{const I=new Map;for(const nt of vt){if(nt.kind!=="facePatch"&&nt.kind!=="faceSplit"&&nt.kind!=="faceCornerArc")continue;let Q=I.get(nt.hostEntityId);Q||(Q={patches:[],splits:[],arcs:[]},I.set(nt.hostEntityId,Q)),nt.kind==="facePatch"?Q.patches.push(nt):nt.kind==="faceSplit"?Q.splits.push(nt):Q.arcs.push(nt)}const H=ha.current,K=(nt,Q)=>nt.length===Q.length&&nt.every((dt,jt)=>dt===Q[jt]);for(const[nt,Q]of I){const dt=H.get(nt);if(!dt)continue;const jt=K(dt.patches,Q.patches),Yt=K(dt.splits,Q.splits),Ut=K(dt.arcs,Q.arcs);jt&&Yt&&Ut?I.set(nt,dt):(jt&&(Q.patches=dt.patches),Yt&&(Q.splits=dt.splits),Ut&&(Q.arcs=dt.arcs))}return ha.current=I,I},[vt]),Fa=m.useRef(null),si=m.useCallback(I=>{var K;if(((K=Fa.current)==null?void 0:K.key)===I)return Fa.current.value;const H=yR(I);return Fa.current={key:I,value:H},H},[]);m.useLayoutEffect(()=>{on||(je.current=vt)},[vt,on]),m.useEffect(()=>{if(!Ve)return;if(i!==Ve.hostEntityId||l!==Ve.hostFaceId){en(null);return}const I=vt.find(Jt=>Jt.id===Ve.hostEntityId&&Jt.kind==="polygon");if(!I){en(null);return}const H=An(I,Ve.hostFaceId);if(!H){en(null);return}const K=vt.filter(Jt=>Jt.kind==="facePatch"&&Jt.hostEntityId===I.id),nt=vt.filter(Jt=>Jt.kind==="faceSplit"&&Jt.hostEntityId===I.id),Q=vt.filter(Jt=>Jt.kind==="faceCornerArc"&&Jt.hostEntityId===I.id),dt=qy(I,K.filter(Jt=>Jt.shape==="rectangle")).filter(Jt=>Jt.hostFaceId===Ve.hostFaceId),jt=nt.filter(Jt=>Jt.hostFaceId===Ve.hostFaceId),Yt=Q.filter(Jt=>Jt.hostFaceId===Ve.hostFaceId);V1(H,dt,jt,Yt).some(Jt=>Jt.regionId===Ve.regionId)||en(null)},[vt,i,l,Ve]),m.useEffect(()=>{ne.current=d,Re.current=u,Dn.current=p,ge.current=g,ie.current=k,Ze.current=_,as.current=j,Pe.current=v,Ao.current=A,Lo.current=z},[p,d,u,j,v,A,z,g,_,k]),m.useEffect(()=>{Gt.current=oe},[oe]),m.useEffect(()=>{Co.current=pe},[pe]),m.useEffect(()=>{Xo.current=Qt},[Qt]);const Ko=m.useCallback(I=>{pn.current=I,wt(I)},[]),ae=m.useCallback(I=>{Kn.current=I,Ne(I)},[]),Za=m.useCallback(I=>{tr.current=I,is(I)},[]),Mr=m.useCallback(I=>{ro.current=I,bn(I)},[]),ri=m.useCallback(()=>{var I;(I=Yo.current)==null||I.call(Yo),Yo.current=null},[]),Qc=m.useCallback(()=>{Co.current=null,Xo.current=null,Ge(null),te(null)},[]),Es=m.useCallback(()=>{var I,H;ri(),Gt.current=null,pn.current=null,Kn.current=null,tr.current=null,ro.current=null,he(null),Qc(),wt(null),Ne(null),is(null),bn(null),(I=as.current)==null||I.call(as,null),(H=Pe.current)==null||H.call(Pe,null)},[Qc,ri]),Us=m.useCallback(()=>{var I,H,K,nt,Q;kt(null),ht(null),Pt(void 0),Es(),Ps(!1),Gs(null),js(null),(I=Ao.current)==null||I.call(Ao,null),(H=Lo.current)==null||H.call(Lo,null),Qs(null),vn(null),so(null),jn.current=null,(K=ge.current)==null||K.call(ge,null),(nt=ie.current)==null||nt.call(ie,null),(Q=Ze.current)==null||Q.call(Ze,null),mt(null),Lt(null),Dn.current(wo)},[Es]);m.useEffect(()=>{var I,H,K,nt,Q;kt(null),ht(null),Pt(void 0),Es(),Ps(!1),Gs(null),js(null),(I=Ao.current)==null||I.call(Ao,null),(H=Lo.current)==null||H.call(Lo,null),Qs(null),vn(null),so(null),jn.current=null,(K=ge.current)==null||K.call(ge,null),(nt=ie.current)==null||nt.call(ie,null),(Q=Ze.current)==null||Q.call(Ze,null),mt(null),Lt(null)},[e,Es]);const Ki=(Je==null?void 0:Je.id)??null;m.useEffect(()=>{const I=Ki!==null;if(e==="offset"&&I){Rn(Kh);return}(e!=="offset"||!I)&&Gs(null)},[e,Ki]),m.useEffect(()=>{var I,H;if(e!=="offset"||Ki===null){(I=Lo.current)==null||I.call(Lo,null);return}(H=Lo.current)==null||H.call(Lo,In??null)},[e,In,Ki]);const ts=m.useCallback(()=>{var I,H;kt(null),ht(null),Pt(void 0),Ps(!1),jn.current=null,mt(null),Lt(null),(I=ge.current)==null||I.call(ge,null),(H=ie.current)==null||H.call(ie,null)},[]);m.useEffect(()=>{const I=document.documentElement;if(!e||Rl(e)){I.classList.remove("floorplan-sketch-pencil-cursor");return}I.classList.add("floorplan-sketch-pencil-cursor");const H=Zt.domElement,K=Nv(e)&&U!==null;return H.style.cursor=K?"none":"",()=>{I.classList.remove("floorplan-sketch-pencil-cursor"),H.style.cursor=""}},[e,Zt,U]);const Wo=uo!==null||$o!==null||(Ot==null?void 0:Ot.mode)==="move";m.useEffect(()=>{Se.current!==Wo&&(Se.current=Wo,f==null||f(Wo))},[Wo,f]),m.useEffect(()=>()=>{Se.current&&(Se.current=!1,f==null||f(!1))},[f]),m.useEffect(()=>{if(!Wo)return;const I=Zt.domElement;return I.style.cursor=(Ot==null?void 0:Ot.mode)==="move"?"grabbing":"grab",()=>{I.style.cursor=""}},[Wo,Zt,Ot==null?void 0:Ot.mode]),m.useEffect(()=>{const I=Zt.domElement,H=()=>{mt(null),(!ut||ut.tool!=="rectangle"||!ut.wallSnap)&&Lt(null)};return I.addEventListener("pointerleave",H),()=>I.removeEventListener("pointerleave",H)},[ut,Zt]),m.useEffect(()=>{if(!on)return;let I=on.startHeightMm,H=null;const K=()=>{var we,Mn;H=null;const dt=je.current,jt=on.selectedId,Yt=dt.find(tn=>tn.id===jt&&tn.kind==="facePatch"),Ut=Yy(dt,jt,I);je.current=Ut,Yt&&!Ut.some(tn=>tn.id===jt&&tn.kind==="facePatch")&&((we=Re.current)==null||we.call(
246Re,Yt.hostEntityId));const Jt=Ut.find(tn=>tn.id===jt);(Mn=Ze.current)==null||Mn.call(Ze,(Jt==null?void 0:Jt.kind)==="polygon"?Math.max(0,Math.round(Jt.heightMm??0)):(Jt==null?void 0:Jt.kind)==="facePatch"?Math.round(Jt.depthMm??0):null),Ft(Ut)},nt=dt=>{if(on.screenNormal){const jt=dt.clientX-on.startClientX,Yt=dt.clientY-on.startClientY,Ut=jt*on.screenNormal.x+Yt*on.screenNormal.y;I=on.startHeightMm+Ut*on.screenNormal.depthSign*20}else{const jt=on.startClientY-dt.clientY;I=on.startHeightMm+jt*20}H===null&&(H=window.requestAnimationFrame(K))},Q=()=>{var jt,Yt;H!==null&&(window.cancelAnimationFrame(H),H=null),K();const dt=on.selectedId;if(iW(dt)){const Ut=je.current,Jt=Ut.find(we=>we.id===dt&&we.kind==="facePatch");if(Jt&&Math.round(Jt.depthMm??0)===0){const we=Ut.filter(Mn=>Mn.id!==dt);je.current=we,(jt=Re.current)==null||jt.call(Re,Jt.hostEntityId)}}Vt(),ne.current(je.current),Qs(null),(Yt=Ze.current)==null||Yt.call(Ze,null),Dn.current(wo)};return window.addEventListener("pointermove",nt),window.addEventListener("pointerup",Q),()=>{H!==null&&window.cancelAnimationFrame(H),window.removeEventListener("pointermove",nt),window.removeEventListener("pointerup",Q)}},[Vt,on,Ft]);const Ds=m.useCallback((I,H)=>{const K=Ht.current;if(!K)return null;const nt=Zt.domElement.getBoundingClientRect();if(I<nt.left||I>nt.right||H<nt.top||H>nt.bottom||nt.width<=0||nt.height<=0)return null;const Q=new Po((I-nt.left)/nt.width*2-1,-((H-nt.top)/nt.height*2-1)),dt=new Ea;dt.setFromCamera(Q,Tt);const jt=K.localToWorld(new le(0,qx,0)),Yt=new le(0,1,0).transformDirection(K.matrixWorld),Ut=ne
246w Ga().setFromNormalAndCoplanarPoint(Yt,jt),Jt=new le;if(!dt.ray.intersectPlane(Ut,Jt))return null;const we=K.worldToLocal(Jt);return rv({x:we.x,z:we.z})},[Tt,Zt]),pc=m.useCallback((I,H,K=!1)=>{const nt=Ds(I,H);if(!nt)return null;let Q=nt;if(G.length>0){const dt=If(nt,G,lL);dt&&(Q=dt.point)}return{point:Q}},[Ds,G]),Ti=m.useCallback((I,H,K)=>{const nt=pc(I,H,K),Q=(nt==null?void 0:nt.point)??Ds(I,H);return Q?(ut==null?void 0:ut.tool)==="measure"&&!K?$c(ut.start,Q).point:Q:null},[ut,pc,Ds]),eo=m.useCallback(I=>{const H=Zt.domElement.getBoundingClientRect();if(H.width<=0||H.height<=0)return null;const K=I.clone().project(Tt);return!Number.isFinite(K.x)||!Number.isFinite(K.y)?null:{x:H.left+(K.x+1)/2*H.width,y:H.top+(1-K.y)/2*H.height}},[Tt,Zt]),yi=m.useCallback((I,H)=>{const K=Ht.current;if(!K)return null;const nt=je.current.find(Mn=>Mn.id===I.hostEntityId&&Mn.kind==="polygon");if(!nt)return null;const Q=An(nt,I.hostFaceId);if(!Q)return null;const dt=Q.normalLocal.clone().transformDirection(K.matrixWorld).normalize(),jt=Tt.position.clone().sub(H.point).dot(dt)>=0?1:-1,Yt=dt.multiplyScalar(jt),Ut=eo(H.point),Jt=eo(H.point.clone().addScaledVector(Yt,1));if(!Ut||!Jt)return null;const we=new Po(Jt.x-Ut.x,Jt.y-Ut.y);return we.lengthSq()<1e-4?null:(we.normalize(),{x:we.x,y:we.y,depthSign:jt})},[Tt,eo]),nr=m.useCallback((I,H,K)=>{const nt=Ht.current;if(!nt)return null;const Q=Zt.domElement.getBoundingClientRect();if(I<Q.left||I>Q.right||H<Q.top||H>Q.bottom||Q.width<=0||Q.height<=0)return null;const dt=new Po((I-Q.left)/Q.width*2-1,-((H-Q.top)/Q.height*2-1)),jt=new Ea;jt.setFromCamera(dt,Tt);const Yt=nt.matrixWorld.clone().invert(),Ut=new nI(jt.ray.origin.clone().applyMatrix4(Yt),jt.ray.direction.clone().transformDirection(Yt));return aW(K,Ut)},[Tt,Zt]);m.useEffect(()=>{var I;if(e==="faceOffset"){if(!Je||!l){js(null),(I=Ao.current)==null||I.call(Ao,null);return}js(H=>H===null?Kh:H)}},[e,l,Je]),m.useEffect(()=>{if(e!=="faceOffset"||!Je||!l)return;const I=H=>{const K=An(Je,l);if(!K){js(null);return}const nt=Zt.domElement.getBoundingClientRect();if(H.clientX<nt.left||H.clientX>nt.right||H.clientY<nt.top||H.clientY>nt.bottom||nt.width<=0||nt.height<=0){js(null);return}const Q=Ve&&Ve.hostEntityId===Je.id&&Ve.hostFaceId===l?Ve.points2D:_e(0,0,K.widthMm,K.heightMm),dt=nr(H.clientX,H.clientY,K);if(!dt){js(null);return}js(cv(Q,dt))};return window.addEventListener("pointermove",I,{passive:!0}),()=>window.removeEventListener("pointermove",I)},[e,nr,Zt.domElement,l,Ve,Je]);const zs=m.useCallback(I=>{const H=Ds(I.nativeEvent.clientX,I.nativeEvent.clientY);if(H)return H;const K=Ht.current?Ht.current.worldToLocal(I.point.clone()):I.point;return rv({x:K.x,z:K.z})},[Ds]),es=m.useCallback((I,H=ut)=>{if((H==null?void 0:H.tool)==="rectangle"&&H.wallSnap)return mt(null),Lt(H.wallSnap),{point:I,isPolygonCloseGesture:!1};const K=lv({candidate:I,entities:vt,draft:Cv(H),tapeAnchor:null});return mt(K.inferenceSnapKind==="none"?null:{kind:K.inferenceSnapKind,point:K.point}),{point:K.point,isPolygonCloseGesture:K.isPolygonCloseGesture}},[ut,vt]),Ca=m.useCallback(I=>{const H=_L({candidate:I,entities:vt});return mt(H.inferenceSnapKind==="none"?null:{kind:H.inferenceSnapKind,point:H.point}),H.point},[vt]),eh=m.useCallback((I,H)=>{if(G.length>0){const K=EL(I,G,H);if(K)return mt(null),Lt(K),{point:K.point,wallSnap:K}}return Lt(null),{point:Ca(I),wallSnap:null}},[Ca,G]),ps=m.useCallback((I,H)=>{const K=Ht.current;if(!K)return null;const nt=1e3,Q=new le(I.x*rt,qx,I.y*rt),dt=Q.clone().add(H==="x"?new le(nt*rt,0,0):new le(0,0,nt*rt)),jt=eo(K.localToWorld(Q.clone())),Yt=eo(K.localToWorld(dt));if(!jt||!Yt)return null;const Ut=Math.hypot(Yt.x-jt.x,Yt.y-jt.y);return!Number.isFinite(Ut)||Ut<=.01?null:nt/Ut},[eo]),Ro=m.useCallback((I,H)=>{const K=Yi(I.vertices);if(!K)return null;const nt=ps(K.center,"x"),Q=ps(K.center,"y"),dt=nt??Q??10;return fL({moving:I,entities:H,excludeEntityIds:[I.id],toleranceXMm:Dv*(nt??dt),toleranceYMm:Dv*(Q??dt)})},[ps]),gs=m.useCallback((I,H)=>{if(!I||!H)return!1;const K=je.current.find(jt=>jt.id===I.hostEntityId&&(jt.kind==="polygon"||jt.kind==="facePatch"));if(!K)return!1;const nt=K.groupId??Me();let Q=null;if(I.tool==="faceLine")Q=sp(I.frame,I.start,H,nt);else if(I.tool==="faceCornerArc"){const jt=n1(I.frame,I.corner,I.firstEdge,I.start);if(jt===null)return!1;Q=GL(I.frame,I.corner,jt,nt)}else Q=RL(K.id,I.hostFaceId,I.start,H,nt),Q&&I.hostFaceId==="front"&&(Q={...Q,depthMm:y2});if(!Q)return!1;const dt=je.current.map(jt=>jt.id===K.id&&(jt.kind==="polygon"||jt.kind==="facePatch")&&!jt.groupId?{...jt,groupId:nt}:jt).concat(Q);return je.current=dt,ne.current(dt),en(null),Q.kind==="faceSplit"||Q.kind==="faceCornerArc"?(u(K.id),h==null||h(I.hostFaceId)):(u(Q.id),h==null||h("top")),Dn.current(wo),Es(),!0},[Es,u,h]),bo=m.useCallback((I,H)=>{const K={...I,hover:H};Mr(K),Co.current=H,Xo.current=I.frame,Ge(H),te(I.frame)},[Mr]),bs=m.useCallback((I,H,K,nt)=>{const Q=BL(I.id,H.faceId,ko(H,K),ko(H,nt));if(!Q)return!1;const dt=je.current.concat(Q);return je.current=dt,ne.current(dt),jn.current=null,kt(null),ht(null),en(null),u(Q.id,{suppressDetail
246sPanelAutoOpen:!0}),h==null||h(H.faceId),Dn.current(wo),Es(),!0},[Es,u,h]),Kr=m.useCallback((I,H)=>{const K=Math.max(1,Math.round(H)),nt=je.current,Q=nt.find(Ut=>Ut.id===I&&Ut.kind==="faceMeasure");if(!Q)return;const dt=_s(Q,nt);if(!dt)return;const jt=m2(dt,Q.start2D,Q.end2D,K);if(Nn(Q.start2D,jt)<1)return;const Yt=nt.map(Ut=>Ut.id===I&&Ut.kind==="faceMeasure"?{...Ut,end2D:jt}:Ut);je.current=Yt,ne.current(Yt)},[_s]),xl=m.useCallback((I,H,K)=>{if(!HR(e))return!1;const nt=ro.current,Q=nt?Fu(nt,H):!1;if(!nt||!Q){const dt={hostEntityId:I.id,hostFaceId:H.faceId,frame:H,start:K,hover:K};return jn.current=null,kt(null),ht(null),en(null),Co.current=K,Xo.current=H,Ge(K),te(H),Mr(dt),u(I.id,{suppressDetailsPanelAutoOpen:!0}),h==null||h(H.faceId),!0}return bs(I,H,nt.start.point,K.point)},[e,bs,u,h,Mr]),pl=m.useCallback((I,H)=>{const K={...I,hover:H};Ko(K);const nt=k2(v2(K)??void 0);Kn.current&&Kn.current.axis!==nt&&ae(null),Co.current=H,Xo.current=I.frame,Ge(H),te(I.frame)},[ae,Ko]),Zi=m.useCallback((I,H,K,nt)=>{const Q=zL(H,K,nt),dt=I.groupId??Me(),jt=sp(H,K,Q,dt);if(!jt)return!1;const Yt=je.current.map(Ut=>Ut.id===I.id&&Ut.kind==="polygon"&&!Ut.groupId?{...Ut,groupId:dt}:Ut).concat(jt);return je.current=Yt,ne.current(Yt),jn.current=null,kt(null),ht(null),en(null),u(I.id),h==null||h(H.faceId),Dn.current(wo),Es(),!0},[Es,u,h]),Si=m.useCallback((I,H,K,nt)=>{const Q=wL(K,nt),dt=$L(H,K,Q);if(!dt)return!1;const jt=I.groupId??Me(),Yt=sp(H,dt.a,dt.b,jt);if(!Yt)return!1;const Ut=je.current.map(Jt=>Jt.id===I.id&&Jt.kind==="polygon"&&!Jt.groupId?{...Jt,groupId:jt}:Jt).concat(Yt);return je.current=Ut,ne.current(Ut),jn.current=null,kt(null),ht(null),en(null),u(I.id),h==null||h(H.faceId),Dn.current(wo),Es(),!0},[Es,u,h]),Fs=m.useCallback((I,H,K)=>{var jt,Yt;if(e!=="faceLine")return!1;const nt=pn.current,Q=nt?Fu(nt,H):!1;if(!nt||!Q){const Ut=VR(H,K),Jt=Ut?mD[Ut]:(jt=K.edges)!=null&&jt.length?[...K.edges]:[...NR],we=Ut?$f(Ut,H.widthMm,H.heightMm):K.point,Mn={...K,point:we,kind:Ut?"endpoint":K.kind,edge:K.edge??Jt[0],edges:[...Jt],labelHebrew:Ut?"נקודת קצה":K.labelHebrew},tn={tool:"faceLine",hostEntityId:I.id,hostFaceId:H.faceId,frame:H,start:we},fn={phase:"start",hostEntityId:I.id,hostFaceId:H.faceId,frame:H,...Ut?{corner:Ut}:{},start:Mn,hover:Mn,allowedEdges:[...Jt]};return jn.current=null,kt(null),ht(null),en(null),Gt.current=tn,Co.current=Mn,Xo.current=H,he(tn),Ge(Mn),te(H),Ko(fn),u(I.id),h==null||h(H.faceId),!0}const dt=K.edge??((Yt=K.edges)==null?void 0:Yt.find(Ut=>nt.allowedEdges.includes(Ut)));return nt.corner?!dt||!nt.allowedEdges.includes(dt)?!1:Zi(I,H,K.point,dt):Si(I,H,nt.start.point,K.point)},[e,Zi,Si,u,h,Ko]);m.useEffect(()=>{if(e!=="faceLine"||!Be)return;const I=H=>{var Mn;if(H.altKey||H.ctrlKey||H.metaKey||H.isComposing)return;const K=H.target;if(K&&(K.tagName==="INPUT"||K.tagName==="TEXTAREA"||K.tagName==="SELECT"||K.isContentEditable))return;const nt=pn.current;if(!nt)return;const Q=v2(nt),dt=k2(Q??void 0);if(!Q||!dt||Math.round(Math.abs(dt==="height"?nt.hover.point.y-nt.start.point.y:nt.hover.point.x-nt.start.point.x))<=0)return;if(/^[0-9]$/.test(H.key)){H.preventDefault();const fn=`${((Mn=Kn.current)==null?void 0:Mn.axis)===dt?Kn.current.valueText:""}${H.key}`.replace(/^0+(?=\d)/,"").slice(0,6);ae({axis:dt,valueText:fn});return}if(H.key==="Backspace"){const tn=Kn.current;if(!tn||tn.axis!==dt)return;H.preventDefault();const fn=tn.valueText.slice(0,-1);ae(fn?{axis:dt,valueText:fn}:null);return}if(H.key==="Escape"){if(!Kn.current)return;H.preventDefault(),ae(null);return}if(H.key!=="Enter")return;const Yt=Kn.current;if(!Yt||Yt.axis!==dt)return;const Ut=Number(Yt.valueText);if(!Number.isFinite(Ut)||Ut<=0)return;const Jt=je.current.find(tn=>tn.id===nt.hostEntityId&&tn.kind==="polygon");if(!Jt)return;H.preventDefault();const we=zR(nt,Q,Ut);Zi(Jt,nt.frame,we,Q)};return window.addEventListener("keydown",I),()=>window.removeEventListener("keydown",I)},[e,Zi,Be,ae]);const Pi=m.useCallback((I,H)=>{const K={...I,hover:H};Za(K),Co.current=H,Xo.current=I.frame,Ge(H),te(I.frame)},[Za]),Na=m.useCallback((I,H,K)=>{if(e!=="faceCornerArc")return!1;const nt=tr.current,Q=nt?Fu(nt,H):!1;if(!nt||!Q){const Yt=K.edge??BR(K)[0];if(!Yt)return!1;const Ut=YL(H,Yt,K.point),Jt=fD(Ut,Yt);if(!Jt||n1(H,Ut,Yt,K.point)===null)return!1;const Mn={tool:"faceCornerArc",hostEntityId:I.id,hostFaceId:H.faceId,frame:H,corner:Ut,firstEdge:Yt,secondEdge:Jt,start:K.point},tn={hostEntityId:I.id,hostFaceId:H.faceId,frame:H,corner:Ut,firstEdge:Yt,secondEdge:Jt,start:K,hover:K};return jn.current=null,kt(null),ht(null),en(null),Gt.current=Mn,Co.current=K,Xo.current=H,he(Mn),Ge(K),te(H),Za(tn),u(I.id),h==null||h(H.faceId),!0}const dt=nt,jt=Gt.current??{tool:"faceCornerArc",hostEntityId:I.id,hostFaceId:H.faceId,frame:H,corner:dt.corner,firstEdge:dt.firstEdge,secondEdge:dt.secondEdge,start:dt.start.point};return gs(jt,K.point)},[e,gs,u,h,Za]),Wr=m.useCallback((I,H)=>{ri();let K=H.point;const nt=(jt,Yt)=>{const Ut=nr(jt,Yt,I.frame);if(!Ut)return K;const Jt=I.tool==="faceLine"?hg(I.frame,Ut)??Co.current??H:Ol(I.frame,Ut,I.start,I.tool==="faceRectangle"?Sx:void 0);return K=Jt.point,Co.current=Jt,Xo.current=I.frame,Ge(Jt),te(I.frame),K},Q=jt=>{nt(jt.clientX,jt.clientY)},dt=jt=>{const Yt=nt(jt.clientX,jt.clientY)??K;ri(),gs(I,Yt),Gt.current===I&&(Gt.current=null,Co.current=null,Xo.current=null,he(null),Ge(null),te(null))};window.addEventListener("pointermove",Q,{passive:!0}),window.addEventListener("pointerup",dt),Yo.current=()=>{window.removeEventListener("pointermove",Q),window.removeEventListener("pointerup",dt)}},[gs,nr,ri]);m.useEffect(()=>{if(!sn)return;const I=K=>{const nt=Ds(K.clientX,K.clientY);nt&&Ft(vt.map(Q=>
246{if(Q.id!==sn.entityId||Q.kind!=="segment")return Q;const dt=sn.endpoint==="a"?Q.b:Q.a;return LL(Q,sn.endpoint,$c(dt,nt).point)}))},H=()=>{const K=Vt();K&&d(K),vn(null)};return window.addEventListener("pointermove",I),window.addEventListener("pointerup",H),()=>{window.removeEventListener("pointermove",I),window.removeEventListener("pointerup",H)}},[Vt,vt,d,Ds,sn,Ft]);const Rr=m.useCallback((I,H,K)=>{var Mn;if(!r)return H;const nt=K.groupId??((Mn=H.find(tn=>tn.id===K.hostId))==null?void 0:Mn.groupId)??null;if(!nt)return H;const Q=o.find(tn=>tn.id===nt);if(!Q)return H;const dt=K.hostId??ND(H,nt),jt=(tn,fn)=>{if(!tn||!fn)return null;const Rs=G.find(hn=>hn.wallId===tn&&hn.side===fn);return Rs?iR(Rs):null},Yt=dt?H.find(tn=>tn.id===dt&&tn.kind==="polygon"):void 0,Ut=(Yt==null?void 0:Yt.kind)==="polygon"?Yt.rectangleWallAnchor:void 0,Jt=Ut?jt(Ut.wallId,Ut.side):null,we=o1({group:Q,prevEntities:I,nextEntities:H,hostId:dt,frame:jt(Q.wallId,Q.wallSide),reanchor:Ut&&Jt?{wallId:Ut.wallId,wallSide:Ut.side,frame:Jt}:null});return we.kind==="keep"?H:(r(tn=>s1(tn,nt,we)),we.kind==="detach"?r1(H,nt):H)},[o,r,G]);m.useEffect(()=>{if(!Ot)return;const I=K=>{const nt=Ds(K.clientX,K.clientY);if(!nt)return;if(Ot.mode==="move"){const we={x:nt.x-Ot.startPoint.x,y:nt.y-Ot.startPoint.y};if(Ot.copyMode){_t.current=null,xt(null);const _o=Xu(je.current,je.current.find(io=>io.id===Ot.entityId&&io.kind==="polygon")??Ot.startEntity,Ot.startEntity),ys=x2(_o,[Ot.entityId],we,{newGroupId:!0});je.current=ys.entities,ne.current(ys.entities),ys.createdIds[0]&&u(ys.createdIds[0]),so(null),Vn();return}const Mn=H1(Ot.startEntity,we);if(Ot.wallSnapMode){const _o=DL(Mn,G,{stickySnap:Qe.current});Qe.current=(_o==null?void 0:_o.polygon.rectangleWallAnchor)??null;const ys=(_o==null?void 0:_o.polygon)??(Mn.rectangleWallAnchor?{...Mn,rectangleWallAnchor:void 0}:Mn);Lt((_o==null?void 0:_o.wallSnap)??null);let io=Xu(Ot.baseEntities,Ot.startEntity,ys);const zn=Ot.startEntity.groupId;if(zn){const Eo={x:ys.vertices[0].x-Ot.startEntity.vertices[0].x,y:ys.vertices[0].y-Ot.startEntity.vertices[0].y};(Eo.x!==0||Eo.y!==0)&&(io=io.map(rr=>rr.kind==="polygon"&&rr.id!==ys.id&&rr.groupId===zn?H1(rr,Eo):rr))}Ft(io);return}let tn=we,fn=tm(Ot.baseEntities,[Ot.entityId],tn);const Rs=fn.find(_o=>_o.id===Ot.entityId&&_o.kind==="polygon"),hn=Rs?Ro(Rs,fn):null;hn&&(tn={x:we.x+hn.delta.x,y:we.y+hn.delta.y},fn=tm(Ot.baseEntities,[Ot.entityId],tn)),Ft(fn);return}const Q=vt.find(we=>we.id===Ot.entityId&&we.kind==="polygon");if(!Q)return;const dt=PL(Q,Ot.handle,nt),jt=(()=>{const we=Q.rectangleWallAnchor;if(!we)return dt;const Mn=Q.vertices,tn=dt.vertices,fn=we.anchorEdgeIndex,Rs=Mn[fn],hn=Mn[(fn+1)%Mn.length],_o=tn[fn],ys=tn[(fn+1)%tn.length];return!Rs||!hn||!_o||!ys||Rs.x!==_o.x||Rs.y!==_o.y||hn.x!==ys.x||hn.y!==ys.y?{...dt,rectangleWallAnchor:void 0}:dt})(),Yt=jt.vertices.map(we=>we.x),Ut=jt.vertices.map(we=>we.y),Jt=kT({coords:[Math.max(...Yt)-Math.min(...Yt),Math.max(...Ut)-Math.min(...Ut)],gridSnapActive:!1,gridStep:0,freeStep:10});Jt!==Go.current&&(Go.current=Jt,Pr("resize")),Ft(Xu(vt,Q,jt))},H=()=>{Ot.mode==="move"&&Ot.wallSnapMode&&(Lt(null),Qe.current=null);const K=Vt();K&&d(Ot.mode==="move"&&!Ot.copyMode?Rr(Ot.baseEntities,K,{hostId:Ot.entityId}):K),so(null),Ot.mode==="move"&&Vn()};return window.addEventListener("pointermove",I),window.addEventListener("pointerup",H),()=>{window.removeEventListener("pointermove",I),window.removeEventListener("pointerup",H)}},[Vn,Vt,Rr,vt,d,u,Ds,Ot,Ro,Ft,G]),m.useEffect(()=>{if(!Ue)return;let I=null;const H=nt=>{const Q=Ds(nt.clientX,nt.clientY);if(!Q)return;const dt=Math.atan2(Q.y-Ue.center.y,Q.x-Ue.center.x),jt=Yu(dt*180/Math.PI-Ue.startAngleDeg),Yt=k3(Ue.baseEntities,Ue.entityIds,Ue.center,jt);if(Ft(Yt),Ue.groupId){const Ut=Ue.startRotationDeg??0;I=Yu(Ut+jt)}},K=()=>{const nt=Vt();if(nt&&d(Rr(Ue.baseEntities,nt,{groupId:Ue.groupId})),Ue.groupId&&r&&I!==null){const Q=Ue.groupId,dt=I;r(jt=>jt.map(Yt=>Yt.id===Q?{...Yt,rotationDeg:dt}:Yt))}hs(null)};return window.addEventListener("pointermove",H),window.addEventListener("pointerup",K),document.body.style.cursor="grabbing",()=>{document.body.style.cursor="",window.removeEventListener("pointermove",H),window.removeEventListener("pointerup",K)}},[Vt,Rr,d,r,Ds,Ue,Ft]),m.useEffect(()=>{var K;if(!Qn||(Ue==null?void 0:Ue.groupId)===Qn)return;const I=i?vt.find(nt=>nt.id===i):null;((I==null?void 0:I.groupId)??(I&&(I.kind==="facePatch"||I.kind==="faceSplit"||I.kind==="faceCornerArc")?(K=vt.find(nt=>nt.id===I.hostEntityId))==null?void 0:K.groupId:void 0))!==Qn&&Lr(null)},[vt,Ue==null?void 0:Ue.groupId,Qn,i]),m.useEffect(()=>{if(!ut||Rl(e))return;const I=H=>{const K=Ds(H.clientX,H.clientY);if(!K)return;const nt=es(K);ht(nt.point),Ps(nt.isPolygonCloseGesture)};return window.addEventListener("pointermove",I,{passive:!0}),()=>window.removeEventListener("pointermove",I)},[e,ut,Ds,es]);const ma=m.useCallback(I=>{d([...vt,I]),en(null),u(I.id)},[vt,d,u]),gn=m.useMemo(()=>!ut||ut.tool!=="line"||!Et?null:{start:ut.start,end:Et,lengthMm:Nn(ut.start,Et)},[ut,Et]),Zo=m.useMemo(()=>
246!ut||ut.tool!=="measure"||!Et?null:{phase:"start",start:ut.start,hover:Et,lengthMm:Nn(ut.start,Et),startElevationMm:ut.startElevationMm,hoverElevationMm:gt},[ut,Et,gt]),et=m.useMemo(()=>{if(e==="faceCornerArc"){if(!Le)return!pe||!Qt?null:{phase:"hover",reference:pe.point,hover:pe.point,lengthMm:0,heightFromCornerMm:0,widthFromCornerMm:0,labelHebrew:pe.kind==="midpoint"?pe.labelHebrew:void 0,hoverKind:pe.kind};const Ut=Le.frame,Jt=n1(Ut,Le.corner,Le.firstEdge,Le.start.point)??0;return{phase:"start",reference:Le.start.point,hover:Le.hover.point,lengthMm:Jt,heightFromCornerMm:Math.round(Math.abs(Le.hover.point.y-Le.start.point.y)),widthFromCornerMm:Math.round(Math.abs(Le.hover.point.x-Le.start.point.x)),labelHebrew:Le.hover.kind==="midpoint"?Le.hover.labelHebrew:void 0,hoverKind:Le.hover.kind}}if(!Be)return null;const I=Be.start.point,H=v2(Be),K=k2(H??void 0)??void 0,nt=(ve==null?void 0:ve.axis)===K&&(ve!=null&&ve.valueText)?Number(ve.valueText):void 0,Q=Math.round(Math.abs(Be.hover.point.y-I.y)),dt=Math.round(Math.abs(Be.hover.point.x-I.x)),jt=K==="height"&&nt!==void 0?nt:Q,Yt=K==="width"&&nt!==void 0?nt:dt;return{phase:Be.phase,reference:I,hover:Be.hover.point,lengthMm:nt??Nn(I,Be.hover.point),heightFromCornerMm:jt,widthFromCornerMm:Yt,activeAxis:K,keyboardEntryMm:nt,labelHebrew:Be.hover.kind==="midpoint"?Be.hover.labelHebrew:void 0,hoverKind:Be.hover.kind}},[e,Le,pe,Qt,ve,Be]),q=m.useMemo(()=>{if(!Be||!oe||oe.tool!=="faceLine")return null;const I=Nn(oe.start,Be.hover.point);return I<1?null:{start:oe.start,hover:Be.hover.point,lengthMm:I,hostEntityId:oe.hostEntityId,hostFaceId:oe.hostFaceId}},[oe,Be]),Ct=m.useMemo(()=>Fe?{phase:"start",reference:Fe.start.point,hover:Fe.hover.point,lengthMm:Nn(Fe.start.point,Fe.hover.point),hostEntityId:Fe.hostEntityId,hostFaceId:Fe.hostFaceId}:!xs||!_s(xs,vt)?null:{phase:"selected",reference:xs.start2D,hover:xs.end2D,lengthMm:Nn(xs.start2D,xs.end2D),hostEntityId:xs.hostEntityId,hostFaceId:xs.hostFaceId,measureEntityId:xs.id},[vt,Fe,_s,xs]),bt=m.useMemo(()=>{if(!Fe)return null;const I=Nn(Fe.start.point,Fe.hover.point);return I<1?null:{start:Fe.start.point,hover:Fe.hover.point,lengthMm:I,hostEntityId:Fe.hostEntityId,hostFaceId:Fe.hostFaceId}},[Fe]),Dt=m.useMemo(()=>{if(!ut||ut.tool!=="rectangle"||!Et)return null;const I=ut.wallSnap?f3(ut.start,Et,ut.wallSnap):Hp(ut.start,Et);return I?Xr(I):null},[ut,Et]),Xt=m.useMemo(()=>e!=="offset"||!Je||In===null?null:$1(Je.vertices,In),[e,In,Je]),me=m.useMemo(()=>rn?vt.find(I=>I.id===rn.hostEntityId&&I.kind==="polygon")??null:Je,[vt,rn,Je]),xe=(rn==null?void 0:rn.hostFaceId)??l,Ee=m.useMemo(()=>{if(e!=="faceOffset")return null;if(rn&&(rn.depthMm??0)>0){const I=vt.find(H=>H.id===rn.hostEntityId&&H.kind==="polygon");return I?Zh(rn,I):null}return!me||!xe?null:An(me,xe)},[e,vt,me,xe,rn]),wn=m.useMemo(()=>Ee?rn&&(rn.depthMm??0)>0?_e(0,0,Ee.widthMm,Ee.heightMm):me?rn?rn.points2D:Ve&&Ve.hostEntityId===me.id&&Ve.hostFaceId===xe?Ve.points2D:_e(0,0,Ee.widthMm,Ee.heightMm):null:null,[me,Ee,xe,rn,Ve]),lt=m.useMemo(()=>e!=="faceOffset"||!wn||zo===null?null:$1(wn,zo),[e,wn,zo]),He=m.useCallback((I,H,K,nt)=>{const Q=CL(I,H,K,void 0,{rectangleWallSnap:I==="rectangle"?nt??null:null});return Q?(ma(Q),ts(),queueMicrotask(()=>p(wo)),!0):(ts(),!1)},[ma,ts,p]),cn=m.useCallback((I,H,K,nt)=>{const Q=VL(I,H,void 0,void 0,K,nt);return Q?(ma(Q),ts(),queueMicrotask(()=>p(wo)),!0):(ts(),!1)},[ma,ts,p]),nn=m.useCallback((I,H,K)=>{var Jt;const nt=jn.current;if(!nt)return;const Q={x:I,y:H};if(!FL(nt.screen,Q)){jn.current=null;return}(Jt=K==null?void 0:K.stopPropagation)==null||Jt.call(K);const jt=Ds(I,H)??Et;if(!jt){ts();return}const Yt=es(jt,{tool:nt.tool,start:nt.start,...nt.tool==="rectangle"?{wallSnap:nt.rectangleWallSnap??null}:{}});He(nt.tool,nt.start,Yt.point,nt.rectangleWallSnap??null)||ts()},[ts,He,Et,Ds,es]);m.useEffect(()=>{if(!ut||Rl(e))return;const I=H=>{nn(H.clientX,H.clientY)};return window.addEventListener("pointerup",I),()=>window.removeEventListener("pointerup",I)},[e,ut,nn]);const or=m.useCallback(()=>{!gn||gn.lengthMm<20||He("line",gn.start,gn.end)},[He,gn]);m.useEffect(()=>{g==null||g((gn==null?void 0:gn.lengthMm)??null)},[gn==null?void 0:gn.lengthMm,g]),m.useEffect(()=>{j==null||j(et)},[et,j]),m.useEffect(()=>{v==null||v(Ct)},[Ct,v]),m.useEffect(()=>{A==null||A(zo)},[zo,A]),m.useEffect(()=>{W&&Kl.current!==W.id&&(Kl.current=W.id,js(W.distanceMm))},[W]),m.useEffect(()=>{if(!N||!Fe||da.current===N.id)return;da.current=N.id;const I=ro.current;if(!I)return;const H=m2(I.frame,I.start.point,I.hover.point,N.lengthMm);bo(I,{point:H,kind:"on-face",labelHebrew:"על פאה"})},[N,Fe,bo]),m.useEffect(()=>{if(!P||!Fe||As.current===P.id)return;As.current=P.id;const I=ro.current;if(!I)return;const H=je.current.find(nt=>nt.id===I.hostEntityId&&(nt.kind==="polygon"||nt.kind==="facePatch"));if(!H)return;
246const K=m2(I.frame,I.start.point,I.hover.point,P.lengthMm);bs(H,I.frame,I.start.point,K)},[bs,P,Fe]),m.useEffect(()=>{L&&ua.current!==L.id&&(ua.current=L.id,Kr(L.measureEntityId,L.lengthMm))},[Kr,L]),m.useEffect(()=>{!b||!gn||po.current!==b.id&&(po.current=b.id,ht(kp(gn.start,gn.end,b.lengthMm)))},[gn,b]);const qn=(Dt==null?void 0:Dt.lengthMm)??null,Oo=(Dt==null?void 0:Dt.widthMm)??null;m.useEffect(()=>{k==null||k(qn!==null&&Oo!==null?{lengthMm:qn,widthMm:Oo}:null)},[k,qn,Oo]),m.useEffect(()=>{!w||!ut||ut.tool!=="rectangle"||!Et||go.current!==w.id&&(go.current=w.id,ht(yL(ut.start,Et,w.lengthMm,w.widthMm,20,ut.wallSnap??null)))},[ut,Et,w]),m.useEffect(()=>{M&&ho.current!==M&&(ho.current=M,or())},[or,M]);const Ks=m.useCallback((I,H)=>{if(!Xi(I)){console.warn("[fp-sketch] commit rejected — invalid polygon",{vertexCount:I.length});return}const K=Ae(I,H);ma(K),p(wo),K.id,I.length},[ma,p]),sr=m.useCallback(I=>{I.length<3||(Ks(I,"polygon"),kt(null),ht(null),Ps(!1),p(wo))},[Ks,p]);m.useEffect(()=>{const I=H=>{var K,nt;if(((K=H.target)==null?void 0:K.tagName)!=="INPUT"&&((nt=H.target)==null?void 0:nt.tagName)!=="TEXTAREA"){if(H.key==="Escape"&&(Us(),en(null),u(null),vn(null),Vn()),H.key==="Enter"&&e==="polygon"&&(ut==null?void 0:ut.tool)==="polygon"){H.preventDefault();const Q=cg({points:ut.points},{type:"close"});Q.commitPoints&&sr(Q.commitPoints)}if((H.key==="Backspace"||H.key==="Delete")&&e==="polygon"&&(ut==null?void 0:ut.tool)==="polygon"){H.preventDefault(),H.stopImmediatePropagation();const Q=cg({points:ut.points},{type:"backspace"});Q.next.points.length===0?(kt(null),ht(null),Ps(!1)):(kt({tool:"polygon",points:Q.next.points}),Ps(!1))}H.key==="Enter"&&e==="line"&&gn&&(H.preventDefault(),or())}};return window.addEventListener("keydown",I),()=>window.removeEventListener("keydown",I)},[e,Us,Vn,or,sr,ut,gn,u]);const Ls=m.useCallback((I=(Je==null?void 0:Je.id)??null,H=In)=>{if(!I||H===null||H<=0)return;const K=dW(vt,I,H);K!==vt&&(d(K),en(null),u(I),Gs(null),p(wo))},[vt,In,p,d,u,Je]),ns=m.useCallback((I,H,K,nt,Q=0)=>{var fn,Rs;const dt=nt??zo??Kh,jt=I.kind==="facePatch"?(()=>{const hn=je.current.find(_o=>_o.id===I.hostEntityId&&_o.kind==="polygon");return hn?Zh(I,hn):null})():An(I,H);if(!jt||dt<=0)return!1;const Yt=I.groupId??Me(),Ut=HL(I.id,H,K.map(hn=>ko(jt,hn)),dt,Yt,void 0,Q);if(!Ut)return!1;const Jt=je.current.map(hn=>hn.id===I.id&&(hn.kind==="polygon"||hn.kind==="facePatch")&&!hn.groupId?{...hn,groupId:Yt}:hn).concat(Ut);je.current=Jt,ne.current(Jt),(fn=Ze.current)==null||fn.call(Ze,null);const we=(Rs=Ut.holes2D)!=null&&Rs[0]?sF(Ut.holes2D[0]):null,Mn=Jt.find(hn=>hn.id===I.id&&hn.kind==="polygon"),tn=Mn&&we?V1(jt,qy(Mn,Jt.filter(hn=>hn.kind==="facePatch"&&hn.hostEntityId===Mn.id&&hn.shape==="rectangle")).filter(hn=>hn.hostFaceId===H),Jt.filter(hn=>hn.kind==="faceSplit"&&hn.hostEntityId===Mn.id&&hn.hostFaceId===H),Jt.filter(hn=>hn.kind==="faceCornerArc"&&hn.hostEntityId===Mn.id&&hn.hostFaceId===H)).find(hn=>hn.role==="remaining"&&Math.abs(hn.bounds.minX-we.minX)<=1&&Math.abs(hn.bounds.minY-we.minY)<=1&&Math.abs(hn.bounds.maxX-we.maxX)<=1&&Math.abs(hn.bounds.maxY-we.maxY)<=1)??null:null;return en(tn),u(tn?I.id:Ut.id),h==null||h(tn?H:Ut.hostFaceId),Dn.current(wo),!0},[zo,u,h]),ii=m.useCallback(I=>{if(I<=0)return;if(rn&&(rn.depthMm??0)>0){const nt=vt.find(dt=>dt.id===rn.hostEntityId&&dt.kind==="polygon"),Q=nt?Zh(rn,nt):null;if(Q){ns(rn,"front",_e(0,0,Q.widthMm,Q.heightMm),I,y2);return}}if(!me||!xe)return;const H=An(me,xe);if(!H)return;const K=rn?rn.points2D:Ve&&Ve.hostEntityId===me.id&&Ve.hostFaceId===xe?Ve.points2D:_e(0,0,H.widthMm,H.heightMm);ns(me,xe,K,I)},[ns,vt,me,xe,rn,Ve]);m.useEffect(()=>{S&&Gi.current!==S.id&&(Gi.current=S.id,js(S.distanceMm),ii(S.distanceMm))},[ii,S]),m.useEffect(()=>{B&&On.current!==B.id&&(On.current=B.id,Rn(B.distanceMm))},[B]),m.useEffect(()=>{R&&to.current!==R.id&&(to.current=R.id,Rn(R.distanceMm),Ls((Je==null?void 0:Je.id)??null,R.distanceMm))},[Ls,R,Je==null?void 0:Je.id]);const Ia=m.useCallback(I=>{const H=b3(je.current,I);return H?(je.current=H.entities,ne.current(H.entities),en(null),u(H.patch.id),h==null||h("top"),H.patch):null},[u,h]),Or=m.useCallback((I,H)=>{const K=H!=null&&H.whole?fW(vt,I):null;if(K){const nt=o.find(Q=>Q.id===K);d(xW(vt,K,(nt==null?void 0:nt.entityIds)??[])),r==null||r(Q=>Q.filter(dt=>dt.id!==K))}else d(M3(vt,I));Pr("itemDelete"),(Ve==null?void 0:Ve.hostEntityId)===I&&en(null),i===I&&u(null),dn(nt=>nt!==I?nt:(Se.current&&(Se.current=!1,f==null||f(!1)),null)),ze(null)},[vt,o,f,d,r,u,i,Ve]),os=m.useCallback((I,H=vo)=>{var dt;const K=H??vo;if(!K)return;const nt=I.nativeEvent,Q=K.kind==="facePatch"?Math.round(K.depthMm??0):Math.max(0,Math.round(K.heightMm??0));(dt=Ze.current)==null||dt.call(Ze,Q),Qs({selectedId:K.id,startClientX:nt.clientX,startClientY:nt.clientY,startHeightMm:Q,screenNormal:K.kind==="facePatch"?yi(K,I):null})},[yi,vo]),Zr=m.useCallback((I,H,K)=>
246{if(I.kind!=="polygon"||!K)return null;const nt=je.current.filter(Ut=>Ut.kind==="facePatch"&&Ut.hostEntityId===I.id&&Ut.hostFaceId===K);if(!nt.length)return null;const Q=rn&&rn.hostEntityId===I.id&&rn.hostFaceId===K?[rn,...nt.filter(Ut=>Ut.id!==rn.id)]:[...nt].reverse(),dt=An(I,K);if(!dt)return null;const jt=Ht.current?Ht.current.worldToLocal(H.point.clone()):H.point.clone(),Yt=Bl(dt,jt);return Q.find(Ut=>{var we;return z1(Yt,Ut.points2D)?(we=Ut.holes2D)!=null&&we.length?!Ut.holes2D.some(Mn=>z1(Yt,Mn)):!0:!1})??null},[rn]),Fn=m.useCallback((I,H,K)=>{K.button===0&&(K.stopPropagation(),ze(null),en(null),vn({entityId:I,endpoint:H}),u(I))},[u]),qr=m.useCallback((I,H,K={})=>{var jt;if(H.button!==0)return;const nt=H.nativeEvent;H.stopPropagation(),nt.preventDefault(),(jt=nt.stopImmediatePropagation)==null||jt.call(nt),ze(null),en(null);const Q=K.wallSnapMode===!0,dt=Q?!1:nt.ctrlKey||nt.metaKey;dn(I.id),Te(Q?I.id:null),Qe.current=Q?I.rectangleWallAnchor??null:null,Se.current||(Se.current=!0,f==null||f(!0)),so({mode:"move",entityId:I.id,startPoint:zs(H),startEntity:I,copyMode:dt,wallSnapMode:Q,baseEntities:vt}),u(I.id)},[vt,f,u,zs]),Ye=m.useMemo(()=>{const I=new Set;for(const H of o)if(H.rigid)for(const K of H.entityIds)I.add(K);return I},[o]),Ke=m.useCallback(I=>{if(I.button!==0||!uo||!Rl(e))return;const H=uo,K=je.current.find(we=>we.id===H&&we.kind==="polygon");if(!K)return;I.stopPropagation();const nt=zs(I),Q=em(je.current,[H]);if(!Q)return;let dt={x:nt.x-Q.x,y:nt.y-Q.y},jt=tm(je.current,[H],dt);const Yt=jt.find(we=>we.id===H&&we.kind==="polygon"),Ut=Yt?Ro(Yt,jt):null;Ut&&(dt={x:dt.x+Ut.delta.x,y:dt.y+Ut.delta.y},jt=tm(je.current,[H],dt)),je.current=jt,ne.current(jt);const Jt=jt.find(we=>we.id===H&&we.kind==="polygon")??K;so({mode:"move",entityId:H,startPoint:nt,startEntity:Jt,copyMode:!1,wallSnapMode:!1,baseEntities:jt})},[e,uo,zs,Ro]),Mo=m.useCallback((I,H)=>{if(H.button!==0)return;const K=em(vt,I);if(!K)return;const nt=zs(H);nt&&(H.stopPropagation(),ze(null),hs({entityIds:I,center:K,startAngleDeg:Math.atan2(nt.y-K.y,nt.x-K.x)*180/Math.PI,baseEntities:vt}))},[vt,zs]),re=m.useCallback((I,H)=>{var jt;if(H.button!==0)return;const K=vt.filter(Yt=>Yt.groupId===I).map(Yt=>Yt.id);if(K.length===0)return;const nt=em(vt,K);if(!nt)return;const Q=zs(H);if(!Q)return;H.stopPropagation(),ze(null);const dt=((jt=o.find(Yt=>Yt.id===I))==null?void 0:jt.rotationDeg)??0;hs({entityIds:K,center:nt,startAngleDeg:Math.atan2(Q.y-nt.y,Q.x-nt.x)*180/Math.PI,baseEntities:vt,groupId:I,startRotationDeg:dt}),Pr("itemPick")},[vt,o,zs]),_n=m.useCallback((I,H,K)=>{K.button===0&&(K.stopPropagation(),ze(null),en(null),Go.current=null,so({mode:"resize",entityId:I,handle:H}),u(I))},[u]),jo=m.useCallback((I,H,K)=>{if(H.widthMm<20||H.heightMm<20)return!1;if(e==="faceMeasure")return xl(I,H,K);if(!gg(e))return!1;if(e==="faceLine")return Fs(I,H,K);if(e==="faceCornerArc")return Na(I,H,K);jn.current=null,kt(null),ht(null),en(null);const nt={tool:"faceRectangle",hostEntityId:I.id,hostFaceId:H.faceId,frame:H,start:K.point};return Gt.current=nt,Co.current=K,Xo.current=H,he(nt),Ge(K),te(H),u(I.id),h==null||h(H.faceId),Wr(nt,K),!0},[e,Na,Fs,xl,u,h,Wr]),Ms=m.useCallback((I,H,K,nt)=>{if(H.stopPropagation(),e==="faceLine"){if(ls.current===H.nativeEvent.timeStamp)return!0;ls.current=H.nativeEvent.timeStamp}if(e==="faceCornerArc"){if(Qo.current===H.nativeEvent.timeStamp)return!0;Qo.current=H.nativeEvent.timeStamp}if(e==="faceMeasure"){if(ms.current===H.nativeEvent.timeStamp)return!0;ms.current=H.nativeEvent.timeStamp}return jo(I,K,nt)},[e,jo]);m.useEffect(()=>{if(e!=="faceLine"&&e!=="faceCornerArc")return;const I=H=>{if(H.button!==0)return;const K=e==="faceLine"?ls:Qo;if(K.current===H.timeStamp)return;const nt=Zt.domElement.getBoundingClientRect();if(H.clientX<nt.left||H.clientX>nt.right||H.clientY<nt.top||H.clientY>nt.bottom)return;const Q=Xo.current,dt=Co.current;if(!Q||!dt||dt.kind!=="endpoint"&&dt.kind!=="midpoint"&&dt.kind!=="on-edge")return;const jt=je.current.find(Yt=>Yt.id===Q.hostEntityId&&Yt.kind==="polygon");jt&&(K.current=H.timeStamp,e==="faceLine"?Fs(jt,Q,dt):Na(jt,Q,dt))};return window.addEventListener("pointerdown",I),()=>window.removeEventListener("pointerdown",I)},[e,Na,Fs,Zt]),m.useEffect(()=>{if(e!=="faceMeasure"||!Fe)return;const I=(Q,dt)=>{const jt=ro.current;if(!jt)return null;const Yt=nr(Q,dt,jt.frame);return Yt?Ol(jt.frame,Yt,jt.start.point,fg):null},H=()=>{const Q=ro.current;return Q?je.current.find(dt=>dt.id===Q.hostEntityId&&(dt.kind==="polygon"||dt.kind==="facePatch"))??null:null},K=Q=>{const dt=ro.current;if(!dt)return;const jt=I(Q.clientX,Q.clientY);jt&&bo(dt,jt)},nt=Q=>
246{if(Q.button===2){Q.preventDefault(),Us();return}if(Q.button!==0||ms.current===Q.timeStamp)return;const dt=Zt.domElement.getBoundingClientRect();if(Q.clientX<dt.left||Q.clientX>dt.right||Q.clientY<dt.top||Q.clientY>dt.bottom)return;const jt=ro.current,Yt=H();if(!jt||!Yt)return;const Ut=I(Q.clientX,Q.clientY);Ut&&(ms.current=Q.timeStamp,xl(Yt,jt.frame,Ut))};return window.addEventListener("pointermove",K,{passive:!0}),window.addEventListener("pointerdown",nt),()=>{window.removeEventListener("pointermove",K),window.removeEventListener("pointerdown",nt)}},[e,xl,Us,Fe,nr,Zt.domElement,bo]);const un=m.useCallback(I=>{var K,nt;if(!e||!xg(e))return!1;if(I.button===2)return(K=I.stopPropagation)==null||K.call(I),Us(),!0;if(I.button!==0)return!1;(nt=I.stopPropagation)==null||nt.call(I);const H=I.rawPoint;if(e==="measure"){if(!ut||ut.tool!=="measure")return mt(null),Lt(null),kt({tool:"measure",start:H,startElevationMm:I.rawElevationMm}),ht(H),Pt(I.rawElevationMm),Ps(!1),!0;mt(null),Lt(null);const Q=Et??H,dt=Et?gt:I.rawElevationMm;return ht(Q),Pt(dt),Ps(!1),cn(ut.start,Q,ut.startElevationMm,dt),!0}if(OR(e)){if(!ut||ut.tool!==e){const jt=e==="rectangle"?eh(H,I.altKey):{point:Ca(H),wallSnap:null};return jn.current={tool:e,start:jt.point,rectangleWallSnap:e==="rectangle"?jt.wallSnap:null,screen:{x:I.clientX,y:I.clientY}},kt(e==="rectangle"?{tool:"rectangle",start:jt.point,wallSnap:jt.wallSnap}:{tool:e,start:jt.point}),ht(jt.point),!0}const Q=lv({candidate:H,entities:vt,draft:Cv(ut),tapeAnchor:null});mt(Q.inferenceSnapKind==="none"?null:{kind:Q.inferenceSnapKind,point:Q.point});const dt=ut.tool==="rectangle"&&ut.wallSnap?Et??H:Et??Q.point;return He(e,ut.start,dt,ut.tool==="rectangle"?ut.wallSnap??null:null),!0}if(e==="polygon"){if(!ut||ut.tool!=="polygon"){const Ut=Ca(H);return kt({tool:"polygon",points:[Ut]}),ht(Ut),Ps(!1),!0}const Q=es(H),dt=Q.point,jt=Q.isPolygonCloseGesture,Yt=cg({points:ut.points},{type:"click",point:dt,isCloseGesture:jt});return Yt.commitPoints?sr(Yt.commitPoints):(kt({tool:"polygon",points:Yt.next.points}),ht(dt),Ps(jt)),!0}return!1},[e,Us,sr,cn,He,ut,vt,Et,gt,Ca,eh,es]),hr=m.useCallback(I=>{if(!(!e||e==="select"||e==="rotate")){if(xg(e)){if(Wt.current===I.nativeEvent.timeStamp)return;const H=e==="measure"?Ti(I.nativeEvent.clientX,I.nativeEvent.clientY,I.nativeEvent.shiftKey)??zs(I):zs(I);Wt.current=I.nativeEvent.timeStamp,un({button:I.button,rawPoint:H,rawElevationMm:void 0,clientX:I.nativeEvent.clientX,clientY:I.nativeEvent.clientY,shiftKey:I.nativeEvent.shiftKey,altKey:I.nativeEvent.altKey,stopPropagation:()=>I.stopPropagation()});return}if(I.button===2){I.stopPropagation(),I.nativeEvent.preventDefault(),Y==null||Y(),Us();return}if(I.stopPropagation(),e==="offset"){Je&&Xt&&Ls(Je.id,In);return}if(e==="pushPull"){os(I);return}}},[e,Us,Ls,In,Xt,Ti,zs,un,Y,Je,os]),_r=m.useCallback(I=>{if(!e||Rl(e))return;oe||(Ge(null),te(null));const H=e==="measure"?Ti(I.nativeEvent.clientX,I.nativeEvent.clientY,I.nativeEvent.shiftKey)??zs(I):zs(I);if(e==="rectangle"&&(!ut||ut.tool!=="rectangle")){const nt=I.nativeEvent.altKey?null:If(H,G);
246if(Lt(nt),nt){mt(null);return}}if(e==="offset"){if(!Je)return;const nt=cv(Je.vertices,H);Rn(nt),Gs(nt===null?null:{x:I.nativeEvent.clientX,y:I.nativeEvent.clientY});return}if(e==="measure"){mt(null),Lt(null),ht(H),Pt(void 0),Ps(!1);return}const K=es(H);ht(K.point),Ps(K.isPolygonCloseGesture)},[e,ut,oe,zs,es,Ti,Je,G]),Ta=m.useCallback(I=>{qe.current!==I.nativeEvent.timeStamp&&(qe.current=I.nativeEvent.timeStamp,nn(I.nativeEvent.clientX,I.nativeEvent.clientY,{stopPropagation:()=>I.stopPropagation()}),Qs(null),vn(null),(Ot==null?void 0:Ot.mode)==="move"&&Vn(),so(null))},[Vn,nn,Ot==null?void 0:Ot.mode]);m.useEffect(()=>{if(!xg(e))return;const I=Zt.domElement,H=Q=>{if(e==="measure"||Wt.current===Q.timeStamp||Q.button!==0&&Q.button!==2)return;const dt=Ds(Q.clientX,Q.clientY);dt&&(Wt.current=Q.timeStamp,un({button:Q.button,rawPoint:dt,clientX:Q.clientX,clientY:Q.clientY,shiftKey:Q.shiftKey,altKey:Q.altKey}))},K=Q=>{const dt=e==="measure"?Ti(Q.clientX,Q.clientY,Q.shiftKey):Ds(Q.clientX,Q.clientY);if(!dt)return;if(Gt.current||(Ge(null),te(null)),e==="rectangle"&&(!ut||ut.tool!=="rectangle")){const Yt=Q.altKey?null:If(dt,G);if(Lt(Yt),Yt){mt(null);return}}if(e==="measure"){mt(null),Lt(null),ht(dt),Pt(void 0),Ps(!1);return}const jt=es(dt);ht(jt.point),Ps(jt.isPolygonCloseGesture)},nt=Q=>{qe.current!==Q.timeStamp&&(qe.current=Q.timeStamp,nn(Q.clientX,Q.clientY),Qs(null),vn(null),so(null))};return window.addEventListener("pointerdown",H,{capture:!0}),I.addEventListener("pointermove",K,{passive:!0}),window.addEventListener("pointerup",nt,{capture:!0}),()=>{window.removeEventListener("pointerdown",H,{capture:!0}),I.removeEventListener("pointermove",K),window.removeEventListener("pointerup",nt,{capture:!0})}},[e,nn,Zt.domElement,un,Ds,es,Ti,ut,i,l,G]);const ss=m.useCallback(I=>{if(e!=="polygon"||(ut==null?void 0:ut.tool)!=="polygon")return;I.stopPropagation();const H=cg({points:ut.points},{type:"close"});H.commitPoints&&sr(H.commitPoints)},[e,sr,ut]),Ai=m.useCallback((I,H)=>{const K=pn.current,nt=tr.current;return e==="faceLine"&&K&&Fu(K,I)?hg(I,H,{allowedEdges:K.allowedEdges,referencePoint:K.start.point,referenceEdges:K.allowedEdges}):e==="faceCornerArc"&&nt&&Fu(nt,I)?hg(I,H,{allowedEdges:[nt.secondEdge]}):hg(I,H)},[e]),No=m.useCallback((I,H,K)=>{var we;if(!gg(e)&&e!=="faceMeasure"||(e==="faceLine"||e==="faceCornerArc")&&(i!==I.id||!l)||e!=="faceMeasure"&&Je&&I.id!==Je.id)return!1;const nt=(e==="faceLine"||e==="faceCornerArc")&&Ki===I.id&&l?l:K,Q=(Qt==null?void 0:Qt.hostEntityId)===I.id&&Qt.faceId===nt?Qt:null,dt=Q??An(I,nt);if(!dt)return!1;const jt=Ht.current?Ht.current.worldToLocal(H.point.clone()):H.point.clone(),Yt=e==="faceLine"||e==="faceCornerArc"||e==="faceMeasure"?nr(H.nativeEvent.clientX,H.nativeEvent.clientY,dt)??Bl(dt,jt):Bl(dt,jt),Ut=Q&&pe&&(pe.kind==="endpoint"||pe.kind==="midpoint"||pe.kind==="on-edge")?pe:null,Jt=e==="faceCornerArc"?Ut??Ai(dt,Yt):e==="faceLine"?Ol(dt,Yt,null,rf(I.id,dt.faceId,je.current)):e==="faceMeasure"?Ol(dt,Yt,((we=ro.current)==null?void 0:we.start.point)??null,fg):Q&&pe?pe:Ol(dt,Yt,null,rf(I.id,dt.faceId,je.current,e==="faceRectangle"?Sx:void 0));return Jt?Ms(I,H,dt,Jt):(H.stopPropagation(),!0)},[e,pe,Qt,nr,Ai,i,l,Je,Ki,Ms]),Er=m.useCallback((I,H,K)=>{var fn;if(I.kind!=="polygon"||!pg(e)||!K||(e==="faceLine"||e==="faceCornerArc")&&(i!==I.id||!l)||e!=="faceMeasure"&&Je&&I.id!==Je.id)return;const nt=(e==="faceLine"||e==="faceCornerArc")&&Ki===I.id&&l?l:K,Q=An(I,nt);if(!Q)return;const dt=Ht.current?Ht.current.worldToLocal(H.point.clone()):H.point.clone(),jt=e==="faceLine"||e==="faceCornerArc"?nr(H.nativeEvent.clientX,H.nativeEvent.clientY,Q)??Bl(Q,dt):Bl(Q,dt),Yt=(oe==null?void 0:oe.hostEntityId)===I.id&&oe.hostFaceId===nt?oe:null,Ut=e==="faceCornerArc",Jt=(Yt==null?void 0:Yt.tool)==="faceRectangle"?Ol(Q,jt,Yt.start,rf(I.id,nt,je.current,Sx)):(Yt==null?void 0:Yt.tool)==="faceLine"?cW(Q,jt,Yt.start):Ut?Ai(Q,jt)??Co.current:e==="faceMeasure"?Ol(Q,jt,((fn=ro.current)==null?void 0:fn.start.point)??null,fg):e==="faceLine"?Ol(Q,jt,null,rf(I.id,nt,je.current)):Ol(Q,jt,(Yt==null?void 0:Yt.start)??null,rf(I.id,nt,je.current,e==="faceRectangle"?Sx:void 0));if(H.stopPropagation(),!Jt){Co.current=null,Xo.current=null,Ge(null),te(null);return}const we=pn.current;if(e==="faceLine"&&we&&Fu(we,Q)){pl(we,Jt);return}const Mn=tr.current;if(e==="faceCornerArc"&&Mn&&Fu(Mn,Q)){Pi(Mn,Jt);return}const tn=ro.current;if(e==="faceMeasure"&&tn&&Fu(tn,Q)){bo(tn,Jt);return}Co.current=Jt,Xo.current=Q,Ge(Jt),te(Q)},[e,oe,nr,Ai,i,l,Je,Ki,Pi,bo,pl]),gc=m.useCallback((I,H,K)=>{var nt;if(H.button===2){if(e==="pushPull"){H.stopPropagation(),H.nativeEvent.preventDefault(),Y==null||Y(),ze(null),Us();return}if(Un){Hn(H);return}if(Uo(H,I))return;H.stopPropagation(),fs(I,H.nativeEvent.clientX,H.nativeEvent.clientY,K);return}
246if(!(H.button===0&&oi(I,H,K))&&!Uo(H,I)){if(I.kind==="polygon"){const Q=CD(I,o);if(K&&Q.has(K)){H.stopPropagation();return}}if(H.button===0&&uo){const Q=er(I.id);if(Q===uo&&Rl(e)){const dt=je.current.find(jt=>jt.id===Q&&jt.kind==="polygon");if(dt){qr(dt,H,{wallSnapMode:$o===Q}),Pr("itemPick");return}}Vn()}if(xg(e)){if(Wt.current===H.nativeEvent.timeStamp)return;const Q=e==="measure"?Ti(H.nativeEvent.clientX,H.nativeEvent.clientY,H.nativeEvent.shiftKey)??zs(H):zs(H);Wt.current=H.nativeEvent.timeStamp,un({button:H.button,rawPoint:Q,rawElevationMm:void 0,clientX:H.nativeEvent.clientX,clientY:H.nativeEvent.clientY,shiftKey:H.nativeEvent.shiftKey,altKey:H.nativeEvent.altKey,stopPropagation:()=>H.stopPropagation()});return}if(w2(e)&&I.kind==="facePatch"&&(I.depthMm??0)>0){const Q=je.current.find(jt=>jt.id===I.hostEntityId&&jt.kind==="polygon"),dt=Q?Zh(I,Q):null;if(dt){H.stopPropagation();const jt=Math.min(dt.widthMm,dt.heightMm),Ut=Math.max(10,Math.min(zo??Kh,Math.floor(jt*.4)-1));ns(I,"front",_e(0,0,dt.widthMm,dt.heightMm),Ut,y2);return}}if(e==="faceRectangle"&&I.kind==="facePatch"&&(I.depthMm??0)>0){const Q=je.current.find(jt=>jt.id===I.hostEntityId&&jt.kind==="polygon"),dt=Q?Zh(I,Q):null;if(dt&&dt.widthMm>=20&&dt.heightMm>=20){const jt=Ht.current?Ht.current.worldToLocal(H.point.clone()):H.point.clone(),Yt=Bl(dt,jt),Ut=Ol(dt,Yt,null,rf(I.id,dt.faceId,je.current,Sx));if(Ut){H.stopPropagation(),ze(null),en(null),x==null||x(null);const Jt={tool:"faceRectangle",hostEntityId:I.id,hostFaceId:dt.faceId,frame:dt,start:Ut.point};Gt.current=Jt,Co.current=Ut,Xo.current=dt,he(Jt),Ge(Ut),te(dt),u(I.id),h==null||h(dt.faceId),Wr(Jt,Ut);return}}}if(e==="faceMeasure"&&I.kind==="facePatch"&&(I.depthMm??0)>0){const Q=It(I,"front");if(Q&&Q.widthMm>=20&&Q.heightMm>=20){const dt=Ht.current?Ht.current.worldToLocal(H.point.clone()):H.point.clone(),jt=nr(H.nativeEvent.clientX,H.nativeEvent.clientY,Q)??Bl(Q,dt),Yt=Ol(Q,jt,((nt=ro.current)==null?void 0:nt.start.point)??null,fg);if(Yt&&(H.stopPropagation(),ze(null),x==null||x(null),ms.current===H.nativeEvent.timeStamp||(ms.current=H.nativeEvent.timeStamp,xl(I,Q,Yt))))return}}if(I.kind==="polygon"&&K&&pg(e)){if(w2(e)){const Q=An(I,K);if(Q){H.stopPropagation(),ns(I,K,_e(0,0,Q.widthMm,Q.heightMm));return}}if(No(I,H,K))return;if(Je&&I.id!==Je.id){H.stopPropagation();return}}if(e==="pushPull"){const Q=Zr(I,H,K);if(Q){H.stopPropagation(),ze(null),en(null),x==null||x(null),u(Q.id),h==null||h(Q.hostFaceId),os(H,Q);return}if(I.kind==="polygon"&&K&&K!=="top"&&K!=="bottom"&&K!=="side"){const dt=sW(je.current,I.id,K);if(dt){H.stopPropagation(),ze(null),en(null),x==null||x(null),je.current=dt.entities,ne.current(dt.entities),u(dt.patch.id),h==null||h(dt.patch.hostFaceId),os(H,dt.patch);return}}}if(H.stopPropagation(),ze(null),en(null),x==null||x(null),u(I.id),I.kind==="polygon"||I.kind==="facePatch"?h==null||h(K??null):I.kind==="faceCornerArc"&&I.verticalThroughCut&&K==="side"?h==null||h("side"):I.kind==="faceMeasure"?h==null||h(I.hostFaceId):h==null||h(null),e==="offset"){if(I.kind!=="polygon")return;if(i!==I.id){Rn(Kh),Gs(null);return}Ls(I.id,In)}else if(e==="pushPull")(I.kind==="polygon"||I.kind==="facePatch")&&os(H,I);else if(e==="rotate"&&I.kind==="polygon"){const Q=I,dt=Q.groupId?vt.filter(jt=>jt.groupId===Q.groupId).map(jt=>jt.id):[I.id];Mo(dt,H)}else Rl(e)&&I.kind==="polygon"&&i===I.id&&qr(I,H)}},[e,xl,Us,Vn,Un,ns,Ls,uo,$o,Hn,vt,zo,nr,un,In,fs,u,x,h,Y,oi,zs,Ti,It,er,i,Je,qr,os,Mo,No,Wr,Zr,Uo,o]),Dr=m.useCallback((I,H,K)=>{if(e==="pushPull"){H.stopPropagation(),H.nativeEvent.preventDefault(),Y==null||Y(),ze(null),Us();return}if(Un){Hn(H);return}Uo(H,I)||(H.stopPropagation(),H.nativeEvent.preventDefault(),fs(I,H.nativeEvent.clientX,H.nativeEvent.clientY,K))},[e,Us,Un,Hn,Y,fs,Uo]),qi=m.useCallback((I,H,K)=>{if(K.button===0&&Rl(e)){if(uo){const nt=er(I.id);if(nt===uo){const Q=je.current.find(dt=>dt.id===nt&&dt.kind==="polygon");if(Q){qr(Q,K,{wallSnapMode:$o===nt}),Pr("itemPick");return}}Vn()}K.stopPropagation(),ze(null),en(null),u(I.id),h==null||h("top"),x==null||x(H)}},[e,Vn,uo,$o,u,h,x,er,qr]),jm=m.useCallback((I,H,K)=>{if(K.button===2){if(e==="pushPull"){K.stopPropagation(),K.nativeEvent.preventDefault(),Y==null||Y(),ze(null),Us();return}if(Un){Hn(K);return}if(Uo(K,I))return;K.stopPropagation(),Y==null||Y(),Vn(),x==null||x(null),u(I.id,{suppressDetail
246sPanelAutoOpen:!0}),h==null||h(H.hostFaceId),en(H),ze({entityId:I.id,x:K.nativeEvent.clientX,y:K.nativeEvent.clientY,faceId:H.hostFaceId,hostFaceRegion:H});return}if(K.button===0&&Un){K.stopPropagation(),ze(null),st==null||st({entityId:I.id,faceId:H.hostFaceId,hostFaceRegion:H});return}if(!Uo(K,I)){if(K.button===0&&uo){if(uo===I.id&&Rl(e)){qr(I,K,{wallSnapMode:$o===I.id});return}Vn()}if(w2(e)){K.stopPropagation(),ns(I,H.hostFaceId,H.points2D);return}if(e==="pushPull"){K.stopPropagation();const nt=Ia(H);nt&&os(K,nt);return}(gg(e)||e==="faceMeasure")&&No(I,K,H.hostFaceId)||(K.stopPropagation(),ze(null),x==null||x(null),u(I.id),h==null||h(H.hostFaceId),en(H))}},[e,Us,Vn,Un,ns,uo,$o,Hn,u,x,h,st,Y,Ia,os,No,qr,Uo]);m.useEffect(()=>{const I=H=>{var K,nt;((K=H.target)==null?void 0:K.tagName)!=="INPUT"&&((nt=H.target)==null?void 0:nt.tagName)!=="TEXTAREA"&&(e==="polygon"&&(ut==null?void 0:ut.tool)==="polygon"||(H.key==="Delete"||H.key==="Backspace")&&i&&(H.preventDefault(),Or(i,{whole:!0})))};return window.addEventListener("keydown",I),()=>window.removeEventListener("keydown",I)},[e,Or,ut,i]);const Ws=JO(ut,Et,bi),yr=Math.max(t.span*8,8),fa=pg(e),Kd=gg(e)||e==="faceMeasure",Zl=m.useCallback(()=>[],[Tt,vt,Zt]),En=m.useCallback(()=>[],[Tt,vt,eo]),Fr=m.useCallback(()=>[],[Tt,Zt,G]),wr=m.useCallback((I,H)=>[],[Tt,Zt,At]),qa=m.useCallback((I,H=0)=>null,[Tt,Zt]),Zd=m.useCallback(()=>[],[Tt,vt,_s,eo]),td=m.useCallback(()=>[],[Tt,vt,eo]);ka(()=>{}),m.useEffect(()=>{},[e,vt,Le,oe,pe,Qt,ve,et,q,Ct,bt,Zo,zo,Nt,on,i,l,c,Ve,Un,Zd,td,En,Zl,Fr,qa,wr,si,G]),m.useEffect(()=>{if(!co){Rt==null||Rt(null);return}const I=co.entityId,H=je.current.find(zn=>zn.id===I)??null,K=H&&co.faceId&&(H.kind==="polygon"||H.kind==="facePatch"||H.kind==="faceCornerArc"&&H.verticalThroughCut&&co.faceId==="side")?{entityId:I,faceId:co.faceId,...co.hostFaceRegion?{hostFaceRegion:co.hostFaceRegion}:{}}:null,nt=(()=>{var Eo,rr;if(!K||!H)return!1;const zn=H.kind==="faceCornerArc"?(Eo=H.faces)==null?void 0:Eo.side:H.kind==="polygon"||H.kind==="facePatch"?(rr=H.faces)==null?void 0:rr[K.faceId]:void 0;return!!(zn!=null&&zn.texture||zn!=null&&zn.color)})(),Q=er(I),dt=Q?je.current.find(zn=>zn.id===Q&&zn.kind==="polygon")??null:null,jt=(()=>{if(!H)return null;const zn=H.groupId;if(zn)return zn;if(H.kind==="facePatch"||H.kind==="faceSplit"||H.kind==="faceCornerArc"){const Eo=je.current.find(rr=>rr.id===H.hostEntityId);return(Eo==null?void 0:Eo.groupId)??null}return null})(),Yt=(()=>{if(!jt)return!1;let zn=0;for(const Eo of je.current)if(Eo.groupId===jt&&(zn+=1,Eo.kind==="facePatch"))return!0;return zn>=2})(),Ut=jt&&o.some(zn=>zn.id===jt)?jt:null,Jt=Ut?{groupId:Ut,entityId:I,faceId:co.faceId??null}:null,we=!!Ut&&!!H&&(H.kind==="polygon"||H.kind==="facePatch"),Mn=!!dt&&dt.sourceTool==="rectangle"&&G.length>0&&!!Xr(dt.vertices),tn=!!dt&&!!av(dt,"right",G),fn=(H==null?void 0:H.kind)!=="faceMeasure"&&(H==null?void 0:H.kind)!=="measure",Rs=(zn,Eo,rr)=>{je.current=zn.entities,ne.current(zn.entities);const Li=(Eo&&rr?zn.createdIds.find(gl=>{const ql=zn.entities.find(Hr=>
246Hr.id===gl&&Hr.kind==="polygon");return!!ql&&ql.sourceTool===Eo.sourceTool&&ql.vertices.length===Eo.vertices.length&&ql.vertices.every((Hr,$e)=>{const bl=Eo.vertices[$e];return!!bl&&Hr.x===bl.x+rr.x&&Hr.y===bl.y+rr.y})})??null:null)??zn.createdIds[0]??null;if(Li){const gl=zn.entities.find(ql=>ql.id===Li);Re.current(Li),h==null||h((gl==null?void 0:gl.kind)==="polygon"?"top":null),x==null||x(null),en(null)}ze(null)},hn=()=>{const zn=Q??I,Eo=x2(je.current,[zn],{x:SR,y:0},{newGroupId:!0});Rs(Eo)},_o=zn=>{if(!Q)return;const Eo=je.current.find(Li=>Li.id===Q&&Li.kind==="polygon")??null;if(!Eo)return;const rr=av(Eo,zn,G);if(!rr)return;const Sa=x2(je.current,[Eo.id],rr,{newGroupId:!0});Rs(Sa,Eo,rr)},ys=()=>{jt&&(Lr(jt),ze(null))},io=()=>{we&&(Vn(),x==null||x(null),ze(null),Dn.current("pushPull"))};Rt==null||Rt({x:co.x,y:co.y,canMove:!!Q,moveLabel:Ut?"הזז תבנית":"הזז אלמנט",moveTarget:Ut?"template":"element",canSnapToWall:Mn,canDuplicateAdjacent:tn,canDuplicate:fn,claddingTarget:K,templateEditTarget:Jt,canPushPull:we,hasCladding:nt,onPushPull:io,onMove:()=>{Q&&dr(Q)},onSnapToWall:()=>{Q&&Mn&&Ii(Q)},onDuplicateRight:()=>_o("left"),onDuplicateLeft:()=>_o("right"),onDuplicate:hn,canMirror:Yt,onMirror:()=>{if(!jt)return;const zn=OW(je.current,jt);je.current=zn,ne.current(zn),ze(null)},canRotate:Yt,onRotateStep:ys,onRotate90:ys,onDelete:()=>Or(I,{whole:!0}),onClose:()=>ze(null)})},[co,er,G,dr,Ii,Vn,Or,o,r,Rt,h,x]),m.useEffect(()=>()=>Rt==null?void 0:Rt(null),[Rt]);const qd=pg(e);return n.jsxs("group",{ref:Ht,children:[ft&&n.jsx($R,{bounds:t}),Nv(e)&&U?n.jsx(WR,{point:U.point,kind:U.kind}):null,Nt?n.jsx(RR,{snap:Nt}):null,vt.map(I=>{if(I.kind==="segment")return n.jsx(QR,{entity:I,selected:I.id===i,selectionVisualDepthMode:a,measurementUnit:tt,onPointerDown:dt=>gc(I,dt),onContextMenu:dt=>Dr(I,dt),onEndpointPointerDown:(dt,jt)=>Fn(I.id,dt,jt)},I.id);if(I.kind==="measure")return n.jsx(eO,{entity:I,selected:I.id===i,measurementUnit:tt,onPointerDown:dt=>gc(I,dt),onContextMenu:dt=>Dr(I,dt),onLabelContextMenu:dt=>{dt.preventDefault(),dt.stopPropagation(),fs(I,dt.clientX,dt.clientY)}},I.id);if(I.kind==="faceSplit"||I.kind==="faceCornerArc")return null;if(I.kind==="faceMeasure"){const dt=_s(I,vt);return dt?n.jsx(UR,{entity:I,frame:dt,selected:I.id===i,measurementUnit:tt,pointerInteractive:Rl(e),onEditFocusRequest:C,onPointerDown:jt=>gc(I,jt,I.hostFaceId),onContextMenu:jt=>Dr(I,jt,I.hostFaceId)},I.id):null}if(I.kind==="facePatch"){if(I.hostFaceId==="front"){const jt=vt.find(Jt=>Jt.id===I.hostEntityId&&Jt.kind==="facePatch"),Yt=jt?vt.find(Jt=>Jt.id===jt.hostEntityId&&Jt.kind==="polygon"):void 0,Ut=jt&&Yt?Zh(jt,Yt):null;return!Yt||!Ut?null:n.jsx(Sv,{entity:I,host:Yt,frameOverride:Ut,selected:I.id===i,selectedFaceId:I.id===i?l:null,selectionVisualDepthMode:a,hostWallAnchored:Gy(Yt,o),onPointerDown:(Jt,we)=>gc(I,Jt,we),onContextMenu:(Jt,we)=>Dr(I,Jt,we)},I.id)}const dt=vt.find(jt=>jt.id===I.hostEntityId&&jt.kind==="polygon");return dt?n.jsx(Sv,{entity:I,host:dt,selected:I.id===i,selectedFaceId:I.id===i?l:null,selectionVisualDepthMode:a,hostWallAnchored:Gy(dt,o),onPointerDown:(jt,Yt)=>gc(I,jt,Yt),onContextMenu:(jt,Yt)=>Dr(I,jt,Yt)},I.id):null}const H=Mi.get(I.id),K=(H==null?void 0:H.patches)??gR,nt=(H==null?void 0:H.splits)??bR,Q=(H==null?void 0:H.arcs)??MR;return n.jsx(YO,{entity:I,selected:I.id===i,selectedEntityId:i,selectedFaceId:I.id===i?l:null,selectedRectangleEdgeIndex:I.id===i?c:null,selectedHostFaceRegion:I.id===i?Ve:null,selectionVisualDepthMode:a,facePatches:K,faceSplits:nt,faceCornerArcs:Q,faceDrawActive:Kd&&(e==="faceMeasure"||!Je||Je.id===I.id),furnitureGroups:o,onPointerDown:(dt,jt)=>gc(I,dt,jt),onContextMenu:(dt,jt)=>Dr(I,dt,jt),onRectangleEdgePointerDown:Wo?void 0:(dt,jt)=>qi(I,dt,jt),onPointerMove:(dt,jt)=>Er(I,dt,jt),onCornerArcPointerDown:(dt,jt)=>gc(dt,jt,"side"),onFaceRegionPointerDown:(dt,jt)=>jm(I,dt,jt),onRectangleHandlePointerDown:!Wo&&Rl(e)&&!Ye.has(I.id)?(dt,jt)=>_n(I.id,dt,jt):void 0},I.id)}),Ws.length>0&&n.jsx(Jn,{raycast:Ss,points:Ws.map(I=>{const H=Ar(I);return[H.x,XD,H.z]}),color:"#3F3A34",lineWidth:1.05}),oe&&pe&&n.jsx(YR,{draft:oe,hover:pe}),Fe&&n.jsx(GR,{tape:Fe,measurementUnit:tt}),Zo&&n.jsx(tO,{preview:Zo,measurementUnit:tt}),qd&&!oe&&pe&&Qt&&(e==="faceLine"||e==="faceCornerArc"?n.jsx(Zy,{frame:Qt,hit:pe}):n.jsx(YD,{frame:Qt,hit:pe,showLabel:!1}
246)),(ut==null?void 0:ut.tool)==="polygon"&&ut.points.map((I,H)=>n.jsx(XR,{point:I,closeTarget:H===0&&ut.points.length>=3,activeCloseTarget:H===0&&bi},`${H}-${I.x}-${I.y}`)),Xt&&Xt.length>=3&&n.jsx(Jn,{raycast:Ss,points:[...Xt,Xt[0]].map(I=>{const H=Ar(I);return[H.x,.095,H.z]}),color:"#D9603B",lineWidth:2.2,transparent:!0,opacity:.95}),lt&&Ee&&lt.length>=3&&n.jsx(Jn,{raycast:Ss,points:[...lt,lt[0]].map(I=>{const H=Ln(Ee,I,wR);return[H.x,H.y,H.z]}),color:"#D9603B",lineWidth:2.2,transparent:!0,opacity:.95}),gn&&gn.lengthMm>=20&&n.jsx(Xp,{position:P3(gn.start,gn.end,.1,.16),label:$i(gn.lengthMm,tt)}),e==="offset"&&Je&&fe&&In!==null&&n.jsx(Uu,{fullscreen:!0,zIndexRange:[70,0],children:n.jsx("div",{className:"pointer-events-none fixed z-[70] select-none rounded-md border border-black/10 bg-[#F7F4EF]/95 px-2 py-1 font-heebo text-[11px] font-bold tabular-nums text-[#182137] shadow-[0_8px_24px_rgba(24,33,55,0.14)]",dir:"rtl",style:{left:fe.x+24,top:fe.y-24},children:$i(In,tt)})}),Ue&&!Ue.groupId&&n.jsx(KO,{center:Ue.center,radiusMm:900}),e!=="rotate"&&(()=>{var tn;const I=i?vt.find(fn=>fn.id===i):null;if(!I)return null;const H=I.groupId??(I.kind==="facePatch"||I.kind==="faceSplit"||I.kind==="faceCornerArc"?(tn=vt.find(fn=>fn.id===I.hostEntityId))==null?void 0:tn.groupId:void 0);if(!H||Ue&&Ue.groupId!==H)return null;const K=!!Ue&&Ue.groupId===H;if(!K&&Qn!==H)return null;const nt=vt.filter(fn=>fn.groupId===H);if(nt.length===0)return null;const Q=nt.filter(fn=>fn.kind==="polygon").map(fn=>fn.id),dt=Q.length>0?Q:nt.map(fn=>fn.id),jt=em(vt,dt);if(!jt)return null;let Yt=0,Ut=0;for(const fn of nt)if(fn.kind==="polygon"){Ut=Math.max(Ut,(fn.baseHeightMm??0)+(fn.heightMm??0));for(const Rs of fn.vertices){const hn=Rs.x-jt.x,_o=Rs.y-jt.y,ys=Math.sqrt(hn*hn+_o*_o);ys>Yt&&(Yt=ys)}}const Jt=Math.max(Yt+LR,850),we=Math.max(Ut+PR,AR),Mn=o.find(fn=>fn.id===H);return n.jsx(ZO,{center:jt,radiusMm:Jt,heightMm:we,rotationDeg:Yu((Mn==null?void 0:Mn.rotationDeg)??0),active:K,onPointerDown:fn=>re(H,fn)})})(),e&&e!=="select"&&e!=="rotate"&&!fa&&n.jsxs("mesh",{position:[t.centerX,qx,t.centerZ],rotation:[-Math.PI/2,0,0],onPointerDown:hr,onPointerMove:_r,onPointerUp:Ta,onDoubleClick:ss,children:[n.jsx("planeGeometry",{args:[yr,yr]}),n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthWrite:!1})]}),uo!==null&&n.jsxs("mesh",{position:[t.centerX,qx-.001,t.centerZ],rotation:[-Math.PI/2,0,0],renderOrder:1,onPointerDown:Ke,children:[n.jsx("planeGeometry",{args:[yr,yr]}),n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthWrite:!1})]})]})}function $R({bounds:t}){const e=Math.max(t.span*20,40),s=xE;return n.jsxs("group",{renderOrder:3,children:[n.jsx(Jn,{points:[[-e,s,0],[0,s,0]],color:"#dc2626",lineWidth:1.5,dashed:!0,dashScale:50}),n.jsx(Jn,{points:[[0,s,0],[e,s,0]],color:"#dc2626",lineWidth:1.5}),n.jsx(Jn,{points:[[0,s,-e],[0,s,0]],color:"#16a34a",lineWidth:1.5,dashed:!0,dashScale:50}),n.jsx(Jn,{points:[[0,s,0],[0,s,e]],color:"#16a34a",lineWidth:1.5}),n.jsx(Jn,{points:[[0,-e,0],[0,0,0]],color:"#2563eb",lineWidth:1.5,dashed:!0,dashScale:50}),n.jsx(Jn,{points:[[0,0,0],[0,e,0]],color:"#2563eb",lineWidth:1.5})]})}function XR({point:t,closeTarget:e,activeCloseTarget:s}){const o=Ar(t);return n.jsxs("group",{position:[o.x,.105,o.z],children:[n.jsxs("mesh",{raycast:Ss,children:[n.jsx("sphereGeometry",{args:[s?.07:e?.055:.04,18,14]}),n.jsx("meshBasicMaterial",{color:s?"#D9603B":"#3F3A34",depthTest:!1})]}),n.jsxs("mesh",{raycast:Ss,children:[n.jsx("sphereGeometry",{args:[s?.038:.024,18,14]}),n.jsx("meshBasicMaterial",{color:"#F7F4EF",depthTest:!1})]})]})}function YR({draft:t,hover:e}){if(t.tool==="faceCornerArc"){const r=n1(t.frame,t.corner,t.firstEdge,t.start),i=r===null?[]:x3(t.frame,t.corner,r),a=r!==null&&i.length>=2,l=i.map(c=>{const d=Ln(t.frame,c,4);return[d.x,d.y,d.z]});return n.jsxs(n.Fragment,{children:[a&&l.length>=2&&n.jsx(Jn,{raycast:Ss,points:l,color:Ni,lineWidth:1.15,transparent:!0,opacity:.9}),!a&&n.jsx(Jn,{raycast:Ss,points:[t.start,e.point].map(c=>{const d=Ln(t.frame,c,4);return[d.x,d.y,d.z]}),color:"#64748b",lineWidth:1.1,transparent:!0,opacity:.85}),n.jsx(Zy,{frame:t.frame,hit:e})]})}const s=t.tool==="faceLine"?qR(t.frame,t.start,e):null,o=t.tool==="faceLine"?[t.start,e.point]:(()=>{const r=Hp(t.start,e.point);return[...r,r[0]]})();return n.jsxs(n.Fragment,{children:[s&&n.jsx(Jn,{raycast:Ss,points:s.map(r=>{const i=Ln(t.frame,r,3.5);return[i.x,i.y,i.z]}),color:"#38BDF8",lineWidth:1.2,transparent:!0,opacity:.55}),n.jsx(Jn,{raycast:Ss,points:o.map(r=>{const i=Ln(t.frame,r,4);return[i.x,i.y,i.z]}),color:Ni,lineWidth:1.15,transparent:!0,opacity:.9}),t.tool==="faceLine"?n.jsx(Zy,{frame:t.frame,hit:e}):n.jsx(YD,{frame:t.frame,hit:e,showLabel:!1})]})}function GR({tape:t}){return n.jsxs(n.Fragment,{children:[n.jsx(Jn,{raycast:Ss,points:[t.start.point,t.hover.point].map(e=>{const s=Ln(t.frame,e,zD);return[s.x,s.y,s.z]}),color:Ni,lineWidth:1.1,transparent:!0,opacity:.92,depthTest:!1}),n.jsx(Ky,{frame:t.frame,point:t.start.point,color:Ni,depthMm:ip}),n.jsx(Ky,{frame:t.frame,point:t.hover.point,color:Ni,depthMm:ip})]})}function UR({entity:t,frame:e,selected:s,measurementUnit:o,pointerInteractive:r,onEditFocusRequest:i,onPointerDown:a,onContextMenu:l}){const[c,d]=m.useState(!1),u=s||c,h=Nn(t.start2D,t.end2D),x=KR(e,t.start2D,t.end2D,ip+16,$D),f=ZR(t.start2D,t.end2D),p=Ln(e,t.end2D,ip);return n.jsxs("group",{children:[u&&n.jsxs(n.Fragment,{children:[n.jsx(Jn,{raycast:Ss,points:[t.start2D,t.end2D].map(b=>{const M=Ln(e,b,zD);return[M.x,M.y,M.z]}),color:s?Ni:"#64748b",lineWidth:1.05,transparent:!0,opacity:s?.8:.48,depthTest:!1}),n.jsx(Xp,{position:x,label:$i(h,o),compact:!0,screenOffset:f})]}),n.jsx(Ky,{frame:e,point:t.end2D,color:s?Ni:"#111111",depthMm:ip}),r&&n.jsxs("mesh",{position:[p.x,p.y,p.z],onPointerDown:b=>{i==null||i(),a(b)},onContextMenu:l,onPointerOver:b=>{b.stopPropagation(),d(!0)},onPointerOut:()=>d(!1),renderOrder:70,children:[n.jsx("sphereGeometry",{args:[ER,20,14]}),n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthTest:!1,depthWrite:!1})]})]})}function Ky({frame:t,point:e,color:s,depthMm:o}){const r=Ln(t,e,o),i=m.useMemo(()=>new Bw().setFromUnitVectors(new le(0,0,1),t.normalLocal.clone().normalize()),[t.normalLocal]);return n.jsxs("group",{position:[r.x,r.y,r.z],renderOrder:68,children:[n.jsxs("mesh",{quaternion:i,raycast:Ss,children:[n.jsx("ringGeometry",{args:[CR,FR,44]}),n.jsx("meshBasicMaterial",{color:s,side:kn,depthTest:!1,depthWrite:!1})]}),n.jsxs("mesh",{raycast:Ss,children:[n.jsx("sphereGeometry",{args:[.012,12,8]}),n.jsx("meshBasicMaterial",{color:s,depthTest:!1,depthWrite:!1})]})]})}function KR(t,e,s,o,r=$D){const i=s.x-e.x,a=s.y-e.y,l=Math.hypot(i,a),c=l<.001?e.x:(e.x+s.x)/2,d=l<.001?e.y:(e.y+s.y)/2;let u=r,h=0;l>=.001&&(u=-a/l*r,h=i/l*r);const x=Ln(t,{x:c+u,y:d+h},o);return[x.x,x.y,x.z]}
246function ZR(t,e){const s=e.x-t.x,o=e.y-t.y;return Math.abs(o)>=Math.abs(s)?{x:72,y:-8}:{x:8,y:-28}}function qR(t,e,s){if(s.kind!=="axis")return null;const o=s.axis??(Math.abs(s.point.y-e.y)<=1?"x":Math.abs(s.point.x-e.x)<=1?"y":null);return o==="x"?[{x:0,y:e.y},{x:t.widthMm,y:e.y}]:o==="y"?[{x:e.x,y:0},{x:e.x,y:t.heightMm}]:null}function Zy({frame:t,hit:e}){const s=Ln(t,e.point,jR),o=JR();return n.jsxs("group",{position:[s.x,s.y,s.z],renderOrder:_R,children:[n.jsxs("mesh",{raycast:Ss,children:[n.jsx("sphereGeometry",{args:[.042,18,14]}),n.jsx("meshBasicMaterial",{color:"#111111",transparent:e.kind==="on-edge",opacity:e.kind==="on-edge"?.42:1,depthTest:!1,depthWrite:!1})]}),e.kind==="midpoint"&&n.jsx(Uu,{center:!0,distanceFactor:8,zIndexRange:[45,0],style:{pointerEvents:"none"},children:n.jsx("span",{"data-testid":"face-line-midpoint-label","data-offset-x":o.x,"data-offset-y":o.y,className:"pointer-events-none whitespace-nowrap rounded-[3px] border border-black/10 bg-[#F7F4EF]/95 px-1.5 py-0.5 font-heebo text-[10px] font-bold leading-none text-[#182137] shadow-sm",style:{transform:`translate(${o.x}px, ${o.y}px)`},children:e.labelHebrew})})]})}function JR(){return{x:104,y:-30}}function YD({frame:t,hit:e,showLabel:s=!0}){const o=Ln(t,e.point,6),r=e.kind==="on-edge"?"#111111":e.kind==="endpoint"||e.kind==="midpoint"?"#16A34A":"#111111";return n.jsxs("group",{position:[o.x,o.y,o.z],children:[n.jsxs("mesh",{raycast:Ss,children:[n.jsx("sphereGeometry",{args:[.038,16,12]}),n.jsx("meshBasicMaterial",{color:r,depthTest:!1})]}),n.jsxs("mesh",{raycast:Ss,children:[n.jsx("sphereGeometry",{args:[.022,16,12]}),n.jsx("meshBasicMaterial",{color:"#F7F4EF",depthTest:!1})]}),s&&n.jsx(Uu,{center:!0,distanceFactor:8,zIndexRange:[45,0],children:n.jsx("span",{className:"pointer-events-none translate-x-6 whitespace-nowrap rounded-[3px] border border-black/10 bg-[#F7F4EF]/95 px-1.5 py-0.5 font-heebo text-[10px] font-bold leading-none text-[#182137] shadow-sm",children:e.labelHebrew})})]})}function QR({entity:t,selected:e,selectionVisualDepthMode:s,measurementUnit:o,onPointerDown:r,onContextMenu:i,onEndpointPointerDown:a}){const l=Ar(t.a),c=Ar(t.b),d=rF(l,c,.1,.16),u=Jc(s);return n.jsxs("group",{children:[n.jsx(F3,{a:l,b:c,onPointerDown:r,onContextMenu:i}),n.jsx(Jn,{points:[[l.x,.06,l.z],[c.x,.06,c.z]],color:e?Ni:t.color??ID,lineWidth:e?1.15:1.05,depthTest:e?u:!0,onPointerDown:r,onContextMenu:i}),e&&n.jsxs(n.Fragment,{children:[n.jsx(Tv,{point:l,selectionVisualDepthMode:s,onPointerDown:h=>a("a",h)}),n.jsx(Tv,{point:c,selectionVisualDepthMode:s,onPointerDown:h=>a("b",h)})]}),n.jsx(Xp,{position:d,label:$i(Nn(t.a,t.b),o)})]})}function Y1(t){return IR}function tO({preview:t,measurementUnit:e}){const s=Ar(t.start),o=Ar(t.hover),r=Y1(t.startElevationMm),i=Y1(t.hoverElevationMm),a=P3(t.start,t.hover,(r+i)/2+.026,.12);return n.jsxs("group",{children:[n.jsx(Jn,{raycast:Ss,points:[[s.x,r,s.z],[o.x,i,o.z]],color:Ni,lineWidth:1.2,transparent:!0,opacity:.82,depthTest:!0,dashed:!0,dashSize:.18,gapSize:.08}),n.jsx(Xp,{position:a,label:$i(t.lengthMm,e),compact:!0})]})}function eO({entity:t,selected:e,measurementUnit:s,onPointerDown:o,onContextMenu:r,onLabelContextMenu:i}){const a=Ar(t.start),l=Ar(t.end),c=Y1(t.startElevationMm),d=Y1(t.endElevationMm),u=[(a.x+l.x)/2,(c+d)/2,(a.z+l.z)/2],h=P3(t.start,t.end,(c+d)/2+.026,.12);return n.jsxs("group",{children:[n.jsx(F3,{a,b:l,ay:c,by:d,onPointerDown:o,onContextMenu:r}),n.jsxs("mesh",{position:u,onPointerDown:o,onContextMenu:r,renderOrder:90,children:[n.jsx("sphereGeometry",{args:[.22,18,14]}),n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthTest:!0,depthWrite:!1})]}),n.jsx(Jn,{raycast:Ss,points:[[a.x,c,a.z],[l.x,d,l.z]],color:Ni,lineWidth:e?1.25:1.05,transparent:!0,opacity:e?.88:.62,depthTest:!0,dashed:!0,dashSize:.18,gapSize:.08}),n.jsx(Xp,{position:h,label:$i(Nn(t.start,t.end),s),compact:!0,onDomContextMenu:i})]})}function Tv({point:t,selectionVisualDepthMode:e,onPointerDown:s}){const o=Jc(e);return n.jsxs("group",{position:[t.x,.085,t.z],children:[n.jsxs("mesh",{onPointerDown:s,children:[n.jsx("sphereGeometry",{args:[.06,18,14]}),n.jsx("meshBasicMaterial",{color:Ni,depthTest:o,depthWrite:!1})]}),n.jsxs("mesh",{onPointerDown:s,children:[n.jsx("sphereGeometry",{args:[.038,18,14]}),n.jsx("meshBasicMaterial",{color:TD,depthTest:o,depthWrite:!1})]}),n.jsxs("mesh",{onPointerDown:s,children:[n.jsx("sphereGeometry",{args:[.105,16,12]}),n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthWrite:!1})]})]})}
246function F3({a:t,b:e,y:s=.065,ay:o,by:r,onPointerDown:i,onContextMenu:a}){const l=m.useMemo(()=>{const c=e.x-t.x,d=(r??s)-(o??s),u=e.z-t.z,h=Math.hypot(c,d,u);if(h<.001)return null;const x=new le(c,d,u).normalize(),f=new Bw().setFromUnitVectors(new le(0,1,0),x);return{length:h,midpoint:[(t.x+e.x)/2,((o??s)+(r??s))/2,(t.z+e.z)/2],quaternion:f}},[t.x,t.z,o,e.x,e.z,r,s]);return l?n.jsxs("mesh",{position:l.midpoint,quaternion:l.quaternion,onPointerDown:i,onContextMenu:a,children:[n.jsx("cylinderGeometry",{args:[ev,ev,l.length,12]}),n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthTest:!0,depthWrite:!1})]}):null}const zp="/textures/floors/tiles-white.jpg",C3=`
247void main() {
248  gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
249}
250`,N3=`
251uniform vec3 uFillColor;
252uniform vec3 uDotColor;
253uniform float uSpacingPx;
254uniform float uDotRadiusPx;
255uniform float uFillAlpha;
256uniform float uDotAlpha;
257
258void main() {
259  vec2 cell = mod(gl_FragCoord.xy, vec2(uSpacingPx)) - vec2(uSpacingPx * 0.5);
260  float distanceToDot = length(cell);
261  float dotMask = 1.0 - smoothstep(uDotRadiusPx - 0.25, uDotRadiusPx + 0.75, distanceToDot);
262  vec3 color = mix(uFillColor, uDotColor, dotMask);
263  float alpha = mix(uFillAlpha, uDotAlpha, dotMask);
264  gl_FragColor = vec4(color, alpha);
265}
266`;function GD(t,e,s){const o=Math.round(t.depthMm??0);return(s==null?void 0:s.kind)==="side"&&t.shape==="rectangle"&&!!t.groupId&&t.groupId===e.groupId&&o>.5&&o<=40}function Sv({entity:t,host:e,frameOverride:s,selected:o,selectedFaceId:r,selectionVisualDepthMode:i,hostWallAnchored:a=!1,onPointerDown:l,onContextMenu:c}){var v;const d=m.useMemo(()=>s??An(e,t.hostFaceId),[s,e,t.hostFaceId]),u=Math.round(t.depthMm??0),h=xO(u),x=(((v=t.holes2D)==null?void 0:v.length)??0)>0,f=m.useMemo(()=>d?g3(d,t,{host:e,depthMm:u}):null,[u,t,d,e]),p=m.useMemo(()=>!d||x?null:h==="recess"?bO(d,t.points2D,u,f==null?void 0:f.recessSideWalls):MO(d,t.points2D,u),[u,t.points2D,d,x,h,f==null?void 0:f.recessSideWalls]),b=ZD(u,3),M=m.useMemo(()=>d&&(h==="surface"||x&&Math.abs(u)>.5)?ap(d,t.points2D,b,t.holes2D):null,[u,t.holes2D,t.points2D,d,x,h,b]),g=m.useMemo(()=>d?dO(u).map(C=>ap(d,t.points2D,C,t.holes2D)).filter(C=>C!==null):[],[u,t.holes2D,t.points2D,d]),w=m.useMemo(()=>d&&r?hO(d,t.points2D,r,u,t.holes2D):null,[u,t.holes2D,t.points2D,d,r]),k=i==="scene"&&!o&&GD(t,e,d),_=m.useMemo(()=>d?k?[]:RD({frame:d,points2D:t.points2D,depthMm:u,recessSideWalls:f==null?void 0:f.recessSideWalls,surfaceOffsetMm:3}):[],[u,t.points2D,d,f==null?void 0:f.recessSideWalls,k]);if(!d)return null;const j=(e.baseHeightMm??0)*rt;return n.jsxs("group",{position:[0,j,0],renderOrder:o?8:6,children:[M&&n.jsx(iO,{geometry:M,entity:t,selected:o,onPointerDown:l,onContextMenu:c}),p&&Math.abs(u)>.5&&n.jsx(cO,{geometry:p,entity:t,selected:o,onPointerDown:l,onContextMenu:c}),!a&&g.map((C,N)=>n.jsx("mesh",{geometry:C,renderOrder:9,onPointerDown:P=>l(P,"top"),onContextMenu:P=>c(P,"top"),onClick:P=>P.stopPropagation(),children:n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthWrite:!1,side:cr})},`pick-${N}`)),_.map((C,N)=>n.jsx(Jn,{raycast:Ss,points:C.points,color:o?Ni:Cb,lineWidth:o?1.15:Nb,depthTest:SD({selected:o,selectionVisualDepthMode:i})},`patch-outline-${N}`)),o&&w&&n.jsx(qD,{geometry:w,selectionVisualDepthMode:i}),o&&r&&n.jsx(uO,{frame:d,faceId:r,points2D:t.points2D,depthMm:u,surfaceDepthMm:b,selectionVisualDepthMode:i})]})}function nO(t){const{color:e}=Mm(t,"top"),s=Math.round(t.depthMm??0)<-.5;return ym(e,{side:kn,polygonOffset:!s,polygonOffsetFactor:s?0:-1,polygonOffsetUnits:s?0:-1,depthTest:!0,depthWrite:!0})}function oO(t){const e=Math.round(t.depthMm??0)<-.5,s=Xf(t.points2D.length,!1,!1),o=[];for(const r of s){const i=Vp(r,!1,!1),{color:a}=Mm(t,r);o[i]=ym(a,{side:kn,polygonOffset:!e,polygonOffsetFactor:e?0:-1,polygonOffsetUnits:e?0:-1,depthTest:!0,depthWrite:!0})}return o}function I3(t){var o,r,i;const e=Xf(t.points2D.length,!1,!1),s=new Set;for(const a of e){const l=(i=(r=(o=t.faces)==null?void 0:o[a])==null?void 0:r.texture)==null?void 0:i.url;l&&s.add(l)}return Array.from(s)}function UD(t){return I3(t).length>0}function KD(t,e,s,o){var c;const r=Math.round(t.depthMm??0)<-.5,i=(c=t.faces)==null?void 0:c[e],a=i==null?void 0:i.texture;if(a!=null&&a.url&&s[a.url]){const d=[Math.max(.05,a.tileWidthCm/100),Math.max(.05,a.tileHeightCm/100)],u=a.groutWidthMm>0?{widthMm:a.groutWidthMm,color:a.groutColor}:void 0,h=Od(s[a.url],1,1,d,u,o,a.orientation);return _3(h,{side:kn,polygonOffset:!r,polygonOffsetFactor:r?0:-1,polygonOffsetUnits:r?0:-1})}const{color:l}=Mm(t,e);return ym(l,{side:kn,polygonOffset:!r,polygonOffsetFactor:r?0:-1,polygonOffsetUnits:r?0:-1,depthTest:!0,depthWrite:!0})}function sO({entity:t,geometry:e,selected:s,onPointerDown:o,onContextMenu:r}){const i=m.useMemo(()=>nO(t),[t]);return n.jsx("mesh",{geometry:e,material:i,renderOrder:s?8:6,onPointerDown:a=>o(a,"top"),onContextMenu:a=>r(a,"top"),onClick:a=>a.stopPropagation()})}function rO({entity:t,geometry:e,selected:s,onPointerDown:o,onContextMenu:r}){const{gl:i}=Vo(),a=m.useMemo(()=>I3(t),[t]),l=m.useMemo(()=>a.length?a:[zp],[a]),c=Ya(l),d=m.useMemo(()=>{const h=Array.isArray(c)?c:[c],x={};return l.forEach((f,p)=>
266{x[f]=h[p]}),x},[c,l]),u=m.useMemo(()=>KD(t,"top",d,i),[t,i,d]);return n.jsx("mesh",{geometry:e,material:u,renderOrder:s?8:6,onPointerDown:h=>o(h,"top"),onContextMenu:h=>r(h,"top"),onClick:h=>h.stopPropagation()})}function iO(t){const e=n.jsx(sO,{...t});return UD(t.entity)?n.jsx($p,{fallback:e,children:n.jsx(m.Suspense,{fallback:e,children:n.jsx(rO,{...t})})}):e}function aO({entity:t,geometry:e,selected:s,onPointerDown:o,onContextMenu:r}){const i=m.useMemo(()=>oO(t),[t]);return n.jsx("mesh",{geometry:e,material:i,renderOrder:s?8:6,onPointerDown:a=>{var c;const l=((c=a.face)==null?void 0:c.materialIndex)??1;o(a,G1(l,t.points2D.length))},onContextMenu:a=>{var c;const l=((c=a.face)==null?void 0:c.materialIndex)??1;r(a,G1(l,t.points2D.length))},onClick:a=>a.stopPropagation()})}function lO({entity:t,geometry:e,selected:s,onPointerDown:o,onContextMenu:r}){const{gl:i}=Vo(),a=m.useMemo(()=>Xf(t.points2D.length,!1,!1),[t.points2D.length]),l=m.useMemo(()=>I3(t),[t]),c=m.useMemo(()=>l.length?l:[zp],[l]),d=Ya(c),u=m.useMemo(()=>{const x=Array.isArray(d)?d:[d],f={};return c.forEach((p,b)=>{f[p]=x[b]}),f},[d,c]),h=m.useMemo(()=>{const x=[];for(const f of a){const p=Vp(f,!1,!1);x[p]=KD(t,f,u,i)}return x},[t,a,i,u]);return n.jsx("mesh",{geometry:e,material:h,renderOrder:s?8:6,onPointerDown:x=>{var p;const f=((p=x.face)==null?void 0:p.materialIndex)??1;o(x,G1(f,t.points2D.length))},onContextMenu:x=>{var p;const f=((p=x.face)==null?void 0:p.materialIndex)??1;r(x,G1(f,t.points2D.length))},onClick:x=>x.stopPropagation()})}function cO(t){const e=n.jsx(aO,{...t});return UD(t.entity)?n.jsx($p,{fallback:e,children:n.jsx(m.Suspense,{fallback:e,children:n.jsx(lO,{...t})})}):e}function ZD(t,e=2){return t>.5?t+e:t<-.5?t-e:e}function dO(t){const e=t>=-.5?t+2:2,s=t<=.5?t-2:-2;return Array.from(new Set([e,s]))}function qD({geometry:t,selectionVisualDepthMode:e}){const s=Jc(e),o=m.useMemo(()=>({uFillColor:{value:new Do(v3)},uDotColor:{value:new Do(j3)},uSpacingPx:{value:16},uDotRadiusPx:{value:.75},uFillAlpha:{value:.08},uDotAlpha:{value:.24}}),[]);return n.jsx("mesh",{geometry:t,renderOrder:11,raycast:()=>null,children:n.jsx("shaderMaterial",{vertexShader:C3,fragmentShader:N3,transparent:!0,depthWrite:!1,depthTest:s,polygonOffset:!0,polygonOffsetFactor:-4,polygonOffsetUnits:-4,side:kn,uniforms:o})})}function uO({frame:t,faceId:e,points2D:s,depthMm:o,surfaceDepthMm:r,selectionVisualDepthMode:i}){const a=Jc(i),l=m.useMemo(()=>{const c=Wf(s,t);if(c.length<3)return[];if(e==="top"||e==="bottom"){const f=c.map((b,M)=>{const g=c[(M+1)%c.length];return{x:(b.x+g.x)/2,y:(b.y+g.y)/2}}),p=e==="top"?r+1:o<-.5?-5:-1;return[...c.map(b=>({point:b,corner:!0})),...f.map(b=>({point:b,corner:!1}))].map(b=>({point:Ln(t,b.point,p),corner:b.corner}))}const d=Number(e.slice(5));if(!Number.isInteger(d)||d<0||d>=c.length||Math.abs(o)<=.5)return[];const u=c[d],h=c[(d+1)%c.length];return[{point:u,depth:0,corner:!0},{point:h,depth:0,corner:!0},{point:h,depth:o,corner:!0},{point:u,depth:o,corner:!0},{point:{x:(u.x+h.x)/2,y:(u.y+h.y)/2},depth:0,corner:!1},{point:{x:(u.x+h.x)/2,y:(u.y+h.y)/2},depth:o,corner:!1},{point:u,depth:o/2,corner:!1},{point:h,depth:o/2,corner:!1}].map(f=>({point:Ln(t,f.point,f.depth+(o>=0?1:-1)),corner:f.corner}))},[o,e,t,s,r]);return l.length?n.jsx("group",{renderOrder:12,children:l.map(({point:c,corner:d},u)=>n.jsxs("group",{position:[c.x,c.y,c.z],children:[n.jsxs("mesh",{raycast:Ss,children:[n.jsx("sphereGeometry",{args:[d?.026:.021,14,10]}),n.jsx("meshBasicMaterial",{color:Ni,depthTest:a,depthWrite:!1})]}),n.jsxs("mesh",{raycast:Ss,children:[n.jsx("sphereGeometry",{args:[d?.014:.011,14,10]}),n.jsx("meshBasicMaterial",{color:TD,depthTest:a,depthWrite:!1})]})]},`patch-point-${u}`))}):null}function hO(t,e,s,o,r){if(s==="top")return ap(t,e,ZD(o,4),r);if(s==="bottom")return ap(t,e,o<-.5?-4:0,r);const i=Number(s.slice(5));return Number.isInteger(i)?mO(t,e,i,o):null}function mO(t,e,s,o){const r=Wf(e,t);if(r.length<3||Math.abs(o)<=.5||s<0||s>=r.length)return null;const i=r[s],a=r[(s+1)%r.length],l=[],c=[],d=Nn(i,a)*rt,u=(x,f,p)=>{const b=Ln(t,x,f);l.push(b.x,b.y,b.z),c.push(p,Math.abs(f)*rt)};u(i,0,0),u(a,0,d),u(a,o,d),u(i,0,0),u(a,o,d),u(i,o,0);const h=new Ua;return h.setAttribute("position",new Ur(l,3)),h.setAttribute("uv",new Ur(c,2)),h.computeVertexNormals(),h.computeBoundingBox(),h.computeBoundingSphere(),h}function ap(t,e,s,o){const r=Wf(e,t);if(r.length<3)return null;const i=(o??[]).map(f=>Wf(f,t)).filter(f=>f.length>=3),a=r.map(f=>new Po(f.x,f.y)),l=i.map(f=>f.map(p=>new Po(p.x,p.y))),c=hb.triangulateShape(a,l);if(!c.length)return null;const d=[...r];for(const f of i)d.push(...f);const u=[],h=[];for(const f of c)for(const p of f){const b=d[p],M=Ln(t,b,s);u.push(M.x,M.y,M.z),h.push(b.x*rt,b.y*rt)}const x=new Ua;return x.setAttribute("position",new Ur(u,3)),x.setAttribute("uv",new Ur(h,2)),x.computeVertexNormals(),x.computeBoundingBox(),x.computeBoundingSphere(),x}function fO(t){return t>.5}function xO(t){return t<-.5?"recess":t>.5?"extrusion":"surface"}function pO(t){return t.reduce((e,s)=>({minX:Math.min(e.minX,s.x),minY:Math.min(e.minY,s.y),maxX:Math.max(e.maxX,s.x),maxY:Math.max(e.maxY,s.y)}),{minX:Number.POSITIVE_INFINITY,minY:Number.POSITIVE_INFINITY,maxX:Number.NEGATIVE_INFINITY,maxY:Number.NEGATIVE_INFINITY})}function gO(t,e,s,o=1){return Math.abs(t.x-s.minX)<=o&&Math.abs(e.x-s.minX)<=o?"minX":Math.abs(t.x-s.maxX)<=o&&Math.abs(e.x-s.maxX)<=o?"maxX":Math.abs(t.y-s.minY)<=o&&Math.abs(e.y-s.minY)<=o?"minY":Math.abs(t.y-s.maxY)<=o&&Math.abs(e.y-s.maxY)<=o?"maxY":null}function bO(t,e,s,o=["minX","maxX","minY","maxY"]){const r=Wf(e,t);if(r.length<3||s>=-.5)return null;const i=hb.triangulateShape(r.map(M=>new Po(M.x,M.y)),[]);if(!i.length)return null;const a=s+vR,l=[],c=[],d=[],u=pO(r),h=new Set(o),x=(M,g)=>{const w=Ln(t,M,g);l.push(w.x,w.y,w.z),c.push(M.x*rt,M.y*rt)},f=(M,g,w)=>{const k=Ln(t,M,g);l.push(k.x,k.y,k.z),c.push(w,Math.abs(g)*rt)};for(const M of i){const[g,w,k]=M.map(_=>r[_]);x(g,a),x(w,a),x(k,a),d.push(1)}for(let M=0;M<r.length;M++){const g=r[M],w=r[(M+1)%r.length],k=gO(g,w,u);if(k&&!h.has(k))continue;const _=2+M,j=Nn(g,w)*rt;f(g,0,0),f(w,a,j),f(w,0,j),d.push(_),f(g,0,0),f(g,a,0),f(w,a,j),d.push(_)}const p=new Ua;p.setAttribute("position",new Ur(l,3)),p.setAttribute("uv",new Ur(c,2));let b=0;for(;b<d.length;){const M=d[b];let g=b+1;for(;g<d.length&&d[g]===M;)g++;p.addGroup(b*3,(g-b)*3,M),b=g}return p.computeVertexNormals(),p.computeBoundingBox(),p.computeBoundingSphere(),p}function MO(t,e,s){const o=Wf(e,t);if(o.length<3||Math.abs(s)<=.5)return null;const r=hb.triangulateShape(o.map(f=>new Po(f.x,f.y)),[]);if(!r.length)return null;const i=[],a=[],l=[],c=(f,p)=>{const b=Ln(t,f,p);i.push(b.x,b.y,b.z),a.push(f.x*rt,f.y*rt)},d=(f,p,b)=>{const M=Ln(t,f,p);i.push(M.x,M.y,M.z),a.push(b,Math.abs(p)*rt)},u=(f,p,b,M,g)=>{c(f,M),c(p,M),c(b,M),l.push(g)};for(const f of r){const[p,b,M]=f.map(g=>o[g]);fO(s)&&u(M,b,p,0,0),u(p,b,M,s,1)}for(let f=0;f<o.length;f++){const p=o[f],b=o[(f+1)%o.length],M=2+f,g=Nn(p,b)*rt;
266d(p,0,0),d(b,0,g),d(b,s,g),l.push(M),d(p,0,0),d(b,s,g),d(p,s,0),l.push(M)}const h=new Ua;h.setAttribute("position",new Ur(i,3)),h.setAttribute("uv",new Ur(a,2));let x=0;for(;x<l.length;){const f=l[x];let p=x+1;for(;p<l.length&&l[p]===f;)p++;h.addGroup(x*3,(p-x)*3,f),x=p}return h.computeVertexNormals(),h.computeBoundingBox(),h.computeBoundingSphere(),h}function G1(t,e){return t===0?"bottom":t===1?"top":`side-${Math.max(0,Math.min(e-1,t-2))}`}function Wf(t,e){const s=[];for(const o of t){const r=ko(e,o),i=s[s.length-1];i&&Nn(i,r)<1||s.push(r)}return s.length>2&&Nn(s[0],s[s.length-1])<1&&s.pop(),Xi(s)?s:[]}function yO({geometry:t,faceId:e,vertexCount:s,isCircle:o,isFlat:r,heightMm:i,selectionVisualDepthMode:a}){const l=Jc(a),c=m.useMemo(()=>$W(t,e,s,o,r),[t,e,s,o,r]),d=TR,u=m.useMemo(()=>({uFillColor:{value:new Do(v3)},uDotColor:{value:new Do(j3)},uSpacingPx:{value:10},uDotRadiusPx:{value:1.5},uFillAlpha:{value:.35},uDotAlpha:{value:.95}}),[]);return c?n.jsx("mesh",{geometry:c,rotation:[-Math.PI/2,0,0],position:[0,d,0],renderOrder:3,raycast:()=>null,children:n.jsx("shaderMaterial",{vertexShader:C3,fragmentShader:N3,transparent:!0,depthWrite:!1,depthTest:l,polygonOffset:!0,polygonOffsetFactor:-4,polygonOffsetUnits:-4,side:kn,uniforms:u})}):null}function wO(t,e){e?(t.transparent=!1,t.opacity=1,t.side=kn,t.polygonOffset=!0,t.polygonOffsetFactor=-1):t.side=cr}function JD(){return new Jg({color:"#ffffff",transparent:!0,opacity:0,depthWrite:!1,side:cr})}function kO(t,e,s,o,r){const i=[];for(const a of e){const l=Vp(a,s,o);if(r!=null&&r.has(a)){i[l]=JD();continue}const{color:c}=Mm(t,a),d=ym(c,{isFlat:o});i[l]=d}return i}function QD(t,e,s,o,r){if(!(e!=null&&e.size))return;const i=E1.prototype.raycast;t.raycast=function(l,c){var u;const d=[];i.call(this,l,d);for(const h of d){const x=((u=h.face)==null?void 0:u.materialIndex)??0,f=am(x,s,o,r);e.has(f)||c.push(h)}}}function Pv({entity:t,geometry:e,isCircle:s,isFlat:o,faceIds:r,hiddenFaceIds:i,onPointerDown:a,onContextMenu:l,onPointerMove:c}){const d=m.useMemo(()=>kO(t,r,s,o,i),[t,r,i,s,o]),u=((i==null?void 0:i.size)??0)>0,h=m.useRef(null);return m.useLayoutEffect(()=>{h.current&&QD(h.current,i,t.vertices.length,s,o)},[t.vertices.length,i,s,o]),n.jsx("mesh",{ref:h,geometry:e,material:d,rotation:[-Math.PI/2,0,0],position:[0,_a,0],onPointerDown:x=>{var b;const f=((b=x.face)==null?void 0:b.materialIndex)??0,p=am(f,t.vertices.length,s,o);i!=null&&i.has(p)||a(x,p)},onContextMenu:x=>{var b;const f=((b=x.face)==null?void 0:b.materialIndex)??0,p=am(f,t.vertices.length,s,o);i!=null&&i.has(p)||l(x,p)},onPointerMove:c?x=>{var b;const f=((b=x.face)==null?void 0:b.materialIndex)??0,p=am(f,t.vertices.length,s,o);i!=null&&i.has(p)||c(x,p)}:void 0,onClick:x=>x.stopPropagation(),children:!u&&n.jsx(xo,{scale:1,threshold:15,color:Cb,lineWidth:Nb})})}function vO({entity:t,geometry:e,isCircle:s,isFlat:o,faceIds:r,hiddenFaceIds:i,onPointerDown:a,onContextMenu:l,onPointerMove:c}){const{gl:d}=Vo(),u=m.useMemo(()=>{var w,k,_;const g=new Set;for(const j of r){const v=(_=(k=(w=t.faces)==null?void 0:w[j])==null?void 0:k.texture)==null?void 0:_.url;v&&g.add(v)}return Array.from(g)},[r,t.faces]),h=m.useMemo(()=>u.length?u:[zp],[u]),x=Ya(h),f=m.useMemo(()=>{const g=Array.isArray(x)?x:[x],w={};return h.forEach((k,_)=>{w[k]=g[_]}),w},[x,h]),p=m.useMemo(()=>{var w,k;const g=[];for(const _ of r){const j=Vp(_,s,o);if(i!=null&&i.has(_)){g[j]=JD();continue}const v=(w=t.faces)==null?void 0:w[_],{color:C}=Mm(t,_);let N;const P=(k=v==null?void 0:v.texture)==null?void 0:k.url;if(P&&f[P]){const L=v.texture,A=[Math.max(.05,L.tileWidthCm/100),Math.max(.05,L.tileHeightCm/100)],W=L.groutWidthMm>0?{widthMm:L.groutWidthMm,color:L.groutColor}:void 0;N=Od(f[P],1,1,A,W,d,L.orientation)}else N=ym(C,{isFlat:o});wO(N,o),g[j]=N}return g},[t,r,f,d,i,s,o]),b=((i==null?void 0:i.size)??0)>0,M=m.useRef(null);return m.useLayoutEffect(()=>{M.current&&QD(M.current,i,t.vertices.length,s,o)},[t.vertices.length,i,s,o]),n.jsx("mesh",{ref:M,geometry:e,material:p,rotation:[-Math.PI/2,0,0],position:[0,_a,0],onPointerDown:g=>{var _;const w=((_=g.face)==null?void 0:_.materialIndex)??0,k=am(w,t.vertices.length,s,o);i!=null&&i.has(k)||a(g,k)},onContextMenu:g=>{var _;const w=((_=g.face)==null?void 0:_.materialIndex)??0,k=am(w,t.vertices.length,s,o);i!=null&&i.has(k)||l(g,k)},onPointerMove:c?g=>{var _;const w=((_=g.face)==null?void 0:_.materialIndex)??0,k=am(w,t.vertices.length,s,o);i!=null&&i.has(k)||c(g,k)}:void 0,onClick:g=>g.stopPropagation(),children:!b&&n.jsx(xo,{scale:1,threshold:15,color:Cb,lineWidth:Nb})})}class $p extends m.Component{constructor(){super(...arguments);UM(this,"state",{hasError:!1})}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(s){console.warn("[floorplan-sketch] texture failed:",s)}render(){return this.state.hasError?this.props.fallback:this.props.children}}function jO({entity:t,geometry:e,isCircle:s,isFlat:o,hiddenFaceIds:r,onPointerDown:i,onContextMenu:a,onPointerMove:l}){const c=m.useMemo(()=>Xf(t.vertices.length,s,o),[t.vertices.length,s,o]);if(!m.useMemo(()=>{var h,x;if(!t.faces)return!1;for(const f of c)if((x=(h=t.faces[f])==null?void 0:h.texture)!=null&&x.url)return!0;return!1},[t.faces,c]))return n.jsx(Pv,{entity:t,geometry:e,isCircle:s,isFlat:o,faceIds:c,hiddenFaceIds:r,onPointerDown:i,onContextMenu:a,onPointerMove:l});const u=n.jsx(Pv,{entity:t,geometry:e,isCircle:s,isFlat:o,faceIds:c,hiddenFaceIds:r,onPointerDown:i,onContextMenu:a,onPointerMove:l});return n.jsx($p,{fallback:u,children:n.jsx(m.Suspense,{fallback:u,children:n.jsx(vO,{entity:t,geometry:e,isCircle:s,isFlat:o,faceIds:c,hiddenFaceIds:r,onPointerDown:i,onContextMenu:a,onPointerMove:l})})})}function _O({entity:t,isCircle:e,isFlat:s,excludedFaceIds:o,includeInferenceTargets:r=!0,onPointerDown:i,onContextMenu:a,onPointerMove:l}){const c=m.useMemo(()=>Xf(t.vertices.length,e,s).filter(d=>d!=="bottom"&&!(o!=null&&o.has(d))),[t.vertices.length,o,e,s]);return n.jsxs(n.Fragment,{children:[c.map(d=>n.jsx(EO,{entity:t,faceId:d,onPointerDown:i,onContextMenu:a,onPointerMove:l},`draw-target-${t.id}-${d}`)),r&&c.map(d=>n.jsx(FO,{entity:t,faceId:d,onPointerDown:i,onContextMenu:a,onPointerMove:l},`edge-target-${t.id}-${d}`))]})}function EO({entity:t,faceId:e,onPointerDown:s,onContextMenu:o,onPointerMove:r}){const i=m.useMemo(()=>An(t,e),[t,e]),a=m.useMemo(()=>
266i?DO(i):null,[i]);return a?n.jsx("mesh",{geometry:a,renderOrder:12,onPointerDown:l=>s(l,e),onContextMenu:l=>o(l,e),onPointerMove:r?l=>r(l,e):void 0,onClick:l=>l.stopPropagation(),children:n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthWrite:!1,side:cr})}):null}function DO(t){const e=[{x:0,y:0},{x:t.widthMm,y:0},{x:t.widthMm,y:t.heightMm},{x:0,y:t.heightMm}],s=[0,1,2,0,2,3],o=[];for(const i of s){const a=Ln(t,e[i],6);o.push(a.x,a.y,a.z)}const r=new Ua;return r.setAttribute("position",new Ur(o,3)),r.computeVertexNormals(),r.computeBoundingBox(),r.computeBoundingSphere(),r}function FO({entity:t,faceId:e,onPointerDown:s,onContextMenu:o,onPointerMove:r}){const i=m.useMemo(()=>An(t,e),[t,e]),a=m.useMemo(()=>{if(!i)return null;const c=[{x:0,y:0},{x:i.widthMm,y:0},{x:i.widthMm,y:i.heightMm},{x:0,y:i.heightMm}],d=c.map((h,x)=>{const f=c[(x+1)%c.length];return{x:(h.x+f.x)/2,y:(h.y+f.y)/2}}),u=h=>Ln(i,h,10);return{corners:c.map(u),midpoints:d.map(u),edges:c.map((h,x)=>({a:u(h),b:u(c[(x+1)%c.length])}))}},[i]);if(!i||!a)return null;const l=r?c=>r(c,e):void 0;return n.jsxs("group",{renderOrder:13,children:[a.edges.map((c,d)=>n.jsx(CO,{a:c.a,b:c.b,onPointerDown:u=>s(u,e),onContextMenu:u=>o(u,e),onPointerMove:l},`edge-${d}`)),[...a.corners,...a.midpoints].map((c,d)=>n.jsxs("mesh",{position:[c.x,c.y,c.z],renderOrder:13,onPointerDown:u=>s(u,e),onContextMenu:u=>o(u,e),onPointerMove:l,onClick:u=>u.stopPropagation(),children:[n.jsx("sphereGeometry",{args:[.085,12,10]}),n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthWrite:!1})]},`point-${d}`))]})}function CO({a:t,b:e,onPointerDown:s,onContextMenu:o,onPointerMove:r}){const i=m.useMemo(()=>{const a=e.clone().sub(t),l=a.length();if(l<.001)return null;const c=new Bw().setFromUnitVectors(new le(0,1,0),a.normalize());return{length:l,midpoint:t.clone().add(e).multiplyScalar(.5),quaternion:c}},[t,e]);return i?n.jsxs("mesh",{position:[i.midpoint.x,i.midpoint.y,i.midpoint.z],quaternion:i.quaternion,renderOrder:13,onPointerDown:s,onContextMenu:o,onPointerMove:r,onClick:a=>a.stopPropagation(),children:[n.jsx("cylinderGeometry",{args:[.07,.07,i.length,10]}),n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthWrite:!1})]}):null}function NO({geometry:t,onPointerDown:e,onContextMenu:s}){return n.jsx("mesh",{geometry:t,rotation:[-Math.PI/2,0,0],position:[0,.075,0],renderOrder:4,onPointerDown:o=>e(o,"top"),onContextMenu:o=>s(o,"top"),onClick:o=>o.stopPropagation(),children:n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthWrite:!1,side:kn})})}function IO(t,e){const s=e.points2D.map(h=>ko(t,h));if(s.length<3)return null;const o=(e.holes2D??[]).map(h=>h.map(x=>ko(t,x))).filter(h=>h.length>=3),r=s.map(h=>new Po(h.x,h.y)),i=o.map(h=>h.map(x=>new Po(x.x,x.y))),a=hb.triangulateShape(r,i);if(!a.length)return null;const l=[...s];for(const h of o)l.push(...h);const c=[],d=[];for(const h of a)for(const x of h){const f=l[x],p=Ln(t,f,Ib);c.push(p.x,p.y,p.z),d.push(f.x*rt,f.y*rt)}const u=new Ua;return u.setAttribute("position",new Ur(c,3)),u.setAttribute("uv",new Ur(d,2)),u.computeVertexNormals(),u.computeBoundingBox(),u.computeBoundingSphere(),u}function tF(t,e){const{color:s}=Mm(t,e);return ym(s,{side:kn,polygonOffset:!0,polygonOffsetFactor:-1,polygonOffsetUnits:-1})}function TO({entity:t,region:e,geometry:s,selected:o,onPointerDown:r}){const i=m.useMemo(()=>tF(t,e.hostFaceId),[t,e.hostFaceId]);return n.jsx("mesh",{geometry:s,material:i,renderOrder:o?7:5,onPointerDown:a=>r(e,a),onClick:a=>a.stopPropagation()})}function SO({entity:t,region:e,geometry:s,selected:o,onPointerDown:r}){var u,h;const{gl:i}=Vo(),a=(u=t.faces)==null?void 0:u[e.hostFaceId],l=((h=a==null?void 0:a.texture)==null?void 0:h.url)??zp,c=Ya(l),d=m.useMemo(()=>{const x=a==null?void 0:a.texture;if(!(x!=null&&x.url))return tF(t,e.hostFaceId);const f=[Math.max(.05,x.tileWidthCm/100),Math.max(.05,x.tileHeightCm/100)],p=x.groutWidthMm>0?{widthMm:x.groutWidthMm,color:x.groutColor}:void 0,b=Od(c,1,1,f,p,i,x.orientation);return _3(b,{side:kn,polygonOffset:!0,polygonOffsetFactor:-1,polygonOffsetUnits:-1})},[a==null?void 0:a.texture,t,i,e.hostFaceId,c]);return n.jsx("mesh",{geometry:s,material:d,renderOrder:o?7:5,onPointerDown:x=>r(e,x),onClick:x=>x.stopPropagation()})}function eF({entity:t,frame:e,region:s,selected:o,selectionVisualDepthMode:r,onPointerDown:i}){var h,x,f;const a=Jc(r),l=m.useMemo(()=>IO(e,s),[e,s]),c=m.useMemo(()=>{const p=[];s.points2D.length>=2&&p.push([...s.points2D,s.points2D[0]].map(b=>{const M=Ln(e,b,_p);return[M.x,M.y,M.z]}));for(const b of s.holes2D??[])b.length<2||p.push([...b,b[0]].map(M=>{const g=ko(e,M),w=Ln(e,g,_p);return[w.x,w.y,w.z]}));return p},[e,s.points2D,s.holes2D]),d=!!((f=(x=(h=t.faces)==null?void 0:h[s.hostFaceId])==null?void 0:x.texture)!=null&&f.url);if(!l)return null;const u=n.jsx(TO,{entity:t,region:s,geometry:l,selected:o,onPointerDown:i});return n.jsxs("group",{children:[d?n.jsx($p,{fallback:u,children:n.jsx(m.Suspense,{fallback:u,children:n.jsx(SO,{entity:t,region:s,geometry:l,selected:o,onPointerDown:i})})}):u,o&&n.jsx(qD,{geometry:l,selectionVisualDepthMode:r}),o&&c.map((p,b)=>p.length>1?n.jsx(Jn,{raycast:Ss,points:p,color:Ni,lineWidth:1.15,depthTest:a},`host-region-outline-${b}`):null)]})}function PO({entity:t,facePatches:e,faceSplits:s,faceCornerArcs:o,selectedRegion:r,selectionVisualDepthMode:i,onPointerDown:a}){const l=m.useMemo(()=>Array.from(new Set([...e.map(d=>d.hostFaceId),...s.map(d=>d.hostFaceId),...o.map(d=>d.hostFaceId)])).map(d=>{const u=An(t,d);if(!u)return null;const h=e.filter(M=>M.hostFaceId===d),x=s.filter(M=>M.hostFaceId===d),f=o.filter(M=>M.hostFaceId===d),p=V1(u,h,x,f),b=h.filter(WO);return{faceId:d,frame:u,regions:p,outlineSegments:[...PD(u,p,_p),...uR(u,b,_p),...AD(u,x,X1),...WD(u,f,X1)]}}).filter(d=>d!==null),[t,e,o,s]);return l.length?n.jsxs("group",{children:[l.map(({faceId:c,outlineSegments:d})=>n.jsx(T3,{segments:d},`host-frame-outline-${c}`)),l.map(({frame:c,regions:d})=>d.map(u=>n.jsx(eF,{entity:t,frame:c,region:u,selected:(r==null?void 0:r.regionId)===u.regionId,selectionVisualDepthMode:i,onPointerDown:a},u.regionId)))]}):null}function T3({segments:t,selected:e=!1,selectionVisualDepthMode:s="overlay"}){return n.jsx(n.Fragment,{children:t.map((o,r)=>
266n.jsx(Jn,{raycast:Ss,points:o.points,color:e?Ni:Cb,lineWidth:e?1.15:Nb,depthTest:SD({selected:e,selectionVisualDepthMode:s})},`${o.role}-${o.boundaryEdge??o.vertexIndex??"edge"}-${r}`))})}function AO(t){if(!t.startsWith("side-"))return null;const e=Number(t.slice(5));return Number.isInteger(e)?e:null}function Av(t,e,s){const o=AO(e);if(o===null||t.vertices.length<3)return null;const r=t.vertices.length;return`side-${s==="previous"?(o-1+r)%r:(o+1)%r}`}function Lv(t,e,s,o,r){const i=An(t,s);if(!i||i.kind!=="side")return null;const a=Math.abs(Math.round(e.depthMm??0));if(a<=1)return null;const l=r==="previous"?Math.max(0,Math.round(i.widthMm-a)):0,c=r==="previous"?Math.round(i.widthMm):Math.min(Math.round(i.widthMm),a),d=Math.max(0,Math.min(Math.round(i.heightMm),o.bounds.minY)),u=Math.max(0,Math.min(Math.round(i.heightMm),o.bounds.maxY));return c-l<=1||u-d<=1?null:{id:`${e.id}:adjacent-${s}`,kind:"facePatch",hostEntityId:t.id,hostFaceId:s,shape:"rectangle",points2D:[{x:l,y:d},{x:c,y:d},{x:c,y:u},{x:l,y:u}],depthMm:0,groupId:e.groupId,createdAt:e.createdAt}}function LO(t,e,s){const o=An(t,e.hostFaceId),r=An(t,s.faceId);if(!o||o.kind!=="side"||!r)return null;const i=Math.round(e.depthMm??0);if(i>=-.5)return null;const a=s.faceId==="top"?o.heightMm:0,l=[Bl(r,Ln(o,{x:s.minU,y:a},0)),Bl(r,Ln(o,{x:s.maxU,y:a},0)),Bl(r,Ln(o,{x:s.maxU,y:a},i)),Bl(r,Ln(o,{x:s.minU,y:a},i))],c=Math.min(...l.map(x=>x.x)),d=Math.max(...l.map(x=>x.x)),u=Math.min(...l.map(x=>x.y)),h=Math.max(...l.map(x=>x.y));return d-c<=1||h-u<=1?null:{id:`${e.id}:cap-${s.faceId}`,kind:"facePatch",hostEntityId:t.id,hostFaceId:s.faceId,shape:"rectangle",points2D:_e(c,u,d,h),depthMm:0,groupId:e.groupId,createdAt:e.createdAt}}function WO(t){return t.id.includes(":adjacent-")||t.id.includes(":cap-")}function qy(t,e){const s=[...e];for(const o of e){const r=Math.round(o.depthMm??0);if(r>=-.5)continue;const i=An(t,o.hostFaceId);if(!i||i.kind!=="side")continue;const a=g3(i,o,{host:t,depthMm:r});if(a){if(a.boundary.touchesMinX){const l=Av(t,o.hostFaceId,"previous");if(l){const c=Lv(t,o,l,a,"previous");c&&s.push(c)}}if(a.boundary.touchesMaxX){const l=Av(t,o.hostFaceId,"next");if(l){const c=Lv(t,o,l,a,"next");c&&s.push(c)}}for(const l of a.capCuts){const c=LO(t,o,l);c&&s.push(c)}}}return s}function RO(t,e,s){const o=new Map,r=[],i=1,a=(c,d,u,h,x,f)=>{if(Math.abs(f-x)<=i)return;const p=Math.min(x,f),b=Math.max(x,f),M=Math.round(u),g=Math.round(h),w=`${c.faceId}:${g}:${d}:${M}`,k=o.get(w);if(k){k.intervals.push({start:p,end:b});return}o.set(w,{frame:c,axis:d,constant:M,depthMm:g,intervals:[{start:p,end:b}]})};for(const c of e){if(c.id===s)continue;const d=An(t,c.hostFaceId);if(!d||!GD(c,t,d))continue;const u=Math.round(c.depthMm??0)+kR,h=c.points2D.map(x=>ko(d,x));for(let x=0;x<h.length;x+=1){const f=h[x],p=h[(x+1)%h.length];if(Math.abs(f.x-p.x)<=i){a(d,"x",(f.x+p.x)/2,u,f.y,p.y);continue}if(Math.abs(f.y-p.y)<=i){a(d,"y",(f.y+p.y)/2,u,f.x,p.x);continue}const b=Ln(d,f,u),M=Ln(d,p,u);r.push({role:"front-rim",points:[[b.x,b.y,b.z],[M.x,M.y,M.z]]})}}const l=[];for(const c of o.values()){const d=[];for(const u of c.intervals.sort((h,x)=>h.start-x.start||h.end-x.end)){const h=d[d.length-1];h&&u.start<=h.end+i?h.end=Math.max(h.end,u.end):d.push({...u})}for(const u of d){const h=c.axis==="x"?{x:c.constant,y:u.start}:{x:u.start,y:c.constant},x=c.axis==="x"?{x:c.constant,y:u.end}:{x:u.end,y:c.constant},f=Ln(c.frame,h,c.depthMm),p=Ln(c.frame,x,c.depthMm);l.push({role:"front-rim",points:[[f.x,f.y,f.z],[p.x,p.y,p.z]]})}}return VD([...l,...r])}function OO({host:t,facePatches:e,selectedEntityId:s,selectionVisualDepthMode:o}){const r=m.useMemo(()=>o!=="scene"?[]:RO(t,e,s),[e,t,s,o]);return r.length?n.jsx(T3,{segments:r,selectionVisualDepthMode:o}):null}function HO({entity:t,cornerArcs:e,selectedEntityId:s,selectedFaceId:o,selectionVisualDepthMode:r,onPointerDown:i}){const a=m.useMemo(()=>e.filter(d=>d.verticalThroughCut&&d.hostFaceId==="top"),[e]);if(!a.length)return null;const l=Math.max(0,t.heightMm??0)*rt,c=_a;return n.jsx(n.Fragment,{children:a.map(d=>{const u=An(t,d.hostFaceId);if(!u||u.kind!=="top")return null;const h=Math.round(u.widthMm),x=Math.round(u.heightMm),f=Math.max(20*rt,d.radiusMm*rt),p=XL(d.corner,h,x,d.radiusMm),b=$f(d.corner,h,x),M=Ln(u,p,0),g=Ln(u,b,0),w=ML(M,g);return w===null?null:n.jsx(zO,{host:t,arc:d,radiusM:f,heightM:l,position:[M.x,c+l/2,M.z],rotationY:w,selected:s===d.id&&o==="side",selectionVisualDepthMode:r,onPointerDown:i},d.id)})})}function S3(t,e){var o;const s=(o=e.faces)==null?void 0:o.side;return s!=null&&s.texture||s!=null&&s.color?{color:s.color??Vd,texture:s.texture}:Mm(t,"top")}function nF(t,e){const{color:s}=S3(t,e),o=ym(s,{isFlat:!1});return o.polygonOffset=!0,o.polygonOffsetFactor=1,o.polygonOffsetUnits=1,o}
266function BO({host:t,arc:e,radiusM:s,heightM:o,position:r,rotationY:i,selected:a,selectionVisualDepthMode:l,onPointerDown:c}){const d=m.useMemo(()=>nF(t,e),[t,e]);return n.jsx(oF,{arc:e,radiusM:s,heightM:o,position:r,rotationY:i,material:d,selected:a,selectionVisualDepthMode:l,onPointerDown:c})}function VO({host:t,arc:e,radiusM:s,heightM:o,position:r,rotationY:i,selected:a,selectionVisualDepthMode:l,onPointerDown:c}){var p;const{gl:d}=Vo(),u=S3(t,e),h=((p=u.texture)==null?void 0:p.url)??zp,x=Ya(h),f=m.useMemo(()=>{const b=u.texture;if(!(b!=null&&b.url))return nF(t,e);const M=[Math.max(.05,b.tileWidthCm/100),Math.max(.05,b.tileHeightCm/100)],g=b.groutWidthMm>0?{widthMm:b.groutWidthMm,color:b.groutColor}:void 0,w=Math.max(.001,Math.PI*s/2),k=Od(x,w,Math.max(.001,o),M,g,d,b.orientation);return _3(k,{side:cr,polygonOffset:!0,polygonOffsetFactor:1,polygonOffsetUnits:1})},[e,u.texture,d,o,t,s,x]);return n.jsx(oF,{arc:e,radiusM:s,heightM:o,position:r,rotationY:i,material:f,selected:a,selectionVisualDepthMode:l,onPointerDown:c})}function oF({arc:t,radiusM:e,heightM:s,position:o,rotationY:r,material:i,selected:a,selectionVisualDepthMode:l,onPointerDown:c}){const d=Jc(l),u=m.useMemo(()=>({uFillColor:{value:new Do(v3)},uDotColor:{value:new Do(j3)},uSpacingPx:{value:10},uDotRadiusPx:{value:1.5},uFillAlpha:{value:.35},uDotAlpha:{value:.95}}),[]);return n.jsxs("group",{children:[n.jsxs("mesh",{position:o,rotation:[0,r,0],onPointerDown:h=>c(t,h),onClick:h=>h.stopPropagation(),children:[n.jsx("cylinderGeometry",{args:[e+.025,e+.025,s+.01,24,1,!0,0,Math.PI/2]}),n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthWrite:!1,side:kn})]}),n.jsx("mesh",{material:i,position:o,rotation:[0,r,0],onPointerDown:h=>c(t,h),onClick:h=>h.stopPropagation(),children:n.jsx("cylinderGeometry",{args:[e,e,s,24,1,!0,0,Math.PI/2]})}),a&&n.jsxs("mesh",{position:o,rotation:[0,r,0],renderOrder:12,raycast:()=>null,children:[n.jsx("cylinderGeometry",{args:[e,e,s,24,1,!0,0,Math.PI/2]}),n.jsx("shaderMaterial",{vertexShader:C3,fragmentShader:N3,transparent:!0,depthWrite:!1,depthTest:d,polygonOffset:!0,polygonOffsetFactor:-4,polygonOffsetUnits:-4,side:kn,uniforms:u})]})]})}function zO({host:t,arc:e,radiusM:s,heightM:o,position:r,rotationY:i,selected:a,selectionVisualDepthMode:l,onPointerDown:c}){var h;const d=!!((h=S3(t,e).texture)!=null&&h.url),u=n.jsx(BO,{host:t,arc:e,radiusM:s,heightM:o,position:r,rotationY:i,selected:a,selectionVisualDepthMode:l,onPointerDown:c});return d?n.jsx($p,{fallback:u,children:n.jsx(m.Suspense,{fallback:u,children:n.jsx(VO,{host:t,arc:e,radiusM:s,heightM:o,position:r,rotationY:i,selected:a,selectionVisualDepthMode:l,onPointerDown:c})})}):u}function $O(t,e){const s=hc(t),o=hc(e);return s===0||o===0?e:Math.sign(s)===Math.sign(o)?[...e].reverse():e}const XO={generateTopUV(t,e,s,o,r){return[new Po(e[s*3],e[s*3+1]),new Po(e[o*3],e[o*3+1]),new Po(e[r*3],e[r*3+1])]},generateSideWallUV(t,e,s,o,r,i){const a=e[s*3],l=e[s*3+1],c=e[s*3+2],d=e[o*3],u=e[o*3+1],h=e[o*3+2],x=e[r*3],f=e[r*3+1],p=e[r*3+2],b=e[i*3],M=e[i*3+1],g=e[i*3+2];return Math.abs(l-u)<.01?[new Po(a,c),new Po(d,h),new Po(x,p),new Po(b,g)]:[new Po(l,c),new Po(u,h),new Po(f,p),new Po(M,g)]}};function sF(t){let e=1/0,s=1/0,o=-1/0,r=-1/0;for(const i of t)i.x<e&&(e=i.x),i.x>o&&(o=i.x),i.y<s&&(s=i.y),i.y>r&&(r=i.y);return{minX:e,minY:s,maxX:o,maxY:r}}function YO({entity:t,selected:e,selectedEntityId:s,selectedFaceId:o,selectedRectangleEdgeIndex:r,selectedHostFaceRegion:i,selectionVisualDepthMode:a,facePatches:l,faceSplits:c,faceCornerArcs:d,faceDrawActive:u,furnitureGroups:h,onPointerDown:x,onContextMenu:f,onPointerMove:p,onRectangleEdgePointerDown:b,onCornerArcPointerDown:M,onFaceRegionPointerDown:g,onRectangleHandlePointerDown:w}){const k=t.sourceTool==="circle",_=DD(t),j=m.useMemo(()=>l??[],[l]),v=m.useMemo(()=>c??[],[c]),C=m.useMemo(()=>d??[],[d]),N=m.useMemo(()=>j.filter(it=>it.shape==="rectangle"),[j]),P=m.useMemo(()=>qy(t,N),[t,N]),L=m.useMemo(()=>t.sourceTool==="rectangle"?Yi(t.vertices):null,[t.sourceTool,t.vertices]),A=m.useMemo(()=>t.sourceTool==="rectangle"?Xr(t.vertices):null,[t.sourceTool,t.vertices]),W=m.useMemo(()=>
266{if(!L||t.vertices.length<3)return[];const it=t.vertices.length,st=new Map;for(const pt of C){if(!pt.verticalThroughCut||pt.hostFaceId!=="top")continue;const xt=pL(t.vertices,L,pt.corner);if(xt!==null)for(let _t=0;_t<it;_t++){const Ft=gL(xt,it,_t);if(!Ft)continue;const Vt=`side-${_t}`,vt=st.get(Vt)??[];vt.push({kind:Ft,rMm:pt.radiusMm,arcId:pt.id}),st.set(Vt,vt)}}const ct=[];for(const[pt,xt]of st){if(P.some(Ht=>Ht.hostFaceId===pt))continue;const _t=An(t,pt);if(!_t||_t.kind!=="side")continue;const Ft=bL(_t,xt.map(Ht=>({kind:Ht.kind,rMm:Ht.rMm})));if(!Ft)continue;const vt=[...new Set(xt.map(Ht=>Ht.arcId))].sort().join("+");ct.push({arcKey:vt,faceId:pt,points2D:Ft})}return ct},[C,t,L,P]),S=m.useMemo(()=>{const it=new Set([...P.map(st=>st.hostFaceId),...v.map(st=>st.hostFaceId),...C.map(st=>st.hostFaceId),...W.map(st=>st.faceId)]);for(const st of CD(t,h))it.add(st);return it},[C,t,h,P,v,W]),B=m.useMemo(()=>Gy(t,h),[t,h]),R=S.size>0,z=m.useMemo(()=>{const it=new $l;it.moveTo(t.vertices[0].x*rt,-t.vertices[0].y*rt);for(let Vt=1;Vt<t.vertices.length;Vt++)it.lineTo(t.vertices[Vt].x*rt,-t.vertices[Vt].y*rt);it.closePath();for(const Vt of t.holes??[]){const vt=$O(t.vertices,Vt);if(vt.length<3)continue;const Ht=new Gd;Ht.moveTo(vt[0].x*rt,-vt[0].y*rt);for(let Tt=1;Tt<vt.length;Tt++)Ht.lineTo(vt[Tt].x*rt,-vt[Tt].y*rt);Ht.closePath(),it.holes.push(Ht)}if(_){const Vt=new dm(it),vt=Vt.getIndex(),Ht=Vt.getAttribute("position");return Vt.clearGroups(),Vt.addGroup(0,(vt==null?void 0:vt.count)??Ht.count,0),Vt}const st=Math.max(0,t.heightMm??0)*rt,ct=new ub(it,{depth:st,bevelEnabled:!1,UVGenerator:XO});zW(ct,t.vertices.length,k);const pt=t.topScaleX??1,xt=t.topScaleY??1,_t=t.bottomScaleX??1,Ft=t.bottomScaleY??1;if(st>0&&(pt!==1||xt!==1||_t!==1||Ft!==1)){let Vt=0,vt=0;for(const Zt of t.vertices)Vt+=Zt.x*rt,vt+=-Zt.y*rt;Vt/=t.vertices.length,vt/=t.vertices.length;const Ht=ct.getAttribute("position"),Tt=st*.001+1e-6;for(let Zt=0;Zt<Ht.count;Zt++){const At=Ht.getZ(Zt),ut=Math.abs(At-st)<=Tt,kt=Math.abs(At)<=Tt;if(!ut&&!kt)continue;const Et=ut?pt:_t,ht=ut?xt:Ft;Et===1&&ht===1||(Ht.setX(Zt,Vt+(Ht.getX(Zt)-Vt)*Et),Ht.setY(Zt,vt+(Ht.getY(Zt)-vt)*ht))}Ht.needsUpdate=!0,ct.computeVertexNormals()}return ct},[t.heightMm,t.holes,t.vertices,t.topScaleX,t.topScaleY,t.bottomScaleX,t.bottomScaleY,k,_]),X=m.useMemo(()=>[...t.vertices,t.vertices[0]].map(it=>{const st=Ar(it),ct=Math.max(0,t.heightMm??0)*rt,pt=ct>0?_a+ct+M2:b2;return[st.x,pt,st.z]}),[t.heightMm,t.vertices]),ft=m.useMemo(()=>{if(!e||!o||o==="top")return null;const it=An(t,o);return it?[{x:0,y:0},{x:it.widthMm,y:0},{x:it.widthMm,y:it.heightMm},{x:0,y:it.heightMm},{x:0,y:0}].map(ct=>{const pt=Ln(it,ct,_v);return[pt.x,pt.y,pt.z]}):null},[t,e,o]),tt=m.useMemo(()=>{if(!e||!o||o==="top")return null;const it=An(t,o);if(!it)return null;const st=it.widthMm,ct=it.heightMm;return[{handle:"nw",point:{x:0,y:ct}},{handle:"n",point:{x:st/2,y:ct},edge:!0},{handle:"ne",point:{x:st,y:ct}},{handle:"e",point:{x:st,y:ct/2},edge:!0},{handle:"se",point:{x:st,y:0}},{handle:"s",point:{x:st/2,y:0},edge:!0},{handle:"sw",point:{x:0,y:0}},{handle:"w",point:{x:0,y:ct/2},edge:!0}].map(xt=>{const _t=Ln(it,xt.point,_v+2);return{...xt,position:[_t.x,_t.y,_t.z]}})},[t,e,o]),G=m.useMemo(()=>{if((t.heightMm??0)<=0)return[];const it=(()=>{const st=An(t,"top");if(!st||st.kind!=="top")return;const ct=[];for(const pt of C){if(!pt.verticalThroughCut||pt.hostFaceId!=="top")continue;const xt=x3(st,pt.corner,pt.radiusMm);if(!(xt!=null&&xt.length)||xt.length<2)continue;const _t=$f(pt.corner,st.widthMm,st.heightMm),Ft=At=>{const ut=Ln(st,At,0);return{x:Math.round(ut.x/rt),y:Math.round(ut.z/rt)}},Vt=Ft(_t),vt=xt[0],Ht=xt[xt.length-1],Tt=Ft(vt),Zt=Ft(Ht);ct.push({apex:Vt,tangents:[Tt,Zt]})}return ct.length?ct:void 0})();return xR({vertices:t.vertices,heightMm:t.heightMm??0,hiddenFaceIds:S,...it!=null&&it.length?{topCornerThroughRounding:it}:{}})},[t,S,C]),Y=Math.max(0,t.heightMm??0),J=Y*rt,Mt=Jc(a),Rt=(t.baseHeightMm??0)*rt;return n.jsxs("group",{position:[0,Rt,0],onContextMenu:e?it=>f(it,o??"top"):void 0,children:[n.jsx(jO,{entity:t,geometry:z,isCircle:k,isFlat:_,hiddenFaceIds:S,onPointerDown:x,onContextMenu:f,onPointerMove:p}),n.jsx(HO,{entity:t,cornerArcs:C,selectedEntityId:s??null,selectedFaceId:o,selectionVisualDepthMode:a,onPointerDown:M}),G.length>0&&n.jsx(T3,{segments:G}),n.jsx(OO,{host:t,facePatches:j,selectedEntityId:s??null,selectionVisualDepthMode:a}),(P.length>0||v.length>0||C.length>0||W.length>0)&&g&&n.jsxs(n.Fragment,{children:[n.jsx(PO,{entity:t,facePatches:P,faceSplits:v,faceCornerArcs:C,selectedRegion:i??null,selectionVisualDepthMode:a,onPointerDown:g}),W.map(it=>{const st=An(t,it.faceId);if(!st)return null;const ct={regionId:`v-through:${t.id}:${it.faceId}:${it.arcKey}
266`,hostEntityId:t.id,hostFaceId:it.faceId,role:"remaining",bounds:sF(it.points2D),points2D:it.points2D};return n.jsx(eF,{entity:t,frame:st,region:ct,selected:(i==null?void 0:i.regionId)===ct.regionId,selectionVisualDepthMode:a,onPointerDown:g},ct.regionId)})]}),u&&!_&&n.jsx(_O,{entity:t,isCircle:k,isFlat:_,excludedFaceIds:S,includeInferenceTargets:!B,onPointerDown:x,onContextMenu:f,onPointerMove:p}),_&&n.jsx(NO,{geometry:z,onPointerDown:x,onContextMenu:f}),e&&o&&(!i&&!S.has(o)?n.jsx(yO,{geometry:z,faceId:o,vertexCount:t.vertices.length,isCircle:k,isFlat:_,heightMm:Y,selectionVisualDepthMode:a}):null),!R&&(_||!!ft)&&n.jsx(Jn,{points:ft??X,color:e?Ni:ID,lineWidth:e?1.15:.9,depthTest:e?Mt:!0}),e&&t.sourceTool==="rectangle"&&b&&n.jsx(GO,{entity:t,selectedEdgeIndex:r??null,y:J>0?_a+J+M2+.002:b2+.003,selectionVisualDepthMode:a,onPointerDown:b,onContextMenu:it=>f(it,o??"top")}),e&&A&&w&&n.jsx(UO,{metrics:A,positions:tt??void 0,y:J>0?_a+J+M2+.035:b2+.012,selectionVisualDepthMode:a,onHandlePointerDown:w,onContextMenu:it=>f(it,o??"top")})]})}function GO({entity:t,selectedEdgeIndex:e,y:s,selectionVisualDepthMode:o,onPointerDown:r,onContextMenu:i}){const a=m.useMemo(()=>Bp(t.vertices),[t.vertices]),l=Jc(o);return a.length?n.jsx("group",{children:a.map(c=>{const d=Ar(c.a),u=Ar(c.b),h=e===c.index;return n.jsxs("group",{children:[n.jsx(F3,{a:d,b:u,y:s+.008,onPointerDown:x=>r(c.index,x),onContextMenu:i}),h&&n.jsx(Jn,{points:[[d.x,s+.004,d.z],[u.x,s+.004,u.z]],color:Ni,lineWidth:1.4,depthTest:l})]},c.index)})}):null}function UO({metrics:t,positions:e,y:s,selectionVisualDepthMode:o,onHandlePointerDown:r,onContextMenu:i}){const a=Jc(o),l=m.useMemo(()=>{if(e!=null&&e.length)return e;const c=t.lengthMm/2,d=t.widthMm/2,u=(x,f)=>({x:Math.round(t.center.x+t.uAxis.x*x+t.vAxis.x*f),y:Math.round(t.center.y+t.uAxis.y*x+t.vAxis.y*f)});return[{handle:"nw",point:u(-c,-d)},{handle:"n",point:u(0,-d),edge:!0},{handle:"ne",point:u(c,-d)},{handle:"e",point:u(c,0),edge:!0},{handle:"se",point:u(c,d)},{handle:"s",point:u(0,d),edge:!0},{handle:"sw",point:u(-c,d)},{handle:"w",point:u(-c,0),edge:!0}].map(x=>{const f=Ar(x.point);return{...x,position:[f.x,s,f.z]}})},[t,e,s]);return n.jsx("group",{children:l.map(({handle:c,position:d,edge:u})=>n.jsxs("group",{position:d,children:[n.jsxs("mesh",{onPointerDown:h=>r(c,h),onContextMenu:i,children:[n.jsx("sphereGeometry",{args:[u?.022:.028,14,10]}),n.jsx("meshBasicMaterial",{color:"#111111",depthTest:a,depthWrite:!1})]}),n.jsxs("mesh",{onPointerDown:h=>r(c,h),onContextMenu:i,children:[n.jsx("sphereGeometry",{args:[.12,16,12]}),n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthWrite:!1})]})]},c))})}function KO({center:t,radiusMm:e}){const s=Ar(t),o=48,r=[];for(let i=0;i<=o;i+=1){const a=i/o*Math.PI*2,l=s.x+Math.cos(a)*e*rt,c=s.z+Math.sin(a)*e*rt;r.push([l,.14,c])}return n.jsx(Jn,{raycast:Ss,points:r,color:Ni,lineWidth:1.4})}function ZO({center:t,radiusMm:e,heightMm:s,rotationDeg:o,active:r,onPointerDown:i}){const a=Ar(t),l=s*rt,c=Math.max(.08,(e-28)*rt),d=(e+28)*rt,u=(e+240)*rt,h=Math.max(0,(e-220)*rt),x=Yu(o)*Math.PI/180,f=e*rt,p=Math.cos(x)*f,b=Math.sin(x)*f,M=36,g=Array.from({length:M},(_,j)=>j),w=()=>{document.body.style.cursor=r?"grabbing":"grab"},k=()=>{r||(document.body.style.cursor="")};return n.jsxs("group",{position:[a.x,l,a.z],renderOrder:9999,children:[n.jsx(Uu,{position:[0,.16,0],center:!0,distanceFactor:8,zIndexRange:[70,0],children:n.jsxs("span",{className:"pointer-events-none whitespace-nowrap rounded-[4px] border border-[#336CFF]/20 bg-white/90 px-1.5 py-0.5 font-heebo text-[10px] font-bold leading-none tabular-nums text-[#182137] shadow-sm",children:[qO(o),"°"]})}),n.jsxs("mesh",{rotation:[-Math.PI/2,0,0],raycast:Ss,renderOrder:9999,children:[n.jsx("ringGeometry",{args:[c,d,96]}),n.jsx("meshBasicMaterial",{color:"#336CFF",transparent:!0,opacity:r?.95:.82,depthTest:!1,depthWrite:!1,side:kn})]}),g.map(_=>{const j=_/M*Math.PI*2,v=_%4===0,C=v?155:95,N=v?155:80,P=Math.cos(j)*((e-C)*rt),L=Math.sin(j)*((e-C)*rt),A=Math.cos(j)*((e+N)*rt),W=Math.sin(j)*((e+N)*rt);return n.jsx(Jn,{raycast:Ss,points:[[P,.012,L],[A,.012,W]],color:v?"#182137":"#336CFF",lineWidth:v?2.25:1.2,depthTest:!1,renderOrder:9999},_)}),n.jsx(Jn,{raycast:Ss,points:[[0,.018,0],[p,.018,b]],color:"#D85D43",lineWidth:1.35,depthTest:!1,renderOrder:1e4}),n.jsxs("mesh",{position:[p,.045,b],onPointerDown:i,onPointerOver:w,onPointerOut:k,renderOrder:10001,children:[n.jsx("sphereGeometry",{args:[.085,24,16]}),n.jsx("meshBasicMaterial",{color:"#D85D43",depthTest:!1,depthWrite:!1})]}),n.jsxs("mesh",{rotation:[-Math.PI/2,0,0],onPointerDown:i,onPointerOver:w,onPointerOut:k,renderOrder:1e4,children:[n.jsx("ringGeometry",{args:[h,u,48]}),n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthTest:!1,depthWrite:!1,side:kn})]})]})}function qO(t){const e=Yu(t);return Number.isInteger(e)?String(e):e.toFixed(1)}function Xp({position:t,label:e,compact:s=!1,screenOffset:o,occlude:r=!1,onDomContextMenu:i}){const a=!!i;return n.jsx(Uu,{position:t,center:!0,distanceFactor:8,zIndexRange:[20,0],occlude:r,children:n.jsx("span",{className:`${a?"pointer-events-auto cursor-pointer":"pointer-events-none"} whitespace-nowrap rounded-[3px] border border-black/10 bg-[#F7F4EF]/90 font-heebo font-bold leading-none text-[#3F3A34] shadow-sm ${s?"px-1 py-[1px] text-[8px]":"px-1.5 py-0.5 text-[10px]"}`,style:o?{transform:`translate(${o.x}px, ${o.y}px)`}:void 0,onContextMenu:i,children:e})})}function P3(t,e,s,o){return rF(Ar(t),Ar(e),s,o)}function rF(t,e,s,o){const r=e.x-t.x,i=e.z-t.z,a=Math.hypot(r,i);if(a<.001)return[(t.x+e.x)/2,s,(t.z+e.z)/2];let l=-i/a,c=r/a;
266return(c<0||Math.abs(c)<.001&&l<0)&&(l*=-1,c*=-1),[(t.x+e.x)/2+l*o,s,(t.z+e.z)/2+c*o]}function JO(t,e,s=!1){if(!t||!e)return[];if(t.tool==="line")return[t.start,e];if(t.tool==="rectangle"){const o=t.wallSnap?f3(t.start,e,t.wallSnap)??[]:Hp(t.start,e);return o.length===0?[]:[...o,o[0]]}if(t.tool==="circle"){const o=Xl(t.start,Nn(t.start,e));return[...o,o[0]]}return t.tool==="polygon"?NL(t.points,e,s):[]}function A3({strokeWidth:t=1.15,...e}){return n.jsx("svg",{viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",stroke:"currentColor",strokeWidth:t,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,...e,children:n.jsx("path",{d:"M10 0.5H14.5V14.5H0.5V0.5H4.5L7.5 2.5M6.5 14.5V7.5M4 7.5H9M12 7.5H14.5"})})}function U1({className:t,...e}){return n.jsx("svg",{viewBox:"0 0 512 512",fill:"currentColor",stroke:"currentColor",strokeWidth:36,strokeLinejoin:"round",paintOrder:"stroke fill",xmlns:"http://www.w3.org/2000/svg","aria-hidden":!0,className:O("h-[20px] w-[20px] shrink-0 text-black group-data-[active]:text-[#173a76]",t),...e,children:n.jsx("path",{d:"M480.707,256.004c0-10.099-6.711-18.528-15.889-21.353v-74.08c9.178-2.825,15.889-11.239,15.889-21.362c0-12.386-10.044-22.422-22.43-22.422c-5.916,0-11.262,2.334-15.25,6.079l-64.06-36.993c0.367-1.631,0.608-3.302,0.608-5.049c0-12.394-10.044-22.431-22.438-22.431c-5.916,0-11.254,2.326-15.25,6.072l-64.059-36.977c0.375-1.639,0.616-3.31,0.616-5.058c0-12.386-10.044-22.43-22.438-22.43c-12.386,0-22.43,10.044-22.43,22.43c0,1.748,0.242,3.419,0.601,5.058l-64.052,36.977c-4.011-3.746-9.35-6.072-15.25-6.072c-12.386,0-22.446,10.037-22.446,22.431c0,1.748,0.234,3.418,0.617,5.049l-64.052,36.993c-4.011-3.746-9.358-6.079-15.273-6.079c-12.386,0-22.43,10.036-22.43,22.422c0,10.123,6.719,18.536,15.889,21.362v74.08c-9.17,2.825-15.889,11.254-15.889,21.353c0,10.099,6.719,18.528,15.889,21.353v74.065c-9.17,2.809-15.889,11.246-15.889,21.361c0,12.386,10.044,22.43,22.43,22.43c5.916,0,11.262-2.318,15.273-6.063l64.052,36.969c-0.383,1.647-0.617,3.302-0.617,5.065c0,12.379,10.037,22.415,22.431,22.415c5.916,0,11.254-2.326,15.265-6.064l64.052,36.97c-0.375,1.654-0.609,3.31-0.609,5.073c0,12.378,10.029,22.422,22.423,22.422c12.409,0,22.453-10.044,22.453-22.422c0-1.764-0.241-3.419-0.624-5.073l64.052-36.97c4.011,3.738,9.35,6.064,15.265,6.064c12.394,0,22.438-10.036,22.438-22.415c0-1.764-0.242-3.418-0.624-5.065l64.052-36.969c4.011,3.746,9.358,6.063,15.273,6.063c12.386,0,22.43-10.044,22.43-22.43c0-10.115-6.711-18.552-15.889-21.361v-74.065C473.996,274.532,480.707,266.103,480.707,256.004z M176.683,75.79l64.067-36.993c4.003,3.746,9.342,6.079,15.258,6.079c5.916,0,11.254-2.334,15.25-6.079l64.067,36.993c-0.374,1.615-0.616,3.294-0.616,5.034c0,1.748,0.242,3.418,0.616,5.049l-64.067,36.993c-4.003-3.746-9.342-6.079-15.25-6.079c-5.916,0-11.254,2.334-15.265,6.079l-64.06-36.993c0.374-1.631,0.616-3.302,0.616-5.049C177.299,79.083,177.057,77.405,176.683,75.79z M148.321,409.816c-3.286,1.022-6.251,2.7-8.71,4.995l-64.067-36.978c0.382-1.631,0.624-3.309,0.624-5.049c0-10.115-6.72-18.552-15.89-21.361v-74.065c3.293-1.015,6.259-2.716,8.717-5.011l64.052,37.01c-0.383,1.623-0.617,3.293-0.617,5.041c0,10.099,6.704,18.528,15.89,21.353V409.816z M148.321,293.036c-3.286,1.022-6.251,2.693-8.71,4.987l-64.067-36.986c0.382-1.616,0.624-3.301,0.624-5.034c0-10.099-6.72-18.528-15.89-21.353v-74.08c3.293-1.022,6.259-2.692,8.717-4.995l64.052,36.993c-0.383,1.623-0.617,3.302-0.617,5.042c0,10.114,6.704,18.528,15.89,21.353V293.036z M139.611,181.252l-64.067-36.994c0.382-1.631,0.624-3.293,0.624-5.05c0-1.724-0.242-3.418-0.624-5.033l64.067-36.993c4.004,3.746,9.342,6.071,15.265,6.071c5.9,0,11.239-2.326,15.25-6.071l64.052,36.993c-0.375,1.615-0.609,3.309-0.609,5.033c0,1.749,0.234,3.419,0.609,5.05l-64.059,36.994c-4.004-3.746-9.342-6.072-15.258-6.072C148.953,175.18,143.615,177.506,139.611,181.252z M249.452,468.225c-3.285,0.991-6.251,2.684-8.709,4.964l-64.06-36.985c0.374-1.6,0.616-3.302,0.616-5.019c0-10.114-6.72-18.551-15.882-21.368V335.75c3.286-1.014,6.251-2.708,8.71-5.003l64.052,37.002c-0.375,1.608-0.609,3.286-0.609,5.034c0,10.099,6.696,18.535,15.882,21.361V468.225z M249.452,351.422c-3.285,1.014-6.251,2.708-8.709,5.01l-64.06-36.993c0.374-1.623,0.616-3.31,0.616-5.042c0-10.114-6.72-18.544-15.882-21.361v-74.073c3.286-1.014,6.251-2.7,8.71-5.002l64.052,36.994c-0.375,1.631-0.609,3.293-0.609,5.049c0,10.099,6.696,18.528,15.882,21.353V351.422z M255.993,233.574c-5.9,0-11.239,2.326-15.25,6.072l-64.06-36.994c0.374-1.623,0.616-3.285,0.616-5.041c0-1.74-0.242-3.419-0.616-5.042l64.06-36.993c4.011,3.754,9.35,
2666.072,15.265,6.072c5.908,0,11.247-2.318,15.25-6.072l64.067,36.993c-0.382,1.623-0.624,3.302-0.624,5.042c0,1.733,0.242,3.418,0.624,5.041l-64.067,36.978c-4.003-3.731-9.342-6.056-15.25-6.056C256.008,233.574,256.008,233.574,255.993,233.574z M350.599,409.816c-9.179,2.817-15.898,11.254-15.898,21.368c0,1.718,0.242,3.419,0.624,5.019l-64.067,36.985c-2.458-2.279-5.432-3.973-8.71-4.964v-74.08c9.162-2.826,15.897-11.262,15.897-21.361c0-1.748-0.241-3.426-0.624-5.034l64.052-37.002c2.458,2.294,5.424,3.989,8.726,5.003V409.816z M350.599,293.036c-9.179,2.817-15.898,11.246-15.898,21.361c0,1.732,0.242,3.419,0.624,5.042l-64.067,36.993c-2.458-2.302-5.416-3.996-8.71-5.01v-74.065c9.162-2.818,15.897-11.254,15.897-21.353c0-1.756-0.241-3.418-0.624-5.057l64.052-36.986c2.458,2.302,5.424,3.988,8.726,5.002V293.036z M341.873,181.252l-64.052-36.994c0.383-1.631,0.624-3.293,0.624-5.05c0-1.724-0.241-3.418-0.624-5.033l64.067-36.993c3.996,3.746,9.334,6.071,15.25,6.071c5.916,0,11.262-2.326,15.266-6.071l64.052,36.993c-0.367,1.615-0.624,3.309-0.624,5.033c0,1.757,0.257,3.419,0.624,5.05l-64.052,36.994c-4.019-3.746-9.358-6.072-15.266-6.072C351.223,175.18,345.885,177.506,341.873,181.252z M451.737,351.422c-9.186,2.809-15.905,11.246-15.905,21.361c0,1.74,0.257,3.418,0.624,5.049l-64.052,36.978c-2.458-2.294-5.432-3.973-8.726-4.995V335.75c9.186-2.825,15.898-11.254,15.898-21.353c0-1.748-0.242-3.418-0.624-5.041l64.052-37.01c2.458,2.294,5.447,3.996,8.732,5.011V351.422z M451.737,234.651c-9.186,2.825-15.905,11.254-15.905,21.353c0,1.733,0.257,3.418,0.624,5.034l-64.052,36.986c-2.458-2.294-5.432-3.965-8.726-4.987v-74.073c9.186-2.825,15.898-11.238,15.898-21.353c0-1.74-0.242-3.419-0.624-5.042l64.076-36.993c2.435,2.302,5.424,3.972,8.709,4.995V234.651z"})})}function Tb({size:t="md",isDark:e,center:s,centerPrimary:o,centerSecondary:r,hideCenter:i=!1,onUp:a,onDown:l,onLeft:c,onRight:d,labels:u,directionButtonProps:h,className:x}){const f=t==="sm",p=f?"h-[112px] w-[112px]":"h-[132px] w-[132px]",b=f?"h-8 w-8 text-[13px]":"h-9 w-9 text-[15px]",M=f?"h-11 w-11":"h-12 w-12",g=f?"inset-[6px]":"inset-[8px]",w=O("absolute z-[1] flex items-center justify-center rounded-full border font-bold transition-all duration-150","active:scale-95 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#D85D43]/45",b,e?"border-white/14 bg-[#182137]/80 text-white/90 shadow-[0_2px_8px_rgba(0,0,0,0.35)] hover:border-[#D85D43]/70 hover:bg-[#D85D43]/20 hover:text-white":"border-[#182137]/10 bg-white text-[#182137] shadow-[0_2px_8px_rgba(24,33,55,0.08)] hover:border-[#D85D43]/55 hover:bg-[#D85D43]/10 hover:text-[#D85D43]"),k=(_,j,v,C,N)=>{const P=h==null?void 0:h[_],{className:L,...A}=P??{};return n.jsx("button",{type:"button",className:O(w,j,L),onClick:v,"aria-label":N,title:N,...A,children:C})};return n.jsxs("div",{dir:"ltr",className:O("relative mx-auto",p,x),children:[n.jsx("div",{className:O("absolute inset-0 rounded-full border",e?"border-white/10 bg-gradient-to-b from-white/[0.07] to-white/[0.02] shadow-[inset_0_1px_0_rgba(255,255,255,0.06)]":"border-[#182137]/08 bg-gradient-to-b from-[#F7F4EF] to-white shadow-[inset_0_1px_0_rgba(255,255,255,0.9),0_4px_14px_rgba(24,33,55,0.06)]")}),n.jsx("div",{className:O("absolute rounded-full border",g,e?"border-white/[0.06]":"border-[#182137]/[0.04]")}),k("up","left-1/2 top-[6px] -translate-x-1/2",a,"↑",u.up),k("down","bottom-[6px] left-1/2 -translate-x-1/2",l,"↓",u.down),k("left","left-[6px] top-1/2 -translate-y-1/2",c,"←",u.left),k("right","right-[6px] top-1/2 -translate-y-1/2",d,"→",u.right),i?null:n.jsx("div",{className:O("absolute left-1/2 top-1/2 z-0 flex -translate-x-1/2 -translate-y-1/2 flex-col items-center justify-center rounded-full border text-center leading-tight tabular-nums",M,e?"border-[#D85D43]/35 bg-[#D85D43]/15 text-white":"border-[#D85D43]/30 bg-[#D85D43]/10 text-[#182137]"),children:s??n.jsxs(n.Fragment,{children:[o?n.jsx("span",{className:O("font-bold",f?"text-[10px]":"text-[11px]"),children:o}):null,r?n.jsx("span",{className:O("font-semibold opacity-70",f?"text-[8px]":"text-[9px]"),children:r}):null]})})]})}const K1=15e3,L3=1e4,QO=50,Wv=30,Rv=16e6,Ov=32e6,tH=.015,eH=.015,nH=.05;function Hv(t){return Array.isArray(t)&&t.length===3&&t.every(e=>typeof e=="number"&&Number.isFinite(e))}function Bv(t,e){return Math.hypot(t[0]-e[0],t[1]-e[1],t[2]-e[2])}function i1(t,e,s){return t+(e-t)*s}function Vv(t,e,s){return[i1(t[0],e[0],s),i1(t[1],e[1],s),i1(t[2],e[2],s)]}function zv(t,e){return t?Bv(t.position,e.position)>=tH||Bv(t.target,e.target)>=eH||Math.abs(t.fov-e.fov)>=nH:!0}function iF(t){if(!Array.isArray(t))return[];const e=t.map(o=>{if(!o||typeof o!="object")return null;const r=o;return typeof r.tMs!="number"||!Number.isFinite(r.tMs)||!Hv(r.position)||!Hv(r.target)||typeof r.fov!="number"||!Number.isFinite(r.fov)?null:{tMs:Math.max(0,r.tMs),position:[...r.position],target:[...r.target],fov:Math.min(110,Math.max(25,r.fov))}}).filter(o=>!!o).sort((o,r)=>o.tMs-r.tMs);if(e.length===0)return[];const s=e[0].tMs;return e.map(o=>({...o,tMs:o.tMs-s}))}function $v(t,e){if(t.length===0)return null;if(t.length===1||e<=t[0].tMs)return{...t[0],tMs:Math.max(0,e)};const s=t[t.length-1];if(e>=s.tMs)return{...s,tMs:e};for(let o=1;o<t.length;o+=1){const r=t[o];if(e>r.tMs)continue;const i=t[o-1],a=Math.max(1,r.tMs-i.tMs),l=(e-i.tMs)/a;return{tMs:e,position:Vv(i.position,r.position,l),target:Vv(i.target,r.target,l),fov:i1(i.fov,r.fov,l)}}return{...s,tMs:e}}function oH(t){var i;const e=iF(t.keyframes);if(e.length<2)return null;const s=Math.min(K1,Math.max(0,e[e.length-1].tMs));if(s<=0)return null;const o=t.id??`walkthrough_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,r=t.createdAt??new Date().toISOString();return{id:o,name:((i=t.name)==null?void 0:i.trim())||`סיור ${new Date(r).toLocaleStr
266ing("he-IL",{day:"2-digit",month:"2-digit",hour:"2-digit",minute:"2-digit"})}`,createdAt:r,durationMs:s,keyframes:e.filter(a=>a.tMs<=s),planRotationDeg:t.planRotationDeg,sceneFingerprint:t.sceneFingerprint}}function W3(t){return Array.isArray(t)?t.map(e=>{if(!e||typeof e!="object")return null;const s=e;if(typeof s.id!="string"||typeof s.name!="string"||typeof s.createdAt!="string"||typeof s.sceneFingerprint!="string"||typeof s.planRotationDeg!="number")return null;const o=iF(s.keyframes);if(o.length<2)return null;const r=typeof s.durationMs=="number"&&Number.isFinite(s.durationMs)?Math.min(K1,Math.max(0,s.durationMs)):o[o.length-1].tMs;return r<=0?null:{id:s.id,name:s.name.trim()||"סיור",createdAt:s.createdAt,durationMs:r,keyframes:o.filter(i=>i.tMs<=r),planRotationDeg:s.planRotationDeg,sceneFingerprint:s.sceneFingerprint,...typeof s.videoAssetId=="string"?{videoAssetId:s.videoAssetId}:{},...typeof s.videoUrl=="string"?{videoUrl:s.videoUrl}:{},...typeof s.videoMimeType=="string"?{videoMimeType:s.videoMimeType}:{},...typeof s.videoStoragePath=="string"?{videoStoragePath:s.videoStoragePath}:{},...s.videoCaptureSource==="live-canvas"?{videoCaptureSource:"live-canvas"}:{},...s.videoExportMode==="render"||s.videoExportMode==="hq"?{videoExportMode:s.videoExportMode}:{}}}).filter(e=>!!e).sort((e,s)=>s.createdAt.localeCompare(e.createdAt)):[]}function sH(t){return!t||typeof t!="object"||Array.isArray(t)?[]:W3(t._floorplanWalkthroughs)}function rH(t,e){return{...t,_floorplanWalkthroughs:W3(e)}}function Xv(t=typeof MediaRecorder<"u"?MediaRecorder.isTypeSupported.bind(MediaRecorder):void 0){return t?["video/mp4;codecs=avc1.640028","video/mp4;codecs=avc1.42E01E","video/mp4","video/webm;codecs=vp9","video/webm;codecs=vp8","video/webm"].find(s=>{try{return t(s)}catch{return!1}})??null:null}function aF(t){return t!=null&&t.includes("mp4")?"mp4":"webm"}const a1={"1080p":{key:"1080p",label:"1080p",width:1920,height:1080,fps:60,bitrate:2e7},"2k":{key:"2k",label:"2K",width:2560,height:1440,fps:60,bitrate:32e6},"4k":{key:"4k",label:"4K",width:3840,height:2160,fps:60,bitrate:48e6}},lF={key:"render",label:"Render",width:1920,height:1080,fps:30,bitrate:16e6},Yv="4k",iH=8,aH=["avc1.640034","avc1.640033","avc1.4d0034"];function R3(){if(typeof window>"u")return null;const t=window;return typeof t.VideoEncoder=="function"&&typeof t.VideoFrame=="function"?t:null}function lH(){return R3()!==null}function Gv(t){return new Promise(e=>setTimeout(e,t))}async function cH(t,e,s,o){var i;const r=R3();if(!((i=r==null?void 0:r.VideoEncoder)!=null&&i.isConfigSupported))return null;for(const a of aH)try{const l=await r.VideoEncoder.isConfigSupported({codec:a,width:t,height:e,bitrate:s,framerate:o});if(l!=null&&l.supported)return a}catch{}return null}async function dH(t){const{getFrameCanvas:e,durationMs:s,fps:o,quality:r,onProgress:i,signal:a}=t,l=R3();if(!(l!=null&&l.VideoEncoder)||!l.VideoFrame)return null;const{width:c,height:d,bitrate:u}=r,h=await cH(c,d,u,o);if(!h)return null;const x=new bI({target:new MI,video:{codec:"avc",width:c,height:d},fastStart:"in-memory"});let f=null;const p=new l.VideoEncoder({output:(_,j)=>x.addVideoChunk(_,j),error:_=>{f=_}});p.configure({codec:h,width:c,height:d,bitrate:u,framerate:o,latencyMode:"quality"});const b=Math.round(1e6/o),M=Math.max(1,Math.round(s/1e3*o)),g=Math.max(1,o*2),w=()=>new DOMException("Walkthrough export cancelled","AbortError");let k=-1;try{for(let j=0;j<M;j+=1){if(a!=null&&a.aborted)throw w();if(f)throw f;const v=Math.min(s,j/o*1e3),C=e(v);if(!C)throw new Error("Walkthrough frame render returned no canvas");const N=new l.VideoFrame(C,{timestamp:j*b,duration:b});p.encode(N,{keyFrame:j%g===0}),N.close();const P=Math.floor((j+1)/M*100);for(P!==k&&(k=P,i==null||i((j+1)/M)),await Gv(0);p.encodeQueueSize>iH;){if(a!=null&&a.aborted)throw w();if(f)throw f;await Gv(4)}}if(await p.flush(),f)throw f;x.finalize();const{buffer:_}=x.target;return{blob:new Blob([_],{type:"video/mp4"}),mimeType:"video/mp4"}}finally{try{p.state!=="closed"&&p.close()}catch{}}}function uH(t,e){const s=new Date(t);return Number.isNaN(s.getTime())?"":s.toLocaleDateString(e,{day:"2-digit",month:"2-digit"})}function Uv(t,e){const s=new Date(t);return Number.isNaN(s.getTime())?"":s.toLocaleTimeString(e,{hour:"2-digit",minute:"2-digit",hour12:!1})}function j2({label:t,onClick:e,disabled:s,tone:o="neutral",children:r}){return yn(),n.jsx("button",{type:"button",onClick:e,disabled:s,"aria-label":t,title:t,className:O("inline-flex h-8 min-w-8 items-center justify-center gap-1 rounded-lg px-2 text-[10px] font-black transition-all duration-150","disabled:cursor-not-allowed disabled:opacity-40",o==="primary"&&"bg-[#182137] text-white shadow-[0_4px_10px_rgba(24,33,55,0.18)] hover:-translate-y-
266px hover:bg-[#101827]",o==="danger"&&"bg-[#FEE2E2] text-[#B91C1C] hover:-translate-y-px hover:bg-[#FECACA]",o==="neutral"&&"border border-[#182137]/10 bg-white/90 text-[#182137] shadow-[0_2px_8px_rgba(24,33,55,0.06)] hover:-translate-y-px hover:border-[#182137]/18 hover:bg-[#F7F4EF]"),children:r})}function hH({recording:t,active:e,fpIsDark:s,walkthroughStatus:o,exportMode:r,exportProgress:i,onPlay:a,onExport:l,onRename:c,onDelete:d}){const{t:u,i18n:h}=yn(),x=r==="render"?Math.min(t.durationMs,L3):t.durationMs,f=Math.max(1,Math.round(x/1e3)),p=o==="exporting"&&e,b=o==="recording"||o==="exporting",M=o!=="idle";return n.jsxs("article",{className:O("group relative overflow-hidden rounded-2xl border p-3 transition-all duration-200",e?"border-[#336CFF]/35 bg-[linear-gradient(145deg,#F5F8FF_0%,#EAF1FF_100%)] shadow-[0_10px_28px_rgba(51,108,255,0.14)]":s?"border-white/10 bg-white/[0.04] hover:border-white/18":"border-[#182137]/10 bg-white/85 shadow-[0_8px_24px_rgba(24,33,55,0.07)] hover:-translate-y-0.5 hover:shadow-[0_14px_32px_rgba(24,33,55,0.11)]"),children:[n.jsx("div",{"aria-hidden":!0,className:O("pointer-events-none absolute -start-6 -top-6 h-16 w-16 rounded-full blur-2xl transition-opacity",e?"bg-[#336CFF]/20 opacity-100":"bg-[#D85D43]/10 opacity-0 group-hover:opacity-100")}),n.jsxs("div",{className:"relative flex items-start gap-3",children:[n.jsxs("button",{type:"button",onClick:a,disabled:b,"aria-label":u("walkthrough.play",{defaultValue:"נגן סיור"}),className:O("relative flex h-11 w-11 shrink-0 items-center justify-center overflow-hidden rounded-full border transition-all duration-150","disabled:cursor-not-allowed disabled:opacity-45",e?"border-[#336CFF]/40 bg-[linear-gradient(145deg,#4F86FF_0%,#173A76_100%)] text-white shadow-[0_8px_18px_rgba(51,108,255,0.35)]":"border-[#182137]/12 bg-[linear-gradient(145deg,#182137_0%,#101827_100%)] text-white shadow-[0_6px_14px_rgba(24,33,55,0.22)] hover:-translate-y-0.5"),children:[n.jsx("span",{className:"pointer-events-none absolute inset-x-1 top-1 h-2 rounded-full bg-white/30 blur-[1px]"}),n.jsx(__,{className:"relative z-10 ms-0.5 h-[18px] w-[18px]",fill:"currentColor",strokeWidth:2.2})]}),n.jsxs("div",{className:"min-w-0 flex-1 pt-0.5",children:[n.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[n.jsx("h3",{className:"truncate text-[13px] font-black tracking-[-0.02em] text-[#182137]",children:t.name}),t.videoUrl&&n.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-[#182137]/8 px-2 py-0.5 text-[9px] font-black text-[#182137]/70",children:[n.jsx(pN,{className:"h-3 w-3",strokeWidth:2.2}),"MP4"]})]}),n.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[n.jsxs("span",{className:"inline-flex items-center rounded-full bg-[#E8DFD3] px-2 py-0.5 text-[10px] font-black tabular-nums text-[#182137]",children:[f,"s"]}),n.jsxs("span",{className:"text-[10px] font-semibold text-[#182137]/45",children:[uH(t.createdAt,h.language),Uv(t.createdAt,h.language)?` · ${Uv(t.createdAt,h.language)}`:""]})]})]})]}),n.jsxs("div",{className:"relative mt-3 flex flex-wrap items-center gap-1.5",children:[n.jsx(j2,{label:u("walkthrough.downloadMp4",{defaultValue:"הורד MP4"}),onClick:l,disabled:o==="recording"||o==="playing"||p,tone:"primary",children:p?n.jsxs("span",{className:"tabular-nums",children:[Math.round(i*100),"%"]}):n.jsxs(n.Fragment,{children:[n.jsx(cT,{className:"h-3.5 w-3.5",strokeWidth:2.2}),n.jsx("span",{children:u("walkthrough.download",{defaultValue:"הורד"})})]})}),n.jsxs(j2,{label:u("walkthrough.rename",{defaultValue:"שנה שם"}),onClick:c,disabled:M,children:[n.jsx(mp,{className:"h-3.5 w-3.5",strokeWidth:2.2}),n.jsx("span",{children:u("walkthrough.edit",{defaultValue:"ערוך"})})]}),n.jsx(j2,{label:u("common.delete",{defaultValue:"מחק"}),onClick:d,disabled:M,tone:"danger",children:n.jsx(gi,{className:"h-3.5 w-3.5",strokeWidth:2.2})})]})]})}function mH({fpIsDark:t,walkthroughStatus:e,walkthroughElapsedLabel:s,walkthroughCount:o,walkthroughExportMode:r,walkthroughExportQuality:i,walkthroughExportProgress:a,canCancelExport:l,walkthroughs:c,activeWalkthroughId:d,onClose:u,onStartRecording:h,onStopRecording:x,onStopPlayback:f,onSetExportMode:p,onSetExportQuality:b,onCancelExport:M,onPlay:g,onExport:w,onRename:k,onDelete:_,style:j}){const{t:v}=yn(),C=m.useRef(null),N=e==="recording",P=e==="playing",L=e==="exporting",A=P||L;return m.useEffect(()=>{if(e==="recording")return;const W=S=>{const B=C.current,R=S.target;!B||!(R instanceof Node)||B.contains(R)||u()};return document.addEventListener("pointerdown",W,!0),()=>document.removeEventListener("pointerdown",W,!0)},[u,e]),n.jsxs("div",{ref:C,dir:"rtl",className:O("fixed z-[95] overflow-hidden rounded-[18px] border font-heebo shadow-[0_24px_70px_rgba(24,33,55,0.22)] backdrop-blur-xl",t?"border-white/10 bg-[#141416]/[0.94] text-white":"border-[#182137]/12 bg-[#F7F4EF]/[0.98] text-[#182137]"),style:{to
266p:j.top,left:j.left,width:j.width,maxWidth:"calc(100vw - 24px)"},children:[n.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 opacity-[0.14]",style:{backgroundImage:"radial-gradient(circle, #182137 1px, transparent 1px)",backgroundSize:"14px 14px"}}),n.jsx("div",{className:"relative border-b border-[#182137]/10 bg-[linear-gradient(180deg,#FFF8F5_0%,#F7F4EF_100%)] px-4 py-3",children:n.jsxs("div",{className:"flex items-start justify-between gap-3",children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[n.jsxs("span",{className:O("relative flex h-10 w-10 shrink-0 items-center justify-center overflow-hidden rounded-xl border text-white shadow-[0_8px_18px_rgba(216,93,67,0.28)]",N?"border-[#FF4D6D]/70 bg-[linear-gradient(145deg,#FF6B8A_0%,#E63946_52%,#9D174D_100%)]":"border-[#FFC6A8]/70 bg-[linear-gradient(145deg,#FFB06F_0%,#D85D43_48%,#8C4FA3_100%)]"),children:[n.jsx("span",{className:"pointer-events-none absolute inset-x-1 top-1 h-2 rounded-full bg-white/35 blur-[1px]"}),n.jsx(Ey,{className:"relative z-10 h-[18px] w-[18px]",strokeWidth:2.2})]}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"truncate text-[14px] font-black tracking-[-0.025em]",children:v("walkthrough.title",{defaultValue:"הקלטת וידאו"})}),n.jsx("div",{className:"mt-0.5 text-[10px] font-bold text-[#182137]/55",children:N?v("walkthrough.recordingElapsed",{defaultValue:"מקליט · {{elapsed}}",elapsed:s}):v("walkthrough.savedCount",{defaultValue:"{{count}} סיורים שמורים",count:o})})]})]}),n.jsx("button",{type:"button",onClick:u,className:"flex h-8 w-8 items-center justify-center rounded-xl border border-[#182137]/10 bg-white/80 text-[#182137] transition hover:bg-white","aria-label":v("common.close",{defaultValue:"סגור"}),title:v("common.close",{defaultValue:"סגור"}),children:n.jsx(Gr,{size:15,strokeWidth:2.2})})]})}),n.jsxs("div",{className:"relative space-y-3 px-4 py-3",children:[N?n.jsxs("button",{type:"button",onClick:x,className:O("relative flex w-full items-center justify-center gap-2 overflow-hidden rounded-2xl border px-4 py-3.5 text-[13px] font-black text-white transition-all duration-150","border-[#182137]/20 bg-[linear-gradient(145deg,#182137_0%,#0A0F18_100%)]","shadow-[inset_0_1px_0_rgba(255,255,255,0.12),0_10px_24px_rgba(24,33,55,0.28)] hover:-translate-y-0.5"),children:[n.jsx("span",{className:"absolute inline-flex h-2.5 w-2.5 animate-ping rounded-full bg-white/70"}),n.jsx(lT,{className:"relative h-[18px] w-[18px]",strokeWidth:2.2}),n.jsx("span",{className:"relative",children:v("walkthrough.stopAndSave",{defaultValue:"עצור ושמור"})})]}):n.jsxs("button",{type:"button",onClick:h,disabled:A,className:O("group relative flex w-full items-center justify-center gap-2 overflow-hidden rounded-2xl border px-4 py-3.5 text-[13px] font-black text-white transition-all duration-150","border-[#FFC6A8]/70 bg-[linear-gradient(145deg,#FF6B8A_0%,#E63946_48%,#BE123C_100%)]","shadow-[inset_0_1px_0_rgba(255,230,235,0.75),0_12px_26px_rgba(230,57,70,0.34)] hover:-translate-y-0.5 disabled:cursor-not-allowed disabled:opacity-55 disabled:hover:translate-y-0"),children:[n.jsx("span",{className:"pointer-events-none absolute inset-x-3 top-1.5 h-3 rounded-full bg-white/30 blur-[1px]"}),n.jsx(Ey,{className:"relative h-[18px] w-[18px]",strokeWidth:2.3}),n.jsx("span",{className:"relative",children:v("walkthrough.recordNew",{defaultValue:"הקלט סיור חדש"})}),n.jsx(zl,{className:"relative h-4 w-4 opacity-80",strokeWidth:2.2})]}),P&&n.jsx("button",{type:"button",onClick:f,className:"w-full rounded-xl border border-[#182137]/12 bg-white px-3 py-2 text-[12px] font-black text-[#182137] transition hover:bg-[#F4F1EA]",children:v("walkthrough.stopPlayback",{defaultValue:"עצור תצוגה"})}),L?n.jsxs("div",{className:"rounded-2xl border border-[#336CFF]/20 bg-[#EAF1FF]/70 px-3 py-3",children:[n.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[n.jsx("span",{className:"text-[11px] font-black text-[#173A76]",children:v("walkthrough.exporting",{defaultValue:"מייצא {{qual
266ity}} · {{progress}}%",quality:r==="render"?lF.label:a1[i].label,progress:Math.round(a*100)})}),n.jsx("button",{type:"button",onClick:M,disabled:!l,className:"rounded-lg px-2 py-1 text-[10px] font-black text-[#D85D43] transition hover:bg-[#D85D43]/10 disabled:opacity-40",children:v("common.cancel",{defaultValue:"בטל"})})]}),n.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-[#182137]/10",children:n.jsx("div",{className:"h-full rounded-full bg-[linear-gradient(90deg,#336CFF_0%,#173A76_100%)] transition-[width] duration-150",style:{width:`${Math.max(2,Math.round(a*100))}%`}})})]}):!N&&n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"grid grid-cols-2 gap-1 rounded-2xl border border-[#182137]/10 bg-white/75 p-1",children:[{mode:"render",label:v("walkthrough.modeRenderReady",{defaultValue:"מוכן לרינדור"})},{mode:"hq",label:v("walkthrough.modeHighQuality",{defaultValue:"איכות גבוהה"})}].map(({mode:W,label:S})=>{const B=r===W;return n.jsx("button",{type:"button",onClick:()=>p(W),className:O("rounded-xl px-2 py-2 text-[11px] font-black transition-all duration-150",B?"bg-[#182137] text-white shadow-[0_6px_14px_rgba(24,33,55,0.22)]":"bg-transparent text-[#182137]/70 hover:bg-[#F4F1EA] hover:text-[#182137]"),children:S},W)})}),r==="render"?n.jsxs("div",{className:"rounded-2xl border border-[#336CFF]/20 bg-[#EAF1FF]/60 px-3 py-2.5",children:[n.jsx("div",{className:"text-[11px] font-black tabular-nums text-[#173A76]",children:v("walkthrough.renderReadySpec",{defaultValue:"1080p · 30fps · עד {{seconds}} שניות · MP4",seconds:Math.round(L3/1e3)})}),n.jsx("div",{className:"mt-1 text-[10px] font-bold text-[#182137]/55",children:v("walkthrough.renderReadyHint",{defaultValue:"מתאים לכל מודלי הרינדור"})}),n.jsx("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:["Seedance","Kling O1","Gemini Omni"].map(W=>n.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-white/80 px-2 py-0.5 text-[9px] font-black text-[#173A76]",children:["✓ ",W]},W))})]}):n.jsxs("div",{className:"rounded-2xl border border-[#182137]/10 bg-white/75 p-1.5",children:[n.jsxs("div",{className:"mb-1.5 flex items-center justify-between px-2 pt-1",children:[n.jsx("span",{className:"text-[10px] font-black text-[#182137]/50",children:v("walkthrough.exportQuality",{defaultValue:"איכות ייצוא"})}),n.jsx("span",{className:"text-[9px] font-bold text-[#D85D43]",children:v("walkthrough.hqNotForModels",{defaultValue:"לא לשליחה למודל רינדור"})})]}),n.jsx("div",{className:"grid grid-cols-3 gap-1",children:Object.keys(a1).map(W=>{const S=i===W;return n.jsx("button",{type:"button",onClick:()=>b(W),className:O("rounded-xl px-2 py-2 text-[11px] font-black transition-all duration-150",S?"bg-[#182137] text-white shadow-[0_6px_14px_rgba(24,33,55,0.22)]":"bg-transparent text-[#182137]/70 hover:bg-[#F4F1EA] hover:text-[#182137]"),children:a1[W].label},W)})})]})]})]}),n.jsxs("div",{className:"relative border-t border-[#182137]/10 px-4 pb-4 pt-1",children:[n.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] font-black text-[#182137]/70",children:[n.jsx(Ok,{className:"h-3.5 w-3.5",strokeWidth:2.2}),v("walkthrough.myTours",{defaultValue:"הסיורים שלי"})]}),c.length>0&&n.jsx("span",{className:"rounded-full bg-[#E8DFD3] px-2 py-0.5 text-[9px] font-black text-[#182137]/70",children:c.length})]}),n.jsx("div",{className:"max-h-[360px] space-y-2.5 overflow-y-auto pe-0.5",children:c.length===0?n.jsxs("div",{className:"rounded-2xl border border-dashed border-[#182137]/14 bg-white/60 px-4 py-8 text-center",children:[n.jsx("div",{className:"mx-auto mb-3 flex h-12 w-12 items-center justify-center rounded-2xl bg-[linear-gradient(145deg,#FFE8DE_0%,#F7F4EF_100%)] text-[#D85D43]",children:n.jsx(Ok,{className:"h-5 w-5",strokeWidth:2.2})}),n.jsx("div",{className:"text-[12px] font-black text-[#182137]/70",children:v("walkthrough.emptyTitle",{defaultValue:"אין סיורי וידאו עדיין"})}),n.jsx("div",{className:"mt-1 text-[10px] font-semibold text-[#182137]/45",children:v("walkthrough.emptyDescription",{defaultValue:"הקליטו סיור, הזיזו את המצלמה במפה, ושמרו MP4 מוכן לשיתוף"})})]}):c.map(W=>n.jsx(hH,{recording:W,active:d===W.id,fpIsDark:t,walkthroughStatus:e,exportMode:r,exportProgress:a,onPlay:()=>g(W),onExport:()=>w(W),onRename:()=>k(W),onDelete:()=>_(W)},W.id))})]})]})}const fH={offsetX:0,offsetY:0,zoom:1},cF=50,xH=.1,pH=10,gH=55e-5,bH=120,Kv=140;function Zv(t,e,s){return{x:(t-s.offsetX)/s.zoom,y:(e-s.offsetY)/s.zoom}}function Wu(t,e,s,o,r,i){let a=(t-s.offsetX)/s.zoom,l=(e-s.offsetY)/s.zoom;if(i%360===0)return{x:a,y:l};const c=-i*Math.PI/180,d=o/2,u=r/2;a-=d,l-=u;const h=Math.cos(c),x=Math.sin(c);return{x:a*h-l*x+d,y:a*x+l*h+u}}function $a(t,e,s,o,r,i){let a=t,l=e;if(i%360!==0){const c=i*Math.PI/180,d=o/2,u=r/2;a-=d,l-=u;const h=Math.cos(c),x=Math.sin(c),f=a*h-l*x,p=a*x+l*h;a=f+d,l=p+u}return{sx:a*s.zoom+s.offsetX,sy:l*s.zoom+s.offsetY}}function qv(t,e,s){const o=(s%360+360)%360;return o===90||o===270?{effW:e,effH:t}:{effW:t,effH:e}}function Jv(t,e,s){return t>=e===(s==="landscape")?0:90}function _2(t,e,s,o){if(e===0)return t;const r=Math.sign(e)*Math.min(Math.abs(e),bH),i=Math.exp(r*gH),a=Math.min(pH,Math.max(xH,t.zoom*i)),l=a/t.zoom;return{zoom:a,offsetX:s-(s-t.offsetX)*l,offsetY:o-(o-t.offsetY)*l}}function bg(t,e,s){return{...t,offsetX:t.offsetX+e,offsetY:t.offsetY+s}}function Qv(t,e,s,o){const a=Math.min((s-80)/t,(o-80)/e)*.75;return{zoom:a,offsetX:(s-t*a)/2+cF,offsetY:(o-e*a)/2}}function dF(t,e,s){const o=t.find(u=>u.id===e);if(!o)return null;const r=`furn_${Date.now()}_${Math.random().toString(36).slice(2,6)}`,i=pi[o.type]||{width:800},a=50/s,l=(o.widthMm??Math.round(i.width*(o.scale||1)))/s,c=Math.max(a,Math.min(l*.35,180/s)),d={...o,id:r,position:{x:o.position.x+c,y:o.position.y+c}};return{next:[...t,d],newId:r}}function uF(t){const e=t.preset?qs[t.preset]:null;return t.widthMm??(e==null?void 0:e.width)??Kc[t.type].width}function MH(t){return Math.hypot(t.end.x-t.start.x,t.end.y-t.start.y)}function tj(t,e){return uF(t)/e/2}function yH(t,e,s){return t-e>=-1e-6&&t+e<=s+1e-6}function wH(t,e,s,o){return Math.abs(t-s)<e+o-1e-6}function kH(t,e,s,o,r){const i=tj(e,r);if(!yH(t,i,o))return!1;for(const a of s){if(a.id===e.id||a.wallId!==e.wallId)continue;const l=tj(a,r);if(wH(t,i,a.positionPx,l))return!1}return!0}function Z1(t,e,s,o,r="auto"){const i=t.find(u=>u.id===e);if(!i||o<=0)return null;const a=s.find(u=>u.id===i.wallId);if(!a)return null;const l=MH(a),c=uF(i)/o,d=[];(r==="right"||r==="auto")&&d.push(i.positionPx+c),(r==="left"||r==="auto")&&d.push(i.positionPx-c);for(const u of d){if(!kH(u,i,t,l,o))continue;const h=`op_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,x={...i,id:h,positionPx:u},f=[...t,x];return{next:f,newId:h,newIdx:f.length-1}}return null}function ej({preset:t,selectedWallRegionId:e,figureInteracting:s=!1,figureRotateMode:o=!1,sketchToolActive:r=!1,sketchElementMoveActive:i=!1}){return t==="inside"&&!!e||s||o||r||i}function vH({compact:t=!1,activeTool:e=null,selectedEntityId:s=null}){const o=!t&&Xy(e),r=!t&&!!s;return{sketchToolActive:o,sketchSelectionActive:r,sketchInteractionActive:o||r}}const Zu=400,hF=Zu,mF=800,Ci=12,O3=5,nm=16,Jy=48,jH=180,_H=300;function EH(t,e,s=nm){return e?{x:nm,y:s}:{x:Math.max(nm,t.width-Jy-nm),y:s}}const fF=12,xF=14,pF=220,gF=28,Qy=44,DH=10,FH=100;function CH(t,e,s,o={leftPx:fF,bottomPx:xF,sizePx:pF}){const r=Math.max(Ci,t.width-e-nm),i=t.height-o.bottomPx-o.sizePx-DH-FH-s;return{x:Math.min(Math.max(o.leftPx,Ci),r),y:Math.max(Ci,i)}}function NH(t,e,s){const o=Math.max(Ci,t.width-e-nm);return{x:Math.min(Math.max(fF,Ci),o),y:Math.max(Ci,t.height-xF-s)}}function IH(t,e,s,o){return bF(t,e,s,o)}function bF(t,e,s,o){const r=Math.max(Ci,e.width-s-nm),i=Math.max(Ci,e.height-o-Ci);return{x:Math.min(Math.max(t.x,Ci),r),y:Math.min(Math.max(t.y,Ci),i)}}const TH=36,SH=8,PH=180,AH=8;function LH(t,e,s,o,r=AH){const i=typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:1440,height:900};let a=t,l=e;return l+o>i.height-r&&(l=e-o),l=Math.max(r,Math.min(l,i.height-o-r)),a+s>i.width-r&&(a=t-s),a=Math.max(r,Math.min(a,i.width-s-r)),{x:a,y:l}}function WH(t){return SH+t*TH}const RH=360,OH=560,HH=20;function nj(t,e,s=RH,o=OH,r=Ci){const i=typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:1440,height:900},a=HH;let l=t+a;l+s>i.width-r&&(l=t-s-a),l=Math.max(r,Math.min(l,i.width-s-r));let c=e-o*.42;const d=e-28;return c>d&&(c=d),c=Math.max(r,Math.min(c,i.height-o-r)),{x:l,y:c}}const BH=96,VH="floorplan.detailsPanelPosition.v1",MF="floorplan.detailsPanelWidth.v1",oj="floorplan.detailsPanelOpen.v1",sj="floorplan.detailsSectionsOpen.v2",rj="floorplan.detailsSectionVisibility.v1",ij="floorplan.detailsSectionOrder.v1";function zH(t){return typeof t!="number"||!Number.isFinite(t)?Zu:Math.max(hF,Math.min(mF,Math.round(t)))}function aj(t,e=Zu){return{x:Math.max(Ci,t.width-e-O3),y:Ci}}function H3(t,e,s=Zu){const o=Math.max(Ci,e.width-s-O3),r=Math.max(Ci,e.height-BH);return{x:Math.min(Math.max(t.x,Ci),o),y:Math.min(Math.max(t.y,Ci),r)}}function l1(t,e,s=Zu){if(!t||typeof t!="object")return aj(e,s);const o=t;return typeof o.x!="number"||typeof o.y!="number"||!Number.isFinite(o.x)||!Number.isFinite(o.y)?aj(e,s):H3({x:o.x,y:o.y},e,s)}function Qh(t){if(t){const e=t.getBoundingClientRect();return{width:e.width,height:e.height}}return typeof window>"u"?{width:1440,height:900}:{width:window.innerWidth,height:Math.max(240,window.innerHeight-96)}}function $H(t,e,s,o){const r=Qh(e);if(typeof window>"u"||!t)return o?o(r):l1(null,r,s);try{const i=window.localStorage.getItem(t);return l1(i?JSON.parse(i):null,r,s)}catch{return o?o(r):l1(null,r,s)}}function B3({viewportFrameRef:t,storageKey:e,enabled:s=!0,getDefaultPosition:o,clampPosition:r,panelWidth:i=Zu,resetPositionKey:a}){const l=m.useCallback((g,w)=>r?r(g,w):H3(g,w,i),[r,i]),[c,d]=m.useState(()=>$H(e,null,i,o)),[u,h]=m.useState(!1),x=m.useRef(null);m.useEffect(()=>{if(!(!s||!e)&&!(typeof window>"u"))try{window.localStorage.setItem(e,JSON.stringify(c))}catch{}},[c,e,s]),m.useEffect(()=>{const g=t.current;if(!g)return;const w=()=>{const _=Qh(g);d(j=>l(j,_))};d(_=>{const j=Qh(g);return l(_,j)}),h(!0);const k=new ResizeObserver(w);return k.observe(g),window.addEventListener("resize",w),()=>{k.disconnect(),window.removeEventListener("resize",w)}},[t,e,l]),m.useEffect(()=>{if(!s)return;const g=t.current;if(!g)return;const w=Qh(g);d(k=>l(k,w))},[l,s,t]),m.useEffect(()=>{if(!s||a===void 0)return;const g=t.current,w=Qh(g),k=o?o(w):l1(null,w,i);d(l(k,w))},[a,s,t,o,l,i]);const f=m.useCallback(g=>{g.button===0&&s&&(g.currentTarget.setPointerCapture(g.pointerId),x.current={pointerId:g.pointerId,startClientX:g.clientX,startClientY:g.clientY,startX:c.x,startY:c.y})},[s,c.x,c.y]),p=m.useCallback(g=>{const w=x.current;if(!w||w.pointerId!==g.pointerId)return;const k=Qh(t.current),_=l({x:w.startX+g.clientX-w.startClientX,y:w.startY+g.clientY-w.startClientY},k);d(_)},[t,l]),b=m.useCallback(g=>{var w;((w=x.current)==null?void 0:w.pointerId)===g.pointerId&&(x.current=null)},[]);return{position:c,setPosition:d,ready:u,headerProps:{onPointerDown:f,onPointerMove:p,onPointerUp:b,onPointerCancel:b}}}const tw=1.6,q1=85*Math.PI/180,V3=15,lj=58,XH="rgba(255, 230, 60, 0.42)",YH="rgba(255, 230, 60, 0.58)",GH="rgba(255, 196, 0, 0.88)",cj="#0a0f18",dj="#000000";function Px(t){return typeof t=="number"&&Number.isFinite(t)}
266function Rf(t){if(!Number.isFinite(t))return 0;let e=t%(Math.PI*2);return e<=-Math.PI&&(e+=Math.PI*2),e>Math.PI&&(e-=Math.PI*2),e}function uj(t){if(!t||typeof t!="object")return null;const e=t;return!Px(e.x)||!Px(e.z)?null:{x:e.x,z:e.z,angle:Rf(Px(e.angle)?e.angle:0),fov:Px(e.fov)?Math.min(Math.max(e.fov,20*Math.PI/180),130*Math.PI/180):q1,height:Px(e.height)?Math.min(Math.max(e.height,.3),6):tw}}function yF(t,e,s={}){const o=(e==null?void 0:e.x)??t.centerX,r=(e==null?void 0:e.z)??t.centerZ,i=mm(t),a=Math.max(t.maxX-t.minX,i*.45),l=Math.max(t.maxZ-t.minZ,i*.45);return a>=l?{x:o-a*.3,z:r,angle:Math.PI/2,fov:s.fov??q1,height:s.height??tw}:{x:o,z:r-l*.3,angle:0,fov:s.fov??q1,height:s.height??tw}}function z3(t,e,s){if(s===0)return{x:t.x,z:t.z};const o=t.x-e.x,r=t.z-e.z,i=Math.cos(s),a=Math.sin(s);return{x:e.x+o*i+r*a,z:e.z-o*a+r*i}}function wF(t,e){const s=Math.sin(t),o=Math.cos(t),r=Math.cos(e),i=Math.sin(e);return Rf(Math.atan2(s*r+o*i,-s*i+o*r))}function UH(t,e,s){const o=-(s*Math.PI)/180,r={x:e.centerX,z:e.centerZ},i=z3({x:t.x,z:t.z},r,o);return{...t,x:i.x,z:i.z,angle:wF(t.angle,o)}}function KH(t,e,s){const o=s*Math.PI/180,r={x:e.centerX,z:e.centerZ},i=z3({x:t.x,z:t.z},r,o);return{...t,x:i.x,z:i.z,angle:wF(t.angle,o)}}function kF(t,e,s,o,r,i,a){const l=i/2,c=s+Math.sin(r-l)*a,d=o+Math.cos(r-l)*a,u=s+Math.sin(r+l)*a,h=o+Math.cos(r+l)*a,x=(t-u)*(o-h)-(s-u)*(e-h),f=(t-c)*(h-d)-(u-c)*(e-d),p=(t-s)*(d-o)-(c-s)*(e-o),b=x<0||f<0||p<0,M=x>0||f>0||p>0;return!(b&&M)}function vF(t,e,s,o,r=V3){const i=t-s,a=e-o;return i*i+a*a<=r*r}function jF(t,e){const{x:s,y:o,angle:r,fov:i,coneLen:a,activeMode:l=null,bodyScale:c=1}=e,d=i/2,u=s+Math.sin(r-d)*a,h=o+Math.cos(r-d)*a,x=s+Math.sin(r+d)*a,f=o+Math.cos(r+d)*a;t.fillStyle=l==="rotate"?YH:XH,t.beginPath(),t.moveTo(s,o),t.lineTo(u,h),t.lineTo(x,f),t.closePath(),t.fill(),t.strokeStyle=GH,t.lineWidth=2,t.beginPath(),t.moveTo(s,o),t.lineTo(u,h),t.moveTo(s,o),t.lineTo(x,f),t.stroke();const p=l==="move";t.save(),t.translate(s,o),t.rotate(Math.atan2(Math.cos(r),Math.sin(r))),t.scale(c,c);const b=19,M=14,g=6,w=8;t.translate(-15.5,0),t.fillStyle=p?dj:cj,t.beginPath(),t.roundRect(-b/2,-M/2,b,M,2.5),t.fill(),t.strokeStyle="#ffffff",t.lineWidth=2.25,t.stroke(),t.fillStyle=p?dj:cj,t.beginPath(),t.roundRect(b/2-.5,-w/2,g+.5,w,1.5),t.fill(),t.restore()}function Jx(t,e,s,o,r){if(r%360===0)return{wx:t,wz:e};const i=r*Math.PI/180,a=t-s,l=e-o,c=a*Math.cos(i)-l*Math.sin(i),d=a*Math.sin(i)+l*Math.cos(i);return{wx:s+c,wz:o+d}}function ZH(t,e,s){const o=e.centerX,r=e.centerZ;let i=1/0,a=-1/0,l=1/0,c=-1/0;for(const d of t)if(!(!d.start||!d.end))for(const u of[d.start,d.end]){const h=(u.x??0)*rt,x=(u.y??0)*rt,f=Jx(h,x,o,r,s);i=Math.min(i,f.wx),a=Math.max(a,f.wx),l=Math.min(l,f.wz),c=Math.max(c,f.wz)}return isFinite(i)?{minX:i,maxX:a,minZ:l,maxZ:c,centerX:(i+a)/2,centerZ:(l+c)/2,span:Math.max(a-i,c-l,.1)}:e}function qH(t,e,s){if(!(e!=null&&e.length))return[];const o=new Set(e.filter(i=>!!i.templateId||!!i.presetKind).map(i=>i.id));if(o.size===0)return[];const r=[];for(const i of t)i.kind==="polygon"&&(!i.groupId||!o.has(i.groupId)||!i.vertices||i.vertices.length<3||r.push({id:i.id,corners:i.vertices.map(a=>({x:a.x*rt,z:a.y*rt})),selected:i.id===s}));return r}const hj=220,E2=12;function JH(t,e){const s=m.useRef(!1),o=m.useMemo(()=>({onPointerDown:i=>{s.current=!1,t.onPointerDown(i)},onPointerMove:i=>{s.current=!0,t.onPointerMove(i)},onPointerUp:i=>{t.onPointerUp(i)},onPointerCancel:i=>{t.onPointerCancel(i)}}),[t]),r=m.useCallback(()=>{if(s.current){s.current=!1;return}e()},[e]);return{dragProps:o,handleActivate:r}}function QH({walls:t,furniture:e=[],templateFootprints:s=[],selectedFurnitureIds:o,bounds:r,planRotationDeg:i=0,cameraPoseRef:a,onMove:l,onRotate:c,size:d=hj,controlMode:u="normal",onDriveTarget:h,onDriveEnd:x,pathPoints:f=[],playhead:p=null,collapsed:b=!1,onExpand:M,onCollapse:g,viewportFrameRef:w}){const{t:k,i18n:_}=yn(),j=m.useRef(null),v=m.useRef(0),C=m.useRef(null),N=m.useRef(null),P=Math.max(190,d),L=P-E2*2,A=58*(P/hj),W=b?Qy:P,S=b?Qy:P+gF,B=m.useCallback(ht=>NH(ht,W,S),[W,S]),R=m.useCallback((ht,gt)=>IH(ht,gt,W,S),[W,S]),{position:z,ready:X,headerProps:ft}=B3({viewportFrameRef:w,getDefaultPosition:B,clampPosition:R,resetPositionKey:P}),{dragProps:tt,handleActivate:G}=JH(ft,()=>M==null?void 0:M()),Y={left:z.x,top:z.y,visibility:X?"visible":"hidden"},J=m.useMemo(()=>ZH(t,r,i),[t,r,i]),{minX:Mt,maxX:Rt,minZ:it,maxZ:st}=J,ct=Rt-Mt||1,pt=st-it||1,xt=L/Math.max(ct,pt),_t=E2+(L-ct*xt)/2,Ft=E2+(L-pt*xt)/2,Vt=m.useCallback(ht=>_t+(ht-Mt)*xt,[_t,Mt,xt]),vt=m.useCallback(ht=>Ft+(ht-it)*xt,[Ft,it,xt]),Ht=m.useCallback((ht,gt)=>({wx:(ht-_t)/xt+Mt,wz:(gt-Ft)/xt+it}),[_t,Ft,xt,Mt,it]),Tt=m.useCallback(ht=>{const gt=ht.currentTarget.getBoundingClientRect();return{mx:ht.clientX-gt.left,mz:ht.clientY-gt.top}},[]),Zt=m.useCallback((ht,gt)=>{const Pt=a.current;if(!Pt)return!1;const U=Vt(Pt.x),mt=vt(Pt.z),Nt=Pt.angle;return kF(ht,gt,U,mt,Nt,Pt.fov,A)},[a,Vt,vt,A]),At=m.useCallback((ht,gt)=>{const Pt=a.current;if(!Pt)return!1;const U=Vt(Pt.x),mt=vt(Pt.z);return vF(ht,gt,U,mt,V3)},[a,Vt,vt]),ut=m.useCallback(ht=>{ht.currentTarget.setPointerCapture(ht.pointerId);const{mx:gt,mz:Pt}=Tt(ht);if(At(gt,Pt))C.current="move",N.current="steer";else if(Zt(gt,Pt)){C.current="rotate",N.current=null;const U=a.current;if(U){const mt=Vt(U.x),Nt=vt(U.z),Lt=Math.atan2(gt-mt,Pt-Nt);c(Lt)}}else{C.current="move",N.current="destination";const{wx:U,wz:mt}=Ht(gt,Pt);u==="recording"&&h?h(U,mt,"destination"):l(U,mt)}},[Tt,At,Zt,a,Vt,vt,Ht,l,c,u,h]),kt=m.useCallback(ht=>{const gt=C.current;if(!gt){const{mx:mt,mz:Nt}=Tt(ht);At(mt,Nt)?ht.currentTarget.style.cursor="grab":Zt(mt,Nt)?ht.currentTarget.style.cursor="crosshair":ht.currentTarget.style.cursor="pointer";return}const{mx:Pt,mz:U}=Tt(ht);if(gt==="move"){const{wx:mt,wz:Nt}=Ht(Pt,U);u==="recording"&&h?(N.current="steer",h(mt,Nt,"steer")):l(mt,Nt)}else if(gt==="rotate"){const mt=a.current;if(!mt)return;const Nt=Vt(mt.x),Lt=vt(mt.z),oe=Math.atan2(Pt-Nt,U-Lt);c(oe)}},[Tt,At,Zt,Ht,a,Vt,vt,l,c,u,h]),Et=m.useCallback(()=>{const ht=N.current;C.current=null,N.current=null,ht==="steer"&&(x==null||x(ht))},[x]);return m.useEffect(()=>{if(b)return;const ht=j.current;if(!ht)return;const gt=ht.getContext("2d"),Pt=window.devicePixelRatio||1;ht.width=P*Pt,ht.height=P*Pt,gt.scale(Pt,Pt);const U=Qt=>_t+(Qt-Mt)*xt,mt=Qt=>Ft+(Qt-it)*xt,Nt=r.centerX,Lt=r.centerZ,oe=t.filter(Qt=>Qt.start&&Qt.end).map(Qt=>{const te=(Qt.start.x??0)*rt,Be=(Qt.start.y??0)*rt,wt=(Qt.end.x??0)*rt,ve=(Qt.end.y??0)*rt,Ne=Jx(te,Be,Nt,Lt,i),Le=Jx(wt,ve,Nt,Lt,i);return{x1:U(Ne.wx),z1:mt(Ne.wz),x2:U(Le.wx),z2:mt(Le.wz)}}),he=e.filter(Qt=>Qt.position&&(Qt.width??0)>0&&(Qt.depth??0)>0).map(Qt=>{const te=(Qt.position.x??0)*rt,Be=(Qt.position.y??0)*rt,wt=(Qt.width??0)*rt,ve=(Qt.depth??0)*rt,Ne=-((Qt.rotation??0)*Math.PI)/180,Le=Math.cos(Ne),is=Math.sin(Ne),Fe=[{x:-wt/2,z:-ve/2},{x:wt/2,z:-ve/2},{x:wt/2,z:ve/2},{x:-wt/2,z:ve/2}].map(bn=>{const Ve=te+bn.x*Le-bn.z*is,en=Be+bn.x*is+bn.z*Le,on=Jx(Ve,en,Nt,Lt,i);return{x:U(on.wx),z:mt(on.wz)}});return{id:Qt.id,corners:Fe,selected:!!Qt.id&&!!(o!=null&&o.has(Qt.id))}}),pe=s.filter(Qt=>Qt.corners.length>=3).map(Qt=>({id:Qt.id,corners:Qt.corners.map(({x:te,z:Be})=>{const wt=Jx(te,Be,Nt,Lt,i);return{x:U(wt.wx),z:mt(wt.wz)}}),selected:!!Qt.selected})),Ge=()=>{gt.clearRect(0,0,P,P),gt.fillStyle="#F7F4EF",gt.beginPath(),gt.roundRect(0,0,P,P,12),gt.fill();const Qt=C.current!==null;gt.strokeStyle=Qt?"rgba(255, 196, 0, 0.55)":"rgba(15,23,42,0.12)",gt.lineWidth=Qt?2:1,gt.beginPath(),gt.roundRect(0,0,P,P,12),gt.stroke();for(const Ne of he)if(Ne.corners.length===4){gt.beginPath(),gt.moveTo(Ne.corners[0].x,Ne.corners[0].z);for(let Le=1;Le<Ne.corners.length;Le++)gt.lineTo(Ne.corners[Le].x,Ne.corners[Le].z);gt.closePath(),gt.fillStyle=Ne.selected?"rgba(51,108,255,0.28)":"rgba(216,75,46,0.24)",gt.strokeStyle=Ne.selected?"rgba(51,108,255,0.9)":"rgba(145,64,42,0.72)",gt.lineWidth=Ne.selected?2:1.25,gt.fill(),gt.stroke()}for(const Ne of pe){gt.beginPath(),gt.moveTo(Ne.corners[0].x,Ne.corners[0].z);for(let Le=1;Le<Ne.corners.length;Le++)gt.lineTo(Ne.corners[Le].x,Ne.corners[Le].z);gt.closePath(),gt.fillStyle=Ne.selected?"rgba(51,108,255,0.32)":"rgba(24,33,55,0.14)",gt.strokeStyle=Ne.selected?"rgba(51,108,255,0.92)":"rgba(24,33,55,0.62)",gt.lineWidth=Ne.selected?1.75:1,gt.setLineDash(Ne.selected?[]:[3,2]),gt.fill(),gt.stroke(),gt.setLineDash([])}gt.strokeStyle="#374151",gt.lineWidth=2,gt.lineCap="round";for(const Ne of oe)gt.beginPath(),gt.moveTo(Ne.x1,Ne.z1),gt.lineTo(Ne.x2,Ne.z2),gt.stroke();f.length>1&&(gt.strokeStyle="rgba(51,108,255,0.78)",gt.lineWidth=P>=260?3:2,gt.lineJoin="round",gt.lineCap="round",gt.beginPath(),f.forEach((Ne,Le)=>{const is=U(Ne.x),Fe=mt(Ne.z);Le===0?gt.moveTo(is,Fe):gt.lineTo(is,Fe)}),gt.stroke());const te=a.current;if(!te){v.current=requestAnimationFrame(Ge);return}const Be=U(te.x),wt=mt(te.z),ve=te.angle;jF(gt,{x:Be,y:wt,angle:ve,fov:te.fov,coneLen:A,activeMode:C.current}),p&&(gt.fillStyle="#336CFF",gt.strokeStyle="#ffffff",gt.lineWidth=2,gt.beginPath(),gt.arc(U(p.x),mt(p.z),P>=260?6:4,0,Math.PI*2),gt.fill(),gt.stroke()),v.current=requestAnimationFrame(Ge)};return v.current=requestAnimationFrame(Ge),()=>cancelAnimationFrame(v.current)}
266,[b,t,e,s,o,r,i,a,_t,Ft,xt,Mt,it,P,A,f,p]),b?n.jsx("div",{className:"pointer-events-auto absolute z-10 font-heebo",style:Y,children:n.jsx("button",{type:"button","aria-label":k("viewer.minimap.show",{defaultValue:"הצג מפה"}),title:k("viewer.minimap.showTitle",{defaultValue:"הצג מפה — לחץ לפתיחה, גרור להזזה"}),onClick:G,className:O("flex h-11 w-11 cursor-move items-center justify-center rounded-xl border shadow-lg backdrop-blur transition","border-[#182137]/10 bg-white/90 text-[#182137] hover:bg-white"),...tt,children:n.jsx(D1,{size:16,strokeWidth:2})})}):n.jsx("div",{className:"pointer-events-auto absolute z-10 font-heebo",style:Y,children:n.jsxs("div",{className:"overflow-hidden rounded-2xl border border-[#182137]/14 bg-[#F7F4EF] shadow-[0_18px_50px_rgba(24,33,55,0.20)]",children:[n.jsxs("div",{dir:_.dir(),className:"flex h-7 cursor-move items-center justify-between border-b border-[#182137]/10 bg-[#FAF8F5] px-2",...ft,children:[n.jsx("span",{className:"text-[10px] font-semibold text-[#182137]/62",children:k("viewer.minimap.title",{defaultValue:"מפה"})}),g&&n.jsx("button",{type:"button","aria-label":k("viewer.minimap.collapse",{defaultValue:"מזער מפה"}),title:k("viewer.minimap.collapse",{defaultValue:"מזער מפה"}),onClick:g,onPointerDown:ht=>ht.stopPropagation(),className:"flex h-6 w-6 items-center justify-center rounded-md text-[#182137]/70 transition hover:bg-[#E8DFD3] hover:text-[#182137]",children:n.jsx(G_,{size:13,strokeWidth:2})})]}),n.jsx("canvas",{ref:j,width:P,height:P,style:{width:P,height:P},className:"block",onPointerDown:ut,onPointerMove:kt,onPointerUp:Et,onPointerLeave:Et})]})})}const tB=6,eB=.35;function _F(t){return Math.hypot(t.end.x-t.start.x,t.end.y-t.start.y)}function mj(t,e){const s=_F(t);if(!Number.isFinite(s)||s<=0)return null;const o={x:(t.end.x-t.start.x)/s,y:(t.end.y-t.start.y)/s};return e==="start"?{wall:t,cornerAt:e,point:t.start,lengthPx:s,awayUnit:o}:{wall:t,cornerAt:e,point:t.end,lengthPx:s,awayUnit:{x:-o.x,y:-o.y}}}function nB(t,e){return Math.hypot(t.x-e.x,t.y-e.y)<=tB}function fj(t,e){return t.cornerAt==="start"?e/2:t.lengthPx-e/2}function oB(t){return t==="corner_glass_door"}function EF(t,e,s,o){if(!Number.isFinite(o)||o<=0)return null;const r=qs.corner_glass_door,i=t.find(M=>M.id===e);if(!i)return null;const a=_F(i),l=r.width/o;if(!Number.isFinite(a)||a<=0||!Number.isFinite(l)||l<=0||a<l)return null;const c=Math.abs(s),d=Math.abs(a-s),u=c<=d?"start":"end",h=Math.min(c,d),x=Math.max(48,l);if(h>x)return null;const f=mj(i,u);if(!f)return null;let p=null,b=Number.POSITIVE_INFINITY;for(const M of t)if(M.id!==i.id)for(const g of["start","end"]){const w=mj(M,g);if(!w||w.lengthPx<l||!nB(f.point,w.point))continue;const k=Math.abs(f.awayUnit.x*w.awayUnit.x+f.awayUnit.y*w.awayUnit.y);k>eB||k<b&&(b=k,p=w)}return p?{preset:"corner_glass_door",type:"door",widthMm:r.width,widthPx:l,corner:f.point,primary:{wallId:f.wall.id,positionPx:fj(f,l),cornerAt:f.cornerAt},return:{wallId:p.wall.id,positionPx:fj(p,l),cornerAt:p.cornerAt}}:null}function DF(t,e){return[{id:e.primaryId,type:"door",preset:"corner_glass_door",wallId:t.primary.wallId,positionPx:t.primary.positionPx,cornerGroupId:e.groupId,cornerArm:"primary"},{id:e.returnId,type:"door",preset:"corner_glass_door",wallId:t.return.wallId,positionPx:t.return.positionPx,cornerGroupId:e.groupId,cornerArm:"return"}]}function FF(t){return oB(t)}const sB=[{hingeSide:"left",swingFace:"front"},{hingeSide:"right",swingFace:"front"},{hingeSide:"left",swingFace:"back"},{hingeSide:"right",swingFace:"back"}];function $3({value:t,onChange:e,fpIsDark:s,faceLabels:o,compact:r=!1}){const{t:i}=yn(),{isRTL:a}=Yd(),l=o??{front:i("openingEditor.openForward",{defaultValue:"פתיחה קדימה"}),back:i("openingEditor.openBackward",{defaultValue:"פתיחה אחורה"})},c=()=>{e({...t,hingeSide:t.hingeSide==="left"?"right":"left"})},d=()=>{e({...t,swingFace:t.swingFace==="front"?"back":"front"})};return n.jsxs("div",{className:O("space-y-3",r&&"space-y-2.5"),children:[n.jsx("div",{className:"grid grid-cols-2 gap-2",children:sB.map(u=>{const h=u.hingeSide===t.hingeSide&&u.swingFace===t.swingFace;return n.jsxs("button",{type:"button",onClick:()=>e(u),className:O("rounded-xl border p-2 transition-all cursor-pointer",a?"text-right":"text-left",h?s?"border-[#F4A99A] bg-[#F4A99A]/15 shadow-[0_0_0_1px_rgba(244,169,154,0.18)]":"border-[#D84B2E] bg-[#FDF6F4] shadow-[0_0_0_1px_rgba(216,75,46,0.14)]":s?"border-white/10 bg-white/[0.04] hover:bg-white/[0.07]":"border-[#182137]/10 bg-white hover:bg-[#FAF6F0]"),"aria-pressed":h,children:[n.jsx(rB,{value:u,active:h,fpIsDark:s}),n.jsx("div",{className:O("mt-1.5 text-[10px] font-semibold",s?"text-white/85":"text-[#30283a]"),children:u.hingeSide==="left"?i("openingEditor.hingeLeft",{defaultValue:"ציר שמאל"}):i("openingEditor.hingeRight",{defaultValue:"ציר ימין"})}),n.jsx("div",{className:O("text-[9px]",s?"text-white/55":"text-[#6f6677]"),children:l[u.swingFace]})]},`${u.hingeSide}-${u.swingFace}`)})}),n.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[n.jsx("button",{type:"button",onClick:c,className:O("rounded-xl px-2.5 py-2 text-[10px] font-semibold transition-all cursor-pointer",s?"bg-white/10 text-white/80 hover:bg-white/15":"bg-[#182137]/[
2660.06] text-[#30283a] hover:bg-[#182137]/[0.09]"),children:i("openingEditor.flipHinge",{defaultValue:"הפוך ציר"})}),n.jsx("button",{type:"button",onClick:d,className:O("rounded-xl px-2.5 py-2 text-[10px] font-semibold transition-all cursor-pointer",s?"bg-white/10 text-white/80 hover:bg-white/15":"bg-[#182137]/[0.06] text-[#30283a] hover:bg-[#182137]/[0.09]"),children:i("openingEditor.flipDirection",{defaultValue:"הפוך כיוון"})})]})]})}function rB({value:t,active:e,fpIsDark:s}){const o=t.hingeSide==="left"?23:69,r=t.hingeSide==="left"?69:23,i=t.swingFace==="front"?12:58,a=t.hingeSide==="left"?o+32:o-32,l=t.swingFace==="front"?17:53,c=(o+a)/2,d=e?"#D84B2E":s?"#F4A99A":"#8C5A44",u=s?"#F5EDE6":"#182137",h=e?"#F4A99A":"#E8D5C8";return n.jsxs("svg",{viewBox:"0 0 92 70",className:"h-[58px] w-full","aria-hidden":!0,children:[n.jsx("path",{d:"M8 34 H23 M69 34 H84",stroke:u,strokeWidth:"5",strokeLinecap:"round",opacity:"0.82"}),n.jsx("path",{d:"M23 34 H69",stroke:u,strokeWidth:"1.4",strokeDasharray:"3 3",opacity:"0.32"}),n.jsx("path",{d:`M ${o} 34 Q ${c} ${l} ${a} ${i}`,fill:"none",stroke:d,strokeWidth:"2",strokeLinecap:"round"}),n.jsx("path",{d:`M ${o} 34 L ${a} ${i}`,stroke:h,strokeWidth:"7",strokeLinecap:"round",opacity:"0.72"}),n.jsx("path",{d:`M ${o} 34 L ${r} 34`,stroke:d,strokeWidth:"2.5",strokeLinecap:"round"}),n.jsx("circle",{cx:o,cy:"34",r:"4.2",fill:d}),n.jsx("circle",{cx:r,cy:"34",r:"2.4",fill:s?"#F5EDE6":"#30283a"}),n.jsx("path",{d:`M ${a-(t.hingeSide==="left"?5:-5)} ${i+(t.swingFace==="front"?2:-2)} L ${a} ${i} L ${a-(t.hingeSide==="left"?1:-1)} ${i+(t.swingFace==="front"?7:-7)}`,fill:"none",stroke:d,strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round"})]})}function X3({value:t,onChange:e,fpIsDark:s,labels:o,compact:r=!1}){const{t:i}=yn(),{isRTL:a}=Yd(),l=o??{front:i("openingEditor.flushForward",{defaultValue:"קו 0 קדימה"}),back:i("openingEditor.flushBackward",{defaultValue:"קו 0 אחורה"})};return n.jsx("div",{className:O("grid grid-cols-2 gap-2",r&&"gap-1.5"),children:["front","back"].map(c=>{const d=t===c;return n.jsxs("button",{type:"button",onClick:()=>e(c),className:O("rounded-xl border px-2.5 py-2 transition-all cursor-pointer active:translate-y-px",a?"text-right":"text-left",d?s?"border-[#F4A99A] bg-[#F4A99A]/15 shadow-[0_2px_0_rgba(244,169,154,0.14)]":"border-[#D84B2E] bg-[#FDF6F4] shadow-[0_2px_0_rgba(216,75,46,0.12)]":s?"border-white/10 bg-white/[0.04] hover:bg-white/[0.07]":"border-[#182137]/10 bg-white hover:bg-[#FAF6F0]"),"aria-pressed":d,children:[n.jsx(iB,{face:c,active:d,fpIsDark:s}),n.jsx("div",{className:O("mt-1.5 text-[10px] font-bold",s?"text-white/85":"text-[#30283a]"),children:l[c]})]},c)})})}function iB({face:t,active:e,fpIsDark:s}){const o=s?"#F5EDE6":"#182137",r=e?"#F4A99A":"#E8D5C8",i=e?"#D84B2E":s?"#F4A99A":"#8C5A44",a=t==="front"?20:50;return n.jsxs("svg",{viewBox:"0 0 92 70",className:"h-[44px] w-full","aria-hidden":!0,children:[n.jsx("path",{d:"M9 35 H83",stroke:o,strokeWidth:"12",strokeLinecap:"round",opacity:"0.18"}),n.jsx("path",{d:"M9 35 H28 M64 35 H83",stroke:o,strokeWidth:"6",strokeLinecap:"round",opacity:"0.78"}),n.jsx("path",{d:"M28 35 H64",stroke:o,strokeWidth:"1.4",strokeDasharray:"3 3",opacity:"0.34"}),n.jsx("rect",{x:"30",y:a-5,width:"32",height:"10",rx:"1.5",fill:r,stroke:i,strokeWidth:"1.8"}),n.jsx("path",{d:`M30 ${a-8} H62`,stroke:i,strokeWidth:"2.4",strokeLinecap:"round"}),n.jsx("path",{d:`M30 ${a+8} H62`,stroke:i,strokeWidth:"1.2",strokeLinecap:"round",opacity:"0.55"})]})}const aB=1.75,lB="https://kibuqatinwtuqlzmryvx.supabase.co/storage/v1/object/public/system-textures/floorplanmanimage.glb",CF=2.1,Wh=.45,Ax="#EC7357",cB=["map","emissiveMap"],dB=["map","normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap","alphaMap","bumpMap","displacementMap","clearcoatMap","clearcoatNormalMap","clearcoatRoughnessMap","sheenColorMap","sheenRoughnessMap","specularIntensityMap","specularColorMap","transmissionMap"];function uB({bounds:t,position:e,rotation:s,rotateMode:o,onPositionChange:r,onRotationChange:i,onInteractingChange:a,onContextMenu:l}){const c=Vo(G=>G.gl),d=Vo(G=>G.camera),u=m.useMemo(()=>c.capabilities.getMaxAnisotropy(),[c]),h=Rw(db,lB,mb),x=m.useRef(null),f=m.useMemo(()=>new Ea,[]),p=m.useMemo(()=>new Ga(new le(0,1,0),0),[]),b=m.useMemo(()=>new Ga(new le(0,1,0),-CF),[]),M=m.useRef(!1),g=m.useRef(!1),w=m.useRef({x:0,z:0}),k=m.useMemo(()=>{const G=h.scene.clone(!0);G.traverse(it=>{if(it.isMesh||(it.raycast=()=>{}),it.isMesh){it.castShadow=!1,it.receiveShadow=!1;const st=Array.isArray(it.material)?it.material:[it.material];for(const ct of st)if(ct){for(const pt of dB){const xt=ct[pt];
266xt&&(xt.anisotropy=u,cB.includes(pt)&&(xt.colorSpace=gm),xt.needsUpdate=!0)}ct.needsUpdate=!0}}});const Y=new Hw().setFromObject(G),J=Y.getSize(new le),Mt=Y.getCenter(new le),Rt=J.y>.001?aB/J.y:1;return G.scale.setScalar(Rt),G.position.set(-Mt.x*Rt,-Y.min.y*Rt,-Mt.z*Rt),G},[h,u]),_=m.useMemo(()=>e||{x:t.centerX+T1.x,z:t.centerZ+T1.z},[e,t.centerX,t.centerZ]),j=s??pE,v=m.useCallback((G,Y,J)=>{var st;if(!((st=x.current)!=null&&st.parent))return null;const Mt=c.domElement.getBoundingClientRect(),Rt=new Po((G-Mt.left)/Mt.width*2-1,-((Y-Mt.top)/Mt.height)*2+1);f.setFromCamera(Rt,d);const it=new le;return f.ray.intersectPlane(J,it)?(x.current.parent.worldToLocal(it),it):null},[d,c,f]),C=m.useCallback(G=>{var J,Mt;if(G.button!==0||!r||o)return;G.stopPropagation();const Y=v(G.clientX,G.clientY,p);w.current=Y?{x:_.x-Y.x,z:_.z-Y.z}:{x:0,z:0},M.current=!0,a==null||a(!0),(Mt=(J=G.target).setPointerCapture)==null||Mt.call(J,G.pointerId)},[r,o,a,v,p,_.x,_.z]),N=m.useCallback(G=>{if(!M.current||!r)return;G.stopPropagation();const Y=v(G.clientX,G.clientY,p);Y&&r({x:Y.x+w.current.x,z:Y.z+w.current.z})},[r,v,p]),P=m.useCallback(G=>{var Y,J;M.current&&(G.stopPropagation(),M.current=!1,a==null||a(!1),(J=(Y=G.target).releasePointerCapture)==null||J.call(Y,G.pointerId))},[a]),L=m.useCallback(G=>{var Y,J;M.current&&(G.stopPropagation(),M.current=!1,a==null||a(!1),(J=(Y=G.target).releasePointerCapture)==null||J.call(Y,G.pointerId))},[a]),A=m.useCallback((G,Y)=>{if(!i)return;const J=v(G,Y,b);if(!J)return;const Mt=J.x-_.x,Rt=J.z-_.z;Math.abs(Mt)<1e-4&&Math.abs(Rt)<1e-4||i(Math.atan2(Mt,Rt))},[i,v,b,_.x,_.z]),W=m.useCallback(G=>{var Y,J;G.button===0&&i&&(G.stopPropagation(),g.current=!0,a==null||a(!0),(J=(Y=G.target).setPointerCapture)==null||J.call(Y,G.pointerId),A(G.clientX,G.clientY))},[i,a,A]),S=m.useCallback(G=>{g.current&&(G.stopPropagation(),A(G.clientX,G.clientY))},[A]),B=m.useCallback(G=>{var Y,J;g.current&&(G.stopPropagation(),g.current=!1,a==null||a(!1),(J=(Y=G.target).releasePointerCapture)==null||J.call(Y,G.pointerId))},[a]),R=m.useCallback(G=>{var Y,J;g.current&&(G.stopPropagation(),g.current=!1,a==null||a(!1),(J=(Y=G.target).releasePointerCapture)==null||J.call(Y,G.pointerId))},[a]),z=m.useCallback(G=>{l&&(G.stopPropagation(),l({x:G.clientX,y:G.clientY}))},[l]),X=o?"grab":r?"move":void 0,ft=m.useCallback(()=>{X&&(c.domElement.style.cursor=X)},[c,X]),tt=m.useCallback(()=>{c.domElement.style.cursor=""},[c]);return n.jsxs("group",{ref:x,position:[_.x,0,_.z],rotation:[0,j,0],onContextMenu:l?z:void 0,onPointerDown:r?C:void 0,onPointerMove:r?N:void 0,onPointerUp:r?P:void 0,onPointerCancel:r?L:void 0,onPointerOver:r||l?ft:void 0,onPointerOut:r||l?tt:void 0,children:[n.jsx("primitive",{object:k}),o&&n.jsx(hB,{onPointerDown:W,onPointerMove:S,onPointerUp:B,onPointerCancel:R})]})}function hB({onPointerDown:t,onPointerMove:e,onPointerUp:s,onPointerCancel:o}){const r=m.useMemo(()=>[0,Math.PI/2,Math.PI,-Math.PI/2],[]);return n.jsxs("group",{position:[0,CF,0],children:[n.jsxs("mesh",{rotation:[-Math.PI/2,0,0],onPointerDown:t,onPointerMove:e,onPointerUp:s,onPointerCancel:o,children:[n.jsx("circleGeometry",{args:[Wh,48]}),n.jsx("meshBasicMaterial",{color:Ax,transparent:!0,opacity:.22,depthWrite:!1,side:kn})]}),n.jsxs("mesh",{rotation:[-Math.PI/2,0,0],children:[n.jsx("ringGeometry",{args:[Wh-.02,Wh,64]}),n.jsx("meshBasicMaterial",{color:Ax,transparent:!0,opacity:.95,depthWrite:!1,side:kn})]}),r.map((i,a)=>n.jsxs("mesh",{position:[Math.sin(i)*(Wh+.05),0,Math.cos(i)*(Wh+.05)],rotation:[0,i,0],children:[n.jsx("boxGeometry",{args:[.025,.025,.08]}),n.jsx("meshBasicMaterial",{color:Ax,transparent:!0,opacity:.85})]},a)),n.jsxs("mesh",{position:[0,0,Wh-.05],rotation:[Math.PI/2,0,0],children:[n.jsx("coneGeometry",{args:[.09,.22,16]}),n.jsx("meshBasicMaterial",{color:"#FFFFFF"})]}),n.jsxs("mesh",{position:[0,0,Wh-.05],rotation:[Math.PI/2,0,0],children:[n.jsx("coneGeometry",{args:[.1,.24,16]}),n.jsx("meshBasicMaterial",{color:Ax,transparent:!0,opacity:.6})]}),n.jsxs("mesh",{position:[0,-.18,0],children:[n.jsx("cylinderGeometry",{args:[.012,.012,.36,8]}),n.jsx("meshBasicMaterial",{color:Ax,transparent:!0,opacity:.55})]})]})}function mB(t){return n.jsx(m.Suspense,{fallback:null,children:n.jsx(uB,{...t})})}const J1=()=>Bo.from("user_wall_textures"),Y3="user-wall-textures";function _f(t){const{data:e}=Bo.storage.from(Y3).getPublicUrl(t);return e.publicUrl}async function fB(t,e,s){const o=t.name.split(".").pop()||"jpg",r=`${e}/${crypto.randomUUID()}.${o}`,{error:i}=await Bo.storage.from(Y3).upload(r,t,{contentType:t.type,upsert:!1});if(i)throw new Error(`העלאה נכשלה: ${i.message}`);const{data:a,error:l}=await J1().insert({user_id:e,name:s,storage_path:r}).select().single();if(l)throw new Error(`שמירה נכשלה: ${l.message}`);return a}
266async function xB(t){await Bo.storage.from(Y3).remove([t.storage_path]);const{error:e}=await J1().delete().eq("id",t.id);if(e)throw new Error(`מחיקה נכשלה: ${e.message}`)}function pB(t){const[e,s]=m.useState([]),[o,r]=m.useState(!1),i=m.useCallback(async()=>{if(!t)return;r(!0);const{data:d}=await J1().select("*").eq("user_id",t).order("created_at",{ascending:!1});s(d||[]),r(!1)},[t]);m.useEffect(()=>{i()},[i]);const a=m.useCallback(async(d,u)=>{t&&(await fB(d,t,u),await i())},[t,i]),l=m.useCallback(async d=>{await xB(d),await i()},[i]),c=m.useCallback(async(d,u)=>{await J1().update({name:u}).eq("id",d),await i()},[i]);return{textures:e,loading:o,upload:a,remove:l,rename:c,refresh:i}}const gB=320,bB=640,D2="#D85D43";function Hu({initialX:t,initialY:e,onClose:s,title:o="תבניות נגרות",subtitle:r="מוצמד לקיר הנבחר",icon:i=DI,isDark:a=!1,width:l=gB,maxHeight:c=bB,dir:d="rtl",closeAriaLabel:u="סגור",children:h}){const x=m.useCallback((k,_)=>({x:Math.max(8,Math.min(k,window.innerWidth-l-8)),y:Math.max(8,Math.min(_,window.innerHeight-120))}),[l]),[f,p]=m.useState(()=>x(t,e)),b=m.useRef(null),M=m.useCallback(k=>{var _,j;k.button===0&&(k.preventDefault(),b.current={dx:k.clientX-f.x,dy:k.clientY-f.y},(j=(_=k.target).setPointerCapture)==null||j.call(_,k.pointerId))},[f.x,f.y]),g=m.useCallback(k=>{const _=b.current;_&&p(x(k.clientX-_.dx,k.clientY-_.dy))},[x]),w=m.useCallback(k=>{var _,j;b.current=null,(j=(_=k.target).releasePointerCapture)==null||j.call(_,k.pointerId)},[]);return m.useEffect(()=>{const k=_=>{_.key==="Escape"&&s()};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[s]),n.jsxs("div",{className:O("fixed z-[62] rounded-[10px] border flex flex-col overflow-hidden","font-heebo","shadow-[0_24px_60px_-12px_rgba(24,33,55,0.32),0_6px_18px_-6px_rgba(24,33,55,0.18)]",a?"bg-[#1A1A1B] border-white/12 text-white":"bg-[#FCFAF6] border-[#182137]/12 text-[#182137]"),style:{left:f.x,top:f.y,width:l,maxHeight:c},dir:d,onContextMenu:k=>k.preventDefault(),children:[n.jsx("div",{"aria-hidden":!0,className:"absolute top-0 right-0 h-full w-[3px]",style:{background:D2}}),n.jsxs("div",{className:O("flex items-center justify-between gap-3 select-none pr-4 pl-2.5 py-3","cursor-grab active:cursor-grabbing",a?"bg-white/[0.03] border-b border-white/8":"bg-[#F7F4EF] border-b border-[#182137]/8"),onPointerDown:M,onPointerMove:g,onPointerUp:w,onPointerCancel:w,children:[n.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[n.jsx(EI,{size:15,strokeWidth:2,className:O(a?"text-white/35":"text-[#182137]/35")}),n.jsx("span",{"aria-hidden":!0,className:"inline-flex h-6 w-6 items-center justify-center rounded-md",style:{background:`${D2}22`,color:D2},children:n.jsx(i,{size:13,strokeWidth:2.2})}),n.jsxs("div",{className:"min-w-0 flex flex-col",children:[n.jsx("span",{className:O("text-[15px] font-black truncate leading-tight",a?"text-white":"text-[#182137]"),style:{letterSpacing:"-0.025em"},children:o}),r&&n.jsx("span",{className:O("text-[10.5px] font-medium leading-none mt-0.5 truncate",a?"text-white/45":"text-[#182137]/55"),children:r})]})]}),n.jsx("button",{type:"button",onClick:s,onPointerDown:k=>k.stopPropagation(),"aria-label":u,className:O("h-7 w-7 inline-flex items-center justify-center rounded-md transition-colors shrink-0",a?"hover:bg-white/10 text-white/65 hover:text-white":"hover:bg-[#182137]/[0.06] text-[#182137]/55 hover:text-[#182137]"),children:n.jsx(Gr,{size:15,strokeWidth:2.2})})]}),n.jsx("div",{className:"overflow-y-auto px-3.5 py-4",children:h})]})}const MB="#f5f5f0",NF="#c8c4bc",ew="#18181b",Sb="#e8e4dc";function yB({gangs:t,className:e}){const o=28+(t-1)*14,r=16/2,i=(64-o)/2,a=14,l=t===1?16:Math.min(11,(o-6*(t-1))/t),c=t*l+Math.max(0,t-1)*6;let d=i+(o-c)/2;return n.jsxs("svg",{viewBox:"0 0 56 64",className:e,"aria-hidden":!0,children:[n.jsx("rect",{x:"4",y:"6",width:"48",height:"52",rx:"3",fill:Sb}),n.jsx("rect",{x:r,y:i,width:40,height:o,rx:"2",fill:MB,stroke:NF,strokeWidth:"1"}),Array.from({length:t}).map((u,h)=>{const x=d;return d+=l+6,n.jsx("rect",{x:r+40/2-a/2,y:x,width:a,height:l,rx:"1.5",fill:ew},h)})]})}function wB({outlets:t,className:e}){const r=t===2,i=r?58:40,a=40,l=(56-i)/2,c=3.2,d=8,u=(h,x,f)=>n.jsxs("g",{children:[n.jsx("circle",{cx:h-d/2,cy:x,r:c,fill:ew}),n.jsx("circle",{cx:h+d/2,cy:x,r:c,fill:ew})]},f);return n.jsxs("svg",{viewBox:"0 0 56 64",className:e,"aria-hidden":!0,
266children:[n.jsx("rect",{x:"4",y:"12",width:"48",height:"44",rx:"3",fill:Sb}),n.jsx("rect",{x:l,y:"16",width:i,height:a,rx:"2",fill:"#f0f0eb",stroke:NF,strokeWidth:"1"}),r?n.jsxs(n.Fragment,{children:[u(l+i*.28,16+a/2,"l"),u(l+i*.72,16+a/2,"r")]}):u(l+i/2,16+a/2,"s")]})}function kB({className:t}){return n.jsxs("svg",{viewBox:"0 0 80 48",className:t,"aria-hidden":!0,children:[n.jsx("rect",{x:"2",y:"4",width:"76",height:"40",rx:"2",fill:Sb}),n.jsx("rect",{x:"6",y:"8",width:"68",height:"32",rx:"2",fill:"#f7f7f3",stroke:"#b8b4ac",strokeWidth:"1"}),n.jsx("rect",{x:"10",y:"10",width:"60",height:"6",rx:"1",fill:"#ececea"}),n.jsx("rect",{x:"52",y:"11.5",width:"5",height:"3",rx:"0.5",fill:"#3a9ad9"}),Array.from({length:5}).map((e,s)=>n.jsx("rect",{x:"12",y:20+s*3.2,width:"56",height:"1.6",rx:"0.4",fill:"#b8b8b2"},s))]})}function vB({inches:t,className:e}){const s=t===10,o=s?28:62,r=s?20:36,i=(80-o)/2,a=(48-r)/2;return n.jsxs("svg",{viewBox:"0 0 80 48",className:e,"aria-hidden":!0,children:[n.jsx("rect",{x:"2",y:"4",width:"76",height:"40",rx:"2",fill:Sb}),n.jsx("rect",{x:i,y:a,width:o,height:r,rx:"1.5",fill:"#1c1c1c",stroke:"#111",strokeWidth:"0.8"}),n.jsx("rect",{x:i+2,y:a+2,width:o-4,height:r-4,rx:"1",fill:"#080808"}),!s&&n.jsx("rect",{x:i+o/2-6,y:a+r+1,width:"12",height:"2.5",rx:"0.5",fill:"#2a2a2a"}),s&&n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:i+o/2,cy:a+3,r:"1.8",fill:"#222"}),n.jsx("circle",{cx:i+o/2,cy:a+3,r:"0.9",fill:"#1a3a5c"})]})]})}const jB=500,_B=300,EB=[1,2,3,4],DB=[1,2],FB=[{inches:60,label:"60 אינץ׳",hint:m5(60)},{inches:10,label:"דלת 10 אינץ׳",hint:m5(10)}],Mg=t=>O("rounded-xl border p-2 flex flex-col min-h-0 gap-1.5",t?"border-white/10 bg-white/[0.03]":"border-[#182137]/8 bg-[#FDFBF7]"),yg=t=>O("text-[10px] font-black tracking-tight shrink-0 px-0.5",t?"text-white/55":"text-[#182137]/55"),wg=t=>O("group flex flex-col items-center gap-1 rounded-lg border p-1.5 transition-all cursor-pointer","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#D85D43]/40",t?"border-white/10 bg-white/[0.04] hover:border-[#D85D43]/50 hover:bg-white/[0.08]":"border-[#182137]/8 bg-white hover:border-[#D85D43] hover:bg-[#FDF6F4] hover:shadow-[0_4px_14px_-4px_rgba(216,93,67,0.25)]"),kg=t=>O("text-[9px] font-bold leading-tight text-center",t?"text-white/80 group-hover:text-white":"text-[#182137]/75 group-hover:text-[#182137]");function vg({isDark:t,children:e}){return n.jsx("div",{className:O("w-full flex items-center justify-center rounded-md overflow-hidden",t?"bg-[#1a1c24]":"bg-gradient-to-b from-[#F0EBE3] to-[#E8E2D8]"),style:{minHeight:52},children:e})}function CB({initialX:t,initialY:e,onClose:s,onSelect:o,isDark:r=!1}){const{t:i,i18n:a}=yn();return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fixed inset-0 z-[60]",onClick:s,onContextMenu:l=>{l.preventDefault(),s()}}),n.jsx(Hu,{initialX:t,initialY:e-400,onClose:s,title:i("viewer.menu.addElectrical",{defaultValue:"הוסף חשמל"}),subtitle:i("electrical.panel.subtitle",{defaultValue:"בחר פריט · לחץ על הקיר"}),icon:_w,isDark:r,width:jB,maxHeight:_B,dir:a.dir(),closeAriaLabel:i("common.close",{defaultValue:"סגור"}),children:n.jsxs("div",{className:"-my-1 grid grid-cols-2 gap-2.5 h-[208px]",children:[n.jsxs("div",{className:Mg(r),children:[n.jsx("h3",{className:yg(r),children:i("electrical.sections.switches",{defaultValue:"מפסקים"})}),n.jsx("div",{className:"grid grid-cols-4 gap-1 flex-1 content-center",children:EB.map(l=>n.jsxs("button",{type:"button",onClick:()=>o({kind:"switch",gangs:l}),className:wg(r),title:i("electrical.fixtures.switch",{gangs:l,defaultValue:`מפסק ${l}`}),children:[n.jsx(vg,{isDark:r,children:n.jsx(yB,{gangs:l,className:"h-[52px] w-auto"})}),n.jsx("span",{className:kg(r),children:l})]},`switch-${l}`))})]}),n.jsxs("div",{className:Mg(r),children:[n.jsx("h3",{className:yg(r),children:i("electrical.sections.outlets",{defaultValue:"שקעים"})}),n.jsx("div",{className:"grid grid-cols-2 gap-1.5 flex-1 content-center",children:DB.map(l=>n.jsxs("button",{type:"button",onClick:()=>o({kind:"socket",outlets:l}),className:wg(r),title:i(l===1?"electrical.fixtures.singleOutlet":"electrical.fixtures.doubleOutlet",{defaultValue:sS(l)}),children:[n.jsx(vg,{isDark:r,children:n.jsx(wB,{outlets:l,className:"h-[52px] w-auto"})}),n.jsx("span",{className:kg(r),children:l===1?i("electrical.options.single",{defaultValue:"יחיד"}):i("electrical.options.double",{defaultValue:"כפול"})})]},`socket-${l}`))})]}
266),n.jsxs("div",{className:Mg(r),children:[n.jsx("h3",{className:yg(r),children:i("electrical.sections.airConditioning",{defaultValue:"מיזוג אוויר"})}),n.jsx("div",{className:"flex-1 flex items-center",children:n.jsxs("button",{type:"button",onClick:()=>o({kind:"ac"}),className:O(wg(r),"w-full"),title:i("electrical.hints.acSize",{defaultValue:"1 מ׳ רוחב · 40 ס״מ גובה"}),children:[n.jsx(vg,{isDark:r,children:n.jsx(kB,{className:"h-[44px] w-full max-w-[120px]"})}),n.jsx("span",{className:kg(r),children:i("electrical.fixtures.ac",{defaultValue:"מזגן יחיד"})})]})})]}),n.jsxs("div",{className:Mg(r),children:[n.jsx("h3",{className:yg(r),children:i("electrical.sections.televisions",{defaultValue:"טלוויזיות"})}),n.jsx("div",{className:"grid grid-cols-2 gap-1.5 flex-1 content-center",children:FB.map(({inches:l,label:c,hint:d})=>n.jsxs("button",{type:"button",onClick:()=>o({kind:"tv",inches:l}),className:wg(r),title:i(l===60?"electrical.hints.tv60Size":"electrical.hints.tv10Size",{defaultValue:d}),children:[n.jsx(vg,{isDark:r,children:n.jsx(vB,{inches:l,className:"h-[44px] w-full max-w-[100px]"})}),n.jsx("span",{className:kg(r),children:i(l===60?"electrical.options.tv60":"electrical.options.doorScreen10",{defaultValue:c})})]},`tv-${l}`))})]})]})})]})}function NB(t){return t===1||t===2||t===3||t===4}function IB(t){return t===1||t===2}function TB(t){return t===60||t===10}function jg(t){return t.type==="switch"?`מפסק ${t.gangs}`:t.type==="socket"?t.outlets===1?"שקע יחיד":"שקע כפול":t.type==="tv"?t.inches===60?"טלוויזיה 60 אינץ׳":"מסך דלת 10 אינץ׳":"מזגן יחיד"}function SB(t){return t.kind==="switch"?`מפסק ${t.gangs}`:t.kind==="socket"?t.outlets===1?"שקע יחיד":"שקע כפול":t.kind==="tv"?t.inches===60?"טלוויזיה 60 אינץ׳":"מסך דלת 10 אינץ׳":"מזגן יחיד"}function PB(t,e){if(!Array.isArray(t))return[];const s=[];for(const o of t){if(!o||typeof o!="object")continue;const r=o;if(!(typeof r.id!="string"||!r.id)&&!(typeof r.wallId!="string"||!r.wallId)&&!(r.wallSide!=="front"&&r.wallSide!=="back")&&!(typeof r.positionAlongWallMm!="number"||!Number.isFinite(r.positionAlongWallMm))&&!(typeof r.centerHeightMm!="number"||!Number.isFinite(r.centerHeightMm))&&!(e&&!e.has(r.wallId))){if(r.type==="switch"&&NB(r.gangs)){s.push({id:r.id,type:"switch",gangs:r.gangs,wallId:r.wallId,wallSide:r.wallSide,positionAlongWallMm:r.positionAlongWallMm,centerHeightMm:r.centerHeightMm});continue}if(r.type==="socket"&&IB(r.outlets)){s.push({id:r.id,type:"socket",outlets:r.outlets,wallId:r.wallId,wallSide:r.wallSide,positionAlongWallMm:r.positionAlongWallMm,centerHeightMm:r.centerHeightMm});continue}if(r.type==="ac"){s.push({id:r.id,type:"ac",wallId:r.wallId,wallSide:r.wallSide,positionAlongWallMm:r.positionAlongWallMm,centerHeightMm:r.centerHeightMm});continue}r.type==="tv"&&TB(r.inches)&&s.push({id:r.id,type:"tv",inches:r.inches,wallId:r.wallId,wallSide:r.wallSide,positionAlongWallMm:r.positionAlongWallMm,centerHeightMm:r.centerHeightMm})}}return s}function AB(t){return`${t}_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function IF(t){return t.type==="switch"?wE(t.gangs):t.type==="socket"?qw(t.outlets):t.type==="tv"?t3(t.inches):Zw()}function xj(t,e,s){return t.type==="switch"?kE(e,s):t.type==="socket"?_E(e,s):t.type==="tv"?FE(e,t.inches,s):ME(e,s)}function LB(t){return t.kind==="switch"?wE(t.gangs):t.kind==="socket"?qw(t.outlets):t.kind==="tv"?t3(t.inches):Zw()}function WB(t){return t.kind==="switch"?JT:t.kind==="socket"?nS:t.kind==="tv"?cS(t.inches):GT}function RB(t,e,s){return s.kind==="switch"?kE(t,e):s.kind==="socket"?_E(t,e):s.kind==="tv"?FE(t,s.inches,e):ME(t,e)}function F2(t){const e=t.start.x*rt,s=t.start.y*rt,o=t.end.x*rt,r=t.end.y*rt,i=o-e,a=r-s;return Math.sqrt(i*i+a*a)/rt}function OB(t,e,s){const o=t.start.x*rt,r=t.start.y*rt,i=t.end.x*rt,a=t.end.y*rt,l=i-o,c=a-r,d=l*l+c*c;
266if(d<1e-12)return null;const u=Math.max(0,Math.min(1,((e.x-o)*l+(e.z-r)*c)/d)),h=Math.sqrt(d)/rt,x=LB(s),f=Math.max(x,h-x),p=Math.max(x,Math.min(f,u*h)),b=e.y/rt,M=WB(s),g=RB(Number.isFinite(b)&&b>0?b:M,t.height,s);return{positionAlongWallMm:p,centerHeightMm:g}}function HB(t,e,s){const o=IF(e),r=Math.max(o,s-o);return Math.max(o,Math.min(r,t))}const C2=280,N2=320,_d=50;function BB(t,e,s){return Math.max(e,Math.min(s,t))}function VB({initialX:t,initialY:e,fixture:s,wallLenMm:o,wallHeightMm:r,measurementUnit:i,isDark:a=!1,onChange:l,onDelete:c,onClose:d}){const{t:u,i18n:h}=yn(),x=m.useCallback(Y=>HB(Y,s,o),[s,o]),f=m.useCallback(Y=>xj(s,Y,r),[s,r]),p=Math.max(12,Math.min(t,window.innerWidth-C2-12)),b=Math.max(12,Math.min(e,window.innerHeight-N2-12)),[M,g]=m.useState({x:p,y:b}),w=m.useRef(null),k=Y=>Number(De(Y,i)),_=Y=>ni(String(Y),i)??0,j=Y=>i==="mm"?Y:Math.max(.1,Y/10),v=IF(s),C=Math.max(v,o-v),N=xj(s,r-50,r),P=i==="mm"?u("settings.millimeters",{defaultValue:"מ״מ"}):u("settings.centimeters",{defaultValue:"ס״מ"}),L=Y=>`${De(Y,i)} ${P}`,A=i==="mm"?0:1,W=k(s.positionAlongWallMm),S=k(v),B=k(C),R=k(s.centerHeightMm),z=k(300),X=k(N),ft=j(10),tt=s.type==="switch"?u("electrical.fixtures.switch",{gangs:s.gangs,defaultValue:jg(s)}):s.type==="socket"?u(s.outlets===1?"electrical.fixtures.singleOutlet":"electrical.fixtures.doubleOutlet",{defaultValue:jg(s)}):s.type==="tv"?u(s.inches===60?"electrical.fixtures.tv60":"electrical.fixtures.doorScreen10",{defaultValue:jg(s)}):u("electrical.fixtures.ac",{defaultValue:jg(s)}),G=(Y,J,Mt,Rt,it)=>n.jsxs("div",{className:"flex items-center gap-2.5",children:[n.jsx("span",{className:O("text-[9px] w-[34px] text-left shrink-0",a?"text-white/45":"text-[#9b95a0]"),children:Y}),n.jsx("input",{type:"range",min:Mt,max:Rt,step:ft,value:BB(J,Mt,Rt),onChange:st=>it(Number(st.target.value)),className:`flex-1 h-[3px] appearance-none bg-[#ede8e4] rounded-full outline-none cursor-pointer
267          [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-3 [&::-webkit-slider-thumb]:h-3
268          [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-[#D84B2E] [&::-webkit-slider-thumb]:shadow-[0_1px_4px_rgba(216,75,46,0.35)]
269          [&::-webkit-slider-thumb]:cursor-pointer`}),n.jsxs("span",{className:O("text-[10px] font-medium w-[52px] text-center shrink-0 tabular-nums",a?"text-white/70":"text-[#5a5065]"),children:[J.toFixed(A),P]})]});return m.useEffect(()=>{const Y=J=>{J.key==="Escape"&&d()};return window.addEventListener("keydown",Y),()=>window.removeEventListener("keydown",Y)},[d]),n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fixed inset-0 z-[60]",onClick:d,onContextMenu:Y=>{Y.preventDefault(),d()}}),n.jsxs("div",{className:O("fixed z-[61] rounded-2xl border shadow-[0_12px_36px_-6px_rgba(0,0,0,0.28)] font-heebo overflow-hidden flex flex-col",a?"bg-[#141416] border-white/10":"bg-white border-black/10"),style:{left:M.x,top:M.y,width:C2,maxHeight:N2},dir:h.dir(),onContextMenu:Y=>Y.preventDefault(),onClick:Y=>Y.stopPropagation(),children:[n.jsxs("div",{className:O("flex items-center justify-between px-3 py-2.5 border-b shrink-0 select-none cursor-move",a?"border-white/10":"border-black/[0.06]"),title:u("trace.dragToMove",{defaultValue:"גרור להזזה"}),onPointerDown:Y=>{var J,Mt;Y.button===0&&(w.current={dx:Y.clientX-M.x,dy:Y.clientY-M.y},(Mt=(J=Y.target).setPointerCapture)==null||Mt.call(J,Y.pointerId))},onPointerMove:Y=>{const J=w.current;J&&g({x:Math.max(12,Math.min(Y.clientX-J.dx,window.innerWidth-C2-12)),y:Math.max(12,Math.min(Y.clientY-J.dy,window.innerHeight-N2-12))})},onPointerUp:Y=>{var J,Mt;w.current=null,(Mt=(J=Y.target).releasePointerCapture)==null||Mt.call(J,Y.pointerId)},onPointerCancel:Y=>{var J,Mt;w.current=null,(Mt=(J=Y.target).releasePointerCapture)==null||Mt.call(J,Y.pointerId)},children:[n.jsx("div",{className:O("text-[12px] font-semibold",a?"text-white/90":"text-[#18181b]"),children:tt}),n.jsx("button",{type:"button",onPointerDown:Y=>Y.stopPropagation(),onClick:d,"aria-label":u("common.close",{defaultValue:"סגור"}),className:O("w-6 h-6 rounded-md flex items-center justify-center cursor-pointer",a?"text-white/45 hover:text-white hover:bg-white/10":"text-[#71717a] hover:text-[#18181b] hover:bg-black/5"),children:n.jsx(Gr,{size:14})})]}),n.jsxs("div",{className:"flex-1 overflow-y-auto px-3 py-3 space-y-3",children:[n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[n.jsx("span",{className:O("text-[11px] font-semibold",a?"text-white/70":"text-[#5a5065]"),children:u("electrical.edit.positionTitle",{defaultValue:"עריכת מיקום"})}),n.jsx("button",{type:"button",onClick:c,className:"px-2.5 py-1 rounded-xl text-[10px] font-medium text-[#d4738a] bg-[#fdf0f3] hover:bg-[#f9d5de] transition-all cursor-pointer",children:u("common.delete",{defaultValue:"מחק"})})]}),G(u("openingEditor.position",{defaultValue:"מיקום"}),W,S,B,Y=>l({positionAlongWallMm:x(_(Y))})),G(u("openingEditor.height",{defaultValue:"גובה"}),R,z,X,Y=>l({centerHeightMm:f(_(Y))})),n.jsx("div",{dir:"ltr",className:"flex justify-center pt-1",children:n.jsxs("div",{className:"grid w-fit grid-cols-3 grid-rows-3 gap-1.5",children:[n.jsx("span",{}),n.jsxs("button",{type:"button","aria-label":u("accessibility.moveUp",{defaultValue:"הזז למעלה"}),onClick:()=>l({centerHeightMm:f(s.centerHeightMm+_d)}),className:O("h-8 min-w-[4.5rem] rounded-xl text-[10px] font-medium border transition-all cursor-pointer",a?"border-white/10 text-white/75 hover:bg-white/10":"border-[#182137]/8 text-[#182137]/70 hover:bg-black/[0.04]"),children:["↑ ",L(_d)]}),n.jsx("span",{}),n.jsxs("button",{type:"button","aria-label":u("accessibility.moveLeft",{defaultValue:"הזז שמאלה"}),onClick:()=>l({positionAlongWallMm:x(s.positionAlongWallMm-_d)}),className:O("h-8 min-w-[4.5rem] rounded-xl text-[10px] font-medium border transition-all cursor-pointer",a?"border-white/10 text-white/75 hover:bg-white/10":"border-[#182137]/8 text-[#182137]/70 hover:bg-black/[0.04]"),children:["← ",L(_d)]}),n.jsx("span",{className:O("flex h-8 w-8 items-center justify-center text-[9px]",a?"text-white/35":"text-[#182137]/35"),children:L(_d)}),n.jsxs("button",{type:"button","aria-label":u("accessibility.moveRight",{defaultValue:"הזז ימינה"}),onClick:()=>l({positionAlongWallMm:x(s.positionAlongWallMm+_d)}),className:O("h-8 min-w-[4.5rem] rounded-xl text-[10px] font-medium border transition-all cursor-pointer",a?"border-white/10 text-white/75 hover:bg-white/10":"border-[#182137]/8 text-[#182137]/70 hover:bg-black/[0.04]"),children:[L(_d)," →"]}),n.jsx("span",{}),n.jsxs("button",{type:"button","aria-label":u("accessibility.moveDown",{defaultValue:"הזז למטה"}),onClick:()=>l({centerHeightMm:f(s.centerHeightMm-_d)}),className:O("h-8 min-w-[4.5rem] rounded-xl text-[10px] font-medium border transition-all cursor-pointer",a?"border-white/10 text-white/75 hover:bg-white/10":"border-[#182137]/8 text-[#182137]/70 hover:bg-black/[0.04]"),children:["↓ ",L(_d)]}),n.jsx("span",{})]})})]})]})]})}const zB=new Set(["B","STRONG","BR","DIV","SPAN"]);function Vl(t){if(typeof document>"u")return t.replace(/<[^>]+>/g,"").trim();const e=document.createElement("div");return e.innerHTML=t,(e.textContent??"").replace(/\s+/g," ").trim()}const $B=t=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;");function zc(t){if(typeof document>"u")return t;const e=document.createElement("div");e.innerHTML=t;const s=o=>
269{if(o.nodeType===Node.TEXT_NODE)return $B(o.textContent??"");if(o.nodeType!==Node.ELEMENT_NODE)return"";const r=o;if(!zB.has(r.tagName))return Array.from(r.childNodes).map(s).join("");if(r.tagName==="BR")return"<br>";const i=Array.from(r.childNodes).map(s).join("");if(r.tagName==="B"||r.tagName==="STRONG")return`<strong>${i}</strong>`;const a=r.style.textAlign;return a==="left"||a==="center"||a==="right"?`<div style="text-align:${a}">${i}</div>`:i};return Array.from(e.childNodes).map(s).join("").trim()}const XB=420,YB=360,GB=["📝","✅","❌","⚠️","💡","🔧","📐","🛋️","🚪","💰","📞","⭐"],Lx=(t,e=!1)=>O("h-7 w-7 rounded-md border flex items-center justify-center transition-colors",e?"border-[#D85D43] bg-[#FDF6F4] text-[#D85D43]":t?"border-white/12 bg-white/[0.04] hover:bg-white/[0.1] text-white":"border-[#182137]/10 bg-white hover:border-[#D84B2E]/35 text-[#182137]");function pj({initialX:t,initialY:e,onClose:s,onSaveAndPlace:o,isDark:r=!1}){const{t:i,i18n:a}=yn(),[l,c]=m.useState("yellow"),[d,u]=m.useState(!1),h=m.useRef(null),[x,f]=m.useState(0),p=m.useCallback(()=>{var _;const k=((_=h.current)==null?void 0:_.innerHTML)??"";f(Vl(k).length)},[]);m.useEffect(()=>{const k=h.current;k&&(k.focus(),p())},[p]);const b=m.useCallback((k,_)=>{var j;document.execCommand(k,!1,_),(j=h.current)==null||j.focus(),p()},[p]),M=m.useCallback(k=>{var _;document.execCommand("insertText",!1,k),(_=h.current)==null||_.focus(),u(!1),p()},[p]),g=m.useCallback(()=>{var j;const k=zc(((j=h.current)==null?void 0:j.innerHTML)??"");Vl(k)&&o({colorId:l,contentHtml:k})},[l,o]),w=x>0;return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fixed inset-0 z-[60]",onClick:s,onContextMenu:k=>{k.preventDefault(),s()}}),n.jsx(Hu,{initialX:t,initialY:e-320,onClose:s,title:i("notes.composer.title",{defaultValue:"הוסף פתק"}),subtitle:i("notes.composer.subtitle",{defaultValue:"כתוב ושמור על הסקיצה"}),icon:Af,isDark:r,width:XB,maxHeight:YB,dir:a.dir(),closeAriaLabel:i("common.close",{defaultValue:"סגור"}),children:n.jsxs("div",{className:"flex flex-col gap-3",dir:a.dir(),children:[n.jsx("style",{children:`
270            [data-note-placeholder]:empty:before {
271              content: attr(data-placeholder);
272              color: #9b95a0;
273              pointer-events: none;
274            }
275          `}),n.jsxs("div",{children:[n.jsx("p",{className:O("text-[9px] font-semibold uppercase tracking-wider mb-1.5",r?"text-white/45":"text-[#9b95a0]"),children:i("notes.colors.label",{defaultValue:"צבע פתק"})}),n.jsx("div",{className:"flex flex-wrap gap-2",children:bb.map(k=>n.jsx("button",{type:"button",title:i(`notes.colors.${k.id}`,{defaultValue:k.label}),onClick:()=>c(k.id),className:O("h-7 w-7 rounded-full border-2 transition-transform",l===k.id?"border-[#D85D43] scale-110":"border-black/10"),style:{backgroundColor:k.hex}},k.id))})]}),n.jsxs("div",{className:"relative",children:[n.jsxs("div",{className:"flex items-center gap-1 mb-1.5",children:[n.jsx("button",{type:"button",className:Lx(r),onClick:()=>b("bold"),title:i("notes.composer.bold",{defaultValue:"מודגש"}),children:n.jsx(iT,{size:14})}),n.jsx("button",{type:"button",className:Lx(r),onClick:()=>b("justifyLeft"),title:i("notes.composer.alignLeft",{defaultValue:"יישור שמאל"}),children:n.jsx(tT,{size:14})}),n.jsx("button",{type:"button",className:Lx(r),onClick:()=>b("justifyCenter"),title:i("notes.composer.alignCenter",{defaultValue:"מרכז"}),children:n.jsx(QI,{size:14})}),n.jsx("button",{type:"button",className:Lx(r),onClick:()=>b("justifyRight"),title:i("notes.composer.alignRight",{defaultValue:"יישור ימין"}),children:n.jsx(eT,{size:14})}),n.jsx("button",{type:"button",className:O(Lx(r,d),"text-sm"),onClick:()=>u(k=>!k),title:i("notes.composer.emoji",{defaultValue:"אימוג׳י"}),children:"😊"})]}),d&&n.jsx("div",{className:O("absolute z-10 top-9 start-0 grid grid-cols-6 gap-1 p-2 rounded-lg border shadow-lg",r?"bg-[#1a1f2e] border-white/10":"bg-white border-black/10"),children:GB.map(k=>n.jsx("button",{type:"button",className:"h-8 w-8 rounded hover:bg-black/5 text-lg",onClick:()=>M(k),children:k},k))}),n.jsx("div",{ref:h,contentEditable:!0,suppressContentEditableWarning:!0,onInput:p,className:O("min-h-[96px] max-h-[200px] overflow-y-auto rounded-xl border px-3 py-2 text-[13px] font-heebo leading-relaxed outline-none",r?"border-white/12 bg-white/[0.04] text-white":"border-[#182137]/12 bg-[#FFFEF8] text-[#182137]"),"data-placeholder":i("notes.composer.placeholder",{defaultValue:"כתוב כאן תזכורת קצרה..."}),"data-note-placeholder":""})]}),n.jsx("button",{type:"button",disabled:!w,onClick:g,className:O("w-full rounded-xl py-2.5 text-[12px] font-bold transition-colors",w?"bg-[#D85D43] text-white hover:bg-[#c24f38]":"bg-black/10 text-black/35 cursor-not-allowed"),children:i("notes.composer.saveNote",{defaultValue:"שמור פתק"})})]})})]})}function UB(t,e){const s=t.start.x*rt,o=t.start.y*rt,r=t.end.x*rt,i=t.end.y*rt,a=r-s,l=i-o,c=a*a+l*l;if(c<1e-12)return null;const d=Math.max(0,Math.min(1,((e.x-s)*a+(e.z-o)*l)/c)),u=Math.sqrt(c)/rt,h=Mb(),x=Math.max(h,u-h),f=Math.max(h,Math.min(x,d*u)),p=e.y
275/rt,b=Wy(Number.isFinite(p)&&p>0?p:kS,t.height);return{positionAlongWallMm:f,centerHeightMm:b}}function KB(t,e){const s=Mb(),o=Math.max(s,e-s);return Math.max(s,Math.min(o,t))}const Ed=50;function ZB(t,e,s){return Math.max(e,Math.min(s,t))}function qB({initialX:t,initialY:e,note:s,wallLenMm:o,wallHeightMm:r,measurementUnit:i,isDark:a=!1,onChange:l,onDelete:c,onClose:d}){const{t:u,i18n:h}=yn(),[x,f]=m.useState(!1),p=m.useRef(null),[b,M]=m.useState(()=>Vl(s.contentHtml).length),g=Mb(),w=m.useCallback(J=>KB(J,o),[o]),k=m.useCallback(J=>Wy(J,r),[r]),_=J=>Number(De(J,i)),j=J=>ni(String(J),i)??0,v=J=>i==="mm"?J:Math.max(.1,J/10),C=Math.max(g,o-g),N=Wy(r-50,r),P=i==="mm"?u("settings.millimeters",{defaultValue:"מ״מ"}):u("settings.centimeters",{defaultValue:"ס״מ"}),L=J=>`${De(J,i)} ${P}`,A=i==="mm"?0:1,W=_(s.positionAlongWallMm),S=_(g),B=_(C),R=_(s.centerHeightMm),z=_(200),X=_(N),ft=v(10),tt=(J,Mt,Rt,it,st)=>n.jsxs("div",{className:"flex items-center gap-2.5",children:[n.jsx("span",{className:O("text-[9px] w-[34px] text-left shrink-0",a?"text-white/45":"text-[#9b95a0]"),children:J}),n.jsx("input",{type:"range",min:Rt,max:it,step:ft,value:ZB(Mt,Rt,it),onChange:ct=>st(Number(ct.target.value)),className:`flex-1 h-[3px] appearance-none bg-[#ede8e4] rounded-full outline-none cursor-pointer
276          [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-3 [&::-webkit-slider-thumb]:h-3
277          [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-[#D84B2E] [&::-webkit-slider-thumb]:shadow-[0_1px_4px_rgba(216,75,46,0.35)]
278          [&::-webkit-slider-thumb]:cursor-pointer`}),n.jsxs("span",{className:O("text-[10px] font-medium w-[52px] text-center shrink-0 tabular-nums",a?"text-white/70":"text-[#5a5065]"),children:[Mt.toFixed(A),P]})]});m.useEffect(()=>{if(!x)return;const J=p.current;J&&(J.innerHTML=s.contentHtml,J.focus(),M(Vl(s.contentHtml).length))},[x,s.contentHtml]);const G=m.useCallback(()=>{var J;M(Vl(((J=p.current)==null?void 0:J.innerHTML)??"").length)},[]),Y=m.useCallback(()=>{var Mt;const J=zc(((Mt=p.current)==null?void 0:Mt.innerHTML)??"");Vl(J)&&(l({contentHtml:J}),f(!1))},[l]);return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fixed inset-0 z-[60]",onClick:d,onContextMenu:J=>{J.preventDefault(),d()}}),n.jsx(Hu,{initialX:t,initialY:e,onClose:d,title:u("notes.wall.title",{defaultValue:"פתק על הקיר"}),subtitle:u("notes.wall.subtitle",{defaultValue:"תזכורת בפרויקט"}),icon:Af,isDark:a,width:360,maxHeight:560,dir:h.dir(),closeAriaLabel:u("common.close",{defaultValue:"סגור"}),children:n.jsxs("div",{className:"flex flex-col gap-3",dir:h.dir(),children:[n.jsx("div",{className:"flex flex-wrap gap-2",children:bb.map(J=>n.jsx("button",{type:"button",title:u(`notes.colors.${J.id}`,{defaultValue:J.label}),onClick:()=>l({colorId:J.id}),className:O("h-6 w-6 rounded-full border-2 transition-transform",s.colorId===J.id?"border-[#D85D43] scale-110":"border-black/10"),style:{backgroundColor:J.hex}},J.id))}),x?n.jsxs(n.Fragment,{children:[n.jsx("div",{ref:p,contentEditable:!0,suppressContentEditableWarning:!0,onInput:G,className:O("min-h-[88px] max-h-[200px] overflow-y-auto rounded-xl border px-3 py-2 text-[13px] font-heebo leading-relaxed outline-none",a?"border-white/12 bg-white/[0.04] text-white":"border-[#182137]/12 text-[#182137]"),style:{backgroundColor:a?void 0:Ku(s.colorId)}}),n.jsx("div",{className:"flex items-center justify-end gap-2",children:n.jsxs("div",{className:"flex gap-2",children:[n.jsx("button",{type:"button",onClick:()=>f(!1),className:O("rounded-lg px-3 py-1.5 text-[11px] font-semibold border",a?"border-white/12 text-white/70":"border-[#182137]/12 text-[#71717a]"),children:u("notes.actions.cancel",{defaultValue:"ביטול"})}),n.jsx("button",{type:"button",onClick:Y,disabled:b===0,className:"rounded-lg px-3 py-1.5 text-[11px] font-bold bg-[#D85D43] text-white disabled:opacity-40",children:u("notes.actions.save",{defaultValue:"שמור"})})]})})]}):n.jsx("div",{className:O("rounded-xl border px-3 py-3 text-[13px] font-heebo leading-relaxed min-h-[100px] max-h-[240px] overflow-y-auto",a?"border-white/12 text-white":"border-[#182137]/10 text-[#182137]"),style:{backgroundColor:a?"rgba(255,255,255,0.04)":Ku(s.colorId)},dangerouslySetInnerHTML:{__html:zc(s.contentHtml)}}),n.jsxs("div",{className:O("space-y-2.5 pt-1 border-t",a?"border-white/10":"border-black/[0.06]"),children:[n.jsx("span",{className:O("text-[11px] font-semibold block",a?"text-white/70":"text-[#5a5065]"),children:u("notes.wall.positionOnWall",{defaultValue:"מיקום על הקיר"})}),tt(u("notes.wall.alongWall",{defaultValue:"לאורך"}),W,S,B,J=>l({positionAlongWallMm:w(j(J))})),tt(u("notes.wall.height",{defaultValue:"גובה"}),R,z,X,J=>l({centerHeightMm:k(j(J))})),n.jsx("div",{dir:"ltr",className:"flex justify-center",children:n.jsxs("div",{className:"grid w-fit grid-cols-3 grid-rows-3 gap-1.5",children:[n.jsx("span",{}),n.jsxs("button",{type:"button","aria-label":u("notes.wall.moveUp",{defaultValue:"הזז למעלה"}),onClick:()=>l({centerHeightMm:k(s.centerHeightMm+Ed)}),className:O("h-8 min-w-[4.5rem] rounded-xl text-[10px] font-medium border transition-all cursor-pointer",a?"border-white/10 text-white/75 hover:bg-white/10":"border-[#182137]/8 text-[#182137]/70 hover:bg-black/[0.04]"),children:["↑ ",L(Ed)]}),n.jsx("span",{}),n.jsxs("button",{type:"button","aria-label":u("notes.wall.moveLeft",{defaultValue:"הזז שמאלה"}),onClick:()=>l({positionAlongWallMm:w(s.positionAlongWallMm-Ed)}),className:O("h-8 min-w-[4.5rem] rounded-xl text-[10px] font-medium border transition-all cursor-pointer",a?"border-white/10 text-white/75 hover:bg-white/10":"border-[#182137]/8 text-[#182137]/70 hover:bg-black/[0.04]"),children:["← ",L(Ed)]}),n.jsx("span",{className:O("flex h-8 w-8 items-center justify-center text-[9px]",a?"text-white/35":"text-[#182137]/35"),children:L(Ed)}),n.jsxs("button",{type:"button","aria-label":u("notes.wall.moveRight",{defaultValue:"הזז ימינה"}),onClick:()=>l({positionAlongWallMm:w(s.positionAlongWallMm+Ed)}),className:O("h-8 min-w-[4.5rem] rounded-xl text-[10px] font-medium border transition-all cursor-pointer",a?"border-white/10 text-white/75 hover:bg-white/10":"border-[#182137]/8 text-[#182137]/70 hover:bg-black/[0.04]"),children:[L(Ed)," →"]}),n.jsx("span",{}),n.jsxs("button",{type:"button","aria-label":u("notes.wall.moveDown",{defaultValue:"הזז למטה"}),onClick:()=>l({centerHeightMm:k(s.centerHeightMm-Ed)}),className:O("h-8 min-w-[4.5rem] rounded-xl text-[10px] font-medium border transition-all cursor-pointer",a?"border-white/10 text-white/75 hover:bg-white/10":"border-[#182137]/8 text-[#182137]/70 hover:bg-black/[0.04]"),children:["↓ ",L(Ed)]}),n.jsx("span",{})]})})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[!x&&n.jsx("button",{type:"button",onClick:()=>f(!0),className:O("flex-1 rounded-xl py-2 text-[12px] font-bold border",a?"border-white/12 text-white hover:bg-white/5":"border-[#182137]/12 text-[#182137] hover:bg-black/[0.03]"),children:u("notes.actions.edit",{defaultValue:"ערוך"})}),n.jsxs("button",{type:"button",onClick:c,className:O("rounded-xl py-2 px-3 text-[12px] font-semibold flex items-center gap-1.5 border",a?"border-red-400/30 text-red-300 hover:bg-red-500/10":"border-red-200 text-red-600 hover:bg-red-50"),children:[n.jsx(gi,{size:14}),u("notes.actions.delete",{defaultValue:"מחק"})]})]})]})})]})}function JB({initialX:t,initialY:e,note:s,isDark:o=!1,onChange:r,onHide:i,onDelete:a,onClose:l}){const{t:c,i18n:d}=yn(),[u,h]=m.useState(!1),x=m.useRef(null),[f,p]=m.useState(()=>Vl(s.contentHtml).length);m.useEffect(()=>{if(!u)return;const g=x.current;g&&(g.innerHTML=s.contentHtml,g.focus(),p(Vl(s.contentHtml).length))},[u,s.contentHtml]);const b=m.useCallback(()=>{var g;p(Vl(((g=x.current)==null?void 0:g.innerHTML)??"").length)},[]),M=m.useCallback(()=>{var w;const g=zc(((w=x.current)==null?void 0:w.innerHTML)??"");Vl(g)&&(r({contentHtml:g}),h(!1))},[r]);return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fixed inset-0 z-[60]",onClick:l,onContextMenu:g=>{g.preventDefault(),l()}}),n.jsx(Hu,{initialX:t,initialY:e,onClose:l,title:c("notes.viewport.title",{defaultValue:"פתק על הסקיצה"}),subtitle:c("notes.viewport.subtitle",{defaultValue:"הערה לאיש מקצוע"}),icon:Af,isDark:o,width:360,maxHeight:500,dir:d.dir(),closeAriaLabel:c("common.close",{defaultValue:"סגור"}),children:n.jsxs("div",{className:"flex flex-col gap-3",dir:d.dir(),children:[n.jsx("div",{className:"flex flex-wrap gap-2",children:bb.map(g=>n.jsx("button",{type:"button",title:c(`notes.colors.${g.id}`,{defaultValue:g.label}),onClick:()=>r({colorId:g.id}),className:O("h-6 w-6 rounded-full border-2 transition-transform",s.colorId===g.id?"border-[#D85D43] 
278scale-110":"border-black/10"),style:{backgroundColor:g.hex}},g.id))}),u?n.jsxs(n.Fragment,{children:[n.jsx("div",{ref:x,contentEditable:!0,suppressContentEditableWarning:!0,onInput:b,className:O("min-h-[100px] max-h-[220px] overflow-y-auto rounded-xl border px-3 py-2 text-[13px] font-heebo leading-relaxed outline-none",o?"border-white/12 bg-white/[0.04] text-white":"border-[#182137]/12 text-[#182137]"),style:{backgroundColor:o?void 0:Ku(s.colorId)}}),n.jsxs("div",{className:"flex justify-end gap-2",children:[n.jsx("button",{type:"button",onClick:()=>h(!1),className:O("rounded-lg px-3 py-1.5 text-[11px] font-semibold border",o?"border-white/12 text-white/70":"border-[#182137]/12 text-[#71717a]"),children:c("notes.actions.cancel",{defaultValue:"ביטול"})}),n.jsx("button",{type:"button",onClick:M,disabled:f===0,className:"rounded-lg px-3 py-1.5 text-[11px] font-bold bg-[#D85D43] text-white disabled:opacity-40",children:c("notes.actions.save",{defaultValue:"שמור"})})]})]}):n.jsx("div",{className:O("rounded-xl border px-3 py-3 text-[13px] font-heebo leading-relaxed min-h-[100px] max-h-[240px] overflow-y-auto",o?"border-white/12 text-white":"border-[#182137]/10 text-[#182137]"),style:{backgroundColor:o?"rgba(255,255,255,0.04)":Ku(s.colorId)},dangerouslySetInnerHTML:{__html:zc(s.contentHtml)}}),n.jsxs("div",{className:"flex items-center gap-2",children:[!u&&n.jsx("button",{type:"button",onClick:()=>h(!0),className:O("flex-1 rounded-xl py-2 text-[12px] font-bold border",o?"border-white/12 text-white hover:bg-white/5":"border-[#182137]/12 text-[#182137] hover:bg-black/[0.03]"),children:c("notes.actions.edit",{defaultValue:"ערוך"})}),n.jsxs("button",{type:"button",onClick:i,className:O("rounded-xl py-2 px-3 text-[12px] font-semibold flex items-center gap-1.5 border",o?"border-white/12 text-white/75 hover:bg-white/5":"border-[#182137]/12 text-[#182137] hover:bg-black/[0.03]"),children:[n.jsx(fc,{size:14}),c("notes.actions.hideNote",{defaultValue:"הסתר פתק"})]}),n.jsxs("button",{type:"button",onClick:a,className:O("rounded-xl py-2 px-3 text-[12px] font-semibold flex items-center gap-1.5 border",o?"border-red-400/30 text-red-300 hover:bg-red-500/10":"border-red-200 text-red-600 hover:bg-red-50"),children:[n.jsx(gi,{size:14}),c("notes.actions.delete",{defaultValue:"מחק"})]})]})]})})]})}function TF(t){return t==="yellow"||t==="pink"||t==="mint"||t==="blue"||t==="lavender"||t==="peach"}function QB(t,e){if(!Array.isArray(t))return[];const s=[];for(const o of t){if(!o||typeof o!="object")continue;const r=o;typeof r.id!="string"||!r.id||typeof r.wallId!="string"||!r.wallId||r.wallSide!=="front"&&r.wallSide!=="back"||typeof r.positionAlongWallMm!="number"||!Number.isFinite(r.positionAlongWallMm)||typeof r.centerHeightMm!="number"||!Number.isFinite(r.centerHeightMm)||typeof r.contentHtml=="string"&&TF(r.colorId)&&(e&&!e.has(r.wallId)||s.push({id:r.id,wallId:r.wallId,wallSide:r.wallSide,positionAlongWallMm:r.positionAlongWallMm,centerHeightMm:r.centerHeightMm,colorId:r.colorId,contentHtml:r.contentHtml}))}return s}function t9(){return`note_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function gj(t){return Math.max(0,Math.min(100,t))}function e9(t){if(!Array.isArray(t))return[];const e=[];for(const s of t){if(!s||typeof s!="object")continue;const o=s;typeof o.id!="string"||!o.id||typeof o.xPct!="number"||!Number.isFinite(o.xPct)||typeof o.yPct!="number"||!Number.isFinite(o.yPct)||typeof o.contentHtml=="string"&&TF(o.colorId)&&e.push({id:o.id,xPct:gj(o.xPct),yPct:gj(o.yPct),colorId:o.colorId,contentHtml:o.contentHtml,hidden:typeof o.hidden=="boolean"?o.hidden:!1,createdAt:typeof o.createdAt=="string"&&o.createdAt?o.createdAt:new Date().toISOString()})}return e}function n9(){return`viewport_note_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}const G3="application/x-floorplan-furniture";function o9(t){return JSON.stringify({type:t.type,label:t.label})}function s9(t){if(!t)return null;try{const e=JSON.parse(t);return typeof e.type!="string"||e.type.trim().length===0?null:{type:e.type,label:typeof e.label=="string"?e.label:void 0}}catch{return null}}function U3(t,e){t.setData(G3,o9(e)),t.setData("text/plain",e.label??e.type),t.effectAllowed="copy"}function r9(t){return s9(t.getData(G3))}const i9={tileWidthCm:100,tileHeightCm:270,groutWidthMm:3,groutColor:"#c8c4bc"};function a9(t){return i9}const l9=[{id:"kitchenAssembly.base30",spec:{kind:"base",labelHe:"תחתון 30",widthMm:300,depthMm:600,heightMm:870,front:{drawerCount:0,doorCount:1}}},{id:"kitchenAssembly.base60",spec:{kind:"base",labelHe:"תחתון 60",widthMm:600,depthMm:600,heightMm:870,front:{drawerCount:1,doorCount:2}}},{id:"kitchenAssembly.base80",spec:{kind:"base",labelHe:"תחתון 80",widthMm:800,depthMm:600,heightMm:870,front:{drawerCount:1,doorCount:2}}},{id:"kitchenAssembly.base90",spec:{kind:"base",labelHe:"תחתון 90",widthMm:900,depthMm:600,heightMm:870,front:{drawerCount:1,doorCount:2}}},{id:"kitchenAssembly.drawerBank60",spec:{kind:"base",labelHe:"ארון מגירות 60",widthMm:600,depthMm:600,heightMm:870,front:{drawerCount:4,doorCount:0}}},{id:"kitchenAssembly.drawerBank3",spec:{kind:"base",labelHe:"ארון 3 מגירות",widthMm:600,depthMm:600,heightMm:870,front:{drawerCount:3,doorCount:0}}},{id:"kitchenAssembly.trashPull",spec:{kind:"base",labelHe:"פינוי אשפה",widthMm:600,depthMm:600,heightMm:870,front:{drawerCount:0,doorCount:1}}},{id:"kitchenAssembly.bottlePull15",spec:{kind:"base",labelHe:"פינוי בקבוקים 15",widthMm:150,depthMm:600,heightMm:870,front:{drawerCount:0,doorCount:1}}},{id:"kitchenAssembly.wall40",spec:{kind:"wall",labelHe:"עליון 40",widthMm:400,depthMm:350,heightMm:720,front:{drawerCount:0,doorCount:1}}},{id:"kitchenAssembly.wall45",spec:{kind:"wall",labelHe:"עליון 45",widthMm:450,depthMm:350,heightMm:720,front:{drawerCount:0,doorCount:1}}},{id:"kitchenAssembly.wall60",spec:{kind:"wall",labelHe:"עליון 60",widthMm:600,depthMm:350,heightMm:720,front:{drawerCount:0,doorCount:2}}},{id:"kitchenAssembly.wall80",spec:{kind:"wall",labelHe:"עליון 80",widthMm:800,depthMm:350,heightMm:720,front:{drawerCount:0,doorCount:2}}},{id:"kitchenAssembly.hood",spec:{kind:"hoodWall",labelHe:"ארון מנדף",widthMm:600,depthMm:350,heightMm:500,front:{drawerCount:0,doorCount:0}}},{id:"kitchenAssembly.tall60",spec:{kind:"tall",labelHe:"גבוה 60",widthMm:600,depthMm:600,heightMm:2200,front:{drawerCount:1,doorCount:2}}},{id:"kitchenAssembly.supermarket40",spec:{kind:"tall",labelHe:"סופרמרקט 40",widthMm:400,depthMm:600,heightMm:2800,front:{drawerCount:0,doorCount:1}}}],c9={base:{drawerCount:1,doorCount:2},wall:{drawerCount:0,doorCount:2},tall:{drawerCount:1,doorCount:2},sinkBase:{drawerCount:0,doorCount:2},ovenTall:{drawerCount:1,doorCount:1},hoodWall:{drawerCount:0,doorCount:0}},d9={base:0,wall:1450,tall:0,sinkBase:0,ovenTall:0,hoodWall:1500}
278,zd=100,K3=-40,Z3="#DCD3C6",u9={base:0,wall:0,tall:zd,sinkBase:0,ovenTall:zd,hoodWall:0},bj="#E8DFD3",Mj=18;function q3(t,e,s,o=zd){const r=s.heightMm-o,i=lo(t,"side-0",[{x:0,y:r},{x:s.widthMm,y:r},{x:s.widthMm,y:s.heightMm},{x:0,y:s.heightMm}],e);return i?{...i,depthMm:K3,color:Z3}:null}function Wn(t,e){const s=e.startMm.x,o=e.startMm.y,r=e.endMm.x,i=e.endMm.y,a=r-s,l=i-o,c=Math.sqrt(a*a+l*l);if(c<1)return{vertices:_e(s,o,s+t.widthMm,o+t.depthMm),positionAlongWallMm:0};const d=a/c,u=l/c,h=e.side==="front"?-u:u,x=e.side==="front"?d:-d,f=e.positionAlongWallMm??Math.max(0,(c-t.widthMm)/2),p=Math.max(0,Math.min(Math.max(0,c-t.widthMm),f)),M=e.thicknessMm/2+t.depthMm,g=s+d*p+h*M,w=o+u*p+x*M,k=(_,j)=>({x:Math.round(g+d*_-h*j),y:Math.round(w+u*_-x*j)});return{vertices:[k(0,0),k(t.widthMm,0),k(t.widthMm,t.depthMm),k(0,t.depthMm)],positionAlongWallMm:p}}function h9(t,e={x:0,y:0},s){const o=Me(),r=be("fps_rect");let i,a;if(s){const p=Wn({widthMm:t.widthMm,depthMm:t.depthMm},s);i=p.vertices,a=p.positionAlongWallMm}else i=_e(e.x,e.y,e.x+t.widthMm,e.y+t.depthMm);const l=d9[t.kind],c={...Ae(i,"rectangle",r),heightMm:t.heightMm,baseHeightMm:l>0?l:void 0,groupId:o},d=t.front??c9[t.kind],h=Pb([c],r,"side-0",{drawerCount:d.drawerCount,doorCount:d.doorCount,toeKickMm:u9[t.kind]}).entities,x=h.map(p=>p.id),f={id:o,entityIds:x,name:t.labelHe,presetKind:t.kind,widthMm:t.widthMm,heightMm:t.heightMm,depthMm:t.depthMm,drawerCount:d.drawerCount,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:a,createdAt:Date.now()};return{entities:h,group:f,hostId:r}}function Pb(t,e,s="side-0",o){const r=t.find(k=>k.id===e&&k.kind==="polygon");if(!r)return{entities:t,patches:[]};const i="side-0",a=An(r,i);if(!a)return{entities:t,patches:[]};const l=r.groupId,c=t.filter(k=>k.kind!=="facePatch"||k.hostEntityId!==e||k.hostFaceId!==i?!0:!(l&&k.groupId===l)),d=Math.max(0,Math.min(6,Math.round(o.drawerCount))),u=Math.max(0,Math.min(4,Math.round(o.doorCount))),h=Math.max(80,Math.min(240,Math.round(o.topDrawerHeightMm??160))),x=Math.max(0,Math.min(a.heightMm-40,Math.round(o.toeKickMm??0))),f=a.heightMm-x,p=d>0?u>0?Math.min(d*h,Math.max(0,f-100)):f:0,b=d>0?p/d:0,M=[];for(let k=0;k<d;k+=1){const _=k*b,j=_+b,v=[{x:0,y:_},{x:a.widthMm,y:_},{x:a.widthMm,y:j},{x:0,y:j}],C=lo(e,i,v,l);C&&M.push({...C,depthMm:Mj,color:bj})}const g=p,w=f;if(u>0&&w-g>20){const k=a.widthMm/u;for(let _=0;_<u;_+=1){const j=_*k,v=j+k,N=lo(e,i,[{x:j,y:g},{x:v,y:g},{x:v,y:w},{x:j,y:w}],l);N&&M.push({...N,depthMm:Mj,color:bj})}}if(x>0){const k=q3(e,l,a,x);k&&M.push(k)}return{entities:[...c,...M],patches:M}}const J3=(t,e,s,o)=>[{x:Math.round(t),y:Math.round(e)},{x:Math.round(s),y:Math.round(e)},{x:Math.round(s),y:Math.round(o)},{x:Math.round(t),y:Math.round(o)}];function ee(t){const e=be("fps_rect"),s=_e(t.origin.x,t.origin.y,t.origin.x+t.widthMm,t.origin.y+t.depthMm);return{...Ae(s,"rectangle",e),heightMm:Math.max(1,Math.round(t.heightMm)),baseHeightMm:t.baseHeightMm&&t.baseHeightMm>0?Math.round(t.baseHeightMm):void 0,color:t.color,groupId:t.groupId}}function Da(t){const e=t.round?(()=>{const r=be("fps_circle"),i=t.origin.x+t.widthMm/2,a=t.origin.y+t.depthMm/2,l=Math.max(t.widthMm,t.depthMm)/2,c=Xl({x:i,y:a},l,t.segments??16);return{...Ae(c,"circle",r),heightMm:Math.max(1,Math.round(t.heightMm)),baseHeightMm:t.baseHeightMm&&t.baseHeightMm>0?Math.round(t.baseHeightMm):void 0,color:t.color,groupId:t.groupId}})():ee(t),s=t.taperTop!==void 0?Math.max(.05,Math.min(3,t.taperTop)):1,o=t.taperBottom!==void 0?Math.max(.05,Math.min(3,t.taperBottom)):1;return{...e,...s!==1?{topScaleX:s,topScaleY:s}:{},...o!==1?{bottomScaleX:o,bottomScaleY:o}:{}}}function $d(t,e,s){const o=An(t,"top");if(!o)return null;const r=o.widthMm,i=o.heightMm,a=Math.min(Math.round(e.widthMm),Math.max(20,Math.round(r-80))),l=Math.min(Math.round(e.depthMm),Math.max(20,Math.round(i-80))),c=r/2+(e.offsetXMm??0),d=i/2+(e.offsetYMm??0),u=lo(t.id,"top",J3(c-a/2,d-l/2,c+a/2,d+l/2),s);return u?{...u,depthMm:-Math.max(20,Math.round(e.downMm)),color:e.color}:null}function Ep(t){const e=be("fps_circle"),s=Xl(t.center,Math.max(4,Math.round(t.radiusMm)));return{...Ae(s,"circle",e),heightMm:Math.max(1,Math.round(t.heightMm)),baseHeightMm:t.baseHeightMm&&t.baseHeightMm>0?Math.round(t.baseHeightMm):void 0,color:t.color,groupId:t.groupId}}function Q1(t){const e=lo(t.hostId,t.faceId,J3(t.x0,t.y0,t.x1,t.y1),t.groupId);return e?{...e,depthMm:Math.round(t.depthMm),color:t.color}:null}function m9(t){const e=Xl({x:t.centerX,y:t.centerY},Math.max(4,Math.round(t.radiusMm))),s=lo(t.hostId,t.faceId,e,t.groupId);return s?{...s,depthMm:Math.round(t.depthMm),color:t.color}:null}function f9(t){const e=[],s=Math.max(1,Math.round(t.count)),r=(t.x1-t.x0)/s;for(let i=0;i<s;i+=1){const a=t.x0+i*r+(r-t.grooveWidthMm)/2,l=a+t.grooveWidthMm,c=lo(t.hostId,t.faceId,J3(a,t.y0,l,t.y1),t.groupId);c&&e.push({...c,depthMm:-Math.abs(Math.round(t.depthMm)),color:t.color})}return e}function wm(t){const e=Math.max(10,Math.round(t.thicknessMm??35)),s=Math.max(e,Math.round(t.spoutReachMm)),o=ee({origin:t.origin,widthMm:e,depthMm:e,baseHeightMm:t.baseHeightMm,heightMm:t.postHeightMm,color:t.color,groupId:t.groupId}),r=ee({origin:{x:t.origin.x,y:t.origin.y-s},widthMm:e,depthMm:s,baseHeightMm:t.baseHeightMm+t.postHeightMm-e,heightMm:e,color:t.color,groupId:t.groupId});return[o,r]}const x9={widthMm:3e3,depthMm:400,heightMm:2400},I2="#EFE9DF",p9="#F7F4EF",T2="#E4DCCE",g9="#CFC5B4",b9="#8C8377",yj=19,Id=8,nw=90,wj=70,ow=30,kj=18,Hl=24,M9=26,y9=-11,vj=30,SF=.38,sw=[3,4,3],c1=6,PF=.24,w9={openModuleFraction:SF,openColumnCompartments:sw,doorColumns:c1,upperBandFraction:PF,structThicknessMm:Hl,plinthHeightMm:nw,capHeightMm:ow,revealMm:Id};function k9(t,e){return{...t,vertices:t.vertices.map(e)}}function v9(t={x:0,y:0},e=x9,s){var ct;const o=Math.max(900,Math.round(e.widthMm)),r=Math.max(200,Math.round(e.depthMm)),i=Math.max(1e3,Math.round(e.heightMm)),a=Me();let l,c;if(s){const pt=Wn({widthMm:o,depthMm:r},s);l=pt.vertices,c=pt.positionAlongWallMm}else l=_e(t.x,t.y,t.x+o,t.y+r);const d=l[0],u=l[1],h=l[3],x=(u.x-d.x)/o,f=(u.y-d.y)/o,p=(h.x-d.x)/r,b=(h.y-d.y)/r,M=pt=>({x:Math.round(d.x+x*pt.x+p*pt.y),y:Math.round(d.y+f*pt.x+b*pt.y)}),g=[],w=pt=>g.push(k9(pt,M)),k=yj,_=r-k,j=nw,v=i-ow,C=(pt,xt,_t,Ft)=>{const Vt=xt-pt,vt=Ft-_t;if(Vt<40||vt<40)return;const Ht=ee({origin:{x:pt,y:0},widthMm:Vt,depthMm:yj,baseHeightMm:_t,heightMm:vt,color:p9,groupId:a});w(Ht);const Tt=Q1({hostId:Ht.id,faceId:"side-0",x0:vj,y0:12,x1:Vt-vj,y1:12+M9,depthMm:y9,color:I2,groupId:a});Tt&&g.push(Tt)};w(ee({origin:{x:0,y:wj},widthMm:o,depthMm:Math.max(40,r-wj),heightMm:nw,color:b9,groupId:a})),w(ee({origin:{x:0,y:0},widthMm:o,depthMm:r,baseHeightMm:v,heightMm:ow,color:I2,groupId:a}));const N=Math.round(o*SF),P=sw.length,L=(N-Hl*(P+1))/P,A=pt=>Hl+pt*(L+Hl),W=j,S=v;w(ee({origin:{x:0,y:r-kj},widthMm:N,depthMm:kj,baseHeightMm:W,heightMm:S-W,color:g9,groupId:a}));for(let pt=0;pt<=P;pt+=1){const xt=pt===0?0:A(pt-1)+L;w(ee({origin:{x:xt,y:k},widthMm:Hl,depthMm:_,baseHeightMm:W,heightMm:S-W,color:T2,groupId:a}))}for(const pt of[W,S-Hl])w(ee({origin:{x:0,y:k},widthMm:N,depthMm:_,baseHeightMm:pt,heightMm:Hl,color:T2,groupId:a}));const B=W+Hl,z=S-Hl-B;for(let pt=0;pt<P;pt+=1){const xt=sw[pt],_t=(z-Hl*(xt-1))/xt;for(let Ft=1;Ft<xt;Ft+=1){const Vt=B+Ft*_t+(Ft-1)*Hl;w(ee({origin:{x:A(pt),y:k},widthMm:L,depthMm:_,baseHeightMm:Math.round(Vt),heightMm:Hl,color:T2,groupId:a}))}}const X=N,ft=o-N;w(ee({origin:{x:X,y:k},widthMm:ft,depthMm:_,baseHeightMm:j,heightMm:v-j,color:I2,groupId:a}));const tt=X+Id,Y=(ft-Id*2-Id*(c1-1))/c1,J=j+Id,Mt=v-Id,Rt=Math.round((Mt-J)*PF),it=Mt-Rt-Id;for(let pt=0;pt<c1;pt+=1){const xt=tt+pt*(Y+Id);C(xt,xt+Y,J,it),C(xt,xt+Y,it+Id,Mt)}const st={id:a,entityIds:g.map(pt=>
278pt.id),name:"יחידת קיר סלון",widthMm:o,depthMm:r,heightMm:i,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:c,createdAt:Date.now()};return{entities:g,group:st,hostId:((ct=g[0])==null?void 0:ct.id)??a}}const j9={doorCount:3,doorWidthMm:600,depthMm:600,heightMm:2700},_9="#F7F4EF",E9="#E8DFD3",D9=20,F9=20,jj=4,C9=18;function N9(t={x:0,y:0},e=j9,s){const o=Math.max(1,Math.round(e.doorCount)),r=Math.max(200,Math.round(e.doorWidthMm)),i=o*r,a=Math.max(200,Math.round(e.depthMm)),l=Math.max(400,Math.round(e.heightMm)),c=Me(),d=be("fps_rect");let u,h;if(s){const k=Wn({widthMm:i,depthMm:a},s);u=k.vertices,h=k.positionAlongWallMm}else u=_e(t.x,t.y,t.x+i,t.y+a);const x={...Ae(u,"rectangle",d),heightMm:l,color:_9,groupId:c},f=[],p=(k,_,j,v,C,N)=>{const P=[{x:Math.round(k),y:Math.round(_)},{x:Math.round(j),y:Math.round(_)},{x:Math.round(j),y:Math.round(v)},{x:Math.round(k),y:Math.round(v)}],L=lo(d,"side-0",P,c);L&&f.push({...L,depthMm:C,color:N})},b=D9,M=l-F9;for(let k=0;k<o;k+=1){const _=k*r,j=_+r,v=k===0?_:_+jj/2,C=k===o-1?j:j-jj/2;p(v,b,C,M,C9,E9)}const g=[x,...f],w={id:c,entityIds:g.map(k=>k.id),name:"ארון בגדים",widthMm:i,depthMm:a,heightMm:l,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:h,createdAt:Date.now()};return{entities:g,group:w,hostId:d}}const I9={leftDoorMm:500,doorWidthMm:400,doorsLeftOfGlass:2,doorsRightOfGlass:3,glassWidthMm:500,glassNiches:6,depthMm:600,heightMm:2750},T9="#F7F4EF",S9="#E8DFD3",P9="#4A443D",_j="#182137",A9=20,L9=20,Ej=4,Dj=18,_g=25,Fj=26,Cj=24,Nj=26,W9=30,R9=.42;function O9(t={x:0,y:0},e=I9,s){const o=Math.max(200,Math.round(e.leftDoorMm)),r=Math.max(200,Math.round(e.doorWidthMm)),i=Math.max(0,Math.round(e.doorsLeftOfGlass)),a=Math.max(0,Math.round(e.doorsRightOfGlass)),l=Math.max(200,Math.round(e.glassWidthMm)),c=Math.max(1,Math.round(e.glassNiches)),d=Math.max(200,Math.round(e.depthMm)),u=Math.max(400,Math.round(e.heightMm)),h=[];h.push({type:"door",widthMm:o,handle:"right"});for(let L=0;L<i;
278L+=1)h.push({type:"door",widthMm:r,handle:"none"});h.push({type:"glass",widthMm:l});for(let L=0;L<a;L+=1){const A=L===a-1;h.push({type:"door",widthMm:r,handle:A?"left":"none"})}const x=h.reduce((L,A)=>L+A.widthMm,0),f=Me(),p=be("fps_rect");let b,M;if(s){const L=Wn({widthMm:x,depthMm:d},s);b=L.vertices,M=L.positionAlongWallMm}else b=_e(t.x,t.y,t.x+x,t.y+d);const g={...Ae(b,"rectangle",p),heightMm:u,color:T9,groupId:f},w=[],k=(L,A,W,S,B,R)=>{const z=[{x:Math.round(L),y:Math.round(A)},{x:Math.round(W),y:Math.round(A)},{x:Math.round(W),y:Math.round(S)},{x:Math.round(L),y:Math.round(S)}],X=lo(p,"side-0",z,f);X&&w.push({...X,depthMm:B,color:R})},_=A9,j=u-L9,v=h.length;let C=0;h.forEach((L,A)=>{const W=C,S=C+L.widthMm;if(C=S,L.type==="door"){const Mt=A===0?W:W+Ej/2,Rt=A===v-1?S:S-Ej/2;if(k(Mt,_,Rt,j,Dj,S9),L.handle&&L.handle!=="none"){const it=(j-_)*R9,st=_+(j-_-it)/2,ct=st+it,pt=28,xt=L.handle==="right"?Rt-pt-Nj:Mt+pt,_t=xt+Nj;k(xt,st,_t,ct,W9,_j)}return}const B=W+_g,R=S-_g,z=_+_g,ft=j-_g-z,tt=-(d-40),G=(ft-Fj*(c-1))/c;for(let Mt=0;Mt<c;Mt+=1){const Rt=z+Mt*(G+Fj),it=Rt+G;k(B,Rt,R,it,tt,P9)}const Y=(W+S)/2-Cj/2,J=Y+Cj;k(Y,_,J,j,Dj+4,_j)});const N=[g,...w],P={id:f,entityIds:N.map(L=>L.id),name:"ארון קיר עם ויטרינה",widthMm:x,depthMm:d,heightMm:u,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:M,createdAt:Date.now()};return{entities:N,group:P,hostId:p}}const H9="#F7F4EF",Ij="#E8DFD3",Wx="#DDD3C4",B9="#6B6558",V9="#3B3B3D",z9="#C7CBD0",$9="#20262F",X9="#D8C7B0",Eg=24,Tj=4,Cu=6,Sj=24,Pj=18,Y9=40,G9={labelHe:"ארון נגרות",widthMm:600,depthMm:600,heightMm:2700,compartments:[{kind:"doors",count:2}]};function U9(t={x:0,y:0},e=G9,s){const o=Math.max(200,Math.round(e.widthMm)),r=Math.max(200,Math.round(e.depthMm)),i=Math.max(400,Math.round(e.heightMm)),a=-(r-Y9),l=Me(),c=be("fps_rect");let d,u;if(s){const j=Wn({widthMm:o,depthMm:r},s);d=j.vertices,u=j.positionAlongWallMm}else d=_e(t.x,t.y,t.x+o,t.y+r);const h={...Ae(d,"rectangle",c),heightMm:i,color:H9,groupId:l},x=[],f=(j,v,C,N,P,L)=>{const A=i-v,W=i-N,S={x:Math.round(Math.min(j,C)),y:Math.round(Math.min(A,W))},B={x:Math.round(Math.max(j,C)),y:Math.round(Math.max(A,W))},R=[{x:S.x,y:S.y},{x:B.x,y:S.y},{x:B.x,y:B.y},{x:S.x,y:B.y}],z=lo(c,"side-0",R,l);z&&x.push({...z,depthMm:P,color:L})},p=(j,v,C,N,P)=>{const L=Math.max(1,P),A=(N-C-Sj*(L-1))/L;for(let W=0;W<L;W+=1){const S=C+W*(A+Sj);f(j,S,v,S+A,a,Wx)}},b=e.compartments.reduce((j,v)=>j+(v.heightMm??0),0),M=e.compartments.filter(j=>j.heightMm===void 0).length,g=M>0?Math.max(0,(i-b)/M):0;let w=0;for(const j of e.compartments){const v=w,C=j.heightMm??g,N=Math.min(i,v+C);if(w=N,N-v<40)continue;const P=Eg,L=o-Eg,A=v+Eg,W=N-Eg;switch(j.kind){case"drawers":{const S=Math.max(1,j.count??3),B=(N-v-Cu*(S+1))/S;for(let R=0;R<S;R+=1){const z=v+Cu+R*(B+Cu);f(Tj,z,o-Tj,z+B,Pj,Ij)}break}case"doors":{const S=Math.max(1,j.count??2),B=(o-Cu*(S+1))/S;for(let R=0;R<S;R+=1){const z=Cu+R*(B+Cu);f(z,v+Cu,z+B,N-Cu,Pj,Ij)}break}case"openShelves":{p(P,L,A,W,j.count??4);break}case"rail":{const S=A+60,B=S+34;f(P,A,L,S,a,Wx),f(P+20,S,L-20,B,-70,B9),f(P,B,L,W,a,Wx);break}case"shoe":{p(P,L,A,W,j.count??3);break}case"appliance":{f(P,A,L,W,a,Wx);const S=P+20,B=L-20,R=A+20,z=W-20;f(S,R,B,z,-30,V9);const X=(S+B)/2,ft=(R+z)/2,tt=Math.min(B-S,z-R)*.36;f(X-tt,ft-tt,X+tt,ft+tt,-18,z9),f(X-tt*.62,ft-tt*.62,X+tt*.62,ft+tt*.62,-12,$9);break}case"ironingSlot":{const S=Math.min((L-P)/2,110),B=(P+L)/2;f(B-S,A,B+S,W,a,Wx),f(B-S*.7,A+30,B+S*.7,W-30,-60,X9);break}}}const k=[h,...x],_={id:l,entityIds:k.map(j=>j.id),name:e.labelHe,widthMm:o,depthMm:r,heightMm:i,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:u,createdAt:Date.now()};return{entities:k,group:_,hostId:c}}const Aj=()=>[{kind:"openShelves",count:2},{kind:"appliance",heightMm:850},{kind:"drawers",count:1,heightMm:100},{kind:"drawers",count:1,heightMm:620}],AF=[{id:"carpentryBedroom.shelfDrawer60",category:"carpentryBedroom",spec:{labelHe:"ארון 60 מדפים + מגירות",widthMm:600,depthMm:600,heightMm:2700,compartments:[{kind:"openShelves",count:4}
278,{kind:"drawers",count:3,heightMm:720}]}},{id:"carpentryBedroom.rail120",category:"carpentryBedroom",spec:{labelHe:"ארון 120 מתלה בגדים",widthMm:1200,depthMm:600,heightMm:2700,compartments:[{kind:"openShelves",count:1,heightMm:380},{kind:"rail"}]}},{id:"carpentryBedroom.rail90",category:"carpentryBedroom",spec:{labelHe:"ארון 90 מתלה + מגירות + נעליים",widthMm:900,depthMm:600,heightMm:2700,compartments:[{kind:"rail"},{kind:"drawers",count:2,heightMm:460},{kind:"shoe",count:2,heightMm:400}]}},{id:"carpentryBedroom.openShelves60",category:"carpentryBedroom",spec:{labelHe:"ארון מדפים פתוח",widthMm:600,depthMm:600,heightMm:2700,compartments:[{kind:"openShelves",count:6}]}},{id:"carpentryUtility.washingMachine",category:"carpentryUtility",spec:{labelHe:"ארון מכונת כביסה",widthMm:650,depthMm:600,heightMm:2700,compartments:Aj()}},{id:"carpentryUtility.dryer",category:"carpentryUtility",spec:{labelHe:"ארון מייבש",widthMm:650,depthMm:600,heightMm:2700,compartments:Aj()}},{id:"carpentryUtility.vacuum30",category:"carpentryUtility",spec:{labelHe:"ארון שואב אבק 30",widthMm:300,depthMm:600,heightMm:2700,compartments:[{kind:"doors",count:1,heightMm:500},{kind:"openShelves",count:1}]}},{id:"carpentryUtility.ironing30",category:"carpentryUtility",spec:{labelHe:"ארון קרש גיהוץ 30",widthMm:300,depthMm:600,heightMm:2700,compartments:[{kind:"drawers",count:1,heightMm:260},{kind:"ironingSlot"}]}}],LF={widthMm:800,depthMm:600,heightMm:870,counterThicknessMm:30,sideOverhangMm:20,frontOverhangMm:25,doorCount:2},K9="#F7F4EF",Z9="#DDD3C4",q9="#C4BAA9",J9="#182137";function Lj(t,e){return{...t,vertices:t.vertices.map(e)}}function Wj(t={x:0,y:0},e=LF,s){const o=Math.max(300,Math.round(e.widthMm)),r=Math.max(300,Math.round(e.depthMm)),i=Math.max(400,Math.round(e.heightMm)),a=Math.max(20,Math.round(e.counterThicknessMm)),l=Math.max(0,Math.round(e.sideOverhangMm)),c=Math.max(0,Math.round(e.frontOverhangMm)),d=Me(),u=be("fps_rect");let h,x;if(s){const R=Wn({widthMm:o,depthMm:r},s);h=R.vertices,x=R.positionAlongWallMm}else{const R=Math.round(t.x),z=Math.round(t.y);h=_e(R,z,R+o,z+r)}const f=h[0],p=h[1],b=h[3],M=(p.x-f.x)/o,g=(p.y-f.y)/o,w=(b.x-f.x)/r,k=(b.y-f.y)/r,_=R=>({x:Math.round(f.x+M*R.x+w*R.y),y:Math.round(f.y+g*R.x+k*R.y)}),j={...Ae(h,"rectangle",u),heightMm:i,color:K9,groupId:d},v=Pb([j],u,"side-0",{drawerCount:0,doorCount:Math.max(1,Math.round(e.doorCount))}),C=ee({origin:{x:-l,y:-c},widthMm:o+l*2,depthMm:r+c,baseHeightMm:i,heightMm:a,color:Z9,groupId:d}),N=Lj(C,_),P=$d(N,{widthMm:Math.round(o*.58),depthMm:Math.round(r*.6),downMm:180,offsetYMm:-40,color:q9},d),L=35,W=wm({origin:{x:Math.round(o/2)-Math.round(L/2),y:r-70-L},baseHeightMm:i+a,postHeightMm:240,spoutReachMm:200,thicknessMm:L,color:J9,groupId:d}).map(R=>Lj(R,_)),S=[...v.entities,N,...P?[P]:[],...W],B={id:d,entityIds:S.map(R=>R.id),name:"יחידת כיור מטבח",widthMm:o,depthMm:r,heightMm:i,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:x,createdAt:Date.now()};return{entities:S,group:B,hostId:u}}const Q9="#F7F4EF",lp="#E8DFD3",WF="#C4BAA9",tV="#DDD3C4",cp=18,d1=4,Rj=12;function eV(t,e){const[s,o,r,i]=t,a=Math.hypot(o.x-s.x,o.y-s.y),l=Math.hypot(r.x-o.x,r.y-o.y),c=Math.max(20,Math.min(e,a-40,l-40));if(!Number.isFinite(c)||c<20)return t;const d={x:(o.x-s.x)/a,y:(o.y-s.y)/a},u={x:(r.x-o.x)/l,y:(r.y-o.y)/l},h={x:o.x-d.x*c,y:o.y-d.y*c},x={x:o.x+u.x*c,y:o.y+u.y*c},f={x:h.x+u.x*c,y:h.y+u.y*c},p=Math.atan2(h.y-f.y,h.x-f.x);let M=Math.atan2(x.y-f.y,x.x-f.x)-p;for(;M>Math.PI;)M-=2*Math.PI;for(;M<-Math.PI;)M+=2*Math.PI;const g=[];for(let w=1;w<Rj;w++){const k=p+M*(w/Rj);g.push({x:Math.round(f.x+c*Math.cos(k)),y:Math.round(f.y+c*Math.sin(k))})}return[s,{x:Math.round(h.x),y:Math.round(h.y)},...g,{x:Math.round(x.x),y:Math.round(x.y)},r,i]}function lm(t,e,s,o,r,i,a,l){const c=lo(t,"side-0",[{x:s,y:o},{x:r,y:o},{x:r,y:i},{x:s,y:i}],e);return c?{...c,depthMm:a,color:l}:null}function nV(t,e,s){const o=t.vertices[0],r=t.vertices[1],i=t.vertices[t.vertices.length-1],a=(r.x-o.x)/e,l=(r.y-o.y)/e,c=(i.x-o.x)/s,d=(i.y-o.y)/s;return u=>({x:Math.round(o.x+a*u.x+c*u.y),y:Math.round(o.y+l*u.x+d*u.y)})}function RF(t,e,s,o,r,i,a,l){const c=_e(s,o,r,i).map(e);return{...Ae(c,"rectangle",be("fps_rect")),heightMm:Math.max(1,Math.round(l)),baseHeightMm:a>0?Math.round(a):void 0,color:tV,groupId:t}}function Ab(t,e,s,o,r,i,a,l){const c=e,d=s,u=o,h=Me(),x=be("fps_rect");let f,p;if(a){const v=Wn({widthMm:c,depthMm:d},a);f=v.vertices,p=v.positionAlongWallMm}else f=_e(i.x,i.y,i.x+c,i.y+d);const b=eV(f,r),M={...Ae(b,"polygon",x),heightMm:u,color:Q9,groupId:h},g=An(M,"side-0"),w=(g==null?void 0:g.widthMm)??Math.max(40,c-r),k=l({host:M,flatW:w,H:u,D:d,toWorld:nV(M,w,d)}
278).filter(Boolean),_=[M,...k],j={id:h,entityIds:_.map(v=>v.id),name:t,widthMm:c,depthMm:d,heightMm:u,wallId:a==null?void 0:a.wallId,wallSide:a==null?void 0:a.side,wallPositionMm:p,createdAt:Date.now()};return{entities:_,group:j,hostId:x}}function oV(t={x:0,y:0},e,s){return Ab("גבוה — קצה עגול",600,600,2200,200,t,s,o=>{const r=Math.round(o.flatW/2);return[lm(o.host.id,o.host.groupId,0,0,r-d1,o.H,cp,lp),lm(o.host.id,o.host.groupId,r,0,o.flatW,o.H,cp,lp)].filter(i=>!!i)})}function sV(t={x:0,y:0},e,s){return Ab("נמוך — קצה עגול",600,600,870,150,t,s,o=>{const i=Math.round(o.flatW/2);return[lm(o.host.id,o.host.groupId,0,0,o.flatW,160,cp,lp),lm(o.host.id,o.host.groupId,0,160+d1,i-d1,o.H,cp,lp),lm(o.host.id,o.host.groupId,i,160+d1,o.flatW,o.H,cp,lp)].filter(a=>!!a)})}function rV(t={x:0,y:0},e,s){return Ab("קצה עגול + נישה",900,600,2200,450,t,s,o=>{const r=Math.max(60,o.flatW-8),i=o.D-60,a=[],l=lm(o.host.id,o.host.groupId,8,120,r,o.H-120,-i,WF);l&&a.push(l);for(const c of[760,1430])a.push(RF(o.host.groupId,o.toWorld,8,20,r,i,c,20));return a})}function iV(t={x:0,y:0},e,s){return Ab("קצה עגול + מדפים פתוחים",900,600,2200,450,t,s,o=>{const r=Math.max(60,o.flatW-8),i=o.D-60,a=[],l=lm(o.host.id,o.host.groupId,8,80,r,o.H-80,-i,WF);l&&a.push(l);for(const c of[480,900,1320,1740])a.push(RF(o.host.groupId,o.toWorld,8,20,r,i,c,18));return a})}const aV="#DDD3C4",Oj=2400,Dg=640,Hj=30,lV=870,S2=40;function cV(t={x:0,y:0},e,s,o){const r=Me(),i=be("fps_rect");let a,l=Oj,c=Dg,d;if(s){const f=Math.hypot(s.endMm.x-s.startMm.x,s.endMm.y-s.startMm.y);l=Math.max(300,Math.round(f));const p=Wn({widthMm:l,depthMm:Dg},{...s,positionAlongWallMm:0});a=p.vertices,c=Dg,d=p.positionAlongWallMm}else if(o){const f=Math.round(o.minX-S2),p=Math.round(o.maxX+S2),b=Math.round(o.minY-S2),M=Math.round(o.maxY);a=_e(f,b,p,M),l=p-f,c=M-b}else a=_e(t.x,t.y,t.x+Oj,t.y+Dg);const u={...Ae(a,"rectangle",i),heightMm:Hj,baseHeightMm:lV,color:aV,groupId:r},h={id:r,entityIds:[i],name:"משטח עבודה",widthMm:l,depthMm:c,heightMm:Hj,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:d,createdAt:Date.now()};return{entities:[u],group:h,hostId:i}}const OF="#F7F4EF",HF="#E8DFD3",BF=18,Hc=4,Qx=600,dV=600,af=Qx+dV;function Bj(t,e,s,o,r){const i=An(e,s);if(!i)return[];const a=[],l=i.widthMm/r;for(let c=0;c<r;c++){const d=c*l+(c===0?Hc:Hc/2),u=(c+1)*l-(c===r-1?Hc:Hc/2),h=lo(t,s,[{x:d,y:0},{x:u,y:0},{x:u,y:i.heightMm},{x:d,y:i.heightMm}],o);h&&a.push({...h,depthMm:BF,color:HF})}return a}function VF(t,e,s,o){const r=o?{x:Math.round(o.startMm.x),y:Math.round(o.startMm.y)}:s,i=Me(),a=be("fps_rect"),l=[{x:r.x+Qx,y:r.y},{x:r.x+af,y:r.y},{x:r.x+af,y:r.y+af},{x:r.x,y:r.y+af},{x:r.x,y:r.y+Qx},{x:r.x+Qx,y:r.y+Qx}],c={...Ae(l,"polygon",a),heightMm:e,color:OF,groupId:i},d=[...Bj(a,c,"side-4",i,1),...Bj(a,c,"side-5",i,1)],u=[c,...d],h={id:i,entityIds:u.map(x=>x.id),name:t,widthMm:af,depthMm:af,heightMm:e,createdAt:Date.now()};return{entities:u,group:h,hostId:a}}function uV(t={x:0,y:0},e,s){return VF("ארון פינה L",870,t,s)}function hV(t={x:0,y:0},e,s){return VF("ארון פינה L גבוה",2200,t,s)}function mV(t={x:0,y:0},e,s){const a=Me(),l=be("fps_rect");let c,d;if(s){const b=Wn({widthMm:900,depthMm:900},s);c=b.vertices,d=b.positionAlongWallMm}else c=_e(t.x,t.y,t.x+900,t.y+900);const u={...Ae(c,"rectangle",l),heightMm:870,color:OF,groupId:a},h=An(u,"side-0"),x=[];if(h){const b=h.heightMm-zd,M=h.widthMm/2;for(let w=0;w<2;w++){const k=w*M+(w===0?Hc:Hc/2),_=(w+1)*M-(w===1?Hc:Hc/2),j=lo(l,"side-0",[{x:k,y:Hc},{x:_,y:Hc},{x:_,y:b},{x:k,y:b}],a);j&&x.push({...j,depthMm:BF,color:HF})}const g=q3(l,a,h,zd);g&&x.push(g)}const f=[u,...x],p={id:a,entityIds:f.map(b=>b.id),name:"פינת קרוסלה",widthMm:900,depthMm:900,heightMm:870,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:d,createdAt:Date.now()};return{entities:f,group:p,hostId:l}}const Lb="#F7F4EF",Gu="#E8DFD3",tb="#2A2B30",eb="#9AA0A6",fV="#3A352F",mc=18,ti=4,xV=870;function Wb(t,e,s,o){if(e){const r=Wn({widthMm:s,depthMm:o},e);return{verts:r.vertices,wallPositionMm:r.positionAlongWallMm}}return{verts:_e(t.x,t.y,t.x+s,t.y+o),wallPositionMm:void 0}}function pV(t,e,s){const o=t[0],r=t[1],i=t[3],a=(r.x-o.x)/e,l=(r.y-o.y)/e,c=(i.x-o.x)/s,d=(i.y-o.y)/s;return u=>({x:Math.round(o.x+a*u.x+c*u.y),y:Math.round(o.y+l*u.x+d*u.y)})}function cm(t,e,s,o,r,i,a,l){const c=lo(t,"side-0",[{x:s,y:o},{x:r,y:o},{x:r,y:i},{x:s,y:i}],e);return c?{...c,depthMm:a,color:l}:null}function Rb(t,e,s,o,r,i,a,l){return{id:t,entityIds:e.map(c=>c.id),name:s,widthMm:o,depthMm:r,heightMm:i,wallId:a==null?void 0:a.wallId,wallSide:a==null?void 0:a.side,wallPositionMm:l,createdAt:Date.now()}}function gV(t={x:0,y:0},e,s){const i=xV,a=30,l=Me(),c=be("fps_rect"),{verts:d,wallPositionMm:u}=Wb(t,s,600,600),h={...Ae(d,"rectangle",c),heightMm:i,color:Lb,groupId:l},x=[],f=150,p=410,b=cm(c,l,ti,ti,600-ti,f,mc,Gu),M=cm(c,l,ti,f+ti,600-ti,p,mc,Gu),g=cm(c,l,ti,p+ti,600-ti,i-ti,mc,Gu);b&&x.push(b),M&&x.push(M),g&&x.push(g);const w=pV(d,600,600),k=_e(8,8,592,592).map(w);x.push({...Ae(k,"rectangle",be("fps_rect")),heightMm:a,baseHeightMm:i,color:tb,groupId:l});const _=i+a,j=[{x:600*.28,y:600*.32},{x:600*.72,y:600*.32},{x:600*.28,y:600*.72},{x:600*.72,y:600*.72}];
278for(const C of j)x.push({...Ae(Xl(w(C),90,24),"circle",be("fps_circle")),heightMm:6,baseHeightMm:_,color:fV,groupId:l});const v=[h,...x];return{entities:v,group:Rb(l,v,"כיריים",600,600,i+a,s,u),hostId:c}}function bV(t={x:0,y:0},e,s){const a=Me(),l=be("fps_rect"),{verts:c,wallPositionMm:d}=Wb(t,s,600,600),u={...Ae(c,"rectangle",l),heightMm:2700,color:Lb,groupId:a},h=ti,x=600-ti,f=[],p=w=>{w&&f.push(w)},b=(w,k,_,j,v,C)=>p(cm(l,a,w,2700-_,j,2700-k,v,C));b(h,0,zd,x,K3,Z3),b(h,zd,760,x,mc,Gu),b(h,1805,2696,x,mc,Gu),b(h+16,795,1360,x-16,4,tb),b(h+60,1300,1325,x-60,mc+8,eb);const M=Math.round(h+16+(x-16-(h+16))*.64);b(h+16,1410,1770,M,4,tb),b(M+8,1410,1770,x-16,6,eb);const g=[u,...f];return{entities:g,group:Rb(a,g,"מגדל תנור + מיקרו",600,600,2700,s,d),hostId:l}}function MV(t={x:0,y:0},e,s){const a=Me(),l=be("fps_rect"),{verts:c,wallPositionMm:d}=Wb(t,s,600,600),u={...Ae(c,"rectangle",l),heightMm:2200,color:Lb,groupId:a},h=ti,x=600-ti,f=[],p=g=>{g&&f.push(g)},b=(g,w,k,_,j,v)=>p(cm(l,a,g,2200-k,_,2200-w,j,v));b(h,0,zd,x,K3,Z3),b(h,zd,880,x,mc,Gu),b(h+16,900,1495,x-16,4,tb),b(h+60,1435,1460,x-60,mc+8,eb),b(h,1515,2180,x,mc,Gu);const M=[u,...f];return{entities:M,group:Rb(a,M,"עמודת תנור",600,600,2200,s,d),hostId:l}}function yV(t={x:0,y:0},e,s){const a=Me(),l=be("fps_rect"),{verts:c,wallPositionMm:d}=Wb(t,s,600,600),u={...Ae(c,"rectangle",l),heightMm:870,color:Lb,groupId:a},h=[],x=cm(l,a,ti,ti,600-ti,55,mc,eb),f=cm(l,a,ti,60,600-ti,870-ti,mc,Gu);x&&h.push(x),f&&h.push(f);const p=[u,...h];return{entities:p,group:Rb(a,p,"מדיח כלים",600,600,870,s,d),hostId:l}}const wV="#F7F4EF",kV="#DCD3C6",vV=10,lf=4;function jV(t={x:0,y:0},e,s){const l=Me(),c=be("fps_rect");let d,u;if(s){const g=Wn({widthMm:600,depthMm:350},s);d=g.vertices,u=g.positionAlongWallMm}else d=_e(t.x,t.y,t.x+600,t.y+350);const h={...Ae(d,"rectangle",c),heightMm:600,baseHeightMm:900,color:wV,groupId:l},x=[],f=8,p=600/f;for(let g=0;g<f;g++){const w=g*p+lf/2,k=(g+1)*p-lf/2,_=lo(c,"side-0",[{x:lf,y:w},{x:600-lf,y:w},{x:600-lf,y:k},{x:lf,y:k}],l);_&&x.push({..._,depthMm:vV,color:kV})}const b=[h,...x],M={id:l,entityIds:b.map(g=>g.id),name:"ארון תריס",widthMm:600,depthMm:350,heightMm:600,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:u,createdAt:Date.now()};return{entities:b,group:M,hostId:c}}const _V={widthMm:2800,depthMm:900,heightMm:870,counterThicknessMm:30,wrapPanelThicknessMm:30,drawerColumnWidthMm:660,drawerHeights:[190,190,380],centerDoorWidthMm:400,dwPanelWidthMm:600,revealMm:20},EV="#F7F4EF",Rx="#E8DFD3",P2="#DDD3C4",DV="#C4BAA9",FV="#182137",CV=18;function Fg(t,e){return{...t,vertices:t.vertices.map(e)}}function NV(t={x:0,y:0},e=_V,s){const o=Math.max(1200,Math.round(e.widthMm)),r=Math.max(500,Math.round(e.depthMm)),i=Math.max(500,Math.round(e.heightMm)),a=Math.max(20,Math.round(e.counterThicknessMm)),l=Math.max(0,Math.round(e.wrapPanelThicknessMm)),c=Math.max(200,Math.round(e.drawerColumnWidthMm)),d=Math.max(200,Math.round(e.centerDoorWidthMm)),u=Math.max(300,Math.round(e.dwPanelWidthMm)),h=Math.max(0,Math.round(e.revealMm)),x=e.drawerHeights.map(Tt=>Math.max(40,Math.round(Tt))),f=Me(),p=be("fps_rect");let b,M;if(s){const Tt=Wn({widthMm:o,depthMm:r},s);b=Tt.vertices,M=Tt.positionAlongWallMm}else{const Tt=Math.round(t.x),Zt=Math.round(t.y);b=_e(Tt,Zt,Tt+o,Zt+r)}const g=b[0],w=b[1],k=b[3],_=(w.x-g.x)/o,j=(w.y-g.y)/o,v=(k.x-g.x)/r,C=(k.y-g.y)/r,N=Tt=>({x:Math.round(g.x+_*Tt.x+v*Tt.y),y:Math.round(g.y+j*Tt.x+C*Tt.y)}),P={...Ae(b,"rectangle",p),heightMm:i,color:EV,groupId:f},L=[],A=(Tt,Zt,At,ut,kt)=>{const Et=lo(p,"side-0",[{x:Tt,y:Zt},{x:At,y:Zt},{x:At,y:ut},{x:Tt,y:ut}],f);Et&&L.push({...Et,depthMm:CV,color:kt})}
278,W=0,S=W+c,B=S+h,R=B+d,z=R+h,X=z+d,ft=X+h,tt=ft+u,G=tt+h,Y=G+c;let J=0;for(const Tt of x)A(W,J,S,J+Tt,Rx),J+=Tt;const Mt=J;A(B,0,R,Mt,Rx),A(z,0,X,Mt,Rx),A(ft,0,tt,Mt,Rx),J=0;for(const Tt of x)A(G,J,Y,J+Tt,Rx),J+=Tt;const Rt=[];if(l>0){const Tt=ee({origin:{x:-l,y:0},widthMm:l,depthMm:r,baseHeightMm:0,heightMm:i,color:P2,groupId:f}),Zt=ee({origin:{x:o,y:0},widthMm:l,depthMm:r,baseHeightMm:0,heightMm:i,color:P2,groupId:f});Rt.push(Fg(Tt,N),Fg(Zt,N))}const it=ee({origin:{x:-l,y:0},widthMm:o+l*2,depthMm:r,baseHeightMm:i,heightMm:a,color:P2,groupId:f}),st=Fg(it,N),ct=Math.max(400,Math.round(o*.21)),pt=Math.max(300,Math.round(r*.55)),xt=$d(st,{widthMm:ct,depthMm:pt,downMm:180,offsetYMm:-40,color:DV},f),_t=35,Vt=wm({origin:{x:Math.round(o/2)-Math.round(_t/2),y:r-70-_t},baseHeightMm:i+a,postHeightMm:240,spoutReachMm:200,thicknessMm:_t,color:FV,groupId:f}).map(Tt=>Fg(Tt,N)),vt=[P,...L,...Rt,st,...xt?[xt]:[],...Vt],Ht={id:f,entityIds:vt.map(Tt=>Tt.id),name:"אי מטבח עם בר",widthMm:o,depthMm:r,heightMm:i,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:M,createdAt:Date.now()};return{entities:vt,group:Ht,hostId:p}}const zF={widthMm:2600,depthMm:1200,heightMm:870,counterThicknessMm:30,wrapPanelThicknessMm:30,drawerColumnWidthMm:600,drawerHeights:[190,190,380],revealMm:20},IV={...zF,widthMm:3400},TV="#F7F4EF",A2="#E8DFD3",L2="#DDD3C4",SV="#C4BAA9",PV="#182137",AV="#2A2B30",LV="#3A352F",WV=18,cf=760,Cg=520,Vj=14;function u1(t,e){return{...t,vertices:t.vertices.map(e)}}function RV(t,e,s,o,r,i,a){const l=[],c=(w,k,_,j,v)=>{const C=lo(t,"side-0",[{x:w,y:k},{x:_,y:k},{x:_,y:j},{x:w,y:j}],e);C&&l.push({...C,depthMm:WV,color:v})},d=i.reduce((w,k)=>w+k,0),u=0,h=u+r,x=s,f=x-r;let p=0;for(const w of i)c(u,p,h,p+w,A2),p+=w;p=0;for(const w of i)c(f,p,x,p+w,A2),p+=w;const b=h+a,g=f-a-b;if(g>200){const w=Math.max(1,Math.round(g/500)),k=g/w;for(let _=0;_<w;_+=1){const j=b+_*k+a/2,v=b+(_+1)*k-a/2;c(j,0,v,d,A2)}}return l}function $F(t){const{toWorld:e,hobCx:s,hobCy:o,H:r,counterT:i,groupId:a}=t,l=[],c=r+i,d=s-cf/2,u=o-Cg/2,h=s+cf/2,x=o+Cg/2,f=_e(d,u,h,x).map(e);l.push({...Ae(f,"rectangle",be("fps_rect")),heightMm:Vj,baseHeightMm:c,color:AV,groupId:a});const p=c+Vj,b=o-Cg*.24,M=o+Cg*.24,g=[{x:s-cf*.32,y:b},{x:s,y:b},{x:s+cf*.32,y:b},{x:s-cf*.18,y:M},{x:s+cf*.18,y:M}];for(const w of g)l.push({...Ae(Xl(e(w),90,24),"circle",be("fps_circle")),heightMm:6,baseHeightMm:p,color:LV,groupId:a});return l}function XF(t,e,s){const o=Math.max(1200,Math.round(e.widthMm)),r=Math.max(500,Math.round(e.depthMm)),i=Math.max(500,Math.round(e.heightMm)),a=Math.max(20,Math.round(e.counterThicknessMm)),l=Math.max(0,Math.round(e.wrapPanelThicknessMm)),c=Math.max(200,Math.round(e.drawerColumnWidthMm)),d=Math.max(0,Math.round(e.revealMm)),u=e.drawerHeights.map(W=>Math.max(40,Math.round(W))),h=Me(),x=be("fps_rect");let f,p;if(s){const W=Wn({widthMm:o,depthMm:r},s);f=W.vertices,p=W.positionAlongWallMm}else{const W=Math.round(t.x),S=Math.round(t.y);f=_e(W,S,W+o,S+r)}const b=f[0],M=f[1],g=f[3],w=(M.x-b.x)/o,k=(M.y-b.y)/o,_=(g.x-b.x)/r,j=(g.y-b.y)/r,v=W=>({x:Math.round(b.x+w*W.x+_*W.y),y:Math.round(b.y+k*W.x+j*W.y)}),C={...Ae(f,"rectangle",x),heightMm:i,color:TV,groupId:h},N=RV(x,h,o,i,c,u,d),P=[];if(l>0){const W=ee({origin:{x:-l,y:0},widthMm:l,depthMm:r,baseHeightMm:0,heightMm:i,color:L2,groupId:h}),S=ee({origin:{x:o,y:0},widthMm:l,depthMm:r,baseHeightMm:0,heightMm:i,color:L2,groupId:h});P.push(u1(W,v),u1(S,v))}const L=ee({origin:{x:-l,y:0},widthMm:o+l*2,depthMm:r,baseHeightMm:i,heightMm:a,color:L2,groupId:h}),A=u1(L,v);return{W:o,D:r,H:i,counterT:a,groupId:h,hostId:x,host:C,frontPatches:N,sidePanels:P,counterSlab:A,toWorld:v,wallPositionMm:p}}function YF(t,e,s,o){return{id:t.groupId,entityIds:e.map(r=>r.id),name:s,widthMm:t.W,depthMm:t.D,heightMm:t.H,wallId:o==null?void 0:o.wallId,wallSide:o==null?void 0:o.side,wallPositionMm:t.wallPositionMm,createdAt:Date.now()}}function OV(t={x:0,y:0},e=zF,s){const o=XF(t,e,s),r=$F({toWorld:o.toWorld,hobCx:o.W/2,hobCy:o.D/2,H:o.H,counterT:o.counterT,groupId:o.groupId}),i=[o.host,...o.frontPatches,...o.sidePanels,o.counterSlab,...r];return{entities:i,group:YF(o,i,"אי מטבח עם כיריים",s),hostId:o.hostId}}function HV(t={x:0,y:0},e=IV,s){const o=XF(t,e,s),{W:r,D:i,H:a,counterT:l,groupId:c,toWorld:d,counterSlab:u}=o,h=$F({toWorld:d,hobCx:Math.round(r*.3),hobCy:i/2,H:a,counterT:l,groupId:c}),x=$d(u,{widthMm:560,depthMm:Math.round(i*.55),downMm:180,offsetXMm:Math.round(r*.22),offsetYMm:-40,color:SV},c),f=35,b=wm({origin:{x:Math.round(r*.72)-Math.round(f/2),y:i-70-f},baseHeightMm:a+l,postHeightMm:240,spoutReachMm:200,thicknessMm:f,color:PV,groupId:c}).map(g=>u1(g,d)),M=[o.host,...o.frontPatches,...o.sidePanels,u,...h,...x?[x]:[],...b];return{entities:M,group:YF(o,M,"אי מטבח עם כיריים וכיור",s),hostId:o.hostId}}const BV={widthMm:700,depthMm:700,heightMm:2200,freezerHeightMm:660,plinthMm:100,revealMm:20},VV="#F7F4EF",zV="#E8DFD3",$V=18;function XV(t={x:0,y:0},e=BV,s){const o=Math.max(400,Math.round(e.widthMm)),r=Math.max(400,Math.round(e.depthMm)),i=Math.max(1500,Math.round(e.heightMm)),a=Math.max(200,Math.round(e.freezerHeightMm)),l=Math.max(0,Math.round(e.plinthMm)),c=Math.max(0,Math.round(e.revealMm)),d=Me(),u=be("fps_rect");let h,x;if(s){const v=Wn({widthMm:o,depthMm:r},s);h=v.vertices,x=v.positionAlongWallMm}else{const v=Math.round(t.x),C=Math.round(t.y);
278h=_e(v,C,v+o,C+r)}const f={...Ae(h,"rectangle",u),heightMm:i,color:VV,groupId:d},p=i-l-a,b=i-l,M=Math.max(0,p-c),g=[],w=(v,C)=>{const N=lo(u,"side-0",[{x:0,y:v},{x:o,y:v},{x:o,y:C},{x:0,y:C}],d);N&&g.push({...N,depthMm:$V,color:zV})};w(0,M),w(p,b);const k=l>0?q3(u,d,{widthMm:o,heightMm:i},l):null,_=[f,...g,...k?[k]:[]],j={id:d,entityIds:_.map(v=>v.id),name:"עמודת מקרר",widthMm:o,depthMm:r,heightMm:i,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:x,createdAt:Date.now()};return{entities:_,group:j,hostId:u}}const YV={depthMm:600,heightMm:2410},df="#EFE9DF",GV="#F7F4EF",UV="#F2ECE2",KV="#8C8377",zj="#D6CCBC",ZV="#FBF1CF",qV="#2A2B30",JV="#8E9299",$j=20,xi=8,rw=110,Xj=90,iw=40,Ng=25,ac=30,Yj=60,QV=26,tz=-12,Gj=40,cc=1596,nb=[{widthMm:20,type:"filler"},{widthMm:460,type:"fridge"},{widthMm:460,type:"fridge"},{widthMm:20,type:"filler"},{widthMm:605,type:"door"},{widthMm:605,type:"door"},{widthMm:600,type:"oven"},{widthMm:605,type:"door"},{widthMm:605,type:"door"},{widthMm:900,type:"doorWide"},{widthMm:435,type:"door"}],ez=nb.reduce((t,e)=>t+e.widthMm,0),GF=cc+ez,UF=.305,KF=.473,aw=.226,ZF=.239,lw=.447,cw=.465,dw=.673,qF=.69,nz={larderWidthMm:cc,totalWidthMm:GF,columns:nb,sideThicknessMm:ac,plinthHeightMm:rw,capHeightMm:iw,larderDrawersTopF:UF,larderNicheTopF:KF,ovenDrawerTopF:aw,ovenNicheBottomF:ZF,ovenNicheTopF:lw,mwNicheBottomF:cw,mwNicheTopF:dw,ovenUpperBottomF:qF};function oz(t,e){return{...t,vertices:t.vertices.map(e)}}function sz(t={x:0,y:0},e=YV,s){var st;const o=GF,r=Math.max(260,Math.round(e.depthMm)),i=Math.max(1200,Math.round(e.heightMm)),a=Me();let l,c;if(s){const ct=Wn({widthMm:o,depthMm:r},s);l=ct.vertices,c=ct.positionAlongWallMm}else l=_e(t.x,t.y,t.x+o,t.y+r);const d=l[0],u=l[1],h=l[3],x=(u.x-d.x)/o,f=(u.y-d.y)/o,p=(h.x-d.x)/r,b=(h.y-d.y)/r,M=ct=>({x:Math.round(d.x+x*ct.x+p*ct.y),y:Math.round(d.y+f*ct.x+b*ct.y)}),g=[],w=ct=>g.push(oz(ct,M)),k=$j,_=r-k,j=rw,v=i-iw,C=v-j,N=ct=>Math.round(j+C*ct),P=(ct,pt,xt,_t,Ft=df)=>w(ee({origin:{x:ct,y:k},widthMm:pt-ct,depthMm:_,baseHeightMm:xt,heightMm:Math.max(1,_t-xt),color:Ft,groupId:a})),L=(ct,pt,xt,_t,Ft=GV)=>{const Vt=pt-ct,vt=_t-xt;if(Vt<40||vt<40)return;const Ht=ee({origin:{x:ct,y:0},widthMm:Vt,depthMm:$j,baseHeightMm:xt,heightMm:vt,color:Ft,groupId:a});w(Ht);const Tt=Q1({hostId:Ht.id,faceId:"side-0",x0:Gj,y0:14,x1:Vt-Gj,y1:14+QV,depthMm:tz,color:df,groupId:a});Tt&&g.push(Tt)};w(ee({origin:{x:0,y:Xj},widthMm:o,depthMm:Math.max(40,r-Xj),heightMm:rw,color:KV,groupId:a})),w(ee({origin:{x:0,y:0},widthMm:o,depthMm:r,baseHeightMm:v,heightMm:iw,color:df,groupId:a}));const A=N(UF),W=N(KF),S=ac,B=cc-ac,R=(B-S-ac*2)/3,z=ct=>S+ct*(R+ac);P(0,cc,j,A),P(0,cc,W,v),w(ee({origin:{x:0,y:r-Ng},widthMm:cc,depthMm:Ng,baseHeightMm:A,heightMm:W-A,color:zj,groupId:a}));for(const ct of[0,cc-ac,z(0)+R,z(1)+R])w(ee({origin:{x:ct,y:k},widthMm:ac,depthMm:_,baseHeightMm:A,heightMm:W-A,color:zj,groupId:a}));w(ee({origin:{x:S,y:k},widthMm:B-S,depthMm:90,baseHeightMm:W-25,heightMm:25,color:ZV,groupId:a}));const ft=(A-j-xi*2-xi*2)/3;for(let ct=0;ct<3;ct+=1){const pt=z(ct);for(let xt=0;xt<3;xt+=1){const _t=j+xi+xt*(ft+xi);L(pt,pt+R,_t,_t+ft)}}const G=(v-W-xi*2-xi)/2;for(let ct=0;ct<3;ct+=1){const pt=z(ct);for(let xt=0;xt<2;xt+=1){const _t=W+xi+xt*(G+xi);L(pt,pt+R,_t,_t+G)}}const Y=(()=>{let ct=cc;for(const pt of nb){if(pt.type==="oven")return{x0:ct,x1:ct+pt.widthMm};ct+=pt.widthMm}return null})();Y?(P(cc,Y.x0,j,v),P(Y.x1,o,j,v)):P(cc,o,j,v);const J=j+xi,Mt=v-xi;let Rt=cc;for(const ct of nb){const pt=Rt+xi/2,xt=Rt+ct.widthMm-xi/2;if(Rt+=ct.widthMm,ct.type==="filler")continue;if(ct.type==="fridge"){L(pt,xt,J,Mt,UV);continue}if(ct.type==="door"){L(pt,xt,J,Mt);continue}if(ct.type==="doorWide"){const Ht=(pt+xt)/2;L(pt,Ht-xi/2,J,Mt),L(Ht+xi/2,xt,J,Mt);continue}const _t=Rt-ct.widthMm,Ft=Rt,Vt=_t+ac,vt=Ft-ac;w(ee({origin:{x:_t,y:k},widthMm:ac,depthMm:_,baseHeightMm:j,heightMm:C,color:df,groupId:a})),w(ee({origin:{x:vt,y:k},widthMm:ac,depthMm:_,baseHeightMm:j,heightMm:C,color:df,groupId:a})),w(ee({origin:{x:Vt,y:r-Ng},widthMm:vt-Vt,depthMm:Ng,baseHeightMm:j,heightMm:C,color:df,groupId:a})),P(Vt,vt,j,N(aw)+xi),P(Vt,vt,N(lw),N(cw)),P(Vt,vt,N(dw),v);for(const Ht of[{zb:N(ZF),zt:N(lw)},{zb:N(cw),zt:N(dw)}]){const Tt=Ht.zt-Ht.zb;w(ee({origin:{x:Vt+4,y:Yj},widthMm:vt-Vt-8,depthMm:Math.max(60,Math.round(_*.75)),baseHeightMm:Ht.zb,heightMm:Tt,color:qV,groupId:a})),w(ee({origin:{x:Vt+24,y:Yj-22},widthMm:vt-Vt-48,depthMm:22,baseHeightMm:Ht.zt-Math.round(Tt*.22),heightMm:34,color:JV,groupId:a}))}
278L(Vt+xi/2,vt-xi/2,J,N(aw)),L(Vt+xi/2,vt-xi/2,N(qF),Mt)}const it={id:a,entityIds:g.map(ct=>ct.id),name:"מטבח מהסקיצה",widthMm:o,depthMm:r,heightMm:i,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:c,createdAt:Date.now()};return{entities:g,group:it,hostId:((st=g[0])==null?void 0:st.id)??a}}const Q3={depthMm:600,heightMm:2800},rz="#F7F4EF",Dd="#E8DFD3",iz="#3A3B40",Uj="#DDD3C4",az="#EDE6DA",Kj="#FBF1CF",Zj="#2A2B30",qj="#4A4C55",So=10,Jj=22,Pc=18,lz=30,Qj=6,cz=-100,Ig=-60,Tg=900,dz=940,t8=950,W2=1500,R2=1540,Sf={linear:[{kind:"applianceCol",widthMm:600},{kind:"stackCol",widthMm:600},{kind:"baseUpper",widthMm:800,base:"drawers"},{kind:"baseUpper",widthMm:800,base:"doors"},{kind:"openBay",widthMm:800}],symmetric:[{kind:"stackCol",widthMm:525},{kind:"baseUpper",widthMm:700,base:"drawers"},{kind:"baseUpper",widthMm:700,base:"doors"},{kind:"baseUpper",widthMm:700,base:"drawers"},{kind:"stackCol",widthMm:525}],compact:[{kind:"applianceCol",widthMm:600},{kind:"baseUpper",widthMm:900,base:"drawers"},{kind:"baseUpper",widthMm:900,base:"doors"}]};function tk(t,e,s,o,r){const i=t.reduce((L,A)=>L+A.widthMm,0),a=Math.max(300,Math.round(o.depthMm)),l=Math.max(1e3,Math.round(o.heightMm)),c=Me(),d=be("fps_rect");let u,h;if(r){const L=Wn({widthMm:i,depthMm:a},r);u=L.vertices,h=L.positionAlongWallMm}else u=_e(s.x,s.y,s.x+i,s.y+a);const x={...Ae(u,"rectangle",d),heightMm:l,color:rz,groupId:c},f=[],p=(L,A,W,S,B,R)=>{const z=l-S,X=l-A,ft=[{x:Math.round(L),y:Math.round(z)},{x:Math.round(W),y:Math.round(z)},{x:Math.round(W),y:Math.round(X)},{x:Math.round(L),y:Math.round(X)}],tt=lo(d,"side-0",ft,c);tt&&f.push({...tt,depthMm:Math.round(B),color:R})},b=(L,A)=>{const W=(Tg-Jj*2)/3;for(let S=0;S<3;S+=1){const B=S*(W+Jj);p(L+So,B+So,A-So,B+W,Pc,Dd)}},M=(L,A)=>{const W=(L+A)/2;p(L+So,So,W-So,Tg,Pc,Dd),p(W+So,So,A-So,Tg,Pc,Dd)},g=(L,A)=>{p(L,Tg,A,dz,lz,iz)},w=(L,A)=>{p(L+So,t8,A-So,W2,cz,Uj),p(L+40,W2-34,A-40,W2-12,Qj,Kj)},k=(L,A)=>{const W=R2+(l-R2)*.62;p(L+So,R2,A-So,W,Pc,Dd),p(L+So,W+So,A-So,l-So,Pc,Dd)},_=(L,A)=>{p(L+So,t8,A-So,l-So,-(a-40),Uj);for(const W of[1480,2040])p(L+So,W,A-So,W+30,Pc,az);p(L+40,l-So-30,A-40,l-So-8,Qj,Kj)},j=(L,A)=>{const W=L+So,S=A-So,B=720,R=B+40+600,z=R+20+340;p(W,So,S,B,Pc,Dd),p(W,B+40,S,R,Ig,Zj),p(W+30,R-70,S-30,R-30,Ig+25,qj),p(W,R+20,S,z,Ig,Zj),p(W+30,z-60,S-30,z-30,Ig+25,qj),p(W,z+40,S,l-So,Pc,Dd)},v=(L,A)=>{const W=l*.5;p(L+So,So,A-So,W,Pc,Dd),p(L+So,W+So,A-So,l-So,Pc,Dd)};let C=0;for(const L of t){const A=C,W=C+L.widthMm;C=W,L.kind==="applianceCol"?j(A,W):L.kind==="stackCol"?v(A,W):L.kind==="openBay"?(M(A,W),g(A,W),_(A,W)):(L.base==="drawers"?b(A,W):M(A,W),g(A,W),w(A,W),k(A,W))}const N=[x,...f],P={id:c,entityIds:N.map(L=>L.id),name:e,widthMm:i,depthMm:a,heightMm:l,wallId:r==null?void 0:r.wallId,wallSide:r==null?void 0:r.side,wallPositionMm:h,createdAt:Date.now()};return{entities:N,group:P,hostId:d}}function uz(t={x:0,y:0},e=Q3,s){return tk(Sf.linear,"מטבח קיר לינארי",t,e,s)}function hz(t={x:0,y:0},e=Q3,s){return tk(Sf.symmetric,"מטבח קיר סימטרי",t,e,s)}function mz(t={x:0,y:0},e=Q3,s){return tk(Sf.compact,"מטבח קיר קומפקטי",t,e,s)}const fz={depthMm:600,heightMm:2800},O2="#F7F4EF",Rh="#E8DFD3",xz="#2E2F35",pz="#4A4B52",gz="#15161A",bz="#15161A",e8="#34353B",Mz="#EDE6DA",n8="#FBF1CF",H2="#2A2B30",o8="#4A4C55",Ac=3600,cl=1200,jr=10,Nu=18,s8=22,JF=30,h1=870,uf=h1+JF,B2=350,Sg=1500,Pg=2900,r8=25;function Iu(t,e){return{...t,vertices:t.vertices.map(e)}}function yz(t={x:0,y:0},e=fz,s){const o=Math.max(300,Math.round(e.depthMm)),r=Math.max(1e3,Math.round(e.heightMm)),i=Me();let a,l;if(s){const S=Wn({widthMm:Ac,depthMm:o},s);a=S.vertices,l=S.positionAlongWallMm}else a=_e(t.x,t.y,t.x+Ac,t.y+o);const c=a[0],d=a[1],u=a[3],h=(d.x-c.x)/Ac,x=(d.y-c.y)/Ac,f=(u.x-c.x)/o,p=(u.y-c.y)/o,b=S=>({x:Math.round(c.x+h*S.x+f*S.y),y:Math.round(c.y+x*S.x+p*S.y)}),M=[],g=(S,B,R,z,X,ft,tt,G)=>{const Y=be("fps_rect"),J=_e(S,B,R,z),Mt={...Ae(J,"rectangle",Y),heightMm:X,baseHeightMm:ft&&ft>0?ft:void 0,color:tt,groupId:i},Rt=[];return G((st,ct,pt,xt,_t,Ft)=>{const Vt=[{x:Math.round(st),y:Math.round(X-xt)},{x:Math.round(pt),y:Math.round(X-xt)},{x:Math.round(pt),y:Math.round(X-ct)},{x:Math.round(st),y:Math.round(X-ct)}],vt=lo(Y,"side-0",Vt,i);vt&&Rt.push({...vt,depthMm:Math.round(_t),color:Ft})}),M.push(Iu(Mt,b),...Rt),Y};g(0,0,cl,o,r,void 0,O2,S=>{const B=jr,R=600-jr,z=1360,X=z+20+340;S(B,jr,R,720,Nu,Rh),S(B,760,R,z,-60,H2),S(B+30,z-70,R-30,z-30,-35,o8),S(B,z+20,R,X,-60,H2),S(B+30,X-60,R-30,X-30,-35,o8),S(B,X+40,R,r-jr,Nu,Rh),S(600+jr,jr,cl-jr,1390,Nu,Rh),S(600+jr,1410,cl-jr,r-jr,Nu,Rh)});const w=g(cl,0,Ac,o,h1,void 0,O2,S=>{const B=(Ac-cl)/3;for(let R=0;R<3;R+=1){const z=R*B,X=z+B,ft=(h1-s8*2)/3;for(let tt=0;tt<3;tt+=1){const G=tt*(ft+s8);S(z+jr,G+jr,X-jr,G+ft,Nu,Rh)}}}),k=Pg-cl;g(cl,o-B2,Pg,o,r-Sg,Sg,O2,S=>{const B=r-Sg;S(jr,0,k-jr,120,-50,H2),S(40,130,k-40,152,Nu,n8);const R=160,z=R+(B-R)*.6;
278S(jr,R,k-jr,z,Nu,Rh),S(jr,z+jr,k-jr,B-jr,Nu,Rh)});const _=Pg,j=Ac;M.push(Iu(ee({origin:{x:_,y:o-20},widthMm:j-_,depthMm:20,baseHeightMm:uf,heightMm:r-uf-10,color:e8,groupId:i}),b));for(const S of[1640,2180])M.push(Iu(ee({origin:{x:_+jr,y:o-B2},widthMm:j-_-jr*2,depthMm:B2-20,baseHeightMm:S,heightMm:30,color:Mz,groupId:i}),b));M.push(Iu(ee({origin:{x:_+40,y:o-60},widthMm:j-_-80,depthMm:12,baseHeightMm:r-90,heightMm:14,color:n8,groupId:i}),b)),M.push(Iu(ee({origin:{x:cl,y:o-25},widthMm:Pg-cl,depthMm:25,baseHeightMm:uf,heightMm:Sg-uf,color:e8,groupId:i}),b));const v=ee({origin:{x:cl,y:-r8},widthMm:Ac-cl,depthMm:o+r8,baseHeightMm:h1,heightMm:JF,color:xz,groupId:i}),C=Iu(v,b);M.push(C);const N=$d(C,{widthMm:520,depthMm:380,downMm:200,offsetXMm:750,offsetYMm:-50,color:pz},i);N&&M.push(N);const P=40,L=cl+(Ac-cl)/2+750,A=wm({origin:{x:Math.round(L-P/2),y:o-70-P},baseHeightMm:uf,postHeightMm:280,spoutReachMm:210,thicknessMm:P,color:gz,groupId:i}).map(S=>Iu(S,b));M.push(...A),M.push(Iu(ee({origin:{x:1850,y:70},widthMm:700,depthMm:500,baseHeightMm:uf,heightMm:28,color:bz,groupId:i}),b));const W={id:i,entityIds:M.map(S=>S.id),name:"מטבח קיר עם כיור וכיריים",widthMm:Ac,depthMm:o,heightMm:r,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:l,createdAt:Date.now()};return{entities:M,group:W,hostId:w}}const wz={depthMm:420,heightMm:2560},V2="#5A5247",kz="#4F4A40",vz="#5F594D",jz="#8A7F6C",_z="#C3B8A2",Ez="#CFC5B0",Dz="#6E6459",Ox=3680,rc=20,z2=[20,930,1840,2750,3660],i8=60,$2=60,X2=70,a8=32,l8=6,Fz=9,c8=18,Oh=10,d8=26,Cz=14,u8=220,h8=24,Nz=[{bay:0,z:2440},{bay:0,z:2040},{bay:0,z:760},{bay:1,z:2440},{bay:1,z:2040},{bay:1,z:760},{bay:2,z:2440},{bay:2,z:2e3},{bay:2,z:1130},{bay:2,z:620},{bay:3,z:2440},{bay:3,z:2040},{bay:3,z:1130},{bay:3,z:620}],Iz=[{bay:1,z0:792,z1:2040},{bay:2,z0:652,z1:1560}],Tz=[{bay:0,z0:360,z1:740,drawers:2},{bay:1,z0:360,z1:740,drawers:2},{bay:2,z0:1560,z1:1980,drawers:1}];function Sz(t,e){return{...t,vertices:t.vertices.map(e)}}function Pz(t={x:0,y:0},e=wz,s){var j;const o=Math.max(260,Math.round(e.depthMm)),r=Math.max(1e3,Math.round(e.heightMm)),i=Me();let a,l;if(s){const v=Wn({widthMm:Ox,depthMm:o},s);a=v.vertices,l=v.positionAlongWallMm}else a=_e(t.x,t.y,t.x+Ox,t.y+o);const c=a[0],d=a[1],u=a[3],h=(d.x-c.x)/Ox,x=(d.y-c.y)/Ox,f=(u.x-c.x)/o,p=(u.y-c.y)/o,b=v=>({x:Math.round(c.x+h*v.x+f*v.y),y:Math.round(c.y+x*v.x+p*v.y)}),M=[],g=v=>M.push(Sz(v,b)),w=v=>({x0:z2[v]+rc+l8,x1:z2[v+1]-rc-l8}),k=[i8,o-i8];for(const v of z2)for(const C of k)g(Ep({center:{x:v,y:C},radiusMm:rc,baseHeightMm:$2,heightMm:r-$2-X2,color:V2,groupId:i})),g(Da({origin:{x:v-rc,y:C-rc},widthMm:rc*2,depthMm:rc*2,baseHeightMm:0,heightMm:$2,color:V2,groupId:i,round:!0,taperBottom:.32})),g(Da({origin:{x:v-rc,y:C-rc},widthMm:rc*2,depthMm:rc*2,baseHeightMm:r-X2,heightMm:X2,color:V2,groupId:i,round:!0,taperTop:.28}));for(const v of Nz){const{x0:C,x1:N}=w(v.bay),P=be("fps_rect"),L={...ee({origin:{x:C,y:0},widthMm:N-C,depthMm:o,baseHeightMm:v.z,heightMm:a8,color:kz,groupId:i}),id:P};g(L);const A=Q1({hostId:P,faceId:"side-0",x0:0,y0:0,x1:N-C,y1:a8,depthMm:Fz,color:vz,groupId:i});A&&M.push(A)}for(const v of Iz){const{x0:C,x1:N}=w(v.bay);g(ee({origin:{x:C,y:o-c8},widthMm:N-C,depthMm:c8,baseHeightMm:v.z0,heightMm:v.z1-v.z0,color:jz,groupId:i}))}for(const v of Tz){const{x0:C,x1:N}=w(v.bay),P=N-C,L=v.z1-v.z0,A=be("fps_rect"),W={...Ae(_e(C,0,N,o),"rectangle",A),heightMm:L,baseHeightMm:v.z0,color:_z,groupId:i},S=[],B=(L-Oh*(v.drawers+1))/v.drawers;for(let R=0;R<v.drawers;R+=1){const z=Oh+R*(B+Oh),X=z+B,ft=Math.round(L-X),tt=Math.round(L-z),G=[{x:Oh,y:ft},{x:Math.round(P-Oh),y:ft},{x:Math.round(P-Oh),y:tt},{x:Oh,y:tt}],Y=lo(A,"side-0",G,i);Y&&S.push({...Y,depthMm:d8,color:Ez});const J=(ft+tt)/2,Mt=Q1({hostId:A,faceId:"side-0",x0:Math.round((P-u8)/2),y0:Math.round(J-h8/2),x1:Math.round((P+u8)/2),y1:Math.round(J+h8/2),depthMm:d8+Cz,color:Dz,groupId:i});Mt&&S.push(Mt)}g(W),M.push(...S)}const _={id:i,entityIds:M.map(v=>v.id),name:"ארון מדפים על עמודים",widthMm:Ox,depthMm:o,heightMm:r,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:l,createdAt:Date.now()};return{entities:M,group:_,hostId:((j=M[0])==null?void 0:j.id)??i}}const Az="#EDE7DC",Lz="#D8CFBF",Wz={widthMm:1400,depthMm:800,heightMm:750,topThicknessMm:40,legSizeMm:80,legInsetMm:90,legTaperBottom:.5,roundLegs:!1};function Rz(t={x:0,y:0},e=Wz,s){const o=Math.max(300,Math.round(e.widthMm)),r=Math.max(300,Math.round(e.depthMm)),i=Math.max(200,Math.round(e.heightMm)),a=Math.max(10,Math.round(e.topThicknessMm)),l=Math.max(20,Math.round(e.legSizeMm)),c=Math.max(0,Math.round(e.legInsetMm)),d=Math.max(50,i-a),u=Me(),h=ee({origin:t,widthMm:o,depthMm:r,heightMm:a,baseHeightMm:d,color:Az,groupId:u}),f=[{x:t.x+c,y:t.y+c},{x:t.x+o-c-l,y:t.y+c},{x:t.x+c,y:t.y+r-c-l},{x:t.x+o-c-l,y:t.y+r-c-l}].map(M=>Da({origin:M,widthMm:l,depthMm:l,heightMm:d,color:Lz,groupId:u,round:e.roundLegs,taperBottom:e.legTaperBottom})),p=[h,...f],b={id:u,entityIds:p.map(M=>M.id),name:"שולחן",widthMm:o,depthMm:r,heightMm:i,createdAt:Date.now()};return{entities:p,group:b,hostId:h.id}}const Oz="#EDE7DC",Hz="#E1D6C6",Bz="#E1D6C6",Vz="#CFC6B6",zz="#EDE7DC",$z="#E8DFD3",Xz="#3A352F",Yz={widthMm:1800,depthMm:450,bodyHeightMm:580,legHeightMm:180,topThicknessMm:40,legSizeMm:55,legTaperBottom:.5,roundLegs:!1,flutesPerDoor:8};function Y2(t,e){return{...t,vertices:t.vertices.map(e)}}function Gz(t={x:0,y:0}
278,e=Yz,s){const o=Math.max(900,Math.round(e.widthMm)),r=Math.max(250,Math.round(e.depthMm)),i=Math.max(200,Math.round(e.bodyHeightMm)),a=Math.max(40,Math.round(e.legHeightMm)),l=Math.max(10,Math.round(e.topThicknessMm)),c=Math.max(20,Math.round(e.legSizeMm)),d=Math.max(0,Math.round(e.flutesPerDoor)),u=Me(),h=be("fps_rect");let x,f;if(s){const it=Wn({widthMm:o,depthMm:r},s);x=it.vertices,f=it.positionAlongWallMm}else{const it=Math.round(t.x),st=Math.round(t.y);x=_e(it,st,it+o,st+r)}const p=x[0],b=x[1],M=x[3],g=(b.x-p.x)/o,w=(b.y-p.y)/o,k=(M.x-p.x)/r,_=(M.y-p.y)/r,j=it=>({x:Math.round(p.x+g*it.x+k*it.y),y:Math.round(p.y+w*it.x+_*it.y)}),v={...Ae(x,"rectangle",h),heightMm:i,baseHeightMm:a,color:Oz,groupId:u},C=[],N=(it,st,ct,pt,xt,_t)=>{const Ft=lo(h,"side-0",[{x:it,y:st},{x:ct,y:st},{x:ct,y:pt},{x:it,y:pt}],u);Ft&&C.push({...Ft,depthMm:xt,color:_t})},P=Math.round(o/3),L=20,A=i-20,W=26,S=18,B=it=>{const st=it+30,ct=it+P-30;if(N(st,L,ct,A,S,Hz),d>0){const pt=ct-st,xt=Math.max(20,Math.round(pt/d*.62));for(let _t=0;_t<d;_t++){const Ft=st+(_t+.5)*(pt/d);N(Math.round(Ft-xt/2),L,Math.round(Ft+xt/2),A,W,Bz)}}};B(0),B(P*2),N(P+30,L,P*2-30,A,-(r-40),Vz);const R=ee({origin:{x:-15,y:-15},widthMm:o+30,depthMm:r+30,baseHeightMm:a+i,heightMm:l,color:$z,groupId:u}),z=Y2(R,j),X=ee({origin:{x:P+30,y:20},widthMm:P-60,depthMm:r-40,baseHeightMm:a+Math.round(i/2),heightMm:20,color:zz,groupId:u}),ft=Y2(X,j),tt=70,G=40,J=[{x:tt,y:G},{x:o-tt-c,y:G},{x:tt,y:r-G-c},{x:o-tt-c,y:r-G-c}].map(it=>Y2(Da({origin:it,widthMm:c,depthMm:c,heightMm:a,color:Xz,groupId:u,round:e.roundLegs,taperBottom:e.legTaperBottom}),j)),Mt=[v,...C,z,ft,...J],Rt={id:u,entityIds:Mt.map(it=>it.id),name:"קרדנזה פלוטד",widthMm:o,depthMm:r,heightMm:a+i+l,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:f,createdAt:Date.now()};return{entities:Mt,group:Rt,hostId:h}}const Uz="#F7F4EF",Kz="#E8DFD3",Zz="#E8DFD3",m8="#F7F4EF",qz={widthMm:2200,depthMm:950,heightMm:800,seatBaseHeightMm:200,seatCushionHeightMm:130,seatCushionDepthMm:850,backCushionHeightMm:350,backCushionDepthMm:120,armrestWidthMm:120,armrestHeightMm:600,cushionRevealMm:20};function Jz(t,e){return{...t,vertices:t.vertices.map(e)}}function Qz(t={x:0,y:0},e=qz,s){const o=Math.max(1500,Math.round(e.widthMm)),r=Math.max(700,Math.round(e.depthMm)),i=Math.max(100,Math.round(e.seatBaseHeightMm)),a=Math.max(60,Math.round(e.seatCushionHeightMm)),l=Math.max(400,Math.min(r,Math.round(e.seatCushionDepthMm))),c=Math.max(150,Math.round(e.backCushionHeightMm)),d=Math.max(60,Math.round(e.backCushionDepthMm)),u=Math.max(70,Math.round(e.armrestWidthMm)),h=Math.max(300,Math.round(e.armrestHeightMm)),x=Math.max(0,Math.round(e.cushionRevealMm)),f=Me(),p=be("fps_rect");let b,M;if(s){const st=Wn({widthMm:o,depthMm:r},s);b=st.vertices,M=st.positionAlongWallMm}else{const st=Math.round(t.x),ct=Math.round(t.y);b=_e(st,ct,st+o,ct+r)}const g=b[0],w=b[1],k=b[3],_=(w.x-g.x)/o,j=(w.y-g.y)/o,v=(k.x-g.x)/r,C=(k.y-g.y)/r,N=st=>({x:Math.round(g.x+_*st.x+v*st.y),y:Math.round(g.y+j*st.x+C*st.y)}),P={...Ae(b,"rectangle",p),heightMm:i,color:Uz,groupId:f},L=u,A=o-u,S=(Math.max(300,A-L)-x*2)/3,B=[];for(let st=0;st<3;st+=1){const ct=L+st*(S+x);B.push(ee({origin:{x:ct,y:0},widthMm:S,depthMm:l,baseHeightMm:i,heightMm:a,color:Kz,groupId:f}))}const R=S,z=r-d,X=[];for(let st=0;st<3;st+=1){const ct=L+st*(R+x);X.push(ee({origin:{x:ct,y:z},widthMm:R,depthMm:d,baseHeightMm:i+a,heightMm:c,color:Zz,groupId:f}))}const ft=Math.max(100,h-i),tt=ee({origin:{x:0,y:0},widthMm:u,depthMm:r,baseHeightMm:i,heightMm:ft,color:m8,groupId:f}),G=ee({origin:{x:o-u,y:0},widthMm:u,depthMm:r,baseHeightMm:i,heightMm:ft,color:m8,groupId:f}),J=[...B,...X,tt,G].map(st=>Jz(st,N)),Mt=[P,...J],Rt=Math.max(e.heightMm,i+a+c),it={id:f,entityIds:Mt.map(st=>st.id),name:"ספה תלת-מושבית",widthMm:o,depthMm:r,heightMm:Rt,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:M,createdAt:Date.now()};return{entities:Mt,group:it,hostId:p}}const t$="#F7F4EF",e$="#E8DFD3",n$="#E8DFD3",o$="#F7F4EF",s$={widthMm:1700,depthMm:800,heightMm:800,seatBaseHeightMm:180,seatCushionHeightMm:120,headEnd:"left",backHeightsMm:[600,400,220],backWidthsMm:[500,400,300],backDepthMm:100,armrestWidthMm:100,armrestHeightMm:600};function r$(t,e){return{...t,vertices:t.vertices.map(e)}}function i$(t={x:0,y:0},e=s$,s){const o=Math.max(1200,Math.round(e.widthMm)),r=Math.max(500,Math.round(e.depthMm)),i=Math.max(80,Math.round(e.seatBaseHeightMm)),a=Math.max(60,Math.round(e.seatCushionHeightMm)),l=Math.max(60,Math.round(e.backDepthMm)),c=Math.max(50,Math.round(e.armrestWidthMm)),d=Math.max(200,Math.round(e.armrestHeightMm)),u=Me(),h=be("fps_rect");let x,f;if(s){const Y=Wn({widthMm:o,depthMm:r},s);x=Y.vertices,f=Y.positionAlongWallMm}else{const Y=Math.round(t.x),J=Math.round(t.y);x=_e(Y,J,Y+o,J+r)}const p=x[0],b=x[1],M=x[3],g=(b.x-p.x)/o,w=(b.y-p.y)/o,k=(M.x-p.x)/r,_=(M.y-p.y)/r,j=Y=>({x:Math.round(p.x+g*Y.x+k*Y.y),y:Math.round(p.y+w*Y.x+_*Y.y)}),v={...Ae(x,"rectangle",h),heightMm:i,color:t$,groupId:u},C=ee({origin:{x:0,y:0},widthMm:o,depthMm:r,baseHeightMm:i,heightMm:a,color:e$,groupId:u}
278),N=e.headEnd==="left",P=i+a,L=r-l,A=10,W=[];let S=N?0:o;for(let Y=0;Y<3;Y+=1){const J=Math.max(60,Math.round(e.backWidthsMm[Y])),Mt=Math.max(80,Math.round(e.backHeightsMm[Y])),Rt=N?S:S-J;W.push(ee({origin:{x:Rt,y:L},widthMm:J,depthMm:l,baseHeightMm:P,heightMm:Mt,color:n$,groupId:u})),N?S+=J+A:S-=J+A}const B=N?0:o-c,R=ee({origin:{x:B,y:0},widthMm:c,depthMm:r,baseHeightMm:i,heightMm:Math.max(100,d-i),color:o$,groupId:u}),X=[C,...W,R].map(Y=>r$(Y,j)),ft=[v,...X],tt=Math.max(e.heightMm,i+a+Math.max(...e.backHeightsMm)),G={id:u,entityIds:ft.map(Y=>Y.id),name:"שזלונג",widthMm:o,depthMm:r,heightMm:tt,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:f,createdAt:Date.now()};return{entities:ft,group:G,hostId:h}}const a$={widthMm:2e3,depthMm:400,heightMm:400,baseHeightMm:500,doorCount:4,doorGapMm:6,frameTopBottomMm:25,frameSideMm:18},l$="#F7F4EF",c$="#E8DFD3",d$=18;function u$(t={x:0,y:0},e=a$,s){const o=Math.max(600,Math.round(e.widthMm)),r=Math.max(200,Math.round(e.depthMm)),i=Math.max(200,Math.round(e.heightMm)),a=Math.max(0,Math.round(e.baseHeightMm)),l=Math.max(1,Math.round(e.doorCount)),c=Math.max(0,Math.round(e.doorGapMm)),d=Math.max(0,Math.round(e.frameTopBottomMm)),u=Math.max(0,Math.round(e.frameSideMm)),h=Me(),x=be("fps_rect");let f,p;if(s){const P=Wn({widthMm:o,depthMm:r},s);f=P.vertices,p=P.positionAlongWallMm}else{const P=Math.round(t.x),L=Math.round(t.y);f=_e(P,L,P+o,L+r)}const b={...Ae(f,"rectangle",x),heightMm:i,baseHeightMm:a>0?a:void 0,color:l$,groupId:h},M=u,g=o-u,k=(Math.max(40,g-M)-c*(l-1))/l,_=d,j=i-d,v=[];for(let P=0;P<l;P+=1){const L=M+P*(k+c),A=L+k,W=lo(x,"side-0",[{x:Math.round(L),y:Math.round(_)},{x:Math.round(A),y:Math.round(_)},{x:Math.round(A),y:Math.round(j)},{x:Math.round(L),y:Math.round(j)}],h);W&&v.push({...W,depthMm:d$,color:c$})}const C=[b,...v],N={id:h,entityIds:C.map(P=>P.id),name:"מזנון טלוויזיה תלוי",widthMm:o,depthMm:r,heightMm:i,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:p,createdAt:Date.now()};return{entities:C,group:N,hostId:x}}const h$="#1A1A1C",m$="#050507";function f$(t={x:0,y:0},e,s){const l=Me(),c=be("fps_rect"),d=_e(t.x,t.y,t.x+1450,t.y+60),u={...Ae(d,"rectangle",c),heightMm:830,baseHeightMm:1100,color:h$,groupId:l},h=25,x=lo(c,"side-0",[{x:h,y:h},{x:1450-h,y:h},{x:1450-h,y:830-h},{x:h,y:830-h}],l),f=[u,...x?[{...x,depthMm:2,color:m$}]:[]],p={id:l,entityIds:f.map(b=>b.id),name:"טלוויזיה",widthMm:1450,depthMm:60,heightMm:830,createdAt:Date.now()};return{entities:f,group:p,hostId:c}}const x$="#EDE7DC",p$="#D8CFBF",g$="#D8CFBF",b$={widthMm:1200,depthMm:600,heightMm:420,topThicknessMm:30,legSizeMm:70,legInsetMm:70,legTaperBottom:.55,withLowerShelf:!0,lowerShelfThicknessMm:24,lowerShelfInsetMm:60,lowerShelfBaseHeightFrac:.35};function M$(t={x:0,y:0},e=b$,s){const o=Math.max(400,Math.round(e.widthMm)),r=Math.max(300,Math.round(e.depthMm)),i=Math.max(200,Math.round(e.heightMm)),a=Math.max(10,Math.round(e.topThicknessMm)),l=Math.max(20,Math.round(e.legSizeMm)),c=Math.max(0,Math.round(e.legInsetMm)),d=Math.max(50,i-a),u=Math.max(8,Math.round(e.lowerShelfThicknessMm)),h=Math.max(0,Math.round(e.lowerShelfInsetMm)),x=Math.max(0,Math.min(d-u,Math.round(d*e.lowerShelfBaseHeightFrac))),f=Me(),p=ee({origin:t,widthMm:o,depthMm:r,heightMm:a,baseHeightMm:d,color:x$,groupId:f}),M=[{x:t.x+c,y:t.y+c},{x:t.x+o-c-l,y:t.y+c},{x:t.x+c,y:t.y+r-c-l},{x:t.x+o-c-l,y:t.y+r-c-l}].map(k=>Da({origin:k,widthMm:l,depthMm:l,heightMm:d,color:p$,groupId:f,taperBottom:e.legTaperBottom})),g=[p,...M];if(e.withLowerShelf){const k=Math.max(100,o-h*2),_=Math.max(100,r-h*2),j=ee({origin:{x:t.x+h,y:t.y+h},widthMm:k,depthMm:_,heightMm:u,baseHeightMm:x,color:g$,groupId:f});g.push(j)}const w={id:f,entityIds:g.map(k=>k.id),name:"שולחן קפה",widthMm:o,depthMm:r,heightMm:i,createdAt:Date.now()};return{entities:g,group:w,hostId:p.id}}const y$="#E8DFD3",w$={widthMm:2e3,depthMm:1500,thicknessMm:8};function k$(t={x:0,y:0},e=w$,s){const o=Math.max(300,Math.round(e.widthMm)),r=Math.max(300,Math.round(e.depthMm)),i=Math.max(2,Math.round(e.thicknessMm)),a=Me(),l=ee({origin:t,widthMm:o,depthMm:r,heightMm:i,color:y$,groupId:a}),c=[l],d={id:a,entityIds:c.map(u=>u.id),name:"שטיח",widthMm:o,depthMm:r,heightMm:i,createdAt:Date.now()};return{entities:c,group:d,hostId:l.id}}const v$="#F7F4EF",j$="#E8DFD3",_$="#E8DFD3",E$={widthMm:1600,depthMm:2e3,platformHeightMm:400,mattressHeightMm:2
27800,headboardDepthMm:100,headboardHeightMm:800};function D$(t,e){return{...t,vertices:t.vertices.map(e)}}function F$(t={x:0,y:0},e=E$,s){const o=Math.max(900,Math.round(e.widthMm)),r=Math.max(1600,Math.round(e.depthMm)),i=Math.max(100,Math.round(e.platformHeightMm)),a=Math.max(80,Math.round(e.mattressHeightMm)),l=Math.max(40,Math.min(r-200,Math.round(e.headboardDepthMm))),c=Math.max(200,Math.round(e.headboardHeightMm)),d=Me(),u=be("fps_rect");let h,x;if(s){const W=Wn({widthMm:o,depthMm:r},s);h=W.vertices,x=W.positionAlongWallMm}else{const W=Math.round(t.x),S=Math.round(t.y);h=_e(W,S,W+o,S+r)}const f=h[0],p=h[1],b=h[3],M=(p.x-f.x)/o,g=(p.y-f.y)/o,w=(b.x-f.x)/r,k=(b.y-f.y)/r,_=W=>({x:Math.round(f.x+M*W.x+w*W.y),y:Math.round(f.y+g*W.x+k*W.y)}),j={...Ae(h,"rectangle",u),heightMm:i,color:v$,groupId:d},v=ee({origin:{x:0,y:0},widthMm:o,depthMm:r,baseHeightMm:i,heightMm:a,color:j$,groupId:d}),C=ee({origin:{x:0,y:r-l},widthMm:o,depthMm:l,baseHeightMm:i,heightMm:c,color:_$,groupId:d}),P=[v,C].map(W=>D$(W,_)),L=[j,...P],A={id:d,entityIds:L.map(W=>W.id),name:"מיטה זוגית עם ראש מרופד",widthMm:o,depthMm:r,heightMm:i+c,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:x,createdAt:Date.now()};return{entities:L,group:A,hostId:u}}const C$="#F7F4EF",N$="#E8DFD3",I$=18,T$={widthMm:450,depthMm:400,heightMm:550,drawerCount:2,revealMm:20,plinthMm:15,topFrameMm:15};function S$(t={x:0,y:0},e=T$,s){const o=Math.max(300,Math.round(e.widthMm)),r=Math.max(250,Math.round(e.depthMm)),i=Math.max(350,Math.round(e.heightMm)),a=Math.max(1,Math.round(e.drawerCount)),l=Math.max(0,Math.round(e.revealMm)),c=Math.max(0,Math.round(e.plinthMm)),d=Math.max(0,Math.round(e.topFrameMm)),u=Me(),h=be("fps_rect");let x,f;if(s){const v=Wn({widthMm:o,depthMm:r},s);x=v.vertices,f=v.positionAlongWallMm}else{const v=Math.round(t.x),C=Math.round(t.y);x=_e(v,C,v+o,C+r)}const p={...Ae(x,"rectangle",h),heightMm:i,color:C$,groupId:u},b=d,M=i-c,w=(Math.max(20,M-b)-l*(a-1))/a,k=[];for(let v=0;v<a;v+=1){const C=b+v*(w+l),N=C+w,P=lo(h,"side-0",[{x:0,y:Math.round(C)},{x:o,y:Math.round(C)},{x:o,y:Math.round(N)},{x:0,y:Math.round(N)}],u);P&&k.push({...P,depthMm:I$,color:N$})}const _=[p,...k],j={id:u,entityIds:_.map(v=>v.id),name:"שידת לילה",widthMm:o,depthMm:r,heightMm:i,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:f,createdAt:Date.now()};return{entities:_,group:j,hostId:h}}const P$="#F7F4EF",A$="#E8DFD3",L$=14,f8=2,W$={doorCount:3,doorWidthMm:800,depthMm:600,heightMm:2400};function R$(t={x:0,y:0},e=W$,s){const o=Math.max(2,Math.round(e.doorCount)),r=Math.max(400,Math.round(e.doorWidthMm)),i=o*r,a=Math.max(400,Math.round(e.depthMm)),l=Math.max(1500,Math.round(e.heightMm)),c=Me(),d=be("fps_rect");let u,h;if(s){const M=Wn({widthMm:i,depthMm:a},s);u=M.vertices,h=M.positionAlongWallMm}else u=_e(t.x,t.y,t.x+i,t.y+a);const x={...Ae(u,"rectangle",d),heightMm:l,color:P$,groupId:c},f=[];for(let M=0;M<o;M+=1){const g=M*r,w=g+r,k=M===0?g:g+f8/2,_=M===o-1?w:w-f8/2,j=lo(d,"side-0",[{x:Math.round(k),y:0},{x:Math.round(_),y:0},{x:Math.round(_),y:l},{x:Math.round(k),y:l}],c);j&&f.push({...j,depthMm:L$,color:A$})}const p=[x,...f],b={id:c,entityIds:p.map(M=>M.id),name:"ארון הזזה",widthMm:i,depthMm:a,heightMm:l,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:h,createdAt:Date.now()};return{entities:p,group:b,hostId:d}}const O$="#F7F4EF",H$="#E8DFD3",B$=18,V$={widthMm:1e3,depthMm:450,heightMm:900,drawerCount:4,revealMm:8,plinthMm:15,topFrameMm:15};function z$(t={x:0,y:0},e=V$,s){const o=Math.max(500,Math.round(e.widthMm)),r=Math.max(300,Math.round(e.depthMm)),i=Math.max(500,Math.round(e.heightMm)),a=Math.max(1,Math.round(e.drawerCount)),l=Math.max(0,Math.round(e.revealMm)),c=Math.max(0,Math.round(e.plinthMm)),d=Math.max(0,Math.round(e.topFrameMm)),u=Me(),h=be("fps_rect");let x,f;if(s){const v=Wn({widthMm:o,depthMm:r},s);x=v.vertices,f=v.positionAlongWallMm}else{const v=Math.round(t.x),C=Math.round(t.y);x=_e(v,C,v+o,C+r)}const p={...Ae(x,"rectangle",h),heightMm:i,color:O$,groupId:u},b=d,M=i-c,w=(Math.max(20,M-b)-l*(a-1))/a,k=[];for(let v=0;v<a;v+=1){const C=b+v*(w+l),N=C+w,P=lo(h,"side-0",[{x:0,y:Math.round(C)},{x:o,y:Math.round(C)},{x:o,y:Math.round(N)},{x:0,y:Math.round(N)}],u);P&&k.push({...P,depthMm:B$,color:H$})}const _=[p,...k],j={id:u,entityIds:_.map(v=>v.id),name:"שידת מגירות",widthMm:o,depthMm:r,heightMm:i,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:f,createdAt:Date.now()};return{entities:_,group:j,hostId:h}}const $$="#F7F4EF",X$="#E8DFD3",Y$="#C9D6DC",G$=18,U$={widthMm:900,depthMm:400,heightMm:850,mirrorWidthMm:900,mirrorThicknessMm:20,mirrorHeightMm:600,mirrorGapMm:100,drawerTopFrameMm:20,drawerHeightMm:180};function K$(t,e){return{...t,vertices:t.vertices.map(e)}}function Z$(t={x:0,y:0},e=U$,s){const o=Math.max(500,Math.round(e.widthMm)),r=Math.max(300,Math.round(e.depthMm)),i=Math.max(500,Math.round(e.heightMm)),a=Math.max(200,Math.min(o,Math.round(e.mirrorWidthMm))),l=Math.max(10,Math.round(e.mirrorThicknessMm)),c=Math.max(200,Math.round(e.mirrorHeightMm)),d=Math.max(0,Math.round(e.mirrorGapMm)),u=Math.max(0,Math.round(e.drawerTopFrameMm)),h=Math.max(60,Math.round(e.drawerHeightMm)),x=Me(),f=be("fps_rect");let p,b;if(s){const z=Wn({widthMm:o,depthMm:r},s);p=z.vertices,b=z.positionAlongWallMm}else{const z=Math.round(t.x),X=Math.round(t.y);p=_e(z,X,z+o,X+r)}
278const M=p[0],g=p[1],w=p[3],k=(g.x-M.x)/o,_=(g.y-M.y)/o,j=(w.x-M.x)/r,v=(w.y-M.y)/r,C=z=>({x:Math.round(M.x+k*z.x+j*z.y),y:Math.round(M.y+_*z.x+v*z.y)}),N={...Ae(p,"rectangle",f),heightMm:i,color:$$,groupId:x},P=lo(f,"side-0",[{x:0,y:u},{x:o,y:u},{x:o,y:u+h},{x:0,y:u+h}],x),L=P?{...P,depthMm:G$,color:X$}:null,A=Math.round((o-a)/2),W=ee({origin:{x:A,y:r-l},widthMm:a,depthMm:l,baseHeightMm:i+d,heightMm:c,color:Y$,groupId:x}),S=K$(W,C),B=[N,S];L&&B.push(L);const R={id:x,entityIds:B.map(z=>z.id),name:"שידת איפור עם מראה",widthMm:o,depthMm:r,heightMm:i+d+c,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:b,createdAt:Date.now()};return{entities:B,group:R,hostId:f}}const q$="#E8DFD3",J$="#3A352F",Q$={widthMm:1200,depthMm:400,heightMm:450,topThicknessMm:120,legSizeMm:70,legInsetMm:70,legTaperBottom:.55};function tX(t={x:0,y:0},e=Q$,s){const o=Math.max(500,Math.round(e.widthMm)),r=Math.max(250,Math.round(e.depthMm)),i=Math.max(300,Math.round(e.heightMm)),a=Math.max(40,Math.round(e.topThicknessMm)),l=Math.max(30,Math.round(e.legSizeMm)),c=Math.max(0,Math.round(e.legInsetMm)),d=Math.max(50,i-a),u=Me(),h=ee({origin:t,widthMm:o,depthMm:r,heightMm:a,baseHeightMm:d,color:q$,groupId:u}),f=[{x:t.x+c,y:t.y+c},{x:t.x+o-c-l,y:t.y+c},{x:t.x+c,y:t.y+r-c-l},{x:t.x+o-c-l,y:t.y+r-c-l}].map(M=>Da({origin:M,widthMm:l,depthMm:l,heightMm:d,color:J$,groupId:u,taperBottom:e.legTaperBottom})),p=[h,...f],b={id:u,entityIds:p.map(M=>M.id),name:"ספסל קצה מיטה",widthMm:o,depthMm:r,heightMm:i,createdAt:Date.now()};return{entities:p,group:b,hostId:h.id}}const eX="#F7F4EF",nX="#E8DFD3",oX="#E8DFD3",sX={widthMm:900,depthMm:2e3,platformHeightMm:400,mattressHeightMm:150,headboardDepthMm:100,headboardHeightMm:700};function rX(t,e){return{...t,vertices:t.vertices.map(e)}}function iX(t={x:0,y:0},e=sX,s){const o=Math.max(700,Math.round(e.widthMm)),r=Math.max(1500,Math.round(e.depthMm)),i=Math.max(100,Math.round(e.platformHeightMm)),a=Math.max(60,Math.round(e.mattressHeightMm)),l=Math.max(40,Math.min(r-200,Math.round(e.headboardDepthMm))),c=Math.max(200,Math.round(e.headboardHeightMm)),d=Me(),u=be("fps_rect");let h,x;if(s){const A=Wn({widthMm:o,depthMm:r},s);h=A.vertices,x=A.positionAlongWallMm}else{const A=Math.round(t.x),W=Math.round(t.y);h=_e(A,W,A+o,W+r)}const f=h[0],p=h[1],b=h[3],M=(p.x-f.x)/o,g=(p.y-f.y)/o,w=(b.x-f.x)/r,k=(b.y-f.y)/r,_=A=>({x:Math.round(f.x+M*A.x+w*A.y),y:Math.round(f.y+g*A.x+k*A.y)}),j={...Ae(h,"rectangle",u),heightMm:i,color:eX,groupId:d},v=ee({origin:{x:0,y:0},widthMm:o,depthMm:r,baseHeightMm:i,heightMm:a,color:nX,groupId:d}),C=ee({origin:{x:0,y:r-l},widthMm:o,depthMm:l,baseHeightMm:i,heightMm:c,color:oX,groupId:d}),N=[v,C].map(A=>rX(A,_)),P=[j,...N],L={id:d,entityIds:P.map(A=>A.id),name:"מיטת יחיד",widthMm:o,depthMm:r,heightMm:i+c,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:x,createdAt:Date.now()};return{entities:P,group:L,hostId:u}}const x8="#F7F4EF",G2="#D8CFBF",aX={widthMm:900,depthMm:2e3,lowerBaseHeightMm:200,platformHeightMm:200,upperBaseHeightMm:1500,postSizeMm:60,postHeightMm:1700,rungCount:3,rungWidthMm:80,rungDepthMm:40,rungHeightMm:30,lowestRungBaseHeightMm:500,rungSpacingMm:400,safetyRailHeightMm:150,safetyRailDepthMm:40};function lX(t,e){return{...t,vertices:t.vertices.map(e)}}function cX(t={x:0,y:0},e=aX,s){const o=Math.max(700,Math.round(e.widthMm)),r=Math.max(1500,Math.round(e.depthMm)),i=Math.max(0,Math.round(e.lowerBaseHeightMm)),a=Math.max(60,Math.round(e.platformHeightMm)),l=Math.max(i+a+600,Math.round(e.upperBaseHeightMm)),c=Math.max(40,Math.round(e.postSizeMm)),d=Math.max(l+a,Math.round(e.postHeightMm)),u=Math.max(2,Math.round(e.rungCount)),h=Math.max(40,Math.round(e.rungWidthMm)),x=Math.max(20,Math.round(e.rungDepthMm)),f=Math.max(20,Math.round(e.rungHeightMm)),p=Math.max(100,Math.round(e.lowestRungBaseHeightMm)),b=Math.max(150,Math.round(e.rungSpacingMm)),M=Math.max(80,Math.round(e.safetyRailHeightMm)),g=Math.max(20,Math.round(e.safetyRailDepthMm)),w=Me(),k=be("fps_rect");let _,j;if(s){const it=Wn({widthMm:o,depthMm:r},s);_=it.vertices,j=it.positionAlongWallMm}else{const it=Math.round(t.x),st=Math.round(t.y);_=_e(it,st,it+o,st+r)}const v=_[0],C=_[1],N=_[3],P=(C.x-v.x)/o,L=(C.y-v.y)/o,A=(N.x-v.x)/r,W=(N.y-v.y)/r,S=it=>({x:Math.round(v.x+P*it.x+A*it.y),y:Math.round(v.y+L*it.x+W*it.y)}),B={...Ae(_,"rectangle",k),heightMm:a,baseHeightMm:i>0?i:void 0,color:x8,groupId:w},R=ee({origin:{x:0,y:0},widthMm:o,depthMm:r,baseHeightMm:l,heightMm:a,color:x8,groupId:w}),X=[{x:0,y:0},{x:o-c,y:0},{x:0,y:r-c},{x:o-c,y:r-c}].map(it=>ee({origin:it,widthMm:c,depthMm:c,heightMm:d,color:G2,groupId:w})),ft=[];for(let it=0;
278it<u;it+=1)ft.push(ee({origin:{x:o-h,y:0},widthMm:h,depthMm:x,baseHeightMm:p+it*b,heightMm:f,color:G2,groupId:w}));const tt=ee({origin:{x:0,y:0},widthMm:o,depthMm:g,baseHeightMm:l+a,heightMm:M,color:G2,groupId:w}),Y=[R,...X,...ft,tt].map(it=>lX(it,S)),J=[B,...Y],Mt=Math.max(l+a+M,d),Rt={id:w,entityIds:J.map(it=>it.id),name:"מיטת קומותיים",widthMm:o,depthMm:r,heightMm:Mt,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:j,createdAt:Date.now()};return{entities:J,group:Rt,hostId:k}}const dX="#EDE7DC",uX="#D8CFBF",hX={widthMm:1200,depthMm:600,heightMm:750,topThicknessMm:30,legSizeMm:70,legInsetMm:70,legTaperBottom:.55};function mX(t={x:0,y:0},e=hX,s){const o=Math.max(600,Math.round(e.widthMm)),r=Math.max(400,Math.round(e.depthMm)),i=Math.max(500,Math.round(e.heightMm)),a=Math.max(15,Math.round(e.topThicknessMm)),l=Math.max(30,Math.round(e.legSizeMm)),c=Math.max(0,Math.round(e.legInsetMm)),d=Math.max(50,i-a),u=Me(),h=ee({origin:t,widthMm:o,depthMm:r,heightMm:a,baseHeightMm:d,color:dX,groupId:u}),f=[{x:t.x+c,y:t.y+c},{x:t.x+o-c-l,y:t.y+c},{x:t.x+c,y:t.y+r-c-l},{x:t.x+o-c-l,y:t.y+r-c-l}].map(M=>Da({origin:M,widthMm:l,depthMm:l,heightMm:d,color:uX,groupId:u,taperBottom:e.legTaperBottom})),p=[h,...f],b={id:u,entityIds:p.map(M=>M.id),name:"שולחן כתיבה",widthMm:o,depthMm:r,heightMm:i,createdAt:Date.now()};return{entities:p,group:b,hostId:h.id}}const fX="#F7F4EF",xX={widthMm:800,depthMm:250,thicknessMm:30,baseHeightMm:1500};function pX(t={x:0,y:0},e=xX,s){const o=Math.max(200,Math.round(e.widthMm)),r=Math.max(100,Math.round(e.depthMm)),i=Math.max(10,Math.round(e.thicknessMm)),a=Math.max(0,Math.round(e.baseHeightMm)),l=Me(),c=be("fps_rect");let d,u;if(s){const p=Wn({widthMm:o,depthMm:r},s);d=p.vertices,u=p.positionAlongWallMm}else{const p=Math.round(t.x),b=Math.round(t.y);d=_e(p,b,p+o,b+r)}const x=[{...Ae(d,"rectangle",c),heightMm:i,baseHeightMm:a>0?a:void 0,color:fX,groupId:l}],f={id:l,entityIds:x.map(p=>p.id),name:"מדף תלוי",widthMm:o,depthMm:r,heightMm:i,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:u,createdAt:Date.now()};return{entities:x,group:f,hostId:c}}const gX="#F7F4EF",bX="#E8DFD3",MX="#DDD3C4",yX="#C4BAA9",wX="#182137",kX={widthMm:900,depthMm:500,heightMm:850,counterThicknessMm:30,sideOverhangMm:20,frontOverhangMm:20,doorCount:2,basinWidthMm:450,basinDepthMm:360,basinDownMm:180};function p8(t,e){return{...t,vertices:t.vertices.map(e)}}function vX(t={x:0,y:0},e=kX,s){const o=Math.max(500,Math.round(e.widthMm)),r=Math.max(300,Math.round(e.depthMm)),i=Math.max(500,Math.round(e.heightMm)),a=Math.max(20,Math.round(e.counterThicknessMm)),l=Math.max(0,Math.round(e.sideOverhangMm)),c=Math.max(0,Math.round(e.frontOverhangMm)),d=Me(),u=be("fps_rect");let h,x;if(s){const z=Wn({widthMm:o,depthMm:r},s);h=z.vertices,x=z.positionAlongWallMm}else{const z=Math.round(t.x),X=Math.round(t.y);h=_e(z,X,z+o,X+r)}const f=h[0],p=h[1],b=h[3],M=(p.x-f.x)/o,g=(p.y-f.y)/o,w=(b.x-f.x)/r,k=(b.y-f.y)/r,_=z=>({x:Math.round(f.x+M*z.x+w*z.y),y:Math.round(f.y+g*z.x+k*z.y)}),j={...Ae(h,"rectangle",u),heightMm:i,color:gX,groupId:d},C=Pb([j],u,"side-0",{drawerCount:0,doorCount:Math.max(1,Math.round(e.doorCount))}).entities.map(z=>z.kind==="facePatch"&&z.id!==u?{...z,color:bX}:z),N=ee({origin:{x:-l,y:-c},widthMm:o+l*2,depthMm:r+c,baseHeightMm:i,heightMm:a,color:MX,groupId:d}),P=p8(N,_),L=$d(P,{widthMm:e.basinWidthMm,depthMm:e.basinDepthMm,downMm:e.basinDownMm,offsetYMm:20,color:yX},d),A=35,S=wm({origin:{x:Math.round(o/2)-Math.round(A/2),y:r-70-A},baseHeightMm:i+a,postHeightMm:240,spoutReachMm:200,thicknessMm:A,color:wX,groupId:d}).map(z=>p8(z,_)),B=[...C,P,...L?[L]:[],...S],R={id:d,entityIds:B.map(z=>z.id),name:"ארון אמבט עם כיור",widthMm:o,depthMm:r,heightMm:i+a,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:x,createdAt:Date.now()};return{entities:B,group:R,hostId:u}}const jX="#F7F4EF",_X="#E8DFD3",EX="#DDD3C4",g8="#C4BAA9",DX="#182137",Dp="#1C1C1C",FX=500,CX=850,b8=30,M8=20,y8=20,Fp=15;function w8(t,e){return{...t,vertices:t.vertices.map(e)}}function NX(t,e,s,o){return wm({origin:{x:Math.round(t-35/2),y:e-70-35},baseHeightMm:s,postHeightMm:240,spoutReachMm:200,thicknessMm:35,color:DX,groupId:o})}function QF(t,e,s,o,r){const i=ee({origin:{x:Math.round(t-o),y:s-Fp},widthMm:2*o,depthMm:Fp,baseHeightMm:e-o,heightMm:2*o,color:Dp,groupId:r}),a=m9({hostId:i.id,faceId:"side-0",centerX:o,centerY:o,radiusMm:o-3,depthMm:14,color:Dp,groupId:r});return{polys:[i],patches:a?[a]:[]}}function k8(t,e,s,o){const r=QF(t,e,s,35,o),i=190,a=ee({origin:{x:Math.round(t-16),y:s-Fp-i},widthMm:32,depthMm:i,baseHeightMm:e-16,heightMm:32,color:Dp,groupId:o}),l=Ep({center:{x:t,y:s-Fp-i+16},radiusMm:16,baseHeightMm:e-110,heightMm:126,color:Dp,groupId:o});return{polys:[...r.polys,a,l],patches:r.patches}}function v8(t,e,s,o){const r=QF(t,e,s,28,o),i=Ep({center:{x:t,y:s-Fp},radiusMm:6,baseHeightMm:e-95,heightMm:100,color:Dp,groupId:o});return{polys:[...r.polys,i],patches:r.patches}}function hf(t={x:0,y:0},e,s){const o=Math.max(500,Math.round(e.widthMm)),r=FX,i=CX,a=i+b8,l=o>=1100?3:2,c=Me(),d=be("fps_rect");let u,h;if(s){const X=Wn({widthMm:o,depthMm:r},s);u=X.vertices,h=X.positionAlongWallMm}else{const X=Math.round(t.x),ft=Math.round(t.y);u=_e(X,ft,X+o,ft+r)}const x=u[0],f=u[1],p=u[3],b=(f.x-x.x)/o,M=(f.y-x.y)/o,g=(p.x-x.x)/r,w=(p.y-x.y)/r,k=X=>({x:Math.round(x.x+b*X.x+g*X.y),y:Math.round(x.y+M*X.x+w*X.y)}),_={...Ae(u,"rectangle",d),heightMm:i,color:jX,groupId:c},v=Pb([_],d,"side-0",{drawerCount:0,doorCount:l}).entities.map(X=>X.kind==="facePatch"&&X.id!==d?{...X,color:_X}:X),C=ee({origin:{x:-M8,y:-y8},widthMm:o+M8*2,depthMm:r+y8,baseHeightMm:i,heightMm:b8,color:EX,groupId:c}),N=w8(C,k),P=[];if(e.doubleBasin){const X=Math.min(400,Math.round(o*.3));for(const ft of[-1,1]){const tt=$d(N,{widthMm:X,depthMm:340,downMm:180,offsetXMm:ft*Math.round(o/4),offsetYMm:2
2780,color:g8},c);tt&&P.push(tt)}}else{const X=$d(N,{widthMm:Math.min(450,Math.round(o*.6)),depthMm:360,downMm:180,offsetYMm:20,color:g8},c);X&&P.push(X)}const L=e.doubleBasin?[o/4,3*o/4]:[o/2],A=[],W=[],S=X=>{A.push(...X.polys),W.push(...X.patches)};if(e.interpotz!=="none"||e.faucet==="wall"){const X=a+130,ft=e.interpotz==="2x3"?4:e.interpotz==="4way"?3:e.interpotz==="3way"?2:1;if(e.doubleBasin){for(const tt of L)S(k8(tt,X,r,c));S(v8(o/2,X,r,c))}else{S(k8(o/2-90,X,r,c));for(let tt=0;tt<ft;tt+=1)S(v8(o/2+10+tt*60,X,r,c))}}else for(const X of L)A.push(...NX(X,r,a,c));const B=A.map(X=>w8(X,k)),R=[...v,N,...P,...B,...W],z={id:c,entityIds:R.map(X=>X.id),name:"ארון אמבט",widthMm:o,depthMm:r,heightMm:a,rigid:!0,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:h,createdAt:Date.now()};return{entities:R,group:z,hostId:d}}const IX="#C9D6DC",TX="#FFF8E0",SX={widthMm:800,depthMm:20,heightMm:800,baseHeightMm:1100,lightWidthMm:800,lightDepthMm:40,lightHeightMm:30,lightGapMm:10};function PX(t,e){return{...t,vertices:t.vertices.map(e)}}function AX(t={x:0,y:0},e=SX,s){const o=Math.max(300,Math.round(e.widthMm)),r=Math.max(10,Math.round(e.depthMm)),i=Math.max(300,Math.round(e.heightMm)),a=Math.max(0,Math.round(e.baseHeightMm)),l=Math.max(100,Math.round(e.lightWidthMm)),c=Math.max(10,Math.round(e.lightDepthMm)),d=Math.max(10,Math.round(e.lightHeightMm)),u=Math.max(0,Math.round(e.lightGapMm)),h=Me(),x=be("fps_rect");let f,p;if(s){const B=Wn({widthMm:o,depthMm:r},s);f=B.vertices,p=B.positionAlongWallMm}else{const B=Math.round(t.x),R=Math.round(t.y);f=_e(B,R,B+o,R+r)}const b=f[0],M=f[1],g=f[3],w=(M.x-b.x)/o,k=(M.y-b.y)/o,_=(g.x-b.x)/r,j=(g.y-b.y)/r,v=B=>({x:Math.round(b.x+w*B.x+_*B.y),y:Math.round(b.y+k*B.x+j*B.y)}),C={...Ae(f,"rectangle",x),heightMm:i,baseHeightMm:a>0?a:void 0,color:IX,groupId:h},N=Math.round((o-l)/2),P=Math.round(-(c-r)/2),L=ee({origin:{x:N,y:P},widthMm:l,depthMm:c,baseHeightMm:a+i+u,heightMm:d,color:TX,groupId:h}),A=PX(L,v),W=[C,A],S={id:h,entityIds:W.map(B=>B.id),name:"מראה עם תאורה",widthMm:o,depthMm:r,heightMm:i+u+d,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:p,createdAt:Date.now()};return{entities:W,group:S,hostId:x}}const LX="#F7F4EF",j8="#E0EAEF",WX={widthMm:900,depthMm:900,trayThicknessMm:50,glassThicknessMm:15,glassHeightMm:2e3};function _8(t,e){return{...t,vertices:t.vertices.map(e)}}function RX(t={x:0,y:0},e=WX,s){const o=Math.max(700,Math.round(e.widthMm)),r=Math.max(700,Math.round(e.depthMm)),i=Math.max(20,Math.round(e.trayThicknessMm)),a=Math.max(10,Math.round(e.glassThicknessMm)),l=Math.max(1500,Math.round(e.glassHeightMm)),c=Me(),d=be("fps_rect");let u,h;if(s){const A=Wn({widthMm:o,depthMm:r},s);u=A.vertices,h=A.positionAlongWallMm}else{const A=Math.round(t.x),W=Math.round(t.y);u=_e(A,W,A+o,W+r)}const x=u[0],f=u[1],p=u[3],b=(f.x-x.x)/o,M=(f.y-x.y)/o,g=(p.x-x.x)/r,w=(p.y-x.y)/r,k=A=>({x:Math.round(x.x+b*A.x+g*A.y),y:Math.round(x.y+M*A.x+w*A.y)}),_={...Ae(u,"rectangle",d),heightMm:i,color:LX,groupId:c},j=ee({origin:{x:0,y:0},widthMm:o,depthMm:a,baseHeightMm:i,heightMm:l,color:j8,groupId:c}),v=ee({origin:{x:0,y:a},widthMm:a,depthMm:Math.max(100,r-a),baseHeightMm:i,heightMm:l,color:j8,groupId:c}),C=_8(j,k),N=_8(v,k),P=[_,C,N],L={id:c,entityIds:P.map(A=>A.id),name:"מקלחון",widthMm:o,depthMm:r,heightMm:i+l,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:h,createdAt:Date.now()};return{entities:P,group:L,hostId:d}}const OX="#F7F4EF",HX="#F0EDE6",BX={widthMm:1700,depthMm:750,heightMm:550,basinWidthMm:1500,basinDepthMm:600,basinDownMm:400};function VX(t={x:0,y:0},e=BX,s){const o=Math.max(1e3,Math.round(e.widthMm)),r=Math.max(500,Math.round(e.depthMm)),i=Math.max(300,Math.round(e.heightMm)),a=Me(),l=be("fps_rect");let c,d;if(s){const p=Wn({widthMm:o,depthMm:r},s);c=p.vertices,d=p.positionAlongWallMm}else{const p=Math.round(t.x),b=Math.round(t.y);c=_e(p,b,p+o,b+r)}const u={...Ae(c,"rectangle",l),heightMm:i,color:OX,groupId:a},h=$d(u,{widthMm:e.basinWidthMm,depthMm:e.basinDepthMm,downMm:e.basinDownMm,color:HX},a),x=[u,...h?[h]:[]],f={id:a,entityIds:x.map(p=>p.id),name:"אמבטיה",widthMm:o,depthMm:r,heightMm:i,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:d,createdAt:Date.now()};return{entities:x,group:f,hostId:l}}const zX="#F7F4EF",$X="#F7F4EF",XX="#182137",YX={widthMm:800,depthMm:350,benchHeightMm:450,backPanelThicknessMm:50,backPanelHeightMm:1800,hookCount:3,hookSizeMm:40,hookFaceTopYMm:810,hookProtrusionMm:50};function GX(t,e){return{...t,vertices:t.vertices.map(e)}}function UX(t={x:0,y:0},e=YX,s){const o=Math.max(500,Math.round(e.widthMm)),r=Math.max(250,Math.round(e.depthMm)),i=Math.max(300,Math.round(e.benchHeightMm)),a=Math.max(20,Math.round(e.backPanelThicknessMm)),l=Math.max(1e3,Math.round(e.backPanelHeightMm)),c=Math.max(1,Math.round(e.hookCount)),d=Math.max(20,Math.round(e.hookSizeMm)),u=Math.max(0,Math.round(e.hookFaceTopYMm)),h=Math.max(20,Math.round(e.hookProtrusionMm)),x=Me(),f=be("fps_rect");let p,b;if(s){const R=Wn({widthMm:o,depthMm:r},s);p=R.vertices,b=R.positionAlongWallMm}else{const R=Math.round(t.x),z=Math.round(t.y);p=_e(R,z,R+o,z+r)}
278const M=p[0],g=p[1],w=p[3],k=(g.x-M.x)/o,_=(g.y-M.y)/o,j=(w.x-M.x)/r,v=(w.y-M.y)/r,C=R=>({x:Math.round(M.x+k*R.x+j*R.y),y:Math.round(M.y+_*R.x+v*R.y)}),N={...Ae(p,"rectangle",f),heightMm:i,color:zX,groupId:x},P=ee({origin:{x:0,y:r-a},widthMm:o,depthMm:a,baseHeightMm:i,heightMm:l,color:$X,groupId:x}),L=GX(P,C),A=[],W=Math.max(60,Math.round((o-d*c)/(c+1)));for(let R=0;R<c;R+=1){const z=W+R*(d+W)+d/2,X=Math.round(z-d/2),ft=Math.round(z+d/2),tt=lo(L.id,"side-0",[{x:X,y:u},{x:ft,y:u},{x:ft,y:u+d},{x:X,y:u+d}],x);tt&&A.push({...tt,depthMm:h,color:XX})}const S=[N,L,...A],B={id:x,entityIds:S.map(R=>R.id),name:"יחידת כניסה",widthMm:o,depthMm:r,heightMm:i+l,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:b,createdAt:Date.now()};return{entities:S,group:B,hostId:f}}const KX="#C9D6DC",ZX={widthMm:600,depthMm:20,heightMm:1800};function qX(t={x:0,y:0},e=ZX,s){const o=Math.max(300,Math.round(e.widthMm)),r=Math.max(10,Math.round(e.depthMm)),i=Math.max(800,Math.round(e.heightMm)),a=Me(),l=be("fps_rect");let c,d;if(s){const f=Wn({widthMm:o,depthMm:r},s);c=f.vertices,d=f.positionAlongWallMm}else{const f=Math.round(t.x),p=Math.round(t.y);c=_e(f,p,f+o,p+r)}const h=[{...Ae(c,"rectangle",l),heightMm:i,color:KX,groupId:a}],x={id:a,entityIds:h.map(f=>f.id),name:"מראת קומה",widthMm:o,depthMm:r,heightMm:i,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:d,createdAt:Date.now()};return{entities:h,group:x,hostId:l}}const JX="#EDE7DC",QX="#D8CFBF",tY={widthMm:1200,depthMm:350,heightMm:800,topThicknessMm:30,legSizeMm:70,legInsetMm:70,legTaperBottom:.55};function eY(t={x:0,y:0},e=tY,s){const o=Math.max(600,Math.round(e.widthMm)),r=Math.max(250,Math.round(e.depthMm)),i=Math.max(500,Math.round(e.heightMm)),a=Math.max(15,Math.round(e.topThicknessMm)),l=Math.max(30,Math.round(e.legSizeMm)),c=Math.max(0,Math.round(e.legInsetMm)),d=Math.max(50,i-a),u=Me(),h=ee({origin:t,widthMm:o,depthMm:r,heightMm:a,baseHeightMm:d,color:JX,groupId:u}),f=[{x:t.x+c,y:t.y+c},{x:t.x+o-c-l,y:t.y+c},{x:t.x+c,y:t.y+r-c-l},{x:t.x+o-c-l,y:t.y+r-c-l}].map(M=>Da({origin:M,widthMm:l,depthMm:l,heightMm:d,color:QX,groupId:u,taperBottom:e.legTaperBottom})),p=[h,...f],b={id:u,entityIds:p.map(M=>M.id),name:"קונסולה נמוכה",widthMm:o,depthMm:r,heightMm:i,createdAt:Date.now()};return{entities:p,group:b,hostId:h.id}}const nY="#EDE7DC",oY="#D8CFBF",sY={widthMm:1400,depthMm:700,heightMm:750,topThicknessMm:30,legSizeMm:70,legInsetMm:70,legTaperBottom:.55};function rY(t={x:0,y:0},e=sY,s){const o=Math.max(800,Math.round(e.widthMm)),r=Math.max(400,Math.round(e.depthMm)),i=Math.max(500,Math.round(e.heightMm)),a=Math.max(15,Math.round(e.topThicknessMm)),l=Math.max(30,Math.round(e.legSizeMm)),c=Math.max(0,Math.round(e.legInsetMm)),d=Math.max(50,i-a),u=Me(),h=ee({origin:t,widthMm:o,depthMm:r,heightMm:a,baseHeightMm:d,color:nY,groupId:u}),f=[{x:t.x+c,y:t.y+c},{x:t.x+o-c-l,y:t.y+c},{x:t.x+c,y:t.y+r-c-l},{x:t.x+o-c-l,y:t.y+r-c-l}].map(M=>Da({origin:M,widthMm:l,depthMm:l,heightMm:d,color:oY,groupId:u,taperBottom:e.legTaperBottom})),p=[h,...f],b={id:u,entityIds:p.map(M=>M.id),name:"שולחן עבודה",widthMm:o,depthMm:r,heightMm:i,createdAt:Date.now()};return{entities:p,group:b,hostId:h.id}}const iY="#F7F4EF",aY="#DDD3C4",Ag=30,E8=24,lY=30,cY={widthMm:800,depthMm:350,heightMm:2e3,cubbyCount:5};function dY(t={x:0,y:0},e=cY,s){const o=Math.max(400,Math.round(e.widthMm)),r=Math.max(200,Math.round(e.depthMm)),i=Math.max(1e3,Math.round(e.heightMm)),a=Math.max(1,Math.round(e.cubbyCount)),l=Me(),c=be("fps_rect");let d,u;if(s){const v=Wn({widthMm:o,depthMm:r},s);d=v.vertices,u=v.positionAlongWallMm}else{const v=Math.round(t.x),C=Math.round(t.y);d=_e(v,C,v+o,C+r)}const h={...Ae(d,"rectangle",c),heightMm:i,color:iY,groupId:l},x=[],f=Ag,p=o-Ag,b=Ag,w=(i-Ag-b-E8*(a-1))/a,k=-(r-lY);for(let v=0;v<a;v+=1){const C=b+v*(w+E8),N=C+w,P=lo(c,"side-0",[{x:f,y:Math.round(C)},{x:p,y:Math.round(C)},{x:p,y:Math.round(N)},{x:f,y:Math.round(N)}],l);P&&x.push({...P,depthMm:k,color:aY})}const _=[h,...x],j={id:l,entityIds:_.map(v=>v.id),name:"ספריית מדפים",widthMm:o,depthMm:r,heightMm:i,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:u,createdAt:Date.now()};return{entities:_,group:j,hostId:c}}const uY="#F7F4EF",hY="#E8DFD3",mY="#3A352F",fY=18,xY={widthMm:400,depthMm:500,heightMm:600,drawerCount:3,revealMm:8,plinthMm:135,topFrameMm:15,wheelDiameterMm:60,wheelHeightMm:130,wheelInsetMm:20};function pY(t={x:0,y:0},e=xY,s){const o=Math.max(300,Math.round(e.widthMm)),r=Math.max(300,Math.round(e.depthMm)),i=Math.max(400,Math.round(e.heightMm)),a=Math.max(1,Math.round(e.drawerCount)),l=Math.max(0,Math.round(e.revealMm)),c=Math.max(0,Math.round(e.plinthMm)),d=Math.max(0,Math.round(e.topFrameMm)),u=Math.max(30,Math.round(e.wheelDiameterMm)),h=Math.max(40,Math.round(e.wheelHeightMm)),x=Math.max(0,Math.round(e.wheelInsetMm)),f=Math.round(t.x),p=Math.round(t.y),b=Me(),M=be("fps_rect"),g=_e(f,p,f+o,p+r),w={...Ae(g,"rectangle",M),heightMm:i,baseHeightMm:h,color:uY,groupId:b}
278,k=d,_=i-c,v=(Math.max(20,_-k)-l*(a-1))/a,C=[];for(let W=0;W<a;W+=1){const S=k+W*(v+l),B=S+v,R=lo(M,"side-0",[{x:0,y:Math.round(S)},{x:o,y:Math.round(S)},{x:o,y:Math.round(B)},{x:0,y:Math.round(B)}],b);R&&C.push({...R,depthMm:fY,color:hY})}const P=[{x:f+x,y:p+x},{x:f+o-x-u,y:p+x},{x:f+x,y:p+r-x-u},{x:f+o-x-u,y:p+r-x-u}].map(W=>Da({origin:W,widthMm:u,depthMm:u,heightMm:h,color:mY,groupId:b,round:!0})),L=[w,...C,...P],A={id:b,entityIds:L.map(W=>W.id),name:"ארונית על גלגלים",widthMm:o,depthMm:r,heightMm:h+i,createdAt:Date.now()};return{entities:L,group:A,hostId:M}}const gY="#F7F4EF",bY="#E8DFD3",MY="#E8DFD3",D8="#F7F4EF",yY={widthMm:1700,depthMm:950,heightMm:850,seatBaseHeightMm:180,seatCushionHeightMm:120,seatCushionDepthMm:850,backCushionHeightMm:550,backCushionDepthMm:120,armrestWidthMm:120,armrestHeightMm:600,cushionRevealMm:20};function wY(t,e){return{...t,vertices:t.vertices.map(e)}}function kY(t={x:0,y:0},e=yY,s){const o=Math.max(1200,Math.round(e.widthMm)),r=Math.max(700,Math.round(e.depthMm)),i=Math.max(100,Math.round(e.seatBaseHeightMm)),a=Math.max(60,Math.round(e.seatCushionHeightMm)),l=Math.max(400,Math.min(r,Math.round(e.seatCushionDepthMm))),c=Math.max(150,Math.round(e.backCushionHeightMm)),d=Math.max(60,Math.round(e.backCushionDepthMm)),u=Math.max(70,Math.round(e.armrestWidthMm)),h=Math.max(300,Math.round(e.armrestHeightMm)),x=Math.max(0,Math.round(e.cushionRevealMm)),f=Me(),p=be("fps_rect");let b,M;if(s){const st=Wn({widthMm:o,depthMm:r},s);b=st.vertices,M=st.positionAlongWallMm}else{const st=Math.round(t.x),ct=Math.round(t.y);b=_e(st,ct,st+o,ct+r)}const g=b[0],w=b[1],k=b[3],_=(w.x-g.x)/o,j=(w.y-g.y)/o,v=(k.x-g.x)/r,C=(k.y-g.y)/r,N=st=>({x:Math.round(g.x+_*st.x+v*st.y),y:Math.round(g.y+j*st.x+C*st.y)}),P={...Ae(b,"rectangle",p),heightMm:i,color:gY,groupId:f},L=u,A=o-u,S=(Math.max(300,A-L)-x)/2,B=[];for(let st=0;st<2;st+=1){const ct=L+st*(S+x);B.push(ee({origin:{x:ct,y:0},widthMm:S,depthMm:l,baseHeightMm:i,heightMm:a,color:bY,groupId:f}))}const R=S,z=r-d,X=[];for(let st=0;st<2;st+=1){const ct=L+st*(R+x);X.push(ee({origin:{x:ct,y:z},widthMm:R,depthMm:d,baseHeightMm:i+a,heightMm:c,color:MY,groupId:f}))}const ft=Math.max(100,h-i),tt=ee({origin:{x:0,y:0},widthMm:u,depthMm:r,baseHeightMm:i,heightMm:ft,color:D8,groupId:f}),G=ee({origin:{x:o-u,y:0},widthMm:u,depthMm:r,baseHeightMm:i,heightMm:ft,color:D8,groupId:f}),J=[...B,...X,tt,G].map(st=>wY(st,N)),Mt=[P,...J],Rt=Math.max(e.heightMm,i+a+c),it={id:f,entityIds:Mt.map(st=>st.id),name:"ספה דו-מושבית",widthMm:o,depthMm:r,heightMm:Rt,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:M,createdAt:Date.now()};return{entities:Mt,group:it,hostId:p}}const F8="#F7F4EF",C8="#E8DFD3",N8="#E8DFD3",vY="#F7F4EF",jY={mainWidthMm:3400,mainDepthMm:950,returnWidthMm:2300,returnDepthMm:950,seatBaseHeightMm:180,seatCushionHeightMm:120,seatCushionDepthMm:850,backCushionHeightMm:550,backCushionDepthMm:120,armrestWidthMm:120,armrestHeightMm:600,cushionRevealMm:20};function _Y(t,e){return{...t,vertices:t.vertices.map(e)}}function EY(t={x:0,y:0},e=jY,s){const o=Math.max(2400,Math.round(e.mainWidthMm)),r=Math.max(700,Math.round(e.mainDepthMm)),i=Math.max(1500,Math.round(e.returnWidthMm)),a=Math.max(700,Math.round(e.returnDepthMm)),l=Math.max(100,Math.round(e.seatBaseHeightMm)),c=Math.max(60,Math.round(e.seatCushionHeightMm)),d=Math.max(400,Math.min(r,Math.round(e.seatCushionDepthMm))),u=Math.max(150,Math.round(e.backCushionHeightMm)),h=Math.max(60,Math.round(e.backCushionDepthMm)),x=Math.max(70,Math.round(e.armrestWidthMm)),f=Math.max(300,Math.round(e.armrestHeightMm)),p=Math.max(0,Math.round(e.cushionRevealMm)),b=Math.max(500,i-a),M=Me(),g=be("fps_rect"),w=Math.round(t.x),k=Math.round(t.y),_=_e(w,k,w+o,k+r),j=_[0],v=_[1],C=_[3],N=(v.x-j.x)/o,P=(v.y-j.y)/o,L=(C.x-j.x)/r,A=(C.y-j.y)/r,W=Ht=>({x:Math.round(j.x+N*Ht.x+L*Ht.y),y:Math.round(j.y+P*Ht.x+A*Ht.y)}),S={...Ae(_,"rectangle",g),heightMm:l,color:F8,groupId:M},B=ee({origin:{x:0,y:-b},widthMm:a,depthMm:b,heightMm:l,color:F8,groupId:M}),R=0,z=o-x,ft=(Math.max(300,z-R)-p*2)/3,tt=[];for(let Ht=0;Ht<3;Ht+=1){const Tt=R+Ht*(ft+p);tt.push(ee({origin:{x:Tt,y:0},widthMm:ft,depthMm:d,baseHeightMm:l,heightMm:c,color:C8,groupId:M}))}const G=-b,Mt=(Math.max(300,0-G)-p)/2,Rt=[];for(let Ht=0;Ht<2;Ht+=1){const Tt=G+Ht*(Mt+p);Rt.push(ee({origin:{x:0,y:Tt},widthMm:d,depthMm:Mt,baseHeightMm:l,heightMm:c,color:C8,groupId:M}))}const it=ee({origin:{x:0,y:r-h},widthMm:o-x,depthMm:h,baseHeightMm:l+c,heightMm:u,color:N8,groupId:M}),st=ee({origin:{x:0,y:-b},widthMm:h,depthMm:b,baseHeightMm:l+c,heightMm:u,color:N8,groupId:M}
278),ct=Math.max(100,f-l),pt=ee({origin:{x:o-x,y:0},widthMm:x,depthMm:r,baseHeightMm:l,heightMm:ct,color:vY,groupId:M}),_t=[B,...tt,...Rt,it,st,pt].map(Ht=>_Y(Ht,W)),Ft=[S,..._t],Vt=l+c+u,vt={id:M,entityIds:Ft.map(Ht=>Ht.id),name:"מודול פינתי",widthMm:o,depthMm:r+b,heightMm:Vt,createdAt:Date.now()};return{entities:Ft,group:vt,hostId:g}}const DY="#F7F4EF",FY="#E8DFD3",CY="#E8DFD3",I8="#F7F4EF",NY={widthMm:900,depthMm:900,heightMm:900,seatBaseHeightMm:180,seatCushionHeightMm:120,seatCushionDepthMm:750,backCushionHeightMm:550,backCushionDepthMm:120,armrestWidthMm:120,armrestHeightMm:600};function IY(t,e){return{...t,vertices:t.vertices.map(e)}}function TY(t={x:0,y:0},e=NY,s){const o=Math.max(700,Math.round(e.widthMm)),r=Math.max(700,Math.round(e.depthMm)),i=Math.max(100,Math.round(e.seatBaseHeightMm)),a=Math.max(60,Math.round(e.seatCushionHeightMm)),l=Math.max(400,Math.min(r,Math.round(e.seatCushionDepthMm))),c=Math.max(150,Math.round(e.backCushionHeightMm)),d=Math.max(60,Math.round(e.backCushionDepthMm)),u=Math.max(70,Math.round(e.armrestWidthMm)),h=Math.max(300,Math.round(e.armrestHeightMm)),x=Me(),f=be("fps_rect");let p,b;if(s){const Y=Wn({widthMm:o,depthMm:r},s);p=Y.vertices,b=Y.positionAlongWallMm}else{const Y=Math.round(t.x),J=Math.round(t.y);p=_e(Y,J,Y+o,J+r)}const M=p[0],g=p[1],w=p[3],k=(g.x-M.x)/o,_=(g.y-M.y)/o,j=(w.x-M.x)/r,v=(w.y-M.y)/r,C=Y=>({x:Math.round(M.x+k*Y.x+j*Y.y),y:Math.round(M.y+_*Y.x+v*Y.y)}),N={...Ae(p,"rectangle",f),heightMm:i,color:DY,groupId:x},P=u,L=Math.max(200,o-u*2),A=ee({origin:{x:P,y:0},widthMm:L,depthMm:l,baseHeightMm:i,heightMm:a,color:FY,groupId:x}),W=ee({origin:{x:P,y:r-d},widthMm:L,depthMm:d,baseHeightMm:i+a,heightMm:c,color:CY,groupId:x}),S=Math.max(100,h-i),B=ee({origin:{x:0,y:0},widthMm:u,depthMm:r,baseHeightMm:i,heightMm:S,color:I8,groupId:x}),R=ee({origin:{x:o-u,y:0},widthMm:u,depthMm:r,baseHeightMm:i,heightMm:S,color:I8,groupId:x}),X=[A,W,B,R].map(Y=>IY(Y,C)),ft=[N,...X],tt=Math.max(e.heightMm,i+a+c),G={id:x,entityIds:ft.map(Y=>Y.id),name:"כורסא",widthMm:o,depthMm:r,heightMm:tt,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:b,createdAt:Date.now()};return{entities:ft,group:G,hostId:f}}const SY="#E8DFD3",PY={widthMm:500,depthMm:500,heightMm:450};function AY(t={x:0,y:0},e=PY,s){const o=Math.max(300,Math.round(e.widthMm)),r=Math.max(300,Math.round(e.depthMm)),i=Math.max(200,Math.round(e.heightMm)),a=Me(),l=ee({origin:t,widthMm:o,depthMm:r,heightMm:i,color:SY,groupId:a}),c=[l],d={id:a,entityIds:c.map(u=>u.id),name:"פוף קוביה",widthMm:o,depthMm:r,heightMm:i,createdAt:Date.now()};return{entities:c,group:d,hostId:l.id}}const LY="#EDE7DC",WY="#D8CFBF",RY={diameterMm:1200,heightMm:720,topThicknessMm:30,topSegments:32,legSizeMm:80,legCenterOffsetMm:360,legTaperBottom:.55,roundLegs:!1};function OY(t={x:0,y:0},e=RY,s){const o=Math.max(700,Math.round(e.diameterMm)),r=o/2,i=Math.max(400,Math.round(e.heightMm)),a=Math.max(15,Math.round(e.topThicknessMm)),l=Math.max(16,Math.round(e.topSegments)),c=Math.max(40,Math.round(e.legSizeMm)),d=Math.max(60,Math.min(r-c,Math.round(e.legCenterOffsetMm))),u=Math.max(50,i-a),h=Math.round(t.x),x=Math.round(t.y),f=h+r,p=x+r,b=Me(),M=be("fps_circle"),g=Xl({x:f,y:p},r,l),w={...Ae(g,"circle",M),heightMm:a,baseHeightMm:u,color:LY,groupId:b},_=[{x:f+d,y:p+d},{x:f-d,y:p+d},{x:f+d,y:p-d},{x:f-d,y:p-d}].map(C=>Da({origin:{x:C.x-c/2,y:C.y-c/2},widthMm:c,depthMm:c,heightMm:u,color:WY,groupId:b,round:e.roundLegs,taperBottom:e.legTaperBottom})),j=[w,..._],v={id:b,entityIds:j.map(C=>C.id),name:"שולחן אוכל עגול",widthMm:o,depthMm:o,heightMm:i,createdAt:Date.now()};return{entities:j,group:v,hostId:w.id}}const HY="#E8DFD3",BY="#D8CFBF",VY="#E8DFD3",zY={seatWidthMm:450,seatDepthMm:450,seatThicknessMm:50,seatMountHeightMm:400,legSizeMm:40,legInsetMm:15,legTaperBottom:.55,backHeightMm:400,backDepthMm:40};function $Y(t={x:0,y:0},e=zY,s){const o=Math.max(350,Math.round(e.seatWidthMm)),r=Math.max(350,Math.round(e.seatDepthMm)),i=Math.max(20,Math.round(e.seatThicknessMm)),a=Math.max(200,Math.round(e.seatMountHeightMm)),l=Math.max(20,Math.round(e.legSizeMm)),c=Math.max(0,Math.round(e.legInsetMm)),d=Math.max(150,Math.round(e.backHeightMm)),u=Math.max(20,Math.round(e.backDepthMm)),h=Math.round(t.x),x=Math.round(t.y),f=Me(),p=ee({origin:{x:h,y:x},widthMm:o,depthMm:r,heightMm:i,baseHeightMm:a,color:HY,groupId:f}),M=[{x:h+c,y:x+c},{x:h+o-c-l,y:x+c},{x:h+c,y:x+r-c-l},{x:h+o-c-l,y:x+r-c-l}].map(_=>Da({origin:_,widthMm:l,depthMm:l,heightMm:a,color:BY,groupId:f,taperBottom:e.legTaperBottom})),g=ee({origin:{x:h,y:x+r-u},widthMm:o,depthMm:u,heightMm:d,baseHeightMm:a+i,color:VY,groupId:f}),w=[p,...M,g],k={id:f,entityIds:w.map(_=>_.id),name:"כיסא אוכל",widthMm:o,depthMm:r,heightMm:a+i+d,createdAt:Date.now()};return{entities:w,group:k,hostId:p.id}}const XY="#EDE7DC",T8="#D8CFBF",YY={widthMm:700,depthMm:600,thicknessMm:40,mountHeightMm:900,bracketWidthMm:100,bracketThicknessMm:40,bracketDropMm:40};function GY(t,e){return{...t,vertices:t.vertices.map(e)}}function UY(t={x:0,y:0},e=YY,s){const o=Math.max(500,Math.round(e.widthMm)),r=Math.max(400,Math.round(e.depthMm)),i=Math.max(20,Math.round(e.thicknessMm)),a=Math.max(700,Math.round(e.mountHeightMm)),l=Math.max(60,Math.min(o/2-20,Math.round(e.bracketWidthMm))),c=Math.max(20,Math.round(e.bracketThicknessMm));Math.max(20,Math.round(e.bracketDropMm));const d=Me(),u=be("fps_rect");let h,x;if(s){const A=Wn({widthMm:o,depthMm:r},s);h=A.vertices,x=A.positionAlongWallMm}else{const A=Math.round(t.x),W=Math.round(t.y);h=_e(A,W,A+o,W+r)}const f=h[0],p=h[1],b=h[3],M=(p.x-f.x)/o,g=(p.y-f.y)/o,w=(b.x-f.x)/r,k=(b.y-f.y)/r,_=A=>({x:Math.round(f.x+M*A.x+w*A.y),y:Math.round(f.y+g*A.x+k*A.y)}),j={...Ae(h,"rectangle",u),heightMm:i,baseHeightMm:a,color:XY,groupId:d},v=Math.max(0,a-c),N=[ee({origin:{x:0,y:0},widthMm:l,depthMm:r,heightMm:c,baseHeightMm:v,color:T8,groupId:d}),ee({origin:{x:o-l,y:0},widthMm:l,depthMm:r,heightMm:c,baseHeightMm:v,color:T8,groupId:d})].map(A=>GY(A,_)),P=[j,...N],L={id:d,entityIds:P.map(A=>A.id),name:"משטח מעל מכונת כביסה",widthMm:o,depthMm:r,heightMm:a+i,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:x,createdAt:Date.now()};return{entities:P,group:L,hostId:u}}const KY="#F7F4EF",ZY="#E8DFD3",qY="#D8CFBF",JY={widthMm:900,depthMm:650,heightMm:2e3,doorCount:2,frameMm:30,doorGapMm:6,doorProtrusionMm:18,louverHeightMm:24,louverPitchMm:60,louverDepthMm:5};function QY(t={x:0,y:0},e=JY,s){const o=Math.max(400,Math.round(e.widthMm)),r=Math.max(300,Math.round(e.depthMm)),i=Math.max(800,Math.round(e.heightMm)),a=Math.max(1,Math.round(e.doorCount)),l=Math.max(0,Math.round(e.frameMm)),c=Math.max(0,Math.round(e.doorGapMm)),d=Math.max(2,Math.round(e.doorProtrusionMm)),u=Math.max(20,Math.round(e.louverHeightMm)),h=Math.max(u+8,Math.round(e.louverPitchMm)),x=Math.max(1,Math.round(e.louverDepthMm)),f=Me(),p=be("fps_rect");let b,M;if(s){const P=Wn({widthMm:o,depthMm:r},s);b=P.vertices,M=P.positionAlongWallMm}else{const P=Math.round(t.x),L=Math.round(t.y);b=_e(P,L,P+o,L+r)}const g={...Ae(b,"rectangle",p),heightMm:i,color:KY,groupId:f},w=[],k=(P,L,A,W,S,B)=>{const R=[{x:Math.round(P),y:Math.round(L)},{x:Math.round(A),y:Math.round(L)},{x:Math.round(A),y:Math.round(W)},{x:Math.round(P),y:Math.round(W)}],z=lo(p,"side-0",R,f);z&&w.push({...z,depthMm:S,color:B})},_=o/a,j=l,v=i-l;for(let P=0;P<a;P+=1){const L=P*_,A=L+_,W=P===0?L:L+c/2,S=P===a-1?A:A-c/2;k(W,j,S,v,d,ZY);const B=W+30,R=S-30;if(R-B>
278=20){let z=j+h;for(;z+u<=v-10;)k(B,z,R,z+u,-x,qY),z+=h}}const C=[g,...w],N={id:f,entityIds:C.map(P=>P.id),name:"מסתור כביסה",widthMm:o,depthMm:r,heightMm:i,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:M,createdAt:Date.now()};return{entities:C,group:N,hostId:p}}const Cp="#3A352F",t7="#DCE8EC",tG=1100,Ob={widthMm:2e3,depthMm:60,heightMm:1050,postSizeMm:40,handrailThicknessMm:45};function e7(t,e){return{...t,vertices:t.vertices.map(e)}}function ek(t,e,s){const o=Math.max(400,Math.round(e.widthMm)),r=Math.max(40,Math.round(e.depthMm)),i=Math.max(700,Math.round(e.heightMm)),a=Math.max(16,Math.min(r,Math.round(e.postSizeMm))),l=Math.max(20,Math.round(e.handrailThicknessMm)),c=Me(),d=be("fps_rect");let u,h;if(s){const L=Wn({widthMm:o,depthMm:r},s);u=L.vertices,h=L.positionAlongWallMm}else{const L=Math.round(t.x),A=Math.round(t.y);u=_e(L,A,L+o,A+r)}const x=u[0],f=u[1],p=u[3],b=(f.x-x.x)/o,M=(f.y-x.y)/o,g=(p.x-x.x)/r,w=(p.y-x.y)/r,k=L=>({x:Math.round(x.x+b*L.x+g*L.y),y:Math.round(x.y+M*L.x+w*L.y)}),_={...Ae(u,"rectangle",d),heightMm:l,baseHeightMm:i-l,color:Cp,groupId:c},j=i-l,v=o-a,C=Math.max(1,Math.ceil(v/tG)),N=C+1,P=[];for(let L=0;L<N;L+=1){const A=v*L/C+a/2;P.push(ee({origin:{x:Math.round(A-a/2),y:Math.round((r-a)/2)},widthMm:a,depthMm:a,heightMm:j,color:Cp,groupId:c}))}return{groupId:c,hostId:d,host:_,toWorld:k,postsLocal:P,W:o,D:r,H:i,postTop:j,postSize:a,wallPositionMm:h}}function nk(t,e,s,o){const r=[...t.postsLocal,...e].map(l=>e7(l,t.toWorld)),i=[t.host,...r],a={id:t.groupId,entityIds:i.map(l=>l.id),name:s,widthMm:t.W,depthMm:t.D,heightMm:t.H,rigid:!0,wallId:o==null?void 0:o.wallId,wallSide:o==null?void 0:o.side,wallPositionMm:t.wallPositionMm,createdAt:Date.now()};return{entities:i,group:a,hostId:t.hostId}}const n7={...Ob,glassThicknessMm:12,glassBaseGapMm:60};function o7(t={x:0,y:0},e=n7,s){const o=ek(t,e,s),r=Math.max(6,Math.round(e.glassThicknessMm)),i=Math.max(0,Math.round(e.glassBaseGapMm)),a=o.postSize,l=o.W-o.postSize,c=ee({origin:{x:a,y:Math.round((o.D-r)/2)},widthMm:Math.max(20,l-a),depthMm:r,heightMm:Math.max(50,o.postTop-i),baseHeightMm:i,color:t7,groupId:o.groupId});return nk(o,[c],"מעקה זכוכית",s)}const s7={...Ob,barCount:4,barSizeMm:20,bottomGapMm:120};function r7(t={x:0,y:0},e=s7,s){const o=ek(t,e,s),r=Math.max(1,Math.round(e.barCount)),i=Math.max(8,Math.round(e.barSizeMm)),a=Math.max(0,Math.round(e.bottomGapMm)),l=o.postSize,c=Math.max(20,o.W-2*o.postSize),d=Math.round((o.D-i)/2),u=o.postTop-i,h=[];for(let x=0;x<r;x+=1){const f=r===1?0:x/(r-1),p=Math.round(u-f*(u-a));h.push(ee({origin:{x:l,y:d},widthMm:c,depthMm:i,heightMm:i,baseHeightMm:Math.max(0,p),color:Cp,groupId:o.groupId}))}return nk(o,h,"מעקה פסים",s)}const i7={...Ob,balusterSizeMm:16,balusterSpacingMm:110,bottomGapMm:0};function a7(t={x:0,y:0},e=i7,s){const o=ek(t,e,s),r=Math.max(8,Math.round(e.balusterSizeMm)),i=Math.max(r+20,Math.round(e.balusterSpacingMm)),a=Math.max(0,Math.round(e.bottomGapMm)),l=o.postSize,c=o.W-o.postSize,d=Math.max(0,c-l),u=Math.round((o.D-r)/2),h=Math.max(50,o.postTop-a),x=[];if(d>=r+20){const f=Math.max(1,Math.ceil((d-r)/i)),p=f-1;for(let b=1;b<=p;b+=1){const M=l+d*b/f;x.push(ee({origin:{x:Math.round(M-r/2),y:u},widthMm:r,depthMm:r,heightMm:h,baseHeightMm:a,color:Cp,groupId:o.groupId}))}}return nk(o,x,"מעקה סורגים",s)}const l7={...Ob,widthMm:1e3,heightMm:1100,glassThicknessMm:15,channelHeightMm:120,glassEmbedMm:80};function c7(t={x:0,y:0},e=l7,s){const o=Math.max(400,Math.round(e.widthMm)),r=Math.max(40,Math.round(e.depthMm)),i=Math.max(700,Math.round(e.heightMm)),a=Math.max(6,Math.min(r,Math.round(e.glassThicknessMm))),l=Math.max(40,Math.min(i-100,Math.round(e.channelHeightMm))),c=Math.max(0,Math.min(l,Math.round(e.glassEmbedMm))),d=Me(),u=be("fps_rect");let h,x;if(s){const A=Wn({widthMm:o,depthMm:r},s);h=A.vertices,x=A.positionAlongWallMm}else{const A=Math.round(t.x),W=Math.round(t.y);h=_e(A,W,A+o,W+r)}const f=h[0],p=h[1],b=h[3],M=(p.x-f.x)/o,g=(p.y-f.y)/o,w=(b.x-f.x)/r,k=(b.y-f.y)/r,_=A=>({x:Math.round(f.x+M*A.x+w*A.y),y:Math.round(f.y+g*A.x+k*A.y)}),j={...Ae(h,"rectangle",u),heightMm:l,color:Cp,groupId:d},v=Math.max(0,l-c),C=ee({origin:{x:0,y:Math.round((r-a)/2)},widthMm:o,depthMm:a,heightMm:Math.max(50,i-v),baseHeightMm:v,color:t7,groupId:d}),N=e7(C,_),P=[j,N],L={id:d,entityIds:P.map(A=>A.id),name:"מעקה זכוכית ללא מסגרת",widthMm:o,depthMm:r,heightMm:i,rigid:!0,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:x,createdAt:Date.now()};return{entities:P,group:L,hostId:u}}
278const eG="#E8DFD3",nG="#3A352F",oG="#3A352F",sG="#E8DFD3",rG={seatRadiusMm:250,seatThicknessMm:50,seatMountHeightMm:450,columnSizeMm:60,columnHeightMm:400,prongLengthMm:250,prongWidthMm:60,prongThicknessMm:50,backWidthMm:450,backDepthMm:30,backHeightMm:600,seatSegments:24};function iG(t,e,s,o,r){const i=Math.cos(r),a=Math.sin(r),l=o/2;return[{x:0,y:-l},{x:s,y:-l},{x:s,y:l},{x:0,y:l}].map(d=>({x:Math.round(t+d.x*i-d.y*a),y:Math.round(e+d.x*a+d.y*i)}))}function aG(t={x:0,y:0},e=rG,s){const o=Math.max(180,Math.round(e.seatRadiusMm)),r=Math.max(20,Math.round(e.seatThicknessMm)),i=Math.max(300,Math.round(e.seatMountHeightMm)),a=Math.max(40,Math.round(e.columnSizeMm)),l=Math.max(200,Math.round(e.columnHeightMm)),c=Math.max(150,Math.round(e.prongLengthMm)),d=Math.max(30,Math.round(e.prongWidthMm)),u=Math.max(20,Math.round(e.prongThicknessMm)),h=Math.max(250,Math.round(e.backWidthMm)),x=Math.max(15,Math.round(e.backDepthMm)),f=Math.max(200,Math.round(e.backHeightMm)),p=Math.max(12,Math.round(e.seatSegments)),b=Math.round(t.x),M=Math.round(t.y),g=o*2,w=b+o,k=M+o,_=Me(),j=be("fps_circle"),v=Xl({x:w,y:k},o,p),C={...Ae(v,"circle",j),heightMm:r,baseHeightMm:i,color:eG,groupId:_},N=ee({origin:{x:w-a/2,y:k-a/2},widthMm:a,depthMm:a,heightMm:l,baseHeightMm:u,color:nG,groupId:_}),P=[];for(let S=0;S<5;S+=1){const B=Math.PI*2*S/5,R=iG(w,k,c,d,B),z=be("fps_rect");P.push({...Ae(R,"rectangle",z),heightMm:u,color:oG,groupId:_})}const L=ee({origin:{x:w-h/2,y:M+g-x},widthMm:h,depthMm:x,heightMm:f,baseHeightMm:i+r,color:sG,groupId:_}),A=[C,N,...P,L],W={id:_,entityIds:A.map(S=>S.id),name:"כיסא ארגונומי",widthMm:g,depthMm:g,heightMm:i+r+f,createdAt:Date.now()};return{entities:A,group:W,hostId:C.id}}const lG="#F7F4EF",cG="#F7F4EF",dG="#E8DFD3",uG="#C9C9C9",hG={cisternWidthMm:500,cisternDepthMm:130,cisternHeightMm:1e3,cisternBaseHeightMm:200,bowlWidthMm:360,bowlDepthMm:540,bowlHeightMm:320,bowlBaseHeightMm:400,seatThicknessMm:30,buttonWidthMm:80,buttonHeightMm:60,buttonDepthMm:5};function mG(t,e){return{...t,vertices:t.vertices.map(e)}}function fG(t={x:0,y:0},e=hG,s){const o=Math.max(350,Math.round(e.cisternWidthMm)),r=Math.max(80,Math.round(e.cisternDepthMm)),i=Math.max(600,Math.round(e.cisternHeightMm)),a=Math.max(0,Math.round(e.cisternBaseHeightMm)),l=Math.max(250,Math.min(o,Math.round(e.bowlWidthMm))),c=Math.max(350,Math.round(e.bowlDepthMm)),d=Math.max(200,Math.round(e.bowlHeightMm)),u=Math.max(300,Math.round(e.bowlBaseHeightMm)),h=Math.max(15,Math.round(e.seatThicknessMm)),x=Math.max(40,Math.round(e.buttonWidthMm)),f=Math.max(30,Math.round(e.buttonHeightMm)),p=Math.max(2,Math.round(e.buttonDepthMm)),b=Me(),M=be("fps_rect");let g,w;if(s){const Y=Wn({widthMm:o,depthMm:r},s);g=Y.vertices,w=Y.positionAlongWallMm}else{const Y=Math.round(t.x),J=Math.round(t.y);g=_e(Y,J,Y+o,J+r)}const k=g[0],_=g[1],j=g[3],v=(_.x-k.x)/o,C=(_.y-k.y)/o,N=(j.x-k.x)/r,P=(j.y-k.y)/r,L=Y=>({x:Math.round(k.x+v*Y.x+N*Y.y),y:Math.round(k.y+C*Y.x+P*Y.y)}),A={...Ae(g,"rectangle",M),heightMm:i,baseHeightMm:a,color:lG,groupId:b},W=(o-l)/2,S=ee({origin:{x:W,y:-c},widthMm:l,depthMm:c,heightMm:d,baseHeightMm:u,color:cG,groupId:b}),B=ee({origin:{x:W,y:-c},widthMm:l,depthMm:c,heightMm:h,baseHeightMm:u+d,color:dG,groupId:b}),R=[S,B].map(Y=>mG(Y,L)),z=(o-x)/2,X=80;let ft=lo(M,"side-0",[{x:Math.round(z),y:X},{x:Math.round(z+x),y:X},{x:Math.round(z+x),y:X+f},{x:Math.round(z),y:X+f}],b);ft&&(ft={...ft,depthMm:p,color:uG});const tt=[A,...R,...ft?[ft]:[]],G={id:b,entityIds:tt.map(Y=>Y.id),name:"אסלה תלויה",widthMm:o,depthMm:r+c,heightMm:a+i,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:w,createdAt:Date.now()};return{entities:tt,group:G,hostId:M}}const xG="#E8DFD3",pG="#D8CFBF",gG={widthMm:2e3,thicknessMm:50,heightMm:2550,baseHeightMm:50,pleatCount:14,pleatWidthMm:30,pleatDepthMm:4};function bG(t={x:0,y:0},e=gG,s){const o=Math.max(600,Math.round(e.widthMm)),r=Math.max(20,Math.round(e.thicknessMm)),i=Math.max(1e3,Math.round(e.heightMm)),a=Math.max(0,Math.round(e.baseHeightMm)),l=Math.max(4,Math.min(40,Math.round(e.pleatCount))),c=Math.max(22,Math.round(e.pleatWidthMm)),d=Math.max(1,Math.round(e.pleatDepthMm)),u=Me(),h=be("fps_rect");let x,f;if(s){const w=Wn({widthMm:o,depthMm:r},s);x=w.vertices,f=w.positionAlongWallMm}else{const w=Math.round(t.x),k=Math.round(t.y);x=_e(w,k,w+o,k+r)}const p={...Ae(x,"rectangle",h),heightMm:i,baseHeightMm:a,color:xG,groupId:u},b=f9({hostId:h,faceId:"side-0",x0:0,x1:o,y0:0,y1:i,count:l,grooveWidthMm:c,depthMm:d,color:pG,groupId:u}),M=[p,...b],g={id:u,entityIds:M.map(w=>w.id),name:"וילון",widthMm:o,depthMm:r,heightMm:a+i,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:f,createdAt:Date.now()};return{entities:M,group:g,hostId:h}}const MG=2700,yG="#2A2A2A",wG="#FDF6E3",d7={housingDiameterMm:110,housingThicknessMm:30,lensDiameterMm:80,lensThicknessMm:8,segments:24};function u7(t={x:0,y:0},e=d7,s,o){const r=Math.max(40,Math.round(e.housingDiameterMm/2)),i=Math.max(10,Math.round(e.housingThicknessMm)),a=Math.max(20,Math.min(r-8,Math.round(e.lensDiameterMm/2))),l=Math.max(3,Math.round(e.lensThicknessMm)),c=Math.max(12,Math.round(e.segments)),d=Math.max(1e3,Math.round((o==null?void 0:o.ceilingHeightMm)??MG)),u=Math.round(t.x),h=Math.round(t.y),x=u+r,f=h+r,p=Me(),b=be("fps_circle"),M={...Ae(Xl({x,y:f},r,c),"circle",b),heightMm:i,baseHeightMm:d-i,color:yG,groupId:p},g=be("fps_circle"),w={...Ae(Xl({x,y:f},a,c),"circle",g),heightMm:l,baseHeightMm:d-i-l,color:wG,groupId:p},k=[M,w],_={id:p,entityIds:k.map(j=>j.id),name:"ספוט שקוע",widthMm:r*2,depthMm:r*2,heightMm:d,rigid:!0,createdAt:Date.now()};return{entities:k,group:_,hostId:M.id}}const kG=2700,vG="#2A2A2A",jG="#1A1A1A",_G="#FDF6E3",h7={lengthMm:1500,railWi
278dthMm:50,railDepthMm:60,spotCount:3,headDiameterMm:40,headDropMm:80,ledThicknessMm:12,ledWidthMm:30,endMarginMm:120};function m7(t={x:0,y:0},e=h7,s,o){const r=Math.max(400,Math.round(e.lengthMm)),i=Math.max(20,Math.round(e.railWidthMm)),a=Math.max(20,Math.round(e.railDepthMm)),l=Math.max(2,Math.min(12,Math.round(e.spotCount))),c=Math.max(12,Math.round(e.headDiameterMm/2)),d=Math.max(20,Math.round(e.headDropMm)),u=Math.max(4,Math.round(e.ledThicknessMm)),h=Math.max(10,Math.min(i,Math.round(e.ledWidthMm))),x=Math.max(0,Math.min(Math.round(e.endMarginMm),Math.floor(r/2)-1)),f=Math.max(1e3,Math.round((o==null?void 0:o.ceilingHeightMm)??kG)),p=Math.round(t.x),b=Math.round(t.y),M=f-a,g=b+i/2,w=Me(),k=be("fps_rect"),_={...Ae(_e(p,b,p+r,b+i),"rectangle",k),heightMm:a,baseHeightMm:M,color:vG,groupId:w},j=l>1?(r-2*x)/(l-1):0,v=[],C=[];for(let A=0;A<l;A+=1){const W=p+x+A*j;v.push(W);const S=be("fps_circle");C.push({...Ae(Xl({x:W,y:g},c,16),"circle",S),heightMm:d,baseHeightMm:M-d,color:jG,groupId:w})}const N=[];for(let A=0;A<v.length-1;A+=1){const W=(v[A]+v[A+1])/2,S=Math.max(40,Math.round(j*.5));N.push(ee({origin:{x:Math.round(W-S/2),y:Math.round(g-h/2)},widthMm:S,depthMm:h,heightMm:u,baseHeightMm:M-u,color:_G,groupId:w}))}const P=[_,...C,...N],L={id:w,entityIds:P.map(A=>A.id),name:"פנל תאורה",widthMm:r,depthMm:i,heightMm:f,rigid:!0,createdAt:Date.now()};return{entities:P,group:L,hostId:k}}const EG="#2A2A2A",DG="#FDF6E3",f7={widthMm:120,depthMm:100,heightMm:250,mountHeightMm:1900,lensDepthMm:5,lensInsetMm:25};function x7(t={x:0,y:0},e=f7,s,o){const r=Math.max(60,Math.round(e.widthMm)),i=Math.max(40,Math.round(e.depthMm)),a=Math.max(80,Math.round(e.heightMm)),l=Math.max(0,Math.round(e.mountHeightMm)),c=Math.max(1,Math.round(e.lensDepthMm)),d=Math.max(10,Math.min(Math.round(e.lensInsetMm),Math.floor(Math.min(r,a)/2)-10)),u=Me(),h=be("fps_rect");let x,f;if(s){const w=Wn({widthMm:r,depthMm:i},s);x=w.vertices,f=w.positionAlongWallMm}else{const w=Math.round(t.x),k=Math.round(t.y);x=_e(w,k,w+r,k+i)}const p={...Ae(x,"rectangle",h),heightMm:a,baseHeightMm:l,color:EG,groupId:u};let b=lo(h,"side-0",[{x:d,y:d},{x:r-d,y:d},{x:r-d,y:a-d},{x:d,y:a-d}],u);b&&(b={...b,depthMm:c,color:DG});const M=[p,...b?[b]:[]],g={id:u,entityIds:M.map(w=>w.id),name:"מנורת קיר",widthMm:r,depthMm:i,heightMm:l+a,wallId:s==null?void 0:s.wallId,wallSide:s==null?void 0:s.side,wallPositionMm:f,rigid:!0,createdAt:Date.now()};return{entities:M,group:g,hostId:h}}const FG="#2A2A2A",CG="#3A352F",NG="#E8DFD3",p7={baseDiameterMm:300,baseThicknessMm:20,poleDiameterMm:50,poleHeightMm:1380,shadeDiameterMm:400,shadeHeightMm:320,shadeTaperTop:.55};function g7(t={x:0,y:0},e=p7,s,o){const r=Math.max(80,Math.round(e.baseDiameterMm/2)),i=Math.max(8,Math.round(e.baseThicknessMm)),a=Math.max(15,Math.round(e.poleDiameterMm/2)),l=Math.max(400,Math.round(e.poleHeightMm)),c=Math.max(r,Math.round(e.shadeDiameterMm/2)),d=Math.max(120,Math.round(e.shadeHeightMm)),u=Math.max(.2,Math.min(1,e.shadeTaperTop)),h=Math.round(t.x),x=Math.round(t.y),f=h+c,p=x+c,b=Me(),M=Ep({center:{x:f,y:p},radiusMm:r,heightMm:i,color:FG,groupId:b}),g=Ep({center:{x:f,y:p},radiusMm:a,baseHeightMm:i,heightMm:l,color:CG,groupId:b}),w=i+l-Math.round(d*.12),k=Da({origin:{x:f-c,y:p-c},widthMm:c*2,depthMm:c*2,baseHeightMm:w,heightMm:d,color:NG,groupId:b,round:!0,segments:24,taperTop:u}),_=[M,g,k],j={id:b,entityIds:_.map(v=>v.id),name:"מנורה עומדת",widthMm:c*2,depthMm:c*2,heightMm:w+d,rigid:!0,createdAt:Date.now()};return{entities:_,group:j,hostId:M.id}}const ca=175,Vs=275,Bs=1e3,U2=60,km="#E4DFD6",IG="#D8CFBF",S8="#3A352F";function Xd(t){const{groupId:e,ox:s,oy:o,n:r,width:i,startTopMm:a,signY:l,color:c=km}=t,d=[];for(let u=0;u<r;u+=1){const h=l>0?o+u*Vs:o-(u+1)*Vs;d.push(ee({origin:{x:s,y:h},widthMm:i,depthMm:Vs,heightMm:a+(u+1)*ca,color:c,groupId:e}))}return d}function TG(t){const{groupId:e,ox:s,oy:o,n:r,depth:i,startTopMm:a,color:l=km}=t,c=[];for(let d=0;d<r;d+=1){const u=s+d*Vs;c.push(ee({origin:{x:u,y:o},widthMm:Vs,depthMm:i,heightMm:a+(d+1)*ca,color:l,groupId:e}))}return c}function P8(t){const{groupId:e,sideX:s,oy:o,n:r}=t,i=50,a=900,l=40,c=[];for(let d=0;d<r;d+=1){const u=(d+1)*ca;(d%3===0||d===r-1)&&c.push(ee({origin:{x:s,y:o+d*Vs+(Vs-i)/2}
278,widthMm:i,depthMm:i,baseHeightMm:u,heightMm:a,color:S8,groupId:e})),c.push(ee({origin:{x:s,y:o+d*Vs},widthMm:l,depthMm:Vs,baseHeightMm:u+a,heightMm:l,color:S8,groupId:e}))}return c}function Ud(t){return{id:t.groupId,entityIds:t.entities.map(e=>e.id),name:t.name,widthMm:Math.round(t.widthMm),depthMm:Math.round(t.depthMm),heightMm:Math.round(t.heightMm),rigid:!0,createdAt:Date.now()}}function SG(t={x:0,y:0},e,s,o){const r=Math.round(t.x),i=Math.round(t.y),a=12,l=Me(),c=Xd({groupId:l,ox:r,oy:i,n:a,width:Bs,startTopMm:0,signY:1}),d=Ud({groupId:l,entities:c,name:"מדרגות ישרות",widthMm:Bs,depthMm:a*Vs,heightMm:a*ca});return{entities:c,group:d,hostId:c[0].id}}function PG(t={x:0,y:0},e,s,o){const r=Math.round(t.x),i=Math.round(t.y),a=2,l=1200,c=Me(),d=Xd({groupId:c,ox:r,oy:i,n:a,width:l,startTopMm:0,signY:1}),u=Ud({groupId:c,entities:d,name:"מדרגות מעבר",widthMm:l,depthMm:a*Vs,heightMm:a*ca});return{entities:d,group:u,hostId:d[0].id}}function AG(t={x:0,y:0},e,s,o){const r=Math.round(t.x),i=Math.round(t.y),a=4,l=1200,c=Me(),d=Xd({groupId:c,ox:r,oy:i,n:a,width:l,startTopMm:0,signY:1}),u=Ud({groupId:c,entities:d,name:"מדרגות כניסה",widthMm:l,depthMm:a*Vs,heightMm:a*ca});return{entities:d,group:u,hostId:d[0].id}}function LG(t={x:0,y:0},e,s,o){const r=Math.round(t.x),i=Math.round(t.y),a=12,l=Me(),c=Xd({groupId:l,ox:r,oy:i,n:a,width:Bs,startTopMm:0,signY:1}),d=P8({groupId:l,sideX:r,oy:i,n:a}),u=P8({groupId:l,sideX:r+Bs-50,oy:i,n:a}),h=[...c,...d,...u],x=Ud({groupId:l,entities:h,name:"מדרגות ישרות עם מעקה",widthMm:Bs,depthMm:a*Vs,heightMm:a*ca+900});return{entities:h,group:x,hostId:c[0].id}}function WG(t={x:0,y:0},e,s,o){const r=Math.round(t.x),i=Math.round(t.y),a=11,l=240,c=Me(),d=[],u=[];for(let f=0;f<a;f+=1){const p=(f+1)*ca;d.push(ee({origin:{x:r,y:i+f*Vs},widthMm:Bs,depthMm:Vs,baseHeightMm:p-U2,heightMm:U2,color:km,groupId:c})),u.push(ee({origin:{x:r+(Bs-l)/2,y:i+f*Vs},widthMm:l,depthMm:Vs,heightMm:p-U2,color:IG,groupId:c}))}const h=[...d,...u],x=Ud({groupId:c,entities:h,name:"מדרגות מרחפות",widthMm:Bs,depthMm:a*Vs,heightMm:a*ca});return{entities:h,group:x,hostId:d[0].id}}function RG(t={x:0,y:0},e,s,o){const r=Math.round(t.x),i=Math.round(t.y),a=5,l=2e3,c=200,d=150,u=Me(),h=[];for(let f=0;f<a;f+=1){const p=l-2*f*c;h.push(ee({origin:{x:r+f*c,y:i+f*c},widthMm:p,depthMm:p,baseHeightMm:f*d,heightMm:d,color:km,groupId:u}))}const x=Ud({groupId:u,entities:h,name:"מדרגות פודיום",widthMm:l,depthMm:l,heightMm:a*d});return{entities:h,group:x,hostId:h[0].id}}function OG(t={x:0,y:0},e,s,o){const r=Math.round(t.x),i=Math.round(t.y),a=6,l=100,c=a*ca,d=Me(),u=Xd({groupId:d,ox:r,oy:i,n:a,width:Bs,startTopMm:0,signY:1}),h=ee({origin:{x:r,y:i+a*Vs},widthMm:2*Bs+l,depthMm:Bs,heightMm:c,color:km,groupId:d}),x=Xd({groupId:d,ox:r+Bs+l,oy:i+a*Vs,n:a,width:Bs,startTopMm:c,signY:-1}),f=[...u,h,...x],p=Ud({groupId:d,entities:f,name:"מדרגות U",widthMm:2*Bs+l,depthMm:a*Vs+Bs,heightMm:2*a*ca});return{entities:f,group:p,hostId:u[0].id}}function HG(t={x:0,y:0},e,s,o){const r=Math.round(t.x),i=Math.round(t.y),a=6,l=a*ca,c=Me(),d=Xd({groupId:c,ox:r,oy:i,n:a,width:Bs,startTopMm:0,signY:1}),u=ee({origin:{x:r,y:i+a*Vs},widthMm:Bs,depthMm:Bs,heightMm:l,color:km,groupId:c}),h=TG({groupId:c,ox:r+Bs,oy:i+a*Vs,n:a,depth:Bs,startTopMm:l}),x=[...d,u,...h],f=Ud({groupId:c,entities:x,name:"מדרגות L",widthMm:Bs+a*Vs,depthMm:a*Vs+Bs,heightMm:2*a*ca});return{entities:x,group:f,hostId:d[0].id}}function BG(t={x:0,y:0},e,s,o){const r=Math.round(t.x),i=Math.round(t.y),a=4,l=3,c=4,d=Me(),u=Xd({groupId:d,ox:r,oy:i,n:a,width:Bs,startTopMm:0,signY:1}),h={x:r+Bs,y:i+a*Vs},x=80,f=Bs+50,p=[];for(let k=0;k<l;k+=1){const _=(90-k*60)*Math.PI/180,j=(90-(k+1)*60)*Math.PI/180,v=[{x:Math.round(h.x+x*Math.cos(_)),y:Math.round(h.y+x*Math.sin(_))},{x:Math.round(h.x+f*Math.cos(_)),y:Math.round(h.y+f*Math.sin(_))},{x:Math.round(h.x+f*Math.cos(j)),y:Math.round(h.y+f*Math.sin(j))},{x:Math.round(h.x+x*Math.cos(j)),y:Math.round(h.y+x*Math.sin(j))}];p.push({...Ae(v,"polygon"),heightMm:(a+k+1)*ca,color:km,groupId:d})}const b=(a+l)*ca,M=Xd({groupId:d,ox:r+Bs+50,oy:i+a*Vs,n:c,width:Bs,startTopMm:b,signY:-1}),g=[...u,...p,...M],w=Ud({groupId:d,entities:g,name:"מדרגות סיבוב",widthMm:2*Bs+50,depthMm:a*Vs+f,heightMm:(a+l+c)*ca});return{entities:g,group:w,hostId:u[0].id}}const VG=[{id:"kitchen",labelHe:"מטבח",columns:3},{id:"kitchenAssembly",labelHe:"הרכבת נגרות · מטבח",columns:3}
278,{id:"carpentryBedroom",labelHe:"הרכבת נגרות · חדר שינה",columns:2},{id:"carpentryUtility",labelHe:"הרכבת נגרות · חדר שירות",columns:2},{id:"living",labelHe:"סלון",columns:2},{id:"dining",labelHe:"פינת אוכל",columns:2},{id:"bedroomMaster",labelHe:"חדר שינה הורים",columns:2},{id:"bedroomKids",labelHe:"חדר ילדים",columns:2},{id:"bathroom",labelHe:"אמבטיה ושירותים",columns:2},{id:"entry",labelHe:"כניסה",columns:2},{id:"office",labelHe:"חדר עבודה",columns:2},{id:"utility",labelHe:"חדר שירות",columns:2},{id:"lighting",labelHe:"תאורה כללית",columns:2},{id:"railings",labelHe:"מעקות",columns:2},{id:"stairs",labelHe:"מדרגות",columns:2},{id:"accessories",labelHe:"צמחייה ואקססוריז",columns:2}],ok=[...l9.map(t=>({id:t.id,category:"kitchenAssembly",nameHe:t.spec.labelHe,build:(e,s)=>h9(t.spec,e,s)})),{id:"kitchenAssembly.sink",category:"kitchenAssembly",nameHe:"ארון כיור + ברז",build:(t,e)=>Wj(t,void 0,e)},{id:"kitchenAssembly.sinkLarge",category:"kitchenAssembly",nameHe:"ארון כיור גדול + ברז",build:(t,e)=>Wj(t,{...LF,widthMm:1200},e)},{id:"kitchenAssembly.roundedTall",category:"kitchenAssembly",nameHe:"גבוה — קצה עגול",build:(t,e)=>oV(t,void 0,e)},{id:"kitchenAssembly.roundedBase",category:"kitchenAssembly",nameHe:"נמוך — קצה עגול",build:(t,e)=>sV(t,void 0,e)},{id:"kitchenAssembly.roundedDisplay",category:"kitchenAssembly",nameHe:"קצה עגול + נישה",build:(t,e)=>rV(t,void 0,e)},{id:"kitchenAssembly.roundedOpenShelves",category:"kitchenAssembly",nameHe:"קצה עגול + מדפים פתוחים",build:(t,e)=>iV(t,void 0,e)},{id:"kitchenAssembly.worktop",category:"kitchenAssembly",nameHe:"משטח עבודה (שיש)",build:(t,e,s)=>cV(t,void 0,e,s==null?void 0:s.worktopRunBoundsMm)},{id:"kitchenAssembly.cornerL",category:"kitchenAssembly",nameHe:"ארון פינה L",build:(t,e)=>uV(t,void 0,e)},{id:"kitchenAssembly.cornerLTall",category:"kitchenAssembly",nameHe:"ארון פינה L גבוה",build:(t,e)=>hV(t,void 0,e)},{id:"kitchenAssembly.carousel",category:"kitchenAssembly",nameHe:"פינת קרוסלה",build:(t,e)=>mV(t,void 0,e)},{id:"kitchenAssembly.cooktop",category:"kitchenAssembly",nameHe:"כיריים (ארון מגירות)",build:(t,e)=>gV(t,void 0,e)},{id:"kitchenAssembly.applianceTower",category:"kitchenAssembly",nameHe:"מגדל תנור + מיקרו",build:(t,e)=>bV(t,void 0,e)},{id:"kitchenAssembly.ovenColumn",category:"kitchenAssembly",nameHe:"עמודת תנור",build:(t,e)=>MV(t,void 0,e)},{id:"kitchenAssembly.dishwasher",category:"kitchenAssembly",nameHe:"מדיח כלים",build:(t,e)=>yV(t,void 0,e)},{id:"kitchenAssembly.tambour",category:"kitchenAssembly",nameHe:"ארון תריס",build:(t,e)=>jV(t,void 0,e)},{id:"kitchen.fridgeTall",category:"kitchenAssembly",nameHe:"עמודת מקרר",build:(t,e)=>XV(t,void 0,e)},...AF.map(t=>({id:t.id,category:t.category,nameHe:t.spec.labelHe,build:(e,s)=>U9(e,t.spec,s)})),{id:"kitchen.sketchWall",category:"kitchen",nameHe:"מטבח מהסקיצה",build:(t,e)=>sz(t,void 0,e)},{id:"kitchen.islandBar",category:"kitchen",nameHe:"אי מטבח עם בר",build:(t,e)=>NV(t,void 0,e)},{id:"kitchen.islandCooktop",category:"kitchen",nameHe:"אי מטבח עם כיריים",build:(t,e)=>OV(t,void 0,e)},{id:"kitchen.islandCooktopSink",category:"kitchen",nameHe:"אי מטבח עם כיריים וכיור",build:(t,e)=>HV(t,void 0,e)},{id:"kitchen.fullLinear",category:"kitchen",nameHe:"מטבח קיר לינארי",build:(t,e)=>uz(t,void 0,e)},{id:"kitchen.fullSymmetric",category:"kitchen",nameHe:"מטבח קיר סימטרי",build:(t,e)=>hz(t,void 0,e)},{id:"kitchen.fullCompact",category:"kitchen",nameHe:"מטבח קיר קומפקטי",build:(t,e)=>mz(t,void 0,e)},{id:"kitchen.fullSink",category:"kitchen",nameHe:"מטבח קיר עם כיור וכיריים",build:(t,e)=>yz(t,void 0,e)},{id:"living.wallUnit",category:"living",nameHe:"יחידת קיר סלון",build:(t,e)=>v9(t,void 0,e)},{id:"living.shelvingPoles",category:"living",nameHe:"ארון מדפים על עמודים",build:(t,e)=>Pz(t,void 0,e)},{id:"living.sofa3",category:"living",nameHe:"ספה תלת-מושבית",build:(t,e)=>Qz(t,void 0,e)},{id:"living.chaise",category:"living",nameHe:"שזלונג",build:(t,e)=>i$(t,void 0,e)},{id:"living.tvFloating",category:"living",nameHe:"מזנון טלוויזיה תלוי",build:(t,e)=>u$(t,void 0,e)},{id:"living.tvScreen",category:"living",nameHe:"טלוויזיה",build:(t,e)=>f$(t)},{id:"living.coffeeTable",category:"living",nameHe:"שולחן קפה",build:(t,e)=>M$(t,void 0)},{id:"living.rug",category:"living",nameHe:"שטיח",build:(t,e)=>k$(t,void 0)},{id:"wardrobe.standard",category:"bedroomKids",nameHe:"ארון בגדים",build:(t,e)=>N9(t,void 0,e)},{id:"wardrobe.wall",category:"living",nameHe:"ארון קיר + ויטרינה",build:(t,e)=>O9(t,void 0,e)},{id:"table.dining",category:"dining",nameHe:"שולחן (רגליים מחודדות)",build:(t,e)=>Rz(t,void 0)},{id:"credenza.fluted",category:"dining",nameHe:"קרדנזה פלוטד (רגליים מחודדות)",build:(t,e)=>Gz(t,void 0,e)}
278,{id:"bedroomMaster.bedUpholstered",category:"bedroomMaster",nameHe:"מיטה זוגית עם ראש מרופד",build:(t,e)=>F$(t,void 0,e)},{id:"bedroomMaster.nightstand",category:"bedroomMaster",nameHe:"שידת לילה",build:(t,e)=>S$(t,void 0,e)},{id:"bedroomMaster.slidingWardrobe",category:"bedroomMaster",nameHe:"ארון הזזה",build:(t,e)=>R$(t,void 0,e)},{id:"bedroomMaster.dresser",category:"bedroomMaster",nameHe:"שידת מגירות",build:(t,e)=>z$(t,void 0,e)},{id:"bedroomMaster.vanity",category:"bedroomMaster",nameHe:"שידת איפור עם מראה",build:(t,e)=>Z$(t,void 0,e)},{id:"bedroomMaster.endBench",category:"bedroomMaster",nameHe:"ספסל קצה מיטה",build:(t,e)=>tX(t,void 0)},{id:"bedroomKids.singleBed",category:"bedroomKids",nameHe:"מיטת יחיד",build:(t,e)=>iX(t,void 0,e)},{id:"bedroomKids.bunkBed",category:"bedroomKids",nameHe:"מיטת קומותיים",build:(t,e)=>cX(t,void 0,e)},{id:"bedroomKids.desk",category:"bedroomKids",nameHe:"שולחן כתיבה",build:(t,e)=>mX(t,void 0)},{id:"bedroomKids.shelf",category:"bedroomKids",nameHe:"מדף תלוי",build:(t,e)=>pX(t,void 0,e)},{id:"bathroom.vanity",category:"bathroom",nameHe:"ארון אמבט עם כיור",build:(t,e)=>vX(t,void 0,e)},{id:"bathroom.mirror",category:"bathroom",nameHe:"מראה עם תאורה",build:(t,e)=>AX(t,void 0,e)},{id:"bathroom.shower",category:"bathroom",nameHe:"מקלחון",build:(t,e)=>RX(t,void 0,e)},{id:"bathroom.tub",category:"bathroom",nameHe:"אמבטיה",build:(t,e)=>VX(t,void 0,e)},{id:"bathroom.vanity60",category:"bathroom",nameHe:"ארון אמבט 60 ס״מ",build:(t,e)=>hf(t,{widthMm:600,faucet:"deck",interpotz:"none"},e)},{id:"bathroom.vanity80",category:"bathroom",nameHe:"ארון אמבט 80 ס״מ",build:(t,e)=>hf(t,{widthMm:800,faucet:"deck",interpotz:"none"},e)},{id:"bathroom.vanity100",category:"bathroom",nameHe:"ארון אמבט 100 ס״מ",build:(t,e)=>hf(t,{widthMm:1e3,faucet:"deck",interpotz:"none"},e)},{id:"bathroom.vanity120",category:"bathroom",nameHe:"ארון אמבט 120 ס״מ",build:(t,e)=>hf(t,{widthMm:1200,faucet:"deck",interpotz:"none"},e)},{id:"bathroom.vanity120Double",category:"bathroom",nameHe:"ארון אמבט 120 כיור כפול",build:(t,e)=>hf(t,{widthMm:1200,doubleBasin:!0,faucet:"deck",interpotz:"none"},e)},{id:"bathroom.vanityWallFaucet",category:"bathroom",nameHe:"ארון אמבט + ברז קיר",build:(t,e)=>hf(t,{widthMm:1e3,faucet:"wall",interpotz:"none"},e)},{id:"entry.unit",category:"entry",nameHe:"יחידת כניסה",build:(t,e)=>UX(t,void 0,e)},{id:"entry.fullMirror",category:"entry",nameHe:"מראת קומה",build:(t,e)=>qX(t,void 0,e)},{id:"entry.console",category:"entry",nameHe:"קונסולה נמוכה",build:(t,e)=>eY(t,void 0)},{id:"office.desk",category:"office",nameHe:"שולחן עבודה",build:(t,e)=>rY(t,void 0)},{id:"office.bookcase",category:"office",nameHe:"ספריית מדפים",build:(t,e)=>dY(t,void 0,e)},{id:"office.pedestal",category:"office",nameHe:"ארונית על גלגלים",build:(t,e)=>pY(t,void 0)},{id:"living.sofa2",category:"living",nameHe:"ספה דו-מושבית",build:(t,e)=>kY(t,void 0,e)},{id:"living.cornerModule",category:"living",nameHe:"מודול פינתי",build:(t,e)=>EY(t,void 0)},{id:"living.armchair",category:"living",nameHe:"כורסא",build:(t,e)=>TY(t,void 0,e)},{id:"living.pouf",category:"living",nameHe:"פוף קוביה",build:(t,e)=>AY(t,void 0)},{id:"dining.round",category:"dining",nameHe:"שולחן אוכל עגול",build:(t,e)=>OY(t,void 0)},{id:"dining.chair",category:"dining",nameHe:"כיסא אוכל",build:(t,e)=>$Y(t,void 0)},{id:"utility.laundryTop",category:"utility",nameHe:"משטח מעל מכונת כביסה",build:(t,e)=>UY(t,void 0,e)},{id:"utility.laundryScreen",category:"utility",nameHe:"מסתור כביסה",build:(t,e)=>QY(t,void 0,e)},{id:"office.ergoChair",category:"office",nameHe:"כיסא ארגונומי",build:(t,e)=>aG(t,void 0)},{id:"bathroom.wcWall",category:"bathroom",nameHe:"אסלה תלויה",build:(t,e)=>fG(t,void 0,e)},{id:"living.curtain",category:"living",nameHe:"וילון",build:(t,e)=>bG(t,void 0,e)},{id:"living.glassRailing",category:"railings",nameHe:"מעקה זכוכית",build:(t,e)=>o7(t,void 0,e)},{id:"railings.glassFrameless",category:"railings",nameHe:"מעקה זכוכית ללא מסגרת",build:(t,e)=>c7(t,void 0,e)},{id:"living.railingHorizontal",category:"railings",nameHe:"מעקה פסים",build:(t,e)=>r7(t,void 0,e)},{id:"living.railingVertical",category:"railings",nameHe:"מעקה סורגים",build:(t,e)=>a7(t,void 0,e)},{id:"lighting.recessed",category:"lighting",nameHe:"ספוט שקוע",build:(t,e,s)=>u7(t,void 0,e,s)},{id:"lighting.panel",category:"lighting",nameHe:"פנל תאורה",build:(t,e,s)=>m7(t,void 0,e,s)},{id:"lighting.wall",category:"lighting",nameHe:"מנורת קיר",build:(t,e,s)=>x7(t,void 0,e)},{id:"lighting.floor",category:"lighting",nameHe:"מנורה עומדת",build:(t,e,s)=>g7(t,void 0)},{id:"stairs.straight",category:"stairs",nameHe:"מדרגות ישרות",build:(t,e)=>SG(t)},{id:"stairs.step2",category:"stairs",nameHe:"מדרגות מעבר",build:(t,e)=>PG(t)},{id:"stairs.winder",category:"stairs",nameHe:"מדרגות סיבוב",build:(t,e)=>BG(t)},{id:"stairs.podium",category:"stairs",nameHe:"מדרגות פודיום",build:(t,e)=>RG(t)},{id:"stairs.uShape",category:"stairs",nameHe:"מדרגות U",build:(t,e)=>OG(t)},{id:"stairs.straightRail",category:"stairs",nameHe:"מדרגות ישרות עם מעקה",build:(t,e)=>LG(t)}
278,{id:"stairs.floating",category:"stairs",nameHe:"מדרגות מרחפות",build:(t,e)=>WG(t)},{id:"stairs.lShape",category:"stairs",nameHe:"מדרגות L",build:(t,e)=>HG(t)},{id:"stairs.stoop",category:"stairs",nameHe:"מדרגות כניסה",build:(t,e)=>AG(t)}];function zG(t){return ok.find(e=>e.id===t)}const ob="application/x-floorplan-template";function $G(t){return ok.filter(e=>e.category===t)}const b7=[{id:"planned.dining.pendant",category:"dining",nameHe:"גוף תאורה תלוי"},{id:"planned.bedroomMaster.tableLamp",category:"bedroomMaster",nameHe:"מנורת לילה"},{id:"planned.bedroomKids.chair",category:"bedroomKids",nameHe:"כיסא"},{id:"planned.bathroom.towelBar",category:"bathroom",nameHe:"מתקן מגבות"},{id:"planned.entry.wallHook",category:"entry",nameHe:"מתלה קיר"},{id:"planned.utility.tallCabinet",category:"utility",nameHe:"ארון שירות גבוה"},{id:"planned.utility.sink",category:"utility",nameHe:"כיור שירות"},{id:"planned.accessories.vase",category:"accessories",nameHe:"אגרטל"},{id:"planned.accessories.decorSet",category:"accessories",nameHe:"סט עיצובי"}];function XG(t){return b7.filter(e=>e.category===t)}function M7(t,e){const s={ceilingHeightMm:e.ceilingHeightMm};if(t.id==="kitchenAssembly.worktop"&&!e.anchoredWall&&!e.floorAnchor){const r=new Set(e.furnitureGroups.filter(u=>{var h;return((h=u.templateId)==null?void 0:h.startsWith("kitchenAssembly."))&&(u.heightMm??0)>0&&(u.heightMm??0)<=1e3}).flatMap(u=>u.entityIds));let i=1/0,a=1/0,l=-1/0,c=-1/0,d=!1;for(const u of e.entities)if(!(u.kind!=="polygon"||!r.has(u.id))&&!((u.baseHeightMm??0)>0)){d=!0;for(const h of u.vertices)h.x<i&&(i=h.x),h.x>l&&(l=h.x),h.y<a&&(a=h.y),h.y>c&&(c=h.y)}if(d){const u=t.build({x:0,y:0},void 0,{...s,worktopRunBoundsMm:{minX:i,minY:a,maxX:l,maxY:c}});return{...u,group:{...u.group,templateId:t.id}}}}let o;if(e.anchoredWall){let r=0;for(const i of e.furnitureGroups){if(i.wallId!==e.anchoredWall.wallId||i.wallSide&&i.wallSide!==e.anchoredWall.side)continue;const a=(i.wallPositionMm??0)+(i.widthMm??0);a>r&&(r=a)}o=t.build({x:0,y:0},{...e.anchoredWall,positionAlongWallMm:r},s)}else if(e.floorAnchor){const r=t.build({x:0,y:0}),i=r.group.widthMm??0,a=r.group.depthMm??0;o=t.build({x:Math.round(e.floorAnchor.positionMm.x-i/2),y:Math.round(e.floorAnchor.positionMm.y-a/2)},void 0,s)}else{let r=-1/0,i=0;for(const a of e.entities){if(a.kind!=="polygon")continue;const l=Math.max(...a.vertices.map(c=>c.x));l>r&&(r=l,i=Math.min(...a.vertices.map(c=>c.y)))}if(r===-1/0)if(e.modelCenterMm){const a=t.build({x:0,y:0}),l=a.group.widthMm??0,c=a.group.depthMm??0;o=t.build({x:Math.round(e.modelCenterMm.x-l/2),y:Math.round(e.modelCenterMm.y-c/2)},void 0,s)}else o=t.build({x:0,y:0},void 0,s);else o=t.build({x:r,y:i},void 0,s)}return{...o,group:{...o.group,templateId:t.id}}}function A8(t,e){const s={...t,...e};return Object.prototype.hasOwnProperty.call(e,"color")&&e.color===void 0&&delete s.color,Object.prototype.hasOwnProperty.call(e,"texture")&&e.texture===void 0&&delete s.texture,s}function YG(t,e,s,o){return t.map(r=>{var c;if(r.id!==e||r.kind!=="polygon"&&r.kind!=="facePatch"&&!(r.kind==="faceCornerArc"&&r.verticalThroughCut&&s==="side"))return r;if(r.kind==="faceCornerArc"){const d=((c=r.faces)==null?void 0:c.side)??{},u=A8(d,o);return!u.color&&!u.texture?{...r,faces:void 0}:{...r,faces:{side:u}}}const i=r.faces??{},a=i[s]??{},l=A8(a,o);if(!l.color&&!l.texture){const{[s]:d,...u}=i;return{...r,faces:Object.keys(u).length?u:void 0}}return{...r,faces:{...i,[s]:l}}})}const GG=[],UG={},KG={},ZG={},qG=new Set,JG=[],QG=[],K2=()=>{},tU=.22;function eU({children:t}){const e=m.useRef(null),s=m.useRef(new Map),o=m.useCallback(()=>{var r;(r=e.current)==null||r.traverse(i=>{if(s.current.has(i)||!(i instanceof E1||i instanceof $_||i instanceof iI))return;const a=i,l=a.material;if(!l)return;const d=(Array.isArray(l)?l:[l]).map(u=>{const h=u.clone();return h.transparent=!0,h.opacity=u.opacity*tU,h.depthWrite=!1,h.needsUpdate=!0,h});s.current.set(i,{material:l,castShadow:i.castShadow,receiveShadow:i.receiveShadow,raycast:i.raycast,clonedMaterials:d}),a.material=Array.isArray(l)?d:d[0],i.castShadow=!1,i.receiveShadow=!1,i.raycast=()=>{}})},[]);return ka(o),m.useEffect(()=>()=>{for(const[r,i]of s.current){const a=r;a.material=i.material,r.castShadow=i.castShadow,r.receiveShadow=i.receiveShadow,r.raycast=i.raycast,i.clonedMaterials.forEac
278h(l=>l.dispose())}s.current.clear()},[]),n.jsx("group",{ref:e,children:t})}const nU=360,oU=468,mf=12,L8=340,Tu=12;function Lg(t,e){if(typeof window>"u")return{x:t,y:e};const s=Math.min(nU,Math.max(240,window.innerWidth-mf*2)),o=Math.min(oU,Math.max(240,window.innerHeight-mf*2));return{x:Math.max(mf,Math.min(t,window.innerWidth-s-mf)),y:Math.max(mf,Math.min(e,window.innerHeight-o-mf))}}const y7=220,w7=94,W8=10,R8=360,O8=500,H8=8;function Np(t,e,s){return Math.max(e,Math.min(s,t))}function B8(t,e,s,o){if(s<=0)return 0;const r=Math.max(0,100-o/s*100);return Np((t-e)/s*100,0,r)}function sU(t){const e=Np(t.left+(t.width-R8)/2,8,Math.max(8,window.innerWidth-R8-8)),s=t.top-O8-H8,o=t.bottom+H8,r=s>=8?s:o,i=Np(r,8,Math.max(8,window.innerHeight-O8-8));return{x:e,y:i}}function rU(t,e,s,o){const r=e.split(/\s+/).filter(Boolean),i=[];let a="";for(const l of r){const c=a?`${a} ${l}`:l;if(t.measureText(c).width<=s){a=c;continue}if(a&&i.push(a),a=l,i.length>=o)break}if(a&&i.length<o&&i.push(a),i.length===o&&r.length>0){const l=i[i.length-1];t.measureText(`${l}...`).width<=s&&(i[i.length-1]=`${l}...`)}return i}function V8(t,e,s,o,r,i){const a=Math.min(i,o/2,r/2);t.beginPath(),t.moveTo(e+a,s),t.lineTo(e+o-a,s),t.quadraticCurveTo(e+o,s,e+o,s+a),t.lineTo(e+o,s+r-a),t.quadraticCurveTo(e+o,s+r,e+o-a,s+r),t.lineTo(e+a,s+r),t.quadraticCurveTo(e,s+r,e,s+r-a),t.lineTo(e,s+a),t.quadraticCurveTo(e,s,e+a,s),t.closePath()}function iU(t,e,s){const o=e.filter(h=>!h.hidden);if(o.length===0)return t.toDataURL("image/png");const r=document.createElement("canvas");r.width=t.width,r.height=t.height;const i=r.getContext("2d");if(!i)return t.toDataURL("image/png");i.drawImage(t,0,0,r.width,r.height);const a=t.clientWidth>0?t.width/t.clientWidth:1,l=y7*a,c=w7*a,d=12*a,u=18*a;for(const h of o){const x=Vl(h.contentHtml);if(!x)continue;const f=Np(h.xPct/100*r.width,8*a,Math.max(8*a,r.width-l-8*a)),p=Np(h.yPct/100*r.height,8*a,Math.max(8*a,r.height-c-8*a));i.font=`${13*a}px Heebo, Arial, sans-serif`;const b=rU(i,x,l-d*2,5),M=Math.max(c,d*2+b.length*u+22*a);i.save(),i.shadowColor="rgba(24, 33, 55, 0.22)",i.shadowBlur=14*a,i.shadowOffsetY=5*a,V8(i,f,p,l,M,10*a),i.fillStyle=Ku(h.colorId),i.fill(),i.restore(),V8(i,f,p,l,M,10*a),i.strokeStyle="rgba(24, 33, 55, 0.18)",i.lineWidth=Math.max(1,a),i.stroke(),i.fillStyle="rgba(24, 33, 55, 0.58)",i.font=`700 ${11*a}px Heebo, Arial, sans-serif`,i.fillText(s,f+d,p+d+8*a),i.fillStyle="#182137",i.font=`${13*a}px Heebo, Arial, sans-serif`,b.forEach((g,w)=>{i.fillText(g,f+d,p+d+30*a+w*u)})}return r.toDataURL("image/png")}const dc=new Set;function aU({bounds:t,figurePosition:e,figureRotation:s,planRotationDeg:o,cameraPreset:r}){yn();const i=Vo(l=>l.camera),a=Vo(l=>l.controls);return m.useEffect(()=>(window.__floorplanInspectViewport=()=>{var A,W;const l=i,c=a,d=((W=(A=c==null?void 0:c.target)==null?void 0:A.clone)==null?void 0:W.call(A))??new le,u=(e==null?void 0:e.x)??t.centerX+T1.x,h=(e==null?void 0:e.z)??t.centerZ+T1.z,x=s??pE,f=t.centerX,p=t.centerZ,b=o*Math.PI/180,M=Math.cos(b),g=Math.sin(b),w=u-f,k=h-p,_=f+M*w+g*k,j=p-g*w+M*k,v=Math.sin(x),C=Math.cos(x),N=M*v+g*C,P=-g*v+M*C,L=Math.hypot(N,P)||1;return{cameraPreset:r,camera:{position:l.position.toArray(),quaternion:l.quaternion.toArray(),fov:l.fov,near:l.near,far:l.far,up:l.up.toArray()},orbitControls:c!=null&&c.target?{target:d.toArray(),distance:l.position.distanceTo(d),minDistance:typeof c.minDistance=="number"?c.minDistance:NaN,maxDistance:typeof c.maxDistance=="number"?c.maxDistance:NaN}:null,figure:{planSpaceXZ_m:{x:u,z:h},rotationY_rad:x,rotationY_deg:x*180/Math.PI,facing_planXZ_unit:{x:v,z:C},approxWorldXZ_m:{x:_,z:j},facing_worldXZ_unit_approx:{x:N/L,z:P/L}},planRotationDeg:o}},()=>{delete window.__floorplanInspectViewport}),[i,a,t,e,s,o,r]),null}const Z2=t=>Number.isFinite(t)?Math.min(1,Math.max(0,t)):0,Wg=t=>Math.min(2.5,Math.max(.02,t));function lU({enabled:t,outdoor:e=!1,onFlagsChange:s}){const{gl:o}=Vo();return m.useEffect(()=>{if(!t){s({shadowMapEnabled:o.shadowMap.enabled});return}const r={shadowMapEnabled:o.shadowMap.enabled,shadowMapType:o.shadowMap.type,shadowMapAutoUpdate:o.shadowMap.autoUpdate,toneMapping:o.toneMapping,toneMappingExposure:o.toneMappingExposure};return o.shadowMap.enabled=!0,o.shadowMap.type=e?oI:sI,o.shadowMap.autoUpdate=!0,o.shadowMap.needsUpdate=!0,o.toneMapping=rI,o.toneMappingExposure=e?1.05:.9,s({shadowMapEnabled:!0}),()=>{o.shadowMap.enabled=r.shadowMapEnabled,o.shadowMap.type=r.shadowMapType,o.shadowMap.autoUpdate=r.shadowMapAutoUpdate,o.shadowMap.needsUpdate=!0,o.toneMapping=r.toneMapping,o.toneMappingExposure=r.toneMappingExposure,s({shadowMapEnabled:r.shadowMapEnabled})}},[t,e,o,s]),null}function cU(){return n.jsxs(n.Fragment,{children:[n.jsx("ambientLight",{intensity:1}),n.jsx("directionalLight",{position:[10,15,10],intensity:1.2}),n.jsx("directionalLight",{position:[-5,10,-5],intensity:.6}),n.jsx("directionalLight",{position:[0,12,-8],intensity:.4}),n.jsx("hemisphereLight",{args:["#b1e1ff","#b97a20",.3]}),n.jsxs(Ow,{background:!1,environmentIntensity:.5,children:[n.jsxs("mesh",{scale:50,children:[n.jsx("sphereGeometry",{}),n.jsx("meshBasicMaterial",{color:"#d3d4d0",side:Sp})]}),n.jsx("directionalLight",{position:[5,8,3],intensity:2}),n.jsx("directionalLight",{position:[-3,5,-2],intensity:1})]})]})}function dU({bounds:t,wallHeight:e,settings:s}){const o=Math.max(mm(t),4),r=o*.75,i=Math.max(e*2.2,4),a=Z2(s.fillLight),l=Z2(s.shadowStrength),c=Z2(s.lightWarmth),d=Math.pow(a,1.08),u=Math.pow(l,1.22),h=Math.pow(c,1.08),x=Wg(.06+d*.72-u*.22),f=Wg(.04
278+d*.62-u*.16),p=.18+u*2.12,b=Wg(.02+d*.56-u*.16),M=Wg(.04+d*.52-u*.1),g=new Do("#dbe7ff").lerp(new Do("#ffdba8"),h).getStyle(),w=new Do("#545f72").lerp(new Do("#896449"),h).getStyle(),k=new Do("#c2cee4").lerp(new Do("#d7bd99"),h).getStyle(),_=new Do("#eef4ff").lerp(new Do("#ffd09a"),h).getStyle(),j=new Do("#d3e3ff").lerp(new Do("#fff0c8"),h).getStyle();return n.jsxs(n.Fragment,{children:[n.jsx("ambientLight",{intensity:x}),n.jsx("hemisphereLight",{args:[g,w,f]}),n.jsx("directionalLight",{castShadow:!0,color:_,position:[t.centerX-o*.45,i,t.centerZ+o*.5],intensity:p,"shadow-mapSize-width":2048,"shadow-mapSize-height":2048,"shadow-camera-near":.1,"shadow-camera-far":o*5,"shadow-camera-left":-r,"shadow-camera-right":r,"shadow-camera-top":r,"shadow-camera-bottom":-r,"shadow-bias":-12e-5,"shadow-normalBias":.018}),n.jsx("directionalLight",{color:j,position:[t.centerX+o*.42,Math.max(e*1.3,2.2),t.centerZ-o*.38],intensity:b}),n.jsx(Ow,{background:!1,environmentIntensity:M,children:n.jsxs("mesh",{scale:50,children:[n.jsx("sphereGeometry",{}),n.jsx("meshBasicMaterial",{color:k,side:Sp})]})})]})}const uw=.3,z8=.1,$8=.3,X8=Ru.degToRad(6),Y8=Ru.degToRad(8),uU=73,hU=[{value:65,label:"צר",title:"עדשה צרה"},{value:73,label:"רגיל",title:"עדשה רגילה"},{value:85,label:"רחב",title:"עדשה רחבה"}],G8=.05,U8=.75,mU=2.35,fU=4.8,xU=5.8,pU=16,gU=1.55,bU=2.7,MU=.3,yU=.035,wU=.35,kU=.35,vU=120,jU=9e-4,_U=14,K8=500,EU=[{hex:"#FAF7F2",label:"לבן חם"},{hex:"#E8DED0",label:"שמנת טבעית"},{hex:"#B8A992",label:"חאקי אוניברסלי · צבע השנה 2026"},{hex:"#C7B79F",label:"חול שקט"},{hex:"#7C7F70",label:"אקליפטוס חם · צבע השנה 2026"},{hex:"#A9B19D",label:"מרווה מעושנת"},{hex:"#49675A",label:"ירקן מעושן · צבע השנה 2026"},{hex:"#2F4A43",label:"ירוק נראגנסט"},{hex:"#C78468",label:"טרקוטה דרום־מערבית"},{hex:"#D8A7A0",label:"ורוד אבקתי"},{hex:"#867B72",label:"אפור־חום"},{hex:"#4B403B",label:"סילואט אספרסו · צבע השנה 2026"}];function k7(t){return!!t&&(t.kind==="polygon"||t.kind==="facePatch"||t.kind==="faceCornerArc"&&t.verticalThroughCut===!0)}function Z8(t,e){var o,r,i;if(e.hostFaceRegion){const a=bD(e.hostFaceRegion),l=t.find(c=>{var d,u;return c.kind==="facePatch"&&c.hostEntityId===((d=e.hostFaceRegion)==null?void 0:d.hostEntityId)&&c.hostFaceId===((u=e.hostFaceRegion)==null?void 0:u.hostFaceId)&&c.promotedRegionKey===a});if(l)return(o=l.faces)==null?void 0:o.top}const s=t.find(a=>a.id===e.entityId);if(k7(s))return s.kind==="faceCornerArc"?(r=s.faces)==null?void 0:r.side:(i=s.faces)==null?void 0:i[e.faceId]}function DU(t){return{...t.color?{color:t.color}:{},...t.texture?{texture:{...t.texture}}:{}}}function q8(t){return!!(t!=null&&t.texture||t!=null&&t.color)}function tp(t,e){const s=Math.max(uw,e-.1);return Math.min(Math.max(t,uw),s)}function J8(t,e){return Math.min(Math.max(t,.08),Math.max(e+.45,uw+.8))}function FU({x:t,y:e,currentLengthMm:s,measurementUnit:o,isDark:r,onCommit:i,onClose:a}){const{t:l,i18n:c}=yn(),d=m.useRef(null),u=m.useRef(null),[h,x]=m.useState(()=>De(s,o)),[f,p]=m.useState(null);m.useEffect(()=>{x(De(s,o)),p(null);const _=window.setTimeout(()=>{var j;return(j=u.current)==null?void 0:j.select()},0);return()=>window.clearTimeout(_)},[s,o]),m.useEffect(()=>{const _=j=>{var v;(v=d.current)!=null&&v.contains(j.target)||a()};return window.addEventListener("mousedown",_),()=>window.removeEventListener("mousedown",_)},[a]);const b=()=>{const _=ni(h,o);if(_===null){p(l("viewer.wallLength.invalid",{defaultValue:"יש להזין אורך תקין."}));return}const j=i(_);j.ok===!0?a():p(j.messageHe)},M=246,g=f?174:148,w=Math.max(12,Math.min(t+14,window.innerWidth-M-12)),k=Math.max(12,Math.min(e-28,window.innerHeight-g-12));return n.jsxs("div",{ref:d,"data-testid":"floorplan-wall-length-editor",className:O("fixed z-[65] w-[246px] overflow-hidden rounded-2xl border font-heebo text-start shadow-[0_18px_44px_rgba(24,33,55,0.22),inset_0_1px_0_rgba(255,255,255,0.7)]","motion-safe:animate-in motion-safe:fade-in motion-safe:zoom-in-95 motion-safe:duration-150",r?"border-white/12 bg-[#141416] text-white":"border-[#D85D43]/22 bg-[#F7F4EF] text-[#182137]"),style:{left:w,top:k},dir:c.dir(),onMouseDown:_=>_.stopPropagation(),onClick:_=>_.stopPropagation(),onDoubleClick:_=>_.stopPropagation(),onContextMenu:_=>{_.preventDefault(),_.stopPropagation()},children:[n.jsxs("div",{className:O("flex items-center justify-between border-b px-3 py-2.5",r?"border-white/10":"border-[#182137]/9"),children:[n.jsxs("div",{children:[n.jsx("div",{className:O("text-[9px] font-bold uppercase tracking-[0.15em]",r?"text-white/42":"text-[#D85D43]"),children:l("viewer.wallLength.eyebrow",{defaultValue:"מידת קיר"})}),n.jsx("div",{className:"mt-0.5 text-[13px] font-black tracking-[-0.025em]",children:l("viewer.wallLength.title",{defaultValue:"שינוי אורך"})})]}),n.jsx("button",{type:"button","aria-label":l("common.close",{defaultValue:"סגור"}),onClick:a,className:O("flex h-8 w-8 items-center justify-center rounded-[10px] border transition active:translate-y-
278px",r?"border-white/10 bg-white/[0.06] text-white/65 hover:bg-white/10":"border-[#182137]/10 bg-[#FFFDFC] text-[#182137]/55 shadow-[0_2px_5px_rgba(24,33,55,0.08)] hover:text-[#182137]"),children:n.jsx(Gr,{size:14})})]}),n.jsxs("div",{className:"px-3 pb-3 pt-2.5",children:[n.jsx("label",{className:O("mb-1 block text-[10px] font-bold",r?"text-white/58":"text-[#182137]/58"),children:l("viewer.wallLength.label",{defaultValue:"אורך קיר"})}),n.jsxs("div",{className:O("flex h-11 items-center overflow-hidden rounded-xl border focus-within:ring-2",r?"border-white/15 bg-[#09090B] focus-within:border-[#D85D43]/70 focus-within:ring-[#D85D43]/15":"border-[#182137]/12 bg-[#FFFDFC] shadow-[inset_0_1px_2px_rgba(24,33,55,0.05)] focus-within:border-[#D85D43]/55 focus-within:ring-[#D85D43]/12"),children:[n.jsx("input",{ref:u,autoFocus:!0,type:"text",inputMode:"decimal",value:h,"aria-label":l("viewer.wallLength.label",{defaultValue:"אורך קיר"}),onChange:_=>{x(_.currentTarget.value),p(null)},onKeyDown:_=>{_.key==="Enter"&&(_.preventDefault(),b()),_.key==="Escape"&&(_.preventDefault(),_.stopPropagation(),a())},className:"h-full min-w-0 flex-1 bg-transparent px-3 text-center text-[16px] font-black tabular-nums outline-none"}),n.jsx("span",{className:O("border-s px-3 text-[10px] font-black",r?"border-white/10 text-white/38":"border-[#182137]/9 text-[#182137]/42"),children:o==="mm"?l("settings.millimeters",{defaultValue:"מ״מ"}):l("settings.centimeters",{defaultValue:"ס״מ"})})]}),f?n.jsx("div",{className:"mt-2 text-[10px] font-bold leading-4 text-[#D85D43]",role:"alert",children:f}):n.jsx("div",{className:O("mt-2 text-[9px] font-medium",r?"text-white/35":"text-[#182137]/42"),children:l("viewer.wallLength.hint",{defaultValue:"Enter לעדכון · Esc לביטול"})})]})]})}const Q8=m.forwardRef(function({scene:e,activeLevelId:s,viewScope:o="floor",cameraFocusRequestId:r=0,onActivateLevel:i,levelVisibility:a=UG,passiveLevelState:l=KG,buildingRoof:c=null,showBuildingRoof:d=!0,roofHostState:u=null,roofSelected:h=!1,onRoofSelectionChange:x,roofContourEditing:f=!1,onRoofContourCommit:p,roofFocusRequestId:b=0,customModelUrls:M,customModelMaterialSlots:g,compact:w,environment:k,environmentEnabled:_=!1,simulateOpenings:j=!1,openOpeningIds:v,floorTextureUrl:C,roomFloorOverrides:N,onRoomFloorOverrideChange:P,roomFloorRegions:L,onRoomFloorRegionsChange:A,onFloorTileOriginChange:W,wallFaceRegions:S,onWallFaceRegionsChange:B,initialPreset:R,tileSizeM:z,grout:X,wallTextures:ft,walls:tt,onWallsChange:G,beams:Y,onBeamsChange:J,selectedBeamId:Mt=null,onBeamSelectionChange:Rt,onWallLengthChange:it,savedWallTiles:st,onUploadWallTile:ct,onRemoveWallTile:pt,onRenameWallTile:xt,personalAssetsLocked:_t=!1,onPremiumRequired:Ft,onFloorTextureChange:Vt,onFloorTileSizeChange:vt,onFloorGroutChange:Ht,floorTileWidthCm:Tt,floorTileHeightCm:Zt,floorGroutWidthMm:At,floorGroutColor:ut,savedFloorTiles:kt,onUploadFloorTile:Et,onRemoveFloorTile:ht,onRenameFloorTile:gt,sidebarMode:Pt,onSidebarModeChange:U,sidebarContent:mt,wallSettingsContent:Nt,measurementUnit:Lt="cm",renderCarpentryPanel:oe,renderFloorTemplatePanel:he,renderFloorMaterialPanel:pe,getFloorMaterialPanelSubtitle:Ge,onFloorFurniturePanelOpen:Qt,renderFloorFurniturePanel:te,getFloorFurniturePanelSubtitle:Be,onFloorplanTemplateDrop:wt,activeFloorplanTemplateId:ve=null,onFloorplanTemplatePlace:Ne,onFloorplanTemplatePlacementCancel:Le,templatePlacementUsesTopView:is=!0,tracedFurniture:Fe,onFurnitureChange:bn,furnType:Ve,furniturePlacementRequestId:en=0,onFurnitureFloorPlaced:on,openingPreset:Qs,onOpeningPresetChange:sn,onAddOpening:vn,openings:Ot,effectiveScale:so,onOpeningsChange:Ue,planRotationDeg:hs=0,floorplanCameraPose:Qn=null,onFloorplanCameraPoseChange:Lr,showCanvasCameraMarker:bi=!1,onCameraPresetChange:Ps,onRoomLabelChange:In,onHiddenWallCountChange:Rn,onRequestSectionOpen:fe,roomCeilingOverrides:Gs,onRoomCeilingOverridesChange:zo,onSelectionChange:js,forceShowCeiling:co=!1,onFurnitureSelectionChange:ze,selectedSmartGlbPart:Un=null,onSmartGlbPartSelect:uo,onSmartGlbPartClear:dn,activeFloorplanSketchTool:$o=null,floorplanSketchEntities:Te=[],floorplanSketchFurnitureGroups:po=[],selectedFloorplanSketchEntityId:ho=null,
278selectedFloorplanSketchEdgeIndex:go=null,selectedFloorplanSketchFaceId:Kl=null,floorplanSketchAxesVisible:da=!0,onFloorplanSketchToolChange:As,onFloorplanSketchEntitiesChange:ua,onFloorplanSketchFurnitureGroupsChange:Gi,onFloorplanSketchSelect:On,onFloorplanSketchFaceSelect:to,onFloorplanSketchEdgeSelect:Wt,onFloorplanSketchHostFaceRegionSelect:qe,floorplanSketchLineLengthRequest:Se=null,floorplanSketchCommitLineRequestId:jn=0,onFloorplanSketchLineDraftLengthChange:je,onFloorplanSketchFaceLineMeasurementChange:ne,onFloorplanSketchFaceMeasureMeasurementChange:Re,onFloorplanSketchFaceMeasureMarkerPointerDown:Dn,floorplanSketchFaceMeasureLengthRequest:ge=null,floorplanSketchCommitFaceMeasureRequest:ie=null,floorplanSketchUpdateFaceMeasureRequest:Ze=null,floorplanSketchRectangleDimensionsRequest:as=null,onFloorplanSketchRectangleDraftDimensionsChange:Pe,onFloorplanSketchPushPullHeightChange:Ao,floorplanSketchFaceOffsetDistanceRequest:Lo=null,floorplanSketchCommitFaceOffsetRequest:Gt=null,onFloorplanSketchFaceOffsetPreviewChange:Co,floorplanSketchOffsetDistanceRequest:Xo=null,floorplanSketchCommitOffsetRequest:pn=null,onFloorplanSketchOffsetPreviewChange:Kn,activeTemplateEditorJobCount:tr=0,templateEditorRecoveredNotice:ro=null,onFloorplanTemplateEditSubmit:ls,figureHidden:Qo=!1,figurePosition:ms=null,figureRotation:Yo=null,onFigureHiddenChange:Qe,onFigurePositionChange:Go,onFigureRotationChange:er,wallElectricalFixtures:Vn=[],onWallElectricalFixturesChange:dr,wallNotes:Ii=[],onWallNotesChange:fs,viewportNotes:Uo=[],onViewportNotesChange:Hn,viewportNoteFocusRequest:ur=null,detailsPanelOpen:oi=!1,walkthroughs:Je=[],onWalkthroughsChange:rn,onWalkthroughRecordingChange:xs,onWalkthroughVideoSave:vo},Ui){const{t:It,i18n:_s}=yn(),ha=m.useRef(null),Mi=m.useRef(null),[Fa,si]=m.useState(null),Ko=m.useRef({openWalkthroughRecorder:()=>{},startWalkthroughRecording:()=>!1,stopWalkthroughRecording:()=>null,playWalkthrough:()=>{},stopWalkthroughPlayback:()=>{},exportWalkthroughVideo:async()=>null}),ae=xc(),Za=WE,Mr=(k==null?void 0:k.sky.timeOfDayMinutes)??wb,ri=m.useMemo(()=>kb(Mr),[Mr]),Qc=m.useMemo(()=>a3(Mr),[Mr]),Es=_?ri.nightStrength:0,Us=_&&Es>=.5;m.useImperativeHandle(Ui,()=>({takeScreenshot:E=>{const F=Mi.current;return F?E!=null&&E.includeViewportNotes?iU(F,Uo,It("notes.label",{defaultValue:"פתק"})):F.toDataURL("image/png"):null},setCameraPreset:E=>ar(E),showAllHiddenWalls:()=>ma(new Set),zoomIn:()=>{Br.current="in",nc(E=>E+1)},zoomOut:()=>{Br.current="out",nc(E=>E+1)},openWalkthroughRecorder:E=>Ko.current.openWalkthroughRecorder(E),startWalkthroughRecording:()=>Ko.current.startWalkthroughRecording(),stopWalkthroughRecording:()=>Ko.current.stopWalkthroughRecording(),playWalkthrough:E=>Ko.current.playWalkthrough(E),stopWalkthroughPlayback:()=>Ko.current.stopWalkthroughPlayback(),exportWalkthroughVideo:(E,F,V)=>Ko.current.exportWalkthroughVideo(E,F,V)}));const Ki=m.useRef({x:0,y:0,z:0}),[ts,Wo]=m.useState(null),[Ds,pc]=m.useState(null),[Ti,eo]=m.useState(null),[yi,nr]=m.useState("front"),[zs,es]=m.useState(!1),[Ca,eh]=m.useState(null),[ps,Ro]=m.useState(null),[gs,bo]=m.useState(null),[bs,Kr]=m.useState(null),[xl,pl]=m.useState(!1),[Zi,Si]=m.useState(null),Fs=Gs??{},Pi=m.useCallback(E=>{if(!zo)return;const F=typeof E=="function"?E(Fs):E;zo(F)},[zo,Fs]),[Na,Wr]=m.useState(!1),[Rr,ma]=m.useState(new Set);m.useEffect(()=>{w||Rn==null||Rn(Rr.size)},[w,Rr.size,Rn]),m.useEffect(()=>{if(!w)return()=>Rn==null?void 0:Rn(0)},[w,Rn]);const[gn,Zo]=m.useState(null),[et,q]=m.useState(null),[Ct,bt]=m.useState(null),[Dt,Xt]=m.useState(null),[me,xe]=m.useState(null),[Ee,wn]=m.useState(null),[lt,He]=m.useState(null),[cn,nn]=m.useState(null),[or,qn]=m.useState(null),[Oo,Ks]=m.useState(null),[sr,Ls]=m.useState(null),[ns,ii]=m.useState(null),[Ia,Or]=m.useState(null),[os,Zr]=m.useState(null),[Fn,qr]=m.useState(null),[Ye,Ke]=m.useState(null),[Mo,re]=m.useState(null),_n=m.useRef(null),jo=m.useRef(null),Ms=m.useRef(Uo);Ms.current=Uo;const[un,hr]=m.useState(null),[_r,Ta]=m.useState(null),[ss,Ai]=m.useState(null),[No,Er]=m.useState(null),[gc,Dr]=m.useState(null),[qi,jm]=m.useState(null),[Ws,yr]=m.useState(null),[fa,xa]=m.useState(null),[Kd,Zl]=m.useState(null),[En,Fr]=m.useState(null),[wr,qa]=m.useState(null),Zd=m.useRef(null),td=m.useRef(null),qd=m.useRef(null),I=m.useRef(null),[H,K]=m.useState(null),[nt,Q]=m.useState(null),[dt,jt]=m.useState(null),[Yt,Ut]=m.useState("cladding"),[Jt,we]=m.useState("builtin"),[Mn,tn]=m.useState(null),[fn,Rs]=m.useState(!1),hn=m.useRef(null),_o=m.useCallback(()=>{Ut("cladding"),we("builtin"),tn(null),Rs(!1)},[]),[ys,io]=m.useState(null),zn=m.useRef(R||"orbit"),[Eo,rr]=m.useState(!1),[Sa,Li]=m.useState(!1),[gl,ql]=m.useState(!1),Hr=m.useRef(null),$e=m.useRef(!1),bl=m.useRef(!1),Io=m.useRef(!1),Jl=m.useRef(null),nh=m.useRef(!1),Jd=m.useRef(!1),[Jr,_m]=m.useState(!1),cs=m.useCallback((E={})=>{const F=Hr.current;if(!F)return;const V={preset:zn.current,selectedWallRegionId:Jl.current,figureInteracting:bl.current||Io.current,figureRotateMode:$e.current,sketchToolActive:nh.current,sketchElementMoveActive:Jd.current,...E};F.enabled=!ej(V)}
278,[]),Zp=m.useCallback(E=>{bl.current=E,Li(E),cs({figureInteracting:E})},[cs]),bc=m.useCallback(E=>{Jd.current=E,_m(E),cs({sketchElementMoveActive:E})},[cs]),qp=m.useCallback(E=>{Io.current=E,ql(E),cs({figureInteracting:bl.current||E})},[cs]),Cs=m.useCallback(()=>{On==null||On(null),to==null||to(null),Wt==null||Wt(null),qe==null||qe(null)},[Wt,to,qe,On]),[ed,kr]=m.useState(null),Pa=m.useRef(!1),ds=m.useRef(null),[pa,To]=m.useState(null),Ho=m.useCallback(()=>{ds.current!==null&&(window.clearTimeout(ds.current),ds.current=null)},[]);m.useEffect(()=>()=>Ho(),[Ho]);const nd=m.useCallback((E,F,V)=>{if(zn.current==="orbit"&&!!it&&!nh.current&&!ho&&!ve&&!cn&&!ns&&Pt!=="opening"&&Pt!=="furniture"){Ho(),ds.current=window.setTimeout(()=>{ds.current=null,Cs(),Wo(E),eo(F),nr(V),Kr(null),es(!1),To({wallId:E,x:F.x,y:F.y,side:V}),Zo(null)},240);return}Na&&(Wo(yt=>{const zt=yt===E?null:E;return zt&&(fe==null||fe("walls")),zt}),eo(F),nr(V),es(!1))},[ve,Ho,Cs,cn,ns,fe,it,ho,Pt,Na]),Ji=m.useCallback((E,F,V)=>{Ho(),To(null),Pa.current=!0,Cs(),Zo({wallId:E,x:F.x,y:F.y,side:V}),kr(null),yr(null),q(null)},[Ho,Cs]),zb=m.useCallback((E,F,V)=>{Cs(),Wo(E),eo(F),nr(V),es(!1),fe==null||fe("walls")},[Cs,fe]),ai=m.useCallback(E=>{Pa.current=!0,Cs(),kr({x:E.x,y:E.y,mode:"hide"}),Zo(null)},[Cs]),Qd=m.useCallback((E,F)=>{Pa.current=!0,Cs(),xa({furnitureId:E,x:F.x,y:F.y}),Zo(null),kr(null),yr(null)},[Cs]),tu=m.useCallback((E,F,V,at)=>{Pa.current=!0,Cs(),!(!Ot||!Ot.find(zt=>zt.id===E))&&(yr({openingId:E,x:F.x,y:F.y,side:V,objectAnchor:at}),Zo(null),kr(null),io(null),Xt(null))},[Cs,Ot]),Ml=m.useCallback(E=>{Fr(E),E&&(K(null),Q(null),Zo(null),yr(null),kr(null),xa(null))},[]),Mc=m.useCallback((E,F)=>{q8(E)&&(Q({assignment:DU(E)}),jt(F??null))},[]),Aa=m.useCallback(()=>{_o(),Q(null),jt(null),K(null),Fr(null),Zo(null),yr(null),xa(null),kr(null)},[_o]),yl=m.useCallback(()=>{$e.current=!1,bl.current=!1,rr(!1),Li(!1),cs({figureRotateMode:!1,figureInteracting:!1})},[cs]),yc=m.useCallback(()=>{Qe==null||Qe(!0),yl(),kr(null)},[yl,Qe]),$b=m.useCallback(()=>{Qe==null||Qe(!1),kr(null)},[Qe]),Jp=m.useCallback(()=>{$e.current=!0,bl.current=!1,rr(!0),Li(!1),kr(null),cs({figureRotateMode:!0,figureInteracting:!1})},[cs]),wl=m.useCallback(E=>{ma(F=>{const V=new Set(F);return V.add(E),V}),Zo(null),Wo(F=>F===E?null:F)},[]),eu=m.useCallback((E,F,V)=>{Ho(),To(null),zn.current!=="walkthrough"&&(Wo(E),eo(F),nr(V),Wr(!0),es(!1),fe==null||fe("walls"))},[Ho,fe]),Qi=m.useRef(!1),mr=m.useCallback((E,F,V,at)=>{!tt||!G||G(tt.map(yt=>yt.id!==E?yt:F==="front"?V?{...yt,texture:V,color:void 0}:at?{...yt,color:at,texture:void 0}:{...yt,texture:void 0,color:void 0}:F==="back"?V?{...yt,backTexture:V,backColor:void 0}:at?{...yt,backColor:at,backTexture:void 0}:{...yt,backTexture:void 0,backColor:void 0}:V?{...yt,edgeTexture:V,edgeColor:void 0}:at?{...yt,edgeColor:at,edgeTexture:void 0}:{...yt,edgeTexture:void 0,edgeColor:void 0}))},[tt,G]),Ns=m.useCallback((E,F)=>{if(!ua)return null;let V=Te,at=E.entityId,yt=E.faceId,zt={entityId:at,faceId:yt};if(E.hostFaceRegion){const Kt=b3(Te,E.hostFaceRegion);if(!Kt)return null;V=Kt.entities,at=Kt.patch.id,yt="top",zt={entityId:at,faceId:yt},On==null||On(Kt.patch.id),to==null||to("top"),qe==null||qe(null)}return ua(YG(V,at,yt,F)),zt},[Te,ua,to,qe,On]),Ja=m.useCallback(E=>{const F=nt==null?void 0:nt.assignment;if(!q8(F))return;const V=F.texture?{texture:{...F.texture},color:void 0}:{color:F.color,texture:void 0},at=Ns(E,V);at&&K(yt=>yt&&{...yt,target:at})},[Ns,nt]);m.useCallback((E,F,V)=>{!tt||!G||G(tt.map(at=>E==="front"?F?{...at,texture:F,color:void 0}:V?{...at,color:V,texture:void 0}:{...at,texture:void 0,color:void 0}:E==="back"?F?{...at,backTexture:F,backColor:void 0}:V?{...at,backColor:V,backTexture:void 0}:{...at,backTexture:void 0,backColor:void 0}:F?{...at,edgeTexture:F,edgeColor:void 0}:V?{...at,edgeColor:V,edgeTexture:void 0}:{...at,edgeTexture:void 0,edgeColor:void 0}))},[tt,G]);const rs=Math.max(0,e.levels.findIndex(E=>E.id===s)),ce=e.levels[rs],nu=m.useMemo(()=>e.levels.map(E=>(E.elevation??0)*rt),[e.levels]),ga=nu[rs]??0,Xb=m.useMemo(()=>e.levels.map(E=>GA(E.walls)),[e.levels]),kl=m.useMemo(()=>e.levels.map(E=>Kw(E.walls,E.beams,E.furniture)),[e.levels]);m.useEffect(()=>{if(!ce)return;const E=new Set(ce.walls.map(F=>F.id));ma(F=>{let V=!1;const at=new Set;for(const yt of F)E.has(yt)?at.add(yt):V=!0;return V?at:F}),Zo(F=>F&&!E.has(F.wallId)?null:F)},[ce]),m.useEffect(()=>{if(!gn)return;const E=F=>{F.key==="Escape"&&Zo(null)};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[gn]),m.useEffect(()=>{if(!un&&!_r&&!ss&&!No)return;const E=F=>{F.key==="Escape"&&(hr(null),Ta(null),Ai(null),Er(null))};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[un,_r,ss,No]),m.useEffect(()=>{if(!fa)return;const E=F=>{F.key==="Escape"&&xa(null)};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[fa]),m.useEffect(()=>{if(!Ws&&!ys&&!et&&!H&&!nt&&!Ct&&!Dt&&!me&&!lt&&!cn&&!Oo&&!sr&&!ns&&!os&&!Fn&&!Mo)return;const E=F=>{F.key==="Escape"&&(yr(null),io(null),q(null),K(null),Q(null),jt(null),bt(null),Xt(null),xe(null),He(null),nn(null),Ks(null),Ls(null),ii(null),Zr(null),qr(null),re(null))};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[Ws,ys,et,H,nt,Ct,Dt,me,lt,cn,Oo,sr,ns,os,Fn,Mo]),m.useEffect(()=>{if(!ed)return;const E=F=>{F.key==="Escape"&&kr(null)};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[ed]),m.useEffect(()=>{if(!En)return;const E=F=>
278{F.key==="Escape"&&(En.onClose(),Fr(null))};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[En]);const Wi=m.useCallback(E=>{const F=E.templateEditTarget;if(!F)return;const V=Lg(E.x-18,E.y-18);qa({groupId:F.groupId,clickedEntityId:F.entityId,clickedFaceId:F.faceId??null,x:V.x,y:V.y,input:"",isSending:!1,messages:[{id:`assistant-${Date.now()}`,role:"assistant",content:"אני כאן. כתבו לי מה לשנות בתבנית הזו."}]})},[]),vl=m.useCallback(E=>{E.button!==0||!wr||(E.preventDefault(),E.currentTarget.setPointerCapture(E.pointerId),Zd.current={pointerId:E.pointerId,startClientX:E.clientX,startClientY:E.clientY,originX:wr.x,originY:wr.y})},[wr]),oh=m.useCallback(E=>{const F=Zd.current;if(!F||F.pointerId!==E.pointerId)return;E.preventDefault();const V=Lg(F.originX+E.clientX-F.startClientX,F.originY+E.clientY-F.startClientY);qa(at=>at&&{...at,x:V.x,y:V.y})},[]),Em=m.useCallback(E=>{const F=Zd.current;!F||F.pointerId!==E.pointerId||(Zd.current=null,E.currentTarget.hasPointerCapture(E.pointerId)&&E.currentTarget.releasePointerCapture(E.pointerId))},[]),ba=m.useCallback((E,F)=>F!=null&&F.length?`${E}
279${F.map(V=>`• ${V}`).join(`
280`)}`:E,[]);m.useEffect(()=>{if(!ro||I.current===ro.id)return;I.current=ro.id;const E=ba(ro.assistantMessageHe,ro.questions);qa(F=>({...F??{},groupId:ro.groupId,clickedEntityId:(F==null?void 0:F.clickedEntityId)??ro.groupId,clickedFaceId:(F==null?void 0:F.clickedFaceId)??null,...Lg((F==null?void 0:F.x)??Math.max(24,window.innerWidth-420),(F==null?void 0:F.y)??92),input:(F==null?void 0:F.input)??"",isSending:!1,jobId:F==null?void 0:F.jobId,messages:[...(F==null?void 0:F.messages)??[],{id:`assistant-${ro.id}`,role:"assistant",content:E}]}))},[ba,ro]),m.useEffect(()=>{if(!wr)return;const E=()=>{qa(F=>{if(!F)return F;const V=Lg(F.x,F.y);return V.x===F.x&&V.y===F.y?F:{...F,x:V.x,y:V.y}})};return window.addEventListener("resize",E),()=>window.removeEventListener("resize",E)},[wr]);const Ri=m.useCallback(async()=>{const E=wr;if(!E||E.isSending)return;const F=E.input.trim();if(!F)return;const V={id:`user-${Date.now()}`,role:"user",content:F};qa(at=>
280at&&at.groupId===E.groupId?{...at,input:"",isSending:!0,messages:[...at.messages,V]}:at);try{const at=ls?await ls({groupId:E.groupId,clickedEntityId:E.clickedEntityId,clickedFaceId:E.clickedFaceId,message:F}):{success:!1,status:"failed",assistantMessageHe:"החיבור לעורכת התבניות לא זמין כרגע."},yt={id:`assistant-${Date.now()}`,role:"assistant",content:ba(at.assistantMessageHe,at.questions)};qa(zt=>zt&&zt.groupId===E.groupId?{...zt,isSending:!1,jobId:at.jobId??zt.jobId,messages:[...zt.messages,yt]}:zt)}catch{qa(at=>at&&at.groupId===E.groupId?{...at,isSending:!1,messages:[...at.messages,{id:`assistant-${Date.now()}`,role:"assistant",content:"לא הצלחתי לשלוח את הבקשה. נסו שוב בעוד רגע."}]}:at)}},[ba,ls,wr]);m.useEffect(()=>{if(!nt)return;const E=F=>{jt({x:F.clientX,y:F.clientY})};return window.addEventListener("pointermove",E,{passive:!0}),()=>window.removeEventListener("pointermove",E)},[nt]),m.useEffect(()=>{if(!Eo)return;const E=F=>{F.key==="Escape"&&yl()};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[Eo,yl]),m.useMemo(()=>{if(!ps||!gs)return null;const E=L==null?void 0:L[ps];return(E==null?void 0:E.find(F=>F.id===gs))??null},[ps,gs,L]);const li=m.useMemo(()=>{var E;return(E=ce==null?void 0:ce.rooms)!=null&&E.length?ce.rooms.map(F=>la(F)).sort().join(";"):""},[ce]);m.useEffect(()=>{const E=ce==null?void 0:ce.rooms;if(!(E!=null&&E.length)){Ro(null),Si(null),Pi({});return}Ro(F=>k5(F,E)),Si(F=>k5(F,E)),Pi(F=>{const V=YE(F,E);return JSON.stringify(F)===JSON.stringify(V)?F:V})},[li]),m.useEffect(()=>{f||pc(null)},[f]);const Gf=m.useCallback(E=>{p==null||p(E)},[p]),no=m.useMemo(()=>{if(!u||!Ds||!u.autoFootprint||!u.canRender)return u;const E={...u.autoFootprint,outer:Ds.outer,holes:Ds.holes,rectangle:jb(Ds.outer)};return{...u,canRender:!0,reason:null,effectiveFootprint:E,footprint:E}},[Ds,u]),Ql=m.useMemo(()=>{const E=e.levels.filter(yo=>a[yo.id]!==!1),F=e.levels.map((yo,Bi)=>({l:yo,e:nu[Bi]??0})).filter(({l:yo})=>a[yo.id]!==!1).map(({e:yo})=>yo);if(E.length===0||!ce)return{span:1,centerX:0,centerZ:0,minX:0,maxX:0,minZ:0,maxZ:0,maxY:0};const V=XT(E,F);if(!d||!c||!(no!=null&&no.canRender)||!no.effectiveFootprint)return V;const at=c.overhangMm*rt,yt=no.effectiveFootprint.outer.map(yo=>yo.x*rt),zt=no.effectiveFootprint.outer.map(yo=>yo.y*rt),Kt=Math.min(...yt.map(yo=>yo-at)),ke=Math.max(...yt.map(yo=>yo+at)),de=Math.min(...zt.map(yo=>yo-at)),ue=Math.max(...zt.map(yo=>yo+at)),mn=Math.max(V.centerX-V.minX,V.maxX-V.centerX,V.centerX-Kt,ke-V.centerX),Yn=Math.max(V.centerZ-V.minZ,V.maxZ-V.centerZ,V.centerZ-de,ue-V.centerZ),Xe=V.centerX-mn,Sn=V.centerX+mn,mo=V.centerZ-Yn,vs=V.centerZ+Yn;return{minX:Xe,maxX:Sn,minZ:mo,maxZ:vs,centerX:V.centerX,centerZ:V.centerZ,span:Math.max(Sn-Xe,vs-mo,.1),maxY:Math.max(V.maxY,no.maxElevationMm*rt)}},[e.levels,a,nu,ce,d,c,no]),tc=d&&(o==="building"||(no==null?void 0:no.hostLevelId)===s),ou=kl[rs]??Ql,Uf=o==="building"||tc&&e.levels.length===1,oo=Uf?Ql:ou,od=Py(ce==null?void 0:ce.furniture),fr=Math.max(od,ce!=null&&ce.walls.length?Math.max(...ce.walls.map(E=>E.height*rt)):2.7),La=Uf?Ql.maxY:fr,su=o==="building"?e.levels.some(E=>a[E.id]!==!1&&Py(E.furniture)>0):od>0,wi=!ce||ce.walls.length===0&&ce.beams.length===0&&!su,ec=m.useMemo(()=>Math.max(mm(oo),La),[oo,La]),Qa=m.useMemo(()=>({x:oo.centerX,z:oo.centerZ}),[oo.centerX,oo.centerZ]),Yb=m.useMemo(()=>{const E=no==null?void 0:no.effectiveFootprint;return!d||!c||!(no!=null&&no.canRender)||!E?null:$A({requestId:b,footprint:E,overhangMm:c.overhangMm,baseElevationMm:no.baseElevationMm,maxElevationMm:no.maxElevationMm,planRotationDeg:hs,rotationCenter:Qa})},[c,no,hs,Qa,b,d]),ki=m.useMemo(()=>VT(ec),[ec]),Kf=m.useMemo(()=>ce?ce.walls.flatMap(E=>{if(Rr.has(E.id))return[];const F=E.end.x-E.start.x,V=E.end.y-E.start.y,at=Math.hypot(F,V);if(at<=1e-6)return[];const yt=-V/at,zt=F/at,Kt=E.thickness/2,ke=ue=>({x:yt*Kt*ue,y:zt*Kt*ue}),de=(ue,mn)=>{const Yn=ke(mn);return{id:`${E.id}:${ue}`,wallId:E.id,side:ue,a:{x:Math.round(E.start.x+Yn.x),y:Math.round(E.start.y+Yn.y)},b:{x:Math.round(E.end.x+Yn.x),y:Math.round(E.end.y+Yn.y)}}};return[de("front",1),de("back",-1)]}):[],[Rr,ce]),{sketchToolActive:ir,sketchInteractionActive:ci}=vH({compact:w,activeTool:$o,selectedEntityId:ho});m.useEffect(()=>{if(Fa)return Fa.classList.toggle("floorplan-sketch-pencil-cursor",ir),()=>{Fa.classList.remove("floorplan-sketch-pencil-cursor")}},[Fa,ir]);const Ma=m.useMemo(()=>ce&&ce.walls.length>0?Math.max(...ce.walls.map(E=>E.height))*rt:2.7,[ce]),wc=ce&&ce.rooms.length>0?ce.rooms[0]:null,kc=m.useMemo(()=>
280{if(!wc||!ce)return null;const E=ce.walls.filter(yt=>wc.wallIds.includes(yt.id));if(E.length===0)return null;let F=0,V=0,at=0;for(const yt of E)F+=yt.start.x*rt,V+=yt.start.y*rt,at++;return{x:F/at,z:V/at}},[wc,ce]),[Ce,ar]=m.useState(R||"orbit"),Oi=!!ve&&!!Ne&&!w,Dm=Ce==="inside"||ci&&!Oi,ru=m.useMemo(()=>HS({preset:Ce,compact:w}),[w,Ce]),sd=ru==="sketchup",[Qp,Gb]=m.useState({shadowMapEnabled:!1}),[t0,e0]=m.useState(0),Zf=m.useCallback(E=>{Gb(F=>{const V={...F,...E};return V.shadowMapEnabled===F.shadowMapEnabled?F:V})},[]),$n=m.useCallback(E=>{e0(F=>F===E.edgeOverlayCount?F:E.edgeOverlayCount)},[]);m.useEffect(()=>{sd||e0(0)},[sd]),m.useEffect(()=>{if(!w)return window.__floorplanVisualStyleDebug={enabled:sd,shadowMapEnabled:Qp.shadowMapEnabled,edgeOverlayCount:sd?t0:0},()=>{delete window.__floorplanVisualStyleDebug}},[w,sd,t0,Qp.shadowMapEnabled]),m.useEffect(()=>{},[w]);const[Fm,Tn]=m.useState(!1),sh=Ce!=="top"&&Ce!=="orbit"&&(Ce==="inside"||Ce==="walkthrough"&&co),jl=!w&&Ce==="orbit";m.useEffect(()=>{zn.current=Ce,cs({preset:Ce})},[Ce,cs]),m.useEffect(()=>{Ce!=="orbit"&&(Ho(),To(null))},[Ho,Ce]),m.useEffect(()=>{!pa||ce!=null&&ce.walls.some(E=>E.id===pa.wallId)||To(null)},[ce==null?void 0:ce.walls,pa]),m.useEffect(()=>{Ce!=="inside"&&(qr(null),re(null))},[Ce]),m.useEffect(()=>{Ps==null||Ps(Ce)},[Ce,Ps]),m.useEffect(()=>{Jl.current=bs,cs({selectedWallRegionId:bs})},[bs,cs]),m.useEffect(()=>{nh.current=ir,cs({sketchToolActive:ir})},[ir,cs]),m.useEffect(()=>{Jd.current=Jr,cs({sketchElementMoveActive:Jr})},[Jr,cs]),m.useEffect(()=>{$e.current=Eo,cs({figureRotateMode:Eo})},[Eo,cs]),m.useEffect(()=>{bl.current=Sa,cs({figureInteracting:Sa})},[Sa,cs]),m.useEffect(()=>{Ce!=="inside"&&(Wr(!1),Kr(null))},[Ce]);const[_l,Xn]=m.useState(1.6),[vc,tl]=m.useState(uU);m.useEffect(()=>{Qn&&(Xn(E=>{const F=tp(Qn.height,Ma);return Math.abs(E-F)<.01?E:F}),tl(E=>{const F=Ru.radToDeg(Qn.fov||q1);return Math.abs(E-F)<.1?E:F}))},[Qn==null?void 0:Qn.height,Qn==null?void 0:Qn.fov,Ma]);const iu=m.useMemo(()=>Qn??yF(oo,kc,{height:_l,fov:Ru.degToRad(vc)}),[oo,_l,Qn,vc,kc]),[Cr,qf]=m.useState(null),rh=m.useCallback(E=>{const F=Hr.current,V=F==null?void 0:F.object;if(!F||!V||zn.current!=="orbit")return;E(F,V);const at=F.enableDamping;F.enableDamping=!1,F.update(),F.enableDamping=at},[]),Jf=m.useCallback(E=>{rh((F,V)=>{V.updateMatrixWorld(!0);const at=Math.max(ec*.085,.28),yt=new le().setFromMatrixColumn(V.matrixWorld,0).normalize(),zt=new le().setFromMatrixColumn(V.matrixWorld,1).normalize(),Kt=new le;E==="left"&&Kt.addScaledVector(yt,at),E==="right"&&Kt.addScaledVector(yt,-at),E==="up"&&Kt.addScaledVector(zt,-at),E==="down"&&Kt.addScaledVector(zt,at),V.position.add(Kt),F.target.add(Kt)})},[rh,ec]),Cm=ej({preset:Ce,selectedWallRegionId:bs,figureInteracting:Sa||gl,figureRotateMode:Eo,sketchToolActive:ir,sketchElementMoveActive:Jr}),[$s,Nr]=m.useState(new Set),[jc,Hi]=m.useState(null),[ih,au]=m.useState(!1),Wa=m.useRef({sidebar:null,furnType:null,requestId:0}),el=m.useRef(!1),Ir=m.useRef(0),rd=m.useRef(0),Nm=m.useRef(0),qo=m.useRef(!1),ws=m.useCallback(E=>{qo.current=E,au(E)},[]),[xr,ah]=m.useState(null),n0=m.useMemo(()=>{if(!xr||!Ot)return null;const E=Ot.findIndex(F=>F.id===xr);return E>=0?E:null},[Ot,xr]),o0=m.useRef(Ot);o0.current=Ot;const ks=m.useCallback(E=>{var F,V;ah(E!==null&&E>=0?((V=(F=o0.current)==null?void 0:F[E])==null?void 0:V.id)??null:null)},[]),Ra=m.useCallback(()=>{Ho(),To(null),Qi.current=!1,Nr(new Set),Hi(null),dn==null||dn(),Zl(null),ks(null),Rt==null||Rt(null),Wo(null),x==null||x(!1),eo(null),Kr(null),Wr(!1),nr("front"),Ro(null),bo(null),Si(null),es(!1),qn(null),Or(null),ws(!1),Le==null||Le(),yl(),Cs()},[Ho,Cs,yl,Le,Rt,x,dn,ks,ws]),Ub=m.useCallback(E=>{Ra(),Qi.current=!0,Rt==null||Rt(E),fe==null||fe("beams")},[Ra,Rt,fe]),s0=m.useRef(s);m.useEffect(()=>{s0.current!==s&&(s0.current=s,Ra(),uu(!1),Dr(null),jm(null),Zo(null),yr(null),xa(null),Fr(null),io(null),bt(null),Xt(null),xe(null),He(null),Ks(null),Ls(null),ii(null))},[s,Ra]),m.useEffect(()=>{xr&&!(Ot!=null&&Ot.some(E=>E.id===xr))&&ah(null)},[Ot,xr]);const Kb=m.useCallback(E=>{if(Qi.current){Qi.current=!1;return}Ra()},[Ra]);m.useEffect(()=>{Pt==="furniture"&&ih&&!w&&ar("top")},[Pt,ih,w]),m.useEffect(()=>{!Oi||!is||(rd.current=0,ar("top"),ws(!1),Nr(new Set),Hi(null),dn==null||dn())},[ve,Oi,is,ws,dn]),m.useEffect(()=>{if(Pt!=="furniture"||!Ve){Wa.current={sidebar:Pt??null,furnType:Ve??null,requestId:en};return}const E=Wa.current,F=E.sidebar!=="furniture",V=E.requestId!==en;F&&el.current?el.current=!1:V&&(ws(!0),Nr(new Set),Hi(null),dn==null||dn(),ze==null||ze([])),Wa.
280current={sidebar:"furniture",furnType:Ve,requestId:en}},[Ve,Pt,en,ze,dn]);const Zb=m.useCallback((E,F)=>{Qi.current=!0,Un!=null&&Un.furnitureId&&Un.furnitureId!==E&&(dn==null||dn());let V=null;Nr(at=>{let yt;return F?(yt=new Set(at),yt.has(E)?yt.delete(E):yt.add(E)):yt=new Set([E]),V=Array.from(yt),yt}),ws(!1),Wo(null),es(!1),ks(null),Pt!=="furniture"&&(el.current=!0),U==null||U("furniture"),V!==null&&(ze==null||ze(V)),fe==null||fe("furniture")},[Pt,Un,U,fe,ze,dn]),Qf=m.useCallback(()=>{performance.now()<Nm.current||Ra()},[Ra]),id=m.useRef(Fe);id.current=Fe;const tx=m.useRef(so);tx.current=so;const nl=m.useRef(bn);nl.current=bn;const ex=m.useRef($s);ex.current=$s;const ad=m.useRef(dn);ad.current=dn;const Im=m.useCallback((E,F)=>{const V=id.current,at=tx.current,yt=nl.current;V&&yt&&at&&yt(V.map(zt=>zt.id===E?{...zt,position:{x:F.x/rt/at,y:F.z/rt/at}}:zt))},[]),lu=m.useCallback(E=>{const F=id.current,V=tx.current,at=nl.current;if(!F||!at||!V)return;const yt=E.x/rt/V,zt=E.z/rt/V,Kt=ex.current;at(F.map(ke=>Kt.has(ke.id)?{...ke,position:{x:ke.position.x+yt,y:ke.position.y+zt}}:ke))},[]),r0=m.useCallback((E,F)=>{const V=id.current,at=nl.current;V&&at&&at(V.map(yt=>yt.id===E?{...yt,rotation:F}:yt))},[]),cu=m.useCallback(E=>{const F=id.current,V=tx.current,at=nl.current;if(!F||!at||!V)return;const yt=dF(F,E,V);yt&&(at(yt.next),Nr(new Set([yt.newId])))},[]),du=m.useCallback(E=>{const F=id.current,V=nl.current;F&&V&&V(F.map(at=>at.id===E?{...at,flipped:!at.flipped}:at))},[]),ld=m.useCallback(E=>{var at;const F=id.current,V=nl.current;!F||!V||(V(F.filter(yt=>yt.id!==E)),Nr(yt=>
280{const zt=new Set(yt);return zt.delete(E),zt}),Hi(null),(at=ad.current)==null||at.call(ad))},[]),lh=m.useCallback((E,F,V,at)=>{const yt=id.current,zt=nl.current;yt&&zt&&zt(yt.map(Kt=>Kt.id===E?{...Kt,widthMm:F,depthMm:V,heightMm:at}:Kt))},[]),cd=m.useCallback((E,F,V)=>{var ke;if(!bn||Fe==null||!so)return ws(!1),!1;const at=(V==null?void 0:V.trim())||((ke=pi[E])==null?void 0:ke.label);at&&pi[E]&&(pi[E]={...pi[E],label:at});const yt={x:F.x/rt/so,y:F.z/rt/so},zt=`furn_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,Kt=[...Fe,{id:zt,type:E,label:at,position:yt,rotation:0}];return bn(Kt),Pr("itemPlace"),ws(!1),Nr(new Set),Hi(null),dn==null||dn(),ze==null||ze([]),Nm.current=performance.now()+500,on==null||on(),!0},[so,bn,on,ze,dn,ws,Fe]),i0=m.useCallback(E=>{if(!qo.current){Qf();return}if(!Ve){ws(!1);return}const F=performance.now();F-Ir.current<400||(Ir.current=F,cd(Ve,E))},[Ve,Qf,cd,ws]),ch=m.useCallback(E=>{if(!Oi||!Ne)return;const F=performance.now();F-rd.current<400||(rd.current=F,Ne(o3(E)))},[Ne,Oi]);m.useEffect(()=>{const E=F=>{var V,at;if((F.key==="Delete"||F.key==="Backspace")&&$s.size>0&&Fe&&bn){if(((V=F.target)==null?void 0:V.tagName)==="INPUT"||((at=F.target)==null?void 0:at.tagName)==="TEXTAREA")return;bn(Fe.filter(yt=>!$s.has(yt.id))),Pr("itemDelete"),Nr(new Set),Hi(null),Zl(null),dn==null||dn()}};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[$s,Fe,bn,dn]),m.useEffect(()=>{const E=F=>{if(F.key!=="Delete"&&F.key!=="Backspace"||!Mt||!Y||!J)return;const V=F.target;V&&(V.tagName==="INPUT"||V.tagName==="TEXTAREA"||V.isContentEditable)||(F.preventDefault(),J(Y.filter(at=>at.id!==Mt)),Rt==null||Rt(null),Pr("itemDelete"))};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[Rt,J,Mt,Y]),m.useEffect(()=>{Mt&&!(Y!=null&&Y.some(E=>E.id===Mt))&&(Rt==null||Rt(null))},[Rt,Mt,Y]),m.useEffect(()=>{const E=F=>{var V,at;if(F.key==="r"&&$s.size>0&&Fe&&bn){if(((V=F.target)==null?void 0:V.tagName)==="INPUT"||((at=F.target)==null?void 0:at.tagName)==="TEXTAREA")return;bn(Fe.map(yt=>$s.has(yt.id)?{...yt,rotation:(yt.rotation+1)%360}:yt)),Pr("itemRotate")}};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[$s,Fe,bn]),m.useEffect(()=>{const E=F=>{if(F.key!=="Escape")return;const V=F.target;V&&(V.tagName==="INPUT"||V.tagName==="TEXTAREA"||V.tagName==="SELECT")||(F.preventDefault(),Ra())};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[Ra]),m.useEffect(()=>{js==null||js({wallId:ts,wallSide:yi,wallRegionId:bs,roomSig:ps,regionId:gs,ceilingRoomSig:Zi})},[ts,yi,bs,ps,gs,Zi,js]),m.useEffect(()=>{Mt&&(ts||xr||$s.size>0||ps||gs||Zi||h)&&(Rt==null||Rt(null))},[Rt,Mt,Zi,$s,xr,gs,ps,ts,h]),m.useEffect(()=>{ze==null||ze(Array.from($s))},[$s,ze]),m.useEffect(()=>{Un&&($s.has(Un.furnitureId)||dn==null||dn())},[$s,Un,dn]),m.useEffect(()=>{jc&&($s.has(jc)||Hi(null))},[$s,jc]),m.useEffect(()=>{const E=Un==null?void 0:Un.furnitureId;E&&o==="floor"&&$s.has(E)&&(Fe!=null&&Fe.some(F=>F.id===E&&F.type.startsWith("blender_")))?(Hi(E),ws(!1)):Fe!=null&&Fe.some(F=>F.id===jc&&F.type.startsWith("blender_"))&&Hi(null)},[Un,$s,Fe,o,jc,ws]),m.useEffect(()=>{Kd&&($s.has(Kd)||Zl(null))},[Kd,$s]);const[dh,uu]=m.useState(!0),{wall:dd,floor:uh,ceiling:nx}=U_(),ta=dd,di=m.useMemo(()=>{const E=[...dd,...uh,...nx],F=new Set;return E.filter(V=>F.has(V.value)?!1:(F.add(V.value),!0))},[dd,uh,nx]);m.useEffect(()=>{Ce==="inside"&&(ks(null),Wo(null),ws(!1))},[Ce]);const hh=m.useCallback(E=>{Qi.current=!0,Ro(E),bo(null),Wo(null),ks(null),Nr(new Set)},[]),hu=m.useCallback((E,F,V,at)=>{ci||Ce!=="walkthrough"&&(!he&&!pe&&!te&&!(Ce==="inside"&&Hn)||(Qi.current=!0,Pa.current=!0,Cs(),hr({roomSig:E,regionId:at,pointMm:{x:Math.round(F.xMm),y:Math.round(F.yMm)},x:V.x,y:V.y})))},[Cs,ci,Ce,he,pe,te,Hn]),Tm=m.useCallback(E=>{Qi.current=!0,Ro(E),bo(null),Wo(null),ks(null),Nr(new Set),es(!0),U==null||U("edit"),fe==null||fe("floor")},[U,fe]),a0=m.useCallback((E,F)=>{Qi.current=!0,Ro(E),bo(F),Wo(null),ks(null),Nr(new Set),es(!0),U==null||U("edit"),fe==null||fe("floor")},[U,fe]),qb=m.useCallback(E=>{Qi.current=!0,Ro(E),bo(null),Wo(null),ks(null),Nr(new Set),es(!0),U==null||U("edit"),fe==null||fe("floor")},[U,fe]),Jb=m.useCallback((E,F,V)=>{if(!A)return;const yt=((L==null?void 0:L[E])??[]).map(zt=>zt.id===F?{...zt,polygon:V}:zt);A(E,yt)},[A,L]);m.useCallback(E=>{const F=ce.rooms.find(yt=>la(yt)===E);if(!F||!F.vertices||F.vertices.length<3)return;const V=(N??{}
280)[E],at={id:`region_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,polygon:F.vertices.map(yt=>({x:yt.x,y:yt.y})),textureUrl:(V==null?void 0:V.textureUrl)??C,color:V==null?void 0:V.color,tileWidthCm:(V==null?void 0:V.tileWidthCm)??Tt,tileHeightCm:(V==null?void 0:V.tileHeightCm)??Zt,groutWidthMm:(V==null?void 0:V.groutWidthMm)??At,groutColor:(V==null?void 0:V.groutColor)??ut,tileOriginXMm:V==null?void 0:V.tileOriginXMm,tileOriginYMm:V==null?void 0:V.tileOriginYMm};A==null||A(E,[at]),P==null||P(E,null),bo(at.id)},[ce.rooms,P,A,N,C,Tt,Zt,At,ut]),m.useCallback(E=>{const F=(L==null?void 0:L[E])??[];if(F.length===0)return;const V=F[0];P==null||P(E,{textureUrl:V.textureUrl,color:V.color,tileWidthCm:V.tileWidthCm,tileHeightCm:V.tileHeightCm,groutWidthMm:V.groutWidthMm,groutColor:V.groutColor,tileOriginXMm:V.tileOriginXMm,tileOriginYMm:V.tileOriginYMm}),A==null||A(E,null),bo(null)},[P,A,L]);const l0=m.useCallback((E,F)=>{const at=((L==null?void 0:L[E])??[]).filter(yt=>yt.id!==F);at.length===0?A==null||A(E,null):A==null||A(E,at),bo(null)},[A,L]);m.useCallback(E=>{if(!ps)return!1;const F=(L==null?void 0:L[ps])??[];if(gs){const V=F.map(at=>at.id===gs?{...at,...E,id:at.id,polygon:at.polygon}:at);return A==null||A(ps,V),!0}if(F.length>0){const{id:V,polygon:at,...yt}=E,zt=(N==null?void 0:N[ps])??{};return P==null||P(ps,{...zt,...yt}),bo(null),!0}return!1},[P,A,N,L,gs,ps]),m.useMemo(()=>{if(!ts||!bs)return null;const E=`${ts}__${yi}`,F=S==null?void 0:S[E];return(F==null?void 0:F.find(V=>V.id===bs))??null},[ts,yi,bs,S]);const c0=m.useCallback((E,F,V)=>{Qi.current=!0,Wo(E),nr(F),Kr(V),Wr(!0),es(!1),Ro(null),bo(null),ks(null),Nr(new Set),fe==null||fe("walls")},[fe]),d0=m.useCallback((E,F)=>{Qi.current=!0,Wo(E),nr(F),Kr(null),Wr(!0),es(!1),Ro(null),bo(null),ks(null),Nr(new Set),fe==null||fe("walls")},[fe]),Sm=m.useCallback((E,F,V,at)=>{if(!B)return;const yt=`${E}__${F}`,Kt=((S==null?void 0:S[yt])??[]).map(ke=>ke.id===V?{...ke,polygon:at}:ke);B(yt,Kt)},[B,S]),u0=m.useCallback((E,F)=>{if(!tt||!G)return;const V=tt.find(Sn=>Sn.id===E);if(!V)return;const at=ce.walls.find(Sn=>Sn.id===E);if(!at)return;const yt=at.end.x-at.start.x,zt=at.end.y-at.start.y,Kt=Math.sqrt(yt*yt+zt*zt),ke=at.height,de=[{u:0,v:0},{u:Kt,v:0},{u:Kt,v:ke},{u:0,v:ke}],ue=F==="front"?V.texture:V.backTexture??V.texture,mn=F==="front"?V.color:V.backColor??V.color,Yn={id:`wallregion_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,polygon:de,textureUrl:ue==null?void 0:ue.url,color:mn,tileWidthCm:ue==null?void 0:ue.tileWidthCm,tileHeightCm:ue==null?void 0:ue.tileHeightCm,orientation:ue==null?void 0:ue.orientation,groutWidthMm:ue==null?void 0:ue.groutWidthMm,groutColor:ue==null?void 0:ue.groutColor},Xe=`${E}__${F}`;B==null||B(Xe,[Yn]),mr(E,F,void 0),Kr(Yn.id)},[tt,G,ce.walls,B,mr]),h0=m.useCallback((E,F)=>{const V=`${E}__${F}`,at=(S==null?void 0:S[V])??[];if(at.length===0)return;const yt=at[0];
280if(yt.textureUrl&&!yt.textureUrl.startsWith("#")){const zt={url:yt.textureUrl,tileWidthCm:yt.tileWidthCm??100,tileHeightCm:yt.tileHeightCm??270,groutWidthMm:yt.groutWidthMm??3,groutColor:yt.groutColor??"#c8c4bc",orientation:ei(yt.orientation)};mr(E,F,zt)}else yt.color?mr(E,F,void 0,yt.color):mr(E,F,void 0);B==null||B(V,null),Kr(null)},[S,B,mr]),ud=m.useCallback((E,F,V)=>{const at=`${E}__${F}`,zt=((S==null?void 0:S[at])??[]).filter(Kt=>Kt.id!==V);zt.length===0?B==null||B(at,null):B==null||B(at,zt),Kr(null)},[S,B]);m.useCallback(E=>{if(!ts)return!1;const F=`${ts}__${yi}`,V=(S==null?void 0:S[F])??[];if(bs){const at=V.map(yt=>yt.id===bs?{...yt,...E,id:yt.id,polygon:yt.polygon}:yt);return B==null||B(F,at),!0}if(V.length>0){const at=ce.walls.find(ue=>ue.id===ts);if(!at)return!0;const yt=at.end.x-at.start.x,zt=at.end.y-at.start.y,Kt=Math.sqrt(yt*yt+zt*zt),ke=at.height,de={...E,id:`wallregion_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,polygon:[{u:0,v:0},{u:Kt,v:0},{u:Kt,v:ke},{u:0,v:ke}]};return B==null||B(F,[de,...V]),Kr(de.id),!0}return!1},[ce.walls,ts,yi,bs,S,B]),m.useEffect(()=>{Qs&&ks(null)},[Qs]),m.useEffect(()=>{const E=F=>{var V,at;if((F.key==="Delete"||F.key==="Backspace")&&xr&&Ot&&Ue){if(((V=F.target)==null?void 0:V.tagName)==="INPUT"||((at=F.target)==null?void 0:at.tagName)==="TEXTAREA")return;const yt=Ot.find(zt=>zt.id===xr);if(!yt){ah(null);return}Ue(Ot.filter(zt=>zt.id!==xr&&(!(yt!=null&&yt.cornerGroupId)||zt.cornerGroupId!==yt.cornerGroupId))),ah(null)}};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[xr,Ot,Ue]),m.useEffect(()=>{const E=F=>{if(F.key!=="Delete"&&F.key!=="Backspace"||!ps||!gs)return;const V=F.target;(V==null?void 0:V.tagName)==="INPUT"||(V==null?void 0:V.tagName)==="TEXTAREA"||l0(ps,gs)};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[ps,gs,l0]),m.useEffect(()=>{const E=F=>{if(F.key!=="Delete"&&F.key!=="Backspace"||!ts||!bs||yi==="edge")return;const V=F.target;(V==null?void 0:V.tagName)==="INPUT"||(V==null?void 0:V.tagName)==="TEXTAREA"||ud(ts,yi,bs)};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[ts,bs,yi,ud]);const ya=m.useCallback(E=>{if(!Ot)return;const F=Ot.findIndex(V=>V.id===E);F!==-1&&(ks(F),uu(!1),sn==null||sn(null),U==null||U("opening"),Wo(null),es(!1),fe==null||fe("openings"))},[Ot,U,sn,fe]),m0=m.useCallback((E,F)=>{if(!so||!ce)return;const V=ce.walls.find(vs=>vs.id===E);if(!V)return;const at=V.start.x*rt,yt=V.start.y*rt,zt=V.end.x*rt,Kt=V.end.y*rt,ke=zt-at,de=Kt-yt,ue=ke*ke+de*de;if(ue===0)return;const mn=Math.max(0,Math.min(1,((F.x-at)*ke+(F.z-yt)*de)/ue)),Yn=Math.sqrt(ue)/rt,Xe=mn*Yn/so;if(Ot)for(let vs=0;vs<Ot.length;vs++){const yo=Ot[vs];if(yo.wallId!==E)continue;const Bi=yo.preset?qs[yo.preset]:null,bu=(yo.widthMm||(Bi==null?void 0:Bi.width)||900)/so/2;if(Math.abs(Xe-yo.positionPx)<bu+20){ks(vs);return}}if(!vn||!Qs){ks(null);return}const Sn=qs[Qs];if(!Sn)return;if(FF(Qs)){const vs=EF(tt??[],E,Xe,so);if(!vs){ks(null);return}const yo=`opening_corner_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,Bi=DF(vs,{groupId:yo,primaryId:`opening_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,returnId:`opening_${Date.now()}_${Math.random().toString(36).slice(2,8)}`});Ue&&Ot?Ue([...Ot,...Bi]):Bi.forEach(vn),Pr("itemPlace"),sn==null||sn(null),ks(null);return}const mo=`opening_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;vn({id:mo,type:Sn.category,preset:Qs,wallId:E,positionPx:Xe,...Sn.hasSwing?rm({hingeSide:"left",swingFace:"front"}):{},...lE(Qs)}),Pr("itemPlace"),sn==null||sn(null),ks(null)},[dh,vn,Qs,sn,so,ce,Ot,Ue,tt]),f0=m.useCallback((E,F,V)=>{if(!cn||!dr||!ce)return;const at=ce.walls.find(ke=>ke.id===E);if(!at)return;const yt=OB(at,{...F,y:F.y-ga},cn);if(!yt)return;const zt=AB(cn.kind);let Kt;cn.kind==="switch"?Kt={id:zt,type:"switch",gangs:cn.gangs,wallId:E,wallSide:V==="back"?"back":"front",positionAlongWallMm:yt.positionAlongWallMm,centerHeightMm:yt.centerHeightMm}:cn.kind==="socket"?Kt={id:zt,type:"socket",outlets:cn.outlets,wallId:E,wallSide:V==="back"?"back":"front",positionAlongWallMm:yt.positionAlongWallMm,centerHeightMm:yt.centerHeightMm}:cn.kind==="tv"?Kt={id:zt,type:"tv",inches:cn.inches,wallId:E,wallSide:V==="back"?"back":"front",positionAlongWallMm:yt.positionAlongWallMm,centerHeightMm:yt.centerHeightMm}
280:Kt={id:zt,type:"ac",wallId:E,wallSide:V==="back"?"back":"front",positionAlongWallMm:yt.positionAlongWallMm,centerHeightMm:yt.centerHeightMm},dr([...Vn,Kt]),nn(null),He(null),qn(zt),Ks({fixtureId:zt,x:Math.max(12,Math.min(window.innerWidth/2-140,window.innerWidth-292)),y:Math.max(12,Math.min(window.innerHeight/2-160,window.innerHeight-332))})},[cn,dr,ce,Vn,ga]),Pm=m.useCallback((E,F)=>{qn(E),Ks({fixtureId:E,x:F.x,y:F.y}),nn(null),He(null)},[]),Am=m.useCallback(E=>{nn(E),He(null)},[]),hd=m.useCallback((E,F)=>{dr&&dr(Vn.map(V=>V.id===E?{...V,...F}:V))},[dr,Vn]),ea=m.useCallback(E=>{dr&&(dr(Vn.filter(F=>F.id!==E)),qn(F=>F===E?null:F),Ks(F=>(F==null?void 0:F.fixtureId)===E?null:F))},[dr,Vn]),ox=m.useCallback(E=>{ii({colorId:E.colorId,contentHtml:zc(E.contentHtml)}),Ls(null),nn(null),He(null),Ks(null)},[]),vr=m.useCallback((E,F,V,at)=>{if(!ns||!fs||!ce)return;const yt=ce.walls.find(ue=>ue.id===E);if(!yt)return;const zt=UB(yt,{...F,y:F.y-ga});if(!zt)return;const Kt=t9(),ke={id:Kt,wallId:E,wallSide:V==="back"?"back":"front",positionAlongWallMm:zt.positionAlongWallMm,centerHeightMm:zt.centerHeightMm,colorId:ns.colorId,contentHtml:ns.contentHtml};fs([...Ii,ke]),ii(null),Or(Kt);const de=nj(at.x,at.y);Zr({noteId:Kt,x:de.x,y:de.y})},[ns,fs,ce,Ii,ga]),x0=m.useCallback((E,F)=>{Or(E);const V=nj(F.x,F.y);Zr({noteId:E,x:V.x,y:V.y}),ii(null),Ls(null),nn(null),He(null)},[]),Oa=m.useCallback((E,F)=>{fs&&fs(Ii.map(V=>V.id===E?{...V,...F,contentHtml:F.contentHtml?zc(F.contentHtml):V.contentHtml}:V))},[fs,Ii]),mu=m.useCallback(E=>{fs&&(fs(Ii.filter(F=>F.id!==E)),Or(F=>F===E?null:F),Zr(F=>(F==null?void 0:F.noteId)===E?null:F))},[fs,Ii]),md=m.useCallback((E,F={x:0,y:0})=>{var zt;const V=(zt=ha.current)==null?void 0:zt.getBoundingClientRect();if(!V)return null;const at=B8(E.x-F.x,V.left,V.width,y7+W8),yt=B8(E.y-F.y,V.top,V.height,w7+W8);return{xPct:at,yPct:yt}},[]),mh=m.useCallback(E=>{if(!Hn||zn.current!=="inside")return;const F=md(E);F&&(qr({x:E.x,y:E.y,xPct:F.xPct,yPct:F.yPct}),re(null),Ke(null),Ls(null),ii(null),Zr(null))},[md,Hn]),Lm=m.useCallback(E=>{if(!Fn||!Hn)return;const F=n9(),V={id:F,xPct:Fn.xPct,yPct:Fn.yPct,colorId:E.colorId,contentHtml:zc(E.contentHtml),hidden:!1,createdAt:new Date().toISOString()};Hn([...Uo,V]),qr(null),Ke(F)},[Fn,Hn,Uo]),_c=m.useCallback((E,F)=>{Hn&&Hn(Uo.map(V=>V.id===E?{...V,...F,contentHtml:F.contentHtml?zc(F.contentHtml):V.contentHtml}:V))},[Hn,Uo]),p0=m.useCallback(E=>{_c(E,{hidden:!0}),Ke(F=>F===E?null:F),re(F=>(F==null?void 0:F.noteId)===E?null:F)},[_c]),fh=m.useCallback(E=>{Hn&&(Hn(Uo.filter(F=>F.id!==E)),Ke(F=>F===E?null:F),re(F=>(F==null?void 0:F.noteId)===E?null:F))},[Hn,Uo]),Ec=m.useCallback((E,F)=>{Ke(E),re({noteId:E,x:F.x,y:F.y}),qr(null)},[]),Wm=m.useCallback((E,F)=>{Ec(E,sU(F.getBoundingClientRect()))},[Ec]),an=m.useCallback((E,F)=>{var at,yt,zt;if(E.button!==0||(at=E.target)!=null&&at.closest("[data-floorplan-viewport-note-action]"))return;E.preventDefault(),E.stopPropagation();const V=E.currentTarget.getBoundingClientRect();_n.current={noteId:F.id,pointerId:E.pointerId,startClientX:E.clientX,startClientY:E.clientY,offsetX:E.clientX-V.left,offsetY:E.clientY-V.top,dragged:!1},Ke(F.id),re(Kt=>(Kt==null?void 0:Kt.noteId)===F.id?null:Kt),(zt=(yt=E.currentTarget).setPointerCapture)==null||zt.call(yt,E.pointerId)},[]),Qb=m.useCallback(E=>{const F=_n.current;if(!F||F.pointerId!==E.pointerId)return;E.preventDefault(),E.stopPropagation();const V=E.clientX-F.startClientX,at=E.clientY-F.startClientY;!F.dragged&&Math.hypot(V,at)>=3&&(F.dragged=!0);const yt=md({x:E.clientX,y:E.clientY},{x:F.offsetX,y:F.offsetY});yt&&_c(F.noteId,yt)},[md,_c]),Rm=m.useCallback(E=>{var V,at;const F=_n.current;!F||F.pointerId!==E.pointerId||(E.preventDefault(),E.stopPropagation(),F.dragged&&(jo.current={noteId:F.noteId,at:Date.now()}),_n.current=null,(at=(V=E.currentTarget).releasePointerCapture)==null||at.call(V,E.pointerId))},[]);m.useEffect(()=>{var V;if(!ur)return;const E=Ms.current.find(at=>at.id===ur.id),F=(V=ha.current)==null?void 0:V.getBoundingClientRect();!E||!F||E.hidden||(zn.current!=="inside"&&ar("inside"),Ke(E.id),qr(null),re(null))},[ur==null?void 0:ur.id,ur==null?void 0:ur.nonce]);const[na,nc]=m.useState(0),Br=m.useRef("in"),fd=m.useRef({x:0,z:0,angle:0,fov:0}),xh=m.useRef(null),xd=m.useRef(null),ol=m.useRef(null),Dc=m.useRef(null),ph=m.useRef(Je);ph.current=Je;const Os=m.useRef(null),sl=m.useRef(null),Om=m.useRef(new Map),pd=m.useRef(new Map),[g0,El]=m.useState(!1),[ui,vi]=m.useState("idle"),[rl,We]=m.useState(null),Hs=m.useRef([]),[fu,xu]=m.useState(0),[tM,sx]=m.useState([]),[pu,rx]=m.useState(null),[gh,il]=m.useState(null),[Hm,eM]=m.useState(null);m.useEffect(()=>(xs==null||xs(ui==="recording"),()=>xs==null?void 0:xs(!1)),[xs,ui]);const b0=m.useRef(null),bh=m.useRef(null),[nM,ix]=m.useState(0),[Bm,M0]=m.useState(Yv),[Cn,oM]=m.useState("render"),sM=Cm||f||ui==="playing"||ui==="exporting",gd=m.useCallback((E,F)=>{xh.current={x:E,z:F}},[]),Mh=m.useCallback(E=>{xd.current=E},[]),Fc=m.useCallback((E,F,V)=>{ol.current={x:E,z:F,mode:V}},[]),y0=m.useCallback(E=>{var F;E==="steer"&&((F=ol.current)==null?void 0:F.mode)==="steer"&&(ol.current=null)},[]),yh=m.useCallback(()=>{const E=Mi.current;
280if(!(E!=null&&E.captureStream)||typeof MediaRecorder>"u")return;const F=Xv();if(!F)return;let V=null,at;try{V=E.captureStream(60);const mn=Math.min(Ov,Math.max(Rv,Math.round(E.width*E.height*60*.3)));at=new MediaRecorder(V,{mimeType:F,videoBitsPerSecond:mn})}catch{V==null||V.getTracks().forEach(mn=>mn.stop());return}const yt=V,zt=[];let Kt=!1,ke=()=>{};const de=new Promise(mn=>{ke=mn}),ue=mn=>{Kt||(Kt=!0,yt.getTracks().forEach(Yn=>Yn.stop()),ke(mn))};at.ondataavailable=mn=>{mn.data.size>0&&zt.push(mn.data)},at.onerror=()=>ue(null),at.onstop=()=>{const mn=at.mimeType||F,Yn=new Blob(zt,{type:mn});ue(Yn.size>0?{blob:Yn,mimeType:Yn.type||mn}:null)};try{at.start(250),sl.current={recorder:at,stream:yt,done:de,abort:()=>ue(null)}}catch{ue(null)}},[]),Vm=m.useCallback(()=>{const E=sl.current;if(sl.current=null,!E)return Promise.resolve(null);if(E.recorder.state!=="inactive")try{E.recorder.requestData(),E.recorder.stop()}catch{E.abort()}return E.done},[]),ax=m.useCallback(async(E,F)=>{const V=await F;if(Om.current.delete(E.id),!V||(pd.current.set(E.id,V),!vo))return;let at=null;try{at=await vo(E,V.blob,V.mimeType)}catch{return}if(!at)return;const yt=ph.current;if(!yt.some(Kt=>Kt.id===E.id))return;const zt=yt.map(Kt=>Kt.id===E.id?{...Kt,videoAssetId:at.id,videoUrl:at.url,videoMimeType:at.mimeType,videoStoragePath:at.storagePath,videoCaptureSource:"live-canvas",videoExportMode:void 0}:Kt);ph.current=zt,rn==null||rn(zt)},[vo,rn]),w0=m.useMemo(()=>{const E=(ce==null?void 0:ce.walls.map(yt=>yt.id))??[],F=(ce==null?void 0:ce.openings.map(yt=>yt.id))??[],V=(ce==null?void 0:ce.furniture.map(yt=>yt.id))??[],at=Te.map(yt=>yt.id);return[`r:${hs}`,`w:${[...E].sort().join(",")}`,`o:${[...F].sort().join(",")}`,`f:${[...V].sort().join(",")}`,`s:${[...at].sort().join(",")}`].join("|")},[Te,ce==null?void 0:ce.furniture,ce==null?void 0:ce.openings,ce==null?void 0:ce.walls,hs]),Cc=m.useCallback(E=>{var Kt;const F=Ki.current,V=(Kt=Hr.current)==null?void 0:Kt.target,at=fd.current,yt={x:F.x+Math.sin(at.angle||0)*2,y:F.y,z:F.z+Math.cos(at.angle||0)*2},zt=at.fov>0?Ru.radToDeg(at.fov):vc;return{tMs:E,position:[F.x,F.y||_l,F.z],target:V?[V.x,V.y,V.z]:[yt.x,yt.y,yt.z],fov:zt}},[_l,vc]),hi=m.useCallback(()=>{Dc.current&&(Dc.current.stopRequested=!0),il(null),ol.current=null},[]),gu=m.useCallback((E,F)=>{hi();const V=Cc(0);return ar("inside"),El(!0),Tn(!1),vi(F),xu(0),il(E.id),rx({x:E.keyframes[0].position[0],z:E.keyframes[0].position[2]}),new Promise(at=>{Dc.current={recording:E,startedAt:performance.now(),restoreFrame:V,onComplete:()=>{vi("idle"),xu(0),rx(null),il(null),at()}}})},[Cc,hi]),zm=m.useCallback(()=>{for(const E of Hs.current)clearTimeout(E);Hs.current=[],We(null)},[]),Vr=m.useCallback(()=>{var at;if(w||ui==="recording")return!1;hi(),(at=Os.current)!=null&&at.interval&&clearInterval(Os.current.interval),ar("inside"),El(!1),Tn(!1),vi("recording"),xu(0),sx([]),il(null),yh();const E=performance.now(),F=()=>{const yt=Math.min(K1,Math.max(0,performance.now()-E)),zt=Cc(yt),Kt=Os.current;if(!Kt)return;const ke=Kt.keyframes[Kt.keyframes.length-1]??null;zv(ke,zt)&&(Kt.keyframes.push(zt),sx([...Kt.keyframes])),xu(yt),yt>=K1&&Ko.current.stopWalkthroughRecording()},V=setInterval(F,QO);return Os.current={startedAt:E,interval:V,keyframes:[]},F(),!0},[w,Cc,yh,hi,ui]),Dl=m.useCallback(()=>w||ui==="recording"||rl!==null?!1:(zm(),hi(),ar("inside"),El(!1),Tn(!1),We(3),Hs.current=[setTimeout(()=>We(2),1e3),setTimeout(()=>We(1),2e3),setTimeout(()=>{Hs.current=[],We(null),Ko.current.startWalkthroughRecording()},3e3)],!0),[zm,w,hi,rl,ui]),Fl=m.useCallback(()=>{const E=Os.current;if(!E)return null;const F=Vm();E.interval&&clearInterval(E.interval),El(!0);const V=Cc(Math.max(0,performance.now()-E.startedAt)),at=E.keyframes[E.keyframes.length-1]??null;(zv(at,V)||at!==null&&V.tMs>at.tMs)&&E.keyframes.push(V),Os.current=null,ol.current=null,vi("idle"),xu(0),sx([]);const yt=oH({keyframes:E.keyframes,planRotationDeg:hs,sceneFingerprint:w0});if(!yt)return ln.error(It("walkthrough.notEnoughPath",{defaultValue:"לא הוקלט מספיק מסלול"})),null;const zt=[yt,...ph.current.filter(Kt=>Kt.id!==yt.id)];
280return ph.current=zt,rn==null||rn(zt),Om.current.set(yt.id,F),ax(yt,F),il(yt.id),ln.success(It("walkthrough.saved",{defaultValue:"הסיור נשמר"})),yt},[ax,Cc,rn,hs,Vm,It,w0]),k0=m.useCallback(async E=>{const F=Mi.current;if(!(F!=null&&F.captureStream)||typeof MediaRecorder>"u")return ln.error(It("walkthrough.captureUnsupported",{defaultValue:"הדפדפן לא תומך בהקלטת וידאו מהקנבס"})),null;const V=Xv();if(!V)return ln.error(It("walkthrough.noSupportedFormat",{defaultValue:"לא נמצא פורמט וידאו נתמך בדפדפן"})),null;const at=F.captureStream(Wv),yt=[],zt=Math.min(Ov,Math.max(Rv,Math.round(F.width*F.height*Wv*.3)));let Kt;try{Kt=new MediaRecorder(at,{mimeType:V,videoBitsPerSecond:zt})}catch{return at.getTracks().forEach(de=>de.stop()),ln.error(It("walkthrough.recorderFailed",{defaultValue:"יצירת מקליט הווידאו נכשלה"})),null}const ke=new Promise((de,ue)=>{Kt.ondataavailable=mn=>{mn.data.size>0&&yt.push(mn.data)},Kt.onerror=()=>ue(new Error("MediaRecorder failed")),Kt.onstop=()=>{de(new Blob(yt,{type:Kt.mimeType||V}))}});try{Kt.start(500),await new Promise(ue=>requestAnimationFrame(()=>ue())),await gu(E,"exporting"),Kt.state!=="inactive"&&Kt.stop();const de=await ke;return{blob:de,mimeType:de.type||V}}catch{return Kt.state!=="inactive"&&Kt.stop(),ln.error(It("walkthrough.exportFailed",{defaultValue:"ייצוא הווידאו נכשל"})),null}finally{at.getTracks().forEach(de=>de.stop())}},[gu,It]),$m=m.useCallback(async(E,F="render",V=Yv)=>{const at=b0.current,yt=F==="render"?lF:a1[V],zt=F==="render"?Math.min(E.durationMs,L3):E.durationMs;if(at&&lH()){const Kt=Cc(0);hi(),ar("inside"),vi("exporting"),ix(0);const ke=new AbortController;bh.current=ke,await new Promise(de=>window.setTimeout(de,180));try{at.beginExport(yt.width,yt.height);const de=await dH({getFrameCanvas:ue=>at.renderFrameAt(E.keyframes,ue),keyframes:E.keyframes,durationMs:zt,fps:yt.fps,quality:yt,onProgress:ue=>ix(ue),signal:ke.signal});if(de)return de}catch(de){if((de==null?void 0:de.name)==="AbortError")return null;console.error("[walkthrough] HQ export failed",de)}finally{at.endExport(Kt),bh.current=null,ix(0)}}return F==="render"?(ln.error(It("walkthrough.renderReadyUnsupported",{defaultValue:"הדפדפן לא יכול לייצר MP4 מוכן־לרינדור. השתמשו ב-Chrome/Edge או עברו לאיכות גבוהה."})),null):k0(E)},[k0,Cc,hi,It]),v0=m.useCallback(E=>{E&&eM({left:E.left,right:E.right,top:E.top,bottom:E.bottom,width:E.width,height:E.height}),ar("inside"),El(!0),Tn(!1)},[]),rM=m.useCallback(()=>{if(zm(),ui==="recording"){El(!1);return}if(ui==="playing"){El(!1);return}hi(),El(!1)},[zm,hi,ui]);m.useEffect(()=>()=>{for(const E of Hs.current)clearTimeout(E);Hs.current=[]},[]);const iM=m.useCallback(E=>{var V;const F=(V=window.prompt("שם הסיור",E.name))==null?void 0:V.trim();!F||F===E.name||rn==null||rn(Je.map(at=>at.id===E.id?{...at,name:F}:at))},[rn,Je]),aM=m.useCallback(E=>{window.confirm(`למחוק את "${E.name}"?`)&&(gh===E.id&&hi(),Om.current.delete(E.id),pd.current.delete(E.id),rn==null||rn(Je.filter(F=>F.id!==E.id)))},[gh,rn,hi,Je]),Xm=m.useCallback((E,F,V)=>{const at=URL.createObjectURL(F),yt=document.createElement("a");yt.href=at,yt.download=`${E.name.replace(/\s+/g,"_")}.${aF(V)}`,yt.click(),URL.revokeObjectURL(at)},[]),lM=m.useCallback(async E=>{il(E.id);const F=Om.current.get(E.id),V=pd.current.get(E.id)??(F?await F:null);if(V){pd.current.set(E.id,V),Xm(E,V.blob,V.mimeType),vi("idle"),il(null),ln.success(V.mimeType.includes("mp4")?It("walkthrough.downloadedMp4",{defaultValue:"הווידאו ירד ב-MP4"}):It("walkthrough.downloadedWebm",{defaultValue:"הווידאו ירד באיכות גבוהה כ-WebM"}));return}const at=E.videoExportMode??"hq",yt=E.videoCaptureSource==="live-canvas";if(E.videoUrl&&(yt||at===Cn)){vi("exporting");try{const de=await(await fetch(E.videoUrl)).blob(),ue=E.videoMimeType||de.type||"video/mp4";Xm(E,de,ue),ue.includes("mp4")||ln.info(It("walkthrough.webmFallback",{defaultValue:"הדפדפן שמר את הווידאו כ-WebM כי MP4 לא נתמך כאן."}))}catch{ln.error(It("walkthrough.downloadFailed",{defaultValue:"הורדת הווידאו נכשלה"}))}finally{vi("idle"),il(null)}return}const zt=await $m(E,Cn,Bm);if(!zt){il(null),vi("idle");return}il(E.id),vi("exporting");let Kt=null;vo&&(Kt=await vo(E,zt.blob,zt.mimeType),Kt||ln.error(It("walkthrough.videoSaveFailed",{defaultValue:"הווידאו נוצר אבל השמירה נכשלה"}))),Kt&&(rn==null||rn(Je.map(ke=>ke.id===E.id?{...ke,videoAssetId:Kt.id,videoUrl:Kt.url,videoMimeType:Kt.mimeType,videoStoragePath:Kt.storagePath,videoExportMode:Cn}:ke))),Xm(E,zt.blob,zt.mimeType),vi("idle"),il(null),ln.success(zt.mimeType.includes("mp4")?It("walkthrough.downloadedMp4",{defaultValue:"הווידאו ירד ב-MP4"}):It("walkthrough.downloadedWebm",{defaultValue:"הווידאו ירד באיכות גבוהה כ-WebM"}))},[Xm,$m,vo,rn,It,Cn,Bm,Je]);m.useEffect(()=>{Ko.current={openWalkthroughRecorder:v0,startWalkthroughRecording:Vr,stopWalkthroughRecording:Fl,playWalkthrough:E=>{gu(E,"playing")},stopWalkthroughPlayback:hi,exportWalkthroughVideo:$m}},[gu,$m,v0,Vr,hi,Fl]),m.useEffect(()=>()=>{var F;(F=Os.current)!=null&&F.interval&&clearInterval(Os.current.interval);const E=sl.current;if(E){E.abort();try{E.recorder.state!=="inactive"&&E.recorder.stop()}catch{}}sl.current=null,Os.current=null,Dc.current=null},[]);const j0=ce&&ce.rooms.length>0?ce.rooms.length===1?It("viewer.roomSummary.one",{area:ce.rooms[0].area??"?",defaultValue:`‏חדר 1 - ${ce.rooms[0].area??"?"} מ״ר`}
280):It("viewer.roomSummary.many",{count:ce.rooms.length,area:ce.rooms.reduce((E,F)=>E+(F.area??0),0).toFixed(0),defaultValue:`‏${ce.rooms.length} חדרים - ${ce.rooms.reduce((E,F)=>E+(F.area??0),0).toFixed(0)} מ״ר`}):null;m.useEffect(()=>{In==null||In(j0)},[j0,In]);const cM=m.useCallback(()=>{Br.current="in",nc(E=>E+1)},[]),dM=m.useCallback(()=>{Br.current="out",nc(E=>E+1)},[]),uM=m.useCallback(()=>{Br.current="reset",nc(E=>E+1)},[]),hM=m.useCallback(E=>{const F=E.shiftKey?$8:z8;Xn(V=>tp(V+F,Ma))},[Ma]),oa=m.useCallback(E=>{const F=E.shiftKey?$8:z8;Xn(V=>tp(V-F,Ma))},[Ma]),mM=m.useCallback(E=>{qf(F=>({id:((F==null?void 0:F.id)??0)+1,direction:E}))},[]);m.useEffect(()=>{if(w||Ce!=="inside"&&Ce!=="walkthrough")return;const E=Fa;if(!E)return;const F=V=>{if(!V.altKey)return;V.preventDefault(),V.stopPropagation();const at=V.deltaY>0?-G8:G8;Xn(yt=>tp(yt+at,Ma))};return E.addEventListener("wheel",F,{passive:!1}),()=>E.removeEventListener("wheel",F)},[w,Ce,Fa,Ma]),m.useEffect(()=>{const E=V=>dc.add(V.code),F=V=>dc.delete(V.code);return window.addEventListener("keydown",E),window.addEventListener("keyup",F),()=>{window.removeEventListener("keydown",E),window.removeEventListener("keyup",F),dc.clear()}},[]);const Ym=m.useRef(null),fM=m.useCallback((E,F)=>{E.button===0&&(E.stopPropagation(),E.currentTarget.setPointerCapture(E.pointerId),Ym.current={pointerId:E.pointerId,startClientX:E.clientX,startClientY:E.clientY,startLeft:F.left,startTop:F.top,panelWidth:F.panelWidth,panelHeight:F.panelHeight,updateAnchor:F.updateAnchor})},[]),xM=m.useCallback(E=>{const F=Ym.current;if(!F||F.pointerId!==E.pointerId)return;const V=Math.max(12,window.innerWidth-F.panelWidth-12),at=Math.max(12,window.innerHeight-F.panelHeight-12),yt=Math.min(Math.max(12,F.startLeft+E.clientX-F.startClientX),V),zt=Math.min(Math.max(12,F.startTop+E.clientY-F.startClientY),at);F.updateAnchor({x:yt+F.panelWidth/2,y:zt+20})},[]),_0=m.useCallback(E=>{var F;((F=Ym.current)==null?void 0:F.pointerId)===E.pointerId&&(Ym.current=null)},[]),pM=m.useCallback((E,F)=>{E.button===0&&(E.preventDefault(),E.stopPropagation(),E.currentTarget.setPointerCapture(E.pointerId),td.current={pointerId:E.pointerId,startClientX:E.clientX,startClientY:E.clientY,startLeft:F.left,startTop:F.top,panelWidth:F.panelWidth,panelHeight:F.panelHeight})},[]),gM=m.useCallback(E=>{const F=td.current;if(!F||F.pointerId!==E.pointerId)return;const V=Math.max(12,window.innerWidth-F.panelWidth-12),at=Math.max(12,window.innerHeight-F.panelHeight-12),yt=Math.min(Math.max(12,F.startLeft+E.clientX-F.startClientX),V),zt=Math.min(Math.max(12,F.startTop+E.clientY-F.startClientY),at);Xt(Kt=>Kt&&{...Kt,x:yt,y:zt})},[]),E0=m.useCallback(E=>{var F;((F=td.current)==null?void 0:F.pointerId)===E.pointerId&&(td.current=null)},[]),lx=m.useCallback((E,F)=>{E.button===0&&(E.preventDefault(),E.stopPropagation(),E.currentTarget.setPointerCapture(E.pointerId),qd.current={pointerId:E.pointerId,startClientX:E.clientX,startClientY:E.clientY,startLeft:F.left,startTop:F.top,panelWidth:F.panelWidth,panelHeight:F.panelHeight})},[]),cx=m.useCallback(E=>{const F=qd.current;if(!F||F.pointerId!==E.pointerId)return;const V=Math.max(12,window.innerWidth-F.panelWidth-12),at=Math.max(12,window.innerHeight-F.panelHeight-12),yt=Math.min(Math.max(12,F.startLeft+E.clientX-F.startClientX),V),zt=Math.min(Math.max(12,F.startTop+E.clientY-F.startClientY),at);bt(Kt=>Kt&&{...Kt,x:yt,y:zt})},[]),D0=m.useCallback(E=>{var F;((F=qd.current)==null?void 0:F.pointerId)===E.pointerId&&(qd.current=null)},[]),bM=m.useMemo(()=>qH(Te,po,ho),[Te,po,ho]);if(!ce)return n.jsx("div",{style:{padding:40,color:"#888",fontFamily:"system-ui"},children:"No levels in scene document."});const F0=!w&&(Ce==="inside"||Ce==="walkthrough"),bd=gh?Je.find(E=>E.id===gh)??null:null,MM=ui==="recording"?tM.map(E=>({x:E.position[0],z:E.position[2]})):(bd==null?void 0:bd.keyframes.map(E=>({x:E.position[0],z:E.position[2]})))??[],C0=pF,yM=`${Math.floor(fu/1e3)}s`,Gm=(()=>{if(typeof window>"u")return{top:52,left:Tu,width:L8};const E=Math.min(L8,Math.max(260,window.innerWidth-Tu*2)),F=Tu,V=52;if(!Hm)return{top:V,left:F,width:E};const at=Hm.left+Hm.width/2-E/2;return{top:Math.min(Math.max(Tu,Hm.bottom+8),Math.max(Tu,window.innerHeight-Tu-160)),left:Math.max(Tu,Math.min(at,window.innerWidth-E-Tu)),width:E}})(),N0=fa?(Fe==null?void 0:Fe.find(E=>E.id===fa.furnitureId))??null:null,pr=Lt==="mm"?It("settings.millimeters",{defaultValue:"מ״מ"}
280):It("settings.centimeters",{defaultValue:"ס״מ"}),wM=cn?cn.kind==="switch"?It("electrical.fixtures.switch",{gangs:cn.gangs,defaultValue:`מפסק ${cn.gangs}`}):cn.kind==="socket"?cn.outlets===1?It("electrical.fixtures.singleOutlet",{defaultValue:"שקע יחיד"}):It("electrical.fixtures.doubleOutlet",{defaultValue:"שקע כפול"}):cn.kind==="tv"?cn.inches===60?It("electrical.fixtures.tv60",{defaultValue:"טלוויזיה 60 אינץ׳"}):It("electrical.fixtures.doorScreen10",{defaultValue:"מסך דלת 10 אינץ׳"}):It("electrical.fixtures.ac",{defaultValue:"מזגן יחיד"}):"",dx=N0?(g==null?void 0:g[N0.type])??[]:[],kM=-Ru.degToRad(hs),I0=(E,F)=>{if(!Ot||!Ue||E<0||E>=Ot.length)return null;const V=Ot[E],at=hm(V),yt=Lf(V);if(!at&&!yt)return n.jsx("div",{className:O("text-[12px]",ae?"text-white/60":"text-[#71717a]"),children:It("viewer.opening.directionUnavailable",{defaultValue:"כיוון פתיחה זמין רק לדלתות או חלונות ציר."})});const zt=de=>{Ue(Ot.map((ue,mn)=>mn===E?{...ue,...de}:ue))},Kt=F?{front:F==="front"?It("viewer.opening.opensThisSide",{defaultValue:"נפתחת לצד הזה"}):It("viewer.opening.opensOtherSide",{defaultValue:"נפתחת לצד השני"}),back:F==="back"?It("viewer.opening.opensThisSide",{defaultValue:"נפתחת לצד הזה"}):It("viewer.opening.opensOtherSide",{defaultValue:"נפתחת לצד השני"})}:void 0,ke=F?{front:F==="front"?It("viewer.opening.zeroLineThisSide",{defaultValue:"קו 0 בצד הזה"}):It("viewer.opening.zeroLineOtherSide",{defaultValue:"קו 0 בצד השני"}),back:F==="back"?It("viewer.opening.zeroLineThisSide",{defaultValue:"קו 0 בצד הזה"}):It("viewer.opening.zeroLineOtherSide",{defaultValue:"קו 0 בצד השני"})}:void 0;return n.jsxs("div",{className:"space-y-3",children:[at&&n.jsx($3,{value:Wd(V),onChange:de=>zt(rm(de)),fpIsDark:ae,faceLabels:Kt}),yt&&n.jsxs("div",{className:O("rounded-2xl border p-2.5",ae?"border-white/10 bg-white/[0.03]":"border-[#182137]/10 bg-white/70"),children:[n.jsx("div",{className:O("mb-2 text-[10px] font-bold",ae?"text-white/75":"text-[#5a5065]"),children:It("viewer.opening.zeroLineSide",{defaultValue:"צד קו 0"})}),n.jsx(X3,{value:xb(V),onChange:de=>zt(Gw(de)),fpIsDark:ae,labels:ke})]})]})},Um=E=>{if(!Ot||!Ue||!so||E<0||E>=Ot.length)return null;const F=Ot[E],V=F.preset?qs[F.preset]:null,at=F.type==="window",yt=Math.round(F.positionPx*so),zt=F.widthMm||(V==null?void 0:V.width)||900,Kt=F.heightMm||(V==null?void 0:V.height)||2100,ke=F.sillHeightMm??(V==null?void 0:V.sillHeight)??900,de=Xe=>Number(De(Xe,Lt)),ue=Xe=>ni(String(Xe),Lt)??0,mn=Xe=>Lt==="mm"?Xe:Math.max(.1,Xe/10),Yn=Xe=>{Ue(Ot.map((Sn,mo)=>mo===E?{...Sn,...Xe}:Sn))};return n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[n.jsxs("div",{className:O("text-[11px] font-semibold truncate",ae?"text-white/70":"text-[#5a5065]"),children:[at?It("viewer.opening.window",{defaultValue:"חלון"}):It("viewer.opening.door",{defaultValue:"דלת"}),V?` — ${It(`opening.${F.preset}`,{defaultValue:V.label})}`:null]}),n.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[!F.cornerGroupId&&n.jsx("button",{onClick:()=>{if(!tt)return;const Xe=Z1(Ot,F.id,tt,so);Xe&&(Ue(Xe.next),ks(Xe.newIdx))},className:O("px-2.5 py-1 rounded-xl text-[10px] font-medium transition-all cursor-pointer",ae?"text-[#F4A99A] bg-white/10 hover:bg-white/15":"text-[#B84A2E] bg-[#FDF6F4] hover:bg-[#FCE8E4]"),children:It("common.duplicate",{defaultValue:"שכפל"})}),n.jsx("button",{onClick:()=>{Ue(Ot.filter((Xe,Sn)=>Sn!==E&&(!F.cornerGroupId||Xe.cornerGroupId!==F.cornerGroupId))),ks(null),bt(null)},className:"px-2.5 py-1 rounded-xl text-[10px] font-medium text-[#d4738a] bg-[#fdf0f3] hover:bg-[#f9d5de] transition-all cursor-pointer",children:It("common.delete",{defaultValue:"מחק"})})]})]}),n.jsxs("div",{className:"space-y-2.5",children:[n.jsx(Hh,{label:It("viewer.opening.position",{defaultValue:"מיקום"}),unit:pr,value:de(yt),min:0,max:de(2e4),step:mn(10),onChange:Xe=>Yn({positionPx:ue(Xe)/so})}),n.jsx(Hh,{label:It("dimensions.width",{defaultValue:"רוחב"}),unit:pr,value:de(zt),min:de(300),max:de(3e3),step:mn(1),showInput:!0,onChange:Xe=>Yn({widthMm:ue(Xe)})}),n.jsx(Hh,{label:It("dimensions.height",{defaultValue:"גובה"}),unit:pr,value:de(Kt),min:de(500),max:de(3e3),step:mn(1),showInput:!0,onChange:Xe=>Yn({heightMm:ue(Xe)})}),at&&n.jsx(Hh,{label:It("viewer.opening.sill",{defaultValue:"אדן"}),unit:pr,value:de(ke),min:0,max:de(1500),step:mn(50),onChange:Xe=>Yn({sillHeightMm:ue(Xe)})})]}),at&&n.jsx("button",{type:"button",onClick:()=>Yn({widthMm:Kt,heightMm:zt}),className:O("w-full rounded-xl px-2.5 py-2 text-[10px] font-semibold transition-all cursor-pointer",ae?"bg-white/10 text-white/80 hover:bg-white/15":"bg-[#182137]/[
2800.06] text-[#30283a] hover:bg-[#182137]/[0.09]"),children:It("viewer.opening.rotate90",{defaultValue:"סובב 90°"})}),n.jsxs("div",{dir:"ltr",className:"flex items-center gap-2 justify-center pt-1",children:[n.jsxs("button",{onClick:()=>Yn({positionPx:Math.max(0,F.positionPx-50/so)}),className:`flex-1 py-1.5 rounded-xl text-[10px] font-medium cursor-pointer transition-all duration-150 text-center
281              border border-[#182137]/8 bg-gradient-to-b from-white to-[#f5f2ec] text-[#182137]/70
282              shadow-[0_2px_0_rgba(24,33,55,0.06),0_2px_6px_rgba(0,0,0,0.04)]
283              hover:border-[#EC7357]/35 hover:from-[#FDF6F4] hover:to-white hover:shadow-[0_2px_0_rgba(216,75,46,0.12)]
284              active:translate-y-px`,children:["← ",De(50,Lt)," ",pr]}),n.jsxs("button",{onClick:()=>Yn({positionPx:F.positionPx+50/so}),className:`flex-1 py-1.5 rounded-xl text-[10px] font-medium cursor-pointer transition-all duration-150 text-center
285              border border-[#182137]/8 bg-gradient-to-b from-white to-[#f5f2ec] text-[#182137]/70
286              shadow-[0_2px_0_rgba(24,33,55,0.06),0_2px_6px_rgba(0,0,0,0.04)]
287              hover:border-[#EC7357]/35 hover:from-[#FDF6F4] hover:to-white hover:shadow-[0_2px_0_rgba(216,75,46,0.12)]
288              active:translate-y-px`,children:[De(50,Lt)," ",pr," →"]})]})]})},ux=({position:E,current:F,title:V,onApply:at,onRemove:yt,onClose:zt,grout:Kt,onGroutChange:ke,currentColor:de,onApplyColor:ue,textures:mn,savedTiles:Yn,getSavedTileUrl:Xe,onPositionChange:Sn,modalBackdrop:mo=!0,variant:vs="standard",onDivide:yo,onMerge:Bi,isDivided:bu=!1,onUploadTile:Xs,onRemoveTile:wh,onRenameTile:kh})=>{const fo=vs==="compact",vh=!!ue,jh=vh?Yt:"cladding",hx=Xs??ct,T0=wh??pt,Km=kh??xt,Mu=!!hx,mx=Mu?Jt:"builtin",vM=Mu&&mx==="my"?fo?100:130:0,fx=ye=>{if(!(!ye.type.startsWith("image/")||!hx)){if(_t){Ft==null||Ft();return}hx(ye,ye.name.replace(/\.[^.]+$/,"").slice(0,16)||"חיפוי")}},Md=fo?Math.min(420,Math.max(320,window.innerWidth-24)):720,_h=(fo?vh?jh==="color"?320:540:480:vh?jh==="color"?300:390:320)+vM,xx=Math.max(12,window.innerWidth-Md-12),jM=Math.max(12,window.innerHeight-_h-12),S0=Math.min(Math.max(12,E.x-Md/2),xx),P0=Math.min(Math.max(12,E.y-20),jM),Nc=(F==null?void 0:F.tileSizeM)??[1,2.7],yu=ei(F==null?void 0:F.orientation),_M=!!Kt&&!!ke&&!!F,EM=mn??ta,Eh=Yn??st??[],A0=Xe??(ye=>_f(ye.storage_path)),Zm=jh==="cladding",L0=vh&&jh==="color";return n.jsxs(n.Fragment,{children:[mo&&n.jsx("div",{className:"fixed inset-0 z-[60]",onClick:zt,onContextMenu:ye=>{ye.preventDefault(),zt()}}),n.jsxs("div",{"data-testid":"floating-cladding-picker",className:O("fixed z-[61] border font-heebo overflow-hidden",fo?"rounded-2xl":"rounded-3xl","shadow-[0_24px_72px_-12px_rgba(24,33,55,0.32),0_0_0_1px_rgba(24,33,55,0.04)]",ae?"bg-[#141416] border-white/10":"bg-[#F7F4EF] border-[#182137]/10"),style:{left:S0,top:P0,width:Md,maxWidth:"calc(100vw - 24px)",maxHeight:_h},dir:_s.dir(),onContextMenu:ye=>ye.preventDefault(),onClick:ye=>ye.stopPropagation(),children:[n.jsxs("div",{className:O("flex items-center justify-between border-b select-none",fo?"px-3.5 py-2.5":"px-5 py-3",Sn&&"cursor-move",ae?"border-white/10":"border-[#182137]/8"),"data-testid":"floating-cladding-picker-header",title:Sn?It("trace.dragToMove",{defaultValue:"גרור להזזה"}):void 0,onPointerDown:Sn?ye=>fM(ye,{left:S0,top:P0,panelWidth:Md,panelHeight:_h,updateAnchor:Sn}):void 0,onPointerMove:Sn?xM:void 0,onPointerUp:Sn?_0:void 0,onPointerCancel:Sn?_0:void 0,children:[n.jsxs("div",{className:"flex items-center gap-2.5",children:[n.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-[#D84B2E]"}),n.jsx("span",{className:O(fo?"text-[12px]":"text-[13px]","font-black tracking-normal",ae?"text-white":"text-[#182137]"),children:V})]}),n.jsx("button",{onClick:zt,onPointerDown:ye=>ye.stopPropagation(),className:O(fo?"w-6 h-6 rounded-md":"w-7 h-7 rounded-lg","flex items-center justify-center cursor-pointer transition-colors",ae?"text-white/50 hover:bg-white/10 hover:text-white":"text-[#182137]/45 hover:bg-[#182137]/[0.06] hover:text-[#182137]"),"aria-label":It("common.close",{defaultValue:"סגור"}),title:It("common.close",{defaultValue:"סגור"}),children:n.jsx(Gr,{size:14})})]}),vh&&!Mu&&n.jsx("div",{className:O("border-b",fo?"px-3.5 py-2":"px-5 py-2.5",ae?"border-white/10":"border-[#182137]/8"),children:n.jsx("div",{className:O("grid grid-cols-2 rounded-xl p-0.5",ae?"bg-white/5":"bg-[#182137]/[
2880.04]"),children:[{key:"cladding",label:It("viewer.cladding.claddingTab",{defaultValue:"חיפויים"}),icon:Gh},{key:"color",label:It("viewer.cladding.colorsTab",{defaultValue:"צבעים"}),icon:Ew}].map(ye=>{const us=ye.icon,Ha=jh===ye.key;return n.jsxs("button",{type:"button","aria-pressed":Ha,onClick:()=>Ut(ye.key),className:O("flex items-center justify-center gap-1.5 rounded-lg font-black transition-colors",fo?"px-2.5 py-1.5 text-[10.5px]":"px-3 py-2 text-[11px]",Ha?ae?"bg-white/12 text-white shadow-sm":"bg-white text-[#182137] shadow-sm":ae?"text-white/55 hover:bg-white/10 hover:text-white":"text-[#182137]/55 hover:bg-white/70 hover:text-[#182137]"),children:[n.jsx(us,{size:13,strokeWidth:2.2}),n.jsx("span",{children:ye.label})]},ye.key)})})}),Mu&&n.jsx("div",{className:O("flex items-center justify-start gap-0.5 border-b",fo?"px-3.5 py-2":"px-5 py-2.5",ae?"border-white/10":"border-[#182137]/8"),children:[{key:"builtin",label:It("materials.builtin.wall",{defaultValue:"חיפויים לקירות"})},{key:"color",label:It("viewer.cladding.colorsTab",{defaultValue:"צבעים"})},{key:"my",label:It("materials.mine.wall",{defaultValue:"החיפויים שלי"})}].map(ye=>n.jsx("button",{type:"button",onClick:()=>{we(ye.key),Ut(ye.key==="color"?"color":"cladding")},className:O("rounded-md font-medium transition-all cursor-pointer",fo?"px-2.5 py-1 text-[10px]":"px-3 py-1 text-[11px]",mx===ye.key?"bg-gradient-to-b from-[#EC7357] to-[#D84B2E] text-white shadow-sm":ae?"text-white/50 hover:text-white/85 hover:bg-white/5":"text-[#71717a] hover:text-[#182137] hover:bg-black/[0.04]"),children:ye.label},ye.key))}),Zm&&(Mu&&mx==="my"?n.jsxs("div",{className:O("border-b",fo?"px-3.5 py-2.5":"px-5 py-3",ae?"border-white/10":"border-[#182137]/8"),children:[n.jsx("input",{ref:hn,type:"file",accept:"image/png,image/jpeg,image/webp",className:"hidden",onChange:ye=>{var Ha;const us=(Ha=ye.target.files)==null?void 0:Ha[0];us&&fx(us),ye.target.value=""}}),n.jsxs("div",{className:O("grid grid-cols-4 gap-1.5 overflow-y-auto",fo?"max-h-[140px]":"max-h-[168px]"),children:[n.jsxs("button",{type:"button",onClick:()=>{var ye;_t?Ft==null||Ft():(ye=hn.current)==null||ye.click()},onDragOver:ye=>{ye.preventDefault(),Rs(!0)},onDragLeave:()=>Rs(!1),onDrop:ye=>{ye.preventDefault(),Rs(!1);const us=ye.dataTransfer.files[0];us&&fx(us)},className:O("relative aspect-square rounded-lg border-2 border-dashed flex items-center justify-center transition-all cursor-pointer",fn?ae?"border-white/40 bg-white/10":"border-[#182137] bg-black/[0.04]":ae?"border-white/15 hover:border-white/30 hover:bg-white/5 bg-white/[0.02]":"border-black/15 hover:border-black/30 hover:bg-black/[0.02] bg-[#fafafa]"),children:[n.jsx(pm,{size:18,className:fn?ae?"text-white":"text-[#182137]":ae?"text-white/45":"text-[#a1a1aa]"}),_t&&n.jsx("span",{className:"absolute start-1 top-1 grid h-5 w-5 place-items-center rounded-md bg-[#182137] text-[#F7F4EF] shadow-sm",children:n.jsx(fp,{size:10,strokeWidth:2.5})})]}),Eh.map(ye=>{const us=A0(ye),Ha=(F==null?void 0:F.url)===us,DM=Mn===ye.id;return n.jsxs("div",{className:"flex flex-col gap-0.5",children:[n.jsxs("button",{type:"button",onClick:()=>_t?Ft==null?void 0:Ft():at({url:us,tileSizeM:Nc,orientation:yu}),className:O("relative group rounded-lg overflow-hidden transition-all cursor-pointer aspect-square",Ha?ae?"ring-2 ring-[#EC7357] ring-offset-2 ring-offset-[#141416]":"ring-2 ring-[#D84B2E] ring-offset-2 ring-offset-[#F7F4EF]":ae?"border border-white/10 hover:border-white/30":"border border-[#182137]/10 hover:border-[#182137]/30"),children:[n.jsx("img",{src:us,alt:ye.name,className:O("w-full h-full object-cover",_t&&"opacity-55 grayscale-[0.2]")}),_t&&n.jsx("span",{className:"pointer-events-none absolute inset-0 grid place-items-center bg-[#182137]/12",children:n.jsx("span",{className:"grid h-7 w-7 place-items-center rounded-lg bg-[#182137] text-[#F7F4EF] shadow-[0_5px_14px_rgba(24,33,55,0.24)]",children:n.jsx(fp,{size:13,strokeWidth:2.5})})}),T0&&n.jsx("button",{type:"button",onClick:Vi=>{Vi.stopPropagation(),_t?Ft==null||Ft():T0(ye)},className:"absolute top-0.5 right-0.5 w-4 h-4 rounded-full bg-red-500 text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",children:n.jsx(Gr,{size:8})})]}),DM&&Km?n.jsx("input",{autoFocus:!0,defaultValue:ye.name,className:O("text-[9px] rounded px-1 py-0.5 text-center outline-none border",ae?"text-white bg-white/10 border-[#
288EC7357]/50":"text-[#18181b] bg-white border-[#D84B2E]"),onBlur:Vi=>{const qm=Vi.target.value.trim();qm?Km(ye.id,qm):tn(null)},onKeyDown:Vi=>{Vi.key==="Enter"&&Vi.target.blur(),Vi.key==="Escape"&&tn(null)},onClick:Vi=>Vi.stopPropagation()}):n.jsx("span",{className:O("text-[9px] text-center truncate leading-tight",ae?"text-white/55":"text-[#52525b]",Km&&(ae?"cursor-text hover:text-white/90":"cursor-text hover:text-[#18181b]")),onClick:Vi=>{Km&&(Vi.stopPropagation(),_t?Ft==null||Ft():tn(ye.id))},children:ye.name})]},ye.id)})]}),Eh.length===0&&n.jsx("p",{className:O("text-center text-[11px] mt-4",ae?"text-white/40":"text-[#b5afa6]"),children:It("viewer.cladding.emptyCustom",{defaultValue:"אין חיפויים מותאמים אישית עדיין"})})]}):n.jsx("div",{className:O("border-b overflow-x-auto",fo?"px-3.5 py-2.5":"px-5 py-3",ae?"border-white/10":"border-[#182137]/8"),children:n.jsxs("div",{className:O("flex items-center min-w-max",fo?"gap-1.5":"gap-2"),children:[EM.map(ye=>{const us=(F==null?void 0:F.url)===ye.value;return n.jsx("button",{onClick:()=>at({url:ye.value,tileSizeM:Nc,orientation:yu}),className:O("relative overflow-hidden transition-all cursor-pointer shrink-0",fo?"w-11 h-11 rounded-lg":"w-14 h-14 rounded-xl",us?ae?"ring-2 ring-[#EC7357] ring-offset-2 ring-offset-[#141416]":"ring-2 ring-[#D84B2E] ring-offset-2 ring-offset-[#F7F4EF]":ae?"border border-white/10 hover:border-white/30":"border border-[#182137]/10 hover:border-[#182137]/30"),title:ye.label,children:n.jsx("img",{src:ye.value,alt:ye.label,className:"w-full h-full object-cover"})},ye.id)}),!Mu&&Eh.length>0&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:O("w-px h-10 mx-1 shrink-0",ae?"bg-white/10":"bg-[#182137]/10")}),Eh.map(ye=>{const us=A0(ye),Ha=(F==null?void 0:F.url)===us;return n.jsx("button",{onClick:()=>at({url:us,tileSizeM:Nc,orientation:yu}),className:O("relative overflow-hidden transition-all cursor-pointer shrink-0",fo?"w-11 h-11 rounded-lg":"w-14 h-14 rounded-xl",Ha?ae?"ring-2 ring-[#EC7357] ring-offset-2 ring-offset-[#141416]":"ring-2 ring-[#D84B2E] ring-offset-2 ring-offset-[#F7F4EF]":ae?"border border-white/10 hover:border-white/30":"border border-[#182137]/10 hover:border-[#182137]/30"),title:ye.name,children:n.jsx("img",{src:us,alt:ye.name,className:"w-full h-full object-cover"})},ye.id)})]})]})})),Zm&&n.jsxs("div",{className:O(fo?"space-y-3 px-3.5 py-3":"flex items-stretch gap-4 px-5 py-4"),children:[n.jsxs("div",{className:O(fo?"space-y-2":"flex-1 min-w-0 space-y-2"),children:[n.jsx("div",{className:O("text-[9px] font-black tracking-[0.08em] uppercase",ae?"text-white/45":"text-[#182137]/45"),children:It("viewer.cladding.dimensions",{defaultValue:"מידות"})}),n.jsxs("div",{className:"space-y-2",children:[n.jsx(Hh,{label:It("dimensions.width",{defaultValue:"רוחב"}),unit:pr,value:Number(De(Nc[0]*1e3,Lt)),min:Number(De(200,Lt)),max:Number(De(5e3,Lt)),step:Lt==="mm"?50:5,onChange:ye=>F&&at({url:F.url,tileSizeM:[(ni(String(ye),Lt)??0)/1e3,Nc[1]],orientation:yu})}),n.jsx(Hh,{label:It("dimensions.height",{defaultValue:"גובה"}),unit:pr,value:Number(De(Nc[1]*1e3,Lt)),min:Number(De(200,Lt)),max:Number(De(5e3,Lt)),step:Lt==="mm"?50:5,onChange:ye=>F&&at({url:F.url,tileSizeM:[Nc[0],(ni(String(ye),Lt)??0)/1e3],orientation:yu})})]}),n.jsxs("div",{children:[n.jsx("div",{className:O("mb-1 text-[9px] font-semibold",ae?"text-white/45":"text-[#182137]/45"),children:It("materials.orientation",{defaultValue:"כיוון"})}),n.jsx("div",{className:O("grid grid-cols-2 rounded-xl p-0.5",ae?"bg-white/5":"bg-[#182137]/[0.04]"),children:[{key:"vertical",label:It("materials.vertical",{defaultValue:"אנכי"})},{key:"horizontal",label:It("materials.horizontal",{defaultValue:"אופקי"})}].map(ye=>{const us=yu===ye.key;return n.jsx("button",{type:"button",disabled:!F,onClick:()=>F&&at({url:F.url,tileSizeM:Nc,orientation:ye.key}),className:O("rounded-lg px-2 py-1.5 text-[10px] font-black transition-colors",!F&&"cursor-not-allowed opacity-45",us?"bg-gradient-to-b from-[#EC7357] to-[#D84B2E] text-white shadow-sm":ae?"text-white/60 hover:bg-white/10":"text-[#182137]/60 hover:bg-white/70"),children:ye.label},ye.key)})})]})]}),_M&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:O(fo?"h-px w-full":"w-px self-stretch",ae?"bg-white/10":"bg-[#182137]/8")}),n.jsxs("div",{className:O(fo?"space-y-2":"flex-1 min-w-0 space-y-2"),children:[n.jsx("div",{className:O("text-[9px] font-black tracking-[0.08em] uppercase",ae?"text-white/45":"text-[#182137]/45"),children:It("viewer.cladding.grout",{defaultValue:"פוגה"})}),n.jsxs("div",{className:"space-y-2",children:[n.jsx(Hh,{label:It("dimensions.width",{defaultValue:"רוחב"}),unit:pr,value:Number(De(Kt.widthMm,Lt)),min:0,max:Number(De(20,Lt)),step:Lt==="mm"?1:.1,onChange:ye=>ke(ni(String(ye),Lt)??0,Kt.color)}),n.jsxs("div",{className:"flex items-center gap-2.5",children:[n.jsx("span",{className:O("text-[9px] w-[34px] text-start shrink-0",ae?"text-white/45":"text-[#9b95a0]"),children:It("viewer.cladding.color",{defaultValue:"צבע"})}),n.jsx("input",{type:"color",value:Kt.color,onChange:ye=>ke(Kt.widthMm,ye.target.value),className:O("h-7 w-12 rounded-md cursor-pointer border overflow-hidden p-0",ae?"border-white/10 bg-transparent":"border-[#182137]/10 bg-white")}),n.jsx("span",{className:O("text-[10px] tabular-nums uppercase",ae?"text-white/55":"text-[#5a5065]"),children:Kt.color})]})]})]})]}),F&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:O(fo?"h-px w-full":"w-px self-stretch",ae?"bg-white/10":"bg-[#182137]/8")}),n.jsxs("div",{className:O(fo?"flex items-center justify-between gap-2":"flex flex-col justify-center gap-2 shrink-0"),children:[n.jsx("div",{className:O("text-[9px] font-black tracking-[0.08em] uppercase",ae?"text-white/45":"text-[#182137]/45"),children:It("viewer.cladding.actions",{defaultValue:"פעולות"})}),n.jsx("button",{onClick:yt,className:O("rounded-xl text-[11px] font-black tracking-normal transition-colors cursor-pointer",fo?"px-3 py-1.5":"px-3.5 py-2",ae?"text-[#F4A99A] bg-white/10 hover:bg-white/15":"text-[#D84B2E] bg-[#FDF6F4] hover:bg-[#FCE8E4] border border-[#D84B2E]/15"),children:It("viewer.cladding.remove",{defaultValue:"הסר חיפוי"})})]})]}),(yo||Bi)&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:O(fo?"h-px w-full":"w-px self-stretch",ae?"bg-white/10":"bg-[#182137]/8")}),n.jsxs("div",{className:O(fo?"space-y-2":"flex flex-col justify-center gap-2 shrink-0 min-w-[120px]"),children:[n.jsx("div",{className:O("text-[9px] font-black tracking-[0.08em] uppercase",ae?"text-white/45":"text-[#182137]/45"),children:It("materials.wallDivision",{defaultValue:"חלוקת חיפוי"})}),bu?n.jsx("button",{onClick:Bi,className:O("rounded-xl text-[11px] font-black tracking-normal transition-colors cursor-pointer",fo?"px-3 py-1.5":"px-3.5 py-2",ae?"text-white/80 bg-white/10 hover:bg-white/15":"text-[#182137] bg-white hover:bg-black/[0.03] border border-[#182137]/10"),children:It("viewer.cladding.merge",{defaultValue:"איחוד חיפוי"})}):n.jsx("button",{onClick:yo,disabled:!yo,className:O("rounded-xl text-[11px] font-black tracking-normal transition-all cursor-pointer text-white bg-gradient-to-b from-[#EC7357] to-[#D84B2E] hover:from-[#f08068] hover:to-[#C04428] shadow-sm disabled:opacity-40 disabled:cursor-not-allowed",fo?"px-3 py-1.5":"px-3.5 py-2"),children:It("materials.divide",{defaultValue:"חלוקה ↴"})})]})]})]}),L0&&n.jsx("div",{className:O(fo?"px-3.5 py-3":"px-5 py-4"),children:n.jsxs("div",{className:O(fo?"space-y-3"
288:"space-y-4"),children:[n.jsx("div",{className:O("grid gap-2",fo?"grid-cols-6":"grid-cols-8"),children:EU.map(ye=>{const us=(de==null?void 0:de.toLowerCase())===ye.hex.toLowerCase(),Ha=It(`viewer.cladding.colors.${ye.hex.slice(1)}`,{defaultValue:ye.label});return n.jsx("button",{type:"button","aria-label":It("viewer.cladding.colorAria",{color:Ha,defaultValue:`צבע ${ye.label}`}),title:Ha,onClick:()=>ue(ye.hex),className:O("rounded-xl border transition-all cursor-pointer",fo?"h-8":"h-10",us?ae?"ring-2 ring-[#EC7357] ring-offset-2 ring-offset-[#141416]":"ring-2 ring-[#D84B2E] ring-offset-2 ring-offset-[#F7F4EF]":ae?"border-white/10 hover:border-white/30":"border-[#182137]/10 hover:border-[#182137]/30"),style:{backgroundColor:ye.hex}},ye.hex)})}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("input",{type:"color","aria-label":It("materials.customColor",{defaultValue:"צבע מותאם אישית"}),value:de&&/^#[0-9A-Fa-f]{6}$/.test(de)?de:"#ffffff",onChange:ye=>ue(ye.target.value),className:O("rounded-xl cursor-pointer border overflow-hidden p-0",fo?"h-9 w-16":"h-10 w-20",ae?"border-white/10 bg-transparent":"border-[#182137]/10 bg-white")}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("div",{className:O("text-[9px] font-black tracking-[0.08em] uppercase",ae?"text-white/45":"text-[#182137]/45"),children:It("materials.customColor",{defaultValue:"צבע מותאם אישית"})}),n.jsx("div",{className:O("mt-1 text-[11px] font-bold tabular-nums uppercase",ae?"text-white/70":"text-[#182137]/65"),children:de&&/^#[0-9A-Fa-f]{6}$/.test(de)?de:"#FFFFFF"})]}),de&&n.jsx("button",{type:"button",onClick:yt,className:O("shrink-0 rounded-xl text-[11px] font-black tracking-normal transition-colors cursor-pointer",fo?"px-3 py-1.5":"px-3.5 py-2",ae?"text-[#F4A99A] bg-white/10 hover:bg-white/15":"text-[#D84B2E] bg-[#FDF6F4] hover:bg-[#FCE8E4] border border-[#D84B2E]/15"),children:It("viewer.cladding.removeColor",{defaultValue:"הסר צבע"})})]})]})})]})]})};return n.jsxs("div",{ref:ha,style:{width:"100%",height:"100%",position:"relative"},onContextMenu:E=>{if(E.preventDefault(),$o==="pushPull"){As==null||As("select"),Fr(null),Pa.current=!1;return}if(nt){Cs(),Aa(),Pa.current=!1;return}if(Pa.current){Pa.current=!1;return}Cs(),Qo&&(kr({x:E.clientX,y:E.clientY,mode:"show"}),Zo(null))},children:[w&&n.jsx(GU,{active:Ce,onChange:ar}),!w&&n.jsx(zU,{onZoomIn:cM,onZoomOut:dM,onReset:uM,showHeight:Ce==="inside"||Ce==="walkthrough",dockAtBottom:Ce==="inside",minimapChromeLayout:Ce==="inside"&&F0?{leftPx:12,bottomPx:14,sizePx:Fm?Qy:C0+gF}:void 0,onHeightUp:hM,onHeightDown:oa,onCameraAim:mM,cameraHeight:_l,interiorFov:vc,onInteriorFovChange:tl,detailsPanelOpen:oi,fpIsDark:ae,viewportFrameRef:ha}),!w&&Ce==="walkthrough"&&n.jsx(YU,{}),!w&&Ce==="inside"&&Uo.some(E=>!E.hidden)&&n.jsx("div",{className:"pointer-events-none absolute inset-0 z-[35]",children:Uo.filter(E=>!E.hidden).map(E=>n.jsxs("div",{"data-floorplan-viewport-note":!0,className:O("pointer-events-auto absolute w-[220px] touch-none select-none rounded-[10px] border px-3 py-2.5 font-heebo text-right shadow-[0_10px_28px_rgba(24,33,55,0.18)] transition","cursor-grab active:cursor-grabbing",Ye===E.id?"border-[#D85D43] ring-2 ring-[#D85D43]/18":"border-[#182137]/15"),style:{left:`${E.xPct}%`,top:`${E.yPct}%`,backgroundColor:Ku(E.colorId)},dir:_s.dir(),onClick:F=>{F.stopPropagation();const V=jo.current;(V==null?void 0:V.noteId)===E.id&&Date.now()-V.at<250||Ke(E.id)},onMouseDown:F=>F.stopPropagation(),onPointerDown:F=>an(F,E),onPointerMove:Qb,onPointerUp:Rm,onPointerCancel:Rm,onContextMenu:F=>{F.preventDefault(),F.stopPropagation(),Ke(E.id)},children:[n.jsxs("div",{className:"mb-2 flex items-center justify-end gap-1.5",children:[n.jsx("button",{type:"button","data-floorplan-viewport-note-action":!0,onPointerDown:F=>F.stopPropagation(),onClick:F=>{F.stopPropagation();const V=F.currentTarget.closest("[data-floorplan-viewport-note]");V?Wm(E.id,V):Ec(E.id,{x:F.clientX,y:F.clientY})},className:"rounded-md border border-[#182137]/10 bg-white/55 px-2 py-1 text-[10px] font-bold text-[#182137]/75 transition hover:bg-white/85",children:"ערוך"}),n.jsx("button",{type:"button","data-floorplan-viewport-note-action":!0,onPointerDown:F=>F.stopPropagation(),onClick:F=>{F.preventDefault(),F.stopPropagation(),p0(E.id)},className:"rounded-md border border-[#182137]/10 bg-white/55 px-2 py-1 text-[10px] font-bold text-[#182137]/75 transition hover:bg-white/85",children:"הסתר"})]}),n.jsx("div",{className:"max-h-[130px] overflow-hidden text-[12.5px] leading-relaxed text-[#182137]",dangerouslySetInnerHTML:{__html:zc(E.contentHtml)}})]},E.id))}),F0&&n.jsx(QH,{collapsed:Fm,onExpand:()=>Tn(!1),walls:ce.walls,furniture:ce.furniture,templateFootprints:bM,selectedFurnitureIds:$s,bounds:oo,planRotationDeg:hs,cameraPoseRef:fd,onMove:gd,onRotate:Mh,size:C0,controlMode:ui==="recording"?"recording":"normal",onDriveTarget:Fc,onDriveEnd:y0,pathPoints:MM,playhead:pu,onCollapse:()=>Tn(!0),viewportFrameRef:ha}),g0&&!w&&n.jsx(mH,{fpIsDark:ae,walkthroughStatus:ui,walkthroughElapsedLabel:yM,walkthroughCount:Je.length,walkthroughExportMode:Cn,walkthroughExportQuality:Bm,walkthroughExportProgress:nM,canCancelExport:!!bh.current,walkthroughs:Je,activeWalkthroughId:gh,onClose:rM,onStartRecording:Dl,onStopRecording:Fl,onStopPlayback:hi,onSetExportMode:oM,onSetExportQuality:M0,onCancelExport:()=>{var E;return(E=bh.current)==null?void 0:E.abort()},onPlay:E=>{gu(E,"playing")},onExport:E=>{lM(E)},onRename:iM,onDelete:aM,style:Gm}),rl!==null&&!w&&n.jsxs("div",{className:"pointer-events-none absolute inset-0 z-[96] flex items-center justify-center","aria-live":"assertive",role:"status",children:[n.jsx("div",{className:"absolute inset-0 bg-[#0b0c10]/35 backdrop-blur-[2px]"}),n.jsx("div",{className:"relative flex h-40 w-40 items-center justify-center rounded-full border-4 border-white/70 bg-[#182137]/70 font-heebo text-[110px] font-black leading-none text-white shadow-[0_20px_60px_rgba(11,12,16,0.45)]",style:{animation:"floorplanCountdownPulse 1s ease-out both"},children:n.jsx("span",{className:"tabular-nums",style:{letterSpacing:"-0.04em"},children:rl})},rl),n.jsx("style",{children:"@keyframes floorplanCountdownPulse{0%{transform:scale(0.55);opacity:0}
28822%{transform:scale(1.08);opacity:1}45%{transform:scale(1)}100%{transform:scale(1);opacity:0.92}}"})]}),nt&&n.jsxs("div",{"data-testid":"sketch-cladding-brush-badge",className:O("pointer-events-none fixed z-[70] flex items-center gap-2 rounded-xl border px-2.5 py-1.5 font-heebo text-[11px] font-black shadow-[0_10px_28px_rgba(24,33,55,0.20)]",ae?"border-white/12 bg-[#141416]/92 text-white":"border-[#182137]/12 bg-white/95 text-[#182137]"),dir:_s.dir(),style:{left:((dt==null?void 0:dt.x)??(H==null?void 0:H.x)??24)+14,top:((dt==null?void 0:dt.y)??(H==null?void 0:H.y)??24)+14},children:[n.jsx("span",{className:"h-5 w-5 shrink-0 rounded-md border border-black/10 bg-cover bg-center",style:nt.assignment.texture?{backgroundImage:`url("${nt.assignment.texture.url}")`}:{backgroundColor:nt.assignment.color??"#FFFFFF"}}),n.jsx("span",{children:It("viewer.cladding.active",{defaultValue:"חיפוי פעיל"})})]}),n.jsx(KN,{className:O(ir&&"floorplan-sketch-pencil-cursor"),camera:{fov:50,near:.05,far:ec*50},gl:{preserveDrawingBuffer:!0,antialias:!0,powerPreference:"high-performance"},style:{background:_?Qc.backgroundColor:"#d3d4d0"},onCreated:({gl:E})=>{Mi.current=E.domElement,si(E.domElement)},onDragOver:E=>{const F=E.dataTransfer.types.includes(G3),V=E.dataTransfer.types.includes(ob);!F&&(!wt||!V)||(E.preventDefault(),E.dataTransfer.dropEffect="copy")},onDrop:E=>{const F=r9(E.dataTransfer);if(F){E.preventDefault(),jm({payload:F,clientX:E.clientX,clientY:E.clientY,nonce:Date.now()});return}if(!wt)return;const V=E.dataTransfer.getData(ob);V&&(E.preventDefault(),Dr({templateId:V,clientX:E.clientX,clientY:E.clientY,nonce:Date.now()}))},onPointerMissed:E=>{if(E.button===2){Cs();return}E.button===0&&Ra()},children:n.jsxs(VS,{outdoor:_,children:[n.jsx(lU,{enabled:sd||_,outdoor:_,onFlagsChange:Zf}),_?n.jsx(qP,{bounds:oo,wallHeight:Ma,timeOfDayMinutes:Mr}):sd?n.jsx(dU,{bounds:oo,wallHeight:Ma,settings:Za}):n.jsx(cU,{}),n.jsx("group",{position:[oo.centerX,0,oo.centerZ],rotation:[0,kM,0],children:n.jsxs("group",{position:[-oo.centerX,0,-oo.centerZ],children:[_&&k&&n.jsx(bA,{environment:k,bounds:oo}),e.levels.map((E,F)=>{var Kt;if(a[E.id]===!1||(Ce==="inside"||Ce==="walkthrough")&&F>rs)return null;const V=nu[F]??0,at=F>0?Xb[F-1]:null,yt=at?n.jsx(MA,{envelope:at,thicknessMm:E.slabThicknessMm??Op}):null,zt=F===rs;if(!zt||o==="building"){const ke=zt?{roomFloorOverrides:N,roomFloorRegions:L,wallFaceRegions:S,roomCeilingOverrides:Fs,sketchEntities:Te,sketchFurnitureGroups:po}:l[E.id]??ZG,de=kl[F]??oo,ue=o==="building",mn=()=>i==null?void 0:i(E.id),Yn=()=>{Pa.current=!0,mn()},Xe=n.jsxs("group",{position:[0,V,0],onClick:ue?Sn=>{Sn.stopPropagation(),mn()}:void 0,onContextMenu:ue?Sn=>{Sn.stopPropagation(),Yn()}:void 0,children:[yt,n.jsx(j5,{level:E,bounds:de,materials:e.materials,nightStrength:_&&ue?Es:0,visualStyle:ru,outdoorShadowsEnabled:_&&ue,customModelUrls:M,customModelMaterialSlots:g,floorTextureUrl:C,roomFloorOverrides:ke.roomFloorOverrides,roomFloorRegions:ke.roomFloorRegions,wallFaceRegions:ke.wallFaceRegions,roomCeilingOverrides:ke.roomCeilingOverrides,tileSizeM:z,grout:X,measurementUnit:Lt,showCeiling:sh,selectedRegionId:null,selectedRoomSig:null,selectedWallId:null,selectedBeamId:null,selectedWallRegionId:null,selectedOpeningId:null,selectedOpeningGroupId:null,selectedCeilingRoomSig:null,selectedFurnitureIds:qG,interactionDisabled:!0,interactionMode:ue?"activate-only":"none",onWallClick:ue?mn:void 0,onWallDoubleClick:ue?mn:void 0,onWallContextMenu:ue?Yn:void 0,onOpeningClick:ue?mn:void 0,onBeamClick:ue?mn:void 0,onOpeningContextMenu:ue?Yn:void 0,onRoomFloorClick:ue?mn:void 0,onRoomFloorDoubleClick:ue?mn:void 0,onRegionClick:ue?mn:void 0,onRegionDoubleClick:ue?mn:void 0,onRemainderClick:ue?mn:void 0,onRoomFloorContextMenu:ue?Yn:void 0,onFurnitureClick:ue?mn:void 0,onFurnitureContextMenu:ue?Yn:void 0,furnitureSelectionEnabled:ue,furnitureTransformEnabled:!1,furnitureSelectOnDoubleClick:!1,levelElevationM:V,collisionGroupName:`walls-${E.id}`}),!w&&n.jsx(Iv,{bounds:de,activeTool:null,entities:ke.sketchEntities??JG,furnitureGroups:ke.sketchFurnitureGroups??QG,selectedEntityId:null,
288selectionVisualDepthMode:Ce==="inside"?"scene":"overlay",floorplanSketchAxesVisible:!1,measurementUnit:Lt,onEntitiesChange:K2,onSelectedEntityChange:K2,onActiveToolChange:K2})]});return o==="floor"?n.jsx(eU,{children:Xe},E.id):n.jsx("group",{children:Xe},E.id)}return n.jsxs("group",{position:[0,V,0],children:[yt,n.jsx(j5,{level:ce,bounds:oo,nightStrength:Es,simulateOpenings:j,openOpeningIds:v,visualStyle:ru,outdoorShadowsEnabled:_,onVisualStyleStatsChange:$n,materials:e.materials,customModelUrls:M,customModelMaterialSlots:g,floorTextureUrl:C,roomFloorOverrides:N,roomFloorRegions:L,selectedRegionId:gs,onRegionClick:a0,onRegionDoubleClick:a0,onRemainderClick:qb,onRegionPolygonChange:Jb,onFloorTileOriginChange:W,selectedRoomSig:ps,onRoomFloorClick:hh,onRoomFloorDoubleClick:Tm,onRoomFloorContextMenu:hu,tileSizeM:z,grout:X,wallTextures:ft,selectedWallId:ts,selectedBeamId:Mt,onBeamClick:Ub,selectedWallSide:yi,wallFaceRegions:S,selectedWallRegionId:Ce==="inside"?bs:null,onWallRegionClick:Ce==="inside"?c0:void 0,onWallRemainderClick:Ce==="inside"?d0:void 0,onWallRegionPolygonChange:Ce==="inside"?Sm:void 0,wallSelectMode:Na,onWallClick:nd,onWallContextMenu:ci&&!Oi?void 0:Ji,hiddenWallIds:Rr,onWallDoubleClick:eu,showWallDimensions:!w&&Ce==="orbit"&&!ci&&!Oi&&!cn&&!ns&&Pt!=="opening"&&Pt!=="furniture",measurementUnit:Lt,floorSelected:zs,onFloorClick:Kb,openingPlaceMode:Pt==="opening"&&!ci&&!Oi,onWallPlaceClick:m0,wallElectricalFixtures:Vn,selectedSwitchId:or,onSwitchClick:dr?Pm:void 0,electricalPlaceMode:!!cn,onWallElectricalPlace:cn?f0:void 0,wallNotes:Ce==="inside"?Ii:GG,selectedNoteId:Ce==="inside"?Ia:null,onNoteClick:Ce==="inside"&&fs?x0:void 0,notePlaceMode:Ce==="inside"&&!!ns,onWallNotePlace:Ce==="inside"&&ns?vr:void 0,onOpeningClick:ya,onOpeningContextMenu:tu,selectedOpeningId:xr,selectedOpeningGroupId:n0!==null&&Ot?((Kt=Ot[n0])==null?void 0:Kt.cornerGroupId)??null:null,selectedFurnitureIds:$s,furnitureRotateModeId:Kd,onFurnitureClick:Zb,selectedSmartGlbPart:Un,smartGlbEditFurnitureId:jc,onSmartGlbPartSelect:uo,onFurnitureContextMenu:Qd,furniturePlaceMode:Pt==="furniture"&&ih&&!ci&&!Oi,onFloorFurniturePlace:i0,onFurnitureDeselectClick:Qf,templatePlaceMode:Oi,onFloorTemplatePlace:ch,furnitureSelectionEnabled:!ci&&!Oi,furnitureTransformEnabled:Ce!=="inside"&&!ci&&!Oi,furnitureSelectOnDoubleClick:Ce==="orbit",interactionDisabled:Dm,interactionMode:"edit",levelElevationM:ga,collisionGroupName:`walls-${E.id}`,showCeiling:sh,roomCeilingOverrides:Fs,selectedCeilingRoomSig:sh?Zi:null,onCeilingClick:sh?ke=>{Si(ke),fe==null||fe("ceiling")}:void 0,onFurnitureMove:Im,onFurnitureGroupMove:lu,onFurnitureRotate:r0,onFurnitureDuplicate:cu,onFurnitureFlip:du,onFurnitureDelete:ld,onFurnitureResize:lh}),!w&&ua&&On&&As&&n.jsx(Iv,{bounds:oo,activeTool:$o,entities:Te,furnitureGroups:po,onFurnitureGroupsChange:Gi,selectedEntityId:ho,selectionVisualDepthMode:Ce==="inside"?"scene":"overlay",selectedFaceId:Kl,selectedRectangleEdgeIndex:go,floorplanSketchAxesVisible:da,measurementUnit:Lt,onEntitiesChange:ua,onSelectedEntityChange:On,onSelectedFaceChange:to,onSelectedRectangleEdgeChange:Wt,onElementMoveActiveChange:bc,onSelectedHostFaceRegionChange:qe,onActiveToolChange:As,lineLengthRequest:Se,commitLineRequestId:jn,onLineDraftLengthChange:je,onFaceLineMeasurementChange:ne,onFaceMeasureMeasurementChange:Re,onFaceMeasureMarkerPointerDown:Dn,faceMeasureLengthRequest:ge,commitFaceMeasureRequest:ie,updateFaceMeasureRequest:Ze,rectangleDimensionsRequest:as,onRectangleDraftDimensionsChange:Pe,onPushPullHeightChange:Ao,faceOffsetDistanceRequest:Lo,commitFaceOffsetRequest:Gt,onFaceOffsetPreviewChange:Co,sketchOffsetDistanceRequest:Xo,commitSketchOffsetRequest:pn,onSketchOffsetPreviewChange:Kn,wallSnapSegments:Kf,onSketchRightClickConsumed:()=>{Pa.current=!0},onDeferContextMenuToWall:Ji,onDeferClickToWall:zb,onRequestContextMenu:Ml,activeCladdingPaintAssignment:(nt==null?void 0:nt.assignment)??null,onCladdingPaintTarget:Ja,onCladdingPaintExit:Aa})]},E.id)}),c&&(no==null?void 0:no.canRender)&&tc&&(Ce==="orbit"||Ce==="top")&&n.jsx(zA,{config:c,host:no,selected:!w&&h,onSelect:w?void 0:()=>{Ra(),x==null||x(!0),fe==null||fe("roof")},onFocus:w?void 0:()=>x==null?void 0:x(!0,{focus:!0})}),!w&&c&&tc&&!(no!=null&&no.canRender)&&n.jsx(YA,{diagnostics:(no==null?void 0:no.diagnostics)??{openEndpoints:[],problematicWallIds:[],wallTopHeightsMm:[],manualOverrideStale:!1,manualOverrideInvalid:!1},elevationMm:(no==null?void 0:no.baseElevationMm)??0}),!w&&c&&tc&&f&&Ce==="top"&&(u==null?void 0:u.canRender)&&u.effectiveFootprint&&n.jsx(XA,{roofType:c.type,footprint:u.effectiveFootprint,baseElevationMm:u.baseElevationMm,overlayElevationMm:u.maxElevationMm,overhangMm:c.overhangMm,planRotationDeg:hs,rotationCenter:Qa,onPreviewChange:pc,onCommit:Gf}),!_&&n.jsx("gridHelper",{args:[ki.sizeM,ki.divisions,"#8f969d","#b3b8bd"],position:[0,BT,0]}),!w&&!Qo&&n.jsx(mB,{bounds:oo,position:ms??(wi?zT:null),rotation:Yo??(wi?$T:null),rotateMode:Eo,onPositionChange:Go,onRotationChange:er,onInteractingChange:Zp,onContextMenu:ai}),!w&&bi&&!!Lr&&(Ce==="orbit"||Ce==="top")&&ui!=="playing"&&ui!=="exporting"&&n.jsx(NU,{pose:iu,bounds:oo,planRotationDeg:hs,framingSpan:ec,elevation:ga,onChange:Lr,onInteractingChange:qp})]})}),n.jsx(CU,{posRef:Ki}),wt&&n.jsx(TU,{request:gc,elevation:ga,onResolved:(E,F)=>wt(E,F)}),n.jsx(IU,{request:qi,elevation:ga,onResolved:(E,F)=>{cd(E.type,F,E.label)}}),!w&&n.jsx(aU,{bounds:oo,figurePosition:ms,figureRotation:Yo,planRotationDeg:hs,cameraPreset:Ce}
288),n.jsx(HU,{preset:Ce,viewScope:o,focusRequestId:r,roofFocusTarget:Yb,bounds:oo,wallHeight:Math.max(Ma,od),elevation:ga,maxSceneHeightM:La,wallGroupName:ce?`walls-${ce.id}`:"walls",zoomTrigger:na,zoomTypeRef:Br,cameraPoseRef:fd,floorplanCameraPose:iu,onFloorplanCameraPoseChange:Lr,planRotationDeg:hs,teleportRef:xh,rotateRef:xd,smoothDriveTargetRef:ol,walkthroughPlaybackRef:Dc,onWalkthroughPlaybackFrame:E=>{xu(E.tMs),rx({x:E.position[0],z:E.position[2]})},registerWalkthroughRenderer:E=>{b0.current=E},roomCenter:kc,cameraHeight:_l,interiorFov:vc,cameraAimCommand:Cr,compact:w,controlsDisabled:sM,externalOrbitRef:Hr,isEmptyScene:wi})]})}),jl&&n.jsx(BU,{isDark:Us,onPan:Jf}),!w&&cn&&n.jsx("div",{className:"absolute top-3 left-1/2 z-20 -translate-x-1/2 rounded-full bg-[#182137]/90 text-white px-4 py-2 text-[11px] font-semibold shadow-lg pointer-events-none",dir:_s.dir(),children:It("viewer.placement.electrical",{item:wM,defaultValue:`מצב הצבת ${SB(cn)} — לחץ על קיר (Esc לביטול)`})}),!w&&ns&&Ce==="inside"&&n.jsx("div",{className:"absolute top-3 left-1/2 z-20 -translate-x-1/2 rounded-full bg-[#182137]/90 text-white px-4 py-2 text-[11px] font-semibold shadow-lg pointer-events-none",dir:_s.dir(),children:It("viewer.placement.note",{defaultValue:"מצב הצבת פתק — לחץ על הקיר (Esc לביטול)"})}),pa&&it&&(()=>{const E=ce==null?void 0:ce.walls.find(F=>F.id===pa.wallId);return E?n.jsx(FU,{x:pa.x,y:pa.y,currentLengthMm:F2(E),measurementUnit:Lt,isDark:ae,onCommit:F=>it(E.id,F),onClose:()=>To(null)},E.id):null})(),gn&&(()=>{const E=3+(Nt?1:0)+(oe?1:0)+(Ce==="inside"&&dr?1:0)+(Ce==="inside"&&Hn?1:0),F=LH(gn.x,gn.y,PH,WH(E));return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fixed inset-0 z-[60]",onClick:()=>Zo(null),onContextMenu:V=>{V.preventDefault(),Zo(null)}}),n.jsxs("div",{className:`fixed z-[61] min-w-[180px] rounded-xl bg-white border border-black/10
289                       shadow-[0_8px_24px_-4px_rgba(0,0,0,0.18)] py-1 font-heebo`,style:{left:F.x,top:F.y},dir:_s.dir(),onContextMenu:V=>V.preventDefault(),children:[(()=>{const V=tt==null?void 0:tt.find(zt=>zt.id===gn.wallId),yt=!!(gn.side==="front"?V==null?void 0:V.texture:gn.side==="back"?V==null?void 0:V.backTexture:V==null?void 0:V.edgeTexture);return n.jsxs("button",{type:"button",onClick:()=>{q({wallId:gn.wallId,x:gn.x,y:gn.y,side:gn.side}),Zo(null)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#18181b]
290                             hover:bg-black/[0.04] active:bg-black/[0.08] transition-colors text-right`,children:[n.jsx(Gh,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:yt?It("viewer.menu.editCladding",{defaultValue:"ערוך חיפוי"}):It("viewer.menu.addCladding",{defaultValue:"הוסף חיפוי"})})]})})(),n.jsxs("button",{type:"button",onClick:()=>wl(gn.wallId),className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#18181b]
291                         hover:bg-black/[0.04] active:bg-black/[0.08] transition-colors text-right`,children:[n.jsx(fc,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("viewer.menu.hideWall",{defaultValue:"הסתר קיר"})})]}),Nt&&n.jsxs("button",{type:"button",onClick:()=>{xe({x:gn.x,y:gn.y}),Zo(null)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#18181b]
292                           hover:bg-black/[0.04] active:bg-black/[0.08] transition-colors text-right`,children:[n.jsx(D1,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("viewer.menu.resize",{defaultValue:"שנה גודל"})})]}),oe&&n.jsxs("button",{type:"button",onClick:()=>{wn({wallId:gn.wallId,side:gn.side,x:gn.x,y:gn.y}),Zo(null)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#18181b]
293                           hover:bg-black/[0.04] active:bg-black/[0.08] transition-colors text-right`,children:[n.jsx(Gh,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("viewer.menu.addCarpentryTemplate",{defaultValue:"הוסף תבנית נגרות"})})]}),Ce==="inside"&&dr&&n.jsxs("button",{type:"button",onClick:()=>{He({wallId:gn.wallId,side:gn.side,x:gn.x,y:gn.y}),Zo(null)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#18181b]
294                           hover:bg-black/[0.04] active:bg-black/[0.08] transition-colors text-right`,children:[n.jsx(_w,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("viewer.menu.addElectrical",{defaultValue:"הוסף חשמל"})})]}),Ce==="inside"&&Hn&&n.jsxs("button",{type:"button",onClick:()=>{mh({x:gn.x,y:gn.y}),Zo(null)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#18181b]
295                           hover:bg-black/[0.04] active:bg-black/[0.08] transition-colors text-right`,children:[n.jsx(Af,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("viewer.menu.addNote",{defaultValue:"הוסף פתק"})})]}),n.jsx("button",{type:"button",onClick:()=>Zo(null),className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#71717a]
296                         hover:bg-black/[0.04] transition-colors text-right`,children:n.jsx("span",{children:It("common.cancel",{defaultValue:"ביטול"})})})]})]})})(),un&&(he||pe||te||Ce==="inside"&&Hn)&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fixed inset-0 z-[60]",onClick:()=>hr(null),onContextMenu:E=>{E.preventDefault(),hr(null)}}),n.jsxs("div",{className:`fixed z-[61] min-w-[180px] rounded-xl bg-white border border-black/10
297                       shadow-[0_8px_24px_-4px_rgba(0,0,0,0.18)] py-1 font-heebo`,style:{left:Math.max(8,Math.min(un.x,window.innerWidth-200)),top:Math.max(8,Math.min(un.y,window.innerHeight-(44+(he?36:0)+(pe?36:0)+(te?36:0)+(Ce==="inside"&&Hn?36:0))))},dir:_s.dir(),onContextMenu:E=>E.preventDefault(),children:[he&&n.jsxs("button",{type:"button",onClick:()=>{Ta({pointMm:un.pointMm,x:un.x,y:un.y}),hr(null)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#18181b]
298                           hover:bg-black/[0.04] active:bg-black/[0.08] transition-colors text-right`,children:[n.jsx(um,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("viewer.menu.addTemplate",{defaultValue:"הוסף תבנית"})})]}),pe&&n.jsxs("button",{type:"button",onClick:()=>{Ro(un.roomSig),bo(un.regionId??null),es(!0),Ai({roomSig:un.roomSig,regionId:un.regionId,x:un.x,y:Math.max(8,un.y-K8)}),hr(null)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#18181b]
299                           hover:bg-black/[0.04] active:bg-black/[0.08] transition-colors text-right`,children:[n.jsx(np,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("viewer.menu.changeFlooring",{defaultValue:"שנה ריצוף"})})]}),te&&n.jsxs("button",{type:"button",onClick:()=>{Qt==null||Qt(),U==null||U("furniture"),Er({roomSig:un.roomSig,x:un.x,y:Math.max(8,un.y-K8)}),hr(null)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#18181b]
300                           hover:bg-black/[0.04] active:bg-black/[0.08] transition-colors text-right`,children:[n.jsx(wf,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("viewer.menu.addFurniture",{defaultValue:"הוסף רהיט"})})]}),Ce==="inside"&&Hn&&n.jsxs("button",{type:"button",onClick:()=>{mh({x:un.x,y:un.y}),hr(null)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#18181b]
301                           hover:bg-black/[0.04] active:bg-black/[0.08] transition-colors text-right`,children:[n.jsx(Af,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("viewer.menu.addNote",{defaultValue:"הוסף פתק"})})]}),n.jsx("button",{type:"button",onClick:()=>hr(null),className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#71717a]
302                         hover:bg-black/[0.04] transition-colors text-right`,children:n.jsx("span",{children:It("common.cancel",{defaultValue:"ביטול"})})})]})]}),En&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fixed inset-0 z-[60]",onClick:()=>
302{En.onClose(),Fr(null)},onContextMenu:E=>{E.preventDefault(),En.onClose(),Fr(null)}}),n.jsxs("div",{className:`fixed z-[61] min-w-[144px] rounded-xl bg-white border border-black/10
303                       shadow-[0_8px_24px_-4px_rgba(0,0,0,0.18)] py-1 font-heebo`,style:{left:Math.max(8,Math.min(En.x,window.innerWidth-208)),top:Math.max(8,Math.min(En.y,window.innerHeight-(76+(En.canMove?36:0)+(En.canSnapToWall?36:0)+(En.canDuplicate?En.canDuplicateAdjacent?72:36:0)+(En.canMirror?36:0)+(En.canRotate?36:0)+(En.claddingTarget?36:0)+(Ce==="inside"&&En.canPushPull?36:0)+(En.templateEditTarget?36:0))))},dir:_s.dir(),onContextMenu:E=>E.preventDefault(),children:[En.templateEditTarget&&n.jsxs("button",{type:"button",onClick:()=>{Wi(En),En.onClose(),Fr(null)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-bold text-[#182137]
304                           transition-colors hover:bg-[#FFF3EC] text-start`,children:[n.jsx(F1,{size:13,strokeWidth:2.2,className:"text-[#D84B2E]"}),n.jsx("span",{children:It("viewer.sketchMenu.askBordi",{defaultValue:"בקש שינויים מבורדי"})})]}),En.claddingTarget&&n.jsxs("button",{type:"button",onClick:()=>{const E=En.claddingTarget;if(!E)return;const F=Z8(Te,E);Ut(F!=null&&F.color&&!F.texture?"color":"cladding"),K({x:En.x,y:En.y,target:E}),En.onClose(),Fr(null)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-bold text-[#182137]
305                           transition-colors hover:bg-[#EEF4FF] text-start`,children:[n.jsx(Gh,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:En.hasCladding?It("viewer.menu.editCladding",{defaultValue:"ערוך חיפוי"}):It("viewer.menu.addCladding",{defaultValue:"הוסף חיפוי"})})]}),Ce==="inside"&&En.canPushPull&&n.jsxs("button",{type:"button",onClick:()=>{En.onPushPull(),Fr(null)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-bold text-[#182137]
306                           transition-colors hover:bg-[#EEF4FF] text-start`,children:[n.jsx(U1,{className:"h-[15px] w-[15px] opacity-70"}),n.jsx("span",{children:"Push/Pull"})]}),En.canMove&&n.jsxs("button",{type:"button",onClick:()=>{En.onMove(),Fr(null)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-bold text-[#182137]
307                           transition-colors hover:bg-[#EEF4FF] text-start`,children:[n.jsx(LI,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:En.moveTarget==="template"?It("viewer.sketchMenu.moveTemplate",{defaultValue:"הזז תבנית"}):It("viewer.sketchMenu.moveElement",{defaultValue:En.moveLabel})})]}),En.canSnapToWall&&n.jsxs("button",{type:"button",onClick:()=>{En.onSnapToWall(),Fr(null)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-bold text-[#182137]
308                           transition-colors hover:bg-[#EEF4FF] text-start`,children:[n.jsx(mT,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("viewer.sketchMenu.snapToWall",{defaultValue:"הצמד לקיר"})})]}),En.canDuplicate&&(En.canDuplicateAdjacent?n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button",onClick:()=>{En.onDuplicateRight(),Fr(null)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-bold text-[#182137]
309                             transition-colors hover:bg-[#F7F4EF] text-start`,children:[n.jsx(s5,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("viewer.sketchMenu.duplicateRight",{defaultValue:"שכפל לימין"})})]}),n.jsxs("button",{type:"button",onClick:()=>{En.onDuplicateLeft(),Fr(null)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-bold text-[#182137]
310                             transition-colors hover:bg-[#F7F4EF] text-start`,children:[n.jsx(o5,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("viewer.sketchMenu.duplicateLeft",{defaultValue:"שכפל לשמאל"})})]})]}):n.jsxs("button",{type:"button",onClick:()=>{En.onDuplicate(),Fr(null)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-bold text-[#182137]
311                           transition-colors hover:bg-[#F7F4EF] text-start`,children:[n.jsx(Pf,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("common.duplicate",{defaultValue:"שכפל"})})]})),En.canMirror&&n.jsxs("button",{type:"button",onClick:()=>{En.onMirror(),Fr(null)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-bold text-[#182137]
312                           transition-colors hover:bg-[#EEF4FF] text-start`,children:[n.jsx(N1,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("common.flip",{defaultValue:"הפוך"})})]}),En.canRotate&&n.jsxs("button",{type:"button",onClick:()=>{const E=En.onRotateStep??En.onRotate90;E==null||E(),Fr(null)},className:`w-full flex items-center justify-start gap-2 px-3 py-2 text-[12px] font-bold text-[#182137]
313                           transition-colors hover:bg-[#EEF4FF] text-start`,children:[n.jsx(zu,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("viewer.menu.rotate",{defaultValue:"סובב"})})]}),n.jsxs("button",{type:"button",onClick:()=>{En.onDelete(),Fr(null)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-bold text-[#B42318]
314                         transition-colors hover:bg-[#FFF1F0] text-start`,children:[n.jsx(gi,{size:13,strokeWidth:2,className:"opacity-80"}),n.jsx("span",{children:It("common.delete",{defaultValue:"מחק"})})]})]})]}),wr&&n.jsxs("div",{"data-testid":"template-editor-chat",className:`fixed z-[72] w-[min(360px,calc(100vw-24px))] overflow-hidden rounded-2xl border border-[#D84B2E]/20 bg-[#F7F4EF]
315                     font-heebo shadow-[0_18px_56px_-18px_rgba(24,33,55,0.45)]`,style:{left:wr.x,top:wr.y},dir:"rtl",children:[n.jsxs("div",{"data-testid":"template-editor-chat-header",className:"flex cursor-grab touch-none select-none items-center justify-between border-b border-[#182137]/10 bg-white/86 px-3.5 py-3 active:cursor-grabbing",onPointerDown:vl,onPointerMove:oh,onPointerUp:Em,onPointerCancel:Em,children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[n.jsx("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-gradient-to-br from-[#EC7357] to-[#D84B2E] text-white shadow-sm",children:n.jsx(F1,{size:18,strokeWidth:2.3})}),n.jsxs("div",{className:"min-w-0 text-right",children:[n.jsxs("div",{className:"flex items-center gap-1.5 text-[14px] font-black text-[#182137]",children:[n.jsx(zl,{size:13,className:"text-[#D84B2E]"}),n.jsx("span",{children:"בורדי"})]}),n.jsx("div",{className:"text-[11px] font-semibold text-[#182137]/56",children:"עורכת תבנית קיימת"})]})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[tr>0&&n.jsxs("span",{className:"rounded-full bg-[#FFF0E8] px-2 py-1 text-[10px] font-black text-[#B64228]",children:[tr," ברקע"]}),n.jsx("button",{type:"button",onClick:()=>qa(null),onPointerDown:E=>E.stopPropagation(),className:"flex h-8 w-8 items-center justify-center rounded-full text-[#182137]/55 transition-colors hover:bg-[#182137]/8 hover:text-[#182137]","aria-label":"סגור",children:n.jsx(Gr,{size:16})})]})]}),n.jsxs("div",{className:"flex max-h-[260px] flex-col gap-2 overflow-y-auto px-3.5 py-3",children:[wr.messages.map(E=>n.jsx("div",{className:O("max-w-[88%] whitespace-pre-wrap rounded-2xl px-3 py-2 text-right text-[12px] font-semibold leading-relaxed",E.role==="user"?"self-start bg-gradient-to-br from-[#EC7357] to-[#D84B2E] text-white shadow-sm":"self-end border border-[#182137]/8 bg-white text-[#182137] shadow-sm"),children:E.content},E.id)),wr.isSending&&n.jsx("div",{className:"self-end rounded-2xl border border-[#182137]/8 bg-white px-3 py-2 text-[#182137]/70 shadow-sm",children:n.jsx(Xa,{size:15,className:"animate-spin"})})]}),n.jsx("div",{className:"border-t border-[#182137]/10 bg-white/80 p-3",children:n.jsxs("form",{className:"flex items-end gap-2",onSubmit:E=>{E.preventDefault(),Ri()},children:[n.jsx("textarea",{value:wr.input,onChange:E=>{const F=E.target.value;qa(V=>V&&{...V,input:F})},onKeyDown:E=>{E.key==="Enter"&&!E.shiftKey&&(E.preventDefault(),Ri())},rows:3,placeholder:"מה לשנות בתבנית?",className:`min-h-[72px] flex-1 resize-none rounded-xl border border-[#D8CDC0] bg-[#FFFDF9] px-3 py-2 text-right text-[12px]
316                           font-semibold text-[#182137] outline-none transition focus:border-[#EC7357] focus:ring-2 focus:ring-[#EC7357]/18`,disabled:wr.isSending}),n.jsx("button",{type:"submit",disabled:wr.isSending||wr.input.trim().length===0,className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-gradient-to-br from-[#EC7357] to-[#D84B2E]
317                           text-white shadow-md transition hover:scale-[1.02] disabled:cursor-not-allowed disabled:opacity-50`,"aria-label":"שלח",children:wr.isSending?n.jsx(Xa,{size:17,className:"animate-spin"}):n.jsx(gN,{size:17})})]})})]}),fa&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fixed inset-0 z-[60]",onClick:()=>xa(null),onContextMenu:E=>{E.preventDefault(),xa(null)}}),n.jsxs("div",{className:`fixed z-[61] min-w-[160px] rounded-xl bg-white border border-black/10
318                       shadow-[0_8px_24px_-4px_rgba(0,0,0,0.18)] py-1 font-heebo`,style:{left:Math.min(fa.x,window.innerWidth-180),top:Math.min(fa.y,window.innerHeight-124)},dir:_s.dir(),onContextMenu:E=>E.preventDefault(),children:[dx.length>0&&n.jsxs("button",{type:"button",onClick:()=>{var V;const E=fa.furnitureId,F=(Un==null?void 0:Un.furnitureId)===E&&dx.some(at=>at.id===Un.slotId)?Un.slotId:(V=dx[0])==null?void 0:V.id;F&&(Nr(new Set([E])),ws(!1),Wo(null),Kr(null),Wr(!1),es(!1),Ro(null),bo(null),ks(null),Si(null),Hi(E),Zl(null),Pt!=="furniture"&&(el.current=!0),U==null||U("furniture"),ze==null||ze([E]),fe==null||fe("furniture",!0),uo==null||uo(E,F),xa(null))},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-bold text-emerald-800
319                           hover:bg-emerald-50 active:bg-emerald-100 transition-colors text-right`,children:[n.jsx(Gh,{size:13,strokeWidth:2,className:"opacity-80"}),n.jsx("span",{children:It("viewer.menu.replaceCladding",{defaultValue:"החלף חיפוי"})})]}),n.jsxs("button",{type:"button",onClick:()=>{const E=fa.furnitureId;Nr(new Set([E])),ws(!1),Wo(null),Kr(null),Wr(!1),es(!1),Ro(null),bo(null),ks(null),Si(null),Hi(null),dn==null||dn(),Zl(E),ze==null||ze([E]),xa(null)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#18181b]
320                         hover:bg-black/[0.04] active:bg-black/[0.08] transition-colors text-right`,children:[n.jsx(zu,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("viewer.menu.rotate",{defaultValue:"סובב"})})]}),n.jsxs("button",{type:"button",onClick:()=>{const E=fa.furnitureId;Nr(new Set([E])),ws(!1),Wo(null),Kr(null),Wr(!1),es(!1),Ro(null),bo(null),ks(null),Si(null),Hi(null),Zl(null),dn==null||dn(),Pt!=="furniture"&&(el.current=!0),U==null||U("furniture"),ze==null||ze([E]),fe==null||fe("furniture",!0),xa(null)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#18181b]
321                         hover:bg-black/[0.04] active:bg-black/[0.08] transition-colors text-right`,children:[n.jsx(um,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("viewer.menu.editFurniture",{defaultValue:"ערוך רהיט"})})]})]})]}),ed&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fixed inset-0 z-[60]",onClick:()=>kr(null),onContextMenu:E=>{E.preventDefault(),kr(null)}}),n.jsxs("div",{className:`fixed z-[61] min-w-[180px] rounded-xl bg-white border border-black/10
322                       shadow-[0_8px_24px_-4px_rgba(0,0,0,0.18)] py-1 font-heebo`,style:{left:Math.min(ed.x,window.innerWidth-200),top:Math.min(ed.y,window.innerHeight-100)},dir:_s.dir(),onContextMenu:E=>E.preventDefault(),children:[ed.mode==="hide"?n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button",onClick:Jp,className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#18181b]
323                             hover:bg-black/[0.04] active:bg-black/[0.08] transition-colors text-right`,children:[n.jsx(zu,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("viewer.menu.rotate",{defaultValue:"סובב"})})]}),n.jsxs("button",{type:"button",onClick:yc,className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#18181b]
324                             hover:bg-black/[0.04] active:bg-black/[0.08] transition-colors text-right`,children:[n.jsx(fc,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("viewer.menu.hideFigure",{defaultValue:"הסתר דמות"})})]})]}):n.jsxs("button",{type:"button",onClick:$b,className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#18181b]
325                           hover:bg-black/[0.04] active:bg-black/[0.08] transition-colors text-right`,children:[n.jsx(Hd,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("viewer.menu.showFigure",{defaultValue:"הפעל דמות"})})]}),n.jsx("button",{type:"button",onClick:()=>kr(null),className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#71717a]
326                         hover:bg-black/[0.04] transition-colors text-right`,children:n.jsx("span",{children:It("common.cancel",{defaultValue:"ביטול"})})})]})]}),Ws&&Ot&&(()=>{var bu;const E=Ot.findIndex(Xs=>Xs.id===Ws.openingId);if(E<0)return null;const F=Ot[E],V=F.type==="window",at=F.preset==="single_door_glass"||F.preset==="arched_door_glass"||F.preset==="corner_glass_door",yt=Yw(F.preset),zt=F.type==="window"&&F.preset==="casement_window",Kt=!V&&!at&&!yt,ke=hm(F),de=Lf(F),ue=!!((bu=F.panelCladding)!=null&&bu[Ws.side]),mn=()=>{io({openingId:F.id,x:Ws.x,y:Ws.y,side:Ws.side}),yr(null)},Yn=()=>{const Xs=Ws.objectAnchor;Xt({openingId:F.id,x:Xs?Xs.x+24:Ws.x+180,y:Xs?Xs.y-210:Ws.y-120,referenceFace:Ws.side}),yr(null)},Xe=Xs=>{if(!Ue)return;const wh=Wd(F);Ue(Ot.map((kh,fo)=>fo===E?{...kh,...rm({...wh,swingFace:Xs})}:kh)),ks(E),yr(null)},Sn=Ws.side==="front"?"back":"front",mo=V?It("viewer.opening.windowDirection",{defaultValue:"כיוון פתיחת חלון"}):It("viewer.opening.doorDirection",{defaultValue:"כיוון פתיחת דלת"}),vs=(zt?260:172)+(Ue?72:0)+(de?36:0),yo=()=>
326{if(!Ue||!tt||!so)return;const Xs=Z1(Ot,F.id,tt,so);Xs&&(Ue(Xs.next),ks(Xs.newIdx),yr(null))},Bi=()=>{Ue&&(Ue(Ot.filter((Xs,wh)=>wh!==E&&(!F.cornerGroupId||Xs.cornerGroupId!==F.cornerGroupId))),ks(null),yr(null))};return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fixed inset-0 z-[60]",onClick:()=>yr(null),onContextMenu:Xs=>{Xs.preventDefault(),yr(null)}}),n.jsxs("div",{className:`fixed z-[61] min-w-[180px] rounded-xl bg-white border border-black/10
327                         shadow-[0_8px_24px_-4px_rgba(0,0,0,0.18)] py-1 font-heebo max-h-[260px] overflow-y-auto`,style:{left:Math.max(12,Math.min(Ws.x,window.innerWidth-212)),top:Math.max(12,Math.min(Ws.y,window.innerHeight-vs))},dir:_s.dir(),onContextMenu:Xs=>Xs.preventDefault(),children:[Kt&&n.jsxs("button",{type:"button",onClick:mn,className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#18181b]
328                             hover:bg-black/[0.04] active:bg-black/[0.08] transition-colors text-right`,children:[n.jsx(Gh,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:ue?It("viewer.menu.editCladding",{defaultValue:"ערוך חיפוי"}):It("viewer.menu.addCladding",{defaultValue:"הוסף חיפוי"})})]}),ke&&n.jsxs("button",{type:"button",onClick:Yn,className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#18181b]
329                             hover:bg-black/[0.04] active:bg-black/[0.08] transition-colors text-right`,children:[n.jsx(N1,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:mo})]}),de&&n.jsxs("button",{type:"button",onClick:Yn,className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#18181b]
330                             hover:bg-black/[0.04] active:bg-black/[0.08] transition-colors text-right`,children:[n.jsx(np,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("viewer.opening.zeroLineSide",{defaultValue:"צד קו 0"})})]}),zt&&Ue&&n.jsxs(n.Fragment,{children:[n.jsxs("button",{type:"button",onClick:()=>Xe(Ws.side),className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#18181b]
331                               hover:bg-black/[0.04] active:bg-black/[0.08] transition-colors text-right`,children:[n.jsx(s5,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("viewer.opening.openOutward",{defaultValue:"פתח החוצה"})})]}),n.jsxs("button",{type:"button",onClick:()=>Xe(Sn),className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#18181b]
332                               hover:bg-black/[0.04] active:bg-black/[0.08] transition-colors text-right`,children:[n.jsx(o5,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("viewer.opening.openInward",{defaultValue:"פתח פנימה"})})]})]}),n.jsxs("button",{type:"button",onClick:()=>{const Xs=Ws.objectAnchor;bt({openingId:F.id,x:Xs?Xs.x+24:Ws.x+180,y:Xs?Xs.y-160:Ws.y-120}),yr(null)},className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#18181b]
333                           hover:bg-black/[0.04] active:bg-black/[0.08] transition-colors text-right`,children:[n.jsx(D1,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("viewer.opening.resize",{defaultValue:"שנה גודל פתח"})})]}),Ue&&!F.cornerGroupId&&n.jsxs("button",{type:"button",onClick:yo,className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#18181b]
334                             hover:bg-black/[0.04] active:bg-black/[0.08] transition-colors text-right`,children:[n.jsx(Pf,{size:13,strokeWidth:2,className:"opacity-70"}),n.jsx("span",{children:It("common.duplicate",{defaultValue:"שכפל"})})]}),Ue&&n.jsxs("button",{type:"button",onClick:Bi,className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] font-bold text-[#B42318]
335                             hover:bg-[#FFF1F0] active:bg-[#FFE4E1] transition-colors text-right`,children:[n.jsx(gi,{size:13,strokeWidth:2,className:"opacity-80"}),n.jsx("span",{children:It("common.delete",{defaultValue:"מחק"})})]}),n.jsx("button",{type:"button",onClick:()=>yr(null),className:`w-full flex items-center gap-2 px-3 py-2 text-[12px] text-[#71717a]
336                           hover:bg-black/[0.04] transition-colors text-right border-t border-black/[0.06]`,children:n.jsx("span",{children:It("common.cancel",{defaultValue:"ביטול"})})})]})]})})(),ys&&Ot&&Ue&&(()=>{var Kt;
336const E=Ot.findIndex(ke=>ke.id===ys.openingId);if(E<0)return null;const F=Ot[E],V=ys.side,at=(Kt=F.panelCladding)==null?void 0:Kt[V],yt=at?{url:at.url,tileSizeM:[at.tileSizeM[0],at.tileSizeM[1]],orientation:ei(at.orientation)}:void 0,zt=ke=>{const ue={...F.panelCladding??{},[V]:ke},Yn=!!(ue.front||ue.back)?{...F,panelCladding:{front:ue.front,back:ue.back}}:{...F,panelCladding:void 0};Ue(Ot.map((Xe,Sn)=>Sn===E?Yn:Xe))};return ux({position:{x:ys.x,y:ys.y},current:yt,title:It("viewer.cladding.doorTitle",{defaultValue:"חיפוי לדלת"}),savedTiles:st,getSavedTileUrl:ke=>_f(ke.storage_path),onUploadTile:ct,onRemoveTile:pt,onRenameTile:xt,onApply:ke=>zt(ke),onRemove:()=>zt(void 0),onClose:()=>{_o(),io(null)},onPositionChange:ke=>io(de=>de&&{...de,x:ke.x,y:ke.y})})})(),et&&tt&&G&&(()=>{var Sn;const E=tt.find(mo=>mo.id===et.wallId);if(!E)return null;const F=et.side,V=F==="front"?E.texture:F==="back"?E.backTexture:E.edgeTexture,at=F==="front"?E.color:F==="back"?E.backColor:E.edgeColor,yt=V?{url:V.url,tileSizeM:[V.tileWidthCm/100,V.tileHeightCm/100],orientation:ei(V.orientation)}:void 0,zt=V?{widthMm:V.groutWidthMm,color:V.groutColor}:void 0,Kt=mo=>{const vs={url:mo.url,tileWidthCm:mo.tileSizeM[0]*100,tileHeightCm:mo.tileSizeM[1]*100,groutWidthMm:(V==null?void 0:V.groutWidthMm)??0,groutColor:(V==null?void 0:V.groutColor)??"#c8c4bc",orientation:ei(mo.orientation??(V==null?void 0:V.orientation))};mr(et.wallId,F,vs)},ke=V?(mo,vs)=>{const yo={...V,groutWidthMm:mo,groutColor:vs};mr(et.wallId,F,yo)}:void 0,de=()=>mr(et.wallId,F,void 0),ue=mo=>mr(et.wallId,F,void 0,mo),mn=F==="front"||F==="back",Yn=`${et.wallId}__${F}`,Xe=(((Sn=S==null?void 0:S[Yn])==null?void 0:Sn.length)??0)>0;return ux({position:{x:et.x,y:et.y},current:yt,currentColor:at,title:It("viewer.cladding.wallTitle",{defaultValue:"חיפוי לקיר"}),savedTiles:st,getSavedTileUrl:mo=>_f(mo.storage_path),onUploadTile:ct,onRemoveTile:pt,onRenameTile:xt,onApply:Kt,onApplyColor:ue,onRemove:de,onClose:()=>{_o(),q(null)},grout:zt,onGroutChange:ke,isDivided:Xe,onDivide:mn&&!Xe?()=>{u0(et.wallId,F),_o(),q(null)}:void 0,onMerge:mn&&Xe?()=>{h0(et.wallId,F),_o(),q(null)}:void 0,onPositionChange:mo=>q(vs=>vs&&{...vs,x:mo.x,y:mo.y})})})(),H&&ua&&(()=>{const E=H.target,F=Te.find(Xe=>Xe.id===E.entityId);if(!k7(F))return null;const V=Z8(Te,E),at=a9(E.faceId),yt=V==null?void 0:V.texture,zt=yt?{url:yt.url,tileSizeM:[yt.tileWidthCm/100,yt.tileHeightCm/100],orientation:ei(yt.orientation)}:void 0,Kt=Xe=>{const Sn={url:Xe.url,tileWidthCm:Math.round(Xe.tileSizeM[0]*100),tileHeightCm:Math.round(Xe.tileSizeM[1]*100),groutWidthMm:(yt==null?void 0:yt.groutWidthMm)??at.groutWidthMm,groutColor:(yt==null?void 0:yt.groutColor)??at.groutColor,orientation:ei(Xe.orientation??(yt==null?void 0:yt.orientation))},mo=Ns(E,{texture:Sn,color:void 0});mo&&K(vs=>vs&&{...vs,target:mo}),Mc({texture:Sn},{x:H.x,y:H.y})},ke=Xe=>{const Sn=Ns(E,{color:Xe,texture:void 0});Sn&&K(mo=>mo&&{...mo,target:Sn}),Mc({color:Xe},{x:H.x,y:H.y})},de=()=>{Ns(E,{color:void 0,texture:void 0}),Q(null),jt(null)},ue=yt?(Xe,Sn)=>{const mo={...yt,groutWidthMm:Xe,groutColor:Sn};Ns(E,{texture:mo}),Mc({texture:mo},{x:H.x,y:H.y})}:void 0,mn=new Set((st??[]).map(Xe=>Xe.id)),Yn=[...st??[],...kt??[]];return ux({position:{x:H.x,y:H.y},current:zt,currentColor:V==null?void 0:V.color,title:It("viewer.cladding.elementTitle",{defaultValue:"חיפוי לאלמנט"}),textures:di,savedTiles:Yn,getSavedTileUrl:Xe=>mn.has(Xe.id)?_f(Xe.storage_path):Gx(Xe.storage_path),onApply:Kt,onApplyColor:ke,onRemove:de,onClose:Aa,onPositionChange:Xe=>K(Sn=>Sn&&{...Sn,x:Xe.x,y:Xe.y}),modalBackdrop:!nt,variant:"compact",grout:yt?{widthMm:yt.groutWidthMm,color:yt.groutColor}:void 0,onGroutChange:ue})})(),Dt&&Ot&&(()=>{const E=Ot.findIndex(de=>de.id===Dt.openingId);if(E<0)return null;const F=Ot[E],V=(F==null?void 0:F.type)==="window",at=340,yt=420,zt=Math.max(12,Math.min(Dt.x,window.innerWidth-at-12)),Kt=Math.max(12,Math.min(Dt.y,window.innerHeight-yt-12)),ke=()=>Xt(null);return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fixed inset-0 z-[60]",onClick:ke,onContextMenu:de=>{de.preventDefault(),ke()}}),n.jsxs("div",{className:O("fixed z-[61] rounded-2xl border shadow-[0_12px_36px_-6px_rgba(0,0,0,0.28)] font-heebo overflow-hidden flex flex-col",ae?"bg-[#141416] border-white/10":"bg-white border-black/10"),style:{left:zt,top:Kt,width:at,maxHeight:yt},dir:_s.dir(),onContextMenu:de=>de.preventDefault(),onClick:de=>de.stopPropagation(),children:[n.jsxs("div",{className:O("flex items-center justify-between px-3 py-2.5 border-b shrink-0 select-none cursor-move",ae?"border-white/10":"border-black/[0.06]"),title:It("trace.dragToMove",{defaultValue:"גרור להזזה"}),onPointerDown:de=>
336pM(de,{left:zt,top:Kt,panelWidth:at,panelHeight:yt}),onPointerMove:gM,onPointerUp:E0,onPointerCancel:E0,children:[n.jsxs("div",{children:[n.jsx("div",{className:O("text-[12px] font-semibold",ae?"text-white/90":"text-[#18181b]"),children:V?It("viewer.opening.windowDirection",{defaultValue:"כיוון פתיחת חלון"}):It("viewer.opening.doorDirection",{defaultValue:"כיוון פתיחת דלת"})}),n.jsx("div",{className:O("text-[10px]",ae?"text-white/45":"text-[#71717a]"),children:V?It("viewer.opening.windowDirectionHint",{defaultValue:"בחר ציר ואת הצד שאליו החלון נפתח"}):It("viewer.opening.doorDirectionHint",{defaultValue:"בחר ציר ואת הצד שאליו הדלת נפתחת"})})]}),n.jsx("button",{onPointerDown:de=>de.stopPropagation(),onClick:ke,className:O("w-6 h-6 rounded-md flex items-center justify-center cursor-pointer",ae?"text-white/45 hover:text-white hover:bg-white/10":"text-[#71717a] hover:text-[#18181b] hover:bg-black/5"),children:n.jsx("span",{className:"text-[14px] leading-none",children:"×"})})]}),n.jsx("div",{className:"flex-1 overflow-y-auto px-3 py-3",children:I0(E,Dt.referenceFace)})]})]})})(),Ct&&Ot&&(()=>{const E=Ot.findIndex(Kt=>Kt.id===Ct.openingId);if(E<0)return null;const F=280,V=320,at=Math.max(12,Math.min(Ct.x,window.innerWidth-F-12)),yt=Math.max(12,Math.min(Ct.y,window.innerHeight-V-12)),zt=()=>bt(null);return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fixed inset-0 z-[60]",onClick:zt,onContextMenu:Kt=>{Kt.preventDefault(),zt()}}),n.jsxs("div",{className:O("fixed z-[61] rounded-2xl border shadow-[0_12px_36px_-6px_rgba(0,0,0,0.28)] font-heebo overflow-hidden flex flex-col",ae?"bg-[#141416] border-white/10":"bg-white border-black/10"),style:{left:at,top:yt,width:F,maxHeight:V},dir:_s.dir(),onContextMenu:Kt=>Kt.preventDefault(),onClick:Kt=>Kt.stopPropagation(),children:[n.jsxs("div",{className:O("flex items-center justify-between px-3 py-2.5 border-b shrink-0 select-none cursor-move",ae?"border-white/10":"border-black/[0.06]"),title:It("trace.dragToMove",{defaultValue:"גרור להזזה"}),onPointerDown:Kt=>lx(Kt,{left:at,top:yt,panelWidth:F,panelHeight:V}),onPointerMove:cx,onPointerUp:D0,onPointerCancel:D0,children:[n.jsx("div",{className:O("text-[12px] font-semibold",ae?"text-white/90":"text-[#18181b]"),children:It("viewer.opening.resize",{defaultValue:"שנה גודל פתח"})}),n.jsx("button",{onPointerDown:Kt=>Kt.stopPropagation(),onClick:zt,className:O("w-6 h-6 rounded-md flex items-center justify-center cursor-pointer",ae?"text-white/45 hover:text-white hover:bg-white/10":"text-[#71717a] hover:text-[#18181b] hover:bg-black/5"),children:n.jsx("span",{className:"text-[14px] leading-none",children:"×"})})]}),n.jsx("div",{className:"flex-1 overflow-y-auto px-3 py-3",children:Um(E)})]})]})})(),me&&Nt&&(()=>{const V=Math.min(me.x,window.innerWidth-340-12),at=Math.min(me.y,window.innerHeight-480-12),yt=()=>xe(null);return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fixed inset-0 z-[60]",onClick:yt,onContextMenu:zt=>{zt.preventDefault(),yt()}}),n.jsxs("div",{className:O("fixed z-[61] rounded-2xl border shadow-[0_12px_36px_-6px_rgba(0,0,0,0.28)] font-heebo overflow-hidden flex flex-col",ae?"bg-[#141416] border-white/10":"bg-white border-black/10"),style:{left:V,top:at,width:340,maxHeight:480},dir:_s.dir(),onContextMenu:zt=>zt.preventDefault(),onClick:zt=>zt.stopPropagation(),children:[n.jsx("div",{className:O("flex items-center justify-end px-3 py-2.5 border-b shrink-0",ae?"border-white/10":"border-black/[0.06]"),children:n.jsx("button",{onClick:yt,className:O("w-6 h-6 rounded-md flex items-center justify-center cursor-pointer",ae?"text-white/45 hover:text-white hover:bg-white/10":"text-[#71717a] hover:text-[#18181b] hover:bg-black/5"),children:n.jsx("span",{className:"text-[14px] leading-none",children:"×"})})}),n.jsx("div",{className:"flex-1 overflow-y-auto px-3 py-3",children:Nt})]})]})})(),Ee&&oe&&n.jsx(Hu,{title:It("viewer.floating.carpentryTemplates",{defaultValue:"תבניות נגרות"}),subtitle:It("viewer.floating.attachedToWall",{defaultValue:"מוצמד לקיר הנבחר"}),dir:_s.dir(),closeAriaLabel:It("common.close",{defaultValue:"סגור"}),initialX:Ee.x,initialY:Ee.y,onClose:()=>wn(null),isDark:ae,children:oe(Ee.wallId,Ee.side)}),lt&&dr&&n.jsx(CB,{initialX:lt.x,initialY:lt.y,onClose:()=>He(null),onSelect:Am,isDark:ae}),Oo&&dr&&(()=>{const E=Vn.find(V=>V.id===Oo.fixtureId);if(!E||!ce)return null;const F=ce.walls.find(V=>V.id===E.wallId);return F?n.jsx(VB,{initialX:Oo.x,initialY:Oo.y,fixture:E,wallLenMm:F2(F),wallHeightMm:F.height,measurementUnit:Lt,isDark:ae,onCh
336ange:V=>hd(E.id,V),onDelete:()=>ea(E.id),onClose:()=>Ks(null)}):null})(),sr&&fs&&n.jsx(pj,{initialX:sr.x,initialY:sr.y,onClose:()=>Ls(null),onSaveAndPlace:ox,isDark:ae}),os&&fs&&(()=>{const E=Ii.find(V=>V.id===os.noteId);if(!E||!ce)return null;const F=ce.walls.find(V=>V.id===E.wallId);return F?n.jsx(qB,{initialX:os.x,initialY:os.y,note:E,wallLenMm:F2(F),wallHeightMm:F.height,measurementUnit:Lt,isDark:ae,onChange:V=>Oa(E.id,V),onDelete:()=>mu(E.id),onClose:()=>Zr(null)}):null})(),Ce==="inside"&&Fn&&Hn&&n.jsx(pj,{initialX:Fn.x,initialY:Fn.y,onClose:()=>qr(null),onSaveAndPlace:Lm,isDark:ae}),Ce==="inside"&&Mo&&Hn&&(()=>{const E=Uo.find(F=>F.id===Mo.noteId);return E?n.jsx(JB,{initialX:Mo.x,initialY:Mo.y,note:E,isDark:ae,onChange:F=>_c(E.id,F),onHide:()=>p0(E.id),onDelete:()=>fh(E.id),onClose:()=>re(null)}):null})(),_r&&he&&n.jsx(Hu,{title:It("viewer.floating.templates",{defaultValue:"תבניות"}),subtitle:It("viewer.floating.placeAtSelectedPoint",{defaultValue:"הצבה בנקודה שנבחרה"}),dir:_s.dir(),closeAriaLabel:It("common.close",{defaultValue:"סגור"}),initialX:_r.x,initialY:_r.y,onClose:()=>Ta(null),isDark:ae,children:he(_r.pointMm)}),ss&&pe&&n.jsx(Hu,{title:It("viewer.menu.changeFlooring",{defaultValue:"שנה ריצוף"}),subtitle:(Ge==null?void 0:Ge(ss.roomSig,ss.regionId))??It("viewer.floating.selectedRoom",{defaultValue:"חדר נבחר"}),dir:_s.dir(),closeAriaLabel:It("common.close",{defaultValue:"סגור"}),icon:np,initialX:ss.x,initialY:ss.y,onClose:()=>Ai(null),isDark:ae,children:pe(ss.roomSig,ss.regionId)}),No&&te&&n.jsx(Hu,{title:It("viewer.menu.addFurniture",{defaultValue:"הוסף רהיט"}),subtitle:(Be==null?void 0:Be(No.roomSig))??It("viewer.floating.chooseFurniture",{defaultValue:"בחר רהיט ולחץ על הרצפה"}),dir:_s.dir(),closeAriaLabel:It("common.close",{defaultValue:"סגור"}),icon:wf,initialX:No.x,initialY:No.y,onClose:()=>Er(null),isDark:ae,width:400,maxHeight:680,children:te()})]})});function CU({posRef:t}){const{camera:e}=Vo();return ka(()=>{t.current.x=e.position.x,t.current.y=e.position.y,t.current.z=e.position.z}),null}function NU({pose:t,bounds:e,planRotationDeg:s,framingSpan:o,elevation:r=0,onChange:i,onInteractingChange:a}){const{camera:l,gl:c}=Vo(),d=m.useRef(new Ea),u=m.useRef(new Ga(new le(0,1,0),0)),h=m.useRef(null),[x,f]=m.useState(null),p=Math.max(.9,Math.min(o*.28,2.4)),b=Math.max(.18,Math.min(o*.035,.34)),M=b*1.45,g=Math.max(.07,b*.28),w=m.useMemo(()=>{const v=t.fov/2,C=new Ua;return C.setAttribute("position",new cb(new Float32Array([0,0,0,Math.sin(-v)*p,0,Math.cos(-v)*p,Math.sin(v)*p,0,Math.cos(v)*p]),3)),C.setIndex([0,1,2]),C.computeVertexNormals(),C},[p,t.fov]),k=m.useMemo(()=>{const v=t.fov/2;return new Ua().setFromPoints([new le(0,.004,0),new le(Math.sin(-v)*p,.004,Math.cos(-v)*p),new le(0,.004,0),new le(Math.sin(v)*p,.004,Math.cos(v)*p)])},[p,t.fov]),_=m.useCallback((v,C,N)=>{const P=c.domElement.getBoundingClientRect();if(P.width===0||P.height===0)return;const L=new Po((v-P.left)/P.width*2-1,-((C-P.top)/P.height)*2+1);u.current.constant=-r,d.current.setFromCamera(L,l);const A=new le;if(!d.current.ray.intersectPlane(u.current,A))return;const W=z3({x:A.x,z:A.z},{x:e.centerX,z:e.centerZ},s*Math.PI/180);if(N==="move"){i({...t,x:W.x,z:W.z});return}const S=W.x-t.x,B=W.z-t.z;Math.hypot(S,B)<.02||i({...t,angle:Rf(Math.atan2(S,B))})},[e.centerX,e.centerZ,l,r,c.domElement,i,s,t]);m.useEffect(()=>{if(!x)return;const v=N=>{_(N.clientX,N.clientY,x)},C=()=>{h.current=null,f(null),a==null||a(!1)};return window.addEventListener("pointermove",v),window.addEventListener("pointerup",C,{once:!0}),window.addEventListener("pointercancel",C,{once:!0}),()=>{window.removeEventListener("pointermove",v),window.removeEventListener("pointerup",C),window.removeEventListener("pointercancel",C)}},[x,a,_]);const j=m.useCallback(v=>C=>{var P,L;C.stopPropagation(),(L=(P=C.nativeEvent)==null?void 0:P.preventDefault)==null||L.call(P),h.current=v,f(v),a==null||a(!0);const N=C.nativeEvent??C;_(N.clientX,N.clientY,v)},[a,_]);return n.jsxs("group",{position:[t.x,r+.07,t.z],rotation:[0,t.angle,0],renderOrder:30,children:[n.jsx("mesh",{geometry:w,onPointerDown:j("rotate"),renderOrder:31,children:n.jsx("meshBasicMaterial",{color:"#FFE63C",transparent:!0,opacity:x==="rotate"?.58:.42,depthWrite:!1,side:kn})}),n.jsx("lineSegments",{geometry:k,renderOrder:32,children:n.jsx("lineBasicMaterial",{color:"#FFC400",transparent:!0,opacity:.88,depthWrite:!1})}),n.jsxs("mesh",{position:[0,.025,-M*.45],onPointerDown:j("move"),renderOrder:35,children:[n.jsx("boxGeometry",{args:[b,g,M]}),n.jsx("meshBasicMaterial",{color:x==="move"?"#000000":"#0A0F18"})]}),n.jsxs("mesh",{position:[0,.025,-M*.08],onPointerDown:j("move"),renderOrder:36,children:[n.jsx("boxGeometry",{args:[b*.42,g*.82,M*.34]}),n.jsx("meshBasicMaterial",{color:x==="move"?"#000000":"#0A0F18"})]}),n.jsxs("mesh",{position:[0,.026,-M*.45],scale:[1.08,1.08,1.08],renderOrder:34,children:[n.jsx("boxGeometry",{args:[b,g,M]}),n.jsx("meshBasicMaterial",{color:"#ffffff",transparent:!0,opacity:.9,depthWrite:!1,side:Sp})]}),n.jsxs("mesh",{position:[0,.035,-M*.28],onPointerDown:j("move"),children:[n.jsx("cylinderGeometry",{args:[b*.95,b*.95,g*1.8,24]}),n.jsx("meshBasicMaterial",{transparent:!0,opacity:0,depthWrite:!1})]})]})}function IU({request:t,elevation:e=0,onResolved:s}){const{camera:o,gl:r}=Vo(),i=m.useRef(0),a=m.useRef(new Ea),l=m.useRef(new Ga(new le(0,1,0),0));return m.useEffect(()=>{if(!t||t.nonce===i.current)return;i.current=t.nonce;const c=r.domElement.getBoundingClientRect();if(c.width===0||c.height===0)return;const d=new Po((t.clientX-c.left)/c.width*2-1,-((t.clientY-c.top)/c.height)*2+1);l.current.constant=-e,a.current.setFromCamera(d,o);const u=new le;a.current.ray.intersectPlane(l.current,u)&&s(t.payload,{x:u.x,z:u.z})},[t,o,e,r,s]),null}function TU({request:t,elevation:e=0,onResolved:s}){const{camera:o,gl:r}=Vo(),i=m.useRef(0),a=m.useRef(new Ea),l=m.useRef(new Ga(new le(0,1,0),0));return m.useEffect(()=>{if(!t||t.nonce===i.current)return;i.current=t.nonce;const c=r.domElement.getBoundingClientRect();if(c.width===0||c.height===0)return;const d=new Po((t.clientX-c.left)/c.width*2-1,-((t.clientY-c.top)/c.height)*2+1);l.current.constant=-e,a.current.setFromCamera(d,o);const u=new le;a.current.ray.intersectPlane(l.current,u)&&s(t.templateId,o3(u))},[t,o,e,r,s]),null}const sk=8,SU=2.7,PU=-1.8994518283512887/sk,AU=-7.387997624294544/sk,t4=2.0218387515639935/SU,LU=12.543028572980656/sk,WU=new le(-.9690268924490247,1.6153388466653937,-4.601828384228499),RU=new le(3.074283338196793,2.472039708507399,-7.402539662553227),OU=new le((8.24962679212883- -1.8994518283512887)/12.543028572980656,(6.455961657289285-2.0218387515639935)/12.543028572980656,(-13.275469322302515- -7.387997624294544)/12.543028572980656).normalize();function HU({preset:t,viewScope:e,focusRequestId:s,roofFocusTarget:o,bounds:r,wallHeight:i,elevation:a=0,maxSceneHeightM:l=0,wallGroupName:c="walls",roomCenter:d,zoomTrigger:u,zoomTypeRef:h,cameraPoseRef:x,floorplanCameraPose:f,onFloorplanCameraPoseChange:p,planRotationDeg:b,teleportRef:M,rotateRef:g,smoothDriveTargetRef
336:w,walkthroughPlaybackRef:k,onWalkthroughPlaybackFrame:_,registerWalkthroughRenderer:j,cameraHeight:v,interiorFov:C,cameraAimCommand:N,compact:P,controlsDisabled:L,externalOrbitRef:A,isEmptyScene:W}){const{camera:S,gl:B,scene:R}=Vo(),z=m.useRef(null),X=m.useRef(null),ft=m.useRef(0),tt=m.useRef(new Ea),G=m.useRef(null),Y=m.useRef(null),J=m.useRef(s),Mt=m.useRef(0),Rt=m.useRef(!1),it=m.useRef(v),st=m.useRef(0),ct=m.useRef(new le),pt=m.useRef(null),xt=m.useRef(null),_t=m.useRef(0);m.useEffect(()=>{xt.current=f??null},[f]),m.useEffect(()=>{const At=S;At.fov=t==="inside"||t==="walkthrough"?C:50,At.updateProjectionMatrix()},[t,S,C]),m.useEffect(()=>{const At=it.current,ut=v-At;if(it.current=v,t!=="inside"&&t!=="walkthrough")return;S.position.y=a+v;const kt=z.current;kt&&t==="inside"&&(kt.target.y=a+J8(kt.target.y-a+ut,i),kt.update())},[v,t,S,i,a]),m.useEffect(()=>{var gt,Pt;if(!N||N.id===st.current||(st.current=N.id,t!=="inside"&&t!=="walkthrough"))return;const At=z.current,kt=(((Pt=(gt=At==null?void 0:At.target)==null?void 0:gt.clone)==null?void 0:Pt.call(gt))??S.position.clone().add(new le(1,0,0))).sub(S.position);kt.lengthSq()<.04&&(S.getWorldDirection(kt),kt.multiplyScalar(2));let Et=kt.clone();if(N.direction==="left"||N.direction==="right")Et.applyAxisAngle(new le(0,1,0),N.direction==="left"?Y8:-Y8);else if(N.direction==="up"||N.direction==="down"){const U=new le().setFromMatrixColumn(S.matrixWorld,0).normalize(),mt=N.direction==="up"?X8:-X8;Et.applyAxisAngle(U,mt);const Nt=S.position.y+Et.y,Lt=S.position.y+kt.y;(N.direction==="up"&&Nt<=Lt||N.direction==="down"&&Nt>=Lt)&&(Et=kt.clone().applyAxisAngle(U,-mt))}else{const U=new le(kt.x,0,kt.z);U.lengthSq()<1e-4&&(S.getWorldDirection(U),U.y=0),U.normalize();const mt=Math.max(Math.hypot(kt.x,kt.z),U8);Et=U.multiplyScalar(mt),Et.y=0}const ht=S.position.clone().add(Et);if(ht.y=a+J8(N.direction==="level"?v:ht.y-a,i),At&&t==="inside"){const U=At.enableDamping;At.target.copy(ht),At.enableDamping=!1,At.update(),At.enableDamping=U}else S.lookAt(ht),S.updateMatrixWorld(!0)},[N,S,v,t,i,a]),m.useEffect(()=>{const At=J.current!==s,ut=!!o&&Mt.current!==o.requestId,kt=Y.current!==t;if(Rt.current&&!kt&&!At&&!ut&&!P)return;J.current=s,o&&(Mt.current=o.requestId),Y.current=t,Rt.current=!0;const Et=z.current,ht=ut&&!!o,gt=ht?o.centerX:r.centerX,Pt=ht?o.centerZ:r.centerZ,{minX:U,maxX:mt,minZ:Nt,maxZ:Lt}=r,oe=ht?Math.max(o.span*1.2,(o.maxY-o.baseY)*1.8,1):Math.max(mm(r),l),he=new le,pe=new le;let Ge=!1;switch(t){case"orbit":{if(P){const Qt=oe*.75;he.set(gt+Qt,i+Qt*.5,Pt+Qt),pe.set(gt,-i*1,Pt)}else if(W&&!ht)Ge=!0,he.copy(RU),pe.copy(WU);else{const Qt=ht?(o.baseY+o.maxY)/2:e==="floor"?a+i*t4:Math.max(i*t4,l*.45);pe.set(gt+(ht?0:oe*PU),Qt,Pt+(ht?0:oe*AU));const te=oe*LU;he.copy(pe).addScaledVector(OU,te)}break}case"top":{const Qt=P?oe*1:oe*1.5,te=ht?(o.baseY+o.maxY)/2:e==="floor"?a:Math.max(0,l*.5);he.set(gt,te+Qt,Pt),pe.set(gt,te,Pt);break}case"inside":{if(f&&!P&&!At){const Qt=UH(f,r,b),te=a+tp(Qt.height??v,i);he.set(Qt.x,te,Qt.z),pe.set(Qt.x+Math.sin(Qt.angle)*2,te,Qt.z+Math.cos(Qt.angle)*2)}else{const Qt=(d==null?void 0:d.x)??gt,te=(d==null?void 0:d.z)??Pt,Be=mt-U,wt=Lt-Nt,ve=a+v;Be>=wt?(he.set(Qt-Be*.3,ve,te),pe.set(Qt+Be*.3,ve,te)):(he.set(Qt,ve,te-wt*.3),pe.set(Qt,ve,te+wt*.3))}break}case"walkthrough":{const Qt=(d==null?void 0:d.x)??gt,te=(d==null?void 0:d.z)??Pt;he.set(Qt,a+v,te),pe.set(Qt+1,a+v,te);break}}if(S.position.copy(he),S.lookAt(pe),S.updateProjectionMatrix(),!Ge){const Qt=S;Qt.updateProjectionMatrix(),S.updateMatrixWorld(!0);const te=he.distanceTo(pe),Be=Math.max(1,B.domElement.clientWidth),wt=Qt.fov*Math.PI/180,ve=B.domElement.clientHeight>0?B.domElement.clientWidth/B.domElement.clientHeight:1,Ne=2*Math.atan(Math.tan(wt/2)*ve),Le=2*Math.tan(Ne/2)*te/Be,is=new le().setFromMatrixColumn(S.matrixWorld,0).normalize();pe.addScaledVector(is,-cF*Le)}S.position.copy(he),Et&&(Et.target.copy(pe),Et.update()),ft.current=S.position.distanceTo(pe),t!=="walkthrough"&&X.current&&X.current.unlock()},[t,e,s,o,r,i,d,S,v,B,W,P,f,b,a,l]),m.useEffect(()=>{if(u===0)return;const At=h.current;if(t==="walkthrough"){const gt=new le;if(S.getWorldDirection(gt),At==="reset"){const Pt=(d==null?void 0:d.x)??r.centerX,U=(d==null?void 0:d.z)??r.centerZ;S.position.set(Pt,a+v,U)}else{const Pt=At==="in"?.5:-.5;S.position.addScaledVector(gt,Pt)}return}const ut=z.current;if(!ut)return;
336const kt=new le().copy(ut.target),Et=new le().subVectors(S.position,kt).normalize(),ht=S.position.distanceTo(kt);At==="in"?S.position.copy(kt).addScaledVector(Et,ht*.7):At==="out"?S.position.copy(kt).addScaledVector(Et,ht*1.4):At==="reset"&&S.position.copy(kt).addScaledVector(Et,ft.current||ht),ut.enableDamping=!1,ut.update(),ut.enableDamping=!0},[u]),m.useEffect(()=>{if(pt.current=null,t!=="orbit"||L)return;const At=B.domElement,ut=kt=>{const Et=z.current;if(!Et)return;kt.preventDefault(),kt.stopPropagation(),kt.stopImmediatePropagation();const ht=S.position.distanceTo(Et.target),gt=pt.current??ht,Pt=Math.sign(kt.deltaY)*Math.min(Math.abs(kt.deltaY),vU),U=Ru.clamp(gt*Math.exp(Pt*jU),Et.minDistance,Et.maxDistance);pt.current=U};return At.addEventListener("wheel",ut,{passive:!1,capture:!0}),()=>At.removeEventListener("wheel",ut,{capture:!0})},[S,L,B,t]),m.useEffect(()=>{G.current=R.getObjectByName(c)||null},[R,c]);const Ft=m.useCallback(At=>{const ut=S;ut.fov=At.fov,ut.updateProjectionMatrix(),S.position.set(At.position[0],At.position[1],At.position[2]);const kt=z.current;if(kt){kt.target.set(At.target[0],At.target[1],At.target[2]);const Et=kt.enableDamping;kt.enableDamping=!1,kt.update(),kt.enableDamping=Et}else S.lookAt(At.target[0],At.target[1],At.target[2]),S.updateMatrixWorld(!0)},[S]),Vt=m.useRef(null);m.useEffect(()=>j?(j({beginExport:(ut,kt)=>{const Et=B.getSize(new Po),ht=S;Vt.current={pixelRatio:B.getPixelRatio(),width:Et.x,height:Et.y,aspect:ht.aspect},B.setPixelRatio(1),B.setSize(ut,kt,!1),ht.aspect=ut/kt,ht.updateProjectionMatrix()},renderFrameAt:(ut,kt)=>{const Et=$v(ut,kt);return Et&&Ft(Et),B.render(R,S),B.domElement},endExport:ut=>{const kt=Vt.current;if(kt){const Et=S;B.setPixelRatio(kt.pixelRatio),B.setSize(kt.width,kt.height,!1),Et.aspect=kt.aspect,Et.updateProjectionMatrix(),Vt.current=null}ut&&Ft(ut)}}),()=>j(null)):void 0,[j,B,S,R,Ft]);const vt=m.useCallback((At,ut)=>{if(At.lengthSq()<=0||ut<=0)return new le;const kt=At.clone().setY(0);if(kt.lengthSq()<=0)return new le;kt.normalize();const Et=S.position.clone(),ht=.3;(!G.current||G.current.name!==c)&&(G.current=R.getObjectByName(c)||null);const gt=G.current;if(gt){const Pt=tt.current;Pt.far=ht+ut;const U=S.position.clone();Pt.set(U,kt);const mt=Pt.intersectObjects(gt.children,!0);if(mt.length>0&&mt[0].distance<ht){const Lt=new le(kt.x,0,0),oe=new le(0,0,kt.z);let he=!0,pe=!0;if(Lt.lengthSq()>.001){Lt.normalize(),Pt.set(U,Lt);const Qt=Pt.intersectObjects(gt.children,!0);he=Qt.length===0||Qt[0].distance>=ht}if(oe.lengthSq()>.001){oe.normalize(),Pt.set(U,oe);const Qt=Pt.intersectObjects(gt.children,!0);pe=Qt.length===0||Qt[0].distance>=ht}const Ge=new le;he&&(Ge.x=kt.x),pe&&(Ge.z=kt.z),Ge.lengthSq()>0&&S.position.addScaledVector(Ge.normalize(),ut)}else S.position.addScaledVector(kt,ut)}else S.position.addScaledVector(kt,ut);return S.position.y=a+v,S.position.clone().sub(Et)},[S,v,a,R,c]);if(ka(()=>{var Et,ht;const At=k.current;if(!At)return;if(At.stopRequested){At.restoreFrame&&Ft(At.restoreFrame),k.current=null,(Et=At.onComplete)==null||Et.call(At);return}const ut=Math.min(At.recording.durationMs,Math.max(0,performance.now()-At.startedAt)),kt=$v(At.recording.keyframes,ut);kt&&(Ft(kt),_==null||_(kt),ut>=At.recording.durationMs&&(At.restoreFrame&&Ft(At.restoreFrame),k.current=null,(ht=At.onComplete)==null||ht.call(At)))}),ka(()=>{if(k.current)return;const At=M.current;if(!At)return;M.current=null,S.position.x=At.x,S.position.z=At.z,S.position.y=a+v;const ut=z.current;if(ut){const kt=new le;S.getWorldDirection(kt),kt.y=0,kt.normalize(),ut.target.set(At.x+kt.x,a+v,At.z+kt.z),ut.enableDamping=!1,ut.update(),ut.enableDamping=!0}}),ka(()=>{if(k.current)return;const At=g.current;if(At===null)return;g.current=null;const ut=2,kt=S.position.x,Et=S.position.z,ht=kt+Math.sin(At)*ut,gt=Et+Math.cos(At)*ut;if(t==="walkthrough")S.lookAt(ht,a+v,gt);else{const Pt=z.current;Pt&&(Pt.target.set(ht,a+v,gt),Pt.enableDamping=!1,Pt.update(),Pt.enableDamping=!0)}}),ka((At,ut)=>{if(k.current||t!=="inside")return;const kt=w.current,Et=ct.current;if(!kt){Et.set(0,0,0);return}const ht=new le(kt.x-S.position.x,0,kt.z-S.position.z),gt=ht.length();if(gt<yU){w.current=null,Et.set(0,0,0);return}const Pt=z.current,U=ht.normalize(),mt=kt.mode==="steer"?fU:mU,Nt=kt.mode==="steer"?pU:xU,Lt=kt.mode==="steer"?bU:gU,oe=Math.min(Math.max(ut,0),.05);if(oe<=0)return;const he=Math.min(mt,Math.max(MU,gt*Lt)),pe=U.multiplyScalar(he),Ge=1-Math.exp(-Nt*oe);Et.lerp(pe,Ge);const Qt=Math.min(gt,Math.max(0,Et.length()*oe)),te=vt(ht,Qt);Pt&&te.lengthSq()>
3360?(Pt.target.add(te),Pt.enableDamping=!1,Pt.update(),Pt.enableDamping=!0):(w.current=null,Et.set(0,0,0))}),ka((At,ut)=>{if(t!=="orbit"||L)return;const kt=pt.current;if(kt===null)return;const Et=z.current;if(!Et){pt.current=null;return}const ht=Et.target,gt=new le().subVectors(S.position,ht),Pt=gt.length();if(Pt<=1e-4){pt.current=null;return}const U=Math.min(Math.max(ut,0),.05),mt=Ru.damp(Pt,kt,_U,U);gt.setLength(mt),S.position.copy(ht).add(gt);const Nt=Et.enableDamping;Et.enableDamping=!1,Et.update(),Et.enableDamping=Nt,Math.abs(mt-kt)<.003&&(pt.current=null)}),ka((At,ut)=>{if(t!=="walkthrough")return;const kt=3,Et=new le;S.getWorldDirection(Et),Et.y=0,Et.normalize();const ht=new le().crossVectors(Et,new le(0,1,0)).normalize(),gt=new le;(dc.has("KeyW")||dc.has("ArrowUp"))&&gt.add(Et),(dc.has("KeyS")||dc.has("ArrowDown"))&&gt.sub(Et),(dc.has("KeyD")||dc.has("ArrowRight"))&&gt.add(ht),(dc.has("KeyA")||dc.has("ArrowLeft"))&&gt.sub(ht),gt.lengthSq()>0&&vt(gt,kt*ut)}),ka(()=>{const At=new le;S.getWorldDirection(At);const ut={x:S.position.x,z:S.position.z,angle:Math.atan2(At.x,At.z),fov:S.fov*Math.PI/180,height:S.position.y-a};if(x.current={x:ut.x,z:ut.z,angle:ut.angle,fov:ut.fov},t!=="inside"||!p)return;const kt=performance.now();if(kt-_t.current<90)return;_t.current=kt;const Et=KH(ut,r,b),ht=xt.current;(!ht||Math.abs(Et.x-ht.x)>.01||Math.abs(Et.z-ht.z)>.01||Math.abs(Rf(Et.angle-ht.angle))>.01||Math.abs(Et.fov-ht.fov)>.001||Math.abs(Et.height-ht.height)>.01)&&(xt.current=Et,p(Et))}),t==="walkthrough")return n.jsx(ZN,{ref:X,args:[S,B.domElement]});const Ht=t==="top",Tt=t==="inside",Zt=Math.max(mm(r),l);return n.jsx(qN,{ref:At=>{z.current=At,A&&(A.current=At)},makeDefault:!0,enabled:!L,enableRotate:!Ht&&!L,enablePan:!L,enableZoom:!L,minDistance:Tt?U8:Zt*.05,maxDistance:Ht?Zt*5:Zt*3,minPolarAngle:Tt?Math.PI*.1:0,maxPolarAngle:Tt?Math.PI*.85:Ht?0:Math.PI*.85,enableDamping:!0,dampingFactor:.08,zoomSpeed:Tt?kU:t==="orbit"?wU:1,rotateSpeed:Tt?.5:.8,panSpeed:Tt?.8:1,touches:{ONE:Ht?ZM.PAN:ZM.ROTATE,TWO:ZM.DOLLY_PAN}})}function BU({isDark:t=!1,onPan:e}){const{t:s}=yn(),o=m.useRef(null),r=m.useRef(null),[i,a]=m.useState(null),l=m.useCallback(b=>{const M=o.current,g=M==null?void 0:M.parentElement;if(!M||!g)return b;const w=g.getBoundingClientRect(),k=M.getBoundingClientRect(),_=10;return{x:Math.min(Math.max(_,b.x),Math.max(_,w.width-k.width-_)),y:Math.min(Math.max(_,b.y),Math.max(_,w.height-k.height-_))}},[]);m.useEffect(()=>{const b=o.current,M=b==null?void 0:b.parentElement;if(!b||!M)return;const g=M.getBoundingClientRect(),w=b.getBoundingClientRect();let k={x:14,y:Math.max(14,g.height-w.height-14)};try{const _=window.localStorage.getItem("floorplan.orbitCanvasPanPad.position.v1"),j=_?JSON.parse(_):null;j&&typeof j.x=="number"&&Number.isFinite(j.x)&&typeof j.y=="number"&&Number.isFinite(j.y)&&(k={x:j.x,y:j.y})}catch{}a(l(k))},[l]),m.useEffect(()=>{const b=()=>{a(M=>M&&l(M))};return window.addEventListener("resize",b),()=>window.removeEventListener("resize",b)},[l]);const c=m.useCallback(b=>{try{window.localStorage.setItem("floorplan.orbitCanvasPanPad.position.v1",JSON.stringify(b))}catch{}},[]),d=b=>{if(!(b instanceof Element))return null;const M=b.closest("[data-pan-direction], [data-orbit-pan-direction]"),g=(M==null?void 0:M.dataset.panDirection)??(M==null?void 0:M.dataset.orbitPanDirection);return g==="up"||g==="down"||g==="left"||g==="right"?g:null},u=b=>{b.stopPropagation();const M=i??{x:14,y:14};r.current={pointerId:b.pointerId,startX:b.clientX,startY:b.clientY,originX:M.x,originY:M.y,moved:!1,pressDirection:d(b.target)},b.currentTarget.setPointerCapture(b.pointerId)},h=b=>{b.stopPropagation();const M=r.current;if(!M||M.pointerId!==b.pointerId)return;const g=b.clientX-M.startX,w=b.clientY-M.startY;g*g+w*w>16&&(M.moved=!0);const k=l({x:M.originX+g,y:M.originY+w});a(k)},x=b=>{b.stopPropagation();const M=r.current;if(!M||M.pointerId!==b.pointerId)return;r.current=null;try{b.currentTarget.releasePointerCapture(b.pointerId)}catch{}const g=l({x:M.originX+b.clientX-M.startX,y:M.originY+b.clientY-M.startY});if(a(g),M.moved){c(g);return}M.pressDirection&&e(M.pressDirection)},f=(b,M)=>
336{b.key!=="Enter"&&b.key!==" "||(b.preventDefault(),b.stopPropagation(),e(M))},p={up:s("viewer.camera.moveModelUp",{defaultValue:"הזז את המודל למעלה"}),down:s("viewer.camera.moveModelDown",{defaultValue:"הזז את המודל למטה"}),left:s("viewer.camera.moveModelLeft",{defaultValue:"הזז את המודל שמאלה"}),right:s("viewer.camera.moveModelRight",{defaultValue:"הזז את המודל ימינה"})};return n.jsx("div",{ref:o,className:O("pointer-events-auto absolute z-20 cursor-grab touch-none select-none rounded-full border p-1.5 font-heebo backdrop-blur-md active:cursor-grabbing",t?"border-white/10 bg-[#090B0F]/88 shadow-[0_8px_26px_rgba(0,0,0,0.38)]":"border-[#182137]/10 bg-[#F7F4EF]/78 shadow-[0_8px_24px_rgba(24,33,55,0.12)]"),style:{left:(i==null?void 0:i.x)??14,top:(i==null?void 0:i.y)??14,visibility:i?"visible":"hidden"},onPointerDown:u,onPointerMove:h,onPointerUp:x,onPointerCancel:x,onWheel:b=>b.stopPropagation(),"aria-label":s("viewer.camera.panModel",{defaultValue:"הזזת המודל על הקנבס"}),dir:"ltr",children:n.jsx(Tb,{size:"sm",isDark:t,hideCenter:!0,labels:p,directionButtonProps:{up:{"data-pan-direction":"up",onKeyDown:b=>f(b,"up"),className:"cursor-pointer"},down:{"data-pan-direction":"down",onKeyDown:b=>f(b,"down"),className:"cursor-pointer"},left:{"data-pan-direction":"left",onKeyDown:b=>f(b,"left"),className:"cursor-pointer"},right:{"data-pan-direction":"right",onKeyDown:b=>f(b,"right"),className:"cursor-pointer"}}})})}function VU(t,e){const s=m.useRef(!1),o=m.useRef(null),r=m.useMemo(()=>({onPointerDown:a=>{s.current=!1,o.current={x:a.clientX,y:a.clientY},t.onPointerDown(a)},onPointerMove:a=>{if(o.current){const l=a.clientX-o.current.x,c=a.clientY-o.current.y;l*l+c*c>16&&(s.current=!0)}t.onPointerMove(a)},onPointerUp:a=>{t.onPointerUp(a)},onPointerCancel:a=>{t.onPointerCancel(a)}}),[t]),i=m.useCallback(()=>{if(s.current){s.current=!1;return}e()},[e]);return{dragProps:r,handleActivate:i}}function zU({onZoomIn:t,onZoomOut:e,onReset:s,showHeight:o,dockAtBottom:r=!1,minimapChromeLayout:i,onHeightUp:a,onHeightDown:l,onCameraAim:c,cameraHeight:d,interiorFov:u,onInteriorFovChange:h,detailsPanelOpen:x=!1,fpIsDark:f,viewportFrameRef:p}){const{t:b,i18n:M}=yn(),[g,w]=m.useState(!0);m.useEffect(()=>{o||w(!1)},[o]);const k=g?Jy:jH,_=g?Jy:_H,j=g?8:16,v=m.useCallback(it=>r?CH(it,k,_,i):EH(it,x,j),[x,j,r,i,k,_]),C=m.useCallback((it,st)=>bF(it,st,k,_),[k,_]),{position:N,ready:P,headerProps:L}=B3({viewportFrameRef:p,enabled:o,getDefaultPosition:v,clampPosition:C,resetPositionKey:r&&`${g}-${(i==null?void 0:i.sizePx)??0}`}),{dragProps:A,handleActivate:W}=VU(L,()=>w(!1)),S=O("overflow-hidden rounded-2xl border text-start shadow-[0_18px_50px_rgba(24,33,55,0.20)]",f?"border-white/[0.10] bg-[#141416] text-white":"border-[#182137]/14 bg-[#F7F4EF] text-[#182137]"),B=O("flex shrink-0 items-center justify-between border-b px-3 py-2",f?"border-white/10":"border-[#182137]/12"),R=O("flex flex-col gap-1.5 p-1.5",f?"bg-[#141416]":"bg-[#FAF8F5]/60"),z=O("overflow-hidden rounded-lg border p-1.5",f?"border-white/10 bg-white/[0.04]":"border-[#182137]/10 bg-white/75"),X=O("mb-1 px-0.5 text-[10px] font-semibold",f?"text-white/55":"text-[#182137]/58"),ft=O("rounded-md p-0.5",f?"bg-white/[0.04]":"bg-[#E8DFD3]/70"),tt=O("flex shrink-0 items-center justify-center rounded-md transition-colors active:scale-[0.96]",f?"text-white/70 hover:bg-white/10 hover:text-white":"text-[#182137]/70 hover:bg-[#E8DFD3] hover:text-[#182137]"),G=O("flex shrink-0 items-center justify-center rounded-lg transition-colors active:scale-[0.96]",f?"text-white/62 hover:bg-white/[0.08] hover:text-white":"text-[#182137]/62 hover:bg-[#E8DFD3] hover:text-[#182137]"),Y=O("h-5 w-px shrink-0",f?"bg-white/10":"bg-[#182137]/12"),J=O(G,"h-7 w-7"),Mt={left:N.x,top:N.y,visibility:P?"visible":"hidden"},Rt=n.jsxs("div",{className:O("flex items-center justify-center gap-0.5",ft),children:[n.jsx("button",{type:"button",onClick:t,className:J,title:b("viewer.camera.zoomIn",{defaultValue:"התקרבות (+)"}),children:n.jsx(pm,{size:14,strokeWidth:1.75})}),n.jsx("span",{className:Y,"aria-hidden":!0}),n.jsx("button",{type:"button",onClick:s,className:J,title:b("viewer.camera.resetView",{defaultValue:"איפוס מבט"}),children:n.jsx(D1,{size:13,strokeWidth:1.75})}),n.jsx("span",{className:Y,"aria-hidden":!0}),n.jsx("button",{type:"button",onClick:e,className:J,title:b("viewer.camera.zoomOut",{defaultValue:"התרחקות (-)"}),children:n.jsx(Pp,{size:14,strokeWidth:1.75})})]});return o?g?n.jsx("div",{className:"pointer-events-auto absolute z-10 font-heebo",style:Mt,children:n.jsx("div",{role:"button",tabIndex:0,onClick:W,onKeyDown:it=>{(it.key==="Enter"||it.key===" ")&&(it.preventDefault(),W())},className:O(S,"flex h-12 w-12 cursor-move items-center justify-center transition-colors"),title:b("viewer.camera.openHint",{defaultValue:"שליטת מצלמה — לחץ לפתיחה, גרור להזזה"}),"aria-expanded":!1,"aria-label":b("viewer.camera.openPanel",{defaultValue:"פתח פאנל שליטת מצלמה"}),...A,children:n.jsx(Hk,{size:20,strokeWidth:1.75,className:f?"text-white/55":"text-[#182137]/55"})})}):n.jsx("div",{className:"pointer-events-auto absolute z-10 w-[11.25rem] font-heebo",style:Mt,children:n.jsxs("div",{className:O(S,"flex min-h-0 flex-col"),dir:M.dir
336(),children:[n.jsxs("div",{className:O(B,"cursor-move"),...L,children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[n.jsx(Hk,{size:15,className:f?"text-white/55":"text-[#182137]/55"}),n.jsx("h2",{className:"truncate text-[14px] font-semibold leading-tight",children:b("viewer.camera.title",{defaultValue:"שליטת מצלמה"})})]}),n.jsx("button",{type:"button",onClick:()=>w(!0),onPointerDown:it=>it.stopPropagation(),className:O(tt,"h-7 w-7"),title:b("viewer.camera.minimize",{defaultValue:"מזער לכפתור מצלמה"}),"aria-label":b("viewer.camera.minimizePanel",{defaultValue:"מזער פאנל שליטת מצלמה"}),children:n.jsx(G_,{size:14})})]}),n.jsxs("div",{className:R,children:[Rt,n.jsxs("div",{className:z,children:[n.jsx("div",{className:X,children:b("viewer.camera.height",{defaultValue:"גובה מצלמה"})}),n.jsxs("div",{className:O("flex items-stretch gap-0.5",ft),children:[n.jsx("button",{type:"button",onClick:a,className:J,title:b("viewer.camera.raise",{defaultValue:"הרמת מצלמה (Shift = צעד גדול 0.3 מ׳)"}),children:n.jsx(E_,{size:15,strokeWidth:1.75})}),n.jsx("div",{className:O("flex min-w-0 flex-1 items-center justify-center rounded-md px-1 py-0.5",f?"bg-white/[0.06]":"bg-white/85"),children:n.jsxs("span",{className:O("font-mono text-[12px] font-semibold tabular-nums tracking-tight",f?"text-white/90":"text-[#182137]"),children:[d.toFixed(1),n.jsx("span",{className:O("ms-0.5 text-[10px] font-medium",f?"text-white/55":"text-[#182137]/58"),children:b("settings.meters",{defaultValue:"מ׳"})})]})}),n.jsx("button",{type:"button",onClick:l,className:J,title:b("viewer.camera.lower",{defaultValue:"הורדת מצלמה (Shift = צעד גדול 0.3 מ׳)"}),children:n.jsx(Yc,{size:15,strokeWidth:1.75})})]})]}),n.jsxs("div",{className:z,children:[n.jsx("div",{className:X,children:b("viewer.camera.aim",{defaultValue:"כיוון עדשה"})}),n.jsxs("div",{className:O("grid grid-cols-3 gap-0.5",ft),role:"group","aria-label":b("viewer.camera.aim",{defaultValue:"כיוון עדשה"}),dir:"ltr",children:[n.jsx("span",{"aria-hidden":!0}),n.jsx("button",{type:"button",onClick:()=>c("up"),className:O(J,"h-7 w-full"),title:b("viewer.camera.aimUp",{defaultValue:"הרם עדשה"}),"aria-label":b("viewer.camera.aimUp",{defaultValue:"הרם עדשה"}),"data-testid":"floorplan-camera-aim-up",children:n.jsx(D_,{size:13,strokeWidth:1.75})}),n.jsx("span",{"aria-hidden":!0}),n.jsx("button",{type:"button",onClick:()=>c("left"),className:O(J,"h-7 w-full"),title:b("viewer.camera.aimLeft",{defaultValue:"סובב עדשה שמאלה"}),"aria-label":b("viewer.camera.aimLeft",{defaultValue:"סובב עדשה שמאלה"}),"data-testid":"floorplan-camera-aim-left",children:n.jsx(F_,{size:13,strokeWidth:1.75})}),n.jsx("button",{type:"button",onClick:()=>c("level"),className:O(J,"h-7 w-full",f?"bg-white/[0.05]":"bg-white/65"),title:b("viewer.camera.aimLevel",{defaultValue:"יישר עדשה"}),"aria-label":b("viewer.camera.aimLevel",{defaultValue:"יישר עדשה"}),"data-testid":"floorplan-camera-aim-level",children:n.jsx(zu,{size:12,strokeWidth:1.75})}),n.jsx("button",{type:"button",onClick:()=>c("right"),className:O(J,"h-7 w-full"),title:b("viewer.camera.aimRight",{defaultValue:"סובב עדשה ימינה"}),"aria-label":b("viewer.camera.aimRight",{defaultValue:"סובב עדשה ימינה"}),"data-testid":"floorplan-camera-aim-right",children:n.jsx(w1,{size:13,strokeWidth:1.75})}),n.jsx("span",{"aria-hidden":!0}),n.jsx("button",{type:"button",onClick:()=>c("down"),className:O(J,"h-7 w-full"),title:b("viewer.camera.aimDown",{defaultValue:"הורד עדשה"}),"aria-label":b("viewer.camera.aimDown",{defaultValue:"הורד עדשה"}),"data-testid":"floorplan-camera-aim-down",children:n.jsx(J_,{size:13,strokeWidth:1.75})}),n.jsx("span",{"aria-hidden":!0})]})]}),n.jsxs("div",{className:z,children:[n.jsx("div",{className:X,children:b("viewer.camera.lensType",{defaultValue:"סוג עדשה"})}),n.jsx("div",{className:O("flex p-0.5",ft),role:"group","aria-label":b("viewer.camera.lensType",{defaultValue:"סוג עדשה"}),children:hU.map(it=>{const st=u===it.value;return n.jsx("button",{type:"button",onClick:()=>h(it.value),title:b(`viewer.camera.lens.${it.value}.title`,{defaultValue:it.title}),className:O("min-w-0 flex-1 rounded-md py-1.5 text-[10px] font-semibold transition-colors active:scale-[0.98]",st?f?"bg-white/[0.08] text-white":"bg-[#E8DFD3] text-[#182137]":f?"text-white/55 hover:bg-white/[0.06] hover:text-white/90":"text-[#182137]/58 hover:bg-[#
336E8DFD3]/60 hover:text-[#182137]"),children:b(`viewer.camera.lens.${it.value}.label`,{defaultValue:it.label})},it.value)})})]})]})]})}):null}function $U(t,e,s){return Math.min(s,Math.max(e,t))}function XU({label:t,unit:e,value:s,min:o,max:r,onCommit:i}){const[a,l]=m.useState(String(s));m.useEffect(()=>{l(String(s))},[s]);const c=()=>{const d=Number(a);if(!Number.isFinite(d)){l(String(s));return}i($U(d,o,r))};return n.jsxs("div",{className:"flex w-[78px] shrink-0 items-center gap-1 rounded-xl border border-[#ddd8d0] bg-white px-1.5 py-1 focus-within:border-[#D84B2E] focus-within:ring-1 focus-within:ring-[#EC7357]/30",children:[n.jsx("input",{type:"text",inputMode:"decimal","aria-label":`${t} ${e}`,value:a,onChange:d=>l(d.target.value),onBlur:c,onKeyDown:d=>{d.key==="Enter"&&(c(),d.target.blur())},className:"min-w-0 flex-1 bg-transparent text-center text-[10px] font-medium tabular-nums text-[#3d3a36] outline-none"}),n.jsx("span",{className:"shrink-0 text-[8px] font-medium text-[#9b95a0]",children:e})]})}function Hh({label:t,unit:e,value:s,min:o,max:r,step:i=10,showInput:a=!1,onChange:l}){return n.jsxs("div",{className:"flex items-center gap-2.5",children:[n.jsx("span",{className:"text-[9px] text-[#9b95a0] w-[34px] text-left shrink-0",children:t}),n.jsx("input",{type:"range",min:o,max:r,step:i,value:s,"aria-label":`${t} ${e}`,onChange:c=>l(Number(c.target.value)),className:`flex-1 h-[3px] appearance-none bg-[#ede8e4] rounded-full outline-none cursor-pointer
337          [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-3 [&::-webkit-slider-thumb]:h-3
338          [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-[#D84B2E] [&::-webkit-slider-thumb]:shadow-[0_1px_4px_rgba(216,75,46,0.35)]
339          [&::-webkit-slider-thumb]:cursor-pointer [&::-webkit-slider-thumb]:transition-all [&::-webkit-slider-thumb]:hover:scale-125`}),a?n.jsx(XU,{label:t,unit:e,value:s,min:o,max:r,onCommit:l}):n.jsxs("span",{className:"text-[10px] font-medium text-[#5a5065] w-[52px] text-center shrink-0 tabular-nums",children:[s," ",e]})]})}function YU(){const[t,e]=m.useState(!0);return m.useEffect(()=>{const s=setTimeout(()=>e(!1),5e3);return()=>clearTimeout(s)},[]),t?n.jsxs("div",{className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-20
340      bg-black/70 text-white rounded-2xl px-6 py-4 text-center backdrop-blur-sm
341      pointer-events-none animate-pulse`,children:[n.jsx("p",{className:"text-sm font-medium mb-1",children:"Click to look around"}),n.jsx("p",{className:"text-xs text-gray-300",children:"WASD / Arrow keys to move"}),n.jsx("p",{className:"text-xs text-gray-400 mt-1",children:"ESC to exit"})]}):null}function GU({active:t,onChange:e}){const{t:s}=yn(),o=t==="top";return n.jsx("div",{className:"absolute bottom-2 left-2 z-10 fp-preset-bar fp-preset-bar--compact",children:n.jsx("button",{type:"button",title:o?s("viewer.camera.returnToIsometric",{defaultValue:"חזור לאיסומטרי"}):s("topBar.topView",{defaultValue:"מבט על"}),className:`fp-preset-bar__btn ${o?"fp-preset-bar__btn--active":""}`,onClick:r=>{r.stopPropagation(),e(o?"orbit":"top")},children:n.jsx(A3,{className:"h-3 w-3 shrink-0"})})})}function UU(t){const e=new DataView(t);if(t.byteLength<20||e.getUint32(0,!0)!==1179937895||e.getUint32(4,!0)!==2||e.getUint32(8,!0)!==t.byteLength)throw new Error("Invalid Blender GLB header");const s=e.getUint32(12,!0);if(e.getUint32(16,!0)!==1313821514||s>t.byteLength-20)throw new Error("Invalid Blender GLB JSON chunk");return JSON.parse(new TextDecoder().decode(new Uint8Array(t,20,s)))}async function KU(t){var d,u,h,x,f;const e=UU(t),s=await crypto.subtle.digest("SHA-256",t),o=Array.from(new Uint8Array(s),p=>p.toString(16).padStart(2,"0")).join(""),r=e.nodes??[],i=((u=(d=e.scenes)==null?void 0:d[e.scene??0])==null?void 0:u.nodes)??[],a=new Set,l=[...i];for(;l.length;){const p=l.pop();!Number.isInteger(p)||p<0||!r[p]||a.has(p)||(a.add(p),l.push(...r[p].children??[]))}const c=[];for(const p of[...a].sort((b,M)=>b-M)){const b=r[p],M=b.mesh;if(typeof M!="number")continue;const g=((x=(h=e.meshes)==null?void 0:h[M])==null?void 0:x.primitives)??[],w=((f=b.name)==null?void 0:f.trim().replace(/_/g," "))||`חלק ${p+1}`;g.forEach((k,_)=>{var C,N,P;if(![4,5,6].includes(k.mode??4))return;const j=k.material,v=typeof j=="number"?(N=(C=e.materials)==null?void 0:C[j])==null?void 0:N.name:void 0;c.push({id:`blender-sha256-${o}-node-${p}-primitive-${_}`,labelHe:g.length>1?`${w} · ${_+1}`:w,source:"node",match:{nodeIndices:[p],meshIndices:[M],primitiveIndices:[_],materialIndices:typeof j=="number"?[j]:[],materialNames:v?[v]:[]},uvMode:((P=k.attributes)==null?void 0:P.TEXCOORD_0)!==void 0?"model":"none"})})}return c}function ZU(t){const e=JSON.stringify(Object.entries(t).map(([c,d])=>[c,d.url]).sort(([c],[d])=>c.localeCompare(d))),[s,o]=m.useState(0),[r,i]=m.useState({sourceKey:"",slots:{},errors:{}});m.useEffect(()=>{const c=new AbortController;let d=!1;i({sourceKey:e,slots:{},errors:{}});const u=JSON.parse(e);for(const[h,x]of u)(async()=>{try{const f=await fetch(x,{signal:c.signal});
341if(!f.ok)throw new Error(`GLB analysis HTTP ${f.status}`);const p=await KU(await f.arrayBuffer());if(d)return;if(p.length===0)throw new Error("GLB has no editable mesh parts");i(b=>b.sourceKey===e?{...b,slots:{...b.slots,[h]:p}}:b)}catch(f){if(d)return;Ys.error("Blender material analysis failed",f),i(p=>p.sourceKey===e?{...p,errors:{...p.errors,[h]:!0}}:p)}})();return()=>{d=!0,c.abort()}},[e,s]);const a=m.useMemo(()=>{const c=r.sourceKey===e?r:{slots:{},errors:{}},d={};for(const[u]of JSON.parse(e))d[u]=!c.slots[u]&&!c.errors[u];return{slotsByType:c.slots,errorsByType:c.errors,loadingByType:d}},[e,r]),l=m.useCallback(()=>o(c=>c+1),[]);return{...a,retry:l}}const qU=0,JU=1,QU=2,e4=16,n4=.85,tK=50;function eK(t,e){return t.deltaMode===JU?{dx:t.deltaX*e4,dy:t.deltaY*e4}:t.deltaMode===QU?{dx:t.deltaX*Math.max(1,e.width)*n4,dy:t.deltaY*Math.max(1,e.height)*n4}:{dx:t.deltaX,dy:t.deltaY}}function nK(t,e){return t.deltaMode!==qU?!1:Math.abs(e.dx)>0||Math.abs(e.dy)<tK}function oK(t,e){const s=eK(t,e);return t.ctrlKey||t.metaKey?{kind:"zoom",delta:-s.dy}:nK(t,s)?{kind:"pan",dx:-s.dx,dy:-s.dy}:{kind:"zoom",delta:-s.dy}}const sK=15,o4=12;function Rg(t,e,s,o,r,i=[]){for(let l=i.length-1;l>=0;l-=1)if(hE(t,i[l],r))return{kind:"beam",beamId:i[l].id};for(let l=o.length-1;l>=0;l--)if(rK(t,o[l],r))return{kind:"furniture",furnitureId:o[l].id};for(const l of s){const c=e.find(d=>d.id===l.wallId);if(c&&iK(t,l,c,r))return{kind:"opening",openingId:l.id}}const a=v7(t,e);return a?{kind:"wall",wallId:a.wall.id,positionPx:a.positionPx}:null}function s4(t,e,s){let o=!1;for(let r=0,i=s.length-1;r<s.length;i=r++){const a=s[r].x,l=s[r].y,c=s[i].x,d=s[i].y;l>e!=d>e&&t<(c-a)*(e-l)/(d-l)+a&&(o=!o)}return o}function r4(t,e,s){if(s<=0)return null;const o=t.x*s,r=t.y*s;for(let i=e.length-1;i>=0;i--){const a=e[i];if(!a.vertices||a.vertices.length<3||!s4(o,r,a.vertices))continue;let l=!1;if(a.holes){for(const c of a.holes)if(c.length>=3&&s4(o,r,c)){l=!0;break}}if(!l)return a.id}return null}function rK(t,e,s){const o=pi[e.type],r=o.width/s/2,i=o.depth/s/2,a=t.x-e.position.x,l=t.y-e.position.y,c=-(e.rotation*Math.PI)/180,d=a*Math.cos(c)-l*Math.sin(c),u=a*Math.sin(c)+l*Math.cos(c);return Math.abs(d)<=r&&Math.abs(u)<=i}function iK(t,e,s,o){if(o<=0)return!1;const r=s.end.x-s.start.x,i=s.end.y-s.start.y,a=Math.sqrt(r*r+i*i);if(a===0)return!1;const l=r/a,c=i/a,d=s.start.x+l*e.positionPx,u=s.start.y+c*e.positionPx,h=e.preset?qs[e.preset]:null,f=(e.widthMm||(h==null?void 0:h.width)||Kc[e.type].width)/o/2,p=(t.x-d)*l+(t.y-u)*c,b=Math.abs((t.x-d)*-c+(t.y-u)*l);return Math.abs(p)<=f+o4&&b<=o4}function hw(t,e,s){const o=s.x-e.x,r=s.y-e.y,i=o*o+r*r;if(i===0)return null;const a=Math.sqrt(i);let l=((t.x-e.x)*o+(t.y-e.y)*r)/i;l=Math.max(0,Math.min(1,l));const c={x:e.x+l*o,y:e.y+l*r},d=Math.sqrt((t.x-c.x)**2+(t.y-c.y)**2);return{proj:c,t:l,dist:d,length:a}}function v7(t,e,s=sK){let o=null,r=s;for(const i of e){const a=hw(t,i.start,i.end);a&&a.dist<r&&(r=a.dist,o={wall:i,positionPx:a.t*a.length})}return o}const aK=12,lK=14,q2=7,cK=8,dK=6;function Lc(t,e,s,o=1,r,i,a){var g,w;const l=aK/Math.max(o,1e-4),c=lK/Math.max(o,1e-4),d=cK/Math.max(o,1e-4),u=k=>!i||(k.wallType??"exterior")===i,h=k=>!i||i!=="exterior"||u(k);let x=l,f=null;for(const k of s)if(k.id!==r)for(const _ of[k.start,k.end]){if(a!=null&&a.excludeEndpoint&&i4(_,a.excludeEndpoint))continue;const j=Math.sqrt((t.x-_.x)**2+(t.y-_.y)**2);j<x&&(x=j,f=_)}if(!f&&((g=a==null?void 0:a.extraSnapWalls)!=null&&g.length))for(const k of a.extraSnapWalls)for(const _ of[k.start,k.end]){if(a!=null&&a.excludeEndpoint&&i4(_,a.excludeEndpoint))continue;const j=Math.sqrt((t.x-_.x)**2+(t.y-_.y)**2);j<x&&(x=j,f=_)}if(f)return{point:{...f},type:"endpoint",snapTarget:f};let p=null;if(e&&(p=uK(t,e,d),p)){const k=i==="exterior"?s.filter(v=>(v.wallType??"exterior")==="exterior"):s,_=hK(e,p.point,c),j=mK(e,_,k,r);if(j)return{point:{x:Math.round(j.point.x),y:Math.round(j.point.y)},type:p.type,snapTarget:j.point,onWall:{wallId:j.wall.id,positionPx:j.positionPx}}}let b=c,M=null;for(const k of s){if(k.id===r||!h(k))continue;const _=hw(t,k.start,k.end);if(!_)continue;const j=l,v=_.t*_.length,C=(1-_.t)*_.length;v<j||C<j||_.dist<b&&(b=_.dist,M={wall:k,proj:_.proj,positionPx:v})}if(M)return{point:{x:Math.round(M.proj.x),y:Math.round(M.proj.y)},type:"wall-body",snapTarget:M.proj,onWall:{wallId:M.wall.id,positionPx:M.positionPx}};if((w=a==null?void 0:a.extraSnapWalls)!=null&&w.length){let k=c,_=null;for(const j of a.extraSnapWalls){const v=hw(t,j.start,j.end);if(!v)continue;const C=l,N=v.t*v.length,P=(1-v.t)*v.length;N<C||P<C||v.dist<k&&(k=v.dist,_=v.proj)}if(_)return{point:{x:Math.round(_.x),y:Math.round(_.y)},type:"wall-body",snapTarget:_}}if(e&&p){const k={...p.point},_=p.type,j=a4(k,s,o,i,e,r);return _==="ortho-h"&&j.xRef?(k.x=j.xRef.x,{point:k,type:_,alignmentGuides:{xRef:j.xRef}}):_==="ortho-v"&&j.yRef?(k.y=j.yRef.y,{point:k,type:_,alignmentGuides:{yRef:j.yRef}}):{point:k,type:_}}
341if(e){const k=a4(t,s,o,i,e,r);if(k.xRef||k.yRef){const _={x:k.xRef?k.xRef.x:t.x,y:k.yRef?k.yRef.y:t.y},j=k.xRef&&k.yRef?"align-xy":k.xRef?"align-x":"align-y";return{point:_,type:j,alignmentGuides:k}}}return{point:t,type:"none"}}function uK(t,e,s){const o=t.x-e.x,r=t.y-e.y,i=Math.abs(Math.atan2(r,o)*180/Math.PI);return(i<q2||i>180-q2)&&Math.abs(r)<=s?{point:{x:t.x,y:e.y},type:"ortho-h"}:Math.abs(i-90)<q2&&Math.abs(o)<=s?{point:{x:e.x,y:t.y},type:"ortho-v"}:null}function hK(t,e,s){const o=e.x-t.x,r=e.y-t.y,i=Math.sqrt(o*o+r*r);return i<1?e:{x:e.x+o/i*s,y:e.y+r/i*s}}function i4(t,e){return Math.abs(t.x-e.x)<.5&&Math.abs(t.y-e.y)<.5}function a4(t,e,s,o,r,i){const a=dK/Math.max(s,1e-4),l=x=>!o||o!=="exterior"||(x.wallType??"exterior")===o;let c=a,d,u=a,h;for(const x of e)if(x.id!==i&&l(x))for(const f of[x.start,x.end]){if(r&&f.x===r.x&&f.y===r.y)continue;const p=Math.abs(t.x-f.x);p<c&&(c=p,d=f);const b=Math.abs(t.y-f.y);b<u&&(u=b,h=f)}return{xRef:d,yRef:h}}function mK(t,e,s,o){let r=null;const i=e.x-t.x,a=e.y-t.y;if(i*i+a*a<1)return null;for(const c of s){if(c.id===o)continue;const d=c.start.x,u=c.start.y,h=c.end.x,x=c.end.y,f=h-d,p=x-u,b=i*p-a*f;if(Math.abs(b)<1e-6)continue;const M=d-t.x,g=u-t.y,w=(M*p-g*f)/b,k=(M*a-g*i)/b;if(!(w<=.001||w>1)&&!(k<=.02||k>=.98)&&(!r||w<r.tRay)){const _={x:t.x+i*w,y:t.y+a*w},j=Math.sqrt(f*f+p*p);r={point:_,wall:c,positionPx:k*j,tRay:w}}}return r?{point:r.point,wall:r.wall,positionPx:r.positionPx}:null}function fK(){return Math.random().toString(36).slice(2,8)}function xK(t,e,s=4){const o=t.end.x-t.start.x,r=t.end.y-t.start.y,i=Math.sqrt(o*o+r*r);if(i<s*3)return null;const a=Math.sqrt((e.x-t.start.x)**2+(e.y-t.start.y)**2),l=Math.sqrt((e.x-t.end.x)**2+(e.y-t.end.y)**2);if(a<s||l<s)return null;const c=((e.x-t.start.x)*o+(e.y-t.start.y)*r)/(i*i),d=Math.round(t.start.x+c*o),u=Math.round(t.start.y+c*r),h={x:d,y:u},x=b=>({...t,id:`${t.id}_${b}_${fK()}`,start:t.start,end:t.end}),f=x("a");f.start=t.start,f.end=h;const p=x("b");return p.start=h,p.end=t.end,[f,p]}function l4(t,e,s,o,r){if(!s||o<=0||!Number.isFinite(o))return null;const i=qs[s];if(!i)return null;const a=v7(t,e,r);if(!a)return null;if(FF(s)){const d=EF(e,a.wall.id,a.positionPx,o);return d?{wallId:d.primary.wallId,positionPx:d.primary.positionPx,preset:s,type:i.category,widthMm:i.width,corner:d}:null}const l=Math.hypot(a.wall.end.x-a.wall.start.x,a.wall.end.y-a.wall.start.y),c=i.width/o/2;return!Number.isFinite(c)||l<=0||a.positionPx-c<0||a.positionPx+c>l?null:{wallId:a.wall.id,positionPx:a.positionPx,preset:s,type:i.category,widthMm:i.width}}const c4=11,d4=10,u4=34,pK=12,gK=18,h4=3e3,m4=20,bK=14;function MK({view:t,walls:e,containerRect:s,imageNaturalSize:o,planRotationDeg:r,measurementUnit:i="cm",onConfirm:a,onCancel:l}){const{t:c}=yn(),d=m.useId().replace(/:/g,""),[u,h]=m.useState({x:0,y:0}),[x,f]=m.useState({x:0,y:0}),[p,b]=m.useState(h4),[M,g]=m.useState(()=>De(h4,i)),[w,k]=m.useState(null),[_,j]=m.useState({p1:!1,p2:!1}),[v,C]=m.useState(!1),N=m.useRef({dx:0,dy:0}),P=m.useRef(0),L=m.useRef(null);m.useEffect(()=>{C(!1)},[r,o==null?void 0:o.w,o==null?void 0:o.h]),m.useEffect(()=>{g(De(p,i))},[p,i]),m.useEffect(()=>{if(!v)return;const U=window.requestAnimationFrame(()=>{var mt,Nt;(mt=L.current)==null||mt.focus({preventScroll:!0}),(Nt=L.current)==null||Nt.select()});return()=>window.cancelAnimationFrame(U)},[v]),m.useEffect(()=>{if(v||!s||!o)return;const U=s.width/2,mt=s.height/2,Nt=Math.min(s.width*.42,340),Lt=Wu(U,mt,t,o.w,o.h,r),oe=Nt/2/t.zoom;h({x:Lt.x-oe,y:Lt.y}),f({x:Lt.x+oe,y:Lt.y}),C(!0)},[s,t,v,o,r]);const A=o?$a(u.x,u.y,t,o.w,o.h,r):{sx:0,sy:0},W=o?$a(x.x,x.y,t,o.w,o.h,r):{sx:0,sy:0},S=Math.sqrt((x.x-u.x)**2+(x.y-u.y)**2),B=m.useCallback((U,mt)=>{var Nt,Lt;if(mt.preventDefault(),mt.stopPropagation(),k(U),U==="bar"&&o){const oe=Wu(mt.clientX-((s==null?void 0:s.left)??0),mt.clientY-((s==null?void 0:s.top)??0),t,o.w,o.h,r);N.current={dx:oe.x-u.x,dy:oe.y-u.y}}else U==="rotate"&&(P.current=Math.sqrt((x.x-u.x)**2+(x.y-u.y)**2)/2);(Lt=(Nt=mt.target).setPointerCapture)==null||Lt.call(Nt,mt.pointerId)},[s,t,u,o,r]),R=m.useCallback(U=>{let mt=null,Nt=bK/Math.max(t.zoom,.01);for(const Lt of e)for(const oe of[Lt.start,Lt.end]){const he=Math.hypot(U.x-oe.x,U.y-oe.y);he<=Nt&&(Nt=he,mt=oe)}return mt?{point:{x:mt.x,y:mt.y},snapped:!0}:{point:U,snapped:!1}},[e,t.zoom]),z=m.useCallback(U=>{if(!w||!s||!o)return;const mt=Wu(U.clientX-s.left,U.clientY-s.top,t,o.w,o.h,r);if(w==="p1"){const Nt=R(mt);h(Nt.point),j(Lt=>Lt.p1===Nt.snapped?Lt:{...Lt,p1:Nt.snapped})}else if(w==="p2"){const Nt=R(mt);f(Nt.point),j(Lt=>Lt.p2===Nt.snapped?Lt:{...Lt,p2:Nt.snapped})}
341else if(w==="bar"){const Nt=mt.x-N.current.dx,Lt=mt.y-N.current.dy,oe={x:Nt-u.x,y:Lt-u.y};h(he=>({x:he.x+oe.x,y:he.y+oe.y})),f(he=>({x:he.x+oe.x,y:he.y+oe.y})),j({p1:!1,p2:!1})}else if(w==="rotate"){const Nt=P.current;if(Nt<.5)return;const Lt=(u.x+x.x)/2,oe=(u.y+x.y)/2,he=Math.atan2(mt.y-oe,mt.x-Lt);h({x:Lt-Math.cos(he)*Nt,y:oe-Math.sin(he)*Nt}),f({x:Lt+Math.cos(he)*Nt,y:oe+Math.sin(he)*Nt}),j({p1:!1,p2:!1})}},[w,s,t,u,x,o,r,R]),X=m.useCallback(()=>{k(null)},[]);m.useEffect(()=>{if(w)return window.addEventListener("pointermove",z),window.addEventListener("pointerup",X),()=>{window.removeEventListener("pointermove",z),window.removeEventListener("pointerup",X)}},[w,z,X]),m.useEffect(()=>{const U=mt=>{mt.key==="Escape"&&(mt.preventDefault(),l())};return window.addEventListener("keydown",U),()=>window.removeEventListener("keydown",U)},[l]);const ft=m.useCallback(()=>{const U=ni(M,i);!U||U<=0||S<1||(b(U),a({scale:U/S,referenceSegment:{start:{x:u.x,y:u.y},end:{x:x.x,y:x.y},distanceMm:U}}))},[M,i,S,a,u,x]),tt=m.useCallback(U=>{const mt=S/2;if(mt<.5)return;const Nt=(u.x+x.x)/2,Lt=(u.y+x.y)/2;U==="horizontal"?(h({x:Nt-mt,y:Lt}),f({x:Nt+mt,y:Lt})):(h({x:Nt,y:Lt-mt}),f({x:Nt,y:Lt+mt}))},[u,x,S]),G=Math.sqrt((W.sx-A.sx)**2+(W.sy-A.sy)**2),Y=Math.atan2(W.sy-A.sy,W.sx-A.sx),J=-Math.sin(Y),Mt=Math.cos(Y),Rt=Math.cos(Y),it=Math.sin(Y),st=Math.max(2,Math.floor(G/pK)),ct=[];for(let U=0;U<=st;U++){const mt=U/st,Nt=A.sx+Rt*G*mt,Lt=A.sy+it*G*mt,oe=U===0||U===st||U%5===0,he=oe?9:5;ct.push({x1:Nt+J*he,y1:Lt+Mt*he,x2:Nt-J*he,y2:Lt-Mt*he,major:oe})}const pt=(A.sx+W.sx)/2,xt=(A.sy+W.sy)/2,_t="#EAB308",Ft="#78350F",Vt="#FDE047",vt=pt+J*u4,Ht=xt+Mt*u4,Tt=Math.abs(Rt)<.35;if(!v)return null;const Zt=`cal-arrow-s-${d}`,At=`cal-arrow-e-${d}`,ut=Ka(i),kt=ni(M,i),Et=!!kt&&kt>0&&S>=1,ht=kt&&S>=1?kt/S:null,gt=kt&&S>=1?De(kt,i):null,Pt=S>=1&&S<m4;return n.jsxs("div",{className:"absolute inset-0 z-50",style:{pointerEvents:"none"},children:[n.jsx("div",{className:"absolute top-2 left-1/2 -translate-x-1/2 w-[min(720px,94vw)] pointer-events-auto",dir:"rtl",children:n.jsxs("div",{className:"rounded-xl border-2 border-yellow-400 bg-white shadow-[0_0_18px_rgba(250,204,21,0.6),0_10px_28px_rgba(0,0,0,0.18)] overflow-hidden flex flex-row-reverse items-center gap-2.5 px-2.5 py-1.5",children:[n.jsx("div",{className:"w-7 h-7 rounded-lg bg-gradient-to-l from-[#EC7357] to-[#B33D24] flex items-center justify-center shrink-0",children:n.jsx(hp,{size:15,className:"text-white",strokeWidth:2.2})}),n.jsx("p",{className:"flex-1 min-w-0 text-right text-[10px] sm:text-[11px] text-gray-700 leading-snug",children:c("calibration.instructions",{defaultValue:"כיול: הניחו על מידה ידועה · גררו קצוות · סובבו בחץ הסיבוב (↕ גם אנכי) · הזינו {{unit}} למטה · שמור",unit:ut})})]})}),n.jsxs("svg",{className:"absolute inset-0 w-full h-full",style:{pointerEvents:"none"},children:[n.jsxs("defs",{children:[n.jsx("marker",{id:Zt,markerWidth:"7",markerHeight:"7",refX:"0",refY:"3.5",orient:"auto",children:n.jsx("path",{d:"M7,0 L0,3.5 L7,7",fill:"none",stroke:Ft,strokeWidth:"1.2"})}),n.jsx("marker",{id:At,markerWidth:"7",markerHeight:"7",refX:"7",refY:"3.5",orient:"auto",children:n.jsx("path",{d:"M0,0 L7,3.5 L0,7",fill:"none",stroke:Ft,strokeWidth:"1.2"})})]}),n.jsx("line",{x1:A.sx,y1:A.sy,x2:W.sx,y2:W.sy,stroke:"transparent",strokeWidth:gK,style:{pointerEvents:"stroke",cursor:w==="bar"?"grabbing":"grab"},onPointerDown:U=>B("bar",U)}),n.jsx("line",{x1:A.sx,y1:A.sy,x2:W.sx,y2:W.sy,stroke:Vt,strokeWidth:16,strokeLinecap:"butt",opacity:.85,style:{pointerEvents:"none"}}),n.jsx("line",{x1:A.sx,y1:A.sy,x2:W.sx,y2:W.sy,stroke:_t,strokeWidth:5,strokeLinecap:"butt",style:{pointerEvents:"none"}}),ct.map((U,mt)=>n.jsx("line",{x1:U.x1,y1:U.y1,x2:U.x2,y2:U.y2,stroke:Ft,strokeWidth:U.major?1.8:1,opacity:U.major?.95:.7,style:{pointerEvents:"none"}},mt)),n.jsx("line",{x1:A.sx-J*18,y1:A.sy-Mt*18,x2:W.sx-J*18,y2:W.sy-Mt*18,stroke:Ft,strokeWidth:2,markerStart:`url(#${Zt})`,markerEnd:`url(#${At})`,opacity:.9,style:{pointerEvents:"none"}}),n.jsx("circle",{cx:A.sx,cy:A.sy,r:c4,fill:_.p1?"#DCFCE7":"#FEF9C3",stroke:_.p1?"#16a34a":_t,strokeWidth:3,className:"drop-shadow-md",style:{pointerEvents:"auto",cursor:w==="p1"?"grabbing":"grab"},onPointerDown:U=>B("p1",U)}),n.jsx("circle",{cx:W.sx,cy:W.sy,r:c4,fill:_.p2?"#DCFCE7":"#FEF9C3",stroke:_.p2?"#16a34a":_t,strokeWidth:3,className:"drop-shadow-md",style:{pointerEvents:"auto",cursor:w==="p2"?"grabbing":"grab"},onPointerDown:U=>B("p2",U)}),n.jsx("line",{x1:pt,y1:xt,x2:vt,y2:Ht,stroke:Ft,strokeWidth:1.5,strokeDasharray:"3 2",opacity:.75,style:{pointerEvents:"none"}}),n.jsx("circle",{cx:vt,cy:Ht,r:d4+4,fill:"transparent",style:{pointerEvents:"auto",cursor:w==="rotate"?"grabbing":"grab"},onPointerDown:U=>B("rotate",U)}),n.jsx("circle",{cx:vt,cy:Ht,r:d4,fill:"#FFFBEB",stroke:_t,strokeWidth:2.5,className:"drop-shadow-md",style:{pointerEvents:"none"}}),n.jsx("g",{transform:`translate(${vt}, ${Ht}) rotate(${Y*180/Math.PI+90})`,style:{pointerEvents:"none"},children:n.jsx("path",{d:"M0,-5.5 L0,5.5 M-4,-2.5 L0,-5.5 L4,-2.5 M-4,2.5 L0,5.5 L4,2.5",fill:"none",stroke:Ft,strokeWidth:1.4,strokeLinecap:"round",strokeLinejoin:"round"})})]}),n.jsx("div",{className:"absolute bottom-3 left-1/2 -translate-x-1/2 w-[min(720px,94vw)] pointer-events-auto",dir:"rtl",children:n.jsxs("div",{className:"flex flex-col gap-1.5",children:[n.jsxs("div",{className:"flex flex-col sm:flex-row-reverse items-stretch sm:items-center gap-2 rounded-xl border-2 border-yellow-400 bg-white shadow-[0_0_18px_rgba(250,204,21,0.6),0_10px_28px_rgba(0,0,0,0.18)] px-2.5 py-2",children:[n.jsxs("div",{className:"flex items-center gap-1.5 flex-row-reverse justify-end flex-1 min-w-0",children:[Tt?n.jsx(l5,{size:15,className:"text-[#C04428] shrink-0 opacity-85"}):n.jsx(a5,{size:15,className:"text-[#C04428] shrink-0 opacity-85"}),n.jsxs("div",{className:"text-right flex-1 min-w-0",children:[n.jsx("div",{className:"text-[9px] font-semibold text-gray-500 uppercase tracking-wide",children:c("calibration.actualLength",{defaultValue:"אורך אמיתי ({{unit}})",unit:ut})}),n.jsx("div",{className:"flex items-center gap-1 flex-row-reverse mt-0.5 justify-end",children:n.jsx("input",{ref:L,t
341ype:"text",inputMode:"decimal",min:"1",step:i==="mm"?"1":"0.1",value:M,onChange:U=>g(U.target.value),onKeyDown:U=>{U.key==="Enter"&&ft()},className:`w-[4.25rem] text-center text-sm font-bold text-gray-900 border border-[#EC7357]/50 rounded-lg px-1.5 py-1 bg-white/90
342                      focus:outline-none focus:ring-2 focus:ring-[#EC7357]/35 focus:border-[#D84B2E]`})})]})]}),n.jsxs("div",{className:"flex items-center gap-1 flex-row-reverse shrink-0",children:[n.jsx("button",{type:"button",title:c("calibration.alignHorizontal",{defaultValue:"יישור אופקי"}),onClick:()=>tt("horizontal"),className:"flex items-center justify-center w-8 h-8 rounded-lg text-gray-600 bg-white/80 hover:bg-white border border-gray-200/90 transition-colors cursor-pointer",children:n.jsx(a5,{size:14})}),n.jsx("button",{type:"button",title:c("calibration.alignVertical",{defaultValue:"יישור אנכי"}),onClick:()=>tt("vertical"),className:"flex items-center justify-center w-8 h-8 rounded-lg text-gray-600 bg-white/80 hover:bg-white border border-gray-200/90 transition-colors cursor-pointer",children:n.jsx(l5,{size:14})}),n.jsx("button",{type:"button",title:c("calibration.freeRotate",{defaultValue:"סיבוב חופשי"}),onClick:()=>tt(Tt?"horizontal":"vertical"),className:"flex items-center justify-center w-8 h-8 rounded-lg text-gray-600 bg-white/80 hover:bg-white border border-gray-200/90 transition-colors cursor-pointer sm:hidden",children:n.jsx(X_,{size:14})})]}),n.jsxs("div",{className:"flex gap-1.5 flex-row-reverse sm:flex-col sm:justify-center shrink-0",children:[n.jsxs("button",{type:"button",onClick:ft,disabled:!Et,className:`flex items-center justify-center gap-1.5 flex-row-reverse px-3 py-2 rounded-lg text-[11px] font-bold text-white
343                  bg-gradient-to-b from-[#EC7357] to-[#D84B2E] hover:from-[#f08068] hover:to-[#C04428]
344                  shadow-[0_2px_0_0_#7a2a18,0_4px_14px_rgba(216,75,46,0.35)]
345                  active:translate-y-px active:shadow-[0_1px_0_0_#7a2a18]
346                  disabled:opacity-45 disabled:shadow-none disabled:translate-y-0 transition-all cursor-pointer`,children:[n.jsx(Ny,{size:14,strokeWidth:2.5}),c("calibration.save",{defaultValue:"שמור כיול"})]}),n.jsxs("button",{type:"button",onClick:l,className:`flex items-center justify-center gap-1 flex-row-reverse px-2.5 py-1.5 rounded-lg text-[10px] font-semibold text-gray-600
347                  bg-white/70 hover:bg-white border border-gray-200/90 transition-colors cursor-pointer`,children:[n.jsx(Gr,{size:14}),c("common.cancel",{defaultValue:"ביטול"})]})]})]}),n.jsx("div",{className:"text-[9px] text-gray-500 text-center leading-tight px-1 space-y-0.5",children:S<1?n.jsx("p",{children:c("calibration.lineTooShort",{defaultValue:"קו קצר מדי — גררו את הקצוות להארכת הקטע"})}):n.jsxs(n.Fragment,{children:[n.jsxs("p",{children:[c("calibration.scaleReadout",{defaultValue:"קנה מידה: {{scale}} מ״מ/px · הקטע = {{pixels}} px",scale:(ht==null?void 0:ht.toFixed(2))??"—",pixels:Math.round(S)}),gt?` = ${gt} ${ut}`:"",_.p1&&_.p2?` · ${c("calibration.snapped",{defaultValue:"🧲 נצמד לפינות קיר"})}`:""]}),Pt?n.jsx("p",{className:"text-amber-700 font-semibold",children:c("calibration.shortSegmentWarning",{defaultValue:"קטע קצר — מומלץ כיול על מידה ארוכה יותר (מעל {{pixels}}px) לדיוק מקסימלי",pixels:m4})}):n.jsx("p",{children:c("calibration.verticalHint",{defaultValue:"גררו את חץ הסיבוב לכיול אנכי · אחרי שמירה אמתו עם «סרט מדידה» ב-2D"})})]})})]})})]})}const yK=new Set(["single_door","single_door_glass","flush_door","double_door","sliding_door","arched_door","arched_door_glass","garage_door","casement_window","awning_window","sliding_window"]);function j7({openings:t,selectedOpeningIdx:e,onOpeningsChange:s,onSelectedOpeningChange:o,effectiveScale:r,walls:i,fpIsDark:a,measurementUnit:l="cm",hideDirectionAndFlushFace:c=!1,isOpen:d=!1,onToggleOpen:u}){const{t:h}=yn(),{isRTL:x}=Yd();if(e<0||e>=t.length)return null;const f=t[e],p=!!f.preset&&yK.has(f.preset),b=f.preset?qs[f.preset]:null,M=f.type==="window",g=Math.round(f.positionPx*r),w=f.widthMm||(b==null?void 0:b.width)||900,k=f.heightMm||(b==null?void 0:b.height)||2100,_=f.sillHeightMm??(b==null?void 0:b.sillHeight)??900,j=hm(f),v=Lf(f),C=M?h("openingEditor.window",{defaultValue:"חלון"}):h("openingEditor.door",{defaultValue:"דלת"}),N=f.preset?h(`opening.${f.preset}`,{defaultValue:(b==null?void 0:b.label)??C}):C,P=L=>{s(t.map((A,W)=>W===e?{...A,...L}:A))};return n.jsxs("div",{dir:x?"rtl":"ltr",className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[n.jsxs("div",{className:O("text-[11px] font-semibold truncate",a?"text-white/70":"text-[#5a5065]"),children:[C," — ",N]}),n.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[p&&u&&n.jsx("button",{type:"button",onClick:u,className:O("px-2.5 py-1 rounded-xl text-[10px] font-medium transition-all cursor-pointer",d?"text-white bg-[#336CFF] hover:bg-[#2559e6]":a?"text-white/80 bg-white/10 hover:bg-white/15":"text-[#182137] bg-[#182137]/[
3470.06] hover:bg-[#182137]/[0.1]"),children:d?h("openingEditor.close",{defaultValue:"סגור"}):h("openingEditor.open",{defaultValue:"פתח"})}),!f.cornerGroupId&&n.jsx("button",{type:"button",onClick:()=>{const L=Z1(t,f.id,i,r);L&&(s(L.next),o(L.newIdx))},className:O("px-2.5 py-1 rounded-xl text-[10px] font-medium transition-all cursor-pointer",a?"text-[#F4A99A] bg-white/10 hover:bg-white/15":"text-[#B84A2E] bg-[#FDF6F4] hover:bg-[#FCE8E4]"),children:h("openingEditor.duplicate",{defaultValue:"שכפל"})}),n.jsx("button",{type:"button",onClick:()=>{s(t.filter((L,A)=>A!==e&&(!f.cornerGroupId||L.cornerGroupId!==f.cornerGroupId))),o(null)},className:"px-2.5 py-1 rounded-xl text-[10px] font-medium text-[#d4738a] bg-[#fdf0f3] hover:bg-[#f9d5de] transition-all cursor-pointer",children:h("openingEditor.delete",{defaultValue:"מחק"})})]})]}),n.jsxs("div",{className:"space-y-2.5",children:[n.jsx(Og,{label:h("openingEditor.position",{defaultValue:"מיקום"}),measurementUnit:l,valueMm:g,minMm:0,maxMm:2e4,onChangeMm:L=>P({positionPx:L/r})}),n.jsx(Og,{label:h("openingEditor.width",{defaultValue:"רוחב"}),measurementUnit:l,valueMm:w,minMm:300,maxMm:3e3,stepMm:1,showInput:!0,onChange:L=>P({widthMm:L})}),n.jsx(Og,{label:h("openingEditor.height",{defaultValue:"גובה"}),measurementUnit:l,valueMm:k,minMm:500,maxMm:3e3,stepMm:1,showInput:!0,onChange:L=>P({heightMm:L})}),M&&n.jsx(Og,{label:h("openingEditor.sill",{defaultValue:"אדן"}),measurementUnit:l,valueMm:_,minMm:0,maxMm:1500,stepMm:50,onChange:L=>P({sillHeightMm:L})})]}),M&&n.jsx("button",{type:"button",onClick:()=>P({widthMm:k,heightMm:w}),className:O("w-full rounded-xl px-2.5 py-2 text-[10px] font-semibold transition-all cursor-pointer",a?"bg-white/10 text-white/80 hover:bg-white/15":"bg-[#182137]/[0.06] text-[#30283a] hover:bg-[#182137]/[0.09]"),children:h("openingEditor.rotate90",{defaultValue:"סובב 90°"})}),!c&&j&&n.jsxs("div",{className:O("rounded-2xl border p-2.5",a?"border-white/10 bg-white/[0.03]":"border-[#182137]/10 bg-white/70"),children:[n.jsx("div",{className:O("mb-2 text-[10px] font-bold",a?"text-white/75":"text-[#5a5065]"),children:M?h("openingEditor.windowOpeningDirection",{defaultValue:"כיוון פתיחת חלון"}):h("openingEditor.doorOpeningDirection",{defaultValue:"כיוון פתיחת דלת"})}),n.jsx($3,{value:Wd(f),onChange:L=>P(rm(L)),fpIsDark:a,compact:!0})]}),!c&&v&&n.jsxs("div",{className:O("rounded-2xl border p-2.5",a?"border-white/10 bg-white/[0.03]":"border-[#182137]/10 bg-white/70"),children:[n.jsx("div",{className:O("mb-2 text-[10px] font-bold",a?"text-white/75":"text-[#5a5065]"),children:h("openingEditor.flushFace",{defaultValue:"צד קו 0"})}),n.jsx(X3,{value:xb(f),onChange:L=>P(Gw(L)),fpIsDark:a,compact:!0})]}),n.jsxs("div",{dir:"ltr",className:"flex items-center gap-2 justify-center pt-1",children:[n.jsxs("button",{type:"button",onClick:()=>P({positionPx:Math.max(0,f.positionPx-50/r)}),className:`flex-1 py-1.5 rounded-xl text-[10px] font-medium cursor-pointer transition-all duration-150 text-center
348            border border-[#182137]/8 bg-gradient-to-b from-white to-[#f5f2ec] text-[#182137]/70
349            shadow-[0_2px_0_rgba(24,33,55,0.06),0_2px_6px_rgba(0,0,0,0.04)]
350            hover:border-[#EC7357]/35 hover:from-[#FDF6F4] hover:to-white hover:shadow-[0_2px_0_rgba(216,75,46,0.12)]
351            active:translate-y-px`,children:["← ",$i(50,l)]}),n.jsxs("button",{type:"button",onClick:()=>P({positionPx:f.positionPx+50/r}),className:`flex-1 py-1.5 rounded-xl text-[10px] font-medium cursor-pointer transition-all duration-150 text-center
352            border border-[#182137]/8 bg-gradient-to-b from-white to-[#f5f2ec] text-[#182137]/70
353            shadow-[0_2px_0_rgba(24,33,55,0.06),0_2px_6px_rgba(0,0,0,0.04)]
354            hover:border-[#EC7357]/35 hover:from-[#FDF6F4] hover:to-white hover:shadow-[0_2px_0_rgba(216,75,46,0.12)]
355            active:translate-y-px`,children:[$i(50,l)," →"]})]})]})}function _7(t,e,s){return Math.min(s,Math.max(e,t))}function wK({label:t,measurementUnit:e,valueMm:s,minMm:o,maxMm:r,onCommitMm:i}){const[a,l]=m.useState(De(s,e));m.useEffect(()=>{l(De(s,e))},[e,s]);const c=()=>{const d=ni(a,e);if(d===null){l(De(s,e));return}i(_7(d,o,r))};return n.jsxs("div",{className:"flex w-[78px] shrink-0 items-center gap-1 rounded-xl border border-[#ddd8d0] bg-white px-1.5 py-1 focus-within:border-[#D84B2E] focus-within:ring-1 focus-within:ring-[#EC7357]/30",children:[n.jsx("input",{type:"text",inputMode:"decimal","aria-label":`${t} ${Ka(e)}`,value:a,onChange:d=>l(d.target.value),onBlur:c,onKeyDown:d=>{d.key==="Enter"&&(c(),d.target.blur())},className:"min-w-0 flex-1 bg-transparent text-center text-[10px] font-medium tabular-nums text-[#3d3a36] outline-none"}),n.jsx("span",{className:"shrink-0 text-[8px] font-medium text-[#9b95a0]",children:Ka(e)})]})}function Og({label:t,measurementUnit:e,valueMm:s,minMm:o,maxMm:r,stepMm:i=10,showInput:a=!1,onChange:l,onCh
355angeMm:c}){const d=u=>{const h=_7(u,o,r);c==null||c(h),l==null||l(h)};return n.jsxs("div",{className:"flex items-center gap-2.5",children:[n.jsx("span",{className:"text-[9px] text-[#9b95a0] w-[34px] text-left shrink-0",children:t}),n.jsx("input",{type:"range",min:o,max:r,step:i,value:s,onChange:u=>d(Number(u.target.value)),className:`flex-1 h-[3px] appearance-none bg-[#ede8e4] rounded-full outline-none cursor-pointer
356          [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-3 [&::-webkit-slider-thumb]:h-3
357          [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-[#D84B2E] [&::-webkit-slider-thumb]:shadow-[0_1px_4px_rgba(216,75,46,0.35)]
358          [&::-webkit-slider-thumb]:cursor-pointer [&::-webkit-slider-thumb]:transition-all [&::-webkit-slider-thumb]:hover:scale-125`}),a?n.jsx(wK,{label:t,measurementUnit:e,valueMm:s,minMm:o,maxMm:r,onCommitMm:d}):n.jsx("span",{className:"text-[10px] font-medium text-[#5a5065] w-[52px] text-center shrink-0 tabular-nums",children:$i(s,e)})]})}const f4=.96,kK=12;function E7(t){return Math.hypot(t.end.x-t.start.x,t.end.y-t.start.y)}function x4(t,e){return e<=0?0:Math.round(E7(t)*e)}function Hx(t,e,s){return s<=0?0:Math.round(Math.hypot(e.x-t.x,e.y-t.y)*s)}function vK(t){return{x:(t.start.x+t.end.x)/2,y:(t.start.y+t.end.y)/2}}function jK(t,e){const s=e.x-t.x,o=e.y-t.y,r=Math.hypot(s,o);if(r<2)return e;const i=Math.abs(s)/r,a=Math.abs(o)/r;return i>=f4&&i>=a?{x:e.x,y:t.y}:a>=f4?{x:t.x,y:e.y}:e}function _K(t,e,s=kK){const o=e.referenceSegment;if(!o)return t;const r=[o.start,o.end];let i=null,a=s;for(const l of r){const c=Math.hypot(t.x-l.x,t.y-l.y);c<=a&&(a=c,i=l)}return i??t}function p4(t,e,s,o){let r=_K(e,s);return t&&!(o!=null&&o.skipAxisSnap)&&(r=jK(t,r)),r}const g4=1e3,EK=5,DK=100;function FK(t){const e=Number.isFinite(t)&&t>0?t:g4/DK;return{spacingPx:g4/e,majorEvery:EK}}function CK(t,e,s={}){const o=e.x-t.x,r=e.y-t.y,i=Math.hypot(o,r);if(i<1)return null;const a=o/i,l=r/i,c=NK(a,l),d=s.offsetPx??28,u=s.extensionGapPx??10,h=s.extensionOverrunPx??5,x=s.labelWidthPx??0,f=s.labelHeightPx??0,p=s.marginPx??8,b=s.minGuideSegmentPx??18,M=s.minLabelSegmentPx??34,g={x:(t.x+e.x)/2,y:(t.y+e.y)/2},w={x:g.x+c.x*d,y:g.y+c.y*d},k=IK(w,{labelWidthPx:x,labelHeightPx:f,canvasWidthPx:s.canvasWidthPx,canvasHeightPx:s.canvasHeightPx,marginPx:p});return{segmentLengthPx:i,guideStart:ff(t,c,d),guideEnd:ff(e,c,d),startExtensionA:ff(t,c,u),startExtensionB:ff(t,c,d+h),endExtensionA:ff(e,c,u),endExtensionB:ff(e,c,d+h),labelCenter:k,showGuide:i>=b,showLabel:i>=M}}function NK(t,e){let s=-e,o=t;return Math.abs(o)<.35?s<0&&(s=-s,o=-o):o<0&&(s=-s,o=-o),{x:s,y:o}}function ff(t,e,s){return{x:t.x+e.x*s,y:t.y+e.y*s}}function IK(t,e){const s=e.labelWidthPx/2,o=e.labelHeightPx/2,r=s+e.marginPx,i=o+e.marginPx,a=e.canvasWidthPx===void 0?void 0:e.canvasWidthPx-s-e.marginPx,l=e.canvasHeightPx===void 0?void 0:e.canvasHeightPx-o-e.marginPx;return{x:a===void 0?t.x:b4(t.x,r,a),y:l===void 0?t.y:b4(t.y,i,l)}}function b4(t,e,s){return s<e?(e+s)/2:Math.min(s,Math.max(e,t))}const M4=.05,TK=44;function SK(t,e){const s=e.x-t.x,o=e.y-t.y;if(Math.hypot(s,o)<.01)return null;const r=Math.atan2(Math.abs(o),Math.abs(s))*180/Math.PI;return Math.max(0,Math.min(90,r))}function PK(t){return`${t.toFixed(1)}°`}function AK(t,e,s){const o=SK(t,e);return o===null?null:s==="ortho-h"||o<=M4?{angleDeg:o,kind:"horizontal",label:"אופקי"}:s==="ortho-v"||90-o<=M4?{angleDeg:o,kind:"perpendicular",label:"ניצב"}:{angleDeg:o,kind:"free",label:PK(o)}}function LK(t,e,s){const o=$a(t.x,t.y,s.view,s.imgSize.w,s.imgSize.h,s.planRotationDeg),r=$a(e.x,e.y,s.view,s.imgSize.w,s.imgSize.h,s.planRotationDeg),i={x:o.sx,y:o.sy},a={x:r.sx,y:r.sy},l=a.x-i.x,c=a.y-i.y,d=Math.hypot(l,c);if(d<(s.minSegmentPx??TK))return null;const u=e.x<t.x?-1:1,h=$a(t.x+u*100,t.y,s.view,s.imgSize.w,s.imgSize.h,s.planRotationDeg),x=h.sx-i.x,f=h.sy-i.y;if(Math.hypot(x,f)<.01)return null;const p=Math.atan2(f,x),b=Math.atan2(c,l),M=WK(b-p),g=Math.min(76,Math.max(32,d*.28)),w=p+M/2,k=g+29,_=s.marginPx??8,j={x:i.x+Math.cos(w)*k,y:i.y+Math.sin(w)*k};return{center:i,radiusPx:g,startAngleRad:p,endAngleRad:b,counterclockwise:M<0,labelCenter:{x:y4(j.x,s.labelWidthPx/2+_,s.canvasSize.w-s.labelWidthPx/2-_),y:y4(j.y,s.labelHeightPx/2+_,s.canvasSize.h-s.labelHeightPx/2-_)},screenStart:i,screenEnd:a}}function WK(t){let e=t;for(;e>Math.PI;)e-=Math.PI*2;for(;e<=-Math.PI;)e+=Math.PI*2;return e}
358function y4(t,e,s){return s<e?(e+s)/2:Math.min(s,Math.max(e,t))}const Hg=1e3,w4=5,m1=1,sb=1;function mw(t){const e=t.endX-t.startX,s=t.endY-t.startY,o=Math.hypot(e,s);if(o<sb)return null;let r=-s/o,i=e/o;(i<-1e-9||Math.abs(i)<1e-9&&r<-1e-9)&&(r=-r,i=-i);const a=r*t.startX+i*t.startY,l=Math.round(r*Hg)/Hg,c=Math.round(i*Hg)/Hg,d=Math.round(a/w4)*w4;return`${l},${c},${d}`}function RK(t){if(t.length===0)return[];const e=OK(t);return HK(e)}function OK(t){if(t.length<2)return t.slice();const e=new Map,s=i=>{let a=e.get(i);return a||(a=[],e.set(i,a)),a};for(let i=0;i<t.length;i++)for(let a=i+1;a<t.length;a++){const l=t[i],c=t[a];if(dp(l)<sb||dp(c)<sb||mw(l)===mw(c))continue;const d=BK(l,c);d&&(s(l.id).push({t:d.tA,x:d.x,y:d.y}),s(c.id).push({t:d.tB,x:d.x,y:d.y}))}if(e.size===0)return t.slice();const o=[];let r=0;for(const i of t){const a=e.get(i.id);if(!a||a.length===0){o.push(i);continue}a.sort((x,f)=>x.t-f.t);const l=[],c=dp(i),d=Math.max(m1/Math.max(c,1),1e-4);for(const x of a){if(x.t<=.001||x.t>=.999)continue;const f=l[l.length-1];f&&Math.abs(f.t-x.t)<d||l.push(x)}if(l.length===0){o.push(i);continue}let u=i.startX,h=i.startY;for(const x of l)o.push({id:`${i.id}__x${r++}`,startX:u,startY:h,endX:Math.round(x.x),endY:Math.round(x.y)}),u=Math.round(x.x),h=Math.round(x.y);o.push({id:`${i.id}__x${r++}`,startX:u,startY:h,endX:i.endX,endY:i.endY})}return o}function HK(t){const e=new Map;for(const o of t){const r=mw(o);r&&(e.has(r)||e.set(r,[]),e.get(r).push(o))}const s=[];for(const[,o]of e){if(o.length===1){const g=o[0];s.push({id:g.id,startX:g.startX,startY:g.startY,endX:g.endX,endY:g.endY,sourceIds:[k4(g.id)]});continue}let r=o[0],i=dp(r);for(let g=1;g<o.length;g++){const w=dp(o[g]);w>i&&(r=o[g],i=w)}const a=r.endX-r.startX,l=r.endY-r.startY,c=Math.hypot(a,l)||1,d=a/c,u=l/c,h=r.startX,x=r.startY,f=[];for(const g of o){const w=(g.startX-h)*d+(g.startY-x)*u,k=(g.endX-h)*d+(g.endY-x)*u,_=Math.min(w,k),j=Math.max(w,k);f.push({t0:_,t1:j,sourceIds:new Set([k4(g.id)])})}const p=[];for(const g of f)p.push(g.t0),p.push(g.t1);p.sort((g,w)=>g-w);const b=[];for(const g of p)(b.length===0||Math.abs(g-b[b.length-1])>m1)&&b.push(g);if(b.length<2)continue;let M=0;for(let g=0;g<b.length-1;g++){const w=b[g],k=b[g+1],_=(w+k)/2,j=new Set;for(const W of f)if(_>=W.t0-m1&&_<=W.t1+m1)for(const S of W.sourceIds)j.add(S);if(j.size===0)continue;const v=Math.round(h+w*d),C=Math.round(x+w*u),N=Math.round(h+k*d),P=Math.round(x+k*u);if(Math.hypot(N-v,P-C)<sb)continue;const L=[...j].sort(),A=L.length===1?L[0]:`norm:${L.join("+")}__s${M++}`;s.push({id:A,startX:v,startY:C,endX:N,endY:P,sourceIds:L})}}return s}function dp(t){const e=t.endX-t.startX,s=t.endY-t.startY;return Math.hypot(e,s)}function k4(t){const e=t.indexOf("__x");if(e>0)return t.slice(0,e);const s=t.indexOf("__s");return s>0?t.slice(0,s):t}function BK(t,e){const s=t.endX-t.startX,o=t.endY-t.startY,r=e.endX-e.startX,i=e.endY-e.startY,a=s*i-o*r;if(Math.abs(a)<1e-6)return null;const l=e.startX-t.startX,c=e.startY-t.startY,d=(l*i-c*r)/a,u=(l*o-c*s)/a;if(d<=.01||d>=.99||u<=.01||u>=.99)return null;const h=t.startX+d*s,x=t.startY+d*o;return{x:h,y:x,tA:d,tB:u}}const f1=50;function VK(t){return D7(t).rooms}function D7(t){const e=zK();if(t.length===0)return{rooms:[],diagnostics:e};const s=RK(t),o=QK(s,f1),r=[],i=(j,v)=>{for(let C=0;C<r.length;C++){const N=r[C],P=N.x-j,L=N.y-v;if(P*P+L*L<=f1*f1)return C}return r.push({x:j,y:v}),r.length-1},a=[],l=j=>{for(;a.length<=j;)a.push([]);return a[j]},c=new Map,d=(j,v,C)=>{const N=`${j},${v}`;let P=c.get(N);P||(P=new Set,c.set(N,P));for(const L of C)P.add(L)};for(const j of o){if(j.startX===j.endX&&j.startY===j.endY)continue;const v=i(j.startX,j.startY),C=i(j.endX,j.endY);if(v===C)continue;const N=j.sourceIds.length>0?j.sourceIds:[j.id];d(v,C,N),d(C,v,N)}for(const[j,v]of c){const C=j.split(","),N=Number(C[0]),P=Number(C[1]),L=[...v].sort(),A=r[N],W=r[P],S=Math.atan2(W.y-A.y,W.x-A.x);l(N).push({from:N,to:P,wallIds:L,idKey:L.join("\0"),angle:S})}if(r.length===0)return{rooms:[],diagnostics:e};for(;a.length<r.length;)a.push([]);for(let j=0;j<64;j++){let v=!1;for(let C=0;C<a.length;C++){const N=a[C];if(N.length!==1)continue;const P=N[0];a[C]=[],a[P.to]=a[P.to].filter(L=>!(L.to===C&&L.idKey===P.idKey)),v=!0}if(!v)break}for(const j of a)j.sort((v,C)=>v.angle!==C.angle?v.angle-C.angle:v.idKey.localeCompare(C.idKey));const u=j=>`${j.from}-${j.to}-${j.idKey}`,h=new Set,x=[],f=j=>{const v=a[j.to];if(!v||v.length===0)return null;const C=v.findIndex(P=>P.to===j.from&&P.idKey===j.idKey);if(C===-1)return null;const N=(C+1)%v.length;return v[N]},p=Math.max(o.length*8+64,256);for(const j of a)for(const v of j){if(h.has(u(v)))continue;const C=[];let N=v,P=0;for(;N&&!h.has(u(N));){if(P++>p){C.length=0;break}h.add(u(N)),C.push(N),N=f(N)}if(C.length<3)continue;const L=C.map(W=>r[W.from]),A=_4(L);Math.abs(A)<1||x.push({edges:C,verts:L,signedArea:A})}if(x.length===0)return{rooms:[],diagnostics:e};const b=[];for(const j of x){const v=Math.abs(j.signedArea);if(v<1)continue;const C=Array.from(new Set(j.edges.flatMap(P=>P.wallIds))).sort(),N=j.signedArea<0?j.verts:[...j.verts].reverse();b.push({wallIds:C,vertices:N,areaMm2:v})}const M=new Map,g=new Set,w=[],k=new Set;for(const[j,v]of b.entries()){const C=YK(v.vertices),N=Math.abs(_4(C));if(N<1)continue;const P=gb(C);if(P){if(M.has(P)){k.add(P),e.droppedDuplicateRoomCandidates.push({polygonKey:P,wallIds:v.wallIds,vertices:C,areaMm2:N,droppedCandidateIndex:j,keptCandidateIndex:M.get(P)??null});continue}M.set(P,j)}else{const L=v.wallIds.join("|");if(g.has(L))continue;g.add(L)}w.push({wallIds:v.wallIds,vertices:C,areaMm2:N})}const _=qK(w,o);return e.duplicateRoomCandidateCount=e.droppedDuplicateRoomCandidates.length,e.duplicateRoomPolygonKeys=[...k].sort(),{rooms:$K(_),diagnostics:e}}function zK(){return{duplicateRoomCandidateCount:0,duplicateRoomPolygonKeys:[],droppedDuplicateRoomCandidates:[]}}function $K(t){if(t.length===0)return[];const e=t.map(l=>({wallIds:l.wallIds,vertices:l.vertices,areaMm2:l.areaMm2,polygonKey:gb(l.vertices)||`fallback:${l.wallIds.join("|")}`,probe:XK(l.vertices)})),s=[...e].sort((l,c)=>l.areaMm2-c.areaMm2),o=new Map;for(const l of e){let c=null;
358for(const d of s)if(d.polygonKey!==l.polygonKey&&!(d.areaMm2<=l.areaMm2+1)&&rk(l.probe.x,l.probe.y,d.vertices)){c=d;break}o.set(l.polygonKey,c?c.polygonKey:null)}const r=new Map,i=(l,c)=>{if(r.has(l))return r.get(l);if(c.has(l))return 0;c.add(l);const d=o.get(l),u=d==null?0:i(d,c)+1;return r.set(l,u),u};for(const l of e)i(l.polygonKey,new Set);const a=new Map;for(const l of e){const c=o.get(l.polygonKey);if(!c)continue;let d=a.get(c);d||(d=[],a.set(c,d)),d.push(l.vertices)}return e.map(l=>({wallIds:l.wallIds,vertices:l.vertices,areaMm2:l.areaMm2,polygonKey:l.polygonKey,parentKey:o.get(l.polygonKey)??void 0,depth:r.get(l.polygonKey)??0,holes:a.get(l.polygonKey)??[]}))}function XK(t){if(t.length<3)return t[0]??{x:0,y:0};const e=JK(t);if(rk(e.x,e.y,t))return e;const s=t.length,o=[];for(let r=0;r<s;r++){const i=t[r],a=t[(r+1)%s];if(i.y===a.y)continue;const l=(e.y-i.y)/(a.y-i.y);l<=0||l>=1||o.push(i.x+l*(a.x-i.x))}if(o.sort((r,i)=>r-i),o.length>=2){let r=e.x,i=0;for(let a=0;a+1<o.length;a+=2){const l=o[a+1]-o[a];l>i&&(i=l,r=(o[a]+o[a+1])/2)}return{x:r,y:e.y}}return{x:(t[0].x+e.x)/2,y:(t[0].y+e.y)/2}}const v4=.5;function YK(t){if(t.length<3)return t;let e=j4(t,v4);return e=UK(e),e=j4(e,v4),e.length>=3?e:t}function j4(t,e){const s=e*e,o=[];for(const r of t){const i=o[o.length-1];if(i){const a=r.x-i.x,l=r.y-i.y;if(a*a+l*l<=s)continue}o.push({x:r.x,y:r.y})}for(;o.length>=2;){const r=o[0],i=o[o.length-1],a=r.x-i.x,l=r.y-i.y;if(a*a+l*l<=s)o.pop();else break}return o}const GK=.5;function UK(t){if(t.length<4)return t;const e=(o,r)=>Math.abs(o-r)<GK;let s=t;for(let o=0;o<s.length+2;o++){const r=[],i=s.length;for(let a=0;a<i;a++){const l=s[(a-1+i)%i],c=s[a],d=s[(a+1)%i],u=e(l.y,c.y)&&e(c.y,d.y),h=e(l.x,c.x)&&e(c.x,d.x);u||h||r.push(c)}if(r.length===s.length)break;if(r.length<3)return t;s=r}return s}function KK(t,e,s,o,r,i){const a=r-s,l=i-o,c=t-s,d=e-o,u=a*a+l*l;if(u<1e-12)return Math.hypot(c,d);let h=(c*a+d*l)/u;h=Math.max(0,Math.min(1,h));const x=s+h*a,f=o+h*l;return Math.hypot(t-x,e-f)}function J2(t,e,s){const o=e.length;for(let r=0;r<o;r++){const i=e[r],a=e[(r+1)%o];if(KK(t.x,t.y,i.x,i.y,a.x,a.y)<=s)return!0}return!1}function ZK(t,e,s){if(e.length<2)return!1;const o=t.startX,r=t.startY,i=t.endX,a=t.endY,l=i-o,c=a-r,d=Math.abs(c)<s,u=Math.abs(l)<s;if(!d&&!u)return!1;const h=e.length;for(let x=0;x<h;x++){const f=e[x],p=e[(x+1)%h],b=p.x-f.x,M=p.y-f.y,g=Math.abs(M)<s,w=Math.abs(b)<s;if(d&&g){if(Math.abs(r-f.y)>s)continue;const k=Math.min(o,i),_=Math.max(o,i),j=Math.min(f.x,p.x),v=Math.max(f.x,p.x);if(_<j-s||k>v+s)continue;if(Math.min(_,v)-Math.max(k,j)>=s)return!0}if(u&&w){if(Math.abs(o-f.x)>s)continue;const k=Math.min(r,a),_=Math.max(r,a),j=Math.min(f.y,p.y),v=Math.max(f.y,p.y);if(_<j-s||k>v+s)continue;if(Math.min(_,v)-Math.max(k,j)>=s)return!0}}return!1}function qK(t,e){const s=f1*3;return t.filter(o=>{const r=new Set(o.wallIds);for(const i of e){if(i.sourceIds.some(h=>r.has(h))||ZK(i,o.vertices,s))continue;const l=(i.startX+i.endX)/2,c=(i.startY+i.endY)/2;if(!rk(l,c,o.vertices)||J2({x:l,y:c},o.vertices,s))continue;const d={x:i.startX,y:i.startY},u={x:i.endX,y:i.endY};if(J2(d,o.vertices,s)&&J2(u,o.vertices,s))return!1}return!0})}function JK(t){let e=0,s=0;for(const r of t)e+=r.x,s+=r.y;const o=t.length;return{x:e/o,y:s/o}}function rk(t,e,s){let o=!1;for(let r=0,i=s.length-1;r<s.length;i=r++){const a=s[r].x,l=s[r].y,c=s[i].x,d=s[i].y,u=d-l;Math.abs(u)<1e-9||l>e!=d>e&&t<(c-a)*(e-l)/u+a&&(o=!o)}return o}function _4(t){const e=t.length;if(e<3)return 0;let s=0;for(let o=0;o<e;o++){const r=t[o],i=t[(o+1)%e];s+=r.x*i.y-i.x*r.y}return s/2}function QK(t,e){const s=[];for(const i of t)s.push({x:i.startX,y:i.startY}),s.push({x:i.endX,y:i.endY});const o=[],r=e*e;for(const i of t){const a=i.endX-i.startX,l=i.endY-i.startY,c=a*a+l*l;if(c<1){o.push(i);continue}const d=[];for(const f of s){if(Math.abs(f.x-i.startX)<1&&Math.abs(f.y-i.startY)<1||Math.abs(f.x-i.endX)<1&&Math.abs(f.y-i.endY)<1)continue;const p=((f.x-i.startX)*a+(f.y-i.startY)*l)/c;if(p<=.01||p>=.99)continue;const b=i.startX+p*a,M=i.startY+p*l;(b-f.x)*(b-f.x)+(M-f.y)*(M-f.y)>r||d.push({t:p,x:f.x,y:f.y})}if(d.length===0){o.push(i);continue}d.sort((f,p)=>f.t-p.t);let u=i.startX,h=i.startY,x=0;for(const f of d)o.push({id:`${i.id}__sub${x++}`,startX:u,startY:h,endX:f.x,endY:f.y,sourceIds:i.sourceIds}),u=f.x,h=f.y;o.push({id:`${i.id}__sub${x++}`,startX:u,startY:h,endX:i.endX,endY:i.endY,sourceIds:i.sourceIds})}return o}function F7(t,e){if(t.length<3||e<=0)return[];const s=t.map(o=>({id:o.id,startX:Math.round(o.start.x*e),startY:Math.round(o.start.y*e),endX:Math.round(o.end.x*e),endY:Math.round(o.end.y*e)}));return VK(s).map((o,r)=>
358{const i=o.vertices.map(c=>E4(c,e)),a=o.holes.map(c=>c.map(d=>E4(d,e))),l=o.areaMm2/1e6;return{id:o.polygonKey||`room_${r+1}`,vertices:i,holes:a,areaSqm:l,areaLabel:`${tZ(l)} מ״ר`,labelPoint:eZ(i),depth:o.depth}}).filter(o=>o.vertices.length>=3&&o.areaSqm>0).sort((o,r)=>r.areaSqm-o.areaSqm)}function E4(t,e){return{x:t.x/e,y:t.y/e}}function tZ(t){return Number.isFinite(t)?t.toFixed(2).replace(/\.?0+$/,""):"0"}function eZ(t){const e=nZ(t);if(e&&oZ(e,t))return e;const s=sZ(t),o=[(s.minY+s.maxY)/2,s.minY+(s.maxY-s.minY)*.42,s.minY+(s.maxY-s.minY)*.58];let r=null;for(const i of o){const a=[];for(let l=0;l<t.length;l++){const c=t[l],d=t[(l+1)%t.length];if(c.y>i==d.y>i)continue;const u=(i-c.y)/(d.y-c.y);a.push(c.x+u*(d.x-c.x))}a.sort((l,c)=>l-c);for(let l=0;l+1<a.length;l+=2){const c=a[l],d=a[l+1],u=d-c;u<=0||(!r||u>r.width)&&(r={point:{x:(c+d)/2,y:i},width:u})}}return r?r.point:{x:(s.minX+s.maxX)/2,y:(s.minY+s.maxY)/2}}function nZ(t){let e=0,s=0,o=0;for(let r=0;r<t.length;r++){const i=t[r],a=t[(r+1)%t.length],l=i.x*a.y-a.x*i.y;e+=l,s+=(i.x+a.x)*l,o+=(i.y+a.y)*l}return Math.abs(e)<1e-4?null:{x:s/(3*e),y:o/(3*e)}}function oZ(t,e){let s=!1;for(let o=0,r=e.length-1;o<e.length;r=o++){const i=e[o],a=e[r];if(i.y>t.y!=a.y>t.y){const l=(a.x-i.x)*(t.y-i.y)/(a.y-i.y)+i.x;t.x<l&&(s=!s)}}return s}function sZ(t){let e=1/0,s=1/0,o=-1/0,r=-1/0;for(const i of t)e=Math.min(e,i.x),s=Math.min(s,i.y),o=Math.max(o,i.x),r=Math.max(r,i.y);return{minX:e,minY:s,maxX:o,maxY:r}}const x1="הקלק והכנס שם לאזור",Sd="__traceRoomLabelDefaults__";function Yp(t){var e;return((e=t[Sd])==null?void 0:e.hidden)!==!1}function C7(t,e){const s=t[e]??{},o=typeof s.hidden=="boolean"?s.hidden:Yp(t);return{...s,hidden:o}}function N7(t,e){return t.map(s=>{var i,a;const o=C7(e,s.id),r=((i=o==null?void 0:o.name)==null?void 0:i.trim())||x1;return{id:s.id,name:r,areaLabel:s.areaLabel,hidden:!!(o!=null&&o.hidden),placeholder:!((a=o==null?void 0:o.name)!=null&&a.trim())}})}function I7(t,e,s){if(e===Sd)return t;const o=Yp(t),i={...t[e]??{},...s},a=A7(i,o),l={...t};return a?l[e]=a:delete l[e],l}function T7(t,e){var o,r;const s={...t,[Sd]:{hidden:!0}};for(const i of e){const a=(r=(o=s[i])==null?void 0:o.name)==null?void 0:r.trim();a?s[i]={name:a}:delete s[i]}return s}function S7(t,e){var o;const s={...t,[Sd]:{hidden:!1}};for(const r of e){const i=s[r];if(!i)continue;const a=(o=i.name)==null?void 0:o.trim();a?s[r]={name:a}:delete s[r]}return s}function P7(t){var i;if(!t||typeof t!="object")return{};const e={};for(const[a,l]of Object.entries(t)){if(!a||!l||typeof l!="object")continue;const c=l,d=typeof c.name=="string"?c.name.trim():"",u=typeof c.hidden=="boolean"?c.hidden:void 0;if(a===Sd){typeof u=="boolean"&&(e[Sd]={hidden:u});continue}(d||typeof u=="boolean")&&(e[a]={...d?{name:d}:{},...typeof u=="boolean"?{hidden:u}:{}})}const s=Yp(e),o=(i=e[Sd])==null?void 0:i.hidden,r=typeof o=="boolean"?{[Sd]:{hidden:o}}:{};for(const[a,l]of Object.entries(e)){if(a===Sd)continue;const c=A7(l,s);c&&(r[a]=c)}return r}function A7(t,e){var i;const s=((i=t.name)==null?void 0:i.trim())||"",o=typeof t.hidden=="boolean"?t.hidden:void 0,r=typeof o=="boolean"&&o!==e;return!s&&!r?null:{...s?{name:s}:{},...r?{hidden:o}:{}}}const rZ=188,iZ=168,aZ=176,lZ=84,Q2=292,ty=280,ey=340,Bg=420,cZ={},dZ=()=>{},yf=7,uZ=14,L7=Object.keys(qs);L7.filter(t=>qs[t].category==="door");L7.filter(t=>qs[t].category==="window");const hZ={exterior:5,interior:3,mamad:4,free:3},p1="#FFD600",mZ="rgba(255, 214, 0, 0.42)",fZ="rgba(255, 214, 0, 0.30)",xZ="rgba(255, 214, 0, 0.62)",fw="#ff9f43",ny="#D85D43";function pZ(t,e,s){const o=s.x-e.x,r=s.y-e.y,i=o*o+r*r;if(i<=1e-9)return Math.hypot(t.x-e.x,t.y-e.y);const a=Math.max(0,Math.min(1,((t.x-e.x)*o+(t.y-e.y)*r)/i));return Math.hypot(t.x-(e.x+o*a),t.y-(e.y+r*a))}function D4(t){return t.length<3||Mp(t)?!1:t.every((e,s)=>Math.hypot(t[(s+1)%t.length].x-e.x,t[(s+1)%t.length].y-e.y)>=2)}function F4(t,e,s,o,r,i){const a=LT(e,s);t.save(),t.beginPath(),t.moveTo(a[0].x,a[0].y);for(let l=1;l<a.length;l+=1)t.lineTo(a[l].x,a[l].y);if(t.closePath(),t.fillStyle=r?"rgba(216,93,67,.35)":"rgba(216,93,67,.20)",t.strokeStyle=r?ny:"rgba(24,33,55,.72)",t.lineWidth=(r?2.5:1.5)/o,t.fill(),t.stroke(),r){const l=Lp(e),c=e.end.x-e.start.x,d=e.end.y-e.start.y,u=Math.hypot(c,d)||1,h=e.widthMm/Math.max(s,.001)/2,x=-d/u,f=c/u,p={x:l.x+x*(
358h+28/o),y:l.y+f*(h+28/o)};t.strokeStyle=ny,t.lineWidth=1.5/o,t.beginPath(),t.moveTo(l.x+x*h,l.y+f*h),t.lineTo(p.x,p.y),t.stroke();for(const b of[e.start,e.end,p])t.fillStyle="#F7F4EF",t.strokeStyle=ny,t.lineWidth=2/o,t.beginPath(),t.arc(b.x,b.y,yf/o,0,Math.PI*2),t.fill(),t.stroke();if(i){t.font=`700 ${12/o}px Heebo, sans-serif`;const b=t.measureText(i).width;t.fillStyle="rgba(247,244,239,.96)",t.strokeStyle="rgba(24,33,55,.12)",t.lineWidth=1/o,t.beginPath(),t.roundRect(l.x-b/2-7/o,l.y-23/o,b+14/o,20/o,5/o),t.fill(),t.stroke(),t.fillStyle="#182137",t.textAlign="center",t.textBaseline="middle",t.fillText(i,l.x,l.y-13/o)}}t.restore()}const W7=25,R7=8,gZ=m.forwardRef(function({imageUrl:e,showBackground:s,showTraceOverlays:o,walls:r,beams:i,openings:a,furniture:l,calibration:c,effectiveScale:d,selected:u,detectionDebug:h,cameraPose:x=null,showCameraMarker:f=!1,onCameraPoseChange:p,traceRoomLabels:b=cZ,onTraceRoomLabelsChange:M=dZ,traceRoomLabelListOpen:g=!1,onTraceRoomLabelListOpenChange:w,traceRoomOverlays:k,sketchPolygons:_,selectedSketchEntityId:j,onSelectSketchEntity:v,onMoveSketchEntity:C,underlayWalls:N=null,showUnderlay:P=!1,externalMode:L,roofContour:A=null,onRoofContourCommit:W,onRoofContourCancel:S,onRoofContourFinish:B,activeFurnType:R,activeOpeningPreset:z,activeWallType:X,wallTypeSettings:ft,measurementUnit:tt="cm",onModeChange:G,onAddWall:Y,onEditWall:J,onAddBeam:Mt,onEditBeam:Rt,onSplitWall:it,onSelect:st,onAddOpening:ct,onEditOpening:pt,onAddFurniture:xt,onMoveFurniture:_t,onOpeningsChange:Ft,onDeleteSelected:Vt,onRotateSelected:vt,onRotateFurniture:Ht,onScaleFurniture:Tt,onCalibrate:Zt},At){const{t:ut,i18n:kt}=yn(),Et=kt.dir(),ht=tt==="mm"?ut("settings.millimeters",{defaultValue:"מ״מ"}):ut("settings.centimeters",{defaultValue:"ס״מ"}),gt=m.useCallback(et=>`${De(et,tt)} ${ht}`,[tt,ht]),Pt=m.useRef(null),U=m.useRef(null),mt=m.useRef(null),Nt=m.useRef(null),Lt=m.useRef(!1),oe=m.useRef([]),he=m.useRef(null),pe=m.useRef(!1),[Ge,Qt]=m.useState(null),te=m.useRef(L),Be=L!==te.current,wt=Be?L||"trace":Ge||L||"trace",ve=et=>Qt(et),Ne=m.useRef(wt);Ne.current=wt;const Le=m.useRef(o);Le.current=o;const is=X||"exterior",Fe=(ft==null?void 0:ft[is])??br[is],bn=c.planRotationDeg??0,Ve=R||"sofa",en=z??null,[on,Qs]=m.useState(null),[sn,vn]=m.useState([]),[Ot,so]=m.useState(!1),[Ue,hs]=m.useState(null),[Qn,Lr]=m.useState(null),bi=m.useRef(sn);bi.current=sn;const Ps=m.useMemo(()=>{if(sn.length<2)return[];const et=Ot?sn.length:sn.length-1;return Array.from({length:et},(q,Ct)=>({id:`roof-snap:${Ct}:${(Ct+1)%sn.length}`,start:sn[Ct],end:sn[(Ct+1)%sn.length],wallType:"free"}))},[sn,Ot]),[In,Rn]=m.useState(null),[fe,Gs]=m.useState(null),[zo,js]=m.useState(null),[co,ze]=m.useState(null),[Un,uo]=m.useState(null);m.useEffect(()=>{wt!=="trace"&&(Qs(null),ze(null),to(null),qe(null)),wt!=="beam"&&(Rn(null),Gs(null)),wt!=="door"&&wt!=="window"&&wt!=="opening"&&uo(null),wt!=="measure2d"&&(Te(null),ho(null))},[wt]),m.useEffect(()=>{if(wt!=="roof")return;const et=(A==null?void 0:A.outer.map(q=>({...q})))??[];vn(et),so(et.length>=3),hs(null),Lr(null)},[wt,A]);const dn=m.useCallback(et=>{if(!D4(et))return!1;const q=et.map(Ct=>({...Ct}));return vn(q),so(!0),W==null||W({outer:q,holes:(A==null?void 0:A.holes.map(Ct=>Ct.map(bt=>({...bt}))))??[]}),!0},[W,A]);m.useEffect(()=>{en||uo(null)},[en]);const[$o,Te]=m.useState(null),[po,ho]=m.useState(null),[go,Kl]=m.useState([]),[da,As]=m.useState(!1),[ua,Gi]=m.useState(null),[On,to]=m.useState(null),[Wt,qe]=m.useState(null),[Se,jn]=m.useState(null),[je,ne]=m.useState(null),[Re,Dn]=m.useState(null),[ge,ie]=m.useState(!1),[Ze,as]=m.useState(!1),[Pe,Ao]=m.useState(null),Lo=m.useRef(Pe);Lo.current=Pe;const[Gt,Co]=m.useState(fH),Xo=m.useRef(null),pn=m.useRef(null),Kn=m.useCallback(et=>{if(typeof window>"u"){Co(et);return}const q=Xo.current;Xo.current=q?Ct=>et(q(Ct)):et,pn.current===null&&(pn.current=window.requestAnimationFrame(()=>{pn.current=null;const Ct=Xo.current;Xo.current=null,Ct&&Co(Ct)}))},[]);m.useEffect(()=>()=>{pn.current!==null&&(window.cancelAnimationFrame(pn.current),pn.current=null),Xo.current=null},[]);const[tr,ro]=m.useState(0),[ls,Qo]=m.useState(null),[ms,Yo]=m.useState(null),[Qe,Go]=m.useState(null),[er,Vn]=m.useState(null),[dr,Ii]=m.useState(!1),fs=w?g:dr,Uo=w??Ii,[Hn,ur]=m.useState(null),oi=m.useRef(a),Je=m.useRef(null),rn=m.useRef(null),xs=m.useMemo(()=>k??(o?F7(r,d):[]),[k,o,r,d]),vo=m.useMemo(()=>xs.map(et=>({...et,areaLabel:ut("roomLabels.areaValue",{area:C4(et.areaSqm),defaultValue:`${C4(et.areaSqm)} מ״ר`})})),[xs,ut]),Ui=m.useMemo(()=>new Set(xs.map(et=>et.id)),[xs]),It=m.useMemo(()=>xs.map(et=>et.id),[xs]),_s=m.useMemo(()=>N7(vo,b).map(et=>({...et,name:et.placeholder?ut("roomLabels.namePlaceholder",{defaultValue:x1}):et.name})),[vo,b,ut]),ha=Yp(b)||_s.some(et=>et.hidden),Mi=m.useCallback((et,q)=>{M(I7(b,et,q))},[b,M]),Fa=m.useCallback(()=>{xs.length!==0&&M(T7(b,It))},[xs.length,b,It,M]);m.useCallback(()=>{M(S7(b,It))},[b,It,M]);const si=m.useCallback((et,q="card")=>{const Ct=Pt.current;if(!Ct)return null;const bt=Ct.getBoundingClientRect(),Dt=et.clientX-bt.left,Xt=et.clientY-bt.top,me=oe.current;for(let xe=me.length-1;xe>=0;xe-=1){const Ee=me[xe],wn=q==="name"?Ee.nameRect:Ee.rect;if(Dt>=wn.left&&Dt<=wn.right&&Xt>=wn.top&&Xt<=wn.bottom)return Ee}return null},[]),Ko=m.useCallback((et,q)=>{var bt;if(!Ui.has(et))return;Vn(null);const Ct=((bt=b[et])==null?void 0:bt.name)??"";ur({roomId:et,x:q.left,y:q.top,width:Math.max(180,q.right-q.left),value:Ct})},[b,Ui]);m.useCallback((et,q)=>{const Ct=U.current,bt=Ct==null?void 0:Ct.getBoundingClientRect(),Dt=q.getBoundingClientRect();Ko(et,bt?{left:Dt.left-bt.left,top:Dt.top-bt.top,right:Dt.right-bt.left,bottom:Dt.bottom-bt.top}
358:{left:64,top:64,right:284,bottom:98})},[Ko]);const ae=m.useCallback(et=>{const q=si(et,"name");!q||!Ui.has(q.roomId)||(et.preventDefault(),et.stopPropagation(),Ko(q.roomId,q.nameRect))},[Ko,si,Ui]),Za=m.useCallback(()=>{Hn&&(Mi(Hn.roomId,{name:Hn.value.trim()||void 0}),ur(null))},[Hn,Mi]);m.useEffect(()=>{oi.current=a,Qo(et=>et&&a.some(q=>q.id===et.openingId)?et:null),Yo(et=>et&&a.some(q=>q.id===et.openingId)?et:null),Go(et=>et&&a.some(q=>q.id===et.openingId)?et:null)},[a]),m.useEffect(()=>{Vn(et=>et&&Ui.has(et.roomId)?et:null),ur(et=>et&&Ui.has(et.roomId)?et:null),!ha&&!w&&Uo(!1)},[Ui,ha,w,Uo]),m.useEffect(()=>{Be&&(te.current=L,Qt(null))},[L,Be]),m.useEffect(()=>{const et=q=>{if(q.key==="Escape"&&(ls||ms||Qe||er||fs||Hn)){q.preventDefault(),Qo(null),Yo(null),Go(null),Vn(null),Uo(!1),ur(null);return}const Ct=q.target;if(!(Ct&&(Ct.tagName==="INPUT"||Ct.tagName==="TEXTAREA"||Ct.isContentEditable))){if(q.key==="Escape"){if(wt==="roof"){q.preventDefault(),vn((A==null?void 0:A.outer.map(bt=>({...bt})))??[]),so(((A==null?void 0:A.outer.length)??0)>=3),hs(null),Lr(null),S==null||S();return}if(wt==="beam"){q.preventDefault(),Rn(null),Gs(null),ve("edit"),G==null||G("edit");return}if(wt==="door"||wt==="window"||wt==="opening"){q.preventDefault(),uo(null),Qo(null),Yo(null),Go(null),ve("edit"),G==null||G("edit");return}wt==="trace"&&on&&(q.preventDefault(),Qs(null),ze(null),to(null),qe(null)),wt==="measure2d"&&$o&&(q.preventDefault(),Te(null),ho(null)),wt==="edit"&&u&&(q.preventDefault(),st(null))}if(wt==="roof"&&q.key==="Enter"){q.preventDefault(),dn(bi.current);return}if(q.key==="Delete"||q.key==="Backspace"){if(wt==="roof"&&Ot&&Ue!==null&&bi.current.length>3){q.preventDefault();const bt=bi.current.filter((Dt,Xt)=>Xt!==Ue);dn(bt)&&hs(null);return}u&&(wt==="edit"||wt==="furniture")&&(q.preventDefault(),Vt())}(q.key==="r"||q.key==="R")&&((u==null?void 0:u.kind)==="furniture"&&(wt==="edit"||wt==="furniture")?(q.preventDefault(),vt()):u==null||u.kind)}};return window.addEventListener("keydown",et),()=>window.removeEventListener("keydown",et)},[u,wt,on,$o,A,Ot,Ue,dn,S,ls,ms,Qe,er,fs,Hn,G,Vt,vt,st]),m.useEffect(()=>{if(!e){mt.current=null,Ao({w:1e4,h:7e3});return}let et=!1;const q=new Image;return q.onload=()=>{et||(mt.current=q,Ao({w:q.naturalWidth,h:q.naturalHeight}))},q.src=e,()=>{et=!0}},[e]),m.useEffect(()=>{if(!Pe||!U.current)return;const et=c.planRotationDeg??0,{effW:q,effH:Ct}=qv(Pe.w,Pe.h,et);Co(Qv(q,Ct,U.current.clientWidth,U.current.clientHeight))},[Pe,c.planRotationDeg]),m.useEffect(()=>{wt==="calibrate"&&!da?(U.current&&Gi(U.current.getBoundingClientRect()),As(!0)):wt!=="calibrate"&&da&&As(!1)},[wt,da]),m.useEffect(()=>{if(!da||!U.current)return;const et=new ResizeObserver(()=>{U.current&&Gi(U.current.getBoundingClientRect())});return et.observe(U.current),()=>et.disconnect()},[da]),m.useEffect(()=>{const et=U.current;if(!et)return;const q=new ResizeObserver(()=>ro(bt=>bt+1));q.observe(et);const Ct=()=>ro(bt=>bt+1);return window.addEventListener("resize",Ct),()=>{q.disconnect(),window.removeEventListener("resize",Ct)}},[]),m.useEffect(()=>{const et=U.current;if(!et)return;const q=Ct=>{if(!Lo.current)return;const bt=Ct.target;if(bt instanceof Element&&bt.closest("[data-fp-wheel-ignore]"))return;Ct.preventDefault(),Ct.stopPropagation();const Dt=et.getBoundingClientRect(),Xt=oK(Ct,{width:Dt.width,height:Dt.height});Xt.kind==="pan"?Kn(me=>bg(me,Xt.dx,Xt.dy)):Kn(me=>_2(me,Xt.delta,Ct.clientX-Dt.left,Ct.clientY-Dt.top))};return et.addEventListener("wheel",q,{passive:!1,capture:!0}),()=>et.removeEventListener("wheel",q,{capture:!0})},[Kn]);const Mr=m.useCallback(et=>{const q=Pt.current;if(!q||!Pe)return null;const Ct=q.getBoundingClientRect(),bt=et.clientX-Ct.left,Dt=et.clientY-Ct.top;return Wu(bt,Dt,Gt,Pe.w,Pe.h,bn)},[Gt,Pe,bn]),ri=m.useCallback(et=>{const q=Mr(et);return q?{x:Math.round(q.x),y:Math.round(q.y)}:null},[Mr]),Qc=m.useCallback(et=>{const q=Pt.current;if(!q||!Pe)return null;const Ct=q.getBoundingClientRect(),bt=$a(et.x,et.y,Gt,Pe.w,Pe.h,bn);return{x:bt.sx+Ct.left,y:bt.sy+Ct.top}},[Gt,Pe,bn]),Es=m.useMemo(()=>P&&N&&N.length>0?N:void 0,[P,N]),Us=m.useCallback(()=>
358{if(!f||!x||!Pe||d<=0)return null;const et=x.x/rt/d,q=x.z/rt/d,Ct=$a(et,q,Gt,Pe.w,Pe.h,bn);return{x:Ct.sx,y:Ct.sy,angle:Rf(x.angle-bn*Math.PI/180)}},[x,d,Pe,bn,f,Gt]),Ki=m.useCallback(et=>{const q=Pt.current,Ct=Us();if(!q||!Ct||!x)return null;const bt=q.getBoundingClientRect(),Dt=et.clientX-bt.left,Xt=et.clientY-bt.top;return vF(Dt,Xt,Ct.x,Ct.y,V3)?"move":kF(Dt,Xt,Ct.x,Ct.y,Ct.angle,x.fov,lj)?"rotate":null},[x,Us]),ts=m.useCallback((et,q)=>{if(!x||!p||d<=0)return;if(q==="move"){const xe=Mr(et);if(!xe)return;p({...x,x:xe.x*d*rt,z:xe.y*d*rt});return}const Ct=Pt.current,bt=Us();if(!Ct||!bt)return;const Dt=Ct.getBoundingClientRect(),Xt=et.clientX-Dt.left,me=et.clientY-Dt.top;p({...x,angle:Rf(Math.atan2(Xt-bt.x,me-bt.y)+bn*Math.PI/180)})},[x,d,Us,p,bn,Mr]);m.useEffect(()=>{var os,Zr,Fn,qr;const et=Pt.current,q=U.current,Ct=mt.current;if(!et||!q)return;const bt=Math.max(1,q.clientWidth),Dt=Math.max(1,q.clientHeight),Xt=Math.max(1,Math.min(typeof window<"u"&&window.devicePixelRatio||1,3)),me=Math.floor(bt*Xt),xe=Math.floor(Dt*Xt);et.width!==me&&(et.width=me),et.height!==xe&&(et.height=xe);const Ee=`${bt}px`,wn=`${Dt}px`;et.style.width!==Ee&&(et.style.width=Ee),et.style.height!==wn&&(et.style.height=wn);const lt=et.getContext("2d");if(!lt)return;lt.setTransform(Xt,0,0,Xt,0,0),lt.imageSmoothingEnabled=!0,lt.imageSmoothingQuality="high",lt.clearRect(0,0,bt,Dt);const He=[];lt.fillStyle="#e8ecef",lt.fillRect(0,0,bt,Dt);const cn=FK(d),nn=cn.spacingPx,or=cn.majorEvery,qn=nn*or*2;let Oo,Ks,sr,Ls;if(Pe){const Ye=[Wu(0,0,Gt,Pe.w,Pe.h,bn),Wu(bt,0,Gt,Pe.w,Pe.h,bn),Wu(0,Dt,Gt,Pe.w,Pe.h,bn),Wu(bt,Dt,Gt,Pe.w,Pe.h,bn)],Ke=Ye.map(re=>re.x),Mo=Ye.map(re=>re.y);Oo=Math.floor((Math.min(...Ke)-qn)/nn)*nn,Ks=Math.floor((Math.min(...Mo)-qn)/nn)*nn,sr=Math.ceil((Math.max(...Ke)+qn)/nn)*nn,Ls=Math.ceil((Math.max(...Mo)+qn)/nn)*nn}else{const Ye=Zv(0,0,Gt),Ke=Zv(bt,Dt,Gt);Oo=Math.floor((Ye.x-qn)/nn)*nn,Ks=Math.floor((Ye.y-qn)/nn)*nn,sr=Math.ceil((Ke.x+qn)/nn)*nn,Ls=Math.ceil((Ke.y+qn)/nn)*nn}const ns=(Ye,Ke,Mo,re,_n,jo,Ms,un)=>{const hr=Math.floor(Ye/nn),_r=Math.ceil(Mo/nn),Ta=Math.floor(Ke/nn),ss=Math.ceil(re/nn),Ai=No=>No%or===0;lt.strokeStyle=_n,lt.lineWidth=Ms/Gt.zoom,lt.beginPath();for(let No=hr;No<=_r;No+=1){if(Ai(No))continue;const Er=No*nn;lt.moveTo(Er,Ke),lt.lineTo(Er,re)}for(let No=Ta;No<=ss;No+=1){if(Ai(No))continue;const Er=No*nn;lt.moveTo(Ye,Er),lt.lineTo(Mo,Er)}lt.stroke(),lt.strokeStyle=jo,lt.lineWidth=un/Gt.zoom,lt.beginPath();for(let No=hr;No<=_r;No+=1){if(!Ai(No))continue;const Er=No*nn;lt.moveTo(Er,Ke),lt.lineTo(Er,re)}for(let No=Ta;No<=ss;No+=1){if(!Ai(No))continue;const Er=No*nn;lt.moveTo(Ye,Er),lt.lineTo(Mo,Er)}lt.stroke()};if(lt.save(),lt.translate(Gt.offsetX,Gt.offsetY),lt.scale(Gt.zoom,Gt.zoom),Pe&&bn%360!==0){const Ye=Pe.w/2,Ke=Pe.h/2;lt.translate(Ye,Ke),lt.rotate(bn*Math.PI/180),lt.translate(-Ye,-Ke)}if(ns(Oo,Ks,sr,Ls,"#d5dbe0","#bcc5ce",.5,.8),Pe&&(lt.shadowColor="rgba(0,0,0,0.12)",lt.shadowBlur=16/Gt.zoom,lt.shadowOffsetX=4/Gt.zoom,lt.shadowOffsetY=4/Gt.zoom,lt.fillStyle="#ffffff",lt.fillRect(0,0,Pe.w,Pe.h),lt.shadowColor="transparent",s&&Ct&&(lt.globalAlpha=.85,lt.drawImage(Ct,0,0,Pe.w,Pe.h),lt.globalAlpha=1)),ge&&Pe&&ns(0,0,Pe.w,Pe.h,"rgba(100, 100, 150, 0.15)","rgba(68, 68, 120, 0.28)",.8,1.1),P&&N&&N.length>0){lt.save(),lt.lineCap="round",lt.lineJoin="round",lt.setLineDash([10/Gt.zoom,7/Gt.zoom]),lt.strokeStyle="rgba(216,93,67,0.72)",lt.lineWidth=2.5/Gt.zoom,lt.beginPath();for(const Ye of N)lt.moveTo(Ye.start.x,Ye.start.y),lt.lineTo(Ye.end.x,Ye.end.y);lt.stroke(),lt.setLineDash([]),lt.restore()}if(Ze&&h&&FZ(lt,h,Gt.zoom),wt==="roof"){if(lt.save(),lt.lineJoin="miter",lt.lineCap="round",sn.length>0){lt.beginPath(),lt.moveTo(sn[0].x,sn[0].y);for(const Ye of sn.slice(1))lt.lineTo(Ye.x,Ye.y);if(Ot){lt.closePath();for(const Ye of(A==null?void 0:A.holes)??[])if(!(Ye.length<3)){lt.moveTo(Ye[0].x,Ye[0].y);for(const Ke of Ye.slice(1))lt.lineTo(Ke.x,Ke.y);lt.closePath()}lt.fillStyle="rgba(216,93,67,0.18)",lt.fill("evenodd")}else Qn&&lt.lineTo(Qn.x,Qn.y);lt.strokeStyle="#D85D43",lt.lineWidth=3/Gt.zoom,lt.setLineDash(Ot?[]:[9/Gt.zoom,6/Gt.zoom]),lt.stroke(),lt.setLineDash([])}for(const[Ye,Ke]of sn.entries()){const Mo=Ue===Ye;lt.beginPath(),lt.arc(Ke.x,Ke.y,(Mo?8:6)/Gt.zoom,0,Math.PI*2),lt.fillStyle=Mo?"#182137":"#F7F4EF",lt.fill(),lt.strokeStyle="#D85D43",lt.lineWidth=2/Gt.zoom,lt.stroke()}if(!Ot&&sn.length>=3){const Ye=sn[0];lt.beginPath(),lt.arc(Ye.x,Ye.y,12/Gt.zoom,0,Math.PI*2),lt.strokeStyle="#182137",lt.lineWidth=2/Gt.zoom,lt.setLineDash([4/Gt.zoom,3/Gt.zoom]),lt.stroke(),lt.setLineDash([])}if(Wt!=null&&Wt.alignmentGuides&&(Wt.alignmentGuides.xRef||Wt.alignmentGuides.yRef)){const{xRef:Ye,yRef:Ke}=Wt.alignmentGuides,Mo=1e5;lt.strokeStyle="#D85D43",lt.lineWidth=1/Gt.zoom,lt.setLineDash([5/Gt.zoom,4/Gt.zoom]),Ye&&(lt.beginPath(),lt.moveTo(Ye.x,-Mo),lt.lineTo(Ye.x,Mo),lt.stroke()),Ke&&(lt.beginPath(),lt.moveTo(-Mo,Ke.y),lt.lineTo(Mo,Ke.y),lt.stroke()),lt.setLineDash([])}if(Qn&&((Wt==null?void 0:Wt.type)==="endpoint"||(Wt==null?void 0:Wt.type)==="wall-body")&&sy(lt,Wt.type,Qn.x,Qn.y,Gt.zoom),!Ot&&sn.length>0&&Qn&&Pe){const Ye=sn[sn.length-1];xw(lt,Ye,Qn,gt(Hx(Ye,Qn,d)),Gt,Pe,bn,Xt,{w:bt,h:Dt},"trace",Et),P4(lt,Ye,Qn,Wt==null?void 0:Wt.type,Gt,Pe,bn,Xt,{w:bt,h:Dt},{horizontal:ut("trace.angle.horizontal",{defaultValue:"אופקי"}),perpendicular:ut("trace.angle.perpendicular",{defaultValue:"ניצב"})},Et)}
358Qn&&A4(lt,Qn.x,Qn.y,Gt.zoom),lt.restore()}if(o&&Pe&&vo.length>0)for(const Ye of vo){const Ke=C7(b,Ye.id);bZ(lt,Ye,Ke,Gt.zoom,Gt,Pe,bn,Xt,{w:bt,h:Dt},He,ut("roomLabels.namePlaceholder",{defaultValue:x1}),Et)}oe.current=He;const ii=o||wt==="measure2d"||wt==="calibrate",Ia=ii;if(o){const Ye=(u==null?void 0:u.kind)==="wall"?u.id:null;lt.lineCap="round";for(const re of r){if(re.id===Ye&&wt==="edit")continue;const _n=re.wallType||"exterior",jo=iE[_n],Ms=(ft==null?void 0:ft[_n])??br[_n],un=hZ[_n],hr=d>0?(re.thicknessMm??Ms.thicknessMm)/d:un;lt.strokeStyle=jo.color,lt.lineWidth=Math.max(un/Gt.zoom,Math.min(hr,12/Gt.zoom)),lt.beginPath(),lt.moveTo(re.start.x,re.start.y),lt.lineTo(re.end.x,re.end.y),lt.stroke(),lt.fillStyle=jo.color;for(const _r of[re.start,re.end])lt.beginPath(),lt.arc(_r.x,_r.y,4/Gt.zoom,0,Math.PI*2),lt.fill()}const Ke=wt==="edit"&&Ye?r.find(re=>re.id===Ye):null;if(Ke){const re=Nt.current;let _n=Ke.start,jo=Ke.end;(re==null?void 0:re.kind)==="wall-endpoint"&&Se&&re.wallId===Ke.id&&(re.endpoint==="start"?_n=Se:jo=Se),lt.strokeStyle="#ff9f43",lt.lineWidth=6/Gt.zoom,lt.beginPath(),lt.moveTo(_n.x,_n.y),lt.lineTo(jo.x,jo.y),lt.stroke();for(const Ms of[_n,jo])lt.fillStyle="#ff9f43",lt.beginPath(),lt.arc(Ms.x,Ms.y,yf/Gt.zoom,0,Math.PI*2),lt.fill(),lt.strokeStyle="#fff",lt.lineWidth=1.5/Gt.zoom,lt.stroke();d>0&&yZ(lt,Ke,Gt.zoom,gt(x4(Ke,d)),"#ff9f43")}const Mo=(u==null?void 0:u.kind)==="beam"?u.id:null;for(const re of i){const _n=(zo==null?void 0:zo.id)===re.id?zo:re;F4(lt,_n,d,Gt.zoom,wt==="edit"&&Mo===re.id,wt==="edit"&&Mo===re.id?gt(t1(_n,d)):void 0)}wt==="beam"&&In&&fe&&F4(lt,{start:In,end:fe,widthMm:u5},d,Gt.zoom,!0,gt(Math.hypot(fe.x-In.x,fe.y-In.y)*d))}if(Ia&&c.referenceSegment&&(wt==="measure2d"||wt==="calibrate")){const Ye=c.referenceSegment;lt.save(),lt.setLineDash([6/Gt.zoom,5/Gt.zoom]),lt.strokeStyle="rgba(234, 179, 8, 0.55)",lt.lineWidth=1.4/Gt.zoom,lt.beginPath(),lt.moveTo(Ye.start.x,Ye.start.y),lt.lineTo(Ye.end.x,Ye.end.y),lt.stroke(),lt.setLineDash([]);for(const Ke of[Ye.start,Ye.end])lt.fillStyle="rgba(234, 179, 8, 0.35)",lt.strokeStyle="#ca8a04",lt.lineWidth=1/Gt.zoom,lt.beginPath(),lt.arc(Ke.x,Ke.y,5/Gt.zoom,0,Math.PI*2),lt.fill(),lt.stroke();lt.restore()}if(ii){for(const Ye of go)S4(lt,Ye.start,Ye.end,Gt.zoom,gt(Hx(Ye.start,Ye.end,d)),!1,Gt,Pe,bn,Xt,{w:bt,h:Dt},Et);$o&&po&&d>0&&S4(lt,$o,po,Gt.zoom,gt(Hx($o,po,d)),!0,Gt,Pe,bn,Xt,{w:bt,h:Dt},Et)}if(o){const Ye=(u==null?void 0:u.kind)==="opening"?u.id:null,Ke=Ye?(os=a.find(re=>re.id===Ye))==null?void 0:os.cornerGroupId:void 0;for(const re of a){const _n=r.find(un=>un.id===re.wallId);if(!_n)continue;const jo=re.id===Ye||!!Ke&&re.cornerGroupId===Ke,Ms=re.preset?qs[re.preset]:null;kZ(lt,re,_n,d,Gt.zoom,jo,ft,{label:re.preset?ut(`opening.${re.preset}`,{defaultValue:(Ms==null?void 0:Ms.label)??(re.type==="door"?"דלת":"חלון")}):re.type==="door"?ut("openingEditor.door",{defaultValue:"דלת"}):ut("openingEditor.window",{defaultValue:"חלון"}),widthLabel:ut("openingEditor.width",{defaultValue:"רוחב"}),heightLabel:ut("openingEditor.height",{defaultValue:"גובה"}),unitLabel:ut("settings.centimeters",{defaultValue:"ס״מ"}),direction:Et})}const Mo=(u==null?void 0:u.kind)==="furniture"?u.id:null;for(const re of l){let _n=re.position;((Zr=Nt.current)==null?void 0:Zr.kind)==="furniture"&&Nt.current.furnitureId===re.id&&Se&&(_n=Se),DZ(lt,{...re,position:_n},d,Gt.zoom,re.id===Mo)}for(const re of _){let _n=re;if(((Fn=Nt.current)==null?void 0:Fn.kind)==="sketch"&&Nt.current.entityId===re.id&&je){const jo=je;_n={...re,vertices:re.vertices.map(Ms=>({x:Ms.x+jo.xMm,y:Ms.y+jo.yMm})),holes:(qr=re.holes)==null?void 0:qr.map(Ms=>Ms.map(un=>({x:un.x+jo.xMm,y:un.y+jo.yMm})))}}EZ(lt,_n,d,Gt.zoom,re.id===j,tt,ht)}if(Un&&Un.preset===en)if(Un.corner)for(const re of[Un.corner.primary,Un.corner.return]){const _n=r.find(jo=>jo.id===re.wallId);_n&&R4(lt,{...Un,wallId:re.wallId,positionPx:re.positionPx},_n,d,Gt.zoom,ft)}else{const re=r.find(_n=>_n.id===Un.wallId);re&&R4(lt,Un,re,d,Gt.zoom,ft)}if(wt==="trace"&&co&&on&&(co.x!==on.x||co.y!==on.y)&&(lt.strokeStyle="#00ff88",lt.lineWidth=2/Gt.zoom,lt.setLineDash([4/Gt.zoom,3/Gt.zoom]),lt.beginPath(),lt.arc(co.x,co.y,10/Gt.zoom,0,Math.PI*2),lt.stroke(),lt.setLineDash([])),wt==="trace"&&on){lt.fillStyle="#336CFF",lt.beginPath(),lt.arc(on.x,on.y,7/Gt.zoom,0,Math.PI*2),lt.fill();const re=(Wt==null?void 0:Wt.point)??On;if(re){const _n=re.x-on.x,jo=re.y-on.y,Ms=Math.sqrt(_n*_n+jo*jo);if(Ms>.01){const un=d>0?Fe.thicknessMm/d/2:4,hr=Math.max(4/Gt.zoom,Math.min(un,12/Gt.zoom)),_r=-jo/Ms*hr,Ta=_n/Ms*hr;if(lt.strokeStyle="#336CFF",lt.lineWidth=2/Gt.zoom,lt.lineCap="round",lt.setLineDash([8/Gt.zoom,5/Gt.zoom]),lt.beginPath(),lt.moveTo(on.x+_r,on.y+Ta),lt.lineTo(re.x+_r,re.y+Ta),lt.stroke(),lt.beginPath(),lt.moveTo(on.x-_r,on.y-Ta),lt.lineTo(re.x-_r,re.y-Ta),lt.stroke(),lt.setLineDash([]),d>0){const ss=Hx(on,re,d);ss>0&&Pe&&xw(lt,on,re,gt(ss),Gt,Pe,bn,Xt,{w:bt,h:Dt},"trace",Et)}
358Pe&&P4(lt,on,re,Wt==null?void 0:Wt.type,Gt,Pe,bn,Xt,{w:bt,h:Dt},{horizontal:ut("trace.angle.horizontal",{defaultValue:"אופקי"}),perpendicular:ut("trace.angle.perpendicular",{defaultValue:"ניצב"})},Et)}if((Wt==null?void 0:Wt.type)==="endpoint"&&Wt.snapTarget&&sy(lt,"endpoint",Wt.snapTarget.x,Wt.snapTarget.y,Gt.zoom),Wt!=null&&Wt.onWall&&Wt.snapTarget&&(Wt.type==="wall-body"||Wt.type==="ortho-h"||Wt.type==="ortho-v")){const un=r.find(hr=>hr.id===Wt.onWall.wallId);un&&(lt.strokeStyle="rgba(99, 102, 241, 0.5)",lt.lineWidth=10/Gt.zoom,lt.lineCap="round",lt.beginPath(),lt.moveTo(un.start.x,un.start.y),lt.lineTo(un.end.x,un.end.y),lt.stroke()),sy(lt,"wall-body",Wt.snapTarget.x,Wt.snapTarget.y,Gt.zoom)}}}if(wt==="trace"&&(Wt!=null&&Wt.alignmentGuides)&&(Wt.alignmentGuides.xRef||Wt.alignmentGuides.yRef)){const{xRef:re,yRef:_n}=Wt.alignmentGuides;lt.strokeStyle="#ff1493",lt.lineWidth=1/Gt.zoom,lt.setLineDash([5/Gt.zoom,4/Gt.zoom]),lt.lineCap="butt";const jo=1e5;re&&(lt.beginPath(),lt.moveTo(re.x,-jo),lt.lineTo(re.x,jo),lt.stroke()),_n&&(lt.beginPath(),lt.moveTo(-jo,_n.y),lt.lineTo(jo,_n.y),lt.stroke()),lt.setLineDash([]),lt.fillStyle="#ff1493";const Ms=3/Gt.zoom;re&&(lt.beginPath(),lt.arc(re.x,re.y,Ms,0,Math.PI*2),lt.fill()),_n&&(_n.x!==(re==null?void 0:re.x)||_n.y!==(re==null?void 0:re.y))&&(lt.beginPath(),lt.arc(_n.x,_n.y,Ms,0,Math.PI*2),lt.fill())}wt==="trace"&&On&&A4(lt,On.x,On.y,Gt.zoom)}lt.restore();const Or=Us();Or&&x&&(lt.save(),lt.setTransform(Xt,0,0,Xt,0,0),jF(lt,{x:Or.x,y:Or.y,angle:Or.angle,fov:x.fov,coneLen:lj,activeMode:Re}),lt.restore())},[r,i,In,fe,zo,a,l,_,j,je,vo,b,on,On,Wt,Un,en,Se,co,sn,Ot,Qn,Ue,A,wt,u,s,o,N,P,ge,Ze,h,Pe,d,Gt,is,ft,Fe,tr,bn,tt,c,go,$o,po,x,Re,Us,gt,Et,ut]);const Wo=m.useRef(!1);m.useEffect(()=>{const et=Ct=>{Ct.code==="Space"&&!Ct.repeat&&(Wo.current=!0)},q=Ct=>{Ct.code==="Space"&&(Wo.current=!1)};return window.addEventListener("keydown",et),window.addEventListener("keyup",q),()=>{window.removeEventListener("keydown",et),window.removeEventListener("keyup",q)}},[]),m.useEffect(()=>{if(wt!=="pan")return;const et=Pt.current;if(!et)return;let q=null,Ct=0,bt=0;const Dt=et.style.cursor,Xt=et.style.touchAction,me=lt=>{q!==null&&(lt&&lt.pointerId!==q||(et.hasPointerCapture(q)&&et.releasePointerCapture(q),q=null,et.style.cursor="grab"))},xe=lt=>{lt.button===0&&(lt.preventDefault(),lt.stopPropagation(),q=lt.pointerId,Ct=lt.clientX,bt=lt.clientY,et.setPointerCapture(lt.pointerId),et.style.cursor="grabbing")},Ee=lt=>{if(lt.pointerId!==q)return;lt.preventDefault();const He=lt.clientX-Ct,cn=lt.clientY-bt;Ct=lt.clientX,bt=lt.clientY,Kn(nn=>bg(nn,He,cn))},wn=lt=>{lt.pointerId===q&&(q=null,et.style.cursor="grab")};return et.style.cursor="grab",et.style.touchAction="none",et.addEventListener("pointerdown",xe),et.addEventListener("pointermove",Ee),et.addEventListener("pointerup",me),et.addEventListener("pointercancel",me),et.addEventListener("lostpointercapture",wn),()=>{et.removeEventListener("pointerdown",xe),et.removeEventListener("pointermove",Ee),et.removeEventListener("pointerup",me),et.removeEventListener("pointercancel",me),et.removeEventListener("lostpointercapture",wn),et.style.cursor=Dt,et.style.touchAction=Xt}},[wt,Kn]);const Ds=m.useCallback(et=>{if(Ne.current==="pan")return;if(et.button===0&&si(et,"card")){et.preventDefault();return}if(et.button===1||et.button===0&&Wo.current){et.preventDefault(),Nt.current={kind:"pan",lastX:et.clientX,lastY:et.clientY};return}if(et.button!==0)return;const q=Ki(et);if(q){Nt.current={kind:"camera-marker",mode:q},Lt.current=!0,Dn(q),ts(et,q),et.preventDefault();return}const Ct=ri(et);if(Ct&&!(!Le.current&&wt!=="measure2d"&&wt!=="calibrate"&&wt!=="roof")){if(wt==="roof"){const bt=sn.findIndex(Dt=>Math.hypot(Ct.x-Dt.x,Ct.y-Dt.y)<=yf/Gt.zoom+4);Ot&&bt>=0&&(Nt.current={kind:"roof-point",pointIndex:bt,initial:sn.map(Dt=>({...Dt}))},Lt.current=!0,hs(bt),et.preventDefault());return}if((wt==="edit"||wt==="furniture")&&u){if(u.kind==="beam"){const bt=i.find(Dt=>Dt.id===u.id);if(bt){for(const lt of["start","end"]){const He=bt[lt];if(Math.hypot(Ct.x-He.x,Ct.y-He.y)<=yf/Gt.zoom+4){Nt.current={kind:"beam-endpoint",beam:bt,endpoint:lt},js(bt),et.preventDefault();return}}const Dt=Lp(bt),Xt=bt.end.x-bt.start.x,me=bt.end.y-bt.start.y,xe=Math.hypot(Xt,me)||1,Ee=bt.widthMm/Math.max(d,.001)/2,wn={x:Dt.x+-me/xe*(Ee+28/Gt.zoom),y:Dt.y+Xt/xe*(Ee+28/Gt.zoom)};if(Math.hypot(Ct.x-wn.x,Ct.y-wn.y)<=yf/Gt.zoom+5){Nt.current={kind:"rotate-beam",beam
358:bt,center:Dt},js(bt),et.preventDefault();return}if(hE(Ct,bt,d,5/Gt.zoom)){Nt.current={kind:"beam-body",beam:bt,startPointer:Ct},js(bt),et.preventDefault();return}}}if(u.kind==="wall"){const bt=r.find(Dt=>Dt.id===u.id);if(bt)for(const Dt of["start","end"]){const Xt=bt[Dt];if(Math.sqrt((Ct.x-Xt.x)**2+(Ct.y-Xt.y)**2)<=yf/Gt.zoom+3){const xe=Math.abs(bt.end.x-bt.start.x),Ee=Math.abs(bt.end.y-bt.start.y);let wn=null,lt=0;Ee<3&&xe>3?(wn="h",lt=bt.start.y):xe<3&&Ee>3&&(wn="v",lt=bt.start.x),Nt.current={kind:"wall-endpoint",wallId:bt.id,endpoint:Dt,constraint:wn,fixedValue:lt},jn(Ct),et.preventDefault();return}}}if(u.kind==="opening"){const bt=a.find(Dt=>Dt.id===u.id);if(bt){const Dt=r.find(Xt=>Xt.id===bt.wallId);if(Dt){const Xt=bt.preset?qs[bt.preset]:null,me=bt.widthMm||(Xt==null?void 0:Xt.width)||Kc[bt.type].width,xe=me/d/2,Ee=Dt.end.x-Dt.start.x,wn=Dt.end.y-Dt.start.y,lt=Math.sqrt(Ee*Ee+wn*wn);if(lt>0){const He=Ee/lt,cn=wn/lt,nn=Dt.start.x+He*bt.positionPx,or=Dt.start.y+cn*bt.positionPx,qn=nn-He*xe,Oo=or-cn*xe,Ks=nn+He*xe,sr=or+cn*xe,Ls=8/Gt.zoom;if(Math.sqrt((Ct.x-qn)**2+(Ct.y-Oo)**2)<Ls){Nt.current={kind:"resize-opening",openingId:bt.id,wallId:bt.wallId,side:"left",startWidthMm:me},et.preventDefault();return}if(Math.sqrt((Ct.x-Ks)**2+(Ct.y-sr)**2)<Ls){Nt.current={kind:"resize-opening",openingId:bt.id,wallId:bt.wallId,side:"right",startWidthMm:me},et.preventDefault();return}if(Math.sqrt((Ct.x-nn)**2+(Ct.y-or)**2)<xe+5){Nt.current={kind:"move-opening",openingId:bt.id,wallId:bt.wallId},et.preventDefault();return}}}}}if(u.kind==="furniture"){const bt=l.find(Dt=>Dt.id===u.id);if(bt){const Dt=pi[bt.type]??{width:1e3,depth:1e3},me=(bt.depthMm??Dt.depth*(bt.scale||1))/d/2+W7/Gt.zoom,xe=bt.rotation*Math.PI/180,Ee=Ct.x-bt.position.x,wn=Ct.y-bt.position.y,lt=Ee*Math.cos(-xe)-wn*Math.sin(-xe),He=Ee*Math.sin(-xe)+wn*Math.cos(-xe),cn=0,nn=-me;if(Math.sqrt((lt-cn)**2+(He-nn)**2)<R7/Gt.zoom+5){Nt.current={kind:"rotate-furniture",furnitureId:bt.id,centerX:bt.position.x,centerY:bt.position.y},et.preventDefault();return}const qn=bt.scale||1,Oo=(bt.widthMm??Dt.width*qn)/d/2,Ks=(bt.depthMm??Dt.depth*qn)/d/2,sr=[[-Oo,-Ks],[Oo,-Ks],[-Oo,Ks],[Oo,Ks]];for(const[ii,Ia]of sr)if(Math.sqrt((lt-ii)**2+(He-Ia)**2)<8/Gt.zoom){const os=Math.sqrt(lt**2+He**2);Nt.current={kind:"resize-furniture",furnitureId:bt.id,startDist:Math.max(os,1),startScale:qn},et.preventDefault();return}const Ls=Math.sqrt((Ct.x-bt.position.x)**2+(Ct.y-bt.position.y)**2),ns=Math.max(bt.widthMm??Dt.width*qn,bt.depthMm??Dt.depth*qn)/d/2;if(Ls<ns+10){Nt.current={kind:"furniture",furnitureId:bt.id,offsetX:Ct.x-bt.position.x,offsetY:Ct.y-bt.position.y},jn(bt.position),et.preventDefault();return}}}}if(wt==="edit"&&j){const bt=_.find(Dt=>Dt.id===j);if(bt&&r4(Ct,[bt],d)===bt.id){Nt.current={kind:"sketch",entityId:bt.id,startPx:Ct},ne({xMm:0,yMm:0}),et.preventDefault();return}}}},[wt,L,u,r,i,a,l,_,j,sn,Ot,d,Gt,ri,si,Ki,ts]),pc=m.useCallback(et=>{const q=Nt.current;if((q==null?void 0:q.kind)==="pan"){Kn(bt=>bg(bt,et.clientX-q.lastX,et.clientY-q.lastY)),q.lastX=et.clientX,q.lastY=et.clientY;return}if(Ne.current==="pan")return;if((q==null?void 0:q.kind)==="camera-marker"){ts(et,q.mode);return}const Ct=ri(et);if(Ct){if((q==null?void 0:q.kind)==="roof-point"){const bt=q.initial[q.pointIndex],Dt=[...r,...Ps.filter(me=>!(me.start.x===bt.x&&me.start.y===bt.y||me.end.x===bt.x&&me.end.y===bt.y))],Xt=Lc(Ct,q.initial[(q.pointIndex-1+q.initial.length)%q.initial.length]??null,Dt,Gt.zoom,void 0,"free",{excludeEndpoint:bt});vn(me=>me.map((xe,Ee)=>Ee===q.pointIndex?Xt.point:xe)),Lr(Xt.point),qe(Xt);return}if(wt==="roof"){const bt=Ot?null:sn[sn.length-1]??null,Dt=Lc(Ct,bt,[...r,...Ps],Gt.zoom,void 0,"free",bt?{excludeEndpoint:bt}:void 0);if(Lr(Dt.point),qe(Dt),Dt.type==="endpoint"||Dt.type==="wall-body"){const Xt=`roof:${Dt.type}:${Dt.point.x},${Dt.point.y}`;Xt!==he.current&&(he.current=Xt,Pr("snap"))}else he.current=null;return}if((q==null?void 0:q.kind)==="beam-endpoint"){const bt=q.endpoint==="start"?q.beam.end:q.beam.start,Dt=Lc(Ct,bt,r,Gt.zoom,void 0,"free",{extraSnapWalls:Es}),Xt={...q.beam,[q.endpoint]:Dt.point};t1(Xt,d)>=I1&&js(Xt);return}if((q==null?void 0:q.kind)==="beam-body"){js(mE(q.beam,{x:Ct.x-q.startPointer.x,y:Ct.y-q.startPointer.y}));return}if((q==null?void 0:q.kind)==="rotate-beam"){let bt=Math.atan2(Ct.y-q.center.y,Ct.x-q.center.x)*180/Math.PI;const Dt=et.shiftKey?15:1;bt=Math.round(bt/Dt)*Dt,js(fE(q.beam,bt));return}
358if((q==null?void 0:q.kind)==="wall-endpoint"){let{x:bt,y:Dt}=Ct;q.constraint==="h"&&(Dt=q.fixedValue),q.constraint==="v"&&(bt=q.fixedValue);const Xt=r.find(xe=>xe.id===q.wallId),me=Lc({x:bt,y:Dt},null,r,Gt.zoom,q.wallId,(Xt==null?void 0:Xt.wallType)??"exterior",{extraSnapWalls:Es});jn(me.point);return}if((q==null?void 0:q.kind)==="furniture"){jn({x:Ct.x-q.offsetX,y:Ct.y-q.offsetY});return}if((q==null?void 0:q.kind)==="sketch"){ne({xMm:(Ct.x-q.startPx.x)*d,yMm:(Ct.y-q.startPx.y)*d});return}if((q==null?void 0:q.kind)==="resize-furniture"){const bt=l.find(Dt=>Dt.id===q.furnitureId);if(bt){const Dt=Ct.x-bt.position.x,Xt=Ct.y-bt.position.y,xe=Math.sqrt(Dt*Dt+Xt*Xt)/q.startDist,Ee=Math.max(.3,Math.min(3,q.startScale*xe)),wn=Math.round(Ee*20)/20;wn!==(bt.scale||1)&&Tt(q.furnitureId,wn)}return}if((q==null?void 0:q.kind)==="rotate-furniture"){const bt=Ct.x-q.centerX,Dt=Ct.y-q.centerY;let Xt=Math.atan2(Dt,bt)*180/Math.PI+90;Xt=Math.round(Xt/15)*15,Xt=(Xt%360+360)%360;const me=l.find(xe=>xe.id===q.furnitureId);(!me||me.rotation!==Xt)&&Ht(q.furnitureId,Xt);return}if((q==null?void 0:q.kind)==="resize-opening"){const bt=a.find(Xt=>Xt.id===q.openingId),Dt=r.find(Xt=>Xt.id===q.wallId);if(bt&&Dt){const Xt=Dt.end.x-Dt.start.x,me=Dt.end.y-Dt.start.y,xe=Math.sqrt(Xt*Xt+me*me);if(xe>0){const Ee=Xt/xe,wn=me/xe,lt=Dt.start.x+Ee*bt.positionPx,He=Dt.start.y+wn*bt.positionPx,cn=(Ct.x-lt)*Ee+(Ct.y-He)*wn;q.startWidthMm/d/2;let nn;q.side==="right"?nn=Math.max(cn,15/Gt.zoom):nn=Math.max(-cn,15/Gt.zoom);const or=Math.round(nn*2*d/50)*50,qn=Math.max(200,Math.min(5e3,or));qn!==bt.widthMm&&pt({...bt,widthMm:qn})}}return}if((q==null?void 0:q.kind)==="move-opening"){const bt=a.find(Xt=>Xt.id===q.openingId),Dt=r.find(Xt=>Xt.id===q.wallId);if(bt&&Dt){const Xt=Dt.end.x-Dt.start.x,me=Dt.end.y-Dt.start.y,xe=Math.sqrt(Xt*Xt+me*me);if(xe>0){const Ee=Xt/xe,wn=me/xe;let lt=(Ct.x-Dt.start.x)*Ee+(Ct.y-Dt.start.y)*wn;const He=bt.preset?qs[bt.preset]:null,nn=(bt.widthMm||(He==null?void 0:He.width)||Kc[bt.type].width)/d/2;lt=Math.max(nn,Math.min(xe-nn,lt)),lt!==bt.positionPx&&pt({...bt,positionPx:lt})}}return}if(wt==="trace"){const bt=on?Lc(Ct,on,r,Gt.zoom,void 0,is,{excludeEndpoint:on,extraSnapWalls:Es}):Lc(Ct,null,r,Gt.zoom,void 0,is,{extraSnapWalls:Es});if(to(Dt=>Dt&&Dt.x===bt.point.x&&Dt.y===bt.point.y?Dt:bt.point),on)if(qe(Dt=>{var Xt,me,xe,Ee,wn,lt,He,cn,nn,or,qn,Oo,Ks,sr,Ls,ns,ii,Ia,Or,os;return Dt&&Dt.type===bt.type&&Dt.point.x===bt.point.x&&Dt.point.y===bt.point.y&&((Xt=Dt.onWall)==null?void 0:Xt.wallId)===((me=bt.onWall)==null?void 0:me.wallId)&&((xe=Dt.onWall)==null?void 0:xe.positionPx)===((Ee=bt.onWall)==null?void 0:Ee.positionPx)&&((lt=(wn=Dt.alignmentGuides)==null?void 0:wn.xRef)==null?void 0:lt.x)===((cn=(He=bt.alignmentGuides)==null?void 0:He.xRef)==null?void 0:cn.x)&&((or=(nn=Dt.alignmentGuides)==null?void 0:nn.xRef)==null?void 0:or.y)===((Oo=(qn=bt.alignmentGuides)==null?void 0:qn.xRef)==null?void 0:Oo.y)&&((sr=(Ks=Dt.alignmentGuides)==null?void 0:Ks.yRef)==null?void 0:sr.x)===((ns=(Ls=bt.alignmentGuides)==null?void 0:Ls.yRef)==null?void 0:ns.x)&&((Ia=(ii=Dt.alignmentGuides)==null?void 0:ii.yRef)==null?void 0:Ia.y)===((os=(Or=bt.alignmentGuides)==null?void 0:Or.yRef)==null?void 0:os.y)?Dt:bt}),bt.type==="endpoint"||bt.type==="wall-body"){const Dt=`${bt.type}:${bt.point.x},${bt.point.y}`;Dt!==he.current&&(he.current=Dt,Pr("snap"))}else he.current=null;else qe(null),he.current=null}if(wt==="beam"){const bt=In?Lc(Ct,In,r,Gt.zoom,void 0,"free",{extraSnapWalls:Es}):Lc(Ct,null,r,Gt.zoom,void 0,"free",{extraSnapWalls:Es});Gs(bt.point),qe(In?bt:null);return}if(wt==="door"||wt==="window"||wt==="opening"){if(!en||!Le.current){uo(null);return}uo(l4(Ct,r,en,d));return}if(wt==="measure2d"){const bt=Mr(et);if(!bt)return;ho(p4($o,bt,c,{skipAxisSnap:et.shiftKey}))}}},[wt,on,In,sn,Ot,Ps,r,a,l,d,Gt,ri,Mr,$o,c,is,en,Es,Ht,Tt,pt,ts,Kn]),Ti=m.useRef(null),eo=m.useRef(null),yi=m.useRef(pc);yi.current=pc;const nr=m.useCallback(et=>{Ti.current={clientX:et.clientX,clientY:et.clientY,shiftKey:et.shiftKey},eo.current===null&&(eo.current=window.requestAnimationFrame(()=>{eo.current=null;const q=Ti.current;Ti.current=null,q&&yi.current(q)}))},[]);m.useEffect(()=>()=>{eo.current!==null&&(window.cancelAnimationFrame(eo.current),eo.current=null),Ti.current=null},[]);const zs=m.useCallback(et=>{const q=Nt.current;if(q){if(q.kind==="roof-point"&&(dn(bi.current)||vn(q.initial)),q.kind==="wall-endpoint"&&Se){const Ct=r.find(bt=>bt.id===q.wallId);Ct&&J({...Ct,[q.endpoint]:Se})}q.kind==="furniture"&&Se&&_t(q.furnitureId,Se),(q.kind==="beam-endpoint"||q.kind==="beam-body"||q.kind==="rotate-beam")&&zo&&(Rt(zo),Lt.current=!0),q.kind==="sketch"&&je&&(je.xMm!==0||je.yMm!==0)&&C(q.entityId,{x:je.xMm,y:je.yMm}),q.kind==="camera-marker"&&Dn(null),Nt.current=null,jn(null),js(null),ne(null)}},[r,Se,zo,je,dn,J,Rt,_t,C]),es=m.useCallback(et=>{var bt;if(Lt.current){Lt.current=!1;return}if(Se||je||si(et,"card"))return;const q=ri(et);if(!q||wt==="calibrate"||Ne.current==="pan")return;if(!Le.current&&wt!=="measure2d"&&wt!=="roof"){wt==="edit"&&(st(null),v(null));return}if(wt==="roof"){const Dt=(Wt==null?void 0:Wt.point)??Qn??q;if(!Ot){const xe=12/Gt.zoom;if(sn.length>=3&&Math.hypot(Dt.x-sn[0].x,Dt.y-sn[0].y)<=xe){dn(sn),Lr(null),qe(null);return}vn(Ee=>[...Ee,{x:Dt.x,y:Dt.y}]),hs(null),qe(null);return}const Xt=8/Gt.zoom,me=sn.findIndex((xe,Ee)=>pZ(Dt,xe,sn[(Ee+1)%sn.length])<=Xt);if(me>=0){const xe=[...sn.slice(0,me+1),{x:Dt.x,y:Dt.y},...sn.slice(me+1)];dn(xe)&&hs(me+1)}else hs(null);qe(null);return}if(wt==="measure2d"){const Dt=Mr(et);if(!Dt)return;const Xt=p4($o,Dt,c,{skipAxisSnap:et.shiftKey});if(!$o){Te(Xt),ho(Xt);return}const me=Xt.x-$o.x,xe=Xt.y-$o.y;Math.hypot(me,xe)>2&&Kl(Ee=>[...Ee,{id:`measure2d_${Date.now()}_${Math.random().toString(36).slice(2,6)}`,start:$o,end:Xt}]),Te(null),ho(null);return}if(wt==="beam"){const Dt=Lc(q,In,r,Gt.zoom,void 0,"free",{extraSnapWalls:Es}).point;if(!In){Rn(Dt),Gs(Dt),Pr("wallStart");return}const Xt={id:dE(),start:In,end:Dt,widthMm:u5,heightMm:NT};if(t1(Xt,d)<I1)return;Mt(Xt),st({kind:"beam",id:Xt.id}),v(null),Rn(null),Gs(null),qe(null),ve("edit"),G==null||G("edit"),Pr("itemPlace");return}if(wt!=="edit"&&!on){const Dt=Rg(q,r,a,[],d);if((Dt==null?void 0:Dt.kind)==="opening"){uo(null),st({kind:"opening",id:Dt.openingId}),v(null),ve("edit"),G==null||G("edit");return}}if(wt==="edit"){const Dt=r4(q,_,d);if(Dt){v(Dt),st(null);return}const Xt=Rg(q,r,a,l,d,i);Xt?(Xt.kind==="wall"?st({kind:"wall",id:Xt.wallId}):Xt.kind==="opening"?st({kind:"opening",id:Xt.openingId}):Xt.kind==="furniture"?st({kind:"furniture",id:Xt.furnitureId}):Xt.kind==="beam"&&st({kind:"beam",id:Xt.beamId}),v(null)):(st(null),v(null));return}if(wt==="door"||wt==="window"||wt==="opening"){if(!en)return;const Dt=qs[en],Xt=l4(q,r,en,d);if(!Xt){uo(null);return}if(Xt.corner){const xe=`opening_corner_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,[Ee,wn]=DF(Xt.corner,{groupId:xe,primaryId:`opening_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,returnId:`opening_${Date.now()}_${Math.random().toString(36).slice(2,8)}`});ct(Ee),ct(wn),Pr("itemPlace"),st({kind:"opening",id:Ee.id}),v(null),uo(null),G==null||G("opening");return}const me=`opening_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;ct({id:me,type:Dt.category,preset:en,wallId:Xt.wallId,positionPx:Xt.positionPx,...Dt.hasSwing?rm({hingeSide:"left",swingFace:"front"}):{},...lE(en)}),Pr("itemPlace"),st({kind:"opening",id:me}),v(null),uo(null),G==null||G("opening");return}if(wt==="furniture"){const Dt=Rg(q,[],[],l,d);if(Dt&&Dt.kind==="furniture"){st({kind:"furniture",id:Dt.furnitureId}),v(null);return}xt({id:`furn_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,type:Ve,label:(bt=pi[Ve])==null?void 0:bt.label,position:q,rotation:0}),Pr("itemPlace"),G==null||G("edit");return}const Ct=(Dt,Xt)=>{if(!(Dt!=null&&Dt.onWall)||Dt.type!=="wall-body"&&Dt.type!=="ortho-h"&&Dt.type!=="ortho-v")return;
358const me=r.find(Ee=>Ee.id===Dt.onWall.wallId);if(!me)return;const xe=xK(me,Xt);xe&&(it==null||it(me.id,xe))};if(on){const Dt=(Wt==null?void 0:Wt.point)??q,Xt={x:Math.round(Dt.x),y:Math.round(Dt.y)},me=Dt.x-on.x,xe=Dt.y-on.y;Math.sqrt(me*me+xe*xe)>3&&(Y({id:`wall_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,start:on,end:Xt,wallType:is}),Pr("wallCommit"),Ct(Wt,Xt)),co&&(Wt==null?void 0:Wt.type)==="endpoint"&&Wt.snapTarget&&Math.abs(Wt.snapTarget.x-co.x)<2&&Math.abs(Wt.snapTarget.y-co.y)<2?(Qs(null),ze(null)):Qs(Xt),qe(null),to(null)}else{const Dt=Lc(q,null,r,Gt.zoom,void 0,is,{extraSnapWalls:Es}),Xt=Dt.point;Qs(Xt),ze(Xt),Pr("wallStart"),Ct(Dt,Xt),qe(null)}},[wt,Ve,on,In,fe,Wt,co,r,i,a,l,_,sn,Ot,Qn,dn,d,Gt.zoom,Se,je,ri,Mr,c,Es,Y,J,it,st,v,Mt,ct,xt,Zt,G,is,en,$o,si]),Ca=m.useCallback(et=>{Zt(et),As(!1),ve("trace"),G==null||G("trace")},[Zt,G]),eh=m.useCallback(()=>{As(!1),ve("edit"),G==null||G("edit")},[G]),ps=m.useCallback(et=>{if(et.preventDefault(),Qs(null),ze(null),to(null),qe(null),uo(null),wt==="roof"){vn((A==null?void 0:A.outer.map(bt=>({...bt})))??[]),so(((A==null?void 0:A.outer.length)??0)>=3),hs(null),Lr(null),S==null||S();return}if(wt==="beam"){Rn(null),Gs(null),ve("edit"),G==null||G("edit");return}if(wt==="door"||wt==="window"||wt==="opening"){Qo(null),Yo(null),Go(null),Vn(null),ve("edit"),G==null||G("edit");return}const q=si(et,"card");if(q&&Le.current){Qo(null),Yo(null),Go(null),Vn({roomId:q.roomId,x:et.clientX,y:et.clientY});return}if(Vn(null),wt==="measure2d"){Qo(null),Yo(null),Go(null),Te(null),ho(null);return}const Ct=ri(et);if(Ct&&Le.current){const bt=Rg(Ct,r,a,[],d);if((bt==null?void 0:bt.kind)==="opening"){st({kind:"opening",id:bt.openingId}),v(null),ve("edit"),G==null||G("edit"),Yo(null),Go(null),Qo({openingId:bt.openingId,x:et.clientX,y:et.clientY});return}}Qo(null),Yo(null),Go(null),wt==="edit"&&st(null)},[wt,A,r,a,d,ri,si,S,st,v,G]),Ro=wt==="edit"&&(u==null?void 0:u.kind)==="wall"?r.find(et=>et.id===u.id)??null:null,[gs,bo]=m.useState("");m.useEffect(()=>{!Ro||d<=0||bo(De(x4(Ro,d),tt))},[Ro,d,tt]);const bs=m.useCallback(()=>{if(!Ro)return;const et=E7(Ro),q=ni(gs,tt);!q||q<=0||et<1||Zt({scale:q/et,referenceSegment:{start:{x:Ro.start.x,y:Ro.start.y},end:{x:Ro.end.x,y:Ro.end.y},distanceMm:q}})},[Ro,gs,tt,Zt]),Kr=(()=>{if(wt!=="trace"||!on||d<=0)return null;const et=(Wt==null?void 0:Wt.point)??On;if(!et)return null;const q=Hx(on,et,d);return q<=0?null:gt(q)})(),xl=m.useCallback(et=>{oi.current=et,Ft(et)},[Ft]),pl=m.useCallback(et=>{if(et===null){st(null),Yo(null);return}const q=oi.current[et];q&&(st({kind:"opening",id:q.id}),Yo(Ct=>Ct&&{...Ct,openingId:q.id}))},[st]),Zi=m.useCallback((et,q)=>{et.button===0&&(et.preventDefault(),et.stopPropagation(),et.currentTarget.setPointerCapture(et.pointerId),Je.current={pointerId:et.pointerId,startClientX:et.clientX,startClientY:et.clientY,startLeft:q.left,startTop:q.top,panelWidth:q.panelWidth,panelHeight:q.panelHeight})},[]),Si=m.useCallback(et=>{const q=Je.current;if(!q||q.pointerId!==et.pointerId)return;const Ct=Au(q.startLeft+et.clientX-q.startClientX,q.startTop+et.clientY-q.startClientY,q.panelWidth,q.panelHeight);Yo(bt=>bt&&{...bt,x:Ct.left,y:Ct.top})},[]),Fs=m.useCallback(et=>{var q;((q=Je.current)==null?void 0:q.pointerId)===et.pointerId&&(Je.current=null)},[]),Pi=m.useCallback((et,q)=>{et.button===0&&(et.preventDefault(),et.stopPropagation(),et.currentTarget.setPointerCapture(et.pointerId),rn.current={pointerId:et.pointerId,startClientX:et.clientX,startClientY:et.clientY,startLeft:q.left,startTop:q.top,panelWidth:q.panelWidth,panelHeight:q.panelHeight})},[]),Na=m.useCallback(et=>{const q=rn.current;if(!q||q.pointerId!==et.pointerId)return;const Ct=Au(q.startLeft+et.clientX-q.startClientX,q.startTop+et.clientY-q.startClientY,q.panelWidth,q.panelHeight);Go(bt=>bt&&{...bt,x:Ct.left,y:Ct.top})},[]),Wr=m.useCallback(et=>{var q;((q=rn.current)==null?void 0:q.pointerId)===et.pointerId&&(rn.current=null)},[]),Rr=(()=>{var bt;if(!Hn)return null;const et=((bt=Pt.current)==null?void 0:bt.clientWidth)??0,q=Math.min(Math.max(Hn.width+28,220),280);return{left:et>0?Math.max(12,Math.min(Hn.x-14,et-q-12)):Math.max(12,Hn.x-14),top:Math.max(12,Hn.y-7),width:q}})(),ma=m.useCallback(()=>
358{if(!U.current)return;const et=U.current.clientWidth,q=U.current.clientHeight;Kn(Ct=>_2(Ct,Kv,et/2,q/2))},[Kn]),gn=m.useCallback(()=>{if(!U.current)return;const et=U.current.clientWidth,q=U.current.clientHeight;Kn(Ct=>_2(Ct,-Kv,et/2,q/2))},[Kn]),Zo=m.useCallback((et,q)=>{Kn(Ct=>bg(Ct,et,q))},[Kn]);return m.useImperativeHandle(At,()=>({zoomIn:ma,zoomOut:gn,panBy:Zo,beginTraceRoomLabelEdit:et=>{Ko(et,{left:64,top:64,right:284,bottom:98})},clientToImagePoint:(et,q)=>Mr({clientX:et,clientY:q}),imagePointToClient:Qc}),[ma,gn,Zo,Ko,Mr,Qc]),m.useCallback(()=>{if(!Pe||!U.current)return;const et=c.planRotationDeg??0,{effW:q,effH:Ct}=qv(Pe.w,Pe.h,et);Co(Qv(q,Ct,U.current.clientWidth,U.current.clientHeight))},[Pe,c.planRotationDeg]),n.jsxs("div",{ref:U,className:"flex flex-col h-full overflow-hidden relative",style:{background:"#e8ecef"},children:[n.jsx("canvas",{ref:Pt,"data-floorplan-mode":wt,"data-floorplan-background-state":e?s?mt.current?"visible":"loading":"hidden":"missing",className:`flex-1 ${wt==="pan"?"":wt==="trace"?"cursor-none":"cursor-crosshair"}`,onClick:es,onDoubleClick:ae,onMouseDown:Ds,onMouseMove:nr,onMouseUp:zs,onMouseLeave:()=>{var et;wt==="trace"&&to(null),wt==="roof"&&(Lr(null),qe(null)),(wt==="door"||wt==="window"||wt==="opening")&&uo(null),((et=Nt.current)==null?void 0:et.kind)==="camera-marker"&&(Nt.current=null,Dn(null))},onContextMenu:ps}),wt==="roof"?n.jsxs("div",{"data-testid":"roof-trace-guide",dir:Et,role:"status",className:"absolute left-1/2 top-3 z-30 flex min-h-12 -translate-x-1/2 items-center gap-3 rounded-xl border border-[#D85D43]/35 bg-[#F7F4EF]/95 px-3 py-2 font-heebo text-[#182137] shadow-[0_10px_28px_rgba(24,33,55,0.16)] backdrop-blur-md",children:[n.jsx("span",{className:"grid h-8 w-8 shrink-0 place-items-center rounded-lg bg-[#D85D43] text-[13px] font-black text-[#F7F4EF] shadow-[0_3px_0_#A9422F]",children:Ot?"✓":Math.min(sn.length+1,9)}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"whitespace-nowrap text-[12px] font-black",children:Ot?"עריכת גבול הגג":"סימון גבול הגג"}),n.jsx("div",{className:"whitespace-nowrap text-[10px] text-[#182137]/58",children:Ot?"גרור נקודה · לחץ על צלע להוספה · Delete למחיקה":"לחץ לאורך ההיקף · סגור בנקודה הראשונה או Enter"})]}),n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("button",{type:"button",onClick:()=>{!Ot&&!dn(bi.current)||B==null||B()},disabled:!Ot&&!D4(sn),className:"min-h-11 rounded-lg bg-[#D85D43] px-3 text-[11px] font-black text-[#F7F4EF] shadow-[0_3px_0_#A9422F] transition-transform hover:-translate-y-0.5 active:translate-y-0.5 active:shadow-none disabled:cursor-not-allowed disabled:opacity-35 motion-reduce:transition-none",children:"סיום"}),n.jsx("button",{type:"button",onClick:S,className:"min-h-11 rounded-lg border border-[#182137]/12 bg-[#E8E3DB] px-3 text-[11px] font-bold text-[#182137] shadow-[0_2px_0_rgba(24,33,55,0.15)] transition-transform hover:-translate-y-0.5 active:translate-y-0.5 active:shadow-none motion-reduce:transition-none",children:"ביטול"})]})]}):null,wt==="beam"?n.jsxs("div",{"data-testid":"beam-placement-guide",dir:Et,role:"status",className:"absolute left-1/2 top-3 z-30 flex min-h-11 -translate-x-1/2 items-center gap-2 rounded-xl border border-[#D85D43]/35 bg-[#F7F4EF]/95 px-3 py-2 font-heebo text-[#182137] shadow-[0_10px_28px_rgba(24,33,55,0.16)] backdrop-blur-md",children:[n.jsx("span",{className:"flex h-6 min-w-6 items-center justify-center rounded-full bg-[#D85D43] px-1.5 text-[11px] font-black text-white",children:In?"2":"1"}),n.jsx("span",{className:"whitespace-nowrap text-[12px] font-black",children:In?ut("beams.endPointPrompt",{defaultValue:"לחצו על נקודת הסיום של הקורה"}):ut("beams.startPointPrompt",{defaultValue:"לחצו על נקודת ההתחלה של הקורה"})}),n.jsx("button",{type:"button",onClick:()=>{Rn(null),Gs(null),qe(null),ve("edit"),G==null||G("edit")},className:"ms-1 flex min-h-8 items-center rounded-lg border border-[#182137]/12 bg-white/80 px-2 text-[10px] font-bold text-[#182137]/65 transition-colors hover:bg-white hover:text-[#182137]",children:ut("beams.cancelPlacement",{defaultValue:"ביטול · Esc"})})]}):null,P&&N&&N.length>0?n.jsxs("div",{dir:"rtl",role:"status",className:"pointer-events-none absolute left-1/2 top-3 z-20 flex -translate-x-1/2 items-center gap-2 rounded-xl border border-[#D85D43]/35 bg-[#F7F4EF]/95 px-3 py-2 font-heebo text-[12px] font-bold text-[#182137] shadow-[0_8px_22px_rgba(24,33,55,0.14)] backdrop-blur-sm",children:[n.jsx("span",{"aria-hidden":"true",className:"block w-6 border-t-2 border-dashed border-[#D85D43]"}),n.jsx("span",{children:"קומת ייחוס — אינה ניתנת לעריכה"})]}):null,Hn&&Rr?n.jsx("form",{dir:Et,className:"pointer-events-auto absolute z-[57] rounded-xl border border-[#D85D43]/30 bg-[#F7F4EF]/98 p-2 font-heebo shadow-[0_16px_42px_rgba(24,33,55,0.2)] backdrop-blur-xl",style:Rr,onSubmit:et=>{et.preventDefault(),Za()},onMouseDown:et=>et.stopPropagation(),onContextMenu:et=>et.preventDefault(),children:n.jsx("input",{autoFocus:!0,dir:Et,value:Hn.value,placeholder:ut("roomLabels.namePlaceholder",{defaultValue:x1}),onFocus:et=>et.currentTarget.select(),onChange:et=>{const q=et.target.value;ur(Ct=>Ct&&{...Ct,value:q})},onBlur:()=>{if(pe.current){pe.current=!1;return}Za()},onKeyDown:et=>{et.key==="Escape"&&(et.preventDefault(),pe.current=!0,ur(null))},className:"h-9 w-full rounded-lg border border-[#182137]/12 bg-[#FDFBF8] px-2 text-start text-[13px] font-bold text-[#182137] outline-none transition focus:border-[#D85D43]/60 focus:ring-2 focus:ring-[#D85D43]/20"})}):null,da&&n.jsx(MK,{view:Gt,walls:r,containerRect:ua,imageNaturalSize:Pe,planRotationDeg:bn,measurementUnit:tt,onConfirm:Ca,onCancel:eh}),er?(()=>{const et=Au(er.x,er.y,aZ,lZ),q=()=>{Fa(),Vn(null),Uo(!0)};return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fixed inset-0 z-[55]",onClick:()=>Vn(null),onContextMenu:Ct=>{Ct.preventDefault(),Vn(null)}}),n.jsxs("div",{dir:Et,className:"fixed z-[56] w-[176px] overflow-hidden rounded-xl border border-[#182137]/10 bg-[#F7F4EF]/95 py-1 font-heebo text-[#182137] shadow-[0_12px_32px_rgba(24,33,55,0.18)] backdrop-blur-xl",style:{left:et.left,top:et.top},onClick:Ct=>Ct.stopPropagation(),onContextMenu:Ct=>Ct.preventDefault(),children:[n.jsxs("button",{type:"button",onClick:q,className:"flex w-full cursor-pointer items-center gap-2 px-3 py-2 text-start text-[12px] font-bold transition-colors hover:bg-[#
358E8E3DB]/80 active:bg-[#E0DFD8]",children:[n.jsx(fc,{size:14,strokeWidth:2.2,className:"shrink-0 text-[#D85D43]"}),n.jsx("span",{children:ut("trace.hideDimensions",{defaultValue:"הסתר מידות"})})]}),n.jsx("button",{type:"button",onClick:()=>Vn(null),className:"flex w-full cursor-pointer items-center px-3 py-2 text-start text-[12px] font-semibold text-[#182137]/58 transition-colors hover:bg-[#E8E3DB]/65",children:ut("common.cancel",{defaultValue:"ביטול"})})]})]})})():null,ls?(()=>{const et=a.find(He=>He.id===ls.openingId),q=et?hm(et):!1,Ct=et?Lf(et):!1,bt=q||Ct,Xt=(et==null?void 0:et.type)==="window"?ut("viewer.opening.windowDirection",{defaultValue:"כיוון פתיחת חלון"}):ut("viewer.opening.doorDirection",{defaultValue:"כיוון פתיחת דלת"}),me=iZ+(bt?36:0)+(Ct&&!q?36:0),xe=Au(ls.x,ls.y,rZ,me),Ee=()=>{const He=N4({imgSize:Pe,view:Gt,planRotationDeg:bn,container:U.current}),cn=I4(ls.x,ls.y,He,Q2,ty);Yo({openingId:ls.openingId,x:cn.left,y:cn.top}),Go(null),Qo(null)},wn=()=>{const He=N4({imgSize:Pe,view:Gt,planRotationDeg:bn,container:U.current}),cn=I4(ls.x,ls.y,He,ey,Bg);Go({openingId:ls.openingId,x:cn.left,y:cn.top}),Yo(null),Qo(null)},lt=()=>{const He=Z1(oi.current,ls.openingId,r,d);if(!He)return;oi.current=He.next,Ft(He.next);const cn=He.next[He.newIdx];cn&&(st({kind:"opening",id:cn.id}),v(null),ve("edit"),G==null||G("edit")),Yo(null),Go(null),Qo(null)};return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fixed inset-0 z-[55]",onClick:()=>Qo(null),onContextMenu:He=>{He.preventDefault(),Qo(null)}}),n.jsxs("div",{dir:Et,className:"fixed z-[56] w-[188px] overflow-hidden rounded-xl border border-[#182137]/10 bg-[#F7F4EF]/95 py-1 font-heebo text-[#182137] shadow-[0_12px_32px_rgba(24,33,55,0.18)] backdrop-blur-xl",style:{left:xe.left,top:xe.top},onClick:He=>He.stopPropagation(),onContextMenu:He=>He.preventDefault(),children:[n.jsxs("button",{type:"button",onClick:Ee,className:"flex w-full cursor-pointer items-center gap-2 px-3 py-2 text-start text-[12px] font-bold transition-colors hover:bg-[#E8E3DB]/80 active:bg-[#E0DFD8]",children:[n.jsx(RI,{size:14,strokeWidth:2.2,className:"shrink-0 text-[#D85D43]"}),n.jsx("span",{children:ut("viewer.opening.resize",{defaultValue:"שנה גודל פתח"})})]}),q&&n.jsxs("button",{type:"button",onClick:wn,className:"flex w-full cursor-pointer items-center gap-2 px-3 py-2 text-start text-[12px] font-bold transition-colors hover:bg-[#E8E3DB]/80 active:bg-[#E0DFD8]",children:[n.jsx(N1,{size:14,strokeWidth:2.2,className:"shrink-0 text-[#D85D43]"}),n.jsx("span",{children:Xt})]}),Ct&&!q&&n.jsxs("button",{type:"button",onClick:wn,className:"flex w-full cursor-pointer items-center gap-2 px-3 py-2 text-start text-[12px] font-bold transition-colors hover:bg-[#E8E3DB]/80 active:bg-[#E0DFD8]",children:[n.jsx(N1,{size:14,strokeWidth:2.2,className:"shrink-0 text-[#D85D43]"}),n.jsx("span",{children:ut("viewer.opening.zeroLineSide",{defaultValue:"צד קו 0"})})]}),n.jsxs("button",{type:"button",onClick:lt,className:"flex w-full cursor-pointer items-center gap-2 px-3 py-2 text-start text-[12px] font-bold transition-colors hover:bg-[#E8E3DB]/80 active:bg-[#E0DFD8]",children:[n.jsx(Pf,{size:14,strokeWidth:2.2,className:"shrink-0 text-[#D85D43]"}),n.jsx("span",{children:ut("common.duplicate",{defaultValue:"שכפל"})})]}),n.jsx("button",{type:"button",onClick:()=>Qo(null),className:"flex w-full cursor-pointer items-center px-3 py-2 text-start text-[12px] font-semibold text-[#182137]/58 transition-colors hover:bg-[#E8E3DB]/65",children:ut("common.cancel",{defaultValue:"ביטול"})})]})]})})():null,ms?(()=>{const et=a.findIndex(bt=>bt.id===ms.openingId);if(et<0)return null;const q=Au(ms.x,ms.y,Q2,ty),Ct=()=>Yo(null);return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fixed inset-0 z-[55]",onClick:Ct,onContextMenu:bt=>{bt.preventDefault(),Ct()}}),n.jsxs("div",{dir:Et,className:"fixed z-[56] flex max-h-[280px] w-[292px] flex-col overflow-hidden rounded-2xl border border-[#D85D43]/25 bg-[#F7F4EF]/95 font-heebo text-[#182137] shadow-[0_18px_48px_rgba(24,33,55,0.22),0_0_0_1px_rgba(255,255,255,0.65)] backdrop-blur-xl",style:{left:q.left,top:q.top},onClick:bt=>bt.stopPropagation(),onContextMenu:bt=>bt.preventDefault(),children:[n.jsxs("div",{className:"flex shrink-0 cursor-move select-none items-center justify-between gap-3 border-b border-[#182137]/10 px-3 py-2.5",title:ut("trace.dragToMove",{defaultValue:"גרור להזזה"}),onPointerDown:bt=>
358Zi(bt,{left:q.left,top:q.top,panelWidth:Q2,panelHeight:ty}),onPointerMove:Si,onPointerUp:Fs,onPointerCancel:Fs,children:[n.jsx("button",{type:"button",onPointerDown:bt=>bt.stopPropagation(),onClick:Ct,className:"flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center rounded-lg text-[#182137]/48 transition-colors hover:bg-[#182137]/[0.06] hover:text-[#182137]",title:ut("common.close",{defaultValue:"סגור"}),"aria-label":ut("common.close",{defaultValue:"סגור"}),children:n.jsx(Gr,{size:15,strokeWidth:2.2})}),n.jsxs("div",{className:"min-w-0 text-start",children:[n.jsx("div",{className:"truncate text-[12px] font-black text-[#182137]",children:ut("viewer.opening.resize",{defaultValue:"שנה גודל פתח"})}),n.jsx("div",{className:"truncate text-[10px] font-semibold text-[#182137]/52",children:ut("trace.liveUpdate",{defaultValue:"עדכון חי בדו-מימד ובתלת-מימד"})})]})]}),n.jsx("div",{className:"flex-1 overflow-y-auto px-3 py-3",children:n.jsx(j7,{openings:a,selectedOpeningIdx:et,onOpeningsChange:xl,onSelectedOpeningChange:pl,effectiveScale:d,walls:r,fpIsDark:!1,measurementUnit:tt,hideDirectionAndFlushFace:!0})})]})]})})():null,Qe?(()=>{const et=a.findIndex(Ee=>Ee.id===Qe.openingId);if(et<0)return null;const q=a[et],Ct=q.type==="window",bt=hm(q),Dt=Lf(q),Xt=Au(Qe.x,Qe.y,ey,Bg),me=()=>Go(null),xe=Ee=>{const wn=a.map((lt,He)=>He===et?{...lt,...Ee}:lt);oi.current=wn,Ft(wn)};return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"fixed inset-0 z-[55]",onClick:me,onContextMenu:Ee=>{Ee.preventDefault(),me()}}),n.jsxs("div",{dir:Et,className:"fixed z-[56] flex w-[340px] flex-col overflow-hidden rounded-2xl border border-black/10 bg-white font-heebo text-[#18181b] shadow-[0_12px_36px_-6px_rgba(0,0,0,0.28)]",style:{left:Xt.left,top:Xt.top,height:Bg},onClick:Ee=>Ee.stopPropagation(),onContextMenu:Ee=>Ee.preventDefault(),children:[n.jsxs("div",{className:"flex shrink-0 cursor-move select-none items-center justify-between gap-3 border-b border-black/[0.06] px-3 py-2.5",title:ut("trace.dragToMove",{defaultValue:"גרור להזזה"}),onPointerDown:Ee=>Pi(Ee,{left:Xt.left,top:Xt.top,panelWidth:ey,panelHeight:Bg}),onPointerMove:Na,onPointerUp:Wr,onPointerCancel:Wr,children:[n.jsx("button",{type:"button",onPointerDown:Ee=>Ee.stopPropagation(),onClick:me,className:"flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center rounded-lg text-[#71717a] transition-colors hover:bg-black/5 hover:text-[#18181b]",title:ut("common.close",{defaultValue:"סגור"}),"aria-label":ut("common.close",{defaultValue:"סגור"}),children:n.jsx(Gr,{size:15,strokeWidth:2.2})}),n.jsxs("div",{className:"min-w-0 text-start",children:[n.jsx("div",{className:"truncate text-[12px] font-semibold text-[#18181b]",children:Ct?ut("viewer.opening.windowDirection",{defaultValue:"כיוון פתיחת חלון"}):ut("viewer.opening.doorDirection",{defaultValue:"כיוון פתיחת דלת"})}),n.jsx("div",{className:"truncate text-[10px] text-[#71717a]",children:Ct?ut("viewer.opening.windowDirectionHint",{defaultValue:"בחר ציר ואת הצד שאליו החלון נפתח"}):ut("viewer.opening.doorDirectionHint",{defaultValue:"בחר ציר ואת הצד שאליו הדלת נפתחת"})})]})]}),n.jsx("div",{className:"flex-1 px-3 py-3",children:n.jsxs("div",{className:"space-y-3",children:[bt&&n.jsx($3,{value:Wd(q),onChange:Ee=>xe(rm(Ee)),fpIsDark:!1}),Dt&&n.jsxs("div",{className:"rounded-2xl border border-[#182137]/10 bg-white/70 p-2.5",children:[n.jsx("div",{className:"mb-2 text-[10px] font-bold text-[#5a5065]",children:ut("viewer.opening.zeroLineSide",{defaultValue:"צד קו 0"})}),n.jsx(X3,{value:xb(q),onChange:Ee=>xe(Gw(Ee)),fpIsDark:!1})]})]})})]})]})})():null,Kr?n.jsx("div",{dir:Et,className:"pointer-events-none absolute bottom-12 left-1/2 z-20 -translate-x-1/2 rounded-lg border border-[#182137]/10 bg-[#182137] px-3 py-1.5 text-center text-sm font-bold text-white shadow-md tabular-nums",children:ut("trace.currentLength",{defaultValue:"אורך נוכחי: {{length}}",length:Kr})}):null,Ro?n.jsxs("div",{dir:Et,className:"pointer-events-auto absolute bottom-12 left-1/2 z-20 flex -translate-x-1/2 flex-row-reverse items-center gap-2 rounded-lg border border-[#182137]/10 bg-white/95 px-3 py-1.5 shadow-md backdrop-blur-sm",children:[n.jsx("button",{type:"button",onClick:bs,className:"rounded-md bg-gradient-to-l from-[#EC7357] to-[#B33D24] px-2.5 py-1 text-[11px] font-bold text-white shadow-sm hover:opacity-90",children:ut("trace.calibrateByWall",{defaultValue:"קבע כיול לפי הקיר"})}),n.jsx("input",{type:"text",inputMode:"decimal",value:gs,onChange:et=>bo(et.target.value),onKeyDown:et=>{et.key==="Enter"&&bs()}
358,className:"w-16 rounded-md border border-[#EC7357]/50 bg-white px-1.5 py-1 text-center text-sm font-bold text-[#182137] tabular-nums focus:border-[#D84B2E] focus:outline-none focus:ring-2 focus:ring-[#EC7357]/35"}),n.jsx("span",{className:"text-[11px] font-semibold text-[#182137]",children:ut("trace.realWallLength",{defaultValue:"אורך אמיתי של הקיר ({{unit}}):",unit:ht})})]}):null]})});function Au(t,e,s,o){const r=typeof window>"u"?s+24:window.innerWidth,i=typeof window>"u"?o+24:window.innerHeight;return{left:Math.max(12,Math.min(t,r-s-12)),top:Math.max(12,Math.min(e,i-o-12))}}function C4(t){return Number.isFinite(t)?t.toFixed(2).replace(/\.?0+$/,""):"0"}function N4({imgSize:t,view:e,planRotationDeg:s,container:o}){if(!t)return null;const r=o==null?void 0:o.getBoundingClientRect(),i=(r==null?void 0:r.left)??0,a=(r==null?void 0:r.top)??0,l=[$a(0,0,e,t.w,t.h,s),$a(t.w,0,e,t.w,t.h,s),$a(0,t.h,e,t.w,t.h,s),$a(t.w,t.h,e,t.w,t.h,s)],c=l.map(p=>p.sx+i),d=l.map(p=>p.sy+a),u=Math.min(...c),h=Math.max(...c),x=Math.min(...d),f=Math.max(...d);return{left:u,right:h,top:x,bottom:f,width:h-u,height:f-x}}function I4(t,e,s,o,r){if(!s)return Au(t+14,e-18,o,r);const i=typeof window>"u"?o+24:window.innerWidth,a=typeof window>"u"?r+24:window.innerHeight,l=12,c=24,d=Math.max(0,s.left-l),u=Math.max(0,i-s.right-l),h=s.left-o-c,x=s.right+c,f=h>=l,p=x+o<=i-l;let b;f&&p?b=u>d?x:h:f?b=h:p?b=x:b=u>d?x:h;const M=Math.min(Math.max(l,e-r/2),Math.max(l,a-r-l));return Au(b,M,o,r)}function bZ(t,e,s,o,r,i,a,l,c,d,u,h){if(e.vertices.length<3)return;t.save(),t.beginPath(),T4(t,e.vertices);for(const f of e.holes)T4(t,f);const x=Math.min(e.depth*.025,.08);if(t.fillStyle=`rgba(51, 108, 255, ${.12+x})`,t.fill("evenodd"),t.strokeStyle="rgba(51, 108, 255, 0.62)",t.lineWidth=1.4/o,t.stroke(),t.restore(),!s.hidden){const f=MZ(t,e,s,r,i,a,l,c,u,h);f&&d.push(f)}}function T4(t,e){if(!(e.length<3)){t.moveTo(e[0].x,e[0].y);for(let s=1;s<e.length;s++)t.lineTo(e[s].x,e[s].y);t.closePath()}}function MZ(t,e,s,o,r,i,a,l,c,d){var z,X;const u=$a(e.labelPoint.x,e.labelPoint.y,o,r.w,r.h,i),h=((z=s.name)==null?void 0:z.trim())||c,x=11,f=15,p=10,b=7,M=8,g=4,w=Math.min(220,Math.max(100,l.w-24));t.save(),t.setTransform(a,0,0,a,0,0),t.direction=d,t.font=`800 ${x}px Heebo, system-ui, sans-serif`;const k=H7(t,h,w-p*2),_=t.measureText(k).width;t.font=`900 ${f}px Heebo, system-ui, sans-serif`;const j=t.measureText(e.areaLabel).width,v=Math.ceil(Math.min(w,Math.max(124,Math.max(_,j)+p*2))),C=x+2,N=f+2,P=Math.ceil(b+C+g+N+M),L=Math.min(l.w-v/2-8,Math.max(v/2+8,u.sx)),A=Math.min(l.h-P/2-8,Math.max(P/2+8,u.sy)),W=L-v/2,S=A-P/2;t.shadowColor="rgba(24, 33, 55, 0.14)",t.shadowBlur=9,t.shadowOffsetY=2,t.fillStyle="rgba(247, 244, 239, 0.97)",t.strokeStyle="rgba(216, 93, 67, 0.46)",t.lineWidth=1,t.beginPath(),t.roundRect(W,S,v,P,8),t.fill(),t.shadowColor="transparent",t.stroke(),t.fillStyle="rgba(232, 227, 219, 0.86)",t.beginPath(),t.roundRect(W+6,S+b+C+2,v-12,N+5,6),t.fill(),t.textAlign="center",t.textBaseline="middle",t.font=`800 ${x}px Heebo, system-ui, sans-serif`,t.fillStyle=(X=s.name)!=null&&X.trim()?"#182137":"rgba(24, 33, 55, 0.56)";const B=S+b+C/2;t.fillText(k,L,B),t.font=`900 ${f}px Heebo, system-ui, sans-serif`,t.fillStyle="#182137";const R=S+b+C+g+N/2+3;return t.fillText(e.areaLabel,L,R),t.restore(),{roomId:e.id,rect:{left:W,top:S,right:W+v,bottom:S+P},nameRect:{left:W+6,top:S+4,right:W+v-6,bottom:S+b+C+g}}}function yZ(t,e,s,o,r){const i=vK(e),a=Math.max(9/s,Math.min(12/s,11/s));t.save(),t.fillStyle=r,t.font=`600 ${a}px system-ui`,t.textAlign="center",t.textBaseline="middle",t.fillText(o,i.x,i.y),t.restore()}function S4(t,e,s,o,r,i,a,l,c,d,u,h){t.save(),t.setLineDash(i?[10/o,6/o]:[8/o,5/o]),t.strokeStyle=i?"rgba(24, 33, 55, 0.4)":"rgba(24, 33, 55, 0.62)",t.lineWidth=(i?1:1.2)/o,t.beginPath(),t.moveTo(e.x,e.y),t.lineTo(s.x,s.y),t.stroke(),t.setLineDash([]);for(const x of[e,s])t.fillStyle="rgba(247,244,239,0.92)",t.strokeStyle=i?"rgba(51,108,255,0.62)":"rgba(24,33,55,0.58)",t.lineWidth=1/o,t.beginPath(),t.arc(x.x,x.y,3.5/o,0,Math.PI*2),t.fill(),t.stroke();t.restore(),l&&xw(t,e,s,r,a,l,c,d,u,i?"measure-preview":"measure",h)}function xw(t,e,s,o,r,i,a,l,c,d,u){const h=$a(e.x,e.y,r,i.w,i.h,a),x=$a(s.x,s.y,r,i.w,i.h,a),f=d==="trace",p=d==="measure-preview",b=f?12:10.5,M=f?8.5:6.5,g=f?3:2.75;t.save(),t.setTransform(l,0,0,l,0,0),t.font=`${f?800:700} ${b}px Heebo, system-ui, sans-serif`;const w=t.measureText(o).width,k=Math.ceil(w+M*2),_=f?24:Math.ceil(b+g*2),j=CK({x:
358h.sx,y:h.sy},{x:x.sx,y:x.sy},{offsetPx:f?40:26,extensionGapPx:f?13:10,extensionOverrunPx:f?6:5,labelWidthPx:k,labelHeightPx:_,canvasWidthPx:c.w,canvasHeightPx:c.h,minGuideSegmentPx:f?24:18,minLabelSegmentPx:f?38:30});if(!j){t.restore();return}if(j.showGuide&&(t.lineCap="butt",t.lineJoin="miter",t.strokeStyle=f?"rgba(24, 33, 55, 0.34)":p?"rgba(51, 108, 255, 0.28)":"rgba(24, 33, 55, 0.3)",t.lineWidth=1,t.beginPath(),t.moveTo(j.guideStart.x,j.guideStart.y),t.lineTo(j.guideEnd.x,j.guideEnd.y),t.stroke(),t.beginPath(),t.moveTo(j.startExtensionA.x,j.startExtensionA.y),t.lineTo(j.startExtensionB.x,j.startExtensionB.y),t.moveTo(j.endExtensionA.x,j.endExtensionA.y),t.lineTo(j.endExtensionB.x,j.endExtensionB.y),t.stroke()),j.showLabel){const v=j.labelCenter.x-k/2,C=j.labelCenter.y-_/2;t.shadowColor=f?"rgba(24, 33, 55, 0.16)":"rgba(24, 33, 55, 0.12)",t.shadowBlur=f?5:4,t.shadowOffsetY=f?1.5:1,t.fillStyle=f?"rgba(247, 244, 239, 0.98)":"rgba(247, 244, 239, 0.96)",t.strokeStyle=f?"rgba(24, 33, 55, 0.22)":"rgba(51, 108, 255, 0.55)",t.lineWidth=f?1.15:1.25,t.beginPath(),t.roundRect(v,C,k,_,f?6:5),t.fill(),t.shadowColor="transparent",t.stroke(),t.fillStyle="#182137",t.textAlign="center",t.textBaseline="middle",t.direction=u,t.fillText(o,j.labelCenter.x,j.labelCenter.y+.5)}t.restore()}function P4(t,e,s,o,r,i,a,l,c,d,u){const h=AK(e,s,o);if(!h)return;const x=h.kind==="horizontal"?d.horizontal:h.kind==="perpendicular"?d.perpendicular:h.label;t.save(),t.setTransform(l,0,0,l,0,0),t.font="800 12px Heebo, system-ui, sans-serif";const f=t.measureText(x).width,p=Math.ceil(f+17),b=24,M=LK(e,s,{view:r,imgSize:i,planRotationDeg:a,canvasSize:c,labelWidthPx:p,labelHeightPx:b});if(!M){t.restore();return}const g=_=>{const j=M.radiusPx-5,v=M.radiusPx+5;t.moveTo(M.center.x+Math.cos(_)*j,M.center.y+Math.sin(_)*j),t.lineTo(M.center.x+Math.cos(_)*v,M.center.y+Math.sin(_)*v)};t.lineCap="round",t.strokeStyle=h.kind==="free"?"rgba(24, 33, 55, 0.5)":"rgba(216, 93, 67, 0.58)",t.lineWidth=1.2,t.beginPath(),t.arc(M.center.x,M.center.y,M.radiusPx,M.startAngleRad,M.endAngleRad,M.counterclockwise),t.stroke(),t.beginPath(),g(M.startAngleRad),g(M.endAngleRad),t.stroke();const w=M.labelCenter.x-p/2,k=M.labelCenter.y-b/2;t.shadowColor="rgba(24, 33, 55, 0.16)",t.shadowBlur=5,t.shadowOffsetY=1.5,t.fillStyle="rgba(247, 244, 239, 0.98)",t.strokeStyle=h.kind==="free"?"rgba(24, 33, 55, 0.22)":"rgba(216, 93, 67, 0.52)",t.lineWidth=1.15,t.beginPath(),t.roundRect(w,k,p,b,6),t.fill(),t.shadowColor="transparent",t.stroke(),t.fillStyle="#182137",t.textAlign="center",t.textBaseline="middle",t.direction=u,t.fillText(x,M.labelCenter.x,M.labelCenter.y+.5),t.restore()}function A4(t,e,s,o){const r=uZ/o,i=Math.max(o,1e-4),a=16/i,l=2/i;t.save(),t.lineCap="butt",t.fillStyle="rgba(255, 215, 64, 0.32)",t.beginPath(),t.arc(e,s,a,0,Math.PI*2),t.fill(),t.strokeStyle="rgba(216, 161, 0, 0.42)",t.lineWidth=1.25/i,t.stroke(),t.strokeStyle="rgba(24, 33, 55, 0.88)",t.lineWidth=2/i,t.beginPath(),t.moveTo(e-r,s),t.lineTo(e+r,s),t.moveTo(e,s-r),t.lineTo(e,s+r),t.stroke(),t.fillStyle="#182137",t.beginPath(),t.arc(e,s,l,0,Math.PI*2),t.fill(),t.restore()}const wZ="#22c55e",oy="#6366f1";function sy(t,e,s,o,r){const i=Math.max(r,1e-4),a=l=>l/i;if(t.save(),t.lineJoin="round",t.lineCap="round",t.strokeStyle="#ffffff",e==="endpoint"){const l=a(11);t.fillStyle=wZ,t.lineWidth=a(1.5),t.beginPath(),t.rect(s-l/2,o-l/2,l,l),t.fill(),t.stroke()}else if(e==="wall-body"){const l=a(6.5);t.fillStyle=oy,t.lineWidth=a(1.5),t.beginPath(),t.arc(s,o,l,0,Math.PI*2),t.fill(),t.stroke()}else if(e==="midpoint"){const l=a(8);t.fillStyle=oy,t.lineWidth=a(1.5),t.beginPath(),t.moveTo(s,o-l),t.lineTo(s-l,o+l),t.lineTo(s+l,o+l),t.closePath(),t.fill(),t.stroke()}else{const l=a(7);t.strokeStyle=oy,t.lineWidth=a(2.4),t.beginPath(),t.moveTo(s-l,o-l),t.lineTo(s+l,o+l),t.moveTo(s+l,o-l),t.lineTo(s-l,o+l),t.stroke()}t.restore()}function O7(t,e,s,o,r){const i=r==="placement"?4/o:r==="selected"?3/o:2/o,a=-e-i,l=-s-i,c=(e+i)*2,d=(s+i)*2;r==="placement"?(t.save(),t.shadowColor=xZ,t.shadowBlur=10/o,t.fillStyle=mZ,t.fillRect(a,l,c,d),t.restore(),t.strokeStyle=p1,t.lineWidth=3.2/o,t.strokeRect(a,l,c,d),t.strokeStyle="rgba(24, 33, 55, 0.42)",t.lineWidth=1.1/o,t.setLineDash([5/o,4/o]),t.strokeRect(a-1.5/o,l-1.5/o,c+3/o,d+3/o),t.setLineDash([])):(t.fillStyle=r==="selected"?"rgba(255, 159, 67, 0.34)":fZ,t.fillRect(a,l,c,d),t.strokeStyle=r==="selected"?fw:p1,t.lineWidth=(r==="selected"?2.8:2.2)/o,t.strokeRect(a,l,c,d));const u=(r==="placement"?7:5)/o;t.strokeStyle=r==="selected"?fw:p1,t.lineWidth=(r==="placement"?2.4:2)/o,t.beginPath(),t.moveTo(-e,-s-u),t.lineTo(-e,s+u),t.moveTo(e,-s-u),t.lineTo(e,s+u),t.stroke()}function kZ(t,e,s,o,r,i,a,l){const c=e.preset?qs[e.preset]:null,d=e.widthMm||(c==null?void 0:c.width)||Kc[e.type].width,u=(c==null?void 0:c.symbol)||(e.type==="door"?"arc":"line");e.type;const h=d/o/2,x=Wd(e),f=x.swingFace==="back"?"right":"left",p=x.hingeSide,b=s.end.x-s.start.x,M=s.end.y-s.start.y,g=Math.sqrt(b*b+M*M);if(g===0)return;const w=b/g,k=M/g,_=s.start.x+w*e.positionPx,j=s.start.y+k*e.positionPx,v=Math.atan2(k,w),C=s.wallType||"exterior",N=(a==null?void 0:a[C])??br[C],P=(s.thicknessMm??N.thicknessMm)/o/2,L=(i?2.4:2.1)/r;if(t.save(),t.translate(_,j),t.rotate(v),t.fillStyle="#f7f4ef",t.fillRect(-h,-P-1/r,h*2,P*2+2/r),O7(t,h,P,r,i?"selected":"idle"),i){const W=5/r;t.fillStyle=fw,t.fillRect(-h-W,-W,W*2,W*2),t.fillRect(h-W,-W,W*2,W*2),t.fillStyle="#ffffff",t.fillRect(-h-W+1.5/r,-W+1.5/r,W*2-3/r,W*2-3/r),t.fillRect(h-W+1.5/r,-W+1.5/r,W*2-3/r,W*2-3/r)}const A=f==="right"?-1:1;if(u==="arc"){t.strokeStyle=i?"#7a3b12":"#8B4513",t.lineWidth=L;const W=p==="right"?h:-h,S=-W;t.beginPath(),t.moveTo(W,0),t.lineTo(S,0),t.stroke(),t.beginPath(),p==="right"?t.arc(W,0,h*2,Math.PI,Math.PI-Math.PI/2*A,A>0):t.arc(W,0,h*2,0,Math.PI/2*A,A<0),t.stroke()}else if(u==="double_arc")t.strokeStyle=i?"#7a3b12":"#8B4513",t.lineWidth=L,t.beginPath(),t.moveTo(-h,0),t.lineTo(0,0),t.stroke(),t.beginPath(),t.arc(-h,0,h,0,Math.PI/2*A,A<0),t.stroke(),t.beginPath(),t.moveTo(h,0),t.lineTo(0,0),t.stroke(),t.beginPath(),t.arc(h,0,h,Math.PI,Math.PI-Math.PI/2*A,A>0),t.stroke();else if(u==="slide")t.strokeStyle=i?"#7a3b12":"#8B4513",t.lineWidth=L,t.setLineDash([3/r,3/r]),t.beginPath(),t.moveTo(-h,2*A/r),t.lineTo(h,2*A/r),t.stroke(),t.setLineDash([]),t.lineWidth=L+.4/r,t.beginPath(),t.moveTo(-h,0),t.lineTo(0,0),t.stroke();else if(u==="line"||u==="corner_line"){t.strokeStyle=u==="corner_line"?i?"#050505":"#161616":i?"#1565C0":"#1976D2",t.lineWidth=L;const W=u==="corner_line"?2.2/r:1.5/r;t.beginPath(),t.moveTo(-h,-W),t.lineTo(h,-W),t.moveTo(-h,W),t.lineTo(h,W),u==="corner_line"&&(t.moveTo(-h,-P),t.lineTo(-
358h,P),t.moveTo(h,-P),t.lineTo(h,P)),t.stroke()}else if(u==="casement"||u==="awning")t.strokeStyle=i?"#1565C0":"#1976D2",t.lineWidth=L,t.beginPath(),t.moveTo(-h,0),t.lineTo(0,P*A),t.lineTo(h,0),t.stroke(),t.beginPath(),t.moveTo(-h,0),t.lineTo(h,0),t.stroke();else if(u==="bay"){t.strokeStyle=i?"#1565C0":"#1976D2",t.lineWidth=L;const W=Math.min(h*.8,P*3)*A,S=h*.5;t.beginPath(),t.moveTo(-h,0),t.lineTo(-S,W),t.lineTo(S,W),t.lineTo(h,0),t.stroke()}else if(u==="rollup"){t.strokeStyle=i?"#7a3b12":"#8B4513",t.lineWidth=L,t.beginPath();for(const W of[-P*.5,0,P*.5])t.moveTo(-h,W),t.lineTo(h,W);t.stroke()}t.restore(),i&&vZ(t,{cx:_,cy:j,ux:w,uy:k,halfW:h,wallHalfT:P,label:l.label,widthLabel:l.widthLabel,heightLabel:l.heightLabel,unitLabel:l.unitLabel,direction:l.direction,widthMm:d,heightMm:e.heightMm||(c==null?void 0:c.height)||Kc[e.type].height,zoom:r})}function vZ(t,e){const s=Math.max(e.zoom,1e-4),o=-e.uy,r=e.ux,i=[{x:e.cx-e.ux*e.halfW-o*e.wallHalfT,y:e.cy-e.uy*e.halfW-r*e.wallHalfT},{x:e.cx-e.ux*e.halfW+o*e.wallHalfT,y:e.cy-e.uy*e.halfW+r*e.wallHalfT},{x:e.cx+e.ux*e.halfW-o*e.wallHalfT,y:e.cy+e.uy*e.halfW-r*e.wallHalfT},{x:e.cx+e.ux*e.halfW+o*e.wallHalfT,y:e.cy+e.uy*e.halfW+r*e.wallHalfT}],a=Math.max(...i.map(L=>L.x)),l=Math.min(...i.map(L=>L.y)),c=106/s,d=8/s,u=7/s,h=10.5/s,x=8.5/s,f=15/s,p=8.5/s,b=12/s,M=36/s;t.save(),t.direction=e.direction,t.font=`800 ${h}px Heebo, system-ui, sans-serif`;const g=jZ(t,e.label,c-d*2,3),w=u*2+g.length*b+5/s+M,k=9/s,_=a+k+c/2,j=l-k-w/2;t.shadowColor="rgba(24, 33, 55, 0.16)",t.shadowBlur=5/s,t.shadowOffsetY=1.5/s,t.fillStyle="rgba(247, 244, 239, 0.96)",t.strokeStyle="rgba(216, 93, 67, 0.72)",t.lineWidth=1.2/s,t.beginPath(),t.roundRect(_-c/2,j-w/2,c,w,5/s),t.fill(),t.shadowColor="transparent",t.stroke(),t.fillStyle="#182137",t.textAlign="center",t.textBaseline="middle";let v=j-w/2+u+b/2;t.font=`800 ${h}px Heebo, system-ui, sans-serif`;for(const L of g)t.fillText(L,_,v),v+=b;const C=j+w/2-u-M,N=_+c*.23,P=_-c*.23;L4(t,N,C,e.widthLabel,W4(e.widthMm),e.unitLabel,x,f,p,s),L4(t,P,C,e.heightLabel,W4(e.heightMm),e.unitLabel,x,f,p,s),t.restore()}function L4(t,e,s,o,r,i,a,l,c,d){t.fillStyle="rgba(24, 33, 55, 0.58)",t.font=`700 ${a}px Heebo, system-ui, sans-serif`,t.fillText(o,e,s+5/d),t.fillStyle="#182137",t.font=`900 ${l}px Heebo, system-ui, sans-serif`,t.fillText(r,e,s+19/d),t.fillStyle="rgba(24, 33, 55, 0.62)",t.font=`700 ${c}px Heebo, system-ui, sans-serif`,t.fillText(i,e,s+31/d)}function W4(t){const e=t/10;return Math.abs(e-Math.round(e))<.01?String(Math.round(e)):e.toFixed(1).replace(/\.0$/,"")}function jZ(t,e,s,o){const r=e.trim().split(/\s+/).filter(Boolean);if(r.length===0)return[""];const i=[];let a="";for(const l of r){const c=a?`${a} ${l}`:l;if(t.measureText(c).width<=s||!a){a=c;continue}if(i.push(a),a=l,i.length===o-1){const d=H7(t,a,s);return i.push(d),i}}return a&&i.length<o&&i.push(a),i}function H7(t,e,s){if(t.measureText(e).width<=s)return e;let o=e;for(;o.length>1&&t.measureText(`${o}…`).width>s;)o=o.slice(0,-1);return`${o}…`}function R4(t,e,s,o,r,i){if(o<=0)return;const a=qs[e.preset];if(!a)return;const l=e.widthMm/o/2,c=s.end.x-s.start.x,d=s.end.y-s.start.y,u=Math.sqrt(c*c+d*d);if(u===0)return;const h=c/u,x=d/u,f=s.start.x+h*e.positionPx,p=s.start.y+x*e.positionPx,b=Math.atan2(x,h),M=s.wallType||"exterior",g=(i==null?void 0:i[M])??br[M],w=(s.thicknessMm??g.thicknessMm)/o/2,k=a.symbol||(e.type==="door"?"arc":"line"),_=e.type==="door"?"#8B4513":"#1565C0",j=2.3/r;if(t.save(),t.translate(f,p),t.rotate(b),t.fillStyle="#f7f4ef",t.fillRect(-l,-w-2/r,l*2,w*2+4/r),O7(t,l,w,r,"placement"),t.fillStyle=p1,t.beginPath(),t.arc(0,0,3.6/r,0,Math.PI*2),t.fill(),t.strokeStyle="rgba(24, 33, 55, 0.55)",t.lineWidth=1.1/r,t.stroke(),t.strokeStyle=_,t.lineWidth=j,t.lineCap="round",k==="arc"){const v=-l;t.beginPath(),t.moveTo(v,0),t.lineTo(l,0),t.stroke(),t.beginPath(),t.arc(v,0,l*2,0,Math.PI/2,!1),t.stroke()}else if(k==="double_arc")t.beginPath(),t.moveTo(-l,0),t.lineTo(0,0),t.moveTo(l,0),t.lineTo(0,0),t.stroke(),t.beginPath(),t.arc(-l,0,l,0,Math.PI/2,!1),t.arc(l,0,l,Math.PI,Math.PI/2,!0),t.stroke();else if(k==="slide")t.setLineDash([3/r,3/r]),t.beginPath(),t.moveTo(-l,2/r),t.lineTo(l,2/r),t.stroke(),t.setLineDash([]),t.lineWidth=2.2/r,t.beginPath(),t.moveTo(-l,0),t.lineTo(0,0),t.stroke();else if(k==="line"||k==="corner_line"){const v=k==="corner_line"?2.2/r:1.6/r;k==="corner_line"&&(t.strokeStyle="#161616"),t.beginPath(),t.moveTo(-l,-v),t.lineTo(l,-v),t.moveTo(-l,v),t.lineTo(l,v),k==="corner_line"&&(t.moveTo(-l,-w),t.lineTo(-l,w),t.moveTo(l,-w),t.lineTo(l,w)),t.stroke()}else if(k==="casement"||k==="awning")t.beginPath(),t.moveTo(-l,0),t.lineTo(0,w),t.lineTo(l,0),t.moveTo(-l,0),t.lineTo(l,0),t.stroke();else if(k==="bay"){const v=Math.min(l*.8,w*3),C=l*.5;t.beginPath(),t.moveTo(-l,0),t.lineTo(-C,v),t.lineTo(C,v),t.lineTo(l,0),t.stroke()}else if(k==="rollup"){t.beginPath();for(const v of[-w*.5,0,w*.5])t.moveTo(-l,v),t.lineTo(l,v);t.stroke()}
358t.restore()}function _Z(t){if(!t)return null;const e=t.trim(),s=/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(e);if(s)return{r:parseInt(s[1]+s[1],16),g:parseInt(s[2]+s[2],16),b:parseInt(s[3]+s[3],16)};const o=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(e);if(o)return{r:parseInt(o[1],16),g:parseInt(o[2],16),b:parseInt(o[3],16)};const r=/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i.exec(e);return r?{r:+r[1],g:+r[2],b:+r[3]}:null}function EZ(t,e,s,o,r,i,a){const l=e.vertices;if(!l||l.length<3||s<=0)return;t.save();const c=new Path2D;c.moveTo(l[0].x/s,l[0].y/s);for(let g=1;g<l.length;g++)c.lineTo(l[g].x/s,l[g].y/s);if(c.closePath(),e.holes){for(const g of e.holes)if(!(g.length<3)){c.moveTo(g[0].x/s,g[0].y/s);for(let w=1;w<g.length;w++)c.lineTo(g[w].x/s,g[w].y/s);c.closePath()}}const d=_Z(e.color)??{r:54,g:108,b:255};t.fillStyle=`rgba(${d.r}, ${d.g}, ${d.b}, ${r?.28:.18})`,t.fill(c,"evenodd"),t.strokeStyle=r?"rgba(255, 159, 67, 0.9)":`rgb(${d.r}, ${d.g}, ${d.b})`,t.lineWidth=(r?1.5:.8)/o,t.stroke(c);let u=1/0,h=1/0,x=-1/0,f=-1/0;for(const g of l)g.x<u&&(u=g.x),g.x>x&&(x=g.x),g.y<h&&(h=g.y),g.y>f&&(f=g.y);const p=x-u,b=f-h,M=p/s;if(M>=24/o){t.fillStyle=r?"#ff9f43":"#111111";const g=Math.max(8/o,Math.min(M*.12,11/o));t.font=`${g}px system-ui`,t.textAlign="center",t.textBaseline="middle",t.fillText(`${De(p,i)}×${De(b,i)} ${a}`,(u+x)/2/s,(h+f)/2/s)}t.restore()}function DZ(t,e,s,o,r){const i=pi[e.type]??{width:1e3,depth:1e3},a=e.scale||1,l=(e.widthMm??i.width*a)/s,c=(e.depthMm??i.depth*a)/s;if(t.save(),t.translate(e.position.x,e.position.y),t.rotate(e.rotation*Math.PI/180),r&&(t.fillStyle="rgba(255, 159, 67, 0.12)",t.fillRect(-l/2,-c/2,l,c),t.strokeStyle="rgba(255, 159, 67, 0.7)",t.lineWidth=1.5/o,t.strokeRect(-l/2,-c/2,l,c)),r){const d=c/2+W7/o,u=R7/o;t.strokeStyle="#ff9f43",t.lineWidth=1.5/o,t.setLineDash([3/o,3/o]),t.beginPath(),t.moveTo(0,-c/2),t.lineTo(0,-d),t.stroke(),t.setLineDash([]),t.fillStyle="#ff9f43",t.beginPath(),t.arc(0,-d,u,0,Math.PI*2),t.fill(),t.strokeStyle="#fff",t.lineWidth=1.5/o,t.beginPath(),t.arc(0,-d,u*.55,-Math.PI*.8,Math.PI*.5),t.stroke();const h=u*.55*Math.cos(Math.PI*.5),x=-d+u*.55*Math.sin(Math.PI*.5);t.fillStyle="#fff",t.beginPath(),t.moveTo(h,x),t.lineTo(h-2/o,x-3/o),t.lineTo(h+2/o,x-1/o),t.closePath(),t.fill();const f=5/o;t.fillStyle="#ff9f43",t.strokeStyle="#fff",t.lineWidth=1/o;for(const[p,b]of[[-l/2,-c/2],[l/2,-c/2],[-l/2,c/2],[l/2,c/2]])t.beginPath(),t.rect(p-f,b-f,f*2,f*2),t.fill(),t.stroke();a!==1&&(t.fillStyle="#ff9f43",t.font=`${9/o}px system-ui`,t.textAlign="center",t.textBaseline="top",t.fillText(`${Math.round(a*100)}%`,0,c/2+4/o))}else{const d=Math.max(3/o,l*.04);t.fillStyle="rgba(150, 170, 140, 0.4)",t.beginPath(),t.moveTo(0,-c/2),t.lineTo(-d,-c/2-d),t.lineTo(d,-c/2-d),t.closePath(),t.fill()}t.restore()}function FZ(t,e,s){const{binary:o,width:r,height:i,hPeakRows:a,vPeakCols:l,rawSegments:c,mergedSegments:d,majorSegments:u}=e,h=t.createImageData(r,i);for(let p=0;p<r*i;p++)o[p]&&(h.data[p*4]=255,h.data[p*4+1]=50,h.data[p*4+2]=50,h.data[p*4+3]=60);const x=document.createElement("canvas");x.width=r,x.height=i,x.getContext("2d").putImageData(h,0,0),t.drawImage(x,0,0),t.strokeStyle="rgba(0, 255, 255, 0.2)",t.lineWidth=1/s;for(const p of a)t.beginPath(),t.moveTo(0,p),t.lineTo(r,p),t.stroke();t.strokeStyle="rgba(255, 0, 255, 0.2)";for(const p of l)t.beginPath(),t.moveTo(p,0),t.lineTo(p,i),t.stroke();t.strokeStyle="rgba(255, 255, 0, 0.2)",t.lineWidth=1/s;for(const p of c)t.beginPath(),t.moveTo(p.start.x,p.start.y),t.lineTo(p.end.x,p.end.y),t.stroke();const f=new Set(u.map(p=>`${p.start.x},${p.start.y}-${p.end.x},${p.end.y}`));t.strokeStyle="rgba(255, 140, 0, 0.3)",t.lineWidth=2/s,t.setLineDash([4/s,4/s]);for(const p of d){const b=`${p.start.x},${p.start.y}-${p.end.x},${p.end.y}`;f.has(b)||(t.beginPath(),t.moveTo(p.start.x,p.start.y),t.lineTo(p.end.x,p.end.y),t.stroke())}if(t.setLineDash([]),e.reconstruction){const p=e.reconstruction,b=t.createImageData(r,i);for(let g=0;g<r*i;g++)p.cleanedBinary[g]&&!o[g]||!p.cleanedBinary[g]&&o[g]&&(b.data[g*4]=50,b.data[g*4+1]=100,b.data[g*4+2]=255,b.data[g*4+3]=40);const M=document.createElement("canvas");M.width=r,M.height=i,M.getContext("2d").putImageData(b,0,0),t.drawImage(M,0,0),t.strokeStyle="rgba(0, 200, 255, 0.4)",t.lineWidth=1.5/s;for(const g of p.rawCenterlines)t.beginPath(),t.moveTo(g.start.x,g.start.y),t.lineTo(g.end.x,g.end.y),t.stroke();t.strokeStyle="rgba(255, 255, 255, 0.6)",t.lineWidth=2.5/s;for(const g of p.finalCenterlines)t.beginPath(),t.moveTo(g.start.x,g.start.y),t.lineTo(g.end.x,g.end.y),t.stroke()}t.strokeStyle="rgba(0, 255, 100, 0.8)",t.lineWidth=3/s;for(const p of u)t.beginPath(),t.moveTo(p.start.x,p.start.y),t.lineTo(p.end.x,p.end.y),t.stroke()}function Gp(t){var x,f,p,b;const e=Number(t.thickness),s=Number((x=t.start)==null?void 0:x.x),o=Number((f=t.start)==null?void 0:f.y),r=Number((p=t.end)==null?void 0:p.x),i=Number((b=t.end
358)==null?void 0:b.y);if(![e,s,o,r,i].every(Number.isFinite)||e<=0)return null;const a=r-s,l=i-o,c=Math.hypot(a,l);if(c<=1e-9)return null;const d=-l/c,u=a/c,h=e/2;return{kind:"wall_centerline_v1",centerline:[[s,o],[r,i]],thickness:e,polygon:[[s+d*h,o+u*h],[r+d*h,i+u*h],[r-d*h,i-u*h],[s-d*h,o-u*h]]}}function Up(t){const e=O4(t.vertices),s=(t.holes??[]).map(r=>O4(r)).filter(r=>r.length>=3),o=e.length>=3;return{kind:"room_polygon_v1",polygon:o?e:[],wallIds:t.wallIds??[],holes:s,areaMm2:typeof t.areaMm2=="number"&&Number.isFinite(t.areaMm2)?t.areaMm2:null,source:"roomInference",valid:o,failReason:o?null:"no-polygon"}}function O4(t){return Array.isArray(t)?t.map(e=>({x:Number(e.x),y:Number(e.y)})).filter(e=>Number.isFinite(e.x)&&Number.isFinite(e.y)):[]}function B7(t){var b,M;const e=t.levels[0],s=(e==null?void 0:e.walls)??[],o=(e==null?void 0:e.rooms)??[],r=t._roomInferenceDiagnostics,i=s.filter(g=>g.geometry||Gp(g)).length,a=o.map(g=>g.geometry??Up({vertices:g.vertices,wallIds:g.wallIds,holes:g.holes,areaMm2:typeof g.area=="number"?Math.round(g.area*1e6):null})),l=a.filter(g=>g.valid).length,c=a.filter(g=>g.wallIds.length>0).length,d=a.length>0?Math.round(a.reduce((g,w)=>g+w.wallIds.length,0)/a.length*100)/100:0,u=s.length>0&&i===s.length,h=s.length>0?i/s.length:0,x=o.length>0?l/o.length:0,f=o.length>0?c/o.length:0,p=s.length===0||h<.8?"bad":u&&x>=.8&&f>=.8?"good":"partial";return{wallCount:s.length,wallGeometryCount:i,roomCount:o.length,validRoomPolygonCount:l,invalidRoomCount:Math.max(0,o.length-l),roomsWithWallIdsCount:c,averageRoomWallCount:d,openingCount:((b=e==null?void 0:e.openings)==null?void 0:b.length)??0,furnitureCount:((M=e==null?void 0:e.furniture)==null?void 0:M.length)??0,duplicateRoomCandidateCount:(r==null?void 0:r.duplicateRoomCandidateCount)??0,duplicateRoomPolygonKeys:(r==null?void 0:r.duplicateRoomPolygonKeys)??[],droppedDuplicateRoomCandidates:(r==null?void 0:r.droppedDuplicateRoomCandidates)??[],trainingSampleQuality:p}}function CZ(t,e){const s=t.levels[0],o=(s==null?void 0:s.walls)??[],r=(s==null?void 0:s.rooms)??[];return{schemaVersion:"floorplan_training_v1",source:{projectId:e.projectId??null,imageUrl:e.imageUrl??null,imageStoragePath:e.imageStoragePath??null,imageBucket:e.imageBucket??null,imageWidth:e.imageWidth??null,imageHeight:e.imageHeight??null,calibration:e.calibration??null,createdAt:e.createdAt??null},walls:o.map(i=>{const a=i.geometry??Gp(i);return{id:i.id,centerline:(a==null?void 0:a.centerline)??null,thickness:i.thickness,polygon:(a==null?void 0:a.polygon)??null,source:i.source,confidence:i.confidence??null,geometry:a}}),rooms:r.map(i=>{const a=i.geometry??Up({vertices:i.vertices,wallIds:i.wallIds,holes:i.holes,areaMm2:typeof i.area=="number"?Math.round(i.area*1e6):null});return{id:i.id,label:i.name,polygon:a.polygon,wallIds:a.wallIds,holes:a.holes,areaMm2:a.areaMm2,valid:a.valid,failReason:a.failReason,geometry:a}}),openings:(s==null?void 0:s.openings)??[],furniture:(s==null?void 0:s.furniture)??[],qa:B7(t),rawSceneSnapshot:t}}function NZ(t){const e=t.walls.length,s=t.walls.filter(d=>!!(d.geometry||d.polygon)).length,o=e>0?s/e:0,r=!!(t.source.imageStoragePath||t.source.imageUrl),i=t.rooms.filter(d=>d.valid&&d.polygon.length>=3).length,a=[],l=[];r||a.push("missing-source-image"),e<4&&a.push("too-few-walls"),o<.8&&a.push("insufficient-wall-geometry"),t.qa.trainingSampleQuality==="bad"&&a.push("bad-geometry-qa"),i===0&&l.push("wall-only-sample"),t.qa.trainingSampleQuality==="partial"&&l.push("partial-geometry-qa"),t.qa.duplicateRoomCandidateCount>0&&l.push("duplicate-room-candidates");const c=a.length===0;return{usable:c,sampleKind:c?i>0?"room":"wall-only":"rejected",quality:c?t.qa.trainingSampleQuality==="good"&&i>0?"good":"partial":"bad",hasSourceImage:r,wallGeometryRatio:Math.round(o*100)/100,reasons:a,warnings:l}}function V7(t){const e=t.trim(),s=e?e.replace(/\.[^.]+$/,"").replace(/[-_]/g," "):"סקיצה חדשה",o=new Date().toISOString();return{schemaVersion:"0.1.0",project:{id:"proj_001",name:s||"סקיצה חדשה",displayUnit:"mm",createdAt:o,updatedAt:o},sourceFiles:[{filename:e||"sketch-placeholder.png",format:e.toLowerCase().endsWith(".svg")?"svg":"png"}],materials:[],levels:[{id:"level_001",name:"Ground Floor",elevation:0,walls:[],beams:[],openings:[],rooms:[],furniture:[],dimensions:[]}]}}function IZ(t){if(t.length<3)return 0;const e=[];for(const a of t)e.push(a.start,a.end);const s=e.reduce((a,l)=>a+l.x,0)/e.length,o=e.reduce((a,l)=>a+l.y,0)/e.length,r=[];for(const a of e)r.some(l=>
358Math.abs(l.x-a.x)<2&&Math.abs(l.y-a.y)<2)||r.push(a);if(r.length<3)return 0;r.sort((a,l)=>Math.atan2(a.y-o,a.x-s)-Math.atan2(l.y-o,l.x-s));let i=0;for(let a=0;a<r.length;a++){const l=r[a],c=r[(a+1)%r.length];i+=l.x*c.y-c.x*l.y}return Math.abs(i)/2}function Td(t,e){if(e.calibrated)return e.scale;if(e.totalAreaSqm&&t.length>=3){const o=IZ(t);if(o>0){const r=e.totalAreaSqm*1e6;return Math.sqrt(r/o)}}let s=0;for(const o of t){const r=Math.abs(o.end.x-o.start.x),i=Math.abs(o.end.y-o.start.y),a=Math.sqrt(r*r+i*i);a>s&&(s=a)}return s>0?8e3/s:1}function TZ(t,e){return t.map(s=>{const o=pi[s.type]??{width:600,depth:600,height:800};return{id:s.id,type:s.type,position:{x:Math.round(s.position.x*e),y:Math.round(s.position.y*e)},rotation:s.rotation,width:s.widthMm??Math.round(o.width*(s.scale||1)),depth:s.depthMm??Math.round(o.depth*(s.scale||1)),height:s.heightMm??Math.round(o.height*(s.scale||1)),flipped:s.flipped||void 0,materialOverrides:s.materialOverrides,source:"manual"}})}function z7(t,e,s){const o=TZ(t,e);if(!s||s.rotationDeg===0&&s.txMm===0&&s.tyMm===0)return o;const r=s.rotationDeg*Math.PI/180,i=Math.cos(r),a=Math.sin(r);return o.map(l=>{const c=l.position.x,d=l.position.y;return{...l,position:{x:Math.round(c*i-d*a+s.txMm),y:Math.round(c*a+d*i+s.tyMm)},rotation:((l.rotation+s.rotationDeg)%360+360)%360}})}function SZ(t,e){const s=new Set,o=t.walls.filter(g=>s.has(g.id)?!1:(s.add(g.id),!0)),r=Td(o,t.calibration),i=t.worldAlign&&(t.worldAlign.rotationDeg!==0||t.worldAlign.txMm!==0||t.worldAlign.tyMm!==0)?t.worldAlign:null,a=i?i.rotationDeg*Math.PI/180:0,l=Math.cos(a),c=Math.sin(a),d=g=>{const w=g.x*r,k=g.y*r;return i?{x:Math.round(w*l-k*c+i.txMm),y:Math.round(w*c+k*l+i.tyMm)}:{x:Math.round(w),y:Math.round(k)}},u=o.map(g=>{const w=d(g.start),k=d(g.end);return{id:g.id,startX:w.x,startY:w.y,endX:k.x,endY:k.y}}),{rooms:h,diagnostics:x}=D7(u),f=h.map((g,w)=>({id:`room_${String(w+1).padStart(3,"0")}`,name:`Room ${w+1}`,wallIds:g.wallIds,area:Math.round(g.areaMm2/1e6*100)/100,vertices:g.vertices,polygonKey:g.polygonKey,parentKey:g.parentKey,depth:g.depth,holes:g.holes,geometry:Up(g),source:"detected",confidence:1})),p=z7(t.furniture,r,i),b=t.beams.map(g=>({id:g.id,start:d(g.start),end:d(g.end),width:Math.max(10,Math.round(g.widthMm)),height:Math.max(10,Math.round(g.heightMm)),source:"manual"})).filter(g=>Math.hypot(g.end.x-g.start.x,g.end.y-g.start.y)>=10);return{level:{id:t.id,name:t.name,elevation:t.elevationMm,...t.slabThicknessMm&&t.slabThicknessMm>0?{slabThicknessMm:t.slabThicknessMm}:{},walls:o.map(g=>{const w=g.wallType||"exterior",k=e[w]??br[w],_={id:g.id,start:d(g.start),end:d(g.end),height:g.heightMm??k.heightMm??Ld,thickness:g.thicknessMm??k.thicknessMm??br[w].thicknessMm,wallType:w,source:g.detectionSource==="ai"?"detected":"manual",...g.color?{materialId:`color_${g.color.replace("#","")}`}:{}},j=Gp(_);return j?{..._,geometry:j}:_}),beams:b,openings:t.openings.map(g=>{const w=(g.preset?qs[g.preset]:void 0)??Kc[g.type]??Kc.door,k=g.preset==="single_door_glass"||g.preset==="arched_door_glass"||g.preset==="corner_glass_door",_=Yw(g.preset),j=g.type==="door"&&!_?k?"glass":"solid":void 0,v=hm(g)?rm(Wd(g)):{},C=Lf(g)?{flushFace:xb(g)}:{};return{id:g.id,type:g.type,...g.preset?{preset:g.preset}:{},wallId:g.wallId,position:Math.round(g.positionPx*r),width:g.widthMm||w.width,height:g.heightMm||w.height,sillHeight:g.sillHeightMm??w.sillHeight,style:j,cornerGroupId:g.cornerGroupId,cornerArm:g.cornerArm,...v,...C,panelColor:g.panelColor,panelCladding:g.panelCladding,source:g.detectionSource==="ai"?"detected":"manual"}}),rooms:f,furniture:p,dimensions:[]},diagnostics:x,walls:o}}function $7(t,e,s=br){var d,u,h,x;if(!t.some(f=>f.walls.length>0||f.beams.length>0))return null;const o=new Date().toISOString(),r=t.map(f=>SZ(f,s)),i=new Set,a=[];for(const{walls:f}of r)for(const p of f){if(!p.color)continue;const b=`color_${p.color.replace("#","")}`;i.has(b)||(i.add(b),a.push({id:b,name:p.color,color:p.color}))}const l=Td(((d=t[0])==null?void 0:d.walls)??[],((u=t[0])==null?void 0:u.calibration)??{scale:1,calibrated:!1});return{schemaVersion:"0.1.0",project:{id:"proj_001",name:e.replace(/\.[^.]+$/,"").replace(/[-_]/g," "),displayUnit:"mm",createdAt:o,updatedAt:o},sourceFiles:[{filename:e,format:e.toLowerCase().endsWith(".svg")?"svg":"png",scale:(h=t[0])!=null&&h.calibration.calibrated?l:void 0}],materials:a,levels:r.map(({level:f})=>f),_roomInferenceDiagnostics:(x=r[0])==null?void 0:x.diagnostics}}function X7(t,e,s,o,r,i=br,a=[]){return t.length===0&&a.length===0?null:$7([{id:"level_001",name:"Ground Floor",elevationMm:0,walls:t,beam
358s:a,openings:e,furniture:s,calibration:o}],r,i)}function PZ(t,e=br){const s=i=>{const a=i.wallType??"exterior",l=e[a]??br[a];return i.heightMm??(l==null?void 0:l.heightMm)??Ld},o=t.filter(i=>(i.wallType??"exterior")!=="free"),r=o.length>0?o:t;return r.length===0?Ld:Math.max(...r.map(s))}function AZ(t,e,s=br){var i;const o=[];let r=0;for(let a=0;a<t.length;a++){o.push(r);const l=PZ(e(a),s),c=((i=t[a+1])==null?void 0:i.slabThicknessMm)??Op;r+=l+c}return o}const LZ={night:"לילה",dawn:"לפנות בוקר",morning:"בוקר",noon:"צהריים",afternoon:"אחר הצהריים",goldenHour:"שעת זהב"};function Y7({timeOfDayMinutes:t,onChange:e,className:s}){const{t:o}=yn(),r=fm(t),i=kb(r),a=o(`environmentTime.phases.${i.phase}`,{defaultValue:LZ[i.phase]}),l=BP(r);return n.jsxs("div",{className:O("space-y-2 rounded-xl border border-[#182137]/9 bg-[#F7F4EF] p-3",s),children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("div",{className:"text-[10px] font-black uppercase tracking-wider text-[#182137]/52",children:o("environmentTime.label",{defaultValue:"שעה ביום"})}),n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"font-mono text-[10px] font-bold tabular-nums text-[#182137]/58",dir:"ltr",children:l}),n.jsx("span",{className:"text-[11px] font-black text-[#D85D43]",children:a})]})]}),n.jsx("input",{type:"range",dir:"ltr",min:eD,max:nD,step:Oy,value:r,onChange:c=>e(fm(c.currentTarget.value)),className:"w-full accent-[#D85D43]","aria-label":o("environmentTime.label",{defaultValue:"שעה ביום"}),"aria-valuetext":`${l} · ${a}`}),n.jsxs("div",{dir:"ltr",className:"flex items-center justify-between text-[#182137]/45",children:[n.jsx(Bk,{className:"h-3.5 w-3.5"}),n.jsx(MT,{className:"h-3.5 w-3.5"}),n.jsx(Dw,{className:"h-3.5 w-3.5"}),n.jsx(FI,{className:"h-3.5 w-3.5"}),n.jsx(Bk,{className:"h-3.5 w-3.5"})]})]})}function H4({label:t,valueMm:e,onChangeMm:s}){const o=Number((e/1e3).toFixed(1));return n.jsxs("label",{className:"grid grid-cols-[1fr_92px] items-center gap-2",children:[n.jsx("span",{className:"text-[11px] font-semibold text-[#182137]/70",children:t}),n.jsxs("span",{className:"flex h-9 items-center overflow-hidden rounded-lg border border-[#182137]/12 bg-[#FFFDFC]",children:[n.jsx("input",{type:"number",min:W1/1e3,max:R1/1e3,step:.5,value:o,onChange:r=>{const i=Number(r.currentTarget.value);if(!Number.isFinite(i))return;const a=Math.min(R1,Math.max(W1,Math.round(i*1e3)));s(a)},className:"min-w-0 flex-1 bg-transparent px-2 text-center text-[12px] font-bold text-[#182137] outline-none"}),n.jsx("span",{className:"pe-2 text-[9px] font-semibold text-[#182137]/40",children:"מ׳"})]})]})}function WZ({value:t,onChange:e,onRefitLot:s,canRefit:o}){const r=l=>e({...t,sky:{timeOfDayMinutes:l}}),i=l=>e({...t,ground:{material:l}}),a=l=>e({...t,lot:{...t.lot,...l}});return n.jsxs("div",{className:"space-y-4 p-3 font-heebo",dir:"rtl",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-[9px] font-bold uppercase tracking-[0.18em] text-[#D85D43]",children:"סביבת חוץ"}),n.jsx("p",{className:"mt-1 text-[11px] leading-5 text-[#182137]/58",children:"שמיים, שמש עם צל, קרקע ומגרש סביב הבניין."})]}),n.jsx(Y7,{timeOfDayMinutes:t.sky.timeOfDayMinutes,onChange:r}),n.jsxs("div",{className:"space-y-2",children:[n.jsx("div",{className:"text-[10px] font-black uppercase tracking-wider text-[#182137]/52",children:"קרקע"}),n.jsx("div",{className:"grid grid-cols-2 gap-2",children:PP.map(l=>{const c=t.ground.material===l;return n.jsxs("button",{type:"button",onClick:()=>i(l),className:O("flex items-center gap-2 rounded-xl border p-2 text-right shadow-[0_3px_0_rgba(24,33,55,0.06)] transition motion-reduce:transition-none",c?"-translate-y-0.5 border-[#D85D43] bg-[#F6E6E0]":"border-[#182137]/10 bg-[#FFFDFC] hover:-translate-y-0.5 hover:border-[#182137]/20"),children:[n.jsx("span",{className:"h-7 w-7 shrink-0 rounded-md border border-black/10 bg-center",style:{backgroundColor:gp[l],backgroundImage:`url(${Ry[l].diffuse})`,backgroundSize:"170%"}}),n.jsx("span",{className:"text-[12px] font-black text-[#182137]",children:Ry[l].labelHe})]},l)})})]}),n.jsxs("div",{className:"space-y-2 rounded-xl border border-[#182137]/9 bg-[#F7F4EF] p-3",children:[n.jsx("div",{className:"mb-1 text-[10px] font-black uppercase tracking-wider text-[#182137]/52",children:"גודל המגרש"}),n.jsx(H4,{label:"רוחב",valueMm:t.lot.widthMm,onChangeMm:l=>a({widthMm:l})}),n.jsx(H4,{label:"עומק",valueMm:t.lot.depthMm,onChangeMm:l=>a({depthMm:l})}),n.jsxs("button",{type:"button",disabled:!o,onClick:s,className:"mt-1 flex min-h-9 w-full items-center justify-center gap-1.5 rounded-lg border border-[#182137]/12 bg-white px-2 text-[10px] font-bold text-[#182137]/75 transition-colors hover:border-[#D85D43]/40 disabled:cursor-not-allowed disabled:opacity-40",children:[n.jsx(zu,{className:"h-3.5 w-3.5"}),"התאם למבנה"]})]})]})}const RZ={door:{min:600,max:2e3},window:{min:400,max:4e3}};function OZ(t,e){if(!Number.isFinite(e)||e<=0)return t;let s=!1;const o=t.map(r=>{if(!r.detectedWidthPx||r.detectedWidthPx<=0||r.widthMm)return r;const i=Math.round(r.detectedWidthPx*e),a=RZ[r.type];return i<a.min||i>a.max?r:(s=!0,{...r,widthMm:i})});return s?o:t}const G7=100,HZ=5e4,B4=.5;function g1(t,e){return Math.hypot(t.x-e.x,t.y-e.y)}function BZ(t,e){return g1(t.start,t.end)*e}function VZ(t){return t.type==="socket"?qw(t.outlets):t.type==="tv"?t3(t.inches):t.type==="ac"?Zw():43}function zZ(t,e,s){var r;let o=G7;for(const i of s.openings??[]){if(i.wallId!==t)continue;const a=i.preset?qs[i.preset]:void 0,l=i.widthMm??(a==null?void 0:a.width)??Kc[i.type].width;o=Math.max(o,i.positionPx*e+l/2)}for(const i of["front","back"])for(const a of((r=s.wallFaceRegions)==null?void 0:r[`${t}__${i}`])??[])for(const l of a.polygon)o=Math.max(o,l.u);for(const i of s.wallElectricalFixtures??[])i.wallId===t&&(o=Math.max(o,i.positionAlongWallMm+VZ(i)));for(const i of s.wallNotes??[])i.wallId===t&&(o=Math.max(o,i.positionAlongWallMm+Mb()));return Math.ceil(o)}function $Z(t){const{walls:e,targetWallId:s,targetLengthMm:o,effectiveScale:r}=t;if(!Number.isFinite(o)||o<G7||o>
358HZ||!Number.isFinite(r)||r<=0)return{ok:!1,code:"invalid-length",messageHe:"יש להזין אורך תקין בין 10 ס״מ ל־50 מטר."};const i=e.find(p=>p.id===s);if(!i)return{ok:!1,code:"wall-not-found",messageHe:"הקיר כבר לא קיים בתוכנית."};const a=g1(i.start,i.end);if(a<1e-6)return{ok:!1,code:"degenerate-wall",messageHe:"לא ניתן לשנות אורך של קיר ללא כיוון."};const l=o/r,c=(i.end.x-i.start.x)/a,d=(i.end.y-i.start.y)/a,u=i.end,h={x:i.start.x+c*l,y:i.start.y+d*l},x=new Set([s]),f=e.map(p=>{if(p.id===s)return{...p,end:h};const b=g1(p.start,u)<=B4,M=g1(p.end,u)<=B4;return!b&&!M?p:(x.add(p.id),{...p,...b?{start:h}:{},...M?{end:h}:{}})});for(const p of f){if(!x.has(p.id))continue;const b=BZ(p,r),M=zZ(p.id,r,t);if(b+.5<M)return{ok:!1,code:"attached-content",minimumLengthMm:M,messageHe:`לא ניתן לקצר את הקיר מתחת ל־${M} מ״מ בגלל פריט שממוקם עליו.`}}return{ok:!0,walls:f,affectedWallIds:Array.from(x)}}function ry(t){return{...t,levels:t.levels.map(e=>({...e,walls:(e.walls??[]).map(s=>{const o=s.geometry??Gp(s);return o?{...s,geometry:o}:s}),rooms:(e.rooms??[]).map(s=>({...s,geometry:s.geometry??Up({vertices:s.vertices,wallIds:s.wallIds,holes:s.holes,areaMm2:typeof s.area=="number"?Math.round(s.area*1e6):null})}))}))}}function XZ(t){const e=t;return!!(e&&e.schemaVersion&&Array.isArray(e.levels)&&e.levels[0]&&Array.isArray(e.levels[0].walls)&&Array.isArray(e.levels[0].rooms))}function YZ(t){const e=[];if(XZ(t.scene_json))return{scene:ry(t.scene_json),source:"levels",warnings:e};const s=UZ(t);if(s)return e.push("converted-legacy-scene-elements"),{scene:ry(s),source:"elements",warnings:e};const o=Array.isArray(t.walls)?t.walls:[];if(o.length>0){const r=X7(o,Array.isArray(t.openings)?t.openings:[],Array.isArray(t.furniture)?t.furniture:[],t.calibration??{scale:1,calibrated:!1},t.image_filename||t.name||"floorplan-project.png");if(r)return e.push("rebuilt-scene-from-traced-columns"),{scene:ry(r),source:"legacy_columns",warnings:e}}return e.push("no-exportable-scene-geometry"),{scene:null,source:"none",warnings:e}}function GZ(t,e={}){const s=YZ(t);if(!s.scene||s.source==="none")throw new Error(`Project ${t.id} has no exportable floorplan scene geometry`);const o=CZ(s.scene,{projectId:t.id,imageUrl:null,imageStoragePath:t.image_storage_path??null,imageBucket:t.image_storage_path?"floorplan-images":null,imageWidth:null,imageHeight:null,calibration:t.calibration??null,createdAt:t.created_at??null,...e});return{scene:s.scene,sample:o,qa:o.qa,usability:NZ(o),sceneSource:s.source,warnings:s.warnings}}function UZ(t){var c;const e=t.scene_json,s=Array.isArray(e==null?void 0:e.elements)?e.elements:[];if(s.length===0)return null;const o=s.filter(d=>d.type==="wall");if(o.length===0)return null;const r=new Date().toISOString(),i=new Map,a=o.flatMap((d,u)=>{const h=pw(d.start),x=pw(d.end);if(!h||!x)return[];const f=xf(d.id)??`wall_${String(u+1).padStart(3,"0")}`;i.set(u,f);const p={id:f,start:h,end:x,height:Vg(d.height)??2800,thickness:Vg(d.thickness)??200,source:d.source==="detected"?"detected":"manual",confidence:ZZ(d.confidence)},b=Gp(p);return[b?{...p,geometry:b}:p]}),l=s.filter(d=>d.type==="room").map((d,u)=>{const h=iy(d.vertices)??iy(d.polygon)??iy(d.overlayCoords)??[],x=KZ(d.wallIds),f=Vg(d.areaMm2),p=Vg(d.area)??(f?Math.round(f/1e6*100)/100:void 0);return{...{id:xf(d.id)??`room_${String(u+1).padStart(3,"0")}`,name:xf(d.name)??xf(d.label)??`Room ${u+1}`,wallIds:x,...typeof p=="number"?{area:p}:{},...h.length>0?{vertices:h}:{},...xf(d.polygonKey)?{polygonKey:xf(d.polygonKey)}:{},source:d.source==="manual"?"manual":"detected"},geometry:Up({vertices:h,wallIds:x,areaMm2:f??(typeof p=="number"?Math.round(p*1e6):null)})}});return{schemaVersion:"0.1.0",project:{id:"proj_001",name:t.name||t.image_filename||"Floorplan project",displayUnit:"mm",createdAt:t.created_at??r,updatedAt:t.updated_at??r},sourceFiles:[{filename:t.image_filename||"floorplan-project.png",format:(c=t.image_filename)!=null&&c.toLowerCase().endsWith(".svg")?"svg":"png"}],materials:[],levels:[{id:"level_001",name:"Ground Floor",elevation:0,walls:a,openings:[],rooms:l,furniture:[],dimensions:[]}]}}function pw(t){const e=t;if(Array.isArray(e)){const r=Number(e[0]),i=Number(e[1]);return Number.isFinite(r)&&Number.isFinite(i)?{x:r,y:i}:null}if(!e||typeof e!="object")return null;const s=Number(e.x),o=Number(e.y??e.z);return Number.isFinite(s)&&Number.isFinite(o)?{x:s,y:o}:null}function iy(t){if(!Array.isArray(t))return null;const e=t.map(pw).filter(s=>!!s);return e.length>0?e:null}function xf(t){return typeof t=="string"&&t.trim()?t:null}function KZ(t){return Array.isArray(t)?t.filter(e=>typeof e=="string"&&e.trim().length>0):[]}function Vg(t){const e=Number(t);return Number.isFinite(e)&&e>0?e:null}function ZZ(t){const e=Number(t);return Number.isFinite(e)&&e>=0&&e<=1?e:void 0}const V4="floorplan-images",Bx="floorplan-segmentation";async function ay(t,e={}){var b;const s=t.trim();if(!s)throw new Error("projectId is required");const{data:o,error:r}=await Bo.functions.invoke("check-admin-status");if(r)throw new Error(`Admin check failed: ${r.message}`);if(!(o!=null&&o.isAdmin))throw new Error("Training sample export is admin-only");const{data:i,error:a}=await Bo.auth.getUser();if(a)throw new Error(`Auth check failed: ${a.message}`);const l=(b=i.user)==null?void 0:b.id;if(!l)throw new Error("Training sample export requires a signed-in user");const{data:c,error:d}=await Bo.from("floorplan_projects").select("*").eq("id",s).single();if(d)throw new Error(`Project load failed: ${d.message}`);const u=c,h=[];let x=null;if(u.image_storage_path){const{data:M,error:g}=await Bo.storage.from(V4).createSignedUrl(u.image_storage_path,3600);g?h.push(`source-image-signed-url-failed:${g.message}`):x=M.signedUrl}const f=GZ(u,{imageUrl:x,imageStoragePath:u.image_storage_path??null,imageBucket:u.image_storage_path?V4:null});f.warnings.push(...h);const p=e.saveToSupabase===!1?JZ(!1):f.usability.usable?await qZ({sampleResult:f,userId:l,project:u,split:e.split??"train",reviewStatus:e.reviewStatus??"pending",captureContext:e.captureContext??null}):QZ(`Rejected training sample was not saved: ${f.usability.reasons.join(", ")||"unknown-reason"}`);return{...f,projectId:s,sourceImageExists:!!u.image_storage_path,save:p,summary:{trainingSampleBucket:p.trainingSampleBucket,trainingSampleStoragePath:p.trainingSampleStoragePath,sampleId:p.sampleRowId,sampleQuality:f.qa.trainingSampleQuality,sourceImageStatus:u.image_storage_path?"connected":"missing",projectFormat:f.sceneSource,saveError:p.error}}}async function qZ(t){const e=new Date().toISOString().replace(/[:.]/g,"-"),s=["training-samples",z4(t.userId),z4(t.project.id),e,"training_sample.json"].join("/"),o=JSON.stringify(t.sampleResult.sample,null,2),r=new Blob([o],{type:"application/json"}),{error:i}=await Bo.storage.from(Bx).upload(s,r,{contentType:"application/json",upsert:!0});if(i)return{attempted:!0,saved:!1,trainingSampleBucket:Bx,trainingSampleStoragePath:s,sampleRowId:null,error:`Training sample upload failed: ${i.message}`};if(!t.project.image_storage_path)return{attempted:!0,saved:!0,trainingSampleBucket:Bx,trainingSampleStoragePath:s,sampleRowId:null,error:"Sample JSON saved, but floorplan_segmentation_samples row was skipped because image_storage_path is missing"};const a=JSON.stringify({trainingSampleStoragePath:s,qa:t.sampleResult.qa,usability:t.sampleResult.usability,sceneSource:t.sampleResult.sceneSource,warnings:t.sampleResult.warnings,...t.captureContext?{captureContext:t.captureContext}:{}}),{data:l,error:c}=await Bo.from("floorplan_segmentation_samples").insert({user_id:t.userId,project_id:t.project.id,image_storage_path:t.project.image_storage_path,split:t.split,source:"manual_trace",review_status:t.reviewStatus,notes:a}).select("id").single();return c?{attempted:!0,saved:!0,trainingSampleBucket:Bx,trainingSampleStoragePath:s,sampleRowId:null,error:`Sample JSON saved, but sample row insert failed: ${c.message}`}:{attempted:!0,saved:!0,trainingSampleBucket:Bx,trainingSampleStoragePath:s,sampleRowId:(l==null?void 0:l.id)??null,error:null}}function JZ(t){return{attempted:t,saved:!1,trainingSampleBucket:null,trainingSampleStoragePath:null,sampleRowId:null,error:null}}function QZ(t){return{attempted:!1,saved:!1,trainingSampleBucket:null,trainingSampleStoragePath:null,sampleRowId:null,error:t}}function z4(t){return t.replace(/[^a-zA-Z0-9_-]/g,"_").slice(0,120)||"unknown"}const Yr=1/10,tq={sofa:"sofa",sofa_2:"sofa",sofa_3seat:"sofa",sofa_corner:"sofa",loveseat:"sofa",armchair:"chair",armchair_2:"chair",armchair_wing:"chair",recliner:"chair",chair:"chair",dining_chair_up:"chair",office_chair:"chair",office_chair_ex:"chair",bar_stool:"chair",table:"table",coffee_table:"table",side_table:"table",console_table:"table",dining_table:"table",dining_table_round:"table",dining_table_ext:"table",bar_table:"table",desk:"desk",desk_l_shape:"desk",desk_standing:"desk",tv_unit:"tv",tv_wall_unit:"tv",bookcase:"wardrobe",display_cabinet:"wardrobe",shelf_wall:"wardrobe",shelf_unit:"wardrobe",cube_shelf:"wardrobe",storage_shelf:"wardrobe",closet_tall:"wardrobe",closet_wide:"wardrobe",closet_shoe:"wardrobe",wardrobe:"wardrobe",wardrobe_sliding:"wardrobe",wardrobe_corner:"wardrobe",wardrobe_open:"wardrobe",nightstand:"cabinet",nightstand_wide:"cabinet",dresser:"cabinet",dresser_tall:"cabinet",sideboard:"cabinet",buffet:"cabinet",filing_cabinet:"cabinet",vanity_table:"cabinet",bed:"bed_d",bed_king:"bed_d",bed_bunk:"bed_d",bed_single:"bed_s",cabinet_lower:"kitchen",cabinet_upper:"kitchen",cabinet_tall:"kitchen",cabinet_corner:"kitchen",kitchen_island:"kitchen",kitchen_island_l:"kitchen",microwave:"kitchen",dishwasher:"kitchen",fridge:"fridge",fridge_double:"fridge",stove:"range",oven_builtin:"range",range_hood:"range",kitchen_sink:"sink",kitchen_sink_dbl:"sink",bathroom_sink:"sink",toilet:"toilet",toilet_wall:"toilet",bidet:"toilet",bathtub:"bathtub",bathtub_corner:"bathtub",bathtub_freestand:"bathtub",shower:"shower",shower_walk_in:"shower",vanity:"vanity",vanity_double:"vanity",washer:"washer",dryer:"dryer"};function eq(t){const e=tq[t];return e||(t.startsWith("sofa")?"sofa":t.startsWith("bed")?"bed_d":t.startsWith("desk")?"desk":t.startsWith("table")||t.includes("dining_table")?"table":t.startsWith("wardrobe")||t.startsWith("closet")?"wardrobe":t.startsWith("cabinet")||t.startsWith("kitchen")?"kitchen":t.startsWith("chair")?"chair":t.includes("sink")?"sink":t.includes("toilet")?"toilet":t.includes("bathtub")?"bathtub":t.includes("shower")?"shower":"generic")}function nq(t){const e=t.start.x*Yr,s=t.start.y*Yr,o=t.end.x*Yr,r=t.end.y*Yr,i=o-e,a=r-s,l=Math.hypot(i,a);if(l<1)return null;const c=t.thickness*Yr/2,d=-a/l*c,u=i/l*c;return[[e+d,s+u],[o+d,r+u],[o-d,r-u],[e-d,s-u]]}function oq(t,e){const s=e.start.x*Yr,o=e.start.y*Yr,r=e.end.x*Yr,i=e.end.y*Yr,a=r-s,l=i-o,c=Math.hypot(a,l);
358if(c<1)return null;const d=a/c,u=l/c,h=Math.min(Math.max(t.position*Yr,0),c),x=s+d*h,f=o+u*h,p=t.width*Yr,b=e.thickness*Yr,M={kind:t.type==="window"?"win":"door",x,y:f,rot:Math.atan2(u,d)*180/Math.PI,d_lo:-p/2,d_hi:p/2,n_lo:-(b/2+2),n_hi:b/2+2};return t.type==="door"&&(M.H=t.height*Yr),M}function sq(t){const e=t.position.x*Yr,s=t.position.y*Yr,o=t.width*Yr/2,r=t.depth*Yr/2,i=(t.rotation??0)*Math.PI/180,a=Math.abs(Math.cos(i)),l=Math.abs(Math.sin(i)),c=a*o+l*r,d=l*o+a*r;return{cat:eq(t.type),name:t.type,x0:e-c,x1:e+c,y0:s-d,y1:s+d}}function rq(t){const e=t.filter(a=>Array.isArray(a.vertices)&&a.vertices.length>=3);if(e.length===0)return null;const s=e.filter(a=>(a.depth??0)===0),o=s.length>0?s:e;let r=null,i=-1;for(const a of o){const l=a.area??iq(a.vertices);l>i&&(i=l,r=a)}return!r||!r.vertices?null:r.vertices.map(a=>[a.x*Yr,a.y*Yr])}function iq(t){let e=0;for(let s=0;s<t.length;s++){const o=t[s],r=t[(s+1)%t.length];e+=o.x*r.y-r.x*o.y}return Math.abs(e)/2}function aq(t){const e=t.levels[0];if(!e)return null;const s=new Map,o=[];for(const c of e.walls){s.set(c.id,c);const d=nq(c);d&&o.push(d)}if(o.length===0)return null;const r=[];for(const c of e.openings){const d=s.get(c.wallId);if(!d)continue;const u=oq(c,d);u&&r.push(u)}const i=e.furniture.map(sq),a=rq(e.rooms),l=e.rooms.filter(c=>Array.isArray(c.vertices)&&c.vertices.length>=3).map(c=>({poly:c.vertices.map(d=>[d.x*Yr,d.y*Yr]),label:c.name}));return{walls:o,floor:a,openings:r,furniture:i,rooms:l,curtain_walls:[],diagnostics:{},categories:{}}}async function U7(t,e){try{const s=await fetch(t);if(!s.ok)throw new Error(`download failed (${s.status})`);const o=await s.blob(),r=URL.createObjectURL(o),i=document.createElement("a");i.href=r,i.download=e,document.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(r),4e3)}catch{window.open(t,"_blank","noopener")}}function lq(t,e){return{x:Math.round(t.x*e),y:Math.round(t.y*e)}}function cq(t,e){return{u:Math.round(t.u*e),v:Math.round(t.v*e)}}function dq(t,e){if(!Number.isFinite(e)||e===1)return t;const s={};for(const[o,r]of Object.entries(t))s[o]=r.map(i=>({...i,polygon:i.polygon.map(a=>lq(a,e)),...i.tileOriginXMm!==void 0?{tileOriginXMm:Math.round(i.tileOriginXMm*e)}:{},...i.tileOriginYMm!==void 0?{tileOriginYMm:Math.round(i.tileOriginYMm*e)}:{}}));return s}function uq(t,e){if(!Number.isFinite(e)||e===1)return t;const s={};for(const[o,r]of Object.entries(t))s[o]=r.map(i=>({...i,polygon:i.polygon.map(a=>cq(a,e))}));return s}function hq(t,e){return!t||!Number.isFinite(e)||e===1?t:{x:t.x*e,z:t.z*e}}const K7="#E8DFD3",rb="#EDE7DC",ib=18;function $4(t){return t&&typeof t=="object"?t:null}function Z7(t,e){const s=typeof t=="number"?t:Number(t);return Number.isFinite(s)?s:e}function Ei(t,e,s,o){const r=Z7(t,o);return Math.round(Math.max(e,Math.min(s,r)))}function Bh(t,e=""){return typeof t=="string"&&t.trim()?t.trim():e}function mq(t){return Array.isArray(t)?t.filter(e=>typeof e=="string"&&e.trim().length>0):[]}function ly(t,e){if(typeof t!="string")return e;const s=t.trim();return/^#[0-9a-fA-F]{3,8}$/.test(s)?s:e}function fq(t){return typeof t=="string"&&(t==="top"||t==="bottom"||t==="side"||/^side-\d+$/.test(t))}function fl(t){if(!t.length)return null;const e=t.map(l=>l.x),s=t.map(l=>l.y),o=Math.min(...e),r=Math.min(...s),i=Math.max(...e),a=Math.max(...s);return[o,r,i,a].every(Number.isFinite)?{xMm:Math.round(o),yMm:Math.round(r),widthMm:Math.round(i-o),heightMm:Math.round(a-r)}:null}function q7(t){return _e(t.xMm,t.yMm,t.xMm+t.widthMm,t.yMm+t.heightMm)}function xq(t,e){return t.xMm>=e.xMm-1&&t.yMm>=e.yMm-1&&t.xMm+t.widthMm<=e.xMm+e.widthMm+1&&t.yMm+t.heightMm<=e.yMm+e.heightMm+1}function pq(t,e){const s=t.xMm+t.widthMm/2,o=t.yMm+t.heightMm/2;return s>=e.xMm&&s<=e.xMm+e.widthMm&&o>=e.yMm&&o<=e.yMm+e.heightMm}function J7(t){return t.xMm+t.widthMm}function Q7(t){return t.yMm+t.heightMm}function gq(t,e,s,o=2){const r=An(t,e);return r?s.xMm>=-o&&s.yMm>=-o&&J7(s)<=r.widthMm+o&&Q7(s)<=r.heightMm+o:!1}function bq(t){return t.sourceTool==="circle"?["side"]:t.vertices.map((e,s)=>`side-${s}`)}function Mq(t,e,s){if(gq(t,e,s))return e;const o=bq(t).map(a=>{const l=An(t,a);if(!l)return null;const c=Math.max(0,J7(s)-l.widthMm),d=Math.max(0,Q7(s)-l.heightMm),u=Math.max(0,l.widthMm-s.widthMm)*Math.max(0,l.heightMm-s.heightMm);return{faceId:a,overflowX:c,overflowY:d,excessArea:u}}).filter(a=>!!a),r=o.filter(a=>a.overflowX<=2&&a.overflowY<=2).sort((a,l)=>a.excessArea-l.excessArea);if(r[0])return r[0].faceId;const i=o.sort((a,l)=>a.overflowX+a.overflowY-(l.overflowX+l.overflowY))[0];return(i==null?void 0:i.faceId)??e}function t6(t,e){const s=new Map(t.filter(i=>i.kind==="polygon").map(i=>[i.id,i]));let o=!1;const r=t.map(i=>{if(i.kind!=="facePatch"&&i.kind!=="faceSplit"||i.groupId!==e)return i;const a=s.get(i.hostEntityId);if(!a)return i;
358const l=i.kind==="facePatch"?fl(i.points2D):fl([i.a2D,i.b2D]);if(!l)return i;const c=Mq(a,i.hostFaceId,l);return c===i.hostFaceId?i:(o=!0,{...i,hostFaceId:c})});return o?r:t}function e6(t,e,s){return(s?[s]:e.map(r=>r.id)).reduce((r,i)=>t6(r,i),t)}function yq(t,e,s){if(t.vertices.length<4){const p=fl(t.vertices);return p?_e(p.xMm,p.yMm,p.xMm+e,p.yMm+s):t.vertices}const[o,r,,i]=t.vertices,a={x:r.x-o.x,y:r.y-o.y},l={x:i.x-o.x,y:i.y-o.y},c=Math.hypot(a.x,a.y),d=Math.hypot(l.x,l.y);if(c<=0||d<=0){const p=fl(t.vertices);return p?_e(p.xMm,p.yMm,p.xMm+e,p.yMm+s):t.vertices}const u={x:a.x/c,y:a.y/c},h={x:l.x/d,y:l.y/d},x={x:Math.round(o.x+u.x*e),y:Math.round(o.y+u.y*e)},f={x:Math.round(o.x+h.x*s),y:Math.round(o.y+h.y*s)};return[o,x,{x:Math.round(x.x+h.x*s),y:Math.round(x.y+h.y*s)},f]}function wq(t){let e=5381;for(let s=0;s<t.length;s+=1)e=(e<<5)+e^t.charCodeAt(s);return`ted_${(e>>>0).toString(36)}`}function gw(t){if(Array.isArray(t))return`[${t.map(gw).join(",")}]`;if(t&&typeof t=="object"){const e=t;return`{${Object.keys(e).sort().map(s=>`${JSON.stringify(s)}:${gw(e[s])}`).join(",")}}`}return JSON.stringify(t)}function kq(t){return t.kind==="polygon"?{id:t.id,kind:t.kind,sourceTool:t.sourceTool,vertices:t.vertices,holes:t.holes??[],heightMm:Math.round(t.heightMm??0),baseHeightMm:Math.round(t.baseHeightMm??0),color:t.color??"",faces:t.faces??{}}:t.kind==="facePatch"?{id:t.id,kind:t.kind,hostEntityId:t.hostEntityId,hostFaceId:t.hostFaceId,points2D:t.points2D,holes2D:t.holes2D??[],depthMm:Math.round(t.depthMm??0),color:t.color??"",faces:t.faces??{}}:t.kind==="faceSplit"?{id:t.id,kind:t.kind,hostEntityId:t.hostEntityId,hostFaceId:t.hostFaceId,a2D:t.a2D,b2D:t.b2D}:t.kind==="faceCornerArc"?{id:t.id,kind:t.kind,hostEntityId:t.hostEntityId,hostFaceId:t.hostFaceId,corner:t.corner,radiusMm:t.radiusMm,verticalThroughCut:!!t.verticalThroughCut,faces:t.faces??{}}:{id:t.id,kind:t.kind}}function vq(t,e){const s=new Set(e.entityIds);for(const r of t)r.groupId===e.id&&s.add(r.id);const o=new Set(t.filter(r=>r.kind==="polygon"&&s.has(r.id)).map(r=>r.id));for(const r of t)(r.kind==="facePatch"||r.kind==="faceSplit"||r.kind==="faceCornerArc")&&(s.has(r.hostEntityId)||o.has(r.hostEntityId))&&s.add(r.id);return t.filter(r=>s.has(r.id))}function jq(t){const e=t.filter(s=>s.kind==="polygon");if(!e.length)return null;for(const s of e)if(t.some(o=>(o.kind==="facePatch"||o.kind==="faceSplit"||o.kind==="faceCornerArc")&&o.hostEntityId===s.id))return s;return e[0]}function _q(t,e){if(t.id===e)return"host";const s=fl(t.vertices),o=Math.round(t.heightMm??0);if(!s)return"block";const r=Math.min(s.widthMm,s.heightMm),i=Math.max(s.widthMm,s.heightMm);return i>600&&o<=40?"slab":o>80&&r<=180&&i<=260?"leg":(t.baseHeightMm??0)>0&&o<=80?"shelf":"block"}function Eq(t){const e=fl(t.points2D);return Math.round(t.depthMm??0)<0?t.hostFaceId==="top"?"basin":"niche":e?e.widthMm<=42||e.heightMm<=42?"flute":e.heightMm<=260&&e.widthMm>=e.heightMm*1.3?"drawer":e.heightMm>=e.widthMm*.8?"door":"patch":"patch"}function bw(t,e,s,o){const r=e.find(u=>u.id===s);if(!r)return null;const i=e6(t,e,s),a=vq(i,r);if(!a.length)return null;const l=jq(a),c=a.map(u=>u.kind==="polygon"?{id:u.id,kind:u.kind,role:_q(u,(l==null?void 0:l.id)??null),bboxMm:fl(u.vertices)??void 0,heightMm:Math.round(u.heightMm??0),baseHeightMm:Math.round(u.baseHeightMm??0),color:u.color}:u.kind==="facePatch"?{id:u.id,kind:u.kind,role:Eq(u),hostEntityId:u.hostEntityId,hostFaceId:u.hostFaceId,bboxMm:fl(u.points2D)??void 0,depthMm:Math.round(u.depthMm??0),color:u.color}:u.kind==="faceSplit"?{id:u.id,kind:u.kind,role:"split",hostEntityId:u.hostEntityId,hostFaceId:u.hostFaceId}:u.kind==="faceCornerArc"?{id:u.id,kind:u.kind,role:"arc",hostEntityId:u.hostEntityId,hostFaceId:u.hostFaceId}:{id:u.id,kind:u.kind,role:"block"}),d=wq(gw({group:{id:r.id,entityIds:r.entityIds.slice().sort(),widthMm:r.widthMm,depthMm:r.depthMm,heightMm:r.heightMm,templateId:r.templateId},entities:a.map(kq).sort((u,h)=>{const x=u.id??"",f=h.id??"";return x.localeCompare(f)})}));return{version:1,units:"mm",group:{id:r.id,name:r.name,templateId:r.templateId,widthMm:r.widthMm,depthMm:r.depthMm,heightMm:r.heightMm},...o?{clicked:o}:{},hostId:(l==null?void 0:l.id)??null,fingerprint:d,parts:c}}function Dq(t){const e=$4(t),s=[],o=[];if(!e)return{ok:!1,errors:["Edit spec must be a JSON object."],warnings:s};const r=Array.isArray(e.operations)?e.operations:[];r.length||o.push("Edit spec must include at least one operation.");const i=[];return r.forEach((a,l)=>{const c=$4(a);if(!c){o.push(`Operation ${l+1} is not an object.`);return}const d=Bh(c.type);if(d==="deleteParts"){const u=mq(c.partIds??c.part_ids);u.length||o.push(`Operation ${l+1} deleteParts requires partIds.`),i.push({type:d,partIds:u});return}if(d==="replaceRegionWithDrawerGrid"){const u=Bh(c.targetPartId??c.target_part_id);u||o.push(`Operation ${l+1} replaceRegionWithDrawerGrid requires targetPartId.`),i.push({type:d,targetPartId:u,rows:Ei(c.rows,1,12,4),columns:Ei(c.columns,1,8,1),gapMm:Ei(c.gapMm??c.gap_mm,0,40,8),depthMm:Ei(c.depthMm??c.depth_mm,-5e3,5e3,ib),color:ly(c.color,K7)});return}if(d==="addBlock"||d==="addSlab"||d==="addLeg"){i.push({type:d,hostId:Bh(c.hostId??c.host_id,""),xMm:Ei(c.xMm??c.x_mm,-5e4,5e4,0),yMm:Ei(c.yMm??c.y_mm,-5e4,5e4,0),widthMm:Ei(c.widthMm??c.width_mm,10,5e4,300),depthMm:Ei(c.depthMm??c.depth_mm,10,5e4,300),heightMm:Ei(c.heightMm??c.height_mm,1,2e4,100),baseHeightMm:Ei(c.baseHeightMm??c.base_height_mm,0,2e4,0),color:ly(c.color,rb),round:c.round===!0,taperBottom:c.taperBottom===void 0&&c.taper_bottom===void 0?void 0:Math.max(.05,Math.min(3,Z7(c.taperBottom??c.taper_bottom,1)))});return}if(d==="resizePart"){const u=Bh(c.partId??c.part_id);u||o.push(`Operation ${l+1} resizePart requires partId.`),i.push({type:d,partId:u,widthMm:c.widthMm===void 0&&c.width_mm===void 0?void 0:Ei(c.widthMm??c.width_mm,10,5e4,100),depthMm:c.depthMm===void 0&&c.depth_mm===void 0?void 0:Ei(c.depthMm??c.depth_mm,1,5e4,100),heightMm:c.heightMm===void 0&&c.height_mm===void 0?void 0:Ei(c.heightMm??c.height_mm,1,2e4,100)});return}if(d==="movePart"){const u=Bh(c.partId??c.part_id);u||o.push(`Operation ${l+1} movePart requires partId.`),i.push({type:d,partId:u,dxMm:Ei(c.dxMm??c.dx_mm,-2e4,2e4,0),dyMm:Ei(c.dyMm??c.dy_mm,-2e4,2e4,0),dzMm
358:Ei(c.dzMm??c.dz_mm,-2e4,2e4,0)});return}if(d==="setDepth"||d==="convertToRecess"){const u=Bh(c.partId??c.part_id);u||o.push(`Operation ${l+1} ${d} requires partId.`),i.push({type:d,partId:u,depthMm:d==="convertToRecess"?-Math.abs(Ei(c.depthMm??c.depth_mm,20,5e4,160)):Ei(c.depthMm??c.depth_mm,-5e4,5e4,ib)});return}if(d==="recolor"){const u=Bh(c.partId??c.part_id),h=c.faceId??c.face_id;u||o.push(`Operation ${l+1} recolor requires partId.`),i.push({type:d,partId:u,color:ly(c.color,rb),faceId:fq(h)?h:void 0});return}o.push(`Unsupported edit operation type: ${d||"missing"}`)}),o.length>0?{ok:!1,errors:o,warnings:s}:{ok:!0,spec:{version:1,units:"mm",operations:i},warnings:s}}function Fq(t){if(t.vertices.length<4)return null;const e=fl(t.vertices);if(!e||e.widthMm<=0||e.heightMm<=0)return null;const s=t.vertices[0],o=t.vertices[1],r=t.vertices[3],i=(o.x-s.x)/e.widthMm,a=(o.y-s.y)/e.widthMm,l=(r.x-s.x)/e.heightMm,c=(r.y-s.y)/e.heightMm;return d=>({x:Math.round(s.x+i*d.x+l*d.y),y:Math.round(s.y+a*d.x+c*d.y)})}function Cq(t,e){return{...t,vertices:t.vertices.map(e)}}function Nq(t,e,s,o={}){const r=new Set(s.map(a=>a.id)),i=s.filter(a=>a.groupId===e).map(a=>a.id);return t.map(a=>{if(a.id!==e)return a;const l=[...new Set([...a.entityIds,...i])].filter(c=>r.has(c));return{...a,...o,entityIds:l}})}function Iq(t,e,s){const o=[],r=t.find(M=>M.id===s.targetPartId);let i=null,a="side-0",l=null,c=s.depthMm??ib;if((r==null?void 0:r.kind)==="facePatch")i=r.hostEntityId,a=r.hostFaceId,l=fl(r.points2D),c=s.depthMm??Math.max(1,Math.round(r.depthMm??ib));else if((r==null?void 0:r.kind)==="polygon"){const M=An(r,"side-0");M&&(i=r.id,a="side-0",l={xMm:0,yMm:0,widthMm:Math.round(M.widthMm),heightMm:Math.round(M.heightMm)})}if(!i||!l||l.widthMm<20||l.heightMm<20)return{entities:t,createdIds:[],warnings:["לא מצאתי אזור מתאים להחלפה במגירות."]};const d=new Set([s.targetPartId]);for(const M of t){if(M.kind!=="facePatch"||M.hostEntityId!==i||M.hostFaceId!==a||M.groupId!==e)continue;const g=fl(M.points2D);g&&(xq(g,l)||pq(g,l))&&d.add(M.id)}const u=Math.max(1,s.rows),h=Math.max(1,s.columns??1),x=Math.max(0,s.gapMm??8),f=(l.widthMm-x*(h-1))/h,p=(l.heightMm-x*(u-1))/u;if(f<10||p<10)return{entities:t,createdIds:[],warnings:["אזור המגירות קטן מדי לחלוקה שביקשת."]};const b=[];for(let M=0;M<u;M+=1)for(let g=0;g<h;g+=1){const w={xMm:Math.round(l.xMm+g*(f+x)),yMm:Math.round(l.yMm+M*(p+x)),widthMm:Math.round(f),heightMm:Math.round(p)},k=lo(i,a,q7(w),e);k&&b.push({...k,depthMm:Math.round(c),color:s.color??K7})}return b.length?{entities:[...t.filter(M=>!d.has(M.id)),...b],createdIds:b.map(M=>M.id),warnings:o}:(o.push("לא הצלחתי ליצור מגירות תקינות באזור המבוקש."),{entities:t,createdIds:[],warnings:o})}function Tq(t,e){const s=Dq(t);if(!s.ok){const x=s;return{ok:!1,reason:"invalid",message:x.errors.join(" "),warnings:x.warnings}}const o=bw(e.entities,e.furnitureGroups,e.groupId);if(!o)return{ok:!1,reason:"missing_group",message:"לא מצאתי את התבנית לעריכה.",warnings:s.warnings};if(e.expectedFingerprint&&o.fingerprint!==e.expectedFingerprint)return{ok:!1,reason:"stale",message:"התבנית השתנתה מאז שביקשת את העריכה. כדאי לשלוח את הבקשה שוב על הגרסה העדכנית.",warnings:s.warnings};let r=t6(e.entities,e.groupId),i=null;const a=[...s.warnings],l=e.groupId;let c={};const d=o.hostId?r.find(x=>x.id===o.hostId&&x.kind==="polygon")??null:null;for(const x of s.spec.operations){if(x.type==="deleteParts"){if(o.hostId&&x.partIds.includes(o.hostId))return{ok:!1,reason:"invalid",message:"לא החלתּי את העריכה כי היא הייתה מוחקת את גוף התבנית מהקנבס.",warnings:a};for(const f of x.partIds)r=M3(r,f);continue}if(x.type==="replaceRegionWithDrawerGrid"){const f=Iq(r,l,x);r=f.entities,a.push(...f.warnings),i=f.createdIds[0]??i;continue}if(x.type==="addBlock"||x.type==="addSlab"||x.type==="addLeg"){const f=(x.hostId?r.find(g=>g.id===x.hostId&&g.kind==="polygon")??null:d)??null,p=x.type==="addLeg"?Da({origin:{x:x.xMm,y:x.yMm},widthMm:x.widthMm,depthMm:x.depthMm,heightMm:x.heightMm,baseHeightMm:x.baseHeightMm,color:x.color??rb,groupId:l,round:x.round,taperBottom:x.taperBottom}):ee({origin:{x:x.xMm,y:x.yMm},widthMm:x.widthMm,depthMm:x.depthMm,heightMm:x.heightMm,baseHeightMm:x.baseHeightMm,color:x.color??rb,groupId:l}),b=f?Fq(f):null,M=b?Cq(p,b):p;r=[...r,M],i=M.id;continue}if(x.type==="resizePart"){const f=r.find(p=>p.id===x.partId);if((f==null?void 0:f.kind)==="polygon"){const p=fl(f.vertices),b=f.vertices.length>=2?Math.round(Math.hypot(f.vertices[1].x-f.vertices[0].x,f.vertices[1].y-f.vertices[0].y)):(p==null?void 0:p.widthMm)??0,M=f.vertices.length>=4?Math.round(Math.hypot(f.vertices[3].x-f.vertices[0].x,f.vertices[3].y-f.vertices[0].y)):(p==null?void 0:p.heightMm)??0,g=x.widthMm??b,w=x.depthMm??M,k={...f,vertices:f.sourceTool==="rectangle"?yq(f,g,w):f.vertices,heightMm:x.heightMm??f.heightMm};r=Xu(r,f,k),o.hostId===f.id&&(c={...c,...x.widthMm!==void 0?{widthMm:x.widthMm}:{},...x.depthMm!==void 0?{depthMm:x.depthMm}:{},...x.heightMm!==void 0?{heightMm:x.heightMm}:{}})}else r=r.map(p=>{if(p.id!==x.partId)return p;if(p.kind==="facePatch"){const b=fl(p.points2D);if(!b)return p;const M=x.widthMm??b.widthMm,g=x.heightMm??b.heightMm,w={xMm:Math.round(b.xMm+(b.widthMm-M)/2),yMm:Math.round(b.yMm+(b.heightMm-g)/2),widthMm:M,heightMm:g};return{...p,points2D:q7(w)}}return p});i=x.partId;continue}if(x.type==="movePart"){const f=x.dxMm??0,p=x.dyMm??0,b=x.dzMm??0;r=r.map(M=>M.id!==x.partId?M:M.kind==="polygon"?{...M,vertices:M.vertices.map(g=>({x:g.x+f,y:g.y+p})),baseHeightMm:b?Math.max(0,Math.round((M.baseHeightMm??0)+b)):M.baseHeightMm}:M.kind==="facePatch"?{...M,points2D:M.points2D.map(g=>({x:g.x+f,y:g.y+p}))}:M),i=x.partId;continue}if(x.type==="setDepth"||x.type==="convertToRecess"){r=r.map(f=>f.id===x.partId&&f.kind==="facePatch"?{...f,depthMm:x.depthMm}:f),i=x.partId;continue}x.type==="recolor"&&(r=r.map(f=>f.id!==x.partId?f:x.faceId&&(f.kind==="polygon"||f.kind==="facePatch")?{...f,faces:{...f.faces??{},[x.faceId]:{color:x.color}}}:f.kind==="polygon"||f.kind==="facePatch"||f.kind==="segment"||f.kind==="faceSplit"||f.kind==="faceCornerArc"?{...f,color:x.color}:f),i=x.partId)}const u=Nq(e.furnitureGroups,l,r,c),h=bw(r,u,l);return h!=null&&h.hostId?{ok:!0,entities:r,furnitureGroups:u,selectedEntityId:i??o.hostId,warnings:a}:{ok:!1,reason:"invalid",message:"לא החלתּי את העריכה כי היא הייתה מוחקת את גוף התבנית מהקנבס.",warnings:a}}function ja(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function om(t){return Array.isArray(t)?t:[]}function Xc(t,e){const s=Number(t);return Number.isFinite(s)?s:e}function zg(t,e){const s=new Set;return t.map(o=>{if(o.id&&!s.has(o.id))return s.add(o.id),o;const r=`${e}_${Date.now()}_${Math.random().toString(36).slice(2,8)}`;return s.add(r),{...o,id:r}})}function Sq(t){const e=ja(t),s=Xc(e==null?void 0:e.scale,1),o=Xc(e==null?void 0:e.planRotationDeg,0);return{scale:s>0?s:1,calibrated:(e==null?void 0:e.calibrated)===!0,...(e==null?void 0:e.totalAreaSqm)!=null&&Number.isFinite(Number(e.totalAreaSqm))?{totalAreaSqm:Number(e.totalAreaSqm)}:{}
358,planRotationDeg:o===90||o===180||o===270?o:0,...ja(e==null?void 0:e.referenceSegment)?{referenceSegment:e.referenceSegment}:{}}}function Pq(t){const e=ja(t);if(!e)return null;const s=Xc(e.rotationDeg,0),o=Xc(e.txMm,0),r=Xc(e.tyMm,0);return s===0&&o===0&&r===0?null:{rotationDeg:s,txMm:o,tyMm:r}}function n6(t){return t==="not_required"||t==="pending"||t==="aligned"}function o6(t,e,s,o){return t===0||!e?"not_required":s?"aligned":o.has(e)?"not_required":"pending"}function cy(t){const e=ja(t);if(!e)return null;const s=e.type==="gable"||e.type==="hip"?e.type:"flat",o=e.finish==="tiles"?"tiles":"smooth",r=e.ridgeDirection==="long-axis"||e.ridgeDirection==="short-axis"?e.ridgeDirection:"auto",i=ja(e.material),a=ja(e.footprintOverride),l=h=>{const x=om(h).map(ja).filter(Boolean).map(f=>({x:Number(f.x),y:Number(f.y)})).filter(f=>Number.isFinite(f.x)&&Number.isFinite(f.y));return x.length>=3?x:null},c=l(a==null?void 0:a.outer),d=om(a==null?void 0:a.holes).map(l).filter(h=>h!==null),u=c&&typeof(a==null?void 0:a.sourceFootprintSignature)=="string"?{outer:c,holes:d,sourceFootprintSignature:a.sourceFootprintSignature}:void 0;return{type:s,finish:o,footprintMode:e.footprintMode==="manual"&&u?"manual":"auto",...u?{footprintOverride:u}:{},pitchDeg:Math.min(60,Math.max(5,Xc(e.pitchDeg,30))),overhangMm:Math.min(2e3,Math.max(0,Xc(e.overhangMm,s==="flat"?0:300))),parapetHeightMm:Math.min(2500,Math.max(0,Xc(e.parapetHeightMm,1e3))),thicknessMm:Math.min(1e3,Math.max(50,Xc(e.thicknessMm,s==="flat"?200:180))),ridgeDirection:r,material:{...typeof(i==null?void 0:i.color)=="string"?{color:i.color}:{},...ja(i==null?void 0:i.texture)?{texture:i.texture}:{},...NA(i==null?void 0:i.preset)?{preset:i.preset}:{}}}}function X4(t,e){const s=Qg(zg(om(t.walls),"wall"),e),o=new Set(s.map(a=>a.id)),r=Db(t.sketch),i=e6(r.entities,r.furnitureGroups);return{walls:s,beams:zg(om(t.beams),"beam").filter(a=>{var c,d,u,h;const l=Math.hypot(Number((c=a==null?void 0:a.end)==null?void 0:c.x)-Number((d=a==null?void 0:a.start)==null?void 0:d.x),Number((u=a==null?void 0:a.end)==null?void 0:u.y)-Number((h=a==null?void 0:a.start)==null?void 0:h.y));return Number.isFinite(l)&&l>0&&Number.isFinite(Number(a==null?void 0:a.widthMm))&&Number(a.widthMm)>0&&Number.isFinite(Number(a==null?void 0:a.heightMm))&&Number(a.heightMm)>0}),openings:zg(om(t.openings),"opening"),furniture:zg(om(t.furniture),"furn"),calibration:Sq(t.calibration),traceRoomLabels:P7(t.traceRoomLabels),roomFloorOverrides:ja(t.roomFloorOverrides)??{},roomFloorRegions:ja(t.roomFloorRegions)??{},wallFaceRegions:ja(t.wallFaceRegions)??{},roomCeilingOverrides:ja(t.roomCeilingOverrides)??{},wallElectricalFixtures:PB(t.wallElectricalFixtures,o),wallNotes:QB(t.wallNotes,o),viewportNotes:e9(t.viewportNotes),sketchEntities:i,sketchFurnitureGroups:r.furnitureGroups??[]}}function Aq(t,e,s){var c;const o=ja(t),r=ja(o==null?void 0:o._levels),i=om(r==null?void 0:r.levels).map(ja).filter(Boolean);if(i.length>0){const d=[],u={},h=new Set,x=new Set;let f=e.imageStoragePath,p=e.imageFilename??((c=e.imageStoragePath)==null?void 0:c.split("/").at(-1))??null;i.forEach((_,j)=>{let v=typeof _.id=="string"&&_.id?_.id:`level_${j+1}`;for(;h.has(v);)v=`${v}_${Math.random().toString(36).slice(2,6)}`;h.add(v);const C=typeof _.imageStoragePath=="string"&&_.imageStoragePath.trim()?_.imageStoragePath:null,N=C??f,L=(typeof _.imageFilename=="string"&&_.imageFilename.trim()?_.imageFilename:null)??(C?C.split("/").at(-1)??null:p),A=Pq(_.imageAlign),W=n6(_.alignmentStatus)?_.alignmentStatus:o6(j,N,A,x);d.push({id:v,name:typeof _.name=="string"&&_.name.trim()?_.name:lD(j),visible:_.visible!==!1,slabThicknessMm:Math.min(1e3,Math.max(50,Xc(_.slabThicknessMm,Op))),imageStoragePath:N,imageFilename:L,imageAlign:A,alignmentStatus:W}),N&&(x.add(N),f=N,p=L),u[v]=X4(_,s)});const b=typeof(r==null?void 0:r.activeLevelId)=="string"?r.activeLevelId:"",M=d.some(_=>_.id===b)?b:d[0].id,g=Object.prototype.hasOwnProperty.call(r??{},"buildingRoof"),w=[...i].reverse().map(_=>cy(_.roof)).find(_=>_!==null)??null,k=g?cy(r==null?void 0:r.buildingRoof):w;return{metas:d,buckets:u,activeLevelId:M,buildingRoof:k}}const a=X4({walls:e.walls,beams:o==null?void 0:o._beams,openings:e.openings,furniture:e.furniture,calibration:e.calibration,traceRoomLabels:o==null?void 0:o._traceRoomLabels,roomFloorOverrides:o==null?void 0:o._roomFloorOverrides,roomFloorRegions:o==null?void 0:o._roomFloorRegions,wallFaceRegions:o==null?void 0:o._wallFaceRegions,wallElectricalFixtures:o==null?void 0:o._wallElectricalFixtures,wallNotes:o==null?void 0:o._wallNotes,viewportNotes:o==null?void 0:o._viewportNotes,sketch:o==null?void 0:o._floorplanSketch},s);return{metas:[$y({imageStoragePath:e.imageStoragePath,imageFilename:e.imageFilename})],buckets:{[Nf]:a},activeLevelId:Nf,buildingRoof:cy(o==null?void 0:o._buildingRoof)}}function Lq(t,e,s,o=null){const r=new Set,i=t.map((a,l)=>{const c=e(a.id),{sketchEntities:d,sketchFurnitureGroups:u,...h}=c,x=n6(a.alignmentStatus)?a.alignmentStatus:o6(l,a.imageStoragePath,a.imageAlign,r),f={id:a.id,name:a.name,visible:a.visible,slabThicknessMm:a.slabThicknessMm,imageStoragePath:a.imageStoragePath,imageFilename:a.imageFilename,imageAlign:a.imageAlign,alignmentStatus:x,...h,sketch:MD(d,u)};return a.imageStoragePath&&r.add(a.imageStoragePath),f});return{version:1,activeLevelId:s,buildingRoof:o,levels:i}}function Oc(t,e){var o;return`${((o=/^[a-zA-Z]+/.exec(t))==null?void 0:o[0])||e}_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function Wq(t,e){if(!t.includes("|"))return t;const s=t.split("|");return s.every(o=>e.has(o))?s.map(o=>e.get(o)).sort().join("|"):t}function $g(t,e){const s={};for(const[o,r]of Object.entries(t))s[e(o)]=r;return s}function Rq(t,e){const s=new Map;for(const a of t)s.set(a.id,Oc(a.id,"sk"));const o=a=>s.get(a)??a,r=t.map(a=>{const l=structuredClone(a);return l.id=o(a.id),typeof l.hostEntityId=="string"&&(l.hostEntityId=o(l.hostEntityId)),Array.isArray(l.containedArcIds)&&(l.containedArcIds=l.containedArcIds.map(o)),l}),i=e.map(a=>{const l=structuredClone(a);return l.id=Oc(a.id,"group"),l.entityIds=a.entityIds.map(o),l});return{entities:r,groups:i}}function Oq(t){const e=new Map,s=t.walls.map(x=>{const f=Oc(x.id,"wall");return e.set(x.id,f),structuredClone({...x,id:f})}),o=x=>e.get(x)??x,r=new Map,i=t.openings.map(x=>
358{const f=structuredClone(x);return f.id=Oc(x.id,"opening"),f.wallId=o(x.wallId),x.cornerGroupId&&(r.has(x.cornerGroupId)||r.set(x.cornerGroupId,Oc(x.cornerGroupId,"corner")),f.cornerGroupId=r.get(x.cornerGroupId)),f}),a=t.furniture.map(x=>structuredClone({...x,id:Oc(x.id,"furn")})),l=t.beams.map(x=>structuredClone({...x,id:Oc(x.id,"beam")})),c=x=>Wq(x,e),d=x=>{const f=x.lastIndexOf("__");return f===-1?x:`${o(x.slice(0,f))}${x.slice(f)}`},u=Rq(t.sketchEntities,t.sketchFurnitureGroups),h=u.groups.map(x=>x.wallId?{...x,wallId:o(x.wallId)}:x);return{walls:s,beams:l,openings:i,furniture:a,calibration:structuredClone(t.calibration),traceRoomLabels:structuredClone(t.traceRoomLabels),roomFloorOverrides:$g(structuredClone(t.roomFloorOverrides),c),roomFloorRegions:$g(structuredClone(t.roomFloorRegions),c),wallFaceRegions:$g(structuredClone(t.wallFaceRegions),d),roomCeilingOverrides:$g(structuredClone(t.roomCeilingOverrides),c),wallElectricalFixtures:t.wallElectricalFixtures.map(x=>structuredClone({...x,id:Oc(x.id,"fixture"),wallId:o(x.wallId)})),wallNotes:t.wallNotes.map(x=>structuredClone({...x,id:Oc(x.id,"note"),wallId:o(x.wallId)})),viewportNotes:t.viewportNotes.map(x=>structuredClone({...x,id:Oc(x.id,"vnote")})),sketchEntities:u.entities,sketchFurnitureGroups:h}}function s6(t){return!t||t.rotationDeg===0&&t.txMm===0&&t.tyMm===0}function ab(t,e,s){const o=t.x*e,r=t.y*e;if(s6(s))return{x:o,y:r};const i=s.rotationDeg*Math.PI/180,a=Math.cos(i),l=Math.sin(i);return{x:o*a-r*l+s.txMm,y:o*l+r*a+s.tyMm}}function lb(t,e,s){const o=e!==0?e:1;if(s6(s))return{x:t.x/o,y:t.y/o};const r=-s.rotationDeg*Math.PI/180,i=Math.cos(r),a=Math.sin(r),l=t.x-s.txMm,c=t.y-s.tyMm;return{x:(l*i-c*a)/o,y:(l*a+c*i)/o}}function Hq(t,e,s){return t.map(o=>({...o,start:lb(ab(o.start,e.scale,e.align),s.scale,s.align),end:lb(ab(o.end,e.scale,e.align),s.scale,s.align)}))}function Bq(t,e,s,o){const r=e.x-t.x,i=e.y-t.y,a=Math.hypot(r,i);if(a<1e-6)return null;const l=o.x-s.x,c=o.y-s.y,u=Math.hypot(l,c)/a;if(!Number.isFinite(u)||u<=0)return null;const h=Math.atan2(c,l)-Math.atan2(i,r),x=h*180/Math.PI,f=Math.cos(h),p=Math.sin(h),b=t.x*u,M=t.y*u;return{scale:u,align:{rotationDeg:x,txMm:s.x-(b*f-M*p),tyMm:s.y-(b*p+M*f)}}}const Vq=14;function zq({traceCanvasRef:t,underlayWalls:e,activeScale:s,activeAlign:o,onApply:r,onCancel:i}){const{t:a}=yn(),[l,c]=m.useState([]),[d,u]=m.useState([]),[h,x]=m.useState([]),f=l.length<2?1:2,p=m.useCallback(()=>{c([]),u([]),x([])},[]);m.useEffect(()=>{const g=w=>{w.key==="Escape"&&(w.preventDefault(),i())};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[i]);const b=m.useCallback(g=>{const w=t.current;if(!w)return;const k=g.currentTarget.getBoundingClientRect(),_=w.clientToImagePoint(g.clientX,g.clientY);if(!_)return;if(l.length<2){c(L=>[...L,_]),x(L=>[...L,{left:g.clientX-k.left,top:g.clientY-k.top,label:l.length+1,ghost:!1}]);return}if(d.length>=2)return;let j=_,v=null,C=Vq;for(const L of e)for(const A of[L.start,L.end]){const W=w.imagePointToClient(A);if(!W)continue;const S=Math.hypot(W.x-g.clientX,W.y-g.clientY);S<=C&&(C=S,j=A,v=W)}const N=ab(j,s,o),P=[...d,N];if(u(P),x(L=>[...L,{left:(v?v.x:g.clientX)-k.left,top:(v?v.y:g.clientY)-k.top,label:d.length+1,ghost:!0}]),P.length===2){const L=Bq(l[0],l[1],P[0],P[1]);if(!L){p();return}r(L)}},[t,l,d,e,s,o,r,p]),M=f===1?a("levels.alignStep1",{defaultValue:"סמנו שתי נקודות זהות על התוכנית החדשה (למשל שתי פינות של חדר המדרגות)"}):a("levels.alignStep2",{defaultValue:"עכשיו סמנו את אותן שתי נקודות על קווי הרפאים של הקומה שמתחת"});return n.jsxs("div",{className:"absolute inset-0 z-[55] cursor-crosshair",style:{pointerEvents:"auto"},onClick:b,children:[h.map((g,w)=>n.jsx("div",{className:"pointer-events-none absolute flex h-[22px] w-[22px] -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full border-2 border-white font-heebo text-[11px] font-black text-white shadow-[0_2px_8px_rgba(24,33,55,0.35)]",style:{left:g.left,top:g.top,background:g.ghost?"#182137":"#B4552D"},children:g.label},w)),n.jsx("div",{dir:"rtl",className:"absolute top-3 left-1/2 w-[min(680px,94%)] -translate-x-1/2",onClick:g=>g.stopPropagation(),children:n.jsxs("div",{className:"flex items-center gap-2.5 rounded-xl border border-[#B4552D]/35 bg-[#F7F4EF] px-3 py-2 font-heebo shadow-[0_10px_36px_rgba(24,33,55,0.18)]",children:[n.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-[#B4552D]",children:n.jsx(np,{size:16,className:"text-white",strokeWidth:2.2})}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"text-[10px] font-black tracking-wide text-[#182137]/55",children:[a("levels.alignTitle",{defaultValue:"יישור מול קומה תחתונה"})," · ",a("levels.alignStepCounter",{step:f,defaultValue:`שלב ${f} מתוך 2`})]}),n.jsx("p",{className:"truncate text-[12.5px] font-bold leading-snug text-[#182137]",title:M,children:M})]}),n.jsxs("button",{type:"button",onClick:p,disabled:h.length===0,className:"flex shrink-0 items-center gap-1 rounded-lg border border-[#182137]/12 bg-white px-2.5 py-1.5 text-[11px] font-bold text-[#182137] transition-colors hover:bg-[#
358E8DFD3] disabled:cursor-not-allowed disabled:opacity-40",children:[n.jsx(zu,{size:13}),a("levels.alignRestart",{defaultValue:"התחל מחדש"})]}),n.jsxs("button",{type:"button",onClick:i,className:"flex shrink-0 items-center gap-1 rounded-lg border border-[#182137]/12 bg-white px-2.5 py-1.5 text-[11px] font-bold text-[#182137] transition-colors hover:bg-[#E8DFD3]",children:[n.jsx(Gr,{size:13}),a("common.cancel",{defaultValue:"ביטול"})]})]})})]})}const b1=new Map,Vx=new Map,Mw="fp_thumb_v1:",$q=2e6;function Xq(t){try{return window.localStorage.getItem(Mw+t)}catch{return null}}function Yq(t,e){var s;try{let o=0;for(let r=0;r<window.localStorage.length;r+=1){const i=window.localStorage.key(r);i!=null&&i.startsWith(Mw)&&(o+=((s=window.localStorage.getItem(i))==null?void 0:s.length)??0)}if(o+e.length>$q)return;window.localStorage.setItem(Mw+t,e)}catch{}}const Gq=3;let M1=0;const r6=[];function Uq(){return M1<Gq?(M1+=1,Promise.resolve()):new Promise(t=>{r6.push(()=>{M1+=1,t()})})}function dy(){var t;M1-=1,(t=r6.shift())==null||t()}let zx=null;function Kq(t){return zx||(zx=new dI({antialias:!0,alpha:!0}),zx.outputColorSpace=gm),zx.setSize(t,t),zx}function Zq(t,e){const s=b1.get(t);if(s)return Promise.resolve(s);const o=Xq(t);if(o)return b1.set(t,o),Promise.resolve(o);const r=Vx.get(t);if(r)return r;const i=Uq().then(()=>new Promise((a,l)=>{const c=new db;mb(c),c.load(t,d=>{try{const u=new aI;u.background=null,u.add(new lI(16777215,1.2));const h=new Yk(16777215,1);h.position.set(3,5,4),u.add(h);const x=new Yk(16777215,.4);x.position.set(-2,3,-2),u.add(x);const f=d.scene;u.add(f);const p=new Hw().setFromObject(f),b=p.getSize(new le),M=p.getCenter(new le),g=Math.max(b.x,b.y,b.z),w=new cI(35,1,.01,100),k=g*2.2;
358w.position.set(M.x+k*.6,M.y+k*.4,M.z+k*.6),w.lookAt(M);const _=Kq(e);_.render(u,w);const j=_.domElement.toDataURL("image/png");b1.set(t,j),Yq(t,j),Vx.delete(t),dy(),u.remove(f),f.traverse(v=>{if(v.geometry&&v.geometry.dispose(),v.material){const C=v.material;Array.isArray(C)?C.forEach(N=>N.dispose()):C.dispose()}}),a(j)}catch(u){Vx.delete(t),dy(),l(u)}},void 0,d=>{Vx.delete(t),dy(),l(d)})}));return Vx.set(t,i),i}const qq={sofas:um,armchairs:wf,living_tables:Q0,tv_units:CI,bookshelves:Qk,rugs:uT,beds:q_,nightstands:Q0,dressers:Ux,bedroom_wardrobes:Cf,mirrors:C_,dining_tables:Q0,dining_chairs:wf,sideboards:Ux,bar_area:zw,kitchen_cabinets:Cf,kitchen_islands:nE,appliances:xT,kitchen_sinks:Jh,bathtubs:Jh,showers:Jh,toilets:Jh,bathroom_sinks:Jh,laundry:Ux,desks:Q0,office_chairs:wf,office_storage:Ux,closets:Cf,shelving:Qk,outdoor_seating:wf,planters:sE},Hb=m.memo(function({furnitureType:e,customModelUrl:s,thumbnailImageUrl:o,subKey:r,label:i,color:a,size:l=48,fillContainer:c=!1,isActive:d}){const[u,h]=m.useState(null),[x,f]=m.useState(!1),p=s||(e?i3[e]:void 0);m.useEffect(()=>{if(o){h(o),f(!1);return}if(!p)return;const _=b1.get(p);if(_){h(_);return}let j=!1;const v=Math.min(l*2,256);return Zq(p,v).then(C=>{j||h(C)}).catch(()=>{j||f(!0)}),()=>{j=!0}},[p,l,o]);const b=`
359    rounded-lg flex items-center justify-center transition-all duration-150 overflow-hidden
360    ${d?"ring-2 ring-[#D84B2E] ring-offset-1 bg-[#FDF6F4]":"bg-gray-50 hover:bg-gray-100"}
361  `,M=c?{width:"100%",height:"100%"}:{width:l,height:l};if(u&&!x)return n.jsx("div",{className:b,style:M,children:n.jsx("img",{src:u,alt:i,style:{width:"100%",height:"100%",objectFit:"contain"},draggable:!1})});const g=qq[r],w=c?36:l*.45,k=c?28:l*.35;return n.jsx("div",{className:b,style:M,children:g?n.jsx(g,{size:w,style:{color:a},strokeWidth:1.5}):n.jsx("span",{className:"font-bold text-center leading-none",style:{color:a,fontSize:k},children:i.charAt(0)})})}),up=()=>Bo.from("user_furniture_models"),ik="user-furniture-models";function Of(t){if(/^https?:\/\//i.test(t))return t;const{data:e}=Bo.storage.from(ik).getPublicUrl(t);return e.publicUrl}async function Jq(t,e,s,o,r){const i=t.name.split(".").pop()||"glb",a=`${e}/${crypto.randomUUID()}.${i}`,{error:l}=await Bo.storage.from(ik).upload(a,t,{contentType:"model/gltf-binary",upsert:!1,cacheControl:"31536000"});if(l)throw new Error(`העלאה נכשלה: ${l.message}`);const{data:c,error:d}=await up().insert({user_id:e,name:s,storage_path:a,width_mm:o.w,depth_mm:o.d,height_mm:o.h,subcategory_id:r??null}).select().single();if(d)throw new Error(`שמירה נכשלה: ${d.message}`);return c}async function Qq(t){await Bo.storage.from(ik).remove([t.storage_path]);const{error:e}=await up().delete().eq("id",t.id);if(e)throw new Error(`מחיקה נכשלה: ${e.message}`)}function ak(t,e){const[s,o]=m.useState([]),[r,i]=m.useState(!1),a=m.useCallback(async()=>{if(!t)return;i(!0);const{data:h}=await up().select("*").eq("user_id",t).order("created_at",{ascending:!1});o(h||[]),i(!1)},[t]);m.useEffect(()=>{a()},[a,e]);const l=m.useCallback(async(h,x,f,p)=>{t&&(await Jq(h,t,x,f,p),await a())},[t,a]),c=m.useCallback(async h=>{await Qq(h),await a()},[a]),d=m.useCallback(async(h,x)=>{await up().update({name:x}).eq("id",h),await a()},[a]),u=m.useCallback(async(h,x)=>{await up().update({subcategory_id:x}).eq("id",h),await a()},[a]);return{models:s,loading:r,upload:l,remove:c,rename:d,setSubcategory:u,refresh:a}}const tJ={Sofa:um,BedDouble:q_,UtensilsCrossed:zw,CookingPot:nE,Bath:Jh,Monitor:C_,Archive:Ux,TreePine:sE,Sparkles:zl,Home:$u};function eJ(t){return t?tJ[t]??$u:$u}function i6(t){return{type:`sys_${t.id}`,label:t.name_he,hasModel:!0,tags:[t.name_he,"ספרייה"],dims:{w:t.width_mm,d:t.depth_mm,h:t.height_mm},isSmartModel:!!t.is_smart_model,editableStrategy:t.editable_strategy??"none"}}function a6(t){return{type:`user_${t.id}`,label:t.name,hasModel:!0,tags:[t.name,"שלי"],dims:{w:t.width_mm,d:t.depth_mm,h:t.height_mm}}}function Y4(t){const e=new Map;for(const s of t){const o=s.subcategory_id;if(!o)continue;const r=e.get(o)??[];r.push(s),e.set(o,r)}return e}function nJ(t,e){const s=[];return t.length>0&&s.push({key:"library",label:"ספריית רהיטים",icon:um,color:"#D84B2E",subs:[{key:"general",label:"כללי",entries:t.map(i6)}]}),e.length>0&&s.push({key:"my-uploads",label:"הרהיטים שלי",icon:zl,color:"#D84B2E",subs:[{key:"general",label:"כללי",entries:e.map(a6)}]}),s}function oJ(t,e,s,o){const r=new Map;for(const c of e){if(!c.enabled)continue;const d=r.get(c.room_id)??[];d.push(c),r.set(c.room_id,d)}const i=Y4(s),a=Y4(o),l=[];for(const c of t){if(!c.enabled)continue;const d=[];for(const u of r.get(c.id)??[]){const h=[...(i.get(u.id)??[]).map(i6),...(a.get(u.id)??[]).map(a6)];h.length!==0&&d.push({key:u.key,label:u.label_he,entries:h})}d.length!==0&&l.push({key:c.key,label:c.label_he,icon:eJ(c.icon),color:c.color??"#D84B2E",subs:d})}return l}function l6(t=[],e=[]){const[s,o]=m.useState([]),[r,i]=m.useState([]),[a,l]=m.useState(!1);m.useEffect(()=>{let h=!1;return l(!0),Promise.all([Bo.from("furniture_rooms").select("*").order("sort_order",{ascending:!0}),Bo.from("furniture_subcategories").select("*").order("sort_order",{ascending:!0})]).then(([x,f])=>{h||(o((x==null?void 0:x.data)||[]),i((f==null?void 0:f.data)||[]),l(!1))}).catch(()=>{h||(o([]),i([]),l(!1))}),()=>{h=!0}},[]);const c=m.useMemo(()=>s.length===0?nJ(t,e):oJ(s,r,t,e),[s,r,t,e]),d=m.useMemo(()=>{const h=new Map,x=new Map(s.map(f=>[f.id,f]));for(const f of r){const p=x.get(f.room_id);p&&h.set(f.id,{roomKey:p.key,subKey:f.key,roomLabel:p.label_he,subLabel:f.label_he})}return h},[s,r]),u=m.useMemo(()=>{const h=new Map;for(const x of r){const f=h.get(x.room_id)??[];f.push(x),h.set(x.room_id,f)}return s.map(x=>({id:x.id,key:x.key,label_he:x.label_he,sort_order:x.sort_order,enabled:x.enabled,subs:(h.get(x.id)??[]).map(f=>({id:f.id,key:f.key,label_he:f.label_he,sort_order:f.sort_order,enabled:f.enabled}))}))},[s,r]);return{catalog:c,loading:a,subcategoryIndex:d,rooms:u}}function sJ(t,e,s){const o=e.trim().toLowerCase();if(!o)return[];const r=[];for(const i of t)for(const a of i.subs)for(const l of a.entries)(l.tags.some(c=>c.toLowerCase().includes(o))||s(l).toLowerCase().includes(o)||l.type.includes(o))&&r.push({room:i,sub:a,entry:l});return r}function rJ(t){let e=0,s=0;for(const o of t.subs)e+=o.entries.length,s+=o.entries.filter(r=>r.hasModel).length;return{available:s,total:e}}function iJ(t){return{available:t.entries.filter(e=>e.hasModel).length,total:t.entries.length}}function G4(t,e){return`${t}:${e}`}function aJ({activeFurnitureType:t,onSelect:e,onBeginDrag:s,onEndDrag:o,userId:r,measurementUnit:i="cm"}){const{t:a}=yn(),l=xc(),[c,d]=m.useState(null),[u,h]=m.useState(null),[x,f]=m.useState(""),p=m.useRef(null),{models:b}=K_(),{models:M}=ak(r),{catalog:g}=l6(b,M),w=m.useMemo(()=>{const W={};for(const S of b)W[`sys_${S.id}`]=Z_(S.storage_path);for(const S of M)W[`user_${S.id}`]=Of(S.storage_path);return W},[b,M]),k=m.useMemo(()=>{const W={};for(const S of b){const B=_I(S.thumbnail_path);B&&(W[`sys_${S.id}`]=B)}return W},[b]),_=x.trim().length>0,j=m.useMemo(()=>_?sJ(g,x,W=>a(`furniture.${W.type}`,{defaultValue:W.label})):null,[x,g,_,a]),v=m.useCallback(W=>{d(S=>S===W?null:W),h(null)},[]),C=m.useCallback((W,S)=>{const B=G4(W,S);h(R=>R===B?null:B)},[]),N=m.useCallback(()=>{var W;
361f(""),(W=p.current)==null||W.focus()},[]),P=O("flex w-full items-center justify-between gap-2 rounded-[3px] border px-2.5 py-2 text-start transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#D85D43]/30",l?"border-white/12 bg-[#0A0A0A] hover:bg-white/[0.06]":"border-[#182137]/12 bg-white hover:bg-[#E8DFD3]"),L=W=>O("flex min-h-[46px] w-full items-center justify-between gap-2 rounded-[8px] border px-2.5 py-2 text-start transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#D85D43]/25",W?l?"border-[#EC7357]/45 bg-[#EC7357]/10":"border-[#D85D43]/35 bg-white":l?"border-white/10 bg-[#111111] hover:bg-white/[0.05]":"border-[#182137]/10 bg-white/80 hover:bg-white"),A=O("h-7 w-full rounded-[3px] border px-2 text-[12px] font-bold tabular-nums outline-none",l?"border-white/15 bg-[#0A0A0A] text-white focus:border-white/35":"border-[#182137]/12 bg-white text-[#182137] focus:border-[#182137]/40");return n.jsxs("div",{className:"flex h-full min-h-0 flex-1 flex-col font-heebo",children:[n.jsxs("div",{className:"relative mb-3 shrink-0",children:[n.jsx("input",{ref:p,type:"text",value:x,onChange:W=>f(W.target.value),placeholder:a("catalogUi.searchPlaceholder",{defaultValue:"חיפוש רהיט…"}),"aria-label":a("catalogUi.searchAria",{defaultValue:"חיפוש רהיט"}),className:A,dir:"rtl"}),x&&n.jsx("button",{type:"button",onClick:N,className:O("absolute left-1.5 top-1/2 -translate-y-1/2 rounded p-0.5 transition-colors",l?"text-white/40 hover:text-white/70":"text-[#182137]/40 hover:text-[#182137]"),"aria-label":a("catalogUi.clearSearch",{defaultValue:"נקה חיפוש"}),children:n.jsx(Gr,{size:12})})]}),n.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain",children:j?n.jsx(uJ,{results:j,activeFurnitureType:t,onSelect:e,onBeginDrag:s,onEndDrag:o,customModelUrls:w,thumbnailUrls:k,fpIsDark:l}):n.jsx("div",{className:"space-y-2",dir:"rtl",children:g.map(W=>{const{available:S,total:B}=rJ(W),R=c===W.key,z=W.icon;return n.jsxs("div",{className:"space-y-2",children:[n.jsxs("button",{type:"button",onClick:()=>v(W.key),"aria-expanded":R,"aria-controls":`furn-room-${W.key}`,className:P,children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[n.jsx(z,{className:"h-5 w-5 shrink-0 text-[#D85D43]",strokeWidth:1.8,"aria-hidden":!0}),n.jsx("span",{className:O("truncate text-[14px] font-black leading-tight tracking-tight",l?"text-white":"text-[#182137]"),style:{letterSpacing:"-0.02em"},children:a(`catalog.rooms.${W.key}`,{defaultValue:W.label})})]}),n.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[n.jsxs("span",{className:O("text-[10px] font-bold tabular-nums",l?"text-white/45":"text-[#182137]/45"),children:[S,"/",B]}),n.jsx(Yc,{className:O("h-4 w-4 shrink-0 transition-transform duration-150",R?"rotate-180":"rotate-0",l?"text-white/55":"text-[#182137]/55"),"aria-hidden":!0})]})]}),R?n.jsx("div",{id:`furn-room-${W.key}`,className:O("space-y-2 rounded-[8px] border p-2",l?"border-white/10 bg-white/[0.03]":"border-[#D85D43]/15 bg-[#F7F4EF]/70"),children:W.subs.map(X=>{const ft=iJ(X),tt=G4(W.key,X.key),G=u===tt;return n.jsxs("div",{className:"space-y-2",children:[n.jsxs("button",{type:"button",onClick:()=>C(W.key,X.key),"aria-expanded":G,"aria-controls":`furn-sub-${tt}`,className:L(G),children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[n.jsx("div",{className:O("flex h-7 w-7 shrink-0 items-center justify-center overflow-hidden rounded-[6px]",l?"bg-white/[0.04]":"bg-[#F7F4EF]"),children:n.jsx(Hb,{subKey:X.key,label:X.label,color:"#D85D43",size:18})}),n.jsx("span",{className:O("truncate text-[12.5px] font-extrabold leading-tight",l?"text-white":"text-[#182137]"),style:{letterSpacing:"-0.015em"},children:a(`catalog.subs.${X.key}`,{defaultValue:X.label})})]}),n.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[n.jsxs("span",{className:O("text-[9.5px] font-bold tabular-nums",l?"text-white/45":"text-[#182137]/45"),children:[ft.available,"/",ft.total]}),n.jsx(Yc,{className:O("h-4 w-4 shrink-0 transition-transform duration-150",G?"rotate-180":"rotate-0",l?"text-white/55":"text-[#182137]/55"),"aria-hidden":!0})]})]}),G?n.jsx("div",{id:`furn-sub-${tt}`,className:O("px-1 pb-1 pt-2.5",l?"border-t border-white/[0.08]":"border-t border-[#D85D43]/15"),children:n.jsx(lJ,{room:W,sub:X,activeFurnitureType:t,onSelect:e,onBeginDrag:s,onEndDrag:o,customModelUrls:w,thumbnailUrls:k,measurementUnit:i,fpIsDark:l})}):null]},X.key)})}):null]},W.key)})})})]})}function lJ({room:t,sub:e,activeFurnitureType:s,onSelect:o,onBeginDrag:r,onEndDrag:i,customModelUrls:a,thumbnailUrls:l,measurementUnit:c,fpIsDark:d}){return n.jsx("div",{className:"grid grid-cols-2 gap-2",children:e.entries.map(u=>{const h=s===u.type;return n.jsx(cJ,{entry:u,subKey:e.key,color:t.color,isActive:h,onSelect:o,onBeginDrag:r,onEndDrag:i,customModelUrl:a==null?void 0:a[u.type],thumbnailImageUrl:l==null?void 0:l[u.type],measurementUnit:c,fpIsDark:d},u.type)})})}function cJ({entry:t,subKey:e,color:s,isActive:o,onSelect:r,onBeginDrag:i,onEndDrag:a,customModelUrl:l,thumbnailImageUrl:c,measurementUnit:d,fpIsDark:u}){const{t:h}=yn(),x=t.dims,f=`${De(x.w,d)}×${De(x.d,d)} ${Ka(d)}`,p=!t.hasModel,b=h(`furniture.${t.type}`,{defaultValue:t.label});return n.jsxs("button",{onClick:p?void 0:()=>r(t.type,t.label),draggable:!p,onDragStart:p?void 0:M=>{i==null||i(t.type,t.label),U3(M.dataTransfer,{type:t.type,label:t.label})},onDragEnd:p?void 0:a,disabled:p,type:"button",title:p?h("catalogUi.comingSoon",{defaultValue:"בקרוב"}):h("catalogUi.placeHint",{defaultValue:"לחיצה: בחירת רהיט · אחר כך לחצו בכל אזור בתוכנית למיקום מדויק · גרירה: מיקום ישיר"}),className:O("relative flex flex-col items-center gap-1.5 rounded-[3px] border p-1.5 transition-colors select-none",p?"cursor-not-allowed border-dashed opacity-45 grayscale":o?u?"cursor-pointer border-[#
361EC7357] bg-[#EC7357]/15 shadow-[0_0_0_1px_rgba(236,115,87,0.42)]":"cursor-pointer border-[#D84B2E] bg-[#FDF1EC] shadow-[0_0_0_1px_rgba(216,75,46,0.18)]":u?"cursor-pointer border-white/12 bg-[#0A0A0A] hover:bg-white/[0.06]":"cursor-pointer border-[#182137]/12 bg-white hover:bg-[#E8DFD3]"),children:[o&&!p?n.jsx("span",{className:"absolute left-1.5 top-1.5 z-10 flex h-5 w-5 items-center justify-center rounded-full bg-[#D84B2E] text-white shadow-sm",children:n.jsx(Gc,{size:12,strokeWidth:3,"aria-hidden":!0})}):null,p?null:n.jsx(dJ,{entry:t}),n.jsx("div",{className:O("relative w-full aspect-square overflow-hidden rounded-[2px]",p?"bg-white/50":u?"bg-[#0A0A0A]":"bg-white"),children:n.jsx("div",{className:"absolute inset-1.5",children:n.jsx(Hb,{furnitureType:t.type,customModelUrl:l,thumbnailImageUrl:c,subKey:e,label:b,color:p?"#9ca3af":o?"#D84B2E":s,fillContainer:!0,isActive:o&&!p})})}),n.jsx("span",{className:O("text-[10.5px] font-bold leading-tight text-center line-clamp-2 tabular-nums",p?u?"text-white/35":"text-[#182137]/35":u?"text-white":"text-[#182137]"),children:b}),n.jsx("span",{className:O("text-[9px] leading-tight",u?"text-white/45":"text-[#182137]/45"),children:p?h("catalogUi.comingSoon",{defaultValue:"בקרוב"}):f})]})}function dJ({entry:t}){const{t:e}=yn();return t.isSmartModel?n.jsxs("div",{className:"absolute right-1.5 top-1.5 z-10 inline-flex items-center gap-0.5 rounded-full bg-emerald-50/95 px-1 py-0.5 text-[7px] font-extrabold text-emerald-700 shadow-sm ring-1 ring-emerald-100",children:[n.jsx(zl,{size:8}),e("catalogUi.smart",{defaultValue:"חכם"})]}):t.editableStrategy==="whole_model"?n.jsxs("div",{className:"absolute right-1.5 top-1.5 z-10 inline-flex items-center gap-0.5 rounded-full bg-amber-50/95 px-1 py-0.5 text-[7px] font-extrabold text-amber-700 shadow-sm ring-1 ring-amber-100",children:[n.jsx(k1,{size:8}),e("catalogUi.baked",{defaultValue:"אפוי"})]}):null}function uJ({results:t,activeFurnitureType:e,onSelect:s,onBeginDrag:o,onEndDrag:r,customModelUrls:i,thumbnailUrls:a,fpIsDark:l}){const{t:c}=yn();return t.length===0?n.jsx("div",{className:O("rounded-[3px] border border-dashed py-10 text-center text-[11px] font-medium",l?"border-white/20 text-white/45":"border-[#182137]/20 text-[#182137]/45"),children:c("catalogUi.noResults",{defaultValue:"לא נמצאו תוצאות"})}):n.jsxs("div",{className:"flex flex-col gap-2",dir:"rtl",children:[n.jsx("div",{className:O("mb-0.5 text-[10px] font-bold tabular-nums",l?"text-white/45":"text-[#182137]/45"),children:c("catalogUi.resultCount",{defaultValue:"{{count}} תוצאות",count:t.length})}),t.map(({room:d,sub:u,entry:h})=>{const x=e===h.type,f=!h.hasModel;return n.jsxs("button",{onClick:f?void 0:()=>s(h.type,h.label),draggable:!f,onDragStart:f?void 0:p=>{o==null||o(h.type,h.label),U3(p.dataTransfer,{type:h.type,label:h.label})},onDragEnd:f?void 0:r,disabled:f,type:"button",title:f?c("catalogUi.comingSoon",{defaultValue:"בקרוב"}):c("catalogUi.placeHint",{defaultValue:"לחיצה: בחירת רהיט · אחר כך לחצו בכל אזור בתוכנית למיקום מדויק · גרירה: מיקום ישיר"}),className:O("flex w-full items-center gap-2 rounded-[3px] border px-2.5 py-2 transition-colors",f?"cursor-not-allowed border-dashed opacity-50 grayscale":x?l?"cursor-pointer border-[#
361EC7357] bg-[#EC7357]/15":"cursor-pointer border-[#D84B2E] bg-[#FDF1EC]":l?"cursor-pointer border-white/12 bg-[#0A0A0A] hover:bg-white/[0.06]":"cursor-pointer border-[#182137]/12 bg-white hover:bg-[#E8DFD3]"),children:[n.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-[2px]",children:n.jsx(Hb,{furnitureType:h.type,customModelUrl:i==null?void 0:i[h.type],thumbnailImageUrl:a==null?void 0:a[h.type],subKey:u.key,label:c(`furniture.${h.type}`,{defaultValue:h.label}),color:f?"#9ca3af":x?"#D84B2E":d.color,size:32,isActive:x&&!f})}),n.jsxs("div",{className:"flex min-w-0 flex-col items-start",children:[n.jsx("span",{className:O("truncate text-[12px] font-black leading-tight",f?l?"text-white/35":"text-[#182137]/35":l?"text-white":"text-[#182137]"),children:c(`furniture.${h.type}`,{defaultValue:h.label})}),n.jsxs("span",{className:O("truncate text-[10px] font-bold",l?"text-white/45":"text-[#182137]/45"),children:[c(`catalog.rooms.${d.key}`,{defaultValue:d.label})," · ",c(`catalog.subs.${u.key}`,{defaultValue:u.label})]})]}),x?n.jsx(Gc,{size:14,className:"ms-auto shrink-0 text-[#D84B2E]"}):null]},h.type)})]})}function c6({value:t,onChange:e,defaultRoomKey:s="my-uploads",compact:o=!1,className:r=""}){const{rooms:i}=l6(),[a,l]=m.useState("");m.useEffect(()=>{if(a)return;if(t){for(const x of i)if(x.subs.some(f=>f.id===t)){l(x.id);return}}const h=i.find(x=>x.key===s)??i.find(x=>x.enabled);h&&l(h.id)},[i,t,a,s]);const c=m.useMemo(()=>{var h;return((h=i.find(x=>x.id===a))==null?void 0:h.subs.filter(x=>x.enabled))??[]},[i,a]);m.useEffect(()=>{if(c.length===0){t!==null&&e(null);return}c.some(x=>x.id===t)||e(c[0].id)},[c,t,e]);const u=`w-full px-2 ${o?"h-8 text-[11px]":"h-9 text-[12px]"} bg-white border border-gray-200 rounded-lg focus:outline-none focus:ring-1 focus:ring-[#EC7357]/50`;return n.jsxs("div",{className:`grid grid-cols-2 gap-1.5 ${r}`,dir:"rtl",children:[n.jsx("select",{value:a,onChange:h=>l(h.target.value),className:u,title:"חדר",children:i.filter(h=>h.enabled).map(h=>n.jsx("option",{value:h.id,children:h.label_he},h.id))}),n.jsxs("select",{value:t??"",onChange:h=>e(h.target.value||null),disabled:c.length===0,className:u,title:"תת-קטגוריה",children:[c.length===0&&n.jsx("option",{value:"",children:"— אין —"}),c.map(h=>n.jsx("option",{value:h.id,children:h.label_he},h.id))]})]})}const uy=["image/jpeg","image/png","image/webp","image/jpg"],hy=15,hJ=()=>Bo.from("user_furniture_models"),mJ=m.forwardRef(function({userId:e,onSuccess:s,disabled:o,variant:r="dropzone",hideCompactTrigger:i=!1,onBusyChange:a},l){const c=r==="compact",d=r==="dialog",{i18n:u}=jw(),{locale:h}=Yd(),x=h==="he"||u.language==="he",{checkTokensAndCall:f}=fb(),p=m.useRef(null),[b,M]=m.useState(!1),[g,w]=m.useState(!1),[k,_]=m.useState(""),[j,v]=m.useState(null),[C,N]=m.useState(null),[P,L]=m.useState(0),[A,W]=m.useState(null),[S,B]=m.useState(null),[R,z]=m.useState(null);m.useEffect(()=>{a==null||a(g)},[g,a]),m.useEffect(()=>()=>a==null?void 0:a(!1),[a]),m.useEffect(()=>{if(!g||!C)return;const pt=()=>{L(Math.max(0,Math.floor((Date.now()-C)/1e3)))};pt();const xt=window.setInterval(pt,1e3);return()=>window.clearInterval(xt)},[g,C]);const X=m.useCallback(pt=>e?uy.includes(pt.type)?pt.size>hy*1024*1024?x?`קובץ גדול מדי (מקסימום ${hy}MB)`:`File too large (max ${hy}MB)`:null:x?"פורמט לא נתמך — רק JPG, PNG או WEBP":"Unsupported format — only JPG, PNG or WEBP":x?"יש להתחבר כדי להשתמש בתכונה זו":"Please sign in to use this feature",[e,x]),ft=m.useCallback(pt=>{const xt=X(pt);if(xt){W(xt);return}W(null),z(pt)},[X]),tt=m.useCallback(()=>{z(null),p.current&&(p.current.value="")},[]),G=m.useCallback(async(pt,xt)=>{var _t,Ft;if(!e){W(x?"יש להתחבר כדי להשתמש בתכונה זו":"Please sign in to use this feature");return}z(null),W(null),w(!0),v(xt),N(Date.now()),L(0);try{_(x?"מעלה תמונה…":"Uploading image…");const Vt=pt.name.split(".").pop()||"png",vt=`${e}/floorplan-${xt}-${Date.now()}.${Vt}`,{error:Ht}
361=await Bo.storage.from("canvas-assets").upload(vt,pt,{cacheControl:"3600",upsert:!1});if(Ht)throw new Error(x?`העלאת תמונה נכשלה: ${Ht.message}`:`Image upload failed: ${Ht.message}`);const{data:{publicUrl:Tt}}=Bo.storage.from("canvas-assets").getPublicUrl(vt);_(xt==="meshy"?x?"יוצר מודל עם טקסטורות עשירות… זה לוקח 3-4 דקות":"Creating textured model… this takes 3-4 minutes":x?"יוצר מודל תלת-מימד… זה לוקח כדקה":"Creating 3D model… this takes about a minute");const Zt=xt==="meshy"?await NI(f,{image:Tt},"generate-3d-meshy",{timeoutPerRequest:12e4}):await II(f,{image:Tt,images:[Tt],seed:0,randomize_seed:!0,generate_color:!0,generate_normal:!0,generate_model:!0},"generate-3d-object",{timeoutPerRequest:12e4});if(!Zt.success){if(Zt.insufficientTokens){const gt=xt==="meshy"?12:3;throw new Error(x?`לא מספיק טוקנים. נדרשים: ${Zt.requiredTokens??gt}, יתרה: ${Zt.currentBalance??0}`:`Not enough tokens. Required: ${Zt.requiredTokens??gt}, balance: ${Zt.currentBalance??0}`)}throw new Error(Zt.user_message||Zt.error||(x?"יצירת המודל נכשלה":"Model creation failed"))}const At=((_t=Zt.data)==null?void 0:_t.model_file)||((Ft=Zt.data)==null?void 0:Ft.model_url);if(!At)throw new Error(x?"לא התקבל קובץ GLB מהשרת":"No GLB file received from server");_(x?"שומר בספרייה שלך…":"Saving to your library…");const ut=new Date().toLocaleDateString(x?"he-IL":"en-US"),kt=xt==="meshy"?x?"(טקסטורות)":"(textured)":"",{data:Et,error:ht}=await hJ().insert({user_id:e,name:x?`רהיט מתמונה ${ut}${kt?" "+kt:""}`:`Furniture from image ${ut}${kt?" "+kt:""}`,storage_path:At,width_mm:1e3,depth_mm:1e3,height_mm:1e3,subcategory_id:S}).select().single();if(ht||!Et)throw new Error(x?`שמירה נכשלה: ${(ht==null?void 0:ht.message)||"ללא תגובה"}`:`Save failed: ${(ht==null?void 0:ht.message)||"no response"}`);ln.success(x?"הרהיט נשמר ב״הרהיטים שלי״":"Furniture saved to My Furniture"),s(Et)}catch(Vt){const vt=Vt instanceof Error?Vt.message:x?"שגיאה לא ידועה":"Unknown error";W(vt),ln.error(vt)}finally{w(!1),_(""),N(null),v(null),p.current&&(p.current.value="")}},[e,f,s,S,x]),Y=m.useCallback(pt=>{var _t;const xt=(_t=pt.target.files)==null?void 0:_t[0];xt&&ft(xt)},[ft]),J=m.useCallback(pt=>{var _t;if(pt.preventDefault(),pt.stopPropagation(),M(!1),g||o||R)return;const xt=(_t=pt.dataTransfer.files)==null?void 0:_t[0];xt&&ft(xt)},[ft,g,o,R]),Mt=m.useCallback(pt=>{pt.preventDefault(),pt.stopPropagation(),!g&&!o&&!R&&M(!0)},[g,o,R]),Rt=m.useCallback(pt=>{pt.preventDefault(),pt.stopPropagation(),M(!1)},[]),it=m.useCallback(()=>{var pt;!g&&!o&&!R&&((pt=p.current)==null||pt.click())},[g,o,R]);m.useImperativeHandle(l,()=>({openPicker:it}),[it]);const st=!g&&(c?!!R:!0);return c&&i&&!(c&&(g||!!R||!!A))?n.jsx("input",{ref:p,type:"file",accept:uy.join(","),onChange:Y,className:"hidden"}):n.jsxs("div",{className:d?"flex w-full flex-col gap-4":c&&i?"flex flex-col gap-1.5 w-full":c?"flex flex-col gap-1.5 min-w-0 flex-1":void 0,children:[n.jsx("input",{ref:p,type:"file",accept:uy.join(","),onChange:Y,className:"hidden"}),c&&g&&n.jsxs("div",{className:"flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-lg bg-[#FDF6F4]/80 border border-[#EC7357]/30",children:[n.jsx("span",{className:"fp-mini-process-signal shrink-0","aria-hidden":!0}),n.jsx("span",{className:"text-[9px] font-semibold text-[#9a3d28] truncate",children:k||(x?"מעבד…":"Processing…")})]}),c&&!i&&!g&&!R&&n.jsxs("button",{type:"button",onClick:it,disabled:o,className:`w-full flex items-center justify-center gap-1 px-2 py-1.5 rounded-lg
362            border border-[#EC7357]/35 bg-white text-[#182137] text-[10px] font-bold
363            hover:bg-[#FDF6F4] hover:border-[#D84B2E]/50
364            disabled:opacity-50 disabled:cursor-not-allowed
365            transition-all cursor-pointer`,children:[n.jsx(C1,{size:12,className:"text-[#D84B2E] shrink-0",strokeWidth:2}),x?"תמונה ל 3D":"Image → 3D"]}),R&&!g?n.jsxs("div",{className:`
366            relative border-2 border-[#D85D43]/35 bg-[#F7F4EF]
367            ${d?"rounded-[14px] px-4 py-4":"rounded-xl px-3 py-3"}
368          `,children:[n.jsx("button",{type:"button",onClick:tt,className:"absolute left-2 top-2 flex h-6 w-6 items-center justify-center rounded-full text-[#182137]/45 hover:bg-[#
368E8E3DB] hover:text-[#182137]","aria-label":x?"ביטול":"Cancel",children:n.jsx(Gr,{size:12})}),n.jsxs("div",{dir:x?"rtl":"ltr",className:"flex flex-col gap-3",children:[n.jsx("span",{className:d?"text-right text-[19px] font-black leading-tight text-[#182137]":"text-center text-[10.5px] font-bold leading-tight text-[#182137]",children:x?"בחרו מסלול יצירה":"Choose creation mode"}),n.jsx("span",{className:d?"max-w-[560px] text-right text-[11px] font-bold leading-relaxed text-[#182137]/55":"px-2 text-center text-[9px] leading-tight text-gray-500 -mt-1",children:R.name.length>28?R.name.slice(0,28)+"…":R.name}),n.jsxs("div",{className:d?"grid w-full gap-3 sm:grid-cols-2":"grid w-full grid-cols-2 gap-2",children:[n.jsx(U4,{provider:"trellis",compact:!d,icon:n.jsx(_w,{size:d?19:16,strokeWidth:2.2}),title:x?"מהיר וחסכוני":"Fast and economical",description:x?"בחירה טובה לרוב הרהיטים ולבדיקת רעיון מהירה.":"Good for most furniture and quick concept checks.",time:x?"1-3 דקות":"1-3 minutes",tokens:x?"3 טוקנים":"3 tokens",technicalLabel:"Trellis",onClick:()=>G(R,"trellis")}),n.jsx(U4,{provider:"meshy",compact:!d,icon:n.jsx(OI,{size:d?19:16,strokeWidth:2.2}),title:x?"טקסטורות עשירות":"Rich textures",description:x?"כשחשוב לראות חומריות, פרטים ומראה איכותי יותר.":"When materials, detail, and richer surfaces matter.",time:x?"3-4 דקות":"3-4 minutes",tokens:x?"12 טוקנים":"12 tokens",technicalLabel:"Meshy",onClick:()=>G(R,"meshy")})]})]})]}):c?null:n.jsx("div",{onDrop:J,onDragOver:Mt,onDragLeave:Rt,onClick:it,className:`
369            relative flex flex-col items-center justify-center gap-1.5
370            px-3 rounded-xl border-2 transition-all select-none
371            ${d?g?"py-4 sm:py-5":"py-7":"py-4"}
372            ${g||o?"cursor-wait border-solid bg-[#E8E3DB]/55 border-[#EC7357]/35":b?"cursor-copy border-dashed bg-[#F8E6DE] border-[#D84B2E] shadow-[0_0_0_4px_rgba(216,75,46,0.15)]":"cursor-pointer border-dashed bg-[#F7F4EF] border-[#EC7357]/30 hover:border-[#D84B2E] hover:bg-[#E8E3DB]/45"}
373          `,children:g?n.jsx(fJ,{provider:j??"trellis",elapsedSeconds:P,progressMessage:k,isHebrew:x,compact:!d}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"relative",children:[n.jsx(C1,{size:22,className:b?"text-[#C04428]":"text-[#D84B2E]",strokeWidth:1.8}),n.jsx(zl,{size:11,className:"absolute -top-1 -left-1 text-amber-400",strokeWidth:2.5})]}),n.jsx("span",{className:`${d?"text-[15px] font-black":"text-[11px] font-bold"} ${b?"text-[#9a3d28]":"text-[#182137]"}`,children:b?x?"שחרר/י כאן":"Drop here":x?"העלו תמונה ברורה של רהיט או חפץ":"Upload a clear furniture or object photo"}),n.jsxs("span",{className:d?"flex items-center gap-1 text-[11px] font-bold text-[#182137]/48":"flex items-center gap-1 text-[9px] text-gray-500",children:[n.jsx(Ap,{size:d?11:9})," ",x?"JPG, PNG או WEBP עד 15MB · החל מ-3 טוקנים":"JPG, PNG or WEBP up to 15MB · from 3 tokens"]})]})}),st&&n.jsxs("div",{className:c?void 0:"mt-2",children:[n.jsx("div",{className:d?"mb-1.5 text-[10.5px] font-black text-[#182137]/55":"text-[9px] font-semibold text-gray-500 mb-1",children:x?"קטגוריה (חדר → תת)":"Category (room → sub)"}),n.jsx(c6,{value:S,onChange:B,compact:!0})]}),A&&n.jsxs("div",{className:"mt-2 flex items-start gap-1.5 px-2.5 py-2 rounded-lg bg-red-50 border border-red-200 text-[10px] text-red-600",children:[n.jsx(Dy,{size:12,className:"shrink-0 mt-0.5"}),n.jsx("span",{className:"leading-tight",children:A})]})]})});function fJ({provider:t,elapsedSeconds:e,progressMessage:s,isHebrew:o,compact:r}){const i=t==="meshy",l=Math.min(94,Math.max(9,Math.round(e/(i?210:105)*88)+8)),c=m.useMemo(()=>(i?[0,20,70,135,185]:[0,12,36,72,92]).reduce((f,p,b)=>e>=p?b:f,0),[e,i]),d=o?["מעלה ומנקה את תמונת המקור","מחלץ עומק וסילואטה",i?"בונה גיאומטריה ומפת UV":"בונה גיאומטריה ראשונית",i?"מריץ מעבר חומריות וטקסטורות":"מצמיד צבע וחומר בסיסי","אורז GLB ושומר בספרייה"]:["Uploading and preparing the source image","Extracting depth and silhouette",i?"Building geometry and UV layout":"Building initial geometry",i?"Running material and texture pass":"Ap
373plying base color and material","Packaging GLB and saving to the library"],u=d[Math.min(c+1,d.length-1)],h=o?`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")} דק׳`:`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`;return n.jsxs("div",{className:`fp-image-to-3d-studio ${r?"fp-image-to-3d-studio--compact":""}`,role:"status","aria-live":"polite",dir:o?"rtl":"ltr",children:[n.jsxs("div",{className:"fp-i3d-scene","aria-hidden":!0,children:[n.jsxs("div",{className:"fp-i3d-plane-stack",children:[n.jsx("span",{className:"fp-i3d-source-card",children:n.jsx(C1,{size:20,strokeWidth:1.9})}),n.jsx("span",{className:"fp-i3d-depth-layer fp-i3d-depth-layer--a"}),n.jsx("span",{className:"fp-i3d-depth-layer fp-i3d-depth-layer--b"}),n.jsx("span",{className:"fp-i3d-depth-layer fp-i3d-depth-layer--c"}),n.jsx("span",{className:"fp-i3d-scanline"})]}),n.jsxs("div",{className:"fp-i3d-transfer",children:[n.jsx("span",{}),n.jsx("span",{}),n.jsx("span",{})]}),n.jsxs("div",{className:"fp-i3d-wireframe",children:[n.jsx("span",{className:"fp-i3d-cube-face fp-i3d-cube-face--front"}),n.jsx("span",{className:"fp-i3d-cube-face fp-i3d-cube-face--back"}),n.jsx("span",{className:"fp-i3d-cube-edge fp-i3d-cube-edge--top"}),n.jsx("span",{className:"fp-i3d-cube-edge fp-i3d-cube-edge--right"}),n.jsx("span",{className:"fp-i3d-cube-edge fp-i3d-cube-edge--bottom"}),n.jsx("span",{className:"fp-i3d-cube-edge fp-i3d-cube-edge--left"}),n.jsx("span",{className:"fp-i3d-mesh-line fp-i3d-mesh-line--one"}),n.jsx("span",{className:"fp-i3d-mesh-line fp-i3d-mesh-line--two"}),n.jsx("span",{className:"fp-i3d-glb-badge",children:"GLB"})]}),n.jsxs("div",{className:"fp-i3d-material-strip",children:[n.jsx("span",{}),n.jsx("span",{}),n.jsx("span",{})]})]}),n.jsxs("div",{className:"fp-i3d-copy",children:[n.jsxs("div",{className:"fp-i3d-kicker",children:[n.jsx(zl,{size:13,strokeWidth:2.4}),n.jsx("span",{children:o?"סטודיו 2D → 3D פעיל":"2D → 3D studio active"})]}),n.jsx("h3",{children:s||(o?"מעבד עכשיו את המודל":"Processing the model now")}),n.jsx("p",{children:o?"השלבים שרצים ברקע מוצגים כאן כאומדן, כדי שיהיה ברור מה קורה עכשיו.":"These background stages are an estimate, so it stays clear what is happening now."})]}),n.jsxs("div",{className:"fp-i3d-progress-shell",children:[n.jsxs("div",{className:"fp-i3d-progress-meta",children:[n.jsx("span",{children:d[c]}),n.jsx("span",{children:h})]}),n.jsx("div",{className:"fp-i3d-progress-track",children:n.jsx("span",{style:{width:`${l}%`}})})]}),n.jsxs("div",{className:"fp-i3d-phase-grid",children:[n.jsxs("span",{className:"fp-i3d-phase fp-i3d-phase--active",children:[n.jsx("span",{children:o?"עכשיו":"Now"}),d[c]]}),n.jsxs("span",{className:"fp-i3d-phase",children:[n.jsx("span",{children:o?"הבא":"Next"}),u]})]})]})}function U4({provider:t,compact:e,icon:s,title:o,description:r,time:i,tokens:a,technicalLabel:l,onClick:c}){const d=t==="meshy";return n.jsxs("button",{type:"button",onClick:c,className:`
374        group flex min-h-full flex-col items-stretch text-right transition-colors
375        ${e?"gap-1 rounded-lg border-2 px-2 py-2.5":"gap-3 rounded-[12px] border px-4 py-4"}
376        ${d?"border-[#D85D43]/38 bg-[#F8E6DE] hover:border-[#D85D43]/65 hover:bg-[#F5D8CE]":"border-[#182137]/18 bg-[#E8E3DB]/65 hover:border-[#182137]/35 hover:bg-[#E0DFD8]"}
377      `,children:[n.jsxs("span",{className:"flex items-center gap-2",children:[n.jsx("span",{className:`
378            flex shrink-0 items-center justify-center rounded-[8px]
379            ${e?"h-7 w-7":"h-9 w-9"}
380            ${d?"bg-[#D85D43] text-[#F7F4EF]":"bg-[#182137] text-[#F7F4EF]"}
381          `,children:s}),n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:e?"block text-[10.5px] font-black leading-tight text-[#182137]":"block text-[16px] font-black leading-tight text-[#182137]",children:o}),!e&&n.jsx("span",{className:"mt-1 block text-[11px] font-bold leading-relaxed text-[#182137]/60",children:r})]})]}),n.jsxs("span",{className:e?"grid grid-cols-1 gap-1 text-center":"mt-auto flex flex-wrap gap-1.5",children:[n.jsx("span",{className:"rounded-full bg-[#F7F4EF]/78 px-2 py-1 text-[9px] font-black tabular-nums text-[#182137]",children:i}),n.jsx("span",{className:"rounded-full bg-[#F7F4EF]/78 px-2 py-1 text-[9px] font-black tabular-nums text-[#182137]",children:a}),n.jsx("span",{className:"rounded-full border border-[#182137]/10 px-2 py-1 text-[8px] font-black uppercase tracking-[0.08em] text-[#182137]/42",children:l})]})]})}function xJ({userId:t,activeFurnitureType:e,onSelect:s,onBeginDrag:o,onEndDrag:r,refreshToken:i,onImageTo3DSuccess:a,measurementUnit:l="cm",personalAssetsLocked:c=!1,onPremiumRequired:d}){const{t:u}=yn(),h=xc(),{models:x,loading:f,upload:p,remove:b,rename:M}=ak(t,i),[g,w]=m.useState(!1),[k,_]=m.useState(null),[j,v]=m.useState(!1),[C,N]=m.useState(null),P=m.useCallback(()=>{g||j||_(null)},[j,g]),L=m.useCallback(()=>c?(d==null||d(),!1):!0,[d,c]);return t?n.jsxs("div",{className:"flex h-full min-h-0 flex-1 flex-col font-heebo",children:[n.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain",children:f?n.jsx("div",{className:"flex items-center justify-center py-8",children:n.jsx(Xa,{size:18,className:O("animate-spin",h?"text-white/35":"text-[#182137]/35")})}):x.length===0?n.jsx(yJ,{fpIsDark:h}):n.jsx("div",{className:"grid grid-cols-2 gap-2",dir:"rtl",children:x.map(A=>{const W=`user_${A.id}`,S=e===W;return n.jsx(MJ,{model:A,isActive:S,fpIsDark:h,onSelect:()=>s(W,Of(A.storage_path),{w:A.width_mm,d:A.depth_mm,h:A.height_mm},A.name),onBeginDrag:()=>
381o==null?void 0:o(W,Of(A.storage_path),{w:A.width_mm,d:A.depth_mm,h:A.height_mm},A.name),onEndDrag:r,onDelete:()=>b(A),onRename:B=>M(A.id,B),measurementUnit:l,locked:c,onLockedAction:d},A.id)})})}),n.jsxs("div",{className:O("mt-3 flex shrink-0 flex-col gap-2 border-t pt-2",h?"border-white/10":"border-[#182137]/10"),children:[C&&n.jsxs("div",{className:"flex items-center gap-1.5 rounded-[3px] border border-red-200 bg-red-50 px-2.5 py-2 text-[10px] text-red-600",children:[n.jsx(Dy,{size:12}),C]}),n.jsxs("div",{className:"flex flex-col gap-1.5",children:[a&&n.jsx(K4,{icon:n.jsx(C1,{size:15,strokeWidth:2.2}),mode:"image",title:u("myFurniture.createFromImage",{defaultValue:"צור רהיט מתמונה"}),fpIsDark:h,onClick:()=>{L()&&(N(null),_("image-to-3d"))}}),n.jsx(K4,{icon:n.jsx(Ap,{size:15,strokeWidth:2.3}),mode:"glb",title:u("myFurniture.uploadGlb",{defaultValue:"העלאת קובץ GLB מוכן"}),fpIsDark:h,strong:!0,onClick:()=>{L()&&(N(null),_("glb-upload"))}})]})]}),!c&&a&&k==="image-to-3d"&&n.jsx(Z4,{title:u("myFurniture.createFromImage",{defaultValue:"צור רהיט מתמונה"}),eyebrow:"AI ל-GLB",description:u("myFurniture.imageDialogDescription",{defaultValue:"מסך יצירה ממוקד: מעלים תמונת רהיט, בוחרים מסלול, ומקבלים מודל GLB שנשמר ב״הרהיטים שלי״."}),icon:n.jsx(zl,{size:20,strokeWidth:2.3}),mode:"image",closeDisabled:j,onClose:P,steps:[u("myFurniture.imageStep1",{defaultValue:"מעלים תמונה ברורה של הרהיט"}),u("myFurniture.imageStep2",{defaultValue:"בוחרים מהיר וחסכוני או טקסטורות עשירות"}),u("myFurniture.imageStep3",{defaultValue:"המודל נשמר בספרייה ואפשר לגרור אותו לתוכנית"})],children:n.jsx(mJ,{userId:t,onSuccess:A=>{a(A),_(null)},variant:"dialog",onBusyChange:v})}),!c&&k==="glb-upload"&&n.jsxs(Z4,{title:u("myFurniture.uploadGlb",{defaultValue:"העלאת קובץ GLB מוכן"}),eyebrow:u("myFurniture.modelImport",{defaultValue:"ייבוא מודל"}),description:u("myFurniture.glbDialogDescription",{defaultValue:"למודלים שכבר מוכנים אצלכם: מעלים קובץ GLB, נותנים שם ומידות בסיסיות, והוא מופיע בספרייה."}),icon:n.jsx(Vw,{size:20,strokeWidth:2.2}),mode:"glb",closeDisabled:g,onClose:P,steps:[u("myFurniture.glbStep1",{defaultValue:"בוחרים קובץ ‎.glb‎ מוכן"}),u("myFurniture.glbStep2",{defaultValue:"מגדירים שם, קטגוריה ומידות בסיסיות"}),u("myFurniture.glbStep3",{defaultValue:"שומרים ל״הרהיטים שלי״ וממקמים בתוכנית"})],children:[C&&n.jsxs("div",{className:"mb-3 flex items-start gap-2 rounded-[8px] border border-red-200 bg-red-50 px-3 py-2 text-[11px] font-bold text-red-600",children:[n.jsx(Dy,{size:14,className:"mt-0.5 shrink-0"}),n.jsx("span",{children:C})]}),n.jsx(gJ,{uploading:g,fpIsDark:h,surface:"dialog",onUpload:async(A,W,S,B)=>{if(L()){N(null),w(!0);try{await p(A,W,S,B),_(null)}catch(R){N(R instanceof Error?R.message:u("myFurniture.uploadError",{defaultValue:"שגיאה בהעלאה"}))}finally{w(!1)}}},onCancel:P,measurementUnit:l})]})]}):n.jsx("div",{className:O("py-8 text-center text-[11px] font-medium",h?"text-white/45":"text-[#182137]/45"),children:u("myFurniture.signInToUpload",{defaultValue:"יש להתחבר כדי להעלות רהיטים"})})}function K4({icon:t,mode:e,title:s,fpIsDark:o,strong:r=!1,onClick:i}){const{t:a}=yn();return n.jsxs("button",{type:"button",onClick:i,className:O("fp-furniture-action group",e==="image"?"fp-furniture-action--image":"fp-furniture-action--glb",r&&"fp-furniture-action--strong",o&&"fp-furniture-action--dark"),dir:"rtl",children:[n.jsx("span",{className:"fp-furniture-action__scene","aria-hidden":!0,children:n.jsxs("span",{className:"fp-furniture-action__plate",children:[n.jsx("span",{className:"fp-furniture-action__glyph",children:t}),n.jsx("span",{className:"fp-furniture-action__depth-line fp-furniture-action__depth-line--one"}),n.jsx("span",{className:"fp-furniture-action__depth-line fp-furniture-action__depth-line--two"}),n.jsx("span",{className:"fp-furniture-action__cube"})]})}),n.jsxs("span",{className:"min-w-0 flex-1 py-0.5",children:[n.jsxs("span",{className:"mb-1 flex flex-wrap items-center justify-start gap-1",children:[n.jsx("span",{className:"fp-furniture-action__badge",children:e==="image"?"AI → GLB":a("myFurniture.readyGlb",{defaultValue:"GLB מוכן"})}),n.jsx("span",{className:"fp-furniture-action__badge fp-furniture-action__badge--quiet",children:e==="image"?a("myFurniture.savedToLibrary",{defaultValue:"נשמר בספרייה"}):a("myFurniture.quickImport",{defaultValue:"ייבוא מהיר"})})]}),n.jsx("span",{className:O("block text-[13.5px] font-black leading-tight",o?"text-white":"text-[#182137]"),children:s})]}),n.jsx("span",{className:"fp-furniture-action__chevron","aria-hidden":!0,
381children:"←"})]})}function Z4({eyebrow:t,title:e,description:s,icon:o,mode:r,steps:i,closeDisabled:a,onClose:l,children:c}){const{t:d}=yn();return m.useEffect(()=>{const u=h=>{h.key==="Escape"&&!a&&l()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[a,l]),typeof document>"u"?null:H_.createPortal(n.jsx("div",{className:"fixed inset-0 z-[90] flex items-center justify-center bg-[#182137]/45 p-3 backdrop-blur-[2px] sm:p-4",onMouseDown:u=>{u.target===u.currentTarget&&!a&&l()},dir:"rtl",role:"presentation",children:n.jsxs("section",{role:"dialog","aria-modal":"true","aria-labelledby":"custom-furniture-dialog-title",className:O("flex max-h-[calc(100vh-24px)] w-full max-w-[760px] flex-col overflow-hidden rounded-[16px] border border-[#D85D43]/24 bg-[#F7F4EF] shadow-[0_24px_80px_-36px_rgba(24,33,55,0.55)] sm:min-h-[500px]",a&&"fp-custom-furniture-dialog--busy"),onMouseDown:u=>u.stopPropagation(),children:[n.jsxs("header",{className:"fp-custom-furniture-dialog-header relative border-b border-[#D85D43]/18 px-4 py-4 sm:px-6",children:[n.jsxs("div",{className:"grid gap-4 lg:grid-cols-[minmax(0,1fr)_240px]",children:[n.jsxs("div",{className:"flex items-start gap-3",children:[n.jsx("span",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-[10px] bg-[#D85D43] text-[#F7F4EF]",children:o}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("div",{className:"mb-1 text-[10px] font-black uppercase text-[#D85D43]",children:t}),n.jsx("h2",{id:"custom-furniture-dialog-title",className:"text-[28px] font-black leading-none text-[#182137] sm:text-[38px]",children:e}),n.jsx("p",{className:"mt-2 max-w-[560px] text-[13px] font-bold leading-relaxed text-[#182137]/68",children:s})]})]}),n.jsx(pJ,{mode:r}),n.jsx("button",{type:"button",onClick:l,disabled:a,className:"absolute left-3 top-3 flex h-8 w-8 shrink-0 cursor-pointer items-center justify-center rounded-[6px] border border-[#182137]/12 bg-[#F7F4EF] text-[#182137]/55 transition-colors hover:bg-[#E8E3DB] hover:text-[#182137] disabled:cursor-wait disabled:opacity-35","aria-label":d("common.close",{defaultValue:"סגור"}),children:n.jsx(Gr,{size:16})})]}),n.jsx("div",{className:"fp-custom-furniture-steps mt-4 grid gap-2 sm:grid-cols-3",children:i.map((u,h)=>n.jsxs("div",{className:"flex min-h-[54px] items-center gap-2 rounded-[10px] border border-[#D85D43]/18 bg-[#F7F4EF]/72 px-3 py-2",children:[n.jsx("span",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-[#182137] text-[11px] font-black tabular-nums text-[#F7F4EF]",children:h+1}),n.jsx("span",{className:"text-[11px] font-black leading-snug text-[#182137]",children:u})]},u))})]}),n.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-4 py-4 sm:px-6 sm:py-5",children:c})]})}),document.body)}function pJ({mode:t}){return n.jsxs("div",{className:`fp-dialog-header-scene fp-dialog-header-scene--${t}`,"aria-hidden":!0,children:[n.jsx("span",{className:"fp-dialog-header-scene__image"}),n.jsx("span",{className:"fp-dialog-header-scene__depth fp-dialog-header-scene__depth--one"}),n.jsx("span",{className:"fp-dialog-header-scene__depth fp-dialog-header-scene__depth--two"}),n.jsx("span",{className:"fp-dialog-header-scene__mesh"}),n.jsx("span",{className:"fp-dialog-header-scene__label",children:t==="image"?"2D → 3D":"GLB"})]})}function gJ({uploading:t,onUpload:e,onCancel:s,measurementUnit:o,fpIsDark:r,surface:i="inline"}){const{t:a}=yn(),l=i==="dialog",c=m.useRef(null),[d,u]=m.useState(null),[h,x]=m.useState(""),[f,p]=m.useState({w:1e3,d:1e3,h:1e3}),[b,M]=m.useState(()=>De(1e3,o)),[g,w]=m.useState(()=>De(1e3,o)),[k,_]=m.useState(()=>De(1e3,o)),[j,v]=m.useState(null);m.useEffect(()=>{M(De(f.w,o)),w(De(f.d,o)),_(De(f.h,o))},[f,o]);const C=m.useCallback(W=>{var B;const S=(B=W.target.files)==null?void 0:B[0];S&&(u(S),h||x(S.name.replace(/\.glb$/i,"").replace(/[_-]/g," ")))},[h]),N=m.useCallback(()=>{if(!d||!h.trim())return;const W=Xg(b,f.w,o),S=Xg(g,f.d,o),B=Xg(k,f.h,o);e(d,h.trim(),{w:W,d:S,h:B},j)},[g,f,d,k,o,h,e,j,b]),P=m.useCallback((W,S)=>{const B=f[W],R=Xg(S,B,o);p(X=>({...X,[W]:R}));const z=De(R,o);W==="w"&&M(z),W==="d"&&w(z),W==="h"&&_(z)},[f,o]),L=O("h-7 w-full rounded-[3px] border px-2 text-[12px] font-bold tabular-nums outline-none text-right",r?"border-white/15 bg-[#0A0A0A] text-white focus:border-white/35":"border-[#182137]/12 bg-white text-[#182137] focu
381s:border-[#182137]/40"),A=O("mb-0.5 text-[10px] font-bold",r?"text-white/55":"text-[#182137]/55");return n.jsxs("div",{className:O("flex flex-col gap-3 border",l?"rounded-[12px] p-4":"rounded-[3px] p-3",r?"border-white/12 bg-[#0A0A0A]":l?"border-[#D85D43]/22 bg-[#E8E3DB]/35":"border-[#182137]/12 bg-white"),children:[n.jsx("input",{ref:c,type:"file",accept:".glb,.gltf",onChange:C,className:"hidden"}),n.jsxs("button",{type:"button",onClick:()=>{var W;return(W=c.current)==null?void 0:W.click()},className:O("flex w-full cursor-pointer flex-col items-center gap-1 border-2 border-dashed text-[10px] transition-colors",l?"rounded-[12px] py-7":"rounded-[3px] py-3",r?"border-white/20 text-white/55 hover:border-[#EC7357]/50 hover:bg-white/[0.04]":"border-[#182137]/20 text-[#182137]/55 hover:border-[#D84B2E]/40 hover:bg-[#E8DFD3]/40"),children:[n.jsx(Vw,{size:20,className:r?"text-white/35":"text-[#182137]/35"}),d?n.jsx("span",{className:"font-bold text-[#D85D43]",children:d.name}):n.jsxs(n.Fragment,{children:[n.jsx("span",{className:O("font-black",l&&"text-[13px] text-[#182137]"),children:a("myFurniture.chooseGlb",{defaultValue:"בחר קובץ GLB"})}),l&&n.jsx("span",{className:"text-[10px] font-bold text-[#182137]/45",children:a("myFurniture.glbFileHint",{defaultValue:"קובץ ‎.glb‎ בלבד, עדיף מודל בגודל סביר לגרירה חלקה בתוכנית"})})]})]}),n.jsxs("div",{children:[n.jsx("div",{className:A,children:a("myFurniture.name",{defaultValue:"שם הרהיט"})}),n.jsx("input",{type:"text",value:h,onChange:W=>x(W.target.value),placeholder:a("myFurniture.namePlaceholder",{defaultValue:"למשל: ספה מודרנית"}),className:L})]}),n.jsxs("div",{children:[n.jsx("div",{className:A,children:a("myFurniture.category",{defaultValue:"קטגוריה (חדר → תת)"})}),n.jsx(c6,{value:j,onChange:v,compact:!0})]}),n.jsxs("div",{children:[n.jsx("div",{className:A,children:a("myFurniture.dimensions",{defaultValue:"מידות ({{unit}})",unit:Ka(o)})}),n.jsxs("div",{className:"grid grid-cols-3 gap-1.5",children:[n.jsxs("div",{children:[n.jsx("div",{className:O("mb-0.5 text-center text-[8px] font-bold",r?"text-white/35":"text-[#182137]/35"),children:a("dimensions.width",{defaultValue:"רוחב"})}),n.jsx("input",{type:"text",inputMode:"decimal",value:b,onChange:W=>M(W.target.value),onBlur:W=>P("w",W.currentTarget.value),className:O(L,"text-center")})]}),n.jsxs("div",{children:[n.jsx("div",{className:O("mb-0.5 text-center text-[8px] font-bold",r?"text-white/35":"text-[#182137]/35"),children:a("dimensions.depth",{defaultValue:"עומק"})}),n.jsx("input",{type:"text",inputMode:"decimal",value:g,onChange:W=>w(W.target.value),onBlur:W=>P("d",W.currentTarget.value),className:O(L,"text-center")})]}),n.jsxs("div",{children:[n.jsx("div",{className:O("mb-0.5 text-center text-[8px] font-bold",r?"text-white/35":"text-[#182137]/35"),children:a("dimensions.height",{defaultValue:"גובה"})}),n.jsx("input",{type:"text",inputMode:"decimal",value:k,onChange:W=>_(W.target.value),onBlur:W=>P("h",W.currentTarget.value),className:O(L,"text-center")})]})]})]}),n.jsxs("div",{className:"mt-1 flex gap-1.5",children:[n.jsxs("button",{type:"button",onClick:N,disabled:!d||!h.trim()||t,className:O("flex h-8 flex-1 cursor-pointer items-center justify-center gap-1.5 rounded-[3px] border text-[11px] font-black transition-colors disabled:cursor-not-allowed disabled:opacity-40",r?"border-[#EC7357] bg-[#EC7357] text-white hover:bg-[#D84B2E]":"border-[#D84B2E] bg-[#D84B2E] text-white hover:bg-[#C04428]"),children:[t?n.jsx(Xa,{size:12,className:"animate-spin"}):n.jsx(Ap,{size:12}),t?a("myFurniture.uploading",{defaultValue:"מעלה..."}):a("myFurniture.saveToLibrary",{defaultValue:"שמור לספרייה"})]}),n.jsx("button",{type:"button",onClick:s,className:O("h-8 cursor-pointer rounded-[3px] border px-3 text-[11px] font-bold transition-colors",r?"border-white/12 bg-[#0A0A0A] text-white/70 hover:bg-white/[0.06]":"border-[#182137]/12 bg-white text-[#182137]/70 hover:bg-[#E8DFD3]"),children:a("common.cancel",{defaultValue:"ביטול"})})]})]})}function Xg(t,e,s){return Math.max(100,ni(t,s)??e)}function bJ(t){return`${t.trim().replace(/[\\/:*?"<>|]+/g,"-").replace(/\s+/g," ").slice(0,80)||"furniture"}.glb`}function MJ({model:t,isActive:e,onSelect:s,onBeginDrag:o,onEndDrag:r,onDelete:i,onRename:a,measurementUnit:l,fpIsDark:c,locked:d=!1,onLockedAction:u}){const{t:h}=yn(),[x,f]=m.useState(!1),[p,b]=m.useState(!1),[M,g]=m.useState(t.name),[w,k]=m.useState(null),[_,j]=m.useState(!1),v=m.useRef(null),C=`${De(t.width_mm,l)}×${De(t.depth_mm,l)} ${Ka(l)}`,N=Of(t.storage_path),P=m.useCallback(B=>{if(B.stopPropagation(),d){u==null||u();return}g(t.name),b(!0),setTimeout(()=>{var R;return(R=v.current)==null?void 0:R.select()},0)},[d,t.name,u]),L=m.useCallback(()=>{const B=M.trim();B&&B!==t.name&&a(B),b(!1)}
381,[M,t.name,a]),A=m.useCallback(()=>{g(t.name),b(!1)},[t.name]);m.useEffect(()=>{if(!w)return;const B=R=>{R.key==="Escape"&&k(null)};return window.addEventListener("keydown",B),()=>window.removeEventListener("keydown",B)},[w]);const W=m.useCallback(B=>{if(B.preventDefault(),B.stopPropagation(),!p){if(d){u==null||u();return}f(!1),k({x:B.clientX,y:B.clientY})}},[p,d,u]),S=m.useCallback(async()=>{if(d){k(null),u==null||u();return}k(null),j(!0);try{await U7(N,bJ(t.name)),ln.success(h("myFurniture.downloadStarted",{defaultValue:"הורדת קובץ GLB התחילה"}))}catch(B){ln.error(B instanceof Error?B.message:h("myFurniture.downloadFailed",{defaultValue:"הורדת קובץ GLB נכשלה"}))}finally{j(!1)}},[d,t.name,N,u,h]);return n.jsxs("div",{className:"group relative",children:[n.jsxs("button",{type:"button",onClick:d?u:s,draggable:!p,title:h("catalogUi.placeHint",{defaultValue:"לחיצה: בחירת רהיט · אחר כך לחצו בכל אזור בתוכנית למיקום מדויק · גרירה: מיקום ישיר"}),onDragStart:B=>{if(!p){if(d){B.preventDefault(),u==null||u();return}o==null||o(),U3(B.dataTransfer,{type:`user_${t.id}`,label:t.name})}},onDragEnd:r,className:O("relative flex w-full flex-col items-center gap-1.5 rounded-[3px] border p-1.5 transition-colors select-none",d&&"opacity-65",e?c?"border-[#EC7357] bg-[#EC7357]/15 shadow-[0_0_0_1px_rgba(236,115,87,0.42)]":"border-[#D84B2E] bg-[#FDF1EC] shadow-[0_0_0_1px_rgba(216,75,46,0.18)]":c?"border-white/12 bg-[#0A0A0A] hover:bg-white/[0.06]":"border-[#182137]/12 bg-white hover:bg-[#E8DFD3]"),children:[e?n.jsx("span",{className:"absolute left-1.5 top-1.5 z-10 flex h-5 w-5 items-center justify-center rounded-full bg-[#D84B2E] text-white shadow-sm",children:n.jsx(Gc,{size:12,strokeWidth:3,"aria-hidden":!0})}):null,n.jsxs("div",{onContextMenu:W,title:h("myFurniture.downloadContextHint",{defaultValue:"קליק ימני להורדת GLB"}),className:O("relative aspect-square w-full overflow-hidden rounded-[2px]",c?"bg-[#0A0A0A]":"bg-white"),children:[n.jsx("div",{className:"absolute inset-1.5",children:n.jsx(Hb,{customModelUrl:N,subKey:"",label:t.name,color:e?"#D84B2E":"#D85D43",fillContainer:!0,isActive:e})}),d&&n.jsx("span",{className:"pointer-events-none absolute inset-0 grid place-items-center bg-[#182137]/10",children:n.jsx("span",{className:"grid h-8 w-8 place-items-center rounded-lg bg-[#182137] text-[#F7F4EF] shadow-[0_6px_16px_rgba(24,33,55,0.28)]",children:n.jsx(fp,{size:14,strokeWidth:2.5})})})]}),p?n.jsx("input",{ref:v,value:M,onChange:B=>g(B.target.value),onBlur:L,onKeyDown:B=>{B.stopPropagation(),B.key==="Enter"&&L(),B.key==="Escape"&&A()},onClick:B=>B.stopPropagation(),className:O("h-5 w-full rounded-[2px] border px-1 text-center text-[10px] font-bold outline-none",c?"border-[#EC7357]/60 bg-[#0A0A0A] text-white":"border-[#D84B2E]/40 bg-white text-[#182137]"),autoFocus:!0}):n.jsx("span",{onClick:P,title:h("myFurniture.rename",{defaultValue:"לחץ לשינוי שם"}),className:O("line-clamp-2 w-full cursor-text text-center text-[10.5px] font-bold leading-tight","hover:underline hover:decoration-dotted",e?c?"text-white":"text-[#182137]":c?"text-white/85":"text-[#182137]"),children:t.name}),n.jsx("span",{className:O("text-[9px] leading-tight tabular-nums",c?"text-white/45":"text-[#182137]/45"),children:C})]}),w&&typeof document<"u"&&H_.createPortal(n.jsx("div",{className:"fixed inset-0 z-[95]",onMouseDown:()=>k(null),onContextMenu:B=>{B.preventDefault(),k(null)},children:n.jsx("div",{className:O("fixed min-w-[154px] overflow-hidden rounded-[8px] border p-1 shadow-[0_16px_40px_rgba(24,33,55,0.22)]",c?"border-white/12 bg-[#111827] text-white":"border-[#182137]/12 bg-[#F7F4EF] text-[#182137]"),style:{left:Math.min(w.x,window.innerWidth-174),top:Math.min(w.y,window.innerHeight-52)},dir:"rtl",onMouseDown:B=>B.stopPropagation(),children:n.jsxs("button",{type:"button",onClick:S,disabled:_,className:O("flex h-9 w-full cursor-pointer items-center gap-2 rounded-[6px] px-2.5 text-right text-[11px] font-black transition-colors disabled:cursor-wait disabled:opacity-55",c?"hover:bg-white/[0.08]":"hover:bg-[#
381E8E3DB]"),children:[n.jsx(xp,{size:14,className:"text-[#D85D43]"}),_?h("myFurniture.downloading",{defaultValue:"מוריד GLB..."}):h("myFurniture.downloadGlb",{defaultValue:"הורד קובץ GLB"})]})})}),document.body),x?n.jsxs("div",{className:"mt-1 flex gap-1",children:[n.jsx("button",{type:"button",onClick:()=>{i(),f(!1)},className:"h-5 flex-1 cursor-pointer rounded-[2px] bg-red-500 text-[8px] font-bold text-white transition-colors hover:bg-red-600",children:h("common.delete",{defaultValue:"מחק"})}),n.jsx("button",{type:"button",onClick:()=>f(!1),className:O("h-5 flex-1 cursor-pointer rounded-[2px] border text-[8px] font-bold transition-colors",c?"border-white/12 bg-[#0A0A0A] text-white/70":"border-[#182137]/12 bg-white text-[#182137]/70"),children:h("common.cancel",{defaultValue:"ביטול"})})]}):n.jsx("button",{type:"button",onClick:()=>d?u==null?void 0:u():f(!0),className:O("absolute right-1 top-1 z-10 flex h-5 w-5 items-center justify-center rounded-[2px] border opacity-0 transition-all group-hover:opacity-100",c?"border-white/12 bg-[#0A0A0A]/90 text-white/55 hover:border-red-400/50 hover:text-red-400":"border-[#182137]/12 bg-white/95 text-[#182137]/45 hover:border-red-300 hover:text-red-500"),"aria-label":h("myFurniture.deleteFurniture",{defaultValue:"מחק רהיט"}),children:n.jsx(gi,{size:10})})]})}function yJ({fpIsDark:t}){const{t:e}=yn();return n.jsxs("div",{className:"flex flex-col items-center justify-center py-10 text-center",children:[n.jsx(Vw,{size:28,className:t?"mb-2 text-white/25":"mb-2 text-[#182137]/25"}),n.jsx("p",{className:O("mb-1 text-[12px] font-black",t?"text-white/70":"text-[#182137]/70"),children:e("myFurniture.emptyTitle",{defaultValue:"אין עדיין רהיטים"})}),n.jsx("p",{className:O("max-w-[180px] text-[10px] font-bold leading-relaxed",t?"text-white/45":"text-[#182137]/45"),children:e("myFurniture.emptyDescription",{defaultValue:"העלו קובץ GLB או הפכו תמונה ל-3D — הרהיטים יופיעו כאן"})})]})}const Ip=1,wJ=2e3,kJ=1e6,q4=t=>`user:${t}`,Ef="utpl_group",d6="user.saved";function Bb(t){return t.kind==="polygon"||t.kind==="facePatch"||t.kind==="faceSplit"||t.kind==="faceCornerArc"}function u6(t){return t.kind==="facePatch"||t.kind==="faceSplit"||t.kind==="faceCornerArc"||t.kind==="faceMeasure"?t.hostEntityId:null}function h6(t,e,s,o){const r=t.filter(Bb),i=new Set;if(o==="all")for(const l of r)l.kind==="polygon"&&i.add(l.id);else{const l=s?r.find(d=>d.id===s):void 0;if(!l)return i;const c=l.groupId;if(c){const d=e.find(u=>u.id===c);for(const u of(d==null?void 0:d.entityIds)??[])i.add(u);for(const u of r)u.groupId===c&&i.add(u.id)}i.add(l.id)}let a=!0;for(;a;){a=!1;for(const l of r){const c=u6(l);i.has(l.id)&&c&&!i.has(c)&&(i.add(c),a=!0),c&&i.has(c)&&!i.has(l.id)&&(i.add(l.id),a=!0)}}return i}function J4(t){let e=0;for(let s=0;s<t.vertices.length;s+=1){const o=t.vertices[s],r=t.vertices[(s+1)%t.vertices.length];e+=o.x*r.y-r.x*o.y}return Math.abs(e/2)}function vJ(t){const s=t.filter(i=>i.kind==="polygon").sort((i,a)=>J4(a)-J4(i))[0];if(!s||s.vertices.length<2)return 0;const o=s.vertices[0],r=s.vertices.find((i,a)=>a>0&&Math.hypot(i.x-o.x,i.y-o.y)>=1);return r?Math.atan2(r.y-o.y,r.x-o.x):0}function yw(t,e){const s=Math.cos(e),o=Math.sin(e);return{x:Math.round(t.x*s-t.y*o),y:Math.round(t.x*o+t.y*s)}}function ww(t){const e=t.filter(c=>c.kind==="polygon");if(e.length===0)return null;let s=1/0,o=1/0,r=-1/0,i=-1/0,a=1/0,l=-1/0;for(const c of e){for(const u of c.vertices)s=Math.min(s,u.x),o=Math.min(o,u.y),r=Math.max(r,u.x),i=Math.max(i,u.y);const d=Math.max(0,Math.round(c.baseHeightMm??0));a=Math.min(a,d),l=Math.max(l,d+Math.max(0,Math.round(c.heightMm??0)))}return{minX:Math.round(s),minY:Math.round(o),maxX:Math.round(r),maxY:Math.round(i),minHeightMm:Number.isFinite(a)?a:0,maxHeightMm:Number.isFinite(l)?l:0}}function m6(t,e){if(!t)return;const s=t.indexOf("|");if(s<0)return t;const o=t.slice(0,s),r=e.get(o);return r?`${r}${t.slice(s)}`:t}function jJ(t){switch(t.kind){case"polygon":return`fps_${t.sourceTool}`;case"facePatch":return"fps_patch";case"faceSplit":return"fps_face_split";case"faceCornerArc":return"fps_corner_arc";case"segment":return"fps_line";case"measure":return"fps_measure";case"faceMeasure":return"fps_face_measure"}}function _J(t,e,s,o){var a,l,c;const r=e.get(t.id);if(t.kind==="polygon"){const d=x=>{const f=yw(x,s);return{x:f.x+o.x,y:f.y+o.y}},{rectangleWallAnchor:u,...h}=t;return{...h,id:r,groupId:Ef,createdAt:0,vertices:t.vertices.map(d),holes:(a=t.holes)==null?void 0:a.map(x=>x.map(d))}}const i=e.get(t.hostEntityId)??t.hostEntityId;return t.kind==="facePatch"?{...t,id:r,groupId:Ef,createdAt:0,hostEntityId:i,points2D:t.points2D.map(d=>({...d})),holes2D:(l=t.holes2D)==null?void 0:l.map(d=>d.map(u=>({...u}))),containedArcIds:(c=t.containedArcIds)==null?void 0:c.map(d=>e.get(d)).filter(d=>!!d),promotedRegionKey:m6(t.promotedRegionKey,e)}:t.kind==="faceSplit"?{...t,id:r,groupId:Ef,createdAt:0,hostEntityId:i,a2D:{...t.a2D}
381,b2D:{...t.b2D}}:{...t,id:r,groupId:Ef,createdAt:0,hostEntityId:i}}function EJ(t){var _;const e=t.name.trim();if(!e)throw new Error("יש לתת שם לתבנית");const s=h6(t.entities,t.furnitureGroups,t.selectedEntityId,t.scope),o=t.entities.filter(j=>s.has(j.id)&&Bb(j));if(!o.some(j=>j.kind==="polygon"))throw new Error(t.scope==="selected"?"יש לבחור מודל לשמירה":"אין מודל לשמירה בקנבס");if(o.length>wJ)throw new Error("המודל גדול מדי לשמירה כתבנית אחת");const r=t.selectedEntityId?o.find(j=>j.id===t.selectedEntityId):void 0,i=r!=null&&r.groupId?t.furnitureGroups.find(j=>j.id===r.groupId):void 0,a=new Map;o.forEach((j,v)=>a.set(j.id,`utpl_entity_${v+1}`));const l=-vJ(o),c=o.map(j=>{var v;return j.kind!=="polygon"?j:{...j,vertices:j.vertices.map(C=>yw(C,l)),holes:(v=j.holes)==null?void 0:v.map(C=>C.map(N=>yw(N,l)))}}),d=ww(c);if(!d)throw new Error("לא נמצאה גאומטריה תקינה לשמירה");const u={x:-d.minX,y:-d.minY},h=o.map(j=>_J(j,a,l,u)),x=ww(h);if(!x)throw new Error("לא נמצאה גאומטריה תקינה לשמירה");const f=Math.max(1,x.maxX-x.minX),p=Math.max(1,x.maxY-x.minY),b=Math.max(1,x.maxHeightMm-x.minHeightMm),M={id:Ef,entityIds:h.map(j=>j.id),name:e,templateId:d6,widthMm:f,depthMm:p,heightMm:b,rotationDeg:0,...t.scope==="selected"&&(i!=null&&i.rigid)?{rigid:!0}:{},createdAt:0},g=Db({entities:h,furnitureGroups:[M]}),w=((_=g.furnitureGroups)==null?void 0:_[0])??M,k={version:Ip,sketchVersion:wp,entities:g.entities,group:w,bounds:x};if(JSON.stringify(k).length>kJ)throw new Error("המודל גדול מדי לשמירה כתבנית אחת");return k}function Yf(t){var x;if(!t||typeof t!="object")return null;const e=t;if(e.version!==Ip||!Array.isArray(e.entities))return null;const s=e.entities.filter(Bb),o=new Set(s.map(f=>f.id));let r=!0;for(;r;){r=!1;for(const f of[...s]){const p=u6(f);p&&!o.has(p)&&(o.delete(f.id),s.splice(s.indexOf(f),1),r=!0)}}if(!s.some(f=>f.kind==="polygon"))return null;const i=e.group&&typeof e.group=="object"?e.group:null,a={id:Ef,entityIds:s.map(f=>f.id),name:typeof(i==null?void 0:i.name)=="string"?i.name:"תבנית אישית",templateId:d6,...i!=null&&i.rigid?{rigid:!0}:{},createdAt:0},l=Db({entities:s,furnitureGroups:[a]}),c=ww(l.entities);if(!c)return null;const d=Math.max(1,c.maxX-c.minX),u=Math.max(1,c.maxY-c.minY),h=Math.max(1,c.maxHeightMm-c.minHeightMm);return{version:Ip,sketchVersion:wp,entities:l.entities,group:{...((x=l.furnitureGroups)==null?void 0:x[0])??a,widthMm:d,depthMm:u,heightMm:h},bounds:c}}function DJ(t,e,s,o){var a,l,c;const r=e.get(t.id);if(t.kind==="polygon"){const{rectangleWallAnchor:d,...u}=t;return{...u,id:r,groupId:s,createdAt:Date.now(),vertices:t.vertices.map(o),holes:(a=t.holes)==null?void 0:a.map(h=>h.map(o))}}const i=e.get(t.hostEntityId)??t.hostEntityId;return t.kind==="facePatch"?{...t,id:r,groupId:s,createdAt:Date.now(),hostEntityId:i,points2D:t.points2D.map(d=>({...d})),holes2D:(l=t.holes2D)==null?void 0:l.map(d=>d.map(u=>({...u}))),containedArcIds:(c=t.containedArcIds)==null?void 0:c.map(d=>e.get(d)).filter(d=>!!d),promotedRegionKey:m6(t.promotedRegionKey,e)}:t.kind==="faceSplit"?{...t,id:r,groupId:s,createdAt:Date.now(),hostEntityId:i,a2D:{...t.a2D},b2D:{...t.b2D}}:{...t,id:r,groupId:s,createdAt:Date.now(),hostEntityId:i}}function my(t,e){const s=Yf(t.payload);if(!s)throw new Error("התבנית אינה תקינה או נוצרה בגרסה שאינה נתמכת");const o=Math.max(1,s.bounds.maxX-s.bounds.minX),r=Math.max(1,s.bounds.maxY-s.bounds.minY),i=Me(),a=new Map;s.entities.forEach(f=>a.set(f.id,be(jJ(f))));let l,c;if(e.wallAnchor){const f=Wn({widthMm:o,depthMm:r},e.wallAnchor);l=f.positionAlongWallMm;const[p,b,,M]=f.vertices;c=g=>({x:Math.round(p.x+(b.x-p.x)*g.x/o+(M.x-p.x)*g.y/r),y:Math.round(p.y+(b.y-p.y)*g.x/o+(M.y-p.y)*g.y/r)})}else{const f=e.origin??{x:0,y:0};c=p=>({x:Math.round(f.x+p.x),y:Math.round(f.y+p.y)})}const d=s.entities.filter(Bb).map(f=>DJ(f,a,i,c)),u=d.find(f=>f.kind==="polygon");if(!u)throw new Error("לא נמצא גוף ראשי בתבנית");
381const h=Date.now(),x={id:i,entityIds:d.map(f=>f.id),name:t.name.trim()||s.group.name||"תבנית אישית",templateId:`user:${t.id}`,widthMm:o,depthMm:r,heightMm:Math.max(1,s.bounds.maxHeightMm-s.bounds.minHeightMm),rotationDeg:0,...s.group.rigid?{rigid:!0}:{},...e.wallAnchor?{wallId:e.wallAnchor.wallId,wallSide:e.wallAnchor.side,wallPositionMm:l}:{},createdAt:h};return{entities:d,group:x,hostId:u.id}}function f6(t,e){const s=Yf(t.payload);if(!s)throw new Error("התבנית אינה תקינה או נוצרה בגרסה שאינה נתמכת");const o=Math.max(1,s.bounds.maxX-s.bounds.minX),r=Math.max(1,s.bounds.maxY-s.bounds.minY);if(e.anchoredWall){let c=0;for(const d of e.furnitureGroups)d.wallId===e.anchoredWall.wallId&&(d.wallSide&&d.wallSide!==e.anchoredWall.side||(c=Math.max(c,(d.wallPositionMm??0)+(d.widthMm??0))));return my(t,{wallAnchor:{...e.anchoredWall,positionAlongWallMm:c}})}if(e.floorAnchor)return my(t,{origin:{x:Math.round(e.floorAnchor.positionMm.x-o/2),y:Math.round(e.floorAnchor.positionMm.y-r/2)}});let i=-1/0,a=0;for(const c of e.entities){if(c.kind!=="polygon")continue;const d=Math.max(...c.vertices.map(u=>u.x));d>i&&(i=d,a=Math.min(...c.vertices.map(u=>u.y)))}const l=i===-1/0?e.modelCenterMm?{x:Math.round(e.modelCenterMm.x-o/2),y:Math.round(e.modelCenterMm.y-r/2)}:{x:0,y:0}:{x:Math.round(i),y:Math.round(a)};return my(t,{origin:l})}function x6(t){const e=Yf(t);return e?{widthMm:Math.max(1,e.bounds.maxX-e.bounds.minX),depthMm:Math.max(1,e.bounds.maxY-e.bounds.minY),heightMm:Math.max(1,e.bounds.maxHeightMm-e.bounds.minHeightMm)}:null}function FJ(t,e,s){const o=s?t.find(r=>r.id===s):void 0;return o!=null&&o.groupId?e.find(r=>r.id===o.groupId)??null:null}function CJ(t){return t.some(e=>e.kind==="polygon")}function NJ(t,e,s){if(!s)return!1;const o=h6(t,e,s,"selected");return t.some(r=>o.has(r.id)&&r.kind==="polygon")}const Yg=()=>Bo.from("floorplan_user_templates");function Q4(t){if(!t||typeof t!="object")return null;const e=t,s=Yf(e.payload);if(!s||typeof e.id!="string"||typeof e.user_id!="string")return null;const o=x6(s);if(!o)return null;const r=e.placement_mode==="floor"||e.placement_mode==="wall"?e.placement_mode:"both";return{id:e.id,user_id:e.user_id,name:typeof e.name=="string"&&e.name.trim()?e.name.trim():"תבנית אישית",payload_version:typeof e.payload_version=="number"?e.payload_version:Ip,payload:s,width_mm:typeof e.width_mm=="number"?e.width_mm:o.widthMm,depth_mm:typeof e.depth_mm=="number"?e.depth_mm:o.depthMm,height_mm:typeof e.height_mm=="number"?e.height_mm:o.heightMm,placement_mode:r,source_project_id:typeof e.source_project_id=="string"?e.source_project_id:null,created_at:typeof e.created_at=="string"?e.created_at:new Date(0).toISOString(),updated_at:typeof e.updated_at=="string"?e.updated_at:new Date(0).toISOString()}}function IJ(t){const[e,s]=m.useState([]),[o,r]=m.useState(!1),[i,a]=m.useState(null),l=m.useCallback(async()=>{if(!t){s([]),a(null);return}r(!0),a(null);const{data:h,error:x}=await Yg().select("*").eq("user_id",t).order("updated_at",{ascending:!1});if(x){Ys.error("[MyFloorplanTemplates] load failed",x),a(x.message||"טעינת התבניות נכשלה"),r(!1);return}s((h??[]).map(Q4).filter(f=>!!f)),r(!1)},[t]);m.useEffect(()=>{l()},[l]);const c=m.useCallback(async h=>{if(!t)throw new Error("יש להתחבר כדי לשמור תבנית");const x=h.name.trim().slice(0,80);if(!x)throw new Error("יש לתת שם לתבנית");const f=Yf(h.payload),p=f?x6(f):null;if(!f||!p)throw new Error("התבנית אינה תקינה");const b=new Date().toISOString(),{data:M,error:g}=await Yg().insert({user_id:t,name:x,payload_version:Ip,payload:f,width_mm:p.widthMm,depth_mm:p.depthMm,height_mm:p.heightMm,placement_mode:h.placementMode,source_project_id:h.sourceProjectId??null,updated_at:b}).select("*").single();if(g)throw new Error(`שמירת התבנית נכשלה: ${g.message}`);const w=Q4(M);if(!w)throw new Error("התבנית נשמרה אך לא ניתן היה לקרוא אותה");return s(k=>[w,...k.filter(_=>_.id!==w.id)]),w},[t]),d=m.useCallback(async(h,x)=>{const f=x.trim().slice(0,80);if(!f)throw new Error("יש לתת שם לתבנית");const p=new Date().toISOString(),{error:b}=await Yg().update({name:f,updated_at:p}).eq("id",h);if(b)throw new Error(`שינוי השם נכשל: ${b.message}`);s(M=>M.map(g=>g.id===h?{...g,name:f,updated_at:p}:g))},[]),u=m.useCallback(async h=>{const{error:x}=await Yg().delete().eq("id",h);if(x)throw new Error(`מחיקת התבנית נכשלה: ${x.message}`);s(f=>f.filter(p=>p.id!==h))},[]);return{templates:e,loading:o,error:i,create:c,rename:d,remove:u,refresh:l}}const kw="1";async function TJ(t){try{const e=new Image;e.crossOrigin="anonymous",await new Promise((r,i)=>{e.onload=()=>r(),e.onerror=()=>i(),e.src=t});const s=document.createElement("canvas");
381s.width=e.naturalWidth,s.height=e.naturalHeight;const o=s.getContext("2d");return o?(o.drawImage(e,0,0),s.toDataURL("image/png")):null}catch{return null}}async function SJ(t){const e=await TJ(t.imageUrl),s={version:kw,createdAt:t.createdAt||new Date().toISOString(),updatedAt:new Date().toISOString(),name:t.filename.replace(/\.[^.]+$/,"").replace(/[-_]/g," "),imageFilename:t.filename,imageDataUrl:e,calibration:t.calibration,wallTypeSettings:t.wallTypeSettings,traceRoomLabels:t.traceRoomLabels,floorplanSketch:t.floorplanSketch,walls:t.walls,openings:t.openings,furniture:t.furniture},o=JSON.stringify(s,null,2),r=new Blob([o],{type:"application/json"}),i=URL.createObjectURL(r),a=document.createElement("a");a.href=i,a.download=`${t.filename.replace(/\.[^.]+$/,"")}.floorplan.json`,a.click(),URL.revokeObjectURL(i)}function PJ(t){const e=JSON.parse(t);if(!e||typeof e!="object")throw new Error("Invalid project file: not an object");if(e.version!==kw)throw new Error(`Unsupported project version: ${e.version} (expected ${kw})`);if(!Array.isArray(e.walls))throw new Error("Invalid project file: missing walls array");return e}function $x({title:t,children:e}){return n.jsxs("div",{className:"mb-4 last:mb-0",children:[n.jsx("div",{className:"mb-2 border-b border-[#EC7357]/25 pb-1.5 text-right",children:n.jsx("span",{className:"text-[10px] font-extrabold uppercase tracking-wide text-[#182137]/75 dark:text-white/60",children:t})}),n.jsx("div",{className:"grid grid-cols-4 gap-2",dir:"rtl",children:e})]})}function Xx({label:t,isActive:e,onClick:s,icon:o,accentColor:r}){return n.jsxs("button",{onClick:s,type:"button",className:`
382        group relative flex flex-col items-center justify-center gap-1.5 rounded-xl px-1 py-2 text-[9px] font-semibold
383        transition-all duration-150 cursor-pointer select-none border
384        ${e?"bg-gradient-to-b from-[#EC7357] to-[#D84B2E] text-white border-[#B33D24] shadow-[0_2px_8px_rgba(216,75,46,0.25)]":"border-[#182137]/10 bg-white text-[#182137]/80 shadow-[0_1px_0_rgba(24,33,55,0.05)] hover:border-[#EC7357]/35 hover:bg-[#FDF6F4] dark:border-white/10 dark:bg-white/[0.04] dark:text-white/80 dark:hover:bg-white/10"}
385      `,children:[o&&n.jsx("span",{className:O("flex min-h-[2.75rem] w-full max-w-[3.25rem] items-center justify-center rounded-lg border transition-colors",e?"border-white/25 bg-white/15":"border-[#182137]/8 bg-[#F7F4EF] dark:border-white/10 dark:bg-white/[0.07]"),children:n.jsx("span",{className:O("flex items-center justify-center",!e&&"group-hover:scale-105"),children:o})}),n.jsx("span",{className:"max-w-full leading-tight text-center [text-wrap:balance]",children:t})]})}const AJ=[{hex:"#FFFFFF",label:"לבן",labelEn:"White"},{hex:"#FAF7F2",label:"לבן חם",labelEn:"Warm White"},{hex:"#E8DCC8",label:"פשתן",labelEn:"Linen"},{hex:"#F5E6C8",label:"קרם",labelEn:"Cream"},{hex:"#D5C7A9",label:"חול",labelEn:"Sand"},{hex:"#8B7355",label:"מוקה",labelEn:"Mocha"},{hex:"#C2B8A3",label:"אפור חם",labelEn:"Warm Gray"},{hex:"#9E9589",label:"אבן",labelEn:"Stone"},{hex:"#d6d3ce",label:"בטון",labelEn:"Concrete"},{hex:"#a09e99",label:"אפור",labelEn:"Gray"},{hex:"#B2BDA0",label:"מרווה",labelEn:"Sage"},{hex:"#808A42",label:"זית",labelEn:"Olive"},{hex:"#3D5A3D",label:"יער",labelEn:"Forest"},{hex:"#D4A5A5",label:"ורוד עתיק",labelEn:"Antique Pink"},{hex:"#C4856B",label:"טרקוטה",labelEn:"Terracotta"},{hex:"#A67B5B",label:"חלודה",labelEn:"Rust"},{hex:"#c4956b",label:"עץ",labelEn:"Wood"},{hex:"#A8C0D0",label:"תכלת",labelEn:"Sky Blue"},{hex:"#2B4C7E",label:"כחול כהה",labelEn:"Navy"},{hex:"#4A7C7E",label:"טורקיז",labelEn:"Turquoise"},{hex:"#5c4033",label:"כהה",labelEn:"Dark"},{hex:"#3D3D3D",label:"פחם",labelEn:"Charcoal"},{hex:"#2D2926",label:"שחור חם",labelEn:"Warm Black"},{hex:"#3C2415",label:"אספרסו",labelEn:"Espresso"}],LJ=new Set(["בטון מלוטש","בטון גולמי"]);function Df({mode:t,target:e,scopeLabel:s,variant:o="floating",onClose:r,hideGeometryControls:i=!1,currentTextureUrl:a,tileWidthCm:l,tileHeightCm:c,measurementUnit:d="cm",orientation:u=Hf,groutWidthMm:h,groutColor:x,onSelectTexture:f,onSelectColor:p,onTileSizeChange:b,onOrientationChange:M,onGroutChange:g,onClear:w,savedTiles:k,getPublicUrl:_,onUploadTile:j,onRemoveTile:v,onRenameTile:C,personalAssetsLocked:N=!1,onPremiumRequired:P,ceilingStyle:L,onCeilingStyleChange:A,gapWidthCm:W,onGapWidthChange:S,coveWidthCm:B,coveDepthCm:R,onCoveDimensionsChange:z,floorIsDivided:X,onFloorDivide:ft,onFloorMerge:tt,floorRegionSelected:G,wallIsDivided:Y,onWallDivide:J,onWallMerge:Mt,wallRegionSelected:Rt}){var Be;const{t:it,i18n:st}=yn(),ct=xc(),pt=o==="embedded",[xt,_t]=m.useState(t);m.useEffect(()=>{i&&xt==="edit"&&_t("material")},[i,xt]);const[Ft,Vt]=m.useState("builtin"),vt=m.useRef(null),Ht=m.useRef(null),[Tt,Zt]=m.useState(!1),[At,ut]=m.useState(null),kt=ei(u),Et=Ka(d);m.useEffect(()=>{if(pt)return;const wt=Ne=>{const Le=Ne.target;Le&&Le.tagName==="CANVAS"||Ht.current&&!Ht.current.contains(Le)&&r()},ve=setTimeout(()=>window.addEventListener("mousedown",wt),100);return()=>{clearTimeout(ve),window.removeEventListener("mousedown",wt)}},[r,pt]);const{wall:ht,floor:gt,ceiling:Pt,roof:U}
385=U_(),mt=m.useMemo(()=>{if(e==="wall")return ht;if(e==="ceiling")return Pt;if(e==="roof")return U;if(e==="shape"){const wt=[...ht,...gt,...Pt,...U],ve=new Set;return wt.filter(Ne=>ve.has(Ne.value)?!1:(ve.add(Ne.value),!0))}return gt},[e,ht,gt,Pt,U]);a&&!a.startsWith("#")&&(((Be=mt.find(wt=>wt.value===a))==null?void 0:Be.type)==="tile"||a&&a.startsWith("/textures/"));const Lt=wt=>{if(!(!wt.type.startsWith("image/")||!j)){if(N){P==null||P();return}j(wt,wt.name.replace(/\.[^.]+$/,"").slice(0,16)||it(`materials.defaultUploadName.${e}`,{defaultValue:e==="wall"?"חיפוי":e==="ceiling"?"תקרה":e==="roof"?"גג":e==="shape"?"חומר":"אריח"}))}},oe=n.jsxs("div",{className:O("flex rounded-lg p-0.5",ct?"bg-white/5":"bg-black/[0.04]"),children:[n.jsx(fy,{isDark:ct,icon:n.jsx(HI,{size:12}),label:it("materials.tabs.materials",{defaultValue:"חומרים"}),isActive:xt==="material",onClick:()=>_t("material")}),n.jsx(fy,{isDark:ct,icon:n.jsx(Ew,{size:12}),label:it("materials.tabs.colors",{defaultValue:"צבעים"}),isActive:xt==="color",onClick:()=>_t("color")}),!i&&n.jsx(fy,{isDark:ct,icon:n.jsx(Q_,{size:12}),label:it("materials.tabs.edit",{defaultValue:"עריכה"}),isActive:xt==="edit",onClick:()=>_t("edit")})]}),he=xt==="material"&&n.jsxs("div",{className:O("flex items-center justify-start gap-0.5 px-3 py-2 border-b",ct?"border-white/10":"border-black/[0.04]"),children:[n.jsx(e_,{isDark:ct,label:it(`materials.builtin.${e}`,{defaultValue:e==="wall"?"חיפויים לקירות":e==="ceiling"?"תקרות":e==="roof"?"חומרי גג":e==="shape"?"חומרים":"ריצוף"}),isActive:Ft==="builtin",onClick:()=>Vt("builtin")}),n.jsx(e_,{isDark:ct,label:it(`materials.mine.${e}`,{defaultValue:e==="wall"?"החיפויים שלי":e==="ceiling"?"התקרות שלי":e==="roof"?"חומרי הגג שלי":e==="shape"?"החומרים שלי":"המרצפות שלי"}),isActive:Ft==="my",onClick:()=>Vt("my")})]}),pe=e==="floor"&&(ft||tt)&&n.jsxs("div",{className:"bg-black/[0.03] rounded-xl p-2.5 space-y-2",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-[10px] font-semibold text-[#71717a] uppercase tracking-wider",children:it("materials.floorDivision",{defaultValue:"חלוקת רצפה"})}),X&&n.jsx("span",{className:"text-[9px] text-[#18181b] bg-white px-1.5 py-0.5 rounded-md border border-black/[0.06]",children:it("materials.active",{defaultValue:"פעיל"})})]}),X?n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"text-[10px] text-[#71717a] leading-relaxed",children:it("materials.floorDivideHint",{defaultValue:"גרור את הפינות או קווי הגבול כדי לעצב את האזור. לחץ על אזור ריק לבחור ריצוף נוסף."})}),n.jsx("button",{onClick:tt,className:"w-full py-1.5 rounded-lg bg-white border border-black/[0.08] text-[#18181b] text-[11px] font-medium hover:bg-black/[0.03] transition-all cursor-pointer",children:it("materials.mergeFloor",{defaultValue:"איחוד חזרה לרצפה אחת"})})]}):n.jsx("button",{onClick:ft,disabled:!ft,className:"w-full py-2 rounded-lg bg-gradient-to-b from-[#EC7357] to-[#D84B2E] text-white text-[11px] font-semibold hover:from-[#f08068] hover:to-[#C04428] transition-all disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer shadow-sm",children:it("materials.divide",{defaultValue:"חלוקה ↴"})})]}),Ge=e==="wall"&&(J||Mt)&&n.jsxs("div",{className:"bg-black/[0.03] rounded-xl p-2.5 space-y-2",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-[10px] font-semibold text-[#71717a] uppercase tracking-wider",children:it("materials.wallDivision",{defaultValue:"חלוקת חיפוי"})}),Y&&n.jsx("span",{className:"text-[9px] text-[#18181b] bg-white px-1.5 py-0.5 rounded-md border border-black/[0.06]",children:it("materials.active",{defaultValue:"פעיל"})})]}),Y?n.jsxs(n.Fragment,{children:[n.jsx("p",{className:"text-[10px] text-[#71717a] leading-relaxed",children:it("materials.wallDivideHint",{defaultValue:"גרור את הפינות או קווי הגבול כדי לעצב את החיפוי. לחץ על אזור ריק לבחור חיפוי נוסף."})}),n.jsx("button",{onClick:Mt,className:"w-full py-1.5 rounded-lg bg-white border border-black/[0.08] text-[#18181b] text-[11px] font-medium hover:bg-black/[0.03] transition-all cursor-pointer",children:it("materials.mergeWall",{defaultValue:"איחוד חזרה לחיפוי אחד"})})]}):n.jsx("button",{onClick:J,disabled:!J,className:"w-full py-2 rounded-lg bg-gradient-to-b from-[#EC7357] to-[#D84B2E] text-white text-[11px] font-semibold hover:from-[#f08068] hover:to-[#C04428] transition-all disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer shadow-sm",children:it("materials.divide",{defaultValue:"חלוקה ↴"})})]}),Qt=pt?O("flex flex-col",ct?"bg-[#141416]":"bg-white/85"):O("absolute left-0 top-0 bottom-0 w-[300px] z-40 flex flex-col backdrop-blur-xl animate-[slideInLeft_0.25s_ease-out]",ct?"bg-[#141416]/95 border-r border-white/10 shadow-[0_8px_32px_-12px_rgba(0,0,0,0.55)]":"bg-white/[0.88] border-r border-black/[0.05] shadow-[0_8px_32px_-12px_rgba(0,0,0,0.12)]"),te=pt?"px-3 py-3 space-y-3"
385:"flex-1 overflow-y-auto px-3 py-3 space-y-3";return n.jsxs("div",{ref:pt?void 0:Ht,className:Qt,onMouseDown:pt?void 0:wt=>wt.stopPropagation(),"data-material-sidebar-variant":pt?"embedded":"floating",children:[pt?n.jsx("div",{className:O("flex items-center justify-start px-3 py-2 border-b",ct?"border-white/10":"border-black/[0.05]"),children:oe}):n.jsxs("div",{className:O("flex items-center justify-between px-4 py-2.5 border-b",ct?"border-white/10":"border-black/[0.05]"),children:[n.jsx("button",{onClick:r,className:O("w-7 h-7 rounded-lg flex items-center justify-center transition-all cursor-pointer",ct?"text-white/45 hover:text-white hover:bg-white/10":"text-[#71717a] hover:text-[#18181b] hover:bg-black/5"),children:n.jsx(v1,{size:15})}),oe]}),!pt&&s&&n.jsxs("div",{className:O("px-4 py-2 border-b text-right",ct?"border-white/10 bg-white/[0.03]":"border-black/[0.05] bg-[#fafafa]"),children:[n.jsx("div",{className:O("text-[9px] font-medium uppercase tracking-wider",ct?"text-white/40":"text-[#a1a1aa]"),children:it("materials.editing",{defaultValue:"עורך"})}),n.jsx("div",{className:O("text-[12px] font-semibold mt-0.5",ct?"text-white/90":"text-[#18181b]"),children:s})]}),he,n.jsxs("div",{className:te,children:[xt==="material"&&n.jsxs(n.Fragment,{children:[n.jsx("input",{ref:vt,type:"file",accept:"image/png,image/jpeg,image/webp",className:"hidden",onChange:wt=>{var Ne;const ve=(Ne=wt.target.files)==null?void 0:Ne[0];ve&&Lt(ve),wt.target.value=""}}),Ft==="my"?n.jsxs("section",{children:[n.jsxs("div",{className:"grid grid-cols-4 gap-1.5",children:[n.jsxs("button",{type:"button",onClick:()=>{var wt;N?P==null||P():(wt=vt.current)==null||wt.click()},onDragOver:wt=>{wt.preventDefault(),Zt(!0)},onDragLeave:()=>Zt(!1),onDrop:wt=>{wt.preventDefault(),Zt(!1);const ve=wt.dataTransfer.files[0];ve&&Lt(ve)},className:`relative aspect-square rounded-lg border-2 border-dashed flex items-center justify-center transition-all cursor-pointer ${Tt?"border-[#18181b] bg-black/[0.04]":"border-black/15 hover:border-black/30 hover:bg-black/[0.02] bg-[#fafafa]"}`,children:[n.jsx(pm,{size:18,className:Tt?"text-[#18181b]":"text-[#a1a1aa]"}),N&&n.jsx("span",{className:"absolute start-1 top-1 grid h-5 w-5 place-items-center rounded-md bg-[#182137] text-[#F7F4EF] shadow-sm",children:n.jsx(fp,{size:10,strokeWidth:2.5})})]}),k==null?void 0:k.map(wt=>{const ve=(_==null?void 0:_(wt.storage_path))??"";return n.jsx(n_,{isDark:ct,url:ve,label:wt.name,isActive:a===ve,locked:N,onClick:()=>N?P==null?void 0:P():f(ve),onRemove:v?()=>N?P==null?void 0:P():v(wt):void 0,isEditing:At===wt.id,onStartEdit:()=>N?P==null?void 0:P():ut(wt.id),onRename:C?Ne=>{C(wt.id,Ne),ut(null)}:void 0,onCancelEdit:()=>ut(null)},wt.id)})]}),(!k||k.length===0)&&n.jsx("p",{className:"text-center text-[11px] text-[#b5afa6] mt-6",children:it("materials.emptyCustom",{defaultValue:"אין חיפויים מותאמים אישית עדיין"})})]}):n.jsx("section",{children:n.jsx("div",{className:"grid grid-cols-4 gap-1.5",children:(e==="ceiling"?mt.filter(wt=>LJ.has(wt.label)):mt).map(wt=>n.jsx(n_,{isDark:ct,url:wt.value,label:wt.label,isActive:a===wt.value,onClick:()=>f(wt.value)},wt.id))})}),n.jsx("button",{onClick:w,className:"w-full py-1.5 rounded-lg text-[#71717a] hover:text-[#18181b] text-[10px] font-medium hover:bg-black/[0.04] transition-all cursor-pointer",children:e==="floor"&&G||e==="wall"&&Rt?it("materials.deleteRegion",{defaultValue:"מחק אזור"}):it(`materials.clear.${e}`,{defaultValue:`ללא ${e==="wall"?"חיפוי":e==="ceiling"?"חיפוי תקרה":e==="roof"?"חיפוי גג":e==="shape"?"חיפוי":"ריצוף"}`})}),pe,Ge]}),xt==="color"&&n.jsxs(n.Fragment,{children:[n.jsx("section",{children:n.jsx("div",{className:"grid grid-cols-6 gap-1.5",children:AJ.map(wt=>{const ve=a===wt.hex,Ne=parseInt(wt.hex.replace("#",""),16)>11184810;return n.jsx("button",{onClick:()=>p(wt.hex),title:st.language==="he"?wt.label:wt.labelEn,className:"group cursor-pointer",children:n.jsx("div",{className:`w-full aspect-square rounded-lg transition-all ${ve?"ring-2 ring-[#D84B2E] ring-offset-2 ring-offset-white scale-105":`${Ne?"border border-black/10":""} shadow-[0_1px_2px_rgba(0,0,0,0.06)] group-hover:scale-105`}`,style:{backgroundColor:wt.hex}})},wt.hex)})})}),n.jsxs("div",{className:"flex items-center gap-2.5 bg-black/[0.03] rounded-xl px-3 py-2",children:[n.jsx("input",{type:"color",defaultValue:a!=null&&a.startsWith("#")?a:"#ffffff",onChange:wt=>p(wt.target.value),className:"w-7 h-7 rounded-lg cursor-pointer bg-transparent border border-black/10"}),n.jsx("span",{className:"text-[10px] text-[#52525b] font-medium",children:it("materials.customColor",{defaultValue:"צבע מותאם אישית"})})]})]}),xt==="edit"&&!i&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"bg-black/[0.03] rounded-xl p-2.5 space-y-2",children:[n.jsx("span",{className:"text-[10px] font-semibold text-[#71717a] uppercase tracking-wider block text-right",children:it(`materials.size.${e}`,{defaultValue:e==="wall"?"גודל חיפוי":e==="ceiling"?"גודל":"גודל אריח"})}),n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx(t_,{isDark:ct,valueMm:l*10,measurementUnit:d,onCommitMm:wt=>b(Math.max(1,Math.round(wt/10)),c)}),n.jsx("span",{className:"text-[#a1a1aa] text-[10px]",children:"×"}),n.jsx(t_,{isDark:ct,valueMm:c*10,measurementUnit:d,onCommitMm:wt=>b(l,Math.max(1,Math.round(wt/10)))}),n.jsx("span",{className:"text-[9px] text-[#71717a] font-medium shrink-0",children:Et})]}),e==="floor"&&n.jsx("div",{className:"grid grid-cols-3 gap-1",children:[[120,60],[100,100],[120,120],[60,90],[90,90],[360,120]].map(([wt,ve])=>{const Ne=l===wt&&c===ve;return n.jsxs(Vh,{isDark:ct,small:!0,active:Ne,onClick:()=>b(wt,ve),children:[De(wt*10,d),"×",De(ve*10,d)]},`${wt}x${ve}`)})})]}),M&&(e==="wall"||e==="shape")&&n.jsxs("div",{className:"bg-black/[0.03] rounded-xl p-2.5 space-y-2",children:[n.jsx("span",{className:"text-[10px] font-semibold text-[#71717a] uppercase tracking-wider block text-right",children:it("materials.orientation",{defaultValue:"כיוון חיפוי"})}),n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx(Vh,{isDark:ct,active:kt==="vertical",onClick:()=>M("vertical"),children:it("materials.vertical",{defaultValue:"אנכי"})}),n.jsx(Vh,{isDark:ct,active:kt==="horizontal",onClick:()=>M("horizontal"),children:it("materials.horizontal",{defaultValue:"אופקי"})})]})]}),n.jsxs("div",{className:"bg-black/[0.03] rounded-xl p-2.5 space-y-2.5",children:[n.jsx("span",{className:`font-semibold text-[#18181b] uppercase tracking-wider block text-right ${e==="floor"?"text-[14px]":"text-[10px] text-[#71717a]"}`,children:it(`materials.grout.${e}`,{defaultValue:e==="wall"?"פרופיל ניתוק":e==="ceiling"?"ניתוק":"פוגה"})}),n.jsxs("div",{className:"space-y-1",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-[10px] text-[#52525b] font-medium",children:it(`materials.groutSize.${e}`,{defaultValue:e==="wall"?"עובי פרופיל":e==="ceiling"?"עובי":"רוחב הפוגה"})}),n.jsx("span",{className:"text-[10px] text-[#18181b] font-mono bg-white px-1.5 py-0.5 rounded-md border border-black/[0.06]",children:$i(h,d)})]}),n.jsx("input",{type:"range",min:0,max:15,step:1,value:h,onChange:wt=>g(Number(wt.target.value),x),className:"w-full h-1.5 accent-[#D84B2E] curs
385or-pointer"})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("span",{className:"text-[10px] text-[#52525b] font-medium block text-right",children:it(`materials.groutColor.${e}`,{defaultValue:e==="wall"?"צבע פרופיל הניתוק":e==="ceiling"?"צבע":"צבע הרוב"})}),n.jsx(WJ,{value:x,onChange:wt=>g(h,wt),isDark:ct})]})]}),pe,Ge,e==="ceiling"&&A&&n.jsxs("div",{className:"bg-black/[0.03] rounded-xl p-2.5 space-y-2",children:[n.jsx("span",{className:"text-[10px] font-semibold text-[#71717a] uppercase tracking-wider",children:it("materials.ceilingStyle",{defaultValue:"סגנון תקרה"})}),n.jsx("div",{className:"flex items-center gap-1",children:[{key:"flat",label:it("materials.ceiling.flat",{defaultValue:"רגילה"})},{key:"gap",label:it("materials.ceiling.gap",{defaultValue:"ניתוק"})},{key:"step",label:it("materials.ceiling.step",{defaultValue:"מדרגה"})}].map(wt=>n.jsx(Vh,{isDark:ct,active:(L??"flat")===wt.key,onClick:()=>A(wt.key),children:wt.label},wt.key))}),L==="gap"&&S&&n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("span",{className:"text-[9px] text-[#71717a] font-medium shrink-0 w-9",children:it("materials.width",{defaultValue:"רוחב"})}),[1,2,3,5].map(wt=>n.jsx(Vh,{isDark:ct,small:!0,active:(W??2)===wt,onClick:()=>S(wt),children:$i(wt*10,d)},wt))]}),L==="step"&&z&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("span",{className:"text-[9px] text-[#71717a] font-medium shrink-0 w-9",children:it("materials.width",{defaultValue:"רוחב"})}),[20,30,40].map(wt=>n.jsx(Vh,{isDark:ct,small:!0,active:(B??30)===wt,onClick:()=>z(wt,R??10),children:$i(wt*10,d)},wt))]}),n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsx("span",{className:"text-[9px] text-[#71717a] font-medium shrink-0 w-9",children:it("materials.depth",{defaultValue:"עומק"})}),[5,10,15].map(wt=>n.jsx(Vh,{isDark:ct,small:!0,active:(R??10)===wt,onClick:()=>z(B??30,wt),children:$i(wt*10,d)},wt))]})]})]})]})]})]})}function WJ({value:t,onChange:e,isDark:s}){const o=m.useRef(null),r=/^#[0-9A-Fa-f]{6}$/.test(t)?t:"#c8c4bc";return n.jsxs("div",{className:"relative w-full",children:[n.jsx("input",{ref:o,type:"color",value:r,onChange:i=>e(i.target.value),className:"pointer-events-none absolute start-0 top-0 h-px w-px opacity-0",tabIndex:-1,"aria-hidden":!0}),n.jsxs("button",{type:"button",onPointerDown:i=>i.stopPropagation(),onClick:()=>{var i;return(i=o.current)==null?void 0:i.click()},className:O("flex w-full items-center gap-2 rounded-lg border p-1.5 transition-colors cursor-pointer",s?"border-white/10 bg-white/5 hover:border-white/20":"border-black/[0.06] bg-white hover:border-black/[0.12]"),children:[n.jsx("span",{className:O("h-7 w-7 shrink-0 rounded-md border shadow-inner",s?"border-white/15":"border-black/10"),style:{backgroundColor:r}}),n.jsx("span",{className:O("text-[10px] font-mono uppercase",s?"text-white/70":"text-[#52525b]"),children:r})]})]})}function t_({valueMm:t,measurementUnit:e,onCommitMm:s,isDark:o}){const[r,i]=m.useState(De(t,e));m.useEffect(()=>{i(De(t,e))},[e,t]);const a=()=>{const l=ni(r,e);l!==null&&l>=10&&l<=9990?s(l):i(De(t,e))};return n.jsx("input",{type:"text",inputMode:"decimal",value:r,onChange:l=>i(l.target.value),onBlur:a,onKeyDown:l=>{l.key==="Enter"&&(a(),l.target.blur())},className:O("w-full px-2 py-1 text-[11px] rounded-lg text-center border transition-all focus:outline-none focus:ring-1",o?"bg-white/5 border-white/10 text-white/90 focus:border-[#EC7357]/50 focus:ring-[#EC7357]/20":"bg-white border-black/[0.08] text-[#18181b] focus:border-[#D84B2E] focus:ring-[#EC7357]/25")})}function fy({icon:t,label:e,isActive:s,onClick:o,isDark:r}){return n.jsxs("button",{onClick:o,className:O("flex items-center gap-1.5 px-3 py-1.5 rounded-md text-[11px] font-semibold transition-all cursor-pointer",s?r?"bg-gradient-to-b from-[#EC7357] to-[#D84B2E] text-white shadow-sm":"bg-white text-[#18181b] shadow-[0_1px_2px_rgba(0,0,0,0.06)]":r?"text-white/50 hover:text-white/80":"text-[#71717a] hover:text-[#18181b]"),children:[t,e]})}function e_({label:t,isActive:e,onClick:s,isDark:o}){return n.jsx("button",{onClick:s,className:O("px-3 py-1 rounded-md text-[11px] font-medium transition-all cursor-pointer",e?"bg-gradient-to-b from-[#EC7357] to-[#D84B2E] text-white shadow-sm":o?"text-white/50 hover:text-white/85 hover:bg-white/5":"text-[#71717a] hover:text-[#18181b] hover:bg-black/[0.04]"),children:t})}function Vh({children:t,active:e,small:s,onClick:o,isDark:r}){return n.jsx("button",{onClick:o,className:O("flex-1 rounded-lg font-medium transition-all cursor-pointer border",s?"py-1 text-[10px]":"py-1.5 text-[11px]",e?"bg-gradient-to-b from-[#EC7357] to-[#D84B2E] text-white border-transparent shadow-sm":r?"bg-white/5 text-white/75 border-white/10 hover:bg-white/10":"bg-white text-[#52525b] border-black/[0.06] hover:bg-[#FDF6F4] hover:border-[#
385EC7357]/25"),children:t})}function n_({url:t,label:e,isActive:s,onClick:o,onRemove:r,isEditing:i,onStartEdit:a,onRename:l,onCancelEdit:c,isDark:d,locked:u=!1}){return n.jsxs("div",{className:"flex flex-col gap-0.5",children:[n.jsxs("button",{onClick:o,className:O("relative group rounded-lg overflow-hidden transition-all cursor-pointer aspect-square",s?d?"ring-2 ring-[#EC7357] ring-offset-2 ring-offset-[#141416]":"ring-2 ring-[#D84B2E] ring-offset-2 ring-offset-white":d?"border border-white/10 shadow-sm hover:border-white/20":"border border-black/[0.06] shadow-[0_1px_2px_rgba(0,0,0,0.04)] hover:border-black/[0.18]"),children:[n.jsx("img",{src:t,alt:e,className:O("w-full h-full object-cover",u&&"opacity-55 grayscale-[0.2]")}),u&&n.jsx("span",{className:"pointer-events-none absolute inset-0 grid place-items-center bg-[#182137]/12",children:n.jsx("span",{className:"grid h-7 w-7 place-items-center rounded-lg bg-[#182137] text-[#F7F4EF] shadow-[0_5px_14px_rgba(24,33,55,0.24)]",children:n.jsx(fp,{size:13,strokeWidth:2.5})})}),r&&n.jsx("button",{onClick:h=>{h.stopPropagation(),r()},className:"absolute top-0.5 right-0.5 w-4 h-4 rounded-full bg-red-500 text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",children:n.jsx(Gr,{size:8})})]}),i&&l?n.jsx("input",{autoFocus:!0,defaultValue:e,className:O("text-[9px] rounded px-1 py-0.5 text-center outline-none border",d?"text-white bg-white/10 border-[#EC7357]/50":"text-[#18181b] bg-white border-[#D84B2E]"),onBlur:h=>{const x=h.target.value.trim();x?l(x):c==null||c()},onKeyDown:h=>{h.key==="Enter"&&h.target.blur(),h.key==="Escape"&&(c==null||c())},onClick:h=>h.stopPropagation()}):n.jsx("span",{className:O("text-[9px] text-center truncate leading-tight",d?"text-white/55":"text-[#52525b]",a&&(d?"cursor-text hover:text-white/90":"cursor-text hover:text-[#18181b]")),onClick:h=>{a&&(h.stopPropagation(),a())},children:e})]})}const RJ=[0,45,60,90,180];function OJ(t){const e=t.replace(/([a-z])([A-Z])/g,"$1 $2").toLowerCase().split(/[^\p{L}]+/u);return e.some(s=>["lamp","lamps","light","lights","lighting","מנורה","מנורת","תאורה"].includes(s))?!1:e.some(s=>["floor","flooring","רצפה","ריצוף"].includes(s))}function HJ(t,e,s){return Math.max(e,Math.min(s,t))}function xy({label:t,value:e,min:s,max:o,step:r,measurementUnit:i,onChange:a}){const l=Ka(i),[c,d]=m.useState(De(e,i)),[u,h]=m.useState(e),x=m.useRef(!1),f=m.useRef(a);f.current=a;const p=m.useRef(null),b=m.useRef(e);m.useEffect(()=>{x.current||h(e)},[e]),m.useEffect(()=>()=>{p.current!=null&&window.clearTimeout(p.current)},[]);const M=m.useRef(!1),g=j=>{h(j),b.current=j,M.current=!0,p.current==null&&(p.current=window.setTimeout(()=>{p.current=null,f.current(b.current)},100))},w=()=>{x.current=!1,p.current!=null&&(window.clearTimeout(p.current),p.current=null),M.current&&(M.current=!1,f.current(b.current))},k=Math.max(0,Math.min(100,(u-s)/(o-s)*100));m.useEffect(()=>{d(De(e,i))},[i,e]);const _=()=>{const j=ni(c,i);if(j===null){d(De(e,i));return}const v=HJ(j,s,o);d(De(v,i)),a(v)};return n.jsxs("div",{className:"grid grid-cols-[42px_minmax(0,1fr)_68px] items-center gap-2",children:[n.jsx("span",{className:"shrink-0 text-[10px] font-black text-[#182137]/70",children:t}),n.jsxs("div",{className:"relative flex h-5 min-w-0 items-center",children:[n.jsx("div",{className:"absolute inset-x-0 h-1.5 rounded-full bg-[#E6E1DA]"}),n.jsx("div",{className:"absolute h-1.5 rounded-full bg-[#D84B2E] shadow-[0_1px_3px_rgba(180,60,40,0.18)]",style:{width:`${k}%`,right:0}}),n.jsx("input",{type:"range",min:s,max:o,step:r,value:u,onChange:j=>g(Number(j.target.value)),onPointerDown:()=>{x.current=!0,b.current=u},onPointerUp:w,onKeyUp:w,className:`relative z-10 h-5 w-full cursor-pointer appearance-none bg-transparent
386            [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-4 [&::-webkit-slider-thumb]:h-4
387            [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-white
388            [&::-webkit-slider-thumb]:border-2 [&::-webkit-slider-thumb]:border-[#D84B2E]
389            [&::-webkit-slider-thumb]:shadow-[0_2px_6px_rgba(216,75,46,0.25),0_0_0_5px_rgba(236,115,87,0.10)]
390            [&::-webkit-slider-thumb]:cursor-grab [&::-webkit-slider-thumb]:active:cursor-grabbing
391            [&::-webkit-slider-thumb]:transition-all [&::-webkit-slider-thumb]:hover:scale-110
392            [&::-moz-range-thumb]:w-4 [&::-moz-range-thumb]:h-4 [&::-moz-range-thumb]:rounded-full
393            [&::-moz-range-thumb]:bg-white [&::-moz-range-thumb]:border-2 [&::-moz-range-thumb]:border-[#D84B2E]
394            [&::-moz-range-thumb]:cursor-grab`})]}),n.jsxs("div",{className:"flex h-8 shrink-0 items-baseline justify-center gap-0.5 rounded-lg border border-[#182137]/10 bg-white/95 px-1.5 shadow-[inset_0_1px_2px_rgba(24,33,55,0.04)] focu
394s-within:border-[#D84B2E]/45 focus-within:ring-2 focus-within:ring-[#EC7357]/12",children:[n.jsx("input",{type:"text",inputMode:"decimal","aria-label":`${t} ${l}`,value:c,onChange:j=>d(j.target.value),onBlur:_,onKeyDown:j=>{j.key==="Enter"&&(_(),j.target.blur())},className:"w-9 bg-transparent text-center font-mono text-[12px] font-bold tabular-nums text-[#182137] outline-none"}),n.jsx("span",{className:"text-[8.5px] font-bold text-[#182137]/35",children:l})]})]})}function BJ({furniture:t,selectedIds:e,onSelectedIdsChange:s,onFurnitureChange:o,effectiveScale:r,onPlaceMore:i,materialSlotsByType:a,materialSlotsLoading:l=!1,materialSlotsError:c=!1,onRetryMaterialSlots:d,selectedSmartGlbPart:u,onSmartGlbPartSelect:h,onSmartGlbPartClear:x,savedMaterialTiles:f,getMaterialTilePublicUrl:p,onUploadMaterialTile:b,onRemoveMaterialTile:M,onRenameMaterialTile:g,personalAssetsLocked:w=!1,onPremiumRequired:k,measurementUnit:_="cm"}){var kt,Et;const{t:j}=yn(),[v,C]=m.useState("floor");if(e.size===0)return null;if(e.size>1)return n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("div",{className:"text-[11px] font-semibold text-[#18181b]",children:j("furnitureInspector.selectedCount",{defaultValue:"{{count}} פריטים נבחרו",count:e.size})}),n.jsx("button",{type:"button",onClick:()=>{o(t.filter(ht=>!e.has(ht.id))),s(new Set)},className:"px-2.5 py-1 rounded-lg text-[10px] font-medium text-red-600 bg-red-50 border border-red-100 hover:bg-red-100 transition-all cursor-pointer",children:j("furnitureInspector.deleteAll",{defaultValue:"מחק הכל"})})]}),n.jsx("div",{className:"text-[9px] text-[#a1a1aa] leading-relaxed",children:j("furnitureInspector.multiSelectHint",{defaultValue:"⌘+לחיצה להוסיף/להסיר · גרור להזיז יחד · R לסובב · Delete למחוק"})})]});const N=[...e][0],P=t.find(ht=>ht.id===N);if(!P)return null;const L=ht=>{o(t.map(gt=>gt.id===N?{...gt,...ht}:gt))},A=pi[P.type]||{width:800,depth:600,height:750,label:j("furniture.fallback",{defaultValue:"רהיט"})},W=50/r,S=()=>{const ht=dF(t,N,r);ht&&(o(ht.next),s(new Set([ht.newId])))},B=P.widthMm||Math.round(A.width*(P.scale||1)),R=P.depthMm||Math.round(A.depth*(P.scale||1)),z=P.heightMm||Math.round(A.height*(P.scale||1)),X=P.type.startsWith("blender_"),ft=(ht,gt,Pt)=>X?Math.max(Pt,ht,Math.ceil(gt*2/1e3)*1e3):Pt,tt=(a==null?void 0:a[P.type])??[],G=X?tt.filter(ht=>OJ(ht.labelHe)):[],Y=(u==null?void 0:u.furnitureId)===N&&tt.some(ht=>ht.id===u.slotId)?u.slotId:null,J=tt.find(ht=>ht.id===Y)??null,Mt=Y?(kt=P.materialOverrides)==null?void 0:kt[Y]:void 0,Rt=X||tt.length>0&&(u==null?void 0:u.furnitureId)===N,it=(ht,gt)=>{L({materialOverrides:DT(P.materialOverrides,ht,gt)})},st=()=>({url:(Mt==null?void 0:Mt.url)??"#ffffff",tileWidthCm:(Mt==null?void 0:Mt.tileWidthCm)??100,tileHeightCm:(Mt==null?void 0:Mt.tileHeightCm)??100,groutWidthMm:(Mt==null?void 0:Mt.groutWidthMm)??3,groutColor:(Mt==null?void 0:Mt.groutColor)??"#c8c4bc",orientation:ei(Mt==null?void 0:Mt.orientation)}),ct=(Math.round(P.rotation)%360+360)%360,pt=ct/359*100,xt=((Et=P.label)==null?void 0:Et.trim())||A.label||j("furniture.fallback",{defaultValue:"רהיט"}),_t="rounded-xl border border-[#E2D4CA] bg-[#FFFDFC] p-2.5 shadow-[0_4px_12px_rgba(24,33,55,0.06),inset_0_1px_0_rgba(255,255,255,0.9)]",Ft="flex h-10 w-10 cursor-pointer items-center justify-center rounded-xl border border-[#182137]/10 bg-white text-[#182137]/70 shadow-[0_2px_0_#D8D1C8,0_4px_10px_rgba(24,33,55,0.06)] transition-all hover:border-[#D84B2E]/35 hover:bg-[#FFF7F3] hover:text-[#9a3d28] active:translate-y-[1px] active:shadow-[0_1px_0_#D8D1C8,0_2px_6px_rgba(24,33,55,0.06)]",Vt=(ht,gt)=>{L({position:{...P.position,x:P.position.x+ht*W,y:P.position.y+gt*W}})},vt=n.jsxs("div",{className:"grid grid-cols-2 gap-2 p-2.5",children:[n.jsxs("button",{type:"button",onClick:S,className:"flex h-9 cursor-pointer items-center justify-center gap-1.5 rounded-lg border border-[#182137]/10 bg-white px-2 text-[11px] font-black text-[#182137] shadow-[0_2px_0_#D8D1C8,0_4px_10px_rgba(24,33,55,0.05)] transition-all hover:border-[#D84B2E]/35 hover:bg-[#FFF7F3] active:translate-y-[1px] active:shadow-none",children:[n.jsx(Pf,{size:13}),j("common.duplicate",{defaultValue:"שכפל"})]}),n.jsxs("button",{type:"button",onClick:()=>{o(t.filter(ht=>
394ht.id!==N)),s(new Set)},className:"flex h-9 cursor-pointer items-center justify-center gap-1.5 rounded-lg border border-[#D84B2E]/20 bg-[#D84B2E]/10 px-2 text-[11px] font-black text-[#9a3d28] shadow-[0_2px_0_rgba(154,61,40,0.18),0_4px_10px_rgba(216,93,67,0.08)] transition-all hover:bg-[#D84B2E]/16 active:translate-y-[1px] active:shadow-none",children:[n.jsx(gi,{size:13}),j("common.delete",{defaultValue:"מחק"})]})]}),Ht=n.jsxs("div",{className:_t,children:[n.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[n.jsx("span",{className:"text-[11px] font-black text-[#182137]",children:j("furnitureInspector.position",{defaultValue:"מיקום"})}),n.jsxs("span",{className:"text-[9px] font-bold text-[#9a3d28]/60",children:[j("furnitureInspector.step",{defaultValue:"צעד"})," ",$i(50,_)]})]}),n.jsx("div",{dir:"ltr",className:"flex justify-center",children:n.jsxs("div",{className:"grid w-fit grid-cols-3 grid-rows-3 gap-1.5",children:[n.jsx("span",{}),n.jsx("button",{type:"button","aria-label":j("accessibility.moveUp",{defaultValue:"הזז למעלה"}),onClick:()=>Vt(0,1),className:Ft,children:n.jsx(D_,{size:18})}),n.jsx("span",{}),n.jsx("button",{type:"button","aria-label":j("accessibility.moveLeft",{defaultValue:"הזז שמאלה"}),onClick:()=>Vt(1,0),className:Ft,children:n.jsx(F_,{size:18})}),n.jsx("span",{className:"flex h-10 w-10 items-center justify-center text-[9px] font-bold text-[#182137]/35",children:$i(50,_)}),n.jsx("button",{type:"button","aria-label":j("accessibility.moveRight",{defaultValue:"הזז ימינה"}),onClick:()=>Vt(-1,0),className:Ft,children:n.jsx(w1,{size:18})}),n.jsx("span",{}),n.jsx("button",{type:"button","aria-label":j("accessibility.moveDown",{defaultValue:"הזז למטה"}),onClick:()=>Vt(0,-1),className:Ft,children:n.jsx(J_,{size:18})}),n.jsx("span",{})]})})]}),Tt=n.jsxs("div",{className:`${_t} space-y-2`,children:[n.jsx("div",{className:"text-[11px] font-black text-[#182137]",children:j("furnitureInspector.dimensions",{defaultValue:"מידות"})}),n.jsx(xy,{label:j("dimensions.width",{defaultValue:"רוחב"}),value:B,min:X?1:100,max:ft(B,A.width,5e3),step:10,measurementUnit:_,onChange:ht=>L({widthMm:ht})}),n.jsx(xy,{label:j("dimensions.depth",{defaultValue:"עומק"}),value:R,min:X?1:100,max:ft(R,A.depth,5e3),step:10,measurementUnit:_,onChange:ht=>L({depthMm:ht})}),n.jsx(xy,{label:j("dimensions.height",{defaultValue:"גובה"}),value:z,min:X?1:100,max:ft(z,A.height,3500),step:10,measurementUnit:_,onChange:ht=>L({heightMm:ht})})]}),Zt=Rt&&n.jsxs("div",{className:"overflow-hidden rounded-2xl border border-emerald-100 bg-gradient-to-b from-emerald-50/70 to-white shadow-[0_2px_6px_rgba(16,185,129,0.08)]",children:[n.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-emerald-100 px-3 py-2",children:[n.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[11px] font-bold text-emerald-800",children:[n.jsx(zl,{size:13}),X?j("blenderMaterials.title",{defaultValue:"ריצוף וחומרים"}):j("furnitureInspector.smartMaterials",{defaultValue:"חיפויים למודל חכם"})]}),Y&&n.jsx("button",{type:"button",onClick:()=>it(Y,null),className:"rounded-lg bg-white px-2 py-1 text-[9px] font-bold text-emerald-800 shadow-sm",children:X?j("blenderMaterials.resetPart",{defaultValue:"החזר חלק למקור"}):j("common.clear",{defaultValue:"נקה"})})]}),X&&n.jsxs("div",{className:"space-y-2 px-3 py-2",children:[n.jsx("p",{className:"text-[11px] font-bold leading-relaxed text-emerald-900",children:j("blenderMaterials.surfaceFirst",{defaultValue:"בחר רצפה מהקיצורים או חלק מהרשימה, ודא שהמשטח מודגש, ואז בחר חומר."})}),n.jsx("div",{className:"grid grid-cols-2 gap-2",children:["floor","shape"].map(ht=>n.jsx("button",{type:"button","aria-pressed":v===ht,onClick:()=>C(ht),className:`min-h-11 cursor-pointer rounded-lg border px-2 py-2 text-[11px] font-black shadow-[0_2px_0_#D8D1C8] transition-colors focus-visible:outline focus-visible:outline-2 focus-visible:outline-[#D85D43] active:translate-y-
394px ${v===ht?"border-[#B33D24] bg-[#D85D43] text-[#F7F4EF]":"border-[#E2D4CA] bg-[#F7F4EF] text-[#182137]"}`,children:ht==="floor"?j("blenderMaterials.flooring",{defaultValue:"ריצוף"}):j("blenderMaterials.otherMaterials",{defaultValue:"חומרים אחרים"})},ht))}),h&&G.length>0&&!l&&!c&&n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("p",{className:"text-[10px] font-semibold text-emerald-800",children:j("blenderMaterials.namedFloors",{defaultValue:"רצפות לפי שם המודל"})}),n.jsx("div",{className:"flex max-h-36 flex-wrap gap-1.5 overflow-y-auto p-0.5",children:G.slice(0,4).map(ht=>n.jsx("button",{type:"button",title:ht.labelHe,"aria-pressed":Y===ht.id,onClick:()=>{C("floor"),h({furnitureId:N,slotId:ht.id})},className:`min-h-11 max-w-full cursor-pointer truncate rounded-lg border px-2 py-2 text-[11px] font-bold shadow-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-[#D85D43] ${Y===ht.id?"border-[#B33D24] bg-[#D85D43] text-[#F7F4EF]":"border-[#E2D4CA] bg-[#F7F4EF] text-[#182137]"}`,children:ht.labelHe},ht.id))}),n.jsx("p",{className:"text-[10px] leading-relaxed text-emerald-800/70",children:j("blenderMaterials.namedFloorsHint",{defaultValue:"ההצעות לפי שמות החלקים בלבד. ודא שהמשטח הרצוי מודגש במודל."})})]}),n.jsx("p",{className:"text-[10px] leading-relaxed text-emerald-800",children:j("blenderMaterials.hint",{defaultValue:"השינוי חל על החלק הנבחר בלבד. אפשר להחזיר את החומרים למקור בכל עת."})}),n.jsx("p",{className:"text-[10px] leading-relaxed text-emerald-800/70",children:j("blenderMaterials.textureHint",{defaultValue:"הטקסטורה נפרסת לפי המיפוי הקיים במודל; אין כאן קביעת מידות אריח או פוגה."})}),h&&tt.length>0&&!l&&!c&&n.jsxs("label",{className:"block space-y-1 text-[10px] font-semibold text-emerald-800",children:[n.jsx("span",{children:j("blenderMaterials.choosePart",{defaultValue:"כל חלקי המודל"})}),n.jsxs("select",{value:Y??"",onChange:ht=>{const gt=ht.target.value;tt.some(Pt=>Pt.id===gt)&&h({furnitureId:N,slotId:gt})},className:"block w-full min-w-0 rounded-lg border border-emerald-200 bg-white px-2 py-2 text-[11px] text-emerald-900",children:[n.jsx("option",{value:"",disabled:!0,children:j("blenderMaterials.choosePartPlaceholder",{defaultValue:"בחירת חלק"})}),tt.map(ht=>n.jsx("option",{value:ht.id,children:ht.labelHe},ht.id))]})]}),Object.keys(P.materialOverrides??{}).length>0&&n.jsx("button",{type:"button",onClick:()=>L({materialOverrides:void 0}),className:"rounded-lg bg-white px-2 py-1.5 text-[10px] font-bold text-emerald-800 ring-1 ring-emerald-100",children:j("blenderMaterials.resetAll",{defaultValue:"החזר את כל החומרים למקור"})})]}),X&&l?n.jsx("div",{role:"status",className:"px-3 py-3 text-[11px] text-emerald-800",children:j("blenderMaterials.loading",{defaultValue:"טוען חלקים לעריכת חומרים…"})}):X&&c?n.jsxs("div",{className:"space-y-2 px-3 py-3",children:[n.jsx("p",{role:"alert",className:"text-[11px] text-emerald-800",children:j("blenderMaterials.loadError",{defaultValue:"לא הצלחנו לטעון את חלקי המודל לעריכה."})}),d&&n.jsx("button",{type:"button",onClick:d,className:"rounded-lg bg-white px-2 py-1.5 text-[10px] font-bold text-emerald-800 ring-1 ring-emerald-100",children:j("blenderMaterials.retry",{defaultValue:"נסה שוב"})})]}):X&&tt.length===0?n.jsx("p",{className:"px-3 py-3 text-[11px] text-emerald-800",children:j("blenderMaterials.noParts",{defaultValue:"לא נמצאו במודל חלקים זמינים לעריכת חומרים."})}):!J||!Y?n.jsxs("div",{className:"space-y-2 px-3 py-3",children:[n.jsx("div",{className:"rounded-xl border border-dashed border-emerald-200 bg-white/80 px-3 py-3 text-center text-[12px] font-bold text-emerald-800",children:X?j("blenderMaterials.selectFirst",{defaultValue:"בחר רצפה מהקיצורים או חלק מהרשימה כדי להתחיל."}):j("furnitureInspector.selectModelPart",{defaultValue:"בחר חלק במודל בתלת-מימד"})}),x&&(u==null?void 0:u.furnitureId)===N&&n.jsx("button",{type:"button",onClick:x,className:"w-full rounded-lg bg-white px-2 py-1.5 text-[10px] font-bold text-emerald-700 ring-1 ring-emerald-100",children:j("common.clearSelection",{defaultValue:"בטל בחירה"})})]}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[n.jsx("span",{className:"text-[10px] font-semibold text-emerald-700/70",children:j("furnitureInspector.partSelected",{defaultValue:"חלק נבחר"})}),n.jsx("span",{className:"truncate rounded-lg bg-white px-2 py-1 text-[10px] font-bold text-emerald-900 shadow-sm",children:J.labelHe})]}
394),n.jsx(Df,{variant:"embedded",hideGeometryControls:X,mode:"material",target:X?v:"shape",onClose:()=>{},currentTextureUrl:Mt==null?void 0:Mt.url,tileWidthCm:(Mt==null?void 0:Mt.tileWidthCm)??100,tileHeightCm:(Mt==null?void 0:Mt.tileHeightCm)??100,measurementUnit:_,orientation:(Mt==null?void 0:Mt.orientation)??Hf,groutWidthMm:(Mt==null?void 0:Mt.groutWidthMm)??3,groutColor:(Mt==null?void 0:Mt.groutColor)??"#c8c4bc",onSelectTexture:ht=>it(Y,{...st(),url:ht}),onSelectColor:ht=>it(Y,{...st(),url:ht}),onTileSizeChange:(ht,gt)=>it(Y,{...st(),tileWidthCm:ht,tileHeightCm:gt}),onOrientationChange:ht=>it(Y,{...st(),orientation:ht}),onGroutChange:(ht,gt)=>it(Y,{...st(),groutWidthMm:ht,groutColor:gt}),onClear:()=>it(Y,null),savedTiles:f,getPublicUrl:p,onUploadTile:b,onRemoveTile:M,onRenameTile:g,personalAssetsLocked:w,onPremiumRequired:k})]})]}),At=n.jsxs("div",{className:`${_t} space-y-2`,children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-[11px] font-black text-[#182137]",children:j("furnitureInspector.rotation",{defaultValue:"סיבוב"})}),n.jsx("div",{className:"rounded-lg border border-[#D84B2E]/18 bg-white px-2 py-0.5 shadow-[inset_0_1px_2px_rgba(24,33,55,0.04)]",children:n.jsxs("span",{className:"font-mono text-[12px] font-bold tabular-nums text-[#9a3d28]",children:[ct,"°"]})})]}),n.jsxs("div",{className:"space-y-1",children:[n.jsx("div",{className:"text-right text-[9px] font-bold text-[#182137]/45",children:j("furnitureInspector.commonAngles",{defaultValue:"זוויות נפוצות"})}),n.jsx("div",{className:"grid grid-cols-5 gap-1",children:RJ.map(ht=>{const gt=ct===ht;return n.jsxs("button",{type:"button",onClick:()=>L({rotation:ht}),className:`cursor-pointer rounded-lg py-1.5 text-[10px] font-bold transition-all
395	                    ${gt?"border border-[#B33D24] bg-[#D84B2E] text-white shadow-[0_2px_0_#9a3d28]":"border border-[#182137]/10 bg-white text-[#182137]/65 shadow-[0_2px_0_#D8D1C8] hover:border-[#D84B2E]/35 hover:bg-[#FFF7F3] hover:text-[#9a3d28]"}`,children:[ht,"°"]},ht)})})]}),n.jsxs("div",{className:"relative flex h-5 items-center",children:[n.jsx("div",{className:"absolute inset-x-0 h-1.5 rounded-full bg-[#E6E1DA]"}),n.jsx("div",{className:"absolute h-1.5 rounded-full bg-[#D84B2E] shadow-[0_1px_3px_rgba(180,60,40,0.18)]",style:{width:`${pt}%`,right:0}}),n.jsx("input",{type:"range",min:0,max:359,step:1,value:ct,onChange:ht=>L({rotation:Number(ht.target.value)}),className:`relative z-10 h-5 w-full cursor-pointer appearance-none bg-transparent
396              [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:w-4 [&::-webkit-slider-thumb]:h-4
397              [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-white
398              [&::-webkit-slider-thumb]:border-2 [&::-webkit-slider-thumb]:border-[#D84B2E]
399              [&::-webkit-slider-thumb]:shadow-[0_2px_6px_rgba(216,75,46,0.25),0_0_0_5px_rgba(236,115,87,0.10)]
400              [&::-webkit-slider-thumb]:cursor-grab [&::-webkit-slider-thumb]:transition-all [&::-webkit-slider-thumb]:hover:scale-110`})]}),n.jsxs("div",{className:"grid grid-cols-3 gap-1.5",children:[n.jsx("button",{type:"button",onClick:()=>L({rotation:(ct-15+360)%360}),className:"cursor-pointer rounded-lg border border-[#182137]/10 bg-white py-2 text-[11px] font-bold text-[#182137]/72 shadow-[0_2px_0_#D8D1C8,0_3px_8px_rgba(24,33,55,0.05)] transition-all hover:border-[#D84B2E]/35 hover:bg-[#FFF7F3] hover:text-[#9a3d28] active:translate-y-[1px] active:shadow-none",children:"−15°"}),n.jsx("button",{type:"button",onClick:()=>L({rotation:(ct+15)%360}),className:"cursor-pointer rounded-lg border border-[#182137]/10 bg-white py-2 text-[11px] font-bold text-[#182137]/72 shadow-[0_2px_0_#D8D1C8,0_3px_8px_rgba(24,33,55,0.05)] transition-all hover:border-[#D84B2E]/35 hover:bg-[#FFF7F3] hover:text-[#9a3d28] active:translate-y-[1px] active:shadow-none",children:"+15°"}),n.jsxs("button",{type:"button",onClick:()=>L({flipped:!P.flipped}),className:"cursor-pointer rounded-lg border border-[#182137]/10 bg-white py-2 text-[11px] font-bold text-[#182137]/72 shadow-[0_2px_0_#D8D1C8,0_3px_8px_rgba(24,33,55,0.05)] transition-all hover:border-[#D84B2E]/35 hover:bg-[#FFF7F3] hover:text-[#9a3d28] active:translate-y-[1px] active:shadow-none",children:["↔ ",j("common.flip",{defaultValue:"הפוך"})]})]})]}),ut=i&&n.jsxs("button",{type:"button",onClick:i,className:"w-full cursor-pointer rounded-xl border border-[#B33D24] bg-[#D84B2E] py-2.5 text-[12px] font-black text-white shadow-[0_3px_0_#9a3d28,0_8px_16px_rgba(216,93,67,0.18),inset_0_1px_0_rgba(255,255,255,0.22)] transition-all hover:bg-[#C94E35] active:translate-y-[1px] active:shadow-[0_1px_0_#9a3d28,0_4px_10px_rgba(216,93,67,0.16)]",children:["+ ",j("furnitureInspector.placeAnother",{defaultValue:"הצב עוד"})]});return n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"overflow-hidden rounded-xl border border-[#D84B2E]/18 bg-[#FAF6F0] shadow-[0_6px_16px_rgba(24,33,55,0.08),inset_0_1px_0_rgba(255,255,255,0.88)]",children:[n.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-[#182137]/10 px-3 py-2.5",children:[n.jsx("button",{type:"button",onClick:()=>s(new Set),title:j("common.back",{defaultValue:"חזרה"}),className:"flex h-8 w-8 cursor-pointer items-center justify-center rounded-lg border border-[#182137]/10 bg-white text-[#182137]/70 shadow-[0_2px_0_#D8D1C8] transition-all hover:border-[#D84B2E]/35 hover:text-[#9a3d28] active:translate-y-[1px] active:shadow-none",children:n.jsx(v1,{size:14})}),n.jsxs("div",{className:"flex-1 min-w-0 text-right",children:[n.jsx("div",{className:"text-[9px] font-bold text-[#9a3d28]/65 leading-none",children:X?j("blenderMaterials.editorTitle",{defaultValue:"עורך מודל"}):j("furnitureInspector.title",{defaultValue:"עורך רהיט"})}),n.jsx("div",{className:"mt-0.5 truncate text-[14px] font-black leading-tight text-[#182137]",children:xt})]})]}),!X&&vt]}),X?n.jsxs(n.Fragment,{children:[Zt,n.jsxs("details",{className:_t,children:[n.jsx("summary",{className:"cursor-pointer py-2 text-[11px] font-black text-[#182137]",children:j("blenderMaterials.modelControls",{defaultValue:"מיקום ומידות המבנה"})}),n.jsxs("div",{className:"space-y-3 pt-2",children:[vt,Ht,Tt,At,ut]})]})]}):n.jsxs(n.Fragment,{children:[Ht,Tt,Zt,At,ut]})]})}function py({className:t}
400){return n.jsxs("svg",{viewBox:"0 0 48 48","aria-hidden":!0,className:t,children:[n.jsx("path",{d:"M7 14.5 33.5 8 41 12.5 14.5 19Z",fill:"#E8E3DB",stroke:"#182137",strokeWidth:"2"}),n.jsx("path",{d:"m14.5 19 26.5-6.5v12L14.5 31Z",fill:"#D85D43",stroke:"#182137",strokeWidth:"2"}),n.jsx("path",{d:"M7 14.5 14.5 19v12L7 26.5Z",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"2"}),n.jsx("path",{d:"M14.5 24.5 41 18",stroke:"#F7F4EF",strokeWidth:"1.5",opacity:".72"})]})}function gy(t,e,s){return Math.max(e,Math.min(s,t))}function VJ({beam:t,effectiveScale:e,measurementUnit:s,fpIsDark:o,mainView:r,onChange:i,onDuplicate:a,onDelete:l,onStartPlacement:c}){const{t:d}=yn(),u=t?t1(t,e):0,h=t?AT(t):0,[x,f]=m.useState({length:"",width:"",height:"",angle:""});m.useEffect(()=>{t&&f({length:De(u,s),width:De(t.widthMm,s),height:De(t.heightMm,s),angle:h.toFixed(1).replace(/\.0$/,"")})},[h,t,u,s]);const p=m.useMemo(()=>t?[{key:"length",label:d("beams.length",{defaultValue:"אורך"}),commit:g=>{const w=ni(g,s),k=gy(w??u,I1,5e4);i(WT(t,k,e))}},{key:"width",label:d("beams.width",{defaultValue:"רוחב"}),commit:g=>{const w=ni(g,s);i({...t,widthMm:gy(w??t.widthMm,IT,TT)})}},{key:"height",label:d("beams.height",{defaultValue:"גובה ירידה"}),commit:g=>{const w=ni(g,s);i({...t,heightMm:gy(w??t.heightMm,ST,PT)})}}]:[],[t,e,u,s,i,d]),b=o?"border-white/10 bg-[#151516] text-[#F7F4EF]":"border-[#182137]/10 bg-[#F7F4EF] text-[#182137]",M=o?"border-white/12 bg-[#0c0c0d] text-[#F7F4EF]":"border-[#182137]/12 bg-[#FFFDFC] text-[#182137]";return t?n.jsxs("div",{className:O("m-3 overflow-hidden rounded-2xl border shadow-[0_10px_28px_rgba(24,33,55,0.08)]",b),children:[n.jsxs("div",{className:O("flex items-center justify-between border-b px-3 py-3",o?"border-white/10":"border-[#182137]/10"),children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(py,{className:"h-9 w-9"}),n.jsxs("div",{children:[n.jsx("div",{className:"text-[13px] font-black tracking-[-0.03em]",children:d("beams.selectedTitle",{defaultValue:"קורה נבחרת"})}),n.jsx("div",{className:O("text-[9px] font-bold",o?"text-white/45":"text-[#182137]/45"),children:d("beams.ceilingAttached",{defaultValue:"צמודה לתקרת הקומה"})})]})]}),n.jsxs("div",{className:"flex gap-1.5",children:[n.jsx("button",{type:"button",onClick:a,title:d("common.duplicate",{defaultValue:"שכפל"}),className:O("flex h-10 w-10 items-center justify-center rounded-xl border shadow-sm transition-transform hover:-translate-y-0.5 active:translate-y-0",M),children:n.jsx(Pf,{size:16})}),n.jsx("button",{type:"button",onClick:l,title:d("common.delete",{defaultValue:"מחק"}),className:"flex h-10 w-10 items-center justify-center rounded-xl border border-[#D85D43]/30 bg-[#FDF0EC] text-[#A8402E] shadow-sm transition-transform hover:-translate-y-0.5 active:translate-y-0",children:n.jsx(gi,{size:16})})]})]}),n.jsxs("div",{className:"grid grid-cols-2 gap-2 p-3",children:[p.map(g=>n.jsxs("label",{className:"text-start",children:[n.jsx("span",{className:O("mb-1 block text-[10px] font-black",o?"text-white/55":"text-[#182137]/55"),children:g.label}),n.jsx("input",{type:"text",inputMode:"decimal",value:x[g.key],onChange:w=>f(k=>({...k,[g.key]:w.currentTarget.value})),onBlur:()=>g.commit(x[g.key]),onKeyDown:w=>{w.key==="Enter"&&w.currentTarget.blur(),w.key==="Escape"&&(w.preventDefault(),f(k=>({...k,[g.key]:g.key==="length"?De(u,s):De(g.key==="width"?t.widthMm:t.heightMm,s)})))},className:O("h-10 w-full rounded-xl border px-2 text-center text-[12px] font-black outline-none focus:border-[#D85D43]/55 focus:ring-2 focus:ring-[#D85D43]/15",M)})]},g.key)),n.jsxs("label",{className:"text-start",children:[n.jsx("span",{className:O("mb-1 block text-[10px] font-black",o?"text-white/55":"text-[#182137]/55"),children:d("beams.angle",{defaultValue:"זווית"})}),n.jsxs("div",{className:O("flex h-10 items-center rounded-xl border px-2 focus-within:border-[#D85D43]/55 focus-within:ring-2 focus-within:ring-[#D85D43]/15",M),children:[n.jsx("input",{type:"number",min:0,max:359.9,step:.5,value:x.angle,onChange:g=>f(w=>({...w,angle:g.currentTarget.value})),onBlur:()=>{const g=Number(x.angle);i(fE(t,Uw(Number.isFinite(g)?g:h)))},onKeyDown:g=>{g.key==="Enter"&&g.currentTarget.blur(),g.key==="Escape"&&(g.preventDefault(),f(w=>({...w,angle:h.toFixed(1).replace(/\.0$/,"")})))},className:"min-w-0 flex-1 bg-transparent text-center text-[12px] font-black outline-none"}),n.jsx("span",{className:"text-[11px] font-black opacity-50",children:"°"})]})]})]}),n.jsx("div",{className:"px-3 pb-3",children:n.jsx("button",{type:"button",onClick:c,className:O("flex min-h-11 w-full items-center justify-center rounded-xl border px-4 text-[11px] font-black shadow-[0_4px_0_rgba(24,33,55,.14)] transition-transform hover:-translate-y-0.5 active:translate-y-0.5 active:shadow-[0_1px_0_rgba(24,33,55,.14)]",o?"border-white/12 bg-[#242426] text-[#F7F4EF]":"border-[#182137]/12 bg-[#E8E3DB] text-[#182137]"),children:d("beams.addAnother",{defaultValue:"הוסף קורה נוספת"})})})]}):n.jsxs("div",{className:O("m-3 rounded-2xl border p-4 shadow-[0_10px_28px_rgba(24,33,55,0.08)]",b),children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("div",{className:"flex h-14 w-14 shrink-0 items-center justify-center rounded-2xl bg-[#E8E3DB] shadow-[inset_0_1px_0_rgba(255,255,255,.8)]",children:n.jsx(py,{className:"h-11 w-11"})}),n.jsxs("div",{className:"min-w-0 text-start",children:[n.jsx("div",{className:"text-[15px] font-black tracking-[-0.035em]",children:d("beams.emptyTitle",{defaultValue:"הוספת קורה לתוכנית"})}),n.jsx("p",{className:O("mt-1 text-[11px] font-medium leading-5",o?"text-white/60":"text-[#182137]/60"),children:r==="3d"?d("beams.empty3dHint",{defaultValue:"נעבור למבט 2D כדי לסמן את שתי נקודות הקורה במדויק."}):d("beams.empty2dHint",{defaultValue:"סמנו נקודת התחלה ונקודת סיום. הקורה תיצמד אוטומטית לתקרה."})})]})]}),n.jsxs("button",{type:"button",onClick:c,className:"mt-4 flex min-h-11 w-full items-center justify-center gap-2 rounded-xl border border-[#B94732] bg-[#D85D43] px-4 text-[12px] font-black text-[#F7F4EF] shadow-[0_6px_0_#A8402E,0_10px_20px_rgba(216,93,67,.22),inset_0_1px_0_rgba(255,255,255,.28)] transition-transform hover:-translate-y-0.5 hover:bg-[#C94E35] active:translate-y-1 active:shadow-[0_2px_0_#A8402E]",children:[n.jsx(py,{className:"h-7 w-7"}),d("beams.add",{defaultValue:"הוסף קורה"})]})]})}function Gg({variant:t,fpIsDark:e,scopeLabel:s,isHint:o,wallHeight:r,wallThickness:i,wallThicknessLabel:a="עובי",onDeleteWall:l,measurementUnit:c="cm"}){const d=(u,h)=>n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:O("w-14 text-[10px] font-semibold",e?"text-white/80":"text-[#182137]"),children:u}),n.jsxs("div",{className:O("flex flex-1 items-center overflow-hidden rounded-lg border",e?"border-white/15 bg-[#0A0A0A]":"border-[#182137]/12 bg-white"),children:[n.jsx("button",{type:"button",onClick:()=>h.onChange(Math.max(h.min,h.value-10)),className:O("flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center transition-colors",e?"text-white/40 hover:bg-white/5 hover:text-white":"text-[#182137]/40 hover:bg-gray-100"),children:n.jsx(Yc,{size:12})}),n.jsx("input",{type:"text",inputMode:"decimal",value:De(h.value,c),onChange:x=>{const f=ni(x.target.value,c);f!==null&&h.onChange(Math.max(h.min,Math.min(h.max,f)))},className:O("h-7 flex-1 bg-transparent text-center text-[12px] font-semibold outline-none [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none",e?"text-white":"text-[#182137]")}),n.jsx("button",{type:"button",onClick:()=>h.onChange(Math.min(h.max,h.value+10)),className:O("flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center transition-colors",e?"text-white/40 hover:bg-white/5 hover:text-white":"text-[#182137]/40 hover:bg-gray-100"),children:n.jsx(E_,{size:12})})]}),n.jsx("span",{className:O("text-[10px] font-semibold",e?"text-white/80":"text-[#182137]"),children:Ka(c)})]});return n.jsxs("div",{className:O("space-y-2 border-b px-3 py-2.5",e?"border-white/10 bg-[#141416]/60":"border-[#182137]/10 bg-[#FAF6F0]"),children:[n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:O("text-[9px] font-medium uppercase tracking-wider",e?"text-white/40":"text-[#a1a1aa]"),children:"עורך"}),n.jsx("div",{className:O("mt-0.5 truncate text-[12px] font-semibold",o?e?"text-white/55":"text-[#71717a]":e?"text-white/90":"text-[#18181b]"),children:s})]}),t==="wall"&&l&&!o&&n.jsx("button",{type:"button",onClick:l,className:"cursor-pointer rounded-lg bg-red-500/10 px-2 py-1 text-[10px] font-medium text-red-500 transition-all hover:bg-red-500/20",children:"מחק"})]}),t==="wall"&&!o&&(r||i)&&n.jsxs("div",{className:"space-y-1.5 pt-1",children:[r&&d("גובה",r),i&&d(a,i)]})]})}function zJ({entity:t,selectedFaceId:e,selectedHostFaceRegion:s=null,rectangleControls:o,groupScaleControls:r,groupMoveControls:i,groupRotationControls:a,facePatchControl
400s:l,measurementUnit:c="cm"}){const{t:d,i18n:u}=yn(),h=xc(),x=c==="mm"?d("settings.millimeters",{defaultValue:"מ״מ"}):d("settings.centimeters",{defaultValue:"ס״מ"}),f=j=>c==="mm"?Math.round(j*10):j,p=j=>c==="mm"?Math.round(j/10):j,b=j=>c==="mm"?Math.round(j):Number(De(j,"cm")),M=j=>Math.round(c==="mm"?j:j*10),g=o!=null&&o.wallAnchor?d("dimensions.width",{defaultValue:"רוחב"}):d("dimensions.length",{defaultValue:"אורך"}),w=o!=null&&o.wallAnchor?d("dimensions.depth",{defaultValue:"עומק"}):d("dimensions.widthOrDepth",{defaultValue:"עומק/רוחב"}),k=j=>{const v=o==null?void 0:o.wallAnchor;if(!v)return d("sketchElement.edge.number",{count:j.index+1,defaultValue:`קו ${j.index+1}`});if(j.index===v.anchorEdgeIndex)return d("sketchElement.edge.wall",{defaultValue:"קו קיר"});if(j.index===(v.anchorEdgeIndex+2)%4)return d("sketchElement.edge.front",{defaultValue:"קו קדמי"});const C=j.index===(v.anchorEdgeIndex+1)%4?1:2;return d("sketchElement.edge.side",{count:C,defaultValue:`קו צד ${C}`})},_=KJ(t,e,s,!!o,c,{width:d("dimensions.width",{defaultValue:"רוחב"}),height:d("dimensions.height",{defaultValue:"גובה"}),depth:d("dimensions.depth",{defaultValue:"עומק"}),radius:d("dimensions.radius",{defaultValue:"רדיוס"})});return n.jsxs("div",{className:"space-y-0",dir:u.dir(),children:[o?n.jsxs(n.Fragment,{children:[n.jsxs("section",{className:O("border-b p-3",h?"border-white/10":"border-[#182137]/10"),children:[n.jsx($h,{children:d("sketchElement.elementDimensions",{defaultValue:"מידות האלמנט"})}),n.jsxs("div",{className:"grid gap-2",children:[n.jsx(by,{label:g,value:o.lengthInputCm,unitLabel:x,disabled:!o.canEditDimensions,onChange:j=>o.onDimensionChange("length",j),onCommit:j=>o.onDimensionCommit("length",j),onFocus:()=>o.onDimensionFocus("length"),onBlur:j=>o.onDimensionBlur("length",j)}),n.jsx(by,{label:w,value:o.widthInputCm,unitLabel:x,disabled:!o.canEditDimensions,onChange:j=>o.onDimensionChange("width",j),onCommit:j=>o.onDimensionCommit("width",j),onFocus:()=>o.onDimensionFocus("width"),onBlur:j=>o.onDimensionBlur("width",j)}),n.jsx(by,{label:d("dimensions.height",{defaultValue:"גובה"}),value:o.heightInputCm,unitLabel:x,disabled:!o.canEditDimensions,onChange:j=>o.onDimensionChange("height",j),onCommit:j=>o.onDimensionCommit("height",j),onFocus:()=>o.onDimensionFocus("height"),onBlur:j=>o.onDimensionBlur("height",j)})]})]}),o.selectedEdgeIndex!==null?n.jsxs("section",{className:O("border-b p-3",h?"border-white/10":"border-[#182137]/10"),children:[n.jsx($h,{children:d("sketchElement.rectangleEdges",{defaultValue:"קווי המלבן"})}),n.jsx("div",{className:"grid gap-1.5",children:o.edges.map(j=>{const v=o.selectedEdgeIndex===j.index,C=j.dimension==="length"?o.lengthInputCm:o.widthInputCm,N=j.dimension==="length"?"length":"width";return n.jsxs("div",{role:"button",tabIndex:0,"aria-pressed":v,onClick:()=>o.onEdgeSelect(j.index),onKeyDown:P=>{(P.key==="Enter"||P.key===" ")&&(P.preventDefault(),o.onEdgeSelect(j.index))},className:O("grid cursor-pointer grid-cols-[1fr_auto] items-center gap-2 rounded-md border px-2.5 py-2 transition-colors",v?"border-[#336CFF] bg-[#336CFF]/10 text-[#182137]":h?"border-white/10 bg-white/[0.035] text-white/80 hover:bg-white/[0.07]":"border-[#182137]/10 bg-white/70 text-[#182137] hover:bg-white"),children:[n.jsx("span",{className:"text-right text-[12px] font-bold",children:k(j)}),v?n.jsxs("label",{className:"flex items-center gap-1",onClick:P=>P.stopPropagation(),children:[n.jsx("input",{value:C,onChange:P=>o.onEdgeLengthChange(j.index,P.target.value),onFocus:P=>{o.onDimensionFocus(N),P.currentTarget.select()},onBlur:P=>{o.onEdgeLengthCommit(j.index,P.currentTarget.value),o.onDimensionBlur(N,P.currentTarget.value)},onKeyDown:P=>{P.key==="Enter"&&(P.preventDefault(),P.currentTarget.blur())},className:O("h-7 w-20 rounded-[4px] border px-2 text-center text-[12px] font-bold tabular-nums outline-none",h?"border-white/15 bg-[#0A0A0A] text-white focus:border-white/35":"border-[#182137]/12 bg-white text-[#182137] focus:border-[#336CFF]"),inputMode:"decimal",disabled:!o.canEditDimensions,"aria-label":d("sketchElement.edge.lengthAria",{edge:k(j),unit:x,defaultValue:`${k(j)} ב${x}`})}),n.jsx("span",{className:O("text-[10px] font-bold",h?"text-white/45":"text-[#182137]/45"),children:x})]}):n.jsxs("span",{className:O("text-[11px] font-bold tabular-nums",h?"text-white/55":"text-[#182137]/55"),children:[De(j.lengthMm,c)," ",x]})]},j.index)})})]}):null]}):null,i?n.jsxs("section",{className:O("border-b p-3",h?"border-white/10":"border-[#182137]/10"),children:[n.jsx($h,{children:d("sketchElement.templatePosition",{defaultValue:"מיקום התבנית"})}),n.jsx("p",{className:O("mb-2 text-[10px] leading-snug",h?"text-white/40":"text-[#182137]/50"),children:d("sketchElement.templatePositionHint",{defaultValue:"מזיז את כל התבנית יחד — גוף, דלתות, מגירות וידיות."})}),n.jsx(UJ,{controls:i,measurementUnit:c,unitLabel:x,isDark:h,labels:{step:d("sketchElement.moveStep",{defaultValue:"צעד"}),forward:d("accessibility.moveTemplateForward",{defaultValue:"הזז את התבנית קדימה"}),back:d("accessibility.moveTemplateBack",{defaultValue:"הזז את התבנית אחורה"}),left:d("accessibility.moveTemplateLeft",{defaultValue:"הזז את התבנית שמאלה"}),right:d("accessibility.moveTemplateRight",{defaultValue:"הזז את התבנית ימינה"})}}),i.outOfBounds?n.jsx("p",{className:"mt-2 text-[10px] font-bold leading-snug text-[#D85D43]",children:d("sketchElement.templateOutOfBounds",{defaultValue:"התבנית יצאה מגבולות התוכנית."})}):null,n.jsx("p",{className:O("mt-2 text-[10px] leading-snug",h?"text-white/40":"text-[#182137]/50"),children:i.wallAttached?d("sketchElement.templateMoveWallHint",{defaultValue:"צמודה לקיר: ← → לאורך הקיר, ↑ החוצה מהקיר. התרחקות מדי מנתקת אותה מהקיר."}):d("sketchElement.templateMoveHint",{defaultValue:"אפשר גם עם חיצי המקלדת. Shift = צעד גדול פי 5. Ctrl+Z מבטל."})})]}):null,l?n.jsxs("section",{className:O("border-b p-3",h?"border-white/10":"border-[#182137]/10"),children:[n.jsx($h,{children:d("sketchElement.selectedPart",{defaultValue:"החלק שנבחר"})}),n.jsx("p",{className:O("mb-2 text-[10px] leading-snug",h?"text-white/40":"text-[#182137]/50"),children:d("sketchElement.selectedPartHint",{defaultValue:"המידות של החלק הבודד שסומן בלבד."})}),n.jsxs("div",{className:"space-y-3",children:[n.jsx(GJ,{onNudge:l.onNudge,measurementUnit:c,isDark:h,positionLabel:d("sketchElement.position",{defaultValue:"מיקום"}),moveLabels:{up:d("accessibility.moveUp",{defaultValue:"הזז למעלה"}),left:d("accessibility.moveLeft",{defaultValue:"הזז שמאלה"}),right:d("accessibility.moveRight",{defaultValue:"הזז ימינה"}),down:d("accessibility.moveDown",{defaultValue:"הזז למטה"})},unitLabel:x}),n.jsx(zh,{label:d("dimensions.width",{defaultValue:"רוחב"}),value:f(l.widthCm),min:f(l.minWidthCm),max:f(l.maxWidthCm),step:c==="mm"?10:1,unitLabel:x,onChange:j=>l.onWidthChange(p(j)),isDark:h}),n.jsx(zh,{label:d("dimensions.height",{defaultValue:"גובה"}
400),value:f(l.heightCm),min:f(l.minHeightCm),max:f(l.maxHeightCm),step:c==="mm"?10:1,unitLabel:x,onChange:j=>l.onHeightChange(p(j)),isDark:h}),n.jsx(zh,{label:d("dimensions.depth",{defaultValue:"עומק"}),value:b(l.depthMm),min:b(l.minDepthMm),max:b(l.maxDepthMm),step:c==="mm"?2:.2,unitLabel:x,onChange:j=>l.onDepthChange(M(j)),isDark:h})]}),n.jsx("p",{className:O("mt-2 text-[10px] leading-snug",h?"text-white/40":"text-[#182137]/50"),children:d("sketchElement.depthDirectionHint",{defaultValue:"עומק חיובי = בולט החוצה, שלילי = שקוע פנימה."})})]}):null,!o&&!l&&_.length>0?n.jsxs("section",{className:O("border-b p-3",h?"border-white/10":"border-[#182137]/10"),children:[n.jsx($h,{children:t.kind==="facePatch"||s?d("sketchElement.faceDimensions",{defaultValue:"מידות הפאה"}):d("sketchElement.elementDimensions",{defaultValue:"מידות האלמנט"})}),n.jsx("div",{className:"grid gap-1.5",children:_.map(j=>n.jsx(ZJ,{label:j.label,value:j.value,unitLabel:x},j.label))})]}):null,r?n.jsxs("section",{className:O("border-b p-3",h?"border-white/10":"border-[#182137]/10"),children:[n.jsx($h,{children:r.title??d("sketchElement.wholeFurnitureSize",{defaultValue:"גודל הרהיט כולו"})}),n.jsx("p",{className:O("mb-2 text-[10px] leading-snug",h?"text-white/40":"text-[#182137]/50"),children:r.description??d("sketchElement.wholeUnitDescription",{defaultValue:"משנה את היחידה כולה יחד."})}),n.jsxs("div",{className:"space-y-3",children:[n.jsx(zh,{label:r.widthLabel??d("dimensions.width",{defaultValue:"רוחב"}),value:f(r.widthCm),min:f(r.minWidthCm),max:f(r.maxWidthCm),step:c==="mm"?10:1,unitLabel:x,onChange:j=>r.onWidthChange(p(j)),isDark:h}),r.onDepthChange&&r.depthCm!==void 0?n.jsx(zh,{label:r.depthLabel??d("dimensions.depth",{defaultValue:"עומק"}),value:f(r.depthCm),min:f(r.minDepthCm??2),max:f(r.maxDepthCm??Math.max(2,r.depthCm)),step:c==="mm"?10:1,unitLabel:x,onChange:j=>{var v;return(v=r.onDepthChange)==null?void 0:v.call(r,p(j))},isDark:h}):null,r.onHeightChange?n.jsx(zh,{label:r.heightLabel??d("dimensions.height",{defaultValue:"גובה"}),value:f(r.heightCm),min:f(r.minHeightCm),max:f(r.maxHeightCm),step:c==="mm"?10:1,unitLabel:x,onChange:j=>{var v;return(v=r.onHeightChange)==null?void 0:v.call(r,p(j))},isDark:h}):null,r.onBaseHeightChange?n.jsx(zh,{label:d("sketchElement.installationHeight",{defaultValue:"גובה התקנה"}),value:f(r.baseHeightCm??0),min:f(r.minBaseHeightCm??0),max:f(r.maxBaseHeightCm??250),step:c==="mm"?10:1,unitLabel:x,onChange:j=>{var v;return(v=r.onBaseHeightChange)==null?void 0:v.call(r,p(j))},isDark:h}):null]}),n.jsx("p",{className:O("mt-2 text-[10px] leading-snug",h?"text-white/40":"text-[#182137]/50"),children:r.helperText??d("sketchElement.partsRedistributeHint",{defaultValue:"החלקים מתחלקים מחדש אוטומטית. לעריכת חלק בודד — בחר אותו במודל."})})]}):null,a?n.jsxs("section",{className:O("border-b p-3",h?"border-white/10":"border-[#182137]/10"),children:[n.jsx($h,{children:d("sketchElement.rotation",{defaultValue:"סיבוב"})}),n.jsx($J,{value:a.rotationDeg,onChange:a.onRotationChange,isDark:h,labels:{angle:d("sketchElement.angle",{defaultValue:"זווית"}),rotationAria:d("sketchElement.rotationAria",{defaultValue:"זווית סיבוב (מעלות)"}),decrease:j=>d("sketchElement.decreaseDegrees",{degrees:j,defaultValue:`הקטן ב-${j} מעלות`}),increase:j=>d("sketchElement.increaseDegrees",{degrees:j,defaultValue:`הגדל ב-${j} מעלות`}),set:j=>d("sketchElement.setRotationDegrees",{degrees:j,defaultValue:`קבע סיבוב ל-${j} מעלות`})}})]}):null]})}function $J({value:t,onChange:e,isDark:s,labels:o}){const r=XJ(t),i=d=>e((r+d+360)%360),a=[0,90,180,270],l=d=>O("flex h-7 min-w-[36px] items-center justify-center rounded-[4px] border px-2 text-[11px] font-bold tabular-nums transition-colors",r===d?"border-[#D85D43] bg-[#D85D43]/10 text-[#D85D43]":s?"border-white/15 bg-white/[0.04] text-white/75 hover:bg-white/[0.1]":"border-[#182137]/12 bg-white text-[#182137] hover:bg-[#182137]/[
4000.05]"),c=O("flex h-7 min-w-[36px] items-center justify-center rounded-[4px] border px-2 text-[11px] font-bold tabular-nums transition-colors",s?"border-white/15 bg-white/[0.04] text-white/75 hover:bg-white/[0.1]":"border-[#182137]/12 bg-white text-[#182137] hover:bg-[#182137]/[0.05]");return n.jsxs("div",{className:"space-y-2",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:O("text-[11px] font-bold",s?"text-white/70":"text-[#182137]/70"),children:o.angle}),n.jsxs("span",{className:O("text-[11px] font-bold tabular-nums",s?"text-white":"text-[#182137]"),children:[YJ(r),"°"]})]}),n.jsx("input",{type:"range",min:0,max:360-Nd,step:Nd,value:r,onChange:d=>e(Number(d.target.value)),className:"w-full cursor-pointer accent-[#D85D43]","aria-label":o.rotationAria}),n.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",dir:"ltr",children:[n.jsxs("button",{type:"button",className:c,onClick:()=>i(-Nd),"aria-label":o.decrease(Nd),children:["−",Nd,"°"]}),n.jsxs("button",{type:"button",className:c,onClick:()=>i(Nd),"aria-label":o.increase(Nd),children:["+",Nd,"°"]}),n.jsx("span",{className:O("mx-1 h-4 w-px",s?"bg-white/15":"bg-[#182137]/15")}),a.map(d=>n.jsxs("button",{type:"button",className:l(d),onClick:()=>e(d),"aria-label":o.set(d),"aria-pressed":r===d,children:[d,"°"]},d))]})]})}function XJ(t){const e=(t%360+360)%360;return Math.round(e*10)/10}function YJ(t){return Number.isInteger(t)?String(t):t.toFixed(1)}function o_(t,e){if(e<1){const s=Math.round(t*10)/10;return Number.isInteger(s)?String(s):s.toFixed(1)}return String(Math.round(t))}function zh({label:t,value:e,min:s,max:o,step:r=1,unitLabel:i,onChange:a,isDark:l}){const c=Math.min(o,Math.max(s,e)),d=o_(c,r),[u,h]=m.useState(d),[x,f]=m.useState(!1);m.useEffect(()=>{x||h(d)},[d,x]);const p=()=>{const b=u.trim().replace(",","."),M=Number(b);if(!Number.isFinite(M)){h(d);return}const g=Math.min(o,Math.max(s,M));a(g),h(o_(g,r))};return n.jsxs("div",{children:[n.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2",children:[n.jsx("span",{className:O("text-[11px] font-bold",l?"text-white/70":"text-[#182137]/70"),children:t}),n.jsxs("label",{className:O("flex w-[78px] shrink-0 items-center gap-1 rounded-[6px] border px-1.5 py-0.5 transition-colors","focus-within:border-[#D85D43] focus-within:ring-1 focus-within:ring-[#D85D43]/30",l?"border-white/15 bg-white/[0.04]":"border-[#182137]/12 bg-white"),children:[n.jsx("input",{type:"text",inputMode:"decimal","aria-label":`${t} (${i})`,value:u,onChange:b=>h(b.target.value),onFocus:()=>f(!0),onBlur:()=>{f(!1),p()},onKeyDown:b=>{b.key==="Enter"?(p(),b.target.blur()):b.key==="Escape"&&(h(d),b.target.blur())},className:O("min-w-0 flex-1 bg-transparent text-center text-[11px] font-bold tabular-nums outline-none",l?"text-white":"text-[#182137]")}),n.jsx("span",{className:O("shrink-0 text-[9px] font-semibold",l?"text-white/45":"text-[#182137]/45"),children:i})]})]}),n.jsx("input",{type:"range",min:s,max:o,step:r,value:c,onChange:b=>a(Number(b.target.value)),className:"w-full cursor-pointer accent-[#D85D43]","aria-label":`${t} (${i})`})]})}function GJ({onNudge:t,measurementUnit:e,isDark:s,positionLabel:o,moveLabels:r,unitLabel:i}){return n.jsxs("div",{children:[n.jsx("span",{className:O("mb-2 block text-center text-[11px] font-bold",s?"text-white/70":"text-[#182137]/70"),children:o}),n.jsx(Tb,{size:"sm",isDark:s,centerPrimary:`${De(10,e)} ${i}`,onUp:()=>t(0,-10),onDown:()=>t(0,10),onLeft:()=>t(-10,0),onRight:()=>t(10,0),labels:r})]})}function UJ({controls:t,measurementUnit:e,unitLabel:s,isDark:o,labels:r}){const i=t.stepMm;return n.jsxs("div",{children:[n.jsxs("div",{className:"mb-3 flex flex-wrap items-center justify-center gap-1.5",children:[n.jsx("span",{className:O("text-[11px] font-bold",o?"text-white/70":"text-[#182137]/70"),children:r.step}),t.stepOptionsMm.map(a=>n.jsxs("button",{type:"button",onClick:()=>t.onStepChange(a),"aria-pressed":a===i,className:O("rounded-full border px-2.5 py-1 text-[10px] font-bold tabular-nums transition-colors",a===i?"border-[#D85D43] bg-[#D85D43] text-white shadow-[0_2px_6px_rgba(216,93,67,0.35)]":o?"border-white/15 bg-white/[0.04] text-white/70 hover:bg-white/[0.1]":"border-[#182137]/12 bg-white text-[#182137]/70 hover:bg-[#182137]/[
4000.05]"),children:[De(a,e)," ",s]},a))]}),n.jsx(Tb,{size:"md",isDark:o,centerPrimary:De(i,e),centerSecondary:s,onUp:()=>t.onMove(0,-i),onDown:()=>t.onMove(0,i),onLeft:()=>t.onMove(-i,0),onRight:()=>t.onMove(i,0),labels:{up:r.forward,down:r.back,left:r.left,right:r.right}})]})}function KJ(t,e,s,o,r,i){if(o)return[];const a=(l,c,d)=>[{label:d[0],value:De(l,r)},{label:d[1],value:De(c,r)}];if(s){const l=s_(s.points2D);return l?a(l.lengthMm,l.widthMm,[i.width,i.height]):[]}if(t.kind==="facePatch"){const l=s_(t.points2D),c=l?a(l.lengthMm,l.widthMm,[i.width,i.height]):[];return c.push({label:i.depth,value:De(Math.round(t.depthMm??0),r)}),c}if(t.kind==="faceCornerArc")return[{label:i.radius,value:De(t.radiusMm,r)}];if(e){const l=An(t,e);if(l)return a(l.widthMm,l.heightMm,[i.width,i.height])}return[]}function s_(t){const e=Yi(t);if(e)return{lengthMm:e.lengthMm,widthMm:e.widthMm};if(t.length<3)return null;const s=t.map(a=>a.x),o=t.map(a=>a.y),r=Math.max(0,Math.round(Math.max(...s)-Math.min(...s))),i=Math.max(0,Math.round(Math.max(...o)-Math.min(...o)));return r>0&&i>0?{lengthMm:r,widthMm:i}:null}function $h({children:t}){const e=xc();return n.jsx("span",{className:O("mb-1.5 block text-start text-[10px] font-semibold uppercase tracking-wider",e?"text-white/55":"text-[#71717a]"),children:t})}function by({label:t,value:e,unitLabel:s,disabled:o,onChange:r,onCommit:i,onFocus:a,onBlur:l}){const c=xc(),[d,u]=m.useState(e),[h,x]=m.useState(!1);m.useEffect(()=>{h||u(e)},[h,e]);const f=p=>{x(!1),u(p),i(p),l(p)};return n.jsxs("label",{className:"grid grid-cols-[86px_1fr_auto] items-center gap-2 text-start",children:[n.jsx("span",{className:O("text-[12px] font-bold",c?"text-white/70":"text-[#182137]/70"),children:t}),n.jsx("input",{value:h?d:e,onChange:p=>{const b=p.target.value;u(b),r(b)},onFocus:p=>{x(!0),u(e),a();const b=p.currentTarget;window.setTimeout(()=>b.select(),0)},onBlur:p=>{f(p.currentTarget.value)},onKeyDown:p=>{p.stopPropagation(),p.key==="Enter"&&(p.preventDefault(),p.currentTarget.blur())},className:O("h-8 min-w-0 rounded-[4px] border px-2 text-center text-[12px] font-bold tabular-nums outline-none",c?"border-white/15 bg-[#0A0A0A] text-white focus:border-white/35":"border-[#182137]/12 bg-white text-[#182137] focus:border-[#336CFF]"),disabled:o,placeholder:"0",inputMode:"decimal"}),n.jsx("span",{className:O("text-[10px] font-bold",c?"text-white/45":"text-[#182137]/45"),children:s})]})}function ZJ({label:t,value:e,unitLabel:s}){const o=xc();return n.jsxs("div",{className:O("grid grid-cols-[86px_1fr_auto] items-center gap-2 rounded-md border px-2.5 py-2 text-start",o?"border-white/10 bg-white/[0.035]":"border-[#182137]/10 bg-white/70"),children:[n.jsx("span",{className:O("text-[12px] font-bold",o?"text-white/70":"text-[#182137]/70"),children:t}),n.jsx("span",{className:O("text-center text-[12px] font-bold tabular-nums",o?"text-white":"text-[#182137]"),children:e}),n.jsx("span",{className:O("text-[10px] font-bold",o?"text-white/45":"text-[#182137]/45"),children:s})]})}const qJ=[{id:"flat",label:"גג שטוח",eyebrow:"מודרני"},{id:"gable",label:"גג גמלון",eyebrow:"משופע"},{id:"gable-tiles",label:"גג גמלון רעפים",eyebrow:"רעפים"},{id:"hip",label:"גג ירכיים",eyebrow:"ארבעה שיפועים"}],JJ={"no-walls":"בקומה העליונה אין מספיק קירות לבניית מעטפת.","pending-alignment":"התוכנית של הקומה העליונה ממתינה ליישור.","host-hidden":"הקומה העליונה מוסתרת. הצג אותה כדי לראות את הגג.","open-envelope":"מעטפת הקירות פתוחה. יש לסגור את כל קירות החוץ.","self-intersection":"מעטפת הקירות חוצה את עצמה.","multiple-shells":"זוהו כמה מעטפות מבנה מנותקות.","offset-failed":"לא ניתן לחשב את פאות התמיכה החיצוניות לפי עובי הקירות.","invalid-envelope":"לא ניתן להפיק מעטפת סגורה מהקירות הקיימים.","non-coplanar-wall-tops":"ראשי קירות החוץ אינם באותו גובה. יש לאחד את גובה קירות התמיכה.","pitched-requires-rectangle":"גג גמלון או ירכיים זמין ב־MVP רק למעטפת מלבנית.","pitched-does-not-support-courtyard":"גג משופע אינו זמין כרגע למבנה עם חצר פנימית."};function QJ(t){return t?t.type==="flat"?"flat":t.type==="gable"&&t.finish==="tiles"?"gable-tiles":t.type:null}function tQ(t,e){const s=(e==null?void 0:e.material)??zy.material,o=e?{footprintMode:e.footprintMode,...e.footprintOverride?{footprintOverride:e.footprintOverride}:{}}:{};return t==="flat"?{...zy,...o,material:s}:{...QA,...o,type:t==="hip"?"hip":"gable",finish:t==="gable-tiles"?"tiles":"smooth",material:s}}function eQ({style:t}){return t==="flat"?n.jsxs("div",{className:"relative h-8 w-14",children:[n.jsx("div",{className:"absolute inset-x-0 bottom-1 h-4 rounded-[3px] border border-[#182137]/30 bg-[#E8DFD3]"}),n.jsx("div",{className:"absolute inset-x-1 top-1 h-1 border-x border-t border-[#D85D43]/80"})]}):n.jsxs("div",{className:"relative h-8 w-14",children:[n.jsx("div",{className:O("absolute left-1/2 top-1 h-7 w-7 -translate-x-1/2 rotate-45 border-l border-t border-[#182137]/35",t==="gable-tiles"?"bg-[#D85D43]/28":"bg-[#E8DFD3]")}),t==="hip"&&n.jsx("div",{className:"absolute left-1/2 top-1 h-7 w-px -translate-x-1/2 bg-[#D85D43]/60"})]})}function Ug({label:t,value:e,min:s,max:o,step:r,suffix:i,onChange:a}){return n.jsxs("label",{className:"grid grid-cols-[1fr_88px] items-center gap-2",children:[n.jsx("span",{className:"text-[11px] font-semibold text-[#182137]/70",children:t}),n.jsxs("span",{className:"flex h-9 items-center overflow-hidden rounded-lg border border-[#182137]/12 bg-[#FFFDFC]",children:[n.jsx("input",{type:"number",min:s,max:o,step:r,value:Math.round(e),onChange:l=>{const c=Number(l.currentTarget.value);Number.isFinite(c)&&a(Math.min(o,Math.max(s,c)))},className:"min-w-0 flex-1 bg-transparent px-2 text-center text-[12px] font-bold text-[#182137] outline-none"}),n.jsx("span",{className:"pe-2 text-[9px] font-semibold text-[#182137]/40",children:i})]})]})}function nQ({value:t,hostState:e,visible:s,onVisibilityChange:o,onDelete:r,onChange:i,onStyleSelect:a=i,contourEditing:l=!1,onStartContourEdit:c,onStopContourEdit:d,onResetContour:u,savedTiles:h,onUploadTile:x,onRemoveTile:f,onRenameTile:p,personalAssetsLocked:b=!1,onPremiumRequired:M,measurementUnit:g="cm"}){const w=QJ(t),k=(t==null?void 0:t.material.texture)??null,_=!!t&&!!e.reason&&e.reason!=="pending-alignment"&&e.reason!=="host-hidden"&&e.reason!=="non-coplanar-wall-tops",j=t&&e.reason?_?"הזיהוי האוטומטי לא מצא מעטפת גג ברורה. עבור על קווי שפת הגג וסגור את הצורה בנקודת ההתחלה.":JJ[e.reason]:null,v=(t==null?void 0:t.footprintMode)==="manual"&&!!t.footprintOverride&&!e.diagnostics.manualOverrideInvalid&&!e.diagnostics.manualOverrideStale,C=m.useMemo(()=>[{id:"auto",label:"אוטומטי"},{id:"long-axis",label:"ציר ארוך"},{id:"short-axis",label:"ציר קצר"}],[]),N=W=>{t&&i({...t,...W})},P=(t==null?void 0:t.material.preset)??null,L=W=>{if(t){if(P===W){N({material:{...t.material,preset:void 0}});return}N({finish:"tiles",material:{...t.material,preset:W}})}},A=W=>
400{const{preset:S,...B}=W;return B};return n.jsxs("div",{className:"space-y-4 p-3 font-heebo",dir:"rtl",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-[9px] font-bold uppercase tracking-[0.18em] text-[#D85D43]",children:"מעטפת בניין"}),n.jsx("p",{className:"mt-1 text-[11px] leading-5 text-[#182137]/58",children:"הגג שייך לבניין ונשען תמיד על הקומה העליונה."})]}),t&&n.jsxs("div",{className:"rounded-xl border border-[#182137]/10 bg-[#E8E3DB] p-3 shadow-[0_3px_0_rgba(24,33,55,0.08)]",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"grid h-9 w-9 shrink-0 place-items-center rounded-lg border border-[#182137]/10 bg-[#F7F4EF] text-[#D85D43] shadow-[0_2px_0_rgba(24,33,55,0.08)]",children:s?n.jsx(Hd,{className:"h-4 w-4"}):n.jsx(fc,{className:"h-4 w-4"})}),n.jsxs("div",{className:"min-w-0 flex-1",role:"status","aria-live":"polite",children:[n.jsx("div",{className:"text-[11px] font-black text-[#182137]",children:s?"הגג מוצג בתצוגה":"הגג מוסתר זמנית"}),n.jsx("p",{className:"mt-0.5 text-[9px] leading-4 text-[#182137]/52",children:"ההסתרה משפיעה על התצוגה בלבד ואינה משנה את הפרויקט."})]})]}),n.jsxs("button",{type:"button","aria-pressed":!s,onClick:()=>o(!s),className:"mt-3 flex min-h-11 w-full items-center justify-center gap-2 rounded-lg border border-[#182137]/12 bg-[#F7F4EF] px-3 text-[11px] font-black text-[#182137] shadow-[0_3px_0_rgba(24,33,55,0.14)] transition hover:-translate-y-0.5 hover:border-[#D85D43]/45 active:translate-y-0.5 active:shadow-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#D85D43]/45 motion-reduce:transform-none motion-reduce:transition-none",children:[s?n.jsx(fc,{className:"h-4 w-4"}):n.jsx(Hd,{className:"h-4 w-4"}),s?"הסתר בתצוגה":"הצג גג"]})]}),n.jsx("div",{className:"grid grid-cols-2 gap-2",children:qJ.map(W=>{const S=W.id===w;return n.jsxs("button",{type:"button",onClick:()=>a(tQ(W.id,t)),className:O("relative min-h-[112px] rounded-xl border p-2.5 text-right shadow-[0_3px_0_rgba(24,33,55,0.06)] transition motion-reduce:transition-none","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#D85D43]/45",S?"border-[#D85D43] bg-[#F6E6E0] -translate-y-0.5 shadow-[0_5px_0_rgba(216,93,67,0.16)]":"border-[#182137]/10 bg-[#FFFDFC] hover:-translate-y-0.5 hover:border-[#182137]/20"),children:[n.jsx("div",{className:"flex h-10 items-center justify-center",children:n.jsx(eQ,{style:W.id})}),n.jsx("div",{className:"mt-1 text-[9px] font-bold uppercase tracking-wider text-[#182137]/38",children:W.eyebrow}),n.jsx("div",{className:"text-[12px] font-black text-[#182137]",children:W.label}),S&&n.jsx("span",{className:"absolute end-2 top-2 grid h-5 w-5 place-items-center rounded-full bg-[#D85D43] text-[#F7F4EF]",children:n.jsx(Gc,{size:11,strokeWidth:3})}),S&&j&&n.jsx("span",{className:"absolute inset-x-2 bottom-2 text-[8px] font-black text-[#9A4433]",children:_?"נדרש סימון":"נדרשת פעולה"})]},W.id)})}),j&&n.jsx("div",{className:"rounded-xl border border-[#D85D43]/22 bg-[#FDF3F0] p-3 text-[#7B3A2D]",children:n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx(zI,{className:"mt-0.5 h-4 w-4 shrink-0"}),n.jsxs("div",{children:[n.jsx("div",{className:"text-[11px] font-black",children:_?"סמן את אזור הגג על התוכנית":"נדרשת פעולה לפני הצגת הגג"}),n.jsx("p",{className:"mt-0.5 text-[10px] leading-4",children:j})]})]})}),t&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"rounded-xl border border-[#182137]/9 bg-[#FFFDFC] p-3",children:[n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx(TI,{className:"mt-0.5 h-4 w-4 shrink-0 text-[#D85D43]"}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("div",{className:"text-[11px] font-black text-[#182137]",children:e.canRender?`מוצמד לקומה העליונה · ${(e.baseElevationMm/1e3).toFixed(2)} מ׳`:_?"סמן וסגור את קווי שפת הגג":"נדרשת פעולה לפני הצמדת הגג"}),n.jsx("div",{className:"mt-0.5 text-[9px] leading-4 text-[#182137]/48",children:v?"קונטור עצמאי שסומן על התוכנית · אינו משנה את קירות הקומה":"עדיין לא סומן קונטור ידני · אפשר לסמן ישירות על התוכנית"})]})]}),n.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-2",children:[n.jsxs("button",{type:"button",onClick:l?d:c,className:O("flex min-h-11 items-center justify-center gap-1.5 rounded-lg border px-2 text-[10px] font-black shadow-[0_3px_0_rgba(24,33,55,0.12)] transition motion-reduce:transition-none",l?"translate-y-0.5 border-[#D85D43] bg-[#D85D43] text-[#F7F4EF] shadow-none":"border-[#182137]/12 bg-[#F7F4EF] text-[#182137] hover:-translate-y-0.5 hover:border-[#D85D43]/45"),children:[n.jsx(bT,{className:"h-3.5 w-3.5"}),l?"סיום סימון":v?"עריכת סימון בתוכנית":"סימון גג על התוכנית"]}),n.jsxs("button",{type:"button",disabled:t.footprintMode!=="manual",onClick:u,className:"flex min-h-11 items-center justify-center gap-1.5 rounded-lg border border-[#182137]/12 bg-[#E8E3DB] px-2 text-[10px] font-bold text-[#182137]/70 shadow-[0_2px_0_rgba(24,33,55,0.12)] transition hover:-translate-y-0.5 hover:border-[#D85D43]/35 disabled:cursor-not-allowed disabled:opacity-35 motion-reduce:transition-none",children:[n.jsx(zu,{className:"h-3.5 w-3.5"}),"חזרה לזיהוי אוטומטי"]})]})]}),n.jsxs("div",{className:"space-y-2 rounded-xl border border-[#182137]/9 bg-[#F7F4EF] p-3",children:[n.jsx("div",{className:"mb-2 text-[10px] font-black uppercase tracking-wider text-[#182137]/52",children:"מידות מתקדמות"}),t.type!=="flat"&&n.jsx(Ug,{label:"שיפוע",value:t.pitchDeg,min:5,max:60,step:1,suffix:"°",onCh
400ange:W=>N({pitchDeg:W})}),n.jsx(Ug,{label:"בליטה מעבר לקיר",value:t.overhangMm,min:0,max:2e3,step:50,suffix:'מ"מ',onChange:W=>N({overhangMm:W})}),t.type==="flat"&&n.jsx(Ug,{label:"גובה מעקה",value:t.parapetHeightMm,min:0,max:2500,step:50,suffix:'מ"מ',onChange:W=>N({parapetHeightMm:W})}),n.jsx(Ug,{label:"עובי הגג",value:t.thicknessMm,min:50,max:1e3,step:10,suffix:'מ"מ',onChange:W=>N({thicknessMm:W})}),t.type!=="flat"&&n.jsxs("div",{className:"pt-1",children:[n.jsx("div",{className:"mb-1.5 text-[10px] font-semibold text-[#182137]/55",children:"כיוון רכס"}),n.jsx("div",{className:"grid grid-cols-3 gap-1 rounded-lg bg-[#182137]/5 p-1",children:C.map(W=>n.jsx("button",{type:"button",onClick:()=>N({ridgeDirection:W.id}),className:O("min-h-9 rounded-md px-1 text-[9px] font-bold transition-colors",t.ridgeDirection===W.id?"bg-[#182137] text-[#F7F4EF]":"text-[#182137]/62 hover:bg-white/80"),children:W.label},W.id))})]})]}),n.jsxs("div",{className:"rounded-xl border border-[#182137]/9 bg-[#FFFDFC] p-3",children:[n.jsx("div",{className:"text-[10px] font-black uppercase tracking-wider text-[#182137]/52",children:"חומר הגג"}),n.jsx("p",{className:"mt-0.5 text-[9px] leading-4 text-[#182137]/45",children:"חומרים מוכנים עם עומק ומרקם. לחיצה חוזרת מבטלת ומחזירה לחיפוי מהספרייה."}),n.jsx("div",{className:"mt-2.5 grid grid-cols-2 gap-2",children:CA.map(W=>{const S=d3[W],B=P===W;return n.jsxs("button",{type:"button",onClick:()=>L(W),"aria-pressed":B,className:O("relative overflow-hidden rounded-xl border p-2 text-right shadow-[0_3px_0_rgba(24,33,55,0.06)] transition motion-reduce:transition-none","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#D85D43]/45",B?"border-[#D85D43] bg-[#F6E6E0] -translate-y-0.5 shadow-[0_5px_0_rgba(216,93,67,0.16)]":"border-[#182137]/10 bg-[#FFFDFC] hover:-translate-y-0.5 hover:border-[#182137]/20"),children:[n.jsx("span",{className:"block h-12 w-full rounded-lg border border-[#182137]/8 bg-cover bg-center",style:{backgroundImage:`url(${S.diffuse})`,backgroundColor:S.trimBase}}),n.jsx("span",{className:"mt-1.5 block text-[12px] font-black text-[#182137]",children:S.labelHe}),n.jsx("span",{className:"block text-[9px] leading-4 text-[#182137]/45",children:S.hintHe}),B&&n.jsx("span",{className:"absolute end-2 top-2 grid h-5 w-5 place-items-center rounded-full bg-[#D85D43] text-[#F7F4EF]",children:n.jsx(Gc,{size:11,strokeWidth:3})})]},W)})})]}),n.jsx(Df,{mode:"material",target:"roof",variant:"embedded",onClose:()=>{},currentTextureUrl:(k==null?void 0:k.url)??t.material.color,tileWidthCm:(k==null?void 0:k.tileWidthCm)??100,tileHeightCm:(k==null?void 0:k.tileHeightCm)??100,measurementUnit:g,groutWidthMm:(k==null?void 0:k.groutWidthMm)??0,groutColor:(k==null?void 0:k.groutColor)??"#c8c4bc",onSelectTexture:W=>N({finish:"tiles",material:{...A(t.material),color:void 0,texture:{url:W,tileWidthCm:(k==null?void 0:k.tileWidthCm)??100,tileHeightCm:(k==null?void 0:k.tileHeightCm)??100,groutWidthMm:(k==null?void 0:k.groutWidthMm)??0,groutColor:(k==null?void 0:k.groutColor)??"#c8c4bc"}}}),onSelectColor:W=>N({finish:"smooth",material:{color:W,texture:null}}),onTileSizeChange:(W,S)=>{k&&N({material:{...A(t.material),texture:{...k,tileWidthCm:W,tileHeightCm:S}}})},onGroutChange:(W,S)=>{k&&N({material:{...A(t.material),texture:{...k,groutWidthMm:W,groutColor:S}}})},onClear:()=>N({finish:"smooth",material:{color:"#d8d2c6",texture:null}}),savedTiles:h,getPublicUrl:_f,onUploadTile:x,onRemoveTile:f,onRenameTile:p,personalAssetsLocked:b,onPremiumRequired:M}),n.jsxs(Fw,{children:[n.jsx(bN,{asChild:!0,children:n.jsxs("button",{type:"button",className:"flex min-h-11 w-full items-center justify-center gap-2 rounded-xl border border-[#D85D43]/30 bg-[#F6E6E0] px-3 text-[11px] font-black text-[#8A3E30] shadow-[0_3px_0_rgba(138,62,48,0.12)] transition hover:-translate-y-0.5 hover:border-[#D85D43]/55 hover:bg-[#F2DCD4] active:translate-y-0.5 active:shadow-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#D85D43]/45 motion-reduce:transform-none motion-reduce:transition-none",children:[n.jsx(gi,{className:"h-4 w-4"}),"מחק את הגג מהפרויקט"]})}),n.jsxs(Cw,{dir:"rtl",className:"border border-[#182137]/12 bg-[#F7F4EF] font-heebo text-[#182137] shadow-[0_24px_60px_rgba(24,33,55,0.18)]",children:[n.jsxs(Nw,{className:"text-right sm:text-right",children:[n.jsx(Iw,{className:"font-heebo text-xl font-black tracking-[-0.035em] text-[#182137]",children:"למחוק את הגג?"}),n.jsx(Tw,{className:"text-right text-sm leading-6 text-[#182137]/65",children:"סגנון הגג, החומר והקונטור יימחקו מהפרויקט."})]}),n.jsxs(Sw,{className:"gap-2 sm:flex-row-reverse sm:justify-start",children:[n.jsx(Pw,{className:"min-h-11 rounded-xl border-[#182137]/15 bg-[#E8E3DB] px-4 font-bold text-[#182137] shadow-[0_3px_0_rgba(24,33,55,0.12)] hover:bg-[#
400E0DFD8] focus-visible:ring-[#D85D43]/45",children:"השאר את הגג"}),n.jsx(Aw,{onClick:r,className:"min-h-11 rounded-xl bg-[#D85D43] px-4 font-black text-[#F7F4EF] shadow-[0_3px_0_#A94231] hover:bg-[#C94E35] active:translate-y-0.5 active:shadow-none focus-visible:ring-[#D85D43]/45 motion-reduce:transform-none",children:"מחק גג"})]})]})]})]})]})}function oQ({hint:t,info:e,toolContent:s}){const o=xc();return n.jsxs("div",{className:O("flex shrink-0 items-center gap-4 border-t px-4",s?"h-12":"h-7",o?"border-white/10 bg-[#0c0c0d] text-white/80":"border-[#182137]/[0.08] bg-[#F7F4EF] text-[#182137]/75"),children:[n.jsx("span",{className:O("min-w-0 flex-1 truncate text-[11px]",o?"text-white/60":"text-[#182137]/65"),children:t}),s&&n.jsx("div",{className:"shrink-0",children:s}),e&&n.jsx("span",{className:O("font-mono text-[11px] tabular-nums",o?"text-white/45":"text-[#182137]/45"),children:e})]})}const Ff=["projectAndPlan","openings","floor","walls","beams","furniture","ceiling","roof","environment","smartAgent","sketchShape","sketchTemplates","settings"],vm=[{id:"projectAndPlan",labelKey:"sections.projectAndPlan",labelFallback:"פרטים ותוכנית",icon:r5,visibleIn:"both",workspaceScope:"both",sketchSoftLock:!1},{id:"openings",labelKey:"sections.openings",labelFallback:"פתחים",icon:Cf,visibleIn:"both",workspaceScope:"floor",sketchSoftLock:!0},{id:"floor",labelKey:"sections.floor",labelFallback:"ריצוף",icon:np,visibleIn:"both",workspaceScope:"floor",sketchSoftLock:!0},{id:"walls",labelKey:"sections.walls",labelFallback:"חיפויים",icon:Gh,visibleIn:"both",workspaceScope:"floor",sketchSoftLock:!0},{id:"beams",labelKey:"sections.beams",labelFallback:"קורות",icon:rT,visibleIn:"both",workspaceScope:"floor",sketchSoftLock:!0},{id:"furniture",labelKey:"sections.furniture",labelFallback:"ריהוט",icon:um,visibleIn:"both",workspaceScope:"floor",sketchSoftLock:!0},{id:"ceiling",labelKey:"sections.ceiling",labelFallback:"תקרה",icon:MN,visibleIn:"both",workspaceScope:"floor",sketchSoftLock:!0},{id:"roof",labelKey:"sections.roof",labelFallback:"גג",icon:$u,visibleIn:"both",workspaceScope:"both",sketchSoftLock:!0},{id:"environment",labelKey:"sections.environment",labelFallback:"סביבה",icon:Dw,visibleIn:"3d",workspaceScope:"both",sketchSoftLock:!0},{id:"smartAgent",labelKey:"sections.smartAgent",labelFallback:"סוכן חכם",icon:F1,visibleIn:"both",workspaceScope:"floor",sketchSoftLock:!1},{id:"sketchShape",labelKey:"sections.sketchShape",labelFallback:"אלמנט",icon:Ew,visibleIn:"both",workspaceScope:"floor",sketchSoftLock:!1,standalone:!1},{id:"sketchTemplates",labelKey:"sections.sketchTemplates",labelFallback:"תבניות",icon:r5,visibleIn:"both",workspaceScope:"floor",sketchSoftLock:!1},{id:"settings",labelKey:"sections.settings",labelFallback:"הגדרות",icon:yN,visibleIn:"both",workspaceScope:"both",sketchSoftLock:!1}];function lk(){return vm.reduce((t,e)=>({...t,[e.id]:!1}),{})}const y1={projectAndPlan:!0,openings:!1,floor:!1,walls:!1,beams:!1,furniture:!1,ceiling:!1,roof:!1,environment:!1,smartAgent:!1,sketchShape:!1,sketchTemplates:!1,settings:!1};function Tp(t){return{...lk(),[t]:!0}}function sQ(t){if(!t||typeof t!="object")return y1;const e=t,s=vm.find(o=>e[o.id]===!0);return s?Tp(s.id):lk()}Tp("projectAndPlan");const rQ=["projectAndPlan","openings","floor","furniture","ceiling","settings"];function iQ(){const t=g6();for(const e of rQ)t[e]=!1;return t}function p6(t,e,s="floor"){const o=t.visibleIn==="both"||t.visibleIn===e,r=t.workspaceScope==="both"||t.workspaceScope===s;return o&&r}const Vb="projectAndPlan";function g6(){return vm.reduce((t,e)=>({...t,[e.id]:!0}),{})}function ep(t){const e=g6();if(!t||typeof t!="object")return e;const s=t;return vm.reduce((o,r)=>({...o,[r.id]:r.id===Vb?!0:typeof s[r.id]=="boolean"?s[r.id]:e[r.id]}),{})}function r_(t,e,s){return e===Vb?{...t,[e]:!0}:ep({...t,[e]:s})}const aQ=new Set(Ff);function My(t){const e=[];if(Array.isArray(t)){for(const s of t)if(typeof s=="string"&&aQ.has(s)){const o=s;e.includes(o)||e.push(o)}}for(const s of Ff){if(e.includes(s))continue;const o=Ff.indexOf(s),r=[...Ff.slice(0,o)].reverse().find(a=>e.includes(a));if(r){e.splice(e.indexOf(r)+1,0,s);continue}const i=Ff.slice(o+1).find(a=>e.includes(a));i?e.splice(e.indexOf(i),0,s):e.push(s)}return e}function lQ(t,e,s,o){const r=new Set(o),i=t.filter(h=>
400r.has(h)),a=i.indexOf(e),l=i.indexOf(s);if(a<0||l<0||a===l)return[...t];const c=[...i],[d]=c.splice(a,1);c.splice(l,0,d);let u=0;return t.map(h=>r.has(h)?c[u++]:h)}function b6(t,e){const s=new Map(e.map((o,r)=>[o,r]));return[...t].sort((o,r)=>(s.get(o.id)??999)-(s.get(r.id)??999))}function M6({mainView:t,viewScope:e="floor",sectionVisibility:s,sectionOrder:o,onSectionVisibilityChange:r,onShowPanel:i,triggerTooltip:a,fpIsDark:l=!1,allowTogglePinnedSection:c=!1,children:d}){const{t:u,i18n:h}=yn(),[x,f]=m.useState(!1),p=b6(vm,o??Ff).filter(M=>M.standalone!==!1&&p6(M,t,e)),b=n.jsx(Qu,{asChild:!0,children:d});return n.jsxs(qu,{open:x,onOpenChange:f,children:[a?n.jsxs(Yl,{children:[n.jsx(Gl,{asChild:!0,children:b}),n.jsx(Ul,{side:"bottom",sideOffset:26,className:"border-[#182137]/12 bg-[#F7F4EF] px-2.5 py-1.5 font-heebo text-[11px] font-semibold leading-none text-[#182137] shadow-[0_8px_22px_rgba(24,33,55,0.16)]",children:a})]}):b,n.jsxs(Ju,{align:"start",side:"bottom",sideOffset:6,dir:h.dir(),"data-testid":"floorplan-details-section-visibility-popover",onOpenAutoFocus:M=>M.preventDefault(),className:O("w-[260px] p-2 shadow-[0_14px_38px_rgba(24,33,55,0.16)]",l?"border-white/10 bg-[#141416] text-white":"border-[#182137]/12 bg-[#F7F4EF] text-[#182137]"),children:[n.jsxs("div",{className:O("border-b px-2 pb-2",l?"border-white/10":"border-[#182137]/10"),children:[n.jsx("p",{className:"text-sm font-semibold",children:u("details.categories",{defaultValue:"קטגוריות במאפיינים"})}),n.jsx("p",{className:O("mt-0.5 text-[11px] leading-snug",l?"text-white/55":"text-[#182137]/58"),children:u("details.chooseVisible",{defaultValue:"בחר מה יוצג בלוח הצד"})})]}),n.jsx("div",{className:"max-h-[360px] overflow-auto py-1 [scrollbar-color:#D9603B_transparent] [scrollbar-width:thin]",children:p.map(M=>{const g=M.id===Vb&&!c,w=()=>{g||(r(M.id,!s[M.id]),i())};return n.jsxs("button",{type:"button","data-testid":`floorplan-section-visibility-${M.id}`,disabled:g,className:O("flex h-9 w-full items-center gap-2 rounded-md px-2 text-start text-sm font-medium",l?"hover:bg-white/10":"hover:bg-[#E8DFD3]",g?"cursor-default opacity-80":"cursor-pointer"),onPointerDown:k=>{k.preventDefault(),k.stopPropagation(),w()},children:[n.jsx(wN,{"data-testid":`floorplan-section-visibility-checkbox-${M.id}`,checked:s[M.id],disabled:g,tabIndex:-1,"aria-hidden":!0,className:O("pointer-events-none border-[#182137]/35 data-[state=checked]:border-[#D9603B] data-[state=checked]:bg-[#D9603B]",l&&"border-white/35")}),n.jsx("span",{className:"min-w-0 flex-1 truncate",children:u(M.labelKey,{defaultValue:M.labelFallback})}),g?n.jsx("span",{className:O("shrink-0 text-[10px] font-semibold",l?"text-white/45":"text-[#182137]/45"),children:u("details.pinned",{defaultValue:"נעוץ"})}):null]},M.id)})})]})]})}function $r({icon:t,label:e,onClick:s,disabled:o,active:r,iconClassName:i}){return n.jsxs(Yl,{children:[n.jsx(Gl,{asChild:!0,children:n.jsx("button",{type:"button",onClick:a=>{Pr("menuClick"),s(a)},onMouseEnter:o?void 0:()=>Pr("menuHover"),disabled:o,"aria-label":e,"data-active":r?"":void 0,className:O("group","flex h-8 w-8 items-center justify-center rounded-[3px] border border-transparent text-[#182137] transition-colors","hover:border-[#182137]/15 hover:bg-[#E8DFD3]","disabled:cursor-not-allowed disabled:opacity-35 disabled:hover:border-transparent disabled:hover:bg-transparent",r&&"border-[#336CFF]/35 bg-[#DDE8FF] text-[#173a76] shadow-[inset_0_0_0_1px_rgba(51,108,255,0.14)]"),children:n.jsx(t,{className:O(t===U1?void 0:"h-[18px] w-[18px]",i),strokeWidth:t===U1||t===A3?void 0:t===w6?2.15:1.85})})}),n.jsx(Ul,{side:"bottom",sideOffset:26,className:"border-[#182137]/12 bg-[#F7F4EF] px-2.5 py-1.5 font-heebo text-[11px] font-semibold leading-none text-[#182137] shadow-[0_8px_22px_rgba(24,33,55,0.16)]",children:e})]})}function cQ({tr:t}){const e=Ty(o=>o.muted),s=Ty(o=>o.toggleMuted);return n.jsx($r,{icon:e?jN:_N,label:e?t("topBar.sound.unmute","הפעל צלילים"):t("topBar.sound.mute","השתק צלילים"),active:!e,onClick:()=>s()})}function y6({label:t,onClick:e,tooltip:s}
400){return n.jsxs(Yl,{children:[n.jsx(Gl,{asChild:!0,children:n.jsx("button",{type:"button",onClick:e,"aria-label":s,"data-testid":`floorplan-view-mode-${t.toLowerCase()}`,className:O("flex h-8 w-8 items-center justify-center rounded-[3px] border border-transparent text-[#182137] transition-colors","hover:border-[#182137]/15 hover:bg-[#E8DFD3]"),children:n.jsx("span",{className:"text-[12px] font-black leading-none tracking-tight",children:t})})}),n.jsx(Ul,{side:"bottom",sideOffset:26,className:"border-[#182137]/12 bg-[#F7F4EF] px-2.5 py-1.5 font-heebo text-[11px] font-semibold leading-none text-[#182137] shadow-[0_8px_22px_rgba(24,33,55,0.16)]",children:s})]})}function dQ({onClick:t,label:e}){return n.jsxs(Yl,{children:[n.jsx(Gl,{asChild:!0,children:n.jsxs("button",{type:"button",onClick:t,"aria-label":e,className:O("group relative inline-flex h-8 w-8 items-center justify-center overflow-hidden rounded-[7px] border text-white transition-all duration-150","border-[#FF8FA3]/70 bg-[linear-gradient(145deg,#FF8FA3_0%,#E63946_48%,#BE123C_100%)] shadow-[inset_0_1px_0_rgba(255,230,235,0.75),inset_0_-2px_0_rgba(120,20,40,0.32),0_5px_12px_rgba(230,57,70,0.32),0_1px_0_rgba(24,33,55,0.14)]","hover:-translate-y-0.5 hover:shadow-[inset_0_1px_0_rgba(255,230,235,0.82),inset_0_-2px_0_rgba(120,20,40,0.28),0_8px_18px_rgba(230,57,70,0.44),0_2px_0_rgba(24,33,55,0.12)]","active:translate-y-[1px]"),children:[n.jsx("span",{className:"pointer-events-none absolute inset-x-1 top-1 h-2 rounded-full bg-white/35 blur-[1px]"}),n.jsx(Ey,{className:"relative z-10 h-[17px] w-[17px] drop-shadow-[0_1px_1px_rgba(88,20,32,0.45)]",strokeWidth:2.25,fill:"currentColor",fillOpacity:.18})]})}),n.jsx(Ul,{side:"bottom",sideOffset:26,className:"border-[#182137]/12 bg-[#F7F4EF] px-2.5 py-1.5 font-heebo text-[11px] font-semibold leading-none text-[#182137] shadow-[0_8px_22px_rgba(24,33,55,0.16)]",children:e})]})}function uQ({onClick:t,ariaLabel:e,tooltip:s}){return n.jsxs(Yl,{children:[n.jsx(Gl,{asChild:!0,children:n.jsxs("button",{type:"button",autoFocus:!0,onClick:t,"aria-label":e,"data-testid":"floorplan-walkthrough-rec-indicator",dir:"ltr",className:O("group relative inline-flex h-8 min-w-[58px] items-center justify-center gap-1.5 overflow-hidden rounded-[7px] border px-1.5 font-mono font-black","border-[#C94E35] bg-[#D85D43] shadow-[inset_0_1px_0_rgba(247,244,239,0.52),inset_0_-2px_0_rgba(121,42,27,0.34),0_0_0_2px_rgba(216,93,67,0.16),0_6px_14px_rgba(216,93,67,0.36)]","transition-all duration-150 hover:-translate-y-0.5 hover:bg-[#C94E35] hover:shadow-[inset_0_1px_0_rgba(247,244,239,0.60),inset_0_-2px_0_rgba(121,42,27,0.30),0_0_0_3px_rgba(216,93,67,0.18),0_8px_18px_rgba(216,93,67,0.42)]","active:translate-y-[1px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#336CFF]/55 focus-visible:ring-offset-2 focus-visible:ring-offset-[#F4F1EA]"),children:[n.jsx("span",{className:"pointer-events-none absolute inset-x-1 top-1 h-1.5 rounded-full bg-[#F7F4EF]/30 blur-[1px]"}),n.jsxs("span",{"aria-hidden":!0,className:"relative flex h-2 w-2 shrink-0 items-center justify-center",children:[n.jsx("span",{className:"absolute inline-flex h-full w-full rounded-full bg-[#F7F4EF]/75 motion-safe:animate-ping motion-reduce:animate-none"}),n.jsx("span",{className:"relative inline-flex h-1.5 w-1.5 rounded-full bg-[#F7F4EF] shadow-[0_0_5px_rgba(247,244,239,0.95)]"})]}),n.jsx("span",{className:"relative rounded-[4px] bg-[#F7F4EF] px-1.5 py-1 text-[10px] leading-none tracking-[0.12em] text-[#182137] shadow-[inset_0_-1px_0_rgba(24,33,55,0.12)]",children:"REC"})]})}),n.jsx(Ul,{side:"bottom",sideOffset:26,className:"border-[#182137]/12 bg-[#F7F4EF] px-2.5 py-1.5 font-heebo text-[11px] font-semibold leading-none text-[#182137] shadow-[0_8px_22px_rgba(24,33,55,0.16)]",children:s})]})}function w6({className:t,strokeWidth:e=1.85,...s}){return n.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:e,strokeLinecap:"round",strokeLinejoin:"round",className:t,"aria-hidden":"true",...s,children:[n.jsx("circle",{cx:"12",cy:"4.6",r:"1.7"}),n.jsx("path",{d:"M11.2 7.6 9.5 11.4l3.5 2 2.5-2.2"}),n.jsx("path",{d:"M9.6 11.3 6.8 13.2"}),n.jsx("path",{d:"M15.3 11.2 17.7 9.7"}),n.jsx("path",{d:"M13 13.4v4.1L9.7 21"}),n.jsx("path",{d:"M13.5 13.7 16 16.7 18.1 21"})]})}function ic({children:t,label:e}){return n.jsx("div",{className:"flex h-8 items-center gap-0.5 border-e border-[#182137]/12 pe-1.5 ps-1.5 last:border-e-0 last:pe-0","aria-label":e,children:t})}function hQ({notes:t,onShow:e,onFocus:s,tr:o,isRTL:r}){const[i,a]=m.useState(!1),l=t.filter(d=>!d.hidden).length,c=[...t].sort((d,u)=>u.createdAt.localeCompare(d.createdAt));return n.jsxs(qu,{open:i,onOpenChange:a,children:[n.jsxs(Yl,{children:[n.jsx(Gl,{asChild:!0,children:n.jsx(Qu,{asChild:!0,children:n.jsxs("button",{type:"button","aria-label":o("topBar.notes.myNotes","הפתקים שלי"),"data-active":i||t.length>0?"":void 0,className:O("group relative flex h-8 items-center justify-center gap-1.5 rounded-[3px] border border-transparent px-2 text-[#182137] transition-colors","hover:border-[#182137]/15 hover:bg-[#
400E8DFD3]",(i||t.length>0)&&"border-[#336CFF]/35 bg-[#DDE8FF] text-[#173a76] shadow-[inset_0_0_0_1px_rgba(51,108,255,0.14)]"),children:[n.jsxs("span",{className:"relative flex h-[18px] w-[18px] shrink-0 items-center justify-center",children:[n.jsx(Af,{className:"h-[18px] w-[18px]",strokeWidth:1.85}),t.length>0&&n.jsx("span",{className:"pointer-events-none absolute -end-1 -top-1 flex h-[13px] min-w-[13px] items-center justify-center rounded-full bg-[#D85D43] px-[3px] text-[8px] font-black leading-none text-white ring-1 ring-[#F4F1EA]",children:t.length})]}),n.jsx("span",{className:"whitespace-nowrap text-[11px] font-black leading-none",children:o("topBar.notes.myNotes","הפתקים שלי")})]})})}),n.jsx(Ul,{side:"bottom",sideOffset:26,className:"border-[#182137]/12 bg-[#F7F4EF] px-2.5 py-1.5 font-heebo text-[11px] font-semibold leading-none text-[#182137] shadow-[0_8px_22px_rgba(24,33,55,0.16)]",children:o("topBar.notes.myNotes","הפתקים שלי")})]}),n.jsxs(Ju,{dir:r?"rtl":"ltr",align:"start",side:"bottom",sideOffset:8,className:"z-[90] w-[310px] rounded-md border-[#182137]/12 bg-[#F7F4EF] p-2 font-heebo text-[#182137] shadow-[0_18px_42px_rgba(24,33,55,0.2)]",children:[n.jsx("div",{className:"flex items-center justify-between border-b border-[#182137]/10 px-1 pb-2",children:n.jsxs("div",{children:[n.jsx("div",{className:"text-[12px] font-black",children:o("topBar.notes.myNotes","הפתקים שלי")}),n.jsx("div",{className:"text-[10px] font-semibold text-[#182137]/55",children:t.length===0?o("topBar.notes.noNotes","אין פתקים"):o("topBar.notes.visibleCount","{{visible}} מוצגים מתוך {{total}}",{visible:l,total:t.length})})]})}),c.length===0?n.jsx("div",{className:"px-2 py-4 text-center text-[12px] font-semibold text-[#182137]/55",children:o("topBar.notes.emptyState","אין עדיין פתקים על הסקיצה")}):n.jsx("div",{className:"mt-2 max-h-[320px] space-y-1 overflow-y-auto",children:c.map(d=>{const u=Vl(d.contentHtml)||o("topBar.notes.untitled","פתק ללא טקסט");return n.jsxs("button",{type:"button",onClick:()=>{d.hidden?e==null||e(d.id):s==null||s(d.id),a(!1)},className:"flex w-full items-center gap-2 rounded-[4px] px-2 py-2 text-right transition-colors hover:bg-[#E8DFD3]",children:[n.jsx("span",{className:"h-8 w-8 shrink-0 rounded-md border border-[#182137]/10",style:{backgroundColor:Ku(d.colorId)}}),n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsx("span",{className:"block truncate text-[12px] font-bold text-[#182137]",children:u}),n.jsx("span",{className:"mt-0.5 block text-[10px] font-semibold text-[#182137]/50",children:d.hidden?o("topBar.notes.hidden","מוסתר"):o("topBar.notes.visible","מוצג")})]}),n.jsx("span",{className:"shrink-0 rounded-md border border-[#182137]/10 bg-white/65 px-2 py-1 text-[10px] font-black text-[#182137]/70",children:d.hidden?o("topBar.notes.showNote","הראה פתק"):o("topBar.notes.focus","סמן")})]},d.id)})})]})]})}function mQ(t){return[{tool:"select",icon:I_,label:t("topBar.sketch.select","בחירה")},{tool:"line",icon:Pp,label:t("topBar.sketch.line","קו")},{tool:"rectangle",icon:$I,label:t("topBar.sketch.rectangle","מלבן")},{tool:"measure",icon:hp,label:t("topBar.sketch.measure","סרט מדידה")},{tool:"polygon",icon:WI,label:t("topBar.sketch.polygon","פוליגון")},{tool:"circle",icon:vN,label:t("topBar.sketch.circle","עיגול")},{tool:"offset",icon:Y_,label:"Offset"},{tool:"pushPull",icon:U1,label:"Push/Pull"},{tool:"rotate",icon:X_,label:t("topBar.sketch.rotate","סיבוב")}]}function fQ(t){return[{tool:"faceLine",icon:Pp,label:t("topBar.sketch.faceLine","קו על פאה")},{tool:"faceCornerArc",icon:gT,label:t("topBar.sketch.faceCornerArc","קשת פינה משיקה")},{tool:"faceRectangle",icon:vI,label:t("topBar.sketch.faceRectangle","מלבן על פאה")},{tool:"faceMeasure",icon:hp,label:t("topBar.sketch.faceMeasure","סרט מדידה על פאה")},{tool:"faceOffset",icon:Y_,label:t("topBar.sketch.faceOffset","אוף סט על פאה")}]}function xQ({activeTool:t,onSetTool:e,tr:s,isRTL:o}){const r=fQ(s),i=r.find(({tool:d})=>d===t)??null,a=(i==null?void 0:i.icon)??fT,l=!!i,c=(i==null?void 0:i.label)??s("topBar.sketch.faceTools","כלים על פאה");return n.jsxs(T_,{dir:o?"rtl":"ltr",children:[n.jsxs(Yl,{children:[n.jsx(Gl,{asChild:!0,children:n.jsx(S_,{asChild:!0,children:n.jsxs("button",{type:"button","aria-label":c,"data-active":l?"":void 0,className:O("group flex h-8 w-10 items-center justify-center gap-0.5 rounded-[3px] border border-transparent text-[#182137] transition-colors","hover:border-[#182137]/15 hover:bg-[#
400E8DFD3]",l&&"border-[#336CFF]/35 bg-[#DDE8FF] text-[#173a76] shadow-[inset_0_0_0_1px_rgba(51,108,255,0.14)]"),children:[n.jsx(a,{className:"h-[17px] w-[17px]",strokeWidth:1.85}),n.jsx(Yc,{className:"h-3 w-3 opacity-70",strokeWidth:2})]})})}),n.jsx(Ul,{side:"bottom",sideOffset:26,className:"border-[#182137]/12 bg-[#F7F4EF] px-2.5 py-1.5 font-heebo text-[11px] font-semibold leading-none text-[#182137] shadow-[0_8px_22px_rgba(24,33,55,0.16)]",children:c})]}),n.jsx(P_,{align:"start",side:"bottom",sideOffset:8,className:"z-[90] min-w-[150px] border-[#182137]/12 bg-[#F7F4EF] p-1 font-heebo text-[#182137] shadow-[0_14px_34px_rgba(24,33,55,0.18)]",children:r.map(({tool:d,icon:u,label:h})=>{const x=t===d;return n.jsxs(A_,{dir:o?"rtl":"ltr",onSelect:()=>e(x?null:d),className:O("flex cursor-pointer items-center justify-between gap-3 rounded-[3px] px-2.5 py-2 text-[12px] font-bold outline-none focus:bg-[#E8DFD3]",x&&"bg-[#DDE8FF] text-[#173a76]"),children:[n.jsxs("span",{className:"flex items-center gap-2",children:[n.jsx(u,{className:"h-4 w-4",strokeWidth:1.85}),n.jsx("span",{children:h})]}),x&&n.jsx(Gc,{className:"h-3.5 w-3.5",strokeWidth:2.2})]},d)})})]})}const pQ=[{format:"skp",label:"SketchUp",hint:".skp"},{format:"obj",label:"OBJ",hint:".obj"},{format:"fbx",label:"FBX",hint:".fbx"}];function gQ({onExport:t,busy:e,disabled:s,tr:o,isRTL:r}){const i=o("topBar.downloadModel","הורד מודל תלת-מימד");return n.jsxs(T_,{dir:r?"rtl":"ltr",children:[n.jsxs(Yl,{children:[n.jsx(Gl,{asChild:!0,children:n.jsx(S_,{asChild:!0,disabled:s||e,children:n.jsxs("button",{type:"button","aria-label":i,disabled:s||e,className:O("group flex h-8 w-10 items-center justify-center gap-0.5 rounded-[3px] border border-transparent text-[#182137] transition-colors","hover:border-[#182137]/15 hover:bg-[#E8DFD3]","disabled:opacity-40 disabled:hover:border-transparent disabled:hover:bg-transparent"),children:[e?n.jsx(Xa,{className:"h-[17px] w-[17px] animate-spin",strokeWidth:1.85}):n.jsx(Iy,{className:"h-[17px] w-[17px]",strokeWidth:1.85}),n.jsx(Yc,{className:"h-3 w-3 opacity-70",strokeWidth:2})]})})}),n.jsx(Ul,{side:"bottom",sideOffset:26,className:"border-[#182137]/12 bg-[#F7F4EF] px-2.5 py-1.5 font-heebo text-[11px] font-semibold leading-none text-[#182137] shadow-[0_8px_22px_rgba(24,33,55,0.16)]",children:i})]}),n.jsx(P_,{align:"start",side:"bottom",sideOffset:8,className:"z-[90] min-w-[160px] border-[#182137]/12 bg-[#F7F4EF] p-1 font-heebo text-[#182137] shadow-[0_14px_34px_rgba(24,33,55,0.18)]",children:pQ.map(({format:a,label:l,hint:c})=>n.jsxs(A_,{dir:r?"rtl":"ltr",onSelect:()=>t(a),className:"flex cursor-pointer items-center justify-between gap-3 rounded-[3px] px-2.5 py-2 text-[12px] font-bold outline-none focus:bg-[#E8DFD3]",children:[n.jsxs("span",{className:"flex items-center gap-2",children:[n.jsx(Iy,{className:"h-4 w-4",strokeWidth:1.85}),n.jsx("span",{children:l})]}),n.jsx("span",{className:"text-[11px] font-semibold text-[#182137]/55",children:c})]},a))})]})}function bQ({environmentEnabled:t,onToggleEnvironment:e,timeOfDayMinutes:s,onTimeOfDayChange:o,tr:r,isRTL:i}){const[a,l]=m.useState(!1),c=m.useRef(null),d=m.useRef(null);m.useEffect(()=>{if(!a)return;const x=f=>{var b,M;const p=f.target;p instanceof Node&&((b=c.current)!=null&&b.contains(p)||(M=d.current)!=null&&M.contains(p)||l(!1))};return document.addEventListener("pointerdown",x,!0),()=>document.removeEventListener("pointerdown",x,!0)},[a]);const u=x=>{x&&!t&&e(),l(x)},h=()=>{t&&e(),l(!1)};return n.jsxs(qu,{open:a,onOpenChange:u,children:[n.jsxs(Yl,{children:[n.jsx(Gl,{asChild:!0,children:n.jsx(Qu,{asChild:!0,children:n.jsx("button",{ref:c,type:"button","aria-label":r("topBar.environmentView","סביבת חוץ"),"data-active":t?"":void 0,className:O("group flex h-8 w-8 items-center justify-center rounded-[3px] border border-transparent text-[#182137] transition-colors","hover:border-[#182137]/15 hover:bg-[#E8DFD3]",t&&"border-[#336CFF]/35 bg-[#DDE8FF] text-[#173a76] shadow-[inset_0_0_0_1px_rgba(51,108,255,0.14)]"),children:n.jsx(Dw,{className:"h-[18px] w-[18px]",strokeWidth:1.85})})})}),n.jsx(Ul,{side:"bottom",sideOffset:26,className:"border-[#182137]/12 bg-[#F7F4EF] px-2.5 py-1.5 font-heebo text-[11px] font-semibold leading-none text-[#182137] shadow-[0_8px_22px_rgba(24,33,55,0.16)]",children:r("topBar.environmentView","סביבת חוץ")})]}),n.jsx(Ju,{ref:d,dir:i?"rtl":"ltr",align:"center",side:"bottom",sideOffset:8,className:"z-[90] w-[240px] rounded-md border-[#182137]/12 bg-[#F7F4EF] p-3 font-heebo text-[#182137] shadow-[0_18px_42px_rgba(24,33,55,0.2)]",children:n.jsxs("div",{className:"space-y-2",onPointerDown:x=>x.stopPropagation(),children:[n.jsx(Y7,{timeOfDayMinutes:s,onChange:o}),t&&n.jsx("button",{type:"button",onClick:h,className:"w-full text-center text-[10px] font-bold text-[#182137]/55 transition-colors hover:text-[#D85D43]",children:r("topBar.disableEnvironment","כבה סביבת חוץ")})]})})]})}function MQ({phaseTrace:t,mainView:e,viewScope:s,autoSaveStatus:o,planOrientationBar:r,centerControls:i,saving:a,wallsEmpty:l,showBackgroun
400d:c,showTraceOverlays:d,onSave:u,onHome:h,onExport:x,onExportModel:f,exportsLocked:p=!1,onExportPremiumRequired:b,isExportingModel:M,onNewProject:g,onUndoWall:w,onClearAll:k,onToggleBackground:_,onToggleTraceOverlays:j,projectsPanelOpen:v,onToggleProjectsPanel:C,sectionVisibility:N,sectionOrder:P,onSectionVisibilityChange:L,onShowDetailsPanel:A,cameraPreset:W,onSetCameraPreset:S,roomLabel:B,environmentEnabled:R,onToggleEnvironment:z,timeOfDayMinutes:X,onTimeOfDayChange:ft,simulateOpenings:tt,onToggleSimulateOpenings:G,activeFloorplanSketchTool:Y,onSetFloorplanSketchTool:J,showFullFloorplanSketchToolbar:Mt,floorplanSketchAxesVisible:Rt,onToggleFloorplanSketchAxes:it,renderModeControl:st,onOpenWalkthroughRecorder:ct,onStopWalkthroughRecording:pt,walkthroughRecorderActive:xt,viewportNotes:_t=[],onViewportNoteShow:Ft,onViewportNoteFocus:Vt,hiddenWallCount:vt=0,onShowHiddenWalls:Ht,renderGalleryDropdown:Tt,canUndo:Zt=!1,canRedo:At=!1,onHistoryUndo:ut,onHistoryRedo:kt,onSetMainView:Et,traceRoomLabelListControl:ht,floorSelectorControl:gt}){const{t:Pt}=yn(),{isRTL:U}=Yd(),mt=(Ge,Qt,te)=>Pt(Ge,{defaultValue:Qt,...te});if(!t)return null;const Nt=mQ(mt),Lt=Mt?Nt:[],oe=Nt.find(({tool:Ge})=>Ge==="measure"),he=e==="3d"&&vt>0&&!!Ht&&(W==="inside"||W==="orbit"),pe=n.jsxs(n.Fragment,{children:[Et&&n.jsx(y6,{label:"2D",onClick:()=>Et("2d"),tooltip:xt?mt("topBar.finishRecordingBefore2d","סיים את ההקלטה לפני המעבר ל־2D"):mt("topBar.switchTo2d","מעבר למצב דו מימד")}),n.jsx($r,{icon:wI,label:mt("topBar.isometric","איסומטרי"),onClick:()=>S("orbit"),active:W==="orbit"}),n.jsx($r,{icon:A3,label:mt("topBar.topView","מבט-על"),onClick:()=>S("top"),active:W==="top"}),n.jsx($r,{icon:w6,label:mt("topBar.insideHome","מתוך הבית"),onClick:()=>S("inside"),active:W==="inside",iconClassName:"h-[20px] w-[20px] text-[#0a0f18]"}),ct&&n.jsxs(n.Fragment,{children:[n.jsx(dQ,{onClick:Ge=>ct(Ge.currentTarget.getBoundingClientRect()),label:mt("topBar.recordVideo","הקלטת וידאו")}),xt&&pt&&n.jsx(uQ,{onClick:pt,ariaLabel:mt("topBar.activeRecordingAria","הקלטה פעילה — עצור ושמור את הסיור"),tooltip:mt("topBar.recordingNow","מקליט עכשיו · לחץ לעצירה ושמירה")})]})]});return n.jsx(N_,{delayDuration:200,skipDelayDuration:120,disableHoverableContent:!0,children:n.jsxs("div",{dir:U?"rtl":"ltr",role:"toolbar","aria-label":mt("topBar.toolbar","סרגל עליון"),className:O("relative flex shrink-0 items-center gap-2 border-b border-[#182137]/10 bg-[#F4F1EA] px-2",Mt?"h-12":"h-10",U&&"font-heebo"),children:[e==="2d"&&ht&&n.jsx("div",{className:"absolute left-[28px] top-1/2 z-[35] flex -translate-y-1/2 items-center rounded-[5px] border border-[#182137]/12 bg-[#F4F1EA] px-0.5 shadow-[0_2px_8px_rgba(24,33,55,0.08)]","aria-label":mt("topBar.areas","אזורים"),children:ht}),i&&n.jsx("div",{className:"pointer-events-none absolute left-[calc(50%_-_20px)] top-1/2 z-40 -translate-x-1/2 -translate-y-1/2",children:n.jsx("div",{className:"fp-topbar-center-controls",children:i})}),e==="3d"&&!Mt&&n.jsx("div",{className:"pointer-events-none absolute left-[calc(50%_-_55px)] top-1/2 z-40 -translate-x-1/2 -translate-y-1/2",children:n.jsx("div",{className:"fp-topbar-center-controls flex h-8 items-center gap-2",children:n.jsx("div",{className:"flex items-center gap-2",children:pe})})}),n.jsx("button",{type:"button",onClick:h,"aria-label":mt("topBar.backToDashboard","חזרה לדשבורד"),className:"relative z-[35] shrink-0 rounded-sm outline-none transition-opacity hover:opacity-85 focus-visible:ring-2 focus-visible:ring-[#336CFF]/60 focus-visible:ring-offset-2 focus-visible:ring-offset-[#F4F1EA]",children:n.jsx("img",{src:kN,alt:"Boardspace",className:O("w-auto object-contain",Mt?"h-[30px]":"h-[36px]")})}),n.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1 overflow-x-auto",children:[n.jsxs(ic,{label:mt("topBar.navigation","ניווט"),children:[n.jsx($r,{icon:$u,label:mt("topBar.backToDashboard","חזרה לדשבורד"),onClick:h}),n.jsx($r,{icon:Lw,label:mt("topBar.myProjects","התוכניות שלי"),onClick:C,active:v}),n.jsx(M6,{mainView:e,viewScope:s,sectionVisibility:N,sectionOrder:P,onSectionVisibilityChange:L,onShowPanel:A,triggerTooltip:mt("topBar.properties","מאפיינים"),children:n.jsx("button",{type:"button","aria-label":mt("topBar.properties","מאפיינים"),"data-testid":"floorplan-topbar-section-visibility-trigger",className:O("group flex h-8 w-8 items-center justify-center rounded-[3px] border border-transparent text-[#182137] transition-colors","hover:border-[#182137]/15 hover:bg-[#
400E8DFD3]"),children:n.jsx(oE,{className:"h-[18px] w-[18px]",strokeWidth:1.85})})})]}),gt&&n.jsx("div",{className:"flex shrink-0 items-center","data-testid":"floorplan-floor-selector",children:gt}),e==="2d"?n.jsxs("div",{className:"flex h-8 shrink-0 items-center gap-0 rounded-[6px] border border-[#182137]/12 bg-[#E8DFD3]/70 px-0.5 shadow-[inset_0_1px_0_rgba(255,255,255,0.55)]","aria-label":mt("topBar.file","קובץ"),"data-testid":"floorplan-2d-file-edit-tray",children:[n.jsx($r,{icon:Ny,label:mt("topBar.save","שמירה"),onClick:u}),n.jsx($r,{icon:Jk,label:mt("topBar.newProject","פרויקט חדש"),onClick:g}),n.jsx($r,{icon:gi,label:mt("topBar.clearAll","ניקוי הכל"),onClick:k,disabled:l}),n.jsx($r,{icon:c?fc:Hd,label:c?mt("topBar.hideBackgroundPlan","הסתר תוכנית רקע"):mt("topBar.showBackgroundPlan","הצג תוכנית רקע"),onClick:_,active:!c}),n.jsx($r,{icon:op,label:d?mt("topBar.hideWallLines","הסתר קווים קירות"):mt("topBar.showWallLines","הצג קווים קירות"),onClick:j,active:!d})]}):n.jsxs(ic,{label:mt("topBar.file","קובץ"),children:[n.jsx($r,{icon:Ny,label:mt("topBar.save","שמירה"),onClick:u}),n.jsx($r,{icon:Jk,label:mt("topBar.newProject","פרויקט חדש"),onClick:g}),n.jsx($r,{icon:xp,label:mt("topBar.downloadImage","הורד תמונה"),onClick:x}),f&&(p?n.jsx($r,{icon:Iy,label:mt("topBar.downloadModel","הורד מודל תלת-מימד"),onClick:()=>b==null?void 0:b()}):n.jsx(gQ,{onExport:f,busy:M,disabled:l,tr:mt,isRTL:U}))]}),e==="3d"&&n.jsxs(ic,{label:mt("topBar.view","תצוגה"),children:[Mt&&n.jsx($r,{icon:kI,label:mt("topBar.axes","צירים"),onClick:it,active:Rt}),n.jsx(bQ,{environmentEnabled:R,onToggleEnvironment:z,timeOfDayMinutes:X,onTimeOfDayChange:ft,tr:mt,isRTL:U}),!Mt&&oe&&n.jsx($r,{icon:oe.icon,label:oe.label,onClick:()=>J(Y==="measure"?"select":"measure"),active:Y==="measure"}),n.jsx($r,{icon:Cf,label:mt("topBar.simulateOpenings","מצב הדמיה — פתיחת דלתות וחלונות"),onClick:G,active:tt})]}),e==="3d"&&Lt.length>0&&n.jsxs(ic,{label:mt("topBar.sketchTools","כלי סקיצה"),children:[Lt.map(({tool:Ge,icon:Qt,label:te})=>n.jsx($r,{icon:Qt,label:te,onClick:()=>J(Y===Ge?"select":Ge),active:Y===Ge},Ge)),Mt&&n.jsx(xQ,{activeTool:Y,onSetTool:J,tr:mt,isRTL:U})]}),r&&e!=="3d"&&n.jsx(ic,{label:mt("topBar.planOrientation","כיוון תוכנית"),children:n.jsx("div",{dir:U?"rtl":"ltr",className:"flex items-center gap-1",children:r})}),e==="3d"&&n.jsxs("div",{className:"ms-auto me-3 flex h-9 items-center gap-[30px]",children:[Mt&&n.jsx(ic,{label:mt("topBar.viewMode","מצב תצוגה"),children:n.jsx("div",{className:"flex -translate-x-5 items-center gap-2",children:pe})}),r&&n.jsx(ic,{label:mt("topBar.planOrientation","כיוון תוכנית"),children:n.jsx("div",{dir:U?"rtl":"ltr",className:"flex items-center gap-1",children:r})}),he&&n.jsx(ic,{label:mt("topBar.hiddenWalls","קירות מוסתרים"),children:n.jsxs(Yl,{children:[n.jsx(Gl,{asChild:!0,children:n.jsxs("button",{type:"button",onClick:Ht,"aria-label":mt("topBar.showHiddenWalls","הצג קירות מוסתרים ({{count}})",{count:vt}),className:O("inline-flex h-8 items-center gap-1.5 rounded-[3px] border border-[#182137]/12 bg-[#F7F4EF]/90 px-2.5 text-[#182137] transition-colors","hover:border-[#182137]/20 hover:bg-[#E8DFD3]","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#336CFF]/55 focus-visible:ring-offset-1 focus-visible:ring-offset-[#F4F1EA]"),children:[n.jsx(Hd,{className:"h-[15px] w-[15px]",strokeWidth:1.9}),n.jsx("span",{className:"whitespace-nowrap text-[11px] font-black leading-none",children:mt("topBar.showHiddenWalls","הצג קירות מוסתרים ({{count}})",{count:vt})})]})}),n.jsx(Ul,{side:"bottom",sideOffset:26,className:"border-[#182137]/12 bg-[#F7F4EF] px-2.5 py-1.5 font-heebo text-[11px] font-semibold leading-none text-[#182137] shadow-[0_8px_22px_rgba(24,33,55,0.16)]",children:mt("topBar.showAllWalls","הצג שוב את כל הקירות")})]})}),W==="inside"&&ut&&kt&&n.jsxs(ic,{label:mt("topBar.history","היסטוריה"),children:[n.jsx($r,{icon:tE,label:mt("topBar.undo","בטל (⌘Z)"),onClick:()=>ut(),disabled:!Zt}),n.jsx($r,{icon:eE,label:mt("topBar.redo","חזור (⌘⇧Z)"),onClick:()=>
400kt(),disabled:!At})]}),n.jsx(ic,{label:mt("topBar.notes.title","פתקים"),children:n.jsx(hQ,{notes:_t,onShow:Ft,onFocus:Vt,tr:mt,isRTL:U})}),n.jsx(ic,{label:mt("topBar.sound.title","צלילים"),children:n.jsx(cQ,{tr:mt})}),(st||Tt)&&n.jsxs("div",{className:"flex h-9 items-center gap-1 rounded-[9px] border border-[#D85D43]/18 bg-[#F7F4EF]/72 p-0.5 shadow-[inset_0_1px_0_rgba(255,248,242,0.82),0_6px_16px_rgba(24,33,55,0.10)]",children:[st,Tt]})]}),(o==="saving"||o==="error")&&n.jsx("div",{className:O("flex h-7 items-center gap-1 rounded-md px-2 text-[10px] font-semibold",o==="saving"?"text-[#336CFF]":"text-red-600"),"aria-live":"polite",children:o==="saving"?n.jsxs(n.Fragment,{children:[n.jsx(Xa,{className:"h-3 w-3 animate-spin"}),n.jsx("span",{children:mt("topBar.saving","שומר")})]}):n.jsxs(n.Fragment,{children:[n.jsx(Gr,{size:12}),n.jsx("span",{children:mt("topBar.saveFailed","שמירה נכשלה")})]})})]})]})})}function yQ({levels:t,activeLevelId:e,viewScope:s,onViewScopeChange:o,onSwitchLevel:r,onAddLevelWithUpload:i,onAddLevelDuplicate:a,onRenameLevel:l,onDeleteLevel:c,onToggleLevelVisible:d,onStartAlign:u,canShowUnderlay:h,showUnderlay:x,onToggleUnderlay:f}){const{t:p}=yn(),[b,M]=m.useState(!1),[g,w]=m.useState(null),[k,_]=m.useState(""),j=m.useRef(null),v=t.find(P=>P.id===e)??t[0],C=[...t].reverse(),N=()=>{g&&l(g,k),w(null)};return n.jsxs(qu,{open:b,onOpenChange:M,children:[n.jsx(Qu,{asChild:!0,children:n.jsxs("button",{type:"button","aria-label":p("levels.selectorAria",{defaultValue:"בורר קומות"}),className:O("flex h-10 items-center gap-1.5 rounded-[9px] border border-[#182137]/12 bg-[#F7F4EF] px-3","font-heebo text-[12.5px] font-bold text-[#182137] shadow-[0_2px_8px_rgba(24,33,55,0.08)]","transition-[transform,background-color,border-color,box-shadow] duration-150 hover:-translate-y-px hover:bg-[#E8E3DB]","active:translate-y-[1px] active:shadow-[inset_0_1px_2px_rgba(24,33,55,0.1)]","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#D85D43]/45",b&&"border-[#D85D43]/45 bg-[#E8E3DB]"),children:[s==="building"?n.jsx(Vk,{className:"h-[15px] w-[15px]",strokeWidth:2}):n.jsx(k1,{className:"h-[15px] w-[15px]",strokeWidth:2}),n.jsx("span",{className:"max-w-[160px] truncate",children:s==="building"?p("levels.buildingScope",{defaultValue:"כל הבניין"}):(v==null?void 0:v.name)??""}),t.length>1&&n.jsx("span",{className:"rounded-full bg-[#182137]/8 px-1.5 text-[10.5px] font-black tabular-nums",children:t.length}),n.jsx(Yc,{className:O("h-3.5 w-3.5 opacity-60 transition-transform",b&&"rotate-180"),strokeWidth:2.4})]})}),n.jsxs(Ju,{dir:"rtl",align:"start",sideOffset:8,className:"w-[318px] rounded-2xl border-[#182137]/12 bg-[#F7F4EF] p-2.5 font-heebo shadow-[0_12px_38px_rgba(24,33,55,0.18)]",children:[n.jsx("div",{className:"mb-2 px-1.5 pt-0.5 text-[11px] font-black tracking-wide text-[#182137]/55",children:p("levels.title",{defaultValue:"קומות הבניין"})}),n.jsxs("div",{role:"group","aria-label":p("levels.viewScopeAria",{defaultValue:"מצב תצוגת קומות"}),className:"mb-2 grid grid-cols-2 gap-1 rounded-xl border border-[#182137]/10 bg-[#E8E3DB]/75 p-1 shadow-inner",children:[n.jsxs("button",{type:"button","aria-pressed":s==="building",onClick:()=>o("building"),className:O("flex min-h-10 items-center justify-center gap-1.5 rounded-lg px-2 text-[11.5px] font-black","transition-[transform,background-color,color,box-shadow] duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#D85D43]/45",s==="building"?"bg-[#D85D43] text-[#F7F4EF] shadow-[0_3px_0_#A84430,0_5px_10px_rgba(24,33,55,0.14)] active:translate-y-[2px] active:shadow-[0_1px_0_#A84430]":"text-[#182137]/72 hover:bg-[#F7F4EF]/80"),children:[n.jsx(Vk,{className:"h-3.5 w-3.5",strokeWidth:2.2}),p("levels.buildingScope",{defaultValue:"כל הבניין"})]}),n.jsxs("button",{type:"button","aria-pressed":s==="floor",onClick:()=>o("floor"),className:O("flex min-h-10 items-center justify-center gap-1.5 rounded-lg px-2 text-[11.5px] font-black","transition-[transform,background-color,color,box-shadow] duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#D85D43]/45",s==="floor"?"bg-[#D85D43] text-[#F7F4EF] shadow-[0_3px_0_#A84430,0_5px_10px_rgba(24,33,55,0.14)] active:translate-y-[2px] active:shadow-[0_1px_0_#A84430]":"text-[#182137]/72 hover:bg-[#F7F4EF]/80"),children:[n.jsx(k1,{className:"h-3.5 w-3.5",
400strokeWidth:2.2}),p("levels.floorScope",{defaultValue:"עבודה על קומה"})]})]}),n.jsx("div",{className:"flex max-h-[300px] flex-col gap-0.5 overflow-y-auto",children:C.map(P=>{const L=P.id===e,A=g===P.id,W=P.alignmentStatus==="pending";return n.jsxs("div",{className:O("group flex min-h-11 items-center gap-1 rounded-xl border border-transparent px-1.5 py-1.5 transition-colors",L?"border-[#D85D43]/30 bg-[#D85D43]/8":"hover:bg-[#182137]/5"),children:[n.jsx("button",{type:"button",disabled:L,"aria-label":L?p("levels.activeFloorAlwaysVisible",{defaultValue:"הקומה הפעילה תמיד מוצגת"}):P.visible?p("levels.hideFloor",{defaultValue:"הסתר בתלת-ממד"}):p("levels.showFloor",{defaultValue:"הצג בתלת-ממד"}),title:L?p("levels.activeFloorAlwaysVisible",{defaultValue:"הקומה הפעילה תמיד מוצגת"}):void 0,onClick:S=>{S.stopPropagation(),d(P.id,!P.visible)},className:O("flex h-8 w-8 shrink-0 items-center justify-center rounded-lg text-[#182137]/55","transition-[transform,background-color,color] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#D85D43]/45",L?"cursor-not-allowed bg-[#D85D43]/10 text-[#D85D43]/70":"hover:bg-[#182137]/8 hover:text-[#182137] active:translate-y-px"),children:L||P.visible?n.jsx(Hd,{className:"h-[15px] w-[15px]"}):n.jsx(fc,{className:"h-[15px] w-[15px] text-[#182137]/30"})}),A?n.jsx("input",{autoFocus:!0,dir:"rtl",value:k,onChange:S=>_(S.target.value),onBlur:N,onKeyDown:S=>{S.key==="Enter"&&N(),S.key==="Escape"&&w(null)},className:"min-w-0 flex-1 rounded-md border border-[#D85D43]/45 bg-[#FEFCF8] px-1.5 py-1 text-[12.5px] font-bold text-[#182137] outline-none focus:ring-2 focus:ring-[#D85D43]/20"}):n.jsxs("button",{type:"button",onClick:()=>{r(P.id),M(!1)},onDoubleClick:S=>{S.stopPropagation(),w(P.id),_(P.name)},className:"flex min-w-0 flex-1 flex-wrap items-center gap-1.5 rounded-md py-1 text-start focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#D85D43]/35",title:p("levels.rowHint",{defaultValue:"לחיצה — מעבר · לחיצה כפולה — שינוי שם"}),children:[n.jsx("span",{className:O("h-1.5 w-1.5 shrink-0 rounded-full",L?"bg-[#D85D43]":"bg-[#182137]/15")}),n.jsx("span",{className:O("min-w-0 truncate text-[12.5px] font-bold",L?"text-[#8F3C29]":"text-[#182137]",!P.visible&&"opacity-45"),children:P.name}),L&&n.jsx("span",{className:"shrink-0 rounded-full bg-[#D85D43] px-1.5 py-0.5 text-[9.5px] font-black leading-none text-[#F7F4EF]",children:p("levels.editingBadge",{defaultValue:"בעריכה"})}),W&&n.jsx("span",{className:"shrink-0 rounded-full border border-[#D85D43]/25 bg-[#D85D43]/10 px-1.5 py-0.5 text-[9.5px] font-black leading-none text-[#9B412D]",children:p("levels.pendingAlignmentBadge",{defaultValue:"טרם יושרה"})})]}),t.length>1&&!A&&n.jsx("button",{type:"button","aria-label":p("levels.deleteFloor",{defaultValue:"מחיקת קומה"}),onClick:S=>{S.stopPropagation(),confirm(p("levels.deleteConfirm",{name:P.name,defaultValue:`למחוק את "${P.name}"? כל הקירות והריהוט שלה יימחקו.`}))&&c(P.id)},className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg text-[#182137]/0 transition-colors hover:bg-[#D84B2E]/10 hover:text-[#D84B2E] focus-visible:text-[#D84B2E] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#D84B2E]/35 group-hover:text-[#182137]/40",children:n.jsx(gi,{className:"h-[13px] w-[13px]"})})]},P.id)})}),h&&n.jsxs("div",{className:"mt-2 border-t border-[#182137]/10 pt-2",children:[n.jsx("div",{className:"mb-1 px-1.5 text-[10.5px] font-black text-[#182137]/50",children:p("levels.referenceFloorTitle",{defaultValue:"קומת ייחוס ב־2D"})}),n.jsxs("div",{className:"grid grid-cols-2 gap-1.5",children:[n.jsxs("button",{type:"button","aria-pressed":x,onClick:f,className:O("flex min-h-11 items-center justify-center gap-1.5 rounded-lg border px-2","text-[11px] font-bold text-[#182137] transition-[transform,background-color,box-shadow] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#D85D43]/45","active:translate-y-[1px]",x?"border-[#D85D43]/35 bg-[#D85D43]/10 shadow-inner":"border-[#182137]/12 bg-[#FEFCF8] shadow-[0_2px_0_rgba(24,33,55,0.12)] hover:bg-[#
400E8E3DB]"),children:[x?n.jsx(fc,{className:"h-3.5 w-3.5"}):n.jsx(Hd,{className:"h-3.5 w-3.5"}),x?p("levels.hideLowerFloor",{defaultValue:"הסתר קומה מתחת"}):p("levels.showLowerFloor",{defaultValue:"הצג קומה מתחת"})]}),u&&n.jsxs("button",{type:"button",onClick:()=>{u(),M(!1)},className:O("flex min-h-11 items-center justify-center gap-1.5 rounded-lg border border-[#182137]/12 bg-[#FEFCF8] px-2","text-[11px] font-bold text-[#182137] shadow-[0_2px_0_rgba(24,33,55,0.12)]","transition-[transform,background-color,box-shadow] hover:bg-[#E8E3DB] active:translate-y-[1px] active:shadow-inner","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#D85D43]/45"),children:[n.jsx(JI,{className:"h-3.5 w-3.5"}),p("levels.alignToLowerFloor",{defaultValue:"יישור מול קומה מתחת"})]})]})]}),n.jsxs("div",{className:"mt-2 border-t border-[#182137]/10 pt-2",children:[n.jsxs("div",{className:"mb-1 flex items-center gap-1 px-1.5 text-[11px] font-black text-[#182137]/55",children:[n.jsx(pm,{className:"h-3 w-3",strokeWidth:2.6}),p("levels.addFloor",{defaultValue:"הוספת קומה"})]}),n.jsxs("div",{className:"flex gap-1.5",children:[n.jsxs("button",{type:"button",onClick:()=>{a(),M(!1)},className:O("flex min-h-11 flex-1 items-center justify-center gap-1.5 rounded-lg border border-[#182137]/12 bg-[#FEFCF8] px-2","text-[11.5px] font-bold text-[#182137] shadow-[0_2px_0_rgba(24,33,55,0.12)]","transition-[transform,background-color,box-shadow] hover:bg-[#E8E3DB] active:translate-y-[1px] active:shadow-inner","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#D85D43]/45"),children:[n.jsx(Pf,{className:"h-[13px] w-[13px]"}),p("levels.duplicateCurrent",{defaultValue:"שכפול הקומה"})]}),n.jsxs("button",{type:"button",onClick:()=>{var P;return(P=j.current)==null?void 0:P.click()},className:O("flex min-h-11 flex-1 items-center justify-center gap-1.5 rounded-lg border border-[#182137]/12 bg-[#FEFCF8] px-2","text-[11.5px] font-bold text-[#182137] shadow-[0_2px_0_rgba(24,33,55,0.12)]","transition-[transform,background-color,box-shadow] hover:bg-[#E8E3DB] active:translate-y-[1px] active:shadow-inner","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#D85D43]/45"),children:[n.jsx(Ap,{className:"h-[13px] w-[13px]"}),p("levels.uploadPlan",{defaultValue:"העלאת תוכנית"})]})]}),n.jsx("input",{ref:j,type:"file",accept:".svg,.png,.jpg,.jpeg,.webp",className:"hidden",onChange:P=>{var A;const L=(A=P.target.files)==null?void 0:A[0];P.target.value="",L&&(i(L),M(!1))}})]})]})]})}function i_({label:t,onClick:e,disabled:s,tooltipSide:o,children:r}){return n.jsxs(Yl,{children:[n.jsx(Gl,{asChild:!0,children:n.jsx("button",{type:"button",onClick:e,disabled:s,"aria-label":t,className:O("fp-preset-bar__btn fp-preset-bar__btn--icon",s&&"opacity-35 cursor-not-allowed"),children:r})}),n.jsx(Ul,{side:o,sideOffset:8,className:"border-[#182137]/12 bg-[#F7F4EF] px-2.5 py-1.5 font-heebo text-[11px] font-semibold leading-none text-[#182137] shadow-[0_8px_22px_rgba(24,33,55,0.16)]",children:t})]})}function wQ({canUndo:t,canRedo:e,onUndo:s,onRedo:o,placement:r="floating"}){const i=r==="floatingTopLeft"?"bottom":"top";return n.jsx(N_,{delayDuration:200,skipDelayDuration:120,disableHoverableContent:!0,children:n.jsxs("div",{role:"toolbar","aria-label":"היסטוריה","data-testid":"floorplan-history-bar",className:O("fp-preset-bar fp-preset-bar--history",r==="floating"&&"absolute bottom-3 left-1/2 z-20 -translate-x-1/2",r==="floatingBottomLeft"&&"absolute bottom-3 left-3 z-20",r==="floatingTopLeft"&&"absolute left-3 top-3 z-30",r==="footer"&&"relative"),children:[n.jsx(i_,{label:"בטל (⌘Z)",onClick:s,disabled:!t,tooltipSide:i,children:n.jsx(tE,{className:"h-[15px] w-[15px] shrink-0",strokeWidth:1.85})}),n.jsx(i_,{label:"חזור (⌘⇧Z)",onClick:o,disabled:!e,tooltipSide:i,children:n.jsx(eE,{className:"h-[15px] w-[15px] shrink-0",strokeWidth:1.85})})]})})}function kQ({items:t,labels:e,onLabelsChange:s,roomIds:o,open:r,onOpenChange:i,onBeginEdit:a}){const{t:l}=yn(),c=Yp(e)||t.some(x=>x.hidden),d=m.useCallback((x,f)=>{s(I7(e,x,f))},[e,s]),u=m.useCallback(()=>{s(S7(e,o))},[e,s,o]),h=m.useCallback(()=>{s(T7(e,o))},[e,s,o]);return t.length===0?null:n.jsxs(qu,{open:r,onOpenChange:i,children:[n.jsxs(Yl,{children:[n.jsx(Gl,{asChild:!0,children:n.jsx(Qu,{asChild:!0,children:n.jsx("button",{type:"button","aria-label":l("roomLabels.list",{defaultValue:"רשימת אזורים"}),"data-active":r?"":void 0,className:O("flex h-8 w-8 items-center justify-center rounded-[3px] border border-transparent text-[#182137] transition-colors","hover:border-[#182137]/15 hover:bg-[#
400E8DFD3]",r&&"border-[#336CFF]/35 bg-[#DDE8FF] text-[#173a76] shadow-[inset_0_0_0_1px_rgba(51,108,255,0.14)]"),children:n.jsx(hT,{className:"h-[18px] w-[18px]",strokeWidth:1.85})})})}),n.jsx(Ul,{side:"bottom",sideOffset:26,className:"border-[#182137]/12 bg-[#F7F4EF] px-2.5 py-1.5 font-heebo text-[11px] font-semibold leading-none text-[#182137] shadow-[0_8px_22px_rgba(24,33,55,0.16)]",children:l("roomLabels.list",{defaultValue:"רשימת אזורים"})})]}),n.jsxs(Ju,{align:"start",side:"bottom",sideOffset:8,dir:"rtl",className:"w-[270px] overflow-hidden rounded-xl border border-[#D85D43]/25 !bg-[#F4F1EA]/[0.98] p-0 font-heebo text-[#182137] shadow-[0_16px_44px_rgba(24,33,55,0.22)] backdrop-blur-md backdrop-saturate-150",onOpenAutoFocus:x=>x.preventDefault(),children:[n.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[#182137]/10 px-3 py-2.5",children:[n.jsx("button",{type:"button",title:l("common.close",{defaultValue:"סגור"}),"aria-label":l("common.close",{defaultValue:"סגור"}),onClick:()=>i(!1),className:"flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center rounded-lg text-[#182137]/48 transition-colors hover:bg-[#182137]/[0.06] hover:text-[#182137]",children:n.jsx(Gr,{size:15,strokeWidth:2.2})}),c?n.jsxs("button",{type:"button",onClick:u,className:"flex h-7 shrink-0 cursor-pointer items-center gap-1.5 rounded-lg border border-[#D85D43]/25 bg-[#FCE8E4] px-2 text-[10px] font-black text-[#9a3d28] transition-colors hover:bg-[#F7D7D0]",children:[n.jsx(Hd,{size:13,strokeWidth:2.1}),l("roomLabels.restoreAll",{defaultValue:"החזר הכל"})]}):n.jsxs("button",{type:"button",onClick:h,className:"flex h-7 shrink-0 cursor-pointer items-center gap-1.5 rounded-lg border border-[#182137]/10 bg-[#E8E3DB]/70 px-2 text-[10px] font-black text-[#182137]/62 transition-colors hover:bg-[#182137]/[0.06]",children:[n.jsx(fc,{size:13,strokeWidth:2.1}),l("roomLabels.hideAll",{defaultValue:"הסתר הכל"})]}),n.jsxs("div",{className:"min-w-0 text-right",children:[n.jsx("div",{className:"truncate text-[12px] font-black text-[#182137]",children:l("roomLabels.title",{defaultValue:"אזורים ומידות"})}),n.jsx("div",{className:"truncate text-[10px] font-semibold text-[#9a3d28]/72",children:l("roomLabels.description",{defaultValue:"נתוני החדרים גם כשהמידות מוסתרות"})})]})]}),n.jsx("div",{className:"max-h-[260px] overflow-y-auto py-1",children:t.map(x=>n.jsxs("div",{className:"flex items-center gap-2 border-b border-[#182137]/[0.06] px-3 py-2 last:border-b-0",children:[n.jsx("button",{type:"button",title:x.hidden?l("roomLabels.showDimensions",{defaultValue:"הצג מידות"}):l("roomLabels.hideDimensions",{defaultValue:"הסתר מידות"}),"aria-label":x.hidden?l("roomLabels.showDimensions",{defaultValue:"הצג מידות"}):l("roomLabels.hideDimensions",{defaultValue:"הסתר מידות"}),onClick:()=>d(x.id,{hidden:!x.hidden}),className:O("flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center rounded-lg border transition-colors",x.hidden?"border-[#D85D43]/30 bg-[#FCE8E4] text-[#D85D43] hover:bg-[#F7D7D0]":"border-[#182137]/10 bg-[#E8E3DB]/70 text-[#182137]/52"),children:x.hidden?n.jsx(Hd,{size:14,strokeWidth:2.1}):n.jsx(fc,{size:14,strokeWidth:2.1})}),n.jsx("button",{type:"button",title:l("roomLabels.rename",{defaultValue:"שנה שם"}),"aria-label":l("roomLabels.rename",{defaultValue:"שנה שם"}),onClick:()=>a(x.id),className:"flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center rounded-lg border border-[#182137]/10 bg-[#FDFBF8]/80 text-[#182137]/62 transition-colors hover:border-[#D85D43]/28 hover:bg-[#FCE8E4] hover:text-[#D85D43]",children:n.jsx(mp,{size:13,strokeWidth:2.1})}),n.jsxs("button",{type:"button",title:l("roomLabels.renameArea",{defaultValue:"שנה שם אזור"}),"aria-label":l("roomLabels.renameArea",{defaultValue:"שנה שם אזור"}),onClick:()=>a(x.id),className:"min-w-0 flex-1 cursor-text rounded-lg bg-transparent px-1 py-0.5 text-right outline-none transition-colors hover:bg-[#182137]/[0.04] focus-visible:ring-2 focus-visible:ring-[#D85D43]/25",children:[n.jsx("span",{className:O("block truncate text-[12px] font-black",x.placeholder?"text-[#182137]/58":"text-[#182137]"),children:x.name}),n.jsx("span",{className:"block text-[11px] font-bold tabular-nums text-[#D85D43]",children:x.areaLabel})]}),n.jsx("span",{className:O("shrink-0 rounded-md px-1.5 py-0.5 text-[9px] font-bold",x.hidden?"bg-[#182137]/10 text-[#182137]/65":"bg-[#D85D43]/12 text-[#9a3d28]"),children:x.hidden?l("roomLabels.hidden",{defaultValue:"מוסתר"}):l("roomLabels.visible",{defaultValue:"מוצג"})})]},x.id))})]})]})}function k6(t){var e;return((e=t.mimeType)==null?void 0:e.startsWith("video/"))===!0||/\.(mp4|webm|mov|m4v)(\?|$)/i.test(t.previewUrl)}function vQ(t){var s,o,r,i;if((s=t.mimeType)!=null&&s.includes("mp4"))return"mp4";if((o=t.mimeType)!=null&&o.includes("webm"))return"webm";if((r=t.mimeType)!=null&&r.includes("jpeg"))return"jpg";if((i=t.mimeType)!=null&&i.includes("png"))return"png";const e=t.storagePath.match(/\.([a-z0-9]+)$/i);return(e==null?void 0:e[1])??(k6(t)?"webm":"png")}function jQ({item:t,onClose:e,onDelete:s}){const{t:o,i18n:r}=yn(),i=m.useCallback(async()=>
400{if(t)try{const c=await(await fetch(t.previewUrl)).blob(),d=URL.createObjectURL(c),u=document.createElement("a");u.href=d,u.download=`${t.name.replace(/\s+/g,"_")}.${vQ(t)}`,u.click(),URL.revokeObjectURL(d)}catch{}},[t]),a=m.useCallback(()=>{t&&window.confirm(o("renderLightbox.deleteConfirm",{name:t.name,defaultValue:`למחוק את "${t.name}"?`}))&&(s(t.id),e())},[t,e,s,o]);return n.jsx(L_,{open:!!t,onOpenChange:l=>{l||e()},children:n.jsxs(W_,{dir:r.dir(),className:"max-w-[92vw] max-h-[92vh] w-auto p-0 overflow-hidden bg-[#F7F4EF] border-[#182137]/15 font-heebo",children:[n.jsx(R_,{className:"sr-only",children:(t==null?void 0:t.name)||o("renderLightbox.preview",{defaultValue:"תצוגה מקדימה"})}),t&&n.jsxs("div",{className:"flex flex-col",children:[n.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5 border-b border-[#182137]/10 bg-[#FDF6F4]",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"font-black text-sm text-[#182137] truncate tracking-[-0.02em]",children:t.name}),n.jsxs("div",{className:"text-[11px] text-[#182137]/55",children:[t.aspectRatio?`${t.aspectRatio} · `:"",new Date(t.createdAt).toLocaleString(r.resolvedLanguage||r.language)]})]}),n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsxs("button",{type:"button",onClick:i,className:"rounded-md px-2.5 py-1.5 bg-white hover:bg-[#EC7357] hover:text-white border border-[#182137]/10 text-[#182137] text-xs font-bold flex items-center gap-1.5 transition-colors",title:o("renderLightbox.downloadTitle",{defaultValue:"הורדה"}),children:[n.jsx(xp,{size:13,strokeWidth:2.2}),o("renderLightbox.download",{defaultValue:"הורד"})]}),n.jsxs("button",{type:"button",onClick:a,className:"rounded-md px-2.5 py-1.5 bg-white hover:bg-red-500 hover:text-white border border-red-300/60 text-red-600 text-xs font-bold flex items-center gap-1.5 transition-colors",title:o("renderLightbox.deleteTitle",{defaultValue:"מחיקה"}),children:[n.jsx(gi,{size:13,strokeWidth:2.2}),o("renderLightbox.delete",{defaultValue:"מחק"})]}),n.jsx("button",{type:"button",onClick:e,className:"rounded-md p-1.5 bg-white hover:bg-[#182137] hover:text-white border border-[#182137]/10 text-[#182137] transition-colors",title:o("renderLightbox.close",{defaultValue:"סגור"}),children:n.jsx(Gr,{size:13,strokeWidth:2.4})})]})]}),n.jsx("div",{className:"bg-[#0f1117] flex items-center justify-center",style:{minHeight:"50vh"},children:k6(t)?n.jsx("video",{src:t.previewUrl,className:"max-w-[92vw] max-h-[78vh]",controls:!0,playsInline:!0,autoPlay:!0}):n.jsx("img",{src:t.previewUrl,alt:t.name,className:"max-w-[92vw] max-h-[78vh] object-contain",draggable:!1})})]})]})})}const a_={faithful:"רנדור נאמן",consistent:"רנדור עקבי",free:"רנדור עם סטייל חופשי"};function v6(t){var e;return((e=t.mimeType)==null?void 0:e.startsWith("video/"))===!0||/\.(mp4|webm|mov|m4v)(\?|$)/i.test(t.previewUrl)}function _Q(t){var s,o,r,i;if((s=t.mimeType)!=null&&s.includes("mp4"))return"mp4";if((o=t.mimeType)!=null&&o.includes("webm"))return"webm";if((r=t.mimeType)!=null&&r.includes("jpeg"))return"jpg";if((i=t.mimeType)!=null&&i.includes("png"))return"png";const e=t.storagePath.match(/\.([a-z0-9]+)$/i);return(e==null?void 0:e[1])??(v6(t)?"webm":"png")}function EQ({bank:t,pendingRenders:e}){var Pt;const{t:s,i18n:o}=yn(),[r,i]=m.useState(!1),[a,l]=m.useState(null),[c,d]=m.useState(!1),[u,h]=m.useState(""),[x,f]=m.useState(null),[p,b]=m.useState(null),[M,g]=m.useState(!1),[w,k]=m.useState(null),[_,j]=m.useState(""),[v,C]=m.useState(null),[N,P]=m.useState(""),L=m.useRef(null),{visibleItems:A,folders:W,currentFolderId:S,setCurrentFolderId:B,loading:R,removeItem:z,renameItem:X,createFolder:ft,renameFolder:tt,deleteFolder:G,moveItemToFolder:Y,items:J}=t,Mt=m.useCallback(()=>{b(null),g(!1)},[]);m.useEffect(()=>{if(!p)return;const U=mt=>{L.current&&!L.current.contains(mt.target)&&Mt()};return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},[p,Mt]);const Rt=m.useMemo(()=>{const U={};return J.forEach(mt=>{mt.folderId&&(U[mt.folderId]=(U[mt.folderId]||0)+1)}),U},[J]),it=S?(Pt=W.find(U=>U.id===S))==null?void 0:Pt.name:null,st=e.length,ct=J.length+st,pt=m.useCallback(async()=>{const U=u.trim();U&&(await ft(U),h(""),d(!1))},[ft,u]),xt=m.useCallback(async U=>{try{const Nt=await(await fetch(U.previewUrl)).blob(),Lt=URL.createObjectURL(Nt),oe=document.createElement("a");oe.href=Lt,oe.download=`${U.name.replace(/\s+/g,"_")}.${_Q(U)}`,oe.click(),URL.revokeObjectURL(Lt)}catch{}},[]),_t=m.useCallback(U=>{window.confirm(s("renderGallery.deleteItemConfirm",{name:U.name,defaultValue:`למחוק את "${U.name}"?`}))&&z(U.id)},[z,s]),Ft=m.useCallback((U,mt)=>{window.confirm(s("renderGallery.deleteFolderConfirm",{name:mt,defaultValue:`למחוק את התיקייה "${mt}"? התמונות יעברו לרוט.`}))&&G(U)},[G,s]),Vt=m.useCallback((U,mt)=>{U.preventDefault(),U.stopPropagation();const{x:Nt,y:Lt}=t5(U.clientX,U.clientY,"item");g(!1),b({x:Nt,y:Lt,imageId:mt})},[]),vt=m.useCallback((U,mt)=>{U.preventDefault(),U.stopPropagation();const{x:Nt,y:Lt}=t5(U.clientX,U.clientY,"folder");g(!1),b({x:Nt,y:Lt,folderId:mt})},[]),Ht=m.useCallback(U=>{k(U.id),j(U.name),Mt()},[Mt]),Tt=m.useCallback(()=>
400{if(!w)return;const U=_.trim();if(U){const mt=J.find(Nt=>Nt.id===w);(!mt||mt.name!==U)&&X(w,U)}k(null),j("")},[w,_,J,X]),Zt=m.useCallback(()=>{k(null),j("")},[]),At=m.useCallback((U,mt)=>{C(U),P(mt),Mt()},[Mt]),ut=m.useCallback(()=>{if(!v)return;const U=N.trim();if(U){const mt=W.find(Nt=>Nt.id===v);(!mt||mt.name!==U)&&tt(v,U)}C(null),P("")},[v,N,W,tt]),kt=m.useCallback(()=>{C(null),P("")},[]),Et=(U,mt)=>{U.dataTransfer.setData("floorplan-render-id",mt),U.dataTransfer.effectAllowed="move"},ht=(U,mt)=>{U.preventDefault(),U.dataTransfer.dropEffect="move",f(mt)},gt=(U,mt)=>{U.preventDefault();const Nt=U.dataTransfer.getData("floorplan-render-id");Nt&&Y(Nt,mt),f(null)};return n.jsxs(n.Fragment,{children:[n.jsxs(qu,{open:r,onOpenChange:i,children:[n.jsx(Qu,{asChild:!0,children:n.jsxs("button",{type:"button","aria-label":st>0?s(st===1?"renderGallery.myGalleryWithPendingOne":"renderGallery.myGalleryWithPendingOther",{count:st,defaultValue:`הגלריה שלי, ${st} רנדורים בעבודה`}):s("renderGallery.myGallery",{defaultValue:"הגלריה שלי"}),title:st>0?s(st===1?"renderGallery.pendingRendersOne":"renderGallery.pendingRendersOther",{count:st,defaultValue:`${st} רנדורים בעבודה`}):s("renderGallery.myGallery",{defaultValue:"הגלריה שלי"}),className:"relative inline-flex h-8 w-8 items-center justify-center rounded-[7px] border border-[#D8D0C5]/70 bg-[linear-gradient(145deg,#FFF8F2_0%,#E7F2E8_48%,#DED8F2_100%)] text-[#182137] shadow-[inset_0_1px_0_rgba(255,248,242,0.86),inset_0_-2px_0_rgba(24,33,55,0.08),0_4px_9px_rgba(24,33,55,0.12)] transition-all duration-150 hover:-translate-y-0.5 hover:border-[#D85D43]/45 hover:text-[#9A3D28] hover:shadow-[inset_0_1px_0_rgba(255,248,242,0.9),inset_0_-2px_0_rgba(24,33,55,0.07),0_7px_14px_rgba(24,33,55,0.16)] active:translate-y-[1px] active:shadow-[inset_0_2px_4px_rgba(24,33,55,0.13),0_2px_5px_rgba(24,33,55,0.10)]",children:[st>0?n.jsx(Xa,{size:17,strokeWidth:2.2,className:"animate-spin text-[#D85D43] motion-reduce:animate-none"}):n.jsx(SI,{size:16,strokeWidth:2}),ct>0&&n.jsx("span",{className:"pointer-events-none absolute right-0.5 top-0.5 flex h-[13px] min-w-[13px] items-center justify-center rounded-full bg-[#D85D43] px-[3px] text-[8px] font-black leading-none text-[#FFF8F2] ring-1 ring-[#F4F1EA]",children:ct>99?"99+":ct})]})}),n.jsxs(Ju,{dir:o.dir(),align:"start",sideOffset:8,className:"w-[340px] p-0 font-heebo bg-[#F7F4EF] border border-[#182137]/15 shadow-[0_18px_60px_rgba(0,0,0,0.18)] rounded-xl overflow-hidden",children:[n.jsxs("div",{className:"px-3 py-2.5 border-b border-[#182137]/10 bg-[#FDF6F4]",children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[n.jsx("div",{className:"w-7 h-7 rounded-lg bg-gradient-to-br from-[#EC7357] via-[#D84B2E] to-[#B33D24] flex items-center justify-center shrink-0",children:n.jsx(zl,{size:13,className:"text-white",strokeWidth:2.2})}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:"text-[13px] font-black text-[#182137] tracking-[-0.02em] truncate",children:s("renderGallery.myGallery",{defaultValue:"הגלריה שלי"})}),n.jsxs("div",{className:"text-[10px] font-bold text-[#182137]/55",children:[s(J.length===1?"renderGallery.renderCountOne":"renderGallery.renderCountOther",{count:J.length,defaultValue:`${J.length} רנדורים`}),st>0?s("renderGallery.pendingSuffix",{count:st,defaultValue:` · ${st} בעבודה`}):""]})]})]}),n.jsxs("button",{type:"button",onClick:()=>d(U=>!U),className:"mt-2 w-full inline-flex items-center justify-center gap-1.5 rounded-md border border-dashed border-[#EC7357]/40 bg-white/70 px-2.5 py-1.5 text-[11px] font-black text-[#9a3d28] hover:border-[#D84B2E] hover:bg-[#FCE8E4] transition-colors",children:[n.jsx(BI,{size:12,strokeWidth:2.2}),s("renderGallery.newFolder",{defaultValue:"תיקייה חדשה"})]}),S&&it&&n.jsxs("div",{className:"mt-2 flex items-center gap-1 text-[11px] font-bold",children:[n.jsx("button",{type:"button",onClick:()=>B(null),className:"text-[#182137]/60 hover:text-[#D84B2E] transition-colors",children:s("renderGallery.root",{defaultValue:"רוט"})}
400),n.jsx(v1,{size:10,className:`text-[#182137]/40 ${o.dir()==="rtl"?"rotate-180":""}`}),n.jsx("span",{className:"text-[#182137] truncate",children:it})]}),c&&n.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[n.jsx("input",{autoFocus:!0,type:"text",value:u,onChange:U=>h(U.target.value),onKeyDown:U=>{U.key==="Enter"&&pt(),U.key==="Escape"&&(d(!1),h(""))},placeholder:s("renderGallery.folderNamePlaceholder",{defaultValue:"שם התיקייה"}),className:"flex-1 px-2 py-1 text-[11px] font-bold rounded-md border border-[#182137]/15 bg-white text-[#182137] placeholder-[#182137]/35 focus:border-[#D84B2E] focus:outline-none"}),n.jsx("button",{type:"button",onClick:pt,className:"px-2 py-1 rounded-md bg-[#D84B2E] text-white text-[11px] font-black hover:bg-[#B33D24]",children:s("renderGallery.create",{defaultValue:"צור"})})]})]}),n.jsx("div",{className:"max-h-[520px] overflow-y-auto",children:R?n.jsx("div",{className:"flex items-center justify-center py-10",children:n.jsx(Xa,{size:20,className:"text-[#D84B2E] animate-spin"})}):n.jsxs("div",{className:"flex flex-col",children:[S===null&&W.length>0&&n.jsx("div",{className:"px-2 pt-2 flex flex-col gap-1",children:W.map(U=>{const mt=v===U.id;return n.jsxs("div",{onClick:()=>{mt||B(U.id)},onContextMenu:Nt=>vt(Nt,U.id),onDragOver:Nt=>ht(Nt,U.id),onDragLeave:()=>f(null),onDrop:Nt=>gt(Nt,U.id),className:`group flex items-center gap-2 px-2.5 py-2 rounded-lg cursor-pointer border transition-all ${x===U.id?"border-[#D84B2E] bg-[#FCE8E4]":"border-[#182137]/8 bg-white hover:border-[#EC7357]/40 hover:bg-[#FDF6F4]"}`,children:[n.jsx(e5,{size:14,className:"text-[#D84B2E] shrink-0"}
400),mt?n.jsx("input",{autoFocus:!0,type:"text",value:N,onChange:Nt=>P(Nt.target.value),onClick:Nt=>Nt.stopPropagation(),onKeyDown:Nt=>{Nt.stopPropagation(),Nt.key==="Enter"&&ut(),Nt.key==="Escape"&&kt()},onBlur:ut,className:"flex-1 min-w-0 text-[12px] font-black text-[#182137] bg-white border border-[#D84B2E] rounded px-1.5 py-0.5 focus:outline-none"}):n.jsx("span",{className:"flex-1 text-[12px] font-black text-[#182137] truncate tracking-[-0.01em]",children:U.name}),n.jsx("span",{className:"text-[10px] font-bold text-[#182137]/45",children:Rt[U.id]||0}),n.jsx("button",{type:"button",onClick:Nt=>{Nt.stopPropagation(),Ft(U.id,U.name)},className:"opacity-0 group-hover:opacity-100 p-1 rounded text-red-500 hover:bg-red-50 transition-opacity",title:s("renderGallery.deleteFolderTooltip",{defaultValue:"מחיקת תיקייה"}),children:n.jsx(gi,{size:11,strokeWidth:2.2})})]},U.id)})}),S!==null&&n.jsxs("div",{onDragOver:U=>ht(U,"__root__"),onDragLeave:()=>f(null),onDrop:U=>gt(U,null),className:`mx-2 mt-2 flex items-center gap-2 px-2.5 py-1.5 rounded-lg border-dashed border text-[11px] font-bold transition-all cursor-pointer ${x==="__root__"?"border-[#D84B2E] bg-[#FCE8E4] text-[#9a3d28]":"border-[#182137]/20 text-[#182137]/55 hover:border-[#EC7357]/40 hover:bg-[#FDF6F4]"}`,onClick:()=>B(null),children:[n.jsx(w1,{size:11}),s("renderGallery.backToRootDrop",{defaultValue:"חזרה לרוט (אפשר לגרור לכאן)"})]}),n.jsxs("div",{className:"flex flex-col gap-2 p-2",children:[S===null&&e.map(U=>n.jsx("div",{className:"relative overflow-hidden rounded-lg border border-[#EC7357]/40 bg-[#FDF6F4]",children:n.jsxs("div",{className:"flex aspect-[3/2] flex-col items-center justify-center gap-2 bg-gradient-to-br from-[#FDF6F4] to-[#F7F4EF]",children:[n.jsx(Xa,{size:28,className:"animate-spin text-[#D84B2E] motion-reduce:animate-none"}),n.jsx("div",{className:"text-[11px] font-black tracking-[-0.01em] text-[#9a3d28]",children:s("renderGallery.pendingStatus",{mode:s(`renderGallery.pendingModes.${U.mode}`,{defaultValue:a_[U.mode]}),defaultValue:`${a_[U.mode]} בעבודה`})}),n.jsx("div",{className:"px-3 text-center text-[9.5px] leading-tight text-[#182137]/55",children:s("renderGallery.pendingHint",{defaultValue:"אפשר לשלוח רנדורים נוספים ולהמשיך לעבוד בעורך"})})]})},U.id)),A.length===0&&st===0&&n.jsxs("div",{className:"text-center py-8 px-4",children:[n.jsx(zl,{size:20,className:"mx-auto text-[#D84B2E]/40 mb-2"}),n.jsx("div",{className:"text-[12px] font-black text-[#182137]/55 tracking-[-0.01em]",children:S?s("renderGallery.emptyFolder",{defaultValue:"התיקייה ריקה"}):s("renderGallery.emptyGallery",{defaultValue:"אין רנדורים עדיין"})}),n.jsx("div",{className:"text-[10px] text-[#182137]/40 mt-1",children:s("renderGallery.emptyHint",{defaultValue:'לחצו על "שלח לרנדור" בהאדר כדי להתחיל'})})]}),A.map(U=>{const mt=w===U.id,Nt=v6(U);return n.jsxs("div",{draggable:!mt,onDragStart:Lt=>Et(Lt,U.id),onClick:()=>{mt||l(U)},onContextMenu:Lt=>Vt(Lt,U.id),className:"group relative rounded-lg overflow-hidden border border-[#182137]/10 bg-white hover:border-[#EC7357]/50 transition-all cursor-zoom-in",children:[Nt?n.jsxs("div",{className:"relative aspect-[3/2] bg-[#10131a]",children:[n.jsx("video",{src:U.previewUrl,className:"h-full w-full object-cover",muted:!0,playsInline:!0,preload:"metadata"}),n.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/10",children:n.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-white/92 text-[#182137] shadow",children:n.jsx(__,{size:17,fill:"currentColor",strokeWidth:2.2})})})]}):n.jsx("img",{src:U.previewUrl,alt:U.name,className:"w-full aspect-[3/2] object-cover block",draggable:!1}),n.jsx("div",{className:"px-2.5 py-1.5 flex items-center justify-between gap-2 border-t border-[#182137]/8 bg-white",children:n.jsxs("div",{className:"min-w-0 flex-1",children:[mt?n.jsx("input",{autoFocus:!0,t
400ype:"text",value:_,onChange:Lt=>j(Lt.target.value),onClick:Lt=>Lt.stopPropagation(),onKeyDown:Lt=>{Lt.stopPropagation(),Lt.key==="Enter"&&Tt(),Lt.key==="Escape"&&Zt()},onBlur:Tt,className:"w-full text-[11.5px] font-black text-[#182137] bg-white border border-[#D84B2E] rounded px-1.5 py-0.5 focus:outline-none"}):n.jsx("div",{className:"text-[11.5px] font-black text-[#182137] truncate tracking-[-0.01em]",children:U.name}),n.jsx("div",{className:"text-[9.5px] text-[#182137]/50",children:Nt?s("renderGallery.video",{defaultValue:"וידאו"}):U.aspectRatio||""})]})}),n.jsxs("div",{className:"absolute top-1.5 left-1.5 flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[n.jsx("button",{type:"button",onClick:Lt=>{Lt.stopPropagation(),xt(U)},className:"inline-flex h-7 w-7 items-center justify-center rounded-md bg-white/95 hover:bg-[#EC7357] hover:text-white text-[#182137] border border-[#182137]/10 shadow",title:s("renderGallery.downloadTooltip",{defaultValue:"הורד"}),children:n.jsx(xp,{size:12,strokeWidth:2.4})}),n.jsx("button",{type:"button",onClick:Lt=>{Lt.stopPropagation(),_t(U)},className:"inline-flex h-7 w-7 items-center justify-center rounded-md bg-white/95 hover:bg-red-500 hover:text-white text-red-600 border border-red-300/60 shadow",title:s("renderGallery.deleteTooltip",{defaultValue:"מחק"}),children:n.jsx(gi,{size:12,strokeWidth:2.4})})]})]},U.id)})]})]})}),n.jsx("div",{className:"px-3 py-2 border-t border-[#182137]/10 bg-[#FDF6F4] text-[9.5px] text-[#182137]/55 text-center leading-snug",children:s("renderGallery.footerHint",{defaultValue:"לחיצה להגדלה · גרירה לתיקייה לסידור · קליק ימני לעוד פעולות"})}),p&&p.imageId&&(()=>{const U=J.find(mt=>mt.id===p.imageId);return U?n.jsxs("div",{ref:L,dir:o.dir(),onClick:mt=>mt.stopPropagation(),onContextMenu:mt=>mt.preventDefault(),style:{left:p.x,top:p.y,minWidth:"180px"},className:"fixed z-[99998] w-52 max-h-[min(90vh,720px)] overflow-x-hidden overflow-y-auto p-1 font-heebo text-[12px] bg-[#F7F4EF] border border-[#182137]/15 shadow-[0_18px_60px_rgba(0,0,0,0.18)] rounded-xl",children:[n.jsxs("button",{type:"button",onClick:()=>{Mt(),xt(U)},className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-start text-[12px] font-bold text-[#182137] hover:bg-[#FDF6F4] hover:text-[#9a3d28] rounded-md transition-colors",children:[n.jsx(xp,{className:"w-3.5 h-3.5 text-[#182137]/70",strokeWidth:2.2}),s("renderGallery.actions.download",{defaultValue:"הורד"})]}),W.length>0&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"h-px mx-3 my-0.5 bg-[#182137]/10"}),n.jsxs("button",{type:"button",onClick:mt=>{mt.stopPropagation(),g(Nt=>!Nt)},className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-start text-[12px] font-bold text-[#182137] hover:bg-[#FDF6F4] hover:text-[#9a3d28] rounded-md transition-colors",children:[n.jsx(VI,{className:"w-3.5 h-3.5 text-[#D84B2E]",strokeWidth:2.2}),s("renderGallery.actions.moveToFolder",{defaultValue:"העבר לתיקייה"}),n.jsx(v1,{className:`w-3 h-3 ms-auto transition-transform ${M?"rotate-90":""}`})]}),M&&n.jsxs("div",{className:"ps-6 pe-2",children:[S&&n.jsxs("button",{type:"button",onClick:()=>{p.imageId&&Y(p.imageId,null),Mt()},className:"flex items-center gap-2 w-full px-2 py-1 text-start text-[11.5px] font-bold text-[#182137] hover:bg-[#FDF6F4] hover:text-[#9a3d28] rounded-md transition-colors",children:[n.jsx(w1,{className:"w-3.5 h-3.5 text-[#182137]/55",strokeWidth:2.2}),n.jsx("span",{className:"truncate",children:s("renderGallery.root",{defaultValue:"רוט"})})]}),W.filter(mt=>mt.id!==U.folderId).map(mt=>n.jsxs("button",{type:"button",onClick:()=>{p.imageId&&Y(p.imageId,mt.id),Mt()},className:"flex items-center gap-2 w-full px-2 py-1 text-start text-[11.5px] font-bold text-[#182137] hover:bg-[#FDF6F4] hover:text-[#9a3d28] rounded-md transition-colors",children:[n.jsx(e5,{className:"w-3.5 h-3.5 text-[#D84B2E]",strokeWidth:2.2}),n.jsx("span",{className:"truncate",children:mt.name})]},mt.id))]})]}),n.jsx("div",{className:"h-px mx-3 my-0.5 bg-[#182137]/10"}),n.jsxs("button",{type:"button",onClick:()=>Ht(U),className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-start text-[12px] font-bold text-[#182137] hover:bg-[#FDF6F4] hover:text-[#9a3d28] rounded-md transition-colors",children:[n.jsx(mp,{className:"w-3.5 h-3.5 text-[#9a3d28]",strokeWidth:2.2}),s("renderGallery.actions.rename",{defaultValue:"שנה שם"})]}),n.jsx("div",{className:"h-px mx-3 my-0.5 bg-[#182137]/10"}),n.jsxs("button",{type:"button",onClick:()=>{Mt(),_t(U)},className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-start text-[12px] font-bold text-red-600 hover:bg-red-50 rounded-md transition-colors",children:[n.jsx(gi,{className:"w-3.5 h-3.5",strokeWidth:2.2}),s("renderGallery.actions.delete",{defaultValue:"מחק"})]})]}):null})(),p&&p.folderId&&(()=>{const U=W.find(mt=>mt.id===p.folderId);return U?n.jsxs("div",{ref:L,dir:o.dir(),onClick:mt=>mt.stopPropagation(),onContextMenu:mt=>mt.preventDefault(),style:{left:p.x,top:p.y,minWidth:"180px"},className:"fixed z-[99998] w-52 max-h-[min(90vh,720px)] overflow-x-hidden overflow-y-auto p-1 font-heebo text-[12px] bg-[#F7F4EF] border border-[#182137]/15 shadow-[0_18px_60px_rgba(0,0,0,0.18)] rounded-xl",children:[n.jsxs("button",{type:"button",onClick:()=>At(U.id,U.name),className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-start text-[12px] font-bold text-[#182137] hover:bg-[#FDF6F4] hover:text-[#9a3d28] rounded-md transition-colors",children:[n.jsx(mp,{className:"w-3.5 h-3.5 text-[#9a3d28]",strokeWidth:2.2}),s("renderGallery.actions.rename",{defaultValue:"שנה שם"})]}),n.jsx("div",{className:"h-px mx-3 my-0.5 bg-[#182137]/10"}),n.jsxs("button",{type:"button",onClick:()=>{Mt(),Ft(U.id,U.name)},className:"flex items-center gap-2 w-full px-2.5 py-1.5 text-start text-[12px] font-bold text-red-600 hover:bg-red-50 rounded-md transition-colors",children:[n.jsx(gi,{className:"w-3.5 h-3.5",strokeWidth:2.2}),s("renderGallery.actions.deleteFolder",{defaultValue:"מחק תיקייה"})]})]}):null})()]})]}),n.jsx(jQ,{item:a,onClose:()=>l(null),onDelete:z})]})}const DQ=[{id:"faithful",title:"רנדור נאמן לעיצוב",description:"משפר את הריאליזם בלבד — בלי להוסיף או לשנות פריטים",icon:XI,accent:"#D85D43",badge:"מומלץ"},{id:"consistent",title:"שמור על עקביות בסגנון",description:"מתאים את האור והצבעוניות לרנדור קודם בפרויקט",icon:k1,accent:"#6D5A8C"},{id:"free",title:"הוסף סטייל באופן חופשי",description:"מאפשר ל-AI להוסיף דקור ואקססוריז לפי שיקול דעתו",icon:j1,accent:"#A24A37"}];function FQ(t){return t.mimeType?t.mimeType.startsWith("image/"):/\.(png|jpe?g|webp|avif)(\?|$)/i.test(t.previewUrl)}function CQ({items:t,currentProjectId:e,loadingReferences:s=!1,onRender:o}){const{t:r}=yn(),[i,a]=m.useState(!1),[l,c]=m.useState("faithful"),[d,u]=m.useState(null),h=m.useMemo(()=>t.filter(b=>FQ(b)&&!!e&&b.sourceFloorplanId===e).slice(0,8),[e,t]);m.useEffect(()=>{var b;d&&h.some(M=>M.id===d)||u(((b=h[0])==null?void 0:b.id)??null)},[h,d]);const x=h.find(b=>b.id===d)??null,f=l==="consistent"&&!x,p=()=>{f||(a(!1),o({mode:l,referenceImageUrl:l==="consistent"?x==null?void 0:x.previewUrl:void 0}))};return n.jsxs(qu,{open:i,onOpenChange:a,children:[n.jsx(Qu,{asChild:!0,children:n.jsxs("button",{type:"button","aria-label":r("renderMode.chooseType",{defaultValue:"בחר סוג רנדור"}),"aria-haspopup":"dialog","data-testid":"floorplan-render-mode-trigger",className:O("group relative inline-flex h-8 min-w-8 items-center justify-center gap-0.5 overflow-hidden rounded-[7px] border border-[#FFC6A8]/65 px-1.5 text-[#FFF8F2]","bg-[linear-gradient(145deg,#FFB06F_0%,#D85D43_48%,#8C4FA3_100%)]","shadow-[inset_0_1px_0_rgba(255,248,242,0.68),inset_0_-2px_0_rgba(88,35,52,0.34),0_5px_10px_rgba(216,93,67,0.28),0_1px_0_rgba(24,33,55,0.18)]","transition-all duration-150 hover:-translate-y-0.5 hover:shadow-[inset_0_1px_0_rgba(255,248,242,0.76),inset_0_-2px_0_rgba(88,35,52,0.30),0_8px_16px_rgba(216,93,67,0.34),0_2px_0_rgba(24,33,55,0.16)]","active:translate-y-[1px] active:shadow-[inset_0_2px_4px_rgba(88,35,52,0.32),0_2px_5px_rgba(216,93,67,0.22)]","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#D85D43]/45 focus-visible:ring-offset-2 focus-visible:ring-offset-[#F4F1EA]"),children:[n.jsx("span",{className:"pointer-events-none absolute inset-x-1 top-1 h-2 rounded-full bg-[#FFF8F2]/35 blur-[1px]"}),n.jsx(j1,{className:"relative z-10 h-4 w-4 drop-shadow-[0_1px_1px_rgba(88,35,52,0.45)]",strokeWidth:2.2}),n.jsx(Yc,{className:"relative z-10 h-3 w-3 opacity-85",strokeWidth:2.4})]})}),n.jsxs(Ju,{dir:"rtl",align:"end",side:"bottom",sideOffset:10,collisionPadding:12,className:"z-[100] w-[420px] max-w-[calc(100vw-24px)] rounded-[16px] border border-[#182137]/12 bg-[#F7F4EF] p-0 font-heebo text-[#182137] shadow-[0_24px_64px_rgba(24,33,55,0.24)]",children:[n.jsx("div",{className:"border-b border-[#182137]/10 px-4 pb-3 pt-4",children:n.jsxs("div",{className:"flex items-start justify-between gap-4",children:[n.jsxs("div",{children:[n.jsx("p",{className:"text-[17px] font-black leading-tight tracking-[-0.035em]",children:r("renderMode.title",{defaultValue:"איך לרנדר את התצוגה?"})}),n.jsx("p",{className:"mt-1 text-[11px] font-medium leading-4 text-[#182137]/62",children:r("renderMode.description",{defaultValue:"בחרו כמה חופש לתת ל-AI לפני שמוציאים טוקנים"})})]}),n.jsx("span",{className:"mt-0.5 rounded-full border border-[#D85D43]/20 bg-[#D85D43]/8 px-2 py-1 text-[9px] font-black text-[#A24A37]",children:r("renderMode.tokenCost",{defaultValue:"4 טוקנים"})})]})}),n.jsx("div",{className:"space-y-2 p-3",role:"radiogroup","aria-label":r("renderMode.type",{defaultValue:"סוג רנדור"}),children:DQ.map(b=>{const M=b.icon,g=l===b.id;return n.jsxs("div",{children:[n.jsxs("button",{type:"button",role:"radio","aria-checked":g,onClick:()=>c(b.id),"data-testid":`floorplan-render-mode-${b.id}`,className:O("group flex min-h-[68px] w-full items-center gap-3 rounded-[12px] border px-3 py-2.5 text-right transition-[border-color,background-color,box-shadow,transform] duration-150","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#D85D43]/35",g?"border-[#182137]/28 bg-[#FFFDF9] shadow-[inset_3px_0_0_var(--mode-accent),0_5px_14px_rgba(24,33,55,0.08)]":"border-[#182137]/10 bg-[#E8E3DB]/38 hover:-translate-y-
400px hover:border-[#182137]/20 hover:bg-[#FFFDF9]/70"),style:{"--mode-accent":b.accent},children:[n.jsx("span",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-[10px] border",style:{color:b.accent,borderColor:`${b.accent}33`,backgroundColor:`${b.accent}12`},children:n.jsx(M,{className:"h-[19px] w-[19px]",strokeWidth:1.9})}),n.jsxs("span",{className:"min-w-0 flex-1",children:[n.jsxs("span",{className:"flex flex-wrap items-center gap-1.5",children:[n.jsx("span",{className:"text-[12px] font-black leading-5",children:r(`renderMode.options.${b.id}.title`,{defaultValue:b.title})}),b.badge&&n.jsx("span",{className:"rounded-full bg-[#D85D43] px-1.5 py-0.5 text-[8px] font-black leading-none text-[#FFF8F2]",children:r("renderMode.recommended",{defaultValue:b.badge})})]}),n.jsx("span",{className:"block text-[10px] font-medium leading-4 text-[#182137]/60",children:r(`renderMode.options.${b.id}.description`,{defaultValue:b.description})})]}),n.jsx("span",{className:O("flex h-5 w-5 shrink-0 items-center justify-center rounded-full border transition-colors",g?"border-[#182137] bg-[#182137] text-[#F7F4EF]":"border-[#182137]/24 bg-transparent text-transparent"),children:n.jsx(Gc,{className:"h-3 w-3",strokeWidth:2.6})})]}),g&&b.id==="consistent"&&n.jsx("div",{className:"mx-2 rounded-b-[12px] border-x border-b border-[#6D5A8C]/18 bg-[#6D5A8C]/[0.055] px-3 pb-3 pt-2.5",children:s?n.jsxs("div",{className:"flex h-16 items-center justify-center gap-2 text-[10px] font-semibold text-[#182137]/55",children:[n.jsx(Xa,{className:"h-3.5 w-3.5 animate-spin"}),r("renderMode.loadingReferences",{defaultValue:"טוען רנדורים מהפרויקט"})]}):h.length===0?n.jsx("div",{className:"rounded-[9px] border border-dashed border-[#6D5A8C]/28 bg-[#F7F4EF]/70 px-3 py-2.5 text-[10px] font-medium leading-4 text-[#182137]/68",children:r("renderMode.noReferences",{defaultValue:"עדיין אין רנדור קודם בפרויקט הזה. צרו קודם רנדור נאמן או חופשי, והוא יוכל לשמש כתמונת הייחוס לסדרה."})}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[n.jsx("span",{className:"text-[10px] font-black",children:r("renderMode.referenceImage",{defaultValue:"תמונת הייחוס לסגנון"})}),n.jsx("span",{className:"text-[9px] font-medium text-[#182137]/52",children:r("renderMode.latestSelected",{defaultValue:"האחרון נבחר אוטומטית"})})]}),n.jsx("div",{className:"grid grid-cols-4 gap-1.5",children:h.map(w=>{const k=w.id===d;return n.jsxs("button",{type:"button",onClick:()=>u(w.id),"aria-label":r("renderMode.selectReference",{defaultValue:"בחר {{name}} כתמונת ייחוס",name:w.name}),"aria-pressed":k,className:O("relative aspect-[4/3] overflow-hidden rounded-[7px] border-2 bg-[#E0DFD8] transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#6D5A8C]/45",k?"border-[#6D5A8C] shadow-[0_4px_10px_rgba(109,90,140,0.24)]":"border-transparent opacity-72 hover:opacity-100"),children:[n.jsx("img",{src:w.previewUrl,alt:"",className:"h-full w-full object-cover"}),k&&n.jsx("span",{className:"absolute end-1 top-1 flex h-4 w-4 items-center justify-center rounded-full bg-[#6D5A8C] text-[#F7F4EF] shadow-sm",children:n.jsx(Gc,{className:"h-2.5 w-2.5",strokeWidth:2.8})})]},w.id)})})]})})]},b.id)})}),n.jsx("div",{className:"border-t border-[#182137]/10 bg-[#E8E3DB]/36 p-3",children:n.jsxs("button",{type:"button",onClick:p,disabled:f,className:O("flex min-h-11 w-full items-center justify-center gap-2 rounded-[10px] border border-[#C94E35] bg-[#D85D43] px-4 text-[12px] font-black text-[#FFF8F2]","shadow-[inset_0_1px_0_rgba(255,248,242,0.38),inset_0_-2px_0_rgba(126,48,34,0.38),0_5px_12px_rgba(216,93,67,0.24)]","transition-all hover:-translate-y-px hover:bg-[#C94E35] hover:shadow-[inset_0_1px_0_rgba(255,248,242,0.4),inset_0_-2px_0_rgba(126,48,34,0.32),0_8px_16px_rgba(216,93,67,0.3)]","active:translate-y-[1px] active:shadow-[inset_0_2px_4px_rgba(126,48,34,0.3),0_2px_5px_rgba(216,93,67,0.18)]","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#D85D43]/45 focus-visible:ring-offset-2 focus-visible:ring-offset-[#E8E3DB]","disabled:cursor-not-allowed disabled:opacity-45 disabled:hover:translate-y-0"),children:[n.jsx(j1,{className:"h-4 w-4",strokeWidth:2.1}),f?r("renderMode.referenceRequired",{defaultValue:"צריך קודם רנדור ייחוס"}):r("renderMode.renderNow",{defaultValue:"רנדר עכשיו · 4 טוקנים"})]})})]})]})}const NQ=`צור רנדור פוטוריאליסטי ומקצועי של החלל המופיע בתמונה 1.
401
402תמונה 1 היא מקור האמת המלא והמחייב לעיצוב.
403
404שמור ללא שינוי על כל מה שתוכנן ונראה בתמונה:
405- המבנה, הקירות, הפתחים, התקרה והרצפה.
406- מיקום המצלמה, זווית הצילום, הפרספקטיבה והקומפוזיציה.
407- כל פריטי הריהוט, גודלם, מיקומם והכיוון שלהם.
408- החומרים, הצבעים, החיפויים, הטקסטורות וגופי התאורה.
409- כל פריט דקורטיבי שכבר קיים בתמונה.
410
411אין להוסיף, להסיר, להחליף, להזיז או לעצב מחדש שום רהיט, חומר, צבע, גוף תאורה, אמנות, צמחייה או אביזר.
412אין להשלים אזורים חסרים באמצעות פריטים מומצאים.
413
414שפר רק את איכות ההמחשה: פוטוריאליזם, חדות, עומק, החזרי אור טבעיים, צללים רכים ואמינים ואיכות החומרים הקיימים.
415
416התוצאה חייבת להיראות כמו צילום מקצועי של העיצוב המדויק שבתמונה 1 — לא כמו הצעת עיצוב חדשה.`,IQ=`צור רנדור פוטוריאליסטי של החלל בתמונה 1, תוך התאמה חזותית מדויקת לסדרת הרנדורים של תמונה 2.
417
418תפקידי התמונות:
419- תמונה 1 היא מקור האמת הבלעדי למבנה, לתכולה ולעיצוב של החלל הנוכחי.
420- תמונה 2 היא תמונת ייחוס לסגנון הצילום והעיבוד בלבד.
421
422מתמונה 1 שמור ללא שינוי על המבנה, הפתחים, המצלמה, הפרספקטיבה, הריהוט, המיקום, המידות, החומרים, הצבעים, החיפויים, התאורה והאביזרים.
423אין להוסיף, להסיר, להחליף, להזיז או להמציא שום פריט.
424
425מתמונה 2 העתק רק את החתימה הצילומית:
426- טמפרטורת האור והאיזון הלבן.
427- גוון האור, רמת החשיפה ועוצמת התאורה הכללית.
428- ניגודיות, רוויה, עומק השחורים ובהירות האזורים הבהירים.
429- רכות הצללים, איכות ההחזרים והתחושה החומרית.
430- סגנון עיבוד הצבע והאווירה הכללית.
431
432אל תעתיק מתמונה 2 רהיטים, חומרים, צבעי פריטים, מבנה, דקור, קומפוזיציה או פרטי עיצוב שאינם קיימים בתמונה 1.
433
434התוצאה צריכה להרגיש כחלק מאותה סדרת צילום של תמונה 2, אך להציג בנאמנות מוחלטת את החלל והעיצוב של תמונה 1.`,TQ=`פעל כמו סטייליסט פנים בכיר שמכין חלל לצילום מגזיני.
435
436תמונה 1 היא החלל הקיים.
437שמור על המבנה, הריהוט המרכזי, המצלמה והאור הקיים.
438
439שפר רק את שכבת הסטיילינג:
440אמנות, כריות, שטיח, שולחן קפה, ספרים, אגרטלים, תאורה רכה, וילונות, צמחייה ואקססוריז.
441
442המטרה: להפוך את החלל ליותר יוקרתי, מצולם ומוכן לפרסום, בלי להחליף את כל העיצוב.
443
444התוצאה צריכה להיות עדינה, אמינה, לא עמוסה, לא מלאכותית.`,SQ={faithful:NQ,consistent:IQ,free:TQ},Su="canvas-assets",l_="floorplan-renders",PQ="floorplan_render_assets",AQ="floorplan_render_folders",pf=()=>Bo.from(PQ),Kg=()=>Bo.from(AQ);function LQ(){const[t,e]=m.useState([]),[s,o]=m.useState([]),[r,i]=m.useState(null),[a,l]=m.useState(!0),{user:c}=Ww(),d=m.useMemo(()=>t.filter(w=>w.folderId===r),[t,r]);m.useEffect(()=>{if(!(c!=null&&c.id)){l(!1);return}let w=!1;return(async()=>{try{const{data:k,error:_}=await Kg().select("id, name, created_at").eq("user_id",c.id).order("name",{ascending:!0});if(w)return;_?Ys.error("[FloorplanRenderBank] Failed to load folders:",_):o((k||[]).map(N=>({id:N.id,name:N.name,createdAt:N.created_at})));const{data:j,error:v}=await pf().select("id, storage_path, name, source, created_at, folder_id, aspect_ratio, mime_type, source_floorplan_id").eq("user_id",c.id).order("created_at",{ascending:!1});if(w)return;if(v){Ys.error("[FloorplanRenderBank] Failed to load:",v);return}const C=(j||[]).map(N=>{const{data:P}=Bo.storage.from(Su).getPublicUrl(N.storage_path);return{id:N.id,previewUrl:P.publicUrl,name:N.name,storagePath:N.storage_path,source:N.source,folderId:N.folder_id,aspectRatio:N.aspect_ratio??null,mimeType:N.mime_type??null,sourceFloorplanId:N.source_floorplan_id??null,createdAt:N.created_at}});e(C)}catch(k){Ys.error("[FloorplanRenderBank] Failed to load:",k)}finally{w||l(!1)}})(),()=>{w=!0}},[c==null?void 0:c.id]);const u=m.useCallback(async w=>{if(!(c!=null&&c.id)||!w.trim())return null;
444const k=crypto.randomUUID(),_=new Date().toISOString(),{error:j}=await Kg().insert({id:k,user_id:c.id,name:w.trim()});if(j)return Ys.error("[FloorplanRenderBank] Create folder failed:",j),null;const v={id:k,name:w.trim(),createdAt:_};return o(C=>[...C,v].sort((N,P)=>N.name.localeCompare(P.name))),v},[c==null?void 0:c.id]),h=m.useCallback(async(w,k)=>{const _=k.trim();if(!_)return;o(v=>v.map(C=>C.id===w?{...C,name:_}:C));const{error:j}=await Kg().update({name:_}).eq("id",w);j&&Ys.error("[FloorplanRenderBank] Rename folder failed:",j)},[]),x=m.useCallback(async w=>{e(_=>_.map(j=>j.folderId===w?{...j,folderId:null}:j)),o(_=>_.filter(j=>j.id!==w)),i(_=>_===w?null:_);const{error:k}=await Kg().delete().eq("id",w);k&&Ys.error("[FloorplanRenderBank] Delete folder failed:",k)},[]),f=m.useCallback(async(w,k)=>{e(j=>j.map(v=>v.id===w?{...v,folderId:k}:v));const{error:_}=await pf().update({folder_id:k}).eq("id",w);_&&Ys.error("[FloorplanRenderBank] Move item failed:",_)},[]),p=m.useCallback(async(w,k,_=null,j=null)=>{if(!(c!=null&&c.id))return null;try{const v=await fetch(w);if(!v.ok)throw new Error(`Fetch failed: ${v.status}`);const C=await v.blob(),N=C.type||"image/png",P=(N.split("/")[1]||"png").replace("jpeg","jpg"),L=crypto.randomUUID(),A=`${c.id}/${l_}/render-${L}.${P}`,{error:W}=await Bo.storage.from(Su).upload(A,C,{contentType:N,upsert:!0});if(W)return Ys.error("[FloorplanRenderBank] Upload failed:",W),null;const S=new Date().toISOString(),{error:B}=await pf().insert({id:L,user_id:c.id,storage_path:A,name:k,mime_type:N,source:"floorplan_render",folder_id:r,aspect_ratio:_,source_floorplan_id:j});if(B)return Ys.error("[FloorplanRenderBank] Insert failed:",B),await Bo.storage.from(Su).remove([A]),null;const{data:R}=Bo.storage.from(Su).getPublicUrl(A),z={id:L,previewUrl:R.publicUrl,name:k,storagePath:A,source:"floorplan_render",folderId:r,aspectRatio:_,mimeType:N,sourceFloorplanId:j,createdAt:S};return e(X=>[z,...X]),z}catch(v){return Ys.error("[FloorplanRenderBank] saveFromUrl failed:",v),null}},[c==null?void 0:c.id,r]),b=m.useCallback(async(w,k,_)=>{if(!(c!=null&&c.id))return null;try{const j=w.type||"application/octet-stream",v=crypto.randomUUID(),C=(_==null?void 0:_.source)??"floorplan_render",N=(_==null?void 0:_.storagePrefix)??l_,P=(_==null?void 0:_.extension)??(j.split("/")[1]||"bin").replace("jpeg","jpg"),L=`${c.id}/${N}/${C}-${v}.${P}`,{error:A}=await Bo.storage.from(Su).upload(L,w,{contentType:j,upsert:!0});if(A)return Ys.error("[FloorplanRenderBank] Blob upload failed:",A),null;const W=new Date().toISOString(),{error:S}=await pf().insert({id:v,user_id:c.id,storage_path:L,name:k,mime_type:j,source:C,folder_id:r,aspect_ratio:(_==null?void 0:_.aspectRatio)??null,source_floorplan_id:(_==null?void 0:_.sourceFloorplanId)??null});if(S)return Ys.error("[FloorplanRenderBank] Blob insert failed:",S),await Bo.storage.from(Su).remove([L]),null;const{data:B}=Bo.storage.from(Su).getPublicUrl(L),R={id:v,previewUrl:B.publicUrl,name:k,storagePath:L,source:C,folderId:r,aspectRatio:(_==null?void 0:_.aspectRatio)??null,mimeType:j,sourceFloorplanId:(_==null?void 0:_.sourceFloorplanId)??null,createdAt:W};return e(z=>[R,...z]),R}catch(j){return Ys.error("[FloorplanRenderBank] saveBlob failed:",j),null}},[c==null?void 0:c.id,r]),M=m.useCallback(async w=>{const k=t.find(_=>_.id===w);e(_=>_.filter(j=>j.id!==w)),k&&await Promise.all([Bo.storage.from(Su).remove([k.storagePath]),pf().delete().eq("id",w)]).catch(_=>Ys.error("[FloorplanRenderBank] Delete failed:",_))},[t]),g=m.useCallback(async(w,k)=>{const _=k.trim();if(!_)return;e(v=>v.map(C=>C.id===w?{...C,name:_}:C));const{error:j}=await pf().update({name:_}).eq("id",w);j&&Ys.error("[FloorplanRenderBank] Rename failed:",j)},[]);return{items:t,visibleItems:d,folders:s,currentFolderId:r,setCurrentFolderId:i,loading:a,saveFromUrl:p,saveBlob:b,removeItem:M,renameItem:g,createFolder:u,renameFolder:h,deleteFolder:x,moveItemToFolder:f}}function WQ(t,e){if(!t||!e)return"3:2";const s=t/e;return s>=1.2?"3:2":s<=.83?"2:3":"1:1"}function RQ(t){return new Promise((e,s)=>{const o=new Image;o.onload=()=>
444e({width:o.naturalWidth,height:o.naturalHeight}),o.onerror=r=>s(r),o.src=t})}function OQ(t){var l;const[e,s]=t.split(","),o=((l=e.match(/data:(.*?);base64/))==null?void 0:l[1])||"image/png",r=atob(s),i=r.length,a=new Uint8Array(i);for(let c=0;c<i;c++)a[c]=r.charCodeAt(c);return new Blob([a],{type:o})}function HQ(t){const{viewerRef:e,miniViewerRef:s,currentProjectId:o}=t,{user:r}=Ww(),{i18n:i}=jw(),a=i.language==="he",{checkTokensAndCall:l}=fb(),c=LQ(),[d,u]=m.useState([]);return{send:m.useCallback(async(x={mode:"faithful"})=>{var b,M,g;if(!(r!=null&&r.id))return ln.error(a?"יש להתחבר כדי לרנדר":"Please sign in to render"),null;if(x.mode==="consistent"&&!x.referenceImageUrl)return ln.error(a?"יש לבחור רנדור קודם כתמונת ייחוס":"Choose a previous render as the style reference"),null;const f=((b=e.current)==null?void 0:b.takeScreenshot())||((M=s==null?void 0:s.current)==null?void 0:M.takeScreenshot());if(!f)return ln.error(a?"לא ניתן לצלם את התצוגה. ודא/י שאת/ה במצב תלת-מימד.":"Cannot capture the view. Make sure you are in 3D mode."),null;const p=`pending-${crypto.randomUUID()}`;u(w=>[{id:p,startedAt:Date.now(),mode:x.mode},...w]);try{const{width:w,height:k}=await RQ(f),_=WQ(w,k),j=OQ(f),v=`${r.id}/floorplan-screenshot-${p}.png`,{error:C}=await Bo.storage.from("canvas-uploads").upload(v,j,{contentType:"image/png",upsert:!1});if(C)throw new Error(a?`העלאת תמונת המקור נכשלה: ${C.message}`:`Source image upload failed: ${C.message}`);const{data:{publicUrl:N}}=Bo.storage.from("canvas-uploads").getPublicUrl(v),P=x.referenceImageUrl?[N,x.referenceImageUrl]:[N],L=await l("gpt-image-2",{prompt:SQ[x.mode],image_urls:P,aspect_ratio:_,quality:"medium",output_format:"png",skip_pending_tracking:!0,canvasDocId:o??null,crm_source:"other",crm_surface:"floorplan-render-button",crm_feature_key:"gpt_image_2_medium",crm_prompt_origin:`floorplan_render_${x.mode}`},"gpt_image_2_medium");if(!L.success){if(L.insufficientTokens)return null;const B=L.user_message||L.error||(a?"הרינדור נכשל":"Render failed");return ln.error(B),null}const A=(g=L.data)==null?void 0:g.generated_url;if(!A)return ln.error(a?"לא התקבלה תמונה מהשרת":"No image received from the server"),null;const W=new Date().toLocaleString("he-IL",{day:"2-digit",month:"2-digit",hour:"2-digit",minute:"2-digit"}),S=await c.saveFromUrl(A,`רנדור ${W}`,_,o??null);return S?(ln.success(a?"הרנדור מוכן":"Render is ready"),S):(ln.error(a?"התמונה נוצרה אך השמירה לגלריה נכשלה":"Image was generated but saving to gallery failed"),null)}catch(w){const k=w instanceof Error?w.message:a?"שגיאה לא ידועה":"Unknown error";return Ys.error("[FloorplanRenderFlow] send failed:",w),ln.error(k),null}finally{u(w=>w.filter(k=>k.id!==p))}},[r==null?void 0:r.id,e,s,o,c,l,a]),pendingRenders:d,bank:c}}function BQ({open:t,onClose:e,viewportFrameRef:s,fpIsDark:o,savedProjects:r,currentProjectId:i,loadingProjects:a,selectMode:l,selectedIds:c,onEnterSelectMode:d,onExitSelectMode:u,onToggleSelected:h,onBulkDelete:x,onLoadProject:f,onDeleteProject:p,renamingProjectId:b,renameDraft:M,onRenameDraftChange:g,onStartRename:w,onCommitRename:k,onCancelRename:_}){const{t:j,i18n:v}=yn(),{isRTL:C}=Yd();return m.useEffect(()=>{if(!t)return;const N=P=>{P.key==="Escape"&&e()};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[t,e]),t?n.jsxs("div",{dir:C?"rtl":"ltr","data-testid":"floorplan-projects-modal",className:"absolute inset-0 z-40 flex items-center justify-center",onClick:N=>{N.target===N.currentTarget&&e()},children:[n.jsx("div",{className:"absolute inset-0 bg-black/40 backdrop-blur-[2px]"}),n.jsxs("div",{className:O("relative flex max-h-[min(80vh,640px)] w-[min(420px,90vw)] flex-col overflow-hidden rounded-2xl border text-right shadow-[0_24px_60px_rgba(24,33,55,0.32)]",o?"border-white/[0.10] bg-[#141416] text-white":"border-[#182137]/14 bg-[#F7F4EF] text-[#182137]"),onClick:N=>N.stopPropagation(),children:[n.jsxs("div",{className:O("flex shrink-0 items-center justify-between border-b px-4 py-3",o?"border-white/10":"border-[#182137]/12"),children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-right",children:[n.jsx(Lw,{size:18,className:O(o?"text-white/55":"text-[#182137]/55")}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("p",{className:O("text-[10px] font-medium",o?"text-white/55":"text-[#182137]/58"),children:j("projects.label",{defaultValue:"פרויקטים"})}),n.jsx("h2",{className:"truncate text-[16px] font-semibold leading-tight",children:j("projects.title",{defaultValue:"התוכניות שלי"})})]})]}),n.jsxs("div",{className:"flex items-center gap-1",children:[r.length>0&&(l?n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",onClick:x,disabled:c.size===0,className:"cursor-pointer rounded-md bg-red-500 px-2 py-1 text-[10px] font-bold text-white transition-colors hover:bg-red-600 disabled:cursor-default disabled:opacity-40",children:j("projects.deleteCount",{defaultValue:"מחק ({{count}})",count:c.size})}),n.jsx("button",{type:"button",onClick:u,className:O("cursor-pointer rounded-md px-2 py-1 text-[10px] font-medium transition-colors",o?"text-white/55 hover:bg-white/10 hover:text-white":"text-[#182137]/55 hover:bg-[#182137]/5 hover:text-[#182137]"),children:j("common.cancel",{defaultValue:"ביטול"})})]}):n.jsx("button",{type:"button",onClick:d,className:O("flex h-7 w-7 cursor-pointer items-center justify-center rounded-md transition-colors",o?"text-white/45 hover:bg-white/10 hover:text-white":"text-[#182137]/45 hover:bg-[#182137]/5 hover:text-[#182137]"),title:j("projects.selectForDeletion",{defaultValue:"סמן למחיקה"}),children:n.jsx(EN,{size:14})})),n.jsx("button",{type:"button","aria-label":j("common.close",{defaultValue:"סגור"}),title:j("common.close",{defaultValue:"סגור"}),onClick:e,className:O("flex h-8 w-8 items-center justify-center rounded-md transition-colors",o?"text-white/70 hover:bg-white/10 hover:text-white":"text-[#182137]/70 hover:bg-[#
444E8DFD3] hover:text-[#182137]"),children:n.jsx(Gr,{size:16})})]})]}),n.jsx("div",{className:O("min-h-0 flex-1 overflow-y-auto p-2",o?"bg-[#141416]":"bg-[#FAF8F5]/60"),children:a?n.jsx("div",{className:"flex items-center justify-center py-8",children:n.jsx("div",{className:O("h-6 w-6 animate-spin rounded-full border-2 border-t-transparent",o?"border-[#F36A2D]":"border-[#D84B2E]")})}):r.length===0?n.jsx("div",{className:O("py-10 text-center text-[12px]",o?"text-white/45":"text-[#182137]/45"),children:j("projects.empty",{defaultValue:"אין פרויקטים שמורים"})}):n.jsx("div",{className:"space-y-1",children:r.map(N=>{const P=c.has(N.id),L=i===N.id;return n.jsxs("div",{className:O("group flex cursor-pointer items-center gap-2 rounded-xl border px-2 py-1.5 text-right transition-all",l&&P?"border-red-300 bg-red-500/10":L?o?"border-[#EC7357]/35 bg-[#EC7357]/[0.12]":"border-[#D84B2E]/30 bg-[#FFEDE8]":o?"border-transparent hover:bg-white/[0.04]":"border-transparent hover:bg-white/90"),onClick:()=>{l?h(N.id):f(N)},children:[l&&n.jsx("div",{className:O("flex h-4 w-4 shrink-0 items-center justify-center rounded border-2 transition-colors",P?"border-red-500 bg-red-500":o?"border-white/20 bg-[#0A0A0A]":"border-[#182137]/20 bg-white"),children:P&&n.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("polyline",{points:"20 6 9 17 4 12"})})}),n.jsx("div",{className:O("flex h-9 w-9 shrink-0 items-center justify-center overflow-hidden rounded-lg",o?"bg-white/5":"bg-[#182137]/5"),children:N.thumbnail_url?n.jsx("img",{src:N.thumbnail_url,alt:"",className:"h-full w-full object-cover"}):n.jsx("span",{className:"text-base",children:"🏠"})}),n.jsxs("div",{className:"min-w-0 flex-1",children:[b===N.id?n.jsx("input",{autoFocus:!0,value:M,onChange:A=>g(A.target.value),onBlur:()=>k(N.id,M),onKeyDown:A=>{A.key==="Enter"&&A.target.blur(),A.key==="Escape"&&_()},onClick:A=>A.stopPropagation(),className:O("w-full rounded border px-1 py-0.5 text-[12px] font-semibold outline-none focus:ring-1",o?"border-[#EC7357]/50 bg-[#0A0A0A] text-white focus:ring-[#EC7357]/30":"border-[#D84B2E]/40 bg-white text-[#182137] focus:ring-[#EC7357]/30")}):n.jsx("div",{className:O("truncate text-[12px] font-semibold",o?"text-white/90":"text-[#182137]"),onDoubleClick:A=>{A.stopPropagation(),l||w(N)},children:N.name}),n.jsx("div",{className:O("text-[10px]",o?"text-white/40":"text-[#182137]/40"),children:new Date(N.updated_at).toLocaleDateString(v.language)})]}),!l&&n.jsx("button",{type:"button",onClick:A=>{A.stopPropagation(),p(N.id)},className:O("flex h-6 w-6 shrink-0 items-center justify-center rounded-full opacity-0 transition-all group-hover:opacity-100",o?"text-white/30 hover:bg-red-500/20 hover:text-red-400":"text-[#182137]/30 hover:bg-red-50 hover:text-red-500"),children:n.jsx(gi,{size:11})})]},N.id)})})})]})]}):null}function VQ(t){if(typeof window>"u"||!t)return Zu;try{const e=window.localStorage.getItem(t);return zH(e?JSON.parse(e):null)}catch{return Zu}}function zQ(t=MF,e=!0){const[s,o]=m.useState(()=>VQ(t));return m.useEffect(()=>{if(!(!e||!t)&&!(typeof window>"u"))try{window.localStorage.setItem(t,JSON.stringify(s))}catch{}},[s,t,e]),{panelWidth:s,setPanelWidth:o}}function $Q({viewportFrameRef:t,enabled:e=!0,panelWidth:s,setPanelWidth:o,position:r,setPosition:i}){const[a,l]=m.useState(!1),[c,d]=m.useState(!1),u=m.useRef(null),h=m.useCallback(M=>{M.button!==0||!e||(M.preventDefault(),M.stopPropagation(),M.currentTarget.setPointerCapture(M.pointerId),u.current={pointerId:M.pointerId,startClientX:M.clientX,startWidth:s,rightEdge:r.x+s},d(!0),document.body.style.cursor="col-resize",document.body.style.userSelect="none")},[e,s,r.x]),x=m.useCallback(M=>{const g=u.current;if(!g||g.pointerId!==M.pointerId)return;const w=M.clientX-g.startClientX,k=Math.max(hF,Math.min(mF,g.startWidth-w)),_=g.rightEdge-k,j=Qh(t.current);o(k),i(H3({x:_,y:r.y},j,k))},[r.y,o,i,t]),f=m.useCallback(M=>{var g;((g=u.current)==null?void 0:g.pointerId)===M.pointerId&&(u.current=null,d(!1),l(!1),document.body.style.cursor="",document.body.style.userSelect="")},[]),p=m.useCallback(M=>{f(M)},[f]);return{resizeEdgeHover:a,resizing:c,resizeEdgeProps:{onPointerEnter:()=>l(!0),onPointerLeave:()=>{u.current||l(!1)},onPointerDown:h,onPointerMove:x,onPointerUp:p,onPointerCancel:p}}}function XQ({entry:t,fpIsDark:e,isLocked:s,isOpen:o,content:r,onOpenChange:i,sectionRef:a}){const{t:l,i18n:c}=yn(),{attributes:d,listeners:u,setActivatorNodeRef:h,setNodeRef:x,transform:f,transition:p,isDragging:b}=LN({id:t.id}),M=t.icon;return n.jsx("div",{ref:x,style:{transform:WN.Transform.toString(f),transition:p},className:O(b&&"relative z-20"),children:n.jsx(YI,{open:s?!1:o,onOpenChange:g=>{s||i(g)},children:n.jsxs("section",{ref:a,"data-testid":`floorplan-detail
444s-section-${t.id}`,className:O("overflow-hidden rounded-lg border scroll-mt-2",e?"border-white/10 bg-white/[0.04]":"border-[#182137]/10 bg-white/75",s&&"opacity-45",b&&"shadow-[0_12px_28px_rgba(24,33,55,0.18)]"),children:[n.jsxs("div",{className:"flex h-11 w-full items-stretch",children:[n.jsx("button",{type:"button",ref:h,"aria-label":l("details.dragReorder",{defaultValue:"גרור לסידור"}),title:l("details.dragSection",{defaultValue:"גרור למעלה או למטה — {{label}}",label:l(t.labelKey,{defaultValue:t.labelFallback})}),"data-testid":`floorplan-details-section-drag-${t.id}`,className:O("touch-none flex w-8 shrink-0 cursor-grab items-center justify-center transition-colors active:cursor-grabbing",e?"text-white/45 hover:bg-white/[0.08] hover:text-white/75":"text-[#182137]/40 hover:bg-[#E8DFD3] hover:text-[#182137]/70"),...d,...u,onPointerDown:g=>{var w;g.stopPropagation(),(w=u==null?void 0:u.onPointerDown)==null||w.call(u,g)},children:n.jsx(RN,{size:14,"aria-hidden":!0})}),n.jsx(GI,{asChild:!0,children:n.jsxs("button",{type:"button","data-testid":`floorplan-details-section-header-${t.id}`,disabled:s,title:s?l("details.closeSketchTool",{defaultValue:"סגור כלי סקיצה כדי לערוך"}):void 0,className:O("flex min-w-0 flex-1 items-center justify-start gap-2 px-2 text-[13px] font-semibold transition-colors",e?"bg-white/[0.04] text-white/90 hover:bg-white/[0.08]":"bg-[#E8DFD3]/70 text-[#182137] hover:bg-[#E8DFD3]",s&&"cursor-not-allowed hover:bg-transparent"),children:[n.jsx(M,{size:15,"aria-hidden":!0,className:O("shrink-0",e?"text-white/58":"text-[#182137]/54")}),n.jsx("span",{className:O("min-w-0 flex-1",c.dir()==="rtl"?"text-right":"text-left"),children:l(t.labelKey,{defaultValue:t.labelFallback})}),n.jsx(Yc,{size:14,className:O("shrink-0 transition-transform",o&&!s?"":"rotate-90",e?"text-white/62":"text-[#182137]/62")})]})})]}),n.jsx(UI,{children:n.jsx("div",{className:O(e?"bg-[#141416]":"bg-white/85"),children:r})})]})})})}function YQ({open:t,onClose:e,onShowPanel:s,viewportFrameRef:o,fpIsDark:r,mainView:i,viewScope:a,sectionVisibility:l,onSectionVisibilityChange:c,sectionOrder:d,onSectionOrderChange:u,sectionContents:h,sectionPresentation:x,sectionsOpen:f,onSectionsOpenChange:p,sketchToolActive:b,blankSketchSession:M=!1,scrollSectionIntoView:g}){const{t:w,i18n:k}=yn(),{panelWidth:_,setPanelWidth:j}=zQ(MF,t),{position:v,setPosition:C,ready:N,headerProps:P}=B3({viewportFrameRef:o,storageKey:VH,enabled:!0,panelWidth:_}),{resizeEdgeHover:L,resizing:A,resizeEdgeProps:W}=$Q({viewportFrameRef:o,enabled:t,panelWidth:_,setPanelWidth:j,position:v,setPosition:C}),S=DN(KM(IN,{activationConstraint:{distance:6}}),KM(NN,{activationConstraint:{distance:6}}),KM(CN,{coordinateGetter:FN})),B=(G,Y)=>p(Y?Tp(G):lk()),R=m.useRef({});m.useEffect(()=>{if(!g)return;const G=R.current[g.id];if(!G)return;const Y=window.setTimeout(()=>{G.scrollIntoView({behavior:"smooth",block:"nearest"})},60);return()=>window.clearTimeout(Y)},[g]);const z=m.useMemo(()=>b6(vm,d),[d]),X=m.useMemo(()=>{const G=[];for(const Y of z){if(Y.standalone===!1||!p6(Y,i,a)||!(Y.id===Vb)&&!l[Y.id])continue;const Mt=h[Y.id];Mt!=null&&G.push(Y)}return G},[z,i,a,l,h]),ft=m.useMemo(()=>X.map(G=>G.id),[X]),tt=G=>{const{active:Y,over:J}=G;!J||Y.id===J.id||u(lQ(d,Y.id,J.id,ft))};return t?n.jsxs("div",{dir:k.dir(),"data-testid":"floorplan-details-panel",className:O("absolute z-30 flex min-h-0 flex-col overflow-hidden rounded-2xl border text-start shadow-[0_18px_50px_rgba(24,33,55,0.20)]",r?"border-white/[0.10] bg-[#141416] text-white":"border-[#182137]/14 bg-[#F7F4EF] text-[#182137]"),style:{left:v.x,top:v.y,width:_,maxWidth:"calc(100% - 24px)",maxHeight:"calc(100% - 24px)",visibility:N?"visible":"hidden",pointerEvents:N?"auto":"none"},children:[n.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":w("details.resizePanel",{defaultValue:"שנה רוחב לוח צד"}),title:w("details.dragLeftToExpand",{defaultValue:"גרור שמאלה להרחבה"}),"data-testid":"floorplan-details-panel-resize-edge",className:O("absolute bottom-0 left-0 top-0 z-40 w-2.5 touch-none cursor-col-resize",(L||A)&&(r?"bg-[#EC7357]/20":"bg-[#EC7357]/15")),...W,children:n.jsx("div",{className:O("pointer-events-none absolute left-1/2 top-1/2 flex h-10 w-5 -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full border shadow-sm transition-opacity",r?"border-white/20 bg-[#141416] text-[#EC7357]":"border-[#182137]/12 bg-white text-[#D85D43]",L||A?"opacity-100":"opacity-0"),children:n.jsx(_1,{size:14,strokeWidth:2.5,"aria-hidden":!0})})}),n.jsxs("div",{className:O("flex shrink-0 cursor-move items-center justify-between border-b px-3.5 py-3",r?"border-white/10":"border-[#182137]/12"),...P,children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[n.jsx(M6,{mainView:i,viewScope:a,sectionVisibility:l,sectionOrder:d,onSectionVisibilityChange:c,onShowPanel:s,fpIsDark:r,allowTogglePinnedSection:M,children:n.jsx("button",{type:"button","aria-label":w("details.categories",{defaultValue:"קטגוריות במאפיינים"}),title:w("details.categoriesHint",{defaultValue:"קטגוריות במאפיינים — בחר מה יוצג בלוח"}
444),"data-testid":"floorplan-details-section-visibility-trigger",onPointerDown:G=>G.stopPropagation(),className:O("flex h-8 w-8 shrink-0 items-center justify-center rounded-md transition-colors",r?"text-white/70 hover:bg-white/10 hover:text-white":"text-[#182137]/70 hover:bg-[#E8DFD3] hover:text-[#182137]"),children:n.jsx(oE,{size:16})})}),n.jsxs("div",{className:"min-w-0",children:[n.jsx("p",{className:O("text-[10px] font-medium",r?"text-white/55":"text-[#182137]/58"),children:w("details.sidePanel",{defaultValue:"לוח צד"})}),n.jsx("h2",{className:"truncate text-[15px] font-semibold leading-tight",children:w("details.properties",{defaultValue:"מאפיינים"})})]})]}),n.jsx("button",{type:"button","aria-label":w("details.collapsePanel",{defaultValue:"כווץ לוח"}),title:w("details.collapsePanel",{defaultValue:"כווץ לוח"}),"data-testid":"floorplan-details-panel-collapse",onClick:e,onPointerDown:G=>G.stopPropagation(),className:O("flex h-8 w-8 items-center justify-center rounded-md transition-colors",r?"text-white/70 hover:bg-white/10 hover:text-white":"text-[#182137]/70 hover:bg-[#E8DFD3] hover:text-[#182137]"),children:n.jsx(_1,{size:16})})]}),n.jsx("div",{className:O("min-h-0 flex-1 space-y-2 overflow-y-auto p-2",r?"bg-[#141416]":"bg-[#FAF8F5]/60"),children:n.jsx(TN,{sensors:S,collisionDetection:SN,onDragEnd:tt,children:n.jsx(PN,{items:ft,strategy:AN,children:X.map(G=>{const Y=b&&G.sketchSoftLock,J=f[G.id],Mt=h[G.id];return n.jsx(XQ,{entry:x!=null&&x[G.id]?{...G,...x[G.id]}:G,fpIsDark:r,isLocked:Y,isOpen:J,content:Mt,onOpenChange:Rt=>B(G.id,Rt),sectionRef:Rt=>{R.current[G.id]=Rt}},G.id)})})})})]}):n.jsx("button",{type:"button",dir:k.dir(),"aria-label":w("details.showProperties",{defaultValue:"הצג מאפיינים"}),title:w("details.showProperties",{defaultValue:"הצג מאפיינים"}),"data-testid":"floorplan-details-panel-reopen",onClick:s,className:O("absolute z-30 flex h-9 w-9 items-center justify-center rounded-md border shadow-[0_4px_12px_rgba(24,33,55,0.10)] transition-colors","rounded-r-none border-r-0",r?"border-white/15 bg-[#141416] text-white hover:bg-white/10":"border-[#182137]/15 bg-[#F7F4EF] text-[#182137] hover:bg-[#E8DFD3]"),style:{right:O3,top:v.y,visibility:N?"visible":"hidden",pointerEvents:N?"auto":"none"},children:n.jsx(KI,{className:"h-4 w-4",strokeWidth:1.8})})}function j6(t,e){return t.filter(s=>s.kind==="polygon"&&s.groupId===e)}function GQ(t){return(Math.atan2(t.y,t.x)*180/Math.PI%180+180)%180}function UQ(t,e){const s=Math.abs(t-e)%180;return Math.min(s,180-s)}function KQ(t){const e=[];for(const s of t){if(s.vertices.length!==4)continue;const o=Xr(s.vertices);if(!o)continue;const r=Math.max(1,o.lengthMm*o.widthMm),i=GQ(o.uAxis),a=e.find(l=>UQ(l.angleDeg,i)<1.5);if(a){a.weight+=r;continue}e.push({angleDeg:i,weight:r,uAxis:o.uAxis,vAxis:o.vAxis})}return e.length===0?{uAxis:{x:1,y:0},vAxis:{x:0,y:1}}:(e.sort((s,o)=>o.weight-s.weight),{uAxis:e[0].uAxis,vAxis:e[0].vAxis})}function Zg(t,e){const s=j6(t,e);if(s.length===0)return null;const{uAxis:o,vAxis:r}=KQ(s);let i=1/0,a=-1/0,l=1/0,c=-1/0,d=1/0,u=-1/0;for(const f of s){for(const b of f.vertices){const M=b.x*o.x+b.y*o.y,g=b.x*r.x+b.y*r.y;i=Math.min(i,M),a=Math.max(a,M),l=Math.min(l,g),c=Math.max(c,g)}const p=f.baseHeightMm??0;d=Math.min(d,p),u=Math.max(u,p+Math.max(0,f.heightMm??0))}if(!Number.isFinite(i)||!Number.isFinite(l))return null;Number.isFinite(d)||(d=0),Number.isFinite(u)||(u=d);const h=(i+a)/2,x=(l+c)/2;return{center:{x:h*o.x+x*r.x,y:h*o.y+x*r.y},uAxis:o,vAxis:r,widthMm:Math.round(a-i),depthMm:Math.round(c-l),heightMm:Math.round(Math.max(0,u-d)),baseHeightMm:Math.round(d),polygonIds:s.map(f=>f.id)}}function ZQ(t,e,s,o){if(t==="top"||t==="bottom")return o;const r=/^side-(\d+)$/.exec(t);return r?Number(r[1])%2===0?s:e:s}function qQ(t,e,s,o,r,i,a){var M;if(!Number.isFinite(o)||!Number.isFinite(r)||!Number.isFinite(i)||Math.abs(o-1)<1e-4&&Math.abs(r-1)<1e-4&&Math.abs(i-1)<1e-4)return t;const{center:l,uAxis:c,vAxis:d,baseHeightMm:u}=s,h=l.x*d.x+l.y*d.y+(a!=null&&a.anchorBackFace?s.depthMm/2:0),x=l.x*c.x+l.y*c.y,f=g=>{const w=x+(g.x*c.x+g.y*c.y-x)*o,k=h+(g.x*d.x+g.y*d.y-h)*r;return{x:Math.round(w*c.x+k*d.x),y:Math.round(w*c.y+k*d.y)}},p=new Map,b=new Map;for(const g of j6(t,e)){const w=g.baseHeightMm??0,k={...g,vertices:g.vertices.map(f),holes:(M=g.holes)==null?void 0:M.map(_=>_.map(f)),...g.heightMm!==void 0?{heightMm:Math.max(1,Math.round(g.heightMm*i))}:{},...g.baseHeightMm!==void 0?{baseHeightMm:Math.max(0,Math.round(u+(w-u)*i))}:{}};p.set(g.id,g),b.set(g.id,k)}return b.size===0?t:t.map(g=>{const w=b.get(g.id);if(w)return w;if(g.kind!=="facePatch")return g;const k=p.get(g.hostEntityId),_=b.get(g.hostEntityId);if(!k||!_)return g;const j=kD(g,k,_);if(g.depthMm===void 0)return j;const v=ZQ(g.hostFaceId,o,r,i);return{...j,depthMm:Math.round(g.depthMm*v)}})}const c_=200,d_=100,u_=100;function JQ({visible:t,stage:e}){const{t:s,i18n:o}=yn();if(!t||!e)return null;const r=e==="enhancing";return n.jsx("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm animate-[fadeIn_0.3s_ease-out]",children:n.jsxs("div",{className:"flex flex-col items-center gap-5 bg-white/95 rounded-2xl px-10 py-8 shadow-2xl animate-[scaleIn_0.3s_ease-out]",children:[n.jsxs("div",{className:"relative w-20 h-20",children:[n.jsx("div",{className:"absolute inset-0 rounded-full border-4 border-transparent animate-spin",style:{borderTopColor:r?"#10b981":"#6b7280",borderRightColor:r?"#10b98140":"#6b728040",animationDuration:"1.2s"}}),n.jsx("div",{className:"absolute inset-2 rounded-full border-4 border-transparent animate-spin",style:{borderBottomColor:r?"#059669":"#4b5563",borderLeftColor:r?"#05966940":"#4b556340",animationDuration:"0.9s",animationDirection:"reverse"}}),n.jsx("div",{className:"absolute inset-5 rounded-full animate-pulse",style:{backgroundColor:r?"#10b98130":"#6b728030"}}),n.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:n.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:r?"#10b981":"#6b7280",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:r?n.jsxs(n.Fragment,{children:[n.jsx("path",{d:"M12 3l1.5 4.5L18 9l-4.5 1.5L12 15l-1.5-4.5L6 9l4.5-1.5z"}),n.jsx("path",{d:"M18 15l1 3 3 1-3 1-1 3-1-3-3-1 3-1z",opacity:"0.5"})]}):n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),n.jsx("line",{x1:"3",y1:"12",x2:"21",y2:"12",className:"animate-pulse"})]})})})]}),n.jsxs("div",{className:"text-center",dir:o.dir(),children:[n.jsx("h3",{className:"text-base font-semibold text-gray-800",children:r?s("scanningOverlay.enhancingTitle",{defaultValue:"משפר את התוכנית עם AI..."}):s("scanningOverlay.scanningTitle",{defaultValue:"סורק קירות..."})}),n.jsx("p",{className:"text-sm text-gray-500 mt-1",children:r?s("scanningOverlay.enhancingDescription",{defaultValue:"מנקה קווים ומסמן קירות בצבעים — כ-30 שניות"}):s("scanningOverlay.scanningDescription",{defaultValue:"מזהה קירות בתוכנית..."})})]}),n.jsx("div",{className:"w-48 h-1.5 bg-gray-200 rounded-full overflow-hidden",children:n.jsx("div",{className:"h-full rounded-full animate-[progressSlide_2s_ease-in-out_infinite]",style:{backgroundColor:r?"#10b981":"#6b7280",width:"40%"}})})]})})}function QQ({className:t}){return n.jsxs("svg",{viewBox:"0 0 24 24",className:t,fill:"none","aria-hidden":!0,
444children:[n.jsx("path",{d:"M4.5 6.5h15v13h-15z",fill:"#F7F4EF",stroke:"currentColor",strokeWidth:"1.5"}),n.jsx("path",{d:"M7 3.5h10v3H7z",fill:"#E8DFD3",stroke:"currentColor",strokeWidth:"1.3"}),n.jsx("path",{d:"M8 10h8M8 14h8",stroke:"#D85D43",strokeWidth:"1.4",strokeLinecap:"round"}),n.jsx("path",{d:"M12 7v12",stroke:"currentColor",strokeWidth:"1",opacity:".65"})]})}function ttt({template:t}){const e=m.useMemo(()=>{const s=Yf(t.payload);if(!s)return[];const o=[],r=(h,x,f)=>({x:(h-x)*.72,y:(h+x)*.34-f*.7});for(const h of s.entities){if(h.kind!=="polygon"||h.vertices.length<3)continue;const x=h.baseHeightMm??0,f=x+Math.max(20,h.heightMm??0);for(let p=0;p<h.vertices.length;p+=1){const b=h.vertices[p],M=h.vertices[(p+1)%h.vertices.length];o.push({key:`${h.id}-side-${p}`,kind:"side",points:[r(b.x,b.y,x),r(M.x,M.y,x),r(M.x,M.y,f),r(b.x,b.y,f)]})}o.push({key:`${h.id}-top`,kind:"top",points:h.vertices.map(p=>r(p.x,p.y,f))})}if(o.length===0)return[];const i=o.flatMap(h=>h.points),a=Math.min(...i.map(h=>h.x)),l=Math.max(...i.map(h=>h.x)),c=Math.min(...i.map(h=>h.y)),d=Math.max(...i.map(h=>h.y)),u=Math.min(50/Math.max(1,l-a),68/Math.max(1,d-c));return o.map(h=>({...h,points:h.points.map(x=>({x:5+(x.x-a)*u,y:6+(x.y-c)*u}))}))},[t]);return n.jsx("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:e.length>0?e.map(s=>n.jsx("polygon",{points:s.points.map(o=>`${o.x},${o.y}`).join(" "),fill:s.kind==="top"?"#F7F4EF":"#E8DFD3",stroke:s.kind==="top"?"#182137":"#D85D43",strokeWidth:s.kind==="top"?1.15:.65,strokeLinejoin:"round"},s.key)):n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"11",y:"15",width:"38",height:"54",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("path",{d:"M18 24h24M18 34h24M18 44h24M18 54h24",stroke:"#D85D43",strokeWidth:"1"})]})})}function ett({templates:t,loading:e,error:s,query:o,fpIsDark:r,selectedTemplateId:i,canSaveSelected:a,canSaveAll:l,defaultName:c,onSave:d,onUse:u,onRename:h,onDelete:x}){const{t:f,i18n:p}=yn(),[b,M]=m.useState(""),[g,w]=m.useState(!1),[k,_]=m.useState(!1),[j,v]=m.useState(c),[C,N]=m.useState(a?"selected":"all"),[P,L]=m.useState("both"),[A,W]=m.useState(null),[S,B]=m.useState(!1),R=(o??b).trim().toLowerCase(),z=t.filter(J=>!R||J.name.toLowerCase().includes(R)),X=o===void 0&&t.length>4,ft=()=>{N(a?"selected":"all"),v(c.trim()||f("myTemplates.defaultName",{defaultValue:"תבנית אישית"})),L("both"),w(!0)},tt=async()=>{if(j.trim()){_(!0);try{await d({name:j.trim(),scope:C,placementMode:P}),w(!1),ln.success(f("myTemplates.saved",{defaultValue:"התבנית נשמרה ב׳התבניות שלי׳"}))}catch(J){ln.error(J instanceof Error?J.message:f("myTemplates.saveFailed",{defaultValue:"שמירת התבנית נכשלה"}))}finally{_(!1)}}},G=(J,Mt)=>{J.dataTransfer.setData(ob,q4(Mt)),J.dataTransfer.effectAllowed="copy"},Y=async()=>{if(A){B(!0);try{await x(A.id),W(null)}catch(J){ln.error(J instanceof Error?J.message:f("myTemplates.deleteFailed",{defaultValue:"מחיקת התבנית נכשלה"}))}finally{B(!1)}}};return n.jsxs(n.Fragment,{children:[n.jsxs("section",{className:"space-y-2","data-testid":"floorplan-my-templates",children:[n.jsxs("div",{className:"mb-1 flex items-center gap-2 px-0.5",children:[n.jsx(QQ,{className:"h-4 w-4 shrink-0 text-[#D85D43]"}),n.jsx("span",{className:O("text-[11px] font-bold",r?"text-white/55":"text-[#182137]/55"),children:f("myTemplates.savedCount",{count:t.length,defaultValue:`${t.length} שמורות`})})]}),n.jsxs("button",{type:"button",onClick:ft,disabled:!a&&!l,className:O("flex min-h-11 w-full items-center justify-center gap-2 rounded-[5px] border border-[#B9412A] bg-[#D85D43] px-3 text-[12px] font-black text-[#F7F4EF] shadow-[0_3px_0_#A63D2A] transition-[transform,background-color,box-shadow] hover:-translate-y-0.5 hover:bg-[#C94E35] active:translate-y-[2px] active:shadow-[0_1px_0_#A63D2A] disabled:cursor-not-allowed disabled:opacity-45"),children:[n.jsx(pm,{className:"h-4 w-4",strokeWidth:2.6}),f("myTemplates.saveAsMine",{defaultValue:"שמור כתבנית שלי"})]}),X?n.jsx("input",{value:b,onChange:J=>M(J.target.value),placeholder:f("myTemplates.searchPlaceholder",{defaultValue:"חיפוש בתבניות שלי…"}),"aria-label":f("myTemplates.searchAria",{defaultValue:"חיפוש בתבניות שלי"}),className:O("h-9 w-full rounded-[3px] border px-2.5 text-[12px] font-bold outline-none",r?"border-white/12 bg-[#0A0A0A] text-white placeholder:text-white/35 focus:border-[#
444EC7357]":"border-[#182137]/12 bg-white text-[#182137] placeholder:text-[#182137]/35 focus:border-[#D85D43]")}):null,s?n.jsx("p",{className:"text-[10px] font-bold text-red-600",children:s}):null,e?n.jsxs("div",{className:O("flex items-center justify-center gap-2 py-5 text-[11px] font-bold",r?"text-white/50":"text-[#182137]/50"),children:[n.jsx(Xa,{className:"h-4 w-4 animate-spin"})," ",f("myTemplates.loading",{defaultValue:"טוען תבניות…"})]}):z.length>0?n.jsx("div",{className:"grid grid-cols-2 gap-2",children:z.map(J=>{const Mt=q4(J.id),Rt=i===Mt;return n.jsxs("div",{className:"relative min-w-0",children:[n.jsxs("button",{type:"button",onClick:()=>u(J),draggable:!0,onDragStart:it=>G(it,J.id),"aria-pressed":Rt,className:O("flex w-full cursor-grab flex-col items-center gap-1 rounded-[4px] border p-1.5 pb-2 transition-colors active:cursor-grabbing",Rt?"border-[#D85D43] bg-[#FDF1EC] shadow-[0_0_0_1px_rgba(216,93,67,0.2)]":r?"border-white/12 bg-[#0A0A0A] hover:bg-white/[0.06]":"border-[#182137]/12 bg-[#F7F4EF] hover:bg-[#E8DFD3]"),title:f("myTemplates.selectHint",{defaultValue:"לחיצה לבחירה · גרירה למיקום מדויק"}),children:[Rt?n.jsx("span",{className:"absolute start-1.5 top-1.5 flex h-5 w-5 items-center justify-center rounded-full bg-[#D85D43] text-[#F7F4EF]",children:n.jsx(Gc,{className:"h-3 w-3",strokeWidth:3})}):null,n.jsx(ttt,{template:J}),n.jsx("span",{className:O("line-clamp-2 text-center text-[10.5px] font-black leading-tight",r?"text-white":"text-[#182137]"),children:J.name}),n.jsx("span",{className:O("text-[9px] font-bold",r?"text-white/40":"text-[#182137]/45"),children:J.placement_mode==="floor"?f("myTemplates.placement.floor",{defaultValue:"רצפה"}):J.placement_mode==="wall"?f("myTemplates.placement.wall",{defaultValue:"קיר"}):f("myTemplates.placement.both",{defaultValue:"רצפה או קיר"})})]}),n.jsxs("div",{className:"absolute end-1 top-1 flex gap-0.5",children:[n.jsx("button",{type:"button",className:"flex h-7 w-7 items-center justify-center rounded-[4px] border border-[#182137]/10 bg-[#F7F4EF]/95 text-[#182137] shadow-sm hover:bg-[#E8DFD3]",title:f("myTemplates.rename",{defaultValue:"שינוי שם"}),"aria-label":f("myTemplates.renameNamed",{name:J.name,defaultValue:`שינוי שם ${J.name}`}),onClick:it=>{it.stopPropagation();const st=window.prompt(f("myTemplates.newNamePrompt",{defaultValue:"שם חדש לתבנית"}),J.name);st&&st.trim()&&st.trim()!==J.name&&h(J.id,st).catch(ct=>ln.error(ct instanceof Error?ct.message:f("myTemplates.renameFailed",{defaultValue:"שינוי השם נכשל"})))},children:n.jsx(mp,{className:"h-3 w-3"})}),n.jsx("button",{type:"button",className:"flex h-7 w-7 items-center justify-center rounded-[4px] border border-red-200 bg-[#F7F4EF]/95 text-red-600 shadow-sm hover:bg-red-50",title:f("myTemplates.delete",{defaultValue:"מחיקת תבנית"}),"aria-label":f("myTemplates.deleteNamed",{name:J.name,defaultValue:`מחיקת ${J.name}`}),onClick:it=>{it.stopPropagation(),W(J)},children:n.jsx(gi,{className:"h-3 w-3"})})]})]},J.id)})}):n.jsx("p",{className:O("py-4 text-center text-[10px] font-bold",r?"text-white/42":"text-[#182137]/45"),children:R?f("myTemplates.noResults",{defaultValue:"לא נמצאו תבניות אישיות"}):f("myTemplates.empty",{defaultValue:"התבניות שתשמור יופיעו כאן בכל פרויקט"})})]}),n.jsx(L_,{open:g,onOpenChange:J=>!k&&w(J),children:n.jsxs(W_,{dir:p.dir(),className:"max-w-[430px] gap-5 rounded-[14px] border-[#182137]/15 bg-[#F7F4EF] p-5 font-heebo text-[#182137] shadow-2xl",children:[n.jsxs(ON,{className:"space-y-1 text-start sm:text-start",children:[n.jsx(R_,{className:"text-[24px] font-black tracking-[-0.035em]",children:f("myTemplates.saveDialog.title",{defaultValue:"שמירה בתבניות שלי"})}),n.jsx(HN,{className:"text-start text-[12px] font-medium text-[#182137]/55",children:f("myTemplates.saveDialog.description",{defaultValue:"התבנית תישמר כמודל חי וניתן לעריכה, ותופיע בכל פרויקט Floorplan."})})]}),n.jsxs("label",{className:"space-y-1.5",children:[n.jsx("span",{className:"text-[11px] font-black",children:f("myTemplates.saveDialog.name",{defaultValue:"שם התבנית"})}),n.jsx("input",{value:j,onChange:J=>v(J.target.value.slice(0,80)),autoFocus:!0,className:"h-11 w-full rounded-[6px] border border-[#182137]/15 bg-white/70 px-3 text-[13px] font-bold outline-none focus:border-[#D85D43] focus:ring-2 focus:ring-[#D85D43]/15",placeholder:f("myTemplates.saveDialog.namePlaceholder",{defaultValue:"לדוגמה: יחידת כניסה אישית"})})]}),n.jsxs("fieldset",{className:"space-y-2",children:[n.jsx("legend",{className:"text-[11px] font-black",children:f("myTemplates.saveDialog.scope",{defaultValue:"מה לשמור?"})}),n.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[n.jsx(h_,{active:C==="selected",disabled:!a,label:f("myTemplates.saveDialog.selectedModel",{defaultValue:"המודל שנבחר"}),helper:f("myTemplates.saveDialog.selectedModelHint",{defaultValue:"הקבוצה והחלקים שלה"}),onClick:()=>N("selected")}),n.jsx(h_,{active:C==="all",disabled:!l,label:f("myTemplates.saveDialog.allModel",{defaultValue:"כל המודל בקנבס"}),helper:f("myTemplates.saveDialog.allModelHint",{defaultValue:"כל הגופים, בלי מידות"}),onClick:()=>N("all")})]})]}),n.jsxs("fieldset",{className:"space-y-2",children:[n.jsx("legend",{className:"text-[11px] font-black",children:f("myTemplates.saveDialog.placement",{defaultValue:"אופן הצבה"})}),n.jsx("div",{className:"grid grid-cols-3 gap-2",children:[{id:"both",label:f("myTemplates.placement.both",{defaultValue:"רצפה או קיר"})},{id:"floor",label:f("myTemplates.placement.floor",{defaultValue:"רצפה"})},{id:"wall",label:f("myTemplates.placement.wall",{defaultValue:"קיר"})}].map(J=>n.jsx("button",{type:"button",onClick:()=>L(J.id),className:O("min-h-11 rounded-[5px] border px-2 text-[11px] font-black transition-colors",P===J.id?"border-[#D85D43] bg-[#D85D43] text-[#F7F4EF] shadow-[0_2px_0_#A63D2A]":"border-[#182137]/12 bg-white/60 text-[#182137] hover:bg-[#
444E8DFD3]"),children:J.label},J.id))})]}),n.jsxs(BN,{className:"flex-row gap-2 sm:flex-row sm:space-x-0",children:[n.jsxs("button",{type:"button",onClick:()=>void tt(),disabled:k||!j.trim()||(C==="selected"?!a:!l),className:"flex min-h-11 flex-1 items-center justify-center gap-2 rounded-[6px] border border-[#B9412A] bg-[#D85D43] px-4 text-[12px] font-black text-[#F7F4EF] shadow-[0_3px_0_#A63D2A] hover:bg-[#C94E35] active:translate-y-[2px] active:shadow-[0_1px_0_#A63D2A] disabled:opacity-45",children:[k?n.jsx(Xa,{className:"h-4 w-4 animate-spin"}):null,k?f("myTemplates.saveDialog.saving",{defaultValue:"שומר…"}):f("myTemplates.saveDialog.save",{defaultValue:"שמור בתבניות שלי"})]}),n.jsx("button",{type:"button",onClick:()=>w(!1),disabled:k,className:"min-h-11 rounded-[6px] border border-[#182137]/15 bg-[#E8DFD3] px-4 text-[12px] font-black text-[#182137] shadow-[0_2px_0_rgba(24,33,55,0.12)]",children:f("common.cancel",{defaultValue:"ביטול"})})]})]})}),n.jsx(Fw,{open:!!A,onOpenChange:J=>{!J&&!S&&W(null)},children:n.jsxs(Cw,{dir:p.dir(),"data-testid":"floorplan-template-delete-dialog",className:"max-w-[430px] gap-5 rounded-[14px] border-[#182137]/15 bg-[#F7F4EF] p-5 font-heebo text-[#182137] shadow-2xl",children:[n.jsxs(Nw,{className:"space-y-2 text-start sm:text-start",children:[n.jsx("div",{className:"flex h-11 w-11 items-center justify-center rounded-[10px] border border-[#D85D43]/25 bg-[#FDF1EC] text-[#D85D43] shadow-[0_2px_0_rgba(168,61,42,0.12)]",children:n.jsx(gi,{className:"h-5 w-5",strokeWidth:2.2})}),n.jsx(Iw,{className:"text-[24px] font-black tracking-[-0.035em]",children:f("myTemplates.deleteDialog.title",{defaultValue:"למחוק את התבנית?"})}),n.jsx(Tw,{className:"text-start text-[13px] font-medium leading-6 text-[#182137]/60",children:f("myTemplates.deleteDialog.description",{name:(A==null?void 0:A.name)??"",defaultValue:`התבנית ״${(A==null?void 0:A.name)??""}״ תימחק לצמיתות מהתבניות שלי.`})})]}),n.jsxs(Sw,{className:"flex-row gap-2 sm:flex-row sm:space-x-0",children:[n.jsx(Aw,{onClick:J=>{J.preventDefault(),Y()},disabled:S,className:"min-h-11 flex-1 rounded-[6px] border border-[#B9412A] bg-[#D85D43] px-4 text-[12px] font-black text-[#F7F4EF] shadow-[0_3px_0_#A63D2A] hover:bg-[#C94E35] focus:ring-[#D85D43]/30 active:translate-y-[2px] active:shadow-[0_1px_0_#A63D2A] disabled:cursor-wait disabled:opacity-60",children:S?f("myTemplates.deleteDialog.deleting",{defaultValue:"מוחק…"}):f("myTemplates.deleteDialog.confirm",{defaultValue:"כן, למחוק"})}),n.jsx(Pw,{disabled:S,className:"min-h-11 rounded-[6px] border border-[#182137]/15 bg-[#E8DFD3] px-4 text-[12px] font-black text-[#182137] shadow-[0_2px_0_rgba(24,33,55,0.12)] hover:bg-[#DDD5C9]",children:f("common.cancel",{defaultValue:"ביטול"})})]})]})})]})}function h_({active:t,disabled:e,label:s,helper:o,onClick:r}){return n.jsxs("button",{type:"button",disabled:e,onClick:r,className:O("min-h-[64px] rounded-[6px] border p-2 text-start transition-colors disabled:cursor-not-allowed disabled:opacity-35",t?"border-[#D85D43] bg-[#FDF1EC] shadow-[inset_0_0_0_1px_rgba(216,93,67,0.16)]":"border-[#182137]/12 bg-white/60 hover:bg-[#E8DFD3]"),children:[n.jsx("span",{className:"block text-[11px] font-black",children:s}),n.jsx("span",{className:"mt-0.5 block text-[9px] font-bold text-[#182137]/48",children:o})]})}function Xh({kind:t}){const e={stroke:"#182137",strokeWidth:1.2,fill:"#F7F4EF"},s={fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:.6},o="#182137";return t==="base"?n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"2",y:"6",width:"56",height:"68",...e}),n.jsx("rect",{x:"5",y:"9",width:"50",height:"9",...s}),n.jsx("circle",{cx:"30",cy:"13.5",r:"0.7",fill:o}),n.jsx("rect",{x:"5",y:"21",width:"24.5",height:"50",...s}),n.jsx("rect",{x:"30.5",y:"21",width:"24.5",height:"50",...s}),n.jsx("circle",{cx:"28",cy:"66",r:"0.8",fill:o}),n.jsx("circle",{cx:"32",cy:"66",r:"0.8",fill:o})]}):t==="wall"?n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,
444children:[n.jsx("rect",{x:"2",y:"18",width:"56",height:"44",...e}),n.jsx("rect",{x:"5",y:"21",width:"24.5",height:"38",...s}),n.jsx("rect",{x:"30.5",y:"21",width:"24.5",height:"38",...s}),n.jsx("circle",{cx:"28",cy:"55",r:"0.8",fill:o}),n.jsx("circle",{cx:"32",cy:"55",r:"0.8",fill:o})]}):t==="tall"?n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"14",y:"2",width:"32",height:"76",...e}),n.jsx("rect",{x:"17",y:"5",width:"26",height:"8",...s}),n.jsx("circle",{cx:"30",cy:"9",r:"0.7",fill:o}),n.jsx("rect",{x:"17",y:"16",width:"12.5",height:"59",...s}),n.jsx("rect",{x:"30.5",y:"16",width:"12.5",height:"59",...s}),n.jsx("circle",{cx:"28.5",cy:"72",r:"0.8",fill:o}),n.jsx("circle",{cx:"31.5",cy:"72",r:"0.8",fill:o})]}):t==="sinkBase"?n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"2",y:"6",width:"56",height:"68",...e}),n.jsx("rect",{x:"7",y:"11",width:"21",height:"10",fill:"#D7CFC1",stroke:"#182137",strokeWidth:"0.7",rx:"0.8"}),n.jsx("rect",{x:"32",y:"11",width:"21",height:"10",fill:"#D7CFC1",stroke:"#182137",strokeWidth:"0.7",rx:"0.8"}),n.jsx("circle",{cx:"17.5",cy:"16",r:"0.7",fill:o,opacity:"0.55"}),n.jsx("circle",{cx:"42.5",cy:"16",r:"0.7",fill:o,opacity:"0.55"}),n.jsx("rect",{x:"5",y:"24",width:"24.5",height:"47",...s}),n.jsx("rect",{x:"30.5",y:"24",width:"24.5",height:"47",...s}),n.jsx("circle",{cx:"28",cy:"66",r:"0.8",fill:o}),n.jsx("circle",{cx:"32",cy:"66",r:"0.8",fill:o})]}):t==="ovenTall"?n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"14",y:"2",width:"32",height:"76",...e}),n.jsx("rect",{x:"17",y:"5",width:"26",height:"14",...s}),n.jsx("circle",{cx:"30",cy:"12",r:"0.7",fill:o}),n.jsx("rect",{x:"17",y:"22",width:"26",height:"33",...s}),n.jsx("line",{x1:"21",y1:"27",x2:"39",y2:"27",stroke:"#182137",strokeWidth:"1.5",strokeLinecap:"round"}),n.jsx("rect",{x:"20",y:"31",width:"20",height:"22",fill:"#182137",opacity:"0.16"}),n.jsx("rect",{x:"17",y:"58",width:"26",height:"17",...s}),n.jsx("circle",{cx:"30",cy:"66.5",r:"0.7",fill:o})]}):n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"24",y:"6",width:"12",height:"20",...e}),n.jsx("polygon",{points:"20,26 40,26 52,52 8,52",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"13",y:"46",width:"34",height:"4",...s}),n.jsx("circle",{cx:"30",cy:"48",r:"0.7",fill:"#D85D43"})]})}function za({widthMm:t,heightMm:e,drawerCount:s,doorCount:o,mounted:r=!1,plinth:i=!1}){const a={stroke:"#182137",strokeWidth:1.2,fill:"#F7F4EF"},l={fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:.6},c={fill:"#DCD3C6",stroke:"#182137",strokeWidth:.5},d=Math.max(14,Math.min(56,t/600*44)),u=(60-d)/2,h=Math.max(28,Math.min(72,e/900*72)),x=r?(80-h)/2:78-h,f=2.5,p=u+f,b=d-f*2,M=x+f,g=h-f*2,w=i&&!r?Math.max(4,g*.06):0,k=g-w,_=s>0?o>0?Math.min(k-8,s*8):k:0,j=s>0?_/s:0,v=M+_,C=k-_,N=o>0?b/o:0;return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:u,y:x,width:d,height:h,...a}),w>0?n.jsx("rect",{x:p,y:M+g-w,width:b,height:w,...c}):null,Array.from({length:s}).map((P,L)=>n.jsx("rect",{x:p,y:M+L*j,width:b,height:Math.max(2,j-.8),...l},`d${L}`)),o>0&&C>4?Array.from({length:o}).map((P,L)=>n.jsx("rect",{x:p+L*N,y:v,width:Math.max(2,N-.8),height:C,...l},`o${L}`)):null]})}function ntt({compartments:t,widthMm:e,heightMm:s}){const o={stroke:"#182137",strokeWidth:1.2,fill:"#F7F4EF"},r={fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:.6},i={fill:"#DDD3C4",stroke:"#182137",strokeWidth:.5},a=Math.max(16,Math.min(52,e/1200*46+12)),l=(60-a)/2,c=74,d=78-c,u=2.2,h=l+u,x=a-u*2,f=s,p=t.reduce((k,_)=>k+(_.heightMm??0),0),b=t.filter(k=>k.heightMm===void 0).length,M=b>0?Math.max(0,(f-p)/b):0,g=[];let w=0;return t.forEach((k,_)=>{const j=k.heightMm??M,v=d+u+w/f*(c-u*2),C=d+u+(w+j)/f*(c-u*2);w+=j;const N=C-v;if(N<2)return;const P=1.4,L=h+P,A=x-P*2,W=`c${_}`;switch(k.kind){case"drawers":{const S=Math.max(1,k.count??3),B=(N-(S+1)*.8)/S;for(let R=0;R<S;R+=1)g.push(n.jsx("rect",{x:L,y:v+.8+R*(B+.8),width:A,height:Math.max(1.5,B),...r},`${W}d${R}`));break}case"doors":{const S=Math.max(1,k.count??2),B=(A-(S+1)*.8)/S;for(let R=0;R<S;R+=1)g.push(n.jsx("rect",{x:L+.8+R*(B+.8),y:v+.8,width:Math.max(1.5,B),height:N-1.6,...r},`${W}o${R}`));break}case"openShelves":case"shoe":{const S=Math.max(1,k.count??(k.kind==="shoe"?3:4)),B=(N-(S-1)*1.4)/S;for(let R=0;R<S;R+=1)g.push(n.jsx("rect",{x:L,y:v+R*(B+1.4),width:A,height:Math.max(1.2,B),...i},`${W}s${R}`));break}case"rail":{g.push(n.jsx("rect",{x:L,y:v,width:A,height:N,...i},`${W}v`));const S=v+Math.min(6,N*.18);g.push(n.jsx("line",{x1:L+1.5,y1:S,x2:L+A-1.5,y2:S,stroke:"#6B6558",strokeWidth:1.1},`${W}r`));break}case"appliance":{g.push(n.jsx("rect",{x:L,y:v,width:A,height:N,fill:"#3B3B3D",stroke:"#182137",strokeWidth:.5},`${W}n`));const S=L+A/2,B=v+N/2,R=Math.min(A,N)*.32;g.push(n.jsx("circle",{cx:S,cy:B,r:R,fill:"#C7CBD0",stroke:"#182137",strokeWidth:.4},`${W}dr`)),g.push(n.jsx("circle",{cx:S,cy:B,r:R*.6,fill:"#20262F"},`${W}g`));break}case"ironingSlot":{const S=Math.min(A*.6,8),B=L+(A-S)/2;g.push(n.jsx("rect",{x:B,y:v,width:S,height:N,...i},`${W}sl`)),g.push(n.jsx("rect",{x:B+S*.28,y:v+2,width:S*.44,height:N-4,fill:"#D8C7B0",stroke:"#182137",strokeWidth:.4},`${W}b`));break}}}),n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,
444children:[n.jsx("rect",{x:l,y:d,width:a,height:c,...o}),g]})}function ott(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("path",{d:"M 24 4 L 46 4 L 46 76 L 24 76 Q 16 76 16 68 L 16 12 Q 16 4 24 4 Z",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"25",y:"6",width:"9",height:"68",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"35",y:"6",width:"9",height:"68",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"})]})}function stt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("path",{d:"M 24 26 L 46 26 L 46 74 L 24 74 Q 16 74 16 68 L 16 32 Q 16 26 24 26 Z",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"25",y:"28",width:"19",height:"9",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"25",y:"39",width:"9",height:"33",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"35",y:"39",width:"9",height:"33",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"})]})}function rtt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("path",{d:"M 30 4 L 48 4 L 48 76 L 30 76 Q 12 76 12 58 L 12 22 Q 12 4 30 4 Z",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"32",y:"14",width:"14",height:"52",fill:"#C4BAA9",stroke:"#182137",strokeWidth:"0.7"}),n.jsx("line",{x1:"32",y1:"31",x2:"46",y2:"31",stroke:"#182137",strokeWidth:"0.7"}),n.jsx("line",{x1:"32",y1:"48",x2:"46",y2:"48",stroke:"#182137",strokeWidth:"0.7"})]})}function itt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("path",{d:"M 30 4 L 48 4 L 48 76 L 30 76 Q 12 76 12 58 L 12 22 Q 12 4 30 4 Z",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"32",y:"18",width:"14",height:"2.4",fill:"#DDD3C4",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("rect",{x:"32",y:"32",width:"14",height:"2.4",fill:"#DDD3C4",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("rect",{x:"32",y:"46",width:"14",height:"2.4",fill:"#DDD3C4",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("rect",{x:"32",y:"60",width:"14",height:"2.4",fill:"#DDD3C4",stroke:"#182137",strokeWidth:"0.5"})]})}function att(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("polygon",{points:"6,34 50,34 54,38 10,38",fill:"#E8E1D5",stroke:"#182137",strokeWidth:"0.9"}),n.jsx("rect",{x:"10",y:"38",width:"44",height:"7",fill:"#DDD3C4",stroke:"#182137",strokeWidth:"0.9"}),n.jsx("line",{x1:"16",y1:"36",x2:"26",y2:"36",stroke:"#182137",strokeWidth:"0.3",opacity:"0.4"}),n.jsx("line",{x1:"34",y1:"36",x2:"46",y2:"36",stroke:"#182137",strokeWidth:"0.3",opacity:"0.4"})]})}function ltt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"6",y:"20",width:"48",height:"7",fill:"#2A2B30",stroke:"#182137",strokeWidth:"1"}),n.jsx("circle",{cx:"18",cy:"23.5",r:"1.6",fill:"#9AA0A6"}),n.jsx("circle",{cx:"30",cy:"23.5",r:"1.6",fill:"#9AA0A6"}),n.jsx("circle",{cx:"42",cy:"23.5",r:"1.6",fill:"#9AA0A6"}),n.jsx("rect",{x:"6",y:"27",width:"48",height:"45",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"9",y:"30",width:"42",height:"8",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"9",y:"40",width:"42",height:"13",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"9",y:"55",width:"42",height:"14",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"})]})}function ctt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"16",y:"4",width:"28",height:"72",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"18",y:"6",width:"24",height:"17",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"18",y:"26",width:"18",height:"14",fill:"#2A2B30",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("rect",{x:"37",y:"26",width:"5",height:"14",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"18",y:"42",width:"24",height:"20",fill:"#2A2B30",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("rect",{x:"21",y:"44",width:"18",height:"2",fill:"#9AA0A6"}),n.jsx("rect",{x:"18",y:"64",width:"24",height:"6",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"18",y:"70",width:"24",height:"4",fill:"#DCD3C6",stroke:"#182137",strokeWidth:"0.5"})]})}function dtt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,
444children:[n.jsx("rect",{x:"6",y:"14",width:"48",height:"58",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"9",y:"17",width:"42",height:"6",fill:"#9AA0A6",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("rect",{x:"9",y:"26",width:"42",height:"43",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"})]})}function utt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"16",y:"6",width:"28",height:"70",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"18",y:"8",width:"24",height:"22",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"18",y:"33",width:"24",height:"20",fill:"#2A2B30",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("rect",{x:"21",y:"35",width:"18",height:"2",fill:"#9AA0A6"}),n.jsx("rect",{x:"18",y:"56",width:"24",height:"14",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"18",y:"70",width:"24",height:"4",fill:"#DCD3C6",stroke:"#182137",strokeWidth:"0.5"})]})}function htt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"6",y:"18",width:"48",height:"54",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"9",y:"21",width:"20.5",height:"43",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"30.5",y:"21",width:"20.5",height:"43",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"9",y:"66",width:"42",height:"4",fill:"#DCD3C6",stroke:"#182137",strokeWidth:"0.5"})]})}function mtt(){const t=Array.from({length:7});return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"8",y:"16",width:"44",height:"40",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),t.map((e,s)=>n.jsx("rect",{x:"10",y:18+s*5.2,width:"40",height:"4",fill:"#DCD3C6",stroke:"#182137",strokeWidth:"0.4"},s))]})}function m_(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("line",{x1:"10",y1:"15",x2:"50",y2:"15",stroke:"#182137",strokeWidth:"0.6",strokeDasharray:"2 1.5",opacity:"0.4"}),n.jsx("line",{x1:"50",y1:"15",x2:"50",y2:"65",stroke:"#182137",strokeWidth:"0.6",strokeDasharray:"2 1.5",opacity:"0.4"}),n.jsx("polygon",{points:"30,65 50,65 50,15 10,15 10,40 30,40",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("line",{x1:"11",y1:"40",x2:"30",y2:"40",stroke:"#D85D43",strokeWidth:"2.6",strokeLinecap:"round"}),n.jsx("line",{x1:"30",y1:"41",x2:"30",y2:"64",stroke:"#D85D43",strokeWidth:"2.6",strokeLinecap:"round"})]})}function ftt(){const t=w9,e=3e3,s=2400,o=2,r=56,i=18,a=44,l=B=>o+B*r/e,c=B=>i+a-B*a/s,d=t.plinthHeightMm,u=s-t.capHeightMm,h=[];let x=0;const f=(B,R,z,X,ft,tt,G=.4)=>h.push(n.jsx("rect",{x:l(B),y:c(X),width:Math.max(.3,l(R)-l(B)),height:Math.max(.3,c(z)-c(X)),fill:ft,stroke:tt,strokeWidth:tt?G:void 0},x++)),p=(B,R,z,X)=>{f(B,R,z,X,"#E8DFD3","#D85D43",.35),h.push(n.jsx("rect",{x:l(B)+.5,y:c(X)+.4,width:Math.max(.5,l(R)-l(B)-1),height:.35,fill:"#C9BFAF"},x++))};f(0,e,0,d,"#8C8377"),f(0,e,d,u,"#F7F4EF","#182137",.9),f(0,e,u,s,"#EFE9DF","#182137",.6);const b=Math.round(e*t.openModuleFraction),M=t.structThicknessMm,g=t.openColumnCompartments.length,w=(b-M*(g+1))/g,k=B=>M+B*(w+M);f(0,b,d,u,"#CFC5B4");for(let B=0;B<=g;B+=1){const R=B===0?0:k(B-1)+w;f(R,R+M,d,u,"#E4DCCE","#182137",.3)}for(const B of[d,u-M])f(0,b,B,B+M,"#E4DCCE","#182137",.3);const _=d+M,j=u-M-_;for(let B=0;B<g;B+=1){const R=t.openColumnCompartments[B],z=(j-M*(R-1))/R;for(let X=1;X<R;X+=1){const ft=_+X*z+(X-1)*M;f(k(B),k(B)+w,ft,ft+M,"#E4DCCE","#182137",.3)}}const v=e-b,C=t.revealMm;f(b,e,d,u,"#EFE9DF","#182137",.4);const P=(v-C*2-C*(t.doorColumns-1))/t.doorColumns,L=d+C,A=u-C,W=(A-L)*t.upperBandFraction,S=A-W-C;for(let B=0;B<t.doorColumns;B+=1){const R=b+C+B*(P+C);p(R,R+P,L,S),p(R,R+P,S+C,A)}return n.jsx("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:h})}function xtt(){const s=h=>2+h*56/3680,o=h=>62-h*56/2560,r=[20,930,1840,2750,3660],i=[[0,2440],[0,2040],[0,760],[1,2440],[1,2040],[1,760],[2,2440],[2,2e3],[2,1130],[2,620],[3,2440],[3,2040],[3,1130],[3,620]],a=[1,2],l=[[0,360,740],[1,360,740],[2,1560,1980]],c=h=>[r[h]+26,r[h+1]-26],d=[];let u=0;for(const h of a){const[x,f]=c(h);d.push(n.jsx("rect",{x:s(x),y:o(2490),width:s(f)-s(x),height:o(60)-o(2490),fill:"#8A7F6C"},u++))}
444for(const h of r)d.push(n.jsx("rect",{x:s(h)-.6,y:o(2490),width:1.2,height:o(60)-o(2490),fill:"#5A5247"},u++)),d.push(n.jsx("polygon",{points:`${s(h)-1.3},${o(2490)} ${s(h)+1.3},${o(2490)} ${s(h)},${o(2560)}`,fill:"#5A5247"},u++)),d.push(n.jsx("polygon",{points:`${s(h)-1.3},${o(60)} ${s(h)+1.3},${o(60)} ${s(h)},${o(0)}`,fill:"#5A5247"},u++));for(const[h,x]of i){const[f,p]=c(h);d.push(n.jsx("rect",{x:s(f),y:o(x)-1.2,width:s(p)-s(f),height:1.2,fill:"#4F4A40"},u++))}for(const[h,x,f]of l){const[p,b]=c(h);d.push(n.jsx("rect",{x:s(p),y:o(f),width:s(b)-s(p),height:o(x)-o(f),fill:"#C3B8A2",stroke:"#182137",strokeWidth:.4},u++)),d.push(n.jsx("rect",{x:s((p+b)/2)-1.7,y:(o(x)+o(f))/2-.3,width:3.4,height:.6,fill:"#6E6459"},u++))}return n.jsx("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:d})}function ptt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"6",y:"4",width:"48",height:"72",stroke:"#182137",strokeWidth:"1.2",fill:"#F7F4EF"}),n.jsx("rect",{x:"6",y:"6",width:"16",height:"68",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"22",y:"6",width:"16",height:"68",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"38",y:"6",width:"16",height:"68",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"})]})}function gtt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"2",y:"15",width:"56",height:"50",stroke:"#182137",strokeWidth:"1.2",fill:"#F7F4EF"}),n.jsx("rect",{x:"2.5",y:"16.5",width:"8.8",height:"47",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"9.4",y:"30",width:"1.3",height:"20",fill:"#182137"}),n.jsx("rect",{x:"11.3",y:"16.5",width:"7.4",height:"47",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"18.8",y:"16.5",width:"7.4",height:"47",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"27",y:"17.5",width:"3.6",height:"6",fill:"#4A443D"}),n.jsx("rect",{x:"27",y:"24.5",width:"3.6",height:"6",fill:"#4A443D"}),n.jsx("rect",{x:"27",y:"31.5",width:"3.6",height:"6",fill:"#4A443D"}),n.jsx("rect",{x:"27",y:"38.5",width:"3.6",height:"6",fill:"#4A443D"}),n.jsx("rect",{x:"27",y:"45.5",width:"3.6",height:"6",fill:"#4A443D"}),n.jsx("rect",{x:"27",y:"52.5",width:"3.6",height:"6",fill:"#4A443D"}),n.jsx("rect",{x:"31.3",y:"17.5",width:"3.6",height:"6",fill:"#4A443D"}),n.jsx("rect",{x:"31.3",y:"24.5",width:"3.6",height:"6",fill:"#4A443D"}),n.jsx("rect",{x:"31.3",y:"31.5",width:"3.6",height:"6",fill:"#4A443D"}),n.jsx("rect",{x:"31.3",y:"38.5",width:"3.6",height:"6",fill:"#4A443D"}),n.jsx("rect",{x:"31.3",y:"45.5",width:"3.6",height:"6",fill:"#4A443D"}),n.jsx("rect",{x:"31.3",y:"52.5",width:"3.6",height:"6",fill:"#4A443D"}),n.jsx("rect",{x:"30.5",y:"16.5",width:"1",height:"47",fill:"#182137"}),n.jsx("rect",{x:"35.6",y:"16.5",width:"7.4",height:"47",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"43.1",y:"16.5",width:"7.4",height:"47",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"50.6",y:"16.5",width:"7",height:"47",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"51.3",y:"30",width:"1.3",height:"20",fill:"#182137"})]})}function f_(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"4",y:"26",width:"52",height:"48",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"7",y:"30",width:"22.5",height:"40",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"30.5",y:"30",width:"22.5",height:"40",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("circle",{cx:"28",cy:"50",r:"0.8",fill:"#182137"}),n.jsx("circle",{cx:"32",cy:"50",r:"0.8",fill:"#182137"}),n.jsx("rect",{x:"1",y:"20",width:"58",height:"6",fill:"#DDD3C4",stroke:"#182137",strokeWidth:"1"}),n.jsx("rect",{x:"18",y:"13",width:"24",height:"9",fill:"#C4BAA9",stroke:"#182137",strokeWidth:"0.7",rx:"1"}),n.jsx("rect",{x:"44",y:"6",width:"1.6",height:"8",fill:"#182137"}
444),n.jsx("rect",{x:"37",y:"6",width:"8.6",height:"1.6",fill:"#182137"})]})}function btt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"14",y:"6",width:"32",height:"68",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"16",y:"8",width:"28",height:"44",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"41",y:"22",width:"1",height:"16",fill:"#182137"}),n.jsx("rect",{x:"16",y:"54",width:"28",height:"14",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"28",y:"56",width:"10",height:"1",fill:"#182137"}),n.jsx("rect",{x:"16",y:"68",width:"28",height:"4",fill:"#DCD3C6",stroke:"#182137",strokeWidth:"0.5"})]})}function Mtt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("path",{d:"M 4 20 L 56 20 L 56 70 L 52 70 L 52 26 L 8 26 L 8 70 L 4 70 Z",fill:"#DDD3C4",stroke:"#182137",strokeWidth:"1"}),n.jsx("line",{x1:"4",y1:"20",x2:"8",y2:"26",stroke:"#182137",strokeWidth:"0.5",opacity:"0.6"}),n.jsx("line",{x1:"56",y1:"20",x2:"52",y2:"26",stroke:"#182137",strokeWidth:"0.5",opacity:"0.6"}),n.jsx("rect",{x:"8",y:"26",width:"44",height:"44",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"0.8"}),n.jsx("rect",{x:"22",y:"13",width:"16",height:"9",fill:"#C4BAA9",stroke:"#182137",strokeWidth:"0.7",rx:"1"}),n.jsx("rect",{x:"40",y:"6",width:"1.4",height:"8",fill:"#182137"}),n.jsx("rect",{x:"34",y:"6",width:"7.4",height:"1.4",fill:"#182137"}),n.jsx("rect",{x:"10",y:"30",width:"8",height:"8.5",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"10",y:"39",width:"8",height:"8.5",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"10",y:"48",width:"8",height:"17",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"19",y:"30",width:"6.5",height:"35",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"26",y:"30",width:"6.5",height:"35",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"33",y:"30",width:"9",height:"35",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"0.4",opacity:"0.85"}),n.jsx("rect",{x:"42",y:"30",width:"8",height:"8.5",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"42",y:"39",width:"8",height:"8.5",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"42",y:"48",width:"8",height:"17",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"})]})}function ytt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("path",{d:"M 4 20 L 56 20 L 56 70 L 52 70 L 52 26 L 8 26 L 8 70 L 4 70 Z",fill:"#DDD3C4",stroke:"#182137",strokeWidth:"1"}),n.jsx("line",{x1:"4",y1:"20",x2:"8",y2:"26",stroke:"#182137",strokeWidth:"0.5",opacity:"0.6"}),n.jsx("line",{x1:"56",y1:"20",x2:"52",y2:"26",stroke:"#182137",strokeWidth:"0.5",opacity:"0.6"}),n.jsx("rect",{x:"8",y:"26",width:"44",height:"44",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"0.8"}),n.jsx("rect",{x:"20",y:"13",width:"20",height:"9",fill:"#2A2B30",stroke:"#182137",strokeWidth:"0.7",rx:"1"}),n.jsx("circle",{cx:"23.5",cy:"19",r:"1",fill:"#9AA0A6"}),n.jsx("circle",{cx:"30",cy:"19",r:"1",fill:"#9AA0A6"}),n.jsx("circle",{cx:"36.5",cy:"19",r:"1",fill:"#9AA0A6"}),n.jsx("circle",{cx:"27",cy:"15.5",r:"1",fill:"#9AA0A6"}),n.jsx("circle",{cx:"33",cy:"15.5",r:"1",fill:"#9AA0A6"}),n.jsx("rect",{x:"10",y:"30",width:"9",height:"8.5",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"10",y:"39",width:"9",height:"8.5",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"10",y:"48",width:"9",height:"17",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"20",y:"30",width:"9.5",height:"35",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"30.5",y:"30",width:"9.5",height:"35",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"41",y:"30",width:"9",height:"8.5",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"41",y:"39",width:"9",height:"8.5",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"41",y:"48",width:"9",height:"17",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"})]})}function wtt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,
444children:[n.jsx("path",{d:"M 2 20 L 58 20 L 58 70 L 54 70 L 54 26 L 6 26 L 6 70 L 2 70 Z",fill:"#DDD3C4",stroke:"#182137",strokeWidth:"1"}),n.jsx("line",{x1:"2",y1:"20",x2:"6",y2:"26",stroke:"#182137",strokeWidth:"0.5",opacity:"0.6"}),n.jsx("line",{x1:"58",y1:"20",x2:"54",y2:"26",stroke:"#182137",strokeWidth:"0.5",opacity:"0.6"}),n.jsx("rect",{x:"6",y:"26",width:"48",height:"44",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"0.8"}),n.jsx("rect",{x:"11",y:"13",width:"18",height:"9",fill:"#2A2B30",stroke:"#182137",strokeWidth:"0.7",rx:"1"}),n.jsx("circle",{cx:"14",cy:"19",r:"0.9",fill:"#9AA0A6"}),n.jsx("circle",{cx:"20",cy:"19",r:"0.9",fill:"#9AA0A6"}),n.jsx("circle",{cx:"26",cy:"19",r:"0.9",fill:"#9AA0A6"}),n.jsx("circle",{cx:"17",cy:"15.5",r:"0.9",fill:"#9AA0A6"}),n.jsx("circle",{cx:"23",cy:"15.5",r:"0.9",fill:"#9AA0A6"}),n.jsx("ellipse",{cx:"42",cy:"17.5",rx:"8",ry:"4.5",fill:"#C4BAA9",stroke:"#182137",strokeWidth:"0.7"}),n.jsx("rect",{x:"49",y:"7",width:"1.4",height:"8",fill:"#182137"}),n.jsx("rect",{x:"43",y:"7",width:"7.4",height:"1.4",fill:"#182137"}),n.jsx("rect",{x:"8",y:"30",width:"8",height:"8.5",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"8",y:"39",width:"8",height:"8.5",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"8",y:"48",width:"8",height:"17",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"17.5",y:"30",width:"11",height:"35",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"29.5",y:"30",width:"11",height:"35",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"44",y:"30",width:"8",height:"8.5",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"44",y:"39",width:"8",height:"8.5",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"44",y:"48",width:"8",height:"17",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"})]})}function ktt(){const t=nz,e=2410,s=2,o=56,r=20,i=42,a=S=>s+S*o/t.totalWidthMm,l=S=>r+i-S*i/e,c=t.plinthHeightMm,d=e-t.capHeightMm,u=S=>c+(d-c)*S,h=8,x=[];let f=0;const p=(S,B,R,z,X,ft,tt=.4)=>x.push(n.jsx("rect",{x:a(S),y:l(z),width:Math.max(.3,a(B)-a(S)),height:Math.max(.3,l(R)-l(z)),fill:X,stroke:ft,strokeWidth:ft?tt:void 0},f++)),b=(S,B,R,z,X="#E8DFD3")=>{p(S,B,R,z,X,"#D85D43",.4),x.push(n.jsx("rect",{x:a(S)+.4,y:l(z)+.35,width:Math.max(.4,a(B)-a(S)-.8),height:.3,fill:"#C9BFAF"},f++))};p(0,t.totalWidthMm,0,c,"#8C8377"),p(0,t.totalWidthMm,c,d,"#F7F4EF","#182137",.9),p(0,t.totalWidthMm,d,e,"#EFE9DF","#182137",.6);const M=t.larderWidthMm,g=t.sideThicknessMm,w=g,k=M-g,_=(k-w-g*2)/3,j=S=>w+S*(_+g),v=u(t.larderDrawersTopF),C=u(t.larderNicheTopF);p(0,M,v,C,"#D6CCBC","#182137",.35),p(w,k,C-60,C,"#FBF1CF");const N=(v-c-h*4)/3,P=(d-C-h*3)/2;for(let S=0;S<3;S+=1){for(let B=0;B<3;B+=1){const R=c+h+B*(N+h);b(j(S),j(S)+_,R,R+N)}for(let B=0;B<2;B+=1){const R=C+h+B*(P+h);b(j(S),j(S)+_,R,R+P)}}const L=c+h,A=d-h;let W=M;for(const S of t.columns){const B=W+h/2,R=W+S.widthMm-h/2;if(W+=S.widthMm,S.type==="filler")continue;if(S.type==="fridge"){b(B,R,L,A,"#F2ECE2");continue}if(S.type==="door"){b(B,R,L,A);continue}
444if(S.type==="doorWide"){const ft=(B+R)/2;b(B,ft-h/2,L,A),b(ft+h/2,R,L,A);continue}const z=B+g,X=R-g;b(z,X,L,u(t.ovenDrawerTopF));for(const[ft,tt]of[[t.ovenNicheBottomF,t.ovenNicheTopF],[t.mwNicheBottomF,t.mwNicheTopF]]){const G=u(ft),Y=u(tt);p(z,X,G,Y,"#2A2B30","#182137",.35),p(z+40,X-40,Y-(Y-G)*.26,Y-(Y-G)*.12,"#8E9299")}b(z,X,u(t.ovenUpperBottomF),A)}return n.jsx("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:x})}function yy({layout:t}){const l=56/t.reduce((b,M)=>b+M.widthMm,0),c=b=>2+b*l,d=b=>62-b/2800*54,u=[];let h=0;const x=(b,M,g,w,k,_="#D85D43",j=.5)=>u.push(n.jsx("rect",{x:c(b)+.4,y:d(w),width:Math.max(0,(M-b)*l-.8),height:Math.max(0,d(g)-d(w)),fill:k,stroke:_,strokeWidth:j},h++)),f=(b,M,g)=>u.push(n.jsx("rect",{x:c(b)+1,y:d(g),width:Math.max(0,(M-b)*l-2),height:.7,fill:"#FBF1CF"},h++));let p=0;for(const b of t){const M=p,g=p+b.widthMm;if(p=g,b.kind==="applianceCol")x(M,g,0,720,"#E8DFD3"),x(M,g,760,1360,"#2A2B30","#182137"),x(M,g,1380,1720,"#2A2B30","#182137"),x(M,g,1760,2800,"#E8DFD3");else if(b.kind==="stackCol")x(M,g,0,1390,"#E8DFD3"),x(M,g,1410,2800,"#E8DFD3");else if(b.kind==="openBay")x(M,g,0,900,"#E8DFD3"),x(M,g,900,940,"#3A3B40","#182137"),x(M,g,950,2800,"#DDD3C4","#182137"),u.push(n.jsx("line",{x1:c(M)+1,y1:d(1480),x2:c(g)-1,y2:d(1480),stroke:"#182137",strokeWidth:.5},h++)),u.push(n.jsx("line",{x1:c(M)+1,y1:d(2040),x2:c(g)-1,y2:d(2040),stroke:"#182137",strokeWidth:.5},h++)),f(M,g,2740);else{if(b.base==="drawers")for(let w=0;w<3;w+=1)x(M,g,w*300,w*300+280,"#E8DFD3");else{const w=(M+g)/2;x(M,w,0,900,"#E8DFD3"),x(w,g,0,900,"#E8DFD3")}x(M,g,900,940,"#3A3B40","#182137"),x(M,g,950,1500,"#DDD3C4","#182137"),f(M,g,1480),x(M,g,1540,2320,"#E8DFD3"),x(M,g,2340,2800,"#E8DFD3")}}return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:2,y:8,width:56,height:54,fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),u]})}function vtt(){const a=h=>2+h*56/3600,l=h=>62-h/2800*54,c=[];let d=0;const u=(h,x,f,p,b,M="#D85D43",g=.5)=>c.push(n.jsx("rect",{x:a(h)+.3,y:l(p),width:Math.max(0,(x-h)*(56/3600)-.6),height:Math.max(0,l(f)-l(p)),fill:b,stroke:M,strokeWidth:g},d++));u(0,600,0,720,"#E8DFD3"),u(0,600,760,1360,"#2A2B30","#182137"),u(0,600,1380,1720,"#2A2B30","#182137"),u(0,600,1760,2800,"#E8DFD3"),u(600,1200,0,1390,"#E8DFD3"),u(600,1200,1410,2800,"#E8DFD3");for(const[h,x]of[[1200,2e3],[2e3,2800],[2800,3600]])u(h,x,0,430,"#E8DFD3"),u(h,x,450,870,"#E8DFD3");return u(1200,3600,870,900,"#2A2B30","#182137"),u(1850,2550,900,935,"#15161A","#182137"),u(2900,3400,900,935,"#15161A","#182137"),c.push(n.jsx("rect",{x:a(3140),y:l(1180),width:.9,height:l(900)-l(1180),fill:"#15161A"},d++)),c.push(n.jsx("rect",{x:a(3040),y:l(1180),width:a(3150)-a(3040),height:.9,fill:"#15161A"},d++)),u(1200,2900,920,1500,"#34353B","#182137"),c.push(n.jsx("rect",{x:a(1240),y:l(1505),width:a(2860)-a(1240),height:.7,fill:"#FBF1CF"},d++)),u(1200,2900,1540,1650,"#2A2B30","#182137"),u(1200,2900,1660,2200,"#E8DFD3"),u(1200,2900,2220,2800,"#E8DFD3"),u(2900,3600,920,2800,"#34353B","#182137"),c.push(n.jsx("line",{x1:a(2940),y1:l(1640),x2:a(3560),y2:l(1640),stroke:"#EDE6DA",strokeWidth:.6},d++)),c.push(n.jsx("line",{x1:a(2940),y1:l(2180),x2:a(3560),y2:l(2180),stroke:"#EDE6DA",strokeWidth:.6},d++)),c.push(n.jsx("rect",{x:a(2940),y:l(2740),width:a(3560)-a(2940),height:.7,fill:"#FBF1CF"},d++)),n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:2,y:8,width:56,height:54,fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),c]})}function jtt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"5",y:"26",width:"50",height:"7",fill:"#EDE7DC",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("polygon",{points:"12,33 17,33 15.6,66 13.4,66",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"1"}),n.jsx("polygon",{points:"43,33 48,33 46.6,66 44.4,66",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"1"})]})}function _tt(){const t=e=>[0,1,2,3,4].map(s=>n.jsx("line",{x1:e+s*2.6,y1:30,x2:e+s*2.6,y2:52,stroke:"#D85D43",strokeWidth:.55},`${e}-${s}`));return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,
444children:[n.jsx("rect",{x:"3",y:"25",width:"54",height:"5",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"1.1"}),n.jsx("rect",{x:"5",y:"30",width:"50",height:"22",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.1"}),n.jsx("rect",{x:"7",y:"31",width:"13",height:"20",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),t(8.3),n.jsx("rect",{x:"22",y:"31",width:"16",height:"20",fill:"#CFC6B6",stroke:"#182137",strokeWidth:"0.6"}),n.jsx("line",{x1:"22",y1:"41",x2:"38",y2:"41",stroke:"#182137",strokeWidth:"0.8"}),n.jsx("rect",{x:"40",y:"31",width:"13",height:"20",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),t(41.3),n.jsx("polygon",{points:"9,52 12,52 11.2,68 9.8,68",fill:"#3A352F"}),n.jsx("polygon",{points:"48,52 51,52 50.2,68 48.8,68",fill:"#3A352F"})]})}function Ett(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"2",y:"58",width:"56",height:"14",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"2",y:"24",width:"8",height:"48",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"50",y:"24",width:"8",height:"48",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"11",y:"24",width:"12.3",height:"22",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"23.85",y:"24",width:"12.3",height:"22",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"36.7",y:"24",width:"12.3",height:"22",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"11",y:"47",width:"12.3",height:"10",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"23.85",y:"47",width:"12.3",height:"10",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"36.7",y:"47",width:"12.3",height:"10",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("line",{x1:"0",y1:"73",x2:"60",y2:"73",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function Dtt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"2",y:"58",width:"56",height:"12",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"2",y:"50",width:"56",height:"8",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"2",y:"12",width:"18",height:"38",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"20.5",y:"24",width:"14",height:"26",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"35",y:"36",width:"12",height:"14",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("line",{x1:"0",y1:"71",x2:"60",y2:"71",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function Ftt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"2",y:"28",width:"56",height:"30",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"5",y:"32",width:"11.5",height:"22",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"17.5",y:"32",width:"11.5",height:"22",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"30",y:"32",width:"11.5",height:"22",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"42.5",y:"32",width:"11.5",height:"22",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("circle",{cx:"11",cy:"43",r:"0.6",fill:"#182137"}),n.jsx("circle",{cx:"23.5",cy:"43",r:"0.6",fill:"#182137"}),n.jsx("circle",{cx:"36",cy:"43",r:"0.6",fill:"#182137"}),n.jsx("circle",{cx:"48.5",cy:"43",r:"0.6",fill:"#182137"}),n.jsx("line",{x1:"0",y1:"72",x2:"60",y2:"72",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function Ctt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("line",{x1:"4",y1:"12",x2:"56",y2:"12",stroke:"#182137",strokeWidth:"0.6",strokeDasharray:"2 1.5",opacity:"0.3"}),n.jsx("rect",{x:"6",y:"26",width:"48",height:"30",rx:"1.5",fill:"#1A1A1C",stroke:"#182137",strokeWidth:"1"}),n.jsx("rect",{x:"9",y:"29",width:"42",height:"24",rx:"0.5",fill:"#050507"})]})}function Ntt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,
444children:[n.jsx("rect",{x:"3",y:"34",width:"54",height:"6",fill:"#EDE7DC",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("polygon",{points:"9,40 13,40 12,66 10,66",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"1"}),n.jsx("polygon",{points:"47,40 51,40 50,66 48,66",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"1"}),n.jsx("rect",{x:"14",y:"52",width:"32",height:"4",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"0.8"}),n.jsx("line",{x1:"0",y1:"68",x2:"60",y2:"68",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function Itt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"4",y:"18",width:"52",height:"44",rx:"3",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"8",y:"22",width:"44",height:"36",rx:"2",fill:"none",stroke:"#182137",strokeWidth:"0.5",opacity:"0.55"}),n.jsx("rect",{x:"12",y:"26",width:"36",height:"28",rx:"1.5",fill:"none",stroke:"#182137",strokeWidth:"0.4",opacity:"0.45"}),n.jsx("circle",{cx:"30",cy:"40",r:"2",fill:"#D85D43",opacity:"0.5"})]})}function Ttt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"6",y:"10",width:"48",height:"62",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"1.2",rx:"2"}),n.jsx("rect",{x:"6",y:"10",width:"48",height:"9",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"11",y:"22",width:"16",height:"9",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"0.5",rx:"1"}),n.jsx("rect",{x:"33",y:"22",width:"16",height:"9",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"0.5",rx:"1"}),n.jsx("line",{x1:"6",y1:"55",x2:"54",y2:"55",stroke:"#182137",strokeWidth:"0.5",opacity:"0.45"})]})}function Stt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"14",y:"20",width:"32",height:"48",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"16",y:"22",width:"28",height:"20",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"16",y:"44",width:"28",height:"20",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("circle",{cx:"30",cy:"32",r:"0.8",fill:"#182137"}),n.jsx("circle",{cx:"30",cy:"54",r:"0.8",fill:"#182137"}),n.jsx("line",{x1:"14",y1:"66",x2:"46",y2:"66",stroke:"#182137",strokeWidth:"0.6",opacity:"0.6"})]})}function Ptt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"3",y:"6",width:"54",height:"72",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"3",y:"6",width:"18",height:"72",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"21",y:"6",width:"18",height:"72",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"39",y:"6",width:"18",height:"72",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.5"}),n.jsx("rect",{x:"19",y:"36",width:"0.8",height:"12",fill:"#182137"}),n.jsx("rect",{x:"37",y:"36",width:"0.8",height:"12",fill:"#182137"}),n.jsx("rect",{x:"55",y:"36",width:"0.8",height:"12",fill:"#182137"})]})}function Att(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"4",y:"16",width:"52",height:"52",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"7",y:"18",width:"46",height:"11",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"7",y:"30",width:"46",height:"11",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"7",y:"42",width:"46",height:"11",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"7",y:"54",width:"46",height:"11",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("circle",{cx:"30",cy:"23.5",r:"0.8",fill:"#182137"}),n.jsx("circle",{cx:"30",cy:"35.5",r:"0.8",fill:"#182137"}),n.jsx("circle",{cx:"30",cy:"47.5",r:"0.8",fill:"#182137"}),n.jsx("circle",{cx:"30",cy:"59.5",r:"0.8",fill:"#182137"}),n.jsx("line",{x1:"4",y1:"66",x2:"56",y2:"66",stroke:"#182137",strokeWidth:"0.6",opacity:"0.6"})]})}function Ltt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,
444children:[n.jsx("rect",{x:"14",y:"8",width:"32",height:"32",fill:"#C9D6DC",stroke:"#182137",strokeWidth:"1",rx:"1"}),n.jsx("line",{x1:"18",y1:"14",x2:"22",y2:"20",stroke:"#FFFFFF",strokeWidth:"0.6",opacity:"0.55"}),n.jsx("rect",{x:"4",y:"46",width:"52",height:"22",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"7",y:"48",width:"46",height:"14",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("circle",{cx:"30",cy:"55",r:"0.8",fill:"#182137"}),n.jsx("line",{x1:"4",y1:"68",x2:"56",y2:"68",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function Wtt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"4",y:"34",width:"52",height:"16",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"1.2",rx:"1.5"}),n.jsx("polygon",{points:"10,50 15,50 13.8,68 11.2,68",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.6"}),n.jsx("polygon",{points:"45,50 50,50 48.8,68 46.2,68",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.6"}),n.jsx("line",{x1:"0",y1:"70",x2:"60",y2:"70",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function Rtt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"14",y:"10",width:"32",height:"62",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"1.2",rx:"2"}),n.jsx("rect",{x:"14",y:"10",width:"32",height:"8",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"22",y:"21",width:"16",height:"9",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"0.5",rx:"1"}),n.jsx("line",{x1:"14",y1:"52",x2:"46",y2:"52",stroke:"#182137",strokeWidth:"0.5",opacity:"0.45"})]})}function Ott(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"6",y:"6",width:"3",height:"68",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"0.6"}),n.jsx("rect",{x:"51",y:"6",width:"3",height:"68",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"0.6"}),n.jsx("rect",{x:"6",y:"46",width:"48",height:"6",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1"}),n.jsx("rect",{x:"6",y:"20",width:"48",height:"6",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1"}),n.jsx("rect",{x:"6",y:"14",width:"48",height:"6",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"0.6"}),n.jsx("rect",{x:"44",y:"38",width:"8",height:"2.5",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("rect",{x:"44",y:"30",width:"8",height:"2.5",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("rect",{x:"44",y:"22",width:"8",height:"2.5",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("line",{x1:"0",y1:"74",x2:"60",y2:"74",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function Htt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"4",y:"26",width:"52",height:"6",fill:"#EDE7DC",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("polygon",{points:"9,32 13,32 12,66 10,66",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"1"}),n.jsx("polygon",{points:"47,32 51,32 50,66 48,66",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"1"}),n.jsx("line",{x1:"0",y1:"68",x2:"60",y2:"68",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function Btt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("line",{x1:"54",y1:"6",x2:"54",y2:"74",stroke:"#182137",strokeWidth:"0.7",strokeDasharray:"2 1.5",opacity:"0.45"}),n.jsx("rect",{x:"8",y:"26",width:"46",height:"5",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("line",{x1:"0",y1:"74",x2:"60",y2:"74",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function Vtt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"29",y:"20",width:"2",height:"8",fill:"#182137"}),n.jsx("rect",{x:"29",y:"20",width:"6",height:"2",fill:"#182137"}),n.jsx("rect",{x:"4",y:"28",width:"52",height:"4",fill:"#DDD3C4",stroke:"#182137",strokeWidth:"1"}),n.jsx("ellipse",{cx:"30",cy:"30",rx:"13",ry:"1.6",fill:"#C4BAA9",stroke:"#182137",strokeWidth:"0.4",opacity:"0.85"}),n.jsx("rect",{x:"6",y:"32",width:"48",height:"34",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"9",y:"34",width:"20",height:"30",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"31",y:"34",width:"20",height:"30",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("circle",{cx:"27",cy:"49",r:"0.8",fill:"#182137"}),n.jsx("circle",{cx:"33",cy:"49",r:"0.8",fill:"#182137"}),n.jsx("line",{x1:"0",y1:"68",x2:"60",y2:"68",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function gf({doors:t=2,double:e=!1,faucet:s="deck",interpotz:o="3way"}){const r=t===3?[9,24,39]:[9,31],i=t===3?13:20,a=e?[22,38]:[30],l=o!=="none"||s==="wall",c=o==="2x3"?4:o==="4way"?3:o==="3way"?2:1;return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,
444children:[l?n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"12",cy:"14",r:"3",fill:"#1C1C1C"}),n.jsx("rect",{x:"12",y:"13.1",width:"14",height:"1.8",fill:"#1C1C1C"}),n.jsx("rect",{x:"24.4",y:"14",width:"1.8",height:"8",fill:"#1C1C1C"}),Array.from({length:c}).map((d,u)=>n.jsxs("g",{children:[n.jsx("circle",{cx:36+u*6,cy:"14",r:"2.4",fill:"#1C1C1C"}),n.jsx("rect",{x:35.6+u*6,y:"16",width:"0.9",height:"6",fill:"#1C1C1C"})]},`ctrl-${u}`))]}):a.map(d=>n.jsxs("g",{children:[n.jsx("rect",{x:d-1,y:20,width:"2",height:"8",fill:"#182137"}),n.jsx("rect",{x:d-1,y:20,width:"6",height:"2",fill:"#182137"})]},`df-${d}`)),n.jsx("rect",{x:"4",y:"28",width:"52",height:"4",fill:"#DDD3C4",stroke:"#182137",strokeWidth:"1"}),a.map(d=>n.jsx("ellipse",{cx:d,cy:"30",rx:e?8:13,ry:"1.6",fill:"#C4BAA9",stroke:"#182137",strokeWidth:"0.4",opacity:"0.85"},`b-${d}`)),n.jsx("rect",{x:"6",y:"32",width:"48",height:"34",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),r.map(d=>n.jsxs("g",{children:[n.jsx("rect",{x:d,y:"34",width:i,height:"30",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("circle",{cx:d+i-2,cy:"49",r:"0.8",fill:"#182137"})]},`d-${d}`)),n.jsx("line",{x1:"0",y1:"68",x2:"60",y2:"68",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function ztt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"10",y:"10",width:"40",height:"3",fill:"#FFF8E0",stroke:"#182137",strokeWidth:"0.6"}),n.jsx("rect",{x:"10",y:"16",width:"40",height:"48",fill:"#C9D6DC",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("line",{x1:"14",y1:"22",x2:"20",y2:"32",stroke:"#FFFFFF",strokeWidth:"0.7",opacity:"0.6"}),n.jsx("line",{x1:"16",y1:"40",x2:"22",y2:"50",stroke:"#FFFFFF",strokeWidth:"0.5",opacity:"0.4"}),n.jsx("line",{x1:"3",y1:"6",x2:"3",y2:"74",stroke:"#182137",strokeWidth:"0.7",strokeDasharray:"2 1.5",opacity:"0.3"}),n.jsx("line",{x1:"57",y1:"6",x2:"57",y2:"74",stroke:"#182137",strokeWidth:"0.7",strokeDasharray:"2 1.5",opacity:"0.3"})]})}function $tt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("line",{x1:"6",y1:"64",x2:"54",y2:"64",stroke:"#182137",strokeWidth:"0.7",strokeDasharray:"2 1.5",opacity:"0.45"}),n.jsx("line",{x1:"54",y1:"16",x2:"54",y2:"64",stroke:"#182137",strokeWidth:"0.7",strokeDasharray:"2 1.5",opacity:"0.45"}),n.jsx("rect",{x:"6",y:"16",width:"48",height:"48",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"6",y:"14",width:"48",height:"2.5",fill:"#E0EAEF",stroke:"#182137",strokeWidth:"0.6"}),n.jsx("rect",{x:"4",y:"16.5",width:"2.5",height:"46",fill:"#E0EAEF",stroke:"#182137",strokeWidth:"0.6"}),n.jsx("circle",{cx:"54",cy:"14",r:"1",fill:"#D85D43",opacity:"0.6"})]})}function Xtt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("line",{x1:"4",y1:"22",x2:"56",y2:"22",stroke:"#182137",strokeWidth:"0.7",strokeDasharray:"2 1.5",opacity:"0.4"}),n.jsx("rect",{x:"4",y:"24",width:"52",height:"32",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2",rx:"2"}),n.jsx("rect",{x:"8",y:"28",width:"44",height:"24",fill:"#F0EDE6",stroke:"#182137",strokeWidth:"0.6",rx:"3"}),n.jsx("circle",{cx:"30",cy:"40",r:"1",fill:"#182137",opacity:"0.6"}),n.jsx("line",{x1:"0",y1:"64",x2:"60",y2:"64",stroke:"#182137",strokeWidth:"0.6",opacity:"0.4"})]})}function Ytt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"10",y:"8",width:"40",height:"50",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"16",y:"30",width:"3",height:"3",fill:"#182137"}),n.jsx("rect",{x:"28.5",y:"30",width:"3",height:"3",fill:"#182137"}),n.jsx("rect",{x:"41",y:"30",width:"3",height:"3",fill:"#182137"}),n.jsx("rect",{x:"6",y:"58",width:"48",height:"10",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("line",{x1:"0",y1:"70",x2:"60",y2:"70",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function Gtt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,
444children:[n.jsx("line",{x1:"6",y1:"4",x2:"6",y2:"74",stroke:"#182137",strokeWidth:"0.7",strokeDasharray:"2 1.5",opacity:"0.35"}),n.jsx("line",{x1:"54",y1:"4",x2:"54",y2:"74",stroke:"#182137",strokeWidth:"0.7",strokeDasharray:"2 1.5",opacity:"0.35"}),n.jsx("rect",{x:"20",y:"6",width:"20",height:"62",fill:"#C9D6DC",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("line",{x1:"23",y1:"12",x2:"33",y2:"28",stroke:"#FFFFFF",strokeWidth:"0.7",opacity:"0.55"}),n.jsx("line",{x1:"25",y1:"36",x2:"32",y2:"52",stroke:"#FFFFFF",strokeWidth:"0.5",opacity:"0.4"}),n.jsx("line",{x1:"0",y1:"70",x2:"60",y2:"70",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function Utt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"4",y:"22",width:"52",height:"5",fill:"#EDE7DC",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("polygon",{points:"9,27 13,27 12,66 10,66",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"1"}),n.jsx("polygon",{points:"47,27 51,27 50,66 48,66",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"1"}),n.jsx("line",{x1:"0",y1:"68",x2:"60",y2:"68",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function Ktt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"3",y:"24",width:"54",height:"7",fill:"#EDE7DC",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("polygon",{points:"8,31 13,31 12,66 9,66",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"1"}),n.jsx("polygon",{points:"47,31 52,31 51,66 48,66",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"1"}),n.jsx("line",{x1:"0",y1:"68",x2:"60",y2:"68",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function Ztt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"12",y:"4",width:"36",height:"68",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"14",y:"6",width:"32",height:"11",fill:"#DDD3C4",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("rect",{x:"14",y:"19",width:"32",height:"11",fill:"#DDD3C4",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("rect",{x:"14",y:"32",width:"32",height:"11",fill:"#DDD3C4",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("rect",{x:"14",y:"45",width:"32",height:"11",fill:"#DDD3C4",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("rect",{x:"14",y:"58",width:"32",height:"11",fill:"#DDD3C4",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("line",{x1:"0",y1:"74",x2:"60",y2:"74",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function qtt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"18",y:"14",width:"24",height:"44",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"20",y:"16",width:"20",height:"10",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"20",y:"27",width:"20",height:"10",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"20",y:"38",width:"20",height:"10",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("circle",{cx:"30",cy:"21",r:"0.7",fill:"#182137"}),n.jsx("circle",{cx:"30",cy:"32",r:"0.7",fill:"#182137"}),n.jsx("circle",{cx:"30",cy:"43",r:"0.7",fill:"#182137"}),n.jsx("line",{x1:"20",y1:"50",x2:"40",y2:"50",stroke:"#182137",strokeWidth:"0.4",opacity:"0.4"}),n.jsx("circle",{cx:"20",cy:"62",r:"2.5",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("circle",{cx:"40",cy:"62",r:"2.5",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("circle",{cx:"20",cy:"68",r:"2.5",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("circle",{cx:"40",cy:"68",r:"2.5",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("line",{x1:"0",y1:"74",x2:"60",y2:"74",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function Jtt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"4",y:"44",width:"52",height:"14",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"4",y:"26",width:"6",height:"32",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"50",y:"26",width:"6",height:"32",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"11",y:"40",width:"19",height:"8",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("rect",{x:"30",y:"40",width:"19",height:"8",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("rect",{x:"11",y:"22",width:"19",height:"18",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("rect",{x:"30",y:"22",width:"19",height:"18",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("line",{x1:"0",y1:"60",x2:"60",y2:"60",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function Qtt(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,
444children:[n.jsx("rect",{x:"6",y:"10",width:"48",height:"14",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"6",y:"24",width:"14",height:"40",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"8",y:"13",width:"11",height:"8",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"0.4"}),n.jsx("rect",{x:"20",y:"13",width:"11",height:"8",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"0.4"}),n.jsx("rect",{x:"32",y:"13",width:"11",height:"8",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"0.4"}),n.jsx("rect",{x:"9",y:"27",width:"8",height:"14",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"0.4"}),n.jsx("rect",{x:"9",y:"42",width:"8",height:"14",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"0.4"}),n.jsx("rect",{x:"45",y:"13",width:"8",height:"8",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"0.7"}),n.jsx("line",{x1:"0",y1:"68",x2:"60",y2:"68",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function tet(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"14",y:"46",width:"32",height:"14",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"14",y:"28",width:"6",height:"32",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"40",y:"28",width:"6",height:"32",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"21",y:"42",width:"18",height:"8",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("rect",{x:"21",y:"22",width:"18",height:"20",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("line",{x1:"0",y1:"62",x2:"60",y2:"62",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function eet(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"14",y:"30",width:"32",height:"36",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"1.2",rx:"2"}),n.jsx("line",{x1:"16",y1:"34",x2:"44",y2:"34",stroke:"#182137",strokeWidth:"0.4",opacity:"0.45",strokeDasharray:"1 1"}),n.jsx("circle",{cx:"30",cy:"48",r:"1.2",fill:"#D85D43",opacity:"0.5"}),n.jsx("line",{x1:"0",y1:"68",x2:"60",y2:"68",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function net(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("circle",{cx:"30",cy:"40",r:"22",fill:"#EDE7DC",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("circle",{cx:"30",cy:"40",r:"19",fill:"none",stroke:"#182137",strokeWidth:"0.4",opacity:"0.4"}),n.jsx("rect",{x:"18",y:"28",width:"3",height:"3",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"0.4"}),n.jsx("rect",{x:"39",y:"28",width:"3",height:"3",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"0.4"}),n.jsx("rect",{x:"18",y:"49",width:"3",height:"3",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"0.4"}),n.jsx("rect",{x:"39",y:"49",width:"3",height:"3",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"0.4"})]})}function oet(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"20",y:"14",width:"20",height:"22",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"18",y:"34",width:"24",height:"6",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("polygon",{points:"20,40 23,40 22,66 21,66",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"1"}),n.jsx("polygon",{points:"37,40 40,40 39,66 38,66",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"1"}),n.jsx("line",{x1:"0",y1:"68",x2:"60",y2:"68",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function set(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("line",{x1:"6",y1:"4",x2:"6",y2:"72",stroke:"#182137",strokeWidth:"0.7",strokeDasharray:"2 1.5",opacity:"0.35"}),n.jsx("rect",{x:"8",y:"22",width:"44",height:"5",fill:"#EDE7DC",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"10",y:"27",width:"6",height:"3",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("rect",{x:"44",y:"27",width:"6",height:"3",fill:"#D8CFBF",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("rect",{x:"14",y:"42",width:"32",height:"22",fill:"none",stroke:"#182137",strokeWidth:"0.5",strokeDasharray:"2 1.5",opacity:"0.4"}),n.jsx("circle",{cx:"30",cy:"53",r:"4",fill:"none",stroke:"#182137",strokeWidth:"0.4",opacity:"0.4"}),n.jsx("line",{x1:"0",y1:"66",x2:"60",y2:"66",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function ret(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,
444children:[n.jsx("rect",{x:"18",y:"8",width:"24",height:"3",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"0.8"}),n.jsx("polygon",{points:"30,41 52,41 52,43 30,43",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.3"}),n.jsx("polygon",{points:"30.6,42.4 37.4,63.3 35.5,63.9 28.7,43.0",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.3"}),n.jsx("polygon",{points:"29.4,42.4 11.6,55.4 10.4,53.8 28.2,40.8",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.3"}),n.jsx("polygon",{points:"28.7,41.0 10.4,28.2 11.6,26.6 29.9,39.4",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.3"}),n.jsx("polygon",{points:"30.6,39.6 35.5,18.1 37.4,18.7 32.5,40.2",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.3"}),n.jsx("circle",{cx:"30",cy:"42",r:"11",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("circle",{cx:"30",cy:"42",r:"2",fill:"#3A352F"})]})}function iet(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("line",{x1:"50",y1:"4",x2:"50",y2:"72",stroke:"#182137",strokeWidth:"0.7",strokeDasharray:"2 1.5",opacity:"0.35"}),n.jsx("rect",{x:"44",y:"10",width:"6",height:"32",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"45",y:"14",width:"4",height:"3",fill:"#C9C9C9",stroke:"#182137",strokeWidth:"0.4"}),n.jsx("rect",{x:"22",y:"42",width:"22",height:"11",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2",rx:"2"}),n.jsx("rect",{x:"22",y:"40",width:"22",height:"3",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"0.7",rx:"1"}),n.jsx("line",{x1:"0",y1:"68",x2:"60",y2:"68",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function aet(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"6",y:"8",width:"48",height:"2",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.4"}),n.jsx("circle",{cx:"6",cy:"9",r:"1.2",fill:"#3A352F"}),n.jsx("circle",{cx:"54",cy:"9",r:"1.2",fill:"#3A352F"}),n.jsx("rect",{x:"8",y:"10",width:"44",height:"58",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("line",{x1:"14",y1:"11",x2:"14",y2:"67",stroke:"#182137",strokeWidth:"0.4",opacity:"0.45"}),n.jsx("line",{x1:"20",y1:"11",x2:"20",y2:"67",stroke:"#182137",strokeWidth:"0.4",opacity:"0.45"}),n.jsx("line",{x1:"26",y1:"11",x2:"26",y2:"67",stroke:"#182137",strokeWidth:"0.4",opacity:"0.45"}),n.jsx("line",{x1:"32",y1:"11",x2:"32",y2:"67",stroke:"#182137",strokeWidth:"0.4",opacity:"0.45"}),n.jsx("line",{x1:"38",y1:"11",x2:"38",y2:"67",stroke:"#182137",strokeWidth:"0.4",opacity:"0.45"}),n.jsx("line",{x1:"44",y1:"11",x2:"44",y2:"67",stroke:"#182137",strokeWidth:"0.4",opacity:"0.45"}),n.jsx("path",{d:"M 8 67 Q 14 70 20 67 T 32 67 T 44 67 T 52 67",fill:"none",stroke:"#182137",strokeWidth:"0.5",opacity:"0.5"}),n.jsx("line",{x1:"0",y1:"72",x2:"60",y2:"72",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function cet(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"11",y:"26",width:"38",height:"36",fill:"#DCE8EC",stroke:"#182137",strokeWidth:"0.8",opacity:"0.85"}),n.jsx("line",{x1:"16",y1:"59",x2:"40",y2:"29",stroke:"#FFFFFF",strokeWidth:"1",opacity:"0.6"}),n.jsx("line",{x1:"24",y1:"60",x2:"44",y2:"34",stroke:"#FFFFFF",strokeWidth:"0.6",opacity:"0.4"}),n.jsx("rect",{x:"7",y:"20",width:"46",height:"5",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.6",rx:"1.5"}),n.jsx("rect",{x:"8",y:"24",width:"3",height:"38",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.4"}),n.jsx("rect",{x:"28.5",y:"24",width:"3",height:"38",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.4"}),n.jsx("rect",{x:"49",y:"24",width:"3",height:"38",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.4"}),n.jsx("line",{x1:"0",y1:"62",x2:"60",y2:"62",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function det(){const t=[27,35,43,51];return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"7",y:"20",width:"46",height:"5",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.6",rx:"1.5"}),n.jsx("rect",{x:"8",y:"24",width:"3",height:"38",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.4"}),n.jsx("rect",{x:"28.5",y:"24",width:"3",height:"38",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.4"}),n.jsx("rect",{x:"49",y:"24",width:"3",height:"38",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.4"}),t.map(e=>
444n.jsx("rect",{x:"11",y:e,width:"38",height:"2.4",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.3",rx:"1"},e)),n.jsx("line",{x1:"0",y1:"62",x2:"60",y2:"62",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function uet(){const t=[14,18,22,26,30,34,38,42,46];return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"7",y:"20",width:"46",height:"5",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.6",rx:"1.5"}),t.map(e=>n.jsx("rect",{x:e,y:"25",width:"1.6",height:"37",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.25"},e)),n.jsx("rect",{x:"8",y:"24",width:"3",height:"38",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.4"}),n.jsx("rect",{x:"49",y:"24",width:"3",height:"38",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.4"}),n.jsx("line",{x1:"0",y1:"62",x2:"60",y2:"62",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function het(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"9",y:"16",width:"42",height:"42",fill:"#DCE8EC",stroke:"#182137",strokeWidth:"0.8",opacity:"0.85"}),n.jsx("line",{x1:"14",y1:"55",x2:"40",y2:"22",stroke:"#FFFFFF",strokeWidth:"1",opacity:"0.6"}),n.jsx("line",{x1:"22",y1:"56",x2:"45",y2:"27",stroke:"#FFFFFF",strokeWidth:"0.6",opacity:"0.4"}),n.jsx("rect",{x:"7",y:"55",width:"46",height:"7",fill:"#3A352F",stroke:"#182137",strokeWidth:"0.6",rx:"1"}),n.jsx("line",{x1:"0",y1:"62",x2:"60",y2:"62",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function met(){const t=[16,22,28,34,40,46,52,58,64];return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"9",y:"8",width:"42",height:"62",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("rect",{x:"11",y:"11",width:"18.5",height:"56",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),n.jsx("rect",{x:"30.5",y:"11",width:"18.5",height:"56",fill:"#E8DFD3",stroke:"#D85D43",strokeWidth:"0.6"}),t.map(e=>n.jsxs("g",{children:[n.jsx("line",{x1:"13.5",y1:e,x2:"27",y2:e,stroke:"#182137",strokeWidth:"0.5",opacity:"0.45"}),n.jsx("line",{x1:"33",y1:e,x2:"46.5",y2:e,stroke:"#182137",strokeWidth:"0.5",opacity:"0.45"})]},e)),n.jsx("circle",{cx:"27.5",cy:"39",r:"0.9",fill:"#182137"}),n.jsx("circle",{cx:"32.5",cy:"39",r:"0.9",fill:"#182137"}),n.jsx("line",{x1:"0",y1:"70",x2:"60",y2:"70",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function fet(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("line",{x1:"0",y1:"14",x2:"60",y2:"14",stroke:"#182137",strokeWidth:"1",opacity:"0.55"}),n.jsx("path",{d:"M 24 18 L 12 64 L 48 64 L 36 18 Z",fill:"#FDF6E3",opacity:"0.4"}),n.jsx("circle",{cx:"30",cy:"16",r:"7",fill:"#2A2A2A",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("circle",{cx:"30",cy:"16",r:"4",fill:"#FDF6E3",stroke:"#182137",strokeWidth:"0.4"}),n.jsx("ellipse",{cx:"30",cy:"64",rx:"17",ry:"2.5",fill:"#FDF6E3",opacity:"0.5"})]})}function xet(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("line",{x1:"0",y1:"12",x2:"60",y2:"12",stroke:"#182137",strokeWidth:"1",opacity:"0.55"}),n.jsx("rect",{x:"6",y:"12",width:"48",height:"4",fill:"#2A2A2A",stroke:"#182137",strokeWidth:"1"}),n.jsx("rect",{x:"17",y:"16",width:"9",height:"2",fill:"#FDF6E3",stroke:"#182137",strokeWidth:"0.3"}),n.jsx("rect",{x:"34",y:"16",width:"9",height:"2",fill:"#FDF6E3",stroke:"#182137",strokeWidth:"0.3"}),n.jsx("rect",{x:"11",y:"16",width:"4",height:"7",rx:"1.5",fill:"#1A1A1A",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("rect",{x:"28",y:"16",width:"4",height:"7",rx:"1.5",fill:"#1A1A1A",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("rect",{x:"45",y:"16",width:"4",height:"7",rx:"1.5",fill:"#1A1A1A",stroke:"#182137",strokeWidth:"0.5"}),n.jsx("path",{d:"M 11 23 L 7 60 L 19 60 L 15 23 Z",fill:"#FDF6E3",opacity:"0.35"}),n.jsx("path",{d:"M 45 23 L 41 60 L 53 60 L 49 23 Z",fill:"#FDF6E3",opacity:"0.35"})]})}function pet(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,
444children:[n.jsx("line",{x1:"14",y1:"4",x2:"14",y2:"72",stroke:"#182137",strokeWidth:"0.8",strokeDasharray:"2 1.5",opacity:"0.4"}),n.jsx("path",{d:"M 14 30 L 40 16 L 40 24 L 14 36 Z",fill:"#FDF6E3",opacity:"0.4"}),n.jsx("path",{d:"M 14 44 L 40 56 L 40 48 L 14 40 Z",fill:"#FDF6E3",opacity:"0.4"}),n.jsx("rect",{x:"14",y:"32",width:"12",height:"16",fill:"#2A2A2A",stroke:"#182137",strokeWidth:"1.2",rx:"1"}),n.jsx("rect",{x:"17",y:"35",width:"6",height:"10",fill:"#FDF6E3",stroke:"#182137",strokeWidth:"0.4",rx:"0.8"}),n.jsx("line",{x1:"0",y1:"72",x2:"60",y2:"72",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function get(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("path",{d:"M 22 14 L 38 14 L 44 30 L 16 30 Z",fill:"#E8DFD3",stroke:"#182137",strokeWidth:"1.2"}),n.jsx("line",{x1:"16",y1:"30",x2:"44",y2:"30",stroke:"#FDF6E3",strokeWidth:"2"}),n.jsx("path",{d:"M 16 30 L 8 66 L 52 66 L 44 30 Z",fill:"#FDF6E3",opacity:"0.3"}),n.jsx("rect",{x:"29",y:"30",width:"2",height:"34",fill:"#3A352F"}),n.jsx("ellipse",{cx:"30",cy:"65",rx:"11",ry:"3",fill:"#2A2A2A",stroke:"#182137",strokeWidth:"1"}),n.jsx("line",{x1:"0",y1:"68",x2:"60",y2:"68",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function Kp(t,e,s,o,r){let i=`M ${t} ${e} L ${t} ${e-r}`,a=t,l=e-r;for(let c=1;c<=s;c+=1)a+=o,i+=` L ${a} ${l}`,c<s&&(l-=r,i+=` L ${a} ${l}`);return`${i} L ${a} ${e} Z`}function bet(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("path",{d:Kp(9,58,4,10,8),fill:"#EDE7DC",stroke:"#182137",strokeWidth:"1.2",strokeLinejoin:"round"}),n.jsx("line",{x1:"0",y1:"58",x2:"60",y2:"58",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function Met(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("path",{d:Kp(8,62,8,6,6.4),fill:"#EDE7DC",stroke:"#182137",strokeWidth:"1.2",strokeLinejoin:"round"}),n.jsx("line",{x1:"0",y1:"62",x2:"60",y2:"62",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function yet(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("path",{d:Kp(12,60,2,18,13),fill:"#EDE7DC",stroke:"#182137",strokeWidth:"1.2",strokeLinejoin:"round"}),n.jsx("line",{x1:"0",y1:"60",x2:"60",y2:"60",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function wet(){const i=c=>
4448+(c+1)*6,a=c=>60-(c+1)*6;return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("path",{d:Kp(8,60,6,6,6),fill:"#EDE7DC",stroke:"#182137",strokeWidth:"1.2",strokeLinejoin:"round"}),n.jsx("line",{x1:i(0),y1:a(0)-12,x2:i(5),y2:a(5)-12,stroke:"#3A352F",strokeWidth:"2",strokeLinecap:"round"}),[0,2,4,5].map(c=>n.jsx("line",{x1:i(c),y1:a(c),x2:i(c),y2:a(c)-12,stroke:"#3A352F",strokeWidth:"1.4"},c)),n.jsx("line",{x1:"0",y1:"60",x2:"60",y2:"60",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function ket(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("path",{d:Kp(18,60,6,6,6),fill:"#DCD3C4",stroke:"#182137",strokeWidth:"0.8",strokeLinejoin:"round",opacity:"0.8"}),Array.from({length:6},(i,a)=>n.jsx("rect",{x:10+a*6-3,y:60-(a+1)*6-3,width:14,height:"3.4",fill:"#EDE7DC",stroke:"#182137",strokeWidth:"0.9",rx:"0.6"},a)),n.jsx("line",{x1:"0",y1:"60",x2:"60",y2:"60",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function vet(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[Array.from({length:5},(r,i)=>{const a=46-i*8,l=58-(i+1)*8;return n.jsx("rect",{x:30-a/2,y:l,width:a,height:8,fill:"#EDE7DC",stroke:"#182137",strokeWidth:"1"},i)}),n.jsx("line",{x1:"0",y1:"58",x2:"60",y2:"58",stroke:"#182137",strokeWidth:"0.6",opacity:"0.5"})]})}function jet(){const t=[22,28,34,40,46,52];return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"10",y:"12",width:"40",height:"10",fill:"#EDE7DC",stroke:"#182137",strokeWidth:"1.1"}),n.jsx("rect",{x:"10",y:"22",width:"16",height:"40",fill:"#EDE7DC",stroke:"#182137",strokeWidth:"1.1"}),n.jsx("rect",{x:"34",y:"22",width:"16",height:"40",fill:"#EDE7DC",stroke:"#182137",strokeWidth:"1.1"}),t.map(e=>n.jsxs("g",{children:[n.jsx("line",{x1:"10",y1:e,x2:"26",y2:e,stroke:"#182137",strokeWidth:"0.7",opacity:"0.6"}),n.jsx("line",{x1:"34",y1:e,x2:"50",y2:e,stroke:"#182137",strokeWidth:"0.7",opacity:"0.6"})]},e))]})}function _et(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:"12",y:"30",width:"16",height:"32",fill:"#EDE7DC",stroke:"#182137",strokeWidth:"1.1"}),n.jsx("rect",{x:"12",y:"14",width:"16",height:"16",fill:"#EDE7DC",stroke:"#182137",strokeWidth:"1.1"}),n.jsx("rect",{x:"28",y:"14",width:"28",height:"16",fill:"#EDE7DC",stroke:"#182137",strokeWidth:"1.1"}),[36,42,48,54].map(t=>n.jsx("line",{x1:"12",y1:t,x2:"28",y2:t,stroke:"#182137",strokeWidth:"0.7",opacity:"0.6"},t)),[34,40,46,52].map(t=>n.jsx("line",{x1:t,y1:"14",x2:t,y2:"30",stroke:"#182137",strokeWidth:"0.7",opacity:"0.6"},t))]})}function Eet(){const r=[200,160,120,80,40,0,-40],i=(a,l)=>{const c=a*Math.PI/180;return{x:30+l*Math.cos(c),y:42-l*Math.sin(c)}};return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[r.slice(0,-1).map((a,l)=>{const c=a,d=r[l+1],u=i(c,5),h=i(c,22),x=i(d,22),f=i(d,5);return n.jsx("path",{d:`M ${u.x} ${u.y} L ${h.x} ${h.y} L ${x.x} ${x.y} L ${f.x} ${f.y} Z`,fill:"#EDE7DC",stroke:"#182137",strokeWidth:"0.9",strokeLinejoin:"round"},a)}),n.jsx("circle",{cx:30,cy:42,r:5,fill:"#DCD3C4",stroke:"#182137",strokeWidth:"1"}),n.jsx("rect",{x:"26",y:"60",width:"16",height:"12",fill:"#EDE7DC",stroke:"#182137",strokeWidth:"1"})]})}function Det(){return n.jsxs("svg",{viewBox:"0 0 60 80",className:"block h-[68px] w-auto","aria-hidden":!0,children:[n.jsx("rect",{x:6,y:10,width:48,height:60,fill:"none",stroke:"#182137",strokeWidth:1.2,strokeDasharray:"3 2.5",opacity:.45}),n.jsx("line",{x1:6,y1:70,x2:54,y2:70,stroke:"#182137",strokeWidth:.8,opacity:.45}),n.jsx("circle",{cx:30,cy:40,r:1.4,fill:"#D85D43",opacity:.55})]})}const Fet={kitchen:zN,kitchenAssembly:AI,carpentryBedroom:pT,carpentryUtility:c5,living:um,dining:zw,bedroomMaster:sT,bedroomKids:oT,bathroom:Jh,entry:Cf,office:aT,utility:c5,lighting:ZI,railings:PI,stairs:VN,accessories:dT},Cet={...Object.fromEntries(AF.map(t=>[t.id,()=>n.jsx(ntt,{compartments:t.spec.compartments,widthMm:t.spec.widthMm,heightMm:t.spec.heightMm}
444)])),"kitchen.base":()=>n.jsx(Xh,{kind:"base"}),"kitchen.wall":()=>n.jsx(Xh,{kind:"wall"}),"kitchen.tall":()=>n.jsx(Xh,{kind:"tall"}),"kitchen.sinkBase":()=>n.jsx(Xh,{kind:"sinkBase"}),"kitchen.ovenTall":()=>n.jsx(Xh,{kind:"ovenTall"}),"kitchen.hoodWall":()=>n.jsx(Xh,{kind:"hoodWall"}),"kitchen.sketchWall":()=>n.jsx(ktt,{}),"kitchen.islandBar":()=>n.jsx(Mtt,{}),"kitchen.islandCooktop":()=>n.jsx(ytt,{}),"kitchen.islandCooktopSink":()=>n.jsx(wtt,{}),"kitchen.fridgeTall":()=>n.jsx(btt,{}),"kitchen.fullLinear":()=>n.jsx(yy,{layout:Sf.linear}),"kitchen.fullSymmetric":()=>n.jsx(yy,{layout:Sf.symmetric}),"kitchen.fullCompact":()=>n.jsx(yy,{layout:Sf.compact}),"kitchen.fullSink":()=>n.jsx(vtt,{}),"kitchenAssembly.base30":()=>n.jsx(za,{widthMm:300,heightMm:850,drawerCount:0,doorCount:1}),"kitchenAssembly.base60":()=>n.jsx(za,{widthMm:600,heightMm:850,drawerCount:1,doorCount:2}),"kitchenAssembly.base80":()=>n.jsx(za,{widthMm:800,heightMm:850,drawerCount:1,doorCount:2}),"kitchenAssembly.base90":()=>n.jsx(za,{widthMm:900,heightMm:850,drawerCount:1,doorCount:2}),"kitchenAssembly.drawerBank60":()=>n.jsx(za,{widthMm:600,heightMm:850,drawerCount:4,doorCount:0}),"kitchenAssembly.drawerBank3":()=>n.jsx(za,{widthMm:600,heightMm:850,drawerCount:3,doorCount:0}),"kitchenAssembly.trashPull":()=>n.jsx(za,{widthMm:600,heightMm:850,drawerCount:0,doorCount:1}),"kitchenAssembly.bottlePull15":()=>n.jsx(za,{widthMm:150,heightMm:850,drawerCount:0,doorCount:1}),"kitchenAssembly.wall40":()=>n.jsx(za,{widthMm:400,heightMm:720,drawerCount:0,doorCount:1,mounted:!0}),"kitchenAssembly.wall45":()=>n.jsx(za,{widthMm:450,heightMm:720,drawerCount:0,doorCount:1,mounted:!0}),"kitchenAssembly.wall60":()=>n.jsx(za,{widthMm:600,heightMm:720,drawerCount:0,doorCount:2,mounted:!0}),"kitchenAssembly.wall80":()=>n.jsx(za,{widthMm:800,heightMm:720,drawerCount:0,doorCount:2,mounted:!0}),"kitchenAssembly.hood":()=>n.jsx(Xh,{kind:"hoodWall"}),"kitchenAssembly.tall60":()=>n.jsx(za,{widthMm:600,heightMm:2200,drawerCount:1,doorCount:2,plinth:!0}),"kitchenAssembly.supermarket40":()=>n.jsx(za,{widthMm:400,heightMm:2800,drawerCount:0,doorCount:1,plinth:!0}),"kitchenAssembly.sink":()=>n.jsx(f_,{}),"kitchenAssembly.sinkLarge":()=>n.jsx(f_,{}),"kitchenAssembly.roundedTall":()=>n.jsx(ott,{}),"kitchenAssembly.roundedBase":()=>n.jsx(stt,{}),"kitchenAssembly.roundedDisplay":()=>n.jsx(rtt,{}),"kitchenAssembly.roundedOpenShelves":()=>n.jsx(itt,{}),"kitchenAssembly.worktop":()=>n.jsx(att,{}),"kitchenAssembly.cornerL":()=>n.jsx(m_,{}),"kitchenAssembly.cornerLTall":()=>n.jsx(m_,{}),"kitchenAssembly.carousel":()=>n.jsx(htt,{}),"kitchenAssembly.cooktop":()=>n.jsx(ltt,{}),"kitchenAssembly.applianceTower":()=>n.jsx(ctt,{}),"kitchenAssembly.ovenColumn":()=>n.jsx(utt,{}),"kitchenAssembly.dishwasher":()=>n.jsx(dtt,{}),"kitchenAssembly.tambour":()=>n.jsx(mtt,{}),"living.wallUnit":()=>n.jsx(ftt,{}),"living.shelvingPoles":()=>n.jsx(xtt,{}),"living.sofa3":()=>n.jsx(Ett,{}),"living.chaise":()=>n.jsx(Dtt,{}),"living.tvFloating":()=>n.jsx(Ftt,{}),"living.tvScreen":()=>n.jsx(Ctt,{}),"living.coffeeTable":()=>n.jsx(Ntt,{}),"living.rug":()=>n.jsx(Itt,{}),"wardrobe.standard":()=>n.jsx(ptt,{}),"wardrobe.wall":()=>n.jsx(gtt,{}),"table.dining":()=>n.jsx(jtt,{}),"credenza.fluted":()=>n.jsx(_tt,{}),"bedroomMaster.bedUpholstered":()=>n.jsx(Ttt,{}),"bedroomMaster.nightstand":()=>n.jsx(Stt,{}),"bedroomMaster.slidingWardrobe":()=>n.jsx(Ptt,{}),"bedroomMaster.dresser":()=>n.jsx(Att,{}),"bedroomMaster.vanity":()=>n.jsx(Ltt,{}),"bedroomMaster.endBench":()=>n.jsx(Wtt,{}),"bedroomKids.singleBed":()=>n.jsx(Rtt,{}),"bedroomKids.bunkBed":()=>n.jsx(Ott,{}),"bedroomKids.desk":()=>n.jsx(Htt,{}),"bedroomKids.shelf":()=>n.jsx(Btt,{}),"bathroom.vanity":()=>n.jsx(Vtt,{}),"bathroom.vanity60":()=>n.jsx(gf,{doors:2,interpotz:"none"}),"bathroom.vanity80":()=>n.jsx(gf,{doors:2,interpotz:"none"}),"bathroom.vanity100":()=>n.jsx(gf,{doors:2,interpotz:"none"}),"bathroom.vanity120":()=>n.jsx(gf,{doors:3,interpotz:"none"}),"bathroom.vanity120Double":()=>n.jsx(gf,{doors:3,double:!0,interpotz:"none"}),"bathroom.vanityWallFaucet":()=>n.jsx(gf,{doors:2,faucet:"wall",interpotz:"none"}),"bathroom.mirror":()=>n.jsx(ztt,{}),"bathroom.shower":()=>n.jsx($tt,{}),"bathroom.tub":()=>n.jsx(Xtt,{}),"entry.unit":()=>n.jsx(Ytt,{}),"entry.fullMirror":()=>n.jsx(Gtt,{}),"entry.console":()=>n.jsx(Utt,{}),"office.desk":()=>n.jsx(Ktt,{}),"office.bookcase":()=>n.jsx(Ztt,{}),"office.pedestal":()=>n.jsx(qtt,{}),"living.sofa2":()=>n.jsx(Jtt,{}),"living.cornerModule":()=>n.jsx(Qtt,{}),"living.armchair":()=>n.jsx(tet,{}),"living.pouf":()=>n.jsx(eet,{}),"dining.round":()=>n.jsx(net,{}),"dining.chair":()=>n.jsx(oet,{}),"utility.laundryTop":()=>n.jsx(set,{}),"office.ergoChair":()=>n.jsx(ret,{}),"bathroom.wcWall":()=>n.jsx(iet,{}),"living.curtain":()=>n.jsx(aet,{}),"living.glassRailing":()=>n.jsx(cet,{}),"railings.glassFrameless":()=>n.jsx(het,{}),"living.railingHorizontal":()=>n.jsx(det,{}),"living.railingVertical":()=>n.jsx(uet,{}),"utility.laundryScreen":()=>n.jsx(met,{}),"lighting.recessed":()=>n.jsx(fet,{}),"lighting.panel":()=>n.jsx(xet,{}),"lighting.wall":()=>n.jsx(pet,{}),"lighting.floor":()=>n.jsx(get,{}),"stairs.winder":()=>n.jsx(Eet,{}),"stairs.podium":()=>n.jsx(vet,{}),"stairs.uShape":()=>n.jsx(jet,{}),"stairs.straight":()=>n.jsx(Met,{}),"stairs.step2":()=>n.jsx(yet,{}),"stairs.straightRail":()=>n.jsx(wet,{}),"stairs.floating":()=>n.jsx(ket,{}),"stairs.lShape":()=>n.jsx(_et,{}),"stairs.stoop":()=>n.jsx(bet,{})};function _6(t,e="immediate"){const s=e==="selectThenClick",o=t==="kitchenAssembly";return{deferToFloorClick:s,requestOrbitView:o&&!s,selectBuiltHost:!o}}function Net(t){return _6("kitchenAssembly",t).requestOrbitView}function wy({entities:t,furnitureGroups:e,selectedEntityId:s,onEntitiesChange:o,onFurnitureGroupsChange:r,onSelectedEntityChange:i,fpIsDark:a,anchoredWall:l,floorAnchor:c,modelCenterMm:d,ceilingHeightMm:u,measurementUnit:h="cm",placementMode:x="immediate",selectedTemplateId:f=null,onTemplateSelect:p,userTemplates:b=[],userTemplatesLoading:M=!1,userTemplatesError:g=null,defaultUserTemplateName:w="תבנית אישית",onSaveUserTemplate:k,onRenameUserTemplate:_,onDeleteUserTemplate:j,onUserTemplateSelect:v,onRequestOrbitView:C,selectPlacedTemplateHost:N=!0,elementContent:P=null}){const{t:L,i18n:A}=yn(),[W,S]=m.useState(""),[B,R]=m.useState("catalog"),z=!!(k&&_&&j),X=P!=null,ft=z||X;m.useEffect(()=>{if(X){R("element");return}R(st=>st==="element"?"catalog":st)},[X]);const[tt,G]=m.useState(new Set),Y=st=>G(ct=>{const pt=new Set(ct);return pt.has(st)?pt.delete(st):(pt.add(st),st==="kitchenAssembly"&&Net(x)&&
444(C==null||C())),pt}),J=O("h-7 w-full rounded-[3px] border px-2 text-[12px] font-bold tabular-nums outline-none",a?"border-white/15 bg-[#0A0A0A] text-white focus:border-white/35":"border-[#182137]/12 bg-white text-[#182137] focus:border-[#182137]/40"),Mt=st=>O("min-w-0 flex-1 rounded-[2px] px-1 py-1.5 text-[10px] font-black leading-tight transition-colors",st?a?"bg-[#EC7357] text-white":"bg-[#D84B2E] text-white":a?"text-white/55 hover:bg-white/[0.06]":"text-[#182137]/55 hover:bg-[#E8DFD3]"),Rt=st=>{const ct=_6(st.category,x);if(ct.deferToFloorClick){p==null||p(st);return}ct.requestOrbitView&&(C==null||C());const pt=M7(st,{entities:t,furnitureGroups:e,anchoredWall:l,floorAnchor:c,modelCenterMm:d,ceilingHeightMm:u});o([...t,...pt.entities]),r([...e.filter(xt=>xt.id!==pt.group.id),pt.group]),ct.selectBuiltHost&&N?i(pt.hostId):N||i(null)},it=st=>{if(x==="selectThenClick"){if(st.placement_mode==="wall"){ln.info(L("sketchWorkflow.wallTemplateRightClick",{defaultValue:"זו תבנית לקיר — לחץ לחיצה ימנית על קיר ובחר הוסף תבנית"}));return}v==null||v(st);return}if(l&&st.placement_mode==="floor"){ln.info(L("sketchWorkflow.floorOnly",{defaultValue:"התבנית הוגדרה להצבה על הרצפה"}));return}if(!l&&st.placement_mode==="wall"){ln.info(L("sketchWorkflow.wallOnly",{defaultValue:"זו תבנית לקיר — פתח את התבניות מלחיצה ימנית על קיר"}));return}try{const ct=f6(st,{entities:t,furnitureGroups:e,anchoredWall:l,floorAnchor:c,modelCenterMm:d});o([...t,...ct.entities]),r([...e.filter(pt=>pt.id!==ct.group.id),ct.group]),i(N?ct.hostId:null)}catch(ct){ln.error(ct instanceof Error?ct.message:L("sketchWorkflow.placeFailed",{defaultValue:"הצבת התבנית נכשלה"}))}};return n.jsxs("div",{dir:A.dir(),className:"space-y-4 px-1 pb-2 font-heebo",children:[ft?n.jsxs("div",{className:O("flex shrink-0 gap-0.5 rounded-[3px] border p-0.5",a?"border-white/12 bg-[#0A0A0A]":"border-[#182137]/12 bg-white"),role:"tablist","aria-label":L("sketchTemplates.tabsAria",{defaultValue:"סוג תבניות"}),children:[n.jsx("button",{type:"button",role:"tab","aria-selected":B==="catalog",onClick:()=>R("catalog"),className:Mt(B==="catalog"),style:{letterSpacing:"-0.02em"},children:L("sketchTemplates.tabs.catalog",{defaultValue:"תבניות"})}),z?n.jsxs("button",{type:"button",role:"tab","aria-selected":B==="mine",onClick:()=>R("mine"),className:Mt(B==="mine"),style:{letterSpacing:"-0.02em"},children:[L("sketchTemplates.tabs.mine",{defaultValue:"תבניות שלי"}),b.length>0?n.jsxs("span",{className:"ms-0.5 opacity-80",children:["(",b.length,")"]}):null]}):null,X?n.jsx("button",{type:"button",role:"tab","aria-selected":B==="element",onClick:()=>R("element"),className:Mt(B==="element"),style:{letterSpacing:"-0.02em"},children:L("sketchTemplates.tabs.element",{defaultValue:"אלמנט"})}):null]}):null,z&&B==="mine"&&k&&_&&j?n.jsx(ett,{templates:b,loading:M,error:g,fpIsDark:a,selectedTemplateId:f,canSaveSelected:NJ(t,e,s),canSaveAll:CJ(t),defaultName:w,onSave:async st=>{await k(st),R("mine")},onUse:it,onRename:_,onDelete:j}):null,X&&B==="element"?n.jsx("div",{"data-testid":"floorplan-templates-element-tab",children:P}):null,(!ft||B==="catalog")&&(()=>{const st=W.trim(),ct=st.toLowerCase(),pt=vt=>L(`sketchTemplates.items.${vt.id.replace(/\./g,"_")}`,{defaultValue:vt.nameHe}),xt=vt=>L(`sketchTemplates.planned.${vt.id.replace(/\./g,"_")}`,{defaultValue:vt.nameHe}),_t=vt=>!st||vt.nameHe.includes(st)||pt(vt).toLowerCase().includes(ct)||vt.id.toLowerCase().includes(ct),Ft=vt=>!st||vt.nameHe.includes(st)||xt(vt).toLowerCase().includes(ct)||vt.id.toLowerCase().includes(ct),Vt=ok.length+b7.length>12;return n.jsxs("div",{className:"space-y-4",children:[Vt?n.jsx("input",{className:J,value:W,onChange:vt=>S(vt.target.value),placeholder:L("sketchWorkflow.searchPlaceholder",{defaultValue:"חיפוש תבנית…"}),"aria-label":L("sketchWorkflow.searchAria",{defaultValue:"חיפוש תבנית"})}):null,VG.map(vt=>{const Ht=$G(vt.id).filter(_t),Tt=XG(vt.id).filter(Ft);if(Ht.length===0&&Tt.length===0)return null;const Zt=st?!0:tt.has(vt.id),At=Fet[vt.id],ut=Ht.length,kt=Tt.length;return n.jsxs("div",{className:"space-y-2",children:[n.jsxs("button",{type:"button",onClick:()=>Y(vt.id),"aria-expanded":Zt,"aria-controls":`tpl-cat-${vt.id}`,className:O("flex w-full items-center justify-between gap-2 rounded-[3px] border px-2.5 py-2 text-start transition-colors",a?"border-white/12 bg-[#0A0A0A] hover:bg-white/[0.06]":"border-[#182137]/12 bg-white hover:bg-[#
444E8DFD3]"),children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[At?n.jsx(At,{className:"h-5 w-5 shrink-0 text-[#D85D43]",strokeWidth:1.8,"aria-hidden":!0}):null,n.jsx("span",{className:O("truncate text-[14px] font-black leading-tight tracking-tight",a?"text-white":"text-[#182137]"),style:{letterSpacing:"-0.02em"},children:L(`sketchTemplates.categories.${vt.id}`,{defaultValue:vt.labelHe})})]}),n.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[n.jsxs("span",{className:O("text-[10px] font-bold tabular-nums",a?"text-white/45":"text-[#182137]/45"),children:[ut,"/",ut+kt]}),n.jsx(Yc,{className:O("h-4 w-4 shrink-0 transition-transform duration-150",Zt?"rotate-180":"rotate-0",a?"text-white/55":"text-[#182137]/55"),"aria-hidden":!0})]})]}),Zt?n.jsxs("div",{id:`tpl-cat-${vt.id}`,className:"grid gap-2",style:{gridTemplateColumns:`repeat(${vt.columns}, minmax(0, 1fr))`},children:[Ht.map(Et=>{const ht=Cet[Et.id],gt=x==="selectThenClick"&&f===Et.id;return n.jsxs("button",{type:"button",onClick:()=>Rt(Et),"aria-pressed":gt,draggable:!0,onDragStart:Pt=>{Pt.dataTransfer.setData(ob,Et.id),Pt.dataTransfer.effectAllowed="copy"},title:x==="selectThenClick"?L("sketchWorkflow.selectThenClickHint",{defaultValue:"לחיצה: בחירת תבנית · אחר כך לחצו בכל אזור בתוכנית למיקום מדויק · גרירה: מיקום ישיר"}):L("sketchWorkflow.immediateHint",{defaultValue:"לחיצה: מיקום אוטומטי · גרירה: מיקום ישיר בכל אזור בתוכנית"}),className:O("relative flex flex-col items-center gap-1.5 rounded-[3px] border p-1.5 transition-colors cursor-grab active:cursor-grabbing",gt?a?"border-[#EC7357] bg-[#EC7357]/15 shadow-[0_0_0_1px_rgba(236,115,87,0.42)]":"border-[#D84B2E] bg-[#FDF1EC] shadow-[0_0_0_1px_rgba(216,75,46,0.18)]":a?"border-white/12 bg-[#0A0A0A] hover:bg-white/[0.06]":"border-[#182137]/12 bg-white hover:bg-[#E8DFD3]"),children:[gt?n.jsx("span",{className:"absolute left-1.5 top-1.5 flex h-5 w-5 items-center justify-center rounded-full bg-[#D84B2E] text-white shadow-sm",children:n.jsx(Gc,{size:12,strokeWidth:3,"aria-hidden":!0})}):null,ht?n.jsx(ht,{}):null,n.jsx("span",{className:O("text-[10.5px] font-bold leading-tight text-center tabular-nums",a?"text-white":"text-[#182137]"),children:pt(Et)})]},Et.id)}),Tt.map(Et=>n.jsxs("div",{role:"presentation","aria-disabled":"true",title:L("sketchWorkflow.plannedTooltip",{defaultValue:"תבנית מתוכננת — בקרוב"}),className:O("relative flex flex-col items-center gap-1.5 rounded-[3px] border border-dashed p-1.5 cursor-not-allowed select-none",a?"border-white/15 bg-[#0A0A0A]/60":"border-[#182137]/20 bg-[#F7F4EF]"),children:[n.jsx(Det,{}),n.jsx("span",{className:O("text-[10.5px] font-bold leading-tight text-center",a?"text-white/55":"text-[#182137]/55"),children:xt(Et)}),n.jsx("span",{className:"absolute top-0.5 start-0.5 rounded-full bg-[#D85D43] px-1.5 py-[1px] text-[8px] font-black leading-none text-white","aria-hidden":!0,children:L("sketchWorkflow.comingSoon",{defaultValue:"בקרוב"})})]},Et.id))]}):null]},vt.id)})]})})()]})}function ky(t){return t.replace(/[؟?]+$/g,"").replace(/\s+/g," ").trim()}function E6(t){return`תשובה לשאלה "${t}": `}function Iet(t,e){const s=ky(t);return s?e.some(o=>{const r=ky(o),i=ky(E6(o));return s===r||s===i}):!1}const Tet=[{title:"בר קפה ביתי",meta:"1400 x 450 x 2100",prompt:"צור בר קפה ביתי פרוצדורלי ברוחב 1400 מ״מ, עומק 450 מ״מ, גובה 2100 מ״מ. בחלק התחתון שתי דלתות פלוטד ברוחב 420 מ״מ כל אחת, שלוש מגירות צרות במרכז, משטח עליון בעובי 40 מ״מ בגובה 900 מ״מ, נישה פתוחה למכונת קפה ברוחב 520 מ״מ וגובה 360 מ״מ, מעליה שני מדפים פתוחים ועוד ארון עליון עם דלתות חלקות. תן צבע גוף אלון בהיר וחזיתות בגוון טרקוטה עדין."},{title:"מחיצת ספרייה דו-צדדית",meta:"2200 x 350 x 1900",prompt:"צור מחיצת ספרייה דו-צדדית ברוחב 2200 מ״מ, עומק 350 מ״מ, גובה 1900 מ״מ. בנה גוף פתוח עם נישות לא סימטריות: 4 עמודות ו-3 שורות בגבהים משתנים, שתי קוביות סגורות בתחתית עם זוג דלתות, גב פתוח כדי שירגיש כמו מחיצה ולא ארון סגור. הוסף סוקל/בסיס דק בגובה 80 מ״מ וצבע גוף עץ כהה עם פנים נישות בגוון שמנת."},{title:"ספסל חלון עם אחסון",meta:"1800 x 480 x 520",prompt:"צור ספסל חלון עם אחסון ברוחב 1800 מ״מ, עומק 480 מ״מ, גובה 520 מ״מ. גוף נמוך עם שלוש מגירות רחבות בחזית, שתי נישות פתוחות בצדדים לספרים, משטח ישיבה עליון בעובי 70 מ״מ בצבע בד אפור בהיר, ורגלי קופסה נסתרות בגובה 60 מ״מ. שמור על מבנה נקי ומודרני."},{title:"ארון מזווה צר",meta:"900 x 500 x 2200",prompt:"צור ארון מזווה צר ברוחב 900 מ״מ, עומק 500 מ״מ, גובה 2200 מ״מ. חלק תחתון עם שתי מגירות עמוקות בגובה 260 מ״מ כל אחת, במרכז נישה פתוחה למיקרוגל ברוחב 
444620 מ״מ וגובה 420 מ״מ, מעליה מדפי תבלינים צרים בצד ימין ועוד זוג דלתות עליונות. הוסף חריצים אנכיים עדינים על הדלתות וצבע גוף לבן חם עם חזיתות ירוק מרווה."},{title:"עמדת משחקים לילדים",meta:"1600 x 420 x 900",prompt:"צור יחידת אחסון משחקים לחדר ילדים ברוחב 1600 מ״מ, עומק 420 מ״מ, גובה 900 מ״מ. חלק תחתון עם 6 קוביות פתוחות לסלסלות, חלק עליון עם שלוש מגירות רחבות, שני מדפים צדדיים פתוחים ותיבה מרכזית גבוהה לצעצועים גדולים. תן צבע גוף לבן, חזיתות בכחול רך וצהוב חרדלי, וכל החלקים יהיו קופסתיים ועריכים."},{title:"קיר תקליטים ופטיפון",meta:"1800 x 400 x 1200",prompt:"צור יחידת תקליטים ופטיפון ברוחב 1800 מ״מ, עומק 400 מ״מ, גובה 1200 מ״מ. תחתית עם רשת של 8 נישות לתקליטי ויניל, מעליה משטח פטיפון בעובי 50 מ״מ בצד שמאל, בצד ימין נישה פתוחה למגבר ושתי מגירות קטנות. הוסף דלתות פלוטד קצרות בשני הצדדים ורגליים מחודדות בגובה 160 מ״מ."},{title:"עמדת כביסה חכמה",meta:"1700 x 650 x 2200",prompt:"צור עמדת כביסה חכמה ברוחב 1700 מ״מ, עומק 650 מ״מ, גובה 2200 מ״מ. השאר שתי נישות פתוחות למכונת כביסה ומייבש זו לצד זו ברוחב 650 מ״מ וגובה 900 מ״מ כל אחת, מעליהן משטח קיפול בעובי 40 מ״מ, בצד ימין ארון שירות גבוה ברוחב 350 מ״מ עם דלת אחת, מעל הכל מדף פתוח ארוך ושתי נישות לסלסלות. צבע לבן מט עם חזית עץ טבעי."},{title:"ראש מיטה עם נישות",meta:"2600 x 300 x 1200",prompt:"צור ראש מיטה פרוצדורלי עם אחסון ברוחב 2600 מ״מ, עומק 300 מ״מ, גובה 1200 מ״מ. מרכז חלק ברוחב 1600 מ״מ וגובה 900 מ״מ, משני הצדדים נישות פתוחות בגודל 300 מ״מ על 260 מ״מ, מדף עליון רציף בעובי 50 מ״מ, ושתי מגירות נמוכות בכל צד בגובה 180 מ״מ. צבע גוף עץ אלון וחלק מרכזי בגוון פשתן בהיר."},{title:"בר משקאות נמוך",meta:"1500 x 420 x 980",prompt:"צור בר משקאות נמוך ברוחב 1500 מ״מ, עומק 420 מ״מ, גובה 980 מ״מ. גוף עם שתי דלתות פלוטד בצדדים, במרכז רשת קוביות לבקבוקים 4 עמודות על 3 שורות, מעליה נישה פתוחה לכוסות ברוחב 520 מ״מ וגובה 260 מ״מ, ומשטח עליון כהה בעובי 45 מ״מ. הוסף רגליים ישרות דקות בגובה 120 מ״מ."},{title:"תחנת חיות מחמד",meta:"1200 x 500 x 850",prompt:"צור תחנת חיות מחמד לבית ברוחב 1200 מ״מ, עומק 500 מ״מ, גובה 850 מ״מ. בצד שמאל נישה פתוחה למיטה ברוחב 520 מ״מ וגובה 420 מ״מ, בצד ימין שתי מגירות לאוכל וציוד, בחזית התחתונה נישה שקועה לשתי קערות ברוחב 420 מ״מ וגובה 140 מ״מ, ומשטח עליון בעובי 40 מ״מ. צבע גוף שמנת וחזיתות ירוק זית."}];function Pet(t,e){const s=Ka(e),o=r=>`${De(Number(r),e)} ${s}`;return{meta:`${t.meta.split(/\s*x\s*/i).map(r=>De(Number(r),e)).join(" x ")} ${s}`,prompt:t.prompt.replace(/(\d+(?:\.\d+)?)\s*מ״מ/g,(r,i)=>o(i))}}function Aet(t){return new Promise((e,s)=>{const o=new FileReader;o.onload=()=>e(String(o.result??"")),o.onerror=()=>s(o.error??new Error("File read failed")),o.readAsDataURL(t)})}function x_(t){return`${t}_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function Let(t,e){return{entityCount:t.length,groupCount:e.length,polygonCount:t.filter(s=>s.kind==="polygon").length,facePatchCount:t.filter(s=>s.kind==="facePatch").length,latestGroups:e.slice(-5).map(s=>({name:s.name??s.templateId??s.id,widthMm:s.widthMm,depthMm:s.depthMm,heightMm:s.heightMm}))}}function Wet({entities:t,furnitureGroups:e,selectedWallAnchor:s,floorplanBounds:o,fpIsDark:r,activeJobCount:i=0,recoveredNotice:a,measurementUnit:l="cm",onEnsureProjectSaved:c,onJobStarted:d,onClarificationAnswered:u}){const{t:h,i18n:x}=yn(),{checkTokensAndCall:f}=fb(),p=m.useRef(null),b=m.useRef(null),M=m.useRef(null),[g,w]=m.useState([{id:"welcome",role:"assistant",content:"היי, כאן בורדי. שלחו לי תמונה, מידות, או תיאור של רהיט, ואני אבנה ממנו תבנית פרוצדורלית שאפשר לערוך בקנבס."}]),[k,_]=m.useState(""),[j,v]=m.useState(null),[C,N]=m.useState(null),[P,L]=m.useState([]),[A,W]=m.useState(null),[S,B]=m.useState(!1),[R,z]=m.useState(!1),[X,ft]=m.useState(!1),tt=m.useMemo(()=>g.filter(xt=>xt.id!=="welcome").map(xt=>({role:xt.role,content:xt.content})),[g]),G=m.useCallback(xt=>{w(_t=>[..._t,{id:x_("assistant"),role:"assistant",content:xt}])},[]);m.useEffect(()=>{if(!a||M.current===a.id)return;M.current=a.id;const xt=(a.questions??[]).slice(0,3);G(a.assistantMessageHe),L(xt),W(xt.length>0?a.id:null)},[G,a]);const Y=m.useCallback(async xt=>{if(xt){if(!xt.type.startsWith("image/")){ln.error(h("smartAgent.imageOnly",{defaultValue:"אפשר לצרף רק קובץ תמונה"}));return}if(xt.size>8*1024*1024){ln.error(h("smartAgent.imageTooLarge",{defaultValue:"התמונה גדולה מדי. נסו תמונה עד 8MB"}));return}try{const _t=await Aet(xt);v(_t),N(xt.name)}catch{ln.error(h("smartAgent.imageReadFailed",{defaultValue:"לא הצלחתי לקרוא את התמונה"}))}}}
444,[h]),J=m.useCallback(xt=>{xt.preventDefault(),xt.stopPropagation(),Array.from(xt.dataTransfer.types).includes("Files")&&ft(!0)},[]),Mt=m.useCallback(xt=>{xt.preventDefault(),xt.stopPropagation();const _t=xt.currentTarget.getBoundingClientRect();(xt.clientX<_t.left||xt.clientX>_t.right||xt.clientY<_t.top||xt.clientY>_t.bottom)&&ft(!1)},[]),Rt=m.useCallback(xt=>{xt.preventDefault(),xt.stopPropagation(),ft(!1);const _t=Array.from(xt.dataTransfer.files??[]).find(Ft=>Ft.type.startsWith("image/"));_t&&Y(_t)},[Y]),it=m.useCallback(async xt=>{xt==null||xt.preventDefault();const _t=k.trim(),Ft=P;if(!_t&&!j){ln.error(h("smartAgent.requestOrImage",{defaultValue:"כתבו בקשה או צרפו תמונה"}));return}if(S)return;if(_t&&Iet(_t,Ft)){ln.error(h("smartAgent.answerInOwnWords",{defaultValue:"ענו לשאלה במילים שלכם במקום לשלוח אותה כפי שהיא"})),window.requestAnimationFrame(()=>{var Ht;return(Ht=p.current)==null?void 0:Ht.focus()});return}const Vt=A,vt=[_t||"צור תבנית לפי התמונה המצורפת.",j?`תמונה מצורפת: ${C??"reference image"}`:""].filter(Boolean).join(`
445`);w(Ht=>[...Ht,{id:x_("user"),role:"user",content:vt}]),_(""),L([]),z(!1),B(!0);try{const Ht=async()=>{Vt&&(await(u==null?void 0:u(Vt)),W(ut=>ut===Vt?null:ut))},Tt=await c(),Zt=await f("floorplan-template-agent-kimi",{mode:"generate",projectId:Tt,message:_t||"צור תבנית לפי התמונה המצורפת.",image:j,conversation:tt,placementContext:{wallAnchor:s??null,floorplanBounds:o??null},currentProject:{units:"mm",internalUnits:"mm",displayUnit:l,displayUnitLabel:Ka(l),existingSketchSummary:Let(t,e),selectedWall:s??void 0,floorplanBounds:o??void 0},crm_source:"floorplan-editor",crm_surface:"floorplan-smart-agent",crm_feature_key:"floorplan_template_agent_generate",crm_prompt_origin:"floorplan_bordi"},"floorplan_template_agent_generate",{maxRetries:0,timeout:18e4}),At=Zt.data??null;if(!Zt.success||!At){G((At==null?void 0:At.assistantMessageHe)||Zt.error||"הסוכן לא הצליח להשלים את הבקשה כרגע.");return}if(G(At.assistantMessageHe),At.status==="running"&&At.jobId){await Ht(),v(null),N(null),d==null||d(At.jobId),ln.success(h("smartAgent.buildingInBackground",{defaultValue:"בורדי מכין את התבנית ברקע"}));return}if(At.status==="needs_clarification"){await Ht(),L((At.questions??[]).slice(0,3)),W(At.jobId??null);return}if(At.status==="ready"){await Ht(),At.jobId&&(d==null||d(At.jobId));return}}catch(Ht){const Tt=Ht instanceof Error?Ht.message:"שגיאה לא צפויה";G(`משהו נתקע ביצירת התבנית: ${Tt}`)}finally{B(!1)}},[G,f,tt,t,e,j,C,k,S,A,u,c,d,o,l,s,h]),st=xt=>{_(E6(xt)),z(!1),window.requestAnimationFrame(()=>{var _t;return(_t=p.current)==null?void 0:_t.focus()})},ct=xt=>{_(xt),L([]),z(!1),window.requestAnimationFrame(()=>{var _t;return(_t=p.current)==null?void 0:_t.focus()})},pt=Ka(l);return n.jsxs("div",{dir:x.dir(),className:O("flex h-[min(66vh,620px)] min-h-[460px] flex-col overflow-hidden",r?"bg-[#141416] text-white":"bg-white text-[#182137]"),children:[n.jsxs("div",{className:O("flex shrink-0 items-center justify-between border-b px-3 py-3",r?"border-white/10 bg-white/[0.03]":"border-[#182137]/10 bg-[#FAF6F0]"),children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[n.jsx("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-xl bg-gradient-to-b from-[#EC7357] to-[#D84B2E] text-white shadow",children:n.jsx(F1,{size:20})}),n.jsxs("div",{className:"min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"text-[13px] font-black",children:"בורדי"}),n.jsx(zl,{size:13,className:"text-[#EC7357]"})]}),n.jsx("p",{className:O("text-[10px] font-semibold",r?"text-white/50":"text-[#182137]/50"),children:h("smartAgent.subtitle",{defaultValue:"סוכן תבניות פרוצדורליות"})})]})]}),s?n.jsx("span",{className:O("rounded-full px-2 py-1 text-[10px] font-bold",r?"bg-white/10 text-white/70":"bg-[#E8DFD3] text-[#182137]/70"),children:h("smartAgent.wallSelected",{defaultValue:"קיר נבחר"})}):null,i>0?n.jsx("span",{className:O("rounded-full px-2 py-1 text-[10px] font-bold",r?"bg-[#EC7357]/20 text-[#F9B29E]":"bg-[#FFE0D8] text-[#B43B22]"),children:h("smartAgent.jobsInBackgroun
445d",{count:i,defaultValue:`${i} ברקע`})}):null]}),n.jsxs("div",{className:"min-h-0 flex-1 space-y-3 overflow-y-auto p-3",dir:"rtl",children:[g.map(xt=>{const _t=xt.role==="user";return n.jsx("div",{className:O("flex",_t?"justify-start":"justify-end"),children:n.jsx("div",{className:O("max-w-[88%] whitespace-pre-wrap rounded-2xl px-3 py-2 text-[12px] leading-relaxed shadow-sm",_t?"rounded-es-md bg-gradient-to-b from-[#EC7357] to-[#D84B2E] text-white":r?"rounded-ee-md border border-white/10 bg-white/[0.06] text-white/88":"rounded-ee-md border border-[#182137]/10 bg-[#F7F4EF] text-[#182137]/85"),children:xt.content})},xt.id)}),S&&n.jsx("div",{className:"flex justify-end",children:n.jsxs("div",{className:O("flex items-center gap-2 rounded-2xl rounded-ee-md px-3 py-2 text-[12px]",r?"bg-white/[0.06] text-white/65":"bg-[#F7F4EF] text-[#182137]/65"),children:[n.jsx(Xa,{size:14,className:"animate-spin"}),h("smartAgent.buildingSpec",{defaultValue:"בורדי בונה מפרט..."})]})}),P.length>0&&n.jsxs("div",{className:O("space-y-1.5 rounded-xl border p-2",r?"border-white/10 bg-white/[0.04]":"border-[#EC7357]/20 bg-[#FDF6F4]"),children:[n.jsx("p",{className:"text-[11px] font-black",children:h("smartAgent.needsClarification",{defaultValue:"בורדי צריך עוד דיוק:"})}),P.map(xt=>n.jsx("button",{type:"button",onClick:()=>st(xt),className:O("block w-full rounded-lg px-2 py-1.5 text-right text-[11px] font-semibold transition-colors",r?"bg-white/[0.06] hover:bg-white/10":"bg-white hover:bg-[#FAF0EC]"),children:xt},xt))]})]}),n.jsxs("form",{onSubmit:it,onDragOver:J,onDragLeave:Mt,onDrop:Rt,className:O("relative shrink-0 space-y-2 border-t p-3",r?"border-white/10 bg-[#101012]":"border-[#182137]/10 bg-[#FAF8F5]",X&&(r?"ring-2 ring-[#EC7357]/70 ring-offset-2 ring-offset-[#101012]":"ring-2 ring-[#EC7357]/55 ring-offset-2 ring-offset-[#FAF8F5]")),children:[X&&n.jsxs("div",{className:O("pointer-events-none absolute inset-2 z-10 flex flex-col items-center justify-center gap-1.5 rounded-xl border-2 border-dashed backdrop-blur-[2px]",r?"border-[#EC7357]/70 bg-[#EC7357]/10 text-[#F9B29E]":"border-[#EC7357]/55 bg-[#EC7357]/8 text-[#B43B22]"),"aria-hidden":!0,children:[n.jsx(n5,{size:22}),n.jsx("span",{className:"text-[12px] font-black",children:h("smartAgent.dropImage",{defaultValue:"שחררו תמונה כאן"})}),n.jsx("span",{className:O("text-[10px] font-semibold",r?"text-white/55":"text-[#182137]/50"),children:h("smartAgent.imageFormats",{defaultValue:"PNG, JPG או WebP עד 8MB"})})]}),j&&n.jsxs("div",{className:O("flex items-center gap-2 rounded-xl border p-2",r?"border-white/10 bg-white/[0.04]":"border-[#182137]/10 bg-white"),children:[n.jsx("img",{src:j,alt:"",className:"h-12 w-12 rounded-lg object-cover"}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] font-bold",children:C}),n.jsx("button",{type:"button",onClick:()=>{v(null),N(null)},className:"flex h-7 w-7 items-center justify-center rounded-lg text-[#D84B2E] hover:bg-[#D84B2E]/10","aria-label":h("smartAgent.removeImage",{defaultValue:"הסר תמונה"}),children:n.jsx(Gr,{size:14})})]}),R&&n.jsxs("div",{className:O("rounded-2xl border p-2 shadow-sm",r?"border-white/10 bg-white/[0.04]":"border-[#182137]/10 bg-white"),children:[n.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2 px-1",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("p",{className:"text-[11px] font-black",children:h("smartAgent.shortcuts",{defaultValue:"קיצורי תבניות"})}),n.jsx("p",{className:O("text-[10px] font-semibold",r?"text-white/45":"text-[#182137]/45"),children:h("smartAgent.shortcutsHint",{defaultValue:"בחרו רעיון, ערכו מידות ושלחו לקימי"})})]}),n.jsx(i5,{size:16,className:"shrink-0 text-[#EC7357]"})]}),n.jsx("div",{className:"max-h-56 space-y-1.5 overflow-y-auto pe-1",children:Tet.map(xt=>{const _t=Pet(xt,l);return n.jsxs("button",{type:"button",onClick:()=>ct(_t.prompt),className:O("block w-full rounded-xl border px-2.5 py-2 text-right transition-colors",r?"border-white/10 bg-black/20 hover:border-[#EC7357]/45 hover:bg-[#
445EC7357]/10":"border-[#182137]/10 bg-[#FAF8F5] hover:border-[#EC7357]/35 hover:bg-[#FFF3EF]"),dir:"rtl",children:[n.jsxs("span",{className:"flex items-center justify-between gap-2",children:[n.jsx("span",{className:"min-w-0 truncate text-[11px] font-black",children:xt.title}),n.jsx("span",{className:O("shrink-0 rounded-full px-2 py-0.5 text-[9px] font-black",r?"bg-white/10 text-white/60":"bg-[#182137]/[0.07] text-[#182137]/55"),children:_t.meta})]}),n.jsx("span",{className:O("mt-1 block overflow-hidden text-ellipsis whitespace-nowrap text-[10px] font-semibold leading-4",r?"text-white/48":"text-[#182137]/48"),children:_t.prompt})]},xt.title)})})]}),n.jsx("textarea",{ref:p,value:k,onChange:xt=>_(xt.currentTarget.value),rows:3,placeholder:`לדוגמה: בנה קרדנזה פלוטד ברוחב ${De(1800,l)} ${pt}, עומק ${De(450,l)} ${pt}, גובה ${De(800,l)} ${pt}, עם רגליים מחודדות... (או גררו תמונה לכאן)`,className:O("w-full resize-none rounded-xl border px-3 py-2 text-right text-[12px] font-medium outline-none transition-colors",r?"border-white/10 bg-[#0A0A0A] text-white placeholder:text-white/30 focus:border-[#EC7357]/60":"border-[#182137]/12 bg-white text-[#182137] placeholder:text-[#182137]/35 focus:border-[#EC7357]/55"),dir:"rtl",enterKeyHint:"send",onKeyDown:xt=>{xt.key==="Enter"&&!xt.shiftKey&&!xt.nativeEvent.isComposing&&(xt.preventDefault(),S||it())}}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("input",{ref:b,type:"file",accept:"image/png,image/jpeg,image/webp",className:"hidden",onChange:xt=>{var _t;return void Y(((_t=xt.currentTarget.files)==null?void 0:_t[0])??null)}}),n.jsx("button",{type:"button",onClick:()=>{var xt;return(xt=b.current)==null?void 0:xt.click()},className:O("flex h-10 w-10 shrink-0 items-center justify-center rounded-xl border transition-colors",r?"border-white/10 bg-white/[0.04] hover:bg-white/10":"border-[#182137]/10 bg-white hover:bg-[#F7F4EF]"),"aria-label":h("smartAgent.attachImage",{defaultValue:"צרף תמונה"}),title:h("smartAgent.attachImage",{defaultValue:"צרף תמונה"}),children:n.jsx(n5,{size:17})}),n.jsxs("button",{type:"submit",disabled:S,className:"flex h-10 flex-1 items-center justify-center gap-2 rounded-xl bg-gradient-to-b from-[#EC7357] to-[#D84B2E] px-3 text-[12px] font-black text-white shadow-[0_2px_0_#9b321e] transition-transform active:translate-y-px disabled:cursor-wait disabled:opacity-70",children:[S?n.jsx(Xa,{size:15,className:"animate-spin"}):n.jsx(j1,{size:15}),h("smartAgent.createTemplate",{defaultValue:"צור תבנית"})]}),n.jsx("button",{type:"button",disabled:S,onClick:()=>z(xt=>!xt),className:O("flex h-10 w-10 shrink-0 items-center justify-center rounded-xl border transition-colors disabled:opacity-60",R?r?"border-[#EC7357]/50 bg-[#EC7357]/15 text-[#F9B29E]":"border-[#EC7357]/40 bg-[#FFF0EB] text-[#D84B2E]":r?"border-white/10 bg-white/[0.04] hover:bg-white/10":"border-[#182137]/10 bg-white hover:bg-[#F7F4EF]"),"aria-label":h("smartAgent.shortcuts",{defaultValue:"קיצורי תבניות"}),"aria-expanded":R,title:h("smartAgent.shortcuts",{defaultValue:"קיצורי תבניות"}),children:n.jsx(i5,{size:17})})]})]})]})}const Fd=(t,e,s)=>Math.max(e,Math.min(s,t));function Ret(t,e,s,o){const r=e.entityIds.find(j=>{var v;return((v=s.find(C=>C.id===j))==null?void 0:v.kind)==="polygon"}),i=r?s.find(j=>j.id===r):void 0;if(!i)return null;const a=i.baseHeightMm??0,l=i.heightMm??0,c=a+l,d=((e.rotationDeg??0)%360+360)%360,u=em(s,e.entityIds);if(!u)return null;const h=e.widthMm??l,x=o.widthMm!==void 0?Math.round(o.widthMm):void 0,f=o.heightMm!==void 0?Math.round(o.heightMm):void 0;let p=null;switch(t){case"lighting.panel":{const j=Fd(x??h,400,6e3);p=m7({x:0,y:0},{...h7,lengthMm:j,spotCount:Fd(Math.round(j/600),2,12)},void 0,{ceilingHeightMm:c});break}case"lighting.recessed":{const j=Fd(x??h,60,600);p=u7({x:0,y:0},{...d7,housingDiameterMm:j},void 0,{ceilingHeightMm:c});break}case"lighting.wall":{p=x7({x:0,y:0},{...f7,widthMm:Fd(x??h,60,1200),heightMm:Fd(f??l,80,1200),mountHeightMm:a},void 0);break}case"lighting.floor":{const j=Fd(f??a+l,800,2400);p=g7({x:0,y:0},{...p7,poleHeightMm:Fd(j-320,400,2100)});break}case"living.glassRailing":case"living.railingHorizontal":case"living.railingVertical":case"railings.glassFrameless":{const j=Fd(x??h,400,8e3),v=Fd(f??e.heightMm??1050,700,1500);t==="living.railingHorizontal"?p=r7({x:0,y:0},{...s7,widthMm:j,heightMm:v},void 0):t==="living.railingVertical"?p=a7({x:0,y:0},{...i7,widthMm:j,heightMm:v},void 0):t==="railings.glassFrameless"?p=c7({x:0,y:0},{...l7,widthMm:j,heightMm:v},void 0):p=o7({x:0,y:0},{...n7,widthMm:j,heightMm:v},void 0);break}default:return null}if(!p)return null;const b=p.entities.map(j=>j.id),M=em(p.entities,b);if(!M)return null;let g=tm(p.entities,b,{x:u.x-M.x,y:u.y-M.y});d!==0&&(g=k3(g,b,u,d));const w=g.map(j=>j.groupId===p.group.id?{...j,groupId:e.id}:j),k={...p.group,id:e.id,name:e.name??p.group.name,templateId:e.templateId,rigid:!0,rotationDeg:d,wallId:e.wallId,wallSide:e.wallSide,wallPositionMm:e.wallPositionMm,createdAt:e.createdAt};return{entities:[...s.filter(j=>
445!e.entityIds.includes(j.id)),...w],group:k}}const Oet=["kitchen","living","dining","bedroom","bathroom","office","accessories"],D6="#E8DFD3",sm="#F2D8CE",F6="#7A6B5E",C6="#DCD4C9",N6="#343A40",I6="#E7EEF2",T6="#A8754A",wa=20;function qh(t){return t&&typeof t=="object"?t:null}function Het(t,e){const s=typeof t=="number"?t:Number(t);return Number.isFinite(s)?s:e}function ao(t,e,s,o){const r=Het(t,o);return Math.round(Math.max(e,Math.min(s,r)))}function Cd(t,e){if(typeof t!="string")return e;const s=t.trim();return s?s.slice(0,80):e}function Wc(t,e){if(typeof t!="string")return e;const s=t.trim();return/^#[0-9a-fA-F]{3,8}$/.test(s)?s:e}function qg(t,e){const s=qh(t)??{},o=ao(s.xMm??s.x,0,e.widthMm-wa,0),r=ao(s.yMm??s.y,0,e.heightMm-wa,0),i=ao(s.widthMm??s.width,wa,e.widthMm-o,Math.max(wa,e.widthMm/2)),a=ao(s.heightMm??s.height,wa,e.heightMm-r,Math.max(wa,e.heightMm/2));return{xMm:o,yMm:r,widthMm:i,heightMm:a}}function Bet(t){var d,u,h,x;const e=[],s=[],o=qh(t);if(!o)return{ok:!1,errors:["Template spec must be a JSON object."],warnings:s};const r={widthMm:ao((d=qh(o.dimensions))==null?void 0:d.widthMm,200,12e3,1200),depthMm:ao((u=qh(o.dimensions))==null?void 0:u.depthMm,100,3e3,450),heightMm:ao((h=qh(o.dimensions))==null?void 0:h.heightMm,100,6e3,900)},i=Oet.includes(o.category)?o.category:"living";i!==o.category&&s.push("Unknown category was normalized to living.");const a=Array.isArray(o.parts)?o.parts:[];a.length===0&&e.push("Template spec must include at least one part.");const l=[];let c=0;return a.forEach((f,p)=>{const b=qh(f);if(!b){e.push(`Part ${p+1} is not an object.`);return}const M=b.type;if(M==="carcass"){c+=1,l.push({type:"carcass",id:Cd(b.id,c===1?"main":`carcass_${c}`),widthMm:ao(b.widthMm,200,12e3,r.widthMm),depthMm:ao(b.depthMm,100,3e3,r.depthMm),heightMm:ao(b.heightMm,100,6e3,r.heightMm),baseHeightMm:b.baseHeightMm===void 0?void 0:ao(b.baseHeightMm,0,3e3,0),color:Wc(b.color,D6)});return}if(M==="slab"){l.push({type:"slab",id:Cd(b.id,`slab_${p+1}`),xMm:ao(b.xMm,-2e3,12e3,0),yMm:ao(b.yMm,-2e3,3e3,0),widthMm:ao(b.widthMm,wa,12e3,r.widthMm),depthMm:ao(b.depthMm,wa,3e3,r.depthMm),heightMm:ao(b.heightMm,1,1e3,40),baseHeightMm:ao(b.baseHeightMm,0,6e3,r.heightMm),color:Wc(b.color,C6)});return}if(M==="frontPatch"){l.push({type:"frontPatch",hostId:Cd(b.hostId,"main"),xMm:ao(b.xMm,0,r.widthMm-wa,0),yMm:ao(b.yMm,0,r.heightMm-wa,0),widthMm:ao(b.widthMm,wa,r.widthMm,Math.max(wa,r.widthMm/2)),heightMm:ao(b.heightMm,wa,r.heightMm,Math.max(wa,r.heightMm/2)),depthMm:ao(b.depthMm,-2e3,300,18),color:Wc(b.color,sm)});return}if(M==="drawerGrid"){l.push({type:"drawerGrid",hostId:Cd(b.hostId,"main"),columns:ao(b.columns,1,12,1),rows:ao(b.rows,1,10,3),bounds:qg(b.bounds,r),color:Wc(b.color,sm)});return}if(M==="doorPair"){l.push({type:"doorPair",hostId:Cd(b.hostId,"main"),bounds:qg(b.bounds,r),color:Wc(b.color,sm)});return}if(M==="flutes"){l.push({type:"flutes",hostId:Cd(b.hostId,"main"),bounds:qg(b.bounds,r),count:ao(b.count,1,80,8),depthMm:ao(b.depthMm,-120,120,18),color:Wc(b.color,"#E07B65")});return}if(M==="niche"){l.push({type:"niche",hostId:Cd(b.hostId,"main"),bounds:qg(b.bounds,r),recessDepthMm:ao(b.recessDepthMm,20,3e3,Math.max(80,r.depthMm-40)),color:Wc(b.color,F6)});return}if(M==="legSet"){const g=b.style==="tapered"||b.style==="round"?b.style:"straight";l.push({type:"legSet",style:g,count:4,heightMm:ao(b.heightMm,40,1200,180),sizeMm:ao(b.sizeMm,25,180,55),color:Wc(b.color,T6)});return}if(M==="basin"){l.push({type:"basin",hostId:Cd(b.hostId,"counter"),xMm:ao(b.xMm,0,r.widthMm,r.widthMm/2),yMm:ao(b.yMm,0,r.depthMm,r.depthMm/2),widthMm:ao(b.widthMm,80,r.widthMm,500),depthMm:ao(b.depthMm,80,r.depthMm,360),downMm:ao(b.downMm,20,800,180),color:Wc(b.color,I6)});return}
445if(M==="faucetLShape"){l.push({type:"faucetLShape",xMm:ao(b.xMm,-2e3,12e3,r.widthMm/2),yMm:ao(b.yMm,-2e3,3e3,r.depthMm-80),heightMm:ao(b.heightMm,80,1e3,240),reachMm:ao(b.reachMm,40,800,200),thicknessMm:ao(b.thicknessMm,10,120,35),color:Wc(b.color,N6)});return}e.push(`Unsupported part type: ${String(M)}`)}),c===0&&e.push("Template spec must include a carcass part."),e.length>0?{ok:!1,errors:e,warnings:s}:{ok:!0,spec:{version:1,units:"mm",nameHe:Cd(o.nameHe,"תבנית חכמה"),category:i,placement:{mode:((x=qh(o.placement))==null?void 0:x.mode)==="wallAnchored"?"wallAnchored":"free"},dimensions:r,parts:l},warnings:s}}function Vet(t){return _e(t.xMm,t.yMm,t.xMm+t.widthMm,t.yMm+t.heightMm)}function bf(t,e,s,o,r){const i=lo(t,"side-0",Vet(e),r);return i?{...i,depthMm:Math.round(s),color:o}:null}function vy(t,e){return{...t,vertices:t.vertices.map(e)}}function zet(t){return t?[t.minX,t.minY,t.maxX,t.maxY].every(Number.isFinite)&&t.maxX>t.minX&&t.maxY>t.minY:!1}function p_(t,e,s){const o=e-t;return o<=s?Math.round(t):Math.round(t+(o-s)/2)}function $et(t,e,s){let o=Number.NEGATIVE_INFINITY,r=Number.POSITIVE_INFINITY;for(const i of t)i.kind==="polygon"&&(o=Math.max(o,...i.vertices.map(a=>a.x)),r=Math.min(r,...i.vertices.map(a=>a.y)));return Number.isFinite(o)?{x:Math.round(o+200),y:Number.isFinite(r)?Math.round(r):0}:zet(s)?{x:p_(s.minX,s.maxX,e.widthMm),y:p_(s.minY,s.maxY,e.depthMm)}:{x:0,y:0}}function Xet(t,e={}){var S,B;const s=Bet(t);if(!s.ok){const R=s;throw new Error(R.errors.join(" "))}const o=s.spec,r=[...s.warnings],i=Me(),a=o.parts.find(R=>R.type==="carcass");if(!a)throw new Error("Template spec must include a carcass part.");const l=o.parts.find(R=>R.type==="legSet"),c=a.baseHeightMm??(l==null?void 0:l.heightMm)??0,d=be("fps_rect"),u=o.placement.mode==="wallAnchored"&&e.wallAnchor,h=e.origin??$et(e.existingEntities??[],{widthMm:a.widthMm,depthMm:a.depthMm,heightMm:a.heightMm},e.floorplanBounds??null);let x,f;if(u){const R=Wn({widthMm:a.widthMm,depthMm:a.depthMm},e.wallAnchor);f=R.vertices,x=R.positionAlongWallMm}else f=_e(h.x,h.y,h.x+a.widthMm,h.y+a.depthMm);const p=f[0],b=f[1],M=f[3],g=(b.x-p.x)/a.widthMm,w=(b.y-p.y)/a.widthMm,k=(M.x-p.x)/a.depthMm,_=(M.y-p.y)/a.depthMm,j=R=>({x:Math.round(p.x+g*R.x+k*R.y),y:Math.round(p.y+w*R.x+_*R.y)}),v={...Ae(f,"rectangle",d),heightMm:a.heightMm,baseHeightMm:c>0?c:void 0,color:a.color??D6,groupId:i},C=[v],N=new Map([[a.id,v]]),P=new Map([[a.id,v.id],["main",v.id]]);a.id!=="main"&&P.set(a.id,v.id);const L=R=>P.get(R)??v.id,A=R=>{R&&C.push(R)};for(const R of o.parts)if(R.type!=="carcass"){if(R.type==="slab"){const z=vy(ee({origin:{x:R.xMm,y:R.yMm},widthMm:R.widthMm,depthMm:R.depthMm,heightMm:R.heightMm,baseHeightMm:R.baseHeightMm,color:R.color??C6,groupId:i}),j);C.push(z),N.set(R.id,z);continue}if(R.type==="frontPatch"){A(bf(L(R.hostId),{xMm:R.xMm,yMm:R.yMm,widthMm:R.widthMm,heightMm:R.heightMm},R.depthMm,R.color??sm,i));continue}if(R.type==="drawerGrid"){const z=Math.max(4,Math.min(14,Math.round(Math.min(R.bounds.widthMm/R.columns,R.bounds.heightMm/R.rows)*.04))),X=(R.bounds.widthMm-z*(R.columns-1))/R.columns,ft=(R.bounds.heightMm-z*(R.rows-1))/R.rows;for(let tt=0;tt<R.rows;tt+=1)for(let G=0;G<R.columns;G+=1)A(bf(L(R.hostId),{xMm:Math.round(R.bounds.xMm+G*(X+z)),yMm:Math.round(R.bounds.yMm+tt*(ft+z)),widthMm:Math.round(X),heightMm:Math.round(ft)},18,R.color??sm,i));continue}if(R.type==="doorPair"){const z=Math.max(6,Math.min(18,Math.round(R.bounds.widthMm*.015
445))),X=Math.max(wa,Math.round((R.bounds.widthMm-z)/2));A(bf(L(R.hostId),{...R.bounds,widthMm:X},18,R.color??sm,i)),A(bf(L(R.hostId),{...R.bounds,xMm:R.bounds.xMm+X+z,widthMm:X},18,R.color??sm,i));continue}if(R.type==="flutes"){const z=R.bounds.widthMm/R.count,X=Math.max(8,Math.min(32,Math.round(z*.42)));for(let ft=0;ft<R.count;ft+=1){const tt=R.bounds.xMm+ft*z+(z-X)/2;A(bf(L(R.hostId),{xMm:Math.round(tt),yMm:R.bounds.yMm,widthMm:X,heightMm:R.bounds.heightMm},R.depthMm,R.color??"#E07B65",i))}continue}if(R.type==="niche"){A(bf(L(R.hostId),R.bounds,-Math.abs(R.recessDepthMm),R.color??F6,i));continue}if(R.type==="legSet"){const z=R.sizeMm??Math.max(35,Math.min(90,Math.round(Math.min(a.widthMm,a.depthMm)*.07))),X=Math.max(30,z),ft=[{x:X,y:X},{x:a.widthMm-X-z,y:X},{x:X,y:a.depthMm-X-z},{x:a.widthMm-X-z,y:a.depthMm-X-z}];for(const tt of ft)C.push(vy(Da({origin:tt,widthMm:z,depthMm:z,heightMm:R.heightMm,color:R.color??T6,groupId:i,round:R.style==="round",taperBottom:R.style==="tapered"?.55:void 0}),j));continue}if(R.type==="basin"){const z=N.get(R.hostId);if(!z){r.push(`Basin host "${R.hostId}" was not found.`);continue}const X=$d(z,{widthMm:R.widthMm,depthMm:R.depthMm,downMm:R.downMm??180,offsetXMm:R.xMm-a.widthMm/2,offsetYMm:R.yMm-a.depthMm/2,color:R.color??I6},i);A(X);continue}if(R.type==="faucetLShape"){const z=wm({origin:{x:R.xMm,y:R.yMm},baseHeightMm:a.heightMm+c,postHeightMm:R.heightMm,spoutReachMm:R.reachMm??200,thicknessMm:R.thicknessMm??35,color:R.color??N6,groupId:i}).map(X=>vy(X,j));C.push(...z)}}const W={id:i,entityIds:C.map(R=>R.id),name:o.nameHe,templateId:"ai.kimi.procedural",widthMm:o.dimensions.widthMm,depthMm:o.dimensions.depthMm,heightMm:o.dimensions.heightMm,wallId:u?(S=e.wallAnchor)==null?void 0:S.wallId:void 0,wallSide:u?(B=e.wallAnchor)==null?void 0:B.side:void 0,wallPositionMm:x,createdAt:Date.now()};return{entities:C,group:W,hostId:d,warnings:r}}function g_(t,e){return Array.isArray(t)?t.filter(s=>typeof s=="string"&&s.trim().length>0).map(s=>s.trim()).slice(0,e):[]}function Bu(t){return typeof t=="number"&&Number.isFinite(t)}function Yet(t){if(!t||typeof t!="object")return null;const e=t,s={minX:e.minX,minY:e.minY,maxX:e.maxX,maxY:e.maxY};return Bu(s.minX)&&Bu(s.minY)&&Bu(s.maxX)&&Bu(s.maxY)&&s.maxX>s.minX&&s.maxY>s.minY?s:null}function b_(t){if(!t||typeof t!="object")return null;const e=t;return Bu(e.x)&&Bu(e.y)?{x:e.x,y:e.y}:null}function Get(t){if(!t||typeof t!="object")return null;const e=t,s=b_(e.startMm),o=b_(e.endMm),r=typeof e.wallId=="string"&&e.wallId?e.wallId:null,i=Bu(e.thicknessMm)?e.thicknessMm:null;return!r||!s||!o||i===null?null:{wallId:r,startMm:s,endMm:o,thicknessMm:i,side:e.side==="back"?"back":"front",positionAlongWallMm:Bu(e.positionAlongWallMm)?e.positionAlongWallMm:void 0}}function Uet(t){return!t||typeof t!="object"?{}:{wallAnchor:Get(t.wallAnchor??t.selectedWallAnchor),floorplanBounds:Yet(t.floorplanBounds)}}function Ket(t,e){if(e.furnitureGroups.some(s=>s.sourceJobId===t.id))return{kind:"duplicate",entities:e.entities,furnitureGroups:e.furnitureGroups};if(t.status==="needs_clarification")return{kind:"clarification",questions:g_(t.questions,3),assistantMessageHe:t.assistant_message_he||"אני צריך עוד כמה פרטים כדי לבנות את התבנית בצורה מדויקת."};if(t.status==="applied")return{kind:"ignored",reason:"applied"};if(t.status==="failed")return{kind:"ignored",reason:"failed"};if(t.status!=="ready")return{kind:"ignored",reason:"pending"};if(!t.template_spec)return{kind:"ignored",reason:"invalid",error:"Missing template spec"};try{const s=Uet(t.placement_context),o=Xet(t.template_spec,{existingEntities:e.entities,wallAnchor:e.wallAnchor??s.wallAnchor??null,floorplanBounds:e.floorplanBounds??s.floorplanBounds??null}),r={...o.group,sourceJobId:t.id};return{kind:"applied",entities:[...e.entities,...o.entities],furnitureGroups:[...e.furnitureGroups,r],built:{...o,group:r},warnings:[...o.warnings,...g_(t.warnings,6)],assistantMessageHe:t.assistant_message_he||"התבנית מוכנה ונוספה לפרויקט."}}
445catch(s){return{kind:"ignored",reason:"invalid",error:s instanceof Error?s.message:"Invalid template spec"}}}function M_(t,e){return Array.isArray(t)?t.filter(s=>typeof s=="string"&&s.trim().length>0).map(s=>s.trim()).slice(0,e):[]}function Zet(t){return{kind:"ignored",reason:t.reason,error:t.message,assistantMessageHe:t.message}}function qet(t,e){if(t.status==="needs_clarification")return{kind:"clarification",questions:M_(t.questions,3),assistantMessageHe:t.assistant_message_he||"אני צריכה עוד פרט קטן לפני שאני משנה את התבנית."};if(t.status==="applied")return{kind:"ignored",reason:"applied"};if(t.status==="failed")return{kind:"ignored",reason:"failed",error:t.error??void 0};if(t.status!=="ready")return{kind:"ignored",reason:"pending"};if(!t.edit_spec)return{kind:"ignored",reason:"invalid",error:"Missing edit spec"};const s=Tq(t.edit_spec,{entities:e.entities,furnitureGroups:e.furnitureGroups,groupId:t.target_group_id,expectedFingerprint:t.target_fingerprint});return s.ok?{kind:"applied",entities:s.entities,furnitureGroups:s.furnitureGroups,selectedEntityId:s.selectedEntityId,warnings:[...s.warnings,...M_(t.warnings,6)],assistantMessageHe:t.assistant_message_he||"סיימתי לערוך את התבנית."}:Zet(s)}const Jet=4e3,Qet=12*6e4;function y_(t){return{success:!1,version:"v2",image:{width:0,height:0},walls:[],openings:[],rooms:[],overlay:{url:null,path:null},warnings:[t],error:t}}async function tnt(t){var i;const e=await Bo.functions.invoke("floorplan-parse-v2",{body:{image_base64:t.imageBase64??null,image_storage_path:t.imageStoragePath??null,project_id:t.projectId??null,image_width:t.imageWidth,image_height:t.imageHeight,scale_mm_per_px:t.scaleMmPerPx&&t.scaleMmPerPx>0?t.scaleMmPerPx:null,variant:t.variant}});if(e.error)return y_(`שגיאה בקריאה לפרסר V2: ${e.error.message}`);const s=e.data;if((s==null?void 0:s.status)!=="running"||!(s!=null&&s.job_id))return s;const o=s.job_id,r=Date.now();for(;Date.now()-r<Qet;){await new Promise(c=>setTimeout(c,Jet)),(i=t.onProgress)==null||i.call(t,Date.now()-r);const a=await Bo.functions.invoke("floorplan-parse-v2",{body:{job_id:o,variant:t.variant}});if(a.error)continue;const l=a.data;if((l==null?void 0:l.status)!=="running")return l}return y_("סריקת פרסר V2 לא הסתיימה בזמן (מעל 8 דקות). נסה שוב.")}async function ent(t,e){const s=new Image;s.crossOrigin="anonymous",s.src=t,await new Promise((d,u)=>{s.onload=()=>d(),s.onerror=()=>u(new Error("Failed to load image"))});const o=1500;let r=s.naturalWidth,i=s.naturalHeight;if(r>o||i>o){const d=o/Math.max(r,i);r=Math.round(r*d),i=Math.round(i*d)}const a=document.createElement("canvas");a.width=r,a.height=i,a.getContext("2d").drawImage(s,0,0,r,i);const c=a.toDataURL("image/jpeg",.85);return`${s.naturalWidth}${s.naturalHeight}${r}${i}${(c.length/1024).toFixed(0)}`,{dataUrl:c,width:r,height:i,originalWidth:s.naturalWidth,originalHeight:s.naturalHeight}}function nnt(t){const e=t.walls.filter(r=>{var i,a;return vw((i=r.line)==null?void 0:i.start)&&vw((a=r.line)==null?void 0:a.end)}).map(r=>ont(r,t.walls)),s=new Map(e.map(r=>[r.id,r])),o=t.openings.map(r=>snt(r,s)).filter(r=>!!r);return{walls:e,openings:o}}function ont(t,e){return{id:t.id,start:{x:t.line.start.x,y:t.line.start.y},end:{x:t.line.end.x,y:t.line.end.y},wallType:int(t,e),detectionSource:"ai"}}function snt(t,e){const s=t.attached_wall_id;if(!s)return null;const o=e.get(s);if(!o||!Array.isArray(t.obb)||t.obb.length!==4)return null;const r=ant(t.obb),i=S6(o.start,o.end);if(i<=0)return null;const a=cnt(r,o.start,o.end),{type:l,preset:c}=rnt(t.type);return{id:t.id,type:l,preset:c,wallId:s,positionPx:P6(a,0,i),detectedWidthPx:lnt(t.obb),detectionSource:"ai"}}function rnt(t){switch(t){case"door_double":return{type:"door",preset:"double_door"};case"sliding_door":return{type:"door",preset:"sliding_door"};case"window":return{type:"window",preset:"fixed_window"};case"opening":return{type:"door",preset:"passage"};case"balcony_door":case"door_single":default:return{type:"door",preset:"single_door"}}}function int(t,e){if(t.wall_type==="exterior"||t.wall_type==="interior")return t.wall_type;const s=e.flatMap(h=>[h.line.start,h.line.end]).filter(vw);if(s.length<4)return"interior";const o=Math.min(...s.map(h=>
445h.x)),r=Math.max(...s.map(h=>h.x)),i=Math.min(...s.map(h=>h.y)),a=Math.max(...s.map(h=>h.y)),l=Math.hypot(r-o,a-i),c=Math.max(24,l*.06),d={x:(t.line.start.x+t.line.end.x)/2,y:(t.line.start.y+t.line.end.y)/2};return Math.abs(t.line.start.y-t.line.end.y)<=Math.abs(t.line.start.x-t.line.end.x)?Math.abs(d.y-i)<=c||Math.abs(d.y-a)<=c?"exterior":"interior":Math.abs(d.x-o)<=c||Math.abs(d.x-r)<=c?"exterior":"interior"}function vw(t){const e=t;return Number.isFinite(e==null?void 0:e.x)&&Number.isFinite(e==null?void 0:e.y)}function ant(t){return{x:t.reduce((e,s)=>e+s.x,0)/t.length,y:t.reduce((e,s)=>e+s.y,0)/t.length}}function lnt(t){const e=t.map((s,o)=>S6(s,t[(o+1)%t.length]));return Math.max(...e)}function cnt(t,e,s){const o=s.x-e.x,r=s.y-e.y,i=o*o+r*r;if(i<=0)return 0;const a=((t.x-e.x)*o+(t.y-e.y)*r)/i;return P6(a,0,1)*Math.sqrt(i)}function S6(t,e){return Math.hypot(e.x-t.x,e.y-t.y)}function P6(t,e,s){return Math.max(e,Math.min(s,t))}const dnt={he:{video:{eyebrow:"פיצ'ר למנויים חודשיים",title:"וידאו בבורדסטיילר 🎬",body:"סרטון סיור בתלת-ממד שמור למנויים חודשיים. מצטרפים למנוי חודשי — ומקבלים הקלטת וידאו חלקה של הבית, יחד עם כל שאר הכלים המתקדמים.",cta:"להצטרפות למנוי ולצילום וידאו",secondary:"אולי אחר כך"},projectLimit:{eyebrow:"החשבון החינמי",title:"פרויקט אחד בחינם ✨",body:"ללא מנוי חודשי אפשר לעצב פרויקט אחד. כדי לפתוח פרויקטים נוספים (או להתחיל מחדש) מצטרפים למנוי חודשי — ואז אין הגבלה. הפרויקט הקיים שלך נשמר ומחכה לך כאן.",cta:"להצטרפות למנוי ולפרויקטים ללא הגבלה",secondary:"אולי אחר כך"},personalLibrary:{eyebrow:"פיצ'ר למנויים חודשיים",title:"הספרייה האישית בבורדסטיילר 🔒",body:"העלאת רהיטים, חיפויים וריצופים אישיים — וגם השימוש בספרייה האישית — פתוחים למנויים חודשיים. מצטרפים למנוי וממשיכים לעבוד עם כל הנכסים שכבר שמרת.",cta:"להצטרפות למנוי ולפתיחת הספרייה",secondary:"אולי אחר כך"},export:{eyebrow:"פיצ'ר למנויים חודשיים",title:"הורדת קבצים מבורדסטיילר 🔒",body:"הורדת תמונה והורדת מודל תלת־ממד זמינות למנויים חודשיים. מצטרפים למנוי ומורידים את הפרויקט כתמונה או כקובץ תלת־ממד.",cta:"להצטרפות למנוי ולפתיחת ההורדות",secondary:"אולי אחר כך"}},en:{video:{eyebrow:"Monthly subscriber feature",title:"Video in BoardStyler 🎬",body:"3D walkthrough video is reserved for monthly subscribers. Join a monthly subscription to record a smooth video of your home — plus every other advanced tool.",cta:"Subscribe & record video",secondary:"Maybe later"},projectLimit:{eyebrow:"Free account",title:"One free project ✨",body:"Without a monthly subscription, you can design one project. Join a monthly subscription to open more projects (or start fresh) with no limit. Your current project stays saved and waiting here.",cta:"Subscribe for unlimited projects",secondary:"Maybe later"},personalLibrary:{eyebrow:"Monthly subscriber feature",title:"Your personal BoardStyler library 🔒",body:"Uploading custom furniture, wall cladding, and flooring — and using your personal library — is reserved for monthly subscribers. Subscribe to keep working with every asset you have saved.",cta:"Subscribe & unlock library",secondary:"Maybe later"},export:{eyebrow:"Monthly subscriber feature",title:"Download from BoardStyler 🔒",body:"Image and 3D model downloads are available to monthly subscribers. Subscribe to download your project as an image or a 3D file.",cta:"Subscribe & unlock downloads",secondary:"Maybe later"}}};function unt({variant:t,onClose:e,onUpgrade:s}){const{locale:o,isRTL:r}=Yd();if(!t)return null;const i=o==="he"?"he":"en",a=dnt[i][t];return n.jsxs("div",{dir:r?"rtl":"ltr",className:"fixed inset-0 z-[100000] flex items-center justify-center px-4 font-heebo text-[#182137]",role:"dialog","aria-modal":"true","aria-labelledby":"boardstyler-upgrade-title","aria-describedby":"boardstyler-upgrade-body",onClick:e,children:[n.jsx("div",{className:"absolute inset-0 bg-[#182137]/55 backdrop-blur-[2px]"}),n.jsxs("section",{onClick:l=>l.stopPropagation(),className:"relative w-full max-w-[480px] overflow-hidden rounded-2xl border border-[#182137]/12 bg-[#F7F4EF] p-6 shadow-[0_24px_70px_rgba(24,33,55,0.32),inset_0_1px_0_rgba(255,255,255,0.58)] sm:p-7",children:[n.jsx("div",{className:"pointer-events-none absolute inset-0 opacity-[0.14]",style:{backgroundImage:"radial-gradient(circle, rgba(24,33,55,0.42) 1px, transparent 1px)",backgroundSize:"22px 22px"}}),n.jsxs("div",{className:"relative",children:[n.jsxs("div",{className:"mb-5 flex items-start justify-between gap-4",children:[n.jsx("div",{className:"rounded-full border border-[#D85D43]/30 bg-[#D85D43]/10 px-3 py-1 text-xs font-black text-[#A13E2B]",children:a.eyebrow}),n.jsx("div",{className:"grid h-14 w-14 shrink-0 place-items-center rounded-2xl border border-[#182137]/10 bg-[#E8E3DB] shadow-[0_10px_24px_rgba(24,33,55,0.12),inset_0_1px_0_rgba(255,255,255,0.52)]",children:n.jsxs("svg",{width:"34",height:"34",viewBox:"0 0 34 34",fill:"none","aria-hidden":"true",children:[n.jsx("path",{d:"M6 10.5L17 5L28 10.5V23.5L17 29L6 23.5V10.5Z",fill:"#F7F4EF",stroke:"#182137",strokeWidth:"2",strokeLinejoin:"round"}),n.jsx("path",{d:"M17 16.5L28 10.5M17 16.5L6 10.5M17 16.5V29",stroke:"#182137",strokeWidth:"2",strokeLinejoin:"round"}),n.jsx("path",{d:"M10.5 20.5L14 22.25M20 11L23.5 12.75",stroke:"#D85D43",strokeWidth:"2.4",strokeLinecap:"round"})]})})]}),n.jsxs("div",{className:O("space-y-3",r?"text-right":"text-left"),children:[n.jsx("h2",{id:"boardstyler-upgrade-title",className:"text-3xl font-black leading-tight sm:text-[34px]",style:{letterSpacing:i==="he"?"-0.035em":"-0.02em"},children:a.title}),n.jsx("p",{id:"boardstyler-upgrade-body",className:"text-[15px] leading-7 text-[#182137]/72",children:a.body})]}),n.jsxs("div",{className:"mt-7 flex flex-col gap-3 sm:flex-row",children:[n.jsx("button",{type:"button",onClick:s,className:"min-h-12 flex-1 rounded-xl bg-[#D85D43] px-5 py-3 text-sm font-black text-[#F7F4EF] shadow-[0_8px_0_#A13E2B,0_18px_28px_rgba(216,93,67,0.25)] transition-transform hover:-translate-y-0.5 hover:bg-[#C94E35] active:translate-y-1 active:shadow-[0_4px_0_#A13E2B,0_12px_20px_rgba(216,93,67,0.18)] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-[#182137]",children:a.cta}),n.jsx("button",{type:"button",onClick:e,className:"min-h-12 rounded-xl border border-[#182137]/12 bg-[#E8E3DB] px-5 py-3 text-sm font-black text-[#182137] shadow-[0_5px_0_rgba(24,33,55,0.16),inset_0_1px_0_rgba(255,255,255,0.55)] transition-transform hover:-translate-y-0.5 active:translate-y-1 active:shadow-[0_2px_0_rgba(24,33,55,0.14)] focu
445s-visible:outline focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-[#D85D43]",children:a.secondary})]})]})]})]})}const w_="floorplan.sketchAxesVisible",lc={thicknessMm:{min:10,max:5e3},heightMm:{min:100,max:5e4}};function hnt(t,e){const{min:s,max:o}=lc[t];return Number.isFinite(e)?Math.max(s,Math.min(o,Math.round(e))):s}function Yh(t){return US(t)}function mnt(t){return t.replace(/[^\d.,xX×*;\s-]/g,"").replace(/\s+/g," ").trimStart()}function fnt(t){const e=t.trim();if(!e||/[,xX×*;\s-]$/.test(e))return null;const s=e.split(/\s*(?:,|x|X|×|\*|;|-|\s+)\s*/).filter(Boolean);return s.length!==2?null:s.every(o=>/^\d+(?:\.\d+)?$/.test(o))?[s[0],s[1]]:null}function k_(t){const e=Yi(t);if(e)return{lengthMm:e.lengthMm,widthMm:e.widthMm};if(t.length<3)return null;const s=t.map(a=>a.x),o=t.map(a=>a.y),r=Math.max(0,Math.round(Math.max(...s)-Math.min(...s))),i=Math.max(0,Math.round(Math.max(...o)-Math.min(...o)));return r>0&&i>0?{lengthMm:r,widthMm:i}:null}function xnt(t,e){return JSON.stringify(t)===JSON.stringify(e)}function jy(t,e){return $w.reduce((s,o)=>(s[o]={thicknessMm:De(t[o].thicknessMm,e),heightMm:De(t[o].heightMm,e)},s),{})}function Yx({preset:t}){const s="#5C3D2E",o="#E8D5C8",r="#9EC9E8",i="#2563A8",a="#050505",l="#C5D6E6",c="#3D4854",d="#1F2937",u="#050505";switch(t){case"single_door":return n.jsxs("svg",{width:34,height:34,viewBox:"0 0 30 30",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"6",y:"3",width:"12",height:"24",rx:"2",fill:o,stroke:s,strokeWidth:"1.65"}),n.jsx("path",{d:"M18 3 A14 14 0 0 1 27 17",stroke:s,strokeWidth:"1",strokeDasharray:"2 2",opacity:"0.65"}),n.jsx("circle",{cx:"15.5",cy:"16",r:"1.5",fill:d})]});case"single_door_glass":return n.jsxs("svg",{width:34,height:34,viewBox:"0 0 30 30",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"6",y:"3",width:"12",height:"24",rx:"2",fill:o,stroke:s,strokeWidth:"1.65"}),n.jsx("rect",{x:"8.5",y:"5.5",width:"7",height:"11",rx:"1",fill:r,stroke:i,strokeWidth:"1.2"}),n.jsx("path",{d:"M18 3 A14 14 0 0 1 27 17",stroke:s,strokeWidth:"1",strokeDasharray:"2 2",opacity:"0.65"}),n.jsx("circle",{cx:"15.5",cy:"21",r:"1.5",fill:d})]});case"flush_door":return n.jsxs("svg",{width:34,height:34,viewBox:"0 0 30 30",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"6",y:"3",width:"18",height:"24",rx:"0.6",fill:"#EFEAE2",stroke:s,strokeWidth:"1.25"}),n.jsx("path",{d:"M8.5 5.5 H21.5 M8.5 24.5 H21.5 M8.5 5.5 V24.5 M21.5 5.5 V24.5",stroke:"#2B211A",strokeWidth:"0.85",opacity:"0.72"}),n.jsx("path",{d:"M24 3 A15 15 0 0 1 29 18",stroke:s,strokeWidth:"1",strokeDasharray:"2 2",opacity:"0.55"}),n.jsx("path",{d:"M18.5 16 H22",stroke:d,strokeWidth:"1.5"}),n.jsx("circle",{cx:"18.3",cy:"16",r:"0.9",fill:d})]});case"double_door":return n.jsxs("svg",{width:34,height:34,viewBox:"0 0 30 30",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"3",y:"3",width:"11",height:"24",rx:"2",fill:o,stroke:s,strokeWidth:"1.65"}),n.jsx("rect",{x:"16",y:"3",width:"11",height:"24",rx:"2",fill:o,stroke:s,strokeWidth:"1.65"}),n.jsx("circle",{cx:"12.5",cy:"16",r:"1.2",fill:d}),n.jsx("circle",{cx:"17.5",cy:"16",r:"1.2",fill:d})]});case"sliding_door":return n.jsxs("svg",{width:34,height:34,viewBox:"0 0 30 30",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"3",y:"3",width:"11",height:"24",rx:"2",fill:o,stroke:s,strokeWidth:"1.65"}),n.jsx("rect",{x:"16",y:"3",width:"11",height:"24",rx:"2",fill:o,stroke:s,strokeWidth:"1.1",strokeDasharray:"2 2",opacity:"0.75"}),n.jsx("path",{d:"M20 15 L25 15",stroke:s,strokeWidth:"1.8"}),n.jsx("path",{d:"M23 13.5 L25 15 L23 16.5",stroke:s,strokeWidth:"1.4",fill:"none"})]});case"corner_glass_door":return n.jsxs("svg",{width:34,height:34,viewBox:"0 0 30 30",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M7 4 V23 H26",stroke:l,strokeWidth:"6.2",opacity:"0.9"}),n.jsx("path",{d:"M7 4 V23 H26",stroke:a,strokeWidth:"2.2"}),n.jsx("path",{d:"M11 7 V19 H23",stroke:a,strokeWidth:"1.4",opacity:"0.8"}),n.jsx("path",{d:"M7 23 L11 19",stroke:a,strokeWidth:"1.5"})]});case"passage":case"wide_doorway":return n.jsxs("svg",{width:34,he
445ight:34,viewBox:"0 0 30 30",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M5 3 L5 27",stroke:c,strokeWidth:"2.1"}),n.jsx("path",{d:"M25 3 L25 27",stroke:c,strokeWidth:"2.1"}),n.jsx("path",{d:"M5 3 L9 3",stroke:c,strokeWidth:"2.1"}),n.jsx("path",{d:"M21 3 L25 3",stroke:c,strokeWidth:"2.1"}),n.jsx("path",{d:"M10 15 L20 15",stroke:s,strokeWidth:"1",strokeDasharray:"2 3",opacity:"0.55"})]});case"arched_door":return n.jsxs("svg",{width:34,height:34,viewBox:"0 0 30 30",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M5 27 L5 11 A10 10 0 0 1 25 11 L25 27 Z",fill:o,stroke:s,strokeWidth:"1.65"}),n.jsx("circle",{cx:"21",cy:"18",r:"1.5",fill:d})]});case"arched_door_glass":return n.jsxs("svg",{width:34,height:34,viewBox:"0 0 30 30",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M5 27 L5 11 A10 10 0 0 1 25 11 L25 27 Z",fill:o,stroke:s,strokeWidth:"1.65"}),n.jsx("path",{d:"M9 25 L9 13 A6 6 0 0 1 21 13 L21 25 Z",fill:r,stroke:i,strokeWidth:"1.1"}),n.jsx("circle",{cx:"21",cy:"23",r:"1.5",fill:d})]});case"fixed_window":return n.jsxs("svg",{width:34,height:34,viewBox:"0 0 30 30",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"8",y:"3",width:"14",height:"24",rx:"2",fill:l,stroke:a,strokeWidth:"1.65"}),n.jsx("line",{x1:"15",y1:"3",x2:"15",y2:"27",stroke:u,strokeWidth:"1.55"})]});case"casement_window":return n.jsxs("svg",{width:34,height:34,viewBox:"0 0 30 30",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"4",y:"5",width:"22",height:"20",rx:"2",fill:l,stroke:a,strokeWidth:"1.65"}),n.jsx("line",{x1:"15",y1:"5",x2:"15",y2:"25",stroke:u,strokeWidth:"1.1"}),n.jsx("path",{d:"M4 15 L9 9 L15 15",fill:r,opacity:"0.85",stroke:i,strokeWidth:"1"}),n.jsx("circle",{cx:"13",cy:"15",r:"1.2",fill:d})]});case"wide_window":return n.jsxs("svg",{width:34,height:34,viewBox:"0 0 30 30",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"2",y:"8",width:"26",height:"14",rx:"2",fill:l,stroke:a,strokeWidth:"1.65"}),n.jsx("line",{x1:"11",y1:"8",x2:"11",y2:"22",stroke:u,strokeWidth:"1.1"}),n.jsx("line",{x1:"19",y1:"8",x2:"19",y2:"22",stroke:u,strokeWidth:"1.1"})]});case"arched_window":return n.jsxs("svg",{width:34,height:34,viewBox:"0 0 30 30",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M6 27 L6 13 A9 9 0 0 1 24 13 L24 27 Z",fill:l,stroke:a,strokeWidth:"1.65"}),n.jsx("line",{x1:"6",y1:"20",x2:"24",y2:"20",stroke:u,strokeWidth:"1.1"}),n.jsx("line",{x1:"15",y1:"13",x2:"15",y2:"27",stroke:u,strokeWidth:"1.1"})]});case"floor_to_ceiling":return n.jsxs("svg",{width:34,height:34,viewBox:"0 0 30 30",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"5",y:"2",width:"20",height:"26",rx:"2",fill:l,stroke:a,strokeWidth:"1.65"}),n.jsx("line",{x1:"15",y1:"2",x2:"15",y2:"28",stroke:u,strokeWidth:"1.1"}),n.jsx("line",{x1:"5",y1:"15",x2:"25",y2:"15",stroke:u,strokeWidth:"1",opacity:"0.9"})]});case"floor_to_ceiling_vertical":return n.jsxs("svg",{width:34,height:34,viewBox:"0 0 30 30",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"5",y:"2",width:"20",height:"26",rx:"2",fill:l,stroke:a,strokeWidth:"1.65"}),n.jsx("line",{x1:"15",y1:"2",x2:"15",y2:"28",stroke:u,strokeWidth:"1.65"})]});case"garage_door":return n.jsxs("svg",{width:34,height:34,viewBox:"0 0 30 30",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"3",y:"5",width:"24",height:"20",rx:"1.5",fill:o,stroke:s,strokeWidth:"1.65"}),n.jsx("line",{x1:"3",y1:"11",x2:"27",y2:"11",stroke:s,strokeWidth:"1.1",opacity:"0.8"}),n.jsx("line",{x1:"3",y1:"16",x2:"27",y2:"16",stroke:s,strokeWidth:"1.1",opacity:"0.8"}),n.jsx("line",{x1:"3",y1:"21",x2:"27",y2:"21",stroke:s,strokeWidth:"1.1",opacity:"0.8"})]});case"awning_window":return n.jsxs("svg",{width:34,height:34,viewBox:"0 0 30 30",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"4",y:"6",width:"22",height:"18",rx:"2",fill:l,stroke:a,strokeWidth:"1.65"}),n.jsx("path",{d:"M4 15 L15 22 L26 15",fill:r,opacity:"0.85",stroke:i,strokeWidth:"1"}),n.jsx("circle",{cx:"15",cy:"12",r:"1.2",fill:d})]});
445case"sliding_window":return n.jsxs("svg",{width:34,height:34,viewBox:"0 0 30 30",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("rect",{x:"3",y:"8",width:"24",height:"14",rx:"1.5",fill:l,stroke:a,strokeWidth:"1.65"}),n.jsx("line",{x1:"15",y1:"8",x2:"15",y2:"22",stroke:u,strokeWidth:"1.4"}),n.jsx("path",{d:"M9 15 L15 15",stroke:a,strokeWidth:"1.6"}),n.jsx("path",{d:"M13 13.5 L15 15 L13 16.5",stroke:a,strokeWidth:"1.2",fill:"none"})]});case"bay_window":return n.jsxs("svg",{width:34,height:34,viewBox:"0 0 30 30",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M3 10 L9 20 H21 L27 10",fill:l,stroke:a,strokeWidth:"1.65"}),n.jsx("line",{x1:"9",y1:"20",x2:"9",y2:"10",stroke:u,strokeWidth:"1.1"}),n.jsx("line",{x1:"21",y1:"20",x2:"21",y2:"10",stroke:u,strokeWidth:"1.1"})]});default:return null}}const pnt=[];function _y(t,e,s,o,r,i,a,l,c="סקיצה חדשה"){return X7(t,s,o,r,i,a,e)??V7(l.trim()||i.trim()||c)}function v_(t,e){e&&Ys.info("[floorplanGeometryQA]",t,B7(e))}const gnt=3e3,bnt=200,Mnt=[10,50,100],ynt=10;function wnt({userId:t,projectId:e,onNavigate:s}){var wk,kk,vk,jk,_k,Ek,Dk,Fk,Ck;const{t:o,i18n:r}=yn(),{isRTL:i}=Yd(),{isAdmin:a}=$N(),{fullAccess:l,isLoading:c,isError:d,refetch:u}=yI(),[h,x]=m.useState("upload");m.useEffect(()=>{yT()},[]);const[f,p]=m.useState(""),[b,M]=m.useState(""),[g,w]=m.useState(e||null),k=m.useRef(e||null),_=m.useRef({}),j=m.useRef(Promise.resolve()),v=m.useRef(null),[C,N]=m.useState(""),[P,L]=m.useState(null),[A,W]=m.useState(null),[S,B]=m.useState(""),[R,z]=m.useState([]),[X,ft]=m.useState([]),[tt,G]=m.useState([]),[Y,J]=m.useState([]),[Mt,Rt]=m.useState({}),[it,st]=m.useState(!1),[ct,pt]=m.useState(null),[xt,_t]=m.useState(null),[Ft,Vt]=m.useState({scale:1,calibrated:!1,planRotationDeg:0}),[vt,Ht]=m.useState(!0),[Tt,Zt]=m.useState(!0),[At,ut]=m.useState(null),[kt,Et]=m.useState(!1),[ht,gt]=m.useState(null),[Pt,U]=m.useState(null),[mt,Nt]=m.useState(0),[Lt,oe]=m.useState(!1),[he,pe]=m.useState(!1),[Ge,Qt]=m.useState(!1),[te,Be]=m.useState(0),[wt,ve]=m.useState(null),[Ne,Le]=m.useState(!1),[is,Fe]=m.useState(!1),[bn,Ve]=m.useState(!1),[,en]=m.useState("classic"),[,on]=m.useState(null),[,Qs]=m.useState(""),[,sn]=m.useState(0),[vn,Ot]=m.useState("trace"),[so,Ue]=m.useState(!1),[hs,Qn]=m.useState(!1),[Lr,bi]=m.useState(b||S||o("project.untitled",{defaultValue:"ללא שם"})),Ps=m.useRef(null),[In,Rn]=m.useState([]),[fe,Gs]=m.useState(!1),[zo,js]=m.useState(!1),[co,ze]=m.useState(new Set),[Un,uo]=m.useState(null),[dn,$o]=m.useState(""),[Te,po]=m.useState(e?"3d":"2d"),[ho,go]=m.useState(e?"building":"floor"),Kl=m.useRef(ho);Kl.current=ho;const[da,As]=m.useState(0),[ua,Gi]=m.useState(0);m.useEffect(()=>{Te==="2d"&&go("floor")},[Te]);const[On,to]=m.useState(wo),[Wt,qe]=m.useState([]),[Se,jn]=m.useState([]),[je,ne]=m.useState(ynt),[Re,Dn]=m.useState([]),[ge,ie]=m.useState([]),[Ze,as]=m.useState(null),[Pe,Ao]=m.useState(null);m.useEffect(()=>{if(!(typeof window>"u")){if(!a){delete window.__floorplanTrainingDebug;return}return window.__floorplanTrainingDebug={exportCurrentProjectTrainingSample:(y=g??"")=>ay(y)},()=>{delete window.__floorplanTrainingDebug}}},[g,a]),m.useEffect(()=>{g||Qt(!1)},[g]);const Lo=m.useRef(new Set),Gt=m.useRef(!1),Co=m.useRef(new Set),Xo=m.useRef(!1),[pn,Kn]=m.useState(null),[tr,ro]=m.useState(null),[ls,Qo]=m.useState(null),[ms,Yo]=m.useState(null);m.useEffect(()=>{jn(y=>{const D=vD(y,Wt);return xnt(y,D)?y:D})},[Wt]);const Qe=m.useRef(!1),[Go,er]=m.useState(()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(w_)!=="false"}catch{return!0}}),[Vn,dr]=m.useState(null),[Ii,fs]=m.useState(""),[Uo,Hn]=m.useState(!1),[ur,oi]=m.useState(null),[Je,rn]=m.useState(0),xs=m.useRef(0),[vo,Ui]=m.useState(null),[It,_s]=m.useState(null),[ha,Mi]=m.useState(""),[Fa,si]=m.useState(!1),Ko=m.useRef(!1),ae=m.useRef(""),Za=m.useRef(null),[Mr,ri]=m.useState(0),[Qc,Es]=m.useState(null),Us=m.useRef(0),[Ki,ts]=m.useState(null),Wo=m.useRef(0),[Ds,pc]=m.useState(null),Ti=m.useRef(0),[eo,yi]=m.useState(null),[nr,zs]=m.useState(""),[es,Ca]=m.useState(""),[eh,ps]=m.useState(""),[Ro,gs]=m.useState(""),[bo,bs]=m.useState(null),[Kr,xl]=m.useState(null),[pl,Zi]=m.useState(null),Si=m.useRef(0),Fs=m.useRef(!1),Pi=m.useRef(""),Na=m.useRef(null),Wr=m.useRef(!1),[Rr,ma]=m.useState(null),[gn,Zo]=m.useState(""),[et,q]=m.useState(!1),Ct=m.useRef(!1),bt=m.useRef(""),[Dt,Xt]=m.useState(null),me=m.useRef(0),[xe,Ee]=m.useState(null),wn=m.useRef(0),lt=m.useRef(null),[He,cn]=m.useState(null),[nn,or]=m.useState(""),qn=m.useRef(!1),Oo=m.useRef(""),[Ks,sr]=m.useState(null),Ls=m.useRef(0),[ns,ii]=m.useState(null),Ia=m.useRef(0),Or=m.useRef(null),os=m.useMemo(()=>Wt.find(y=>y.id===pn&&y.kind==="segment")??null,[Wt,pn]),Zr=m.useMemo(()=>os?Nn(os.a,os.b):null,[os]),Fn=m.useMemo(()=>Wt.find(y=>y.id===pn&&y.kind==="polygon"&&y.sourceTool==="rectangle"&&!!Xr(y.vertices))??null,[Wt,pn]),qr=m.useMemo(()=>Wt.find(y=>y.id===pn&&y.kind==="polygon")??null,[Wt,pn]),Ye=m.useMemo(()=>Wt.filter(y=>y.kind==="polygon"),[Wt]),Ke=m.useMemo(()=>
445{if(!Fn||Fn.kind!=="polygon")return null;const y=Xr(Fn.vertices);return y?{lengthMm:y.lengthMm,widthMm:y.widthMm}:null},[Fn]),Mo=m.useMemo(()=>Fn?Bp(Fn.vertices):[],[Fn]),re=m.useMemo(()=>Fn&&tr?An(Fn,tr):null,[tr,Fn]),_n=m.useMemo(()=>re?{lengthMm:Math.max(0,Math.round(re.widthMm)),widthMm:Math.max(0,Math.round(re.heightMm))}:null,[re]),jo=(re==null?void 0:re.kind)==="side",Ms=(Fn==null?void 0:Fn.kind)==="polygon"?Math.max(0,Math.round(Fn.heightMm??0)):null,un=m.useMemo(()=>Wt.find(y=>y.id===pn&&y.kind==="facePatch")??null,[Wt,pn]),hr=m.useMemo(()=>un?k_(un.points2D):null,[un]),_r=m.useMemo(()=>ms?k_(ms.points2D):null,[ms]),ss=Ke??(_r??hr??_n??Ke),Ai=m.useMemo(()=>{var $;const y=($=Fn==null?void 0:Fn.rectangleWallAnchor)==null?void 0:$.anchorEdgeIndex;if(y==null)return null;const D=Mo.find(Z=>Z.index===y);if(!D)return null;const T=D.dimension;return{length:T,width:T==="length"?"width":"length"}},[(wk=Fn==null?void 0:Fn.rectangleWallAnchor)==null?void 0:wk.anchorEdgeIndex,Mo]),No=un?Math.round(un.depthMm??0):null,Er=(Fn==null?void 0:Fn.id)??(un==null?void 0:un.id)??null,Dr=jo&&re?Math.max(0,Math.round(re.heightMm)):No??Ms;m.useEffect(()=>{Te!=="3d"&&to(wo)},[Te]),m.useEffect(()=>{try{window.localStorage.setItem(w_,Go?"true":"false")}catch{}},[Go]);const[qi,jm]=m.useState("orbit"),[Ws,yr]=m.useState(!1),fa=m.useRef("orbit"),xa=m.useRef("orbit");xa.current=qi;const[Kd,Zl]=m.useState(0);m.useEffect(()=>{Te!=="3d"&&Zl(0)},[Te]),m.useEffect(()=>{const y=qi==="inside"&&fa.current!=="inside";fa.current=qi,y&&nt(!1)},[qi]);const[En,Fr]=m.useState(!1),[wr,qa]=m.useState(()=>new Set),Zd=m.useCallback(y=>{qa(D=>{const T=new Set(D);return T.has(y)?T.delete(y):T.add(y),T})},[]),[td,qd]=m.useState(null),[I,H]=m.useState(!1),[K,nt]=m.useState(()=>{if(typeof window>"u")return!0;try{const y=window.localStorage.getItem(oj);return y===null?!0:y!=="false"}catch{return!0}}),Q=m.useRef(!1),dt=m.useCallback(()=>{Q.current=!1,nt(!0)},[]),jt=m.useCallback(()=>{Q.current=!0,nt(!1)},[]);m.useEffect(()=>{if(!(typeof window>"u"))try{window.localStorage.setItem(oj,String(K))}catch{}},[K]);const[Yt,Ut]=m.useState(()=>{if(typeof window>"u")return y1;try{const y=window.localStorage.getItem(sj);return y?sQ(JSON.parse(y)):y1}catch{return y1}});m.useEffect(()=>{if(!(typeof window>"u"))try{window.localStorage.setItem(sj,JSON.stringify(Yt))}catch{}},[Yt]);const[Jt,we]=m.useState(!1),Mn=m.useRef(!1),tn=m.useRef(null),[fn,Rs]=m.useState(()=>{if(typeof window>"u")return ep(null);try{const y=window.localStorage.getItem(rj);return ep(y?JSON.parse(y):null)}catch{return ep(null)}});m.useEffect(()=>{if(!(typeof window>"u"))try{window.localStorage.setItem(rj,JSON.stringify(fn))}catch{}},[fn]);const[hn,_o]=m.useState(()=>{if(typeof window>"u")return My(null);try{const y=window.localStorage.getItem(ij);return My(y?JSON.parse(y):null)}catch{return My(null)}});m.useEffect(()=>{if(!(typeof window>"u"))try{window.localStorage.setItem(ij,JSON.stringify(hn))}catch{}},[hn]);const ys=m.useCallback((y,D)=>{Rs(T=>Jt&&y==="projectAndPlan"?{...T,[y]:D}:r_(T,y,D))},[Jt]),io=m.useCallback((y,D)=>{var $;const T=(($=vm.find(Z=>Z.id===y))==null?void 0:$.workspaceScope)??"both";Te==="3d"&&T!=="both"&&T!==ho&&(go(T),As(Z=>Z+1)),Rs(Z=>Jt?{...Z,[y]:!0}:r_(Z,y,!0)),Ut(Tp(y)),Q.current||nt(!0),bM(Z=>({id:y,nonce:((Z==null?void 0:Z.nonce)??0)+1}))},[Jt,ho,Te]),zn=h==="trace"&&C&&vn!=="roof"&&vn!=="opening"&&vn!=="furniture"&&(Te==="2d"||Te==="3d"&&qi==="orbit"),Eo=m.useRef(!1);m.useEffect(()=>{const y=zn,D=y&&!Eo.current;Eo.current=y,D&&Ut(Tp("projectAndPlan"))},[zn]),m.useEffect(()=>{const y=Jt,D=Mn.current;y&&!D?(Rs(T=>(tn.current=T,iQ())),io("sketchTemplates",!0)):!y&&D&&(Rs(tn.current??ep(null)),tn.current=null),Mn.current=y},[Jt,io]),m.useEffect(()=>{if(pn){if(Qe.current){Qe.current=!1;return}io("sketchTemplates",!0)}},[pn,io]),m.useEffect(()=>{if(!Fn){ls!==null&&Qo(null);return}ls!==null&&!Mo.some(y=>y.index===ls)&&Qo(null)},[ls,Fn,Mo]);const rr=m.useRef(null),Sa=m.useRef(null),[Li,gl]=m.useState("exterior"),[ql,Hr]=m.useState(!1),[$e,bl]=m.useState(()=>$S()),[Io,Jl]=m.useState(()=>Uh()),[nh,Jd]=m.useState(()=>jy(Uh(),$e)),[Jr,_m]=m.useState("/textures/floors/concrete-raw.jpg"),[cs,Zp]=m.useState(100),[bc,qp]=m.useState(100),[Cs,ed]=m.useState(5),[kr,Pa]=m.useState("#c8c4bc"),[ds,pa]=m.useState({}),To=m.useCallback((y,D)=>{pa(T=>{const $={...T};return D===null?delete $[y]:$[y]=D,$})},[]),[Ho,nd]=m.useState({}),Ji=m.useCallback((y,D)=>{nd(T=>{const $={...T};return D===null||D.length===0?delete $[y]:$[y]=D,$})},[]),zb=m.useCallback((y,D,T)=>{if(D){nd($=>{const Z=$[y];return Z?{...$,[y]:Z.map(ot=>ot.id===D?{...ot,tileOriginXMm:T.xMm,tileOriginYMm:T.yMm}:ot)}:$});return}pa($=>({...$,[y]:{...$[y]??{},tileOriginXMm:T.xMm,tileOriginYMm:T.yMm}}))},[]),[ai,Qd]=m.useState({}),[tu,Ml]=m.useState([]),[Mc,Aa]=m.useState([]),[yl,yc]=m.useState([]),[$b,Jp]=m.useState(null),[wl,eu]=m.useState([]),[Qi,mr]=m.useState({}),[Ns,Ja]=m.useState([$y()]),[rs,ce]=m.useState(null),[nu,ga]=m.useState(!0),[Xb,kl]=m.useState(!1),[Wi,vl]=m.useState(!1),oh=m.useRef(!0),Em=m.useRef(null);m.useEffect(()=>{Te!=="3d"&&kl(!1)},[Te]);const ba=m.useRef(rs);ba.current=rs;const Ri=m.useRef([null]),li=m.useRef(0),[,Gf]=m.useState(0),no=m.useRef("floor"),[Ql,tc]=m.useState(e1),ou=m.useRef(Ql);ou.current=Ql;const Uf=Ql.enabled,[oo,od]=m.useState(Nf),fr=m.useRef(oo),[La,su]=m.useState({}),wi=m.useRef(Ns);wi.current=Ns;const ec=m.useRef(La);ec.current=La;const Qa=m.useRef({}),[Yb,ki]=m.useState(!1),[Kf,ir]=m.useState(!1),ci=m.useRef(null);ci.current={walls:R,beams:X,openings:tt,furniture:Y,calibration:Ft,traceRoomLabels:Mt,roomFloorOverrides:ds,roomFloorRegions:Ho,wallFaceRegions:ai,roomCeilingOverrides:Qi,wallElectricalFixtures:tu,wallNotes:Mc,viewportNotes:yl,sketchEntities:Wt,sketchFurnitureGroups:Se};const Ma=m.useCallback(y=>y===fr.current&&ci.current?ci.current:ec.current[y]??Eu(),[]),wc=m.useCallback(y=>{hu.current=!0,z(y.walls),ft(y.beams),G(y.openings),J(y.furniture),Vt(y.calibration),Rt(y.traceRoomLabels),pa(y.roomFloorOverrides),nd(y.roomFloorRegions),Qd(y.wallFaceRegions),mr(y.roomCeilingOverrides),Ml(y.wallElectricalFixtures),Aa(y.wallNotes),yc(y.viewportNotes),qe(y.sketchEntities),jn(y.sketchFurnitureGroups),pt(null),Kn(null),to(wo),Fm(null),_l(null),vc(null),iu(null),qf(null),ta.current=[],di.current=-1,Tm(D=>D+1),setTimeout(()=>{hu.current=!1},0)},[]),kc=m.useCallback(async y=>{const D=y.id,T=()=>fr.current===D,$=()=>{W(y.imageStoragePath),B(y.imageFilename??"")},Z=Qa.current[D];if(Z!=null&&Z.url.startsWith("blob:")){if(!T())return;N(Z.url),$();return}if(y.imageStoragePath){T()&&N("");try{const ot=await Gk(y.imageStoragePath);if(!T())return;N(ot),$()}catch(ot){console.error("Failed to resolve level image:",ot),T()&&$()}return}T()&&(N(""),$())},[]),Ce=m.useRef(null),ar=m.useCallback(()=>{vr.current=!0,setTimeout(()=>{var y;(y=Ce.current)==null||y.call(Ce)},400)},[]),Oi=m.useCallback(()=>{const y=fr.current,D=ci.current;return D&&(C.startsWith("blob:")&&(Qa.current[y]={url:C,fetchedAt:Date.now()}),su(T=>({...T,[y]:D}))),y},[C]),Dm=m.useCallback(y=>{var Z;
445const D=fr.current,T=wi.current.find(ot=>ot.id===y);if(!T)return;if(Wi){ln.info(o("levels.finishRoofTraceBeforeLeave",{defaultValue:"סיים או בטל את סימון הגג לפני המעבר"}));return}if(go("floor"),ki(!1),ir(!1),As(ot=>ot+1),pt(null),_t(null),Fm(null),_l(null),vc(null),iu(null),qf(null),Cl(null),us(""),sa(null),to(wo),T.visible||Ja(ot=>ot.map(St=>St.id===y?{...St,visible:!0}:St)),y===D)return;const $=ec.current[y]??Eu((Z=ci.current)==null?void 0:Z.calibration);Oi(),su(ot=>{const St={...ot};return delete St[y],St}),wc($),od(y),fr.current=y,kc(T),ar()},[Wi,Oi,wc,kc,ar,o]),ru=m.useCallback(y=>{const D=ci.current;if(!D)return null;const T=(y==null?void 0:y.duplicateFromActive)===!0,$=wi.current.find(Bt=>Bt.id===fr.current),Z=JA(),ot={id:Z,name:lD(wi.current.length),visible:!0,slabThicknessMm:Op,imageStoragePath:T?($==null?void 0:$.imageStoragePath)??null:null,imageFilename:T?($==null?void 0:$.imageFilename)??null:null,imageAlign:T&&($!=null&&$.imageAlign)?{...$.imageAlign}:null,alignmentStatus:"not_required"},St=T?Oq(D):Eu(D.calibration);if(T){const Bt=Qa.current[fr.current];C.startsWith("blob:")?Qa.current[Z]={url:C,fetchedAt:Date.now()}:Bt&&(Qa.current[Z]=Bt)}return Oi(),Ja(Bt=>[...Bt,ot]),wc(St),go("floor"),ki(!1),ir(!1),As(Bt=>Bt+1),pt(null),_t(null),od(Z),fr.current=Z,kc(ot),ar(),Z},[C,Oi,wc,kc,ar]),sd=m.useCallback(y=>{const D=wi.current;if(D.length<=1)return;const T=D.findIndex(ot=>ot.id===y);if(T===-1)return;const $=D[T],Z=D.filter(ot=>ot.id!==y);if($.imageStoragePath&&!Z.some(ot=>ot.imageStoragePath===$.imageStoragePath)&&qM($.imageStoragePath).catch(()=>{}),delete Qa.current[y],y===fr.current){const ot=Z[Math.max(0,T-1)],St=ec.current[ot.id]??Eu();su(Bt=>{const qt={...Bt};return delete qt[y],delete qt[ot.id],qt}),wc(St),go("floor"),ki(!1),ir(!1),As(Bt=>Bt+1),od(ot.id),fr.current=ot.id,kc(ot)}else su(ot=>{const St={...ot};return delete St[y],St});Ja(Z.map(ot=>ot.id===fr.current?{...ot,visible:!0}:ot)),ar()},[wc,kc,ar]),Qp=m.useCallback((y,D)=>{const T=D.trim();T&&(Ja($=>$.map(Z=>Z.id===y?{...Z,name:T}:Z)),ar())},[ar]),Gb=m.useCallback((y,D)=>{y===fr.current&&!D||(Ja(T=>T.map($=>$.id===y?{...$,visible:D}:$)),ar())},[ar]),t0=m.useCallback(async y=>{const D=ru();if(!D)return;we(!1),to(wo);const T=URL.createObjectURL(y);if(Qa.current[D]={url:T,fetchedAt:Date.now()},N(T),L(y),B(y.name),po("2d"),go("floor"),Ja($=>$.map(Z=>Z.id===D?{...Z,alignmentStatus:"pending"}:Z)),ln.info(o("levels.pendingAlignmentNotice",{defaultValue:"התוכנית נוספה. מומלץ ליישר אותה מול הקומה שמתחת לפני תצוגת הבניין."})),t)try{const $=await Uk(y,t);Ja(Z=>Z.map(ot=>ot.id===D?{...ot,imageStoragePath:$,imageFilename:y.name}:ot)),fr.current===D&&W($),ar()}catch($){console.warn("Level image upload failed, continuing locally:",$.message)}},[ru,ar,o,t]),e0=m.useCallback(()=>{ru({duplicateFromActive:!0})},[ru]),Zf=m.useCallback(()=>{_.current={},Ja([$y()]),od(Nf),fr.current=Nf,su({}),ce(null),ba.current=null,ga(!0),tc(e1),ou.current=e1,kl(!1),vl(!1),Ri.current=[null],li.current=0,no.current="floor",Gf(y=>y+1),Qa.current={},go("floor"),ki(!1),ir(!1),As(y=>y+1)},[]);m.useEffect(()=>{Ja(y=>y.map(D=>{if(D.id!==fr.current)return D;const T=A??null,$=S||null;return D.imageStoragePath===T&&D.imageFilename===$?D:{...D,imageStoragePath:T,imageFilename:$}}))},[A,S]);const[$n,Fm]=m.useState(null),[Tn,sh]=m.useState("front"),[jl,_l]=m.useState(null),[Xn,vc]=m.useState(null),[tl,iu]=m.useState(null),[Cr,qf]=m.useState(null),[rh,Jf]=m.useState(!1),[Cm,$s]=m.useState(null),[Nr,jc]=m.useState(null),[Hi,ih]=m.useState(null),au=m.useRef(null),Wa=m.useRef(null);m.useEffect(()=>()=>{Wa.current&&clearTimeout(Wa.current)},[]);const el=m.useCallback(y=>{Wa.current&&(clearTimeout(Wa.current),Wa.current=null),au.current=y,ih(y)},[]),Ir=$e==="mm"?o("settings.millimeters",{defaultValue:"מ״מ"}):o("settings.centimeters",{defaultValue:"ס״מ"}),rd=m.useCallback(y=>`${De(y,$e)} ${Ir}`,[$e,Ir]),Nm=m.useRef($e);Nm.current=$e;const qo=m.useCallback(y=>De(y,Nm.current),[]),ws=m.useCallback(y=>ni(y,Nm.current),[]);m.useEffect(()=>{XS($e)},[$e]);const xr=m.useCallback((y,D)=>{Qd(T=>{const $={...T};return D===null||D.length===0?delete $[y]:$[y]=D,$})},[]),ah=m.useCallback((y,D,T)=>{const $=Yh(T);$.startsWith("-")||Jd(Z=>({...Z,[y]:{...Z[y],[D]:$}}))},[]),n0=m.useCallback((y,D)=>{var St,Bt;const T=((St=nh[y])==null?void 0:St[D])??"",$=((Bt=Io[y])==null?void 0:Bt[D])??lc[D].min,Z=T.trim()===""?$:ni(T,$e),ot=hnt(D,Z??$);Jl(qt=>({...qt,[y]:{...qt[y],[D]:ot}})),Jd(qt=>({...qt,[y]:{...qt[y],[D]:De(ot,$e)}}))},[$e,nh,Io]),o0=m.useCallback(()=>{const y=Uh();Jl(y),Jd(jy(y,$e))},[$e]);m.useEffect(()=>{Jd(jy(Io,$e))},[$e,Io]);const ks=m.useCallback((y,D)=>{const T=fr.current,$={...ci.current??Eu(),sketchEntities:(D==null?void 0:D.floorplanSketchEntities)??Wt,sketchFurnitureGroups:(D==null?void 0:D.floorplanSketchFurnitureGroups)??Se},Z=Lq(Ns,St=>St===T?$:La[St]??Eu(),T,ba.current),ot=Z.levels[0];return rH({...y??{},_blenderModels:_.current,_beams:ot.beams,_traceRoomLabels:ot.traceRoomLabels,_roomFloorOverrides:ot.roomFloorOverrides,_roomFloorRegions:ot.roomFloorRegions,_wallFaceRegions:ot.wallFaceRegions,_wallTypeSettings:Io,_environment:ou.current,_floorplanFigure:{hidden:rh,position:Cm,rotation:Nr},_floorplanCameraPose:au.current??Hi,_floorplanSketch:ot.sketch,_wallElectricalFixtures:ot.wallElectricalFixtures,_wallNotes:ot.wallNotes,_viewportNotes:ot.viewportNotes,_levels:Z},wl)},[Mt,ds,Ho,ai,Io,rh,Cm,Nr,Hi,Wt,Se,tu,Mc,yl,wl,Ns,La]),Ra=m.useCallback(y=>{Ml(y),vr.current=!0},[]),Ub=m.useCallback(y=>{Aa(y),vr.current=!0},[]),s0=m.useCallback(y=>{yc(y),vr.current=!0},[]),Kb=m.useCallback(y=>{Jp({id:y,nonce:Date.now()})},[]),Zb=m.useCallback(y=>{yc(D=>D.map(T=>T.id===y?{...T,hidden:!1}:T)),vr.current=!0,Jp({id:y,nonce:Date.now()})},[]),Qf=m.useCallback(y=>{eu(W3(y)),vr.current=!0},[]),[id,tx]=m.useState(null);m.useRef(null);const{textures:nl,upload:ex,remove:ad,rename:Im}=jI(t),{textures:lu,upload:r0,remove:cu,rename:du}=pB(t),{templates:ld,loading:lh,error:cd,create:i0,rename:ch,remove:dh}=IJ(t),uu=m.useMemo(()=>{var D;const y=FJ(Wt,Se,pn);return((D=y==null?void 0:y.name)==null?void 0:D.trim())||b.trim()||o("myTemplates.defaultName",{defaultValue:"תבנית אישית"})},[Wt,Se,b,pn,o]),dd=m.useCallback(async y=>{const D=EJ({entities:Wt,furnitureGroups:Se,selectedEntityId:pn,scope:y.scope,name:y.name});
445await i0({name:y.name,payload:D,placementMode:y.placementMode,sourceProjectId:g})},[i0,g,Wt,Se,pn]),uh=m.useMemo(()=>{const y=new Set(["/textures/floors/tiles-white.jpg","/textures/floors/tiles-gray.jpg"]),D={"/textures/floors/wood-parquet.jpg":1,"/textures/floors/wood-oak.jpg":1,"/textures/floors/concrete-light.jpg":2,"/textures/floors/concrete-raw.jpg":2,"/textures/floors/marble-white.jpg":1,"/textures/floors/stone-travertine.jpg":1},T=Jr&&!Jr.startsWith("#")&&!Jr.startsWith("/textures/");if(Jr&&(y.has(Jr)||T))return{tileSizeM:[cs/100,bc/100],grout:Cs>0?{widthMm:Cs,color:kr}:void 0};const $=Jr&&D[Jr]||1;return{tileSizeM:[$,$],grout:void 0}},[Jr,cs,bc,Cs,kr]),nx=m.useMemo(()=>{const y=T=>({url:T.url,tileSizeM:[T.tileWidthCm/100,T.tileHeightCm/100],orientation:ei(T.orientation),grout:T.groutWidthMm>0?{widthMm:T.groutWidthMm,color:T.groutColor}:void 0}),D={};for(const T of R)(T.texture||T.backTexture||T.edgeTexture||T.color||T.backColor||T.edgeColor)&&(D[T.id]={front:T.texture?y(T.texture):void 0,back:T.backTexture?y(T.backTexture):void 0,edge:T.edgeTexture?y(T.edgeTexture):void 0,frontColor:T.color,backColor:T.backColor,edgeColor:T.edgeColor});return D},[R]),ta=m.useRef([]),di=m.useRef(-1),hh=m.useRef(null),hu=m.useRef(!1),[,Tm]=m.useState(0),a0=di.current>0,qb=di.current>=0&&di.current<ta.current.length-1,Jb=li.current>0,l0=li.current>=0&&li.current<Ri.current.length-1,c0=Jb||a0,d0=l0||qb,Sm=m.useCallback(y=>{const D=JM(y.wallTypeSettings);hu.current=!0,z(Qg(y.walls,D)),ft(y.beams??[]),G(y.openings),J(y.furniture),nd(y.roomFloorRegions??{}),Qd(y.wallFaceRegions??{}),Jl(D),qe(y.floorplanSketchEntities??[]),jn(y.floorplanSketchFurnitureGroups??[]),Kn(null),setTimeout(()=>{hu.current=!1},0)},[]),u0=m.useCallback(()=>{di.current<=0||(di.current-=1,Sm(ta.current[di.current]),Tm(y=>y+1))},[Sm]),h0=m.useCallback(()=>{di.current>=ta.current.length-1||(di.current+=1,Sm(ta.current[di.current]),Tm(y=>y+1))},[Sm]),ud=m.useCallback(y=>{const D=y?structuredClone(y):null;ba.current=D,ce(D),vr.current=!0,Gf(T=>T+1)},[]),ya=m.useCallback(y=>{const D=y?structuredClone(y):null,T=Ri.current[li.current]??null;JSON.stringify(T)!==JSON.stringify(D)&&(Ri.current=Ri.current.slice(0,li.current+1),Ri.current.push(D),Ri.current.length>50&&Ri.current.shift(),li.current=Ri.current.length-1,no.current="roof",ud(D))},[ud]),m0=m.useCallback(()=>{li.current<=0||(li.current-=1,ud(Ri.current[li.current]??null))},[ud]),f0=m.useCallback(()=>{li.current>=Ri.current.length-1||(li.current+=1,ud(Ri.current[li.current]??null))},[ud]),Pm=m.useCallback(()=>{const y=li.current>0,D=di.current>0;(no.current==="roof"||!D)&&y?m0():u0()},[u0,m0]),Am=m.useCallback(()=>{const y=li.current>=0&&li.current<Ri.current.length-1,D=di.current>=0&&di.current<ta.current.length-1;(no.current==="roof"||!D)&&y?f0():h0()},[h0,f0]);m.useEffect(()=>{if(!hu.current)return no.current="floor",hh.current&&clearTimeout(hh.current),hh.current=setTimeout(()=>{const y={walls:R,beams:X,openings:tt,furniture:Y,roomFloorRegions:Ho,wallFaceRegions:ai,wallTypeSettings:Io,floorplanSketchEntities:Wt,floorplanSketchFurnitureGroups:Se},D=ta.current[di.current];D&&D.walls===y.walls&&D.beams===y.beams&&D.openings===y.openings&&D.furniture===y.furniture&&D.roomFloorRegions===y.roomFloorRegions&&D.wallFaceRegions===y.wallFaceRegions&&D.wallTypeSettings===y.wallTypeSettings&&D.floorplanSketchEntities===y.floorplanSketchEntities&&D.floorplanSketchFurnitureGroups===y.floorplanSketchFurnitureGroups||(ta.current=ta.current.slice(0,di.current+1),ta.current.push(y),ta.current.length>50&&ta.current.shift(),di.current=ta.current.length-1,Tm(T=>T+1))},350),()=>{hh.current&&clearTimeout(hh.current)}},[R,X,tt,Y,Ho,ai,Io,Wt,Se]),m.useEffect(()=>{const y=D=>{const T=D.target;T&&(T.tagName==="INPUT"||T.tagName==="TEXTAREA")||!(D.metaKey||D.ctrlKey)||(D.key==="z"&&!D.shiftKey?(D.preventDefault(),Pm()):(D.key==="z"&&D.shiftKey||D.key==="y")&&(D.preventDefault(),Am()))};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[Pm,Am]),m.useEffect(()=>{const y=D=>{if(D.key!=="Escape")return;const T=D.target;T&&(T.tagName==="INPUT"||T.tagName==="TEXTAREA")||Te==="3d"&&Xy(On)&&(D.preventDefault(),to(wo)
445)};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[On,Te]);const hd=m.useRef(null),ea=m.useRef(null),ox=m.useRef(null),vr=m.useRef(!1),x0=m.useCallback(y=>{au.current=uj(y),vr.current=!0,Wa.current&&(clearTimeout(Wa.current),Wa.current=null),xa.current==="inside"?Wa.current=setTimeout(()=>{Wa.current=null,ih(au.current)},600):ih(au.current)},[]),Oa=m.useRef(!1),mu=m.useRef(null),md=m.useRef(null),mh=m.useRef(null),Lm=m.useRef(null),_c=m.useRef(0),[p0,fh]=m.useState("idle"),Ec=m.useRef(null),{checkTokensAndCall:Wm}=fb(),an=xc(),[Qb,Rm]=m.useState(null),na=m.useCallback(y=>c?(ln.info(o("messages.subscriptionAccessLoading",{defaultValue:"בודקים את סטטוס המנוי…"})),!0):d?(ln.error(o("messages.subscriptionAccessFailed",{defaultValue:"לא הצלחנו לאמת את המנוי. מנסים שוב…"})),u(),!0):l?!1:(Rm(y),!0),[d,c,l,u,o]),nc=m.useCallback(()=>!g&&In.length<1?!1:na("projectLimit"),[na,g,In.length]),Br=m.useCallback(()=>na("personalLibrary"),[na]),fd=m.useCallback(()=>na("export"),[na]),xh=m.useCallback(async(y,D)=>{Br()||await ex(y,D)},[Br,ex]),xd=m.useCallback(async(y,D)=>{Br()||await r0(y,D)},[Br,r0]);m.useEffect(()=>{mu.current=At},[At]),m.useEffect(()=>{md.current=Pt},[Pt]);const ol=m.useCallback((y=!0)=>{mh.current&&(clearTimeout(mh.current),mh.current=null),Lm.current&&(clearTimeout(Lm.current),Lm.current=null),y&&(_c.current+=1)},[]),Dc=m.useCallback(y=>{ol();const D=_c.current;mu.current=y,md.current="כיול",Et(!1),U("כיול"),ut(y),mh.current=setTimeout(()=>{_c.current!==D||md.current!=="כיול"||mu.current!==y||(Et(!0),Lm.current=setTimeout(()=>{if(_c.current!==D||md.current!=="כיול"||mu.current!==y){Et(!1);return}mu.current=null,ut(null),Et(!1)},bnt))},gnt)},[ol]),ph=m.useCallback(()=>{ol(),mu.current=null,Et(!1),ut(null)},[ol]);m.useEffect(()=>()=>ol(),[ol]);const Os=m.useCallback((y,D)=>{const T=j.current.then(async()=>{if(!t)throw new Error("צריך להתחבר כדי לשמור את הפרויקט.");const $=k.current;if(!$&&In.length>=1&&na("projectLimit"))throw new Error("FREE_PROJECT_LIMIT");fh("saving");const Z=_y(R,X,tt,Y,Ft,S,Io,b,o("project.newSketch",{defaultValue:"סקיצה חדשה"}));v_("before save",Z);const ot=wi.current[0],St=Ma(ot.id),Bt=await Kk(t,{name:b||S||o("project.untitled",{defaultValue:"ללא שם"}),imageFilename:ot.imageFilename??"",imageStoragePath:ot.imageStoragePath||void 0,walls:St.walls,openings:St.openings,furniture:St.furniture,calibration:St.calibration,sceneJson:ks(Z,y)},$||void 0);return $||(k.current=Bt,w(Bt),D!=null&&D.navigateOnCreate&&s&&(v.current=Bt,s(`/floorplan-editor/${Bt}`))),vr.current=!1,fh("saved"),Ec.current&&clearTimeout(Ec.current),Ec.current=setTimeout(()=>fh("idle"),2e3),Bt});return j.current=T.then(()=>{},()=>{}),T},[t,R,X,tt,Y,Ft,S,Io,b,A,g,s,ks,Ma,na,In.length,o]),sl=HQ({viewerRef:ea,miniViewerRef:ox,currentProjectId:g}),Om=m.useCallback(async(y,D,T)=>{const $=await sl.bank.saveBlob(D,y.name,{source:"floorplan_walkthrough",sourceFloorplanId:g??null,storagePrefix:"floorplan-walkthroughs",extension:aF(T),aspectRatio:"video"});return $?{id:$.id,url:$.previewUrl,mimeType:$.mimeType??T,storagePath:$.storagePath}:null},[g,sl.bank]),pd=m.useCallback(async y=>{const D=y.scene_json,T=uI(D==null?void 0:D._blenderModels);_.current=T;for(const[Is,mi]of Object.entries(T))pi[Is]={width:mi.widthMm,depth:mi.depthMm,height:mi.heightMm,label:mi.label};px(Is=>({...Object.fromEntries(Object.entries(Is).filter(([mi])=>!mi.startsWith("blender_"))),...Object.fromEntries(Object.entries(T).map(([mi,ra])=>[mi,ra.url]))}));const $=JM(D==null?void 0:D._wallTypeSettings),Z=Aq(D,{walls:y.walls||[],openings:y.openings||[],furniture:y.furniture||[],calibration:y.calibration||{scale:1,calibrated:!1},imageStoragePath:y.image_storage_path||null,imageFilename:y.image_filename||null},$),ot=Z.metas.find(Is=>Is.id===Z.activeLevelId)??Z.metas[0],St=Z.metas.map(Is=>Is.id===ot.id?{...Is,visible:!0}:Is),Bt=Z.buckets[ot.id]??Eu(),qt={};for(const Is of Z.metas)Is.id!==ot.id&&(qt[Is.id]=Z.buckets[Is.id]??Eu());Qa.current={},Ja(St),su(qt),ce(Z.buildingRoof),ba.current=Z.buildingRoof,ga(!0);const se=RP(D==null?void 0:D._environment);tc(se),ou.current=se,kl(!1),vl(!1),Ri.current=[Z.buildingRoof?structuredClone(Z.buildingRoof):null],li.current=0,no.current="floor",Gf(Is=>
445Is+1),od(ot.id),fr.current=ot.id,go(St.length>1?"building":"floor"),ki(!1),ir(!1),As(Is=>Is+1),z(Bt.walls),ft(Bt.beams),G(Bt.openings),J(Bt.furniture),Rt(Bt.traceRoomLabels),el(uj(D==null?void 0:D._floorplanCameraPose)),pa(Bt.roomFloorOverrides),nd(Bt.roomFloorRegions),Qd(Bt.wallFaceRegions),mr(Bt.roomCeilingOverrides),Ml(Bt.wallElectricalFixtures),Aa(Bt.wallNotes),yc(Bt.viewportNotes),eu(sH(D)),Jl($);const Pn=D&&typeof D=="object"?D._floorplanFigure:null;if(Jf(!!(Pn&&Pn.hidden)),$s(Pn&&Pn.position?Pn.position:null),jc(Pn&&typeof Pn.rotation=="number"?Pn.rotation:null),qe(Bt.sketchEntities),jn(Bt.sketchFurnitureGroups),Kn(null),to(wo),Hr(!1),pt(null),Vt(Bt.calibration),B(ot.imageFilename??""),M(y.name||y.image_filename||""),p(y.created_at),w(y.id),k.current=y.id,Qt(!!y.training_contributed),we(!1),sa(null),Lo.current.clear(),Dn([]),Co.current.clear(),ie([]),Ao(null),as(null),ta.current=[],di.current=-1,C&&URL.revokeObjectURL(C),ot.imageStoragePath){const Is=await Gk(ot.imageStoragePath);N(Is),W(ot.imageStoragePath)}else N(""),W(null);Oa.current=!1,Ve(!1),Fe(!1),Le(!1),x("trace")},[C,el]),g0=m.useRef(pd);g0.current=pd,m.useEffect(()=>{if(e){if(v.current===e){v.current=null;return}(async()=>{try{const y=await hI(e);await g0.current(y),po("3d")}catch(y){console.error("Failed to load project:",y),ut(`שגיאה בטעינת פרויקט: ${y.message}`)}})()}},[e]),m.useEffect(()=>{t&&(async()=>{Gs(!0);try{const y=await J0(t);Rn(y)}catch{}finally{Gs(!1)}})()},[t]),m.useEffect(()=>{k.current=g},[g]);const El=m.useCallback(async()=>{if(t&&!(!g&&!C)&&!(!C&&R.length===0&&X.length===0&&tt.length===0&&Y.length===0&&Wt.length===0&&wl.length===0&&!ba.current&&!ou.current.enabled&&wi.current.length<=1)&&vr.current)try{await Os()}catch(y){console.error("Auto-save failed:",y),fh("error"),Ec.current&&clearTimeout(Ec.current),Ec.current=setTimeout(()=>fh("idle"),4e3)}},[t,C,g,R.length,X.length,tt.length,Y.length,Wt.length,wl.length,Os]);Ce.current=El,m.useEffect(()=>{if(!(h!=="trace"||!t)&&!hu.current)return vr.current=!0,hd.current&&clearTimeout(hd.current),hd.current=setTimeout(()=>{El()},3e3),()=>{hd.current&&clearTimeout(hd.current)}},[R,X,tt,Y,Wt,Ft,Mt,ds,Ho,ai,Io,rh,Cm,Nr,Hi,tu,Mc,yl,wl,rs,Ql,h,t,El]),m.useEffect(()=>{const y=()=>{if(!(!vr.current||!t)&&!(!C&&R.length===0&&X.length===0&&tt.length===0&&Y.length===0&&Wt.length===0&&wl.length===0&&!ba.current&&!ou.current.enabled))try{const D=_y(R,X,tt,Y,Ft,S,Io,b,o("project.newSketch",{defaultValue:"סקיצה חדשה"})),T=wi.current[0],$=Ma(T.id);Kk(t,{name:b||S||o("project.untitled",{defaultValue:"ללא שם"}),imageFilename:T.imageFilename??"",imageStoragePath:T.imageStoragePath||void 0,walls:$.walls,openings:$.openings,furniture:$.furniture,calibration:$.calibration,sceneJson:ks(D)},k.current||void 0)}catch{}};return window.addEventListener("beforeunload",y),()=>window.removeEventListener("beforeunload",y)},[t,C,R,X,tt,Y,Wt,wl.length,Ft,S,Io,b,A,g,ks]),m.useEffect(()=>()=>{var y;hd.current&&(clearTimeout(hd.current),vr.current&&((y=Ce.current)==null||y.call(Ce)))},[]);const ui=JSON.stringify(Ns.map(({id:y,name:D,slabThicknessMm:T,imageAlign:$})=>({id:y,name:D,slabThicknessMm:T,imageAlign:$}))),vi=m.useMemo(()=>JSON.parse(ui),[ui]),rl=m.useMemo(()=>{if(h!=="trace")return null;const D=AZ(vi,$=>{var ot;const Z=vi[$];return Z?Z.id===oo?R:((ot=La[Z.id])==null?void 0:ot.walls)??[]:[]},Io),T=vi.map(($,Z)=>{const ot=$.id===oo,St=ot?null:La[$.id];return{id:$.id,name:$.name,elevationMm:D[Z],slabThicknessMm:Z>0?$.slabThicknessMm:void 0,walls:ot?R:(St==null?void 0:St.walls)??[],beams:ot?X:(St==null?void 0:St.beams)??[],openings:ot?tt:(St==null?void 0:St.openings)??[],furniture:ot?pnt:(St==null?void 0:St.furniture)??[],calibration:ot?Ft:(St==null?void 0:St.calibration)??{scale:1,calibrated:!1},worldAlign:$.imageAlign}});return $7(T,S,Io)??V7(b.trim()||S.trim()||o("project.newSketch",{defaultValue:"סקיצה חדשה"}))},[h,R,X,tt,Ft,S,Io,b,vi,oo,La,o]),We=m.useMemo(()=>{var Z;if(!rl)return null;const y=rl.levels.find(ot=>ot.id===oo)??rl.levels[0];if(!y)return rl;const D=Td(R,Ft),T=((Z=vi.find(ot=>ot.id===oo))==null?void 0:Z.imageAlign)??null,$=z7(Y,D,T);return{...rl,levels:rl.levels.map(ot=>ot.id===y.id?{...ot,furniture:$}:ot)}},[rl,Y,R,Ft,oo,vi]),Hs=m.useMemo(()=>Y5(We,Ns,rs),[rs,Ns,We]),fu=m.useCallback(()=>{kl(!1),Wi&&(vl(!1),Zt(oh.current)),Ot(y=>y==="roof"?"edit":y)},[Wi]);m.useEffect(()=>{rs||fu()},[rs,fu]);const xu=m.useCallback(()=>{const y=(We==null?void 0:We.levels.flatMap(D=>D.walls??[]))??[];tc(D=>{const T=!D.enabled;let $=D.lot;if(T&&LP($)){const Z=B5(y);Z&&($=Z)}return{...D,enabled:T,lot:$}})},[We]),tM=m.useCallback(()=>{const y=(We==null?void 0:We.levels.flatMap(T=>T.walls??[]))??[],D=B5(y);D&&tc(T=>({...T,lot:D}
445))},[We]),sx=(We==null?void 0:We.levels.some(y=>{var D;return(((D=y.walls)==null?void 0:D.length)??0)>0}))??!1,pu=m.useCallback(()=>{const y=wi.current[wi.current.length-1];y&&(oh.current=Tt,fr.current!==y.id&&Dm(y.id),po("2d"),go("floor"),Ht(!0),Zt(!1),ki(!1),ir(!1),Ot("roof"),pt(null),kl(!1),vl(!0),io("roof"))},[io,Tt,Dm]),rx=m.useCallback(y=>{ga(y),y||fu()},[fu]),gh=m.useCallback(()=>{fu(),ga(!0),ya(null)},[fu,ya]),il=m.useCallback(y=>{var $;ga(!0),ya(y),vl(!1);const D=Y5(We,Ns,y);if(!D.canRender&&D.reason!=="pending-alignment"&&D.reason!=="host-hidden"&&D.reason!=="non-coplanar-wall-tops"){pu();return}po("3d"),Ns.length>1&&go("building"),ki(!1),ir(!1),kl(!0),($=ea.current)==null||$.setCameraPreset("orbit"),Gi(Z=>Z+1)},[ya,pu,Ns,We]),Hm=m.useCallback((y,D)=>{if(kl(y),!y){vl(!1);return}D!=null&&D.focus&&Gi(T=>T+1)},[]),eM=m.useCallback(()=>{rs&&pu()},[rs,pu]);m.useEffect(()=>{var D;if(!rs||Wi||Hs.canRender){(!rs||Hs.canRender)&&(Em.current=null);return}if(Hs.reason==="pending-alignment"||Hs.reason==="host-hidden"||Hs.reason==="non-coplanar-wall-tops")return;const y=[g??"new",Hs.hostLevelId??"none",Hs.reason??"unknown",((D=rs.footprintOverride)==null?void 0:D.sourceFootprintSignature)??"auto"].join(":");Em.current!==y&&(Em.current=y,pu())},[rs,g,pu,Wi,Hs]);const b0=m.useCallback(()=>{vl(!1),Zt(oh.current),Ot("edit"),kl(!1)},[]),bh=m.useCallback(()=>{var y;vl(!1),Zt(oh.current),Ot("edit"),po("3d"),wi.current.length>1&&go("building"),kl(!0),(y=ea.current)==null||y.setCameraPreset("orbit"),Gi(D=>D+1),io("roof")},[io]),nM=m.useCallback(()=>{const y=ba.current;y&&(ya({...y,footprintMode:"auto",footprintOverride:void 0}),vl(!1),Zt(oh.current),Ot("edit"),Gi(D=>D+1))},[ya]),ix=m.useCallback(y=>{const D=ba.current,T=Hs.sourceFootprintSignature;!D||!T||ya({...D,footprintMode:"manual",footprintOverride:{outer:y.outer.map($=>({...$})),holes:y.holes.map($=>$.map(Z=>({...Z}))),sourceFootprintSignature:T}})},[ya,Hs.sourceFootprintSignature]);m.useEffect(()=>{!rs||rs.footprintMode!=="manual"||!rs.footprintOverride||!Hs.diagnostics.manualOverrideStale||!Hs.autoFootprint||ya({...rs,footprintOverride:{outer:Hs.autoFootprint.outer.map(y=>({...y})),holes:Hs.autoFootprint.holes.map(y=>y.map(D=>({...D}))),sourceFootprintSignature:Hs.autoFootprint.sourceFootprintSignature}})},[rs,ya,Hs]),m.useEffect(()=>{v_("scene built",We)},[We]);const Bm=m.useMemo(()=>Object.fromEntries(Ns.map(y=>[y.id,y.visible])),[Ns]),M0=m.useMemo(()=>{const y={};for(const[D,T]of Object.entries(La))y[D]={roomFloorOverrides:T.roomFloorOverrides,roomFloorRegions:T.roomFloorRegions,wallFaceRegions:T.wallFaceRegions,roomCeilingOverrides:T.roomCeilingOverrides,sketchEntities:T.sketchEntities,sketchFurnitureGroups:T.sketchFurnitureGroups};return y},[La]),Cn=m.useMemo(()=>Td(R,Ft),[R,Ft]),oM=m.useMemo(()=>{const y=Ns[Ns.length-1],D=(rs==null?void 0:rs.footprintMode)==="manual"?rs.footprintOverride:null;return!Wi||!y||oo!==y.id||!D||Hs.diagnostics.manualOverrideInvalid?null:{outer:D.outer.map(T=>lb(T,Cn,y.imageAlign)),holes:D.holes.map(T=>T.map($=>lb($,Cn,y.imageAlign)))}},[oo,rs,Cn,Ns,Wi,Hs.diagnostics.manualOverrideInvalid]),sM=m.useCallback(y=>{var Bt,qt;
445const D=ba.current,T=wi.current[wi.current.length-1];if(!D||!T||fr.current!==T.id)return;const $=Td(((Bt=ci.current)==null?void 0:Bt.walls)??[],((qt=ci.current)==null?void 0:qt.calibration)??Ft),Z=se=>ab(se,$,T.imageAlign),ot=y.outer.map(Z),St=y.holes.map(se=>se.map(Z));if(!yp({outer:ot,holes:St}).valid){ln.error("קונטור הגג אינו תקין. ודא שאין קווים חוצים או צלעות קצרות מדי.");return}ya({...D,footprintMode:"manual",footprintOverride:{outer:ot,holes:St,sourceFootprintSignature:`drawn:${T.id}`}})},[Ft,ya]),gd=m.useMemo(()=>Math.max(0,Ns.findIndex(y=>y.id===oo)),[Ns,oo]),Mh=gd>0?Ns[gd-1]:null,Fc=Mh?La[Mh.id]:null,y0=!!Fc&&Fc.walls.length>0,yh=m.useMemo(()=>{var T;if(!Mh||!Fc||Fc.walls.length===0)return null;const y=Td(Fc.walls,Fc.calibration),D=((T=Ns[gd])==null?void 0:T.imageAlign)??null;return Hq(Fc.walls,{scale:y,align:Mh.imageAlign},{scale:Cn,align:D})},[Mh,Fc,Ns,gd,Cn]),Vm=gd>0&&y0&&!!C,ax=Yb&&gd>0&&!!yh,w0=m.useCallback(()=>{wi.current.findIndex(D=>D.id===fr.current)<=0||(po("2d"),go("floor"),ki(!0),ir(!0))},[]),Cc=m.useCallback(y=>{Vt(T=>({...T,scale:y.scale,calibrated:!0}));const D=fr.current;Ja(T=>T.map($=>$.id===D?{...$,imageAlign:y.align,alignmentStatus:"aligned"}:$)),ir(!1),ar(),ln.success(o("levels.aligned",{defaultValue:"הקומה יושרה מול הקומה שמתחת"}))},[ar,o]);m.useEffect(()=>{Kf&&(!Vm||Te!=="2d")&&ir(!1)},[Kf,Vm,Te]);const[hi,gu]=m.useState(!1),zm=m.useCallback(async y=>{if(fd()||hi)return;const D=We??_y(R,X,tt,Y,Ft,S,Io,b,o("project.newSketch",{defaultValue:"סקיצה חדשה"})),T=D?aq(D):null;if(!T){ln.error(o("messages.exportNoModel",{defaultValue:"אין מודל לייצוא — שרטטו קירות תחילה."}));return}const $=y==="skp"?"floorplan_export_skp":"floorplan_export_mesh",Z=ln.loading(y==="skp"?o("messages.exportSketchupLoading",{defaultValue:"בונה קובץ SketchUp… זה עשוי לקחת עד דקה"}):o("messages.exportModelLoading",{defaultValue:"מייצא את המודל…"}));gu(!0);try{const ot=await Wm("sketchup-agent",{action:"export_floorplan",plan:T,format:y,project_id:g??null,crm_surface:"floorplan-editor",crm_feature_key:$},$,{maxRetries:0,timeout:18e4}),St=ot.success?ot.data:null;if(!ot.success||!(St!=null&&St.success)||!St.url){ln.error((St==null?void 0:St.error)||ot.error||o("messages.exportFailed",{defaultValue:"הייצוא נכשל. נסו שוב."}),{id:Z});return}const Bt=(b||S||"boardspace-floorplan").replace(/\.[^.]+$/,"").replace(/[^\w֐-׿-]+/g,"_")||"boardspace-floorplan";await U7(St.url,`${Bt}.${y}`),ln.success(y==="skp"?o("messages.exportSketchupSuccess",{defaultValue:"קובץ SketchUp מוכן והורד!"}):o("messages.exportModelSuccess",{defaultValue:"קובץ {{format}} הורד!",format:y.toUpperCase()}),{id:Z})}catch(ot){console.error("[floorplan] model export failed",ot),ln.error(o("messages.exportFailed",{defaultValue:"הייצוא נכשל. נסו שוב."}),{id:Z})}finally{gu(!1)}},[fd,hi,We,R,tt,Y,Ft,S,Io,b,Wm,g,o]),Vr=m.useCallback((y,D,T,$)=>{z(Z=>Z.map(ot=>ot.id!==y?ot:D==="front"?T?{...ot,texture:T,color:void 0}:$?{...ot,color:$,texture:void 0}:{...ot,texture:void 0,color:void 0}:D==="back"?T?{...ot,backTexture:T,backColor:void 0}:$?{...ot,backColor:$,backTexture:void 0}:{...ot,backTexture:void 0,backColor:void 0}:T?{...ot,edgeTexture:T,edgeColor:void 0}:$?{...ot,edgeColor:$,edgeTexture:void 0}:{...ot,edgeTexture:void 0,edgeColor:void 0}))},[]),Dl=m.useCallback(y=>{var $;if(!$n)return!1;const D=`${$n}__${Tn}`,T=ai[D]??[];if(jl){const Z=T.map(ot=>ot.id===jl?{...ot,...y,id:ot.id,polygon:ot.polygon}:ot);return xr(D,Z),!0}if(T.length>0){const Z=($=We==null?void 0:We.levels[0])==null?void 0:$.walls.find(Pn=>Pn.id===$n);if(!Z)return!0;const ot=Z.end.x-Z.start.x,St=Z.end.y-Z.start.y,Bt=Math.sqrt(ot*ot+St*St),qt=Z.height,se={...y,id:`wallregion_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,polygon:[{u:0,v:0},{u:Bt,v:0},{u:Bt,v:qt},{u:0,v:qt}]};return xr(D,[se,...T]),!0}return!1},[$n,Tn,jl,ai,xr,We]),Fl=m.useCallback(y=>{if(!Xn)return!1;const D=Ho[Xn]??[];if(tl){const T=D.map($=>
445$.id===tl?{...$,...y,id:$.id,polygon:$.polygon}:$);return Ji(Xn,T),!0}if(D.length>0){const{id:T,polygon:$,...Z}=y,ot=ds[Xn]??{};return To(Xn,{...ot,...Z}),!0}return!1},[Xn,tl,Ho,ds,Ji,To]),k0=m.useCallback(y=>{if(!$n||Dl({textureUrl:y,color:void 0}))return;const D=R.find(Z=>Z.id===$n),T=Tn==="edge"?D==null?void 0:D.edgeTexture:Tn==="back"?(D==null?void 0:D.backTexture)??(D==null?void 0:D.texture):D==null?void 0:D.texture,$={url:y,tileWidthCm:(T==null?void 0:T.tileWidthCm)??100,tileHeightCm:(T==null?void 0:T.tileHeightCm)??270,groutWidthMm:(T==null?void 0:T.groutWidthMm)??3,groutColor:(T==null?void 0:T.groutColor)??"#c8c4bc",orientation:ei(T==null?void 0:T.orientation)};Vr($n,Tn,$)},[$n,Tn,R,Dl,Vr]),$m=m.useCallback(y=>{$n&&(Dl({textureUrl:y,color:y})||Vr($n,Tn,void 0,y))},[$n,Tn,Dl,Vr]),v0=m.useCallback((y,D)=>{if(!$n||Dl({tileWidthCm:y,tileHeightCm:D}))return;const T=R.find(Z=>Z.id===$n),$=Tn==="edge"?T==null?void 0:T.edgeTexture:Tn==="back"?(T==null?void 0:T.backTexture)??(T==null?void 0:T.texture):T==null?void 0:T.texture;$&&Vr($n,Tn,{...$,tileWidthCm:y,tileHeightCm:D})},[$n,Tn,R,Dl,Vr]),rM=m.useCallback((y,D)=>{if(!$n||Dl({groutWidthMm:y,groutColor:D}))return;const T=R.find(Z=>Z.id===$n),$=Tn==="edge"?T==null?void 0:T.edgeTexture:Tn==="back"?(T==null?void 0:T.backTexture)??(T==null?void 0:T.texture):T==null?void 0:T.texture;$&&Vr($n,Tn,{...$,groutWidthMm:y,groutColor:D})},[$n,Tn,R,Dl,Vr]),iM=m.useCallback(y=>{if(!$n)return;const D=ei(y);if(Dl({orientation:D}))return;const T=R.find(Z=>Z.id===$n),$=Tn==="edge"?T==null?void 0:T.edgeTexture:Tn==="back"?(T==null?void 0:T.backTexture)??(T==null?void 0:T.texture):T==null?void 0:T.texture;$&&Vr($n,Tn,{...$,orientation:D})},[$n,Tn,R,Dl,Vr]),aM=m.useCallback(()=>{if(!$n)return;const y=`${$n}__${Tn}`,D=ai[y]??[];if(jl&&D.length>0){xr(y,D.filter(T=>T.id!==jl));return}D.length>0||Vr($n,Tn,void 0)},[$n,Tn,jl,ai,xr,Vr]),Xm=m.useCallback((y,D)=>{var mi;const T=R.find(ra=>ra.id===y),$=(mi=We==null?void 0:We.levels[0])==null?void 0:mi.walls.find(ra=>ra.id===y);if(!T||!$)return;const Z=$.end.x-$.start.x,ot=$.end.y-$.start.y,St=Math.sqrt(Z*Z+ot*ot),Bt=$.height,qt=D==="front"?T.texture:T.backTexture??T.texture,se=D==="front"?T.color:T.backColor??T.color,Pn={id:`wallregion_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,polygon:[{u:0,v:0},{u:St,v:0},{u:St,v:Bt},{u:0,v:Bt}],textureUrl:qt==null?void 0:qt.url,color:se,tileWidthCm:qt==null?void 0:qt.tileWidthCm,tileHeightCm:qt==null?void 0:qt.tileHeightCm,orientation:qt==null?void 0:qt.orientation,groutWidthMm:qt==null?void 0:qt.groutWidthMm,groutColor:qt==null?void 0:qt.groutColor},Is=`${y}__${D}`;xr(Is,[Pn]),Vr(y,D,void 0),_l(Pn.id)},[R,We,xr,Vr]),lM=m.useCallback((y,D)=>{const T=`${y}__${D}`,$=ai[T]??[];if($.length===0)return;const Z=$[0];if(Z.textureUrl&&!Z.textureUrl.startsWith("#")){const ot={url:Z.textureUrl,tileWidthCm:Z.tileWidthCm??100,tileHeightCm:Z.tileHeightCm??270,groutWidthMm:Z.groutWidthMm??3,groutColor:Z.groutColor??"#c8c4bc",orientation:ei(Z.orientation)};Vr(y,D,ot)}else Z.color?Vr(y,D,void 0,Z.color):Vr(y,D,void 0);xr(T,null),_l(null)},[ai,xr,Vr]),j0=m.useCallback(y=>{if(Xn){if(Fl({id:"",polygon:[],textureUrl:y,color:void 0}))return;const D=ds[Xn]??{};To(Xn,{...D,textureUrl:y,color:void 0})}else _m(y)},[Xn,Fl,ds,To]),cM=m.useCallback(y=>{if(Xn){if(Fl({id:"",polygon:[],textureUrl:y,color:y}))return;const D=ds[Xn]??{};To(Xn,{...D,textureUrl:y,color:y})}else _m(y)},[Xn,Fl,ds,To]),dM=m.useCallback((y,D)=>{if(Xn){if(Fl({id:"",polygon:[],tileWidthCm:y,tileHeightCm:D}))return;const T=ds[Xn]??{};To(Xn,{...T,tileWidthCm:y,tileHeightCm:D})}else Zp(y),qp(D)},[Xn,Fl,ds,To]),uM=m.useCallback((y,D)=>{if(Xn){if(Fl({id:"",polygon:[],groutWidthMm:y,groutColor:D}))return;const T=ds[Xn]??{};To(Xn,{...T,groutWidthMm:y,groutColor:D})}else ed(y),Pa(D)},[Xn,Fl,ds,To]),hM=m.useCallback(()=>{if(Xn){const y=Ho[Xn]??[];if(tl&&y.length>0){Ji(Xn,y.filter(D=>D.id!==tl));return}if(y.length>0){To(Xn,null);return}To(Xn,null)}else _m(void 0)},[Xn,tl,Ho,Ji,To]),oa=m.useCallback(y=>{mr(D=>{var Z;const T={...D},$=((Z=We==null?void 0:We.levels[0])==null?void 0:Z.rooms)??[];for(const ot of $){const St=la(ot);T[St]={...T[St],...y}}return T})},[We]),mM=m.useCallback(y=>{const D=Cr;D?mr(T=>({...T,[D]:{...T[D],textureUrl:y,color:void 0}})):oa({textureUrl:y,color:void 0})},[Cr,oa]),Ym=m.useCallback(y=>{const D=Cr;D?mr(T=>({...T,[D]:{...T[D],textureUrl:y,color:y}})):oa({textureUrl:y,color:y})},[Cr,oa]),fM=m.useCallback((y,D)=>{const T=Cr;T?mr($=>({...$,[T]:{...$[T],tileWidthCm:y,tileHeightCm:D}})):oa({tileWidthCm:y,tileHeightCm:D})},[Cr,oa]),xM=m.useCallback((y,D)=>{const T=Cr;T?mr($=>({...$,[T]:{...$[T],groutWidthMm:y,groutColor:D}})):oa({groutWidthMm:y,groutColor:D})},[Cr,oa]),_0=m.useCallback(y=>{const D=Cr;D?mr(T=>({...T,[D]:{...T[D],ceilingStyle:y}})):oa({ceilingStyle:y})},[Cr,oa]),pM=m.useCallback(y=>{const D=Cr,T=y/100;D?mr($=>({...$,[D]:{...$[D],gapWidth:T}})):oa({gapWidth:T})},[Cr,oa]),gM=m.useCallback((y,D)=>{const T=Cr,$=y/100,Z=D/100;T?mr(ot=>({...ot,[T]:{...ot[T],coveWidth:$,coveDepth:Z}})):oa({coveWidth:$,coveDepth:Z})},[Cr,oa]),E0=m.useCallback(()=>{const y=Cr;y&&mr(D=>{const T={...D};return delete T[y],T})},[Cr]),lx=m.useCallback(y=>{var Z;const D=(Z=We==null?void 0:We.levels[0])==null?void 0:Z.rooms.find(ot=>la(ot)===y);if(!D||!D.vertices||D.vertices.length<3)return;
445const T=ds[y],$={id:`region_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,polygon:D.vertices.map(ot=>({x:ot.x,y:ot.y})),textureUrl:(T==null?void 0:T.textureUrl)??Jr,color:T==null?void 0:T.color,tileWidthCm:(T==null?void 0:T.tileWidthCm)??cs,tileHeightCm:(T==null?void 0:T.tileHeightCm)??bc,groutWidthMm:(T==null?void 0:T.groutWidthMm)??Cs,groutColor:(T==null?void 0:T.groutColor)??kr,tileOriginXMm:T==null?void 0:T.tileOriginXMm,tileOriginYMm:T==null?void 0:T.tileOriginYMm};Ji(y,[$]),To(y,null),iu($.id)},[We,ds,Jr,cs,bc,Cs,kr,Ji,To]),cx=m.useCallback(y=>{const D=Ho[y]??[];if(D.length===0)return;const T=D[0];To(y,{textureUrl:T.textureUrl,color:T.color,tileWidthCm:T.tileWidthCm,tileHeightCm:T.tileHeightCm,groutWidthMm:T.groutWidthMm,groutColor:T.groutColor,tileOriginXMm:T.tileOriginXMm,tileOriginYMm:T.tileOriginYMm}),Ji(y,null),iu(null)},[Ho,Ji,To]),[D0,bM]=m.useState(void 0),F0=m.useMemo(()=>{var D;const y=(D=We==null?void 0:We.levels[0])==null?void 0:D.rooms;return y!=null&&y.length?y.map(T=>la(T)).sort().join(";"):""},[We]);m.useEffect(()=>{var D,T;if(!((T=(D=We==null?void 0:We.levels[0])==null?void 0:D.rooms)!=null&&T.length)){pa({});return}const y=We.levels[0].rooms;pa($=>{const Z=YE($,y);return JSON.stringify($)===JSON.stringify(Z)?$:Z})},[F0]);const bd=m.useMemo(()=>Tt?F7(R,Cn):[],[Tt,R,Cn]),MM=m.useMemo(()=>N7(bd,Mt),[bd,Mt]),C0=m.useMemo(()=>bd.map(y=>y.id),[bd]),yM=m.useMemo(()=>{var $,Z,ot;const y=($=We==null?void 0:We.levels)==null?void 0:$[0];if(!y)return null;const D=(Z=y.rooms)==null?void 0:Z[0],T=(ot=D==null?void 0:D.vertices)!=null&&ot.length?{x:D.vertices.reduce((St,Bt)=>St+Bt.x,0)/D.vertices.length/1e3,z:D.vertices.reduce((St,Bt)=>St+Bt.y,0)/D.vertices.length/1e3}:null;return yF(Kw(y.walls),T)},[We]),Gm=Hi??yM,N0=m.useMemo(()=>{if(!$n)return null;const y=R.find(D=>D.id===$n);return y?{wallId:y.id,startMm:{x:Math.round(y.start.x*Cn),y:Math.round(y.start.y*Cn)},endMm:{x:Math.round(y.end.x*Cn),y:Math.round(y.end.y*Cn)},thicknessMm:y.thicknessMm??100,side:Tn==="back"?"back":"front"}:null},[Cn,$n,Tn,R]),pr=m.useMemo(()=>{if(R.length===0)return null;const y=[],D=[];for(const St of R)y.push(St.start.x*Cn,St.end.x*Cn),D.push(St.start.y*Cn,St.end.y*Cn);const T=Math.round(Math.min(...y)),$=Math.round(Math.min(...D)),Z=Math.round(Math.max(...y)),ot=Math.round(Math.max(...D));return![T,$,Z,ot].every(Number.isFinite)||Z<=T||ot<=$?null:{minX:T,minY:$,maxX:Z,maxY:ot}},[Cn,R]),wM=m.useMemo(()=>pr?{x:Math.round((pr.minX+pr.maxX)/2),y:Math.round((pr.minY+pr.maxY)/2)}:null,[pr]),dx=m.useMemo(()=>Re.filter(y=>y.status==="pending"||y.status==="running").length,[Re]),kM=m.useMemo(()=>ge.filter(y=>y.status==="pending"||y.status==="running").length,[ge]),I0=m.useCallback(y=>{var $,Z;const D=(($=y.placement_context)==null?void 0:$.wallAnchor)??((Z=y.placement_context)==null?void 0:Z.selectedWallAnchor)??null;if(!(D!=null&&D.wallId))return null;const T=R.find(ot=>ot.id===D.wallId);return T?{wallId:T.id,startMm:{x:Math.round(T.start.x*Cn),y:Math.round(T.start.y*Cn)},endMm:{x:Math.round(T.end.x*Cn),y:Math.round(T.end.y*Cn)},thicknessMm:T.thicknessMm??D.thicknessMm??100,side:D.side==="back"?"back":"front"}:null},[Cn,R]),Um=m.useCallback(async()=>{if(!(!g||!t||h!=="trace")&&!Gt.current){Gt.current=!0;try{const y=await mI(g);Dn(y);let D=Wt,T=Se;const $=[];let Z=!1,ot=null;const St=Lo.current;for(const Bt of y){if(St.has(Bt.id))continue;const qt=Ket(Bt,{entities:D,furnitureGroups:T,wallAnchor:I0(Bt),floorplanBounds:pr});if(qt.kind==="applied"){D=qt.entities,T=qt.furnitureGroups,$.push(Bt.id),Z=!0,ot=qt.built.hostId,qt.warnings.length>0&&as({id:`${Bt.id}:warnings`,assistantMessageHe:qt.warnings.join(`
446`)});continue}if(qt.kind==="duplicate"){vr.current||$.push(Bt.id);continue}if(qt.kind==="clarification"){St.add(Bt.id),as({id:Bt.id,assistantMessageHe:qt.assistantMessageHe,questions:qt.questions}),ln.message("בורדי צריך עוד פרטים כדי להשלים את התבנית");continue}qt.kind==="ignored"&&qt.reason==="invalid"&&(St.add(Bt.id),as({id:Bt.id,assistantMessageHe:qt.error?`קיבלתי תבנית, אבל היא לא עברה ולידציה
446: ${qt.error}`:"קיבלתי תבנית, אבל היא לא עברה ולידציה."}))}Z&&(qe(D),jn(T),to(wo),ot&&(Kn(ot),Qo(null),ro(null),Yo(null)),po("3d"),io("sketchTemplates"),vr.current=!0,await Os({floorplanSketchEntities:D,floorplanSketchFurnitureGroups:T}),ln.success("התבנית מוכנה ונוספה לפרויקט")),$.length>0&&(await Promise.all($.map(Bt=>Zk(Bt))),$.forEach(Bt=>St.add(Bt)),Dn(Bt=>Bt.filter(qt=>!$.includes(qt.id))))}catch(y){Ys.error("Template agent recovery failed:",y)}finally{Gt.current=!1}}},[g,t,h,Wt,Se,I0,pr,io,Os]);m.useEffect(()=>{if(!g||!t||h!=="trace")return;Um();const y=window.setInterval(()=>{Um()},4e3);return()=>window.clearInterval(y)},[g,t,h,Um]);const ux=m.useCallback(async y=>{try{await Zk(y),Lo.current.add(y),Dn(D=>D.filter(T=>T.id!==y)),as(D=>(D==null?void 0:D.id)===y?null:D)}catch(D){Ys.error("Template agent clarification consume failed:",D)}},[]),E=m.useCallback(async()=>{if(!(!g||!t||h!=="trace")&&!Xo.current){Xo.current=!0;try{const y=await fI(g);ie(y);let D=Wt,T=Se;const $=[];let Z=!1,ot=null;const St=Co.current;for(const Bt of y){if(St.has(Bt.id))continue;const qt=qet(Bt,{entities:D,furnitureGroups:T});if(qt.kind==="applied"){D=qt.entities,T=qt.furnitureGroups,$.push(Bt.id),Z=!0,ot=qt.selectedEntityId??ot,qt.warnings.length>0&&Ao({id:`${Bt.id}:warnings`,groupId:Bt.target_group_id,assistantMessageHe:qt.warnings.join(`
447`)});continue}if(qt.kind==="clarification"){St.add(Bt.id),Ao({id:Bt.id,groupId:Bt.target_group_id,assistantMessageHe:qt.assistantMessageHe,questions:qt.questions}),ln.message("בורדי צריכה עוד פרט קטן לפני העריכה");continue}qt.kind==="ignored"&&(qt.reason==="invalid"||qt.reason==="stale"||qt.reason==="missing_group")&&(St.add(Bt.id),Ao({id:Bt.id,groupId:Bt.target_group_id,assistantMessageHe:qt.assistantMessageHe??qt.error??"לא הצלחתי להחיל את העריכה על התבנית."}))}Z&&(qe(D),jn(T),to(wo),ot&&(Kn(ot),Qo(null),ro(null),Yo(null)),po("3d"),io("sketchTemplates"),vr.current=!0,await Os({floorplanSketchEntities:D,floorplanSketchFurnitureGroups:T}),ln.success("בורדי עדכנה את התבנית")),$.length>0&&(await Promise.all($.map(Bt=>xI(Bt))),$.forEach(Bt=>St.add(Bt)),ie(Bt=>Bt.filter(qt=>!$.includes(qt.id))))}catch(y){Ys.error("Template editor recovery failed:",y)}finally{Xo.current=!1}}},[g,t,h,Wt,Se,io,Os]);m.useEffect(()=>{if(!g||!t||h!=="trace")return;E();const y=window.setInterval(()=>{E()},4e3);return()=>window.clearInterval(y)},[g,t,h,E]);const F=m.useCallback(async y=>{if(!t)return{success:!1,status:"failed",assistantMessageHe:"צריך להתחבר כדי לערוך תבנית עם בורדי."};let D=g;try{D=await Os(void 0,{navigateOnCreate:!0})}catch(ot){return{success:!1,status:"failed",assistantMessageHe:ot instanceof Error?ot.message:"לא הצלחתי לשמור את הפרויקט לפני העריכה."}}const T=bw(Wt,Se,y.groupId,{entityId:y.clickedEntityId,faceId:y.clickedFaceId??null});if(!T)return{success:!1,status:"failed",assistantMessageHe:"לא מצאתי את התבנית שנבחרה. נסו ללחוץ עליה שוב."};const $=await Wm("floorplan-template-editor-kimi",{mode:"edit",projectId:D,message:y.message,targetGroupId:y.groupId,targetFingerprint:T.fingerprint,targetSnapshot:T,measurementContext:{internalUnits:"mm",displayUnit:$e,displayUnitLabel:Ka($e)},clickedContext:{entityId:y.clickedEntityId,faceId:y.clickedFaceId??null},crm_surface:"floorplan-editor",crm_feature_key:"floorplan_template_agent_edit"},"floorplan_template_agent_edit",{maxRetries:0,timeout:18e4}),Z=$.success?$.data:null;return!$.success||!(Z!=null&&Z.success)?{success:!1,status:"failed",assistantMessageHe:(Z==null?void 0:Z.assistantMessageHe)||$.error||"לא הצלחתי לפתוח עבודת עריכה."}:(E(),{success:!0,status:Z.status??"running",assistantMessageHe:Z.assistantMessageHe||"אני עורכת את התבנית ברקע.",jobId:Z.jobId,questions:Array.isArray(Z.questions)?Z.questions:void 0})},[Wm,g,Wt,Se,$e,E,Os,t]),V=m.useCallback(async y=>{const D=y.name.toLowerCase().split(".").pop()||"";if(!["svg","png","jpg","jpeg"].includes(D)){alert(o("messages.unsupportedImageFormat",{defaultValue:"פורמטים נתמכים: SVG, PNG, JPG"}));return}if(C&&URL.revokeObjectURL(C),we(!1),sa(null),N(URL.createObjectURL(y)),L(y),B(y.name),M(y.name.replace(/\.[^.]+$/,"")),_.current={},z([]),ft([]),G([]),J([]),pt(null),Rt({}),Ml([]),Aa([]),yc([]),eu([]),el(null),qe([]),jn([]),Kn(null),to(wo),Jl(Uh()),Hr(!1),Vt({scale:1,calibrated:!1,planRotationDeg:0}),w(null),Lo.current.clear(),Dn([]),Co.current.clear(),ie([]),Ao(null),as(null),A&&qM(A).catch(()=>{}),W(null),p(new Date().toISOString()),ut(null),gt(null),ve(null),U(null),Nt(0),Be(0),Le(!1),Fe(!1),Ve(!0),Oa.current=!0,po("2d"),Ot("calibrate"),x("trace"),t)try{const T=await Uk(y,t);W(T)}catch(T){console.warn("Image upload failed, continuing locally:",T.message)}ut(null),Oa.current=!0},[C,t,A,o]),at=m.useCallback(async y=>{var D;if(C){x("detecting"),ve(null),ut(y==="smp"?o("scanReview.scanningCv",{defaultValue:"סורק עם מודל ה-CV המאומן (ניסיוני)..."}):o("scanReview.scanningParser",{defaultValue:"סורק את התוכנית עם Parser V2..."})),en("ai");try{const T=await ent(C,!0),Z=await tnt({imageBase64:!A?T.dataUrl:null,imageStoragePath:A,projectId:g,imageWidth:T.originalWidth,imageHeight:T.originalHeight,scaleMmPerPx:Ft.calibrated&&Number.isFinite(Ft.scale)?Ft.scale:null,variant:y});window.__floorplanParserV2Debug=Z;const ot=[...(Z.walls??[]).map(Bt=>Number(Bt.confidence)),...(Z.openings??[]).map(Bt=>
447Number(Bt.confidence))].filter(Bt=>Number.isFinite(Bt)),St=ot.length?ot.reduce((Bt,qt)=>Bt+qt,0)/ot.length:0;if(!Z.success||(((D=Z.walls)==null?void 0:D.length)??0)<2){U("Parser V2 Failed"),Nt(0),Be(Number.isFinite(St)?St:0),ut(Z.error||o("scanReview.notEnoughWalls",{defaultValue:"Parser V2 לא זיהה מספיק קירות. נסו לצייר ידנית."}));return}ve(Z),U("Parser V2"),Nt(Z.walls.length),Be(Number.isFinite(St)?St:0),ut(o("scanReview.ready",{defaultValue:"נוצרה שכבת בדיקה. אשרו את הקירות והפתחים לפני החלה."}))}catch(T){Ys.error("Floorplan Parser V2 detect error:",T),ut(o("scanReview.error",{message:T.message,defaultValue:`שגיאה: ${T.message}`})),U("Parser V2 Failed")}finally{x("trace")}}},[Ft.calibrated,Ft.scale,g,A,C,o]);m.useCallback(async()=>{if(!(!g||Lt)){oe(!0),U("שיפור זיהוי"),ut("שומר דגימה לשיפור הזיהוי…");try{await Os();const y=await ay(g,{captureContext:"corrected_ai_scan"});y.summary.saveError?ut(`השמירה נכשלה: ${y.summary.saveError}`):y.usability.usable?ut("תודה! התיקון נשמר כדוגמה לשיפור זיהוי ה-AI 🙏"):ut("הדגימה לא נשמרה — התיקון עדיין חלקי מדי (חסרים קירות/חדרים).")}catch(y){Ys.error("Floorplan training sample capture failed:",y),ut(`שגיאה בשמירת הדגימה: ${(y==null?void 0:y.message)??"לא ידוע"}`)}finally{oe(!1)}}},[g,Lt,Os]),m.useCallback(async()=>{if(he)return;if(!t){U("אימון מודל"),ut("צריך להתחבר כדי לתרום תוכנית לאימון.");return}if(!Ft.calibrated){U("אימון מודל"),ut("צריך לכייל את התוכנית (סרגל הכיול) לפני תרומה לאימון — תוכנית לא מכוילת לא נכנסת לדאטהסט.");return}if(R.length<4){U("אימון מודל"),ut(`צריך לפחות 4 קירות כדי לתרום לאימון (יש ${R.length}).`);return}const y=new Set(R.map(Z=>Z.id)),D=tt.filter(Z=>Z.detectionSource!=="ai"&&y.has(Z.wallId)&&Number.isFinite(Z.positionPx)),T=D.filter(Z=>Z.type==="door").length,$=D.filter(Z=>Z.type==="window").length;pe(!0),U("אימון מודל"),ut("שומר ומוסיף את התוכנית לדאטהסט האימון…");try{const Z=await Os();await pI(Z),Qt(!0);try{await ay(Z,{captureContext:"editor_train_button",reviewStatus:"approved"})}catch(St){Ys.error("Floorplan wall-sample export (best-effort) failed:",St)}const ot=D.length?`${T} דלתות ו-${$} חלונות`:"ללא פתחים ידניים (תיתרם רק לאימון הקירות — סמן דלתות/חלונות לאימון הפתחים)";ut(`נוסף לאימון ✓ ${R.length} קירות, ${ot}.`)}catch(Z){Ys.error("Floorplan training contribution failed:",Z),ut(`הוספה לאימון נכשלה: ${(Z==null?void 0:Z.message)??"לא ידוע"}`)}finally{pe(!1)}},[he,t,Ft.calibrated,R,tt,Os]);const yt=m.useCallback(()=>{if(!(wt!=null&&wt.success))return;const{walls:y,openings:D}=nnt(wt),T=[...(wt.walls??[]).map(Z=>Number(Z.confidence)),...(wt.openings??[]).map(Z=>Number(Z.confidence))].filter(Z=>Number.isFinite(Z)),$=T.length?T.reduce((Z,ot)=>Z+ot,0)/T.length:0;z(Qg(y,Io)),G(D),pt(null),U("Parser V2"),Nt(y.length),Be(Number.isFinite($)?$:0),ut(o("scanReview.applied",{walls:y.length,openings:D.length,defaultValue:`הוחלו ${y.length} קירות ו-${D.length} פתחים מסריקת Parser V2.`})),Ot("edit"),ve(null)},[wt,Io,o]),zt=m.useCallback(()=>{ve(null),U("Parser V2"),ut(o("scanReview.rejected",{defaultValue:"תוצאת Parser V2 נדחתה. אפשר להמשיך בשרטוט ידני."}))},[o]),Kt=m.useCallback(async()=>{if(!t){await SJ({imageUrl:C,filename:S,calibration:Ft,walls:R,openings:tt,furniture:Y,traceRoomLabels:Mt,createdAt:f,wallTypeSettings:Io,floorplanSketch:MD(Wt,Se)});return}Ue(!0);try{await Os(void 0,{navigateOnCreate:!0}),ut(o("messages.projectSaved",{defaultValue:"הפרויקט נשמר בהצלחה."})),U("Saved"),J0(t).then(y=>Rn(y)).catch(()=>{})}catch(y){(y==null?void 0:y.message)!=="FREE_PROJECT_LIMIT"&&alert(o("messages.saveFailed",{defaultValue:"שמירה נכשלה: {{message}}",message:y.message}))}finally{Ue(!1)}},[t,C,S,Ft,R,tt,Y,Mt,Wt,Se,f,Io,Os,o]),ke=m.useCallback(()=>{var T,$;if(fd())return;const y=((T=ea.current)==null?void 0:T.takeScreenshot({includeViewportNotes:!0}))||(($=ox.current)==null?void 0:$.takeScreenshot({includeViewportNotes:!0}));if(!y){alert(R.length===0&&Wt.length===0?o("messages.exportImageNoContent",{defaultValue:"אין תוכן לייצוא — ציירו קירות על התוכנית או סקיצה ב־3D תחילה."}):o("messages.exportImageUnavailable",{defaultValue:"לא ניתן לצלם את התצוגה כרגע."}));return}const D=document.createElement("a");D.href=y,D.download=`${(S||"floorplan").replace(/\.[^.]+$/,"")}_3D.png`,D.click()},[fd,S,R.length,Wt.length,o]),de=m.useCallback(async()=>
447{if(!t){const y=document.createElement("input");y.type="file",y.accept=".json,.floorplan.json",y.onchange=async()=>{var T;const D=(T=y.files)==null?void 0:T[0];if(D)try{const $=PJ(await D.text()),Z=JM($.wallTypeSettings);C&&URL.revokeObjectURL(C),Zf(),we(!1),sa(null),N($.imageDataUrl||""),B($.imageFilename),Vt($.calibration),z(Qg($.walls,Z)),G($.openings||[]),J($.furniture||[]),Rt(P7($.traceRoomLabels)),Jl(Z);const ot=Db($.floorplanSketch);qe(ot.entities),jn(ot.furnitureGroups),Kn(null),to(wo),Hr(!1),pt(null),p($.createdAt),Oa.current=!1,Ve(!1),Fe(!1),Le(!1),x("trace")}catch($){alert(o("messages.loadFailed",{message:$.message,defaultValue:`טעינה נכשלה: ${$.message}`}))}},y.click();return}Gs(!0);try{const y=await J0(t);Rn(y)}catch(y){alert(o("messages.projectListLoadFailed",{message:y.message,defaultValue:`טעינת רשימה נכשלה: ${y.message}`}))}finally{Gs(!1)}},[t,C,o]),ue=m.useCallback(async y=>{try{await pd(y),po("3d"),s&&s(`/floorplan-editor/${y.id}`)}catch(D){alert(o("messages.loadFailed",{message:D.message,defaultValue:`טעינה נכשלה: ${D.message}`}))}},[pd,s,o]),mn=m.useCallback(async y=>{if(!na("projectLimit")&&confirm(o("dialogs.deleteProject",{defaultValue:"למחוק את הפרויקט?"})))try{await qk(y),Rn(D=>D.filter(T=>T.id!==y)),g===y&&w(null)}catch(D){alert(o("messages.deleteFailed",{message:D.message,defaultValue:`מחיקה נכשלה: ${D.message}`}))}},[na,g,o]),Yn=m.useCallback(async()=>{if(!na("projectLimit")&&co.size!==0&&confirm(o("dialogs.deleteProjects",{count:co.size,defaultValue:`למחוק ${co.size} פרויקטים?`})))try{await Promise.all([...co].map(y=>qk(y))),Rn(y=>y.filter(D=>!co.has(D.id))),g&&co.has(g)&&w(null),ze(new Set),js(!1)}catch(y){alert(o("messages.deleteFailed",{message:y.message,defaultValue:`מחיקה נכשלה: ${y.message}`}))}},[na,co,g,o]),Xe=m.useCallback(async(y,D)=>{const T=D.trim();if(!T){uo(null);return}try{await gI(y,T),Rn($=>$.map(Z=>Z.id===y?{...Z,name:T}:Z)),g===y&&M(T)}catch($){alert(o("messages.renameFailed",{message:$.message,defaultValue:`שינוי שם נכשל: ${$.message}`}))}uo(null)},[g,o]),Sn=m.useCallback(()=>{C&&URL.revokeObjectURL(C),Zf(),x("upload"),N(""),B(""),M(""),z([]),ft([]),G([]),J([]),pt(null),Ml([]),Aa([]),yc([]),eu([]),el(null),qe([]),jn([]),Kn(null),to(wo),Jl(Uh()),Hr(!1),Vt({scale:1,calibrated:!1,planRotationDeg:0}),p(""),w(null),W(null),L(null),Lo.current.clear(),Dn([]),Co.current.clear(),ie([]),Ao(null),as(null),ut(null),gt(null),ve(null),U(null),Nt(0),Be(0),Le(!1),Fe(!1),Ve(!1),we(!1),sa(null),s&&s("/floorplan-editor")},[C,s]),mo=m.useCallback(()=>{nc()||(C&&URL.revokeObjectURL(C),A&&qM(A).catch(()=>{}),Zf(),N(""),L(null),B(""),M(o("project.newSketch",{defaultValue:"סקיצה חדשה"})),z([]),ft([]),G([]),J([]),Rt({}),Ml([]),Aa([]),eu([]),el(null),pt(null),qe([]),jn([]),Kn(null),to(wo),Jl(Uh()),Hr(!1),Vt({scale:1,calibrated:!1,planRotationDeg:0}),p(new Date().toISOString()),w(null),Lo.current.clear(),Dn([]),Co.current.clear(),ie([]),Ao(null),as(null),W(null),pa({}),nd({}),Qd({}),Ml([]),Aa([]),yc([]),mr({}),Jf(!1),$s(null),jc(null),ut(null),gt(null),ve(null),U(null),Nt(0),Be(0),Oa.current=!1,Fe(!1),Ve(!1),Le(!1),x("trace"),po("3d"),Ot("edit"),vr.current=!1,we(!0),sa(null),s&&s("/floorplan-editor"))},[C,A,s,nc,o]),vs=m.useCallback(y=>{z(D=>[...D,aE(y,Io)])},[Io]),yo=m.useCallback((y,D)=>{z(T=>{const $=T.findIndex(ot=>ot.id===y);if($===-1)return T;const Z=[...T];return Z.splice($,1,D[0],D[1]),Z}),G(T=>T.map($=>{if($.wallId!==y)return $;const Z=Math.sqrt((D[0].end.x-D[0].start.x)**2+(D[0].end.y-D[0].start.y)**2);return $.positionPx<=Z?{...$,wallId:D[0].id}:{...$,wallId:D[1].id,positionPx:$.positionPx-Z}}))},[]),Bi=m.useCallback(y=>{const D=Td(R,Ft);z(T=>T.map($=>$.id===y.id?y:$)),G(T=>T.filter($=>{if($.wallId!==y.id)return!0;const Z=Math.sqrt((y.end.x-y.start.x)**2+(y.end.y-y.start.y)**2),ot=$.positionPx*D,St=$.preset?qs[$.preset]:null,Bt=($.widthMm||(St==null?void 0:St.width)||Kc[$.type].width)/2;return ot-Bt>=0&&ot+Bt<=Z*D}))},[R,Ft]),bu=m.useCallback((y,D)=>{const T=$Z({walls:R,targetWallId:y,targetLengthMm:D,effectiveScale:Cn,openings:tt,wallFaceRegions:ai,wallElectricalFixtures:tu,wallNotes:Mc});return T.ok===!1?{ok:!1,messageHe:T.code==="attached-content"&&T.minimumLengthMm?o("wallSettings.attachedContentMinimum",{length:rd(T.minimumLengthMm),defaultValue:`לא ניתן לקצר את הקיר מתחת ל־${rd(T.minimumLengthMm)} בגלל פריט שממוקם עליו.`}):T.messageHe,minimumLengthMm:T.minimumLengthMm}:(z(T.walls),{ok:!0})},[Cn,rd,tt,o,tu,ai,Mc,R]),Xs=m.useCallback(y=>G(D=>[...D,y]),[]),wh=m.useCallback(y=>G(D=>D.map(T=>T.id===y.id?y:T)),[]),kh=m.useCallback(y=>{J(D=>[...D,y])},[]),fo=m.useCallback(y=>{kh(y),us("")},[kh]),vh=m.useCallback((y,D)=>J(T=>T.map($=>
447$.id===y?{...$,position:D}:$)),[]),jh=m.useCallback((y,D)=>J(T=>T.map($=>$.id===y?{...$,rotation:D}:$)),[]),hx=m.useCallback((y,D)=>J(T=>T.map($=>$.id===y?{...$,scale:D}:$)),[]),T0=m.useCallback(y=>{pt(y),(y==null?void 0:y.kind)==="beam"&&io("beams")},[io]),Km=m.useCallback(y=>{const{scale:D,referenceSegment:T}=y,$=bn,Z=Td(R,Ft),ot=Td(R,{...Ft,scale:D,calibrated:!0}),St=Z>0?ot/Z:1;if(St!==1&&Number.isFinite(St)){Wt.length>0&&(qe(se=>HW(se,St)),jn(se=>BW(se,St))),nd(se=>dq(se,St)),Qd(se=>uq(se,St)),$s(se=>hq(se,St));{const se=au.current;el(se&&{...se,x:se.x*St,z:se.z*St})}}Vt(se=>({...se,scale:D,calibrated:!0,referenceSegment:T})),G(se=>OZ(se,ot));const Bt=Number.isFinite(D)?D.toFixed(2):String(D),qt=rd(T.distanceMm);Dc(St!==1&&Number.isFinite(St)&&Wt.length>0?o("calibration.savedGeometryUpdated",{scale:Bt,reference:qt,defaultValue:`הכיול נשמר (${Bt} מ״מ/px, ${qt}) — הגאומטריה עודכנה. אמתו על הקו הצהוב.`}):o("calibration.savedVerify",{scale:Bt,reference:qt,defaultValue:`הכיול נשמר (${Bt} מ״מ/px, ${qt}) — אמתו על הקו הצהוב עם «סרט מדידה» מתוך כפתור ההגדרות ב-2D.`})),$&&(Ve(!1),Fe(!0),Ot("trace"))},[R,Ft,Wt,bn,rd,Dc,o]),Mu=m.useCallback(y=>{y&&Vt(D=>({...D,totalAreaSqm:y})),Ve(!1),Fe(!1),Oa.current=!0,x("trace"),Ot("trace"),Le(!0)},[]),mx=m.useCallback(async y=>{if(C){if(!Ft.calibrated){Ve(!0),Fe(!1),Oa.current=!0,x("trace"),po("2d"),Ot("calibrate");return}y&&Vt(D=>({...D,totalAreaSqm:y})),Ve(!1),Fe(!1),Oa.current=!0,await at()}},[C,Ft.calibrated,at]),vM=m.useCallback(async y=>{if(C){if(!Ft.calibrated){Ve(!0),Fe(!1),Oa.current=!0,x("trace"),po("2d"),Ot("calibrate");return}y&&Vt(D=>({...D,totalAreaSqm:y})),Ve(!1),Fe(!1),Oa.current=!0,await at("smp")}},[C,Ft.calibrated,at]);m.useEffect(()=>{h!=="trace"||!C||Ne||Ft.calibrated||Oa.current||(Oa.current=!0,po("2d"),Ot("calibrate"))},[h,C,Ne,Ft.calibrated]);const fx=m.useCallback(y=>{Vt(D=>({...D,planRotationDeg:y}))},[]),[Md,_h]=m.useState(null);m.useEffect(()=>{if(!C){_h(null);return}const y=new Image;y.onload=()=>_h({w:y.naturalWidth,h:y.naturalHeight}),y.onerror=()=>_h(null),y.src=C},[C]);const xx=m.useCallback(()=>{ct&&(ct.kind==="wall"?(z(y=>y.filter(D=>D.id!==ct.id)),G(y=>y.filter(D=>D.wallId!==ct.id)),Ml(y=>y.filter(D=>D.wallId!==ct.id)),Aa(y=>y.filter(D=>D.wallId!==ct.id))):ct.kind==="opening"?G(y=>{const D=y.find(T=>T.id===ct.id);return y.filter(T=>T.id!==ct.id&&(!(D!=null&&D.cornerGroupId)||T.cornerGroupId!==D.cornerGroupId))}):ct.kind==="furniture"?J(y=>y.filter(D=>D.id!==ct.id)):ct.kind==="beam"&&ft(y=>y.filter(D=>D.id!==ct.id)),pt(null))},[ct]),jM=m.useCallback(()=>{(ct==null?void 0:ct.kind)==="furniture"&&J(y=>y.map(D=>D.id===ct.id?{...D,rotation:(D.rotation+90)%360}:D))},[ct]),S0=m.useCallback(()=>{z(y=>{const D=y[y.length-1];return D&&(G(T=>T.filter($=>$.wallId!==D.id)),Ml(T=>T.filter($=>$.wallId!==D.id)),Aa(T=>T.filter($=>$.wallId!==D.id))),y.slice(0,-1)})},[]),P0=m.useCallback(()=>{z([]),ft([]),G([]),J([]),Rt({}),Ml([]),Aa([]),yc([]),eu([]),el(null),qe([]),jn([]),pt(null),Kn(null),to(wo)},[]),Nc=vn==="trace"?"trace":vn==="edit"?"edit":vn==="roof"?"roof":vn==="beam"?"beam":vn==="opening"?"opening":vn==="furniture"?"furniture":vn==="calibrate"?"calibrate":vn==="measure2d"?"measure2d":vn==="pan"?"pan":"trace",yu=m.useCallback(y=>{Ot(y),y==="trace"&&gl("exterior")},[]),_M=m.useCallback(()=>{Ht(!0),Zt(!0),po("2d"),go("floor"),ki(!1),ir(!1),Ot("beam"),pt(null),Cl(null),us(""),to(wo)},[]),EM=m.useCallback(y=>{ft(D=>[...D,y]),pt({kind:"beam",id:y.id}),Ot("edit"),io("beams")},[io]),Eh=m.useCallback(y=>{ft(D=>D.map(T=>T.id===y.id?y:T))},[]),A0=m.useCallback(()=>{if((ct==null?void 0:ct.kind)!=="beam")return;const y=X.find(T=>T.id===ct.id);if(!y)return;const D=RT(y,Cn);ft(T=>[...T,D]),pt({kind:"beam",id:D.id}),io("beams")},[X,Cn,io,ct]),[Zm,L0]=m.useState("sofa"),[ye,us]=m.useState(""),[Ha,DM]=m.useState(0),[Vi,qm]=m.useState("catalog"),[W0,px]=m.useState({}),[yd,Cl]=m.useState(null),[Jm,sa]=m.useState(null),[ck,A6]=m.useState(0);m.useEffect(()=>{vn!=="opening"&&yd!==null&&Cl(null)},[vn,yd]);const dk=m.useCallback(y=>{const D=y??wo;to(D),D!==wo&&(po("3d"),go("floor"),ho!=="floor"&&As(T=>T+1),Ot("edit"),Cl(null),us(""),sa(null),pt(null),D==="measure"&&Dc(o("measurement.threeDTapeHint",{defaultValue:"סרט מדידה 3D: למדידה מדויקת מומלץ מבט מלמעלה (כפתור «מבט על») — לא מחליפים אוטומטית. לאימות כיול השתמשו ב«סרט מדידה» מתוך כפתור ההגדרות בסרגל 2D."})))},[ho,Dc,o]);m.useEffect(()=>{!(Te==="3d"&&(vn==="opening"||vn==="furniture"||Jm||On!==wo||qi==="inside"||qi==="walkthrough"))||ho==="floor"||(go("floor"),ki(!1),ir(!1),As(D=>D+1))},[On,Jm,ho,Te,vn,qi]);const{models:R0}=ak(t,ck),{models:Qm}=K_();m.useEffect(()=>{if(Qm.length!==0){for(const y of Qm){const D=`sys_${y.id}`;pi[D]={width:y.width_mm,depth:y.depth_mm,height:y.height_mm,label:y.name_he}}px(y=>{const D={...y};for(const T of Qm){const $=`sys_${T.id}`;D[$]||(D[$]=Z_(T.storage_path))}return D})}},[Qm]),m.useEffect(()=>{if(R0.length!==0){for(const y of R0){const D=`user_${y.id}`;pi[D]={width:y.width_mm,depth:y.depth_mm,height:y.height_mm,label:y.name}}px(y=>{const D={...y};for(const T of R0){const $=`user_${T.id}`;D[$]||(D[$]=Of(T.storage_path))}return D})}},[R0]);const O0=m.useCallback((y,D,T,$)=>{px(Z=>({...Z,[y]:D})),pi[y]={width:T.w,depth:T.d,height:T.h,label:($==null?void 0:$.trim())||y.replace("user_","").slice(0,8)}},[]),gx=m.useCallback((y,D)=>{const T=D==null?void 0:D.trim();T&&pi[y]&&(pi[y]={...pi[y],label:T}),L0(y),us(y),pt($=>($==null?void 0:$.kind)==="furniture"?null:$),_t(null),Ot("furniture")},[]),H0=m.useCallback((y,D)=>{gx(y,D),DM(T=>T+1)},[gx]),L6=m.useCallback((y,D,T,$)=>{O0(y,D,T,$),H0(y,$)}
447,[O0,H0]),W6=m.useCallback((y,D,T,$)=>{O0(y,D,T,$),gx(y,$)},[O0,gx]);m.useEffect(()=>{if(Y.length===0)return;const y=new Set;for(const D of Y){const T=W0[D.type]||i3[D.type];T&&y.add(T)}for(const D of y)try{Rw.preload(db,D,mb)}catch{}},[Y,W0]);const bx=ZU(_.current),Dh=m.useMemo(()=>{const y={...bx.slotsByType};for(const D of Qm){const T=Array.isArray(D.material_slots)?D.material_slots:[];T.length>0&&(y[`sys_${D.id}`]=T)}return y},[Qm,bx.slotsByType]);m.useEffect(()=>{if(!xt)return;const y=Y.find(T=>T.id===xt.furnitureId);if(!y){_t(null);return}(Dh[y.type]??[]).some(T=>T.id===xt.slotId)||_t(null)},[Y,xt,Dh]);const uk=m.useCallback((y,D)=>{var $;if(ho!=="floor")return;const T=Y.find(Z=>Z.id===y);!T||!(($=Dh[T.type])!=null&&$.some(Z=>Z.id===D))||(pt({kind:"furniture",id:y}),_t({furnitureId:y,slotId:D}),io("furniture"))},[io,Y,ho,Dh]),R6=m.useCallback(y=>{const D=`user_${y.id}`,T=Of(y.storage_path);px($=>({...$,[D]:T})),pi[D]={width:y.width_mm,depth:y.depth_mm,height:y.height_mm,label:"רהיט"},L0(D),us(D),A6($=>$+1),qm("mine"),Ot("furniture")},[]),O6=(()=>{const y=["single_door","flush_door","single_door_glass","double_door","sliding_door","passage"],D=["corner_glass_door","garage_door"],T=["arched_door","arched_door_glass","wide_doorway"],$=["fixed_window","casement_window","awning_window","sliding_window","wide_window"],Z=["bay_window","arched_window","floor_to_ceiling","floor_to_ceiling_vertical"];return n.jsxs(n.Fragment,{children:[n.jsx($x,{title:o("openingCatalog.categories.doors",{defaultValue:"דלתות"}),children:y.map(ot=>n.jsx(Xx,{label:o(`opening.${ot}`,{defaultValue:qs[ot].label}),isActive:yd===ot,onClick:()=>{Cl(ot),Ot("opening")},icon:n.jsx(Yx,{preset:ot})},ot))}),n.jsx($x,{title:o("openingCatalog.categories.specialDoors",{defaultValue:"מיוחדות"}),children:D.map(ot=>n.jsx(Xx,{label:o(`opening.${ot}`,{defaultValue:qs[ot].label}),isActive:yd===ot,onClick:()=>{Cl(ot),Ot("opening")},icon:n.jsx(Yx,{preset:ot})},ot))}),n.jsx($x,{title:o("openingCatalog.categories.archedDoors",{defaultValue:"קשתיות"}),children:T.map(ot=>n.jsx(Xx,{label:o(`opening.${ot}`,{defaultValue:qs[ot].label}),isActive:yd===ot,onClick:()=>{Cl(ot),Ot("opening")},icon:n.jsx(Yx,{preset:ot})},ot))}),n.jsx($x,{title:o("openingCatalog.categories.windows",{defaultValue:"חלונות"}),children:$.map(ot=>n.jsx(Xx,{label:o(`opening.${ot}`,{defaultValue:qs[ot].label}),isActive:yd===ot,onClick:()=>{Cl(ot),Ot("opening")},icon:n.jsx(Yx,{preset:ot})},ot))}),n.jsx($x,{title:o("openingCatalog.categories.specialWindows",{defaultValue:"מיוחדים"}),children:Z.map(ot=>n.jsx(Xx,{label:o(`opening.${ot}`,{defaultValue:qs[ot].label}),isActive:yd===ot,onClick:()=>{Cl(ot),Ot("opening")},icon:n.jsx(Yx,{preset:ot})},ot))})]})})(),FM=n.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[n.jsxs("div",{className:O("furniture-catalog-tabs mb-3 flex shrink-0 gap-1 rounded-[3px] border p-0.5",an?"border-white/12 bg-[#0A0A0A]":"border-[#182137]/12 bg-white"),role:"tablist",children:[n.jsx("button",{type:"button",role:"tab","aria-selected":Vi==="catalog",onClick:()=>qm("catalog"),className:O("flex-1 rounded-[2px] py-2 text-[12px] font-black transition-colors",Vi==="catalog"?an?"bg-[#EC7357] text-white":"bg-[#D84B2E] text-white":an?"text-white/55 hover:bg-white/[0.06]":"text-[#182137]/55 hover:bg-[#E8DFD3]"),style:{letterSpacing:"-0.02em"},children:o("catalogUi.catalogTab",{defaultValue:"קטלוג"})}),n.jsx("button",{type:"button",role:"tab","aria-selected":Vi==="mine",onClick:()=>qm("mine"),className:O("flex-1 rounded-[2px] py-2 text-[12px] font-black transition-colors",Vi==="mine"?an?"bg-[#EC7357] text-white":"bg-[#D84B2E] text-white":an?"text-white/55 hover:bg-white/[0.06]":"text-[#182137]/55 hover:bg-[#E8DFD3]"),style:{letterSpacing:"-0.02em"},children:o("catalogUi.myFurnitureTab",{defaultValue:"הרהיטים שלי"})})]}),n.jsx("div",{className:"flex min-h-0 flex-1 overflow-hidden",children:Vi==="catalog"?n.jsx(aJ,{activeFurnitureType:ye,onSelect:H0,onBeginDrag:gx,measurementUnit:$e}):n.jsx(xJ,{userId:t,activeFurnitureType:ye,refreshToken:ck,onImageTo3DSuccess:R6,measurementUnit:$e,onSelect:L6,onBeginDrag:W6,personalAssetsLocked:!l,onPremiumRequired:Br})})]}),H6=null,CM=((vk=(kk=We==null?void 0:We.levels[0])==null?void 0:kk.rooms)==null?void 0:vk.length)??0,hk=CM?o("project.metaWithRooms",{walls:R.length,openings:tt.length,furniture:Y.length,rooms:CM,defaultValue:`${R.length} קירות · ${tt.length} פתחים · ${Y.length} ריהוט · ${CM} חדרים`}):o("project.metaWithoutRooms",{walls:R.length,openings:tt.length,furniture:Y.length,defaultValue:`${R.length} קירות · ${tt.length} פתחים · ${Y.length} ריהוט`}),mk=m.useCallback(()=>{var y,D;Te==="3d"?(y=ea.current)==null||y.zoomIn():(D=Sa.current)==null||D.zoomIn()},[Te]),fk=m.useCallback(()=>{var y,D;Te==="3d"?(y=ea.current)==null||y.zoomOut():(D=Sa.current)==null||D.zoomOut()},[Te]),B6=m.useCallback(y=>{var ot;const T={up:[0,-82],down:[0,82],left:[-82,0],right:[82,0]},[$,Z]=T[y];(ot=Sa.current)==null||ot.panBy($,Z)},[]),NM=m.useCallback(y=>{var D;if(y==="3d"){if(Wi){ln.info(o("levels.finishRoofTraceBeforeLeave",{defaultValue:"סיים או בטל את סימון ה×
447’×’ לפני המעבר"}));return}po("3d"),ki(!1),ir(!1),(D=ea.current)==null||D.setCameraPreset("orbit");return}if(Ws){ln.info(o("topBar.finishRecordingBefore2d",{defaultValue:"סיים את ההקלטה לפני המעבר ל־2D"}));return}po("2d"),go("floor"),ki(!1),ir(!1),As(T=>T+1)},[Wi,o,Ws]),V6=m.useCallback(y=>{var D;if(y==="building"&&Ws){ln.info(o("levels.finishRecordingBeforeBuilding",{defaultValue:"סיים את ההקלטה לפני המעבר לתצוגת כל הבניין"}));return}if(y==="building"&&Wi){ln.info(o("levels.finishRoofTraceBeforeLeave",{defaultValue:"סיים או בטל את סימון הגג לפני המעבר"}));return}go(y),ki(!1),ir(!1),As(T=>T+1),y==="building"&&(po("3d"),(D=ea.current)==null||D.setCameraPreset("orbit"))},[o,Ws,Wi]),z6=m.useCallback(y=>{var D;y!=="top"&&vl(!1),(y==="inside"||y==="walkthrough")&&(go("floor"),ki(!1),ir(!1),As(T=>T+1)),(D=ea.current)==null||D.setCameraPreset(y)},[]),$6=td??"",X6=void 0,Y6=m.useCallback(y=>{if(dr(y),y===null){Hn(!1),fs(Zr===null?"":qo(Zr));return}Uo||fs(qo(y))},[Uo,Zr]),wu=m.useCallback(y=>`${qo(y.lengthMm)}, ${qo(y.widthMm)}`,[qo]);m.useEffect(()=>{Vn!==null||Uo||fs(Zr===null?"":qo(Zr))},[Vn,Uo,$e,Zr]);const G6=m.useCallback(y=>{const D=Yh(y);fs(D);const T=ws(D);if(T===null)return;const $=Math.max(20,T);if(Vn===null&&os){qe(ot=>ot.map(St=>St.id!==os.id||St.kind!=="segment"?St:IL(St,$)));return}const Z=xs.current+1;xs.current=Z,oi({id:Z,lengthMm:$})},[Vn,os]),Mx=m.useCallback(y=>{const D=Yh(y);bt.current=D,Zo(D);const T=ws(D);if(T===null)return;const $=Math.max(1,T),Z=me.current+1;me.current=Z,Xt({id:Z,distanceMm:$})},[]),U6=m.useCallback(y=>{if(ma(y),Ct.current)return;if(y===null){bt.current="",Zo("");return}const D=qo(y);bt.current=D,Zo(D)},[]),K6=m.useCallback(y=>{Ct.current=!0,q(!0),Mx(y)},[Mx]),B0=m.useCallback(()=>{const y=ws(bt.current)??Rr;if(y===null||y<=0)return;const D=Math.max(1,y);Ct.current=!1,q(!1);const T=wn.current+1;wn.current=T,Ee({id:T,distanceMm:D})},[Rr]),wd=m.useCallback(y=>{const D=Yh(y);ae.current=D,Mi(D);const T=ws(D);if(T===null)return;const $=Math.max(1,T);if((It==null?void 0:It.phase)==="selected"){const ot=It.measureEntityId??pn;if(!ot)return;const St=Ti.current+1;Ti.current=St,pc({id:St,measureEntityId:ot,lengthMm:$});return}const Z=Us.current+1;Us.current=Z,Es({id:Z,lengthMm:$})},[It,pn]),V0=m.useCallback(y=>{const T=`${Ko.current?ae.current:""}${y}`.replace(/^0+(?=\d)/,"").slice(0,6);Ko.current=!0,si(!0),wd(T)},[wd]),Z6=m.useCallback(y=>{Ko.current=!0,si(!0),wd(y)},[wd]),IM=m.useCallback(()=>{var T;const y=ws(ae.current)??(It==null?void 0:It.lengthMm)??null;if(y===null||y<=0)return;const D=Math.max(1,y);if(Ko.current=!1,si(!1),(It==null?void 0:It.phase)==="start"){const $=Wo.current+1;Wo.current=$,ts({id:$,lengthMm:D});return}(It==null?void 0:It.phase)==="selected"&&(wd(ae.current),(T=Za.current)==null||T.blur())},[wd,It]),q6=m.useCallback(y=>{if(y.key==="Enter"){y.preventDefault(),IM();return}if(y.key==="Escape"){if(y.preventDefault(),Ko.current=!1,!It){ae.current="",Mi("");return}const D=De(It.lengthMm,$e);ae.current=D,Mi(D);return}if(y.key==="Backspace"){if(y.preventDefault(),!Ko.current){Ko.current=!0,si(!0),wd("");return}const D=ae.current.slice(0,-1);if(!D){Ko.current=!1,ae.current="",Mi("");return}wd(D);return}if(/^[0-9]$/.test(y.key)){y.preventDefault(),V0(y.key);return}if((y.key==="."||y.key===",")&&$e!=="mm"){if(y.preventDefault(),!Ko.current){V0("0.");return}ae.current.includes(".")||V0(".")}},[V0,wd,It,IM,$e]),J6=m.useCallback(()=>{ri(y=>y+1)},[]);m.useEffect(()=>{bt.current=gn},[gn]),m.useEffect(()=>{ae.current=ha},[ha]),m.useEffect(()=>{if(Ko.current)return;if(!It){ae.current="",Mi("");return}const y=De(It.lengthMm,$e);ae.current=y,Mi(y)},[It,$e]);const xk=m.useRef(null);m.useEffect(()=>{const y=(It==null?void 0:It.phase)??null;y==="start"&&xk.current!=="start"&&ri(D=>D+1),xk.current=y},[It==null?void 0:It.phase]),m.useEffect(()=>{if(!It)return;const y=Za.current;y&&(y.focus(),y.select())},[Mr]),m.useEffect(()=>{if(Ct.current)return;const y=Rr===null?"":qo(Rr);bt.current=y,Zo(y)},[Rr,$e]),m.useEffect(()=>{if(On!=="faceOffset"){Ct.current=!1,q(!1);return}const y=D=>{const T=D.target,$=T==null?void 0:T.tagName;if(T===lt.current){D.key==="Enter"&&(D.preventDefault(),D.stopPropagation(),B0());return}if($==="TEXTAREA"||$==="SELECT"||$==="INPUT")return;if(D.key==="Enter"){D.preventDefault(),D.stopPropagation(),B0();return}if(D.key==="Backspace"){D.preventDefault(),D.stopPropagation();const St=Ct.current;Ct.current=!0,q(!0);const Bt=St?bt.current:"";Mx(Bt.slice(0,-1));return}
447if(D.key.length!==1||!/[\d.]/.test(D.key))return;D.preventDefault(),D.stopPropagation();const Z=Ct.current;Ct.current=!0,q(!0);const ot=Z?bt.current:"";Mx(ot+D.key)};return window.addEventListener("keydown",y,!0),()=>window.removeEventListener("keydown",y,!0)},[On,Mx,B0]);const yx=m.useCallback(y=>{const D=Yh(y);Oo.current=D,or(D);const T=ws(D);if(T===null)return;const $=Math.max(1,T),Z=Ls.current+1;Ls.current=Z,sr({id:Z,distanceMm:$})},[]),Q6=m.useCallback(y=>{if(cn(y),qn.current)return;if(y===null){Oo.current="",or("");return}const D=qo(y);Oo.current=D,or(D)},[]),tC=m.useCallback(y=>{qn.current=!0,yx(y)},[yx]),z0=m.useCallback(()=>{const y=ws(Oo.current)??He;if(y===null||y<=0)return;const D=Math.max(1,y);qn.current=!1;const T=Ia.current+1;Ia.current=T,ii({id:T,distanceMm:D})},[He]);m.useEffect(()=>{Oo.current=nn},[nn]),m.useEffect(()=>{if(qn.current)return;const y=He===null?"":qo(He);Oo.current=y,or(y)},[He,$e]),m.useEffect(()=>{if(On!=="offset"){qn.current=!1;return}const y=D=>{const T=D.target,$=T==null?void 0:T.tagName;if(T===Or.current){D.key==="Enter"&&(D.preventDefault(),D.stopPropagation(),z0());return}if($==="TEXTAREA"||$==="SELECT"||$==="INPUT")return;if(D.key==="Enter"){D.preventDefault(),D.stopPropagation(),z0();return}if(D.key==="Backspace"){D.preventDefault(),D.stopPropagation();const St=qn.current;qn.current=!0;const Bt=St?Oo.current:"";yx(Bt.slice(0,-1));return}if(D.key.length!==1||!/[\d.]/.test(D.key))return;D.preventDefault(),D.stopPropagation();const Z=qn.current;qn.current=!0;const ot=Z?Oo.current:"";yx(ot+D.key)};return window.addEventListener("keydown",y,!0),()=>window.removeEventListener("keydown",y,!0)},[On,yx,z0]);const eC=m.useCallback(y=>{if(yi(y),y===null){bs(null),Fs.current=!1;const D=ss?wu(ss):"";Pi.current=D,ps(D),zs(ss?qo(ss.lengthMm):""),Ca(ss?qo(ss.widthMm):""),gs(Dr===null?"":qo(Dr));return}if(!Fs.current){const D=wu(y);Pi.current=D,ps(D)}bo!=="length"&&zs(qo(y.lengthMm)),bo!=="width"&&Ca(qo(y.widthMm))},[wu,bo,Dr,ss]);m.useEffect(()=>{if(!(eo!==null||bo)){if(zs(ss?qo(ss.lengthMm):""),Ca(ss?qo(ss.widthMm):""),!Fs.current){const y=ss?wu(ss):"";Pi.current=y,ps(y)}pl===null&&gs(Dr===null?"":qo(Dr))}},[eo,bo,pl,wu,$e,Dr,ss]);const nC=m.useCallback(y=>{Zi(y),bo!=="height"&&gs(y===null?Dr===null?"":qo(Dr):qo(y))},[bo,Dr]),Ba=m.useCallback((y,D)=>{let T=y,$=!1;if(y){const Z=Wt.find(St=>St.id===y),ot=Z==null?void 0:Z.groupId;if(ot){const St=Se.find(Bt=>Bt.id===ot);if(St!=null&&St.rigid){const Bt=St.entityIds.find(qt=>{var se;return((se=Wt.find(Pn=>Pn.id===qt))==null?void 0:se.kind)==="polygon"});Bt&&Bt!==y&&(T=Bt,$=!0)}}}Qe.current=!!(D!=null&&D.suppressDetailsPanelAutoOpen&&T!==null&&T!==pn),Kn(T),Qo(null),(T===null||$)&&(ro(null),Yo(null))},[pn,Wt,Se]),Fh=m.useCallback((y,D)=>{const T=Xr(y.vertices);if(!T)return;const $=Math.max(20,Math.round(D.lengthMm??T.lengthMm)),Z=Math.max(20,Math.round(D.widthMm??T.widthMm)),ot=D.heightMm===void 0?void 0:Math.max(0,Math.round(D.heightMm)),St=D.baseHeightMm===void 0?void 0:Math.max(0,Math.round(D.baseHeightMm));qe(qt=>{var zr;const se=qt.find(ju=>ju.id===y.id&&ju.kind==="polygon"&&ju.sourceTool==="rectangle");if(!se)return qt;const Pn=Xr(se.vertices);if(!Pn)return qt;const Is=Math.max(20,Math.round(D.lengthMm??Pn.lengthMm)),mi=Math.max(20,Math.round(D.widthMm??Pn.widthMm)),ra=((zr=se.rectangleWallAnchor)==null?void 0:zr.anchorEdgeIndex)??null,of={...D.lengthMm!==void 0||D.widthMm!==void 0?ra===null?hD(se,Is,mi):SL(se,Is,mi,ra):se,...ot!==void 0?{heightMm:ot}:{},...St!==void 0?{baseHeightMm:St}:{}},lr=Xu(qt,se,of);if(!se.groupId||ra!==null||qt.filter(ju=>ju.kind==="polygon"&&ju.groupId===se.groupId).length>=2)return lr;const Sh=Is/Math.max(1,Pn.lengthMm),OM=mi/Math.max(1,Pn.widthMm),Tr=se.heightMm??0,Il=ot!==void 0&&Tr>0?ot/Tr:1;return VW(lr,se,Pn.center,Pn.uAxis,Pn.vAxis,Sh,OM,Il)});const Bt=y.groupId?Wt.filter(qt=>qt.kind==="polygon"&&qt.groupId===y.groupId).length<2:!1;y.groupId&&Bt&&jn(qt=>qt.map(se=>se.id===y.groupId?{...se,widthMm:$,depthMm:Z,...ot!==void 0?{heightMm:ot}:{}}:se))},[Wt]),TM=m.useCallback((y,D)=>{var Bt;const T=Zg(Wt,y);if(!T)return;
447const $=!!((Bt=Se.find(qt=>qt.id===y))!=null&&Bt.wallId),Z=D.widthMm===void 0?T.widthMm:Math.max(Math.min(c_,T.widthMm),Math.round(D.widthMm)),ot=D.depthMm===void 0?T.depthMm:Math.max(Math.min(d_,T.depthMm),Math.round(D.depthMm)),St=D.heightMm===void 0?T.heightMm:Math.max(Math.min(u_,T.heightMm),Math.round(D.heightMm));qe(qt=>{const se=Zg(qt,y);return se?qQ(qt,y,se,Z/Math.max(1,se.widthMm),ot/Math.max(1,se.depthMm),St/Math.max(1,se.heightMm),{anchorBackFace:$}):qt}),jn(qt=>qt.map(se=>se.id===y?{...se,widthMm:Z,depthMm:ot,heightMm:St}:se))},[Wt,Se]),wx=m.useCallback(y=>{var T;if(!(y!=null&&y.wallId))return null;const D=R.find($=>$.id===y.wallId);return D?rR({startMm:{x:D.start.x*Cn,y:D.start.y*Cn},endMm:{x:D.end.x*Cn,y:D.end.y*Cn},thicknessMm:D.thicknessMm??((T=Io[D.wallType??"exterior"])==null?void 0:T.thicknessMm)??100,side:y.wallSide}):null},[R,Cn,Io]),oC=m.useCallback((y,D)=>{if(!Number.isFinite(D.x)||!Number.isFinite(D.y)||D.x===0&&D.y===0)return;const T=Wt,$=tm(T,[y],D);if($===T)return;const Z=T.find(se=>se.id===y),ot=Z==null?void 0:Z.groupId,St=ot?Se.find(se=>se.id===ot)??null:null;if(!ot||!St){qe($);return}const Bt=wx(St),qt=o1({group:St,prevEntities:T,nextEntities:$,frame:Bt});qe(qt.kind==="detach"?r1($,ot):$),qt.kind!=="keep"&&jn(se=>s1(se,ot,qt))},[Wt,Se,wx]),SM=m.useCallback((y,D,T)=>{if(!Number.isFinite(D)||!Number.isFinite(T)||D===0&&T===0)return;const $=Zg(Wt,y);if(!$)return;const Z=Wt.filter(Pn=>Pn.groupId===y).map(Pn=>Pn.id);if(Z.length===0)return;const ot=Se.find(Pn=>Pn.id===y)??null,St=wx(ot),Bt=lR($,St,D,T);if(Bt.x===0&&Bt.y===0)return;const qt=tm(Wt,Z,Bt);if(qt===Wt)return;const se=ot?o1({group:ot,prevEntities:Wt,nextEntities:qt,frame:St}):{kind:"keep"};qe(se.kind==="detach"?r1(qt,y):qt),se.kind!=="keep"&&jn(Pn=>s1(Pn,y,se))},[Wt,Se,wx]);m.useEffect(()=>{const y=D=>{if(!pn||D.metaKey||D.ctrlKey||D.altKey||xa.current==="walkthrough")return;const T=D.target;if(T&&(T.tagName==="INPUT"||T.tagName==="TEXTAREA"||T.isContentEditable))return;const $=je*(D.shiftKey?5:1);let Z=0,ot=0;if(D.key==="ArrowRight")Z=$;else if(D.key==="ArrowLeft")Z=-$;else if(D.key==="ArrowUp")ot=-$;else if(D.key==="ArrowDown")ot=$;else return;const St=Wt.find(qt=>qt.id===pn),Bt=St==null?void 0:St.groupId;Bt&&(D.preventDefault(),SM(Bt,Z,ot))};return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[pn,Wt,je,SM]);const Ch=m.useCallback((y,D,T)=>{const $=Yh(D);if(y==="length"?zs($):y==="height"?gs($):Ca($),(T==null?void 0:T.commit)===!1)return;const Z=ws($);if(Z===null||y!=="height"&&Z<20)return;if(y==="height"){if(ms){const se=b3(Wt,ms);if(!se)return;Zi(Z),qe(Yy(se.entities,se.patch.id,Z)),Kn(se.patch.id),ro("top"),Yo(null);return}if(!Er)return;const qt=un?Z:Math.max(0,Z);Zi(qt),qe(se=>Yy(se,Er,qt));return}const ot=eo??Ke;if(!ot)return;const St={lengthMm:y==="length"?Math.max(20,Z):ot.lengthMm,widthMm:y==="width"?Math.max(20,Z):ot.widthMm};if(eo===null&&Fn){Fh(Fn,St);return}const Bt=Si.current+1;Si.current=Bt,xl({id:Bt,...St})},[eo,Wt,un,ms,Fn,Ke,Er,Fh]),$0=m.useCallback(y=>{const D=mnt(y);Pi.current=D,ps(D)},[]),Nh=m.useCallback(()=>{const y=fnt(Pi.current);if(!y)return;const D=ws(y[0]),T=ws(y[1]);if(D===null||T===null||D<20||T<20)return;const $={lengthMm:Math.max(20,D),widthMm:Math.max(20,T)};if(eo===null&&Fn){Wr.current=!1,Fh(Fn,$);return}if(!(eo??Ke)){Wr.current=!0;return}Wr.current=!1;const ot=Si.current+1;Si.current=ot,xl({id:ot,...$})},[Fh,eo,ws,Fn,Ke]);m.useEffect(()=>{Wr.current&&(eo!==null||!Ke||Nh())},[Nh,eo,Ke]);const PM=m.useCallback((y,D,T)=>{const $=Mo.find(Z=>Z.index===y);$&&Ch($.dimension,D,T)},[Ch,Mo]),AM=Vn??Zr,tf=On==="line"||!!os,kx=!tf&&(On==="faceLine"||On==="faceCornerArc")&&vo!==null,X0=!tf&&!kx&&It!==null&&(On==="faceMeasure"||It.phase==="selected"),pk=Vn!==null,sC=AM!==null,Ih=eo??Ke??_r??hr??_n,Y0=jo&&eo===null&&!un&&!ms,LM=!tf&&!kx&&!X0&&On!=="faceOffset"&&On!=="offset"&&(On==="rectangle"||On==="pushPull"||!!Fn||Y0||!!un||!!ms),rC=!tf&&!kx&&!X0&&On==="faceOffset",iC=!tf&&!kx&&!X0&&On==="offset"&&!!qr,WM=!!eo||!!Ke,Th=pl??Dr,aC=(!!Er||!!ms)&&(On==="pushPull"||pl!==null||(Th??0)>0),gk=m.useCallback((y,D)=>{bs(null);const T=D===void 0?null:ws(Yh(D)),$=T===null?null:y==="height"?T:Math.max(20,T);if(y==="length"){zs($!==null?qo($):Ih?qo(Ih.lengthMm):"");return}if(y==="width"){Ca($!==null?qo($):Ih?qo(Ih.widthMm):"");return}gs($!==null?qo($):Th===null?"":qo(Th))},[Ih,Th]),Ic=m.useCallback(y=>y==="height"||!Ai?y:Ai[y],[Ai]),bk=m.useCallback(y=>{const D=y==="length"?nr:es;if(bo===y)return D;const T=eo??Ke,$=y==="length"?T==null?void 0:T.lengthMm:T==null?void 0:T.widthMm;return $===void 0?D:De($,$e)},[eo,bo,nr,es,$e,Ke]),lC=m.useCallback(()=>
447{if(bo==="height")return Ro;const y=pl??Dr;return y===null?"":De(y,$e)},[pl,bo,Ro,$e,Dr]),cC=m.useCallback((y,D)=>{Ch(Ic(y),D,{commit:!1})},[Ch,Ic]),dC=m.useCallback((y,D)=>{Ch(Ic(y),D)},[Ch,Ic]),uC=m.useCallback(y=>{bs(Ic(y))},[Ic]),hC=m.useCallback((y,D)=>{gk(Ic(y),D)},[gk,Ic]),mC=m.useCallback((y,D)=>{PM(y,D,{commit:!1})},[PM]);m.useEffect(()=>{if(!LM||!WM||Y0){Fs.current=!1;return}const y=D=>{var St;if(D.metaKey||D.ctrlKey||D.altKey)return;const T=D.target,$=T==null?void 0:T.tagName;if(T===Na.current){D.key==="Enter"&&(D.preventDefault(),D.stopPropagation(),Nh(),Fs.current=!1,(St=Na.current)==null||St.blur());return}if($==="TEXTAREA"||$==="SELECT"||$==="INPUT")return;if(D.key==="Enter"){if(!Fs.current)return;D.preventDefault(),D.stopPropagation(),Nh(),Fs.current=!1;return}if(D.key==="Escape"){if(!Fs.current)return;D.preventDefault(),D.stopPropagation(),Fs.current=!1;const Bt=eo??Ke,qt=Bt?wu(Bt):"";Pi.current=qt,ps(qt);return}if(D.key==="Backspace"){D.preventDefault(),D.stopPropagation();const Bt=Fs.current;Fs.current=!0;const qt=Bt?Pi.current:"";$0(qt.slice(0,-1));return}if(D.key.length!==1||!/[\d.,xX×*;\s]/.test(D.key))return;D.preventDefault(),D.stopPropagation();const Z=Fs.current;Fs.current=!0;const ot=Z?Pi.current:"";$0(ot+D.key)};return window.addEventListener("keydown",y,!0),()=>window.removeEventListener("keydown",y,!0)},[Nh,eo,LM,WM,Y0,wu,Ke,$0]);const ef=O("flex h-8 items-center gap-2 rounded-[4px] border px-2.5 font-heebo",an?"border-white/10 bg-white/[0.06] text-white":"border-[#182137]/10 bg-white/75 text-[#182137]"),kd=O("text-[11px] font-bold",an?"text-white/65":"text-[#182137]/65"),ku=O("text-[10px] font-bold",an?"text-white/40":"text-[#182137]/40"),vu=O("h-6 w-20 rounded-[3px] border px-2 text-center text-[12px] font-bold tabular-nums outline-none",an?"border-white/15 bg-[#0A0A0A] text-white focus:border-white/35":"border-[#182137]/12 bg-white text-[#182137] focus:border-[#182137]/40"),fC=(()=>{const y=vo==null?void 0:vo.labelHebrew;if(!y)return"";const T={"סימון מדידה":"sketchFooter.snap.measurementMark","נקודת קצה":"sketchFooter.snap.endpoint",אמצע:"sketchFooter.snap.midpoint","על קצה":"sketchFooter.snap.onEdge","נעול ציר":"sketchFooter.snap.axisLocked","על פאה":"sketchFooter.snap.onFace","נעול ציר אופקי":"sketchFooter.snap.horizontalAxisLocked","נעול ציר אנכי":"sketchFooter.snap.verticalAxisLocked"}[y];return T?o(T,{defaultValue:y}):y})(),Mk=tf?n.jsxs("div",{dir:r.dir(),className:ef,children:[n.jsx("span",{className:kd,children:o("sketchFooter.lineLength",{defaultValue:"אורך קו"})}),n.jsx("input",{value:Ii,onChange:y=>G6(y.target.value),onFocus:y=>{Hn(!0),y.currentTarget.select()},onBlur:()=>{Hn(!1),fs(AM===null?"":qo(AM))},onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),pk?rn(D=>D+1):y.currentTarget.blur())},className:vu,disabled:!sC,placeholder:"0",inputMode:"decimal"}),n.jsx("span",{className:ku,children:Ir}),n.jsx("button",{type:"button",onClick:()=>rn(y=>y+1),disabled:!pk,className:"h-6 rounded-[3px] bg-[#182137] px-2.5 text-[10px] font-bold text-[#F7F4EF] transition-colors hover:bg-[#26304a] disabled:cursor-not-allowed disabled:opacity-45",children:o("sketchFooter.confirm",{defaultValue:"אישור"})})]}):kx?n.jsxs("div",{dir:r.dir(),className:ef,children:[vo!=null&&vo.labelHebrew?n.jsx("span",{className:O(kd,"text-[#336CFF]"),children:fC}):null,n.jsx("span",{className:kd,children:o("dimensions.height",{defaultValue:"גובה"})}),n.jsx("input",{value:De((vo==null?void 0:vo.heightFromCornerMm)??0,$e),readOnly:!0,className:O(vu,(vo==null?void 0:vo.activeAxis)==="height"&&"ring-1 ring-[#336CFF]/45"),inputMode:"decimal"}),n.jsx("span",{className:ku,children:Ir}),n.jsx("span",{className:kd,children:o("dimensions.width",{defaultValue:"רוחב"})}),n.jsx("input",{value:De((vo==null?void 0:vo.widthFromCornerMm)??0,$e),readOnly:!0,className:O(vu,(vo==null?void 0:vo.activeAxis)==="width"&&"ring-1 ring-[#336CFF]/45"),inputMode:"decimal"}),n.jsx("span",{className:ku,children:Ir})]}):X0?n.jsxs("div",{dir:r.dir(),className:ef,children:[n.jsx("span",{className:kd,children:o("sketchFooter.length",{defaultValue:"אורך"})}),n.jsx("input",{ref:Za,value:ha,onChange:y=>Z6(y.target.value),onFocus:y=>{si(!0),y.currentTarget.select()},onBlur:()=>{if(si(!1),Ko.current=!1,!It){ae.current="",Mi("");return}const y=De(It.lengthMm,$e);ae.current=y,Mi(y)},onKeyDown:q6,className:O(vu,Fa&&"ring-1 ring-[#336CFF]/45"),inputMode:"decimal","aria-label":o("accessibility.measurementLength",{unit:Ir,defaultValue:`אורך מדידה ב${Ir}`})}),n.jsx("span",{className:ku,children:Ir}),(It==null?void 0:It.phase)==="start"?n.jsx("button",{type:"button",onClick:IM,className:"h-6 rounded-[3px] bg-[#182137] px-2.5 text-[10px] font-bold text-[#F7F4EF] transition-colors hover:bg-[#26304a]",children:o("sketchFooter.confirm",{defaultValue:"אישור"})}):null]}):rC?n.jsxs("div",{dir:r.dir(),className:ef,children:[n.jsx("span",{className:kd,children:o("sketchFooter.offsetDistance",{defaultValue:"מרחק אוף סט"})}),n.jsx("input",{ref:lt,value:gn,onChange:y=>K6(y.target.value),onFocus:y=>{q(!0),y.currentTarget.select()},onBlur:()=>{if(q(!1),On!=="faceOffset"&&!Ct.current){const y=Rr!==null?qo(Rr):"";bt.current=y,Zo(y)}},onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),y.stopPropagation(),B0())},className:vu,placeholder:"0",inputMode:"decimal","aria-label":o("accessibility.offsetDistance",{unit:Ir,defaultValue:`מרחק אוף סט ב${Ir}`})}),n.jsx("span",{className:ku,children:Ir})]}):iC?n.jsxs("div",{dir:r.dir(),className:ef,children:[n.jsx("span",{className:kd,children:o("sketchFooter.offsetDistance",{defaultValue:"מרחק אוף סט"})}),n.jsx("input",{ref:Or,value:nn,onChange:y=>tC(y.target.value),onFocus:y=>{qn.current=!0,y.currentTarget.select()},onBlur:()=>{if(On!=="offset"&&!qn.current){const y=He!==null?qo(He):"";Oo.current=y,or(y)}},onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),y.stopPropagation(),z0())},className:vu,placeholder:"0",inputMode:"decimal","aria-label":o("accessibility.canvasOffsetDistance",{unit:Ir,defaultValue:`מרחק אוף סט (קנבס) ב${Ir}`})}),n.jsx("span",{className:ku,children:Ir})]}):LM?n.jsxs("div",{dir:r.dir(),className:ef,children:[n.jsx("span",{className:kd,children:o("sketchFooter.dimensions",{defaultValue:"מידות"})}),n.jsx("input",{ref:Na,value:eh,onChange:y=>{Fs.current=!0,$0(y.target.value)},onFocus:y=>{Fs.current=!0,y.currentTarget.select()},onBlur:()=>{Nh(),Fs.current=!1;const y=Ih?wu(Ih):"";Pi.current=y,ps(y)},onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),Nh(),y.currentTarget.blur()),y.key==="Escape"&&(y.preventDefault(),y.currentTarget.blur())},className:O(vu,"w-32"),disabled:!WM||Y0,placeholder:"40, 60",inputMode:"text","aria-label":o("accessibility.rectangleDimensions",{unit:Ir,defaultValue:`מידות מלבן ב${Ir}`})}),n.jsx("span",{className:ku,children:Ir}),aC&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:kd,children:un?o("sketchFooter.depthWithColon",{defaultValue:"עומק:"}):o("sketchFooter.heightWithColon",{defaultValue:"גובה:"})}),n.jsx("input",{value:Ro,onChange:y=>Ch("height",y.target.value),onFocus:y=>{bs("height"),y.currentTarget.select()},onBlur:()=>{bs(null),gs(Th===null?"":qo(Th))},onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),y.currentTarget.blur())},className:vu,disabled:Th===null,placeholder:"0",inputMode:"decimal"}),n.jsx("span",{className:ku,children:Ir})]})]}):null,xC=!!Md&&(Te==="2d"||Te==="3d"&&qi==="top")&&Md?(()=>{const y=Md.w,D=Md.h,T=Jv(y,D,"landscape"),$=Jv(y,D,"portrait"),Z=Ft.planRotationDeg??0,ot=St=>`px-2.5 h-9 rounded-lg text-[11px] font-semibold transition-all duration-100 border cursor-pointer shrink-0 ${St?"bg-gradient-to-b from-[#EC7357] to-[#D84B2E] text-white border-[#
447EC7357]/50 shadow-sm":"bg-white text-gray-600 border-gray-200/90 hover:bg-gray-50 hover:border-gray-300 dark:bg-white/10 dark:text-white/80 dark:border-white/15"}`;return n.jsxs(n.Fragment,{children:[n.jsxs("div",{dir:r.dir(),className:"flex items-center gap-1 shrink-0",children:[n.jsx("button",{type:"button",title:o("trace.landscapeOrientation",{defaultValue:"הצגת התוכנית באופק"}),className:ot(Z===T),onClick:()=>fx(T),children:o("trace.landscape",{defaultValue:"אופקי"})}),n.jsx("button",{type:"button",title:o("trace.portraitOrientation",{defaultValue:"הצגת התוכנית לאורך (ורטיקלי)"}),className:ot(Z===$),onClick:()=>fx($),children:o("trace.portrait",{defaultValue:"ורטיקלי"})})]}),n.jsx("div",{className:"w-px h-5 bg-gray-200 shrink-0","aria-hidden":!0})]})})():null,yk=(y="panel")=>{const D=y==="compact";return n.jsxs("div",{dir:r.dir(),className:"text-start",children:[n.jsxs("div",{className:O("flex items-center justify-between gap-3",D?"mb-2":"mb-3"),children:[n.jsxs("div",{className:"min-w-0",children:[n.jsx("div",{className:O("font-black tracking-[-0.02em]",D?"text-[12px]":"text-[13px]"),children:D?o("wallSettings.compactTitle",{defaultValue:"עובי וגובה קירות"}):o("wallSettings.title",{defaultValue:"הגדרות קירות"})}),n.jsx("div",{className:O("font-medium",D?"text-[9px] text-[#9a3d28]/70":"text-[10px]",an&&!D?"text-white/45":D?"":"text-[#182137]/45"),children:D?o("wallSettings.byType",{defaultValue:"לפי סוג קיר"}):o("wallSettings.description",{defaultValue:"עובי/עומק וגובה לפי סוג קיר"})})]}),n.jsxs("button",{type:"button",onClick:o0,className:O("flex shrink-0 items-center gap-1.5 rounded-lg text-[10px] font-bold transition-colors",D?"h-7 border border-[#EC7357]/25 bg-[#EC7357]/10 px-2 text-[#9a3d28] hover:bg-[#EC7357]/20":"h-8 px-2.5",!D&&(an?"bg-white/[0.06] text-white/70 hover:bg-white/10 hover:text-white":"bg-[#182137]/5 text-[#182137]/65 hover:bg-[#182137]/[0.08] hover:text-[#182137]")),title:o("common.resetToDefault",{defaultValue:"איפוס לברירת מחדל"}),children:[n.jsx(zu,{size:D?12:13}),o("common.reset",{defaultValue:"איפוס"})]})]}),n.jsx("div",{className:D?"grid grid-cols-2 gap-2":"space-y-2.5",children:$w.map(T=>{const $=Io[T],Z=iE[T],ot=o(`wallTypeDisplay.${T}`,{defaultValue:d5[T]});return n.jsxs("div",{className:O(D?"rounded-xl border border-[#E2D4CA] bg-[#FFFDFC] p-2 shadow-[0_4px_12px_rgba(24,33,55,0.06),inset_0_1px_0_rgba(255,255,255,0.9)]":"rounded-xl border p-3",!D&&(an?"border-white/10 bg-white/[0.04]":"border-[#182137]/8 bg-[#F7F4EF]/55")),children:[n.jsxs("div",{className:O("flex items-center justify-between gap-2",D?"mb-1.5":"mb-2.5"),children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[n.jsx("span",{className:O("rounded-full ring-2",D?"h-2 w-2 ring-[#F7F4EF]":"h-2.5 w-2.5 ring-white/70"),style:{backgroundColor:Z.color}}),n.jsx("span",{className:O("truncate font-black",D?"text-[10.5px] text-[#182137]":"text-[12px]"),children:ot})]}),n.jsx("span",{className:O("shrink-0 font-semibold",D?"text-[8.5px] text-[#182137]/40":"text-[10px]",an&&!D?"text-white/40":D?"":"text-[#182137]/40"),children:T==="free"?o("wallSettings.nextWall",{defaultValue:"לקיר הבא"}):o(`wallType.${T}`,{defaultValue:Z.label})})]}),n.jsx("div",{className:O("grid grid-cols-2",D?"gap-1.5":"gap-2.5"),children:[{key:"thicknessMm",label:T==="free"?o("dimensions.depth",{defaultValue:"עומק"}):o("wallSettings.thickness",{defaultValue:"עובי"}),min:lc.thicknessMm.min,max:lc.thicknessMm.max,step:10},{key:"heightMm",label:o("dimensions.height",{defaultValue:"גובה"}),min:lc.heightMm.min,max:lc.heightMm.max,step:10}].map(St=>{var Bt;return n.jsxs("label",{className:"block",children:[n.jsx("span",{className:O("mb-1 block font-bold",D?"text-[8.5px] text-[#182137]/55":"text-[10px]",an&&!D?"text-white/55":D?"":"text-[#182137]/55"),children:St.label}),n.jsxs("div",{className:O("flex items-center overflow-hidden rounded-lg border",D?"h-7 border-[#182137]/10 bg-white/95 shadow-[inset_0_1px_2px_rgba(24,33,55,0.04)] focu
447s-within:border-[#D84B2E]/45 focus-within:ring-2 focus-within:ring-[#EC7357]/12":"h-9",!D&&(an?"border-white/[0.12] bg-[#0A0A0A]":"border-[#182137]/10 bg-white")),children:[n.jsx("input",{type:"text",inputMode:"decimal",min:St.min,max:St.max,step:St.step,value:((Bt=nh[T])==null?void 0:Bt[St.key])??De($[St.key],$e),onChange:qt=>ah(T,St.key,qt.currentTarget.value),onBlur:()=>n0(T,St.key),onKeyDown:qt=>{qt.key==="Enter"&&(qt.preventDefault(),qt.currentTarget.blur()),qt.key==="Escape"&&(qt.preventDefault(),ah(T,St.key,De($[St.key],$e)))},className:O("h-full min-w-0 flex-1 bg-transparent text-center font-bold outline-none [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none",D?"px-1 text-[10.5px] text-[#182137]":"px-2 text-[12px]",an&&!D?"text-white":D?"":"text-[#182137]")}),n.jsx("span",{className:O("font-bold",D?"px-1 text-[8.5px] text-[#182137]/35":"px-2 text-[10px]",an&&!D?"text-white/35":D?"":"text-[#182137]/35"),children:Ir})]})]},St.key)})})]},T)})})]})},pC=ql||(vn==="calibrate"||vn==="measure2d"||vn==="trace"&&(Li==="mamad"||Li==="free")),G0=y=>O("flex h-9 min-w-0 items-center justify-center gap-1.5 rounded-xl border px-2 text-[11px] font-black transition-all",y?"border-[#D84B2E]/45 bg-[#D84B2E] text-white shadow-[0_7px_14px_rgba(216,93,67,0.2),inset_0_1px_0_rgba(255,255,255,0.25)]":"border-[#182137]/10 bg-[#FFFDFC] text-[#182137]/78 shadow-[0_3px_10px_rgba(24,33,55,0.06),inset_0_1px_0_rgba(255,255,255,0.9)] hover:border-[#D84B2E]/25 hover:bg-[#FFF7F3] hover:text-[#182137]"),gC=Te==="2d"?n.jsxs("div",{dir:r.dir(),className:"fp-preset-bar fp-preset-bar--2d fp-preset-bar--header",children:[n.jsx(y6,{label:"3D",onClick:()=>NM("3d"),tooltip:o("twoDTools.switchTo3d",{defaultValue:"מעבר לתלת מימד איסומטרי"})}),n.jsxs(qu,{open:ql,onOpenChange:Hr,children:[n.jsx(Qu,{asChild:!0,children:n.jsx("button",{type:"button",title:o("trace.toolsAndSettings",{defaultValue:"כלים והגדרות"}),"aria-label":o("trace.toolsAndSettings",{defaultValue:"כלים והגדרות"}),"data-testid":"floorplan-2d-settings-trigger",className:`fp-preset-bar__btn fp-preset-bar__btn--settings ${pC?"fp-preset-bar__btn--active":""}`,children:n.jsx(Q_,{size:13})})}),n.jsxs(Ju,{dir:r.dir(),align:"center",sideOffset:10,className:"relative w-[390px] max-w-[calc(100vw-24px)] overflow-hidden rounded-2xl border border-[#D84B2E]/22 bg-[#F7F4EF] p-3 font-heebo text-[#182137] shadow-[0_18px_50px_rgba(24,33,55,0.18),0_0_0_1px_rgba(255,255,255,0.76),inset_0_1px_0_rgba(255,255,255,0.88)] backdrop-blur-md","data-testid":"floorplan-2d-settings-popover",children:[n.jsx("div",{className:"pointer-events-none absolute inset-0 bg-[linear-gradient(135deg,rgba(255,255,255,0.62),rgba(247,244,239,0.92)_42%,rgba(232,227,219,0.82))]"}),n.jsx("div",{className:"pointer-events-none absolute inset-x-4 top-0 h-px bg-gradient-to-r from-transparent via-[#D84B2E]/65 to-transparent"}),n.jsxs("div",{className:"relative mb-3 text-start",children:[n.jsx("div",{className:"text-[13px] font-black tracking-[-0.02em]",children:o("twoDTools.moreTools",{defaultValue:"כלים נוספים"})}),n.jsx("div",{className:"text-[10px] font-semibold text-[#9a3d28]/70",children:o("twoDTools.description",{defaultValue:"קירות מיוחדים, כיול ומדידה"})})]}),n.jsxs("div",{className:"relative mb-3 grid grid-cols-2 gap-2",children:[n.jsxs("button",{type:"button",className:G0(vn==="trace"&&Li==="mamad"),onClick:()=>{Ot("trace"),gl("mamad"),Hr(!1)},children:[n.jsx(op,{size:13}),o("wallTypeDisplay.mamad",{defaultValue:"קיר ממ״ד"})]}),n.jsxs("button",{type:"button",className:G0(vn==="trace"&&Li==="free"),onClick:()=>{Ot("trace"),gl("free"),Hr(!1)},children:[n.jsx(op,{size:13,strokeWidth:1.55}),o("wallTypeDisplay.free",{defaultValue:"קיר חופשי"})]}),n.jsxs("button",{type:"button",className:G0(vn==="calibrate"),onClick:()=>{Ot("calibrate"),Hr(!1)},children:[n.jsx(hp,{size:13}),o("twoDTools.calibration",{defaultValue:"כיול"})]}),n.jsxs("button",{type:"button",className:G0(vn==="measure2d"),onClick:()=>
447{Ot("measure2d"),Hr(!1)},children:[n.jsx(hp,{size:13,strokeWidth:1.4}),o("twoDTools.tapeMeasure",{defaultValue:"סרט מדידה"})]})]}),n.jsx("div",{className:"relative border-t border-[#182137]/10 pt-3",children:yk("compact")})]})]}),["exterior","interior"].map(y=>n.jsxs("button",{type:"button",className:`fp-preset-bar__btn ${vn==="trace"&&Li===y?"fp-preset-bar__btn--active":""}`,onClick:()=>{Ot("trace"),gl(y)},children:[n.jsx(op,{size:13,strokeWidth:y==="interior"?1.2:2}),o(`wallTypeDisplay.${y}`,{defaultValue:d5[y]})]},y)),n.jsx("div",{className:"fp-preset-bar__divider","aria-hidden":!0}),n.jsxs("button",{type:"button",className:`fp-preset-bar__btn ${vn==="edit"?"fp-preset-bar__btn--active":""}`,onClick:()=>Ot("edit"),children:[n.jsx(I_,{size:13}),o("twoDTools.edit",{defaultValue:"עריכה"})]}),n.jsxs("button",{type:"button",className:`fp-preset-bar__btn ${vn==="pan"?"fp-preset-bar__btn--active":""}`,onClick:()=>Ot("pan"),children:[n.jsx(qI,{size:13}),o("twoDTools.pan",{defaultValue:"הזזה"})]})]}):null,bC=yk("panel"),U0=m.useCallback(y=>{const D=We==null?void 0:We.levels[0],T=(D==null?void 0:D.rooms)??[],$=(D==null?void 0:D.walls)??[];for(const Z of T){if(!Z.vertices||Z.vertices.length<3||!S1(y,Z.vertices))continue;const ot=$.filter(St=>{var Bt;return(Bt=Z.wallIds)==null?void 0:Bt.includes(St.id)}).map(St=>St.height).filter(St=>typeof St=="number"&&St>0);if(ot.length)return Math.max(...ot)}return Ld},[We]),MC=m.useCallback((y,D)=>{const T=R.find(qt=>qt.id===y);if(!T)return null;const $=T.wallType??"exterior",Z=Io[$],ot=T.thicknessMm??(Z==null?void 0:Z.thicknessMm)??100,St=T.heightMm??(Z==null?void 0:Z.heightMm)??Ld,Bt={wallId:y,startMm:{x:Math.round(T.start.x*Cn),y:Math.round(T.start.y*Cn)},endMm:{x:Math.round(T.end.x*Cn),y:Math.round(T.end.y*Cn)},thicknessMm:ot,side:D==="edge"?"front":D};return n.jsx(wy,{entities:Wt,furnitureGroups:Se,selectedEntityId:pn,onEntitiesChange:qe,onFurnitureGroupsChange:jn,onSelectedEntityChange:Ba,fpIsDark:an,anchoredWall:Bt,ceilingHeightMm:St,measurementUnit:$e,userTemplates:ld,userTemplatesLoading:lh,userTemplatesError:cd,defaultUserTemplateName:uu,onSaveUserTemplate:dd,onRenameUserTemplate:ch,onDeleteUserTemplate:dh})},[R,Cn,Wt,Se,pn,Ba,an,$e,ld,lh,cd,uu,dd,ch,dh,Io]),yC=m.useCallback(y=>n.jsx(wy,{entities:Wt,furnitureGroups:Se,selectedEntityId:pn,onEntitiesChange:qe,onFurnitureGroupsChange:jn,onSelectedEntityChange:Ba,fpIsDark:an,floorAnchor:{positionMm:y},ceilingHeightMm:U0(y),measurementUnit:$e,userTemplates:ld,userTemplatesLoading:lh,userTemplatesError:cd,defaultUserTemplateName:uu,onSaveUserTemplate:dd,onRenameUserTemplate:ch,onDeleteUserTemplate:dh}),[Wt,Se,pn,Ba,an,$e,ld,lh,cd,uu,dd,ch,dh,U0]),vx=m.useCallback((y,D,T)=>{const $=Ho[y]??[];if(D){const Z=$.map(ot=>ot.id===D?{...ot,...T,id:ot.id,polygon:ot.polygon}:ot);return Ji(y,Z),!0}if($.length>0){const{id:Z,polygon:ot,...St}=T,Bt=ds[y]??{};return To(y,{...Bt,...St}),!0}return!1},[Ho,ds,Ji,To]),nf=m.useCallback((y,D)=>{var St;const T=((St=We==null?void 0:We.levels[0])==null?void 0:St.rooms)??[],$=T.findIndex(Bt=>la(Bt)===y),Z=Ho[y]??[],ot=$>=0?o("scope.room",{defaultValue:"חדר {{count}}",count:$+1}):o("scope.selectedRoom",{defaultValue:"חדר נבחר"});if(Z.length>0){if(D){const Bt=Z.findIndex(qt=>qt.id===D);return Bt>=0?o("scope.roomRegion",{defaultValue:"{{room}} · אזור {{count}}",room:ot,count:Bt+1}):ot}return o("scope.roomNewRegion",{defaultValue:"{{room}} · אזור חדש",room:ot})}return $>=0?o("scope.roomArea",{defaultValue:"{{room}} · {{area}} מ״ר",room:ot,area:T[$].area??"?"}):ot},[We,Ho,o]),wC=m.useCallback((y,D)=>{const T=Ho[y]??[],$=D?T.find(lr=>lr.id===D)??null:null,Z=ds[y],ot=($==null?void 0:$.textureUrl)??(Z==null?void 0:Z.textureUrl)??(Z==null?void 0:Z.color)??Jr,St=($==null?void 0:$.tileWidthCm)??(Z==null?void 0:Z.tileWidthCm)??cs,Bt=($==null?void 0:$.tileHeightCm)??(Z==null?void 0:Z.tileHeightCm)??bc,qt=($==null?void 0:$.groutWidthMm)??(Z==null?void 0:Z.groutWidthMm)??Cs,se=($==null?void 0:$.groutColor)??(Z==null?void 0:Z.groutColor)??kr,Pn=T.length>0,Is=lr=>{if(vx(y,D,{id:"",polygon:[],textureUrl:lr,color:void 0}))return;const Nl=ds[y]??{};To(y,{...Nl,textureUrl:lr,color:void 0})},mi=lr=>{if(vx(y,D,{id:"",polygon:[],textureUrl:lr,color:lr}))return;const Nl=ds[y]??{};To(y,{...Nl,textureUrl:lr,color:lr})},ra=(lr,Nl)=>{if(vx(y,D,{id:"",polygon:[],tileWidthCm:lr,tileHeightCm:Nl}))return;const Sh=ds[y]??{};To(y,{...Sh,tileWidthCm:lr,tileHeightCm:Nl})},q0=(lr,Nl)=>{if(vx(y,D,{id:"",polygon:[],groutWidthMm:lr,groutColor:Nl}))return;const Sh=ds[y]??{};To(y,{...Sh,groutWidthMm:lr,groutColor:Nl})},of=()=>{if(D&&T.length>0){Ji(y,T.filter(lr=>lr.id!==D));return}if(T.length>0){To(y,null);return}To(y,null)};return n.jsxs("div",{className:"flex flex-col",children:[n.jsx(Gg,{variant:"floor",fpIsDark:an,scopeLabel:nf(y,D),isHint:!1,measurementUnit:$e}),n.jsx(Df,{variant:"embedded",mode:"material",target:"floor",onClose:()=>{},currentTextureUrl:ot,tileWidthCm:St,tileHeightCm:Bt,measurementUnit:$e,groutWidthMm:qt,groutColor:se,onSelectTexture:Is,onSelectColor:mi,onTileSizeChange:ra,onGroutChange:q0,onClear:of,savedTiles:nl,getPublicUrl:lr=>Gx(lr),onUploadTile:xh,onRemoveTile:ad,onRenameTile:Im,personalAssetsLocked:!l,onPremiumRequired:Br,floorIsDivided:Pn,floorRegionSelected:!!$,onFloorDivide:Pn?void 0:()=>lx(y),onFloorMerge:Pn?()=>cx(y):void 0})]})},[Ho,ds,Jr,cs,bc,Cs,kr,vx,To,Ji,lx,cx,an,nf,$e,nl,xh,l,Br,ad,Im]),kC=m.useCallback((y,D)=>nf(y,D),[nf]),vC=m.useCallback(()=>n.jsx("div",{className:"left-panel-grid flex min-h-[300px] flex-col overflow-hidden",style:{height:"min(56vh, 520px)"},onWheel:y=>y.stopPropagation(),children:FM}),[FM]),jC=m.useCallback(y=>nf(y,null),[nf]),_C=m.useCallback(()=>{sa(null),to(wo)},[]),RM=m.useCallback((y,D)=>{let T;if(y.startsWith("user:")){const $=y.slice(5),Z=ld.find(ot=>ot.id===$);if(!Z){ln.error(o("messages.userTemplateNotFound",{defaultValue:"התבנית האישית לא נמצאה"})),sa(null);return}if(Z.placement_mode==="wall"){ln.info(o("messages.wallTemplatePlacementHint",{defaultValue:"זו תבנית לקיר — לחץ לחיצה ימנית על קיר ובחר הוסף תבנית"})),sa(null);return}
447try{T=f6(Z,{entities:Wt,furnitureGroups:Se,floorAnchor:{positionMm:D}})}catch(ot){ln.error(ot instanceof Error?ot.message:o("messages.templatePlacementFailed",{defaultValue:"הצבת התבנית נכשלה"})),sa(null);return}}else{const $=zG(y);if(!$){sa(null);return}T=M7($,{entities:Wt,furnitureGroups:Se,floorAnchor:{positionMm:D},ceilingHeightMm:U0(D)})}qe([...Wt,...T.entities]),jn([...Se.filter($=>$.id!==T.group.id),T.group]),Ba(null),sa(null)},[Wt,Se,ld,qe,jn,Ba,U0,o]),EC=m.useCallback(y=>{sa(y.id),po("3d"),Ot("edit"),Cl(null),us(""),pt(null),to(wo),Ba(null)},[Ba]),DC=m.useCallback(y=>{sa(`user:${y.id}`),po("3d"),Ot("edit"),Cl(null),us(""),pt(null),to(wo),Ba(null)},[Ba]),FC=m.useCallback((y,D)=>{RM(y,D)},[RM]),[CC,K0]=m.useState(!1),jx=m.useRef(null),Z0=m.useCallback(y=>{const D=!g&&!C,T=R.length>0||X.length>0||tt.length>0||Y.length>0||Wt.length>0||wl.length>0;if(D&&T){jx.current=y,K0(!0);return}y()},[g,C,R.length,X.length,tt.length,Y.length,Wt.length,wl.length]),NC=m.useCallback(()=>{Z0(()=>s==null?void 0:s("/dashboard"))},[Z0,s]),IC=m.useCallback(()=>{nc()||Z0(()=>Sn())},[Z0,Sn,nc]),TC=m.useCallback(y=>{na("video")||(po("3d"),window.requestAnimationFrame(()=>{var D;(D=ea.current)==null||D.openWalkthroughRecorder(y)}))},[na]),SC=m.useCallback(()=>{var y;(y=ea.current)==null||y.stopWalkthroughRecording()},[]),PC=m.useCallback(async()=>{try{await Os()}catch(D){alert(o("messages.saveFailed",{defaultValue:"שמירה נכשלה: {{message}}",message:(D==null?void 0:D.message)??D}));return}K0(!1);const y=jx.current;jx.current=null,y==null||y()},[Os,o]),AC=m.useCallback(()=>{K0(!1);const y=jx.current;jx.current=null,y==null||y()},[]);return n.jsxs("div",{className:"w-full h-full flex flex-col bg-surface-0 font-heebo",children:[n.jsx(Fw,{open:CC,onOpenChange:K0,children:n.jsxs(Cw,{dir:i?"rtl":"ltr",className:"font-heebo text-start",children:[n.jsxs(Nw,{children:[n.jsx(Iw,{children:o("dialogs.saveBeforeExit.title",{defaultValue:"לשמור את הפרויקט?"})}),n.jsx(Tw,{children:o("dialogs.saveBeforeExit.description",{defaultValue:"ציירת משהו בקנבס אבל הפרויקט עדיין לא נשמר. לשמור אותו לפני היציאה?"})})]}),n.jsxs(Sw,{className:"gap-2 sm:justify-start",children:[n.jsx(Aw,{onClick:PC,children:o("dialogs.saveBeforeExit.confirm",{defaultValue:"כן, שמור"})}),n.jsx(Pw,{onClick:AC,children:o("dialogs.saveBeforeExit.discard",{defaultValue:"לא, אל תשמור"})})]})]})}),n.jsx(MQ,{phaseTrace:h==="trace",mainView:Te,viewScope:ho,autoSaveStatus:p0,planOrientationBar:Te==="2d"?null:xC,centerControls:gC,saving:so,wallsEmpty:R.length===0,showBackground:vt,showTraceOverlays:Tt,onSave:Kt,onHome:NC,onExport:ke,onExportModel:zm,exportsLocked:!l,onExportPremiumRequired:fd,isExportingModel:hi,onNewProject:IC,onUndoWall:S0,onClearAll:P0,onToggleBackgroun
447d:()=>Ht(y=>!y),onToggleTraceOverlays:()=>Zt(y=>!y),projectsPanelOpen:I,onToggleProjectsPanel:()=>H(y=>!y),sectionVisibility:fn,sectionOrder:hn,onSectionVisibilityChange:ys,onShowDetailsPanel:dt,cameraPreset:qi,roomLabel:td,environmentEnabled:Uf,onToggleEnvironment:xu,timeOfDayMinutes:Ql.sky.timeOfDayMinutes,onTimeOfDayChange:y=>tc(D=>({...D,sky:{timeOfDayMinutes:y}})),simulateOpenings:En,onToggleSimulateOpenings:()=>Fr(y=>!y),activeFloorplanSketchTool:On,onSetFloorplanSketchTool:dk,showFullFloorplanSketchToolbar:Jt,floorplanSketchAxesVisible:Go,onToggleFloorplanSketchAxes:()=>er(y=>!y),onSetCameraPreset:z6,onOpenWalkthroughRecorder:TC,onStopWalkthroughRecording:SC,walkthroughRecorderActive:Ws,viewportNotes:yl,onViewportNoteShow:Zb,onViewportNoteFocus:Kb,hiddenWallCount:Kd,onShowHiddenWalls:()=>{var y;return(y=ea.current)==null?void 0:y.showAllHiddenWalls()},renderModeControl:n.jsx(CQ,{items:sl.bank.items,currentProjectId:g,loadingReferences:sl.bank.loading,onRender:sl.send}),renderGalleryDropdown:n.jsx(EQ,{bank:sl.bank,pendingRenders:sl.pendingRenders}),canUndo:c0,canRedo:d0,onHistoryUndo:Pm,onHistoryRedo:Am,onSetMainView:NM,floorSelectorControl:Jt?void 0:n.jsx(yQ,{levels:Ns,activeLevelId:oo,viewScope:ho,onViewScopeChange:V6,onSwitchLevel:Dm,onAddLevelWithUpload:y=>{t0(y)},onAddLevelDuplicate:e0,onRenameLevel:Qp,onDeleteLevel:sd,onToggleLevelVisible:Gb,onStartAlign:Vm?w0:void 0,canShowUnderlay:Te==="2d"&&y0,showUnderlay:ax,onToggleUnderlay:()=>ki(y=>!y)}),traceRoomLabelListControl:h==="trace"&&Te==="2d"?n.jsx(kQ,{items:MM,labels:Mt,onLabelsChange:Rt,roomIds:C0,open:it,onOpenChange:st,onBeginEdit:y=>{var D;return(D=Sa.current)==null?void 0:D.beginTraceRoomLabelEdit(y)}}):null}),At&&Pt&&n.jsxs("div",{className:O("h-10 overflow-hidden bg-[#FDF6F4] border-b border-[#EC7357]/20 flex items-center px-5 gap-2.5 shrink-0 transition-[height,opacity,border-color] duration-200 ease-out dark:bg-[#2a1f1c] dark:border-white/10",kt?"h-0 opacity-0 border-transparent":"opacity-100 animate-[fadeIn_0.2s_ease-out]"),children:[n.jsx("span",{className:`px-2 py-0.5 rounded text-[10px] font-bold uppercase tracking-wide ${Pt.startsWith("AI")?"bg-blue-100 text-blue-700":Pt==="Footprint"?"bg-[#FCE8E4] text-[#9a3d28] dark:bg-white/10 dark:text-[#F4A99A]":"bg-amber-100 text-amber-700"}`,children:Pt}),n.jsx("span",{className:"text-sm text-text-2 truncate flex-1",children:At}),n.jsx("button",{onClick:ph,className:"text-text-3 hover:text-text-0 cursor-pointer text-sm",children:"✕"})]}),n.jsx("div",{className:"flex-1 flex overflow-hidden",children:n.jsxs("div",{ref:rr,className:"flex-1 relative overflow-hidden",children:[Te==="3d"&&qi!=="inside"&&n.jsxs("div",{className:"absolute left-3 top-3 z-30 flex flex-col items-center rounded-md border border-[#182137]/10 bg-white/90 shadow-[0_4px_14px_rgba(24,33,55,0.12)] backdrop-blur-sm",children:[n.jsx("button",{type:"button","aria-label":o("accessibility.zoomIn",{defaultValue:"התקרבות"}),title:o("accessibility.zoomIn",{defaultValue:"התקרבות"}),onClick:mk,className:"flex h-9 w-9 items-center justify-center text-[#182137] transition-colors hover:bg-[#F4F1EA]",children:n.jsx(pm,{size:17,strokeWidth:2.2})}),n.jsx("div",{className:"h-px w-5 bg-[#182137]/10"}),n.jsx("button",{type:"button","aria-label":o("accessibility.zoomOut",{defaultValue:"התרחקות"}),title:o("accessibility.zoomOut",{defaultValue:"התרחקות"}),onClick:fk,className:"flex h-9 w-9 items-center justify-center text-[#182137] transition-colors hover:bg-[#F4F1EA]",children:n.jsx(Pp,{size:17,strokeWidth:2.2})})]}),Te==="2d"?n.jsxs(n.Fragment,{children:[n.jsx(gZ,{ref:Sa,imageUrl:C,showBackground:vt,showTraceOverlays:Tt,walls:R,beams:X,openings:tt,furniture:Y,calibration:Ft,effectiveScale:Cn,selected:ct,cameraPose:Gm,showCameraMarker:!!Gm&&!Wi,onCameraPoseChange:x0,traceRoomLabels:Mt,onTraceRoomLabelsChange:Rt,traceRoomLabelListOpen:it,onTraceRoomLabelListOpenChange:st,traceRoomOverlays:bd,sketchPolygons:Ye,selectedSketchEntityId:pn,onSelectSketchEntity:Ba,onMoveSketchEntity:oC,detectionDebug:ht,externalMode:Nc,roofContour:oM,onRoofContourCommit:sM,onRoofContourCancel:b0,onRoofContourFinish:bh,activeFurnT
447ype:Zm,activeOpeningPreset:yd??void 0,wallTypeSettings:Io,measurementUnit:$e,onModeChange:yu,onAddWall:vs,onEditWall:Bi,onSplitWall:yo,onAddBeam:EM,onEditBeam:Eh,onSelect:T0,onAddOpening:Xs,onEditOpening:wh,onOpeningsChange:G,onAddFurniture:fo,onMoveFurniture:vh,onDeleteSelected:xx,onRotateSelected:jM,onRotateFurniture:jh,onScaleFurniture:hx,onCalibrate:Km,activeWallType:Li,underlayWalls:yh,showUnderlay:ax}),Kf&&yh&&n.jsx(zq,{traceCanvasRef:Sa,underlayWalls:yh,activeScale:Cn,activeAlign:((jk=Ns[gd])==null?void 0:jk.imageAlign)??null,onApply:Cc,onCancel:()=>ir(!1)})]}):We?n.jsx(Q8,{ref:ea,scene:We,activeLevelId:oo,viewScope:ho,cameraFocusRequestId:da,onActivateLevel:Dm,levelVisibility:Bm,passiveLevelState:M0,buildingRoof:rs,showBuildingRoof:nu,roofHostState:Hs,roofSelected:Xb,onRoofSelectionChange:Hm,roofContourEditing:Wi,onRoofContourCommit:ix,roofFocusRequestId:ua,customModelUrls:W0,customModelMaterialSlots:Dh,environment:Ql,environmentEnabled:Uf,simulateOpenings:En,openOpeningIds:wr,floorTextureUrl:Jr,roomFloorOverrides:ds,onRoomFloorOverrideChange:To,roomFloorRegions:Ho,onRoomFloorRegionsChange:Ji,onFloorTileOriginChange:zb,wallFaceRegions:ai,onWallFaceRegionsChange:xr,tileSizeM:uh.tileSizeM,grout:uh.grout,wallTextures:nx,walls:R,onWallsChange:z,beams:X,onBeamsChange:ft,selectedBeamId:(ct==null?void 0:ct.kind)==="beam"?ct.id:null,onBeamSelectionChange:y=>{pt(y?{kind:"beam",id:y}:null),y&&io("beams")},onWallLengthChange:bu,savedWallTiles:lu,onUploadWallTile:xd,onRemoveWallTile:cu,onRenameWallTile:du,personalAssetsLocked:!l,onPremiumRequired:Br,onFloorTextureChange:_m,onFloorTileSizeChange:(y,D)=>{Zp(y),qp(D)},onFloorGroutChange:(y,D)=>{ed(y),Pa(D)},floorTileWidthCm:cs,floorTileHeightCm:bc,floorGroutWidthMm:Cs,floorGroutColor:kr,savedFloorTiles:nl,onUploadFloorTile:xh,onRemoveFloorTile:ad,onRenameFloorTile:Im,sidebarMode:vn,onSidebarModeChange:Ot,sidebarContent:H6,wallSettingsContent:bC,measurementUnit:$e,renderCarpentryPanel:MC,renderFloorTemplatePanel:yC,renderFloorMaterialPanel:wC,getFloorMaterialPanelSubtitle:kC,renderFloorFurniturePanel:vC,getFloorFurniturePanelSubtitle:jC,onFloorFurniturePanelOpen:_C,onFloorplanTemplateDrop:FC,activeFloorplanTemplateId:Jm,onFloorplanTemplatePlace:y=>{Jm&&RM(Jm,y)},onFloorplanTemplatePlacementCancel:()=>sa(null),templatePlacementUsesTopView:!Jt,openingPreset:yd,onOpeningPresetChange:Cl,onAddOpening:y=>G(D=>[...D,y]),openings:tt,effectiveScale:Cn,onOpeningsChange:G,tracedFurniture:Y,onFurnitureChange:J,furnType:Zm,furniturePlacementRequestId:Ha,onFurnitureFloorPlaced:()=>us(""),planRotationDeg:Ft.planRotationDeg??0,floorplanCameraPose:Gm,showCanvasCameraMarker:!!Gm,onFloorplanCameraPoseChange:x0,onCameraPresetChange:jm,onRoomLabelChange:qd,onHiddenWallCountChange:Zl,onRequestSectionOpen:io,roomCeilingOverrides:Qi,onRoomCeilingOverridesChange:mr,onSelectionChange:y=>{Fm(y.wallId),sh(y.wallSide),_l(y.wallRegionId),vc(y.roomSig),iu(y.regionId),qf(y.ceilingRoomSig)},onFurnitureSelectionChange:y=>{y.length>0?pt({kind:"furniture",id:y[0]}):pt(D=>(D==null?void 0:D.kind)==="furniture"?null:D),_t(D=>D&&y.includes(D.furnitureId)?D:null)},selectedSmartGlbPart:xt,onSmartGlbPartSelect:uk,onSmartGlbPartClear:()=>_t(null),forceShowCeiling:Yt.ceiling,activeFloorplanSketchTool:On,floorplanSketchEntities:Wt,floorplanSketchFurnitureGroups:Se,selectedFloorplanSketchEntityId:pn,selectedFloorplanSketchEdgeIndex:ls,floorplanSketchAxesVisible:Jt&&Go,onFloorplanSketchToolChange:dk,onFloorplanSketchEntitiesChange:qe,onFloorplanSketchFurnitureGroupsChange:jn,onFloorplanSketchSelect:Ba,selectedFloorplanSketchFaceId:tr,onFloorplanSketchFaceSelect:y=>{ro(y),y!==null&&Qo(null)},onFloorplanSketchEdgeSelect:Qo,onFloorplanSketchHostFaceRegionSelect:Yo,floorplanSketchLineLengthRequest:ur,floorplanSketchCommitLineRequestId:Je,onFloorplanSketchLineDraftLengthChange:Y6,onFloorplanSketchFaceLineMeasurementChange:Ui,onFloorplanSketchFaceMeasureMeasurementChange:_s,onFloorplanSketchFaceMeasureMarkerPointerDown:J6,floorplanSketchFaceMeasureLengthRequest:Qc,floorplanSketchCommitFaceMeasureRequest:Ki,floorplanSketchUpdateFaceMeasureRequest:Ds,floorplanSketchRectangleDimensionsRequest:Kr,onFloorplanSketchRectangleDraftDimensionsChange:eC,onFloorplanSketchPushPullHeightChange:nC,floorplanSketchFaceOffsetDistanceRequest:Dt,floorplanSketchCommitFaceOffsetRequest:xe,onFloorplanSketchFaceOffsetPreviewChange:U6,floorplanSketchOffsetDistanceRequest:Ks,floorplanSketchCommitOffsetRequest:ns,onFloorplanSketchOffsetPreviewChange:Q6,activeTemplateEditorJobCount:kM,templateEditorRecoveredNotice:Pe,onFloorplanTemplateEditSubmit:F,figureHidden:rh,figurePosition:Cm,figureRotation:Nr,onFigureHiddenChange:y=>{Jf(y),vr.current=!0},onFigurePositionChange:y=>{$s(y),vr.current=!0},onFigureRotationChange:y=>{jc(y),vr.current=!0},wallElectricalFixtures:tu,onWallElectricalFixturesChange:Ra,wallNotes:Mc,onWallNotesChange:Ub,viewportNotes:yl,onViewportNotesChange:s0,viewportNoteFocusRequest:$b,walkthroughs:wl,onWalkthroughsChange:Qf,onWalkthroughRecordingChange:yr,onWalkthroughVideoSave:Om,detailsPanelOpen:K}):n.jsx("div",{className:"w-full h-full flex items-center justify-center bg-viewer-bg text-gray-500 text-sm",children:o("viewer.drawWallsFor3d",{defaultValue:"צייר קירות כדי לראות תצוגה תלת-ממדית"})}),h==="trace"&&n.jsx(BQ,{open:I,onClose:()=>H(!1),viewportFrameRef:rr,fpIsDark:an,savedProjects:In,currentProjectId:g,loadingProjects:fe,selectMode:zo,selectedIds:co,onEnterSelectMode:()=>js(!0),onExitSelectMode:()=>{js(!1),ze(new Set)},onToggleSelected:y=>ze(D=>{const T=new Set(D);return T.has(y)?T.delete(y):T.add(y),T}),onBulkDelete:Yn,onLoadProject:y=>{ue(y),H(!1)},onDeleteProject:mn,renamingProjectId:Un,renameDraft:dn,onRenameDraftChange:$o,onStartRename:y=>{uo(y.id),$o(y.name)},onCommitRename:Xe,onCancelRename:()=>uo(null)}),h==="trace"&&(()=>{var Sk,Pk,Ak,Lk,Wk;const y=n.jsxs("div",{className:"flex items-center gap-2",dir:"rtl",children:[n.jsx("div",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-lg bg-gradient-to-br from-[#EC7357] to-[#D84B2E] shadow-sm",children:n.jsx("span",{className:"text-[9px] font-black tracking-wide text-white",children:"3D"})}),hs?n.jsx("input",{ref:Ps,value:Lr,onChange:$t=>bi($t.target.value),onBlur:()=>{Qn(!1);const $t=Lr.trim();$t&&$t!==b?(M($t),vr.current=!0):bi(b||S||o("project.untitled",{defaultValue:"ללא שם"}))},onKeyDown:$t=>{$t.key==="Enter"&&$t.target.blur(),$t.key==="Escape"&&(bi(b||S||o("project.untitled",{defaultValue:"ללא שם"})),Qn(!1))},className:O("min-w-0 flex-1 rounded-lg border px-1.5 py-0.5 text-right text-[12px] font-semibold outline-none focus:ring-2",an?"border-white/20 bg-[#0A0A0A] text-white focus:border-[#
447EC7357]/50 focus:ring-[#EC7357]/20":"border-[#D84B2E]/35 bg-white text-[#182137] focus:border-[#D84B2E] focus:ring-[#EC7357]/25"),autoFocus:!0}):n.jsx("span",{className:O("min-w-0 flex-1 cursor-pointer truncate rounded px-1 py-0.5 text-[12px] font-semibold transition-colors",an?"text-white/90 hover:bg-white/5":"text-[#182137] hover:bg-white/80"),onClick:()=>{bi(b||S||o("project.untitled",{defaultValue:"ללא שם"})),Qn(!0)},title:o("project.rename",{defaultValue:"לחץ לשינוי שם"}),children:b||S||o("project.untitled",{defaultValue:"ללא שם"})})]}),D=n.jsxs("div",{className:O("group relative h-[200px] w-full overflow-hidden",an?"bg-[#0A0A0A]":"bg-[#E8E6E0]"),children:[Te==="2d"?We?n.jsx(Q8,{ref:ox,scene:We,activeLevelId:oo,viewScope:"building",levelVisibility:Bm,passiveLevelState:M0,buildingRoof:rs,showBuildingRoof:nu,roofHostState:Hs,customModelUrls:W0,customModelMaterialSlots:Dh,compact:!0,floorTextureUrl:Jr,tileSizeM:uh.tileSizeM,grout:uh.grout,wallTextures:nx,walls:R,onWallsChange:z,savedWallTiles:lu,onUploadWallTile:xd,onRemoveWallTile:cu,onRenameWallTile:du,personalAssetsLocked:!l,onPremiumRequired:Br}):n.jsx("div",{className:O("flex h-full w-full items-center justify-center text-xs",an?"text-white/40":"text-[#182137]/40"),children:o("project.no3dPreview",{defaultValue:"אין תצוגת 3D"})}):C?n.jsx("img",{src:C,alt:"2D",className:"h-full w-full bg-white object-contain"}):n.jsx("div",{className:O("flex h-full w-full items-center justify-center text-xs",an?"text-white/40":"text-[#182137]/40"),children:o("project.noPlan",{defaultValue:"אין תוכנית"})}),n.jsx("div",{className:"absolute left-2 top-2 z-10",children:n.jsx("button",{type:"button",className:"flex items-center gap-1 rounded-full bg-gradient-to-r from-[#EC7357] to-[#D84B2E] px-2.5 py-1 text-[11px] font-bold text-white shadow-md transition-opacity hover:opacity-90",title:Te==="2d"?o("project.open3dInMain",{defaultValue:"פתח תצוגת 3D במסך הראשי"}):o("project.returnTo2dInMain",{defaultValue:"חזור לתצוגת 2D במסך הראשי"}),onClick:$t=>{$t.stopPropagation(),NM(Te==="2d"?"3d":"2d")},children:Te==="2d"?o("project.switchTo3d",{defaultValue:"החלף ל-3D ↗"}):o("project.switchTo2d",{defaultValue:"החלף ל-2D ↗"})})})]}),T=n.jsxs("div",{className:"flex flex-col",children:[n.jsx("div",{className:"border-b border-[#182137]/8 px-3 py-2.5",children:y}),n.jsx("div",{className:"border-b border-[#182137]/8",children:D}),hk&&n.jsx("div",{className:O("px-3 py-1.5 text-right text-[10px]",an?"text-white/45":"text-[#182137]/50"),children:hk})]}),$=Tn==="front"?o("scope.wallFront",{defaultValue:"צד קדמי"}):Tn==="back"?o("scope.wallBack",{defaultValue:"צד אחורי"}):o("scope.wallEdge",{defaultValue:"צד / עובי"}),Z=(()=>
447{if(!$n)return o("scope.selectWall",{defaultValue:"בחר קיר ב-3D"});if(Tn==="edge")return o("scope.wall",{defaultValue:"קיר · {{side}}",side:$});const $t=`${$n}__${Tn}`,Ie=ai[$t]??[];if(Ie.length>0){if(jl){const xn=Ie.findIndex(Oe=>Oe.id===jl);return xn>=0?o("scope.wallRegion",{defaultValue:"קיר · {{side}} · אזור {{count}}",side:$,count:xn+1}):o("scope.wall",{defaultValue:"קיר · {{side}}",side:$})}return o("scope.wallNewRegion",{defaultValue:"קיר · {{side}} · אזור חדש",side:$})}return o("scope.wall",{defaultValue:"קיר · {{side}}",side:$})})(),ot=((Sk=We==null?void 0:We.levels[0])==null?void 0:Sk.rooms)??[],St=(()=>{if(!Xn)return ot.length>0?o("scope.selectFloor",{defaultValue:"לחץ על רצפה של חדר ב-3D"}):o("scope.noClosedRooms",{defaultValue:"אין חדרים סגורים"});const $t=ot.findIndex(Oe=>la(Oe)===Xn),Ie=Ho[Xn]??[],xn=$t>=0?o("scope.room",{defaultValue:"חדר {{count}}",count:$t+1}):o("scope.selectedRoom",{defaultValue:"חדר נבחר"});if(Ie.length>0){if(tl){const Oe=Ie.findIndex(Jo=>Jo.id===tl);return Oe>=0?o("scope.roomRegion",{defaultValue:"{{room}} · אזור {{count}}",room:xn,count:Oe+1}):xn}return o("scope.roomNewRegion",{defaultValue:"{{room}} · אזור חדש",room:xn})}return $t>=0?o("scope.roomArea",{defaultValue:"{{room}} · {{area}} מ״ר",room:xn,area:ot[$t].area??"?"}):xn})(),Bt=(()=>{if(!Cr)return ot.length>0?o("scope.selectCeiling",{defaultValue:"לחץ על תקרה של חדר ב-3D"}):o("scope.noClosedRooms",{defaultValue:"אין חדרים סגורים"});const $t=ot.findIndex(Ie=>la(Ie)===Cr);return $t>=0?o("scope.ceilingRoom",{defaultValue:"תקרה · חדר {{count}}",count:$t+1}):o("scope.ceilingSelectedRoom",{defaultValue:"תקרה · חדר נבחר"})})(),qt=Cr??(ot[0]?la(ot[0]):null),se=qt?Qi[qt]:void 0,Pn=(ct==null?void 0:ct.kind)==="wall"?R.find($t=>$t.id===ct.id):null,Is=Pn?(()=>{var Oe;
447const $t=Pn.wallType||"exterior",Ie=((Oe=Io[$t])==null?void 0:Oe.heightMm)??2700;return{value:Pn.heightMm??Ie,min:lc.heightMm.min,max:lc.heightMm.max,onChange:Jo=>Bi({...Pn,heightMm:Jo})}})():void 0,mi=Pn?(()=>{var Oe;const $t=Pn.wallType||"exterior",Ie=((Oe=Io[$t])==null?void 0:Oe.thicknessMm)??lc.thicknessMm.min;return{value:Pn.thicknessMm??Ie,min:lc.thicknessMm.min,max:lc.thicknessMm.max,onChange:Jo=>Bi({...Pn,thicknessMm:Jo})}})():void 0,ra=(ct==null?void 0:ct.kind)==="opening"?tt.findIndex($t=>$t.id===ct.id):-1,q0=n.jsxs("div",{className:"flex flex-col",children:[ra>=0&&Cn&&n.jsx("div",{className:O("border-b p-3",an?"border-white/10 bg-[#141416]/60":"border-[#182137]/10 bg-[#FAF6F0]"),children:n.jsx(j7,{openings:tt,selectedOpeningIdx:ra,onOpeningsChange:G,onSelectedOpeningChange:$t=>{var Ie;pt($t===null?null:{kind:"opening",id:(Ie=tt[$t])==null?void 0:Ie.id})},effectiveScale:Cn,walls:R,fpIsDark:an,measurementUnit:$e,isOpen:(()=>{var Ie;const $t=(Ie=tt[ra])==null?void 0:Ie.id;return!!$t&&(En||wr.has($t))})(),onToggleOpen:()=>{var Ie;const $t=(Ie=tt[ra])==null?void 0:Ie.id;$t&&Zd($t)}})}),n.jsx("div",{className:"p-3 left-panel-grid",children:O6})]}),of=(ct==null?void 0:ct.kind)==="furniture",lr=of&&Y.some($t=>$t.id===ct.id&&$t.type.startsWith("blender_")),Nl=n.jsx("div",{className:"flex min-h-0 flex-col",children:of&&Cn?n.jsx("div",{className:"p-3",children:n.jsx(BJ,{furniture:Y,selectedIds:new Set([ct.id]),onSelectedIdsChange:$t=>{if($t.size===0)pt(null);else{const Ie=[...$t][0];pt({kind:"furniture",id:Ie})}},onFurnitureChange:$t=>{fr.current===oo&&Kl.current==="floor"&&J($t)},effectiveScale:Cn,onPlaceMore:()=>H0(Zm),materialSlotsByType:Dh,selectedSmartGlbPart:xt,onSmartGlbPartSelect:$t=>uk($t.furnitureId,$t.slotId),materialSlotsLoading:bx.loadingByType[((Pk=Y.find($t=>$t.id===ct.id))==null?void 0:Pk.type)??""],materialSlotsError:bx.errorsByType[((Ak=Y.find($t=>$t.id===ct.id))==null?void 0:Ak.type)??""],onRetryMaterialSlots:bx.retry,onSmartGlbPartClear:()=>_t(null),savedMaterialTiles:lu,getMaterialTilePublicUrl:_f,onUploadMaterialTile:xd,onRemoveMaterialTile:cu,onRenameMaterialTile:du,personalAssetsLocked:!l,onPremiumRequired:Br,measurementUnit:$e},`${oo}:${ct.id}`)}):n.jsx("div",{className:"left-panel-grid flex min-h-[300px] flex-col overflow-hidden p-3",style:{height:"min(56vh, 520px)"},onWheel:$t=>$t.stopPropagation(),children:FM})}),Sh=(ct==null?void 0:ct.kind)==="beam"?X.find($t=>$t.id===ct.id)??null:null,OM=n.jsx(VJ,{beam:Sh,effectiveScale:Cn,measurementUnit:$e,fpIsDark:an,mainView:Te,onChange:Eh,onDuplicate:A0,onDelete:xx,onStartPlacement:_M}),Tr=(()=>{if(!$n||!jl)return null;const $t=`${$n}__${Tn}`;return(ai[$t]??[]).find(xn=>xn.id===jl)??null})(),Il=$n?R.find($t=>$t.id===$n):null,zr=Il?Tn==="edge"?Il.edgeTexture:Tn==="back"?Il.backTexture??Il.texture:Il.texture:void 0,ju=Il?Tn==="edge"?Il.edgeColor:Tn==="back"?Il.backColor??Il.color:Il.color:void 0,LC=(Tr==null?void 0:Tr.textureUrl)??(zr==null?void 0:zr.url)??ju,WC=(Tr==null?void 0:Tr.tileWidthCm)??(zr==null?void 0:zr.tileWidthCm)??100,RC=(Tr==null?void 0:Tr.tileHeightCm)??(zr==null?void 0:zr.tileHeightCm)??270,OC=ei((Tr==null?void 0:Tr.orientation)??(zr==null?void 0:zr.orientation)),HC=(Tr==null?void 0:Tr.groutWidthMm)??(zr==null?void 0:zr.groutWidthMm)??3,BC=(Tr==null?void 0:Tr.groutColor)??(zr==null?void 0:zr.groutColor)??"#c8c4bc",Nk=$n?`${$n}__${Tn}`:"",HM=Nk?(((Lk=ai[Nk])==null?void 0:Lk.length)??0)>0:!1,VC=!!Tr,BM=($t,Ie)=>{const xn=Tn===$t;return n.jsx("button",{type:"button",onClick:()=>sh($t),disabled:!$n,className:O("flex-1 rounded-md px-2 py-1.5 text-[11px] font-bold transition-colors",!$n&&"cursor-not-allowed opacity-40",xn?"bg-gradient-to-r from-[#EC7357] to-[#D84B2E] text-white shadow":an?"bg-white/5 text-white/70 hover:bg-white/10":"bg-[#182137]/5 text-[#182137]/70 hover:bg-[#182137]/10"),children:Ie},$t)},zC=n.jsxs("div",{className:"flex flex-col",children:[n.jsx(Gg,{variant:"wall",fpIsDark:an,scopeLabel:Z,isHint:!$n,wallHeight:Is,wallThickness:mi,wallThicknessLabel:(Pn==null?void 0:Pn.wallType)==="free"?"עומק":"עובי",onDeleteWall:Pn?xx:void 0,measurementUnit:$e}),n.jsxs("div",{className:O("flex items-center gap-1.5 border-b px-3 py-2",an?"border-white/10 bg-[#141416]/60":"border-[#182137]/10 bg-[#FAF6F0]"),children:[n.jsx("span",{className:O("ms-1 text-[10px] font-semibold",an?"text-white/45":"text-[#182137]/50"),children:"בחר צד:"}),BM("front","קדמי"),BM("back","אחורי"),BM("edge","עובי")]}),n.jsx(Df,{variant:"embedded",mode:"material",target:"wall",onClose:()=>{},currentTextureUrl:LC,tileWidthCm:WC,tileHeightCm:RC,measurementUnit:$e,orientation:OC,groutWidthMm:HC,groutColor:BC,onSelectTexture:k0,onSelectColor:$m,onTileSizeChange:v0,onOrientationChange:iM,onGroutChange:rM,onClear:aM,savedTiles:lu,getPublicUrl:$t=>Gx($t),onUploadTile:xd,onRemoveTile:cu,onRenameTile:du,personalAssetsLocked:!l,onPremiumRequired:Br,wallIsDivided:HM,wallRegionSelected:VC,onWallDivide:$n&&(Tn==="front"||Tn==="back")&&!HM?()=>Xm($n,Tn):void 0,onWallMerge:$n&&(Tn==="front"||Tn==="back")&&HM?()=>lM($n,Tn):void 0})]}),ia=!Xn||!tl?null:(Ho[Xn]??[]).find(Ie=>Ie.id===tl)??null,ji=Xn?ds[Xn]:void 0,$C=(ia==null?void 0:ia.textureUrl)??(ji==null?void 0:ji.textureUrl)??(ji==null?void 0:ji.color)??Jr,XC=(ia==null?void 0:ia.tileWidthCm)??(ji==null?void 0:ji.tileWidthCm)??cs,YC=(ia==null?void 0:ia.tileHeightCm)??(ji==null?void 0:ji.tileHeightCm)??bc,GC=(ia==null?void 0:ia.groutWidthMm)??(ji==null?void 0:ji.groutWidthMm)??Cs,UC=(ia==null?void 0:ia.groutColor)??(ji==null?void 0:ji.groutColor)??kr,VM=Xn?(((Wk=Ho[Xn])==null?void 0:Wk.length)??0)>0:!1,KC=n.jsxs("div",{className:"flex flex-col",children:[n.jsx(Gg,{variant:"floor",fpIsDark:an,scopeLabel:St,isHint:!Xn,measurementUnit:$e}),n.jsx(Df,{variant:"embedded",mode:"material",target:"floor",onClose:()=>{},currentTextureUrl:$C,tileWidthCm:XC,tileHeightCm:YC,measurementUnit:$e,groutWidthMm:GC,groutColor:UC,onSelectTexture:j0,onSelectColor:cM,onTileSizeChange:dM,onGroutChange:uM,onClear:hM,savedTiles:nl,getPublicUrl:$t=>Gx($t),onUploadTile:xh,onRemoveTile:ad,onRenameTile:Im,personalAssetsLocked:!l,onPremiumRequired:Br,floorIsDivided:VM,floorRegionSelected:!!ia,onFloorDivide:Xn&&!VM?()=>lx(Xn):void 0,onFloorMerge:Xn&&VM?()=>cx(Xn):void 0})]}),ZC=(se==null?void 0:se.textureUrl)??(se==null?void 0:se.color)??"#f5f5f0",qC=(se==null?void 0:se.tileWidthCm)??100,JC=(se==null?void 0:se.tileHeightCm)??100,QC=(se==null?void 0:se.groutWidthMm)??5,tN=(se==null?void 0:se.groutColor)??"#c8c4bc",eN=n.jsxs("div",{className:"flex flex-col",children:[n.jsx(Gg,{variant:"ceiling",fpIsDark:an,scopeLabel:Bt,isHint:!Cr,measurementUnit:$e}),n.jsx(Df,{variant:"embedded",mode:"material",target:"ceiling",onClose:()=>{},currentTextureUrl:ZC,tileWidthCm:qC,tileHeightCm:JC,measurementUnit:$e,groutWidthMm:QC,groutColor:tN,onSelectTexture:mM,onSelectColor:Ym,onTileSizeChange:fM,onGroutChange:xM,onClear:E0,savedTiles:lu,getPublicUrl:$t=>Gx($t),onUploadTile:xd,onRemoveTile:cu,onRenameTile:du,personalAssetsLocked:!l,onPremiumRequired:Br,ceilingStyle:(se==null?void 0:se.ceilingStyle)??"flat",onCeilingStyleChange:_0,gapWidthCm:Math.round(((se==null?void 0:se.gapWidth)??.02)*100),onGapWidthChange:pM,coveWidthCm:Math.round(((se==null?void 0:se.coveWidth)??.3)*100),coveDepthCm:Math.round(((se==null?void 0:se.coveDepth)??.1)*100),onCoveDimensionsChange:gM})]}),nN=n.jsx(Wet,{entities:Wt,furnitureGroups:Se,selectedWallAnchor:N0,floorplanBounds:pr,fpIsDark:an,activeJobCount:dx,recoveredNotice:Ze,measurementUnit:$e,onEnsureProjectSaved:()=>Os(void 0,{navigateOnCreate:!0}),onJobStarted:()=>{Um()},onClarificationAnswered:ux}),oN=n.jsxs("div",{className:"space-y-3 p-3",dir:i?"rtl":"ltr","data-testid":"floorplan-settings-panel",children:[n.jsxs("div",{className:"space-y-0.5 text-start",children:[n.jsx("div",{className:O("text-[13px] font-black",an?"text-white":"text-[#182137]"),children:o("settings.title",{defaultValue:"הגדרות מערכת"})}),n.jsx("div",{className:O("text-[10px] font-semibold",an?"text-white/45":"text-[#182137]/50"),children:o("settings.measurementMethod",{defaultValue:"שיטת מדידה"})})]}),n.jsx("div",{className:O("grid grid-cols-2 rounded-[4px] border p-1",an?"border-white/10 bg-white/[0.04]":"border-[#182137]/10 bg-[#F7F4EF]"),role:"radiogroup","aria-label":o("settings.measurementMethod",{defaultValue:"שיטת מדידה"}),"data-testid":"floorplan-measurement-unit-control",children:[{id:"cm",label:o("settings.centimeters",{defaultValue:"ס״מ"})},{id:"mm",label:o("settings.millimeters",{defaultValue:"מ״מ"})}].map($t=>{const Ie=$e===$t.id;return n.jsx("button",{type:"button",role:"radio","aria-checked":Ie,"data-testid":`floorplan-measurement-unit-${$t.id}`,onClick:()=>bl($t.id),className:O("h-9 rounded-[3px] text-[12px] font-black transition-colors",Ie?"bg-[#182137] text-[#F7F4EF]":an?"text-white/62 hover:bg-white/[0.08]":"text-[#182137]/62 hover:bg-white"),children:$t.label},$t.id)})})]}
447),gr=pn?Wt.find($t=>$t.id===pn&&($t.kind==="polygon"||$t.kind==="facePatch"||$t.kind==="faceCornerArc"&&$t.verticalThroughCut===!0)):void 0,zM=(()=>{if(!gr)return null;const $t=gr.groupId;if(!$t)return null;const Ie=Wt.find(Oe=>Oe.kind==="polygon"&&Oe.sourceTool==="rectangle"&&Oe.groupId===$t&&typeof Oe.heightMm=="number"&&Oe.heightMm>0);return Ie&&Wt.some(Oe=>Oe.kind==="facePatch"&&Oe.hostEntityId===Ie.id)?Ie:null})(),al=(()=>{const $t=gr==null?void 0:gr.groupId;if(!$t)return null;const Ie=Se.find(xn=>xn.id===$t);return Ie!=null&&Ie.rigid?Ie:null})(),_x=al?(()=>{const $t=al.entityIds.find(Ie=>{var xn;return((xn=Wt.find(Oe=>Oe.id===Ie))==null?void 0:xn.kind)==="polygon"});return $t?Wt.find(Ie=>Ie.id===$t)??null:null})():null,Ph=$t=>{if(!al)return;const Ie=Ret(al.templateId??"",al,Wt,$t);if(!Ie)return;qe(Ie.entities),jn(Oe=>Oe.map(Jo=>Jo.id===Ie.group.id?Ie.group:Jo));const xn=Ie.group.entityIds.find(Oe=>{var Jo;return((Jo=Ie.entities.find(Sl=>Sl.id===Oe))==null?void 0:Jo.kind)==="polygon"});xn&&Ba(xn)},Ik=(()=>{if(!al)return null;const $t=al.templateId??"",Ie=Math.round((al.widthMm??0)/10);if($t==="lighting.panel")return{widthLabel:o("dimensions.length",{defaultValue:"אורך"}),widthCm:Ie,minWidthCm:40,maxWidthCm:600,heightCm:0,minHeightCm:0,maxHeightCm:0,onWidthChange:xn=>Ph({widthMm:xn*10})};if($t==="lighting.recessed")return{widthLabel:o("dimensions.diameter",{defaultValue:"קוטר"}),widthCm:Ie,minWidthCm:6,maxWidthCm:60,heightCm:0,minHeightCm:0,maxHeightCm:0,onWidthChange:xn=>Ph({widthMm:xn*10})};if($t==="lighting.wall"){const xn=Math.round(((_x==null?void 0:_x.heightMm)??0)/10);return{widthLabel:o("dimensions.width",{defaultValue:"רוחב"}),widthCm:Ie,minWidthCm:6,maxWidthCm:120,heightLabel:o("dimensions.height",{defaultValue:"גובה"}),heightCm:xn,minHeightCm:8,maxHeightCm:120,onWidthChange:Oe=>Ph({widthMm:Oe*10}),onHeightChange:Oe=>Ph({heightMm:Oe*10})}}if($t==="lighting.floor"){const xn=Math.round((al.heightMm??0)/10);return{widthLabel:o("dimensions.height",{defaultValue:"גובה"}),widthCm:xn,minWidthCm:80,maxWidthCm:240,heightCm:0,minHeightCm:0,maxHeightCm:0,onWidthChange:Oe=>Ph({heightMm:Oe*10})}}if($t==="living.glassRailing"||$t==="living.railingHorizontal"||$t==="living.railingVertical"||$t==="railings.glassFrameless"){const xn=Math.round((al.heightMm??0)/10);return{widthLabel:o("dimensions.length",{defaultValue:"אורך"}),widthCm:Ie,minWidthCm:40,maxWidthCm:800,heightLabel:o("dimensions.height",{defaultValue:"גובה"}),heightCm:xn,minHeightCm:70,maxHeightCm:150,onWidthChange:Oe=>Ph({widthMm:Oe*10}),onHeightChange:Oe=>Ph({heightMm:Oe*10})}}return null})(),sN=(()=>{if(!gr||al||zM)return null;if(gr.kind==="polygon"&&gr.sourceTool==="rectangle"&&Xr(gr.vertices))return gr;if(gr.kind!=="facePatch")return null;const $t=Wt.find(xn=>xn.kind==="polygon"&&xn.id===gr.hostEntityId&&xn.sourceTool==="rectangle"&&!!Xr(xn.vertices));if(!$t)return null;const Ie=$t.groupId?Se.find(xn=>xn.id===$t.groupId):null;return Ie!=null&&Ie.rigid?null:$t})(),Ah=(()=>{const $t=gr==null?void 0:gr.groupId;if(!$t||al)return null;const Ie=Se.find(Oe=>Oe.id===$t);return Ie&&Wt.filter(Oe=>Oe.kind==="polygon"&&Oe.groupId===$t).length>=2?Ie:null})(),Tl=Ah?Zg(Wt,Ah.id):null,Tk=Ah&&Tl?{title:o("sketchElement.wholeFurnitureSize",{defaultValue:"גודל הרהיט כולו"}),description:o("sketchElement.wholeUnitDescription",{defaultValue:"משנה את היחידה כולה יחד."}),helperText:o("sketchElement.partsRedistributeHint",{defaultValue:"החלקים מתחלקים מחדש אוטומטית. לעריכת חלק בודד — בחר אותו במודל."}),widthCm:Math.round(Tl.widthMm/10),depthCm:Math.round(Tl.depthMm/10),heightCm:Math.round(Tl.heightMm/10),minWidthCm:Math.min(Math.round(c_/10),Math.round(Tl.widthMm/10)),minDepthCm:Math.min(Math.round(d_/10),Math.round(Tl.depthMm/10)),minHeightCm:Math.min(Math.round(u_/10),Math.round(Tl.heightMm/10)),maxWidthCm:Math.max(600,Math.round(Tl.widthMm/10)+100),maxDepthCm:Math.max(300,Math.round(Tl.depthMm/10)+100),maxHeightCm:Math.max(320,Math.round(Tl.heightMm/10)+50),onWidthChange:$t=>TM(Ah.id,{widthMm:Math.round($t*10)}),onDepthChange:$t=>TM(Ah.id,{depthMm:Math.round($t*10)}),onHeightChange:$t=>TM(Ah.id,{heightMm:Math.round($t*10)}),baseHeightCm:Math.round(Tl.baseHeightMm/10),minBaseHeightCm:0,maxBaseHeightCm:250,onBaseHeightChange:$t=>{const Ie=Math.max(0,Math.round($t*10))-Tl.baseHeightMm;if(Ie===0)return;const xn=Ah.id;qe(Oe=>Oe.map(Jo=>Jo.kind==="polygon"&&Jo.groupId===xn?{...Jo,baseHeightMm:Math.max(0,Math.round((Jo.baseHeightMm??0)+Ie))}:Jo))}}:null,_i=zM??sN,Ex=_i?Xr(_i.vertices):null,ll=_i!=null&&_i.groupId?Se.find($t=>$t.id===_i.groupId)??null:null,sf=!!(ll!=null&&ll.templateId||ll!=null&&ll.presetKind||ll!=null&&ll.sourceJobId||ll!=null&&ll.name&&ll.name!=="רהיט ידני"),rN=!!zM,vd=gr&&gr.kind==="facePatch"?gr:null,Dx=vd?Wt.find($t=>$t.kind==="polygon"&&$t.id===vd.hostEntityId):void 0,$M=vd&&Dx?An(Dx,vd.hostFaceId):null,iN=(()=>{var Fx;if(!vd||!Dx||!$M)return;const $t=vd.id,Ie=Dx.id,xn=vd.points2D.map(fi=>fi.x),Oe=vd.points2D.map(fi=>fi.y),Jo=Math.max(0,Math.round(Math.max(...xn)-Math.min(...xn))),Sl=Math.max(0,Math.round(Math.max(...Oe)-Math.min(...Oe))),aa=Math.round(vd.depthMm??0),Tc=Math.round(((Fx=Xr(Dx.vertices))==null?void 0:Fx.widthMm)??600),Pl=fi=>{qe(Va=>{const Al=Va.find(Ll=>Ll.kind==="polygon"&&Ll.id===Ie);return Al?Va.map(Ll=>Ll.kind==="facePatch"&&Ll.id===$t?fi(Ll,Al):Ll):Va})};return{widthCm:Math.round(Jo/10),heightCm:Math.round(Sl/10),depthMm:aa,minWidthCm:2,maxWidthCm:Math.max(2,Math.round($M.widthMm/10)),minHeightCm:2,maxHeightCm:Math.max(2,Math.round($M.heightMm/10)),minDepthMm:-Tc,maxDepthMm:200,onWidthChange:fi=>Pl((Va,Al)=>xv(Va,Al,Math.round(fi*10),Sl)),onHeightChange:fi=>Pl((Va,Al)=>xv(Va,Al,Jo,Math.round(fi*10))),onDepthChange:fi=>Pl(Va=>({...Va,depthMm:Math.round(fi)})),onNudge:(fi,Va)=>Pl((Al,Ll)=>vW(Al,Ll,fi,Va))}})(),aN=(()=>{const $t=gr==null?void 0:gr.groupId;if(!$t)return;const Ie=Se.find(Oe=>Oe.id===$t);if(!Ie)return;const xn=(()=>
447{if(!pr)return!1;let Oe=1/0,Jo=1/0,Sl=-1/0,aa=-1/0;for(const Tc of Wt)if(Tc.kind==="polygon"&&Tc.groupId===$t)for(const Pl of Tc.vertices)Oe=Math.min(Oe,Pl.x),Jo=Math.min(Jo,Pl.y),Sl=Math.max(Sl,Pl.x),aa=Math.max(aa,Pl.y);return Number.isFinite(Oe)?Sl<pr.minX||Oe>pr.maxX||aa<pr.minY||Jo>pr.maxY:!1})();return{stepMm:je,stepOptionsMm:Mnt,onStepChange:Oe=>ne(Oe),onMove:(Oe,Jo)=>SM($t,Oe,Jo),outOfBounds:xn,wallAttached:!!Ie.wallId}})(),lN=gr?n.jsx(zJ,{entity:gr,selectedFaceId:tr,selectedHostFaceRegion:ms,groupScaleControls:Ik||Tk||(_i&&Ex&&(sf||rN)?{title:o("sketchElement.wholeFurnitureSize",{defaultValue:"גודל הרהיט כולו"}),description:sf?o("sketchElement.wholeUnitDescription",{defaultValue:"משנה את היחידה כולה יחד."}):o("sketchElement.rectangleFacesDescription",{defaultValue:"משנה את המלבן וכל הפאות שעליו יחד."}),helperText:sf?o("sketchElement.partsRedistributeHint",{defaultValue:"החלקים מתחלקים מחדש אוטומטית. לעריכת חלק בודד — בחר אותו במודל."}):o("sketchElement.offsetsStayAttachedHint",{defaultValue:"אוף סטים ומלבנים על פאה נשארים מחוברים למלבן."}),widthLabel:sf?o("dimensions.width",{defaultValue:"רוחב"}):_i.rectangleWallAnchor?o("dimensions.width",{defaultValue:"רוחב"}):o("dimensions.length",{defaultValue:"אורך"}),depthLabel:o("dimensions.depth",{defaultValue:"עומק"}),widthCm:Math.round(Ex.lengthMm/10),depthCm:Math.round(Ex.widthMm/10),heightCm:Math.round((_i.heightMm??0)/10),minWidthCm:sf?40:2,minDepthCm:2,maxWidthCm:Math.max(600,Math.round(Ex.lengthMm/10)+100),maxDepthCm:Math.max(300,Math.round(Ex.widthMm/10)+100),minHeightCm:sf?40:0,maxHeightCm:320,onWidthChange:$t=>{Fh(_i,{lengthMm:Math.round($t*10)})},onDepthChange:$t=>{Fh(_i,{widthMm:Math.round($t*10)})},onHeightChange:$t=>{Fh(_i,{heightMm:Math.round($t*10)})},..._i.groupId||(_i.baseHeightMm??0)>0?{baseHeightCm:Math.round((_i.baseHeightMm??0)/10),minBaseHeightCm:0,maxBaseHeightCm:250,onBaseHeightChange:$t=>{const Ie=_i,Oe=Math.max(0,Math.round($t*10))-(Ie.baseHeightMm??0);if(Oe===0)return;const Jo=Ie.groupId;qe(Sl=>Sl.map(aa=>aa.kind!=="polygon"||!(Jo?aa.groupId===Jo:aa.id===Ie.id)?aa:{...aa,baseHeightMm:Math.max(0,Math.round((aa.baseHeightMm??0)+Oe))}))}}:{}}:void 0),groupMoveControls:aN,groupRotationControls:_i??_x?(()=>{const $t=_i??_x,Ie=$t.id,xn=$t.groupId??null,Oe=xn?Se.find(Tc=>Tc.id===xn):null,Jo=Xr($t.vertices),Sl=Jo?Math.atan2(Jo.uAxis.y,Jo.uAxis.x)*180/Math.PI:0,aa=Yu((Oe==null?void 0:Oe.rotationDeg)??Sl);return{rotationDeg:aa,onRotationChange:Tc=>{var Rk;const Pl=Yu(Tc),Fx=Pl-aa;if(Fx===0)return;const fi=Wt,Va=xn??((Rk=fi.find(_u=>_u.id===Ie))==null?void 0:Rk.groupId),Al=Va?fi.filter(_u=>_u.groupId===Va).map(_u=>_u.id):[Ie];if(Al.length===0)return;const Ll=em(fi,Al);if(!Ll)return;const XM=k3(fi,Al,Ll,Fx),YM=Oe?o1({group:Oe,prevEntities:fi,nextEntities:XM,frame:wx(Oe)}):{kind:"keep"};qe(YM.kind==="detach"&&Oe?r1(XM,Oe.id):XM),xn&&jn(_u=>(YM.kind==="keep"?_u:s1(_u,xn,YM)).map(GM=>GM.id===xn?{...GM,rotationDeg:Pl}:GM))}}})():void 0,facePatchControls:iN,measurementUnit:$e,rectangleControls:!al&&Fn&&gr.id===Fn.id&&Ke?{lengthInputCm:bk(Ic("length")),widthInputCm:bk(Ic("width")),heightInputCm:lC(),edges:Mo,selectedEdgeIndex:ls,wallAnchor:Fn.rectangleWallAnchor,canEditDimensions:!!Ke,onDimensionChange:cC,onDimensionCommit:dC,onDimensionFocus:uC,onDimensionBlur:hC,onEdgeSelect:Qo,onEdgeLengthChange:mC,onEdgeLengthCommit:PM}:void 0}):null,cN=n.jsx(wy,{entities:Wt,furnitureGroups:Se,selectedEntityId:pn,onEntitiesChange:qe,onFurnitureGroupsChange:jn,onSelectedEntityChange:Ba,fpIsDark:an,modelCenterMm:wM,measurementUnit:$e,placementMode:Jt?"immediate":"selectThenClick",selectPlacedTemplateHost:!Jt,selectedTemplateId:Jm,onTemplateSelect:EC,userTemplates:ld,userTemplatesLoading:lh,userTemplatesError:cd,defaultUserTemplateName:uu,onSaveUserTemplate:dd,onRenameUserTemplate:ch,onDeleteUserTemplate:dh,onUserTemplateSelect:DC,onRequestOrbitView:()=>{var $t;return($t=ea.current)==null?void 0:$t.setCameraPreset("orbit")},elementContent:lN}),dN={projectAndPlan:T,openings:q0,floor:KC,walls:zC,beams:OM,furniture:Nl,ceiling:eN,roof:n.jsx(nQ,{value:rs,hostState:Hs,visible:nu,onVisibilityChange:rx,onDelete:gh,onChange:ya,onStyleSelect:il,contourEditing:Wi,onStartContourEdit:eM,onStopContourEdit:bh,onResetContour:nM,savedTiles:lu,onUploadTile:xd,onRemoveTile:cu,onRenameTile:du,personalAssetsLocked:!l,onPremiumRequired:Br,measurementUnit:$e}
447),environment:n.jsx(WZ,{value:Ql,onChange:tc,onRefitLot:tM,canRefit:sx}),smartAgent:nN,sketchShape:null,sketchTemplates:cN,settings:oN};return n.jsx(YQ,{open:K,onClose:jt,onShowPanel:dt,viewportFrameRef:rr,fpIsDark:an,mainView:Te,viewScope:ho,sectionVisibility:fn,onSectionVisibilityChange:ys,sectionOrder:hn,onSectionOrderChange:_o,sectionContents:dN,sectionPresentation:lr?{furniture:{labelKey:"blenderMaterials.sectionTitle",labelFallback:"ריצוף וחומרי המודל",icon:O_}}:void 0,sectionsOpen:Yt,onSectionsOpenChange:Ut,sketchToolActive:Xy(On),blankSketchSession:Jt,scrollSectionIntoView:D0})})(),h==="trace"&&!(Te==="3d"&&qi==="inside")?n.jsx(wQ,{canUndo:c0,canRedo:d0,onUndo:Pm,onRedo:Am,placement:Te==="2d"?"floatingTopLeft":"floating"}):null,h==="trace"&&Te==="2d"?n.jsxs(n.Fragment,{children:[n.jsx(knt,{isDark:an,onPan:B6}),n.jsx(vnt,{onZoomIn:mk,onZoomOut:fk})]}):null,(h==="upload"||is)&&n.jsx(jnt,{imageUrl:C,onFile:y=>{nc()||V(y)},onLoad:de,onContinue:Mu,onStartBlankSketch:mo,onScanWithAi:mx,onScanWithAiSmp:vM,showAiScan:a,postCalibrationChoice:is,savedProjects:In,loadingProjects:fe,onSelectProject:ue,onBackToDashboard:s?()=>s("/dashboard"):void 0}),h==="detecting"&&n.jsx(JQ,{visible:!0,stage:"enhancing"}),n.jsx(unt,{variant:Qb,onClose:()=>Rm(null),onUpgrade:()=>{Rm(null),s&&s("/billing?locked=boardstyler")}}),h==="trace"&&wt?n.jsx("div",{className:"absolute inset-0 z-40 flex items-center justify-center bg-black/35 p-4 backdrop-blur-[2px]",dir:r.dir(),children:n.jsxs("div",{className:O("w-full max-w-[420px] rounded-2xl border p-5 text-start shadow-[0_18px_60px_rgba(0,0,0,0.28)]",an?"border-white/12 bg-[#141416] text-white":"border-[#182137]/12 bg-white text-[#182137]"),children:[n.jsxs("div",{className:"mb-4 flex items-start justify-between gap-3",children:[n.jsxs("div",{children:[n.jsx("div",{className:O("text-xs font-semibold",an?"text-[#EC7357]":"text-[#D84B2E]"),children:"Parser V2"}),n.jsx("h3",{className:"mt-1 font-heebo text-xl font-black leading-tight",children:o("scanReview.title",{defaultValue:"אשרו את תוצאת הסריקה"})})]}),n.jsx("button",{type:"button",onClick:zt,className:O("flex h-8 w-8 shrink-0 items-center justify-center rounded-md transition-colors",an?"bg-white/8 hover:bg-white/12":"bg-[#182137]/6 hover:bg-[#182137]/10"),"aria-label":o("accessibility.rejectScan",{defaultValue:"דחה סריקה"}),title:o("accessibility.rejectScan",{defaultValue:"דחה סריקה"}),children:n.jsx(Gr,{className:"h-4 w-4",strokeWidth:2.2})})]}),n.jsxs("div",{className:O("grid grid-cols-3 gap-2 text-sm",an?"text-white/72":"text-[#182137]/72"),children:[n.jsxs("div",{className:O("rounded-lg px-3 py-2",an?"bg-white/6":"bg-[#F7F4EF]"),children:[n.jsx("div",{className:"text-[11px] opacity-65",children:o("scanReview.walls",{defaultValue:"קירות"})}),n.jsx("div",{className:"text-lg font-bold",children:((_k=wt.walls)==null?void 0:_k.length)??0})]}),n.jsxs("div",{className:O("rounded-lg px-3 py-2",an?"bg-white/6":"bg-[#F7F4EF]"),children:[n.jsx("div",{className:"text-[11px] opacity-65",children:o("scanReview.openings",{defaultValue:"פתחים"})}),n.jsx("div",{className:"text-lg font-bold",children:((Ek=wt.openings)==null?void 0:Ek.length)??0})]}),n.jsxs("div",{className:O("rounded-lg px-3 py-2",an?"bg-white/6":"bg-[#F7F4EF]"),children:[n.jsx("div",{className:"text-[11px] opacity-65",children:o("scanReview.rooms",{defaultValue:"חדרים"})}),n.jsx("div",{className:"text-lg font-bold",children:((Dk=wt.rooms)==null?void 0:Dk.length)??0})]})]}),(wt.warnings??[]).length>0?n.jsx("div",{className:O("mt-3 rounded-lg px-3 py-2 text-xs leading-relaxed",an?"bg-[#EC7357]/12 text-[#FFD4CA]":"bg-[#EC7357]/10 text-[#7A2A18]"),children:(wt.warnings??[]).slice(0,2).join(" ")}):null,(Fk=wt.overlay)!=null&&Fk.url||(Ck=wt.overlay)!=null&&Ck.image_base64?n.jsx("div",{className:O("mt-3 overflow-hidden rounded-lg border",an?"border-white/10":"border-[#182137]/10"),children:n.jsx("img",{src:wt.overlay.url??wt.overlay.image_base64??"",alt:"",className:"max-h-[240px] w-full object-contain"})}):null,n.jsxs("div",{className:"mt-5 flex gap-2",children:[n.jsx("button",{type:"button",onClick:zt,className:O("flex-1 rounded-xl border py-3 text-sm font-bold transition-colors",an?"border-white/12 text-white/80 hover:bg-white/8":"border-[#182137]/12 text-[#182137] hover:bg-[#F7F4EF]"),children:o("scanReview.reject",{defaultValue:"דחה"})}),n.jsx("button",{type:"button",onClick:yt,className:"flex-1 rounded-xl bg-[#336CFF] py-3 text-sm font-bold text-white shadow-[0_8px_20px_rgba(51,108,255,0.25)] transition-transform hover:brightness-105 active:scale-[0.99]",children:o("scanReview.apply",{defaultValue:"החל קירות ופתחים"})})]})]})}):null,Ne&&n.jsx("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/30 backdrop-blur-[2px]",children:n.jsx("div",{dir:r.dir(),className:"bg-white/95 backdrop-blur-xl rounded-2xl shadow-[0_8px_40px_rgba(0,0,0,0.12)] max-w-[520px] w-full mx-4 border border-white/60",children:n.jsxs("div",{className:"p-7 space-y-4",children:[n.jsx("h2",{className:"text-xl font-bold text-gray-900 text-center tracking-tight",children:o("welcomeGuide.title",{defaultValue:"סימון קירות"})}),n.jsxs("p",{className:"text-[14px] text-gray-500 text-center leading-relaxed",children:[o("welcomeGuide.description",{defaultValue:"צפה וראה איך לסמן קירות מנקודה לנקודה באופן רציף."}),n.jsx("br",{}),n.jsx("span",{className:"text-gray-400",children:o("welcomeGuide.openingsLater",{defaultValue:"חלונות ודלתות נוסיף אחרי."})})]}),n.jsx("div",{className:"mx-auto w-[280px] h-[280px] rounded-xl overflow-hidden bg-gray-50 border border-gray-100",children:n.jsx("video",{src:"https://kibuqatinwtuqlzmryvx.supabase.co/storage/v1/object/public/canvas-uploads/8cd433c2-5d0e-4675-a902-4fbb41ebfd67/1775446812461.mp4",autoPlay:!0,loop:!0,muted:!0,playsInl
447ine:!0,className:"w-full h-full object-cover object-[42%_center]"})}),n.jsx("button",{onClick:async()=>{if(Le(!1),t&&A)try{await Os(void 0,{navigateOnCreate:!0}),J0(t).then(y=>Rn(y)).catch(()=>{})}catch{}},className:"w-full py-2.5 rounded-xl bg-gradient-to-b from-[#EC7357] to-[#D84B2E] hover:from-[#f08068] hover:to-[#C04428] text-white font-semibold text-[13px] transition-colors cursor-pointer shadow-sm",children:o("welcomeGuide.start",{defaultValue:"ברור לי, בואו נתחיל"})})]})})})]})}),Mk?n.jsx(oQ,{hint:$6,info:X6,toolContent:Mk}):null]})}const j_="floorplan.canvasPanPad.position.v1";function knt({isDark:t,onPan:e}){const{t:s}=yn(),o=m.useRef(null),r=m.useRef(null),[i,a]=m.useState(null),l=m.useCallback(b=>{const M=o.current,g=M==null?void 0:M.parentElement;if(!M||!g)return b;const w=g.getBoundingClientRect(),k=M.getBoundingClientRect(),_=10;return{x:Math.min(Math.max(_,b.x),Math.max(_,w.width-k.width-_)),y:Math.min(Math.max(_,b.y),Math.max(_,w.height-k.height-_))}},[]);m.useEffect(()=>{const b=o.current,M=b==null?void 0:b.parentElement;if(!b||!M)return;const g=M.getBoundingClientRect(),w=b.getBoundingClientRect();let k={x:42,y:Math.max(14,g.height-w.height-96)};try{const _=window.localStorage.getItem(j_),j=_?JSON.parse(_):null;j&&typeof j.x=="number"&&Number.isFinite(j.x)&&typeof j.y=="number"&&Number.isFinite(j.y)&&(k={x:j.x,y:j.y})}catch{}a(l(k))},[l]),m.useEffect(()=>{const b=()=>{a(M=>M&&l(M))};return window.addEventListener("resize",b),()=>window.removeEventListener("resize",b)},[l]);const c=m.useCallback(b=>{try{window.localStorage.setItem(j_,JSON.stringify(b))}catch{}},[]),d=b=>{if(!(b instanceof Element))return null;const M=b.closest("[data-pan-direction]"),g=M==null?void 0:M.dataset.panDirection;return g==="up"||g==="down"||g==="left"||g==="right"?g:null},u=b=>{b.stopPropagation();const M=i??{x:42,y:96};r.current={pointerId:b.pointerId,startX:b.clientX,startY:b.clientY,originX:M.x,originY:M.y,moved:!1,pressDirection:d(b.target)},b.currentTarget.setPointerCapture(b.pointerId)},h=b=>{b.stopPropagation();const M=r.current;if(!M||M.pointerId!==b.pointerId)return;const g=b.clientX-M.startX,w=b.clientY-M.startY;g*g+w*w>16&&(M.moved=!0),a(l({x:M.originX+g,y:M.originY+w}))},x=b=>{b.stopPropagation();const M=r.current;if(!M||M.pointerId!==b.pointerId)return;r.current=null;try{b.currentTarget.releasePointerCapture(b.pointerId)}catch{}const g=l({x:M.originX+b.clientX-M.startX,y:M.originY+b.clientY-M.startY});if(a(g),M.moved){c(g);return}M.pressDirection&&e(M.pressDirection)},f=(b,M)=>{b.key!=="Enter"&&b.key!==" "||(b.preventDefault(),b.stopPropagation(),e(M))},p={up:s("accessibility.moveUp",{defaultValue:"הזז למעלה"}),down:s("accessibility.moveDown",{defaultValue:"הזז למטה"}),left:s("accessibility.moveLeft",{defaultValue:"הזז שמאלה"}),right:s("accessibility.moveRight",{defaultValue:"הזז ימינה"})};return n.jsx("div",{ref:o,className:O("pointer-events-auto absolute z-20 cursor-grab touch-none select-none rounded-full border p-1.5 font-heebo backdrop-blur-md active:cursor-grabbing",t?"border-white/10 bg-[#090B0F]/88 shadow-[0_8px_26px_rgba(0,0,0,0.38)]":"border-[#182137]/10 bg-[#F7F4EF]/78 shadow-[0_8px_24px_rgba(24,33,55,0.12)]"),style:{left:(i==null?void 0:i.x)??42,top:(i==null?void 0:i.y)??96,visibility:i?"visible":"hidden"},onPointerDown:u,onPointerMove:h,onPointerUp:x,onPointerCancel:x,onWheel:b=>b.stopPropagation(),"aria-label":s("accessibility.panCanvas",{defaultValue:"הזזת התוכנית על הקנבס"}),role:"toolbar",dir:"ltr",children:n.jsx(Tb,{size:"sm",isDark:t,hideCenter:!0,labels:p,directionButtonProps:{up:{"data-pan-direction":"up",onKeyDown:b=>f(b,"up"),className:"cursor-pointer"},down:{"data-pan-direction":"down",onKeyDown:b=>f(b,"down"),className:"cursor-pointer"},left:{"data-pan-direction":"left",onKeyDown:b=>f(b,"left"),className:"cursor-pointer"},right:{"data-pan-direction":"right",onKeyDown:b=>f(b,"right"),className:"cursor-pointer"}}})})}function vnt({onZoomIn:t,onZoomOut:e}){const{t:s}=yn(),o="flex h-9 w-9 items-center justify-center text-[#182137] transition-colors hover:bg-[#F4F1EA]";return n.jsxs("div",{className:"absolute bottom-3 left-3 z-20 flex flex-row items-center rounded-md border border-[#182137]/10 bg-white/90 shadow-[0_4px_14px_rgba(24,33,55,0.12)] backdrop-blur-sm",role:"toolbar","aria-label":s("accessibility.zoomControls",{defaultValue:"זום"}),children:[n.jsx("button",{type:"button","aria-label":s("accessibility.zoomIn",{defaultValue:"התקרבות"}),title:s("accessibility.zoomIn",{defaultValue:"התקרבות"}),onClick:t,className:o,children:n.jsx(pm,{size:17,strokeWidth:2.2})}),n.jsx("div",{className:"h-5 w-px bg-[#182137]/10"}),n.jsx("button",{type:"button","aria-label":s("accessibility.zoomOut",{defaultValue:"התרחקות"}),title:s("accessibility.zoomOut",{defaultValue:"התרחקות"}),onClick:e,className:o,children:n.jsx(Pp,{size:17,strokeWidth:2.2})})]})}function jnt({imageUrl:t,onFile:e,onLoad:s,onContinue:o,onStartBlankSketch:r,onScanWithAi:i,onScanWithAiSmp:a,showAiScan:l,postCalibrationCh
447oice:c=!1,savedProjects:d,loadingProjects:u,onSelectProject:h,onBackToDashboard:x}){const f=xc(),{t:p,i18n:b}=yn(),{isRTL:M}=Yd(),[g,w]=m.useState(!1),[k,_]=m.useState(""),[j,v]=m.useState(""),[C,N]=m.useState("upload"),P=!!t,L=m.useMemo(()=>{const B=j.trim().toLocaleLowerCase(b.language);return B?d.filter(R=>[R.name,R.id,R.image_filename].filter(Boolean).some(z=>String(z).toLocaleLowerCase(b.language).includes(B))):d},[j,d]),A=()=>{if(c)return;const B=parseFloat(k);return B>0?B:void 0},W=O("w-full max-w-[780px] overflow-hidden rounded-[24px] border text-right shadow-[0_30px_90px_rgba(24,33,55,0.24)] transition-colors font-heebo",f?"border-white/10 bg-[#141416] shadow-[0_24px_80px_rgba(0,0,0,0.55)]":"border-[#182137]/10 bg-white shadow-[0_8px_40px_rgba(24,33,55,0.1)]"),S="fixed inset-0 z-50 flex items-center justify-center bg-black/45 backdrop-blur-sm p-4";return C==="projects"?n.jsx("div",{className:S,dir:M?"rtl":"ltr",children:n.jsxs("div",{className:W,children:[n.jsxs("div",{className:O("relative overflow-hidden border-b px-6 pb-5 pt-5 sm:px-8",f?"border-white/10 bg-[#141416]":"border-[#182137]/8 bg-white"),children:[n.jsx("div",{className:"pointer-events-none absolute -start-12 -top-16 h-40 w-40 rounded-full border border-[#D85D43]/20"}),n.jsx("div",{className:"pointer-events-none absolute -start-5 -top-9 h-28 w-28 rounded-full border border-[#D85D43]/15"}),n.jsxs("div",{className:"relative flex items-start justify-between gap-4",children:[n.jsxs("button",{type:"button",onClick:()=>N("upload"),className:O("flex min-h-11 items-center gap-1.5 rounded-xl px-3 text-[12px] font-bold transition-all",f?"text-white/55 hover:bg-white/10 hover:text-white":"text-[#182137]/55 hover:bg-[#F7F4EF] hover:text-[#182137]"),children:[n.jsx(_1,{className:"h-3.5 w-3.5"}),p("onboarding.back",{defaultValue:"חזרה"})]}),n.jsxs("div",{className:"text-right",children:[n.jsxs("div",{className:O("mb-1 flex items-center justify-end gap-2 text-[10px] font-bold tracking-[0.16em]",f?"text-[#EC7357]":"text-[#D85D43]"),children:[n.jsx("span",{children:"FLOORPLAN LIBRARY"}),n.jsx("span",{className:"font-mono tracking-normal opacity-60",children:"02"})]}),n.jsx("h2",{className:O("font-heebo text-[28px] font-black leading-none tracking-[-0.04em] sm:text-[34px]",f?"text-white":"text-[#182137]"),style:{fontWeight:900},children:p("onboarding.myProjects",{defaultValue:"התוכניות שלי"})}),n.jsx("p",{className:O("mt-2 text-[12px]",f?"text-white/45":"text-[#182137]/50"),children:p("onboarding.projectsDescription",{defaultValue:"בחרו תוכנית קיימת והמשיכו בדיוק מהמקום שבו עצרתם"})})]})]}),n.jsxs("label",{className:O("relative mt-5 flex h-12 items-center gap-3 rounded-2xl border px-4 transition-all focus-within:ring-2",f?"border-white/10 bg-white/[0.05] focus-within:border-[#EC7357]/60 focus-within:ring-[#EC7357]/10":"border-[#182137]/10 bg-[#F7F4EF]/75 focus-within:border-[#D85D43]/50 focus-within:ring-[#D85D43]/10"),children:[n.jsx(XN,{className:O("h-4 w-4 shrink-0",f?"text-white/45":"text-[#182137]/45")}),n.jsx("input",{value:j,onChange:B=>v(B.target.value),placeholder:p("onboarding.searchProjects",{defaultValue:"חיפוש לפי שם, אות יחידה או מזהה..."}),className:O("min-w-0 flex-1 bg-transparent text-[13px] outline-none placeholder:font-medium",f?"text-white placeholder:text-white/35":"text-[#182137] placeholder:text-[#182137]/40"),"aria-label":p("onboarding.searchProjectsAria",{defaultValue:"חיפוש בתוכניות"})}),n.jsx("span",{className:O("hidden text-[10px] font-bold sm:block",f?"text-white/30":"text-[#182137]/30"),children:p("onboarding.projectCount",{defaultValue:"{{count}} תוכניות",count:L.length})})]})]}),n.jsxs("div",{className:O("max-h-[58vh] overflow-y-auto px-5 py-5 sm:px-8 sm:py-6",f?"bg-[#0E0E10]":"bg-[#F7F4EF]/65"),children:[u?n.jsx("div",{className:"flex items-center justify-center py-14",children:n.jsx("div",{className:O("h-7 w-7 animate-spin rounded-full border-2 border-t-transparent",f?"border-white/30":"border-[#D84B2E]")})}):d.length===0?n.jsx("div",{className:O("py-12 text-center text-sm",f?"text-white/40":"text-[#182137]/40"),children:p("onboarding.noSavedProjects",{defaultValue:"אין פרויקטים שמורים"})}):L.length===0?n.jsx("div",{className:O("rounded-2xl border border-dashed px-5 py-12 text-center text-sm",f?"border-white/10 text-white/45":"border-[#182137]/15 text-[#182137]/50"),children:p("onboarding.noMatchingProject",{defaultValue:"לא מצאנו תוכנית בשם הזה"})}):n.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:L.map((B,R)=>n.jsxs("button",{type:"button",onClick:()=>h(B),className:O("group relative flex min-h-[132px] w-full items-stretch gap-4 overflow-hidden rounded-2xl border p-3 text-right shadow-[0_3px_0_rgba(24,33,55,0.06)] transition-all duration-200 hover:-translate-y-0.5 hover:shadow-[0_10px_24px_rgba(24,33,55,0.10)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#D85D43]",f?"border-white/10 bg-[#1A1A1B] hover:border-[#
447EC7357]/50":"border-[#182137]/8 bg-white hover:border-[#D85D43]/35"),children:[n.jsxs("div",{className:O("relative mt-0.5 h-[104px] w-[116px] shrink-0 overflow-hidden rounded-xl border [perspective:500px]",f?"border-white/10 bg-[#252526]":"border-[#182137]/10 bg-[#E0DFD8]"),children:[n.jsxs("div",{className:"absolute inset-2 rotate-[-5deg] skew-y-[-3deg] overflow-hidden rounded-md border border-white/40 bg-[#E8E3DB] shadow-[5px_7px_0_rgba(24,33,55,0.12)]",children:[B.thumbnail_url?n.jsx("img",{src:B.thumbnail_url,alt:"",className:"h-full w-full object-cover"}):n.jsx("div",{className:"h-full w-full bg-[linear-gradient(90deg,transparent_48%,rgba(24,33,55,.14)_49%,transparent_51%),linear-gradient(0deg,transparent_48%,rgba(24,33,55,.14)_49%,transparent_51%)] bg-[length:22px_22px]"}),n.jsx("div",{className:"pointer-events-none absolute inset-0 bg-gradient-to-tr from-[#182137]/20 via-transparent to-white/25"})]}),n.jsx("span",{className:"absolute bottom-1.5 start-2 rounded-md bg-[#182137] px-1.5 py-0.5 font-mono text-[8px] font-bold text-[#F7F4EF]",children:"ISO"})]}),n.jsxs("div",{className:"flex min-w-0 flex-1 flex-col justify-between py-1",children:[n.jsxs("div",{className:O("flex items-start gap-1.5 text-[15px] font-black leading-tight",f?"text-white":"text-[#182137]"),children:[B.training_contributed?n.jsx("span",{className:"shrink-0",title:p("onboarding.contributedToTraining",{defaultValue:"נתרמה לאימון המודל"}),children:"🎓"}):null,n.jsx("span",{className:"truncate",children:B.name})]}),n.jsxs("div",{className:O("flex items-center justify-between gap-2 text-[10px]",f?"text-white/40":"text-[#182137]/45"),children:[n.jsx("span",{children:new Date(B.updated_at).toLocaleDateString(b.language)}),n.jsx("span",{className:O("font-bold",f?"text-[#EC7357]":"text-[#D85D43]"),children:p("onboarding.wallCount",{defaultValue:"{{count}} קירות",count:B.walls.length})})]}),n.jsxs("span",{className:O("flex items-center gap-1 text-[11px] font-bold opacity-0 transition-opacity group-hover:opacity-100",f?"text-[#EC7357]":"text-[#D85D43]"),children:[p("onboarding.open",{defaultValue:"פתיחה"})," ",n.jsx(nT,{className:"h-3.5 w-3.5"})]})]})]},B.id))}),x?n.jsx("div",{className:O("sticky bottom-0 border-t px-3 py-3",f?"border-white/10 bg-[#0E0E10]":"border-[#182137]/8 bg-[#F7F4EF]/50"),children:n.jsxs("button",{type:"button",onClick:x,className:O("flex w-full items-center justify-center gap-2 rounded-xl py-3 text-[13px] font-bold transition-all",f?"text-[#FF6B6B] hover:bg-[#FF6B6B]/10":"text-[#E60023] hover:bg-[#E60023]/08"),children:[n.jsx($u,{className:"h-4 w-4 shrink-0",strokeWidth:2.2,"aria-hidden":!0}),p("onboarding.backToDashboard",{defaultValue:"חזרה לדשבורד"})]})}):null]})]})}):n.jsx("div",{className:S,dir:M?"rtl":"ltr",children:n.jsx("div",{className:W,children:P?n.jsxs("div",{className:O("space-y-4 p-6",f?"bg-[#141416]":"bg-white"),children:[n.jsx("h2",{className:O("font-heebo text-[22px] leading-tight",f?"text-white":"text-[#182137]"),style:{fontWeight:900,letterSpacing:"-0.02em"},children:c?p("onboarding.chooseNext",{defaultValue:"בחרו איך להמשיך"}):p("onboarding.buildingSize",{defaultValue:"גודל המבנה"})}),n.jsx("p",{className:O("text-[12px] leading-relaxed",f?"text-white/45":"text-[#182137]/50"),children:c?p("onboarding.calibrationSaved",{defaultValue:"הכיול נשמר. עכשיו אפשר לסרוק אוטומטית או להמשיך לשרטוט ידני."}):p("onboarding.areaDescription",{defaultValue:"הזינו שטח דירה/מבנה (מ״ר) לכיול. אפשר לדלג."})}),c?null:n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("label",{className:O("text-[12px] font-medium",f?"text-white/55":"text-[#182137]/60"),children:p("onboarding.areaLabel",{defaultValue:"שטח במ״ר"})}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("input",{type:"number",min:1,step:1,placeholder:p("onboarding.areaPlaceholder",{defaultValue:"לדוגמה: 120"}),value:k,onChange:B=>_(B.target.value),onKeyDown:B=>{B.key==="Enter"&&o(A())},className:O("flex-1 rounded-xl border px-3 py-2.5 text-sm text-right transition-all",f?"border-white/15 bg-[#0A0A0A] text-white placeholder:text-white/30 focus:border-[#
447EC7357]/50 focus:outline-none focus:ring-2 focus:ring-[#EC7357]/20":"border-[#182137]/12 bg-white text-[#182137] focus:border-[#D84B2E] focus:outline-none focus:ring-2 focus:ring-[#EC7357]/20"),autoFocus:!0}),n.jsx("span",{className:O("whitespace-nowrap text-xs",f?"text-white/40":"text-[#182137]/40"),children:p("onboarding.squareMeters",{defaultValue:"מ״ר"})})]})]}),n.jsx("button",{type:"button",onClick:()=>{o(A())},className:"w-full rounded-xl bg-gradient-to-r from-[#EC7357] to-[#D84B2E] py-3 text-[14px] font-bold text-white shadow-[0_8px_24px_rgba(216,75,46,0.35)] transition-transform hover:brightness-105 active:scale-[0.99]",children:c?p("onboarding.continueManual",{defaultValue:"המשך לשרטוט ידני"}):p("onboarding.continue",{defaultValue:"המשך"})}),x?n.jsxs("button",{type:"button",onClick:x,className:O("flex w-full items-center justify-center gap-2 rounded-xl py-2.5 text-[13px] font-semibold transition-colors",f?"text-[#FF6B6B] hover:bg-[#FF6B6B]/10":"text-[#E60023] hover:bg-[#E60023]/08"),children:[n.jsx($u,{className:"h-4 w-4 shrink-0",strokeWidth:2.2,"aria-hidden":!0}),p("onboarding.backToDashboard",{defaultValue:"חזרה לדשבורד"})]}):null]}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:O("relative flex h-[162px] shrink-0 flex-col overflow-hidden p-4",f?"bg-[#1A1A1A]":"bg-[#F7F4EF]"),children:[n.jsxs("div",{className:O("absolute end-3 top-3 z-10 flex items-center gap-2 text-[10px] font-semibold uppercase tracking-[0.14em]",f?"text-white/70":"text-[#182137]/70"),children:[n.jsx("span",{children:"בורדסטיילר"}),n.jsx("span",{className:O("rounded-sm px-1.5 py-0.5 font-mono text-[10px] normal-case tracking-normal",f?"bg-white/10 text-white":"bg-[#182137]/10 text-[#182137]"),children:"01"})]}),n.jsx("div",{className:"pointer-events-none flex flex-1 items-center justify-center pt-2",children:n.jsx("div",{className:"h-[100px] w-full max-w-[220px]",children:n.jsx(vT,{isDark:f})})}),n.jsx("div",{className:O("absolute bottom-3 start-3 z-10 flex h-9 w-9 items-center justify-center rounded-lg",f?"bg-white/10 text-white":"bg-white text-[#182137] shadow-[0_2px_8px_rgba(24,33,55,0.1)]"),children:n.jsx(O_,{className:"h-4 w-4",strokeWidth:2.2})})]}),n.jsxs("div",{className:O("space-y-4 p-5",f?"border-t border-white/[0.08] bg-[#141416]":"border-t border-[#182137]/[0.06] bg-white"),children:[n.jsxs("div",{className:"space-y-1",children:[n.jsx("h2",{className:O("font-heebo text-[22px] leading-[1.05] sm:text-[24px]",f?"text-white":"text-[#182137]"),style:{fontWeight:900,letterSpacing:"-0.02em"},children:p("onboarding.howToStart",{defaultValue:"איך תרצו להתחיל?"})}),n.jsx("p",{className:O("text-[12px] leading-relaxed",f?"text-white/50":"text-[#182137]/50"),children:p("onboarding.startDescription",{defaultValue:"העלאת תוכנית דו־ממדית או סקיצה ישירות בתלת־ממד"})})]}),n.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:[n.jsxs("div",{className:"flex min-h-0 flex-col gap-2",children:[n.jsxs("div",{className:"space-y-0.5 px-0.5",children:[n.jsx("h3",{className:O("text-[13px] font-bold leading-tight",f?"text-white/95":"text-[#182137]"),children:p("onboarding.uploadPlan",{defaultValue:"העלה תוכנית קומה"})}),n.jsx("p",{className:O("text-[11px] leading-snug",f?"text-white/45":"text-[#182137]/45"),children:p("onboarding.uploadFormats",{defaultValue:"גררו או לחצו — PNG,‏ JPG,‏ SVG"})})]}),n.jsxs("button",{type:"button",onDragOver:B=>{B.preventDefault(),w(!0)},onDragLeave:()=>w(!1),onDrop:B=>{B.preventDefault(),w(!1),B.dataTransfer.files[0]&&e(B.dataTransfer.files[0])},onClick:()=>{const B=document.createElement("input");B.type="file",B.accept=".svg,.png,.jpg,.jpeg",B.onchange=()=>{var R;(R=B.files)!=null&&R[0]&&e(B.files[0])},B.click()},className:O("flex min-h-[148px] flex-1 flex-col items-center justify-center gap-2 rounded-xl border-2 border-dashed px-2 py-6 transition-all duration-200",g?"scale-[1.01] border-[#EC7357] bg-[#EC7357]/12 shadow-[0_0_0_1px_rgba(236,115,87,0.3)]":f?"border-white/20 bg-[#0A0A0A] hover:border-white/30 hover:bg-[#0D0D0F]":"border-[#182137]/15 bg-[#F7F4EF] hover:border-[#D84B2E]/35 hover:bg-white"),children:[n.jsx("div",{className:O("flex h-11 w-11 items-center justify-center rounded-xl",g?"bg-[#EC7357]/25 text-[#EC7357]":f?"bg-white/5 text-white/50":"bg-[#182137]/5 text-[#182137]/40"),children:n.jsx(Ap,{className:"h-5 w-5",strokeWidth:2})}),n.jsx("span",{className:O("text-center text-[12px] font-medium leading-snug",f?"text-white/55":"text-[#182137]/55"),children:p("onboarding.dropPlan",{defaultValue:"גרור תוכנית לכאן או לחץ לבחירה"})})]})]}),n.jsxs("div",{className:"flex min-h-0 flex-col gap-2",children:[n.jsxs("div",{className:"space-y-0.5 px-0.5",children:[n.jsx("h3",{className:O("text-[13px] font-bold leading-tight",f?"text-white/95":"text-[#182137]"),children:p("onboarding.startSketch",{defaultValue:"שרטט סקיצה מאפס"})}),n.jsx("p",{className:O("text-[11px] leading-snug",f?"text-white/45":"text-[#182137]/45"),children:p("onboarding.sketchDescription",{defaultValue:"קו, מלבן, עיגול, פוליגון ואופסט — ישר בתלת־ממד"})})]}),n.jsxs("button",{type:"button",onClick:()=>r(),className:O("flex min-h-[148px] flex-1 flex-col items-center justify-center gap-2 rounded-xl border-2 border-dashed px-3 py-6 text-center transition-all duration-200",f?"border-white/20 bg-[#0A0A0A] hover:border-[#
447EC7357]/45 hover:bg-[#141416]":"border-[#182137]/15 bg-[#F7F4EF] hover:border-[#D84B2E]/35 hover:bg-white"),children:[n.jsx("div",{className:O("flex h-11 w-11 items-center justify-center rounded-xl",f?"bg-white/5 text-[#EC7357]":"bg-[#182137]/5 text-[#D84B2E]"),children:n.jsx(op,{className:"h-5 w-5",strokeWidth:2})}),n.jsx("span",{className:O("text-[12px] font-semibold leading-snug",f?"text-white/80":"text-[#182137]"),children:p("onboarding.openBlankCanvas",{defaultValue:"פתח קנבס ריק ב־3D"})})]})]})]}),n.jsxs("button",{type:"button",onClick:B=>{B.stopPropagation(),N("projects"),s()},className:O("mt-1 flex w-full items-center justify-between rounded-xl px-4 py-3 text-[13px] font-semibold transition-colors",f?"bg-white/[0.06] text-white/90 hover:bg-white/[0.1]":"bg-[#182137] text-white hover:bg-[#0E1423]"),children:[n.jsx("span",{children:p("onboarding.openSavedProject",{defaultValue:"פתיחת פרויקט שמור"})}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Lw,{className:"h-4 w-4 opacity-80"}),n.jsx(_1,{className:"h-4 w-4 opacity-70"})]})]}),x?n.jsxs("button",{type:"button",onClick:x,className:O("flex w-full items-center justify-center gap-2 rounded-xl py-3 text-[13px] font-semibold transition-colors",f?"text-[#FF6B6B] hover:bg-[#FF6B6B]/10":"text-[#E60023] hover:bg-[#E60023]/08"),children:[n.jsx($u,{className:"h-4 w-4 shrink-0",strokeWidth:2.2,"aria-hidden":!0}),p("onboarding.backToDashboard",{defaultValue:"חזרה לדשבורד"})]}):null]})]})})})}function kot(){const{user:t}=Ww(),{projectId:e}=YN(),s=GN();return n.jsx("div",{className:"floorplan-editor font-heebo",dir:"ltr",style:{width:"100vw",height:"100vh"},children:n.jsx(wnt,{userId:t==null?void 0:t.id,projectId:e,onNavigate:o=>s(o,{replace:!0})})})}export{kot as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.