PageSourceSearch

https://app.relius.ai/assets/RoomRentals-CgXqmHjW.js

js relius.ai collected 2026-10-05 13:10:22 UTC 63,670 bytes, 30 lines download raw bytes

1import{r as h,j as e,L as ye,C as le}from"./apiConfig-BRLg321A.js";import{O as M,ac as G,aP as k,g as F,Z as J,_ as W,$ as Z,a1 as ee,ct as ne,ad as se,a2 as ue,m as H,U as ae,W as I,dw as fe,a3 as he,dx as K,B as u,A as O,J as U,dg as Pe,db as te,bk as Le,bp as $e,ag as Qe,a8 as Y,C as X,a5 as re,dy as Me,dz as Be,ai as ce,aJ as ve,X as xe,cS as ze,Q as Oe,K as pe,aS as Ne,au as Se,cC as Ue,a4 as Te,aj as oe,I as Q,a0 as _,b3 as Ke,V as _e,aG as Ge,b as He,u as Ye,ar as Ve,dA as Xe,aa as Je,ab as We,aw as Ze}from"./main-BHuHMuGX.js";import{g as es,a as ss,b as as,d as ts,e as rs,l as ge,R as ke,f as Ee,h as qe,i as is,r as ns,j as ls}from"./RoomAvailabilityCalendar-BpNnygOF.js";import{C as P,d as L,a as je,b as be}from"./Card-BR9XhemT.js";import{E as Ae}from"./ErrorState-zoAM2oYV.js";import{i as os}from"./errors-C7Lcv44x.js";import{P as ds}from"./printer-DTkmqhYS.js";import{C as Fe}from"./circle-x-COShVRyE.js";import{D as we,T as Ce}from"./TimePicker-79M0mOJv.js";import{C as cs}from"./circle-check-BdQMOQ6e.js";import{F as ms}from"./funnel-CWYEg1va.js";import"./index-BYWpZM-r.js";import"./subMonths-B7i-fdd4.js";import"./endOfMonth-CD8d8gJk.js";import"./eachDayOfInterval-CURMIYWB.js";import"./parseISO-e2dWFo5_.js";import"./useClickOutside-DdwIDak1.js";import"./isToday-CeG6CqFW.js";import"./constructNow-BQOy7Eqd.js";import"./chevron-left-CO56mQSd.js";import"./chevron-right-ByxeWboN.js";import"./isAfter-Bo5ZmCzd.js";const z={pending:{label:"Pending Approval",color:"yellow",icon:"Clock"},approved:{label:"Approved",color:"green",icon:"CheckCircle"},rejected:{label:"Rejected",color:"red",icon:"XCircle"},canceled:{label:"Canceled",color:"gray",icon:"Ban"},completed:{label:"Completed",color:"blue",icon:"Check"}};function xs({rental:t,onClose:b}){const[s,m]=h.useState(24),[n,w]=h.useState(null),i=h.useRef(null),y=h.useRef(new Map),c="https://app.relius.ai",{data:v=[],isLoading:R,isError:f,error:g,refetch:j}=M({queryKey:["rental-qr-tokens",t.id],queryFn:async()=>(await Me({room_id:t.roomId,is_active:!0,token_type:Be.ROOM_RENTAL})).filter(S=>S.rental_metadata?.rental_id===t.id)}),C=G({mutationFn:()=>es(t.id,s),onSuccess:()=>{k.success("QR code generated successfully"),j()},onError:r=>{k.error("Failed to generate QR code",{description:F(r)})}}),l=()=>{C.mutate()},N=r=>`${c}/rental-access/${r.token}`,p=async r=>{await navigator.clipboard.writeText(N(r)),w(r.id),k.success("URL copied to clipboard"),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>w(null),2e3)};h.useEffect(()=>()=>{i.current&&clearTimeout(i.current)},[]);const T=r=>{const S=document.getElementById(`qr-code-${r.id}`);if(!S){k.error("QR code not found");return}const q=new XMLSerializer().serializeToString(S),d=document.createElement("canvas"),D=d.getContext("2d"),$=new Image;$.onload=()=>{d.width=$.width,d.height=$.height,D?.drawImage($,0,0);const B=d.toDataURL("image/png"),V=document.createElement("a");V.download=`rental-qr-${t.room?.name||"room"}-${t.id.slice(0,8)}.png`,V.href=B,V.click(),k.success("QR code downloaded")},$.src=`data:image/svg+xml;base64,${btoa(unescape(encodeURIComponent(q)))}`},o=r=>{const S=y.current.get(r.id);if(!S)return;const q=window.open("","_blank");if(!q){k.error("Unable to open print window. Please check your popup blocker.");return}q.document.write(`
2      <!DOCTYPE html>
3      <html>
4        <head>
5          <title>Room Access QR Code - ${t.room?.name||"Room"} - ${r.id}</title>
6          <style>
7            body {
8              font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
9              padding: 40px;
10              max-width: 500px;
11              margin: 0 auto;
12            }
13            .header { text-align: center; margin-bottom: 20px; }
14            .qr-container { text-align: center; padding: 20px; border: 2px solid #e5e7eb; border-radius: 12px; }
15            .details { margin-top: 20px; padding: 16px; background: #f9fafb; border-radius: 8px; }
16            .detail-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid #e5e7eb; }
17            .detail-row:last-child { border-bottom: none; }
18            .label { color: #6b7280; }
19            .value { font-weight: 500; }
20            .instructions { margin-top: 20px; padding: 16px; background: #eff6ff; border-radius: 8px; font-size: 14px; color: #1d4ed8; }
21            @media print {
22              body { padding: 20px; }
23            }
24          </style>
25        </head>
26        <body>
27          ${S.innerHTML}
28        </body>
29      </html>
30    `),q.document.close(),q.focus(),setTimeout(()=>{q.print(),q.close()},250)},E=r=>new Date(r.expires_at)<new Date,A=v.filter(r=>!E(r)&&r.is_active),x=f&&os(g),a=f&&!x;return e.jsx(J,{open:!0,onOpenChange:r=>
30!r&&b(),children:e.jsxs(W,{size:"lg",internalScroll:!0,children:[e.jsxs(Z,{children:[e.jsxs(ee,{className:"flex items-center gap-2",children:[e.jsx(ne,{className:"h-6 w-6 text-blue-600","aria-hidden":"true"}),"Room Access QR Code"]}),e.jsx(se,{children:t.room?.name||"Room"})]}),e.jsxs(ue,{className:"space-y-6",children:[e.jsx("div",{className:"bg-gray-50 rounded-lg p-4",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(H,{className:"h-5 w-5 text-gray-400"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-gray-900",children:t.room?.name||"Room"}),e.jsxs("div",{className:"text-xs text-gray-500",children:[t.room?.building&&`${t.room.building}`,t.room?.floor&&` - Floor ${t.room.floor}`]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ae,{className:"h-5 w-5 text-gray-400"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-gray-900",children:t.renterName}),e.jsx("div",{className:"text-xs text-gray-500",children:"Renter"})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(I,{className:"h-5 w-5 text-gray-400"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-gray-900",children:fe(t.startDatetime)}),e.jsx("div",{className:"text-xs text-gray-500",children:"Rental Date"})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(he,{className:"h-5 w-5 text-gray-400"}),e.jsxs("div",{children:[e.jsxs("div",{className:"text-sm font-medium text-gray-900",children:[K(t.startDatetime)," - ",K(t.endDatetime)]}),e.jsx("div",{className:"text-xs text-gray-500",children:"Time"})]})]})]})}),e.jsxs("div",{className:"p-4 bg-blue-50 rounded-lg border border-blue-200",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-3",children:"Generate New QR Code"}),e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-end",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{htmlFor:"rental-qr-duration",className:"block text-sm font-medium text-gray-700 mb-1",children:"Valid Duration (hours)"}),e.jsx("input",{type:"number",id:"rental-qr-duration",value:s,onChange:r=>m(parseInt(r.target.value)||24),min:"1",max:"168",className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:["QR code valid for ",s," hours (",Math.floor(s/24)," days)"]})]}),e.jsx(u,{onClick:l,disabled:C.isPending,className:"w-full sm:w-auto",children:C.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ye,{className:"h-4 w-4 mr-2 animate-spin"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"h-4 w-4 mr-2"}),"Generate QR Code"]})})]}),C.isError&&e.jsx(O,{tone:"danger",density:"compact",role:"alert",title:"QR code generation failed",className:"mt-4",actions:e.jsx(u,{type:"button",variant:"secondary",size:"sm",onClick:l,disabled:C.isPending,children:"Retry generation"}),children:F(C.error)})]}),R&&e.jsx(U,{state:"loading",density:"compact",title:"Loading QR codes",icon:e.jsx(ye,{className:"h-8 w-8 animate-spin text-blue-600"})}),a&&e.jsx(U,{state:"error",density:"compact",headingLevel:3,title:"QR codes could not be loaded",description:F(g),actions:e.jsx(u,{type:"button",variant:"secondary",onClick:()=>{j()},children:"Retry QR codes"})}),!R&&!a&&A.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Active QR Codes"}),e.jsx("div",{className:"space-y-6",children:A.map(r=>e.jsxs("div",{ref:S=>{S?y.current.set(r.id,S):y.current.delete(r.id)},"data-token-id":r.id,className:"bg-white rounded-lg border border-gray-200 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"header p-4 bg-gray-50 border-b border-gray-200 text-center",children:[e.jsxs("h4",{className:"font-semibold text-gray-900",children:[t.room?.name||"Room"," - Access QR Code"]}),e.jsxs("p",{className:"text-sm text-gray-600",children:[fe(t.startDatetime)," • ",K(t.startDatetime)," -"," ",K(t.endDatetime)]})]}),e.jsx("div",{className:"qr-container p-6 flex justify-center",children:e.jsx("div",{className:"p-4 bg-white border-4 border-gray-200 rounded-lg",children:e.jsx(Pe,{id:`qr-code-${r.id}`,value:N(r),size:200,level:"H",includeMargin:!0})})}),e.jsxs("div",{className:"details p-4 bg-gray-50 border-t border-gray-200",children:[e.jsxs("div",{className:"mb-3 flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"px-2 py-1 bg-green-100 text-green-800 rounded-full text-xs font-medium",children:"Active"}),e.jsxs("span",{className:"text-xs text-gray-500",children:[r.uses_count==="SINGLE_USE"?"Single Use":"Multiple Use"," (",r.used_count," used)"]})]}),e.jsxs("span",{className:"text-sm text-gray-600",children:["Expires: ",te(r.expires_at)]})]}),e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{htmlFor:`rental-access-url-${r.id}`,className:"block text-xs font-medium text-gray-500 mb-1",children:"Access URL"}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("input",{id:`rental-access-url-${r.id}`,type:"text",readOnly:!0,value:N(r),className:"min-w-0 flex-1 rounded-md border border-gray-300 bg-white px-3 py-2 font-mono text-sm"}),e.jsx(u,{type:"button",variant:"ghost",size:"icon",onClick:()=>p(r),"aria-label":n===r.id?`Access URL copied for token ${r.id}`:`Copy access URL for token ${r.id}`,children:n===r.id?e.jsx(Le,{className:"w-5 h-5 text-green-600"}):e.jsx($e,{className:"w-5 h-5"})})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>T(r),className:"w-full sm:flex-1",children:[e.jsx(Qe,{className:"h-4 w-4 mr-2"}),"Download PNG"]}),e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>o(r),"aria-label":`Print QR code for token ${r.id}`,className:"w-full sm:flex-1",children:[e.jsx(ds,{className:"h-4 w-4 mr-2"}),"Print"]})]})]}),e.jsx("div",{className:"instructions p-4 bg-blue-50 border-t border-blue-100",children:e.jsxs("p",{className:"text-sm text-blue-800",children:[e.jsx("strong",{children:"Instructions:"})," Scan this QR code at the room entrance to confirm your access. The code can be scanned multiple times during your rental peri
30od."]})})]},r.id))})]}),!R&&!a&&A.length===0&&e.jsx(Y,{reason:"no-data",tone:"stage",icon:ne,title:"No active QR codes for this rental",description:"Generate a code above and renters can scan it for access details.",density:"compact",className:"border-2 border-dashed"}),e.jsx(O,{tone:"warning",title:"How to Use",icon:e.jsx(X,{className:"h-5 w-5"}),children:e.jsxs("ul",{className:"text-sm text-amber-800 space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"Generate a QR code for the rental period"}),e.jsx("li",{children:"Download or print the QR code"}),e.jsx("li",{children:"Give the QR code to the renter"}),e.jsx("li",{children:"Renter scans the code at the room entrance with their phone"}),e.jsx("li",{children:"Access is logged for your records"}),e.jsx("li",{children:"QR codes expire after the specified duration for security"})]})})]}),e.jsx(re,{children:e.jsx(u,{variant:"outline",onClick:b,children:"Close"})})]})})}function ie(){const[t,b]=h.useState("ALL"),[s,m]=h.useState(null),[n,w]=h.useState(null),i=ce(),{data:y,isLoading:c,isError:v,refetch:R}=M({queryKey:["my-rentals",t],queryFn:()=>as({statusFilter:t==="ALL"?void 0:t,upcomingOnly:!1})}),f=y?.items||[],g=t!=="ALL",j=G({mutationFn:ss,onSuccess:()=>{k.success("Rental canceled successfully"),i.invalidateQueries({queryKey:["my-rentals"]}),m(null)},onError:o=>{k.error("Failed to cancel rental",{description:F(o)})}}),C=o=>{j.mutate(o)},l=o=>{switch(z[o].icon){case"Clock":return he;case"CheckCircle":return le;case"XCircle":return Fe;case"Ban":return xe;default:return X}},N=o=>{const E=z[o];return{yellow:"bg-yellow-100 text-yellow-800 border-yellow-200",green:"bg-green-100 text-green-800 border-green-200",red:"bg-red-100 text-red-800 border-red-200",gray:"bg-gray-100 text-gray-800 border-gray-200",blue:"bg-blue-100 text-blue-800 border-blue-200"}[E.color]||"bg-gray-100 text-gray-800"},p=o=>(o.status==="pending"||o.status==="approved")&&new Date(o.startDatetime)>new Date,T=o=>o.status==="approved"&&new Date(o.endDatetime)>new Date;return c?e.jsx(U,{state:"loading",density:"compact",title:"Loading your rentals"}):v?e.jsx(Ae,{title:"Couldn't load your rentals",description:"Your requests are still there — we just couldn't reach them. Nothing was changed.",onRetry:()=>{R()}}):e.jsxs("div",{className:"space-y-6",children:[e.jsx(P,{children:e.jsx(L,{className:"p-4",children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(u,{variant:t==="ALL"?"primary":"outline",size:"sm",onClick:()=>b("ALL"),"aria-pressed":t==="ALL",children:"All"}),Object.entries(z).map(([o,E])=>e.jsx(u,{variant:t===o?"primary":"outline",size:"sm",onClick:()=>b(o),"aria-pressed":t===o,children:E.label},o))]})})}),f.length===0?e.jsx(Y,{reason:g?"no-results":"no-data",tone:"stage",icon:I,title:"No rentals found",description:g?`You don't have any ${z[t]?.label.toLowerCase()} rentals.`:"You haven't made any room rental requests yet."}):e.jsx("div",{className:"space-y-4",children:f.map(o=>{const E=l(o.status);return e.jsxs(P,{className:"hover:shadow-md transition-shadow",children:[e.jsx(je,{className:"pb-3",children:e.jsxs("div",{className:"flex min-w-0 flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(be,{className:"break-words text-lg",children:o.room?.name||"Room"}),e.jsxs("p",{className:"text-sm text-gray-600 mt-1",children:[o.room?.building&&`${o.room.building} • `,o.room?.capacity&&`Capacity: ${o.room.capacity}`]})]}),e.jsxs("div",{className:`flex shrink-0 items-center gap-2 self-start rounded-full border px-3 py-1 ${N(o.status)}`,children:[e.jsx(E,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm font-medium",children:z[o.status]?.label??o.status??"Unknown"})]})]})}),e.jsxs(L,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(I,{className:"h-5 w-5 text-gray-400 mt-0.5"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-gray-700",children:"Start"}),e.jsxs("div",{className:"text-sm text-gray-600",children:[ve(o.startDatetime)," at ",K(o.startDatetime)]})]})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(I,{className:"h-5 w-5 text-gray-400 mt-0.5"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-gray-700",children:"End"}),e.jsxs("div",{className:"text-sm text-gray-600",children:[ve(o.endDatetime)," at ",K(o.endDatetime)]})]})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-gray-700 mb-1",children:"Purpose"}),e.jsx("p",{className:"break-words text-sm text-gray-600 [overflow-wrap:anywhere]",children:o.purposeDescription})]}),(T(o)||p(o))&&e.jsxs("div",{className:"flex flex-col gap-2 border-t pt-2 sm:flex-row sm:flex-wrap",children:[T(o)&&e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>w(o),className:"w-full text-blue-600 hover:text-blue-700 hover:bg-blue-50 sm:w-auto",children:[e.jsx(ne,{className:"h-4 w-4 mr-1"}),"Get Access QR"]}),p(o)&&e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>m(o.id),className:"w-full text-red-600 hover:text-red-700 hover:bg-red-50 sm:w-auto",children:[e.jsx(xe,{className:"h-4 w-4 mr-1"}),"Cancel Rental"]})]})]})]},o.id)})}),e.jsx(J,{open:!!s,onOpenChange:o=>!o&&m(null),children:e.jsxs(W,{size:"sm",children:[e.jsxs(Z,{children:[e.jsx(ee,{children:"Cancel Rental?"}),e.jsx(se,{children:"Are you sure you want to cancel this rental? This action cannot be undone."})]}),e.jsxs(re,{children:[e.jsx(u,{variant:"outline",onClick:()=>m(null),disabled:j.isPending,children:"Keep Rental"}),e.jsx(u,{variant:"danger",onClick:()=>s&&C(s),disabled:j.isPending,children:j.isPending?"Canceling...":"Yes, Cancel"})]})]})}),n&&e.jsx(xs,{rental:n,onClose:()=>w(null)})]})}
30function De({open:t,onOpenChange:b,preselectedRoom:s,onSuccess:m}){const{user:n}=ze(),w=ce(),[i,y]=h.useState({roomId:"",startDate:"",startTime:"",endDate:"",endTime:"",purposeDescription:"",notes:""}),[c,v]=h.useState({}),[R,f]=h.useState(!s),[g,j]=h.useState("idle"),[C,l]=h.useState(0);h.useEffect(()=>{t&&s?(y(d=>({...d,roomId:s.id})),f(!1)):t&&f(!0)},[t,s]),h.useEffect(()=>{t||(y({roomId:"",startDate:"",startTime:"",endDate:"",endTime:"",purposeDescription:"",notes:""}),v({}),j("idle"),l(0))},[t]);const{data:N,isLoading:p,isError:T,error:o,refetch:E}=M({queryKey:["rentable-rooms"],queryFn:()=>ge({pageSize:100}),enabled:t}),A=N?.items||[],x=A.find(d=>d.id===i.roomId)||(s?.id===i.roomId?s:null);h.useEffect(()=>{if(!!!(i.roomId&&i.startDate&&i.startTime&&i.endDate&&i.endTime)){j("idle");return}j("checking");const $=setTimeout(async()=>{try{const B=`${i.startDate}T${i.startTime}:00`,V=`${i.endDate}T${i.endTime}:00`,Ie=await rs(i.roomId,B,V);j(Ie.available?"available":"unavailable")}catch(B){console.error("Failed to check availability:",B),j("error")}},500);return()=>clearTimeout($)},[C,i.roomId,i.startDate,i.startTime,i.endDate,i.endTime]);const a=G({mutationFn:ts,onSuccess:()=>{k.success("Rental request submitted!",{description:x?.requiresApproval?"Your request has been submitted for approval. You will be notified once reviewed.":"Your rental has been confirmed."}),w.invalidateQueries({queryKey:["my-rentals"]}),w.invalidateQueries({queryKey:["room-availability"]}),m?.(),b(!1)},onError:d=>{k.error("Failed to submit rental request",{description:F(d)})}}),r=()=>{const d={};if(i.roomId||(d.roomId="Please select a room"),i.startDate||(d.startDate="Start date is required"),i.startTime||(d.startTime="Start time is required"),i.endDate||(d.endDate="End date is required"),i.endTime||(d.endTime="End time is required"),i.purposeDescription.trim()||(d.purposeDescription="Please describe the purpose of your rental"),i.startDate&&i.startTime&&i.endDate&&i.endTime){const $=new Date(`${i.startDate}T${i.startTime}`),B=new Date(`${i.endDate}T${i.endTime}`);$>=B&&(d.endTime="End time must be after start time"),$<new Date&&(d.startDate="Start time cannot be in the past")}const D=!!(i.roomId&&i.startDate&&i.startTime&&i.endDate&&i.endTime);return g==="unavailable"?d.general="The selected time slot is not available. Please choose a different time.":D&&g!=="available"&&(d.general="Availability could not be verified. Retry the check before submitting your request."),v(d),Object.keys(d).length===0},S=d=>{if(d.preventDefault(),!r())return;const D={roomId:i.roomId,startDatetime:`${i.startDate}T${i.startTime}:00`,endDatetime:`${i.endDate}T${i.endTime}:00`,purposeDescription:i.purposeDescription,notes:i.notes||void 0};a.mutate(D)},q=Oe(new Date,"yyyy-MM-dd");return e.jsx(J,{open:t,onOpenChange:b,children:e.jsxs(W,{size:"lg",internalScroll:!0,children:[e.jsxs(Z,{children:[e.jsxs(ee,{className:"flex items-center gap-2",children:[e.jsx(I,{className:"h-5 w-5 text-primary-600"}),"Request Room Rental"]}),e.jsxs(se,{children:["Fill out the form below to request a room rental."," ",x?.requiresApproval&&"Your request will be reviewed by an administrator."]})]}),e.jsxs("form",{onSubmit:S,className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs(ue,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{id:"rental-request-room-label",className:"text-sm font-medium leading-none",children:"Room *"}),s&&!R?e.jsxs("div",{className:"flex flex-col items-stretch gap-3 rounded-lg border bg-gray-50 p-3 sm:flex-row sm:items-center",role:"group","aria-labelledby":"rental-request-room-label",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-gray-900",children:s.name}),e.jsx("div",{className:"flex items-center gap-4 text-sm text-gray-600 mt-1",children:e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(pe,{className:"h-3.5 w-3.5"}),s.capacity," people"]})})]}),e.jsx(u,{type:"button",variant:"outline",size:"sm",onClick:()=>{y(d=>({...d,roomId:""})),f(!0),j("idle"),v(d=>({...d,roomId:void 0,general:void 0}))},children:"Change"})]}):e.jsxs(e.Fragment,{children:[T&&e.jsx(O,{tone:"danger",density:"compact",role:"alert",title:"Rooms could not be loaded",actions:e.jsx(u,{type:"button",variant:"secondary",size:"sm",onClick:()=>{E()},children:"Retry rooms"}),children:F(o)}),e.jsxs("select",{id:"room","aria-labelledby":"rental-request-room-label","aria-invalid":!!c.roomId,"aria-describedby":c.roomId?"rental-request-room-error":void 0,value:i.roomId,onChange:d=>{y(D=>({...D,roomId:d.target.value})),v(D=>({...D,roomId:void 0,general:void 0}))},disabled:p||T,className:`w-full h-10 px-3 rounded-md border text-sm ${c.roomId?"border-red-500":"border-gray-300"} focus:outline-none focus:ring-2 focus:ring-primary-500`,children:[e.jsx("option",{value:"",children:"Select a room..."}),A.map(d=>
30e.jsxs("option",{value:d.id,children:[d.name," (Capacity: ",d.capacity,")"]},d.id))]}),c.roomId&&e.jsx("p",{id:"rental-request-room-error",className:"text-red-500 text-sm",role:"alert",children:c.roomId})]})]}),e.jsxs("fieldset",{className:"space-y-4",children:[e.jsxs("legend",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(he,{className:"h-4 w-4 text-gray-400","aria-hidden":"true"}),"Date & Time *"]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",role:"group","aria-labelledby":"rental-request-start-date-label","aria-describedby":c.startDate?"rental-request-start-date-error":void 0,children:[e.jsx("span",{id:"rental-request-start-date-label",className:"text-sm text-gray-600",children:"Start Date"}),e.jsx(we,{value:i.startDate,onChange:d=>y(D=>({...D,startDate:d,endDate:d||D.endDate})),min:q,placeholder:"Select date"}),c.startDate&&e.jsx("p",{id:"rental-request-start-date-error",className:"text-red-500 text-xs",role:"alert",children:c.startDate})]}),e.jsxs("div",{className:"space-y-2",role:"group","aria-labelledby":"rental-request-start-time-label","aria-describedby":c.startTime?"rental-request-start-time-error":void 0,children:[e.jsx("span",{id:"rental-request-start-time-label",className:"text-sm text-gray-600",children:"Start Time"}),e.jsx(Ce,{value:i.startTime,onChange:d=>y(D=>({...D,startTime:d})),placeholder:"Select time"}),c.startTime&&e.jsx("p",{id:"rental-request-start-time-error",className:"text-red-500 text-xs",role:"alert",children:c.startTime})]}),e.jsxs("div",{className:"space-y-2",role:"group","aria-labelledby":"rental-request-end-date-label","aria-describedby":c.endDate?"rental-request-end-date-error":void 0,children:[e.jsx("span",{id:"rental-request-end-date-label",className:"text-sm text-gray-600",children:"End Date"}),e.jsx(we,{value:i.endDate,onChange:d=>y(D=>({...D,endDate:d})),min:i.startDate||q,placeholder:"Select date"}),c.endDate&&e.jsx("p",{id:"rental-request-end-date-error",className:"text-red-500 text-xs",role:"alert",children:c.endDate})]}),e.jsxs("div",{className:"space-y-2",role:"group","aria-labelledby":"rental-request-end-time-label","aria-describedby":c.endTime?"rental-request-end-time-error":void 0,children:[e.jsx("span",{id:"rental-request-end-time-label",className:"text-sm text-gray-600",children:"End Time"}),e.jsx(Ce,{value:i.endTime,onChange:d=>y(D=>({...D,endTime:d})),placeholder:"Select time"}),c.endTime&&e.jsx("p",{id:"rental-request-end-time-error",className:"text-red-500 text-xs",role:"alert",children:c.endTime})]})]}),g!=="idle"&&e.jsxs(O,{tone:g==="checking"?"neutral":g==="available"?"success":"danger",density:"compact",role:g==="unavailable"||g==="error"?"alert":"status",actions:g==="error"?e.jsx(u,{type:"button",variant:"secondary",size:"sm",onClick:()=>l(d=>d+1),children:"Retry availability"}):void 0,children:[g==="checking"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-current"}),e.jsx("span",{className:"text-sm",children:"Checking availability..."})]}),g==="available"&&e.jsxs(e.Fragment,{children:[e.jsx(cs,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm font-medium",children:"Time slot is available!"})]}),g==="unavailable"&&e.jsxs(e.Fragment,{children:[e.jsx(X,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm font-medium",children:"Time slot is not available. Please choose a different time."})]}),g==="error"&&e.jsxs(e.Fragment,{children:[e.jsx(X,{className:"h-4 w-4","aria-hidden":"true"}),e.jsx("span",{className:"text-sm font-medium",children:"Availability could not be verified. Retry before submitting."})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Ne,{htmlFor:"purpose",className:"flex items-center gap-1",children:[e.jsx(Se,{className:"h-4 w-4 text-gray-400"}),"Purpose of Rental *"]}),e.jsx("textarea",{id:"purpose",value:i.purposeDescription,onChange:d=>y(D=>({...D,purposeDescription:d.target.value})),placeholder:"e.g., Bible study, prayer meeting, birthday party...",rows:3,className:`w-full px-3 py-2 border rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-primary-500 ${c.purposeDescription?"border-red-500":"border-gray-300"}`,"aria-invalid":!!c.purposeDescription,"aria-describedby":c.purposeDescription?"rental-request-purpose-error":void 0}),c.purposeDescription&&e.jsx("p",{id:"rental-request-purpose-error",className:"text-red-500 text-sm",role:"alert",children:c.purposeDescription})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ne,{htmlFor:"notes",children:"Additional Notes (Optional)"}),e.jsx("textarea",{id:"notes",value:i.notes,onChange:d=>y(D=>({...D,notes:d.target.value})),placeholder:"Any special requirements or additional information...",rows:2,className:"w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-primary-500"})]}),n&&e.jsxs("div",{className:"bg-gray-50 p-4 rounded-lg space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-gray-600",children:"Renter Information"}),e.jsxs("div",{className:"text-sm",children:[e.jsx("p",{className:"font-medium text-gray-900",children:n.full_name}),e.jsx("p",{className:"text-gray-600",children:n.email})]})]}),x?.requiresApproval&&e.jsx(O,{tone:"warning",density:"compact",title:"Ap
30proval required",children:e.jsxs("p",{children:[e.jsx("strong",{children:"Note:"})," This room requires approval. You will receive a notification once your request has been reviewed."]})}),c.general&&e.jsx(O,{tone:"danger",density:"compact",role:"alert",icon:e.jsx(X,{className:"h-4 w-4"}),children:c.general})]}),e.jsxs(re,{className:"border-t border-gray-100 pt-4",children:[e.jsx(u,{type:"button",variant:"outline",onClick:()=>b(!1),disabled:a.isPending,children:"Cancel"}),e.jsx(u,{type:"submit",disabled:a.isPending||g!=="available",children:a.isPending?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2"}),"Submitting..."]}):"Submit Request"})]})]})]})})}const de='data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="400" height="300" viewBox="0 0 400 300"%3E%3Crect fill="%23f3f4f6" width="400" height="300"/%3E%3Cg fill="%239ca3af"%3E%3Crect x="175" y="120" width="50" height="60"/%3E%3Crect x="140" y="90" width="120" height="30"/%3E%3C/g%3E%3C/svg%3E';function us({room:t,onRequestRental:b,onViewAvailability:s}){const m=[...t.amenitiesList||[],...t.equipmentList||[],...t.features||[]].slice(0,4);return e.jsxs(P,{className:"overflow-hidden hover:shadow-md transition-shadow",children:[e.jsxs("div",{className:"relative aspect-[16/10] bg-gray-100",children:[e.jsx("img",{src:t.imageUrl||de,alt:t.name,className:"w-full h-full object-cover",onError:n=>{n.target.src=de}}),t.requiresApproval&&e.jsx("div",{className:"absolute top-2 right-2 bg-amber-500 text-white text-xs font-medium px-2 py-1 rounded-full",children:"Requires Approval"}),t.availableForPublic&&e.jsxs("div",{className:"absolute top-2 left-2 bg-green-500 text-white text-xs font-medium px-2 py-1 rounded-full flex items-center gap-1",children:[e.jsx(le,{className:"w-3 h-3"}),"Public"]})]}),e.jsxs(L,{className:"p-4",children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("h3",{className:"font-semibold text-lg text-gray-900",children:t.name}),(t.building||t.floor)&&e.jsxs("p",{className:"text-sm text-gray-500 flex items-center gap-1 mt-1",children:[e.jsx(Te,{className:"w-3.5 h-3.5"}),[t.building,t.floor].filter(Boolean).join(" • ")]})]}),e.jsx("div",{className:"flex items-center gap-4 mb-3",children:e.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-gray-700",children:[e.jsx(pe,{className:"w-4 h-4 text-gray-400"}),e.jsxs("span",{children:["Up to ",t.capacity," people"]})]})}),t.description&&e.jsx("p",{className:"text-sm text-gray-600 mb-3 line-clamp-2",children:t.description}),m.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-4",children:[m.map((n,w)=>e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-700",children:n},w)),(t.amenitiesList?.length||0)+(t.equipmentList?.length||0)+(t.features?.length||0)>4&&e.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-500",children:["+",(t.amenitiesList?.length||0)+(t.equipmentList?.length||0)+(t.features?.length||0)-4," ","more"]})]}),e.jsxs("div",{className:"flex gap-2 pt-2 border-t",children:[e.jsxs(u,{variant:"outline",size:"sm",className:"flex-1",onClick:()=>s(t),children:[e.jsx(I,{className:"w-4 h-4 mr-1.5"}),"Availability"]}),e.jsx(u,{size:"sm",className:"flex-1",onClick:()=>b(t),children:"Request Rental"})]})]})]})}function hs(){return e.jsxs(P,{className:"overflow-hidden",children:[e.jsx("div",{className:"aspect-[16/10] bg-gray-200 animate-pulse"}),e.jsxs(L,{className:"p-4 space-y-3",children:[e.jsx("div",{className:"h-6 bg-gray-200 rounded animate-pulse w-3/4"}),e.jsx("div",{className:"h-4 bg-gray-200 rounded animate-pulse w-1/2"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"h-4 bg-gray-200 rounded animate-pulse w-24"}),e.jsx("div",{className:"h-4 bg-gray-200 rounded animate-pulse w-20"})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx("div",{className:"h-8 bg-gray-200 rounded animate-pulse flex-1"}),e.jsx("div",{className:"h-8 bg-gray-200 rounded animate-pulse flex-1"})]})]})]})}function ps(){const[t,b]=h.useState(""),[s,m]=h.useState(null),[n,w]=h.useState(!1),[i,y]=h.useState(null),[c,v]=h.useState(null),[R,f]=h.useState(!1),{data:g,isLoading:j,error:C,refetch:l}=M({queryKey:["rentable-rooms",s],queryFn:()=>ge({pageSize:50,minCapacity:s||void 0})}),N=g?.items||[],p=N.filter(r=>{if(!t.trim())return!0;const S=t.toLowerCase();return r.name.toLowerCase().includes(S)||r.building?.toLowerCase().includes(S)||r.description?.toLowerCase().includes(S)||r.amenitiesList?.some(q=>q.toLowerCase().includes(S))||r.features?.some(q=>q.toLowerCase().includes(S))}),T=r=>{v(r),f(!0)},o=r=>{y(r)},E=()=>{y(null)},A=()=>{l()},x=()=>{b(""),m(null)},a=t||s;return j?e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex items-center gap-4",children:e.jsx("div",{className:"flex-1",children:e.jsx(Ue,{className:"h-10 w-full max-w-md"})})}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:[1,2,3,4,5,6].map(r=>e.jsx(hs,{},r))})]}):C?e.jsx(Ae,{title:"Couldn't load rooms",description:"The room list is unavailable right now. Nothing was changed.",onRetry:()=>
30{l()}}):N.length===0?e.jsx(Y,{reason:"no-data",tone:"stage",icon:H,title:"No rooms available",description:"There are no rooms open for rental yet — check back later or ask an administrator."}):i?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-col items-stretch justify-between gap-2 sm:flex-row sm:items-center",children:[e.jsx(u,{variant:"outline",onClick:E,children:"← Back to Rooms"}),e.jsx(u,{onClick:()=>T(i),children:"Request Rental"})]}),e.jsx("div",{className:"bg-white rounded-lg border p-4",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("img",{src:i.imageUrl||de,alt:i.name,className:"w-24 h-24 rounded-lg object-cover",onError:r=>{r.target.src=de}}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:i.name}),(i.building||i.floor)&&e.jsxs("p",{className:"text-sm text-gray-500 flex items-center gap-1 mt-1",children:[e.jsx(Te,{className:"w-3.5 h-3.5"}),[i.building,i.floor].filter(Boolean).join(" • ")]}),e.jsx("div",{className:"flex items-center gap-4 mt-2",children:e.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-gray-700",children:[e.jsx(pe,{className:"w-4 h-4 text-gray-400"}),e.jsxs("span",{children:["Up to ",i.capacity," people"]})]})})]})]})}),e.jsxs("div",{className:"bg-white rounded-lg border",children:[e.jsxs("div",{className:"p-4 border-b",children:[e.jsxs("h3",{className:"font-semibold text-gray-900 flex items-center gap-2",children:[e.jsx(I,{className:"w-5 h-5 text-primary-600"}),"Room Availability"]}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"Green days are available for booking. Red days have existing events or rentals."})]}),e.jsx("div",{className:"p-4",children:e.jsx(ke,{roomId:i.id,highlightAvailable:!0})})]}),e.jsx(De,{open:R,onOpenChange:f,preselectedRoom:c,onSuccess:A})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4",children:[e.jsxs("div",{className:"relative flex-1 max-w-md",children:[e.jsx(oe,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400","aria-hidden":"true"}),e.jsx(Q,{id:"browse-rooms-search",type:"text",placeholder:"Search rooms by name, location, or amenities...","aria-label":"Search rooms",value:t,onChange:r=>b(r.target.value),className:"pl-9"}),t&&e.jsx("button",{type:"button",onClick:()=>b(""),className:"absolute right-0 top-1/2 inline-flex min-h-10 min-w-10 -translate-y-1/2 items-center justify-center rounded-md text-gray-400 hover:text-gray-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-600","aria-label":"Clear room search",children:e.jsx(xe,{className:"w-4 h-4","aria-hidden":"true"})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>w(!n),className:n?"bg-gray-100":"",children:[e.jsx(ms,{className:"w-4 h-4 mr-1.5"}),"Filters",a&&e.jsx("span",{className:"ml-1.5 bg-primary-100 text-primary-700 text-xs font-medium px-1.5 py-0.5 rounded-full",children:(t?1:0)+(s?1:0)})]}),a&&e.jsx(u,{variant:"ghost",size:"sm",onClick:x,children:"Clear All"})]})]}),n&&e.jsx("div",{className:"bg-gray-50 rounded-lg p-4 flex flex-wrap gap-4",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{htmlFor:"browse-rooms-capacity",className:"text-sm font-medium text-gray-700",children:"Minimum Capacity"}),e.jsxs("select",{id:"browse-rooms-capacity",value:s||"",onChange:r=>m(r.target.value?parseInt(r.target.value):null),className:"h-9 px-3 rounded-md border border-gray-300 text-sm focus:outline-none focus:ring-2 focus:ring-primary-500",children:[e.jsx("option",{value:"",children:"Any"}),e.jsx("option",{value:"10",children:"10+ people"}),e.jsx("option",{value:"25",children:"25+ people"}),e.jsx("option",{value:"50",children:"50+ people"}),e.jsx("option",{value:"100",children:"100+ people"}),e.jsx("option",{value:"200",children:"200+ people"})]})]})}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("p",{className:"text-sm text-gray-600",children:p.length===N.length?`${N.length} room${N.length!==1?"s":""} available`:`Showing ${p.length} of ${N.length} rooms`})}),p.length===0&&a&&e.jsx(Y,{reason:"no-results",tone:"stage",icon:oe,title:"No matching rooms",description:"Other rooms may sit outside the current filters.",cta:{label:"Clear filters",onClick:x}}),p.length>0&&e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:p.map(r=>e.jsx(us,{room:r,onRequestRental:T,onViewAvailability:o},r.id))}),e.jsx(De,{open:R,onOpenChange:f,preselectedRoom:c,onSuccess:A})]})}function gs(){const[t,b]=h.useState(""),[s,m]=h.useState("ALL"),{data:n,isLoading:w,isError:i,error:y,refetch:c}=M({queryKey:["admin-rentals-all",s,t],queryFn:()=>Ee({statusFilter:s==="ALL"?void 0:s,search:t||void 0})}),{data:v,isError:R,error:f,refetch:g}=M({queryKey:["rental-statistics"],queryFn:qe}),j=n?.items||[],C=!!t||s!=="ALL";return e.jsxs("div",{className:"space-y-6",children:[R&&e.jsx(O,{tone:"danger",role:"alert",title:"Rental statistics could not be loaded",actions:e.jsx(u,{type:"button",variant:"secondary",onClick:()=>{g()},children:"Retry statistics"}),children:F(f)}),v&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsx(P,{children:e.jsx(L,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600",children:"Total Rentals"}),e.jsx("p",{className:"text-2xl font-bold text-gray-900",children:(v?.approvedRentals||0)+(v?.pendingApprovals||0)})]}),e.jsx(H,{className:"h-8 w-8 text-gray-400 opacity-50"})]})})}),e.jsx(P,{children:e.jsx(L,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600",children:"Approved"}),e.jsx("p",{className:"text-2xl font-bold text-green-600",children:v?.approvedRentals||0})]}),e.jsx(I,{className:"h-8 w-8 text-green-600 opacity-50"})]})})}),e.jsx(P,{children:e.jsx(L,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600",children:"Pending"}),e.jsx("p",{className:"text-2xl font-bold text-blue-600",children:v?.pendingApprovals||0})]}),e.jsx(ae,{className:"h-8 w-8 text-blue-600 opacity-50"})]})})}),e.jsx(P,{children:e.jsx(L,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-gray-600",children:"Upcoming"}),e.jsx("p",{className:"text-2xl font-bold text-purple-600",children:v?.upcomingRentals||0})]}),e.jsx(I,{className:"h-8 w-8 text-purple-600 opacity-50"})]})})})]}),e.jsx(P,{children:e.jsx(L,{className:"p-4",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"relative md:col-span-2",children:[e.jsx(oe,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 transform text-gray-400","aria-hidden":"true"}),e.jsx(Q,{id:"all-rentals-search",type:"text",placeholder:"Search by renter name, room, or purpose...","aria-label":"Search rentals",value:t,onChange:l=>b(l.target.value),className:"pl-10"})]}),e.jsx("label",{htmlFor:"all-rentals-status",className:"sr-only",children:"Filter rentals by status"}),e.jsxs("select",{id:"all-rentals-status",value:s,onChange:l=>m(l.target.value),className:"px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"ALL",children:"All Statuses"}
30),Object.entries(z).map(([l,N])=>e.jsx("option",{value:l,children:N.label},l))]})]})})}),w?e.jsx(U,{state:"loading",density:"compact",title:"Loading rentals",description:"Please wait while the rental list is retrieved."}):i?e.jsx(U,{state:"error",density:"compact",title:"Rentals could not be loaded",description:F(y),actions:e.jsx(u,{type:"button",variant:"secondary",onClick:()=>{c()},children:"Retry rentals"})}):j.length===0?e.jsx(Y,{reason:C?"no-results":"no-data",tone:"stage",icon:I,title:"No rentals found",description:C?"No rentals match your current filters.":"No rooms have been booked yet."}):e.jsx("div",{className:"space-y-4",children:j.map(l=>e.jsxs(P,{className:"hover:shadow-md transition-shadow",children:[e.jsx(je,{className:"pb-3",children:e.jsxs("div",{className:"flex flex-col items-start justify-between gap-3 sm:flex-row",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs(be,{className:"flex min-w-0 items-center gap-2 break-words text-lg [overflow-wrap:anywhere]",children:[e.jsx(H,{className:"h-5 w-5 text-gray-400"}),l.room?.name||"Room"]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-2 break-words text-sm text-gray-600 [overflow-wrap:anywhere]",children:[e.jsx(ae,{className:"h-4 w-4"}),e.jsx("span",{children:l.renterName}),l.isExternalUser&&e.jsx(_,{variant:"secondary",className:"ml-2",children:"External"})]})]}),e.jsx(_,{variant:l.status==="pending"?"warning":l.status==="approved"?"success":l.status==="rejected"?"default":"secondary",children:z[l.status]?.label??l.status??"Unknown"})]})}),e.jsxs(L,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-600",children:"Start:"}),e.jsx("span",{className:"ml-2 font-medium",children:te(l.startDatetime)})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-600",children:"End:"}),e.jsx("span",{className:"ml-2 font-medium",children:te(l.endDatetime)})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-gray-700 mb-1",children:"Purpose:"}),e.jsx("p",{className:"break-words text-sm text-gray-600 [overflow-wrap:anywhere]",children:l.purposeDescription})]}),l.isExternalUser&&e.jsxs("div",{className:"bg-gray-50 p-3 rounded-lg text-sm",children:[e.jsx("div",{className:"font-medium text-gray-700 mb-1",children:"Contact Information:"}),e.jsxs("div",{className:"space-y-1 text-gray-600",children:[l.renterEmail&&e.jsxs("div",{children:["Email: ",l.renterEmail]}),l.renterPhone&&e.jsxs("div",{children:["Phone: ",l.renterPhone]})]})]})]})]},l.id))})]})}function js(){const[t,b]=h.useState(null),[s,m]=h.useState(!1),[n,w]=h.useState(!1),[i,y]=h.useState(""),c=ce(),{data:v,isLoading:R,isError:f,error:g,refetch:j}=M({queryKey:["admin-rentals","pending"],queryFn:()=>Ee({statusFilter:"pending"})}),C=v?.items||[],l=C.length,N=G({mutationFn:x=>is(x),onSuccess:()=>{k.success("Rental approved successfully"),c.invalidateQueries({queryKey:["admin-rentals"]}),c.invalidateQueries({queryKey:["rental-statistics"]}),m(!1),b(null)},onError:x=>{k.error("Failed to approve rental",{description:F(x)})}}),p=G({mutationFn:({rentalId:x,reason:a})=>ns(x,{rejectionReason:a}),onSuccess:()=>{k.success("Rental rejected"),c.invalidateQueries({queryKey:["admin-rentals"]}),c.invalidateQueries({queryKey:["rental-statistics"]}),w(!1),b(null),y("")},onError:x=>{k.error("Failed to reject rental",{description:F(x)})}}),T=x=>{b(x),m(!0)},o=x=>{b(x),w(!0)},E=()=>{t&&N.mutate(t.id)},A=()=>{t&&i.trim()?p.mutate({rentalId:t.id,reason:i}):k.error("Please provide a rejection reason")};return e.jsxs("div",{className:"space-y-6",children:[l>0&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(_,{variant:"warning",className:"text-base px-3 py-1",children:[l," pending approval",l!==1?"s":""]})}),R?e.jsx(U,{state:"loading",density:"compact",title:"Loading pending rentals"}):f?e.jsx(U,{state:"error",density:"compact",title:"Pending rentals could not be loaded",description:F(g),actions:e.jsx(u,{type:"button",variant:"secondary",onClick:()=>{j()},children:"Retry pending rentals"})}):C.length===0?e.jsx(Y,{reason:"no-data",tone:"stage",icon:le,title:"All caught up",description:"There are no pending rental requests at this time."}):e.jsx("div",{className:"space-y-4",children:C.map(x=>e.jsxs(P,{className:"hover:shadow-md transition-shadow border-l-4 border-l-amber-400",children:[e.jsx(je,{className:"pb-3",children:e.jsxs("div",{className:"flex min-w-0 flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs(be,{className:"flex min-w-0 items-start gap-2 break-words text-lg",children:[e.jsx(H,{className:"h-5 w-5 text-gray-400"}),x.room?.name||"Room"]}),e.jsxs("div",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-2 text-sm text-gray-600",children:[e.jsx(ae,{className:"h-4 w-4"}),e.jsx("span",{children:x.renterName}),x.isExternalUser&&e.jsx(_,{variant:"secondary",className:"ml-2",children:"Exter
30nal"})]})]}),e.jsx(_,{variant:"warning",children:"Pending"})]})}),e.jsxs(L,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-600",children:"Start:"}),e.jsx("span",{className:"ml-2 font-medium",children:te(x.startDatetime)})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-gray-600",children:"End:"}),e.jsx("span",{className:"ml-2 font-medium",children:te(x.endDatetime)})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-gray-700 mb-1",children:"Purpose:"}),e.jsx("p",{className:"break-words text-sm text-gray-600 [overflow-wrap:anywhere]",children:x.purposeDescription})]}),x.isExternalUser&&e.jsxs("div",{className:"bg-gray-50 p-3 rounded-lg text-sm",children:[e.jsx("div",{className:"font-medium text-gray-700 mb-1",children:"Contact Information:"}),e.jsxs("div",{className:"space-y-1 text-gray-600",children:[x.renterEmail&&e.jsxs("div",{children:["Email: ",x.renterEmail]}),x.renterPhone&&e.jsxs("div",{children:["Phone: ",x.renterPhone]})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 border-t pt-2 sm:flex-row",children:[e.jsxs(u,{variant:"outline",size:"sm",onClick:()=>o(x),className:"flex-1 text-red-600 hover:text-red-700 hover:bg-red-50",children:[e.jsx(Fe,{className:"h-4 w-4 mr-1"}),"Reject"]}),e.jsxs(u,{variant:"primary",size:"sm",onClick:()=>T(x),className:"flex-1",children:[e.jsx(le,{className:"h-4 w-4 mr-1"}),"Approve"]})]})]})]},x.id))}),e.jsx(J,{open:s&&!!t,onOpenChange:x=>{x||(m(!1),b(null))},children:e.jsxs(W,{size:"sm",children:[e.jsxs(Z,{children:[e.jsx(ee,{children:"Approve Rental?"}),e.jsxs(se,{children:["Approve rental for ",e.jsx("strong",{children:t?.renterName})," at"," ",e.jsx("strong",{children:t?.room?.name}),"?"]})]}),e.jsxs(re,{children:[e.jsx(u,{variant:"outline",onClick:()=>m(!1),children:"Cancel"}),e.jsx(u,{onClick:E,disabled:N.isPending,children:N.isPending?"Approving...":"Approve"})]})]})}),e.jsx(J,{open:n&&!!t,onOpenChange:x=>{x||(w(!1),b(null),y(""))},children:e.jsxs(W,{size:"sm",children:[e.jsxs(Z,{children:[e.jsx(ee,{children:"Reject Rental?"}),e.jsxs(se,{children:["Reject rental for ",e.jsx("strong",{children:t?.renterName}),"?"]})]}),e.jsxs(ue,{children:[e.jsx("label",{htmlFor:"rental-rejection-reason",className:"block text-sm font-medium text-gray-700 mb-1",children:"Rejection Reason *"}),e.jsx("textarea",{id:"rental-rejection-reason",value:i,onChange:x=>y(x.target.value),placeholder:"Please provide a reason for rejection...",rows:3,className:"w-full rounded-md border border-gray-300 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),e.jsxs(re,{children:[e.jsx(u,{variant:"outline",onClick:()=>{w(!1),y("")},disabled:p.isPending,children:"Cancel"}),e.jsx(u,{variant:"danger",onClick:A,disabled:p.isPending||!i.trim(),children:p.isPending?"Rejecting...":"Reject"})]})]})})]})}function bs({onClose:t,onSuccess:b}){const[s,m]=h.useState({roomId:"",startDate:"",startTime:"",endDate:"",endTime:"",purposeDescription:"",notes:"",isExternal:!1,personId:"",renterName:"",renterEmail:"",renterPhone:"",autoApprove:!0}),[n,w]=h.useState({}),[i,y]=h.useState(!1),[c,v]=h.useState(""),[R,f]=h.useState(!1),[g,j]=h.useState(-1),{data:C}=M({queryKey:["rentable-rooms-admin"],queryFn:()=>ge({pageSize:100})}),{data:l}=M({queryKey:["member-search",c],queryFn:async()=>{if(!c||c.length<2)return[];const a=await Ge.get("/people",{params:{search:c,page_size:10}});return(a.data.data||a.data.items||[]).map(r=>({id:r.id,firstName:r.first_name||r.firstName||"",lastName:r.last_name||r.lastName||"",email:r.email||""}))},enabled:c.length>=2&&!s.isExternal}),N=C?.items||[],p=l||[],T=G({mutationFn:ls,onSuccess:()=>{k.success("Rental created successfully"),b?.(),t()},onError:a=>{k.error("Failed to create rental",{description:F(a)})}}),o=()=>{const a={};if(s.roomId||(a.roomId="Room is required"),s.startDate||(a.startDate="Start date is required"),s.startTime||(a.startTime="Start time is required"),s.endDate||(a.endDate="End date is required"),s.endTime||(a.endTime="End time is required"),s.purposeDescription.trim()||(a.purposeDescription="Purpose is required"),s.isExternal?(s.renterName.trim()||(a.renterName="Renter name is required"),s.renterEmail.trim()||(a.renterEmail="Renter email is required")):s.personId||(a.personId="Select a church member"),s.startDate&&s.startTime&&s.endDate&&s.endTime){const r=new Date(`${s.startDate}T${s.startTime}`),S=new Date(`${s.endDate}T${s.endTime}`);r>=S&&(a.endDate="End time must be after start time")}return w(a),Object.keys(a).length===0},E=a=>
30{if(a.preventDefault(),!o())return;const r={roomId:s.roomId,startDatetime:`${s.startDate}T${s.startTime}:00`,endDatetime:`${s.endDate}T${s.endTime}:00`,purposeDescription:s.purposeDescription,notes:s.notes||void 0,isExternal:s.isExternal,personId:s.isExternal?void 0:s.personId,renterName:s.isExternal?s.renterName:void 0,renterEmail:s.isExternal?s.renterEmail:void 0,renterPhone:s.isExternal&&s.renterPhone?s.renterPhone:void 0,autoApprove:s.autoApprove};T.mutate(r)},A=a=>{m({...s,personId:a.id,renterName:`${a.firstName} ${a.lastName}`,renterEmail:a.email}),v(`${a.firstName} ${a.lastName}`),f(!1),j(-1)},x=a=>{if(a.key==="Escape"){f(!1),j(-1);return}p.length!==0&&(a.key==="ArrowDown"?(a.preventDefault(),f(!0),j(r=>(r+1)%p.length)):a.key==="ArrowUp"?(a.preventDefault(),f(!0),j(r=>r<=0?p.length-1:r-1)):a.key==="Home"?(a.preventDefault(),j(0)):a.key==="End"?(a.preventDefault(),j(p.length-1)):a.key==="Enter"&&g>=0&&(a.preventDefault(),A(p[g])))};return e.jsxs(Ke,{isOpen:!0,onClose:t,title:"Create Rental",size:"lg",children:[e.jsx("p",{className:"mb-5 text-sm text-gray-600",children:"Admin-created rental booking"}),e.jsxs("form",{onSubmit:E,className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"admin-rental-room",className:"block text-sm font-medium text-gray-700 mb-1",children:"Room *"}),e.jsxs("select",{id:"admin-rental-room",value:s.roomId,onChange:a=>m({...s,roomId:a.target.value}),className:`w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 ${n.roomId?"border-red-500":"border-gray-300"}`,"aria-invalid":!!n.roomId,"aria-describedby":n.roomId?"admin-rental-room-error":void 0,children:[e.jsx("option",{value:"",children:"Select a room..."}),N.map(a=>e.jsxs("option",{value:a.id,children:[a.name," ",a.building?`(${a.building})`:""," — capacity ",a.capacity]},a.id))]}),n.roomId&&e.jsx("p",{id:"admin-rental-room-error",role:"alert",className:"text-red-500 text-sm mt-1",children:n.roomId})]}),e.jsxs("div",{className:"flex flex-col gap-2 rounded-lg bg-gray-100 p-1 sm:flex-row",role:"group","aria-label":"Renter type",children:[e.jsxs("button",{type:"button",onClick:()=>m({...s,isExternal:!1,personId:"",renterName:"",renterEmail:"",renterPhone:""}),"aria-pressed":!s.isExternal,className:`flex-1 flex items-center justify-center gap-2 py-2 px-4 rounded-md text-sm font-medium transition-colors ${s.isExternal?"text-gray-600 hover:text-gray-900":"bg-white shadow text-blue-700"}`,children:[e.jsx(ae,{className:"h-4 w-4"}),"Church Member"]}),e.jsxs("button",{type:"button",onClick:()=>m({...s,isExternal:!0,personId:"",renterName:"",renterEmail:"",renterPhone:""}),"aria-pressed":s.isExternal,className:`flex-1 flex items-center justify-center gap-2 py-2 px-4 rounded-md text-sm font-medium transition-colors ${s.isExternal?"bg-white shadow text-blue-700":"text-gray-600 hover:text-gray-900"}`,children:[e.jsx(_e,{className:"h-4 w-4"}),"External Renter"]})]}),s.isExternal?e.jsxs("div",{className:"space-y-4 p-4 border border-gray-200 rounded-lg",children:[e.jsx("h4",{className:"font-medium text-gray-900",children:"External Renter Info"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"admin-external-renter-name",className:"block text-sm font-medium text-gray-700 mb-1",children:"Name *"}),e.jsx(Q,{id:"admin-external-renter-name",value:s.renterName,onChange:a=>m({...s,renterName:a.target.value}),placeholder:"John Smith",className:n.renterName?"border-red-500":"","aria-invalid":!!n.renterName,"aria-describedby":n.renterName?"admin-external-renter-name-error":void 0}),n.renterName&&e.jsx("p",{id:"admin-external-renter-name-error",className:"text-red-500 text-sm mt-1",role:"alert",children:n.renterName})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"admin-external-renter-email",className:"block text-sm font-medium text-gray-700 mb-1",children:"Email *"}),e.jsx(Q,{id:"admin-external-renter-email",type:"email",value:s.renterEmail,onChange:a=>m({...s,renterEmail:a.target.value}),placeholder:"[email protected]",className:n.renterEmail?"border-red-500":"","aria-invalid":!!n.renterEmail,"aria-describedby":n.renterEmail?"admin-external-renter-email-error":void 0}),n.renterEmail&&e.jsx("p",{id:"admin-external-renter-email-error",className:"text-red-500 text-sm mt-1",role:"alert",children:n.renterEmail})]}),e.jsxs("div",{className:"md:col-span-2",children:[e.jsx("label",{htmlFor:"admin-external-renter-phone",className:"block text-sm font-medium text-gray-700 mb-1",children:"Phone"}),e.jsx(Q,{id:"admin-external-renter-phone",value:s.renterPhone,onChange:a=>m({...s,renterPhone:a.target.value}),placeholder:"+1-555-123-4567"})]})]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"admin-rental-member-search",className:"block text-sm font-medium text-gray-700",children:"Search Member *"}),e.jsxs("div",{className:"relative",children:[e.jsx(Q,{id:"admin-rental-member-search",role:"combobox","aria-autocomplete":"list","aria-expanded":R&&p.length>0&&!s.personId,"aria-controls":R&&p.length>0&&!s.personId?"admin-rental-member-results":void 0,"aria-activedescendant":g>=0?`admin-rental-member-option-${p[g]?.id}`:void 0,"aria-invalid":!!n.personId,"aria-describedby":n.personId?"admin-rental-member-error":void 0,value:c,onChange:a=>{v(a.target.value),f(!0),j(-1),s.personId&&m({...s,personId:"",renterName:"",renterEmail:""})},onFocus:()=>f(!0),onKeyDown:x,placeholder:"Type a member name...",className:n.personId?"border-red-500":""}),R&&p.length>0&&!s.personId&&e.jsx("div",{id:"admin-rental-member-results",role:"listbox","aria-label":"Member search results",className:"absolute z-10 mt-1 w-full bg-white border border-gray-200 rounded-md shadow-lg max-h-48 overflow-y-auto",children:p.map((a,r)=>
30e.jsxs("button",{id:`admin-rental-member-option-${a.id}`,type:"button",role:"option","aria-selected":g===r,onClick:()=>A(a),onMouseEnter:()=>j(r),className:`min-h-10 w-full px-4 py-2 text-left text-sm ${g===r?"bg-gray-100":"hover:bg-gray-50"}`,children:[e.jsxs("span",{className:"font-medium",children:[a.firstName," ",a.lastName]}),a.email&&e.jsx("span",{className:"text-gray-500 ml-2",children:a.email})]},a.id))})]}),s.personId&&e.jsxs("p",{className:"text-sm text-green-600",role:"status",children:["Selected: ",s.renterName," (",s.renterEmail,")"]}),n.personId&&e.jsx("p",{id:"admin-rental-member-error",className:"text-red-500 text-sm mt-1",role:"alert",children:n.personId})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("h3",{className:"font-semibold text-lg flex items-center",children:[e.jsx(I,{className:"h-5 w-5 mr-2 text-gray-400"}),"Date & Time"]}),s.roomId&&e.jsx(u,{type:"button",variant:"ghost",size:"sm",onClick:()=>y(!i),children:i?"Hide Calendar":"View Availability"})]}),i&&s.roomId&&e.jsx("div",{className:"mb-4",children:e.jsx(ke,{roomId:s.roomId,onDateSelect:a=>{const r=a.toISOString().split("T")[0];m({...s,startDate:r,endDate:r})},highlightAvailable:!0})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"admin-rental-start-date",className:"block text-sm font-medium text-gray-700 mb-1",children:"Start Date *"}),e.jsx(Q,{id:"admin-rental-start-date",type:"date",value:s.startDate,onChange:a=>m({...s,startDate:a.target.value}),className:n.startDate?"border-red-500":"","aria-invalid":!!n.startDate,"aria-describedby":n.startDate?"admin-rental-start-date-error":void 0}),n.startDate&&e.jsx("p",{id:"admin-rental-start-date-error",className:"text-red-500 text-sm mt-1",role:"alert",children:n.startDate})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"admin-rental-start-time",className:"block text-sm font-medium text-gray-700 mb-1",children:"Start Time *"}),e.jsx(Q,{id:"admin-rental-start-time",type:"time",value:s.startTime,onChange:a=>m({...s,startTime:a.target.value}),className:n.startTime?"border-red-500":"","aria-invalid":!!n.startTime,"aria-describedby":n.startTime?"admin-rental-start-time-error":void 0}),n.startTime&&e.jsx("p",{id:"admin-rental-start-time-error",className:"text-red-500 text-sm mt-1",role:"alert",children:n.startTime})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"admin-rental-end-date",className:"block text-sm font-medium text-gray-700 mb-1",children:"End Date *"}),e.jsx(Q,{id:"admin-rental-end-date",type:"date",value:s.endDate,onChange:a=>m({...s,endDate:a.target.value}),min:s.startDate||void 0,className:n.endDate?"border-red-500":"","aria-invalid":!!n.endDate,"aria-describedby":n.endDate?"admin-rental-end-date-error":void 0}),n.endDate&&e.jsx("p",{id:"admin-rental-end-date-error",className:"text-red-500 text-sm mt-1",role:"alert",children:n.endDate})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"admin-rental-end-time",className:"block text-sm font-medium text-gray-700 mb-1",children:"End Time *"}),e.jsx(Q,{id:"admin-rental-end-time",type:"time",value:s.endTime,onChange:a=>m({...s,endTime:a.target.value}),className:n.endTime?"border-red-500":"","aria-invalid":!!n.endTime,"aria-describedby":n.endTime?"admin-rental-end-time-error":void 0}),n.endTime&&e.jsx("p",{id:"admin-rental-end-time-error",className:"text-red-500 text-sm mt-1",role:"alert",children:n.endTime})]})]})]}),e.jsxs("div",{children:[e.jsxs("label",{htmlFor:"admin-rental-purpose",className:"block text-sm font-medium text-gray-700 mb-1",children:[e.jsx(Se,{className:"inline h-4 w-4 mr-1"}),"Purpose *"]}),e.jsx("textarea",{id:"admin-rental-purpose",value:s.purposeDescription,onChange:a=>m({...s,purposeDescription:a.target.value}),placeholder:"Staff meeting, community event, etc.",rows:3,className:`w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 ${n.purposeDescription?"border-red-500":"border-gray-300"}`,"aria-invalid":!!n.purposeDescription,"aria-describedby":n.purposeDescription?"admin-rental-purpose-error":void 0}),n.purposeDescription&&e.jsx("p",{id:"admin-rental-purpose-error",className:"text-red-500 text-sm mt-1",role:"alert",children:n.purposeDescription})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"admin-rental-notes",className:"block text-sm font-medium text-gray-700 mb-1",children:"Notes"}),e.jsx("textarea",{id:"admin-rental-notes",value:s.notes,onChange:a=>m({...s,notes:a.target.value}),placeholder:"Any special requests...",rows:2,className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),e.jsxs("div",{className:"flex items-center gap-3 p-4 bg-green-50 border border-green-200 rounded-lg",children:[e.jsx("input",{type:"checkbox",id:"autoApprove",checked:s.autoApprove,onChange:a=>m({...s,autoApprove:a.target.checked}),className:"w-4 h-4 text-green-600 rounded focus:ring-2 focus:ring-green-500"}),e.jsxs("label",{htmlFor:"autoApprove",className:"cursor-pointer",children:[e.jsx("span",{className:"font-medium text-gray-900",children:"Auto-approve"}),e.jsx("span",{className:"text-sm text-gray-600 ml-2",children:"(Skip approval workflow and confirm immediately)"})]})]}),e.jsxs("div",{className:"flex flex-col-reverse gap-3 pt-4 sm:flex-row",children:[e.jsx(u,{type:"button",variant:"outline",onClick:t,className:"w-full sm:flex-1",disabled:T.isPending,children:"Cancel"}),e.jsx(u,{type:"submit",className:"w-full sm:flex-1",disabled:T.isPending,children:T.isPending?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2"}),"Creating..."]}):"Create Rental"})]})]})]})}const me=[{key:"my-rentals",label:"My Rentals",icon:I,adminOnly:!1},{key:"browse",label:"Browse Rooms",icon:oe,adminOnly:!1},{key:"all",label:"All Rentals",icon:H,adminOnly:!0},{key:"pending",label:"Pending Approvals",icon:Xe,adminOnly:!0,showBadge:!0}],Re=["my-rentals","browse","all","pending"];function zs(){const{user:t}=He(),b=Ye(),s=ce(),{tab:m}=Ve(),n=t?.role==="super_admin"||t?.role==="admin"||t?.role==="staff",[w,i]=h.useState(!1),y=()=>
30{if(m&&Re.includes(m)){const l=m;return me.find(p=>p.key===l)?.adminOnly&&!n?"my-rentals":l}return"my-rentals"},[c,v]=h.useState(y),{data:R}=M({queryKey:["rental-statistics"],queryFn:qe,enabled:n}),f=R?.pendingApprovals||0;h.useEffect(()=>{if(m&&Re.includes(m)){const l=m;me.find(p=>p.key===l)?.adminOnly&&!n?(b("/rooms/my-rentals",{replace:!0}),v("my-rentals")):v(l)}},[m,n,b]);const g=l=>{v(l),b(`/rooms/${l}`,{replace:!0})},j=me.filter(l=>!l.adminOnly||n),C=()=>{switch(c){case"my-rentals":return e.jsx(ie,{});case"browse":return e.jsx(ps,{});case"all":return n?e.jsx(gs,{}):e.jsx(ie,{});case"pending":return n?e.jsx(js,{}):e.jsx(ie,{});default:return e.jsx(ie,{})}};return e.jsxs(Je,{children:[e.jsxs("div",{className:"mb-6 flex flex-col items-stretch justify-between gap-4 sm:flex-row sm:items-center",children:[e.jsx(We,{title:"Room Rentals",description:"Request and manage room rentals for your events and activities"}),n&&e.jsxs(u,{variant:"primary",onClick:()=>i(!0),children:[e.jsx(Ze,{className:"h-4 w-4 mr-1","aria-hidden":"true"}),"New Rental"]})]}),e.jsx("div",{className:"mb-6 flex flex-wrap gap-3",role:"group","aria-label":"Rental views",children:j.map(l=>{const N=l.icon,p=c===l.key;return e.jsxs(u,{variant:p?"primary":"secondary",onClick:()=>g(l.key),className:p?"":"bg-white","aria-pressed":p,children:[e.jsx(N,{className:"mr-2 h-4 w-4","aria-hidden":"true"}),l.label,l.showBadge&&f>0&&e.jsx(_,{variant:"danger",className:"ml-2 px-1.5 py-0.5 text-xs min-w-[1.25rem] text-center",children:f})]},l.key)})}),C(),w&&e.jsx(bs,{onClose:()=>i(!1),onSuccess:()=>{s.invalidateQueries({queryKey:["admin-rentals"]}),s.invalidateQueries({queryKey:["rental-statistics"]}),s.invalidateQueries({queryKey:["my-rentals"]})}})]})}export{zs as RoomRentals};

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.