1import{b as Y,c as L,k as J,r as t,t as K,j as e,B as a,d as f,E as U}from"./index-_aijvlUq.js";import{P as _}from"./PageHeader-DCofr6qo.js";import{I as W}from"./Input-ysTyZFq5.js";import{B as b}from"./Badge-DJIi163x.js";import{C as X}from"./ConfirmDialog-CODvETNM.js";import{a as Z}from"./Skeleton-B3Wj6cNd.js";import{p as l}from"./partnerships-B_F3kdIQ.js";import{U as $}from"./UpgradePrompt-CWmCKX75.js";import{E as F}from"./EmptyState-CPGKooqj.js";const ee={active:{color:"green",label:"Active"},pending:{color:"yellow",label:"Pending"},declined:{color:"red",label:"Declined"},cancelled:{color:"gray",label:"Cancelled"}},se=new Set(["complete"]);function me(){const x=Y(s=>s.user?.orgId),C=L(s=>s.showSuccess),j=J(s=>s.planTier),y=L(s=>s.showError),[o,H]=t.useState([]),[Q,P]=t.useState(!0),[N,v]=t.useState(!1),[d,p]=t.useState(""),[w,m]=t.useState([]),[A,k]=t.useState(!1),[i,S]=t.useState(null),[R,q]=t.useState(""),[V,E]=t.useState(!1),[n,c]=t.useState(null),I=t.useRef(null),u=t.useCallback(async()=>{if(!x){P(!1);return}try{const s=await l.list();H(s)}catch{y(K("partnerships"))}finally{P(!1)}},[]);t.useEffect(()=>{u()},[u]),t.useEffect(()=>{if(d.length<2){m([]);return}const s=new AbortController,r=setTimeout(async()=>{k(!0);try{const h=await l.searchOrgs(d,{signal:s.signal});m(h)}catch(h){h.name!=="AbortError"&&!s.signal.aborted&&m([])}finally{s.signal.aborted||k(!1)}},300);return()=>{clearTimeout(r),s.abort()}},[d]);const z=()=>{v(!0),S(null),q(""),p(""),m([]),setTimeout(()=>I.current?.scrollIntoView({behavior:"smooth",block:"start"}),50)},G=async()=>{if(i){E(!0);try{await l.create({partnerOrgId:i.id,notes:R||void 0}),C("Partnership request sent"),v(!1),u()}catch(s){y(s.response?.data?.error?.message||U)}finally{E(!1)}}},M=async()=>{if(!n)return;const{type:s,id:r}=n;try{s==="accept"?await l.accept(r):s==="decline"?await l.decline(r):s==="cancel"&&await l.cancel(r),C(s==="accept"?"Partnership accepted":s==="decline"?"Request declined":"Partnership cancelled"),u()}catch(h){y(h.response?.data?.error?.message||U)}finally{c(null)}},O=o.filter(s=>s.status==="active"),T=o.filter(s=>s.status==="pending"&&s.partnerOrgId===x),D=o.filter(s=>s.status==="pending"&&s.requestingOrgId===x),B=o.filter(s=>s.status==="declined"||s.status==="cancelled"),g=s=>(s.requestingOrgId===x?s.partnerOrg:s.requestingOrg)?.name||"Unknown";return Q?e.jsxs("div",{children:[e.jsx(_,{title:"Partnerships",breadcrumbs:[{label:"Home",to:"/"},{label:"Settings"},{label:"Partnerships"}]}),e.jsx("div",{className:"space-y-2",children:Array.from({length:3}).map((s,r)=>e.jsx(Z,{lines:2},r))})]}):e.jsxs("div",{className:"px-4 md:px-0",children:[e.jsx(_,{title:"Partnerships",subtitle:"Manage cooperative partnerships with other organizations",breadcrumbs:[{label:"Home",to:"/"},{label:"Settings"},{label:"Partnerships"}],actions:!N&&e.jsx(a,{variant:"primary",size:"md",onClick:z,children:"New partnership"})}),j&&!se.has(j)&&e.jsx($,{featureName:"Partnerships",requiredTier:"complete",currentTier:j,description:"Partner with other organizations to share music libraries and coordinate performances.",className:"mb-4"}),N&&e.jsxs("div",{ref:I,className:"bg-white rounded-xl border border-gray-200 p-6 mb-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-4",children:"New Partnership"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Search organization"}),i?e.jsxs("div",{className:"flex items-center gap-2 p-2 bg-gray-50 rounded-lg border",children:[e.jsx("span",{className:"text-sm font-medium",children:i.name}),i.shortName&&e.jsxs("span",{className:"text-xs text-gray-500",children:["(",i.shortName,")"]}),e.jsx(a,{variant:"ghost",size:"sm",className:"ml-auto",onClick:()=>{S(null),p("")},children:"Change"})]}):e.jsxs(e.Fragment,{children:[e.jsx(W,{value:d,onChange:s=>p(s.target.value),placeholder:"Type at least 2 characters..."}),A&&e.jsx("p",{className:"text-xs text-gray-400 mt-1",children:"Searching..."}),w.length>0&&e.jsx("ul",{className:"mt-1 border rounded-lg divide-y max-h-48 overflow-y-auto",children:w.map(s=>e.jsx("li",{children:e.jsxs(a,{variant:"ghost",size:"sm",className:"w-full text-left justify-start rounded-none",onClick:()=>{S(s),m([]),p("")},children:[s.name,s.shortName&&e.jsxs("span",{className:"text-gray-400 ml-1",children:["(",s.shortName,")"]})]})},s.id))}),d.length>=2&&!A&&w.length===0&&e.jsx(F,{size:"compact",title:"No organizations foun
1d."})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Notes (optional)"}),e.jsx("textarea",{className:"w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-brand-500 focus:border-transparent",rows:3,maxLength:500,value:R,onChange:s=>q(s.target.value),placeholder:"Introduce your organization or explain the partnership request..."})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx(a,{variant:"primary",onClick:G,disabled:!i,isLoading:V,children:"Send request"}),e.jsx(a,{variant:"secondary",onClick:()=>v(!1),children:"Cancel"})]})]})]}),O.length>0&&e.jsxs("section",{className:"mb-6",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-3",children:"Active Partnerships"}),e.jsx("div",{className:"space-y-2",children:O.map(s=>e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 p-4 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:g(s)}),e.jsxs("p",{className:"text-xs text-gray-500",children:["Partners since ",f(s.respondedAt||s.createdAt)]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(b,{color:"green",children:"Active"}),e.jsx(a,{variant:"ghost",size:"sm",onClick:()=>c({type:"cancel",id:s.id}),children:"Cancel"})]})]},s.id))})]}),T.length>0&&e.jsxs("section",{className:"mb-6",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-3",children:"Incoming Requests"}),e.jsx("div",{className:"space-y-2",children:T.map(s=>e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:g(s)}),e.jsxs("p",{className:"text-xs text-gray-500",children:["Received ",f(s.requestedAt)]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(b,{color:"yellow",children:"Pending"}),e.jsx(a,{variant:"primary",size:"sm",onClick:()=>c({type:"accept",id:s.id}),children:"Accept"}),e.jsx(a,{variant:"ghost",size:"sm",onClick:()=>c({type:"decline",id:s.id}),children:"Decline"})]})]}),s.notes&&e.jsx("p",{className:"mt-2 text-sm text-gray-600 bg-gray-50 rounded-lg p-2",children:s.notes})]},s.id))})]}),D.length>0&&e.jsxs("section",{className:"mb-6",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-3",children:"Outgoing Requests"}),e.jsx("div",{className:"space-y-2",children:D.map(s=>e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 p-4 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:g(s)}),e.jsxs("p",{className:"text-xs text-gray-500",children:["Sent ",f(s.requestedAt)]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(b,{color:"yellow",children:"Pending"}),e.jsx(a,{variant:"ghost",size:"sm",onClick:()=>c({type:"cancel",id:s.id}),children:"Cancel request"})]})]},s.id))})]}),B.length>0&&e.jsxs("section",{className:"mb-6",children:[e.jsx("h3",{className:"text-sm font-semibold text-gray-500 uppercase tracking-wide mb-3",children:"Past"}),e.jsx("div",{className:"space-y-2",children:B.map(s=>{const r=ee[s.status];return e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 p-4 flex items-center justify-between opacity-60",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:g(s)}),e.jsx("p",{className:"text-xs text-gray-500",children:f(s.cancelledAt||s.respondedAt||s.createdAt)})]}),e.jsx(b,{color:r.color,children:r.label})]},s.id)})})]}),o.length===0&&!N&&e.jsx(F,{card:!0,title:"No partnerships yet.",action:e.jsx(a,{variant:"primary",size:"sm",onClick:z,children:"Create first partnership"})}),e.jsx(X,{isOpen:!!n,onClose:()=>c(null),onConfirm:M,title:n?.type==="accept"?"Accept Partnership":n?.type==="decline"?"Decline Request":"Cancel Partnership",message:n?.type==="accept"?"Accept this partnership request? You will be able to share music libraries.":n?.type==="decline"?"Decline this partnership request?":"Cancel this partnership? Cross-org music access will be revoked immediately.",confirmLabel:n?.type==="accept"?"Accept":n?.type==="decline"?"Decline":"Cancel Partnership"})]})}
1export{me as PartnershipsPage};
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.