1import{h as H,c as W,a as Y,r as l,j as e,S as G,T as fe,p as J,B as S,E as I,l as ge,d as be,t as K,C as P,L as ye,k as te,g as je}from"./index-_aijvlUq.js";import{u as Ne,P as Ce}from"./PageHeader-DCofr6qo.js";import{v as D}from"./venues-DxAiztOL.js";import{M as ve}from"./MapLink-BG5aOsD1.js";import{U as ke}from"./UsageLimitBanner-FQhQBbSE.js";import{I as T}from"./Input-ysTyZFq5.js";import{a as Se}from"./Skeleton-B3Wj6cNd.js";import{U as ae}from"./UpgradePrompt-CWmCKX75.js";import{u as re,s as De}from"./useHighlightParam-DCzFvxlk.js";import{M as we}from"./MobileListSkeleton-BxuyWDCs.js";import{M as Le}from"./MobileFab-CAyx0Bpg.js";import{B as oe}from"./BottomSheet-BiQNSujt.js";import{C as Ee}from"./ConfirmDialog-CODvETNM.js";import{U as Ae}from"./usStates-B3oQG6kH.js";import{E as Fe}from"./EmptyState-CPGKooqj.js";import{T as Te}from"./Tabs-CGDUdv1I.js";import"./Badge-DJIi163x.js";const ie={name:"",address:"",city:"",state:"",county:"",stageCapacity:"",stageWidthFt:"",stageDepthFt:"",notes:""};function se(t){return t?{name:t.name??"",address:t.address??"",city:t.city??"",state:t.state??"",county:t.county??"",stageCapacity:t.stageCapacity??"",stageWidthFt:t.stageWidthFt??"",stageDepthFt:t.stageDepthFt??"",notes:t.notes??""}:{...ie}}function le({venue:t=null,onSaved:s,onCancel:o,onDeleted:n,showTopActions:d=!1}){const c=!!t,u=H(b=>b.currentOrg?.id),{showSuccess:i,showError:f}=W(),{canFully:N}=Y(),L=N("performance:delete"),[m,j]=l.useState(()=>se(t)),[C,k]=l.useState(!1),[p,h]=l.useState(!1),v=l.useRef(c?se(t):null),g=b=>w=>j(M=>({...M,[b]:w.target.value})),B=!c||!v.current||Object.keys(ie).some(b=>m[b]!==v.current[b]),x=!!m.name.trim()&&B;async function R(b){if(b?.preventDefault?.(),!!m.name.trim()){k(!0);try{const w={...m,stageCapacity:m.stageCapacity?parseInt(m.stageCapacity,10):null,stageWidthFt:m.stageWidthFt?parseInt(m.stageWidthFt,10):null,stageDepthFt:m.stageDepthFt?parseInt(m.stageDepthFt,10):null};if(c){const M=await D.update(t.id,w);i("Location updated"),s?.(M,"edit")}else{const M=await D.create({...w,orgId:u});i("Location added"),s?.(M,"create")}}catch(w){f(w.message||I)}finally{k(!1)}}}async function A(){try{await D.remove(t.id),i("Location deleted"),h(!1),n?.(t.id)}catch(b){h(!1),f(b.message||J)}}const r=()=>e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(S,{type:"button",size:"sm",isLoading:C,disabled:!x,onClick:R,children:c?"Save changes":"Create"}),e.jsx(S,{type:"button",variant:"secondary",size:"sm",onClick:o,children:"Cancel"}),c&&L&&n&&e.jsx(S,{type:"button",variant:"danger",size:"sm",className:"ml-auto",onClick:()=>h(!0),children:"Delete"})]});return e.jsxs(e.Fragment,{children:[e.jsx(Ee,{isOpen:p,onClose:()=>h(!1),onConfirm:A,title:"Delete Location",message:`Delete "${t?.name}"? This cannot be undone.`,confirmLabel:"Delete"}),d&&e.jsx("div",{className:"mb-4",children:r()}),e.jsxs("form",{onSubmit:R,className:"space-y-3",children:[e.jsx(T,{label:"Name",placeholder:"City Auditorium",value:m.name,onChange:g("name"),required:!0}),e.jsx(T,{label:"Address",placeholder:"123 Main St",value:m.address,onChange:g("address")}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(T,{label:"City",value:m.city,onChange:g("city")}),e.jsx(G,{label:"State",options:Ae,value:m.state,onChange:g("state")})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(T,{label:"County",value:m.county,onChange:g("county")}),e.jsx(T,{label:"Stage Capacity",type:"number",min:"1",placeholder:"e.g. 30",value:m.stageCapacity,onChange:g("stageCapacity")})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(T,{label:"Stage Width (ft)",type:"number",min:"1",placeholder:"e.g. 50",value:m.stageWidthFt,onChange:g("stageWidthFt")}
1),e.jsx(T,{label:"Stage Depth (ft)",type:"number",min:"1",placeholder:"e.g. 30",value:m.stageDepthFt,onChange:g("stageDepthFt")})]}),e.jsx(fe,{label:"Notes",value:m.notes,onChange:g("notes"),rows:2,maxLength:2e3,placeholder:"Stage dimensions, parking info, special requirementsâ¦"}),r()]})]})}function Me({isOpen:t,onClose:s,venue:o=null,onSaved:n,onDeleted:d}){return e.jsx(oe,{isOpen:t,onClose:s,title:o?"Edit location":"New location",children:e.jsx("div",{style:{padding:"var(--bb-space-4)"},children:t&&e.jsx(le,{venue:o,onCancel:s,onSaved:(c,u)=>{n?.(c,u),s?.()},onDeleted:c=>{d?.(c),s?.()}},o?.id||"new")})})}function ne({p:t,isPast:s,stageCapacity:o}){return e.jsxs("li",{className:`flex items-center gap-3 text-sm ${t.capacityWarning?"bg-red-50 rounded-lg px-2 py-1":""}`,children:[e.jsx("span",{className:`tabular-nums shrink-0 w-24 ${s?"text-gray-400":"text-gray-500"}`,children:be(t.performanceDate)}),e.jsx("span",{className:`truncate ${s?"text-gray-600":"font-medium text-gray-800"}`,children:t.title}),t.ensembleName&&e.jsxs("span",{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium shrink-0 ${s?"bg-gray-100 text-gray-500":"bg-blue-100 text-blue-700"}`,children:[t.ensembleName,t.playerCount?` · ${t.playerCount} ${t.playerCountSource==="seated"?"playing":t.playerCount===1?"member":"members"}`:""]}),t.capacityWarning&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs font-medium bg-red-100 text-red-700 shrink-0",title:`${t.playerCount} ${t.playerCountSource==="seated"?"players seated for this concert":"active members in the ensemble"}; the stage holds ${o}`,children:[e.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v2m0 4h.01M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"})}),"Over capacity"]})]})}function ce({venueId:t,stageCapacity:s}){const[o,n]=l.useState(void 0);if(l.useEffect(()=>{let i=!1;return D.performances(t).then(f=>{i||n(f)}).catch(()=>{i||n([])}),()=>{i=!0}},[t]),o===void 0)return e.jsx("p",{className:"text-sm text-gray-400",children:"Loadingâ¦"});if(o.length===0)return e.jsx("p",{className:"text-sm text-gray-400",children:"No performances recorded at this location."});const d=ge(),c=o.filter(i=>i.performanceDate>=d).sort((i,f)=>String(i.performanceDate).localeCompare(String(f.performanceDate))),u=o.filter(i=>i.performanceDate<d).sort((i,f)=>String(f.performanceDate).localeCompare(String(i.performanceDate)));return e.jsxs("div",{className:"space-y-4",children:[c.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-gray-400 uppercase tracking-wide mb-2",children:"Upcoming"}),e.jsx("ul",{className:"space-y-1.5",children:c.map(i=>e.jsx(ne,{p:i,isPast:!1,stageCapacity:s},i.id))})]}),u.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-gray-400 uppercase tracking-wide mb-2",children:"Past"}),e.jsx("ul",{className:"space-y-1.5",children:u.map(i=>e.jsx(ne,{p:i,isPast:!0,stageCapacity:s},i.id))})]})]})}function de({venueId:t,canManage:s,canDelete:o,onCountChange:n}){const{showSuccess:d,showError:c}=W(),[u,i]=l.useState(void 0),[f,N]=l.useState(!1),[L,m]=l.useState(!1),[j,C]=l.useState(""),[k,p]=l.useState("");l.useEffect(()=>{let r=!1;return D.listBlackoutDates(t).then(b=>{r||i(b)}).catch(()=>{r||i([])}),()=>{r=!0}},[t]);function h(r){i(r),n?.(r.length)}async function v(){if(j)try{const r=await D.addBlackoutDate(t,{date:j,reason:k,source:"manual",confirmed:!0});h([...u??[],r].sort((b,w)=>b.date.localeCompare(w.date))),C(""),p(""),m(!1)}catch(r){c(r.message||I)}}async function g(){N(!0);try{const r=await D.addBlackoutDatesBulk(t,Be(new Date().getFullYear()));h(r),d("Added suggested blackout dates")}catch(r){c(r.message||K("blackout dates"))}finally{N(!1)}}async function B(r){try{const b=await D.confirmBlackoutDate(t,r);i(w=>(w??[]).map(M=>M.id===r?b:M))}catch(b){c(b.message||I)}}async function x(r){try{await D.removeBlackoutDate(t,r),h((u??[]).filter(b=>b.id!==r))}catch(b){c(b.message||J)}}if(u===void 0)return e.jsx("p",{className:"text-sm text-gray-400",children:"Loadingâ¦"});const R=u.filter(r=>r.confirmed),A=u.filter(r=>!r.confirmed);return e.jsxs("div",{className:"space-y-3",children:[s&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(S,{size:"sm",variant:"secondary",onClick:()=>m(!L),children:L?"Cancel":"Add date"}),e.jsx(S,{size:"sm",variant:"secondary",isLoading:f,onClick:g,children:"Suggest blackout dates"})]}),L&&e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-end gap-2",children:[e.jsx(T,{label:"Date",type:"date",value:j,onChange:r=>C(r.target.value),className:"sm:w-40"}),e.jsx(T,{label:"Reason",value:k,onChange:r=>p(r.target.value),placeholder:"e.g. Holiday closure",className:"flex-1"}),e.jsx(S,{size:"sm",onClick:v,disabled:!j,children:"Add"})]}),A.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-amber-600 uppercase tracking-wide mb-2",children:"Suggested (unconfirmed)"}),e.jsx("ul",{className:"space-y-1",children:A.map(r=>e.jsxs("li",{className:"flex items-center gap-3 text-sm bg-amber-50 rounded-lg px-3 py-2",children:[e.jsx("span",{className:"tabular-nums text-gray-600 shrink-0 w-24",children:r.date}),e.jsx("span",{className:"text-gray-600 truncate flex-1",children:r.reason||"No reason"}),e.jsxs("div",{className:"flex gap-1 shrink-0",children:[s&&e.jsx(S,{variant:"ghost",size:"sm",onClick:()=>B(r.id),children:"Confirm"}),o&&e.jsx(S,{variant:"ghost",size:"sm",className:"text-red-500 hover:text-red-700",onClick:()=>x(r.id),children:"Remove"})]})]},r.id))})]}),R.length>0?e.jsxs("div",{children:[A.length>0&&e.jsx("p",{className:"text-xs font-semibold text-gray-400 uppercase tracking-wide mb-2",children:"Confirmed"}),e.jsx("ul",{className:"space-y-1",children:R.map(r=>e.jsxs("li",{className:"flex items-center gap-3 text-sm",children:[e.jsx("span",{className:"tabular-nums text-gray-600 shrink-0 w-24",children:r.date}),e.jsx("span",{className:"text-gray-500 truncate flex-1",children:r.reason||"No reason"}),e.jsx("span",{className:"text-xs text-gray-400 shrink-0",children:r.source==="ai_suggested"?"Suggested":"Manual"}),o&&e.jsx(S,{variant:"ghost",size:"sm",className:"text-red-500 hover:text-red-700 shrink-0",onClick:()=>x(r.id),children:"Remove"})]},r.id))})]}):A.length===0?e.jsx("p",{className:"text-sm text-gray-400",children:"No blackout dates. Add dates manually, or have common closures suggested for you."}):null]})}function Be(t){const s=[];
1s.push({date:`${t}-01-01`,reason:"New Year's Day"}),s.push({date:`${t}-07-04`,reason:"Independence Day"}),s.push({date:`${t}-12-24`,reason:"Christmas Eve"}),s.push({date:`${t}-12-25`,reason:"Christmas Day"}),s.push({date:`${t}-12-31`,reason:"New Year's Eve"}),s.push({date:`${t}-11-11`,reason:"Veterans Day"}),s.push({date:z(t,0,1,3),reason:"Martin Luther King Jr. Day"}),s.push({date:z(t,1,1,3),reason:"Presidents' Day"}),s.push({date:Re(t,4,1),reason:"Memorial Day"}),s.push({date:z(t,8,1,1),reason:"Labor Day"}),s.push({date:z(t,9,1,2),reason:"Columbus Day"});const o=z(t,10,4,4);s.push({date:o,reason:"Thanksgiving"});const n=new Date(o);n.setDate(n.getDate()+1),s.push({date:P(n),reason:"Day after Thanksgiving"});const d=$e(t);s.push({date:d,reason:"Easter Sunday"});const c=new Date(d);return c.setDate(c.getDate()-2),s.push({date:P(c),reason:"Good Friday"}),s.map(u=>({...u,source:"ai_suggested",confirmed:!1}))}function z(t,s,o,n){const d=new Date(t,s,1);let c=0;for(;c<n;)d.getDay()===o&&c++,c<n&&d.setDate(d.getDate()+1);return P(d)}function Re(t,s,o){const n=new Date(t,s+1,0);for(;n.getDay()!==o;)n.setDate(n.getDate()-1);return P(n)}function $e(t){const s=t%19,o=Math.floor(t/100),n=t%100,d=Math.floor(o/4),c=o%4,u=Math.floor((o+8)/25),i=Math.floor((o-u+1)/3),f=(19*s+o-d-i+15)%30,N=Math.floor(n/4),L=n%4,m=(32+2*c+2*N-f-L)%7,j=Math.floor((s+11*f+22*m)/451),C=Math.floor((f+m-7*j+114)/31)-1,k=(f+m-7*j+114)%31+1;return P(new Date(t,C,k))}const Ve={"application/pdf":"PDF","image/png":"PNG","image/jpeg":"JPG","image/webp":"WebP","application/msword":"DOC","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"DOCX"};function ze(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(0)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function me({venueId:t,canManage:s,canDelete:o,onCountChange:n}){const{showSuccess:d,showError:c}=W(),[u,i]=l.useState(void 0),[f,N]=l.useState(!1),[L,m]=l.useState(""),j=l.useRef(null);l.useEffect(()=>{let p=!1;return D.listDocuments(t).then(h=>{p||i(h)}).catch(()=>{p||i([])}),()=>{p=!0}},[t]);async function C(){const p=j.current?.files?.[0];if(p){N(!0);try{const v=[await D.uploadDocument(t,p,L),...u??[]];i(v),n?.(v.length),m(""),j.current&&(j.current.value=""),d("Document uploaded")}catch(h){c(h.message||I)}finally{N(!1)}}}async function k(p){try{await D.removeDocument(t,p);const h=(u??[]).filter(v=>v.id!==p);i(h),n?.(h.length),d("Document removed")}catch(h){c(h.message||J)}}return u===void 0?e.jsx("p",{className:"text-sm text-gray-400",children:"Loadingâ¦"}):e.jsxs("div",{className:"space-y-3",children:[s&&e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-end gap-2",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:"block text-xs font-medium text-gray-500 mb-1",children:"Upload Document"}),e.jsx("input",{ref:j,type:"file",accept:".pdf,.doc,.docx,.png,.jpg,.jpeg,.webp",className:"block w-full text-sm text-gray-500 file:mr-2 file:py-1.5 file:px-3 file:rounded-lg file:border file:border-gray-200 file:text-sm file:font-medium file:bg-white file:text-gray-700 hover:file:bg-gray-50"})]}),e.jsx(T,{label:"Label",value:L,onChange:p=>m(p.target.value),placeholder:"e.g. Stage Layout",className:"sm:w-40"}),e.jsx(S,{size:"sm",isLoading:f,onClick:C,children:"Upload"})]}),u.length>0?e.jsx("ul",{className:"space-y-1",children:u.map(p=>e.jsxs("li",{className:"flex items-center gap-3 text-sm bg-gray-50 rounded-lg px-3 py-2",children:[e.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-xs font-bold bg-gray-200 text-gray-600 shrink-0",children:Ve[p.mimeType]||"FILE"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"font-medium text-gray-700 truncate",children:p.label||p.fileName}),p.label&&e.jsx("p",{className:"text-xs text-gray-400 truncate",children:p.fileName})]}),e.jsx("span",{className:"text-xs text-gray-400 shrink-0",children:ze(p.fileSize)}),o&&e.jsx(S,{variant:"ghost",size:"sm",className:"text-red-500 hover:text-red-700 shrink-0",onClick:()=>k(p.id),children:"Remove"})]},p.id))}):e.jsx("p",{className:"text-sm text-gray-400",children:"No documents. Upload parking instructions, stage layouts, room specs, or event calendars."})]})}const Pe=[{key:"performances",label:"Performances"},{key:"blackouts",label:"Blackout Dates"},{key:"documents",label:"Documents"}];
1function We({venue:t,isOpen:s,onClose:o,canManage:n,canDelete:d,onEdit:c}){const[u,i]=l.useState("performances");l.useEffect(()=>{s&&i("performances")},[s,t?.id]);const f=t?[t.address,t.city,t.state,t.county].filter(Boolean).join(", "):"";return e.jsx(oe,{isOpen:s&&!!t,onClose:o,title:t?.name||"",children:t&&e.jsxs("div",{style:{padding:"var(--bb-space-4)"},children:[f&&e.jsx("p",{className:"text-sm text-gray-500",children:f}),t.notes&&e.jsx("p",{className:"text-xs text-gray-500 italic mt-1",children:t.notes}),n&&e.jsx("div",{className:"mt-3 mb-1",children:e.jsx(S,{size:"sm",variant:"secondary",onClick:()=>c?.(t),children:"Edit location"})}),e.jsx("div",{className:"flex border-b border-gray-200 my-4",children:Pe.map(N=>e.jsx("button",{type:"button",onClick:()=>i(N.key),className:`px-3 py-2 text-xs font-medium border-b-2 transition-colors ${u===N.key?"border-band-500 text-band-700":"border-transparent text-gray-400"}`,children:N.label},N.key))}),u==="performances"&&e.jsx(ce,{venueId:t.id,stageCapacity:t.stageCapacity}),u==="blackouts"&&e.jsx(de,{venueId:t.id,canManage:n,canDelete:d}),u==="documents"&&e.jsx(me,{venueId:t.id,canManage:n,canDelete:d})]})})}function Ie(t){const s=[t.address,t.city,t.state].filter(Boolean);return s.length===0?null:`https://maps.google.com/?q=${encodeURIComponent([t.name,...s].join(", "))}`}function qe(){const t=H(x=>x.currentOrg?.id),{showError:s}=W(),{canFully:o}=Y(),n=o("performance:create"),d=o("performance:delete"),[c,u]=l.useState([]),[i,f]=l.useState(!0),[N,L]=l.useState(""),[m,j]=l.useState(!1),[C,k]=l.useState(null),[p,h]=l.useState(null);re(c,i,h);const v=l.useCallback(()=>{t&&(f(!0),D.list(t).then(x=>u(Array.isArray(x)?x:[])).catch(()=>s(K("locations"))).finally(()=>f(!1)))},[t]);l.useEffect(()=>{v()},[v]);const g=N.trim().toLowerCase(),B=g?c.filter(x=>[x.name,x.address,x.city,x.state].filter(Boolean).join(" ").toLowerCase().includes(g)):c;return e.jsxs("div",{style:{paddingBottom:n?96:void 0},children:[e.jsx("form",{onSubmit:x=>x.preventDefault(),style:{padding:"var(--bb-space-3) var(--bb-space-4) var(--bb-space-3)",background:"var(--bb-bg)"},children:e.jsxs("div",{style:{position:"relative"},children:[e.jsx(Oe,{}),e.jsx("input",{type:"search",value:N,onChange:x=>L(x.target.value),placeholder:"Search locations","aria-label":"Search locations",style:{width:"100%",padding:"12px 14px 12px 38px",fontSize:15,borderRadius:"var(--bb-radius-md)",border:"1px solid var(--bb-border-soft)",background:"var(--bb-surface)",color:"var(--bb-fg)",outline:"none"}})]})}),i?e.jsx(we,{variant:"performance",count:3}):B.length===0?e.jsx("div",{style:{margin:"var(--bb-space-4)",padding:"var(--bb-space-6)",background:"var(--bb-surface)",border:"1px solid var(--bb-border-soft)",borderRadius:"var(--bb-radius-lg)",textAlign:"center",color:"var(--bb-fg-muted)"},children:g?"No locations match.":"No locations yet."}):e.jsx("ul",{"data-testid":"mobile-locations-list",style:{listStyle:"none",margin:0,padding:0},children:B.map(x=>e.jsx(Ue,{venue:x,onOpen:()=>h(x)},x.id))}),n&&e.jsx(Le,{onClick:()=>j(!0),label:"New location",testId:"mobile-location-fab"}),e.jsx(Me,{isOpen:m||!!C,venue:C,onClose:()=>{j(!1),k(null)},onSaved:v,onDeleted:v}),e.jsx(We,{venue:p,isOpen:!!p,onClose:()=>h(null),canManage:n,canDelete:d,onEdit:x=>{h(null),k(x)}})]})}function Ue({venue:t,onOpen:s}){const o=Ie(t),n=[t.address,t.city,t.state].filter(Boolean).join(", ");return e.jsxs("li",{onClick:s,style:{margin:"0 var(--bb-space-4) var(--bb-space-3)",padding:"var(--bb-space-4)",background:"var(--bb-surface)",border:"1px solid var(--bb-border)",borderRadius:"var(--bb-radius-lg)",boxShadow:"var(--bb-shadow-xs)",cursor:"pointer"},children:[e.jsx("div",{style:{fontSize:17,fontWeight:700,color:"var(--bb-fg)"},children:t.name}),n&&e.jsx("div",{style:{marginTop:2,fontSize:13,color:"var(--bb-fg-muted)"},children:n}),e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:8,marginTop:10,alignItems:"center"},children:[o&&e.jsx("a",{href:o,target:"_blank",rel:"noopener noreferrer",onClick:d=>d.stopPropagation(),style:{minHeight:44,minWidth:64,padding:"0 14px",display:"inline-flex",alignItems:"center",background:"var(--bb-primary-soft)",color:"var(--bb-primary)",fontSize:14,fontWeight:600,textDecoration:"none",borderRadius:"var(--bb-radius-md)"},children:"Open in Maps â"}),t.stageCapacity!=null&&e.jsxs("span",{style:{fontSize:13,color:"var(--bb-fg-muted)"}
1,children:["Stage capacity: ",t.stageCapacity]})]})]})}function Oe(){return e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"var(--bb-fg-subtle)",strokeWidth:2,"aria-hidden":"true",style:{position:"absolute",left:12,top:14},children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})}const _e={excellent:"bg-green-100 text-green-700",good:"bg-green-50 text-green-600",fair:"bg-amber-100 text-amber-700",poor:"bg-red-100 text-red-700",needs_repair:"bg-red-100 text-red-700"};function Ge({a:t}){const s=[t.makeModel,t.serialNumber&&`SN ${t.serialNumber}`,t.inventoryTag&&`Tag ${t.inventoryTag}`].filter(Boolean).join(" · ");return e.jsxs("li",{className:"flex items-center gap-3 text-sm",children:[e.jsxs("span",{className:"font-medium text-gray-800 truncate",children:[t.name,t.quantity>1?` Ã${t.quantity}`:""]}),t.categoryName&&e.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-gray-100 text-gray-500 shrink-0",children:t.categoryName}),t.condition&&e.jsx("span",{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium shrink-0 ${_e[t.condition]||"bg-gray-100 text-gray-500"}`,children:String(t.condition).replace("_"," ")}),t.needsRepair&&e.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-amber-100 text-amber-700 shrink-0",children:"Needs repair"}),s&&e.jsx("span",{className:"text-xs text-gray-400 truncate",children:s})]})}function He({venueId:t}){const[s,o]=l.useState(void 0);return l.useEffect(()=>{let n=!1;return D.equipment(t).then(d=>{n||o(d)}).catch(()=>{n||o([])}),()=>{n=!0}},[t]),s===void 0?e.jsx("p",{className:"text-sm text-gray-400",children:"Loadingâ¦"}):s.length===0?e.jsx("p",{className:"text-sm text-gray-400",children:"No assets stored at this location."}):e.jsxs("div",{className:"space-y-4",children:[e.jsx("ul",{className:"space-y-1.5",children:s.map(n=>e.jsx(Ge,{a:n},n.id))}),e.jsxs("p",{className:"text-xs text-gray-400",children:["Storage locations are set on each item in ",e.jsx(ye,{to:"/equipment",className:"text-band-600 hover:text-band-700",children:"Equipment"}),"."]})]})}function ut(){Ne();const{currentOrg:t}=H(),{showError:s}=W(),{canFully:o,canAny:n}=Y(),d=o("performance:create"),c=o("performance:delete"),u=n("equipment:list"),i=te(a=>a.getMetric("venues")),f=te(a=>a.planTier),N=je(),m=!f||new Set(["essentials","complete"]).has(f),[j,C]=l.useState([]),[k,p]=l.useState(!0),[h,v]=l.useState(""),[g,B]=l.useState(""),[x,R]=l.useState("name"),[A,r]=l.useState(!1),[b,w]=l.useState(null),[M,q]=l.useState(null),[$,U]=l.useState("performances"),O=l.useRef(null);re(j,k||N,a=>{q(a.id),U("performances"),De(a.id)}),l.useEffect(()=>{t&&ue()},[t]);async function ue(){p(!0);try{const a=await D.list(t.id);C(a)}catch{s(K("locations"))}finally{p(!1)}}function X(){w(null),r(!0),requestAnimationFrame(()=>O.current?.scrollIntoView({behavior:"smooth",block:"start"}))}function pe(a){w(a),r(!0),requestAnimationFrame(()=>O.current?.scrollIntoView({behavior:"smooth",block:"start"}))}function _(){r(!1),w(null)}function xe(a,y){C(y==="edit"?F=>F.map(E=>E.id===a.id?{...E,...a}:E):F=>[...F,{...a,performanceCount:0,rehearsalCount:0,blackoutDateCount:0,documentCount:0,equipmentCount:0}].sort((E,V)=>E.name.localeCompare(V.name))),_()}function he(a){C(y=>y.filter(F=>F.id!==a)),_()}function Q(a,y,F){C(E=>E.map(V=>V.id===a?{...V,[y]:F}:V))}const Z=h.trim()?j.filter(a=>[a.name,a.city,a.state,a.county].some(y=>y?.toLowerCase().includes(h.toLowerCase()))):j,ee=[...g?Z.filter(a=>g==="performances"?a.performanceCount>0:g==="rehearsals"?a.rehearsalCount>0:g==="assets"?(a.equipmentCount||0)>0:g==="unused"?!a.performanceCount&&!a.rehearsalCount&&!a.equipmentCount:!0):Z].sort((a,y)=>x==="performances"?(y.performanceCount||0)-(a.performanceCount||0)||a.name.localeCompare(y.name):x==="rehearsals"?(y.rehearsalCount||0)-(a.rehearsalCount||0)||a.name.localeCompare(y.name):x==="assets"?(y.equipmentCount||0)-(a.equipmentCount||0)||a.name.localeCompare(y.name):x==="next"&&(a.nextPerformanceDate||"9999").localeCompare(y.nextPerformanceDate||"9999")||a.name.localeCompare(y.name));return N?e.jsx(qe,{}):e.jsxs("div",{children:[e.jsx(Ce,{title:"Locations",breadcrumbs:[{label:"Home",to:"/"},{label:"Locations"}],actions:d&&!A?e.jsx(S,{onClick:X,children:"New location"}):null}),i&&e.jsx(ke,{metricName:"Venues",current:i.current,limit:i.limit}),e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-2",children:[e.jsx(T,{placeholder:"Search locationsâ¦",value:h,onChange:a=>v(a.target.value),className:"w-64",active:!!h.trim()}),e.jsx(G,{value:g,onChange:a=>B(a.target.value),active:!!g,className:"w-44",options:[{value:"",label:"All locations"},{value:"performances",label:"With performances"},{value:"rehearsals",label:"With rehearsals"},{value:"assets",label:"With assets"},{value:"unused",label:"Unused"}]}),e.jsx(G,{value:x,onChange:a=>R(a.target.value),active:x!=="name",className:"w-48",options:[{value:"name",label:"Sort: Name"},{value:"performances",label:"Sort: Most performances"},{value:"rehearsals",label:"Sort: Most rehearsals"},{value:"assets",label:"Sort: Most assets"},{value:"next",label:"Sort: Next performance"}]})]}),A&&e.jsxs("div",{ref:O,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:b?"Edit Location":"New Location"}),e.jsx(le,{venue:b,showTopActions:!0,onSaved:xe,onCancel:_,onDeleted:he})]}),!A&&(k?e.jsx("div",{className:"space-y-2",children:Array.from({length:4}).map((a,y)=>e.jsx(Se,{lines:2},y))}
1):ee.length===0?e.jsx(Fe,{card:!0,title:h||g?"No locations match your filters.":"No locations yet.",action:d&&!h&&!g&&!A?e.jsx(S,{onClick:X,children:"Create first location"}):null}):e.jsx("div",{className:"space-y-2",children:ee.map(a=>{const y=[a.address,a.city,a.state,a.county].filter(Boolean).join(", "),F=M===a.id;return e.jsxs("div",{id:`row-${a.id}`,className:"bg-white rounded-xl border border-gray-200 overflow-hidden scroll-mt-4",children:[e.jsxs("div",{className:"px-5 py-4 flex items-start gap-4",children:[e.jsxs("button",{type:"button",className:"flex-1 min-w-0 text-left",onClick:()=>{F?q(null):(q(a.id),U("performances"))},children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap min-w-0",children:[e.jsx("p",{className:"font-medium text-gray-900 break-words min-w-0",children:a.name}),a.stageCapacity&&e.jsxs("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-gray-100 text-gray-600",children:["Cap: ",a.stageCapacity]}),e.jsx("svg",{className:`h-4 w-4 text-gray-400 shrink-0 transition-transform duration-200 ${F?"rotate-180":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})})]}),y&&e.jsx("div",{className:"mt-0.5 break-words",children:e.jsx(ve,{name:a.name,address:a.address,city:a.city,state:a.state,label:y,size:"xs"})}),e.jsxs("div",{className:"flex flex-wrap gap-4 mt-1.5 text-xs text-gray-400",children:[e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-gray-500",children:"Last: "}),a.lastPerformanceDate??"None"]}),e.jsxs("span",{children:[e.jsx("span",{className:"font-medium text-gray-500",children:"Next: "}),a.nextPerformanceDate??"None"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0 pt-0.5",children:[a.performanceCount>0&&e.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-700",children:[a.performanceCount," perf",a.performanceCount!==1?"s":""]}),a.rehearsalCount>0&&e.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-600",children:[a.rehearsalCount," rehearsal",a.rehearsalCount!==1?"s":""]}),(a.equipmentCount||0)>0&&e.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-violet-100 text-violet-700",children:[a.equipmentCount," asset",a.equipmentCount!==1?"s":""]}),(a.blackoutDateCount||0)>0&&e.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-amber-100 text-amber-700",children:[a.blackoutDateCount," blackout",a.blackoutDateCount!==1?"s":""]}),(a.documentCount||0)>0&&e.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-700",children:[a.documentCount," doc",a.documentCount!==1?"s":""]}),d&&e.jsx(S,{variant:"ghost",size:"sm",onClick:E=>{E.stopPropagation(),pe(a)},children:"Edit"})]})]}),F&&e.jsxs("div",{className:"border-t border-gray-100",children:[e.jsx(Te,{size:"sm",className:"px-2",ariaLabel:"Location details",tabs:[{key:"performances",label:"Performances"},...u?[{key:"assets",label:"Assets"}]:[],{key:"blackouts",label:"Blackout dates"},{key:"documents",label:"Documents"}],value:$,onChange:U}),e.jsxs("div",{className:"px-5 py-4",children:[a.notes&&e.jsx("p",{className:"text-xs text-gray-500 mb-3 italic",children:a.notes}),$==="performances"&&e.jsx(ce,{venueId:a.id,stageCapacity:a.stageCapacity}),$==="assets"&&u&&e.jsx(He,{venueId:a.id}),$==="blackouts"&&(m?e.jsx(de,{venueId:a.id,canManage:d,canDelete:c,onCountChange:E=>Q(a.id,"blackoutDateCount",E)}):e.jsx(ae,{featureName:"Venue Blackout Dates",requiredTier:"essentials",currentTier:f,description:"Block holidays, venue closures, and custom dates to prevent scheduling conflicts."})),$==="documents"&&(m?e.jsx(me,{venueId:a.id,canManage:d,canDelete:c,onCountChange:E=>Q(a.id,"documentCount",E)}):e.jsx(ae,{featureName:"Venue Documents",requiredTier:"essentials",currentTier:f,description:"Upload stage layouts, parking maps, and venue specs so everyone arrives prepared."}))]})]})]},a.id)})}))]})}export{ut as LocationsPage};
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.