1import{a8 as D,u as E,r as l,j as e,B as m,L as F,J as H,h as L,i as P,k as T,l as k,m as A,s as f,ae as h,ad as V}from"./index-DLd_kDlx.js";import{S as g}from"./SuperAdminLayout-BsUvQU2j.js";import{T as I}from"./TechLeadPicker-DENSUSgV.js";import{L as M}from"./label-D4-ENrYn.js";import{S as $,a as J,b as Y,c as K,d as Q}from"./select-RSrodAEw.js";import{u as W}from"./useTechLeads-Cmw-XrPs.js";import{L as B}from"./loader-circle-D2miE2xB.js";import{A as X}from"./arrow-left-BXtn7MCa.js";import{U as Z}from"./user-round-check-syjRkPJS.js";import{T as ee}from"./trash-2-0uuZSTFd.js";import{P as se}from"./plus-0WhrdjYO.js";import{G as ae}from"./git-branch-C-twpC7K.js";import{S as te}from"./save-DnzFMk1L.js";import"./NotificationIcon-C1wwYnH5.js";import"./popover-BMD5FOmU.js";import"./scroll-area-BXTuUF24.js";import"./index-Deh-4PO1.js";import"./index-BdQq_4o_.js";import"./NotificationItem-Dc2WXW-y.js";import"./formatDistanceToNow-57P64IbE.js";import"./en-US-9SRVm7yB.js";import"./differenceInCalendarMonths-BA0TPVs2.js";import"./endOfDay-DkR3ZXc8.js";import"./endOfMonth-CYn6pTOm.js";import"./message-square-CtxeCfRz.js";import"./trophy-DBX-jNOC.js";import"./triangle-alert-Chqk_WK7.js";import"./dropdown-menu-DSd1c3Vk.js";import"./index-lTaZyIGy.js";import"./chevron-right-CD1gvy-q.js";import"./crown-hzm_bRIt.js";import"./user-check-DxoAQXwU.js";import"./star-BH1OFEcs.js";import"./globe-C057RQ73.js";import"./timer-CZhDpZys.js";import"./briefcase-business-CphIeAJd.js";import"./key-round-B79BulHq.js";import"./search-DFH5eAlA.js";import"./command-BReSBG4f.js";import"./chevron-down-DpJJsCer.js";import"./chevron-up-M4SAwIjf.js";const re=i=>{var u;return((u=V.find(c=>c.id===i))==null?void 0:u.name)||i},$e=()=>{var S;const{podId:i}=D(),u=E(),{techLeads:c,isLoading:U}=W(),[n,z]=l.useState(null),[d,j]=l.useState(""),[p,x]=l.useState([]),[O,v]=l.useState(!0),[_,w]=l.useState(!1);l.useEffect(()=>{if(!i)return;(async()=>{v(!0);const[{data:t,error:s},{data:r,error:o}]=await Promise.all([f.from("pods").select("id, pod_name, pod_type, tech_lead_id, project_start_date, completion_deadline, github_repo_url, projects(title, description, career_paths)").eq("id",i).single(),f.from("multilateral_pod_tech_lead_invitations").select("invited_tech_lead_id, pathway").eq("pod_id",i).eq("status","accepted")]);s||o?h({title:"Unable to load pod setup",description:(s==null?void 0:s.message)||(o==null?void 0:o.message),variant:"destructive"}):(z(t),j((t==null?void 0:t.tech_lead_id)||""),x((r||[]).map(C=>({tech_lead_id:C.invited_tech_lead_id,pathway:C.pathway})))),v(!1)})()},[i]);const y=l.useMemo(()=>{var a;return Array.isArray((a=n==null?void 0:n.projects)==null?void 0:a.career_paths)?n.projects.career_paths:[]},[n]),q=p.map(a=>a.tech_lead_id).filter(Boolean),G=()=>x(a=>[...a,{tech_lead_id:"",pathway:y[0]||""}]),b=(a,t)=>x(s=>s.map((r,o)=>o===a?{...r,...t}:r)),R=a=>x(t=>t.filter((s,r)=>r!==a)),N=async a=>{if(!i)return;const t=p.filter(r=>r.tech_lead_id&&r.pathway);if(t.length!==p.length){h({title:"Complete all member assignments",description:"Select both a pathway and tech lead for every row.",variant:"destructive"});return}if(new Set(t.map(r=>r.tech_lead_id)).size!==t.length){h({title:"Duplicate tech lead",description:"Each tech lead can only be assigned once.",variant:"destructive"});return}w(!0);const{error:s}=await f.rpc("manage_super_admin_pod_assignments",{p_pod_id:i,p_owner_tech_lead_id:d||null,p_member_assignments:t});if(w(!1),s){h({title:"Assignment update failed",description:s.message,variant:"destructive"});return}h({title:d?"Tech leads assigned":"Pod saved without an owner",description:d?"The owner and collaborating members now have access.":"You can return to assign an owner later."}),a&&u("/super-admin/projects")};return O||U?e.jsx(g,{children:e.jsx("div",{className:"flex justify-center py-24",children:e.jsx(B,{className:"h-6 w-6 animate-spin"})})}):n?e.jsx(g,{children:e.jsxs("div",{className:"mx-auto max-w-4xl space-y-6",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(m,{variant:"ghost",size:"icon",asChild:!0,children:e.jsx(F,{to:"/super-admin/projects",children:e.jsx(X,{className:"h-5 w-5"})})}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Assign Tech Leads"}),e.jsx(H,{variant:d?"default":"secondary",children:d?"Owner selected":"Owner unassigned"})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[n.pod_name," · ",(S=n.projects)==null?void 0:S.title]})]})]}),e.jsxs(L,{children:[e.jsxs(P,{children:[e.jsxs(T,{className:"flex items-center gap-2",children:[e.jsx(Z,{className:"h-5 w-5"})," Pod owner"]}),e.jsx(k,{children:"The owner has full pod controls and is the only tech lead who can create or link the GitHub repository."})]}),e.jsxs(A,{className:"space-y-3",children:[e.jsx(I,{techLeads:c,value:d,onChange:j,excludeUserIds:p.map(a=>{var t;return((t=c.find(s=>s.id===a.tech_lead_id))==null?void 0:t.user_id)||""}),placeholder:"Select pod owner"}),d&&e.jsx(m,{variant:"outline",size:"sm",onClick:()=>j(""),children:"Leave pod unassigned"})]})]}),n.pod_type==="multilateral"&&e.jsxs(L,{children:[e.jsxs(P,{children:[e.jsx(T,{children:"Pathway tech-lead members"}),e.jsx(k,{children:"Members receive immediate collaboration access but cannot manage the pod repository."})]}),e.jsxs(A,{className:"space-y-4",children:[p.map((a,t)=>e.jsxs("div",{className:"grid gap-3 rounded-lg border p-4 md:grid-cols-[1fr_2fr_auto]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(M,{children:"Pathway"}),e.jsxs($,{value:a.pathway,onValueChange:s=>b(t,{pathway:s}),children:[e.jsx(J,{children:e.jsx(Y,{placeholder:"Select pathway"})}),e.jsx(K,{children:y.map(s=>e.jsx(Q,{value:s,children:re(s)},s))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(M,{children:"Tech lead"}),e.jsx(I,{techLeads:c,value:a.tech_lead_id,pathwayFilter:a.pathway||void 0,onChange:s=>b(t,{tech_lead_id:s}),excludeUserIds:[d,...q.filter(s=>s!==a.tech_lead_id)].map(s=>{var r;return((r=c.find(o=>o.id===s))==null?void 0:r.user_id)||""})})]}),e.jsx(m,{variant:"ghost",size:"icon",className:"self-end text-destructive",onClick:()=>R(t),children:e.jsx(ee,{className:"h-4 w-4"})})]},`${t}-${a.tech_lead_id}`)),e.jsxs(m,{variant:"outline",onClick:G,children:[e.jsx(se,{className:"mr-2 h-4 w-4"})," Add pathway tech lead"]})]})]}),e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm text-amber-900",children:[e.jsx(ae,{className:"mt-0.5 h-4 w-4"}),e.jsx("span",{children:d?"After saving, the selected owner can open the sprint board and link the pod repository.":"This pod can remain unassigned. Repository setup will stay unavailable until an owner is selected."})]}),e.jsxs("div",{className:"flex flex-wrap justify-end gap-3",children:[e.jsxs(m,{variant:"outline",disabled:_,onClick:()=>N(!1),children:[e.jsx(te,{className:"mr-2 h-4 w-4"})," Save assignments"]}),e.jsxs(m,{disabled:_,onClick:()=>N(!0),children:[_&&e.jsx(B,{className:"mr-2 h-4 w-4 animate-spin"})," Finish"]}
1)]})]})}):e.jsx(g,{children:e.jsx("p",{children:"Pod not found."})})};export{$e 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.