PageSourceSearch

https://nieruchomoscipodhala.pl/assets/Map3D-CXWFzG0T.js

js nieruchomoscipodhala.pl collected 2026-10-08 07:35:13 UTC 134,939 bytes, 2 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-export-qO9ihxhS.js","assets/vendor-cjs-D6EFhZyk.js"])))=>i.map(i=>d[i]);
2var e=Object.defineProperty;import{r as t,j as a,L as r,u as n,h as o,H as i}from"./vendor-react-DMNGpIRZ.js";import{m as s}from"./vendor-mapbox-DQvQbty9.js";import{V as l,B as c,e as d,u,H as p,U as m}from"./app-shared-DeC6gtjQ.js";import{s as h}from"./home-sections-bottom-CLopf6A6.js";import{u as g}from"./vendor-ui-utils-CwHcxtzl.js";import{u as x}from"./index-iOzchrkN.js";import{M as y}from"./MarkerDragConfirm-Dm1pSDSP.js";import{X as f,av as b,k as w,M as v,aW as j,aA as z,aE as k,i as N,u as S,a4 as C,aB as L,J as F,aX as P,ar as _,aY as M,as as I,aN as E,F as D,B as T,aZ as $,_ as R,c as A,$ as O,a6 as Z,a as W,C as B,al as q,N as U,a_ as G,az as J,a$ as H}from"./vendor-icons-CQq8vWmq.js";import{c as K}from"./vendor-cjs-D6EFhZyk.js";import{C as X,p as Y,k as V}from"./app-config-C4j2-E61.js";import{e as Q,P as ee}from"./pdf-fonts-ByQskoRq.js";import{o as te,b as ae}from"./offerUrl-DdC1qTxq.js";import"./vendor-styling-VH1XAVo5.js";import"./vendor-forms-DMqFZ8fW.js";import"./vendor-motion-CHtcCaB1.js";import"./home-sections-top-CUu-N0G6.js";import"./vendor-query-DWNtL-y1.js";import"./vendor-supabase-DiedMGWA.js";let re=null,ne=null;const oe=e=>new Promise(t=>setTimeout(t,e));async function ie(){if(re)return re;if(ne)return ne;ne=(async()=>{let e=null;for(let a=1;a<=4;a++)try{const{data:e,error:t}=await h.functions.invoke("get-mapbox-token");if(t){const e=t.message??String(t);if(/503|degraded|temporarily unavailable|Failed to fetch|NetworkError|timeout/i.test(e)&&a<4){await oe(400*2**(a-1));continue}throw new Error(`Mapbox token service unavailable: ${e}`)}if(!(null==e?void 0:e.token))throw new Error("Mapbox token missing in response");return re=e.token,re}catch(t){if(e=t,a>=4)break;await oe(400*2**(a-1))}throw e instanceof Error?e:new Error("Mapbox token service unavailable")})();try{return await ne}finally{ne=null}}const se={active:{label:"Dostępna",cls:"bg-emerald-500/90 text-white"},reserved:{label:"Rezerwacja",cls:"bg-amber-500/90 text-white"},sold:{label:"Sprzedana",cls:"bg-zinc-700/90 text-white"},rented:{label:"Wynajęta",cls:"bg-zinc-700/90 text-white"}},le=()=>a.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:a.jsx("path",{d:"M3 8.5 L6.5 12 L13 4"})}),ce=e=>{if("undefined"==typeof window)return 0;const t=window.innerHeight;return"mini"===e?76:"half"===e?Math.round(.44*t):Math.round(.86*t)},de=({property:e,onClose:n,onBalconyView:o,mapMode:i,onToggleMapMode:s})=>{const[u,p]=t.useState(0),[m,h]=t.useState(!1),[g,x]=t.useState("half"),[y,S]=t.useState(null),C=t.useRef(null),L=t.useRef(0),F=t.useRef(!1);t.useEffect(()=>{p(0),h(!1),e&&x("half"),S(null)},[null==e?void 0:e.id]),t.useEffect(()=>{if(!e)return;const t=e=>{"Escape"===e.key&&n()};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[e,n]);const P=!!e,_=(null==e?void 0:e.images)??[],M=e?se[e.status]??{label:e.status,cls:"bg-muted text-foreground"}:null,I=(null==e?void 0:e.matterportUrl)??null,E=t.useMemo(()=>e?function(e,t){const a=(e??"").replace(/\s+/g," ").split(new RegExp("(?<=[.!?])\\s+")).map(e=>e.trim()).filter(e=>e.length>=30&&e.length<=180),r=`${new Intl.NumberFormat("pl-PL").format(t.price)} PLN`,n=[t.area&&t.area>0?`${t.area} m²`:null,t.lot_area&&t.lot_area>0?`działka ${t.lot_area} m²`:null].filter(Boolean).join(" · ");var o;return[...a,`${o=t.type,o?o[0].toUpperCase()+o.slice(1):o} · ${t.location}`,n||"Z prywatnego portfolio Podhala",`Cena: ${r}`].slice(0,3)}(e.description,{type:e.property_type,location:e.location,price:e.price,area:e.area,lot_area:e.lot_area}):[],[e]),D=()=>{if(!F.current)return;F.current=!1;const e=y??ce(g);if(e<56)return S(null),void n();const t=["mini","half","full"];let a="half",r=1/0;for(const n of t){const t=Math.abs(ce(n)-e);t<r&&(r=t,a=n)}x(a),S(null),C.current=null},T=y??(P?ce(g):0);return a.jsxs(a.Fragment,{children:[a.jsx("div",{onClick:n,"aria-hidden":"true",className:l("fixed inset-0 z-40 bg-foreground
2/20 backdrop-blur-[2px] transition-opacity duration-300 sm:hidden",P&&"full"===g?"opacity-100 pointer-events-auto":"opacity-0 pointer-events-none")}),a.jsxs("aside",{role:"dialog","aria-modal":"false","aria-label":e?`Szczegóły oferty: ${e.title}`:"Szczegóły oferty",style:{height:"undefined"!=typeof window&&window.innerWidth<640?`${T}px`:void 0,transition:F.current?"none":"height 320ms cubic-bezier(0.16,1,0.3,1), opacity 300ms, transform 300ms"},className:l("fixed z-50 liquid-glass-luxe map3d-quickview overflow-hidden","left-0 right-0 bottom-0 rounded-t-2xl","sm:left-auto sm:right-4 sm:top-4 sm:bottom-4 sm:w-[400px] sm:h-auto sm:rounded-3xl","transition-opacity duration-[400ms] [transition-timing-function:cubic-bezier(0.16,1,0.3,1)]",P?"opacity-100 translate-y-0 scale-100 sm:translate-x-0 is-open":"opacity-0 translate-y-[15px] scale-95 pointer-events-none sm:translate-y-0 sm:translate-x-[110%]"),children:[a.jsx("div",{role:"button",tabIndex:0,"aria-label":"Przeciągnij, aby zmienić wysokość panelu",onPointerDown:e=>{var t,a;"undefined"!=typeof window&&window.innerWidth>=640||(F.current=!0,C.current=e.clientY,L.current=ce(g),S(L.current),null==(a=(t=e.currentTarget).setPointerCapture)||a.call(t,e.pointerId))},onPointerMove:e=>{if(!F.current||null==C.current)return;const t=e.clientY-C.current,a=Math.max(40,Math.min(window.innerHeight,L.current-t));S(a)},onPointerUp:D,onPointerCancel:D,onClick:()=>{F.current||x(e=>"mini"===e?"half":"half"===e?"full":"mini")},className:"sm:hidden pt-1.5 pb-1 cursor-grab active:cursor-grabbing",children:a.jsx("div",{className:"map3d-sheet-handle"})}),e?a.jsxs("div",{className:"flex flex-col h-full",children:[a.jsxs("div",{className:"sm:hidden flex items-center gap-3 px-4 pb-2",children:[a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsx("div",{className:"text-[13px] font-semibold text-white truncate leading-tight",children:e.title}),a.jsxs("div",{className:"text-[11px] text-[#D4AF37] font-semibold",children:[new Intl.NumberFormat("pl-PL").format(e.price)," PLN",e.area&&e.area>0?a.jsxs("span",{className:"text-white/60 font-normal",children:[" · ",e.area," m²"]}):null]})]}),a.jsx("button",{type:"button",onClick:n,"aria-label":"Zamknij panel",className:"shrink-0 w-8 h-8 rounded-full liquid-glass-luxe flex items-center justify-center text-white",children:a.jsx(f,{className:"w-4 h-4"})})]}),a.jsxs("div",{className:l("relative shrink-0 p-2 sm:block","mini"===g?"hidden":"block"),children:[_.length>0?a.jsxs("div",{className:"relative h-40 sm:h-56 bg-black/40 overflow-hidden rounded-lg",children:[a.jsx("img",{src:_[u],alt:`${e.title} – zdjęcie ${u+1}`,width:800,height:448,loading:"lazy",className:"w-full h-full object-cover",onError:e=>{e.currentTarget.style.display="none"}}),_.length>1&&a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button",onClick:()=>p(e=>_.length?(e-1+_.length)%_.length:0),"aria-label":"Poprzednie zdjęcie",className:"absolute left-2 top-1/2 -translate-y-1/2 w-9 h-9 rounded-full liquid-glass-luxe flex items-center justify-center text-foreground hover:scale-105 transition-transform",children:a.jsx(b,{className:"w-4 h-4"})}),a.jsx("button",{type:"button",onClick:()=>p(e=>_.length?(e+1)%_.length:0),"aria-label":"Następne zdjęcie",className:"absolute right-2 top-1/2 -translate-y-1/2 w-9 h-9 rounded-full liquid-glass-luxe flex items-center justify-center text-foreground hover:scale-105 transition-transform",children:a.jsx(w,{className:"w-4 h-4"})}),a.jsx("div",{className:"absolute bottom-2 left-1/2 -translate-x-1/2 flex gap-1.5 px-2 py-1 rounded-full liquid-glass-luxe",children:_.slice(0,8).map((e,t)=>a.jsx("span",{className:l("h-1.5 rounded-full transition-all",t===u?"bg-[#D4AF37] w-4":"bg-white/40 w-1.5")},t))})]})]}):a.jsx("div",{className:"h-32 bg-black/30 rounded-lg flex items-center justify-center",children:a.jsx(v,{className:"w-8 h-8 text-white/40"})}),a.jsx("button",{type:"button",onClick:n,"aria-label":"Zamknij panel",className:"hidden sm:flex absolute top-3 right-3 w-9 h-9 rounded-full liquid-glass-luxe items-center justify-center text-white hover:scale-105 transition-transform",children:a.jsx(f,{className:"w-4 h-4"})})]}),a.jsxs("div",{className:l("flex-1 overflow-y-auto px-5 py-3 space-y-4 sm:block","mini"===g?"hidden":"block"),children:[a.jsxs("div",{className:"hidden sm:block",children:[a.jsxs("div",{className:"flex items-start gap-2 mb-1",children:[M&&a.jsx("span",{className:l("inline-block px-2 py-0.5 rounded-full text-[10px] font-semibold uppercase tracking-wide",M.cls),children:M.label}),a.jsx(c,{variant:"outline",className:"text-[10px] capitalize bg-white/5 border-white/15 text-white/80",children:e.property_type})]}),a.jsx("h2",{className:"text-lg font-semibold leading-tight font-display text-white",children:e.title}),a.jsxs("p",{className:"text-xs text-white/65 flex items-center gap-1 mt-1",children:[a.jsx(v,{className:"w-3 h-3 text-[#D4AF37]"})," ",e.location]})]}),a.jsxs("div",{className:"hidden sm:flex items-baseline gap-3 flex-wrap",children:[a.jsxs("div",{className:"text-2xl font-bold font-display text-[#D4AF37] leading-none",children:[new Intl.NumberFormat("pl-PL").format(e.price)," ",a.jsx("span",{className:"text-sm font-medium text-white/60",children:"PLN"})]}),e.area&&e.area>0||e.lot_area&&e.lot_area>0?a.jsxs("div",{className:"text-xs text-white/70",children:[e.area&&e.area>0?`${e.area} m²`:null,e.area&&e.lot_area&&e.area>0&&e.lot_area>0?" · ":null,e.lot_area&&e.lot_area>0?`działka ${e.lot_area} m²`:null]}):null]}),a.jsxs("div",{className:"sm:hidden flex items-center gap-2 flex-wrap",children:[M&&a.jsx("span",{className:l("inline-block px-2 py-0.5 rounded-full text-[10px] font-semibold uppercase tracking-wide",M.cls),children:M.label}),a.jsxs("p",{className:"text-[11px] text-white/65 flex items-center gap-1",children:[a.jsx(v,{className:"w-3 h-3 text-[#D4AF37]"})," ",e.location]})]}),E.length>0&&a.jsxs("div",{className:l("full"===g?"block":"hidden","sm:block"),children:[a.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.08em] text-white/55 mb-2",children:"Atuty"}),a.jsx("ul",{className:"quickview-atut-list",children:E.map((e,t)=>a.jsxs("li",{children:[a.jsx(le,{}),a.jsx("span",{children:e})]},t))})]}),I&&a.jsxs("div",{className:l("space-y-2","full"===g?"block":"hidden","sm:block"),children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-[0.08em] text-white/55",children:"Spacer 360°"}),a.jsxs("button",{type:"button",onClick:()=>h(e=>!e),className:"text-[11px] text-[#D4AF37] hover:underline inline-flex items-center gap-1",children:[a.jsx(j,{className:"w-3 h-3"}),m?"Ukryj":"Pokaż"]})]}),m&&a.jsx("div",{className:"relative w-full aspect-video rounded-xl overflow-hidden border border-white/10 bg-black",children:a.jsx("iframe",{src:I,title:`Matterport 360° – ${e.title}
2`,allow:"xr-spatial-tracking; gyroscope; accelerometer; fullscreen",allowFullScreen:!0,loading:"lazy",className:"absolute inset-0 w-full h-full border-0"})})]})]}),a.jsxs("div",{className:l("shrink-0 p-3 border-t border-white/10 bg-black/20 backdrop-blur-md flex flex-col gap-2 sm:flex","mini"===g?"hidden":"flex"),children:[a.jsxs(d,{onClick:()=>o(e),className:"w-full gap-1.5 bg-[#D4AF37] hover:bg-[#c9a430] text-black",size:"sm",children:[a.jsx(z,{className:"w-4 h-4"}),"Widok z balkonu"]}),a.jsxs(d,{type:"button",variant:"outline",size:"sm",onClick:s,"aria-pressed":"3d-satellite"===i,"aria-label":"3d-satellite"===i?"Przełącz na widok 2D":"Przełącz na widok 3D",className:"w-full min-h-[44px] gap-1.5 bg-white/5 border-white/15 text-white hover:bg-white/10 hover:text-white",children:["3d-satellite"===i?a.jsx(k,{className:"w-4 h-4"}):a.jsx(z,{className:"w-4 h-4"}),"3d-satellite"===i?"Widok 2D":"Widok 3D"]}),a.jsx(d,{asChild:!0,variant:"outline",size:"sm",className:"w-full bg-white/5 border-white/15 text-white hover:bg-white/10 hover:text-white",children:a.jsxs(r,{to:`/oferty/${e.slug??e.id}`,className:"gap-1.5",children:["Zobacz pełną ofertę",a.jsx(N,{className:"w-3.5 h-3.5"})]})})]})]}):null]})]})},ue=[15,23,42],pe=[212,175,55],me=[255,255,255],he=[100,116,139],ge=[248,249,252],xe=e=>new Intl.NumberFormat("pl-PL",{style:"currency",currency:"PLN",maximumFractionDigits:0}).format(e),ye={budowlana:"Budowlana (MN/MNU)",zagrodowa:"Zagrodowa (RM)",rolna:"Rolna (R)"};async function fe(e){var t;const{address:a,area_m2:r,c_base_pln:n,c_min_pln:o,c_max_pln:i,mpzp:s,computed_at:l}=e,{default:c}=await K(async()=>{const{default:e}=await import("./vendor-export-qO9ihxhS.js").then(e=>e.j);return{default:e}},__vite__mapDeps([0,1])),d=new c({unit:"mm",format:"a4",orientation:"portrait"});await Q(d);const u=d.internal.pageSize.getWidth(),p=d.internal.pageSize.getHeight(),m=18;var h;d.setFillColor(...ue),d.rect(0,0,u,82,"F"),d.setFillColor(...pe),d.rect(0,0,u,3.5,"F"),d.setFont(ee,"bold"),d.setTextColor(...me),d.setFontSize(22),d.setCharSpace(1.2),d.text("NIERUCHOMOŚCI PODHALA",m,30),d.setCharSpace(0),d.setFont(ee,"normal"),d.setTextColor(...pe),d.setFontSize(10),d.setCharSpace(2.5),d.text("RAPORT WYCENY DZIAŁKI",m,40),d.setCharSpace(0),d.setDrawColor(...pe),d.setLineWidth(.35),d.line(m,45,73,45),d.setFont(ee,"normal"),d.setTextColor(180,195,215),d.setFontSize(8.5),d.text(`Wygenerowano: ${h=l,h.toLocaleDateString("pl-PL",{year:"numeric",month:"long",day:"numeric"})}`,m,52),d.setFont(ee,"bold"),d.setTextColor(...me),d.setFontSize(13.5);const g=d.splitTextToSize(a,u-36-20);d.text(g,m,63),d.setFillColor(212,175,55,18),d.setFillColor(35,50,80),d.roundedRect(u-m-35,12,35,13,3,3,"F"),d.setFont(ee,"bold"),d.setTextColor(...pe),d.setFontSize(7.5),d.setCharSpace(1),d.text("AEstymator v2",u-m-17.5,20,{align:"center"}),d.setCharSpace(0);const x=(u-36)/3;[{label:"POWIERZCHNIA",value:`${r.toLocaleString("pl-PL")} m²`},{label:"MPZP / PRZEZNACZENIE",value:ye[s]??s},{label:"LOKALIZACJA",value:(null==(t=a.split(",").slice(-1)[0])?void 0:t.trim())||"Podhale"}].forEach((e,t)=>{const a=m+t*x,r=x-4;d.setFont(ee,"normal"),d.setTextColor(...he),d.setFontSize(7.5),d.setCharSpace(1.5),d.text(e.label,a,92),d.setCharSpace(0),d.setFont(ee,"bold"),d.setTextColor(...ue),d.setFontSize(10);const n=d.splitTextToSize(e.value,r);d.text(n,a,98),t<2&&(d.setDrawColor(220,225,235),d.setLineWidth(.25),d.line(a+x-2,88,a+x-2,106))}),d.setDrawColor(220,225,235),d.setLineWidth(.3),d.line(m,110,u-m,110);const y=m,f=u-36;if(d.setFillColor(...ge),d.roundedRect(y,118,f,72,4,4,"F"),d.setDrawColor(...pe),d.setLineWidth(.5),d.roundedRect(y,118,f,72,4,4,"S"),d.setFont(ee,"normal"),d.setTextColor(...he),d.setFontSize(8.5),d.setCharSpace(2.5),d.text("SZACOWANA WARTOŚĆ NIERUCHOMOŚCI",u/2,131,{align:"center"}),d.setCharSpace(0),d.setFont(ee,"bold"),d.setTextColor(...pe),d.setFontSize(38),d.text(xe(n),u/2,151,{align:"center"}),d.setDrawColor(...pe),d.setLineWidth(.3),d.line(u/2-22,156,u/2+22,156),d.setFont(ee,"normal"),d.setTextColor(...he),d.setFontSize(9),d.text(`Zakres:  ${xe(o)}  —  ${xe(i)}`,u/2,166,{align:"center"}),d.setFontSize(7.5),d.setTextColor(160,175,195),d.text("(szybka sprzedaż)",u/2-28,172,{al
2ign:"center"}),d.text("(negocjacja)",u/2+28,172,{align:"center"}),d.setFont(ee,"normal"),d.setFontSize(7.5),d.setTextColor(...he),d.text("* Wycena orientacyjna, nie stanowi operatu szacunkowego.",u/2,181,{align:"center"}),e.land_value_pln||e.building_value_pln){d.setFont(ee,"normal"),d.setFontSize(8),d.setTextColor(...ue);const t=[e.land_value_pln?`Grunt: ${xe(e.land_value_pln)}`:null,e.building_value_pln?`Budynek: ${xe(e.building_value_pln)}`:null].filter(Boolean).join("   ·   ");d.text(t,u/2,186,{align:"center"})}d.setFillColor(240,243,248),d.roundedRect(y,200,f,11,2,2,"F"),d.setFont(ee,"normal"),d.setTextColor(...he),d.setFontSize(7.5),d.text(e.source_label||"Wycena na podstawie danych RCiWN + scrapera ofertowego, model AEstymator v2  ·  nieruchomoscipodhala.pl",u/2,207,{align:"center"});const b=[{icon:"✦",text:"Bezpłatna konsultacja"},{icon:"✦",text:"Pełna obsługa prawna"},{icon:"✦",text:"Podhale i okolice"}],w=f/b.length;if(b.forEach((e,t)=>{const a=y+t*w+w/2;d.setFont(ee,"bold"),d.setTextColor(...pe),d.setFontSize(11),d.text(e.icon,a,218,{align:"center"}),d.setFont(ee,"normal"),d.setTextColor(...ue),d.setFontSize(8.5),d.text(e.text,a,224,{align:"center"})}),e.expert_comment){d.setFont(ee,"normal"),d.setTextColor(...he),d.setFontSize(7.5);const t=d.splitTextToSize(e.expert_comment,f);d.text(t.slice(0,2),y,234)}const v=p-38;if(d.setFillColor(...ue),d.rect(0,v,u,38,"F"),d.setFillColor(...pe),d.rect(0,v,u,2.5,"F"),d.setFont(ee,"bold"),d.setTextColor(...me),d.setFontSize(13),d.text("Chcesz dokładną wycenę?",m,v+11),d.setFont(ee,"normal"),d.setTextColor(...pe),d.setFontSize(10),d.text("Skontaktuj się z nami — wycena bezpłatna.",m,v+18.5),d.setFont(ee,"bold"),d.setTextColor(180,195,215),d.setFontSize(8.5),d.text(`☎  ${X.mainPhone}`,m,v+26.5),d.text(`✉  ${X.email}`,66,v+26.5),d.setFont(ee,"bold"),d.setTextColor(...pe),d.setFontSize(9),d.text(X.domain,u-m,v+26.5,{align:"right"}),d.setFont(ee,"normal"),d.setTextColor(120,140,170),d.setFontSize(7),d.text(X.address.full,u-m,v+33,{align:"right"}),"number"==typeof e.lat&&"number"==typeof e.lng){const t=await async function(e,t){try{const a=await ie(),r=`https://api.mapbox.com/styles/v1/mapbox/satellite-streets-v12/static/pin-l+BD5205(${t},${e})/${t},${e},16,0/1200x800@2x?access_token=${encodeURIComponent(a)}`,n=await fetch(r);if(!n.ok)return null;const o=await n.blob();return await new Promise(e=>{const t=new FileReader;t.onloadend=()=>e("string"==typeof t.result?t.result:null),t.onerror=()=>e(null),t.readAsDataURL(o)})}catch{return null}}(e.lat,e.lng);if(t){d.addPage(),d.setFillColor(...ue),d.rect(0,0,u,30,"F"),d.setFillColor(...pe),d.rect(0,0,u,2.5,"F"),d.setFont(ee,"bold"),d.setTextColor(...me),d.setFontSize(15),d.text("Lokalizacja nieruchomości",m,19),d.setFont(ee,"normal"),d.setTextColor(...pe),d.setFontSize(8),d.setCharSpace(1.5),d.text("AEstymator v2",u-m,19,{align:"right"}),d.setCharSpace(0);const n=15,o=u-2*n,i=2*o/3,s=42;d.setDrawColor(...pe),d.setLineWidth(.5),d.roundedRect(n-1.5,s-1.5,o+3,i+3,2,2,"S"),d.addImage(t,"PNG",n,s,o,i,void 0,"FAST");const l=s+i+12;d.setFont(ee,"bold"),d.setTextColor(...ue),d.setFontSize(10.5);const c=d.splitTextToSize(a,o);d.text(c,n,l),d.setFont(ee,"normal"),d.setTextColor(...he),d.setFontSize(8.5),d.text(`Współrzędne: ${e.lat.toFixed(6)}, ${e.lng.toFixed(6)}  ·  powierzchnia: ${r.toLocaleString("pl-PL")} m²`,n,l+7+5*(c.length-1)),d.setFontSize(7.5),d.text("Podkład mapowy: Mapbox / Maxar. Lokalizacja poglądowa — nie zastępuje wypisu i wyrysu z ewidencji gruntów.",n,l+13+5*(c.length-1));const h=20,g=p-h;d.setFillColor(...ue),d.rect(0,g,u,h,"F"),d.setFillColor(...pe),d.rect(0,g,u,2,"F"),d.setFont(ee,"normal"),d.setTextColor(180,195,215),d.setFontSize(8.5),d.text(`☎  ${X.mainPhone}    ✉  ${X.email}`,m,g+12.5),d.setFont(ee,"bold"),d.setTextColor(...pe),d.setFontSize(9),d.text(X.domain,u-m,g+12.5,{align:"right"})}}const j=l.toISOString().slice(0,10),z=`wycena-${k=a,k.toLowerCase().replace(/ą/g,"a").replace(/ć/g,"c").replace(/ę/g,"e").replace(/ł/g,"l").replace(/ń/g,"n").replace(/ó/g,"o").replace(/ś/g,"s").replace(/ź|ż/g,"z").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)}-${j}.pdf`;var k;d.save(z)}const be=e=>new Intl.NumberFormat("pl-PL",{style:"currency",currency:"PLN",maximumFractionDigits:0}).format(e),we={rciwn_primary:"RCiWN · 1 km / 12 mies.",rciwn_fallback:"RCiWN fallback · 3 km / 24 mies.",calibration:"Kalibracja regionalna",offer_market_fallback:"Fallback ofertowy · 8 km",regional_model:"Model regionalny Podhale"};function ve({lat:e,lng:r,area:n,location:o,parcelId:i,estimatedWidthM:s}){var c,m,g,x,y,f,b,w,v,j,z,k,N,_,M,I,E,D;const[T,$]=t.useState("budowlana"),[R,A]=t.useState("brak"),[O,Z]=t.useState("plaska"),[W,B]=t.useState("pelna"),[q,U]=t.useState("auto"),[G,J]=t.useState(2),[H,K]=t.useState("standard"),[X,Y]=t.useState(!1),[V,Q]=t.useState(null),[ee,te]=t.useState(null),[ae,re]=t.useState(!1),{toast:ne}=u(),oe=e=>l("px-2 py-1 rounded-md text-[10px] font-semibold border transition-all",e?"bg-accent/90 text-slate-900 border-accent":"bg-muted/60 text-muted-foreground border-border hover:bg-muted");return a.jsxs("div",{className:"mt-2 rounded-md border border-accent/40 bg-accent/5 p-2.5 space-y-2.5",children:[a.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] font-semibold text-accent",children:[a.jsx(S,{className:"w-3 h-3"})," Aestimator AI · wycena hybrydowa"]}),null!=s&&s<12&&a.jsxs("div",{className:"flex items-start gap-1.5 rounded-md border border-amber-500/40 bg-amber-500/10 p-2 text-[10px] leading-snug text-amber-700 dark:text-amber-400",children:[a.jsx(C,{className:"w-3 h-3 mt-0.5 shrink-0"}),a.jsxs("span",{children:["Szacowana szerokość działki: ~",s," m — możliwe ograniczenia zabudowy (do zwer
2yfikowania ręcznie)."]})]}),a.jsxs("div",{className:"space-y-1.5",children:[a.jsx(p,{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"MPZP"}),a.jsx("div",{className:"flex gap-1 flex-wrap",children:["budowlana","zagrodowa","rolna"].map(e=>a.jsx("button",{type:"button",onClick:()=>$(e),className:oe(T===e),children:e},e))})]}),a.jsxs("div",{className:"space-y-1.5",children:[a.jsx(p,{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Widok na Tatry"}),a.jsx("div",{className:"flex gap-1 flex-wrap",children:["panorama","czesciowy","brak"].map(e=>a.jsx("button",{type:"button",onClick:()=>A(e),className:oe(R===e),children:e},e))})]}),a.jsxs("div",{className:"space-y-1.5",children:[a.jsx(p,{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Nachylenie"}),a.jsx("div",{className:"flex gap-1 flex-wrap",children:["plaska","srednia","stroma"].map(e=>a.jsx("button",{type:"button",onClick:()=>Z(e),className:oe(O===e),children:e},e))})]}),a.jsxs("div",{className:"space-y-1.5",children:[a.jsx(p,{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Infrastruktura"}),a.jsx("div",{className:"flex gap-1 flex-wrap",children:["pelna","sluzebnosc","brak"].map(e=>a.jsx("button",{type:"button",onClick:()=>B(e),className:oe(W===e),children:e},e))})]}),a.jsxs("div",{className:"space-y-1.5 pt-1 border-t border-border/50",children:[a.jsxs(p,{className:"text-[10px] uppercase tracking-wide text-muted-foreground flex items-center gap-1",children:[a.jsx(L,{className:"w-3 h-3"})," Zabudowa (Issue #13)"]}),a.jsx("div",{className:"flex gap-1 flex-wrap",children:["auto","dom","brak"].map(e=>a.jsx("button",{type:"button",onClick:()=>U(e),className:oe(q===e),children:"auto"===e?"auto (GUGiK)":e},e))})]}),"brak"!==q&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"space-y-1.5",children:[a.jsx(p,{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Kondygnacje"}),a.jsx("div",{className:"flex gap-1 flex-wrap",children:[1,2,3].map(e=>a.jsx("button",{type:"button",onClick:()=>J(e),className:oe(G===e),children:e},e))})]}),a.jsxs("div",{className:"space-y-1.5",children:[a.jsx(p,{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:"Standard"}),a.jsx("div",{className:"flex gap-1 flex-wrap",children:["premium","standard","do_remontu"].map(e=>a.jsx("button",{type:"button",onClick:()=>K(e),className:oe(H===e),children:e.replace("_"," ")},e))})]})]}),a.jsxs(d,{type:"button",onClick:async function(){Y(!0),te(null),Q(null);try{const{data:t,error:a}=await h.functions.invoke("aestimator-valuate",{body:{lat:e,lng:r,area:n,location:o,parcel_id:i,mpzp:T,view:R,slope:O,infra:W,building_mode:q,building_floors:G,building_standard:H,estimated_width_m:s??void 0}});if(a)throw a;if(!t)throw new Error("Brak odpowiedzi");Q(t)}catch(t){const e=t instanceof Error?t.message:"Nie udało się wykonać wyceny.";te(e)}finally{Y(!1)}},disabled:X||!n||n<=0,className:"w-full h-8 text-xs bg-accent text-slate-900 hover:bg-accent/90",children:[X?a.jsx(F,{className:"w-3 h-3 animate-spin mr-1"}):null,X?"Wyceniam…":"Wyceń nieruchomość"]}),ee&&a.jsx("p",{className:"text-[10px] text-destructive leading-tight",children:ee}),V&&a.jsxs("div",{className:"space-y-2 text-xs",children:[V.narrow_plot_warning&&a.jsxs("div",{className:"flex items-start gap-1.5 rounded-md border border-amber-500/40 bg-amber-500/10 p-2 text-[10px] leading-snug text-amber-700 dark:text-amber-400",children:[a.jsx(C,{className:"w-3 h-3 mt-0.5 shrink-0"}),a.jsx("span",{children:V.narrow_plot_warning})]}),a.jsxs("div",{className:"text-[10px] text-muted-foreground space-y-0.5",children:[a.jsxs("div",{children:["C_base: ",a.jsxs("span",{className:"font-semibold text-foreground",children:[be((null==(c=V.aggregate)?void 0:c.c_base)??0),"/m²"]})," · ",we[(null==(m=V.aggregate)?void 0:m.source)??""]??(null==(g=V.aggregate)?void 0:g.source)??"—",((null==(x=V.aggregate)?void 0:x.rciwn_sample)??0)>0&&` · n_RCiWN=${null==(y=V.aggregate)?void 0:y.rciwn_sample}`]}),((null==(f=V.aggregate)?void 0:f.scraper_weight)??0)>0&&a.jsxs("div",{children:["Mix scraper 30%: ",be((null==(b=V.aggregate)?void 0:b.c_base_scraper)??0),"/m² (n=",(null==(w=V.aggregate)?void 0:w.scraper_sample)??0,", 1.5 km / 60 dni)"]}),(null==(v=V.geoportal_data)?void 0:v.has_buildings)&&a.jsxs("div",{className:"text-foreground",children:["🏠 GUGiK: ",(null==(j=V.geoportal_data)?void 0:j.building_count)??0,"× budynek · zabudowa ",(null==(z=V.geoportal_data)?void 0:z.building_footprint_sqm)??0," m²",(null==(k=V.geoportal_data)?void 0:k.floors)?` · ${V.geoportal_data.floors} kondygn.`:""]})]}),"built"===V.property_type&&a.jsxs("div",{className:"grid grid-cols-2 gap-1.5",children:[a.jsxs("div",{className:"rounded-md border border-border bg-background/60 p-1.5",children:[a.jsx("div",{className:"text-[9px] uppercase text-muted-foreground",children:"Grunt"}),a.jsx("div",{className:"text-[12px] font-bold text-foreground",children:be((null==(N=V.calculations)?void 0:N.land_estimated_value)??0)})]}),a.jsxs("div",{className:"rounded-md border border-border bg-background/60 p-1.5",children:[a.jsx("div",{className:"text-[9px] uppercase text-muted-foreground",children:"Budynek"}),a.jsx("div",{className:"text-[12px] font-bold text-foreground",children:be((null==(_=V.calculations)?void 0:_.building_estimated_value)??0)})]})]}),a.jsxs("div",{className:"grid grid-cols-3 gap-1.5",children:[a.jsxs("div",{className:"rounded-md border border-border bg-background/60 p-1.5 text-center",children:[a.jsx("div",{className:"text-[9px] uppercase text-muted-foreground",children:"Szybka sprzedaż"}),a.jsx("div",{className:"text-[11px] font-bold text-foreground",children:be((null==(M=V.valuation_ranges)?void 0:M.pessimistic_quick_sale)??0)})]}),a.jsxs("div",{className:"rounded-md border border-accent bg-accent/15 p-1.5 text-center",children:[a.jsx("div",{className:"text-[9px] uppercase text-accent",children:"Realna"}),a.jsx("div",{className:"text-[12px] font-bold text-foreground",children:be((null==(I=V.valuation_ranges)?void 0:I.realistic_market)??0)})]}),a.jsxs("div",{className:"rounded-md border border-border bg-background/60 p-1.5 text-center",children:[a.jsx("div",{className:"text-[9px] uppercase text-muted-foreground",children:"Negocjacja"}),a.jsx("div",{className:"text-[11px] font-bold text-foreground",children:be((null==(E=V.valuation_ranges)?void 0:E.optimistic_negotiation)??0)})]})]}),a.jsxs("div",{className:"rounded-md bg-muted/60 p-2 text-[11px] text-foreground",children:[a.jsx("div",{className:"text-[9px] uppercase text-muted-foreground mb-0.5",children:"Wartość całkowita"}),a.jsx("div",{className:"font-bold",children:be((null==(D=V.calculations)?void 0:D.total_estimated_value)??0)})]}),V.expert_comment&&a.jsx("p",{className:"text-[10px] italic text-muted-foreground leading-snug border-l-2 border-accent/50 pl-2",children:V.expert_comment}),a.jsxs(d,{type:"button",onClick:async function(){var t,a,i,s,l,c;if(V){re(!0);try{const d=(null==(t=V.calculations)?void 0:t.total_estimated_value)??(null==(a=V.aggregate)?void 0:a.c_base)??0,u=(null==(i=V.valuation_ranges)?void 0:i.pessimistic_quick_sale)??Math.round(.8*d),p=(null==(s=V.valuation_ranges)?void 0:s.optimistic_negotiation)??Math.round(1.2*d),m=o||`${e.toFixed(5)}, ${r.toFixed(5)}`;await fe({address:m,area_m2:n,c_base_pln:d,c_min_pln:u,c_max_pln:p,mpzp:T,land_value_pln:null==(l=V.calculations)?void 0:l.land_estimated_value,building_value_pln:null==(c=V.calculations)?void 0:c.building_estimated_value,source_label:"Wycena na podstawie RCiWN + scrapera ofertowego; Geoportal służy wyłącznie do geometrii/zabudowy.",expert_comment:V.expert_comment,computed_at:new Date,lat:e,lng:r}),ne({title:"Raport PDF wygenerowany",description:"Plik został pobrany na Twoje urządzenie."})}catch(d){const e=d instanceof Error?d.message:"Spróbuj ponownie.";ne({title:"Błąd generowania PDF",description:e,variant:"destructive"})}finally{re(!1)}}},disabled:ae,variant:"outline",className:"w-full h-8 text-xs border-accent/50 text-accent hover:bg-accent/10 hover:text-accent gap-1.5",children:[ae?a.jsx(F,{className:"w-3 h-3 animate-spin"}):a.jsx(P,{className:"w-3 h-3"}),ae?"Generuję PDF…":"Pobierz raport PDF"]})]})]})}class je extends t.Component{constructor(){var t;super(...arguments),((t,a,r)=>{a in t?e(t,a,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[a]=r})(this,"symbol"!=typeof(t="state")?t+"":t,{error:null})}static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){}render(){return this.state.error?a.jsxs("div",{className:"mt-2 rounded-md border border-destructive/40 bg-destructive/10 p-2 text-[11px] text-destructive",children:["Panel Aestimatora chwilowo niedostępny. Spróbuj ponownie.",a.jsx("button",{type:"button",className:"block mt-1 underline",onClick:()=>this.setState({error:null}),children:"Resetuj panel"})]}):this.props.children}}const ze=(e,t,a)=>e.getUint32(t,a),ke=(e,t,a)=>e.getFloat64(t,a),Ne=(e,t,a,r)=>({position:[ke(e,t,a),ke(e,t+8,a)],offset:t+8*r}),Se=(e,t,a,r)=>{const n=ze(e,t,a);let o=t+4;const i=[];for(let s=0;s<n;s+=1){const t=Ne(e,o,a,r);i.push(t.position),o=t.offset}return{positions:i,offset:o}},Ce=(e,t=0)=>{const a=e.getUint8(t);if(0!==a&&1!==a)throw new Error("Unsupported WKB byte order");const r=1===a,n=-536870912&(o=ze(e,t+1,r))?{type:255&o,dimensions:2+(2147483648&o?1:0)+(1073741824&o?1:0),hasSrid:!!(536870912&o)}:o>=3e3?{type:o-3e3,dimensions:4,hasSrid:!1}:o>=2e3?{type:o-2e3,dimensions:3,hasSrid:!1}:o>=1e3?{type:o-1e3,dimensions:3,hasSrid:!1}:{type:o,dimensions:2,hasSrid:!1};var o;let i=t+5;switch(n.hasSrid&&(i+=4),n.type){case 1:{const t=Ne(e,i,r,n.dimensions);return{geometry:{type:"Point",coordinates:t.position},offset:t.offset}}case 2:{const t=Se(e,i,r,n.dimensions);return{geometry:{type:"LineString",coordinates:t.positions},offset:t.offset}}case 3:{const t=((e,t,a,r)=>{const n=ze(e,t,a);let o=t+4;const i=[];for(let s=0;s<n;s+=1){const t=Se(e,o,a,r);i.push(t.positions),o=t.offset}return{coordinates:i,offset:o}})(e,i,r,n.dimensions);return{geometry:{type:"Polygon",coordinates:t.coordinates},offset:t.offset}}case 4:{const t=ze(e,i,r);i+=4;const a=[];for(let r=0;r<t;r+=1){const t=Ce(e,i);a.push(t.geometry.coordinates),i=t.offset}return{geometry:{type:"MultiPoint",coordinates:a},offset:i}}case 5:{const t=ze(e,i,r);i+=4;const a=[];for(let r=0;r<t;r+=1){const t=Ce(e,i);a.push(t.geometry.coordinates),i=t.offset}return{geometry:{type:"MultiLineString",coordinates:a},offset:i}}case 6:{const t=ze(e,i,r);i+=4;const a=[];for(let r=0;r<t;r+=1){const t=Ce(e,i);a.push(t.geometry.coordinates),i=t.offset}return{geometry:{type:"MultiPolygon",coordinates:a},offset:i}}case 7:{const t=ze(e,i,r);i+=4;const a=[];for(let r=0;r<t;r+=1){const t=Ce(e,i);a.push(t.geometry),i=t.offset}return{geometry:{type:"GeometryCollection",geometries:a},offset:i}}default:throw new Error(`Unsupported WKB geometry type: ${n.type}`)}},Le=e=>{const t=(e=>{const t=e.trim().replace(/^\\x/i,"").replace(/\s+/g,"");if(!t||t.length%2!=0||/[^0-9a-f]/i.test(t))throw new Error("Invalid WKB hex payload");const a=new Uint8Array(t.length/2);for(let r=0;r<t.length;r+=2)a[r/2]=Number.parseInt(t.slice(r,r+2),16);return a})(e);return Ce(new DataView(t.buffer,t.byteOffset,t.byteLength)).geometry};function Fe(e,t,a={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!Pe(e[0])||!Pe(e[1]))throw new Error("coordinates must contain numbers");return function(e,t,a={}){const r={type:"Feature"};return(0===a.id||a.id)&&(r.id=a.id),a.bbox&&(r.bbox=a.bbox),r.properties={},r.geometry=e,r}({type:"Point",coordinates:e},0,a)}function Pe(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}const _e=11102230246251565e-32,Me=134217729,Ie=(3+8*_e)*_e;function Ee(e,t,a,r,n){let o,i,s,l,c=t[0],d=r[0],u=0,p=0;d>c==d>
vendor: 2,900 bytes, line 2
2-c?(o=c,c=t[++u]):(o=d,d=r[++p]);let m=0;if(u<e&&p<a)for(d>c==d>-c?(i=c+o,s=o-(i-c),c=t[++u]):(i=d+o,s=o-(i-d),d=r[++p]),o=i,0!==s&&(n[m++]=s);u<e&&p<a;)d>c==d>-c?(i=o+c,l=i-o,s=o-(i-l)+(c-l),c=t[++u]):(i=o+d,l=i-o,s=o-(i-l)+(d-l),d=r[++p]),o=i,0!==s&&(n[m++]=s);for(;u<e;)i=o+c,l=i-o,s=o-(i-l)+(c-l),c=t[++u],o=i,0!==s&&(n[m++]=s);for(;p<a;)i=o+d,l=i-o,s=o-(i-l)+(d-l),d=r[++p],o=i,0!==s&&(n[m++]=s);return 0===o&&0!==m||(n[m++]=o),m}function De(e){return new Float64Array(e)}const Te=De(4),$e=De(8),Re=De(12),Ae=De(16),Oe=De(4);function Ze(e,t,a,r,n,o){const i=(t-o)*(a-n),s=(e-n)*(r-o),l=i-s,c=Math.abs(i+s);return Math.abs(l)>=33306690738754716e-32*c?l:-function(e,t,a,r,n,o,i){let s,l,c,d,u,p,m,h,g,x,y,f,b,w,v,j,z,k;const N=e-n,S=a-n,C=t-o,L=r-o;w=N*L,p=Me*N,m=p-(p-N),h=N-m,p=Me*L,g=p-(p-L),x=L-g,v=h*x-(w-m*g-h*g-m*x),j=C*S,p=Me*C,m=p-(p-C),h=C-m,p=Me*S,g=p-(p-S),x=S-g,z=h*x-(j-m*g-h*g-m*x),y=v-z,u=v-y,Te[0]=v-(y+u)+(u-z),f=w+y,u=f-w,b=w-(f-u)+(y-u),y=b-j,u=b-y,Te[1]=b-(y+u)+(u-j),k=f+y,u=k-f,Te[2]=f-(k-u)+(y-u),Te[3]=k;let F=function(e,t){let a=t[0];for(let r=1;r<4;r++)a+=t[r];return a}(0,Te),P=22204460492503146e-32*i;if(F>=P||-F>=P)return F;if(u=e-N,s=e-(N+u)+(u-n),u=a-S,c=a-(S+u)+(u-n),u=t-C,l=t-(C+u)+(u-o),u=r-L,d=r-(L+u)+(u-o),0===s&&0===l&&0===c&&0===d)return F;if(P=11093356479670487e-47*i+Ie*Math.abs(F),F+=N*d+L*s-(C*c+S*l),F>=P||-F>=P)return F;w=s*L,p=Me*s,m=p-(p-s),h=s-m,p=Me*L,g=p-(p-L),x=L-g,v=h*x-(w-m*g-h*g-m*x),j=l*S,p=Me*l,m=p-(p-l),h=l-m,p=Me*S,g=p-(p-S),x=S-g,z=h*x-(j-m*g-h*g-m*x),y=v-z,u=v-y,Oe[0]=v-(y+u)+(u-z),f=w+y,u=f-w,b=w-(f-u)+(y-u),y=b-j,u=b-y,Oe[1]=b-(y+u)+(u-j),k=f+y,u=k-f,Oe[2]=f-(k-u)+(y-u),Oe[3]=k;const _=Ee(4,Te,4,Oe,$e);w=N*d,p=Me*N,m=p-(p-N),h=N-m,p=Me*d,g=p-(p-d),x=d-g,v=h*x-(w-m*g-h*g-m*x),j=C*c,p=Me*C,m=p-(p-C),h=C-m,p=Me*c,g=p-(p-c),x=c-g,z=h*x-(j-m*g-h*g-m*x),y=v-z,u=v-y,Oe[0]=v-(y+u)+(u-z),f=w+y,u=f-w,b=w-(f-u)+(y-u),y=b-j,u=b-y,Oe[1]=b-(y+u)+(u-j),k=f+y,u=k-f,Oe[2]=f-(k-u)+(y-u),Oe[3]=k;const M=Ee(_,$e,4,Oe,Re);w=s*d,p=Me*s,m=p-(p-s),h=s-m,p=Me*d,g=p-(p-d),x=d-g,v=h*x-(w-m*g-h*g-m*x),j=l*c,p=Me*l,m=p-(p-l),h=l-m,p=Me*c,g=p-(p-c),x=c-g,z=h*x-(j-m*g-h*g-m*x),y=v-z,u=v-y,Oe[0]=v-(y+u)+(u-z),f=w+y,u=f-w,b=w-(f-u)+(y-u),y=b-j,u=b-y,Oe[1]=b-(y+u)+(u-j),k=f+y,u=k-f,Oe[2]=f-(k-u)+(y-u),Oe[3]=k;const I=Ee(M,Re,4,Oe,Ae);return Ae[I-1]}(e,t,a,r,n,o,c)}function We(e,t){var a,r,n,o,i,s,l,c,d,u=0,p=e[0],m=e[1],h=t.length;for(a=0;a<h;a++){r=0;var g=t[a],x=g.length-1;if((c=g[0])[0]!==g[x][0]&&c[1]!==g[x][1])throw new Error("First and last coordinates in a ring must be the same");for(o=c[0]-p,i=c[1]-m;r<x;r++){if(s=(d=g[r+1])[0]-p,l=d[1]-m,0===i&&0===l){if(s<=0&&o>=0||o<=0&&s>=0)return 0}else if(l>=0&&i<=0||l<=0&&i>=0){if(0===(n=Ze(o,s,i,l,0,0)))return 0;(n>0&&l>0&&i<=0||n<0&&l<=0&&i>0)&&u++}c=d,i=l,o=s}}return u%2!=0}var Be=function(e,t,a={}){if(!e)throw new Error("point is required");if(!t)throw new Error("polygon is required");
2const r=function(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return[...e.geometry.coordinates];if("Point"===e.type)return[...e.coordinates]}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return[...e];throw new Error("coord must be GeoJSON Point or an Array of numbers")}(e),n="Feature"===(o=t).type?o.geometry:o;var o;const i=n.type,s=t.bbox;let l=n.coordinates;if(s&&!1===function(e,t){return t[0]<=e[0]&&t[1]<=e[1]&&t[2]>=e[0]&&t[3]>=e[1]}(r,s))return!1;"Polygon"===i&&(l=[l]);let c=!1;for(var d=0;d<l.length;++d){const e=We(r,l[d]);if(0===e)return!a.ignoreBoundary;e&&(c=!0)}return c};const qe=e=>{if(!e)return null;let t=1/0,a=1/0,r=-1/0,n=-1/0;const o=e=>{if(Array.isArray(e)&&"number"==typeof e[0]&&"number"==typeof e[1]){const[o,i]=e;return o<t&&(t=o),i<a&&(a=i),o>r&&(r=o),void(i>n&&(n=i))}Array.isArray(e)&&e.forEach(o)};return"GeometryCollection"===e.type?e.geometries.forEach(e=>o(e.coordinates)):o(e.coordinates),isFinite(t)&&isFinite(a)&&isFinite(r)&&isFinite(n)?[t,a,r,n]:null},Ue=(e,t)=>{if(!e||!t||0===t.length)return[];if("Polygon"!==(a=e).type&&"MultiPolygon"!==a.type)return[];var a;const r=qe(e);if(!r)return[];const[n,o,i,s]=r,l=[];for(const c of t){const{longitude:t,latitude:a}=c;if("number"==typeof t&&"number"==typeof a&&!(t<n||t>i||a<o||a>s))try{Be(Fe([t,a]),e)&&l.push(c)}catch{continue}}return l},Ge={"3d-satellite":"mapbox://styles/mapbox/satellite-streets-v12","2d-streets":"mapbox://styles/mapbox/streets-v12","2d-outdoors":"mapbox://styles/mapbox/outdoors-v12"},Je={active:{label:"Dostępna",cls:"bg-emerald-500/90 text-white"},reserved:{label:"Rezerwacja",cls:"bg-amber-500/90 text-white"},sold:{label:"Sprzedana",cls:"bg-zinc-700/90 text-white"},rented:{label:"Wynajęta",cls:"bg-zinc-700/90 text-white"}},He={center:[20.0317,49.4775],zoom:11,pitch:70,bearing:-20},Ke="geoportal-parcels",Xe="geoportal-parcels-layer",Ye="geoportal-parcel-selected",Ve="geoportal-parcel-selected-fill",Qe="geoportal-parcel-selected-line",et="geoportal-parcel-selected-line-glow",tt="geoportal-mpzp",at="geoportal-mpzp-layer",rt="poi-skilifts",nt="poi-skilifts-layer",ot="poi-trailheads",it="poi-trailheads-layer",st="poi-icon-skilift",lt="poi-icon-trailhead",ct={[st]:'\n    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40" width="40" height="40">\n      <circle cx="20" cy="20" r="14" fill="#111827" stroke="#D4AF37" stroke-width="1.5"/>\n      <path d="M10 12 L30 22" stroke="#D4AF37" stroke-width="1.4" stroke-linecap="round"/>\n      <path d="M22 17 l3 0 l0 5 l-3 0 z M22 22 l3 4 M25 22 l-3 4" stroke="#D4AF37" stroke-width="1.2" fill="none" stroke-linecap="round" stroke-linejoin="round"/>\n      <circle cx="10" cy="12" r="1.3" fill="#D4AF37"/>\n      <circle cx="30" cy="22" r="1.3" fill="#D4AF37"/>\n    </svg>',[lt]:'\n    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40" width="40" height="40">\n      <circle cx="20" cy="20" r="14" fill="#111827" stroke="#D4AF37" stroke-width="1.5"/>\n      <path d="M11 27 L18 16 L22 22 L25 18 L30 27 Z" fill="none" stroke="#D4AF37" stroke-width="1.5" stroke-linejoin="round"/>\n      <circle cx="24" cy="13" r="1.6" fill="#D4AF37"/>\n    </svg>'},dt=async(e,t,a)=>{if(e.hasImage(t))return;const r=new Blob([a.trim()],{type:"image/svg+xml;charset=utf-8"}),n=URL.createObjectURL(r);try{const a=await new Promise((e,t)=>{const a=new Image(40,40);a.onload=()=>e(a),a.onerror=e=>t(e),a.src=n});e.hasImage(t)||e.addImage(t,a,{pixelRatio:2})}catch{}finally{URL.revokeObjectURL(n)}},ut="isochrone-source",pt="isochrone-fill-layer",mt="isochrone-line-layer",ht=[5,15,30],gt={driving:"Auto",walking:"Pieszo",cycling:"Rower"},xt="measure-source",yt="measure-line",ft="measure-fill",bt="measure-points",wt="draw-area-source",vt="viewed-offers",jt="properties-heatmap",zt="properties-heatmap-layer",kt="ai-price-heatmap",Nt="ai-price-heatmap-layer",St="ai-price-heatmap-labels",Ct=(e,t)=>{const a=e=>e*Math.PI/180,r=a(t[1]-e[1]),n=a(t[0]-e[0]),o=a(e[1]),i=a(t[1]),s=Math.sin(r/2)**2+Math.cos(o)*Math.cos(i)*Math.sin(n/2)**2;return 12742017.6*Math.asin(Math.sqrt(s))},Lt=e=>{if(e.length<3)return 0;const t=e.reduce((e,t)=>
2e+t[1],0)/e.length,a=111320,r=111320*Math.cos(t*Math.PI/180);let n=0;for(let o=0,i=e.length-1;o<e.length;i=o++){const t=e[o][0]*r,s=e[o][1]*a;n+=e[i][0]*r*s-t*(e[i][1]*a)}return Math.abs(n)/2},Ft=(e="{bbox-epsg-3857}",t=Date.now())=>`https://mapy.geoportal.gov.pl/wss/ext/KrajowaIntegracjaMiejscowychPlanowZagospodarowaniaPrzestrzennego?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&FORMAT=image/png&TRANSPARENT=true&LAYERS=raster,wektor-str,wektor-lzb,wektor-pow,wektor-lin,wektor-pkt,granice&SRS=EPSG:3857&WIDTH=256&HEIGHT=256&BBOX=${e}&cb=${t}`,Pt=(e,t)=>{const a=Math.max(Math.min(t,85.05112878),-85.05112878);return[20037508.34*e/180,Math.log(Math.tan((90+a)*Math.PI/360))/(Math.PI/180)*(20037508.34/180)]},_t="selected-parcels-bbox-debug",Mt="selected-parcels-bbox-debug-line",It=e=>e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2,Et=e=>{try{const t=e.getStyle();if(!(null==t?void 0:t.layers))return;const a=/poi-label|poi_label|shop|food|drink|lodging|gas|commercial/i;for(const r of t.layers)if("symbol"===r.type&&a.test(r.id))try{e.setLayoutProperty(r.id,"visibility","none")}catch{}}catch{}},Dt="buildings-3d-hover",Tt="composite",$t="buildings-3d-ground-shadow",Rt="building",At=e=>{var t;try{if(e.getLayer(Dt))return;if(!e.getSource(Tt))return;const a=null==(t=(e.getStyle().layers??[]).find(e=>{var t;return"symbol"===e.type&&(null==(t=e.layout)?void 0:t["text-field"])}))?void 0:t.id;e.getLayer($t)||e.addLayer({id:$t,source:Tt,"source-layer":Rt,type:"fill",minzoom:14,filter:["==",["get","extrude"],"true"],paint:{"fill-color":"hsl(30, 20%, 8%)","fill-opacity":.22}},a),e.addLayer({id:Dt,source:Tt,"source-layer":Rt,type:"fill-extrusion",minzoom:14,filter:["==",["get","extrude"],"true"],paint:{"fill-extrusion-color":["case",["boolean",["feature-state","hover"],!1],"hsl(43, 74%, 49%)",["interpolate",["linear"],["get","height"],0,"hsl(150, 22%, 18%)",12,"hsl(150, 20%, 24%)",30,"hsl(150, 16%, 30%)"]],"fill-extrusion-height":["interpolate",["linear"],["zoom"],14,0,14.5,["get","height"]],"fill-extrusion-base":["interpolate",["linear"],["zoom"],14,0,14.5,["get","min_height"]],"fill-extrusion-opacity":.55,"fill-extrusion-vertical-gradient":!0}},a)}catch(a){}},Ot=()=>{const e=t.useRef(null),u=t.useRef(null),j=t.useRef(new Map),N=t.useRef(null),C=t.useRef(new Map),L=t.useRef(null),P=t.useRef(new Set),K=t.useRef(null),X=t.useRef(null),Q=t.useRef(null),{user:ee,session:re}=x(),ne=n(),[oe,se]=t.useState(!1),[le]=o(),ce=t.useRef(!1),[ue,pe]=t.useState(!0);t.useState("idle");const[me,he]=t.useState(null),[ge,xe]=t.useState(!0),[ye,be]=t.useState(!1),[we,ze]=t.useState(!1),[ke,Ne]=t.useState(!1),[Se,Ce]=t.useState(!1),[Fe,Pe]=t.useState(!1),[_e,Me]=t.useState(!1),[Ie,Ee]=t.useState([]),[De,Te]=t.useState(!1),[$e,Re]=t.useState(null),[Ae,Oe]=t.useState("driving"),[Ze,We]=t.useState(!1),[Be,$t]=t.useState(!1),[Ot,Zt]=t.useState([]),[Wt,Bt]=t.useState(!1),[qt,Ut]=t.useState(null),[Gt,Jt]=t.useState(!1),Ht=t.useRef(!1),Kt=t.useCallback(async()=>{const e=u.current;if(e){Bt(!0),Ut(null);try{const t=e.getBounds();if(!t)throw new Error("Brak granic mapy.");const a=.34,r=(e,t)=>{if(t-e<=a)return[e,t];const r=(e+t)/2;return[r-a/2,r+a/2]},[n,o]=r(t.getSouth(),t.getNorth()),[i,s]=r(t.getWest(),t.getEast()),l=111320*(o-n),c=111320*(s-i)*Math.cos((n+o)/2*Math.PI/180),d=Math.min(2e3,Math.max(200,50*Math.ceil(Math.sqrt(l*c/2e3)/50))),{data:u,error:p}=await h.functions.invoke("aestimator-price-grid",{body:{bbox:{swLat:n,swLng:i,neLat:o,neLng:s},gridStepM:d,onlyBuilding:Ht.current}});if(p)throw p;const m=(null==u?void 0:u.points)??[];Zt(m),0===m.length&&Ut(0===((null==u?void 0:u.rciwn_found)??0)?"Brak transakcji RCiWN w tej okolicy — heatmapa AI nie ma z czego policzyc cen.":"Za malo transakcji przy punktach siatki (potrzeba min. 3 w promieniu 1,2 km).")}catch(t){const e=t instanceof Error?t.message:"Nie udało się policzyć siatki cen AI.";Ut(e),g.error(e)}finally{Bt(!1)}}},[]),Xt=t.useCallback(e=>{$t(e),e&&Kt()},[Kt]),[Yt,Vt]=t.useState(!1),Qt=t.useRef(!1);t.useEffect(()=>{Qt.current=Yt},[Yt]);const[ea,ta]=t.useState([]),aa=t.useRef([]);t.useEffect(()=>{aa.current=ea},[ea]);const[ra,na]=t.useState(!1),oa=t.useRef(!1);t.useEffect(()=>{oa.current=ra},[ra]);const[ia,sa]=t.useState([]),la=t.useRef([]);t.useEffect(()=>{la.current=ia},[ia]);const[ca,da]=t.useState(null),[ua,pa]=t.useState(()=>{try{const e=window.localStorage.getItem(vt);return e?new Set(JSON.parse(e)):new Set}catch{return new Set}}),ma=t.useCallback(e=>{pa(t=>{if(t.has(e))return t;const a=new Set(t);a.add(e);try{window.localStorage.setItem(vt,JSON.stringify(Array.from(a)))}catch{}return a})}
2,[]),[ha,ga]=t.useState(!1),[xa,ya]=t.useState(0),[fa,ba]=t.useState("3d-satellite"),[wa,va]=t.useState([]),[ja,za]=t.useState(0),ka=t.useRef("3d-satellite"),Na=t.useRef(null),Sa=t.useRef(!1),Ca=t.useRef(0),La="true"===le.get("debug"),Fa=t.useRef(null),[Pa,_a]=t.useState(0),[Ma,Ia]=t.useState(0),[Ea,Da]=t.useState(0),[Ta,$a]=t.useState(0),[Ra,Aa]=t.useState("—"),[Oa,Za]=t.useState("—"),[Wa,Ba]=t.useState("—"),[qa,Ua]=t.useState("—"),[Ga,Ja]=t.useState("idle"),[Ha,Ka]=t.useState(!1),Xa=t.useRef(!1);t.useEffect(()=>{Xa.current=Ha},[Ha]);const[Ya,Va]=t.useState([]),[Qa,er]=t.useState({}),tr=t.useRef(!1),ar=t.useRef([]);t.useEffect(()=>{ar.current=Ya},[Ya]);const rr=t.useRef(0);t.useEffect(()=>{const e=Ya.length;0===rr.current&&e>0&&Ne(!1),rr.current=e},[Ya.length]);const nr=t.useCallback(async e=>{if(!oe)return;const t=null==re?void 0:re.access_token;if(t){er(t=>({...t,[e.parcelId]:{status:"loading"}}));try{const{data:a,error:r}=await h.functions.invoke("mpzp-analyze",{body:{parcel_id:e.parcelId,bbox:e.bbox??null,geometry:e.geometry},headers:{Authorization:`Bearer ${t}`}});if(r)throw r;er(t=>({...t,[e.parcelId]:a?{...a,status:"ready"}:{status:"error",error:"Brak danych MPZP."}}))}catch(a){const t=a instanceof Error?a.message:"Nie udało się przeanalizować MPZP.";er(a=>({...a,[e.parcelId]:{status:"error",error:t}}))}}else er(t=>({...t,[e.parcelId]:{status:"error",error:"Brak aktywnej sesji admina."}}))},[oe,null==re?void 0:re.access_token]);t.useEffect(()=>{Ya.forEach(e=>{Qa[e.parcelId]||nr(e)})},[Qa,Ya,nr]);const or=t.useRef([]);t.useEffect(()=>{or.current=wa},[wa]);const ir=t.useRef(new Set);t.useEffect(()=>{const e=new Set;Ya.forEach(t=>t.matchedOffers.forEach(t=>e.add(t.pinId))),ir.current=e},[Ya]);const[sr,lr]=t.useState([]),cr=t.useCallback(()=>{_a(0),Ia(0),Da(0),$a(0),Aa("—"),Za("—"),Ba("—"),Ua("—"),lr([]),Fa.current=null},[]);t.useEffect(()=>{if(!La)return;const e=e=>{lr(t=>{const a={ts:Date.now(),blockedURI:e.blockedURI||"(inline)",violatedDirective:e.violatedDirective||e.effectiveDirective||"(unknown)"},r=t[0];return r&&r.blockedURI===a.blockedURI&&r.violatedDirective===a.violatedDirective?t:[a,...t].slice(0,20)})};return window.addEventListener("securitypolicyviolation",e),()=>window.removeEventListener("securitypolicyviolation",e)},[La]);const[dr,ur]=t.useState(null),[pr,mr]=t.useState(!1),[hr,gr]=t.useState(null),xr=t.useCallback(async(e,t={})=>{const{lng:a,lat:r}=e;tr.current=!0,Ce(!0);const n=(new Date).toLocaleTimeString("pl-PL",{hour12:!1});Za("loading…"),Ba(n),Ua("…");try{const e="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InNjdmFiY2lsemZhcmxuaWh4eG9iIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjI5MTczNTUsImV4cCI6MjA3ODQ5MzM1NX0.4ip3HSsEdbD-ah1ywPpYeV6Oa9-_gUbelX01qLK-tg8",n=`https://${"scvabcilzfarlnihxxob"}.supabase.co/functions/v1/geoportal-proxy?action=parcel-by-xy&lng=${a}&lat=${r}`,o=await fetch(n,{headers:{apikey:e,Authorization:`Bearer ${e}`}});Ua(String(o.status));let i={};try{i=await o.json()}catch{}if(!o.ok||!i.wkbHex)return Za(404===o.status?"404 no parcel":`${o.status} ${i.error??"error"}`),t.silent||404===o.status||g.error("Nie udało się pobrać granic działki."),null;const s=Le(i.wkbHex),l=i.parcelId??"unknown",c=qe(s),d=Ue(s,or.current);d.sort((e,t)=>(e.longitude-a)**2+(e.latitude-r)**2-((t.longitude-a)**2+(t.latitude-r)**2));const u=d.map(e=>({pinId:e.id,url:e.slug?te(e.slug):ae("/oferty"),title:e.title,location:e.location,description:`${e.property_type} · ${e.location}${e.area?` · ${e.area} m²`:""}${e.lot_area?` · działka ${e.lot_area} m²`:""}`,price:e.price})),p={parcelId:l,geometry:s,bbox:c??void 0,matchedOffers:u};return Va(e=>{const a=e.filter(e=>e.parcelId!==l);return t.replace?[p]:[...a,p]}),Za(`ok ${l}`),t.silent||g.success(`Podświetlono działkę: ${l}`),p}catch(o){return Za("exception"),Ua("EXC"),t.silent||g.error("Nie udało się pobrać granic działki."),null}finally{window.setTimeout(()=>{tr.current=!1},1200)}},[]),yr=t.useCallback(async e=>{try{const t="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InNjdmFiY2lsemZhcmxuaWh4eG9iIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjI5MTczNTUsImV4cCI6MjA3ODQ5MzM1NX0.4ip3HSsEdbD-ah1ywPpYeV6Oa9-_gUbelX01qLK-tg8",a=`https://${"scvabcilzfarlnihxxob"}.supabase.co/functions/v1/geoportal-proxy?action=parcel-by-id&id=${encodeURIComponent(e)}`,r=await fetch(a,{headers:{apikey:t,Authorization:`Bearer ${t}`}});if(!r.ok)return null;const n=await r.json().catch(()=>({}));if(!n.wkbHex)return null;const o=Le(n.wkbHex),i=qe(o);return{parcelId:n.parcelId??e,geometry:o,bbox:i??void 0,matchedOffers:[]}}catch(t){return null}},[]),fr=t.useCallback(async e=>{const t=Array.from(new Set(e.filter(Boolean))).slice(0,20);if(0!==t.length){tr.current=!0,Ce(!0);try{const e=(await Promise.all(t.map(yr))).filter(e=>null!==e);if(0===e.length)return void g.error("Nie udało się pobrać granic działek tej oferty.");Va(e);let a=1/0,r=1/0,n=-1/0,o=-1/0;for(const t of e)t.bbox&&(t.bbox[0]<a&&(a=t.bbox[0]),t.bbox[1]<r&&(r=t.bbox[1]),t.bbox[2]>n&&(n=t.bbox[2]),t.bbox[3]>o&&(o=t.bbox[3]));const i=u.current;if(i&&isFinite(a)&&isFinite(r)&&isFinite(n)&&isFinite(o)){const e="3d-satellite"===ka.current;i.fitBounds([[a,r],[n,o]],{padding:{top:120,right:window.innerWidth>=640?480:40,bottom:200,left:60},pitch:e?55:0,bearing:e?-20:0,duration:2200,essential:!0})}e.length<t.length?g.warning(`Podświetlono ${e.length} z ${t.length} działek.`):g.success(`Podświetlono ${e.length} ${1===e.length?"działkę":"działek"} tej oferty.`)}finally{window.setTimeout(()=>{tr.current=!1},1500)}}},[yr]),[br,wr]=t.useState(""),[vr,jr]=t.useState(!1),zr=t.useCallback(async()=>
2{if(!oe)return;const e=br.trim().replace(/\s+/g,"");if(e)if(!(e.length<8||e.length>60)&&e.includes("_")&&e.includes(".")&&/^[0-9A-Za-z_./-]+$/.test(e)){jr(!0),tr.current=!0,Ce(!0);try{const t=await yr(e);if(!t)return void g.error(`Nie znaleziono działki ${e} w Geoportalu.`);Va(e=>[...e.filter(e=>e.parcelId!==t.parcelId),t]);const a=u.current;if(a&&t.bbox){const e="3d-satellite"===ka.current;a.fitBounds([[t.bbox[0],t.bbox[1]],[t.bbox[2],t.bbox[3]]],{padding:{top:120,right:window.innerWidth>=640?480:40,bottom:200,left:60},pitch:e?55:0,bearing:e?-20:0,duration:2200,essential:!0})}g.success(`Znaleziono działkę: ${t.parcelId}`)}finally{jr(!1),window.setTimeout(()=>{tr.current=!1},1500)}}else g.error("Nieprawidłowy format numeru działki. Przykład: 121101_1.0001.2995/16");else g.error("Wpisz numer działki.")},[oe,br,yr]),kr=t.useCallback(e=>{const t=u.current;t&&(t.flyTo({center:[e.longitude,e.latitude],zoom:17,pitch:55,bearing:180,duration:2800,essential:!0,easing:It,curve:1.6}),t.once("idle",()=>{try{const a=(t.queryTerrainElevation([e.longitude,e.latitude],{exaggerated:!0})??0)+6,r=t.getFreeCameraOptions();r.position=s.MercatorCoordinate.fromLngLat({lng:e.longitude,lat:e.latitude},a),r.setPitchBearing(72,180),t.setFreeCameraOptions(r)}catch(a){t.easeTo({pitch:75,bearing:180,zoom:17.5,duration:800})}}),g.success("Widok z balkonu — patrzysz na Tatry"))},[]);t.useEffect(()=>{if(!ee)return void se(!1);let e=!1;return(async()=>{const{data:t}=await h.from("user_roles").select("role").eq("user_id",ee.id).eq("role","admin").maybeSingle();e||se(!!t)})(),()=>{e=!0}},[ee]),t.useEffect(()=>{oe||wr("")},[oe]),t.useEffect(()=>{if(!e.current||u.current)return;if(!(()=>{try{if(!s.supported||!s.supported({failIfMajorPerformanceCaveat:!1}))return!1;const e=document.createElement("canvas");return!!(e.getContext("webgl2")||e.getContext("webgl")||e.getContext("experimental-webgl"))}catch{return!1}})())return xe(!1),pe(!1),void he("Twoja przeglądarka lub urządzenie nie obsługuje WebGL wymaganego do mapy 3D.");let t=!1;return(async()=>{var a,r;try{const n=await ie();if(t)return;s.accessToken=n;try{null==(r=(a=s).setTelemetryEnabled)||r.call(a,!1)}catch{}let o=!1;const i=e.current;if(!i)return;i.style.width="100%",i.style.height=`${window.innerHeight}px`;const l=new s.Map({container:i,style:Ge["3d-satellite"],center:He.center,zoom:He.zoom,pitch:He.pitch,bearing:He.bearing,antialias:!0,maxPitch:85,failIfMajorPerformanceCaveat:!1,attributionControl:!0,preserveDrawingBuffer:!0,transformRequest:(e,t)=>(Xa.current&&"Tile"===t&&e.includes("mapy.geoportal.gov.pl")&&e.match(/[?&]BBOX=([^&]+)/i),{url:e})});u.current=l,l.addControl(new s.NavigationControl({visualizePitch:!0}),"bottom-right"),l.addControl(new s.FullscreenControl,"bottom-right");let c=null;const d=()=>{const t=e.current;t&&u.current&&(t.style.width="100%",t.style.height=`${window.innerHeight}px`,null!==c&&window.cancelAnimationFrame(c),c=window.requestAnimationFrame(()=>{var e;c=null;try{null==(e=u.current)||e.resize()}catch(t){}}))};d();const p=new ResizeObserver(()=>{d()});p.observe(i);const m=()=>{d()};window.addEventListener("resize",m),window.addEventListener("orientationchange",m);let h=null,x=!1;const y=()=>{x||(x=!0,null!==h&&(cancelAnimationFrame(h),h=null))};Na.current=y,["flyTo","easeTo","fitBounds","jumpTo"].forEach(e=>{const t=l[e].bind(l);l[e]=(...e)=>(y(),t(...e))}),["mousedown","touchstart","wheel","dblclick","dragstart","keydown"].forEach(e=>l.on(e,y));const f=()=>{var e,a;if(x||t)return;if(Sa.current)return;const r="undefined"!=typeof window&&(null==(e=window.matchMedia)?void 0:e.call(window,"(prefers-reduced-motion: reduce)").matches),n="undefined"!=typeof window&&(null==(a=window.matchMedia)?void 0:a.call(window,"(max-width: 767px)").matches);if(r||n)return;Sa.current=!0,Ca.current+=1;let o=performance.now();const i=e=>{if(x||!u.current)return;const t=e-o;o=e;try{const e=u.current.getBearing();u.current.setBearing(e+.0072*t)}catch{}h=requestAnimationFrame(i)};h=requestAnimationFrame(i)},b=()=>{if(!t&&u.current){try{if("3d-satellite"===ka.current)u.current.getSource("mapbox-dem")||u.current.addSource("mapbox-dem",{type:"raster-dem",url:"mapbox://mapbox.mapbox-terrain-dem-v1",tileSize:512,maxzoom:14}),u.current.setTerrain({source:"mapbox-dem",exaggeration:1.4});else try{u.current.setTerrain(null)}catch{}At(u.current);try{u.current.setLight({anchor:"map",color:"hsl(38, 92%, 78%)",intensity:.35,position:[1.5,140,55]})}catch{}
2try{u.current.setFog({range:[.5,10],color:"rgba(255, 244, 214, 0.35)","high-color":"rgba(180, 205, 255, 0.35)","horizon-blend":.12,"space-color":"rgba(20, 24, 38, 0.9)","star-intensity":0})}catch{}try{u.current.getLayer("sky")||u.current.addLayer({id:"sky",type:"sky",paint:{"sky-type":"atmosphere","sky-atmosphere-sun":[140,55],"sky-atmosphere-sun-intensity":15,"sky-atmosphere-color":"rgba(200, 215, 255, 1)","sky-atmosphere-halo-color":"rgba(255, 244, 214, 1)"}})}catch{}Et(u.current)}catch(e){}d(),pe(!1)}},w=()=>{b(),f()};l.on("style.load",b),l.once("style.load",w),l.once("load",w),l.on("error",e=>{var a,r;const n=(null==(a=null==e?void 0:e.error)?void 0:a.message)??"Mapbox error";if(!o&&!t&&"string"==typeof n&&/load.*style|sprite|glyphs/i.test(n)){o=!0;try{null==(r=u.current)||r.setStyle("mapbox://styles/mapbox/streets-v12")}catch(i){}}});const v=l.getCanvas(),j=e=>{e.preventDefault(),g.warning("Mapa chwilowo niedostępna — próba przywrócenia...");const t=()=>{var e;v.removeEventListener("webglcontextrestored",t),g.success("Mapa 3D przywrócona!");try{null==(e=u.current)||e.triggerRepaint()}catch{}};v.addEventListener("webglcontextrestored",t,!1),window.setTimeout(()=>{v.removeEventListener("webglcontextrestored",t),u.current||ne("/mapa")},8e3)};v.addEventListener("webglcontextlost",j,!1);const z=window.setTimeout(()=>{var e;t||(null==(e=u.current)?void 0:e.isStyleLoaded())||(g.warning("Mapa ładuje się wolno. Jeśli coś nie działa, odśwież stronę."),pe(!1))},25e3);l.once("idle",()=>{window.clearTimeout(z),d()});const k=()=>{y(),window.clearTimeout(z),p.disconnect(),window.removeEventListener("resize",m),window.removeEventListener("orientationchange",m),null!==c&&(window.cancelAnimationFrame(c),c=null),v.removeEventListener("webglcontextlost",j,!1)};l.on("remove",k)}catch(n){if(t)return;g.info("Przełączono na mapę 2D dla lepszej wydajności."),ne("/mapa")}})(),()=>{var e;t=!0,j.current.forEach(e=>e.remove()),j.current.clear(),null==(e=u.current)||e.remove(),u.current=null}},[]),t.useEffect(()=>{var e;const t=u.current;if(t&&!ue&&ka.current!==fa){ka.current=fa,null==(e=Na.current)||e.call(Na);try{j.current.forEach(e=>e.remove()),j.current.clear();const e=()=>{a();try{if("3d-satellite"===fa)t.getSource("mapbox-dem")||t.addSource("mapbox-dem",{type:"raster-dem",url:"mapbox://mapbox.mapbox-terrain-dem-v1",tileSize:512,maxzoom:14}),t.setTerrain({source:"mapbox-dem",exaggeration:1.4});else try{t.setTerrain(null)}catch{}}catch(e){}At(t);try{t.setLight({anchor:"map",color:"hsl(38, 92%, 78%)",intensity:.35,position:[1.5,140,55]})}catch{}try{t.setFog({range:[.5,10],color:"rgba(255, 244, 214, 0.35)","high-color":"rgba(180, 205, 255, 0.35)","horizon-blend":.12,"space-color":"rgba(20, 24, 38, 0.9)","star-intensity":0})}catch{}try{t.getLayer("sky")||t.addLayer({id:"sky",type:"sky",paint:{"sky-type":"atmosphere","sky-atmosphere-sun":[140,55],"sky-atmosphere-sun-intensity":15,"sky-atmosphere-color":"rgba(200, 215, 255, 1)","sky-atmosphere-halo-color":"rgba(255, 244, 214, 1)"}})}catch{}Et(t),za(e=>e+1)},a=()=>{ka.current===fa&&("3d-satellite"===fa?t.getPitch()<1&&t.easeTo({pitch:He.pitch,duration:800}):(t.getPitch()>.5||Math.abs(t.getBearing())>.5)&&t.easeTo({pitch:0,bearing:0,duration:800}))},r=()=>{ka.current===fa&&(t.setStyle(Ge[fa]),t.once("style.load",e),t.once("idle",()=>a()))};if("3d-satellite"===fa)r();else{try{t.stop()}catch{}try{t.setTerrain(null)}catch{}t.jumpTo({pitch:0,bearing:0}),requestAnimationFrame(()=>requestAnimationFrame(r))}}catch(a){}}},[fa,ue]),t.useEffect(()=>{if(!u.current||ue)return;let e=!1;return(async()=>{const{data:t,error:a}=await h.from("properties").select("id, slug, title, price, property_type, location, latitude, longitude, images, status, is_off_market, area, lot_area, description, parcel_ids").in("status",["active","reserved"]).not("latitude","is",null).not("longitude","is",null);if(e)return;if(a)return;const r=(t??[]).filter(e=>"number"==typeof e.latitude&&"number"==typeof e.longitude);va(r),ya(r.length)})(),()=>{e=!0}},[ue]),t.useEffect(()=>{const e=u.current;if(!e||ue)return;if(ce.current)return;const t=le.get("lat"),a=le.get("lng"),r=le.get("id")??le.get("property");let n=t?Number(t):NaN,o=a?Number(a):NaN;if((!Number.isFinite(n)||!Number.isFinite(o))&&r&&wa.length>0){const e=wa.find(e=>e.id===r);e&&Number.isFinite(e.latitude)&&Number.isFinite(e.longitude)&&(n=e.latitude,o=e.longitude)}if(!Number.isFinite(n)||!Number.isFinite(o))return;if(n<48.5||n>50.5||o<18.5||o>21.5)return;ce.current=!0;const i=Number(le.get("zoom")),s=Number(le.get("pitch")),l=Number(le.get("bearing"));"1"===le.get("parcels")&&Ce(!0),"1"===le.get("mpzp")&&Pe(!0),"1"===le.get("poi")&&Me(!0),"1"===le.get("heatmap")&&We(!0);const c=r?wa.find(e=>e.id===r):void 0,d=(null==c?void 0:c.parcel_ids)&&c.parcel_ids.length>0?c.parcel_ids:null;if(d?fr(d):(xr({lng:o,lat:n},{replace:!0,silent:!0}),e.flyTo({center:[o,n],zoom:Number.isFinite(i)&&i>0?i:17,pitch:Number.isFinite(s)?s:65,bearing:Number.isFinite(l)?l:-20,duration:2800,essential:!0,easing:It,curve:1.6,offset:window.innerWidth>=640?[-200,0]:[0,-120]})),r&&wa.length>0){const e=wa.find(e=>e.id===r);e&&gr({id:e.id,slug:e.slug,title:e.title,price:e.price,property_type:e.property_type,location:e.location,area:e.area,lot_area:e.lot_area,status:e.status,images:e.images,latitude:e.latitude,longitude:e.longitude,matterportUrl:null,description:e.description??null})}},[le,ue,wa,xr,fr]),t.useEffect(()=>{const e=u.current;
2e&&!ue&&(j.current.forEach(e=>e.remove()),j.current.clear(),wa.forEach(t=>{const a=document.createElement("div");a.style.willChange="transform",a.style.cursor=oe?"grab":"pointer",oe&&(a.title="Przeciągnij, aby zmienić lokalizację (admin)"),a.setAttribute("aria-label",`Oferta: ${t.title}, cena ${t.price} PLN`);const r=document.createElement("span");var n;r.className="liquid-glass-pin",r.innerHTML=`<span class="pin-amount">${n=t.price,n>=1e6?`${(n/1e6).toFixed(2)} mln`:n>=1e3?`${Math.round(n/1e3)}k`:n.toString()}</span><span class="pin-unit">PLN</span>`,a.appendChild(r);const o=(e,a)=>{const r=K.current;if(!r)return;const n=Je[t.status]??{label:t.status,cls:"bg-muted text-foreground"},o=t.area&&t.area>0?`${t.area} m²`:t.lot_area&&t.lot_area>0?`${t.lot_area} m² (działka)`:"—",i=e=>String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;");r.innerHTML=`\n          <div class="font-semibold text-foreground text-[13px] leading-tight mb-1 max-w-[240px] truncate">${i(t.title)}</div>\n          <div class="flex items-center gap-2 text-[11px]">\n            <span class="text-muted-foreground">${i(o)}</span>\n            <span class="inline-block px-1.5 py-0.5 rounded ${i(n.cls)} text-[10px] font-medium">${i(n.label)}</span>\n          </div>\n          <div class="text-[11px] font-bold text-accent mt-1">${new Intl.NumberFormat("pl-PL").format(t.price)} PLN</div>\n        `,r.style.opacity="1";const s=r.getBoundingClientRect(),l=window.innerWidth,c=window.innerHeight;let d=e+14,u=a+14;d+s.width>l-8&&(d=e-s.width-14),u+s.height>c-8&&(u=a-s.height-14),r.style.transform=`translate(${d}px, ${u}px)`};let i=null,l=null;const c=()=>{null!==l&&(clearTimeout(l),l=null)};a.addEventListener("mouseenter",e=>{r.style.transform="scale(1.08)",o(e.clientX,e.clientY),ir.current.has(t.id)&&u.current&&(c(),l=setTimeout(()=>{l=null,u.current&&(null==i||i.remove(),i=new s.Popup({closeButton:!1,closeOnClick:!1,offset:18,className:"map3d-offer-popup",maxWidth:"240px"}).setLngLat([t.longitude,t.latitude]).setHTML((()=>{var e;const a=null==(e=t.images)?void 0:e[0],r=(t.title||"").replace(/"/g,"&quot;");return`\n          <div style="font-family:inherit;max-width:220px">\n            ${a?`<img src="${a}" alt="${r}" width="220" height="120" style="display:block;width:100%;height:120px;object-fit:cover;border-radius:6px;margin-bottom:6px"/>`:""}\n            <div style="font-weight:600;font-size:13px;line-height:1.2;margin-bottom:4px;color:#0f172a">${r}</div>\n            <div style="font-size:12px;font-weight:700;color:#D4AF37">${new Intl.NumberFormat("pl-PL").format(t.price)} PLN</div>\n          </div>\n        `})()).addTo(u.current))},180))}),a.addEventListener("mousemove",e=>{o(e.clientX,e.clientY)}),a.addEventListener("mouseleave",()=>{r.style.transform="",r.style.backgroundColor="",r.style.color="",r.style.boxShadow="",(()=>{const e=K.current;e&&(e.style.opacity="0")})(),c(),null==i||i.remove(),i=null}),a.addEventListener("click",a=>{var r;a.stopPropagation(),ma(t.id),gr({id:t.id,slug:t.slug,title:t.title,price:t.price,property_type:t.property_type,location:t.location,area:t.area,lot_area:t.lot_area,status:t.status,images:t.images,latitude:t.latitude,longitude:t.longitude,matterportUrl:null,description:t.description??null}),t.parcel_ids&&t.parcel_ids.length>0?fr(t.parcel_ids):(xr({lng:t.longitude,lat:t.latitude},{replace:!0,silent:!0}),null==(r=u.current)||r.flyTo({center:[t.longitude,t.latitude],zoom:Math.max(e.getZoom(),16.5),pitch:Math.max(e.getPitch(),65),offset:window.innerWidth>=640?[-200,0]:[0,-120],duration:1800,essential:!0,easing:It,curve:1.5}))});const d=new s.Marker({element:a,draggable:oe}).setLngLat([t.longitude,t.latitude]).addTo(e);if(oe){const e=t.latitude,r=t.longitude;d.on("dragstart",()=>{a.style.cursor="grabbing"}),d.on("dragend",()=>{a.style.cursor="grab";const n=d.getLngLat();ur({property:t,newLat:n.lat,newLng:n.lng,marker:d,originalLat:e,originalLng:r})})}j.current.set(t.id,d)}))},[wa,oe,ue,ja,xr,fr]),t.useEffect(()=>{const e=u.current;if(!e||ue)return;const t="properties-cluster",a="properties-cluster-hit",r=()=>
2{null!==L.current&&(P.current.forEach(e=>{const t=j.current.get(e);t&&(t.setOffset([0,0]),t.getElement().classList.remove("liquid-glass-pin--spider"))}),P.current.clear(),L.current=null)},n=()=>{if(!e.getSource(t))return;const a=e.querySourceFeatures(t),n=new Set,o=new Set;a.forEach(a=>{const i=a.properties??{};if(i.cluster&&void 0!==i.cluster_id&&"Point"===a.geometry.type){const o=i.cluster_id;n.add(o);const l=a.geometry.coordinates.slice(),c=i.point_count??0;let d=C.current.get(o);if(d){d.setLngLat(l);const e=d.getElement(),t=e.querySelector(".cluster-count"),a=e.querySelector(".cluster-label");t&&(t.textContent=String(c)),a&&(a.textContent=1===c?"oferta":c<5?"oferty":"ofert")}else{const a=document.createElement("div");a.className="liquid-glass-cluster",a.setAttribute("role","button"),a.setAttribute("aria-label",`Klaster ${c} ofert. Kliknij, aby przybliżyć.`),a.innerHTML=`<span class="cluster-count">${c}</span><span class="cluster-label">${1===c?"oferta":c<5?"oferty":"ofert"}</span>`,a.addEventListener("click",a=>{a.stopPropagation(),((a,n)=>{const o=e.getSource(t);o&&o.getClusterExpansionZoom(a,(o,i)=>{o||null==i||i<=e.getZoom()+.1||i>=17?(a=>{const n=e.getSource(t);n&&n.getClusterLeaves(a,1/0,0,(e,t)=>{if(e||!t)return;r(),L.current=a;const n=t.length,o=Math.max(36,18+4*n);t.forEach((e,t)=>{const a=(e.properties??{}).propertyId;if(!a)return;const r=j.current.get(a);if(!r)return;const i=t/n*Math.PI*2-Math.PI/2,s=Math.cos(i)*o,l=Math.sin(i)*o;r.setOffset([s,l]);const c=r.getElement();c.classList.add("liquid-glass-pin--spider"),c.style.display="",c.style.transition="transform 0.28s cubic-bezier(0.4, 0, 0.2, 1)",P.current.add(a)})})})(a):(r(),e.flyTo({center:n,zoom:Math.min(i+.5,17),duration:1800,essential:!0,easing:It,curve:1.5}))})})(o,l)}),d=new s.Marker({element:a,anchor:"center"}).setLngLat(l).addTo(e),C.current.set(o,d)}}else i.propertyId&&o.add(i.propertyId)}),C.current.forEach((e,t)=>{n.has(t)||(e.remove(),C.current.delete(t))}),j.current.forEach((e,t)=>{const a=e.getElement();o.has(t)||P.current.has(t)?a.style.display="":a.style.display="none"})},o=()=>{const r={type:"FeatureCollection",features:wa.map(e=>({type:"Feature",properties:{propertyId:e.id},geometry:{type:"Point",coordinates:[e.longitude,e.latitude]}}))},o=e.getSource(t);o?o.setData(r):(e.addSource(t,{type:"geojson",data:r,cluster:!0,clusterMaxZoom:14,clusterRadius:50}),e.addLayer({id:a,type:"circle",source:t,paint:{"circle-radius":1,"circle-opacity":0}})),requestAnimationFrame(()=>n())};e.isStyleLoaded()?o():e.once("load",o);const i=()=>{n(),null!==L.current&&(r(),n())},l=e=>{e.sourceId===t&&e.isSourceLoaded&&n()},c=()=>{null!==L.current&&(r(),n())};return e.on("moveend",i),e.on("sourcedata",l),e.on("click",c),()=>{e.off("moveend",i),e.off("sourcedata",l),e.off("click",c),C.current.forEach(e=>e.remove()),C.current.clear(),r();try{e.getLayer(a)&&e.removeLayer(a),e.getSource(t)&&e.removeSource(t)}catch{}}},[wa,ue,ja]),t.useEffect(()=>{const e=(null==hr?void 0:hr.id)??null;j.current.forEach((t,a)=>{const r=t.getElement().querySelector(".liquid-glass-pin");r&&(r.classList.remove("liquid-glass-pin--active","liquid-glass-pin--dimmed"),e&&(a===e?r.classList.add("liquid-glass-pin--active"):r.classList.add("liquid-glass-pin--dimmed")))})},[null==hr?void 0:hr.id,wa,ja]),t.useEffect(()=>{j.current.forEach((e,t)=>{const a=or.current.find(e=>e.id===t),r=e.getElement();if(!a||!ca)return void(r.style.display="");const n=((e,t)=>{const[a,r]=e;let n=!1;for(let o=0,i=t.length-1;o<t.length;i=o++){const[e,s]=t[o],[l,c]=t[i];s>r!=c>r&&a<(l-e)*(r-s)/(c-s+1e-12)+e&&(n=!n)}return n})([a.longitude,a.latitude],ca);r.style.display=n?"":"none"})},[ca,wa,ja]),t.useEffect(()=>{j.current.forEach((e,t)=>{const a=e.getElement().querySelector(".liquid-glass-pin");a&&(a.style.opacity=ua.has(t)?"0.55":"")})},[ua,wa,ja]),t.useEffect(()=>{if(!hr)return;const e=e=>{"Escape"===e.key&&gr(null)};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[hr]),t.useEffect(()=>{const e=u.current;if(!e)return;if(N.current&&(N.current.remove(),N.current=null),!hr)return;const{longitude:t,latitude:a,id:r}
2=hr;if(!Number.isFinite(t)||!Number.isFinite(a))return;const n=document.createElement("div");n.className="map3d-target-pin",n.setAttribute("aria-hidden","true");const o=document.createElement("div");o.className="map3d-target-pin-inner",o.innerHTML='\n      <svg viewBox="0 0 34 44" xmlns="http://www.w3.org/2000/svg">\n        <path class="pin-body" d="M17 1C8.163 1 1 8.163 1 17c0 10.5 12.5 22.5 15.05 25.14a1.35 1.35 0 0 0 1.9 0C20.5 39.5 33 27.5 33 17 33 8.163 25.837 1 17 1z"/>\n        <path class="pin-stroke" d="M17 1C8.163 1 1 8.163 1 17c0 10.5 12.5 22.5 15.05 25.14a1.35 1.35 0 0 0 1.9 0C20.5 39.5 33 27.5 33 17 33 8.163 25.837 1 17 1z"/>\n        <circle class="pin-dot" cx="17" cy="17" r="5.5"/>\n      </svg>\n    ',n.appendChild(o);const i=new s.Marker({element:n,anchor:"bottom"}).setLngLat([t,a]).addTo(e);return N.current=i,()=>{i.remove(),N.current===i&&(N.current=null)}},[null==hr?void 0:hr.id,null==hr?void 0:hr.latitude,null==hr?void 0:hr.longitude]),t.useEffect(()=>{const e=u.current;if(!e||ue)return;const t=()=>{var t;const a=Q.current;if(null!=a)try{e.setFeatureState({source:Tt,sourceLayer:Rt,id:a},{hover:!1})}catch{}Q.current=null;const r=X.current;r&&(r.style.opacity="0");try{const a=null==(t=e.getCanvas)?void 0:t.call(e);a&&(a.style.cursor="")}catch{}},a=a=>{if(!(a.originalEvent.target instanceof HTMLCanvasElement))return void t();if(!e.getLayer(Dt))return;const r=e.queryRenderedFeatures(a.point,{layers:[Dt]});if(0===r.length)return void t();const n=r[0],o=n.id;if(null==o)return;if(Q.current!==o){if(null!==Q.current)try{e.setFeatureState({source:Tt,sourceLayer:Rt,id:Q.current},{hover:!1})}catch{}Q.current=o;try{e.setFeatureState({source:Tt,sourceLayer:Rt,id:o},{hover:!0})}catch{}}const i=n.properties??{},s="number"==typeof i.height?`${Math.round(i.height)} m`:"—",l="number"==typeof i.min_height?i.min_height:0,c="number"==typeof i.height?Math.max(0,i.height-l):null,d=c?Math.max(1,Math.round(c/3)):null,u=X.current;u&&(u.innerHTML=`\n          <div class="font-semibold text-foreground text-[13px] leading-tight mb-1">Budynek</div>\n          <div class="flex items-center gap-2 text-[11px]">\n            <span class="text-muted-foreground">Wysokość: ${s}</span>\n            ${d?`<span class="inline-block px-1.5 py-0.5 rounded bg-muted text-foreground/80 text-[10px] font-medium">~${d} ${1===d?"kondygnacja":d<5?"kondygnacje":"kondygnacji"}</span>`:""}\n          </div>\n          <div class="text-[10px] text-muted-foreground/70 mt-1">Dane OSM / Mapbox</div>\n        `,u.style.opacity="1",((e,t)=>{const a=X.current;if(!a)return;const r=a.getBoundingClientRect(),n=window.innerWidth,o=window.innerHeight;let i=e+14,s=t+14;i+r.width>n-8&&(i=e-r.width-14),s+r.height>o-8&&(s=t-r.height-14),a.style.transform=`translate(${i}px, ${s}px)`})(a.originalEvent.clientX,a.originalEvent.clientY)),e.getCanvas().style.cursor="pointer"},r=()=>t();return e.on("mousemove",a),e.on("mouseout",r),()=>{e.off("mousemove",a),e.off("mouseout",r),t()}},[ue,ja]);const Nr=t.useCallback(async()=>{if(!dr)return;mr(!0);const{error:e}=await h.from("properties").update({latitude:dr.newLat,longitude:dr.newLng}).eq("id",dr.property.id);mr(!1),e?(g.error("Błąd zapisu lokalizacji"),dr.marker.setLngLat([dr.originalLng,dr.originalLat])):(g.success("Lokalizacja zapisana"),va(e=>e.map(e=>e.id===dr.property.id?{...e,latitude:dr.newLat,longitude:dr.newLng}:e))),ur(null)},[dr]),Sr=t.useCallback(()=>{dr&&(dr.marker.setLngLat([dr.originalLng,dr.originalLat]),ur(null))},[dr]);t.useEffect(()=>{const e=u.current;if(!e||ue)return;const t=()=>{const t=!!e.getSource(Ke);if(Se){t||(e.addSource(Ke,{type:"raster",tiles:["https://integracja.gugik.gov.pl/cgi-bin/KrajowaIntegracjaEwidencjiGruntow?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&FORMAT=image/png&TRANSPARENT=true&LAYERS=dzialki,numery_dzialek&SRS=EPSG:3857&WIDTH=256&HEIGHT=256&BBOX={bbox-epsg-3857}"],tileSize:256,minzoom:15.5}),e.addLayer({id:Xe,type:"raster",source:Ke,slot:"top",minzoom:15.5,paint:{"raster-opacity":1,"raster-contrast":.2,"raster-resampling":"nearest","raster-fade-duration":0}})),!tr.current&&e.getZoom()<16.5&&(e.flyTo({center:e.getCenter(),zoom:16.5,pitch:"3d-satellite"===ka.current?He.pitch:0,bearing:"3d-satellite"===ka.current?e.getBearing():0,duration:2200,essential:!0,easing:It,curve:1.5}),g.info("Przybliżam mapę, aby pokazać granice działek"));try{e.triggerRepaint()}catch{}}else{e.getLayer(Xe)&&e.removeLayer(Xe),e.getSource(Ke)&&e.removeSource(Ke);try{e.triggerRepaint()}catch{}}};e.isStyleLoaded()?t():e.once("styledata",t);const a=e=>{var t,a;const r=e,n=(null==r?void 0:r.sourceId)===Ke,o=(null==(t=null==r?void 0:r.error)?void 0:t.message)??"",i=(null==(a=null==r?void 0:r.error)?void 0:a.status)??(null==r?void 0:r.status);if(!n&&!/gugik\.gov\.pl|KrajowaIntegracjaEwidencjiGruntow/i.test(o)||!Se)return;if(404===i||/not found|404/i.test(o))return;_a(e=>e+1);const s=o.toLowerCase();/cors|cross-origin|access-control/.test(s)?Ia(e=>e+1):/timeout|timed out|etimedout|aborted/.test(s)?Da(e=>e+1):$a(e=>e+1),Aa(o||`status ${i??"?"}`);const l="Serwery Geoportalu są w tej chwili obciążone lub niedostępne. Granice mogą być niewidoczne.",c=Date.now(),d=Fa.current;d&&d.message===l&&c-d.timestamp<15e3||(Fa.current={message:l,timestamp:c},g.error(l,{duration:6e3}))};return e.on("error",a),()=>{e.off("styledata",t),e.off("error",a)}},[Se,ue,ja]),t.useEffect(()=>{const e=u.current;if(!e||ue)return;const t=()=>{const t=!!e.getSource(tt);if(Fe){if(e.getZoom()<16.5&&(e.flyTo({zoom:16.5,pitch:"3d-satellite"===ka.current?He.pitch:0,bearing:"3d-satellite"===ka.current?e.getBearing():0,duration:2400,essential:!0,easing:It,curve:1.5}),g.info("Przybliżam mapę, aby pokazać Plan Zagospodarowania")),!t){Ja("loading");const t=Date.now(),a=Ft("{bbox-epsg-3857}",t),r=(e=>{const t=e.getBounds(),a=Pt(t.getWest(),t.getSouth()),r=Pt(t.getEast(),t.getNorth());return[a[0],a[1],r[0],r[1]].map(e=>e.toFixed(2)).join(",")})(e);Ft(r,t),Xa.current,e.addSource(tt,{type:"raster",tiles:[a],tileSize:256,minzoom:14}),e.addLayer({id:at,type:"raster",source:tt,slot:"top",minzoom:14,paint:{"raster-opacity":.8,"raster-resampling":"nearest","raster-fade-duration":0}})}try{e.triggerRepaint()}catch{}}else{e.getLayer(at)&&e.removeLayer(at),e.getSource(tt)&&e.removeSource(tt),Ja("idle");try{e.triggerRepaint()}catch{}}};e.isStyleLoaded()?t():e.once("styledata",t);const a=e=>{var t,a;const r=e,n=(null==(t=null==r?void 0:r.error)?void 0:t.message)??"",o=(null==(a=null==r?void 0:r.error)?void 0:a.status)??(null==r?void 0:r.status);if((null==r?void 0:r.sourceId)!==tt&&!/KrajowaIntegracjaMiejscowychPlanow|mapy\.geoportal\.gov\.pl/i.test(n)||!Fe)return;if(404===o||/not found|404/i.test(n))return;const i="Serwery Geoportalu (MPZP) są obciążone. Plany mogą być chwilowo niewidoczne.",s=Date.now(),l=Fa.current;l&&l.message===i&&s-l.timestamp<15e3||(Fa.current={message:i,timestamp:s},Ja("error"),g.error(i,{duration:6e3}))},r=e=>{const t=e;(null==t?void 0:t.sourceId)===tt&&t.isSourceLoaded&&(Xa.current,Ja("loaded"))};return e.on("error",a),e.on("sourcedata",r),()=>{e.off("styledata",t),e.off("error",a),e.off("sourcedata",r);try{e.getLayer(at)&&e.removeLayer(at),e.getSource(tt)&&e.removeSource(tt)}catch{}}},[Fe,ue,ja]),t.useEffect(()=>{const e=u.current;if(!e||ue)return;let t=!1;return(async()=>
2{if(await Promise.all([dt(e,st,ct[st]),dt(e,lt,ct[lt])]),!t)try{e.getSource(rt)||e.addSource(rt,{type:"geojson",data:Y}),e.getSource(ot)||e.addSource(ot,{type:"geojson",data:V});const t={"icon-allow-overlap":!0,"icon-ignore-placement":!1,"text-field":["get","name"],"text-size":11,"text-offset":[0,1.4],"text-anchor":"top","text-font":["Open Sans Semibold","Arial Unicode MS Bold"],"text-optional":!0},a={"text-color":"#ffffff","text-halo-color":"rgba(0,0,0,0.75)","text-halo-width":1.4,"icon-opacity":.95};e.getLayer(nt)?e.setLayoutProperty(nt,"visibility",_e?"visible":"none"):e.addLayer({id:nt,type:"symbol",source:rt,minzoom:12,layout:{...t,"icon-image":st,"icon-size":.55,visibility:_e?"visible":"none"},paint:a}),e.getLayer(it)?e.setLayoutProperty(it,"visibility",_e?"visible":"none"):e.addLayer({id:it,type:"symbol",source:ot,minzoom:12,layout:{...t,"icon-image":lt,"icon-size":.55,visibility:_e?"visible":"none"},paint:a})}catch{}})(),()=>{t=!0}},[_e,ue,ja]),t.useEffect(()=>{const e=u.current;if(!e||ue)return;const t=()=>{try{e.getLayer(mt)&&e.removeLayer(mt),e.getLayer(pt)&&e.removeLayer(pt),e.getSource(ut)&&e.removeSource(ut)}catch{}};if(0===Ie.length)return t(),Te(!1),void Re(null);let a=!1;const r=hr&&Number.isFinite(hr.longitude)&&Number.isFinite(hr.latitude)?[hr.longitude,hr.latitude]:(()=>{const t=e.getCenter();return[t.lng,t.lat]})();Te(!0),Re(null);const n=setTimeout(async()=>{var n;try{const o="https://scvabcilzfarlnihxxob.supabase.co/functions/v1/mapbox-isochrone",i=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",apikey:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InNjdmFiY2lsemZhcmxuaWh4eG9iIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjI5MTczNTUsImV4cCI6MjA3ODQ5MzM1NX0.4ip3HSsEdbD-ah1ywPpYeV6Oa9-_gUbelX01qLK-tg8",Authorization:"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InNjdmFiY2lsemZhcmxuaWh4eG9iIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjI5MTczNTUsImV4cCI6MjA3ODQ5MzM1NX0.4ip3HSsEdbD-ah1ywPpYeV6Oa9-_gUbelX01qLK-tg8"},body:JSON.stringify({lng:r[0],lat:r[1],minutes:Ie,profile:Ae})}),l=await i.text();if(a)return;if(!i.ok){const e=429===i.status?"Zbyt wiele zapytań — odczekaj minutę.":`Nie udało się pobrać izochron (${i.status}).`;return Re(e),g.error(e),void Te(!1)}let c=null;try{c=JSON.parse(l)}catch{c=null}if(!(null==(n=null==c?void 0:c.features)?void 0:n.length))return Re("Brak obszaru dojazdu dla tego punktu."),void Te(!1);t(),e.addSource(ut,{type:"geojson",data:c}),e.addLayer({id:pt,type:"fill",source:ut,layout:{visibility:"visible"},paint:{"fill-color":"#D4AF37","fill-opacity":.28,"fill-opacity-transition":{duration:400}}}),e.addLayer({id:mt,type:"line",source:ut,layout:{visibility:"visible"},paint:{"line-color":"#D4AF37","line-width":2,"line-opacity":.9}});try{const t=new s.LngLatBounds;let a=!1;const r=e=>{if(Array.isArray(e)&&"number"==typeof e[0]&&"number"==typeof e[1])return t.extend([e[0],e[1]]),void(a=!0);Array.isArray(e)&&e.forEach(r)};c.features.forEach(e=>{const t=e.geometry;(null==t?void 0:t.coordinates)&&r(t.coordinates)}),a&&e.fitBounds(t,{padding:{top:80,bottom:120,left:60,right:60},duration:900,maxZoom:15})}catch{}Te(!1)}catch(o){a||(Re("Błąd sieci podczas pobierania izochron."),g.error("Błąd sieci podczas pobierania izochron."),Te(!1))}},300);return()=>{a=!0,clearTimeout(n)}},[Ie,Ae,null==hr?void 0:hr.id,null==hr?void 0:hr.latitude,null==hr?void 0:hr.longitude,ue,ja]),t.useEffect(()=>{const e=u.current;if(!e||ue)return;const t=()=>{try{e.getLayer(zt)&&e.removeLayer(zt),e.getSource(jt)&&e.removeSource(jt)}catch{}};if(!Ze||0===wa.length)return void t();const a=wa.map(e=>e.price).filter(e=>Number.isFinite(e)&&e>0),r=a.length?Math.min(...a):0,n=a.length?Math.max(...a):1,o=Math.max(1,n-r),i={type:"FeatureCollection",features:wa.map(e=>({type:"Feature",properties:{weight:e.price>0?Math.min(1,Math.max(.15,(e.price-r)/o)):.5},geometry:{type:"Point",coordinates:[e.longitude,e.latitude]}}))};return t(),e.addSource(jt,{type:"geojson",data:i}),e.addLayer({id:zt,type:"heatmap",source:jt,maxzoom:14,paint:{"heatmap-weight":["get","weight"],"heatmap-intensity":["interpolate",["linear"],["zoom"],8,.6,14,2.4],"heatmap-radius":["interpolate",["linear"],["zoom"],8,18,14,60],"heatmap-opacity":["interpolate",["linear"],["zoom"],8,.85,15,.35],"heatmap-color":["interpolate",["linear"],["heatmap-density"],0,"rgba(0,0,0,0)",.15,"rgba(59,130,246,0.45)",.4,"rgba(212,175,55,0.7)",.7,"rgba(245,158,11,0.85)",1,"rgba(220,38,38,0.95)"]}}),t},[Ze,wa,ue,ja]),t.useEffect(()=>{const e=u.current;if(!e||ue)return;const t=()=>{try{e.getLayer(Nt)&&e.removeLayer(Nt),e.getLayer(St)&&e.removeLayer(St),e.getSource(kt)&&e.removeSource(kt)}catch{}};if(!oe||!Be||0===Ot.length)return void t();const a=Ot.map(e=>e.c_base_per_sqm).filter(e=>Number.isFinite(e)&&e>0),r=a.length?Math.min(...a):0,n=a.length?Math.max(...a):1,o=Math.max(1,n-r),i={type:"FeatureCollection",features:Ot.map(e=>({type:"Feature",properties:{weight:e.c_base_per_sqm>0?Math.min(1,Math.max(.15,(e.c_base_per_sqm-r)/o)):.5,price:Math.round(e.c_base_per_sqm),sample:e.sample_size},geometry:{type:"Point",coordinates:[e.lng,e.lat]}}))};return t(),e.addSource(kt,{type:"geojson",data:i}),e.addLayer({id:Nt,type:"heatmap",source:kt,maxzoom:14,paint:{"heatmap-weight":["get","weight"],"heatmap-intensity":["interpolate",["linear"],["zoom"],8,.6,14,2.4],"heatmap-radius":["interpolate",["linear"],["zoom"],8,18,14,60],"heatmap-opacity":["interpolate",["linear"],["zoom"],8,.85,15,.35],"heatmap-color":["interpolate",["linear"],["heatmap-density"],0,"rgba(0,0,0,0)",.15,"rgba(59,130,246,0.45)",.4,"rgba(212,175,55,0.7)",.7,"rgba(245,158,11,0.85)",1,"rgba(220,38,38,0.95)"]}}),e.addLayer({id:St,type:"symbol",source:kt,minzoom:12,layout:{"text-field":["concat",["to-string",["get","price"]]," zł/m²"],"text-size":["interpolate",["linear"],["zoom"],12,10,16,13],"text-font":["Open Sans Semibold","Arial Unicode MS Bold"],"text-allow-overlap":!1,"text-padding":6},paint:{"text-color":"#ffffff","text-halo-color":"rgba(0,0,0,0.85)","text-halo-width":1.6}}),t},[oe,Be,Ot,ue,ja]),t.useEffect(()=>{const e=u.current;if(!e||ue)return;const t=()=>{try{e.getLayer(bt)&&e.removeLayer(bt),e.getLayer(yt)&&e.removeLayer(yt),e.getLayer(ft)&&e.removeLayer(ft),e.getSource(xt)&&e.removeSource(xt)}catch{}};if(!Yt)return t(),void(e.getCanvas().style.cursor="");e.getCanvas().style.cursor="crosshair",e.getSource(xt)||(e.addSource(xt,{type:"geojson",data:{type:"FeatureCollection",features:[]}}
2),e.addLayer({id:ft,type:"fill",source:xt,filter:["==",["geometry-type"],"Polygon"],paint:{"fill-color":"#D4AF37","fill-opacity":.12}}),e.addLayer({id:yt,type:"line",source:xt,filter:["any",["==",["geometry-type"],"LineString"],["==",["geometry-type"],"Polygon"]],paint:{"line-color":"#D4AF37","line-width":2.2,"line-dasharray":[2,1.5]}}),e.addLayer({id:bt,type:"circle",source:xt,filter:["==",["geometry-type"],"Point"],paint:{"circle-radius":4.5,"circle-color":"#0a0a0a","circle-stroke-color":"#D4AF37","circle-stroke-width":1.5}})),(t=>{const a=t.map(e=>({type:"Feature",properties:{},geometry:{type:"Point",coordinates:e}}));t.length>=2&&t.length<3?a.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:t}}):t.length>=3&&a.push({type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[...t,t[0]]]}});const r=e.getSource(xt);null==r||r.setData({type:"FeatureCollection",features:a})})(aa.current);const a=e=>{if(!(e.originalEvent.target instanceof HTMLCanvasElement))return;const t=[e.lngLat.lng,e.lngLat.lat];ta(e=>[...e,t])},r=e=>{e.preventDefault()};return e.on("click",a),e.on("dblclick",r),e.doubleClickZoom.disable(),()=>{e.off("click",a),e.off("dblclick",r),e.doubleClickZoom.enable(),t(),e.getCanvas().style.cursor=""}},[Yt,ue,ja]),t.useEffect(()=>{const e=u.current;if(!e||!Yt)return;const t=e.getSource(xt);if(!t)return;const a=ea,r=a.map(e=>({type:"Feature",properties:{},geometry:{type:"Point",coordinates:e}}));2===a.length?r.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:a}}):a.length>=3&&r.push({type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[...a,a[0]]]}}),t.setData({type:"FeatureCollection",features:r})},[ea,Yt]);const Cr=t.useCallback(()=>{if(ea.length<2)return null;let e=0;for(let t=1;t<ea.length;t++)e+=Ct(ea[t-1],ea[t]);return{dist:e,area:ea.length>=3?Lt(ea):0}},[ea]);t.useEffect(()=>{const e=u.current;if(!e||ue)return;if(!ra)return void(e.getCanvas().style.cursor="");e.getCanvas().style.cursor="crosshair",e.getSource(wt)||(e.addSource(wt,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),e.addLayer({id:"draw-area-fill",type:"fill",source:wt,filter:["==",["geometry-type"],"Polygon"],paint:{"fill-color":"#4ade80","fill-opacity":.14}}),e.addLayer({id:"draw-area-line",type:"line",source:wt,filter:["any",["==",["geometry-type"],"LineString"],["==",["geometry-type"],"Polygon"]],paint:{"line-color":"#4ade80","line-width":2.2,"line-dasharray":[2,1.5]}}),e.addLayer({id:"draw-area-points",type:"circle",source:wt,filter:["==",["geometry-type"],"Point"],paint:{"circle-radius":4.5,"circle-color":"#0a0a0a","circle-stroke-color":"#4ade80","circle-stroke-width":1.5}})),(t=>{const a=t.map(e=>({type:"Feature",properties:{},geometry:{type:"Point",coordinates:e}}));2===t.length?a.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:t}}):t.length>=3&&a.push({type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[...t,t[0]]]}});const r=e.getSource(wt);null==r||r.setData({type:"FeatureCollection",features:a})})(la.current);const t=e=>{if(!(e.originalEvent.target instanceof HTMLCanvasElement))return;const t=[e.lngLat.lng,e.lngLat.lat];sa(e=>[...e,t])},a=e=>{e.preventDefault()};return e.on("click",t),e.on("dblclick",a),e.doubleClickZoom.disable(),()=>{e.off("click",t),e.off("dblclick",a),e.doubleClickZoom.enable(),e.getCanvas().style.cursor=""}},[ra,ue,ja]),t.useEffect(()=>{const e=u.current;if(!e)return;const t=e.getSource(wt);if(!t)return;const a=ca??ia,r=a.map(e=>({type:"Feature",properties:{},geometry:{type:"Point",coordinates:e}}));2===a.length?r.push({type:"Feature",properties:{},geometry:{type:"LineString",coordinates:a}}):a.length>=3&&r.push({type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:[[...a,a[0]]]}}),t.setData({type:"FeatureCollection",features:r})},[ia,ca]);const Lr=t.useCallback(()=>{ia.length<3||(da(ia),na(!1),g.success("Pokazuję oferty w zaznaczonym obszarze."))},[ia]),Fr=t.useCallback(()=>{sa([]),da(null),na(!1);try{const e=u.current,t=null==e?void 0:e.getSource(wt);null==t||t.setData({type:"FeatureCollection",features:[]})}catch{}},[]),Pr=t.useRef(null),[_r,Mr]=t.useState(!1),[Ir,Er]=t.useState(null),Dr=t.useRef(null),Tr=t.useCallback(e=>{Dr.current&&URL.revokeObjectURL(Dr.current.url),Dr.current=e,Er(e)},[]);t.useEffect(()=>()=>{Dr.current&&URL.revokeObjectURL(Dr.current.url)},[]);const $r=t.useCallback(async()=>{var e;const t=u.current;if(!t||_r)return;Tr(null),null==(e=Na.current)||e.call(Na);const a=t.getCenter(),r=hr&&Number.isFinite(hr.longitude)&&Number.isFinite(hr.latitude)?[hr.longitude,hr.latitude]:[a.lng,a.lat];let n=null;const o=[];let i="mp4";try{const e="undefined"!=typeof MediaRecorder?["video/mp4;codecs=avc1.42E01E","video/mp4","video/webm;codecs=vp9","video/webm"].find(e=>
2MediaRecorder.isTypeSupported(e)):void 0,a=t.getCanvas();e&&"function"==typeof a.captureStream&&(i=e.startsWith("video/mp4")?"mp4":"webm",n=new MediaRecorder(a.captureStream(30),{mimeType:e,videoBitsPerSecond:8e6}),n.ondataavailable=e=>{e.data&&e.data.size>0&&o.push(e.data)},n.start())}catch{n=null}Mr(!0),g.info("Kinowy przelot 3D — kliknij mapę, aby przerwać.");let s=!1;const l=()=>{s=!0},c=["mousedown","touchstart","wheel","dblclick","keydown"];c.forEach(e=>t.on(e,l));const d=e=>new Promise(t=>window.setTimeout(t,e));try{t.easeTo({center:r,zoom:16.2,pitch:72,bearing:-30,duration:3200,essential:!0}),await d(3400),s||await new Promise(e=>{const a=t.getBearing(),r=performance.now(),n=t=>{if(s||!u.current)return void e();const o=Math.min(1,(t-r)/11e3),i=o<.5?2*o*o:1-Math.pow(-2*o+2,2)/2;try{u.current.setBearing(a+360*i)}catch{}o>=1?e():Pr.current=requestAnimationFrame(n)};Pr.current=requestAnimationFrame(n)}),s||(t.easeTo({center:r,zoom:15.4,pitch:78,bearing:180,duration:3e3,essential:!0}),await d(3200))}finally{c.forEac
2h(e=>t.off(e,l)),null!==Pr.current&&(cancelAnimationFrame(Pr.current),Pr.current=null),Mr(!1);const e=n;if(e&&"inactive"!==e.state&&(await new Promise(t=>{e.onstop=()=>t(),e.stop()}),o.length>0)){const e=URL.createObjectURL(new Blob(o,{type:o[0].type||"video/mp4"}));Tr({url:e,ext:i}),g.success("Film jest gotowy. Kliknij „Pobierz film”.")}}},[_r,Tr,hr]),Rr=t.useCallback(()=>{if(!Ir)return;const e=document.createElement("a");e.href=Ir.url,e.download=`przelot-3d-${Date.now()}.${Ir.ext}`,document.body.appendChild(e),e.click(),e.remove()},[Ir]),Ar=t.useCallback(()=>{const e=u.current;if(e)try{e.triggerRepaint(),requestAnimationFrame(()=>{const t=e.getCanvas().toDataURL("image/png"),a=document.createElement("a");a.href=t,a.download=`mapa3d-${Date.now()}.png`,document.body.appendChild(a),a.click(),a.remove(),g.success("Zapisano zrzut mapy.")})}catch{g.error("Nie udało się zapisać zrzutu mapy.")}},[]),Or=t.useCallback(async()=>{const e=u.current;if(!e)return;if(e.isMoving()){const t=g.info("Czekam na ustabilizowanie widoku…");await new Promise(t=>{let a=!1;const r=()=>{a||(a=!0,clearTimeout(n),e.off("moveend",r),t())},n=setTimeout(r,3e3);e.once("moveend",r)}),g.dismiss(t)}const t=e.getCenter(),a=new URLSearchParams;a.set("lat",t.lat.toFixed(6)),a.set("lng",t.lng.toFixed(6)),a.set("zoom",e.getZoom().toFixed(2)),a.set("pitch",e.getPitch().toFixed(1)),a.set("bearing",e.getBearing().toFixed(1)),a.set("mode",fa),Se&&a.set("parcels","1"),Fe&&a.set("mpzp","1"),_e&&a.set("poi","1"),Ze&&a.set("heatmap","1"),(null==hr?void 0:hr.id)&&a.set("id",hr.id);
2const r=ae(`/mapa-3d?${a.toString()}`);try{await navigator.clipboard.writeText(r),g.success("Link skopiowany — wklej, aby udostępnić ten widok.")}catch{try{window.prompt("Skopiuj link:",r)}catch{g.error("Nie udało się skopiować linku automatycznie.",{description:r,duration:2e4})}}},[fa,Se,Fe,_e,Ze,null==hr?void 0:hr.id]);t.useEffect(()=>{const e=u.current;if(!e||ue)return;if(!Se)return;let t=!1,a=!1;e.getSource(Ye)||e.addSource(Ye,{type:"geojson",data:{type:"FeatureCollection",features:[]}}),e.getLayer(Ve)||e.addLayer({id:Ve,type:"fill",source:Ye,slot:"top",paint:{"fill-color":"#D4AF37","fill-opacity":["interpolate",["linear"],["zoom"],12,0,14.5,.4]}}),e.getLayer(et)||e.addLayer({id:et,type:"line",source:Ye,slot:"top",paint:{"line-color":"#D4AF37","line-width":7,"line-blur":4,"line-opacity":["interpolate",["linear"],["zoom"],12,0,14.5,.55]}}),e.getLayer(Qe)||e.addLayer({id:Qe,type:"line",source:Ye,slot:"top",paint:{"line-color":"#D4AF37","line-width":1.5,"line-opacity":["interpolate",["linear"],["zoom"],12,0,14.5,.95]}});const r=async e=>{if(a)return;if(tr.current)return;if(Qt.current)return;if(oa.current)return;const r=e.originalEvent.target;if(!(r instanceof HTMLCanvasElement))return;if(null==r?void 0:r.closest(".mapboxgl-marker"))return;const{lng:n,lat:o}=e.lngLat;a=!0;const i=(new Date).toLocaleTimeString("pl-PL",{hour12:!1});Za("loading…"),Ba(i),Ua("…");try{const e="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InNjdmFiY2lsemZhcmxuaWh4eG9iIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjI5MTczNTUsImV4cCI6MjA3ODQ5MzM1NX0.4ip3HSsEdbD-ah1ywPpYeV6Oa9-_gUbelX01qLK-tg8",a=`https://scvabcilzfarlnihxxob.supabase.co/functions/v1/geoportal-proxy?action=parcel-by-xy&lng=${n}&lat=${o}`;let r;try{r=await fetch(a,{headers:{apikey:e,Authorization:`Bearer ${e}`}})}catch(s){return Za("network error"),Ua("NET"),void g.error("Nie udało się pobrać geometrii działki z Geoportalu. Serwery państwowe mogą być przeciążone.")}if(Ua(String(r.status)),429===r.status)return Za("429 rate-limited"),void g.warning("Zbyt wiele zapytań o działki w krótkim czasie. Zwolnij na chwilę.");if(r.status>=500&&r.status<600)return Za(`${r.status} server error`),void g.error("Nie udało się pobrać geometrii działki z Geoportalu. Serwery państwowe mogą być przeciążone.");let i,c={};try{c=await r.json()}catch{}if(!r.ok){if(404!==r.status)throw Za(`${r.status} ${c.error??"error"}`),new Error(c.error??`HTTP ${r.status}`);return Za("404 no parcel"),void g.info(c.error??"Brak działki w tym miejscu.")}if(t||!c.wkbHex)return void Za("ok (empty)");try{i=Le(c.wkbHex)}catch(l){return Za("wkb parse error"),void g.error("Nie udało się przetworzyć geometrii działki.")}const d=c.parcelId??"unknown",u=qe(i),p=Ue(i,or.current);p.sort((e,t)=>(e.longitude-n)**2+(e.latitude-o)**2-((t.longitude-n)**2+(t.latitude-o)**2));const m=p.map(e=>({pinId:e.id,url:e.slug?te(e.slug):ae("/oferty"),title:e.title,location:e.location,description:`${e.property_type} · ${e.location}${e.area?` · ${e.area} m²`:""}${e.lot_area?` · działka ${e.lot_area} m²`:""}`,price:e.price})),h=ar.current;h.some(e=>e.parcelId===d)?(Va(h.filter(e=>e.parcelId!==d)),Za(`removed ${d}`),g.info(`Usunięto z zaznaczenia: ${d}`)):(Va([...h,{parcelId:d,geometry:i,bbox:u??void 0,matchedOffers:m}]),Za(`ok ${d}`),g.success(m.length>0?`Dodano: ${d} (${m.length} ${1===m.length?"oferta":"ofert"})`:`Dodano do zaznaczenia: ${d}`))}catch(l){Za("exception"),Ua("EXC"),g.error("Nie udało się pobrać granic działki.")}finally{a=!1}
2};e.on("click",r);const n=e.getCanvas(),o=n.style.cursor;return n.style.cursor="crosshair",()=>{t=!0;try{e.off("click",r),n.style.cursor=o}catch{}}},[Se,ue,ja]),t.useEffect(()=>{const e=u.current;if(!e||ue)return;const t=e.getSource(Ye);if(!t)return;const a={type:"FeatureCollection",features:Ya.map(e=>({type:"Feature",properties:{parcelId:e.parcelId},geometry:e.geometry}))};t.setData(a)},[Ya,ue,ja,Se]),t.useEffect(()=>{const e=u.current;if(!e||ue)return;const t=()=>{try{e.getLayer(Mt)&&e.removeLayer(Mt),e.getSource(_t)&&e.removeSource(_t)}catch{}};if(!La||0===Ya.length)return void t();const a={type:"FeatureCollection",features:Ya.filter(e=>e.bbox).map(e=>{const[t,a,r,n]=e.bbox;return{type:"Feature",properties:{parcelId:e.parcelId},geometry:{type:"Polygon",coordinates:[[[t,a],[r,a],[r,n],[t,n],[t,a]]]}}})},r=e.getSource(_t);return r?r.setData(a):(e.addSource(_t,{type:"geojson",data:a}),e.addLayer({id:Mt,type:"line",source:_t,slot:"top",paint:{"line-color":"#ef4444","line-width":2,"line-dasharray":[3,2],"line-opacity":.9}})),t},[La,Ya,ue,ja]),t.useEffect(()=>{const e=u.current;if(e&&!ue&&!Se){try{e.getLayer(Qe)&&e.removeLayer(Qe),e.getLayer(et)&&e.removeLayer(et),e.getLayer(Ve)&&e.removeLayer(Ve),e.getSource(Ye)&&e.removeSource(Ye)}catch{}Va([])}},[Se,ue]);const Zr=t.useCallback(e=>{Va(t=>t.filter(t=>t.parcelId!==e))},[]),Wr=t.useCallback(()=>{Va([]),g.info("Wyczyszczono zaznaczenie działek.")},[]),Br=t.useCallback(()=>{if(0===Ya.length)return;const e={type:"FeatureCollection",features:Ya.map(e=>({type:"Feature",properties:{parcelId:e.parcelId},geometry:e.geometry}))},t=new Blob([JSON.stringify(e,null,2)],{type:"application/geo+json"}),a=URL.createObjectURL(t),r=document.createElement("a");r.href=a,r.download="wybrane-dzialki.geojson",document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(a),g.success(`Wyeksportowano ${Ya.length} działek do GeoJSON.`)},[Ya]),qr=t.useCallback(async(e="auto")=>{var t,a,r,n,o,i,s,l,c,d,p,m;if(!u.current||0===Ya.length)return void g.error("Brak zaznaczonych działek lub mapa nie jest gotowa.");if(1!==Ya.length)return void g.error("Raport wyceny PDF działa dla jednej zaznaczonej działki naraz.");const x=Ya[0],y="Polygon"===x.geometry.type?null==(t=x.geometry.coordinates)?void 0:t[0]:"MultiPolygon"===x.geometry.type?null==(r=null==(a=x.geometry.coordinates)?void 0:a[0])?void 0:r[0]:void 0,f=null==re?void 0:re.access_token;if(!y||y.length<3||!f)return void g.error("Brak geometrii działki lub aktywnej sesji admina.");const b=Math.round(Lt(y)),w=y.reduce((e,t)=>e+t[0],0)/y.length,v=y.reduce((e,t)=>e+t[1],0)/y.length,j=((null==(n=Qa[x.parcelId])?void 0:n.designation)??"").toLowerCase(),z=j.includes("rol")?"rolna":j.includes("zagrod")?"zagrodowa":"budowlana";try{const{data:e,error:t}=await h.functions.invoke("aestimator-valuate",{body:{lat:v,lng:w,area:b,location:(null==(o=x.matchedOffers[0])?void 0:o.location)??null,parcel_id:x.parcelId,mpzp:z,view:"brak",slope:"plaska",infra:"pelna",building_mode:"auto",building_floors:2,building_standard:"standard"},headers:{Authorization:`Bearer ${f}`}});if(t)throw t;if(!e)throw new Error("Brak danych wyceny z Aestimatora.");const a=(null==(i=e.calculations)?void 0:i.total_estimated_value)??(null==(s=e.valuation_ranges)?void 0:s.realistic_market)??0;await fe({address:(null==(l=x.matchedOffers[0])?void 0:l.location)??`Działka ${x.parcelId}`,area_m2:b,c_base_pln:a,c_min_pln:(null==(c=e.valuation_ranges)?void 0:c.pessimistic_quick_sale)??Math.round(.8*a),c_max_pln:(null==(d=e.valuation_ranges)?void 0:d.optimistic_negotiation)??Math.round(1.2*a),mpzp:z,land_value_pln:null==(p=e.calculations)?void 0:p.land_estimated_value,building_value_pln:null==(m=e.calculations)?void 0:m.building_estimated_value,source_label:`AEstymator v2 · RCiWN + scraper + Geoportal · działka ${x.parcelId}`,expert_comment:e.expert_comment,computed_at:new Date,lat:v,lng:w}),g.success("Raport PDF z wyceną został pobrany.")}catch(k){g.error(k instanceof Error?k.message:"Nie udało się wygenerować raportu wyceny PDF.")}},[Ya]),Ur=t.useCallback(()=>{var e,t;null==(e=Na.current)||e.call(Na),null==(t=u.current)||t.flyTo({...He,duration:3e3,essential:!0,easing:It,curve:1.6})},[]);return a.jsxs("div",{className:"fixed inset-0 bg-background",children:[a.jsxs(i,{children:[a.jsx("title",{children:"Mapa 3D działek — Podhale, Spisz, Orawa | Kancelaria Centrum"}),a.jsx("meta",{name:"description",content:"Interaktywna mapa 3D nieruchomości i działek na Podhalu, Spiszu i Orawie. Zobacz ukształtowanie terenu, nasłonecznienie i granice ewidencyjne — zanim pojedziesz w teren. Bezpłatne, umów prezentację."}),a.jsx("link",{rel:"canonical",href:"https://nieruchomoscipodhala.pl/mapa-3d"}),a.jsx("meta",{property:"og:type",content:"website"}),a.jsx("meta",{property:"og:title",content:"Mapa 3D działek — Podhale, Spisz, Orawa | Kancelaria Centrum"}),a.jsx("meta",{property:"og:description",content:"Interaktywna mapa 3D nieruchomości i działek na Podhalu, Spiszu i Orawie. Zobacz teren, nasłonecznienie i granice ewidencyjne zanim pojedziesz na miejsce."}),a.jsx("meta",{property:"og:url",content:"https://nieruchomoscipodhala.pl/mapa-3d"}),a.jsx("script",{type:"application/ld+json",children:JSON.stringify({"@context":"https://schema.org","@type":"WebApplication",name:"Mapa 3D działek Podhala",url:"https://nieruchomoscipodhala.pl/mapa-3d",applicationCategory:"RealEstateApplication",operatingSystem:"Web (WebGL)",browserRequirements:"Requires WebGL",description:"Interaktywna mapa 3D nieruchomości i działek na Podhalu, Spiszu i Orawie z warstwą Geoportalu ULDK i MPZP.",inLanguage:"pl-PL",provider:{"@type":"RealEstateAgent",name:"Kancelaria Obrotu Nieruchomościami Centrum",url:"https://nieruchomoscipodhala.pl",telephone:"+48531648150",address:{"@type":"PostalAddress",streetAddress:"ul. Królowe
2j Jadwigi 42/1",postalCode:"34-400",addressLocality:"Nowy Targ",addressCountry:"PL"}},offers:{"@type":"Offer",price:"0",priceCurrency:"PLN",availability:"https://schema.org/InStock"}})}),a.jsx("script",{type:"application/ld+json",children:JSON.stringify({"@context":"https://schema.org","@type":"FAQPage",mainEntity:[{"@type":"Question",name:"Czy mapa pokazuje rzeczywiste granice działek?",acceptedAnswer:{"@type":"Answer",text:"Tak. Granice ewidencyjne pobieramy na żywo z państwowego Geoportalu (usługa ULDK). Ostateczne wytyczenie granic w terenie wykonuje uprawniony geodeta."}},{"@type":"Question",name:"Czy mogę obejrzeć działkę przed wizytą na miejscu?",acceptedAnswer:{"@type":"Answer",text:"Tak — to główny cel mapy 3D. Sprawdzisz ukształtowanie terenu, nasłonecznienie, sąsiedztwo i widoki z komputera lub telefonu."}},{"@type":"Question",name:"Czy korzystanie z mapy 3D jest płatne?",acceptedAnswer:{"@type":"Answer",text:"Nie. Mapa 3D jest w pełni bezpłatna i nie wymaga rejestracji."}}]})}),a.jsx("script",{type:"application/ld+json",children:JSON.stringify({"@context":"https://schema.org","@type":"HowTo",name:"Jak korzystać z mapy 3D działek Podhala",de
2scription:"Cztery kroki, żeby obejrzeć działkę na Podhalu w widoku 3D, zanim pojedziesz w teren.",totalTime:"PT3M",step:[{"@type":"HowToStep",position:1,name:"Otwórz mapę",text:"Wejdź na /mapa-3d — potrzebna jest przeglądarka z obsługą WebGL."},{"@type":"HowToStep",position:2,name:"Wybierz ofertę",text:"Kliknij pinezkę z ceną lub wybierz nieruchomość z listy; kamera przeleci nad działką i podświetli jej granice."},{"@type":"HowToStep",position:3,name:"Obracaj widok 3D",text:"Przeciągnij prawym przyciskiem myszy (lub dwoma palcami na telefonie), zmień porę dnia suwakiem słońca, włącz warstwę MPZP."},{"@type":"HowToStep",position:4,name:"Umów prezentację",text:"Kliknij Zadzwoń lub Umów spotkanie w panelu oferty — skontaktujemy się w ciągu jednego dnia roboczego."}]})})]}),a.jsxs("div",{className:"sr-only","aria-hidden":"true",children:[a.jsx("h1",{children:"Interaktywna mapa 3D działek i nieruchomości — Podhale, Spisz, Orawa"}),a.jsx("p",{children:"Nasza mapa 3D pozwala kupującym ocenić działkę lub dom z każdej perspektywy — obrót o 360°, pochylenie kamery, symulacja słońca o różnych porach dnia i podkład satelitarny łączą się z warstwami z państwowego Geoportalu (ULDK, MPZP)."}),a.jsx("h2",{children:"Czym jest nasza mapa 3D"}),a.jsx("p",{children:'Autorskie narzędzie Kancelarii Obrotu Nieruchomościami Centrum, zbudowane na Mapbox GL JS z realistycznym modelem terenu. Zintegrowane z Geoportalem krajowym (ULDK) — granice działek ewidencyjnych rysują się automatycznie po wskazaniu punktu. Warstwa MPZP pokazuje miejscowe plany zagospodarowania, a spacery 360° pozwalają wejść „do środka" wybranych ofert. Jesteśmy jedni z nielicznych pośredników w Polsce oferujących taką wizualizację.'}),a.jsx("h2",{children:"Co zobaczysz przed wizytą na działce"}),a.jsxs("ul",{children:[a.jsx("li",{children:"Ukształtowanie i nachylenie terenu."}),a.jsx("li",{children:"Nasłonecznienie stoków — symulacja pozycji słońca dla dowolnej daty i godziny."}),a.jsx("li",{children:"Granice ewidencyjne z Geoportalu (ULDK), z numerem działki i powierzchnią."}),a.jsx("li",{children:"Otoczenie i widoki — panorama Tatr, sąsiednia zabudowa, lasy, cieki wodne."}),a.jsx("li",{children:"Dojazd — drogi publiczne, odległość do wyciągu, szlaku i centrum miejscowości."})]}),a.jsx("h2",{children:"Jak korzystać z mapy 3D"}),a.jsxs("ol",{children:[a.jsx("li",{children:"Otwórz mapę na /mapa-3d."}),a.jsx("li",{children:"Wybierz ofertę — kliknij pinezkę z ceną lub wybierz nieruchomość z listy."}),a.jsx("li",{children:"Obracaj widok 3D — przeciągnij prawym przyciskiem myszy lub dwoma palcami na telefonie."}),a.jsx("li",{children:"Umów prezentację — kliknij Zadzwoń lub Umów spotkanie w panelu oferty."})]}),a.jsxs("blockquote",{children:[a.jsx("p",{children:'„Na Podhalu ukształtowanie terenu potrafi przesądzić o wartości działki. Dzięki mapie 3D klient widzi nachylenie stoku, nasłonecznienie i granice ewidencyjne, zanim pojedzie na miejsce."'}),a.jsx("footer",{children:"— Maciej Żywczak, Kancelaria Obrotu Nieruchomościami Centrum"})]}),a.jsx("h2",{children:"Pytania o mapę 3D"}),a.jsx("h3",{children:"Czy mapa pokazuje rzeczywiste granice działek?"}),a.jsx("p",{children:"Tak. Granice ewidencyjne pobieramy na żywo z państwowego Geoportalu (usługa ULDK). Ostateczne wytyczenie granic w terenie wykonuje uprawniony geodeta."}),a.jsx("h3",{children:"Czy mogę obejrzeć działkę przed wizytą na miejscu?"}),a.jsx("p",{children:"Tak — to główny cel mapy 3D. Sprawdzisz ukształtowanie terenu, nasłonecznienie, sąsiedztwo i widoki z komputera lub telefonu."}),a.jsx("h3",{children:"Czy korzystanie z mapy 3D jest płatne?"}),a.jsx("p",{children:"Nie. Mapa 3D jest w pełni bezpłatna i nie wymaga rejestracji."})]}),a.jsx("div",{ref:e,className:l("absolute inset-0 map3d-canvas",hr&&"map3d-panel-open"),"aria-label":"Interaktywna mapa 3D Podhala"}),a.jsx("div",{ref:K,className:"fixed top-0 left-0 z-[60] pointer-events-none liquid-glass border border-accent/30 rounded-lg px-3 py-2 text-xs opacity-0 transition-opacity duration-150",style:{transform:"translate(-9999px, -9999px)"},"aria-hidden":"true"}),a.jsx("div",{ref:X,className:"fixed top-0 left-0 z-[59] pointer-events-none liquid-glass border border-accent/20 rounded-lg px-3 py-2 text-xs opacity-0 transition-opacity duration-150",style:{transform:"translate(-9999px, -9999px)",backdropFilter:"blur(8px)",WebkitBackdropFilter:"blur(8px)"},"aria-hidden":"true"}),a.jsx(de,{property:hr,onClose:()=>gr(null),onBalconyView:e=>kr(e),mapMode:fa,onToggleMapMode:()=>ba("3d-satellite"===fa?"2d-streets":"3d-satellite")}),dr&&a.jsx(y,{propertyTitle:dr.property.title,newLat:dr.newLat,newLng:dr.newLng,onConfirm:Nr,onCancel:Sr,saving:pr}),ue&&a.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/80 backdrop-blur-sm z-50",children:a.jsxs("div",{className:"flex flex-col items-center gap-3",children:[a.jsx(F,{className:"w-10 h-10 text-accent animate-spin"}),a.jsx("p",{className:"text-sm text-muted-foreground",children:"Ładowanie mapy 3D…"})]})}),me&&!ue&&!ge&&a.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/95 backdrop-blur-sm z-50 px-6",children:a.jsxs("div",{className:"max-w-md text-center bg-card/95 border border-border/50 rounded-2xl shadow-2xl p-8",children:[a.jsx("div",{className:"w-12 h-12 mx-auto mb-4 rounded-full bg-accent/10 flex items-center justify-center",children:a.jsx(v,{className:"w-6 h-6 text-accent"})}),a.jsx("p",{className:"text-lg font-semibold text-foreground mb-2",children:"Mapa 3D niedostępna"}),a.jsx("p",{className:"text-sm text-muted-foreground mb-5 leading-relaxed",children:"Twoja przeglądarka lub urządzenie nie obsługuje WebGL wymaganego do mapy 3D."}),a.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 justify-center",children:[a.jsx(d,{asChild:!0,children:a.jsxs(r,{to:"/mapa",children:[a.jsx(_,{className:"w-4 h-4 mr-1.5"}),"Klasyczna mapa 2D"]})}),a.jsxs(d,{variant:"outline",onClick:()=>window.location.reload(),children:[a.jsx(M,{className:"w-4 h-4 mr-1.5"}),"Spróbuj ponownie"]})]})]})}),a.jsxs("div",{className:"absolute top-4 left-4 z-40 flex items-center gap-2",children:[a.jsx(d,{asChild:!0,variant:"ghost",size:"sm",className:"liquid-glass-luxe border-0 text-white hover:bg-white/10 hover:text-white h-9 px-3",children:a.jsxs(r,{to:"/oferty","aria-label":"Powrót do listy ofert",children:[a.jsx(_,{className:"w-4 h-4 mr-1.5"}),"Oferty"]})}),a.jsxs(c,{className:"liquid-glass-luxe text-white gap-1.5 py-1.5 px-3 border-0",children:[a.jsx(v,{className:"w-3 h-3 text-accent"}),a.jsx("span",{className:"text-xs font-semibold",children:"Mapa 3D Podhala"})]}),xa>0&&a.jsxs(c,{variant:"outline",className:"liquid-glass-luxe text-xs border-0 text-white py-1.5 px-2.5",children:[xa," ofert"]})]}),a.jsxs("button",{type:"button",onClick:()=>ga(e=>!e),"aria-label":ha?"Zamknij panel sterowania":"Otwórz panel sterowania","aria-expanded":ha,className:"md:hidden fixed bottom-[88px] right-4 z-50 px-4 py-3 rounded-full shadow-lg liquid-glass-luxe text-white border border-white/20 inline-flex items-center gap-2",children:[ha?a.jsx(f,{className:"w-4 h-4","aria-hidden":"true"}):a.jsx(I,{className:"w-4 h-4","aria-hidden":"true"}),a.jsx("span",{className:"text-sm font-medium",children:ha?"Zamknij":"Filtry / Narzędzia"})]}),a.jsx("div",{"aria-hidden":"true",onClick:()=>
2ga(!1),className:l("md:hidden fixed inset-0 z-30 bg-foreground/30 backdrop-blur-[2px] transition-opacity duration-300",ha?"opacity-100":"opacity-0 pointer-events-none")}),a.jsx("button",{type:"button",onClick:()=>be(e=>!e),"aria-label":ye?"Rozwiń panel narzędzi":"Zwiń panel narzędzi",className:"hidden md:flex absolute top-1/2 -translate-y-1/2 z-50 items-center justify-center w-8 h-16 rounded-r-xl liquid-glass-luxe border border-accent/30 text-accent hover:text-white transition-all duration-300",style:{left:ye?0:288},children:ye?a.jsx(w,{className:"w-4 h-4"}):a.jsx(b,{className:"w-4 h-4"})}),a.jsxs("div",{className:l("z-40 flex flex-col gap-3","md:absolute md:top-4 md:left-4 md:max-w-[280px] md:max-h-none md:overflow-visible md:p-0 md:transition-transform md:duration-300 md:ease-out md:rounded-none","fixed left-0 right-0 bottom-0 max-h-[75vh] overflow-y-auto p-3 rounded-t-3xl transition-transform duration-300 ease-out",ha?"translate-y-0":"translate-y-full md:translate-y-0",ye?"md:-translate-x-full":"md:translate-x-0"),children:[a.jsxs("div",{className:"liquid-glass-luxe p-1.5 flex gap-1",role:"group","aria-label":"Tryb mapy",children:[a.jsxs("button",{type:"button",onClick:()=>ba("3d-satellite"),className:l("flex-1 flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-[10px] text-[11px] font-semibold transition-all","3d-satellite"===fa?"bg-white text-slate-900 shadow-sm":"text-white/75 hover:bg-white/10 hover:text-white"),"aria-pressed":"3d-satellite"===fa,children:[a.jsx(z,{className:"w-3.5 h-3.5"})," 3D"]}),a.jsxs("button",{type:"button",onClick:()=>ba("2d-streets"),className:l("flex-1 flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-[10px] text-[11px] font-semibold transition-all","2d-streets"===fa?"bg-white text-slate-900 shadow-sm":"text-white/75 hover:bg-white/10 hover:text-white"),"aria-pressed":"2d-streets"===fa,children:[a.jsx(k,{className:"w-3.5 h-3.5"})," 2D"]}),a.jsxs("button",{type:"button",onClick:()=>ba("2d-outdoors"),className:l("flex-1 flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-[10px] text-[11px] font-semibold transition-all","2d-outdoors"===fa?"bg-white text-slate-900 shadow-sm":"text-white/75 hover:bg-white/10 hover:text-white"),"aria-pressed":"2d-outdoors"===fa,children:[a.jsx(E,{className:"w-3.5 h-3.5"})," Teren"]})]}),a.jsxs("div",{className:"liquid-glass-luxe p-3.5 space-y-3.5",children:[a.jsxs("div",{className:"flex items-center justify-between gap-3",children:[a.jsxs(p,{htmlFor:"toggle-parcels",className:"flex items-center gap-2 text-xs font-semibold cursor-pointer text-white",children:[a.jsx(E,{className:"w-3.5 h-3.5 text-accent"}),"Granice działek"]}),a.jsx(m,{id:"toggle-parcels",checked:Se,onCheckedChange:Ce,"aria-label":"Pokaż granice działek z Geoportalu"})]}),a.jsxs("div",{className:l("flex items-center justify-between gap-3 rounded-md -mx-1 px-1","loading"===Ga&&"shimmer-loading"),children:[a.jsxs(p,{htmlFor:"toggle-mpzp",className:"flex items-center gap-2 text-xs font-semibold cursor-pointer text-white",children:[a.jsx(E,{className:"w-3.5 h-3.5 text-accent"}),"Plan Zagospodarowania (MPZP)","loading"===Ga&&a.jsx(F,{className:"w-3 h-3 animate-spin text-accent","aria-label":"Ładowanie planu"})]}),a.jsx(m,{id:"toggle-mpzp",checked:Fe,onCheckedChange:Pe,"aria-label":"Pokaż Miejscowy Plan Zagospodarowania Przestrzennego"})]}),a.jsxs("div",{className:"flex items-center justify-between gap-3",children:[a.jsxs(p,{htmlFor:"toggle-poi",className:"flex items-center gap-2 text-xs font-semibold cursor-pointer text-white",children:[a.jsx(z,{className:"w-3.5 h-3.5 text-accent"}),"Punkty turystyczne"]}),a.jsx(m,{id:"toggle-poi",checked:_e,onCheckedChange:Me,"aria-label":"Pokaż wyciągi narciarskie i wejścia na szlaki"})]}),Se&&a.jsx("p",{className:"text-[10px] text-white/70 leading-tight",children:"Działki widoczne od zoom 15 — przybliż mapę."}),Fe&&a.jsx("p",{className:"text-[10px] text-white/70 leading-tight",children:"Plan zagospodarowania widoczny od zoom 13. Dane: Geoportal KIMP."}),Fe&&oe&&a.jsx("a",{href:"https://mapy.geoportal.gov.pl/imap/Imgp_2.html?gpmap=gp0",target:"_blank",rel:"noopener noreferrer",className:"text-[10px] text-accent underline",children:"Sprawdź legendę MPZP na Geoportalu"})]}),a.jsxs("div",{className:"liquid-glass-luxe p-3.5",children:[a.jsxs("div",{className:"flex items-center justify-between gap-3",children:[a.jsxs(p,{htmlFor:"toggle-heatmap",className:"flex items-center gap-2 text-xs font-semibold cursor-pointer text-white",children:[a.jsx(D,{className:"w-3.5 h-3.5 text-accent"}),"Heatmapa cen"]}),a.jsx(m,{id:"toggle-heatmap",checked:Ze,onCheckedChange:We,"aria-label":"Pokaż heatmapę cen i gęstości ofert"})]}),Ze&&a.jsx("p",{className:"text-[10px] text-white/65 leading-tight mt-2",children:"Cieplejszy odcień = droższe oferty / większa gęstość."})]}),oe&&a.jsxs("div",{className:"liquid-glass-luxe p-3.5",children:[a.jsxs("div",{className:"flex items-center justify-between gap-3",children:[a.jsxs(p,{htmlFor:"toggle-ai-
2heatmap",className:"flex items-center gap-2 text-xs font-semibold cursor-pointer text-white",children:[a.jsx(S,{className:"w-3.5 h-3.5 text-accent"}),"Heatmapa AI (wycena)"]}),a.jsx(m,{id:"toggle-ai-heatmap",checked:Be,onCheckedChange:Xt,"aria-label":"Pokaż heatmapę cen z wyceny AI (widoczne tylko dla admina)"})]}),Be&&a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"text-[10px] text-white/65 leading-tight mt-2",children:'Cena bazowa z wyceny AI (RCiWN + scraper) w siatce punktów widocznego obszaru. To NIE są ceny ofertowe — nie mylić z "Heatmapa cen" powyżej.'}),a.jsxs("div",{className:"flex items-center justify-between gap-2 mt-2",children:[a.jsx("span",{className:"text-[10px] text-white/60",children:Wt?"Liczę siatkę cen…":`${Ot.length} punktów`}),a.jsxs(d,{type:"button",size:"sm",variant:"outline",onClick:()=>{Kt()},disabled:Wt,className:"h-6 px-2 text-[10px] border-white/20 text-white hover:bg-white/10",children:[Wt?a.jsx(F,{className:"w-3 h-3 animate-spin"}):a.jsx(M,{className:"w-3 h-3"}),a.jsx("span",{className:"ml-1",children:"Odśwież"})]})]}),a.jsxs("label",{className:"flex items-center gap-2 mt-2 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:Gt,disabled:Wt,onChange:e=>{const t=e.target.checked;Ht.current=t,Jt(t),Kt()},className:"w-3.5 h-3.5 accent-accent"}),a.jsx("span",{className:"text-[10px] text-white/70 leading-tight",children:"Tylko działki budowlane (wg MPZP) — dokładniejsze ceny, ale rzadsza siatka"})]}),qt&&a.jsx("p",{className:"text-[10px] text-destructive leading-tight mt-1",children:qt}),Ot.length>0&&(()=>{const e=Ot.map(e=>e.c_base_per_sqm).filter(e=>Number.isFinite(e)&&e>0);if(0===e.length)return null;const t=e=>Math.round(e).toLocaleString("pl-PL");return a.jsxs("div",{className:"mt-2",children:[a.jsx("div",{className:"h-1.5 w-full rounded-full",style:{background:"linear-gradient(90deg, rgba(59,130,246,0.9) 0%, rgba(212,175,55,0.95) 40%, rgba(245,158,11,0.95) 70%, rgba(220,38,38,0.95) 100%)"}}),a.jsxs("div",{className:"flex items-center justify-between mt-1",children:[a.jsxs("span",{className:"text-[10px] text-white/60",children:[t(Math.min(...e))," zł/m²"]}),a.jsxs("span",{className:"text-[10px] text-white/60",children:[t(Math.max(...e))," zł/m²"]})]}),a.jsx("p",{className:"text-[10px] text-white/45 leading-tight mt-1",children:"Skala dotyczy widocznego obszaru. Przybliż mapę (zoom 12+), żeby zobaczyć ceny przy poszczególnych punktach."})]})})()]})]}),oe&&a.jsxs("form",{className:"liquid-glass-luxe p-3.5 space-y-2.5",onSubmit:e=>{e.preventDefault(),zr()},children:[a.jsxs("label",{htmlFor:"parcel-search",className:"flex items-center gap-2 text-xs font-semibold text-white",children:[a.jsx(T,{className:"w-3.5 h-3.5 text-accent"}),"Szukaj działki po numerze"]}),a.jsxs("div",{className:"flex gap-1.5",children:[a.jsx("input",{id:"parcel-search",type:"text",value:br,onChange:e=>wr(e.target.value),placeholder:"121101_1.0001.2995/16",maxLength:60,autoComplete:"off",className:"flex-1 min-w-0 h-11 rounded-md bg-background/40 border border-white/20 px-2.5 text-xs text-white placeholder:text-white/50 focus:outline-none focus:ring-2 focus:ring-accent"}),a.jsx("button",{type:"submit",disabled:vr,"aria-label":"Szukaj działki",className:"h-11 w-11 shrink-0 flex items-center justify-center rounded-md bg-accent text-accent-foreground disabled:opacity-60",children:vr?a.jsx(F,{className:"w-4 h-4 animate-spin"}):a.jsx(T,{className:"w-4 h-4"})})]})]}),a.jsxs("div",{className:"liquid-glass-luxe p-3.5 space-y-2.5",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2 text-xs font-semibold text-white",children:[a.jsx(k,{className:"w-3.5 h-3.5 text-accent"}),"Czas dojazdu"]}),De&&a.jsx(F,{className:"w-3 h-3 animate-spin text-accent","aria-label":"Ładuję izochrony"})]}),a.jsx("div",{className:"flex gap-1",role:"group","aria-label":"Tryb transportu",children:["driving","walking","cycling"].map(e=>{const t=Ae===e,r="driving"===e?G:"walking"===e?J:H;return a.jsxs("button",{type:"button",onClick:()=>Oe(e),className:l("flex-1 flex items-center justify-center gap-1 px-1.5 py-1.5 rounded-[8px] text-[10px] font-semibold transition-all",t?"bg-white text-slate-900 shadow-sm":"bg-white/5 text-white/70 hover:bg-white/10 hover:text-white"),"aria-pressed":t,title:gt[e],children:[a.jsx(r,{className:"w-3 h-3"})," ",gt[e]]},e)})}),a.jsx("div",{className:"flex gap-1.5",role:"radiogroup","aria-label":"Wybierz próg czasowy izochrony",children:ht.map(e=>{const t=Ie[0]===e;return a.jsxs("button",{type:"button",role:"radio",onClick:()=>{Ee(t=>t[0]===e?[]:[e])},className:l("flex-1 px-2 py-1.5 rounded-[10px] text-[11px] font-semibold transition-all border",t?"bg-accent/90 text-slate-900 border-accent shadow-md":"bg-white/5 text-white/75 border-white/10 hover:bg-white/10 hover:text-white"),"aria-checked":t,"aria-pressed":t,children:[e," min"]},e)})}),$e&&a.jsx("p",{role:"alert",className:"text-[10px] leading-tight text-red-300 bg-red-500/10 border border-red-400/30 rounded-[8px] px-2 py-1.5",children:$e}),a.jsx("p",{className:"text-[10px] text-white/65 leading-tight",children:hr?"Punkt startowy: wybrana oferta.":"Punkt startowy: środek widoku. Wybierz ofertę, aby liczyć od pinezki."})]}),a.jsxs("div",{className:"liquid-glass-luxe p-3.5 space-y-2.5",children:[a.jsxs("div",{className:"flex items-center gap-2 text-xs font-semibold text-white",children:[a.jsx($,{className:"w-3.5 h-3.5 text-accent"}),"Narzędzia"]}),a.jsxs("button",{type:"button",onClick:()=>{Vt(e=>(e&&ta([]),!e))},className:l("w-full flex items-center justify-center gap-1.5 px-2 py-2 rounded-[10px] text-[11px] font-semibold transition-all border",Yt?"bg-accent/90 text-slate-900 border-accent shadow-md":"bg-white/5 text-white/80 border-white/10 hover:bg-white/10 hover:text-white"),"aria-pressed":Yt,children:[a.jsx($,{className:"w-3.5 h-3.5"}),Yt?"Zakończ pomiar":"Zmierz odległość / pole"]}),Yt&&a.jsxs("div",{className:"space-y-1.5",children:[(()=>{const e=Cr();return e?a.jsxs("div",{className:"flex items-center justify-between gap-2 text-[11px] text-white",children:[a.jsxs("span",{children:["Dystans: ",a.jsx("span",{className:"text-accent font-semibold",children:(r=e.dist,r>=1e3?`${(r/1e3).toFixed(2)} km`:`${Math.round(r)} m`)})]}),e.area>0&&a.jsxs("span",{children:["Pole: ",a.jsx("span",{className:"text-accent font-semibold",children:(t=e.area,t>=1e4?`${(t/1e4).toFixed(2)} ha`:`${Math.round(t)} m²`)})]})]}):a.jsx("p",{className:"text-[10px] text-white/65 leading-tight",children:"Klikaj punkty na mapie. 3+ punkty = pole powierzchni."});var t,r})(),a.jsx("button",{type:"button",onClick:()=>ta([]),className:"w-full text-[10px] text-white/70 hover:text-white py-1 rounded-[8px] hover:bg-white/5 transition-colors",children:"Wyczyść punkty"})]}),a.jsxs("button",{type:"button",onClick:$r,disabled:_r,className:l("w-full flex items-center justify-center gap-1.5 px-2 py-2 rounded-[10px] text-[11px] font-semibold transition-all border",_r?"bg-accent/90 text-slate-900 border-accent shadow-md cursor-wait":"bg-white/5 text-white/80 border-white/10 hover:bg-white/10 hover:text-white"),title:"Uruchom kinowy przelot wokół oferty z kadrem na Tatry",children:[a.jsx(S,{className:"w-3.5 h-3.5"}),_r?"Trwa przelot…":"Zobacz w 3D"]}),a.jsxs("button",{type:"button",onClick:Rr,disabled:!Ir||_r,className:"w-full flex items-center justify-center gap-1.5 px-2 py-2 rounded-[10px] text-[11px] font-semibold bg-white/5 text-white/80 border border-white/10 hover:bg-white/10 hover:text-white transition-all disabled:cursor-not-allowed disabled:opacity-40",title:Ir?"Pobierz przygotowany film z przelotu 3D":"Najpierw uruchom przelot 3D",children:[a.jsx(R,{className:"w-3.5 h-3.5"})," Pobierz film"]}),a.jsxs("div",{className:"grid grid-cols-2 gap-1.5",children:[a.jsxs("button",{type:"button",onClick:Ar,className:"flex items-center justify-center gap-1 px-2 py-1.5 rounded-[10px] text-[10px] font-semibold bg-white/5 text-white/80 border border-white/10 hover:bg-white/10 hover:text-white transition-all",title:"Pobierz PNG bieżącego widoku",children:[a.jsx(A,{className:"w-3 h-3"})," PNG"]}),a.jsxs("button",{type:"button",onClick:Or,className:"flex items-center justify-center gap-1 px-2 py-1.5 rounded-[10px] text-[10px] font-semibold bg-white/5 text-white/80 border border-white/10 hover:bg-white/10 hover:text-white transition-all",title:"Skopiuj link z bieżącym widokiem",children:[a.jsx(O,{className:"w-3 h-3"}
2)," Udostępnij"]})]})]}),a.jsxs("div",{className:"liquid-glass-luxe p-3.5 space-y-2.5",children:[a.jsxs("div",{className:"flex items-center gap-2 text-xs font-semibold text-white",children:[a.jsx(v,{className:"w-3.5 h-3.5 text-accent"}),"Obszar wyszukiwania"]}),a.jsxs("button",{type:"button",onClick:()=>{ra?na(!1):(sa([]),da(null),na(!0))},className:l("w-full flex items-center justify-center gap-1.5 px-2 py-2 rounded-[10px] text-[11px] font-semibold transition-all border",ra?"bg-accent/90 text-slate-900 border-accent shadow-md":"bg-white/5 text-white/80 border-white/10 hover:bg-white/10 hover:text-white"),"aria-pressed":ra,children:[a.jsx(v,{className:"w-3.5 h-3.5"}),ra?"Rysowanie…":"Zaznacz obszar"]}),ra&&a.jsx("p",{className:"text-[10px] text-white/65 leading-tight",children:"Klikaj punkty na mapie, aby narysować obszar (min. 3 punkty)."}),(ra||ia.length>0||ca)&&a.jsxs("div",{className:"grid grid-cols-2 gap-1.5",children:[a.jsx("button",{type:"button",onClick:Lr,disabled:ia.length<3,className:"flex items-center justify-center gap-1 px-2 py-1.5 rounded-[10px] text-[10px] font-semibold bg-white/5 text-white/80 border border-white/10 hover:bg-white/10 hover:text-white transition-all disabled:opacity-40 disabled:cursor-not-allowed",children:"Zastosuj obszar"}),a.jsxs("button",{type:"button",onClick:Fr,className:"flex items-center justify-center gap-1 px-2 py-1.5 rounded-[10px] text-[10px] font-semibold bg-white/5 text-white/80 border border-white/10 hover:bg-white/10 hover:text-white transition-all",children:[a.jsx(Z,{className:"w-3 h-3"})," Wyczyść"]})]})]}),a.jsx("div",{className:"liquid-glass-luxe p-2",children:a.jsxs(d,{variant:"ghost",size:"sm",onClick:Ur,className:"w-full h-8 text-xs text-white hover:bg-white/10 hover:text-white",children:[a.jsx(M,{className:"w-3 h-3 mr-1.5"}),"Reset widoku"]})})]}),Ya.length>0&&a.jsxs(a.Fragment,{children:[a.jsx("button",{type:"button",onClick:()=>ze(e=>!e),"aria-label":we?"Rozwiń panel działek":"Zwiń panel działek",className:"hidden md:flex absolute z-50 items-center justify-center w-8 h-16 rounded-l-xl liquid-glass-luxe border border-accent/30 text-accent hover:text-white transition-all duration-300",style:{to
2p:"50%",transform:"translateY(-50%)",right:we?0:308},children:we?a.jsx(b,{className:"w-4 h-4"}):a.jsx(w,{className:"w-4 h-4"})}),a.jsxs("button",{type:"button",onClick:()=>Ne(!1),"aria-label":`Rozwiń panel zaznaczonych działek (${Ya.length})`,"aria-expanded":!1,"data-testid":"parcel-panel-expand",className:l("md:hidden fixed left-3 right-3 bottom-3 z-40 h-[52px] pl-16 pr-4 rounded-lg","bg-background/90 backdrop-blur-md border border-border/60 shadow-xl","flex items-center justify-between gap-3",ke?"flex":"hidden"),children:[a.jsxs("span",{className:"inline-flex items-center gap-2",children:[a.jsxs("span",{className:"inline-flex items-center rounded-full border border-accent/40 bg-accent/10 px-2.5 py-1 text-xs font-semibold text-accent",children:[Ya.length," ",1===Ya.length?"parcela":"parcele"]}),a.jsx("span",{className:"text-xs text-muted-foreground",children:"Zaznaczone działki"})]}),a.jsx(W,{className:"h-4 w-4 text-accent shrink-0","aria-hidden":!0})]}),a.jsxs("aside",{className:l("z-40 rounded-lg bg-background/90 backdrop-blur-md border border-border/60 shadow-xl","fixed left-3 right-3 bottom-3 max-h-[78vh] flex-col",ke?"hidden md:flex":"flex","md:absolute md:left-auto md:right-4 md:top-4 md:bottom-auto md:w-[300px] md:max-h-[70vh] md:transition-transform md:duration-300 md:ease-out",we?"md:translate-x-[calc(100%+1rem)]":"md:translate-x-0"),"aria-label":"Panel zaznaczonych działek",children:[a.jsx("button",{type:"button",onClick:()=>Ne(!0),"aria-label":"Zwiń panel zaznaczonych działek","aria-expanded":!0,"data-testid":"parcel-panel-collapse-handle",className:"md:hidden w-full flex items-center justify-center pt-2 pb-1 shrink-0",children:a.jsx("span",{className:"h-1 w-10 rounded-full bg-border","aria-hidden":!0})}),a.jsxs("header",{className:"flex items-center justify-between gap-2 px-3 pt-3 pb-2 border-b border-border/40 md:pt-3",children:[a.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[a.jsx(d,{type:"button",size:"icon",variant:"ghost",className:"md:hidden h-8 w-8 shrink-0 text-accent",onClick:()=>Ne(!0),"aria-label":"Zwiń panel zaznaczonych działek","data-testid":"parcel-panel-collapse",title:"Zwiń panel",children:a.jsx(B,{className:"h-4 w-4"})}),a.jsxs("div",{className:"min-w-0",children:[a.jsx("div",{className:"text-[10px] uppercase tracking-wide text-accent font-semibold",children:"Zaznaczone działki"}),a.jsxs("div",{className:"text-sm font-semibold text-foreground",children:[Ya.length," ",1===Ya.length?"parcela":"parcele"]})]})]}),a.jsx(d,{type:"button",size:"icon",variant:"ghost",className:"h-8 w-8 shrink-0",onClick:Wr,"aria-label":"Wyczyść całe zaznaczenie",title:"Wyczyść zaznaczenie",children:a.jsx(Z,{className:"h-4 w-4"})})]}),a.jsxs("div",{className:"overflow-y-auto flex-1 min-h-0",children:[a.jsx("ul",{className:"px-2 py-2 space-y-1",children:Ya.map(e=>{const t=Qa[e.parcelId];return a.jsxs("li",{className:"flex items-center justify-between gap-2 rounded-md bg-muted/50 hover:bg-muted px-2 py-1.5 text-xs",children:[a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsxs("div",{className:"flex items-center gap-1.5",children:[a.jsx("span",{className:"font-mono text-foreground truncate",title:e.parcelId,children:e.parcelId}),e.matchedOffers.length>0&&a.jsxs("span",{className:"inline-flex items-center gap-1 shrink-0 rounded-full border border-accent/40 bg-accent/10 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide text-accent",title:`Powiązane oferty: ${e.matchedOffers.length}`,children:[a.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-accent","aria-hidden":!0}),1===e.matchedOffers.length?"Oferta":`${e.matchedOffers.length} ofert`]})]}),e.matchedOffers.slice(0,2).map(e=>a.jsxs("div",{className:"mt-0.5 text-[10px] text-muted-foreground truncate",title:e.title,children:["• ",e.title]},e.pinId)),e.matchedOffers.length>2&&a.jsxs("div",{className:"mt-0.5 text-[10px] text-muted-foreground",children:["…i ",e.matchedOffers.length-2," więcej"]}),oe&&t&&a.jsx("div",{className:"mt-2 rounded-md border border-border/60 bg-background/70 p-2 text-[10px] leading-snug",children:"loading"===t.status?a.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[a.jsx(F,{className:"h-3 w-3 animate-spin"})," Analizuję MPZP…"]}):"error"===t.status?a.jsxs("div",{className:"text-destructive",children:["MPZP: ",t.error??"błąd analizy"]}):a.jsxs("div",{className:"space-y-1",children:[a.jsxs("div",{children:[a.jsx("span",{className:"text-muted-foreground",children:"Przeznaczenie:"})," ",a.jsx("span",{className:"font-semibold text-foreground",children:t.designation??"—"})]}),a.jsxs("div",{children:[a.jsx("span",{className:"text-muted-foreground",children:"Intensywność:"})," ",t.intensity??"—"]}
2),a.jsxs("div",{children:[a.jsx("span",{className:"text-muted-foreground",children:"Wysokość:"})," ",t.maxHeight??"—"]}),a.jsxs("div",{children:[a.jsx("span",{className:"text-muted-foreground",children:"Dach:"})," ",t.roof??"—"]}),t.recommendation&&a.jsx("div",{className:"pt-1 text-accent",children:t.recommendation})]})})]}),a.jsx(d,{type:"button",size:"icon",variant:"ghost",className:"h-7 w-7 shrink-0 text-muted-foreground hover:text-destructive",onClick:()=>Zr(e.parcelId),"aria-label":`Usuń działkę ${e.parcelId}`,title:"Usuń z zaznaczenia",children:a.jsx(f,{className:"h-3.5 w-3.5"})})]},e.parcelId)})}),a.jsxs("div",{className:"px-3 py-2 border-t border-border/40 space-y-2 pb-6",children:[a.jsxs(d,{type:"button",size:"sm",className:"w-full gap-2",onClick:Br,children:[a.jsx(R,{className:"h-4 w-4"}),"Eksportuj do GeoJSON"]}),a.jsxs(d,{type:"button",size:"sm",variant:"outline",className:"w-full gap-2",onClick:()=>{qr()},children:[a.jsx(q,{className:"h-4 w-4"}),"Pobierz raport PDF z mapą"]}),oe&&Ya.map(e=>{const t=function(e){const t="MultiPolygon"===e.type&&e.coordinates.length>0?{type:"Polygon",coordinates:e.coordinates[0]}:e,a=qe(t);if(!a)return null;const[r,n,o,i]=a,s=(r+o)/2,l=(n+i)/2;return Number.isFinite(s)&&Number.isFinite(l)?[s,l]:null}(e.geometry);if(!t)return null;const[r,n]=t,o=`${n.toFixed(6)},${r.toFixed(6)}`,i=Ya.length>1?` — ${e.parcelId.split(".").pop()}`:"";return a.jsxs("div",{className:"flex gap-2","data-testid":"parcel-navigate",children:[a.jsxs(d,{type:"button",size:"sm",variant:"outline",className:"flex-1 gap-2","aria-label":`Nawiguj Google Maps do działki ${e.parcelId}`,onClick:()=>window.open(`https://www.google.com/maps/dir/?api=1&destination=${o}&travelmode=driving`,"_blank","noopener,noreferrer"),children:[a.jsx(U,{className:"h-4 w-4"}),"Nawiguj (Google)",i]}),a.jsx(d,{type:"button",size:"sm",variant:"outline",className:"gap-2","aria-label":`Nawiguj Waze do działki ${e.parcelId}`,onClick:()=>window.open(`https://waze.com/ul?ll=${o}&navigate=yes`,"_blank","noopener,noreferrer"),children:"Waze"})]},`nav-${e.parcelId}`)}),oe&&1===Ya.length&&(()=>{var e;const t=Ya[0],r=(()=>{var e,a,r;const n=t.geometry;return"Polygon"===n.type?null==(e=n.coordinates)?void 0:e[0]:"MultiPolygon"===n.type?null==(r=null==(a=n.coordinates)?void 0:a[0])?void 0:r[0]:void 0})();if(!r||r.length<3)return null;const n=Lt(r),o=r.reduce((e,t)=>e+t[0],0)/r.length,i=r.reduce((e,t)=>e+t[1],0)/r.length,s=function(e){if(!e||e.length<3)return null;const t=e.reduce((e,[,t])=>e+t,0)/e.length,a=111320*Math.cos(t*Math.PI/180),r=function(e){const t=[...e].sort((e,t)=>e[0]-t[0]||e[1]-t[1]),a=(e,t,a)=>(t[0]-e[0])*(a[1]-e[1])-(t[1]-e[1])*(a[0]-e[0]),r=[];for(const i of t){for(;r.length>=2&&a(r[r.length-2],r[r.length-1],i)<=0;)r.pop();r.push(i)}const n=[];for(let i=t.length-1;i>=0;i--){const e=t[i];for(;n.length>=2&&a(n[n.length-2],n[n.length-1],e)<=0;)n.pop();n.push(e)}r.pop(),n.pop();const o=r.concat(n);return o.length>=3?o:e}(e.map(([e,t])=>[e*a,111320*t]));if(r.length<2)return null;if(2===r.length)return 0;let n=1/0;const o=r.length;for(let i=0;i<o;i++){const[e,t]=r[i],[a,s]=r[(i+1)%o],l=a-e,c=s-t,d=Math.hypot(l,c);if(0===d)continue;const u=-c/d,p=l/d;let m=1/0,h=-1/0;for(const[n,o]of r){const a=(n-e)*u+(o-t)*p;a<m&&(m=a),a>h&&(h=a)}const g=h-m;g<n&&(n=g)}return Number.isFinite(n)?Math.round(10*n)/10:null}(r);return a.jsx(je,{children:a.jsx(ve,{lat:i,lng:o,area:Math.round(n),location:(null==(e=t.matchedOffers[0])?void 0:e.location)??null,parcelId:t.parcelId,estimatedWidthM:s})})})()]})]})]})]}),La&&a.jsxs("div",{className:"absolute bottom-4 left-4 z-50 max-w-[300px] rounded-lg bg-background/80 backdrop-blur-md border border-border/50 p-3 text-[11px] font-mono text-foreground shadow-lg",children:[a.jsx("div",{className:"font-semibold text-accent mb-1.5 uppercase tracking-wide text-[10px]",children:"Debug · Geoportal"}),a.jsxs("div",{className:"space-y-0.5",children:[a.jsxs("div",{children:[a.jsx("span",{className:"text-muted-foreground",children:"WMS total:"})," ",a.jsx("span",{className:"text-foreground",children:Pa})]}),a.jsxs("div",{children:[a.jsx("span",{className:"text-muted-foreground",children:"CORS:"})," ",a.jsx("span",{className:"text-foreground",children:Ma}),"  ",a.jsx("span",{className:"text-muted-foreground",children:"timeout:"})," ",a.jsx("span",{className:"text-foreground",children:Ea}),"  ",a.jsx("span",{className:"text-muted-foreground",children:"other:"})," ",a.jsx("span",{className:"text-foreground",children:Ta})]}),a.jsxs("div",{className:"break-words",children:[a.jsx("span",{className:"text-muted-foreground",children:"Last WMS:"})," ",a.jsx("span",{className:"text-foreground",children:Ra})]}),a.jsxs("div",{className:"break-words",children:[a.jsx("span",{className:"text-muted-foreground",children:"ULDK:"})," ",a.jsx("span",{className:"text-foreground",children:Oa})]}),a.jsxs("div",{children:[a.jsx("span",{className:"text-muted-foreground",children:"ULDK code:"})," ",a.jsx("span",{className:"text-foreground",children:qa}),"  ",a.jsx("span",{className:"text-muted-foreground",children:"at:"})," ",a.jsx("span",{className:"text-foreground",children:Wa})]}),a.jsxs("div",{children:[a.jsx("span",{className:"text-muted-foreground",children:"MPZP:"})," ",a.jsx("span",{className:"text-foreground",children:Ga})]})]}),a.jsxs("div",{className:"mt-2 pt-2 border-t border-border/40",children:[a.jsxs("div",{className:"text-muted-foreground mb-1",children:["CSP violations (",sr.length,")"]}
2),0===sr.length?a.jsx("div",{className:"text-foreground/60",children:"— brak —"}):a.jsx("ul",{className:"max-h-32 overflow-y-auto space-y-1 pr-1",children:sr.map((e,t)=>a.jsxs("li",{className:"break-all leading-snug",children:[a.jsx("span",{className:"text-destructive",children:e.violatedDirective})," ",a.jsxs("span",{className:"text-foreground/80",children:["→ ",e.blockedURI]})]},`${e.ts}-${t}`))})]}),a.jsxs("div",{className:"mt-2 pt-2 border-t border-border/40 flex items-center justify-between gap-2",children:[a.jsx(p,{htmlFor:"toggle-wms-log",className:"text-[10px] uppercase tracking-wide text-muted-foreground cursor-pointer leading-tight",children:"Loguj adresy URL WMS (Verbose)"}),a.jsx(m,{id:"toggle-wms-log",checked:Ha,onCheckedChange:Ka,"aria-label":"Przełącznik logowania adresów URL WMS"})]}),a.jsxs(d,{type:"button",size:"sm",variant:"outline",className:"mt-2 h-7 w-full text-[10px]",onClick:cr,children:[a.jsx(M,{className:"h-3 w-3"}),"Resetuj liczniki"]})]})]})};export{Ft as buildMpzpWmsUrl,Ot 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.