1import{c as Ye,t as Ge,r as n,s as o,j as e,T as Ke,B as w,I as Z,m as C,M as he,a as Qe,w as R,x as M,K,N as Q,O as X,y as ee,a7 as hs,E as xs}from"./index-MoAbC8_9.js";import{A as fs}from"./AdminPageLayout-DL0avA2R.js";import{C as xe}from"./checkbox-D2A7tWS7.js";import{S as vs}from"./switch-BHj3-8MN.js";import{B as ze}from"./badge-BHbYeRgi.js";import{S as Xe}from"./scroll-area-CoT3wSM0.js";import{T as gs,a as js,c as ye,b as ke}from"./tabs-5EVsfllK.js";import{S as ws}from"./separator-CQ84aZ0V.js";import{C as Oe}from"./confirm-dialog-DHYtbMdr.js";import{D as _s,a as Ns,b as bs,c as ys,d as ks}from"./dialog-DrI7Oddz.js";import{R as Be,a as Ve}from"./radio-group-BtSPrM_8.js";import{U as Le}from"./user-plus-BJ2nTN1d.js";import{S as Ss}from"./search-_fcwEKN-.js";import{A as Cs}from"./arrow-right-left-Yai1ia-T.js";import{U as zs}from"./users-xui-UtA1.js";import{T as Ps}from"./trash-2-DRJ_nWSl.js";import{U as Ue}from"./user-Cvsz7Lm_.js";import{C as Ts}from"./circle-check-big-_JLEBINb.js";import{S as De,d as As}from"./Header-CnJGZ8vQ.js";import{S as We}from"./save-DWdLHugL.js";import{K as Je}from"./key-Do0I7jZr.js";import{E as $s}from"./eye-off-D1RUMkPr.js";import{E as Os}from"./eye-DKrvAixa.js";import{C as Ls}from"./copy-BJvw7_4P.js";import{H as Us}from"./history-GAI9mcQt.js";import{M as Ds}from"./monitor-BfzJ2sMA.js";import{f as Se}from"./format-Beid_ZIk.js";import{c as Ce}from"./cs-DzBP63t1.js";import"./Layout-jB2m3rBw.js";import"./collapsible-BIxz44zB.js";import"./breadcrumb-CmKLwRya.js";import"./AdminSidebar-B1OFksO6.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"./chevron-down-BDe4YKQW.js";import"./house-DjS1WMqx.js";import"./index-D9-GACGG.js";import"./index-BdQq_4o_.js";import"./mountain-BHfTfCFy.js";import"./en-US-CQ3IMwMG.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 Rs=Ye("Smartphone",[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]]);/** 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 Ms=Ye("Tablet",[["rect",{width:"16",height:"20",x:"4",y:"2",rx:"2",ry:"2",key:"76otgf"}],["line",{x1:"12",x2:"12.01",y1:"18",y2:"18",key:"1dp563"}]]),Es=({open:_,onOpenChange:p,userId:b,userEmail:t,userName:L,onComplete:fe})=>{var de,me;const{toast:T}=Ge(),[k,A]=n.useState("action"),[x,E]=n.useState(null),[z,ve]=n.useState([]),[S,B]=n.useState(null),[se,te]=n.useState(""),[ge,ae]=n.useState(!1),[re,V]=n.useState(!1),[W,J]=n.useState(!1),[Pe,ne]=n.useState(!1),[I,U]=n.useState(null);n.useEffect(()=>{_&&(A("action"),E(null),B(null),te(""),J(!1),U(null),we())},[_]);const[H,ie]=n.useState([]),[oe,je]=n.useState([]),we=async()=>{ae(!0);const[a,r,d,l]=await Promise.all([o.from("owner_contacts").select("id, first_name, last_name, company_name, email, user_id, is_active, language").eq("is_active",!0).order("last_name"),o.from("apartment_owners").select("owner_contact_id, apartments(code)").eq("is_current",!0),o.from("owner_contact_persons").select("id, email, user_id, first_name, last_name, owner_contact_id").not("user_id","is",null),o.from("owner_contact_persons").select("id, email, first_name, last_name, owner_contact_id, role_type").is("user_id",null).eq("can_login",!0)]),v=r.data||[],F=(a.data||[]).map(O=>({...O,apartments:v.filter(q=>q.owner_contact_id===O.id).map(q=>{var D;return((D=q.apartments)==null?void 0:D.code)||"?"})}));ve(F),ie(d.data||[]),je(l.data||[]),ae(!1)},y=a=>a.company_name||`${a.first_name||""} ${a.last_name||""}`.trim()||"Neuvedeno",u=n.useMemo(()=>
11{if(!t)return null;const a=t.toLowerCase(),r=z.find(l=>l.email&&l.user_id&&l.email.toLowerCase()===a);if(r)return r;const d=H.find(l=>l.email&&l.email.toLowerCase()===a);if(d){const l=z.find(v=>v.id===d.owner_contact_id);if(l)return l}return null},[z,H,t]),h=n.useMemo(()=>{if(!t||u)return null;const a=t.toLowerCase(),r=oe.find(l=>l.email&&l.email.toLowerCase()===a);if(!r)return null;const d=z.find(l=>l.id===r.owner_contact_id);return d?{person:r,owner:d}:null},[t,u,oe,z]);n.useEffect(()=>{h&&!u&&(B(h.owner.id),E("replace_login"),A("confirm"))},[h,u]),n.useEffect(()=>{if(!u||!t){U(null);return}const a=t.toLowerCase(),r=z.filter(v=>v.email&&v.email.toLowerCase()===a&&v.user_id&&v.is_active),d=H.filter(v=>v.email&&v.email.toLowerCase()===a),l=r.length+d.length;l===1?(U("strong"),E("delete_account"),J(!0)):l>1?U("weak"):U(null)},[u,z,H,t]);const le=z.filter(a=>{var d;const r=se.toLowerCase();return y(a).toLowerCase().includes(r)||((d=a.email)==null?void 0:d.toLowerCase().includes(r))||a.apartments.some(l=>l.toLowerCase().includes(r))}),f=z.find(a=>a.id===S),Te=()=>{x&&A(x==="delete_account"?"confirm":"select_owner")},Ae=async(a,r,d)=>{try{const{data:{session:l}}=await o.auth.getSession();if(!l)return;const v=window.location.origin;await o.functions.invoke("send-notification-email",{body:{template_type:"duplicate_registration",language:d,recipient_email:a,variables:{"{userName}":r,"{loginLink}":`${v}/auth`,"{resetPasswordUrl}":`${v}/reset-password`,"{emailSignature}":""}}})}catch(l){console.error("Failed to send notification:",l)}},$e=async()=>{var a;if(t)try{const r=window.location.origin,d=((a=h==null?void 0:h.owner)==null?void 0:a.language)||(f==null?void 0:f.language)||"cs";await o.functions.invoke("send-notification-email",{body:{template_type:"registration_approved",language:d,recipient_email:t,variables:{"{userName}":L?` ${L}`:"","{loginLink}":`${r}/auth`,"{resetPasswordUrl}":`${r}/reset-password`,"{emailSignature}":""}}})}catch(r){console.error("Failed to send approval notification:",r)}},_e=async()=>{V(!0);try{const{data:{session:a}}=await o.auth.getSession();if(!a)throw new Error("Nenà pÅihlášen");if(x==="delete_account"){if(W&&u&&u.email){ne(!0);const l=u.language||"en";await Ae(u.email,y(u),l),ne(!1)}const r=await fetch("https://wasldznewicttoslpmnx.supabase.co/functions/v1/admin-user-actions",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a.access_token}`},body:JSON.stringify({userId:b,action:"delete_user",audit:u?{action:"duplicate_registration_deleted",target_email:t,reason:"existing_active_account_found",details:{notification_sent:W,matched_owner_contact_id:u.id,matched_owner_name:y(u),duplicate_type:I}}:void 0})}),d=await r.json();if(!r.ok)throw new Error(d.error||"Chyba pÅi mazánÃ");T({title:"Smazáno",description:"Registrace byla smazána."}),fe("delete_account"),p(!1);return}if(!S||!f){T({variant:"destructive",title:"Chyba",description:"Vyberte vlastnÃka."}),V(!1);return}if(x==="replace_login"){const{error:r}=await o.rpc("approve_user",{target_user_id:b});if(r)throw new Error(r.message);const d=h&&h.owner.id===S;if(d)await o.from("owner_contact_persons").update({user_id:b}).eq("id",h.person.id);else if(await o.from("owner_contacts").update({user_id:b}).eq("id",S),await o.from("apartment_owners").update({user_id:b}).eq("owner_contact_id",S).eq("is_current",!0),f.user_id&&f.user_id!==b){const{data:l}=await o.from("owner_contacts").select("id").eq("user_id",f.user_id);(!l||l.length===0)&&await o.from("user_roles").delete().eq("user_id",f.user_id).eq("role","owner")}T({title:"Schváleno",description:d?`Uživatel byl propojen jako zástupce vlastnÃka ${y(f)}.`:`Uživatel byl propojen s vlastnÃkem ${y(f)}.`})}if(x==="add_authorized_person"){const{error:r}=await o.rpc("approve_user",{target_user_id:b});if(r)throw new Error(r.message);const d=L.split(" "),l=d[0]||"",v=d.slice(1).join(" ")||"";await o.from("owner_contact_persons").insert({owner_contact_id:S,first_name:l,last_name:v,email:t,role_type:"representative",can_login:!0,can_vote:!1,can_receive_notifications:!0,user_id:b}),T({title:"Schváleno",description:`Uživatel byl pÅidán jako povÄÅená osoba k ${y(f)}.`})}if(x==="add_coowner"){const{error:r}=await o.rpc("approve_user",{target_user_id:b});if(r)throw new Error(r.message);const d=L.split(" "),{data:l,error:v}=await o.from("owner_contacts").insert({first_name:d[0]||null,last_name:d.slice(1).join(" ")||null,email:t,user_id:b,is_active:!0}).select("id").single();if(v||!l)throw new Error("NepodaÅilo se vytvoÅit kontakt vlastnÃka");const F=f.apartments;if(F.length>0){const{data:O}=await o.from("apartments").select("id, code").in("code",F);if(O&&O.length>0){const q=O.map(D=>
11({apartment_id:D.id,owner_contact_id:l.id,user_id:b,is_current:!0,member_from:new Date().toISOString().split("T")[0],share_percentage:0}));await o.from("apartment_owners").insert(q)}}T({title:"Schváleno",description:`Uživatel byl pÅidán jako spoluvlastnÃk k bytům ${F.join(", ")}. Nastavte podÃly.`})}await $e(),fe(x??void 0),p(!1)}catch(a){const r=(a==null?void 0:a.message)||"NepodaÅilo se provést akci.",d=r.includes("IDENTITY_EMAIL_MISMATCH");T({variant:"destructive",title:d?"Schválenà zablokováno â nesoulad e-mailu":"Chyba",description:d?r.replace(/^.*IDENTITY_EMAIL_MISMATCH:\s*/,""):r})}V(!1)},ce={replace_login:{title:"Nahradit pÅihlášenà stávajÃcÃho vlastnÃka",desc:"Tento úÄet se stane novým pÅihlášenÃm pro vybraného vlastnÃka. Původnà úÄet zůstane, ale nebude propojen.",icon:e.jsx(Cs,{className:"h-5 w-5"})},add_authorized_person:{title:"PÅidat jako povÄÅenou osobu",desc:"Uživatel bude pÅidán jako povÄÅená osoba (zástupce) k vybraného vlastnÃka.",icon:e.jsx(Le,{className:"h-5 w-5"})},add_coowner:{title:"PÅidat jako spoluvlastnÃka",desc:"VytvoÅà nový vlastnický záznam a pÅidá uživatele jako spoluvlastnÃka k bytům vybraného vlastnÃka.",icon:e.jsx(zs,{className:"h-5 w-5"})},delete_account:{title:"Smazat registraci",desc:"Smaže tento úÄet úplnÄ. Uživatel se bude muset registrovat znovu.",icon:e.jsx(Ps,{className:"h-5 w-5"})}};return e.jsx(_s,{open:_,onOpenChange:p,children:e.jsxs(Ns,{className:"max-w-xl",children:[e.jsxs(bs,{children:[e.jsxs(ys,{className:"font-serif",children:[k==="action"&&"Zpracovat registraci",k==="select_owner"&&"Vyberte vlastnÃka",k==="confirm"&&"PotvrzenÃ"]}),e.jsxs(ks,{children:[k==="action"&&`Registrace: ${L} (${t||"bez e-mailu"})`,k==="select_owner"&&`${(de=ce[x])==null?void 0:de.title}`,k==="confirm"&&"Zkontrolujte a potvrÄte akci"]})]}),k==="action"&&e.jsxs("div",{className:"space-y-4",children:[u&&e.jsxs("div",{className:`rounded-lg border p-3 text-sm flex items-start gap-2 ${I==="strong"?"border-green-300 bg-green-50/50 text-green-800":"border-amber-300 bg-amber-50/50 text-amber-800"}`,children:[e.jsx(Ke,{className:"h-5 w-5 shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:I==="strong"?"Duplicitnà registrace detekována":"NejednoznaÄná shoda â zkontrolujte ruÄnÄ"}),e.jsxs("p",{className:"mt-1",children:["E-mail ",e.jsx("strong",{children:t})," již patÅà vlastnÃkovi"," ",e.jsx("strong",{children:y(u)}),u.apartments.length>0&&e.jsxs(e.Fragment,{children:[" (",u.apartments.map(a=>`TOP ${a.replace(/^TOP\s*/i,"")}`).join(", "),")"]}),I==="strong"?". Nová pending registrace pravdÄpodobnÄ nenà potÅeba. DoporuÄujeme smazat tuto registraci a pÅÃpadnÄ vlastnÃka notifikovat.":". Existuje vÃce možných shod â rozhodnutà ponechte na vlastnÃm posouzenÃ."]})]})]}),!u&&h&&e.jsxs("div",{className:"rounded-lg border border-blue-300 bg-blue-50/50 p-3 text-sm flex items-start gap-2 text-blue-800",children:[e.jsx(Le,{className:"h-5 w-5 shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Nalezena shoda â existujÃcà zástupce"}),e.jsxs("p",{className:"mt-1",children:["E-mail ",e.jsx("strong",{children:t})," odpovÃdá zástupci"," ",e.jsxs("strong",{children:[h.person.first_name," ",h.person.last_name]})," ","u vlastnÃka"," ",e.jsx("strong",{children:y(h.owner)}),h.owner.apartments.length>0&&e.jsxs(e.Fragment,{children:[" (",h.owner.apartments.map(a=>`TOP ${a.replace(/^TOP\s*/i,"")}`).join(", "),")"]}),". DoporuÄujeme zvolit ",e.jsx("strong",{children:'âNahradit pÅihlášenÃ"'})," pro propojenà úÄtu."]})]})]}),e.jsx(Be,{value:x||"",onValueChange:a=>E(a),children:Object.entries(ce).map(([a,{title:r,desc:d,icon:l}])=>e.jsxs("label",{className:`flex items-start gap-3 p-3 rounded-lg border cursor-pointer transition-colors ${x===a?"border-primary bg-primary/5":"border-border hover:bg-muted/50"} ${a==="delete_account"?"border-destructive/30":""}`,children:[e.jsx(Ve,{value:a,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[l,e.jsx("span",{className:`font-medium text-sm ${a==="delete_account"?"text-destructive":""}`,children:r})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:d})]})]},a))}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(w,{variant:"outline",onClick:()=>p(!1),children:"ZruÅ¡it"}),e.jsx(w,{disabled:!x,onClick:Te,children:x==="delete_account"?"PokraÄovat":"Vybrat vlastnÃka â"})]})]}),k==="select_owner"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Ss,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(Z,{placeholder:"Hledat vlastnÃka...",value:se,onChange:a=>te(a.target.value),className:"pl-9"})]}),ge?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(C,{className:"h-6 w-6 animate-spin text-primary"})}):e.jsx(Xe,{className:"h-[300px]",children:e.jsxs(Be,{value:S||"",onValueChange:B,children:[le.map(a=>e.jsxs("label",{className:`flex items-center gap-3 p-3 rounded-lg border cursor-pointer transition-colors mb-1 ${S===a.id?"border-primary bg-primary/5":"border-border hover:bg-muted/50"}`,children:[e.jsx(Ve,{value:a.id}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm truncate",children:y(a)}),a.user_id&&e.jsx(ze,{variant:"outline",className:"text-[10px] shrink-0",children:"má úÄet"})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[a.apartments.length>0&&e.jsx("span",{children:a.apartments.map(r=>`TOP ${r.replace(/^TOP\s*/i,"")}`).join(", ")}),a.email&&e.jsxs("span",{children:["· ",a.email]})]})]})]},a.id)),le.length===0&&e.jsx("p",{className:"text-center text-muted-foreground py-8 text-sm",children:"Žádný vlastnÃk neodpovÃdá hledánÃ"})]})}),e.jsxs("div",{className:"flex justify-between pt-2",children:[e.jsx(w,{variant:"outline",onClick:()=>A("action"),children:"â ZpÄt"}),e.jsx(w,{disabled:!S,onClick:()=>A("confirm"),children:"Potvrdit â"})]})]}),k==="confirm"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border p-4 space-y-2 bg-muted/30",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Uživatel:"}),e.jsx("span",{className:"font-medium",children:L}),t&&e.jsxs("span",{className:"text-muted-foreground",children:["(",t,")"]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Akce:"}),e.jsx("span",{className:"font-medium",children:(me=ce[x])==null?void 0:me.title})]}),f&&e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"VlastnÃk:"}),e.jsx("span",{className:"font-medium",children:y(f)}),f.apartments.length>0&&e.jsx(ze,{variant:"outline",className:"text-[10px]",children:f.apartments.map(a=>`TOP ${a.replace(/^TOP\s*/i,"")}`).join(", ")})]})]}),h&&x==="replace_login"&&h.owner.id===S&&e.jsxs("div",{className:"rounded-lg border border-blue-300 bg-blue-50/50 p-3 text-sm flex items-start gap-2 text-blue-800",children:[e.jsx(Le,{className:"h-5 w-5 shrink-0 mt-0.5"}),e.jsxs("div",{children:["ÃÄet bude propojen se zástupcem ",e.jsxs("strong",{children:[h.person.first_name," ",h.person.last_name]})," u vlastnÃka ",e.jsx("strong",{children:y(h.owner)}),"."]})]}),x==="replace_login"&&(f==null?void 0:f.user_id)&&!h&&e.jsx("div",{className:"rounded-lg border border-amber-200 bg-amber-50/50 p-3 text-sm text-amber-800",children:"â ï¸ Tento vlastnÃk má již propojený úÄet. StávajÃcà propojenà bude nahrazeno."}),x==="delete_account"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded-lg border border-destructive/30 bg-destructive/5 p-3 text-sm text-destructive",children:"â ï¸ ÃÄet bude trvale smazán. Tuto akci nelze vrátit."}),u&&u.email&&e.jsxs("label",{className:"flex items-start gap-3 p-3 rounded-lg border border-border bg-muted/20 cursor-pointer",children:[e.jsx(xe,{checked:W,onCheckedChange:a=>J(a===!0),className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(he,{className:"h-4 w-4"}),"Notifikovat vlastnÃka"]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["OdeÅ¡le e-mail na ",e.jsx("strong",{children:u.email})," s informacÃ, že úÄet již existuje a může se pÅihlásit pomocà Magic Linku nebo si zmÄnit heslo."]})]})]})]}),e.jsxs("div",{className:"flex justify-between pt-2",children:[e.jsx(w,{variant:"outline",onClick:()=>A(x==="delete_account"||h?"action":"select_owner"),children:"â ZpÄt"}),e.jsxs(w,{disabled:re,variant:x==="delete_account"?"destructive":"default",onClick:_e,children:[re&&e.jsx(C,{className:"h-4 w-4 animate-spin mr-1"}),x==="delete_account"?"Smazat úÄet":"Provést"]})]})]})]})})},Is=({userId:_})=>{const{toast:p}=Ge(),b=Qe(),[t,L]=n.useState(null),[fe,T]=n.useState(!0),[k,A]=n.useState(""),[x,E]=n.useState(""),[z,ve]=n.useState(""),[S,B]=n.useState(""),[se,te]=n.useState(""),[ge,ae]=n.useState(!1),[re,V]=n.useState(!1),[W,J]=n.useState(!1),[Pe,ne]=n.useState(!1),[I,U]=n.useState(!1),[H,ie]=n.useState(!1),[oe,je]=n.useState(!1),[we,y]=n.useState(!1),[u,h]=n.useState(!1),[le,f]=n.useState(!1),[Te,Ae]=n.useState(!1),[$e,_e]=n.useState(!1),[ce,de]=n.useState(!1),[me,a]=n.useState(!1),[r,d
11]=n.useState(""),[l,v]=n.useState(!1),[F,O]=n.useState(!1),[q,D]=n.useState(!1),[Re,es]=n.useState([]),[ss,Me]=n.useState(!1),[Ee,Ie]=n.useState(!1),[ts,He]=n.useState(!1),[m,pe]=n.useState(null),[Ne,Fe]=n.useState(!1),Y=(s=>{if(!s)return{level:"weak",label:"",color:""};let c=0;return s.length>=6&&(c+=1),s.length>=10&&(c+=1),s.length>=14&&(c+=1),/[a-z]/.test(s)&&(c+=1),/[A-Z]/.test(s)&&(c+=1),/[0-9]/.test(s)&&(c+=1),/[^a-zA-Z0-9]/.test(s)&&(c+=1),c<=3?{level:"weak",label:"Slabé",color:"bg-destructive"}:c<=5?{level:"medium",label:"StÅednÃ",color:"bg-yellow-500"}:{level:"strong",label:"Silné",color:"bg-green-500"}})(r);n.useEffect(()=>{G()},[_]);const G=async()=>{T(!0);const{data:s,error:c}=await o.rpc("admin_get_profile",{_user_id:_}),i=Array.isArray(s)?s[0]:null;if(c||!i){p({variant:"destructive",title:"Chyba",description:"NepodaÅilo se naÄÃst uživatele."}),T(!1);return}const{data:N,error:P}=await o.from("user_roles").select("role").eq("user_id",_);if(P){p({variant:"destructive",title:"Chyba",description:"NepodaÅilo se naÄÃst role."}),T(!1);return}const g=N.map($=>$.role),j={id:i.id,user_id:i.user_id,full_name:i.full_name,first_name:i.first_name,last_name:i.last_name,email:i.email,apartment_number:i.apartment_number,phone:i.phone,roles:g,approval_status:i.approval_status||"pending",approved_at:i.approved_at,approved_by:i.approved_by,rejected_at:i.rejected_at,rejected_by:i.rejected_by};L(j),A(i.first_name||""),E(i.last_name||""),ve(i.email||""),B(i.phone||""),te(i.apartment_number||""),ae(g.includes("admin")),V(g.includes("owner")),J(g.includes("beirat")),ne(g.includes("spravce")),T(!1),as(_),rs(_),(i.approval_status==="pending"||i.approval_status==="rejected")&&ns(i.email)},as=async s=>{Me(!0);const{data:c,error:i}=await o.from("login_history").select("*").eq("user_id",s).order("logged_in_at",{ascending:!1}).limit(50);!i&&c&&es(c),Me(!1)},rs=async s=>{const{data:c}=await o.from("forum_subscribers").select("id").eq("user_id",s).maybeSingle();Ie(!!c)},ns=async s=>{if(!s){pe(null);return}const c=s.toLowerCase(),{data:i}=await o.from("owner_contacts").select("id, first_name, last_name, company_name, email, user_id, is_active, language").ilike("email",c),{data:N}=await o.from("owner_contact_persons").select("id, email").ilike("email",c),P=(i||[]).filter(g=>g.user_id&&g.is_active);if(P.length===1&&(!N||N.length===0)){const g=P[0],{data:j}=await o.from("apartment_owners").select("apartments(code)").eq("owner_contact_id",g.id).eq("is_current",!0),$=(j||[]).map(ue=>{var be;return((be=ue.apartments)==null?void 0:be.code)||"?"});pe({type:"strong",owner:g,apartments:$})}else if(P.length>0||N&&N.length>0){const g=P[0]||(i||[])[0];if(g){const{data:j}=await o.from("apartment_owners").select("apartments(code)").eq("owner_contact_id",g.id).eq("is_current",!0),$=(j||[]).map(be=>{var Ze;return((Ze=be.apartments)==null?void 0:Ze.code)||"?"}),ue=[];P.length>1&&ue.push("vÃce vlastnÃků se stejným e-mailem"),N&&N.length>0&&ue.push("e-mail je použit i u kontaktnà osoby"),pe({type:"weak",owner:g,apartments:$,reason:ue.join(", ")})}else pe(null)}else pe(null)},qe=async s=>{if(t){Fe(!0);try{const{data:{session:c}}=await o.auth.getSession();if(!c)throw new Error("Nenà pÅihlášen");if(s&&(m!=null&&m.owner.email)){const P=m.owner.language||"en",g=m.owner.company_name||`${m.owner.first_name||""} ${m.owner.last_name||""}`.trim()||"",j=window.location.origin;await o.functions.invoke("send-notification-email",{body:{template_type:"duplicate_registration",language:P,recipient_email:m.owner.email,variables:{"{userName}":g?` ${g}`:"","{loginLink}":`${j}/auth`,"{resetPasswordUrl}":`${j}/reset-password`,"{emailSignature}":""}}})}const{data:i,error:N}=await o.functions.invoke("admin-user-actions",{body:{userId:t.user_id,action:"delete_user",audit:{action:"duplicate_registration_deleted",target_email:t.email,reason:"existing_active_account_found",details:{notification_sent:s,matched_owner_contact_id:m==null?void 0:m.owner.id,matched_owner_name:(m==null?void 0:m.owner.company_name)||`${(m==null?void 0:m.owner.first_name)||""} ${(m==null?void 0:m.owner.last_name)||""}`.trim(),duplicate_type:m==null?void 0:m.type}}}});if(N)throw new Error(N.message);p({title:"Duplicitnà registrace smazána",description:s?"Uživatel byl informován e-mailem.":"Registrace byla smazána bez notifikace."}),b("/admin")}catch(c){p({variant:"destructive",title:"Chyba",description:c.message||"NepodaÅilo se smazat registraci."})}Fe(!1)}},is=async s=>{He(!0),s?await o.from("forum_subscribers").insert({user_id:_}):await o.from("forum_subscribers").delete().eq("user_id",_),Ie(s),He(!1),p({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."})},os=async()=>
11{if(!t)return;U(!0);const{error:s}=await o.from("profiles").update({first_name:k||null,last_name:x||null,email:z||null,phone:S||null,apartment_number:se||null,full_name:[k,x].filter(Boolean).join(" ")||null}).eq("id",t.id);s?p({variant:"destructive",title:"Chyba",description:"NepodaÅilo se uložit profil."}):(p({title:"Uloženo",description:"Profil byl úspÄÅ¡nÄ aktualizován."}),G()),U(!1)},ls=async()=>{if(!t)return;ie(!0);const s=[];ge&&s.push("admin"),re&&s.push("owner"),W&&s.push("beirat"),Pe&&s.push("spravce");const{data:c}=await o.from("user_roles").select("role").eq("user_id",t.user_id),i=new Set((c||[]).map(j=>j.role)),N=new Set(s),P=s.filter(j=>!i.has(j)),g=[...i].filter(j=>!N.has(j));if(P.length>0){const{error:j}=await o.from("user_roles").insert(P.map($=>({user_id:t.user_id,role:$})));if(j){p({variant:"destructive",title:"Chyba",description:"NepodaÅilo se pÅidat role."}),ie(!1);return}}for(const j of g){const{error:$}=await o.from("user_roles").delete().eq("user_id",t.user_id).eq("role",j);$&&console.warn("Failed to remove role:",j,$)}p({title:"Uloženo",description:"Role byly úspÄÅ¡nÄ aktualizovány."}),G(),ie(!1)},cs=async()=>{if(!(t!=null&&t.email)){p({variant:"destructive",title:"Chyba",description:"Uživatel nemá nastaven e-mail."});return}je(!0);try{const{data:s,error:c}=await o.functions.invoke("send-auth-email",{body:{email:t.email,type:"password_reset",redirectTo:window.location.origin}});c||s!=null&&s.error?p({variant:"destructive",title:"Chyba",description:"NepodaÅilo se odeslat reset hesla."}):p({title:"Odesláno",description:`E-mail pro reset hesla byl odeslán na ${t.email}.`})}catch{p({variant:"destructive",title:"Chyba",description:"NepodaÅilo se odeslat reset hesla."})}je(!1)},ds=()=>{const s="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%&*";let c="";for(let i=0;i<12;i++)c+=s.charAt(Math.floor(Math.random()*s.length));d(c),v(!0)},ms=async()=>{r&&(await navigator.clipboard.writeText(r),O(!0),setTimeout(()=>O(!1),2e3))},ps=async()=>{if(!(!t||!r)){if(r.length<6){p({variant:"destructive",title:"Chyba",description:"Heslo musà mÃt alespoÅ 6 znaků."});return}y(!0);try{const{data:{session:s}}=await o.auth.getSession(),c=await fetch("https://wasldznewicttoslpmnx.supabase.co/functions/v1/admin-user-actions",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s==null?void 0:s.access_token}`},body:JSON.stringify({userId:t.user_id,password:r})}),i=await c.json();if(!c.ok)throw new Error(i.error||"NepodaÅilo se nastavit heslo");p({title:"Heslo zmÄnÄno",description:"Nové heslo bylo úspÄÅ¡nÄ nastaveno."}),d(""),v(!1)}catch(s){p({variant:"destructive",title:"Chyba",description:s.message||"NepodaÅilo se nastavit heslo."})}y(!1)}},us=s=>{switch(s){case"Mobil":return e.jsx(Rs,{className:"h-4 w-4"});case"Tablet":return e.jsx(Ms,{className:"h-4 w-4"});default:return e.jsx(Ds,{className:"h-4 w-4"})}};return fe?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(C,{className:"h-8 w-8 animate-spin text-primary"})}):t?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-4 pb-4 border-b",children:[e.jsx("div",{className:"h-12 w-12 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx(Ue,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h2",{className:"text-xl font-semibold",children:t.full_name||`${t.first_name||""} ${t.last_name||""}`.trim()||"Neuvedeno"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t.email||"Bez e-mailu"})]}),e.jsx(ze,{className:t.approval_status==="approved"?"bg-green-100 text-green-800 border-green-200":t.approval_status==="rejected"?"bg-destructive/10 text-destructive border-destructive/20":"bg-amber-100 text-amber-800 border-amber-200",children:t.approval_status==="approved"?"Schváleno":t.approval_status==="rejected"?"ZamÃtnuto":"Äeká na schválenÃ"})]}),t.approval_status!=="approved"&&m&&e.jsx(R,{className:m.type==="strong"?"border-green-300 bg-green-50/50":"border-amber-300 bg-amber-50/50",children:e.jsxs(M,{className:"pt-4 pb-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[m.type==="strong"?e.jsx(Ts,{className:"h-5 w-5 text-green-600 shrink-0 mt-0.5"}):e.jsx(Ke,{className:"h-5 w-5 text-amber-600 shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-foreground",children:m.type==="strong"?"Duplicitnà registrace detekována":"NejednoznaÄná shoda â zkontrolujte ruÄnÄ"}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Tento e-mail je již pÅiÅazen k aktivnÃmu úÄtu:"," ",e.jsx("strong",{children:m.owner.company_name||`${m.owner.first_name||""} ${m.owner.last_name||""}`.trim()}),m.apartments.length>0&&e.jsxs(e.Fragment,{children:[" (",m.apartments.map(s=>`TOP ${s.replace(/^TOP\s*/i,"")}`).join(", "),")"]}),". ",m.type==="strong"?"Nová pending registrace pravdÄpodobnÄ nenà potÅeba.":`${m.reason||"Existuje vÃce možných shod."}`]})]})]}),m.type==="strong"&&e.jsxs("div",{className:"flex gap-2 ml-8",children:[e.jsxs(w,{variant:"outline",size:"sm",disabled:Ne,onClick:()=>qe(!1),children:[Ne?e.jsx(C,{className:"h-4 w-4 animate-spin mr-1"}):null,"Smazat duplicitnà registraci"]}),e.jsxs(w,{size:"sm",disabled:Ne,onClick:()=>qe(!0),children:[Ne?e.jsx(C,{className:"h-4 w-4 animate-spin mr-1"}):e.jsx(he,{className:"h-4 w-4 mr-1"}),"Smazat a informovat uživatele"]})]})]})}),t.approval_status!=="approved"&&e.jsx(R,{className:"border-amber-200 bg-amber-50/50",children:e.jsxs(M,{className:"pt-4 pb-4 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-foreground",children:t.approval_status==="rejected"?"Registrace tohoto uživatele byla zamÃtnuta":"Tento uživatel Äeká na schválenÃ"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"SchválenÃm zÃská roli vlastnÃka a pÅÃstup do aplikace."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(w,{variant:"outline",size:"sm",disabled:le,className:"text-destructive border-destructive/30",onClick:()=>_e(!0),children:[le?e.jsx(C,{className:"h-4 w-4 animate-spin mr-1"}):null,"ZamÃtnout"]}),e.jsxs(w,{size:"sm",disabled:u,onClick:()=>de(!0),children:[u?e.jsx(C,{className:"h-4 w-4 animate-spin mr-1"}):e.jsx(De,{className:"h-4 w-4 mr-1"}),"Zpracovat registraci"]})]})]})}),e.jsx(Oe,{open:$e,onOpenChange:_e,title:"ZamÃtnout registraci?",description:"Uživatel nebude mÃt pÅÃstup do aplikace.",variant:"destructive",onConfirm:async()=>{f(!0);const{error:s}=await o.rpc("reject_user",{target_user_id:_});s?p({variant:"destructive",title:"Chyba",description:s.message}):(p({title:"ZamÃtnuto",description:"Registrace byla zamÃtnuta."}),G()),f(!1)}}),e.jsx(Oe,{open:Te,onOpenChange:Ae,title:"Schválit registraci?",description:"Uživatel zÃská pÅÃstup do aplikace a bude mu pÅiÅazena role vlastnÃka.",variant:"default",onConfirm:async()=>{var i;h(!0);const{data:s,error:c}=await o.rpc("approve_user",{target_user_id:_});if(c){const N=(i=c.message)==null?void 0:i.includes("IDENTITY_EMAIL_MISMATCH");p({variant:"destructive",title:N?"Schválenà zablokováno â nesoulad e-mailu":"Chyba",description:N?c.message.replace(/^.*IDENTITY_EMAIL_MISMATCH:\s*/,""):c.message})}else p({title:"Schváleno",description:"Registrace byla schválena."+(s==="approved_linked"?" VlastnÃk byl automaticky propojen.":s==="approved_ambiguous_match"?" Nalezeno vÃce vlastnÃků se shodným emailem â propojte ruÄnÄ.":" VlastnÃk nebyl automaticky nalezen â propojte ruÄnÄ.")}),G();h(!1)}}),e.jsx(Es,{open:ce,onOpenChange:de,userId:_,userEmail:t.email,userName:t.full_name||`${t.first_name||""} ${t.last_name||""}`.trim()||"Neuvedeno",onComplete:s=>{s==="delete_account"?b("/admin"):G()}}),(t.approved_at||t.rejected_at)&&e.jsxs("div",{className:"text-xs text-muted-foreground flex gap-4",children:[t.approved_at&&e.jsxs("span",{children:["Schváleno: ",Se(new Date(t.approved_at),"dd.MM.yyyy HH:mm",{locale:Ce})]}),t.rejected_at&&e.jsxs("span",{children:["ZamÃtnuto: ",Se(new Date(t.rejected_at),"dd.MM.yyyy HH:mm",{locale:Ce})]})]}),t.approval_status==="approved"&&t.email&&e.jsxs(w,{variant:"outline",size:"sm",disabled:me,onClick:async()=>{a(!0);try{const s=window.location.origin.replace(/\/admin.*/,""),c="de",i=[t.first_name,t.last_name].filter(
11Boolean).join(" ")||t.full_name||"";await o.functions.invoke("send-notification-email",{body:{template_type:"registration_approved",language:c,recipient_email:t.email,variables:{"{userName}":i?` ${i}`:"","{loginLink}":`${s}/auth`,"{resetPasswordUrl}":`${s}/reset-password`,"{emailSignature}":""}}}),p({title:"Odesláno",description:`PÅÃstupový e-mail odeslán na ${t.email}.`})}catch(s){p({variant:"destructive",title:"Chyba",description:s.message||"NepodaÅilo se odeslat e-mail."})}a(!1)},children:[me?e.jsx(C,{className:"h-4 w-4 animate-spin mr-1"}):e.jsx(he,{className:"h-4 w-4 mr-1"}),"Poslat pÅÃstupový e-mail"]}),e.jsxs(gs,{defaultValue:"profile",className:"w-full",children:[e.jsxs(js,{className:"grid w-full grid-cols-4",children:[e.jsx(ye,{value:"profile",children:"Profil"}),e.jsx(ye,{value:"roles",children:"Role"}),e.jsx(ye,{value:"access",children:"PÅÃstup"}),e.jsx(ye,{value:"history",children:"Historie"})]}),e.jsx(ke,{value:"profile",className:"space-y-4 mt-4",children:e.jsxs(R,{children:[e.jsxs(K,{children:[e.jsx(Q,{className:"text-lg",children:"Osobnà údaje"}),e.jsx(X,{children:"Upravte základnà informace o uživateli"})]}),e.jsxs(M,{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(ee,{htmlFor:"firstName",children:"Jméno"}),e.jsx(Z,{id:"firstName",value:k,onChange:s=>A(s.target.value),placeholder:"Jan"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ee,{htmlFor:"lastName",children:"PÅÃjmenÃ"}),e.jsx(Z,{id:"lastName",value:x,onChange:s=>E(s.target.value),placeholder:"Novák"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ee,{htmlFor:"email",children:"E-mail (kontaktnÃ)"}),e.jsx(Z,{id:"email",type:"email",value:z,onChange:s=>ve(s.target.value),placeholder:"[email protected]"})]}),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(ee,{htmlFor:"phone",children:"Telefon"}),e.jsx(Z,{id:"phone",value:S,onChange:s=>B(s.target.value),placeholder:"+420 123 456 789"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ee,{htmlFor:"apartment",children:"ÄÃslo apartmánu"}),e.jsx(Z,{id:"apartment",value:se,onChange:s=>te(s.target.value),placeholder:"A1"})]})]}),e.jsx("div",{className:"pt-4",children:e.jsxs(w,{onClick:os,disabled:I,children:[I?e.jsx(C,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(We,{className:"h-4 w-4 mr-2"}),"Uložit profil"]})})]})]})}),e.jsxs(ke,{value:"roles",className:"space-y-4 mt-4",children:[e.jsxs(R,{children:[e.jsxs(K,{children:[e.jsx(Q,{className:"text-lg",children:"PÅiÅazené role"}),e.jsx(X,{children:"Nastavte oprávnÄnà uživatele v systému"})]}),e.jsxs(M,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center space-x-3 p-4 border rounded-lg",children:[e.jsx(xe,{id:"roleAdmin",checked:ge,onCheckedChange:s=>ae(s===!0)}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("label",{htmlFor:"roleAdmin",className:"flex items-center gap-2 font-medium cursor-pointer",children:[e.jsx(De,{className:"h-4 w-4 text-primary"}),"Administrátor"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Plný pÅÃstup ke správÄ webu, uživatelů a obsahu"})]})]}),e.jsxs("div",{className:"flex items-center space-x-3 p-4 border rounded-lg",children:[e.jsx(xe,{id:"roleOwner",checked:re,onCheckedChange:s=>V(s===!0)}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("label",{htmlFor:"roleOwner",className:"flex items-center gap-2 font-medium cursor-pointer",children:[e.jsx(Ue,{className:"h-4 w-4 text-secondary-foreground"}),"VlastnÃk"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"PÅÃstup k sekci pro vlastnÃky apartmánů"})]})]}),e.jsxs("div",{className:"flex items-center space-x-3 p-4 border rounded-lg",children:[e.jsx(xe,{id:"roleBeirat",checked:W,onCheckedChange:s=>J(s===!0)}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("label",{htmlFor:"roleBeirat",className:"flex items-center gap-2 font-medium cursor-pointer",children:[e.jsx(De,{className:"h-4 w-4 text-amber-600"}),"Beirat"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Älen poradnÃho sboru vlastnÃků"})]})]}),e.jsxs("div",{className:"flex items-center space-x-3 p-4 border rounded-lg",children:[e.jsx(xe,{id:"roleSpravce",checked:Pe,onCheckedChange:s=>ne(s===!0)}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("label",{htmlFor:"roleSpravce",className:"flex items-center gap-2 font-medium cursor-pointer",children:[e.jsx(Ue,{className:"h-4 w-4 text-blue-600"}),"Správce"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Správce nemovitosti (Hausverwaltung)"})]})]})]}),e.jsx("div",{className:"pt-4",children:e.jsxs(w,{onClick:ls,disabled:H,children:[H?e.jsx(C,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(We,{className:"h-4 w-4 mr-2"}),"Uložit role"]})})]})]}),e.jsxs(R,{children:[e.jsxs(K,{children:[e.jsx(Q,{className:"text-lg",children:"Fórum notifikace"}),e.jsx(X,{children:"Nastavenà e-mailových notifikacà z fóra pro tohoto uživatele"})]}),e.jsx(M,{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:Ee?"Uživatel nedostává n
11otifikace z fóra":"Uživatel dostává notifikace z fóra"})]}),e.jsx(vs,{checked:!Ee,disabled:ts,onCheckedChange:s=>is(!s)})]})})]})]}),e.jsxs(ke,{value:"access",className:"space-y-4 mt-4",children:[e.jsxs(R,{children:[e.jsxs(K,{children:[e.jsxs(Q,{className:"text-lg flex items-center gap-2",children:[e.jsx(Je,{className:"h-5 w-5"}),"Manuálnà nastavenà hesla"]}),e.jsx(X,{children:"Zadejte nové heslo nebo jej vygenerujte náhodnÄ"})]}),e.jsxs(M,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(ee,{htmlFor:"newPassword",children:"Nové heslo"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Z,{id:"newPassword",type:l?"text":"password",value:r,onChange:s=>d(s.target.value),placeholder:"Zadejte nové heslo",className:"pr-20"}),e.jsxs("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex gap-1",children:[e.jsx(w,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>v(!l),children:l?e.jsx($s,{className:"h-4 w-4"}):e.jsx(Os,{className:"h-4 w-4"})}),r&&e.jsx(w,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",onClick:ms,children:F?e.jsx(As,{className:"h-4 w-4 text-green-500"}):e.jsx(Ls,{className:"h-4 w-4"})})]})]}),e.jsxs(w,{type:"button",variant:"outline",onClick:ds,children:[e.jsx(hs,{className:"h-4 w-4 mr-2"}),"Generovat"]})]}),r&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-2 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full transition-all duration-300 ${Y.color}`,style:{width:Y.level==="weak"?"33%":Y.level==="medium"?"66%":"100%"}})}),e.jsx("span",{className:`text-sm font-medium ${Y.level==="weak"?"text-destructive":Y.level==="medium"?"text-yellow-600":"text-green-600"}`,children:Y.label})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Pro silné heslo použijte: velká i malá pÃsmena, ÄÃsla a speciálnà znaky"})]}),!r&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Heslo musà mÃt alespoÅ 6 znaků"})]}),e.jsxs(w,{onClick:()=>D(!0),disabled:we||!r||r.length<6,children:[we?e.jsx(C,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Je,{className:"h-4 w-4 mr-2"}),"Uložit heslo"]}),e.jsx(Oe,{open:q,onOpenChange:D,title:"Potvrdit zmÄnu hesla",description:`Opravdu chcete nastavit nové heslo pro uživatele ${t.full_name||t.email||"tohoto uživatele"}? Tato akce je nevratná.`,confirmText:"Ano, nastavit heslo",cancelText:"ZruÅ¡it",onConfirm:()=>{D(!1),ps()}})]})]}),e.jsx(ws,{}),e.jsxs(R,{children:[e.jsxs(K,{children:[e.jsxs(Q,{className:"text-lg flex items-center gap-2",children:[e.jsx(he,{className:"h-5 w-5"}),"Reset hesla e-mailem"]}),e.jsx(X,{children:"OdeÅ¡le uživateli e-mail s odkazem pro reset hesla"})]}),e.jsxs(M,{children:[e.jsxs(w,{onClick:cs,disabled:oe||!t.email,variant:"outline",children:[oe?e.jsx(C,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(he,{className:"h-4 w-4 mr-2"}),"Odeslat reset hesla"]}),!t.email&&e.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:"Uživatel nemá nastaven e-mail"})]})]})]}),e.jsx(ke,{value:"history",className:"space-y-4 mt-4",children:e.jsxs(R,{children:[e.jsxs(K,{children:[e.jsxs(Q,{className:"text-lg flex items-center gap-2",children:[e.jsx(Us,{className:"h-5 w-5"}),"Historie pÅihlášenÃ"]}),e.jsx(X,{children:"PoslednÃch 50 pÅihlášenà uživatele"})]}),e.jsx(M,{children:ss?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(C,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):Re.length===0?e.jsx("p",{className:"text-center py-8 text-muted-foreground",children:"Žádná historie pÅihlášenÃ"}):e.jsx(Xe,{className:"h-[400px] pr-4",children:e.jsx("div",{className:"space-y-3",children:Re.map(s=>e.jsxs("div",{className:"flex items-start gap-3 p-3 border rounded-lg",children:[e.jsx("div",{className:"mt-0.5",children:us(s.device_type)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-medium",children:Se(new Date(s.logged_in_at),"dd.MM.yyyy",{locale:Ce})}),e.jsx("span",{className:"text-muted-foreground",children:Se(new Date(s.logged_in_at),"HH:mm",{locale:Ce})})]}),e.jsx("div",{className:"text-sm text-muted-foreground mt-1",children:[s.browser,s.os].filter(
11Boolean).join(" ⢠")||"Neznámé zaÅÃzenÃ"})]}),s.device_type&&e.jsx(ze,{variant:"outline",className:"shrink-0",children:s.device_type})]},s.id))})})})]})})]})]}):e.jsxs("div",{className:"text-center py-12",children:[e.jsx("p",{className:"text-muted-foreground",children:"Uživatel nenalezen"}),e.jsx(w,{variant:"ghost",onClick:()=>b("/admin"),className:"mt-4",children:"ZpÄt na seznam"})]})},Et=()=>{const{id:_}=xs(),p=Qe();return _?e.jsx(fs,{title:"Detail uživatele",breadcrumbs:[{label:"Administrace",href:"/admin"},{label:"Uživatelé",href:"/admin"},{label:"Detail uživatele"}],activeSection:"users",children:e.jsx(Is,{userId:_})}):(p("/admin"),null)};export{Et 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.