1import{c as as,t as Pe,r as a,s as c,j as e,w as E,K as U,N as q,O as Y,x as F,B as k,ax as ss,I as T,a4 as It,m as K,y as g,M as ne,a7 as Se,n as Hs,F as Mt,a as Zs,E as Ut}from"./index-MoAbC8_9.js";import{B as P}from"./badge-BHbYeRgi.js";import{T as $s}from"./table-pagination-DgaWMZqT.js";import{A as As}from"./AdminPageLayout-DL0avA2R.js";import{C as oe}from"./checkbox-D2A7tWS7.js";import{T as qt,a as Vt,c as me,b as ue}from"./tabs-5EVsfllK.js";import{S as Ee,a as Fe,b as Re,c as Ie,d as he}from"./select-ChAxOmxm.js";import{T as fe,a as _e,b as te,c as w,d as ye,e as N}from"./table-BNHSYido.js";import{S as Ht}from"./switch-BHj3-8MN.js";import{S as ts}from"./save-DWdLHugL.js";import{D as Bs,a as Ws,b as Js,c as Ks,e as Zt}from"./dialog-DrI7Oddz.js";import{C as $t}from"./chevron-down-BDe4YKQW.js";import{C as Bt,S as Me}from"./Header-CnJGZ8vQ.js";import{E as Wt}from"./eye-DKrvAixa.js";import{C as Jt}from"./circle-check-big-_JLEBINb.js";import{C as Kt}from"./circle-minus-C6Bv3LRu.js";import{C as Gt}from"./circle-help-BFmb_2uk.js";import{C as Es}from"./circle-check-7w5_oQMu.js";import{C as Fs}from"./copy-BJvw7_4P.js";import{C as je}from"./confirm-dialog-DHYtbMdr.js";import{P as Xt}from"./plus-CkJQv7GY.js";import{S as Yt}from"./star-CU0yRqe0.js";import{L as Qt}
1from"./log-in-CT_3hHd4.js";import{V as ea,M as sa}from"./collapsible-BIxz44zB.js";import{P as ta}from"./pencil-C_0Cp3wi.js";import{T as Ue}from"./trash-2-DRJ_nWSl.js";import{L as aa,U as na}from"./unlink-CxCPpy3W.js";import{f as ia}from"./format-Beid_ZIk.js";import{c as ra}from"./cs-DzBP63t1.js";import{I as la}from"./InvitePreviewDialog-DT7jKBqI.js";import{A as ca}from"./arrow-left-CZKmX_Y-.js";import{U as Ae}from"./user-Cvsz7Lm_.js";import{S as oa}from"./shield-check-DViJUJ8V.js";import{U as Rs}from"./user-plus-BJ2nTN1d.js";import{L as da}from"./lock-BEcuk4Jx.js";import{K as Is}from"./key-Do0I7jZr.js";import{U as Ms}from"./users-xui-UtA1.js";import{H as ma}from"./house-DjS1WMqx.js";import{E as ua}from"./external-link-Bd1Ktkpe.js";import"./chevron-left-BrISfdwW.js";import"./Layout-jB2m3rBw.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"./file-text-Bif0RP8Y.js";import"./building-crte1H4H.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"./index-D9-GACGG.js";import"./chevron-up-JyGCcpt9.js";import"./mountain-BHfTfCFy.js";import"./en-US-CQ3IMwMG.js";import"./textarea-4z16PwID.js";import"./send-DIVN8qsp.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const ha=as("FilePenLine",[["path",{d:"m18 5-2.414-2.414A2 2 0 0 0 14.172 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2",key:"142zxg"}],["path",{d:"M21.378 12.626a1 1 0 0 0-3.004-3.004l-4.01 4.012a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506z",key:"2t3380"}],["path",{d:"M8 18h1",key:"13wk12"}]]);/** 7 * @license lucide-react v0.462.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const pa=as("KeyRound",[["path",{d:"M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z",key:"1s6t7t"}],["circle",{cx:"16.5",cy:"7.5",r:".5",fill:"currentColor",key:"w0ekpg"}]]);/** 12 * @license lucide-react v0.462.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const xa=as("Wifi",[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M2 8.82a15 15 0 0 1 20 0",key:"dnpr2z"}],["path",{d:"M5 12.859a10 10 0 0 1 14 0",key:"1x1e6c"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}]]),Us=o=>It.cs[o]??o;function va({ownerId:o}){const{toast:b}=Pe(),[i,V]=a.useState([]),[B,j]=a.useState([]),[H,n]=a.useState([]),[G,R]=a.use
16State({}),[W,z]=a.useState({}),[I,d]=a.useState(null),[x,C]=a.useState(null),[O,u]=a.useState(null),[J,Z]=a.useState(null),Q=a.useCallback(async()=>{var y;const[m,M,ee,_]=await Promise.all([c.rpc("admin_get_legal_delivery_audit",{p_owner_id:o}),c.from("legal_delivery_representative_authorizations").select("*").eq("owner_id",o).order("verified_at",{ascending:!1}),c.from("owner_contact_persons").select("id, first_name, last_name, user_id").eq("owner_contact_id",o).order("sort_order"),c.from("owner_contacts").select("user_id").eq("id",o).maybeSingle()]);V(m.data??[]),j(M.data??[]),n(ee.data??[]);const ie=((y=_.data)==null?void 0:y.user_id)??null;d(ie);const{data:l}=await c.from("legal_delivery_preferences").select("postal_pending_poll_id").eq("owner_id",o).maybeSingle();if(Z((l==null?void 0:l.postal_pending_poll_id)??null),ie){const{data:re}=await c.from("profiles").select("portal_access_enabled, portal_access_disabled_reason").eq("user_id",ie).maybeSingle(),ae=re;C((ae==null?void 0:ae.portal_access_enabled)??null),u((ae==null?void 0:ae.portal_access_disabled_reason)??null)}else C(null)},[o]);a.useEffect(()=>{Q()},[Q]);const r=async m=>{const{error:M}=await c.rpc("admin_grant_legal_delivery_authorization",{p_contact_person_id:m,p_document_reference:G[m]??"",p_valid_until:W[m]||null});M?b({variant:"destructive",title:"Chyba",description:M.message}):(b({title:"OprávnÄnà zaevidováno"}),R(ee=>({...ee,[m]:""})),Q())},h=async m=>{const M=window.prompt("Důvod odvolánà oprávnÄnÃ:");if(!M)return;const{error:ee}=await c.rpc("admin_revoke_legal_delivery_authorization",{p_id:m,p_reason:M});ee?b({variant:"destructive",title:"Chyba",description:ee.message}):Q()},f=async()=>{if(!I)return;const m=window.prompt("Důvod reaktivace (na základÄ jakého požadavku vlastnÃka):");if(!m||m.trim().length<5)return;const{error:M}=await c.rpc("admin_reactivate_portal_access",{p_user_id:I,p_reason:m.trim()});M?b({variant:"destructive",title:"Chyba",description:M.message}):(b({title:"PÅÃstup do portálu byl znovu aktivován"}),Q())},se=async()=>{if(!I)return;const m=window.prompt("Důvod administrátorské blokace pÅÃstupu:");if(!m||m.trim().length<5)return;const{error:M}=await c.rpc("admin_disable_portal_access",{p_user_id:I,p_reason:m.trim()});M?b({variant:"destructive",title:"Chyba",description:M.message}):(b({title:"PÅÃstup do portálu byl zablokován"}),Q())},$=new Date().toISOString().slice(0,10);return e.jsxs(E,{className:"mt-6",children:[e.jsxs(U,{children:[e.jsx(q,{className:"text-base",children:"Komunikace a doruÄovánà (§ 24 odst. 5 WEG)"}),e.jsx(Y,{className:"text-xs",children:"Volbu může provést jen vlastnÃk nebo zástupce s doloženým oprávnÄnÃm jednat za vlastnÃka v této záležitosti. Admin volbu za vlastnÃka nenastavuje."})]}),e.jsxs(F,{className:"space-y-6",children:[I&&x!==null&&e.jsxs("section",{className:"space-y-2",children:[e.jsx("h4",{className:"text-sm font-semibold",children:"PÅÃstup do portálu"}),e.jsx("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:x?e.jsxs(e.Fragment,{children:[e.jsx(P,{variant:"default",className:"text-[10px]",children:"PÅÃstup aktivnÃ"}),J&&e.jsx(P,{variant:"secondary",className:"text-[10px]",children:"PoÅ¡tou â Äeká na dokonÄenà hlasovánÃ"}),e.jsx(k,{size:"sm",variant:"ghost",className:"h-6 px-2 text-xs",onClick:se,children:"Zablokovat pÅÃstup"})]}):O==="admin"?e.jsxs(e.Fragment,{children:[e.jsx(P,{variant:"destructive",className:"text-[10px]",children:"PÅÃstup zablokován administrátorem"}),e.jsx(k,{size:"sm",variant:"outline",className:"h-6 px-2 text-xs",onClick:f,children:"Znovu povolit pÅÃstup"})]}):e.jsx(P,{variant:"destructive",className:"text-[10px]",children:"PoÅ¡tou â portál deaktivován"})}),!x&&O!=="admin"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"PÅÃstup deaktivovaný kvůli volbÄ poÅ¡tovnà komunikace nelze obnovit tlaÄÃtkem. Obnovà se, až vlastnÃk zvolà Elektronicky a potvrdà souhlas (SouhlasÃm). Do té doby mu pÃsemnosti posÃlejte poÅ¡tou."})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h4",{className:"text-sm font-semibold",children:"Historie zmÄn"}),i.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"V portálu nenà evid
16ována žádná volba (Nezvoleno)."}):i.map(m=>e.jsxs("details",{className:"rounded-md border p-2 text-xs",children:[e.jsxs("summary",{className:"cursor-pointer",children:[ss(m.created_at,"cs")," · ",Us(m.previous_method)," â ",e.jsx("strong",{children:Us(m.new_method)}),m.email&&` · ${m.email}`," · zdroj: ",m.source," · ",m.language.toUpperCase()," · verze ",m.terms_version,m.authorization_id&&" · jednal zástupce"]}),e.jsx("pre",{className:"mt-2 whitespace-pre-wrap font-sans text-muted-foreground",children:m.text_snapshot})]},m.id))]}),H.length>0&&e.jsxs("section",{className:"space-y-2",children:[e.jsx("h4",{className:"text-sm font-semibold",children:"Doložená oprávnÄnà zástupců"}),H.map(m=>{const M=B.filter(_=>_.contact_person_id===m.id),ee=M.find(_=>!_.revoked_at&&(!_.valid_until||_.valid_until>=$));return e.jsxs("div",{className:"rounded-md border p-2 text-xs space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"font-medium",children:[m.first_name," ",m.last_name]}),e.jsx(P,{variant:ee?"default":"outline",className:"text-[10px]",children:ee?"OprávnÄnà platné":"Bez oprávnÄnÃ"}),!m.user_id&&e.jsx("span",{className:"text-muted-foreground",children:"(bez úÄtu)"})]}),M.map(_=>e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-muted-foreground",children:[e.jsxs("span",{children:[_.document_reference," · ovÄÅeno ",ss(_.verified_at,"cs"),_.valid_until&&` · platà do ${_.valid_until}`]}),_.revoked_at?e.jsxs("span",{children:["· odvoláno ",ss(_.revoked_at,"cs")," (",_.revoke_reason,")"]}):e.jsx(k,{size:"sm",variant:"ghost",className:"h-6 px-2 text-xs",onClick:()=>h(_.id),children:"Odvolat"})]},_.id)),!ee&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(T,{className:"h-7 text-xs flex-1 min-w-[220px]",placeholder:"Podklad (napÅ. plná moc ze dne â¦, výpis z rejstÅÃku)",value:G[m.id]??"",onChange:_=>R(ie=>({...ie,[m.id]:_.target.value}))}),e.jsx(T,{type:"date",className:"h-7 text-xs w-[150px]",value:W[m.id]??"",onChange:_=>z(ie=>({...ie,[m.id]:_.target.value}))}),e.jsx(k,{size:"sm",className:"h-7 text-xs",disabled:(G[m.id]??"").trim().length<3,onClick:()=>r(m.id),children:"Zaevidovat ovÄÅené oprávnÄnÃ"})]})]},m.id)})]})]})]})}const ga=({apartments:o})=>{const{toast:b}=Pe(),[i,V]=a.useState({}),[B,j]=a.useState({}
16),[H,n]=a.useState(!0),[G,R]=a.useState(null),W=o.map(x=>x.apartment_id);a.useEffect(()=>{W.length>0?z():n(!1)},[o]);const z=async()=>{const{data:x}=await c.from("apartment_wifi_credentials").select("*").in("apartment_id",W),C={},O={};(x||[]).forEach(u=>{C[u.apartment_id]=u,O[u.apartment_id]={...u}}),o.forEach(u=>{O[u.apartment_id]||(O[u.apartment_id]={apartment_id:u.apartment_id,wifi_ssid:"",wifi_password:"",vlan_id:null,ap_name:"",notes:""})}),V(C),j(O),n(!1)},I=async x=>{const C=B[x];if(!C)return;R(x);const O={apartment_id:x,wifi_ssid:C.wifi_ssid||null,wifi_password:C.wifi_password||null,vlan_id:C.vlan_id||null,ap_name:C.ap_name||null,notes:C.notes||null};if(i[x]){const{error:u}=await c.from("apartment_wifi_credentials").update(O).eq("id",i[x].id);if(u){b({variant:"destructive",title:"Chyba",description:"NepodaÅilo se uložit."}),R(null);return}}else{const{error:u}=await c.from("apartment_wifi_credentials").insert(O);if(u){b({variant:"destructive",title:"Chyba",description:"NepodaÅilo se uložit."}),R(null);return}}b({title:"WiFi údaje uloženy"}),R(null),z()},d=(x,C,O)=>{j(u=>({...u,[x]:{...u[x],[C]:O}}))};return H?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(K,{className:"h-6 w-6 animate-spin text-primary"})}):W.length===0?e.jsx(E,{children:e.jsx(F,{className:"py-8 text-center text-muted-foreground",children:"VlastnÃk nemá pÅiÅazené žádné apartmány."})}):e.jsx("div",{className:"space-y-6",children:o.map(x=>{var O;const C=B[x.apartment_id]||{};return e.jsxs(E,{children:[e.jsx(U,{children:e.jsxs(q,{className:"text-lg flex items-center gap-2",children:[e.jsx(xa,{className:"h-5 w-5"}),x.apartment.code," â WiFi"]})}),e.jsxs(F,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{children:"SSID"}),e.jsx(T,{value:C.wifi_ssid||"",onChange:u=>d(x.apartment_id,"wifi_ssid",u.target.value),placeholder:"Název WiFi sÃtÄ"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{children:"Heslo"}),e.jsx(T,{value:C.wifi_password||"",onChange:u=>d(x.apartment_id,"wifi_password",u.target.value),placeholder:"Heslo WiFi"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{children:"VLAN ID"}),e.jsx(T,{type:"number",value:((O=C.vlan_id)==null?void 0:O.toString())||"",onChange:u=>d(x.apartment_id,"vlan_id",u.target.value?parseInt(u.target.value):null),placeholder:"VLAN ÄÃslo"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{children:"AP Name"}),e.jsx(T,{value:C.ap_name||"",onChange:u=>d(x.apartment_id,"ap_name",u.target.value),placeholder:"Název access pointu"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{children:"Poznámky"}),e.jsx(T,{value:C.notes||"",onChange:u=>d(x.apartment_id,"notes",u.target.value),placeholder:"Volitelné poznámky"})]}),e.jsxs(k,{onClick:()=>I(x.apartment_id),disabled:G===x.apartment_id,children:[G===x.apartment_id?e.jsx(K,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(ts,{className:"h-4 w-4 mr-2"}),"Uložit"]})]})]},x.apartment_id)})})},ja={magic_link:"Magic Link",vote_confirmation:"Potvrzenà hlasu",vote_coowner_notification:"Oznámenà spoluvlastnÃkům",vote_invitation:"Pozvánka k hlasovánÃ",vote_reminder:"PÅipomÃnka",vote_result:"Výsledky hlasovánÃ",announcement_notification:"OznámenÃ",forum_new_post:"Nový pÅÃspÄvek",forum_new_comment:"OdpovÄÄ ve fóru",test_magic_link:"Test: Magic Link",test_vote_confirmation:"Test: Potvrzenà hlasu",test_vote_coowner_notification:"Test: Oznámenà spoluvl.",test_vote_invitation:"Test: Pozvánka",test_vote_reminder:"Test: PÅipomÃnka",test_vote_result:"Test: Výsledky",test_announcement_notification:"Test: OznámenÃ",test_forum_new_post:"Test: Nový pÅÃspÄvek"},qs={sent:{label:"Odesláno",variant:"default",icon:Jt},failed:{label:"Chyba",variant:"destructive",icon:Hs},skipped:{label:"PÅeskoÄeno",variant:"secondary",icon:Kt},unknown:{label:"Neznámý",variant:"outline",icon:Gt}},fa=({ownerEmail:o})=>
16{const[b,i]=a.useState([]),[V,B]=a.useState(!1),[j,H]=a.useState(null),[n,G]=a.useState(1),[R,W]=a.useState(10),[z,I]=a.useState(null),[d,x]=a.useState(""),[C,O]=a.useState(!1),u=async()=>{if(!o)return;B(!0);const{data:r}=await c.from("email_history").select("id, sent_at, recipient, actual_recipient, template_type, subject, status, error_message, language, rendered_html").eq("recipient",o).order("sent_at",{ascending:!1}).limit(200),{data:h}=await c.from("email_history").select("id, sent_at, recipient, actual_recipient, template_type, subject, status, error_message, language, rendered_html").eq("actual_recipient",o).order("sent_at",{ascending:!1}).limit(200),f=new Map;[...r||[],...h||[]].forEach($=>{f.set($.id,$)});const se=Array.from(f.values()).sort(($,m)=>new Date(m.sent_at).getTime()-new Date($.sent_at).getTime());i(se),B(!1)};a.useEffect(()=>{u()},[o]);const J=async r=>{if(x(r.subject||""),r.rendered_html){I(r.rendered_html);return}if(!r.template_type||!r.language)return;O(!0),I(null);const h=r.template_type.replace(/^test_/,""),{data:f}=await c.from("email_templates").select("body_html").eq("template_type",h).eq("language",r.language).eq("is_active",!0).maybeSingle();I((f==null?void 0:f.body_html)||'<p style="padding:20px;color:#888;">Å ablona nenalezena.</p>'),O(!1)},Z=r=>new Date(r).toLocaleString("cs-CZ",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"});if(!o)return e.jsx(E,{children:e.jsxs(F,{className:"py-12 text-center",children:[e.jsx(ne,{className:"h-10 w-10 mx-auto text-muted-foreground mb-3"}),e.jsx("p",{className:"text-muted-foreground",children:"VlastnÃk nemá nastaven email â historie nenà k dispozici."})]})});const Q=b.slice((n-1)*R,n*R);return e.jsxs(e.Fragment,{children:[e.jsxs(E,{children:[e.jsx(U,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs(q,{className:"text-lg flex items-center gap-2",children:[e.jsx(ne,{className:"h-5 w-5"}),"E-mailová komunikace"]}),e.jsxs(Y,{children:["VÅ¡echny e-maily odeslané na ",o," (",b.length," záznamů)."]})]}),e.jsx(k,{variant:"outline",size:"icon",onClick:u,disabled:V,children:e.jsx(Se,{className:`h-4 w-4 ${V?"animate-spin":""}`})})]})}),e.jsx(F,{children:V?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(K,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):b.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(ne,{className:"h-8 w-8 mx-auto text-muted-foreground mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Žádné e-maily nebyly odeslány."})]}):e.jsxs(e.Fragment,{children:[e.jsxs(fe,{children:[e.jsx(_e,{children:e.jsxs(te,{children:[e.jsx(w,{className:"w-8"}),e.jsx(w,{children:"Datum"}),e.jsx(w,{children:"Typ"}),e.jsx(w,{children:"PÅedmÄt"}),e.jsx(w,{children:"Stav"}),e.jsx(w,{className:"w-10"})]})}),e.jsx(ye,{children:Q.map(r=>{const h=qs[r.status]||qs.unknown,f=h.icon,se=j===r.id;return e.jsxs(e.Fragment,{children:[e.jsxs(te,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>H(se?null:r.id),children:[e.jsx(N,{className:"px-2",children:se?e.jsx($t,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(Bt,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx(N,{className:"text-xs whitespace-nowrap",children:Z(r.sent_at)}),e.jsx(N,{children:e.jsx(P,{variant:"secondary",className:"text-xs",children:ja[r.template_type||""]||r.template_type||"â"})}),e.jsx(N,{className:"text-sm max-w-[300px] truncate",children:r.subject||"â"}),e.jsx(N,{children:e.jsxs(P,{variant:h.variant,className:"gap-1",children:[e.jsx(f,{className:"h-3 w-3"}),h.label]})}),e.jsx(N,{className:"px-2",children:e.jsx(k,{variant:"ghost",size:"icon",className:"h-7 w-7",title:"Náhled e-mailu",onClick:$=>{$.stopPropagation(),J(r)},children:e.jsx(Wt,{className:"h-4 w-4 text-muted-foreground"})})})]},r.id),se&&e.jsx(te,{children:e.jsx(N,{colSpan:6,className:"bg-muted/30 px-6 py-4",children:e.jsxs("div",{className:"space-y-1 text-xs max-w-xl",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"font-medium text-muted-foreground w-32 shrink-0",children:"PÅÃjemce"}),e.jsx("span",{children:r.recipient})]}),r.actual_recipient&&r.actual_recipient!==r.recipient&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"font-medium text-muted-foreground w-32 shrink-0",children:"Původnà pÅÃjemce"}),e.jsx("span",{children:r.actual_recipient})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"font-medium text-muted-foreground w-32 shrink-0",children:"Jazyk"}),e.jsx("span",{children:r.language==="cs"?"ÄeÅ¡tina":r.language==="de"?"Deutsch":r.language==="en"?"English":r.language||"â"})]}),r.error_message&&e.jsxs("div",{className:"mt-2 p-2 bg-destructive/10 rounded-md",children:[e.jsx("span",{className:"font-medium text-destructive block mb-1",children:"Chyba:"}),e.jsx("pre",{className:"text-destructive whitespace-pre-wrap break-all font-mono",children:r.error_message})]})]})})},`${r.id}-detail`)]})})})]}),e.jsx($s,{currentPage:n,totalPages:Math.max(1,Math.ceil(b.length/R)),pageSize:R,totalItems:b.length,onPageChange:G,onPageSizeChange:r=>{W(r),G(1)},pageSizeOptions:[10,20,50],language:"cs"})]})})]}),e.jsx(Bs,{open:z!==null,onOpenChange:r=>{r||I(null)},children:e.jsxs(Ws,{className:"max-w-2xl max-h-[80vh] overflow-hidden flex flex-col",children:[e.jsx(Js,{children:e.jsx(Ks,{className:"text-base",children:d||"Náhled e-mailu"})}),C?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(K,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):e.jsx("div",{className:"flex-1 overflow-auto border rounded-md",children:e.jsx("iframe",{srcDoc:z||"",className:"w-full min-h-[400px] border-0",sandbox:"",title:"Email preview"})})]})})]})},_a=({ownerEmail:o,ownerUserId:b})=>{const{toast:i}
16=Pe(),[V,B]=a.useState([]),[j,H]=a.useState(!1),n=async()=>{if(!o)return;H(!0);const d="id, sent_at, status, recipient, actual_recipient, provider_message_id, error_message, magic_link_token_prefix",[{data:x},{data:C}]=await Promise.all([c.from("email_history").select(d).eq("template_type","magic_link").eq("recipient",o).order("sent_at",{ascending:!1}).limit(100),c.from("email_history").select(d).eq("template_type","magic_link").eq("actual_recipient",o).order("sent_at",{ascending:!1}).limit(100)]),O=new Map;[...x||[],...C||[]].forEach(r=>O.set(r.id,r));const u=Array.from(O.values()).sort((r,h)=>new Date(h.sent_at).getTime()-new Date(r.sent_at).getTime()),J=u.map(r=>r.magic_link_token_prefix).filter(r=>!!r);let Z={};if(J.length>0){let r=c.from("login_history").select("id, logged_in_at, magic_link_token_prefix, user_id, status").in("magic_link_token_prefix",J).eq("status","success");b&&(r=r.eq("user_id",b));const{data:h}=await r;(h||[]).forEach(f=>{f.magic_link_token_prefix&&!Z[f.magic_link_token_prefix]&&(Z[f.magic_link_token_prefix]={logged_in_at:f.logged_in_at,id:f.id})})}const Q=u.map(r=>{var h,f;return{...r,verified_at:r.magic_link_token_prefix&&((h=Z[r.magic_link_token_prefix])==null?void 0:h.logged_in_at)||null,verified_login_id:r.magic_link_token_prefix&&((f=Z[r.magic_link_token_prefix])==null?void 0:f.id)||null}});B(Q),H(!1)};a.useEffect(()=>{n()},[o,b]);const G=d=>new Date(d).toLocaleString("cs-CZ",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"}),R=async(d,x)=>{try{await navigator.clipboard.writeText(d),i({title:"ZkopÃrováno",description:x})}catch{}};if(!o)return null;const W=V.filter(d=>d.status==="sent").length,z=V.filter(d=>d.verified_at).length,I=V.filter(d=>d.status==="failed").length;return e.jsxs(E,{children:[e.jsx(U,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs(q,{className:"text-lg flex items-center gap-2",children:[e.jsx(pa,{className:"h-5 w-5"}),"Historie pÅihlaÅ¡ovacÃch odkazů (Magic Link)"]}),e.jsxs(Y,{children:["Odesláno: ",e.jsx("span",{className:"font-medium text-foreground",children:W})," ·"," ","OvÄÅeno: ",e.jsx("span",{className:"font-medium text-emerald-600",children:z})," ·"," ","Chyby: ",e.jsx("span",{className:"font-medium text-destructive",children:I})]})]}),e.jsx(k,{variant:"outline",size:"icon",onClick:n,disabled:j,children:e.jsx(Se,{className:`h-4 w-4 ${j?"animate-spin":""}`})})]})}),e.jsx(F,{children:j?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(K,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):V.length===0?e.jsx("div",{className:"text-center py-8 text-sm text-muted-foreground",children:"Žádné magic linky nebyly odeslány."}):e.jsxs(fe,{children:[e.jsx(_e,{children:e.jsxs(te,{children:[e.jsx(w,{children:"Odesláno"}),e.jsx(w,{children:"Stav odeslánÃ"}),e.jsx(w,{children:"OvÄÅenà tokenu"}),e.jsx(w,{children:"Token prefix"}),e.jsx(w,{children:"Message ID"})]})}),e.jsx(ye,{children:V.map(d=>e.jsxs(te,{className:"text-xs",children:[e.jsx(N,{className:"whitespace-nowrap",children:G(d.sent_at)}),e.jsxs(N,{children:[d.status==="sent"?e.jsxs(P,{variant:"default",className:"gap-1",children:[e.jsx(Es,{className:"h-3 w-3"}),"Odesláno"]}):d.status==="failed"?e.jsxs(P,{variant:"destructive",className:"gap-1",title:d.error_message||"",children:[e.jsx(Hs,{className:"h-3 w-3"}),"Chyba"]}):e.jsx(P,{variant:"secondary",children:d.status}),d.error_message&&e.jsx("div",{className:"mt-1 text-[10px] text-destructive/80 max-w-[240px] truncate",title:d.error_message,children:d.error_message})]}),e.jsx(N,{children:d.verified_at?e.jsxs(P,{variant:"default",className:"gap-1 bg-emerald-600 hover:bg-emerald-600",children:[e.jsx(Es,{className:"h-3 w-3"}),"OvÄÅeno ",G(d.verified_at)]}):d.status==="sent"?e.jsxs(P,{variant:"outline",className:"gap-1 text-muted-foreground",children:[e.jsx(Mt,{className:"h-3 w-3"}),"NeovÄÅeno"]}):e.jsx("span",{className:"text-muted-foreground",children:"â"})}),e.jsx(N,{className:"font-mono",children:d.magic_link_token_prefix?e.jsxs("button",{className:"hover:underline inline-flex items-center gap-1",onClick:()=>R(d.magic_link_token_prefix,"Token prefix"),title:"ZkopÃrovat",children:[d.magic_link_token_prefix,e.jsx(Fs,{className:"h-3 w-3 opacity-50"})]}):"â"}),e.jsx(N,{className:"font-mono max-w-[200px]",children:d.provider_message_id?e.jsxs("button",{className:"hover:underline inline-flex items-center gap-1 truncate max-w-full",onClick:()=>
16R(d.provider_message_id,"Message ID"),title:d.provider_message_id,children:[e.jsx("span",{className:"truncate",children:d.provider_message_id}),e.jsx(Fs,{className:"h-3 w-3 opacity-50 shrink-0"})]}):"â"})]},d.id))})]})})]})},Vs={executive:"Jednatel",procurist:"Prokurista",assistant:"Asistent",billing_contact:"FakturaÄnà kontakt",representative:"PovÄÅená osoba",other:"OstatnÃ"},ya=["executive","procurist","assistant","billing_contact","other"],Na=["representative","other"],ba=({ownerContactId:o,ownerType:b})=>{const{toast:i}=Pe(),V=Zs(),[B,j]=a.useState([]),[H,n]=a.useState(!0),[G,R]=a.useState(!1),[W,z]=a.useState(null),[I,d]=a.useState(!1),[x,C]=a.useState(!1),[O,u]=a.useState(null),J=b==="individual",Z=J?"representative":"executive",Q=J?Na:ya,r={first_name:"",last_name:"",email:"",phone:"",role_type:Z,role_label:"",is_primary:!1,can_login:!1,can_vote:!1,can_receive_notifications:!0,is_authorized_signer:!1},[h,f]=a.useState(r);a.useEffect(()=>{se()},[o]);const se=async()=>{n(!0);const{data:l,error:y}=await c.from("owner_contact_persons").select("*").eq("owner_contact_id",o).order("sort_order",{ascending:!0});y&&console.error("Error fetching contact persons:",y),j(l||[]),n(!1)},$=()=>{z(null);const l=B.some(y=>y.is_primary);f({...r,is_primary:!l}),R(!0)},m=async()=>{var ae,Ne;if(!h.first_name.trim()||!h.last_name.trim()){i({variant:"destructive",title:"Chyba",description:"Jméno a pÅÃjmenà jsou povinné."});return}const l=h.email.trim();if((h.can_login||h.can_receive_notifications)&&!l){i({variant:"destructive",title:"Chyba",description:"E-mail je povinný pokud je zapnuto pÅihlášenà nebo notifikace."});return}d(!0);const y={owner_contact_id:o,first_name:h.first_name.trim(),last_name:h.last_name.trim(),email:l||null,phone:h.phone.trim()||null,role_type:h.role_type,role_label:h.role_label.trim()||null,is_primary:h.is_primary,can_login:h.can_login,can_vote:h.can_vote,can_receive_notifications:l?h.can_receive_notifications:!1,is_authorized_signer:h.is_authorized_signer};let re;if(W?{error:re}=await c.from("owner_contact_persons").update(y).eq("id",W):{error:re}=await c.from("owner_contact_persons").insert(y),re){const be=(ae=re.message)!=null&&ae.includes("idx_one_primary_per_owner")?"Může existovat pouze jedna primárnà kontaktnà osoba.":(Ne=re.message)!=null&&Ne.includes("Email is required")?"E-mail je povinný pokud je zapnuto pÅihlášenà nebo notifikace.":re.message||"NepodaÅilo se uložit.";i({variant:"destructive",title:"Chyba",description:be}),d(!1);return}i({title:W?"Osoba aktualizována":"Osoba pÅidána"}),R(!1),d(!1),se()},M=async()=>{if(!O)return;const{error:l}=await c.from("owner_contact_persons").delete().eq("id",O);l?i({variant:"destructive",title:"Chyba",description:"NepodaÅilo se smazat osobu."}):(i({title:"Osoba smazána"}),se()),C(!1),u(null)},ee=J?"PovÄÅené osoby":"Kontaktnà osoby",_=J?"Osoby, kterým můžete povolit pÅÃstup do portálu, zasÃlánà notifikacà a pÅÃpadnÄ i hlasovánà jménem vlastnÃka.":"Osoby oprávnÄné jednat za vlastnÃka a použÃvat portál podle pÅidÄlených oprávnÄnÃ.",ie="PÅidat osobu";return H?e.jsx(E,{className:"mt-6",children:e.jsx(F,{className:"py-8 flex justify-center",children:e.jsx(K,{className:"h-6 w-6 animate-spin text-muted-foreground"})})}):e.jsxs(e.Fragment,{children:[e.jsxs(E,{className:"mt-6",children:[e.jsxs(U,{className:"flex flex-row items-center justify-between space-y-0 pb-3",children:[e.jsxs("div",{children:[e.jsx(q,{className:"text-lg",children:ee}),e.jsx(Y,{children:_})]}),e.jsxs(k,{size:"sm",onClick:$,className:"gap-1.5",children:[e.jsx(Xt,{className:"h-3.5 w-3.5"}),ie]})]}),e.jsx(F,{children:B.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:J?"ZatÃm nejsou pÅidány žádné povÄÅené osoby.":"ZatÃm nejsou pÅidány žádné kontaktnà osoby."}):e.jsxs(fe,{children:[e.jsx(_e,{children:e.jsxs(te,{children:[e.jsx(w,{children:"Jméno"}),e.jsx(w,{children:"Role"}),e.jsx(w,{children:"E-mail"}),e.jsx(w,{children:"Telefon"}),e.jsx(w,{children:"OprávnÄnÃ"}),e.jsx(w,{className:"w-[80px] text-right",children:"Akce"})]})}
16),e.jsx(ye,{children:B.map(l=>e.jsxs(te,{children:[e.jsx(N,{className:"font-medium",children:e.jsxs("div",{className:"flex items-center gap-2",children:[l.is_primary&&e.jsx(Yt,{className:"h-3.5 w-3.5 text-accent-foreground fill-accent shrink-0"}),e.jsxs("span",{children:[l.first_name," ",l.last_name]})]})}),e.jsxs(N,{children:[e.jsx(P,{variant:"outline",className:"text-xs",children:Vs[l.role_type]||l.role_type}),l.role_label&&e.jsx("span",{className:"ml-1.5 text-xs text-muted-foreground",children:l.role_label})]}),e.jsx(N,{className:"text-sm text-muted-foreground",children:l.email||"â"}),e.jsx(N,{className:"text-sm text-muted-foreground",children:l.phone||"â"}),e.jsx(N,{children:e.jsxs("div",{className:"flex gap-1.5",children:[l.can_login&&e.jsx("span",{title:"Může se pÅihlásit",children:e.jsx(Qt,{className:"h-3.5 w-3.5 text-primary"})}),l.can_vote&&e.jsx("span",{title:"Může hlasovat",children:e.jsx(ea,{className:"h-3.5 w-3.5 text-primary"})}),l.can_receive_notifications&&e.jsx("span",{title:"Dostává notifikace",children:e.jsx(ne,{className:"h-3.5 w-3.5 text-primary"})}),l.is_authorized_signer&&e.jsx("span",{title:"OprávnÄný podpisovatel",children:e.jsx(ha,{className:"h-3.5 w-3.5 text-primary"})})]})}),e.jsx(N,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-1",children:[e.jsx(k,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:()=>V(`/admin/contact-person/${l.id}`),children:e.jsx(ta,{className:"h-3.5 w-3.5"})}),e.jsx(k,{size:"icon",variant:"ghost",className:"h-7 w-7 text-destructive hover:text-destructive",onClick:()=>{u(l.id),C(!0)},children:e.jsx(Ue,{className:"h-3.5 w-3.5"})})]})})]},l.id))})]})})]}),e.jsx(Bs,{open:G,onOpenChange:R,children:e.jsxs(Ws,{className:"max-w-lg",children:[e.jsx(Js,{children:e.jsx(Ks,{children:W?J?"Upravit povÄÅenou osobu":"Upravit kontaktnà osobu":J?"PÅidat povÄÅenou osobu":"PÅidat kontaktnà osobu"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{children:"Jméno *"}),e.jsx(T,{value:h.first_name,onChange:l=>f(y=>({...y,first_name:l.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{children:"PÅÃjmenà *"}),e.jsx(T,{value:h.last_name,onChange:l=>f(y=>({...y,last_name:l.target.value}))})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{children:"E-mail"}),e.jsx(T,{type:"email",value:h.email,onChange:l=>f(y=>({...y,email:l.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{children:"Telefon"}),e.jsx(T,{value:h.phone,onChange:l=>f(y=>({...y,phone:l.target.value}))})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{children:"Role"}),e.jsxs(Ee,{value:h.role_type,onValueChange:l=>f(y=>({...y,role_type:l})),children:[e.jsx(Fe,{children:e.jsx(Re,{})}),e.jsx(Ie,{children:Q.map(l=>e.jsx(he,{value:l,children:Vs[l]},l))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{children:"Vlastnà popis role"}),e.jsx(T,{value:h.role_label,onChange:l=>f(y=>({...y,role_label:l.target.value})),placeholder:"NapÅ. hlavnà jednatel"})]})]}),e.jsxs("div",{className:"space-y-3 rounded-md border p-4",children:[e.jsx("p",{className:"text-sm font-medium",children:"OprávnÄnÃ"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(oe,{id:"cp-primary",checked:h.is_primary,onCheckedChange:l=>f(y=>({...y,is_primary:l===!0}))}),e.jsx(g,{htmlFor:"cp-primary",className:"text-sm cursor-pointer",children:"Primárnà kontakt"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(oe,{id:"cp-login",checked:h.can_login,onCheckedChange:l=>f(y=>({...y,can_login:l===!0}))}),e.jsx(g,{htmlFor:"cp-login",className:"text-sm cursor-pointer",children:"Může se pÅihlásit"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(oe,{id:"cp-vote",checked:h.can_vote,onCheckedChange:l=>f(y=>({...y,can_vote:l===!0}
16))}),e.jsx(g,{htmlFor:"cp-vote",className:"text-sm cursor-pointer",children:"Může hlasovat"})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground ml-6",children:"Tato osoba bude moci hlasovat jménem vlastnÃka."})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(oe,{id:"cp-notif",checked:h.can_receive_notifications,onCheckedChange:l=>f(y=>({...y,can_receive_notifications:l===!0}))}),e.jsx(g,{htmlFor:"cp-notif",className:"text-sm cursor-pointer",children:"Dostává notifikace"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(oe,{id:"cp-signer",checked:h.is_authorized_signer,onCheckedChange:l=>f(y=>({...y,is_authorized_signer:l===!0}))}),e.jsx(g,{htmlFor:"cp-signer",className:"text-sm cursor-pointer",children:"OprávnÄný podpisovatel"})]})]})]})]}),e.jsxs(Zt,{children:[e.jsx(k,{variant:"outline",onClick:()=>R(!1),children:"ZruÅ¡it"}),e.jsxs(k,{onClick:m,disabled:I,children:[I&&e.jsx(K,{className:"h-4 w-4 animate-spin mr-2"}),W?"Uložit":"PÅidat"]})]})]})}),e.jsx(je,{open:x,onOpenChange:C,title:"Smazat kontaktnà osobu",description:"Opravdu chcete smazat tuto kontaktnà osobu? Tato akce je nevratná.",confirmText:"Smazat",onConfirm:M})]})},ka={linked:{label:"Propojeno",cls:"bg-emerald-100 text-emerald-800 border-emerald-200",Icon:aa},unlinked:{label:"Odpojeno",cls:"bg-rose-100 text-rose-800 border-rose-200",Icon:na},changed:{label:"ZmÄnÄno",cls:"bg-amber-100 text-amber-800 border-amber-200",Icon:Se}},wa=({ownerContactId:o})=>{const[b,i]=a.useState([]),[V,B]=a.useState(!0);return a.useEffect(()=>{o&&(async()=>{B(!0);const{data:j}=await c.from("owner_user_link_audit").select("*").eq("owner_contact_id",o).order("created_at",{ascending:!1});i(j||[]),B(!1)})()},[o]),e.jsxs(E,{children:[e.jsxs(U,{children:[e.jsxs(q,{className:"text-lg flex items-center gap-2",children:[e.jsx(Me,{className:"h-5 w-5"}),"Historie propojenà úÄtu"]}),e.jsxs(Y,{children:["Auditnà záznamy zmÄn vazby vlastnÃk â uživatelský úÄet (",b.length,"). Záznamy nejsou upravitelné z administrace aplikace."]})]}),e.jsx(F,{children:V?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(K,{className:"h-5 w-5 animate-spin text-primary"})}):b.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Žádné záznamy o zmÄnÄ propojenÃ."}):e.jsx("ul",{className:"space-y-2",children:b.map(j=>{const H=ka[j.action];return e.jsxs("li",{className:"flex items-start gap-3 p-3 rounded-md border bg-muted/20",children:[e.jsxs(P,{className:`${H.cls} gap-1 text-xs shrink-0`,children:[e.jsx(H.Icon,{className:"h-3 w-3"}),H.label]}),e.jsxs("div",{className:"flex-1 min-w-0 text-sm",children:[e.jsxs("div",{className:"text-xs",children:[e.jsx("span",{className:"text-rose-700 line-through mr-2",children:j.old_user_email||(j.old_user_id?j.old_user_id.slice(0,8):"â")}),"â",e.jsx("span",{className:"text-emerald-700 ml-2",children:j.new_user_email||(j.new_user_id?j.new_user_id.slice(0,8):"â")})]}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:[ia(new Date(j.created_at),"dd.MM.yyyy HH:mm",{locale:ra})," · provedl: ",j.performed_by_email||(j.performed_by?j.performed_by.slice(0,8):"systém"),j.source&&j.source!=="app"&&e.jsx(P,{variant:"outline",className:"ml-2 text-[10px]",children:j.source})]}),j.reason&&e.jsxs("div",{className:"text-xs text-muted-foreground mt-1 italic",children:["â",j.reason,'"']})]})]},j.id)})})})]})},Mn=()=>{const{id:o}=Ut(),b=Zs(),{toast:i}=Pe(),[V,B]=a.useState(!0),[j,H]=a.useState(!1),[n,G]=a.useState(null),[R,W]=a.useState("profile"),[z,I]=a.useState(""),[d,x]=a.useState("individual"),[C,O]=a.useState("cs"),[u,J]=a.useState(""),[Z,Q]=a.useState(""),[r,h]=a.useState(""),[f,se]=a.useState(""),[$,m]=a.useState(""),[M,ee]=a.useState(!1),[_,ie]=a.useState(null),[l,y]=a.useState(""),[re,ae]=a.useState(!1),[Ne,be]=a.useState(!1),[qe,Ca]=a.useState(!1),[Gs,ns]=a.useState(!1),[Xs,Ys]=a.useState(null),Ve=(s=!1)=>{if(!z){i({variant:"destructive",title:"Chyba",description:"Pro náhled je nutný e-mail."});return}Ys({email:z,first_name:u,last_name:Z,language:C,role:"owner",owner_contact_id:o,force_resend:s}),ns(!0)}
16,[ce,is]=a.useState(null),[Qs,rs]=a.useState(!1),[za,et]=a.useState([]),[ls,cs]=a.useState(!1),[He,os]=a.useState(!1),[Ze,ds]=a.useState(!1),[ke,ms]=a.useState(!1),[us,hs]=a.useState(""),[$e,ps]=a.useState(!1),[xs,vs]=a.useState(!1),[st,gs]=a.useState(!1),[pe,tt]=a.useState([]),[Oe,at]=a.useState([]),[le,js]=a.useState(""),[fs,nt]=a.useState(new Date().toISOString().split("T")[0]),[De,Be]=a.useState("100"),[xe,Te]=a.useState("percent"),[we,We]=a.useState(""),[_s,Je]=a.useState(!1),[it,Le]=a.useState(!1),[ys,Ns]=a.useState(null),[rt,lt]=a.useState({}),[ct,Ke]=a.useState(!1),[ot,bs]=a.useState(!1),[dt,Ge]=a.useState(!1),[mt,ks]=a.useState(!1),[ut,Xe]=a.useState(!1),[ht,ws]=a.useState(!1),[pt,Ye]=a.useState(!1),[xt,Cs]=a.useState(!1),[ve,vt]=a.useState([]),[gt,zs]=a.useState(!1),[Qe,Ss]=a.useState(1),[Ce,jt]=a.useState(25),[es,ft]=a.useState([]),[_t,Ps]=a.useState(!1);a.useEffect(()=>{o&&(de(),ge(),wt())},[o]);const de=async()=>{const{data:s,error:t}=await c.from("owner_contacts").select("*").eq("id",o).maybeSingle();if(t||!s){i({variant:"destructive",title:"Chyba",description:"VlastnÃk nebyl nalezen."}),b("/admin");return}G(s),I(s.email||""),x(s.user_type||"individual"),O(s.language||"cs"),J(s.first_name||""),Q(s.last_name||""),h(s.phone||""),se(s.company_name||""),B(!1),s.email&&yt(s.email),s.user_id&&(Os(s.user_id),Ct(s.user_id),Ds(s.user_id),bt(s.user_id))},yt=async s=>{rs(!0);try{const t=s.trim().toLowerCase(),{data:p}=await c.from("email_history").select("sent_at, status, template_type, error_message, language").or(`recipient.ilike.${t},actual_recipient.ilike.${t}`).eq("template_type","account_invitation").order("sent_at",{ascending:!1}).limit(1).maybeSingle();is(p||null)}catch{is(null)}finally{rs(!1)}},Os=async s=>{const{data:t}=await c.from("user_roles").select("*").eq("user_id",s);if(t){et(t),os(t.some(v=>v.role==="owner")),ds(t.some(v=>v.role==="admin")),ms(t.some(v=>v.role==="beirat")),ps(t.some(v=>v.role==="spravce"));const L=t.find(v=>v.role==="beirat");hs((L==null?void 0:L.beirat_since)||"")}const{data:p}=await c.from("forum_subscribers").select("id").eq("user_id",s).maybeSingle();vs(!!p)},Nt=async s=>{n!=null&&n.user_id&&(gs(!0),s?await c.from("forum_subscribers").insert({user_id:n.user_id}):await c.from("forum_subscribers").delete().eq("user_id",n.user_id
16),vs(s),gs(!1),i({title:s?"Notifikace vypnuty":"Notifikace zapnuty",description:s?"Uživatel nebude dostávat e-maily z fóra.":"Uživatel bude dostávat e-maily z fóra."}))},Ds=async s=>{try{const{data:t}=await c.functions.invoke("admin-user-actions",{body:{userId:s,action:"get_user_info"}});t!=null&&t.success&&ie(t)}catch{}},bt=async s=>{zs(!0);const{data:t}=await c.from("login_history").select("*").eq("user_id",s).order("logged_in_at",{ascending:!1});vt(t||[]),zs(!1)},ge=async()=>{const{data:s}=await c.from("apartment_owners").select(` 17 *, 18 apartment:apartments(*) 19 `).eq("owner_contact_id",o).order("is_current",{ascending:!1}).order("member_from",{ascending:!1}),t=s||[];if(tt(t),t.length>0){const p=t.map(S=>S.apartment_id),{data:L}=await c.from("apartment_owners").select("apartment_id, owner_contact_id, share_percentage, owner_contact:owner_contacts(first_name, last_name, company_name, id)").in("apartment_id",p).eq("is_current",!0).neq("owner_contact_id",o),v={};(L||[]).forEach(S=>{const A=S.owner_contact,X=(A==null?void 0:A.company_name)||[A==null?void 0:A.first_name,A==null?void 0:A.last_name].filter(Boolean).join(" ")||"Neznámý";v[S.apartment_id]||(v[S.apartment_id]=[]),v[S.apartment_id].push({name:X,owner_contact_id:(A==null?void 0:A.id)||S.owner_contact_id,share_percentage:S.share_percentage})}),lt(v)}},kt=async(s,t)=>{if(!t)return;const{error:p}=await c.from("apartment_owners").update({member_from:t}).eq("id",s);if(p){i({variant:"destructive",title:"Chyba",description:"NepodaÅilo se uložit datum."});return}i({title:"Datum upraveno"}),ge()},wt=async()=>{const{data:s}=await c.from("apartments").select("*").eq("status","active").order("sort_order",{ascending:!0});at(s||[])},Ct=async s=>{Ps(!0);const{data:t}=await c.from("forum_posts").select(` 20 id, 21 content, 22 created_at, 23 thread_id, 24 thread:forum_threads(id, title, category_id, category:forum_categories(slug)) 25 `).eq("user_id",s).order("created_at",{ascending:!1}).limit(50);ft(t||[]),Ps(!1)},zt=async()=>{H(!0);const{error:s}=await c.from("owner_contacts").update({email:z.trim()||null,user_type:d,language:C,first_name:u.trim()||null,last_name:Z.trim()||null,phone:r.trim()||null,company_name:f.trim()||null}).eq("id",o);if(s){i({variant:"destructive",title:"Chyba",description:"NepodaÅilo se uložit zmÄny."}),H(!1);return}i({title:"Profilové informace uloženy"}),H(!1)},St=async()=>{if(!z){i({variant:"destructive",title:"Chyba",description:"Pro vytvoÅenà úÄtu je nutný email."});return}let s=$.trim();if(!s){const t="ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789",p=new Uint32Array(12);crypto.getRandomValues(p),s=Array.from(p,L=>t[L%t.length]).join("")}if(s.length<6){i({variant:"destructive",title:"Chyba",description:"Heslo musà mÃt alespoÅ 6 znaků."});return}be(!0);try{const{data:t,error:p}=await c.functions.invoke("admin-create-user",{body:{email:z,password:s,first_name:u,last_name:Z,owner_
25contact_id:o,role:"owner"}});if(p||t!=null&&t.error){let L=(t==null?void 0:t.error)||(p==null?void 0:p.message)||"NepodaÅilo se vytvoÅit úÄet.";try{const v=p==null?void 0:p.context;if(v!=null&&v.json){const S=await v.json();S!=null&&S.error&&(L=S.error)}}catch{}i({variant:"destructive",title:"Chyba",description:L}),be(!1);return}try{await navigator.clipboard.writeText(s)}catch{}window.alert(`ÃÄet pro ${z} byl vytvoÅen s rolà VlastnÃk. 26 27Heslo: ${s} 28 29(Heslo bylo zkopÃrováno do schránky â pÅedejte ho vlastnÃkovi.)`),m(""),de()}catch(t){i({variant:"destructive",title:"Chyba",description:t.message||"Neznámá chyba."})}be(!1)},Pt=async()=>{if(n!=null&&n.user_id){cs(!0);try{const s=[];He&&s.push("owner"),Ze&&s.push("admin"),ke&&s.push("beirat"),$e&&s.push("spravce");const{data:t,error:p}=await c.from("user_roles").select("role").eq("user_id",n.user_id);if(p){i({variant:"destructive",title:"Chyba",description:"NepodaÅilo se naÄÃst aktuálnà role."});return}const L=new Set((t||[]).map(X=>X.role)),v=new Set(s),S=s.filter(X=>!L.has(X)),A=[...L].filter(X=>!v.has(X));if(S.length>0){const{error:X}=await c.from("user_roles").insert(S.map(ze=>({user_id:n.user_id,role:ze})));if(X){i({variant:"destructive",title:"Chyba",description:"NepodaÅilo se uložit role."});return}}for(const X of A){const{error:ze}
29=await c.from("user_roles").delete().eq("user_id",n.user_id).eq("role",X);if(ze){i({variant:"destructive",title:"Chyba",description:"NepodaÅilo se odebrat nÄkteré role."});return}}ke&&await c.from("user_roles").update({beirat_since:us||null}).eq("user_id",n.user_id).eq("role","beirat"),i({title:"Role uloženy"}),Os(n.user_id)}finally{cs(!1)}}},Ts=()=>{const s="ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789!@#$%";let t="";for(let p=0;p<12;p++)t+=s.charAt(Math.floor(Math.random()*s.length));m(t)},Ot=async()=>{if(!$||$.length<6){i({variant:"destructive",title:"Chyba",description:"Heslo musà mÃt alespoÅ 6 znaků."});return}ee(!0);try{const{data:s,error:t}=await c.functions.invoke("admin-user-actions",{body:{userId:n==null?void 0:n.user_id,password:$}});t||s!=null&&s.error?i({variant:"destructive",title:"Chyba",description:(s==null?void 0:s.error)||(t==null?void 0:t.message)||"NepodaÅilo se nastavit heslo."}):(i({title:"Heslo nastaveno",description:"Nové heslo bylo úspÄÅ¡nÄ nastaveno."}),m(""),n!=null&&n.user_id&&Ds(n.user_id))}catch(s){i({variant:"destructive",title:"Chyba",description:s.message||"Neznámá chyba."})}ee(!1)},Dt=async()=>{if(!z){i({variant:"destructive",title:"Chyba",description:"Email nenà nastaven."});return}try{const{data:s,error:t}=await c.functions.invoke("send-auth-email",{body:{email:z,type:"password_reset",redirectTo:window.location.origin}});if(t||s!=null&&s.error){i({variant:"destructive",title:"Chyba",description:"NepodaÅilo se odeslat reset hesla."});return}i({title:"Email pro reset hesla odeslán"})}catch{i({variant:"destructive",title:"Chyba",description:"NepodaÅilo se odeslat reset hesla."})}},Tt=async()=>{if(!l||!l.includes("@")){i({variant:"destructive",title:"Chyba",description:"Zadejte platný email."});return}ae(!0);try{const{data:s,error:t}=await c.functions.invoke("admin-user-actions",{body:{userId:n==null?void 0:n.user_id,action:"change_email",newEmail:l}});t||s!=null&&s.error?i({variant:"destructive",title:"Chyba",description:(s==null?void 0:s.error)||(t==null?void 0:t.message)||"NepodaÅilo se zmÄnit email."}):(i({title:"Email zmÄnÄn",description:`Login email byl zmÄnÄn na ${l}.`}),I(l),y(""),de())}catch(s){i({variant:"destructive",title:"Chyba",description:s.message||"Neznámá chyba."})}ae(!1)},Lt=async()=>{var v;if(!le){i({variant:"destructive",title:"Chyba",description:"Vyberte apartmán."});return}if(pe.some(S=>S.apartment_id===le&&S.is_current)){i({variant:"destructive",title:"Chyba",description:"Tento apartmán je tomuto vlastnÃkovi již pÅiÅazen."});return}let t=null;if(xe==="percent")t=De?parseFloat(De):null;else{const S=Oe.find(A=>A.id===le);we&&(S!=null&&S.weg_anteil_rv)&&(t=parseFloat(we)/Number(S.weg_anteil_rv)*100)}if(t!=null){const{data:S}=await c.from("apartment_owners").select("share_percentage").eq("apartment_id",le).eq("is_current",!0),A=(S||[]).reduce((X,ze)=>X+(Number(ze.share_percentage)||0),0);if(A+t>100){i({variant:"destructive",title:"Chyba",description:`SouÄet podÃlů by pÅesáhl 100%. Aktuálnà obsazenÃ: ${A.toFixed(2)}%, zbývá ${(100-A).toFixed(2)}%.`});return}}Je(!0);const{error:p}=await c.from("apartment_owners").insert({apartment_id:le,owner_contact_id:o,is_current:!0,member_from:fs,share_percentage:t});if(p){i({variant:"destructive",title:"Chyba",description:(v=p.message)!=null&&v.includes("uq_apartment_owners_active")?"Tento apartmán je tomuto vlastnÃkovi již pÅiÅazen.":"NepodaÅilo se pÅiÅadit apartmán."}),Je(!1);return}const{data:L}=await c.from("apartment_wifi_credentials").select("id").eq("apartment_id",le).maybeSingle();L||await c.from("apartment_wifi_credentials").insert({apartment_id:le}),i({title:"Apartmán pÅiÅazen"}),Je(!1),js(""),Be("100"),We(""),Te("percent"),ge()},At=async s=>{const{error:t}=await c.from("apartment_owners").update({is_current:!1,member_to:new Date().toISOString().split("T")[0]}).eq("id",s);if(t){i({variant:"destructive",title:"Chyba",description:"NepodaÅilo se ukonÄit vlastnictvÃ."});return}i({title:"Vlastnictvà ukonÄeno"}),ge()},Et=s=>{Ns(s),Le(!0)},Ft=async()=>{if(!ys)return;const{error:s}=await c.from("apartment_owners").delete().eq("id",ys);if(s){i({variant:"destructive",title:"Chyba",description:"NepodaÅilo se odebrat pÅiÅazenÃ."}),Le(!1);return}i({title:"PÅiÅazenà odebráno"}),Le(!1),Ns(null),ge()},Ls=()=>{const s=(n==null?void 0:n.company_name)||[n==null?void 0:n.first_name,n==null?void 0:n.last_name].filter(
29Boolean).join(" ")||"Neznámý",t=pe.filter(p=>p.is_current);if(t.length>0){const p=t.map(L=>L.apartment.code).join(", ");return`${s} (${p})`}return s},Rt=Oe.filter(s=>!pe.some(t=>t.apartment_id===s.id&&t.is_current)),D=!!(n!=null&&n.user_id);return V?e.jsx(As,{title:"NaÄÃtánÃ...",activeSection:"owners",breadcrumbs:[{label:"VlastnÃci",href:"/admin"}],children:e.jsx("div",{className:"flex items-center justify-center py-24",children:e.jsx(K,{className:"h-8 w-8 animate-spin text-primary"})})}):e.jsx(As,{title:Ls(),activeSection:"owners",breadcrumbs:[{label:"VlastnÃci",href:"/admin"},{label:Ls()}],children:e.jsxs("div",{className:"max-w-6xl w-full",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-8",children:[e.jsx(k,{variant:"ghost",size:"icon",onClick:()=>b("/admin?section=property&sub=owners"),className:"shrink-0",children:e.jsx(ca,{className:"h-5 w-5"})}),e.jsx("div",{className:"flex-1",children:e.jsx("p",{className:"text-muted-foreground",children:"Detail vlastnÃka"})}),D?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(P,{className:"bg-primary text-primary-foreground gap-1",children:[e.jsx(Ae,{className:"h-3 w-3"}),"Má úÄet"]}),_&&!_.last_sign_in_at&&z&&e.jsxs(k,{size:"sm",variant:"outline",className:"gap-1.5 border-amber-400 text-amber-700 hover:bg-amber-50",onClick:()=>Ve(!0),disabled:qe,children:[e.jsx(ne,{className:"h-3.5 w-3.5"}),"Poslat znovu pozvánku"]})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(P,{variant:"secondary",className:"gap-1",children:[e.jsx(Ae,{className:"h-3 w-3"}),"Bez úÄtu"]}),z&&e.jsxs(k,{size:"sm",className:"gap-1.5 bg-emerald-600 hover:bg-emerald-700 text-white",onClick:()=>Ve(!1),disabled:qe,children:[e.jsx(ne,{className:"h-3.5 w-3.5"}),"Pozvat e-mailem"]})]})]}),e.jsxs(qt,{value:R,onValueChange:W,children:[e.jsxs(Vt,{className:"grid w-full grid-cols-7",children:[e.jsx(me,{value:"profile",children:"Profil"}),e.jsx(me,{value:"security",children:"PÅÃstup"}),e.jsx(me,{value:"apartments",children:"Apartmány"}),e.jsx(me,{value:"wifi",children:"WiFi"}),e.jsx(me,{value:"forum",children:"Fórum"}),e.jsx(me,{value:"emails",children:"E-maily"}),e.jsx(me,{value:"history",children:"Historie"})]}),e.jsxs(ue,{value:"profile",className:"mt-6",children:[e.jsxs(E,{children:[e.jsx(U,{children:e.jsx(q,{className:"text-lg",children:"Profilové informace"})}),e.jsxs(F,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"email",children:"Email (login)"}),e.jsx(T,{id:"email",type:"email",value:z,onChange:s=>I(s.target.value),placeholder:"[email protected]"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Email sloužà jako pÅihlaÅ¡ovacà jméno"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"userType",children:"Typ uživatele"}),e.jsxs(Ee,{value:d,onValueChange:x,children:[e.jsx(Fe,{id:"userType",children:e.jsx(Re,{})}),e.jsxs(Ie,{children:[e.jsx(he,{value:"individual",children:"Individual (Jednotlivec)"}),e.jsx(he,{value:"company",children:"Firma"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"language",children:"Preferovaný jazyk"}),e.jsxs(Ee,{value:C,onValueChange:O,children:[e.jsx(Fe,{id:"language",children:e.jsx(Re,{})}),e.jsxs(Ie,{children:[e.jsx(he,{value:"cs",children:"ÄeÅ¡tina"}),e.jsx(he,{value:"en",children:"English"}),e.jsx(he,{value:"de",children:"NÄmÄina"})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"firstName",children:"Jméno"}),e.jsx(T,{id:"firstName",value:u,onChange:s=>J(s.target.value),placeholder:"Jméno"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"lastName",children:"PÅÃjmenÃ"}),e.jsx(T,{id:"lastName",value:Z,onChange:s=>Q(s.target.value),placeholder:"PÅÃjmenÃ"})]})]}),d==="company"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"companyName",children:"Název firmy"}),e.jsx(T,{id:"companyName",value:f,onChange:s=>se(s.target.value),placeholder:"Název firmy"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"phone",children:"Telefon"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(T,{id:"phone",value:r,onChange:s=>h(s.target.value),placeholder:"+420 123 456 789",className:"flex-1"}),r&&r.trim()&&e.jsx("a",{href:`https://wa.me/${r.replace(/[\s\-()]/g,"")}`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center justify-center rounded-md border border-input bg-background px-3 hover:bg-accent hover:text-accent-foreground transition-colors",title:"OtevÅÃt WhatsApp chat",children:e.jsx("svg",{viewBox:"0 0 24 24",className:"h-4 w-4 text-green-600",fill:"currentColor",children:e.jsx("path",{d:"M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.
29198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z"})})})]})]}),e.jsxs(k,{onClick:zt,disabled:j,children:[j?e.jsx(K,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(ts,{className:"h-4 w-4 mr-2"}),"Uložit zmÄny"]})]})]}),o&&e.jsx(ba,{ownerContactId:o,ownerType:d}),o&&e.jsx(va,{ownerId:o}),e.jsxs(E,{className:"border-amber-300 mt-6",children:[e.jsxs(U,{children:[e.jsx(q,{className:"text-lg text-amber-700",children:"Správa uživatele"}),e.jsx(Y,{children:"Deaktivace zablokuje pÅihlášenÃ, ukonÄà vlastnictvà a smaže hlasy. Reaktivace obnovà pÅihlášenà (vlastnictvà je tÅeba znovu pÅiÅadit). Smazánà je nevratné."})]}),e.jsxs(F,{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap gap-3",children:[(n==null?void 0:n.is_active)===!1?e.jsxs(k,{variant:"outline",className:"border-emerald-400 text-emerald-700 hover:bg-emerald-50 hover:text-emerald-900",onClick:()=>Ye(!0),disabled:xt,children:[e.jsx(oa,{className:"h-4 w-4 mr-2"}),"Reaktivovat uživatele"]}):e.jsxs(k,{variant:"outline",className:"border-amber-400 text-amber-700 hover:bg-amber-50 hover:text-amber-900",onClick:()=>Ge(!0),disabled:mt,children:[e.jsx(Me,{className:"h-4 w-4 mr-2"}),"Deaktivovat uživatele"]}),e.jsxs(k,{variant:"destructive",onClick:()=>Xe(!0),disabled:ht,children:[e.jsx(Ue,{className:"h-4 w-4 mr-2"}),"Smazat uživatele"]})]}),(n==null?void 0:n.is_active)===!1&&e.jsx(P,{variant:"secondary",className:"text-amber-700 bg-amber-100",children:"Deaktivován"})]})]}),e.jsx(je,{open:dt,onOpenChange:Ge,title:"Deaktivovat uživatele?",description:`Uživatel "${u} ${Z}" bude deaktivován: vÅ¡echna vlastnictvà budou ukonÄena, hlasy v anketách smazány a pÅihlášenà zablokováno. Kontaktnà údaje zůstanou zachovány. PozdÄji lze reaktivovat.`,confirmText:"Deaktivovat",onConfirm:async()=>{ks(!0);try{const{data:s,error:t}=await c.functions.invoke("admin-user-actions",{body:{userId:(n==null?void 0:n.user_id)||null,action:"deactivate_owner",ownerContactId:o}});t||s!=null&&s.error?i({variant:"destructive",title:"Chyba",description:(s==null?void 0:s.error)||(t==null?void 0:t.message)||"NepodaÅilo se deaktivovat uživatele."}):(i({title:"Uživatel deaktivován",description:"Uživatel byl úspÄÅ¡nÄ deaktivován."}),de(),ge())}catch(s){i({variant:"destructive",title:"Chyba",description:s.message||"Neznámá chyba."})}ks(!1),Ge(!1)},variant:"destructive"}),e.jsx(je,{open:pt,onOpenChange:Ye,title:"Reaktivovat uživatele?",description:`Uživatel "${u} ${Z}" bude reaktivován: pÅihlášenà bude znovu povoleno. Vlastnictvà apartmánů je tÅeba znovu pÅiÅadit ruÄnÄ.`,confirmText:"Reaktivovat",onConfirm:async()=>{Cs(!0);try{const{data:s,error:t}=await c.functions.invoke("admin-user-actions",{body:{userId:(n==null?void 0:n.user_id)||null,action:"reactivate_owner",ownerContactId:o}});t||s!=null&&s.error?i({variant:"destructive",title:"Chyba",description:(s==null?void 0:s.error)||(t==null?void 0:t.message)||"NepodaÅilo se reaktivovat uživatele."}):(i({title:"Uživatel reaktivován",description:"Uživatel byl úspÄÅ¡nÄ reaktivován."}),de())}catch(s){i({variant:"destructive",title:"Chyba",description:s.message||"Neznámá chyba."})}Cs(!1),Ye(!1)}}),e.jsx(je,{open:ut,onOpenChange:Xe,title:"Opravdu smazat uživatele?",description:`POZOR: Tato akce je NEVRATNÃ! Uživatel "${u} ${Z}" bude trvale smazán vÄetnÄ: vÅ¡ech pÅiÅazenà apartmánů, hlasů v anketách, uživatelského úÄtu (pokud existuje), profilu a historie pÅihlášenÃ.`,confirmText:"Trvale smazat",onConfirm:async()=>{ws(!0);try{const{data:s,error:t}=await c.functions.invoke("admin-user-actions",{body:{userId:(n==null?void 0:n.user_id
29)||null,action:"delete_owner",ownerContactId:o}});t||s!=null&&s.error?i({variant:"destructive",title:"Chyba",description:(s==null?void 0:s.error)||(t==null?void 0:t.message)||"NepodaÅilo se smazat uživatele."}):(i({title:"Uživatel smazán",description:"Uživatel byl trvale smazán."}),b("/admin?section=property&sub=owners"))}catch(s){i({variant:"destructive",title:"Chyba",description:s.message||"Neznámá chyba."})}ws(!1),Xe(!1)},variant:"destructive"})]}),e.jsxs(ue,{value:"security",className:"mt-6 space-y-6",children:[e.jsxs(E,{children:[e.jsxs(U,{children:[e.jsxs(q,{className:"text-lg flex items-center gap-2",children:[e.jsx(ne,{className:"h-5 w-5"}),"PÅihlášenà pÅes Magic Link"]}),e.jsx(Y,{children:"Primárnà způsob pÅihlášenÃ. Uživatel obdržà jednorázový odkaz na email, pÅes který se pÅihlásà bez nutnosti hesla."})]}),e.jsx(F,{children:D?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(P,{className:"bg-primary text-primary-foreground gap-1",children:[e.jsx(Ae,{className:"h-3 w-3"}),"ÃÄet aktivnÃ"]}),e.jsx("span",{className:"text-sm text-muted-foreground",children:z})]}),_&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 pt-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"ÃÄet vytvoÅen: "}),e.jsx("span",{className:"font-medium",children:_.created_at?new Date(_.created_at).toLocaleDateString("cs-CZ",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"}):"â"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Poslednà zmÄna: "}),e.jsx("span",{className:"font-medium",children:_.updated_at?new Date(_.updated_at).toLocaleDateString("cs-CZ",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"}):"â"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Poslednà pÅihlášenÃ: "}),e.jsx("span",{className:"font-medium",children:_.last_sign_in_at?new Date(_.last_sign_in_at).toLocaleDateString("cs-CZ",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"}):"ZatÃm se nepÅihlásil"})]})]})]}):e.jsx("div",{className:"space-y-4",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"Pro aktivaci pÅÃstupu je nutné nejprve vytvoÅit uživatelský úÄet."})})})]}),z&&e.jsxs(E,{children:[e.jsxs(U,{children:[e.jsxs(q,{className:"text-lg flex items-center gap-2",children:[e.jsx(ne,{className:"h-5 w-5"}),"Pozvánka e-mailem"]}),e.jsx(Y,{children:"PÅehled poslednà odeslané pozvánky pro nastavenà / obnovu hesla."})]}),e.jsxs(F,{className:"space-y-4",children:[Qs?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(K,{className:"h-4 w-4 animate-spin"})," NaÄÃtámâ¦"]}):ce?e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Odesláno: "}),e.jsx("span",{className:"font-medium",children:new Date(ce.sent_at).toLocaleDateString("cs-CZ",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"})})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Status: "}),ce.status==="sent"?e.jsx(P,{className:"bg-emerald-600 text-white",children:"DoruÄeno"}):ce.status==="failed"?e.jsx(P,{variant:"destructive",children:"Selhalo"}):e.jsx(P,{variant:"secondary",children:ce.status})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Jazyk: "}),e.jsx("span",{className:"font-medium uppercase",children:ce.language||"â"})]}),ce.error_message&&e.jsxs("div",{className:"md:col-span-3 text-xs text-destructive",children:["Chyba: ",ce.error_message]})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Pro tohoto vlastnÃka zatÃm nebyla odeslána žádná pozvánka."}),(()=>{const s=D&&_&&!_.last_sign_in_at,t=!D;if(!t&&!s)return null;const v=(ce?Date.now()-new Date(ce.sent_at).getTime():1/0)<1*60*1e3;return e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 pt-2 border-t",children:[e.jsxs(k,{size:"sm",variant:t?"default":"outline",className:t?"bg-emerald-600 hover:bg-emerald-700 text-white gap-1.5":"gap-1.5",onClick:()=>Ve(s),disabled:qe||v,children:[e.jsx(ne,{className:"h-3.5 w-3.5"}),t?"Pozvat e-mailem":"Poslat pozvánku znovu"]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[s?"ÃÄet existuje, ale uživatel se jeÅ¡tÄ nepÅihlásil.":"PoÅ¡le odkaz pro nastavenà hesla.",v&&" PoÄkejte chvÃli mezi pokusy."]})]})})()]})]}),D&&e.jsxs(E,{children:[e.jsxs(U,{children:[e.jsxs(q,{className:"text-lg flex items-center gap-2",children:[e.jsx(ne,{className:"h-5 w-5"}),"ZmÄnit pÅihlaÅ¡ovacà email"]}
29),e.jsx(Y,{children:"ZmÄnà email, kterým se uživatel pÅihlaÅ¡uje do systému."})]}),e.jsxs(F,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{children:"Aktuálnà email"}),e.jsx(T,{value:z,disabled:!0,className:"bg-muted"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"newLoginEmail",children:"Nový email"}),e.jsx(T,{id:"newLoginEmail",type:"email",value:l,onChange:s=>y(s.target.value),placeholder:"[email protected]"})]})]}),e.jsxs(k,{onClick:Tt,disabled:re||!l||l===z,children:[re?e.jsx(K,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(ne,{className:"h-4 w-4 mr-2"}),"ZmÄnit email"]})]})]}),!D&&e.jsxs(E,{children:[e.jsxs(U,{children:[e.jsxs(q,{className:"text-lg flex items-center gap-2",children:[e.jsx(Rs,{className:"h-5 w-5"}),"VytvoÅit uživatelský úÄet"]}),e.jsx(Y,{children:"VytvoÅà úÄet s poÄáteÄnÃm heslem. Uživatel se pak může pÅihlásit heslem nebo pÅes Magic Link."})]}),e.jsx(F,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{children:"Email (login)"}),e.jsx(T,{value:z,disabled:!0,className:"bg-muted"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"newPassword",children:"Heslo"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(T,{id:"newPassword",type:"text",value:$,onChange:s=>m(s.target.value),placeholder:"Zadejte nebo vygenerujte heslo"}),e.jsx(k,{variant:"outline",size:"icon",onClick:Ts,title:"Vygenerovat heslo",children:e.jsx(Se,{className:"h-4 w-4"})})]})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'Pokud heslo nezadáte, vygeneruje se automaticky. ÃÄet dostane roli âVlastnÃk" a žádný e-mail se neposÃlá.'}),e.jsxs(k,{onClick:St,disabled:Ne||!z,children:[Ne?e.jsx(K,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(Rs,{className:"h-4 w-4 mr-2"}),"VytvoÅit úÄet (VlastnÃk)"]})]})})]}),D&&e.jsxs(E,{children:[e.jsxs(U,{children:[e.jsxs(q,{className:"text-lg flex items-center gap-2",children:[e.jsx(da,{className:"h-5 w-5"}),"Nastavit heslo"]}),e.jsx(Y,{children:"Pro uživatele, kteÅà nechtÄjà použÃvat Magic Link. Heslo můžete zadat manuálnÄ nebo vygenerovat."})]}),e.jsxs(F,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"setPassword",children:"Nové heslo"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(T,{id:"setPassword",type:"text",value:$,onChange:s=>m(s.target.value),placeholder:"Zadejte nebo vygenerujte heslo"}),e.jsx(k,{variant:"outline",size:"icon",onClick:Ts,title:"Vygenerovat heslo",children:e.jsx(Se,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Heslo je zobrazeno v Äitelné formÄ, abyste ho mohli pÅedat uživateli."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(k,{onClick:Ot,disabled:M||!$||$.length<6,children:[M?e.jsx(K,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(Is,{className:"h-4 w-4 mr-2"}),"Nastavit heslo"]}),e.jsxs(k,{variant:"outline",onClick:Dt,children:[e.jsx(ne,{className:"h-4 w-4 mr-2"}),"Odeslat reset e-mailem"]})]})]})]}),e.jsxs(E,{children:[e.jsxs(U,{children:[e.jsx(q,{className:"text-lg",children:"Role uživatele"}),e.jsx(Y,{children:D?"Uživatel může mÃt pÅiÅazeno vÃce rolà souÄasnÄ.":"Role lze pÅiÅadit až po vytvoÅenà uživatelského úÄtu."})]}),e.jsxs(F,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:`flex items-center justify-between p-3 border rounded-lg ${D?"":"opacity-50"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(oe,{id:"roleOwner",checked:He,onCheckedChange:s=>os(!!s),disabled:!D}),e.jsxs("div",{children:[e.jsxs(g,{htmlFor:"roleOwner",className:"font-medium cursor-pointer flex items-center gap-2",children:[e.jsx(Ae,{className:"h-4 w-4"}),"VlastnÃk"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Standardnà uživatel s pÅÃstupem k vlastnÃm datům"})]})]}),He&&D&&e.jsx(P,{variant:"outline",children:"AktivnÃ"})]}),e.jsxs("div",{className:`flex items-center justify-between p-3 border rounded-lg ${D?"":"opacity-50"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(oe,{id:"roleAdmin",checked:Ze,onCheckedChange:s=>ds(!!s),disabled:!D}),e.jsxs("div",{children:[e.jsxs(g,{htmlFor:"roleAdmin",className:"font-medium cursor-pointer flex items-center gap-2",children:[e.jsx(Me,{className:"h-4 w-4"}),"Administrátor"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Plný pÅÃstup ke vÅ¡em funkcÃm systému"})]})]}),Ze&&D&&e.jsx(P,{variant:"outline",children:"AktivnÃ"})]}),e.jsxs("div",{className:`p-3 border rounded-lg space-y-3 ${D?"":"opacity-50"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(oe,{id:"roleBeirat",checked:ke,onCheckedChange:s=>ms(!!s),disabled:!D}),e.jsxs("div",{children:[e.jsxs(g,{htmlFor:"roleBeirat",className:"font-medium cursor-pointer flex items-center gap-2",children:[e.jsx(Ms,{className:"h-4 w-4"}),"Poradnà sbor (Beirat)"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Älen poradnÃho sboru s rozÅ¡ÃÅeným pÅÃstupem"})]})]}),ke&&D&&e.jsx(P,{variant:"outline",children:"AktivnÃ"})]}),ke&&D&&e.jsxs("div",{className:"ml-7 flex items-center gap-3",children:[e.jsx(g,{htmlFor:"beiratSince",className:"text-sm text-muted-foreground whitespace-nowrap",children:"Älen od:"}),e.jsx(T,{id:"beiratSince",type:"date",value:us,onChange:s=>hs(s.target.value),className:"w-48"})]})]}),e.jsxs("div",{className:`flex items-center justify-between p-3 border rounded-lg ${D?"":"opacity-50"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(oe,{id:"roleSpravce",checked:$e,onCheckedChange:s=>ps(!!s),disabled:!D}),e.jsxs("div",{children:[e.jsxs(g,{htmlFor:"roleSpravce",className:"font-medium cursor-pointer flex items-center gap-2",children:[e.jsx(Me,{className:"h-4 w-4"}),"Správce"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Správce nemovitosti s oprávnÄnÃm ke správÄ"})]})]}),$e&&D&&e.jsx(P,{variant:"outline",children:"AktivnÃ"})]})]}),D&&e.jsxs(k,{onClick:Pt,disabled:ls,children:[ls?e.jsx(K,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(ts,{className:"h-4 w-4 mr-2"}),"Uložit role"]})]})]}),D&&e.jsxs(E,{children:[e.jsxs(U,{children:[e.jsx(q,{className:"text-lg",children:"Fórum notifikace"}),e.jsx(Y,{children:"Nastavenà e-mailových notifikacà z fóra pro tohoto uživatele"})]}),e.jsx(F,{children:e.jsxs("div",{className:"flex items-center justify-between p-4 border rounded-lg",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("label",{className:"font-medium",children:"E-mailové notifikace z fóra"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:xs?"Uživatel nedostává n
29otifikace z fóra":"Uživatel dostává notifikace z fóra"})]}),e.jsx(Ht,{checked:!xs,disabled:st,onCheckedChange:s=>Nt(!s)})]})})]}),D&&e.jsxs(E,{className:"border-destructive",children:[e.jsxs(U,{children:[e.jsx(q,{className:"text-lg text-destructive",children:"Smazat uživatele"}),e.jsx(Y,{children:"Tato akce je nevratná. Uživatelský úÄet bude trvale smazán."})]}),e.jsx(F,{children:e.jsxs(k,{variant:"destructive",onClick:()=>Ke(!0),disabled:ot,children:[e.jsx(Ue,{className:"h-4 w-4 mr-2"}),"Smazat úÄet"]})})]}),e.jsx(je,{open:ct,onOpenChange:Ke,title:"Opravdu smazat uživatelský úÄet?",description:`Tato akce je nevratná. ÃÄet uživatele "${u} ${Z}" (${z}) bude trvale smazán vÄetnÄ vÅ¡ech rolà a profilu. Kontaktnà údaje vlastnÃka zůstanou zachovány.`,confirmText:"Smazat úÄet",onConfirm:async()=>{bs(!0);try{const{data:s,error:t}=await c.functions.invoke("admin-user-actions",{body:{userId:n==null?void 0:n.user_id,action:"delete_user"}});t||s!=null&&s.error?i({variant:"destructive",title:"Chyba",description:(s==null?void 0:s.error)||(t==null?void 0:t.message)||"NepodaÅilo se smazat úÄet."}):(i({title:"ÃÄet smazán",description:"Uživatelský úÄet byl trvale smazán."}),de())}catch(s){i({variant:"destructive",title:"Chyba",description:s.message||"Neznámá chyba."})}bs(!1),Ke(!1)},variant:"destructive"})]}),e.jsxs(ue,{value:"apartments",className:"mt-6 space-y-6",children:[e.jsxs(E,{children:[e.jsx(U,{children:e.jsx(q,{className:"text-lg",children:"PÅiÅadit nový apartmán"})}),e.jsxs(F,{children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mb-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{children:"Apartmán"}),e.jsxs(Ee,{value:le,onValueChange:s=>{js(s),Be("100"),Te("percent");const t=Oe.find(p=>p.id===s);We(t!=null&&t.weg_anteil_rv?String(t.weg_anteil_rv):"")},children:[e.jsx(Fe,{children:e.jsx(Re,{placeholder:"Vyberte apartmán"})}),e.jsx(Ie,{children:Rt.map(s=>{var t;return e.jsxs(he,{value:s.id,children:[s.code," (",((t=s.weg_anteil_rv)==null?void 0:t.toLocaleString("cs-CZ"))??"â"," WEG RV)"]},s.id)})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{children:"VlastnÃk od"}),e.jsx(T,{type:"date",value:fs,onChange:s=>nt(s.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(g,{className:"mb-0",children:"PodÃl"}),e.jsxs("label",{className:"flex items-center gap-1.5 text-sm cursor-pointer",children:[e.jsx("input",{type:"radio",name:"shareMode",checked:xe==="percent",onChange:()=>Te("percent"),className:"accent-primary"}),"Procenta (%)"]}),e.jsxs("label",{className:"flex items-center gap-1.5 text-sm cursor-pointer",children:[e.jsx("input",{type:"radio",name:"shareMode",checked:xe==="weg",onChange:()=>Te("weg"),className:"accent-primary"}),"WEG RV"]})]}),xe==="percent"?e.jsx(T,{type:"number",min:"0",max:"100",step:"0.01",placeholder:"napÅ. 100",value:De,onChange:s=>Be(s.target.value)}):e.jsx(T,{type:"number",min:"0",step:"1",placeholder:"napÅ. 22630",value:we,onChange:s=>We(s.target.value)}),le&&(()=>{const s=Oe.find(L=>L.id===le);if(!(s!=null&&s.weg_anteil_rv))return null;const t=xe==="percent"?parseFloat(De)||0:(parseFloat(we)||0)/Number(s.weg_anteil_rv)*100,p=xe==="weg"?parseFloat(we)||0:t/100*Number(s.weg_anteil_rv);return e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["= ",t.toFixed(2),"% (",Math.round(p).toLocaleString("cs-CZ")," z ",Number(s.weg_anteil_rv).toLocaleString("cs-CZ")," WEG RV)"]})})()]})]}),e.jsxs(k,{onClick:Lt,disabled:_s||!le,children:[_s?e.jsx(K,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(ma,{className:"h-4 w-4 mr-2"}),"PÅiÅadit apartmán"]})]})]}),e.jsxs(E,{children:[e.jsx(U,{children:e.jsx(q,{className:"text-lg",children:"PÅiÅazené apartmány"})}),e.jsx(F,{children:pe.length===0?e.jsx("p",{className:"text-muted-foreground text-sm py-4 text-center",children:"Žádné apartmány nejsou pÅiÅazeny."}):e.jsxs(fe,{children:[e.jsx(_e,{children:e.jsxs(te,{children:[e.jsx(w,{children:"Apartmán"}),e.jsx(w,{children:"WEG PodÃl"}),e.jsx(w,{children:"SpoluvlastnÃk"}),e.jsx(w,{children:"Od"}),e.jsx(w,{children:"Do"}),e.jsx(w,{children:"Status"}),e.jsx(w,{className:"text-right",children:"Akce"})]})}),e.jsx(ye,{children:pe.map(s=>{const t=Number(s.apartment.weg_anteil_rv)||0,p=s.share_percentage,L=rt[s.apartment_id]||[];return e.jsxs(te,{children:[e.jsx(N,{className:"font-medium",children:s.apartment.code}),e.jsx(N,{children:e.jsxs("div",{className:"space-y-0.5",children:[p!=null?e.jsxs("span",{className:"font-medium text-sm",children:[p,"%"]}):t>0&&L.length===0?e.jsx("span",{className:"font-medium text-sm",children:"100%"}):e.jsx("span",{className:"text-muted-foreground text-sm",children:"â"}),t>0&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["(",t.toLocaleStr
29ing("cs-CZ")," WEG RV)"]})]})}),e.jsx(N,{children:L.length>0?e.jsx("div",{className:"flex flex-wrap gap-1",children:L.map((v,S)=>e.jsxs(P,{variant:"outline",className:"cursor-pointer hover:bg-accent text-xs",onClick:()=>b(`/admin/owner/${v.owner_contact_id}`),children:[e.jsx(Ms,{className:"h-3 w-3 mr-1"}),v.name,v.share_percentage!=null&&e.jsxs("span",{className:"ml-1 text-muted-foreground",children:[v.share_percentage,"%"]})]},S))}):e.jsx("span",{className:"text-muted-foreground text-sm",children:"â"})}),e.jsx(N,{children:e.jsx(T,{type:"date",value:s.member_from,className:"w-36 h-8 text-sm",onChange:v=>kt(s.id,v.target.value)})}),e.jsx(N,{className:"text-muted-foreground",children:s.member_to?new Date(s.member_to).toLocaleDateString("cs-CZ"):"-"}),e.jsx(N,{children:s.is_current?e.jsx(P,{className:"bg-primary text-primary-foreground",children:"AktivnÃ"}):e.jsx(P,{variant:"secondary",children:"UkonÄeno"})}),e.jsx(N,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-1",children:[s.is_current&&e.jsx(k,{variant:"outline",size:"sm",onClick:()=>At(s.id),children:"UkonÄit vlastnictvÃ"}),e.jsx(k,{variant:"ghost",size:"icon",onClick:()=>Et(s.id),children:e.jsx(Ue,{className:"h-4 w-4 text-destructive"})})]})})]},s.id)})})]})})]})]}),e.jsx(ue,{value:"wifi",className:"mt-6",children:e.jsx(ga,{apartments:pe.filter(s=>s.is_current).map(s=>({apartment_id:s.apartment_id,apartment:{code:s.apartment.code}}))})}),e.jsx(ue,{value:"forum",className:"mt-6",children:e.jsxs(E,{children:[e.jsxs(U,{children:[e.jsxs(q,{className:"text-lg flex items-center gap-2",children:[e.jsx(sa,{className:"h-5 w-5"}),"PÅÃspÄvky ve fóru"]}),e.jsx(Y,{children:D?`Celkem ${es.length} pÅÃspÄvků`:"PÅÃspÄvky ve fóru nejsou k dispozici pro kontakty bez uživatelského úÄtu."})]}),e.jsx(F,{children:D?_t?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(K,{className:"h-6 w-6 animate-spin text-primary"})}):es.length===0?e.jsx("p",{className:"text-muted-foreground text-sm py-8 text-center",children:"Tento uživatel zatÃm nepÅidal žádný pÅÃspÄvek."}):e.jsxs(fe,{children:[e.jsx(_e,{children:e.jsxs(te,{children:[e.jsx(w,{children:"Datum"}),e.jsx(w,{children:"Vlákno"}),e.jsx(w,{children:"Náhled obsahu"}),e.jsx(w,{className:"text-right",children:"Akce"})]})}),e.jsx(ye,{children:es.map(s=>{var A,X;const t=s.thread,p=(A=t==null?void 0:t.category)==null?void 0:A.slug,L=p?`/owners/forum/${p}/${t==null?void 0:t.id}`:"#",v=((X=s.content)==null?void 0:X.replace(/<[^>]*>/g,""))||"",S=v.length>80?v.substring(0,80)+"â¦":v;return e.jsxs(te,{children:[e.jsx(N,{className:"text-muted-foreground whitespace-nowrap",children:new Date(s.created_at).toLocaleDateString("cs-CZ",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"})}),e.jsx(N,{className:"font-medium max-w-[200px] truncate",children:(t==null?void 0:t.title)||"Neznámé vlákno"}),e.jsx(N,{className:"text-muted-foreground max-w-[250px] truncate",children:S}),e.jsx(N,{className:"text-right",children:e.jsx(k,{variant:"ghost",size:"sm",onClick:()=>b(L),title:"Zobrazit pÅÃspÄvek",children:e.jsx(ua,{className:"h-4 w-4"})})})]},s.id)})})]}):e.jsx("p",{className:"text-muted-foreground text-sm py-8 text-center",children:"PÅÃspÄvky ve fóru nejsou k dispozici pro kontakty bez uživatelského úÄtu."})})]})}),e.jsxs(ue,{value:"emails",className:"mt-6 space-y-6",children:[e.jsx(_a,{ownerEmail:(n==null?void 0:n.email)||null,ownerUserId:(n==null?void 0:n.user_id)||null}),e.jsx(fa,{ownerEmail:(n==null?void 0:n.email)||null})]}),e.jsxs(ue,{value:"history",className:"mt-6",children:[e.jsxs(E,{children:[e.jsxs(U,{children:[e.jsxs(q,{className:"text-lg flex items-center gap-2",children:[e.jsx(Is,{className:"h-5 w-5"}),"Historie pÅihlášenÃ"]}),e.jsxs(Y,{children:["VÅ¡echna pÅihlášenà s datem, metodou a zaÅÃzenÃm (",ve.length," záznamů)."]})]}),e.jsx(F,{children:D?gt?e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(K,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):ve.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Žádná pÅihlášenà nebyla zaznamenána."}):e.jsxs(e.Fragment,{children:[e.jsxs(fe,{children:[e.jsx(_e,{children:e.jsxs(te,{children:[e.jsx(w,{children:"Datum a Äas"}),e.jsx(w,{children:"Metoda"}),e.jsx(w,{children:"ProhlÞeÄ"}),e.jsx(w,{children:"OS"}),e.jsx(w,{children:"ZaÅÃzenÃ"})]})}
29),e.jsx(ye,{children:ve.slice((Qe-1)*Ce,Qe*Ce).map(s=>e.jsxs(te,{children:[e.jsx(N,{className:"whitespace-nowrap",children:new Date(s.logged_in_at).toLocaleDateString("cs-CZ",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit"})}),e.jsx(N,{children:e.jsx(P,{variant:s.login_method==="magiclink"?"secondary":"outline",children:s.login_method==="magiclink"?"âï¸ Magic Link":"ð Heslo"})}),e.jsx(N,{children:s.browser||"â"}),e.jsx(N,{children:s.os||"â"}),e.jsx(N,{children:s.device_type||"â"})]},s.id))})]}),ve.length>Ce&&e.jsx($s,{currentPage:Qe,totalPages:Math.ceil(ve.length/Ce),pageSize:Ce,totalItems:ve.length,onPageChange:Ss,onPageSizeChange:s=>{jt(s),Ss(1)},language:"cs"})]}):e.jsx("p",{className:"text-muted-foreground text-sm py-8 text-center",children:"Historie pÅihlášenà nenà k dispozici pro kontakty bez uživatelského úÄtu."})})]}),o&&e.jsx("div",{className:"mt-6",children:e.jsx(wa,{ownerContactId:o})})]})]}),e.jsx(je,{open:it,onOpenChange:Le,title:"Odebrat pÅiÅazenÃ",description:"Opravdu chcete odebrat toto pÅiÅazenà apartmánu? Tato akce je nevratná.",confirmText:"Odebrat",onConfirm:Ft}),e.jsx(la,{open:Gs,onOpenChange:ns,params:Xs,onSent:()=>de()})]})})};export{Mn 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.