1import{r as n,j as e}from"./vendor-react-T2eZ94sy.js";import{u as q,d as M,s as c,X as Q,L as V}from"./index-DxLbpY9G.js";import{L as D}from"./loader-circle-DYizBw7N.js";import{U as K}from"./user-plus-JULkFmD5.js";import{S as E}from"./search-DtxnJL7J.js";import{L as O}from"./lock-open-DDRaEsYS.js";import{T as W}from"./trash-uu0WgElZ.js";function se(){const{language:a}=q(),{user:N}=M(),[w,R]=n.useState([]),[$,U]=n.useState(!0),[h,o]=n.useState(""),[A,v]=n.useState(!1),[S,m]=n.useState(""),[_,u]=n.useState(""),[L,p]=n.useState(""),[C,x]=n.useState([]),[T,j]=n.useState(!1);n.useEffect(()=>{f()},[]);const f=async()=>{try{U(!0);const{data:r,error:t}=await c.from("retreat_access").select("*").order("granted_at",{ascending:!1});if(t)throw t;const s=await Promise.all((r||[]).map(async d=>{const{data:l}=await c.from("profiles").select("id, username, handle").eq("id",d.user_id).single();return{...d,user:l||void 0}}));R(s)}catch(r){console.error("Error fetching retreat access list:",r),alert(a==="de"?"Fehler beim Laden der Zugriffe":"Error loading access list")}finally{U(!1)}},B=async r=>{if(r.length<2){x([]);return}j(!0);try{const{data:t,error:s}=await c.from("profiles").select("id, username, handle").or("username.ilike.%".concat(r,"%,handle.ilike.%").concat(r,"%")).limit(10);if(s)throw s;const d=new Set(w.map(i=>i.user_id)),l=(t||[]).filter(i=>!d.has(i.id));x(l||[])}catch(t){console.error("Error searching users:",t)}finally{j(!1)}},F=r=>{o(r),B(r)},P=async r=>{if(N)try{j(!1);const{error:t}=await c.from("retreat_access").insert({user_id:r,granted_by:N.id,notes:L.trim()||null});if(t)throw t;await f(),m(""),u(""),p(""),o(""),x([]),v(!1),alert(a==="de"?"Zugriff hinzugefügt":"Access granted")}catch(t){console.error("Error adding retreat access:",t),alert(a==="de"?"Fehler beim Hinzufügen: ".concat(t.message):"Error adding access: ".concat(t.message))}},H=async(r,t)=>{const{error:s}=await c.from("retreat_access").update({all_tabs_unlocked:!t}).eq("id",r);s||await f()},G=async(r,t)=>{if(confirm(a==="de"?"Zugriff für ".concat(t," wirklich entfernen?"):"Really remove access for ".concat(t,"?")))try{const{error:s}=await c.from("retreat_access").delete().eq("id",r);if(s)throw s;await f(),alert(a==="de"?"Zugriff entfernt":"Access removed")}catch(s){console.error("Error removing retreat access:",s),alert(a==="de"?"Fehler beim Entfernen":"Error removing access")}},z=r=>/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(r.trim()),b=_.trim(),k=S||(z(b)?b:""),y=w.filter(r=>{var d,l;if(!h)return!0;const t=h.toLowerCase(),s=r.user;return((d=s==null?void 0:s.username)==null?void 0:d.toLowerCase().includes(t))||((l=s==null?void 0:s.handle)==null?void 0:l.toLowerCase().includes(t))});return $?e.jsxs("div",{className:"min-h-screen bg-gray-50 dark:bg-surface-elevated",children:[e.jsx("div",{className:"h-20"}),e.jsx("div",{className:"container mx-auto px-4 py-8",children:e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(D,{className:"w-8 h-8 text-bronze-500 animate-spin"})})})]}):e.jsxs("div",{className:"min-h-screen bg-gray-50 dark:bg-surface-elevated",children:[e.jsx("div",{className:"h-20"}),e.jsx("div",{className:"container mx-auto px-4 py-8",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:a==="de"?"Retreat-Zugriff verwalten":"Manage Retreat Access"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",children:a==="de"?"Verwalte, welche Benutzer Zugriff auf die Trading Retreat Seite haben":"Manage which users have access to the Trading Retreat page"})]}),e.jsxs("button",{onClick:()=>v(!A),className:"flex items-center gap-2 px-4 py-2 bg-surface-elevated hover:bg-surface-elevated text-white rounded-lg transition-colors",children:[e.jsx(K,{className:"w-4 h-4"}),a==="de"?"Benutzer hinzufügen":"Add User"]})]}),A&&e.jsxs("div",{className:"bg-white dark:bg-surface-elevated rounded-xl border border-gray-200 dark:border-gray-700 p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:a==="de"?"Neuen Zugriff hinzufügen":"Add New Access"}),e.jsx("button",{onClick:()=>{v(!1),o(""),x([]),m(""),u(""),p("")},className:"p-1 hover:bg-gray-100 dark:hover:bg-gray-700 rounded",children:e.jsx(Q,{className:"w-5 h-5 text-gray-600 dark:text-gray-400"})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1 text-gray-700 dark:text-gray-300",children:a==="de"?"Benutzer suchen (Username/Handle)":"Search user (username/h
1andle)"}),e.jsxs("div",{className:"relative",children:[e.jsx(E,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-gray-400"}),e.jsx("input",{type:"text",value:h,onChange:r=>F(r.target.value),placeholder:a==="de"?"Benutzername oder Handle...":"Username or handle...",className:"w-full pl-10 pr-3 py-2 rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-surface-elevated text-gray-900 dark:text-white"})]}),T&&e.jsxs("div",{className:"mt-2 flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400",children:[e.jsx(D,{className:"w-4 h-4 animate-spin"}),a==="de"?"Suche...":"Searching..."]}),C.length>0&&e.jsx("div",{className:"mt-2 border border-gray-200 dark:border-gray-700 rounded-lg bg-white dark:bg-surface-elevated max-h-60 overflow-y-auto",children:C.map(r=>e.jsxs("button",{onClick:()=>{m(r.id),u(""),o(r.username||r.handle||r.id),x([])},className:"w-full text-left px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors ".concat(S===r.id?"bg-surface-elevated dark:bg-surface-elevated":""),children:[e.jsx("div",{className:"font-medium text-gray-900 dark:text-white",children:r.username||r.handle||r.id}),(r.username||r.handle)&&r.username!==(r.username||r.handle)&&e.jsx("div",{className:"text-sm text-gray-600 dark:text-gray-400",children:r.username||r.handle}),e.jsxs("div",{className:"text-xs text-gray-500 dark:text-gray-500",children:["UID: ",r.id]})]},r.id))})]}),e.jsxs("div",{className:"relative py-2",children:[e.jsx("div",{className:"absolute inset-0 flex items-center","aria-hidden":"true",children:e.jsx("div",{className:"w-full border-t border-gray-200 dark:border-gray-700"})}),e.jsx("div",{className:"relative flex justify-center",children:e.jsx("span",{className:"px-2 text-xs text-gray-500 dark:text-gray-400 bg-white dark:bg-surface-elevated",children:a==="de"?"oder":"or"})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1 text-gray-700 dark:text-gray-300",children:a==="de"?"UID hinzufügen (UUID)":"Add by UID (UUID)"}),e.jsx("input",{type:"text",value:_,onChange:r=>{u(r.target.value),m("")},placeholder:"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",className:"w-full px-3 py-2 rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-surface-elevated text-gray-900 dark:text-white"}),b.length>0&&!z(b)&&e.jsx("p",{className:"text-xs text-red-500 mt-1",children:a==="de"?"Bitte eine gültige UUID eingeben.":"Please enter a valid UUID."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1 text-gray-700 dark:text-gray-300",children:a==="de"?"Notizen (optional)":"Notes (optional)"}),e.jsx("textarea",{value:L,onChange:r=>p(r.target.value),className:"w-full px-3 py-2 rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-surface-elevated text-gray-900 dark:text-white",rows:2,placeholder:a==="de"?"Z.B. Name der Person, Grund für Zugriff...":"e.g. Person name, reason for access..."})]}),e.jsx("button",{onClick:()=>k&&P(k),disabled:!k,className:"w-full px-4 py-2 bg-green-600 hover:bg-green-700 disabled:opacity-50 disabled:cursor-not-allowed text-white rounded-lg transition-colors",children:a==="de"?"Zugriff hinzufügen":"Add Access"})]})]}),e.jsxs("div",{className:"bg-white dark:bg-surface-elevated rounded-xl border border-gray-200 dark:border-gray-700 overflow-hidden",children:[e.jsx("div",{className:"p-4 border-b border-gray-200 dark:border-gray-700",children:e.jsxs("div",{className:"relative",children:[e.jsx(E,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-gray-400"}),e.jsx("input",{type:"text",value:h,onChange:r=>o(r.target.value),placeholder:a==="de"?"Nach Benutzern suchen...":"Search users...",className:"w-full pl-10 pr-3 py-2 rounded-lg border border-gray-300 dark:border-gray-700 bg-white dark:bg-surface-elevated text-gray-900 dark:text-white"})]})}),e.jsx("div",{className:"divide-y divide-gray-200 dark:divide-gray-700",children:y.length===0?e.jsx("div",{className:"p-8 text-center text-gray-500 dark:text-gray-400",children:a==="de"?"Keine Zugriffe vorhanden":"No access entries found"}):y.map(r=>{var t,s,d,l,i,I;return e.jsxs("div",{className:"p-4 hover:bg-gray-50 dark:hover:bg-[#1A1714]/50 transition-colors flex items-center justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-medium text-gray-900 dark:text-white",children:((t=r.user)==null?void 0:t.username)||((s=r.user)==null?void 0:s.handle)||r.user_id}),(((d=r.user)==null?void 0:d.username)||((l=r.user)==null?void 0:l.handle))&&e.jsx("div",{className:"text-sm text-gray-600 dark:text-gray-400",children:((i=r.user)==null?void 0:i.username)||((I=r.user)==null?void 0:I.handle)}),e.jsxs("div",{className:"text-xs text-gray-500 dark:text-gray-500 mt-1",children:["UID: ",r.user_id]}),r.notes&&e.jsx("div",{className:"text-sm text-gray-500 dark:text-gray-500 mt-1",children:r.notes}),e.jsxs("div",{className:"text-xs text-gray-500 dark:text-gray-500 mt-1",children:[a==="de"?"Hinzugefügt am":"Added on",":"," ",new Date(r.granted_at).toLocaleDateString()]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>{var g;return H(r.id,(g=r.all_tabs_unlocked)!=null?g:!1)},className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-semibold transition-colors ".concat(r.all_tabs_unlocked?"bg-green-600 hover:bg-green-700 text-white":"bg-gray-100 dark:bg-white/5 hover:bg-gray-200 dark:hover:bg-white/10 text-gray-600 dark:text-gray-400"),title:a==="de"?"Alle Tabs freischalten":"Unlock all tabs",children:r.all_tabs_unlocked?e.jsxs(e.Fragment,{children:[e.jsx(O,{className:"w-3.5 h-3.5"})," ",a==="de"?"Alle offen":"All open"]}):e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"w-3.5 h-3.5"}
1)," ",a==="de"?"Gesperrt":"Locked"]})}),e.jsx("button",{onClick:()=>{var g,Z;return G(r.id,((g=r.user)==null?void 0:g.username)||((Z=r.user)==null?void 0:Z.handle)||r.user_id)},className:"p-2 hover:bg-red-100 dark:hover:bg-red-900/30 rounded text-red-500 transition-colors",title:a==="de"?"Zugriff entfernen":"Remove access",children:e.jsx(W,{className:"w-4 h-4"})})]})]},r.id)})}),y.length>0&&e.jsxs("div",{className:"p-4 border-t border-gray-200 dark:border-gray-700 text-sm text-gray-600 dark:text-gray-400",children:[a==="de"?"Gesamt:":"Total:"," ",y.length," ",a==="de"?"Zugriffe":"access entries"]})]})]})})]})}export{se 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.