1import{c as Q,k as Z,l as ee,m as se,n as ae,r,j as e,B as $,u as te,a as re,o as ne,d as le,q as ie,t as oe,v as ce,w as de,F as me,x as Y,y as xe,L as V}from"./index-BkxA9Opm.js";import{u as ue,U as H,T as X,I as G,a as pe,F as he,A as be}from"./AddCoachModal-Dt0M57LY.js";import{X as ge}from"./x-9IBNpUhR.js";import{M as ye}from"./mail-B3rv7FGX.js";import{L as J}from"./loader-circle-BT3B1TAE.js";import{S as fe}from"./search-DC86C07g.js";import{C as je}from"./circle-check-r26pZsmF.js";import{u as Ne}from"./useFacility-BGkOVEXo.js";import"./DataGrid-DlTJc5zy.js";import"./styling-BAK3lO6f.js";import"./pitcherIdentity-dbjBLCcs.js";import"./ball-type-OspwjJfw.js";import"./spin-model-FpeNnCaR.js";import"./video-BCBXVJQe.js";import"./charts-vendor-B1U9qLe-.js";import"./user-round-WWFkBPM-.js";import"./arrow-left-Dr1Ja2jI.js";import"./users-BqPJOdSH.js";import"./check-btxvX4s3.js";import"./shield-BuqO-8nI.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 ve=Q("RefreshCcw",[["path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"14sxne"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16",key:"1hlbsb"}],["path",{d:"M16 16h5v5",key:"ccwih5"}]]);/** 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 we=Q("Star",[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]]),Ce=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,ke=s=>(s||"").trim().toLowerCase(),Se=s=>{if(((s==null?void 0:s.facilityPlan)||"").toLowerCase().trim()==="team")return"free";const l=typeof(s==null?void 0:s.playerLicenseType)=="string"?s.playerLicenseType.trim():"";return l?l.toLowerCase():"pro"},Pe=s=>{var n,m;const a=Z.currentUser,l=(a==null?void 0:a.uid)||"";if((n=a==null?void 0:a.displayName)!=null&&n.trim())return a.displayName.trim();if(Array.isArray(s==null?void 0:s.coaches)&&l){const x=s.coaches.find(i=>((i==null?void 0:i.coachId)||(i==null?void 0:i.id))===l);if((m=x==null?void 0:x.name)!=null&&m.trim())return x.name.trim()}return a!=null&&a.email?a.email.split("@")[0]:(s==null?void 0:s.facilityName)||"PitchLab Coach"},Le=async({email:s,facility:a,playerDisplayName:l="",playerUserId:n=""})=>{var o,y;const m=((o=Z.currentUser)==null?void 0:o.uid)||"";if(!m)throw new Error("You must be signed in to send invites.");const x=(a==null?void 0:a.id)||"";if(!x)throw new Error("A facility is required to send invites.");const i=ke(s);if(!Ce.test(i))throw new Error("Enter a valid player email address.");const g=((y=a==null?void 0:a.facilityName)==null?void 0:y.trim())||"Your facility",f=Se(a),t=Pe(a),j=l.trim()||i,h=(n==null?void 0:n.trim())||void 0;await ee();const u=se(ae,"createConnectionRequest"),C={facilityId:x,facilityName:g,playerEmail:i,playerName:j,requestedBy:m,requestedByName:t,licenseType:f};h&&(C.playerId=h);const c=await u(C),b=c==null?void 0:c.data;if(!b||typeof b.requestId!="string")throw new Error("Unexpected response from invite service.");return b},Ae=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,K=s=>s?s.split("@")[0].split(/[._-]/).filter(Boolean).map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join(" "):"",Fe=({facility:s,onClose:a,onSuccess:l})=>{var d,w;const[n,m]=r.useState(""),[x,i]=r.useState(!1),[g,f]=r.useState(!1),[t,j]=r.useState(!1),[h,u]=r.useState(""),[C,c]=r.useState(""),[b,o]=r.useState(null),[y,k]=r.useState(!1),{searchForUser:A,isSearching:F}=ue(),E=(s==null?void 0:s.facilityName)||"your organization",B=(s==null?void 0:s.facilityPlan)||"",M=(s==null?void 0:s.usedPlayerLicenses)||0,D=((w=(d=s==null?void 0:s.paymentProcessor)==null?void 0:d.stripe)==null?void 0:w.minimumPlayerLicenseCount)??0,q=((s==null?void 0:s.playerLicenseType)||"Free").trim(),R=q.charAt(0).toUpperCase()+q.slice(1),N=B!=="team"&&D>0&&M>=D;r.useEffect(()=>{const p=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=p}},[]),r.useEffect(()=>{k(!N)},[N]);const S=N&&!y,T=r.useMemo(()=>h||K(n),[h,n]),P=()=>{f(!1),j(!1),u(""),c(""),o(null)},I=()=>{P(),m(""),a()},O=async()=>{const p=n.trim().toLowerCase();if(!Ae.test(p)){o({type:"error",message:"Enter a valid player email address."});return}m(p),o(null),f(!1),j(!1),u(""),c("");try{const v=await A({email:p,facilityId:(s==null?void 0:s.id)||null,type:"player"});
11f(!0),j(!0),u(v.displayName),c(v.userId),o({type:"info",message:`We'll email them instructions to join ${E}.`})}catch(v){const L=v;(L==null?void 0:L.code)===pe.USER_NOT_FOUND?(f(!0),j(!1),u(K(p)),c(""),o({type:"info",message:`We'll email them instructions to join ${E}.`})):(f(!1),o({type:"error",message:(L==null?void 0:L.message)||"Unable to search for that email right now. Please try again."}))}},z=async()=>{i(!0),o(null);try{await Le({email:n,facility:s,playerDisplayName:T,playerUserId:C}),$.success(`Connection request sent to ${T||n}`),P(),m(""),a(),l==null||l()}catch(p){const v=p;o({type:"error",message:(v==null?void 0:v.message)||"Unable to send the connection request. Please try again shortly."}),console.error(p)}finally{i(!1)}},W=()=>{if(!g){o({type:"error",message:"Search for a player email before sending a request."});return}z()},_=t?"border-green-200 bg-green-50 text-green-800":"border-blue-200 bg-blue-50 text-blue-800";return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-gray-900/70 p-4",children:e.jsxs("div",{className:"relative w-full max-w-3xl bg-white rounded-3xl shadow-2xl border border-gray-100 max-h-[calc(100vh-2rem)] overflow-hidden flex flex-col",role:"dialog","aria-modal":"true",children:[e.jsx("button",{type:"button",onClick:I,className:"absolute top-4 right-4 inline-flex items-center justify-center rounded-full p-2 text-gray-500 hover:text-gray-900 hover:bg-gray-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-amber-500","aria-label":"Close add player modal",children:e.jsx(ge,{className:"h-5 w-5"})}),e.jsx("div",{className:"px-6 py-5 border-b border-gray-100 bg-gradient-to-r from-white to-gray-50",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-3 rounded-2xl bg-blue-50 text-blue-600",children:e.jsx(H,{className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs uppercase tracking-wider text-gray-500",children:"Player onboarding"}),e.jsx("h2",{className:"text-2xl font-semibold text-gray-900",children:"Connect a new player"}),e.jsx("p",{className:"text-sm text-gray-500",children:E})]})]})}),N?e.jsxs("div",{className:"px-6 py-4 border-b border-amber-100 bg-amber-50 text-amber-900 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 font-semibold",children:[e.jsx(X,{className:"w-5 h-5"}),e.jsx("span",{children:"Billing change may be required"})]}),e.jsx("p",{className:"text-sm",children:"This facility already uses every included seat. Adding a new player will require adding an additional prorated player license for the remainder of this billing period."}),y?e.jsx("div",{}):e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsx("button",{type:"button",onClick:()=>k(!0),className:"inline-flex items-center gap-2 rounded-lg bg-amber-500 px-4 py-2 text-sm font-semibold text-white hover:bg-amber-600",children:"Accept"}),e.jsx("button",{type:"button",onClick:I,className:"inline-flex items-center gap-2 rounded-lg border border-transparent px-4 py-2 text-sm font-medium text-amber-900 hover:bg-amber-100",children:"Close"})]})]}):null,e.jsxs("div",{className:`flex-1 overflow-y-auto px-6 py-6 space-y-6 ${S?"pointer-events-none opacity-60":""}`,children:[e.jsxs("section",{className:"space-y-3",children:[e.jsx("label",{className:"text-sm font-medium text-gray-700",htmlFor:"player-email-input",children:"Player email"}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row",children:[e.jsxs("div",{className:"flex-1 flex items-center gap-3 rounded-2xl border border-gray-200 bg-white px-4 py-3 shadow-sm",children:[e.jsx(ye,{className:"w-5 h-5 text-gray-400"}),e.jsx("input",{id:"player-email-input",type:"email",value:n,onChange:p=>{m(p.target.value),g&&P()},className:"flex-1 text-sm text-gray-900 placeholder:text-gray-400 focus:outline-none",placeholder:"Enter player email",autoComplete:"off",autoCorrect:"off",spellCheck:!1,disabled:S||F})]}),e.jsx("button",{type:"button",onClick:()=>{O()},disabled:S||F||!n.trim(),className:"inline-flex items-center justify-center gap-2 rounded-2xl bg-blue-600 text-white font-semibold px-6 py-3 text-sm shadow-sm hover:bg-blue-700 disabled:opacity-60",children:F?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"w-4 h-4 animate-spin"}),"Searching"]}):e.jsxs(e.Fragment,{children:[e.jsx(fe,{className:"w-4 h-4"}),"Search"]})})]})]}),g?e.jsxs("div",{className:`rounded-2xl border px-5 py-4 ${_}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-base font-semibold text-gray-900",children:T||n}),e.jsx("p",{className:"text-sm text-gray-600",children:n})]}),e.jsx("div",{className:"text-xs font-semibold uppercase tracking-wide text-gray-500",children:t?"Existing player":"New invite"})]}),e.jsx("p",{className:"mt-3 text-sm text-gray-600",children:t?"This player already has a Pitchlab account. We'll notify them about your connection request.":"We'll send them an invite with steps to
11join your facility and activate their license."})]}):null,b?e.jsxs("div",{className:`flex items-start gap-3 rounded-2xl border px-4 py-3 text-sm ${b.type==="error"?"border-red-200 bg-red-50 text-red-700":b.type==="success"?"border-green-200 bg-green-50 text-green-800":"border-blue-200 bg-blue-50 text-blue-800"}`,children:[b.type==="error"?e.jsx(X,{className:"w-5 h-5"}):b.type==="success"?e.jsx(je,{className:"w-5 h-5"}):e.jsx(G,{className:"w-5 h-5"}),e.jsx("p",{className:"leading-5",children:b.message})]}):null,e.jsxs("div",{className:"rounded-3xl border border-gray-100 bg-gray-50 p-5 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-gray-600",children:[e.jsx(G,{className:"w-5 h-5"}),e.jsx("p",{className:"text-sm font-semibold uppercase tracking-wide",children:"How it works"})]}),e.jsx("p",{className:"text-sm text-gray-600",children:"Input the playerâs email to send an invitation. Once the player accepts, their sessions automatically sync to your facility and consume an available license."}),e.jsxs("ul",{className:"list-disc list-inside text-sm text-gray-600 space-y-1",children:[e.jsx("li",{children:"Players receive onboarding instructions via email."}),e.jsx("li",{children:"You can revoke their access or free their license at any time."}),e.jsx("li",{children:"Billing updates only occur when all included seats are already in use."})]})]}),e.jsxs("div",{className:"rounded-3xl border border-blue-100 bg-blue-50 p-5 space-y-4",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-blue-700",children:"Connection details"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-3 rounded-2xl bg-white/80 text-blue-600",children:e.jsx(ve,{className:"w-5 h-5"})}),e.jsxs("div",{className:"flex-1 flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-blue-600",children:"Connection type"}),e.jsx("p",{className:"text-sm font-semibold text-blue-900",children:"Data sharing"})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-3 rounded-2xl bg-white/80 text-amber-600",children:e.jsx(we,{className:"w-5 h-5"})}),e.jsxs("div",{className:"flex-1 flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-blue-600",children:"License type"}),e.jsx("p",{className:"text-sm font-semibold text-blue-900",children:R})]})]})]}),N?e.jsxs("p",{className:"text-sm text-blue-800",children:["Adding a new player will increase your billed seats from ",M," to ",M+1,"."]}):e.jsx("p",{className:"text-sm text-blue-800",children:"This player will consume one of your included seats."}),e.jsxs("p",{className:"text-sm text-blue-800",children:["This connection will grant the user a"," ",R," license. You can manage licenses in the Player Management section."]})]}),g?e.jsx("button",{type:"button",onClick:()=>{m(""),P()},className:"inline-flex items-center gap-2 text-sm font-medium text-blue-700 hover:text-blue-800",children:"Start a different search"}):null]}),e.jsxs("div",{className:"border-t border-gray-100 bg-gray-50 px-6 py-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("button",{type:"button",onClick:I,className:"px-4 py-2 text-sm font-medium text-gray-700 rounded-lg border border-gray-200 bg-white hover:bg-gray-50",children:"Close"}),e.jsx("button",{type:"button",onClick:W,disabled:S||!g||x,className:"inline-flex items-center gap-2 px-5 py-2.5 text-sm font-semibold text-white rounded-lg bg-blue-600 hover:bg-blue-700 disabled:opacity-60",children:x?e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"w-4 h-4 animate-spin"}),"Sending"]}):e.jsxs(e.Fragment,{children:[e.jsx(H,{className:"w-4 h-4"}),"Send connection request"]})})]})]})})},U="[email protected]",Ee=!1,Me=({mode:s="dashboard"}={})=>{const a=te(),l=re(),{facilityId:n}=ne(),[m,x]=r.useState(!1),[i,g]=r.useState(!1),{isDeveloper:f}=le(),{facility:t,isLoading:j,error:h,refresh:u,management:C}=Ne(n||null,{includeManagementData:s==="manager"}),{userId:c,subscriptions:b,refresh:o}=ie(),y=r.useCallback(()=>{a("/dashboard")},[a]),k=(l==null?void 0:l.state)||null,A=s==="manager"&&(k==null?void 0:k.from)==="facility-dashboard",F=r.useCallback(()=>
11{if(A&&n){a(`/facilities/${n}`);return}a("/dashboard")},[A,n,a]),E=s==="manager"&&A?"Back to Facility":"Back to Dashboard",B=s==="manager",M=B?"min-h-[calc(100vh-60px)] bg-gray-50 py-8 px-4 sm:px-6 lg:px-10":"min-h-[calc(100vh-60px)] bg-gray-50 py-4 px-4 sm:px-6 lg:px-[50px]",D=B?"max-w-[1600px] mx-auto w-full":"w-full",q=r.useCallback(async()=>{var w;if(!t)return;const d=(w=window.prompt("Rename facility",t.facilityName||""))==null?void 0:w.trim();if(!(!d||d===t.facilityName))try{await oe(ce(de,me,t.id),{facilityName:d}),await u(),$.success("Facility renamed.")}catch(p){console.error("Failed to rename facility.",p),$.error("Unable to rename facility. Try again later.")}},[u,t]),[R,N]=r.useState(!1),S=t?Y(t,c,b):null,T=r.useCallback(async()=>{N(!0);try{const d=await o();if(d.userId!==c||!d.isResolved)throw new Error("We couldnât verify subscription management. Please retry from Account â Billing.");const w=Y(t||{},c,d.subscriptions);await xe(w,c)}catch(d){$.error(d.message||"Unable to open billing. Please retry.")}finally{N(!1)}},[o,t,c]),P=r.useCallback(()=>{x(!0)},[]),I=r.useCallback(()=>{x(!1)},[]),O=r.useCallback(()=>{g(!0)},[]),z=r.useCallback(()=>{g(!1)},[]),W=r.useCallback(()=>{t&&a(`/facilities/${t.id}/manage`,{state:{from:"facility-dashboard"}})},[a,t]),_=r.useCallback(()=>{t&&a(`/facilities/${t.id}`)},[a,t]);if(j)return e.jsx(V,{fullScreen:!0,message:"Loading facility dataâ¦"});if(h){const d=(h==null?void 0:h.code)==="permission-denied";return e.jsx("div",{className:"min-h-[calc(100vh-60px)] flex items-center justify-center bg-gray-50 px-4",children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-lg border border-red-100 p-8 max-w-lg text-center",children:[e.jsx("h1",{className:"text-xl font-semibold text-gray-900 mb-2",children:"Unable to load facility"}),e.jsx("p",{className:"text-sm text-gray-600 mb-6",children:d?e.jsxs(e.Fragment,{children:["You are not authorized to view this facility, if you believe this is an error please contact"," ",e.jsx("a",{href:`mailto:${U}`,className:"text-blue-600 hover:text-blue-700 underline",children:U})]}):h.message||e.jsxs(e.Fragment,{children:["There was an error retrieving facility data, please contact"," ",e.jsx("a",{href:`mailto:${U}`,className:"text-blue-600 hover:text-blue-700 underline",children:U})]})}),e.jsx("button",{type:"button",onClick:u,className:"px-5 py-2.5 bg-amber-500 text-white rounded-lg font-medium hover:bg-amber-600",children:"Retry"})]})})}return n?t?e.jsx("div",{className:M,children:e.jsxs("div",{className:D,children:[e.jsx(he,{facility:t,onBack:s==="manager"?F:y,backLabel:E,onRenameFacility:q,onOpenBilling:S?T:void 0,onAddPlayer:P,onAddCoach:O,onRefresh:u,viewMode:s==="manager"?"management":"dashboard",onNavigateToManager:W,onNavigateToDashboard:_,viewerIsDeveloper:Ee,management:C}),m&&t?e.jsx(Fe,{facility:t,onClose:I,onSuccess:u}):null,i&&t?e.jsx(be,{facility:t,onClose:z,onSuccess:u}):null,R&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/20",children:e.jsx("div",{className:"bg-white rounded-xl p-6 shadow-xl",children:e.jsx(V,{size:"small",message:"Opening Billing Portal"})})})]})}):e.jsx("div",{className:"min-h-[calc(100vh-60px)] flex items-center justify-center bg-gray-50 px-4",children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-lg border border-gray-100 p-8 max-w-lg text-center space-y-4",children:[e.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:"Facility not found"}),e.jsx("p",{className:"text-sm text-gray-600",children:"We could not locate that facility or you no longer have access."}),e.jsx("button",{type:"button",onClick:y,className:"px-5 py-2.5 bg-amber-500 text-white rounded-lg font-medium hover:bg-amber-600",children:"Back to dashboard"})]})}):e.jsx("div",{className:"min-h-[calc(100vh-60px)] flex items-center justify-center bg-gray-50 px-4",children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-lg border border-gray-100 p-8 max-w-lg text-center space-y-4",children:[e.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:"Facility route missing"}),e.jsx("p",{className:"text-sm text-gray-600",children:"Select a facility from the dashboard to view its details."}),e.jsx("button",{type:"button",onClick:y,className:"px-5 py-2.5 bg-amber-500 text-white rounded-lg font-medium hover:bg-amber-600",children:"Back to dashboard"})]})})},Ze=()=>e.jsx(Me,{mode:"manager"});export{Ze as FacilityManagerDetail,Me 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.