1import{E as Ce,a as _e,t as ke,r as t,s as r,j as e,m as _,B as m,w as k,K as T,N as A,x as O,y as l,I as u}from"./index-MoAbC8_9.js";import{A as se}from"./AdminPageLayout-DL0avA2R.js";import{T as Te}from"./textarea-4z16PwID.js";import{B as re}from"./badge-BHbYeRgi.js";import{T as Ae,a as Oe,c as D,b as q}from"./tabs-5EVsfllK.js";import{S as ne,a as ie,b as le,c as oe,d as v}from"./select-ChAxOmxm.js";import{T as De,a as qe,b as ce,c as x,d as Fe,e as j}from"./table-BNHSYido.js";import{D as Ve,f as Pe,a as ze,b as Ie,c as Be}from"./dialog-DrI7Oddz.js";import{C as Ee}from"./confirm-dialog-DHYtbMdr.js";import{S as Le}from"./switch-BHj3-8MN.js";import{T as He}from"./TransferOwnershipDialog-DJ-o6_JR.js";import{S as Re}from"./save-DWdLHugL.js";import{B as Ue}from"./building-crte1H4H.js";import{U as $e}from"./users-xui-UtA1.js";import{F as Ke}from"./file-text-Bif0RP8Y.js";import{A as We}from"./arrow-right-left-Yai1ia-T.js";import{U as Ze}from"./user-plus-BJ2nTN1d.js";import{T as Ge}from"./trash-2-DRJ_nWSl.js";import"./Layout-jB2m3rBw.js";import"./Header-CnJGZ8vQ.js";import"./mountain-BHfTfCFy.js";import"./user-Cvsz7Lm_.js";import"./collapsible-BIxz44zB.js";import"./breadcrumb-CmKLwRya.js";import"./AdminSidebar-B1OFksO6.js";import"./scroll-area-CoT3wSM0.js";import"./index-BdQq_4o_.js";import"./bell-CKHJStUz.js";import"./clipboard-list-CzdQdj9P.js";import"./calculator-GhS8BFwe.js";import"./upload-BH1HltYO.js";import"./wallet-e9E2tgeo.js";import"./calendar-CnsXUgOr.js";import"./trending-up-Cg9WFJWB.js";import"./trending-down-EHPUNHPt.js";import"./settings-BUFFH3UG.js";import"./database-yc2noHJi.js";import"./file-search-B2CpYcS_.js";import"./chevron-down-BDe4YKQW.js";import"./house-DjS1WMqx.js";import"./index-D9-GACGG.js";import"./chevron-up-JyGCcpt9.js";import"./checkbox-D2A7tWS7.js";import"./alert-B1M6s1_G.js";import"./circle-check-7w5_oQMu.js";import"./arrow-left-CZKmX_Y-.js";import"./arrow-right-QNKB-9eH.js";const Ra=()=>{const{id:n}=Ce(),de=_e(),{toast:s}=ke(),[me,pe]=t.useState(!0),[F,g]=t.useState(!1),[b,he]=t.useState(null),[o,V]=t.useState(""),[c,P]=t.useState(""),[d,z]=t.useState(""),[y,I]=t.useState(""),[f,B]=t.useState("active"),[N,E]=t.useState(""),[L,H]=t.useState(""),[R,U]=t.useState(!1),[p,ue]=t.useState([]),[xe,je]=t.useState([]),[fe,$]=t.useState(!1),[w,K]=t.useState(""),[W,S]=t.useState(!1),[ve,C]=t.useState(!1),[Z,G]=t.useState(null),[ge,J]=t.useState(!1);t.useEffect(()=>{n&&(be(),h(),M())},[n]);const be=async()=>{var Y,ee,ae,te;const{data:a,error:i}=await r.from("apartments").select("*").eq("id",n).maybeSingle();if(i||!a){s({variant:"destructive",title:"Chyba",description:"Apartmán nebyl nalezen."}),de("/admin");return}he(a),V(a.code),P(((Y=a.floor)==null?void 0:Y.toString())||""),z(((ee=a.sqm)==null?void 0:ee.toString())||""),I(((ae=a.terrace_sqm)==null?void 0:ae.toString())||""),B(a.status||"active"),E(((te=a.weg_anteil_rv)==null?void 0:te.toString())||""),U(a.excluded_from_voting??!1),H(a.notes||""),pe(!1)},h=async()=>{const{data:a}=await r.from("apartment_owners").select("*, owner_contact:owner_contacts(*)").eq("apartment_id",n).order("is_current",{ascending:!1}).order("member_from",{ascending:!1});ue(a||[])},M=async()=>{const{data:a}=await r.from("owner_contacts").select("*").order("last_name",{ascending:!0});je(a||[])},ye=async()=>{if(!o.trim()){s({variant:"destructive",title:"Chyba",description:"Kód apartmánu je povinný."});return}g(!0);const{error:a}=await r.from("apartments").update({code:o.trim(),floor:c?parseInt(c):null,sqm:d?parseFloat(d):null,terrace_sqm:y?parseFloat(y):null,status:f,weg_anteil_rv:N?parseFloat(N):null,excluded_from_voting:R,notes:L.trim()||null}).eq("id",n);if(a){s({variant:"destructive",title:"Chyba",description:a.code==="23505"?"Apartmán s tÃmto kódem již existuje.":"NepodaÅilo se uložit zmÄny."}),g(!1);return}s({title:"Apartmán byl upraven"}),g(!1)},Q=a=>a?a.company_name?a.company_name:[a.first_name,a.last_name].filter(Boolean).join(" ")||"-":"-",Ne=async()=>{if(!w){s({variant:"destructive",title:"Chyba",description:"Vyberte vlastnÃka."});return}S(!0),await r.from("apartment_owners").update({is_current:!1}).eq("apartment_id",n).eq("is_current",!0);const{error:a}=await r.from("apartment_owners").insert({apartment_id:n,owner_contact_id:w,is_current:!0,member_from:new Date().toISOString().split("T")[0]});if(a){s({variant:"destructive",title:"Chyba",description:"NepodaÅilo se pÅidat vlastnÃka."}),S(!1);return}s({title:"VlastnÃk pÅidán"}),S(!1),$(!1),K(""),h()},we=async()=>
1{if(!Z)return;const{error:a}=await r.from("apartment_owners").delete().eq("id",Z);a?s({variant:"destructive",title:"Chyba",description:"NepodaÅilo se odebrat vlastnÃka."}):(s({title:"VlastnÃk odebrán"}),h()),C(!1),G(null)},Se=async a=>{await r.from("apartment_owners").update({is_current:!1}).eq("apartment_id",n);const{error:i}=await r.from("apartment_owners").update({is_current:!0}).eq("id",a);if(i){s({variant:"destructive",title:"Chyba",description:"NepodaÅilo se nastavit aktuálnÃho vlastnÃka."});return}s({title:"Aktuálnà vlastnÃk nastaven"}),h()},X=xe.filter(a=>!p.some(i=>i.owner_contact_id===a.id));return me?e.jsx(se,{title:"Detail apartmánu",activeSection:"property",activeSubSection:"apartments",breadcrumbs:[{label:"Administrace",href:"/admin"},{label:"Apartmány",href:"/admin?section=property&sub=apartments"},{label:"Detail"}],children:e.jsx("div",{className:"flex items-center justify-center py-24",children:e.jsx(_,{className:"h-8 w-8 animate-spin text-primary"})})}):e.jsxs(se,{title:`${o}`,activeSection:"property",activeSubSection:"apartments",breadcrumbs:[{label:"Administrace",href:"/admin"},{label:"Apartmány",href:"/admin?section=property&sub=apartments"},{label:o}],children:[e.jsxs("div",{className:"max-w-6xl space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-serif text-2xl font-bold text-foreground",children:o}),e.jsxs("p",{className:"text-muted-foreground text-sm mt-1",children:[d?`${d} m²`:"",d&&c?" · ":"",c?`${c}. patro`:"",f==="active"?"":` · ${f}`]})]}),e.jsxs(m,{onClick:ye,disabled:F,size:"sm",className:"gap-1.5",children:[F?e.jsx(_,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Re,{className:"h-3.5 w-3.5"}),"Uložit zmÄny"]})]}),e.jsxs(Ae,{defaultValue:"info",className:"space-y-4",children:[e.jsxs(Oe,{children:[e.jsxs(D,{value:"info",className:"gap-1.5",children:[e.jsx(Ue,{className:"h-3.5 w-3.5"}),"Profil"]}),e.jsxs(D,{value:"owners",className:"gap-1.5",children:[e.jsx($e,{className:"h-3.5 w-3.5"}),"VlastnÃci"]}),e.jsxs(D,{value:"notes",className:"gap-1.5",children:[e.jsx(Ke,{className:"h-3.5 w-3.5"}),"Poznámky"]})]}),e.jsx(q,{value:"info",children:e.jsxs(k,{children:[e.jsx(T,{children:e.jsx(A,{className:"text-base",children:"Základnà informace"})}),e.jsxs(O,{children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"code",children:"Kód apartmánu *"}),e.jsx(u,{id:"code",value:o,onChange:a=>V(a.target.value),placeholder:"napÅ. TOP 1"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"floor",children:"Patro"}),e.jsx(u,{id:"floor",type:"number",value:c,onChange:a=>P(a.target.value),placeholder:"0"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"sqm",children:"Plocha apartmánu (m²)"}),e.jsx(u,{id:"sqm",type:"number",step:"0.1",value:d,onChange:a=>z(a.target.value),placeholder:"56,7"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"terraceSqm",children:"Plocha terasy (m²)"}),e.jsx(u,{id:"terraceSqm",type:"number",step:"0.1",value:y,onChange:a=>I(a.target.value),placeholder:"21,8"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 mt-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"status",children:"Stav"}),e.jsxs(ne,{value:f,onValueChange:B,children:[e.jsx(ie,{id:"status",children:e.jsx(le,{})}),e.jsxs(oe,{children:[e.jsx(v,{value:"active",children:"AktivnÃ"}),e.jsx(v,{value:"inactive",children:"NeaktivnÃ"}),e.jsx(v,{value:"archived",children:"Archivovaný"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"wegAnteil",children:"WEG Share RV"}),e.jsx(u,{id:"wegAnteil",type:"number",value:N,onChange:a=>E(a.target.value),placeholder:"0"})]}),e.jsxs("div",{className:"flex items-center gap-3 pt-6",children:[e.jsx(Le,{id:"excludedFromVoting",checked:R,onCheckedChange:U}),e.jsx(l,{htmlFor:"excludedFromVoting",className:"cursor-pointer",children:"VylouÄen z hlasovánÃ"})]})]})]})]})}),e.jsx(q,{value:"owners",children:e.jsxs(k,{children:[e.jsxs(T,{className:"flex flex-row items-center justify-between",children:[e.jsx(A,{className:"text-base",children:"VlastnÃci"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(m,{size:"sm",variant:"outline",className:"gap-1.5",onClick:()=>J(!0),disabled:p.filter(a=>a.is_current).length===0,children:[e.jsx(We,{className:"h-3.5 w-3.5"}),"PÅevod vlastnictvÃ"]}),e.jsxs(Ve,{open:fe,onOpenChange:$,children:[e.jsx(Pe,{asChild:!0,children:e.jsxs(m,{size:"sm",disabled:X.length===0,className:"gap-1.5",children:[e.jsx(Ze,{className:"h-3.5 w-3.5"}),"PÅidat vlastnÃka"]})}),e.jsxs(ze,{children:[e.jsx(Ie,{children:e.jsx(Be,{children:"PÅidat vlastnÃka"})}),e.jsxs("div",{className:"space-y-4 pt-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:"Vyberte vlastnÃka"}),e.jsxs(ne,{value:w,onValueChange:K,children:[e.jsx(ie,{children:e.jsx(le,{placeholder:"Vyberte vlastnÃka..."})}),e.jsx(oe,{children:X.map(a=>e.jsxs(v,{value:a.id,children:[Q(a),a.email&&` (${a.email})`]},a.id))})]})]}),e.jsxs(m,{onClick:Ne,disabled:W,className:"w-full",children:[W?e.jsx(_,{className:"h-4 w-4 animate-spin mr-2"}):null,"PÅidat"]})]})]})]})]})]}),e.jsx(O,{className:"p-0",children:p.length===0?e.jsx("p",{className:"text-muted-foreground text-sm py-8 text-center",children:"Žádnà vlastnÃci zatÃm nebyli pÅiÅazeni."}):e.jsxs(De,{children:[e.jsx(qe,{children:e.jsxs(ce,{className:"hover:bg-transparent",children:[e.jsx(x,{children:"Jméno"}),e.jsx(x,{children:"E-mail"}),e.jsx(x,{children:"Od"}),e.jsx(x,{children:"Status"}),e.jsx(x,{className:"text-right w-[160px]",children:"Akce"})]})}),e.jsx(Fe,{children:p.map(a=>{var i;return e.jsxs(ce,{className:"h-10",children:[e.jsx(j,{className:"font-medium text-sm py-1",children:Q(a.owner_
1contact)}),e.jsx(j,{className:"text-sm text-muted-foreground py-1",children:((i=a.owner_contact)==null?void 0:i.email)||"-"}),e.jsx(j,{className:"text-sm text-muted-foreground py-1",children:new Date(a.member_from).toLocaleDateString("cs-CZ")}),e.jsx(j,{className:"py-1",children:a.is_current?e.jsx(re,{className:"bg-primary text-primary-foreground",children:"AktuálnÃ"}):e.jsx(re,{variant:"secondary",children:"Historický"})}),e.jsx(j,{className:"text-right py-1",children:e.jsxs("div",{className:"flex justify-end gap-1",children:[!a.is_current&&e.jsx(m,{variant:"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>Se(a.id),children:"Nastavit aktuálnÃ"}),e.jsx(m,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>{G(a.id),C(!0)},children:e.jsx(Ge,{className:"h-3.5 w-3.5 text-destructive"})})]})})]},a.id)})})]})})]})}),e.jsx(q,{value:"notes",children:e.jsxs(k,{children:[e.jsx(T,{children:e.jsx(A,{className:"text-base",children:"Poznámky"})}),e.jsx(O,{children:e.jsx(Te,{value:L,onChange:a=>H(a.target.value),placeholder:"Dalšà informace o apartmánu...",rows:4})})]})})]})]}),e.jsx(Ee,{open:ve,onOpenChange:C,title:"Odebrat vlastnÃka",description:"Opravdu chcete odebrat tohoto vlastnÃka? Tato akce je nevratná.",confirmText:"Odebrat",onConfirm:we}),b&&e.jsx(He,{open:ge,onOpenChange:J,apartmentId:b.id,apartmentCode:b.code,currentOwners:p,onCompleted:()=>{h(),M()}})]})};export{Ra 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.