PageSourceSearch

https://www.abbeytheatre.co.uk/assets/Admin-B9vK7CH0.js

js abbeytheatre.co.uk collected 2026-09-25 08:04:19 UTC 9,964 bytes, 1 lines download raw bytes

1import{k as me,l as xe,r as i,s as u,q as j,bj as W,j as e,L as Y,B as m,bk as he,P as w,bl as ge,bm as pe,bn as fe,bo as je,U as we,K as ve,a2 as _e,G as Ne}from"./index-tvAeWDDu.js";import{u as Se}from"./usePageViews-CUrUJL8y.js";import{S as E,a as T,b as I,c as F,d as r}from"./select-D_9989fq.js";import{P as be}from"./plus-D42lu7Dc.js";import{A as De}from"./arrow-up-down-gH--rdUs.js";import{C as ye}from"./chart-column-CPHzpnt9.js";import{S as Ce}from"./share-2-BbCiwwqf.js";import{M as Pe}from"./megaphone-EkrqxxEy.js";import{P as ke}from"./pencil-BZLOcPeQ.js";import{R as Me}from"./rotate-ccw-BeiB7EMq.js";import"./index-BdQq_4o_.js";import"./chevron-down-DdqJBhHb.js";import"./chevron-up-eQONr_xY.js";function Ge(){const{user:x,isAdmin:l,isShowAdmin:A,isMarketing:v,isTrustee:L,isAnyAdmin:h,canEditProduction:J,assignedProductions:B,loading:g}=me(),_=xe(),[R,Q]=i.useState([]),[X,V]=i.useState(!0),[$,ee]=i.useState(new Map),[O,se]=i.useState(new Map),[z,te]=i.useState(new Map),q={isAdmin:l,isMarketing:v,isTrustee:L},[o,G]=i.useState(()=>{const s=sessionStorage.getItem("admin_productions_dateFilter");return s||null}),[d,ae]=i.useState(()=>sessionStorage.getItem("admin_productions_typeFilter")||"non-courses"),[p,ie]=i.useState(()=>sessionStorage.getItem("admin_productions_sortOption")||"date-asc"),{viewCounts:U}=Se("production");i.useEffect(()=>{o!==null&&sessionStorage.setItem("admin_productions_dateFilter",o)},[o]),i.useEffect(()=>{sessionStorage.setItem("admin_productions_typeFilter",d)},[d]),i.useEffect(()=>{sessionStorage.setItem("admin_productions_sortOption",p)},[p]),i.useEffect(()=>{!g&&o===null&&G(A&&!l?"my-productions":"future")},[g,l,A,o]),i.useEffect(()=>{!g&&(!x||!h)&&_("/admin/login")},[x,h,g,_]),i.useEffect(()=>{x&&h&&D()},[x,h]);const D=async()=>{const{data:s,error:t}=await u.from("productions").select("*");if(t){j.error("Failed to load productions"),V(!1);return}const{data:n}=await u.from("showtimes").select("production_id, date, external_bookings, external_tickets"),[{data:S},{data:b}]=await Promise.all([u.from("production_images").select("production_id"),u.from("scheduled_posts").select("production_id, scheduled_post_items(id)").not("production_id","is",null)]),C=new Map,P=new Map,k=new Map;n?.forEach(a=>{const c=C.get(a.production_id)||[];c.push(new Date(`${a.date}T00:00:00`)),C.set(a.production_id,c),P.set(a.production_id,(P.get(a.production_id)||0)+(a.external_bookings||0)),k.set(a.production_id,(k.get(a.production_id)||0)+(a.external_tickets||0))});const Z=new Set;S?.forEach(a=>{Z.add(a.production_id)});const H=new Date;H.setHours(0,0,0,0);const le=(s||[]).map(a=>{const c=C.get(a.id)||[],K=c.filter(f=>f>=H),ce=K.length>0?new Date(Math.min(...K.map(f=>f.getTime()))):null,de=c.length>0?new Date(Math.max(...c.map(f=>f.getTime()))):null,ue=!a.description?.trim()||!a.synopsis?.trim()||!a.running_time?.trim();return{...a,nextShowDate:ce,lastShowDate:de,hasImages:Z.has(a.id),hasMissingDetails:ue}}),M=new Map;b?.forEach(a=>{if(a.production_id){const c=Array.isArray(a.scheduled_post_items)?a.scheduled_post_items.length:0;M.set(a.production_id,(M.get(a.production_id)||0)+c)}}),Q(le),ee(P),se(k),te(M),V(!1)},N=i.useMemo(()=>{let s=R.filter(t=>{if(o==="cancelled")return t.is_cancelled;if(t.is_cancelled)return!1;const n=t.type==="Daytime Course";if(d==="courses"&&!n||d==="non-courses"&&n)return!1;switch(o){case"future":return!!t.nextShowDate;case"past":return!t.nextShowDate;case"missing-details":return t.hasMissingDetails;case"missing-images":return!t.hasImages;case"my-productions":return l?!0:B.includes(t.id);default:return!0}});return s.sort((t,n)=>{const S=(t.nextShowDate||t.lastShowDate)?.getTime()??0,b=(n.nextShowDate||n.lastShowDate)?.getTime()??0;switch(p){case"date-asc":return S-b;case"date-desc":return b-S;case"name-asc":return t.title.localeCompare(n.title);case"name-desc":return n.title.localeCompare(t.title);default:return 0}}),s},[R,o,d,p,l,B]),ne=async s=>{if(!confirm("Cancel this production? It will be removed from public listings and all online booking will be blocked. Existing orders will be preserved."))return;const{error:t}=await u.from("productions").update({is_cancelled:!0,cancelled_at:new Date().toISOString()}).eq("id",s);t?j.error("Failed to cancel production"):(j.success("Production cancelled"),D())},re=async s=>{if(!confirm("Restore this cancelled production? It will appear in public listings and online booking will be available again."))return;const{error:t}=await u.from("productions").update({is_cancelled:!1,cancelled_at:null}).eq("id",s);t?j.error("Failed to restore production"):(j.success("Production restored"),D())};if(g||!x||!h)return null;const y=W("production_edit",q),oe=W("production_marketing",q);return e.jsx("div",{className:"min-h-screen bg-background",children:e.jsxs("main",{className:"container mx-auto px-4 py-8",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 mb-6",children:[e.jsx("h1",{className:"text-3xl font-bold text-foreground",children:"Productions"}),y.canEdit&&e.jsx(Y,{to:"/admin/productions/new",children:e.jsxs(m,{children:[e.jsx(be,{className:"mr-2 h-4 w-4"}),"New Production"]})})]}),e.jsxs("div",{className:"flex flex-wrap gap-3 mb-6",children:[e.jsxs(E,{value:o??"future",onValueChange:s=>G(s),children:[e.jsx(T,{className:"w-[180px]",children:e.jsx(I,{placeholder:"Status"})}),e.jsxs(F,{children:[e.jsx(r,{value:"my-productions",children:"My Productions"}),e.jsx(r,{value:"future",children:"Future Dated"}),e.jsx(r,{value:"past",children:"Past Dated"}),e.jsx(r,{value:"missing-details",children:"Missing Details"}),e.jsx(r,{value:"missing-images",children:"Missing Images"}),l&&e.jsx(r,{value:"cancelled",children:"Deleted / Cancelled"})]})]}),e.jsxs(E,{value:d,onValueChange:s=>ae(s),children:[e.jsx(T,{className:"w-[140px]",children:e.jsx(I,{placeholder:"Type"})}),e.jsxs(F,{children:[e.jsx(r,{value:"non-courses",children:"Non-Courses"}),e.jsx(r,{value:"courses",children:"Courses"})]})]}),e.jsxs(E,{value:p,onValueChange:s=>ie(s),children:[e.jsxs(T,{className:"w-[160px]",children:[e.jsx(De,{className:"mr-2 h-4 w-4"}),e.jsx(I,{placeholder:"Sort by"})]}),e.jsxs(F,{children:[e.jsx(r,{value:"date-asc",children:"Date (Earliest)"}),e.jsx(r,{value:"date-desc",children:"Date (Latest)"}),e.jsx(r,{value:"name-asc",children:"Name (A-Z)"}),e.jsx(r,{value:"name-desc",children:"Name (Z-A)"})]})]}),e.jsxs("div",{className:"text-sm text-muted-foreground self-center ml-2",children:[N.length," production",N.length!==1?"s":""]})]}),X?e.jsx("p",{className:"text-muted-foreground",children:"Loading productions..."}):N.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx("p",{className:"text-muted-foreground mb-4",children:"No productions match the current filters"}),y.canEdit&&e.jsx(Y,{to:"/admin/productions/new",children:e.jsx(m,{children:"Create a new production"})})]}):e.jsx(he,{children:e.jsx("div",{className:"grid gap-4",children:N.map(s=>{const t=l||L?!0:J(s.id),n=l;return e.jsxs("div",{className:Ne("border border-border rounded-lg p-6 flex justify-between items-start transition-opacity",!t&&!v&&"opacity-60"),children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2 flex-wrap",children:[e.jsx("h3",{className:"text-xl font-bold text-foreground",children:s.title}),s.type==="Daytime Course"&&e.jsx(w,{variant:"secondary",className:"text-xs",children:"Course"}),s.is_cancelled&&e.jsx(w,{variant:"destructive",className:"text-xs",children:"Cancelled"}),s.hasMissingDetails&&e.jsx(w,{variant:"destructive",className:"text-xs",children:"Missing Details"}),!s.hasImages&&e.jsx(w,{variant:"outline",className:"text-xs border-destructive text-destructive",children:"No Images"}),!t&&!v&&e.jsxs(ge,{children:[e.jsx(pe,{children:e.jsx(fe,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx(je,{children:e.jsx("p",{children:"You don't have permission to edit this production"})})]}),!t&&!v&&e.jsx(w,{variant:"outline",className:"text-xs",children:"View Only"})]}),e.jsx("p",{className:"text-muted-foreground mb-2",children:s.description}),e.jsxs("div",{className:"text-sm text-muted-foreground flex flex-wrap gap-x-4",children:[s.nextShowDate&&e.jsxs("span",{children:["Next: ",s.nextShowDate.toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})]}),e.jsxs("span",{children:["Running time: ",s.running_time,s.age_guidance?.trim()?` | Guide: ${s.age_guidance}`:""]}),U[s.id]!=null&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ye,{className:"h-3 w-3"}
1),U[s.id].toLocaleString()," views"]}),($.get(s.id)||0)>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(we,{className:"h-3 w-3"}),($.get(s.id)||0).toLocaleString()," bookings"]}),(O.get(s.id)||0)>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ve,{className:"h-3 w-3"}),(O.get(s.id)||0).toLocaleString()," tickets"]}),(z.get(s.id)||0)>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Ce,{className:"h-3 w-3"}),(z.get(s.id)||0).toLocaleString()," social posts"]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[oe.canView&&e.jsx(m,{variant:"outline",size:"icon",onClick:()=>_(`/admin/productions/${s.id}/marketing`),"aria-label":`Marketing view for ${s.title}`,title:"Marketing View",children:e.jsx(Pe,{className:"h-4 w-4"})}),y.canEdit&&e.jsx(m,{variant:"outline",size:"icon",disabled:!t,onClick:()=>t&&_(`/admin/productions/${s.id}`),"aria-label":`Edit ${s.title}`,children:e.jsx(ke,{className:"h-4 w-4"})}),n&&s.is_cancelled&&e.jsx(m,{variant:"outline",size:"icon",onClick:()=>re(s.id),"aria-label":`Restore ${s.title}`,title:"Restore production",children:e.jsx(Me,{className:"h-4 w-4"})}),n&&!s.is_cancelled&&e.jsx(m,{variant:"outline",size:"icon",onClick:()=>ne(s.id),"aria-label":`Cancel ${s.title}`,title:"Cancel production",children:e.jsx(_e,{className:"h-4 w-4"})})]})]},s.id)})})})]})})}export{Ge 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.