1import{E as Te,a as Re,t as Me,r as t,s as m,j as e,m as N,B as c,w as me,K as de,N as pe,O as ue,x as he,y as o,I as d,M as y,a7 as xe}from"./index-MoAbC8_9.js";import{A as ve}from"./AdminPageLayout-DL0avA2R.js";import{B as Fe}from"./badge-BHbYeRgi.js";import{C as b}from"./checkbox-D2A7tWS7.js";import{S}from"./separator-CQ84aZ0V.js";import{S as Ve,a as Ze,b as Ue,c as $e,d as Be}from"./select-ChAxOmxm.js";import{C as He}from"./confirm-dialog-DHYtbMdr.js";import{I as qe}from"./InvitePreviewDialog-DT7jKBqI.js";import{A as Je}from"./arrow-left-CZKmX_Y-.js";import{U as Ke}from"./user-Cvsz7Lm_.js";import{S as Ge}from"./save-DWdLHugL.js";import{S as Ye}from"./Header-CnJGZ8vQ.js";import{K as Qe}from"./key-Do0I7jZr.js";import{L as We}from"./lock-BEcuk4Jx.js";import"./Layout-jB2m3rBw.js";import"./collapsible-BIxz44zB.js";import"./breadcrumb-CmKLwRya.js";import"./AdminSidebar-B1OFksO6.js";import"./scroll-area-CoT3wSM0.js";import"./index-BdQq_4o_.js";import"./bell-CKHJStUz.js";import"./clipboard-list-CzdQdj9P.js";import"./file-text-Bif0RP8Y.js";import"./users-xui-UtA1.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"./chevron-up-JyGCcpt9.js";import"./dialog-DrI7Oddz.js";import"./textarea-4z16PwID.js";import"./tabs-5EVsfllK.js";import"./eye-DKrvAixa.js";import"./send-DIVN8qsp.js";import"./mountain-BHfTfCFy.js";const je={executive:"Jednatel",procurist:"Prokurista",assistant:"Asistent",billing_contact:"FakturaÄnà kontakt",representative:"PovÄÅená osoba",other:"OstatnÃ"},Xe=["executive","procurist","assistant","billing_contact","other"],es=["representative","other"],Js=()=>{const{id:h}=Te(),z=Re(),{toast:n}=Me(),[fe,P]=t.useState(!0),[A,L]=t.useState(!1),[r,ge]=t.useState(null),[E,Ne]=t.useState(""),[ye,be]=t.useState("individual"),[O,_e]=t.useState(""),[x,I]=t.useState(""),[v,D]=t.useState(""),[l,T]=t.useState(""),[R,M]=t.useState(""),[F,V]=t.useState("representative"),[Z,U]=t.useState(""),[$,B]=t.useState(!1),[_,H]=t.useState(!1),[q,J]=t.useState(!1),[w,K]=t.useState(!0),[G,Y]=t.useState(!1),[p,g]=t.useState(""),[Q,W]=t.useState(!1),[X,ee]=t.useState(!1),[se,ss]=t.useState(!1),[we,te]=t.useState(!1),[Ce,ke]=t.useState(null),ae=(s=!1)=>{if(!l.trim()){n({variant:"destructive",title:"Chyba",description:"Pro pozvánku je nutný e-mail."});return}ke({email:l.trim(),first_name:x,last_name:v,role:"owner",contact_person_id:h,force_resend:s}),te(!0)},[C,ie]=t.useState(""),[ne,re]=t.useState(!1),[u,Se]=t.useState(null),[ze,k]=t.useState(!1),[ts,oe]=t.useState(!1);t.useEffect(()=>{h&&f()},[h]);const f=async()=>{P(!0);const{data:s,error:a}=await m.from("owner_contact_persons").select("*").eq("id",h).maybeSingle();if(a||!s){n({variant:"destructive",title:"Chyba",description:"Osoba nebyla nalezena."}),z("/admin");return}const i=s;ge(i),_e(i.owner_contact_id),I(i.first_name),D(i.last_name),T(i.email||""),M(i.phone||""),V(i.role_type),U(i.role_label||""),B(i.is_primary),H(i.can_login),J(i.can_vote),K(i.can_receive_notifications),Y(i.is_authorized_signer);const{data:j}=await m.from("owner_contacts").select("first_name, last_name, company_name, user_type, id").eq("id",i.owner_contact_id).maybeSingle();j&&(Ne(j.company_name||[j.first_name,j.last_name].filter(Boolean).join(" ")||"Neznámý"),be(j.user_type||"individual")),i.user_id&&Pe(i.user_id),P(!1)},Pe=async s=>{try{const{data:a}=await m.functions.invoke("admin-user-actions",{body:{userId:s,action:"get_user_info"}});a!=null&&a.success&&Se(a)}catch{}},Ae=async()=>{var i;if(!x.trim()||!v.trim()){n({variant:"destructive",title:"Chyba",description:"Jméno a pÅÃjmenà jsou povinné."});return}const s=l.trim();if((_||w)&&!s){n({variant:"destructive",title:"Chyba",description:"E-mail je povinný pokud je zapnuto pÅihlášenà nebo notifikace."});return}L(!0);const{error:a}=await m.from("owner_contact_persons").update({first_name:x.trim(),last_name:v.trim(),email:s||null,phone:R.trim()||null,role_type:F,role_label:Z.trim()||null,is_primary:$,can_login:_,can_vote:q,can_receive_notifications:s?w:!1,is_authorized_signer:G}).eq("id",h);if(a){const j=(i=a.message)!=null&&i.includes("idx_one_primary_per_owner")?"Může existovat pouze jedna primárnà kontaktnà osoba.":a.message||"NepodaÅilo se uložit.";n({variant:"destructive",title:"Chyba",description:j})}else n({title:"Profil uložen"}),f();L(!1)},le=()=>{const s="ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789!@#$%";let a="";for(let i=0;i<12;i++)a+=s.charAt(Math.floor(Math.random()*s.length));g(a)},Le=async()=>
1{if(!l){n({variant:"destructive",title:"Chyba",description:"Pro vytvoÅenà úÄtu je nutný e-mail."});return}if(!p||p.length<6){n({variant:"destructive",title:"Chyba",description:"Heslo musà mÃt alespoÅ 6 znaků."});return}ee(!0);try{const{data:s,error:a}=await m.functions.invoke("admin-create-user",{body:{email:l,password:p,first_name:x,last_name:v,contact_person_id:h,role:"owner"}});a||s!=null&&s.error?n({variant:"destructive",title:"Chyba",description:(s==null?void 0:s.error)||(a==null?void 0:a.message)||"NepodaÅilo se vytvoÅit úÄet."}):(n({title:"ÃÄet vytvoÅen",description:`ÃÄet pro ${l} byl úspÄÅ¡nÄ vytvoÅen.`}),g(""),f())}catch(s){n({variant:"destructive",title:"Chyba",description:s.message||"Neznámá chyba."})}ee(!1)},Ee=async()=>{if(!p||p.length<6){n({variant:"destructive",title:"Chyba",description:"Heslo musà mÃt alespoÅ 6 znaků."});return}W(!0);try{const{data:s,error:a}=await m.functions.invoke("admin-user-actions",{body:{userId:r==null?void 0:r.user_id,password:p}});a||s!=null&&s.error?n({variant:"destructive",title:"Chyba",description:(s==null?void 0:s.error)||(a==null?void 0:a.message)}):(n({title:"Heslo nastaveno"}),g(""))}catch(s){n({variant:"destructive",title:"Chyba",description:s.message})}W(!1)},Oe=async()=>{if(!C.trim()){n({variant:"destructive",title:"Chyba",description:"Zadejte nový e-mail."});return}re(!0);try{const{data:s,error:a}=await m.functions.invoke("admin-user-actions",{body:{userId:r==null?void 0:r.user_id,action:"change_email",newEmail:C.trim()}});a||!(s!=null&&s.success)?n({variant:"destructive",title:"Chyba",description:(s==null?void 0:s.error)||(a==null?void 0:a.message)||"NepodaÅilo se zmÄnit e-mail."}):(n({title:"PÅihlaÅ¡ovacà e-mail zmÄnÄn"}),ie(""),f())}catch(s){n({variant:"destructive",title:"Chyba",description:s.message})}re(!1)},Ie=async()=>{if(!(r!=null&&r.user_id))return;oe(!0),await m.from("owner_contact_persons").update({user_id:null}).eq("id",h);const{error:s}=await m.functions.invoke("admin-user-actions",{body:{userId:r.user_id,action:"delete_user"}});n(s?{variant:"destructive",title:"Chyba",description:"NepodaÅilo se smazat úÄet."}:{title:"ÃÄet smazán"}),k(!1),oe(!1),f()},De=ye==="individual"?es:Xe;if(fe)return e.jsx(ve,{title:"Detail osoby",activeSection:"owners",children:e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(N,{className:"h-8 w-8 animate-spin text-primary"})})});if(!r)return null;const ce=!!r.user_id;return e.jsxs(ve,{title:`${x} ${v}`,breadcrumbs:[{label:"Administrace",href:"/admin"},{label:E,href:`/admin/owner/${O}`},{label:`${x} ${v}`}],activeSection:"owners",children:[e.jsxs("div",{className:"max-w-3xl space-y-6",children:[e.jsxs(c,{variant:"ghost",size:"sm",onClick:()=>z(`/admin/owner/${O}`),className:"gap-1.5 -ml-2 mb-2",children:[e.jsx(Je,{className:"h-4 w-4"}),"ZpÄt na ",E]}),e.jsxs(me,{children:[e.jsxs(de,{children:[e.jsxs(pe,{className:"text-lg flex items-center gap-2",children:[e.jsx(Ke,{className:"h-5 w-5"}),"Profil osoby"]}),e.jsxs(ue,{children:[e.jsx(Fe,{variant:"outline",className:"text-xs",children:je[r.role_type]||r.role_type}),r.role_label&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:r.role_label})]})]}),e.jsxs(he,{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(o,{children:"Jméno *"}),e.jsx(d,{value:x,onChange:s=>I(s.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"PÅÃjmenà *"}),e.jsx(d,{value:v,onChange:s=>D(s.target.value)})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"E-mail"}),e.jsx(d,{type:"email",value:l,onChange:s=>T(s.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Telefon"}),e.jsx(d,{value:R,onChange:s=>M(s.target.value)})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Role"}),e.jsxs(Ve,{value:F,onValueChange:V,children:[e.jsx(Ze,{children:e.jsx(Ue,{})}),e.jsx($e,{children:De.map(s=>e.jsx(Be,{value:s,children:je[s]},s))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Vlastnà popis role"}),e.jsx(d,{value:Z,onChange:s=>U(s.target.value),placeholder:"NapÅ. hlavnà jednatel"})]})]}),e.jsx(S,{}),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(b,{id:"cp-primary",checked:$,onCheckedChange:s=>B(s===!0)}),e.jsx(o,{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(b,{id:"cp-login",checked:_,onCheckedChange:s=>H(s===!0)}),e.jsx(o,{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(b,{id:"cp-vote",checked:q,onCheckedChange:s=>J(s===!0)}),e.jsx(o,{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(b,{id:"cp-notif",checked:w,onCheckedChange:s=>K(s===!0)}),e.jsx(o,{htmlFor:"cp-notif",className:"text-sm cursor-pointer",children:"Dostává n
1otifikace"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(b,{id:"cp-signer",checked:G,onCheckedChange:s=>Y(s===!0)}),e.jsx(o,{htmlFor:"cp-signer",className:"text-sm cursor-pointer",children:"OprávnÄný podpisovatel"})]})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(c,{onClick:Ae,disabled:A,children:[A&&e.jsx(N,{className:"h-4 w-4 animate-spin mr-2"}),e.jsx(Ge,{className:"h-4 w-4 mr-2"}),"Uložit zmÄny"]})})]})]}),e.jsxs(me,{children:[e.jsxs(de,{children:[e.jsxs(pe,{className:"text-lg flex items-center gap-2",children:[e.jsx(Ye,{className:"h-5 w-5"}),"Správa uživatelského úÄtu"]}),e.jsx(ue,{children:ce?"Tato osoba má uživatelský úÄet pro pÅÃstup do portálu.":"Tato osoba zatÃm nemá uživatelský úÄet. VytvoÅte ho pro umožnÄnà pÅihlášenÃ."})]}),e.jsx(he,{className:"space-y-6",children:ce?e.jsxs(e.Fragment,{children:[u&&e.jsxs("div",{className:"text-xs text-muted-foreground space-y-1 bg-muted/50 rounded-md p-3",children:[e.jsxs("p",{children:["ÃÄet vytvoÅen: ",u.created_at?new Date(u.created_at).toLocaleDateString("cs"):"â"]}),e.jsxs("p",{children:["Poslednà pÅihlášenÃ: ",u.last_sign_in_at?new Date(u.last_sign_in_at).toLocaleDateString("cs"):"â"]}),e.jsxs("p",{children:["PÅihlaÅ¡ovacà e-mail: ",e.jsx("span",{className:"font-medium text-foreground",children:u.email||l})]})]}),u&&!u.last_sign_in_at&&l&&e.jsxs("div",{className:"space-y-2 rounded-md border border-amber-200 bg-amber-50/40 p-3",children:[e.jsxs("p",{className:"text-sm font-medium flex items-center gap-2 text-amber-800",children:[e.jsx(y,{className:"h-4 w-4"}),"Uživatel se jeÅ¡tÄ nepÅihlásil"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"PoÅ¡lete mu znovu pozvánkový odkaz pro nastavenà hesla."}),e.jsxs(c,{size:"sm",variant:"outline",className:"border-amber-400 text-amber-800 hover:bg-amber-50",onClick:()=>ae(!0),disabled:se,children:[e.jsx(y,{className:"h-4 w-4 mr-2"}),"Poslat znovu pozvánku"]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("p",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(We,{className:"h-4 w-4"}),"ZmÄnit heslo"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(d,{type:"text",value:p,onChange:s=>g(s.target.value),placeholder:"Nové heslo (min. 6 znaků)"}),e.jsxs(c,{type:"button",variant:"outline",size:"sm",onClick:le,className:"shrink-0",children:[e.jsx(xe,{className:"h-3.5 w-3.5 mr-1"}),"Generovat"]})]}),e.jsxs(c,{size:"sm",onClick:Ee,disabled:Q,children:[Q&&e.jsx(N,{className:"h-4 w-4 animate-spin mr-2"}),"Nastavit heslo"]})]}),e.jsx(S,{}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("p",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(y,{className:"h-4 w-4"}),"ZmÄnit pÅihlaÅ¡ovacà e-mail"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(d,{type:"email",value:C,onChange:s=>ie(s.target.value),placeholder:"Nový pÅihlaÅ¡ovacà e-mail"}),e.jsxs(c,{size:"sm",onClick:Oe,disabled:ne,className:"shrink-0",children:[ne&&e.jsx(N,{className:"h-4 w-4 animate-spin mr-2"}),"ZmÄnit"]})]})]}),e.jsx(S,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-destructive",children:"Smazat úÄet"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Smaže pÅihlaÅ¡ovacà úÄet. Záznam osoby zůstane zachován."}),e.jsx(c,{variant:"destructive",size:"sm",onClick:()=>k(!0),children:"Smazat úÄet"})]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-3 rounded-md border-2 border-emerald-200 bg-emerald-50/40 p-4",children:[e.jsxs("p",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(y,{className:"h-4 w-4 text-emerald-700"}),"Pozvat k pÅihlášenÃ"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"DoporuÄený způsob. Osoba dostane e-mail s odkazem pro nastavenà vlastnÃho hesla. Žádné heslo se nepÅedává administrátorem ani neukládá v plain textu."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"E-mail pro pozvánku"}),e.jsx(d,{value:l,disabled:!0,className:"bg-muted"}),!_&&e.jsx("p",{className:"text-xs text-amber-700",children:"Tip: Aby se osoba mohla pÅihlásit, zaÅ¡krtnÄte výše oprávnÄnà âMůže se pÅihlásitâ."})]}),e.jsxs(c,{onClick:()=>ae(!1),disabled:se||!l,className:"bg-emerald-600 hover:bg-emerald-700 text-white",children:[e.jsx(y,{className:"h-4 w-4 mr-2"}),"Pozvat e-mailem"]})]}),e.jsxs("details",{className:"rounded-md border border-dashed p-4",children:[e.jsx("summary",{className:"cursor-pointer text-sm font-medium text-muted-foreground",children:"PokroÄilé: vytvoÅit úÄet s konkrétnÃm heslem"}),e.jsxs("div",{className:"space-y-3 mt-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Použijte jen výjimeÄnÄ, napÅ. když uživatel nemá pÅÃstup k e-mailu. Heslo si nepoznamenávejte â sdÄlte ho osobnÄ."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Heslo *"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(d,{type:"text",value:p,onChange:s=>g(s.target.value),placeholder:"Zadejte heslo (min. 6 znaků)"}),e.jsxs(c,{type:"button",variant:"outline",size:"sm",onClick:le,className:"shrink-0",children:[e.jsx(xe,{className:"h-3.5 w-3.5 mr-1"}),"Generovat"]})]})]}),e.jsxs(c,{variant:"outline",onClick:Le,disabled:X||!l,children:[X&&e.jsx(N,{className:"h-4 w-4 animate-spin mr-2"}),e.jsx(Qe,{className:"h-4 w-4 mr-2"}),"VytvoÅit úÄet s heslem"]})]})]})]})})]})]}),e.jsx(He,{open:ze,onOpenChange:k,title:"Smazat uživatelský úÄet",description:"Opravdu chcete smazat pÅihlaÅ¡ovacà úÄet této osoby? Záznam kontaktnà osoby zůstane zachován, ale osoba se nebude moci pÅihlásit.",confirmText:"Smazat úÄet",onConfirm:Ie}),e.jsx(qe,{open:we,onOpenChange:te,params:Ce,onSent:()=>f()})]})};export{Js 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.