1import{e as g,P as H,f as F,au as E,bl as A,K as C,t as x,j as e,B as j,L as $,C as B,d as I,a as K,b as P,k as S,ay as R,ar as M,aD as U,r as z,h as _,I as b,bm as V,aN as G,ab as D,ac as L,ad as O,ae as Q,af as q}from"./index-DHwBXtP2.js";import{S as W}from"./ShareBlock-CGHZcX59.js";import{l as Y,d as J,s as X,a as Z,b as ee,c as se,e as ae}from"./booking-calendars.functions-C4JBLX-j.js";import{C as te}from"./calendar-days-DrfArz66.js";import{C as ne}from"./calendar-plus-DFqwP2jP.js";import{S as ie}from"./settings-2-DxqHAQDa.js";const T=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function pe(){const o=g(H),{data:N}=F({queryKey:["workspaces"],queryFn:()=>o({})}),d=N?.[0],h=E(),y=g(Y),k=g(A),{data:v,isLoading:p}=F({queryKey:["calendar-summaries",d?.id],queryFn:()=>y({data:{workspaceId:d.id}}),enabled:!!d?.id}),{data:i}=F({queryKey:["booking-config",d?.id],queryFn:()=>k({data:{workspaceId:d.id}}),enabled:!!d?.id}),c=()=>{h.invalidateQueries({queryKey:["calendar-summaries",d?.id]}),h.invalidateQueries({queryKey:["booking-config",d?.id]})},n=g(J),l=g(X),r=C({mutationFn:t=>n({data:{workspaceId:d.id,id:t}}),onSuccess:()=>{x.success("Calendar duplicated (inactive)"),c()},onError:t=>x.error(t.message)}),m=C({mutationFn:t=>l({data:{workspaceId:d.id,...t}}),onSuccess:()=>c(),onError:t=>x.error(t.message)}),s=v??[],a=i?.forms??[],w=typeof window>"u"?"https://trybrain.io":window.location.origin;return e.jsxs("div",{className:"mx-auto w-full max-w-6xl space-y-6 p-4 md:p-8",children:[e.jsxs("header",{className:"flex flex-wrap items-end justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"flex items-center gap-2 text-2xl font-semibold",children:[e.jsx(te,{className:"h-6 w-6 text-primary"}),"Calendar management"]}),e.jsx("p",{className:"mt-1 max-w-2xl text-sm text-muted-foreground",children:"Every bookable calendar in this workspace. Open one to configure its intake form, qualification, limits, availability, host routing and booking behaviour."})]}),e.jsx(j,{asChild:!0,children:e.jsxs($,{to:"/calendars/$id",params:{id:"new"},children:[e.jsx(ne,{className:"mr-2 h-4 w-4"}),"New calendar"]})})]}),p?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading calendarsâ¦"}):s.length===0?e.jsx(B,{children:e.jsx(I,{className:"p-8 text-center text-sm text-muted-foreground",children:"No calendars yet. Create one to start taking bookings on your own domain."})}):e.jsx("div",{className:"grid gap-4 md:grid-cols-2",children:s.map(t=>{const u=`${w}/book/${t.slug}`;return e.jsxs(B,{className:t.active?"":"opacity-70",children:[e.jsx(K,{className:"pb-2",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(P,{className:"text-base",children:t.name}),e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:[t.duration_minutes," min · ",t.timezone," ·"," ",t.assignment_strategy.replace(/_/g," ")]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{variant:t.active?"default":"secondary",children:t.active?"Live":"Paused"}),e.jsx(R,{checked:t.active,onCheckedChange:f=>m.mutate({id:t.id,active:f})})]})]})}),e.jsxs(I,{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap gap-2 text-xs",children:[e.jsxs(S,{variant:"outline",children:[t.bookings30d," booked · 30d"]}),e.jsxs(S,{variant:"outline",children:[t.upcoming," upcoming"]}),e.jsx(S,{variant:"outline",children:t.lead_form_id?`Form: ${a.find(f=>f.id===t.lead_form_id)?.name??"linked"}`:"Default fields"})]}),e.jsx("div",{className:"flex flex-wrap gap-1",children:t.hosts.length===0?e.jsx("span",{className:"text-xs text-destructive",children:"No bookable host â leads see zero available times"}):t.hosts.map(f=>e.jsxs(S,{variant:"secondary",className:"text-[11px] font-normal",children:[f.name,f.outOfOffice?" · OOO":""]},f.id))}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(j,{size:"sm",variant:"outline",asChild:!0,children:e.jsxs($,{to:"/calendars/$id",params:{id:t.id},children:[e.jsx(ie,{className:"mr-2 h-4 w-4"}),"Configure"]})}),e.jsxs(j,{size:"sm",variant:"ghost",onClick:()=>{navigator.clipboard.writeText(u),x.success("Booking link copied")},children:[e.jsx(M,{className:"mr-2 h-4 w-4"}),"Copy link"]}),e.jsx(j,{size:"sm",variant:"ghost",asChild:!0,children:e.jsxs("a",{href:u,target:"_blank",rel:"noreferrer",children:[e.jsx(U,{className:"mr-2 h-4 w-4"}),"Preview"]})}),e.jsx(j,{size:"sm",variant:"ghost",onClick:()=>r.mutate(t.id),disabled:r.isPending,children:"Duplicate"})]}),e.jsx(W,{path:`/book/${t.slug}`,embedEnabled:t.embed_enabled!==!1})]})]},t.id)})}),d?.id?e.jsx(de,{workspaceId:d.id}):null,d?.id?e.jsx(re,{workspaceId:d.id}):null]})}function de({workspaceId:o}){const N=E(),d=g(A),{data:h}=F({queryKey:["booking-config",o],queryFn:()=>d({data:{workspaceId:o}})}),y=g(Z),k=g(ee),v=()=>{N.invalidateQueries({queryKey:["booking-config",o]})},p=h?.schedules??[],i=h?.scheduleRules??[],[c,n]=z.useState(null),[l,r]=z.useState(""),m=C({mutationFn:a=>y({data:{workspaceId:o,...a}}),onSuccess:()=>{x.success("Schedule saved"),r(""),v()},onError:a=>x.error(a.message)}),s=C({mutationFn:a=>k({data:{workspaceId:o,id:a}}),onSuccess:()=>{x.success("Schedule deleted"),v()},onError:a=>x.error(a.message)});return e.jsxs(B,{children:[e.jsxs(K,{children:[e.jsx(P,{className:"text-base",children:"Reusable availability schedules"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Define working hours once (for example âUS sales hoursâ) and attach them to any host. Host-specific overrides still apply on top."})]}),e.jsxs(I,{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[e.jsxs("div",{className:"grow",children:[e.jsx(_,{className:"text-xs",children:"New schedule name"}
1),e.jsx(b,{value:l,onChange:a=>r(a.target.value),placeholder:"US sales hours"})]}),e.jsxs(j,{size:"sm",disabled:!l.trim()||m.isPending,onClick:()=>m.mutate({name:l.trim(),timezone:"America/New_York",rules:[1,2,3,4,5].map(a=>({weekday:a,start_time:"09:00",end_time:"17:00"}))}),children:[e.jsx(V,{className:"mr-2 h-4 w-4"}),"Add"]})]}),p.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No schedules yet."}):e.jsx("div",{className:"divide-y rounded-md border",children:p.map(a=>{const w=i.filter(u=>u.schedule_id===a.id),t=c===a.id;return e.jsxs("div",{className:"p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:a.name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[a.timezone," ·"," ",w.length===0?"no hours":w.map(u=>`${T[u.weekday]} ${u.start_time.slice(0,5)}â${u.end_time.slice(0,5)}`).join(", ")]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{size:"sm",variant:"outline",onClick:()=>n(t?null:a.id),children:t?"Close":"Edit hours"}),e.jsx(j,{size:"sm",variant:"ghost",onClick:()=>s.mutate(a.id),children:e.jsx(G,{className:"h-4 w-4"})})]})]}),t?e.jsx(le,{timezone:a.timezone,rules:w.map(u=>({weekday:u.weekday,start_time:u.start_time.slice(0,5),end_time:u.end_time.slice(0,5)})),onSave:(u,f)=>m.mutate({id:a.id,name:a.name,timezone:f,rules:u}),saving:m.isPending}):null]},a.id)})})]})]})}function le({rules:o,timezone:N,onSave:d,saving:h}){const[y,k]=z.useState(N),[v,p]=z.useState(()=>T.map((i,c)=>{const n=o.find(l=>l.weekday===c);return{weekday:c,enabled:!!n,start_time:n?.start_time??"09:00",end_time:n?.end_time??"17:00"}}));return e.jsxs("div",{className:"mt-3 space-y-2 rounded-md bg-muted/40 p-3",children:[e.jsxs("div",{className:"max-w-xs",children:[e.jsx(_,{className:"text-xs",children:"Timezone"}),e.jsx(b,{value:y,onChange:i=>k(i.target.value)})]}),v.map((i,c)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{checked:i.enabled,onCheckedChange:n=>p(l=>l.map((r,m)=>c===m?{...r,enabled:n}:r))}),e.jsx("span",{className:"w-10 text-xs",children:T[i.weekday]}),e.jsx(b,{type:"time",className:"w-28",value:i.start_time,disabled:!i.enabled,onChange:n=>p(l=>l.map((r,m)=>c===m?{...r,start_time:n.target.value}:r))}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"to"}),e.jsx(b,{type:"time",className:"w-28",value:i.end_time,disabled:!i.enabled,onChange:n=>p(l=>l.map((r,m)=>c===m?{...r,end_time:n.target.value}:r))})]},i.weekday)),e.jsx(j,{size:"sm",disabled:h,onClick:()=>d(v.filter(i=>i.enabled).map(i=>({weekday:i.weekday,start_time:i.start_time,end_time:i.end_time})),y),children:"Save hours"})]})}function re({workspaceId:o}){const N=E(),d=g(A),{data:h}=F({queryKey:["booking-config",o],queryFn:()=>d({data:{workspaceId:o}})}),y=g(se),k=g(ae),v=()=>{N.invalidateQueries({queryKey:["booking-config",o]})},p=h?.blackouts??[],i=h?.hosts??[],c=h?.eventTypes??[],[n,l]=z.useState({start_date:"",end_date:"",reason:"",hostId:"all",eventTypeId:"all"}),r=C({mutationFn:()=>y({data:{workspaceId:o,start_date:n.start_date,end_date:n.end_date||n.start_date,reason:n.reason||null,hostId:n.hostId==="all"?null:n.hostId,eventTypeId:n.eventTypeId==="all"?null:n.eventTypeId}}),onSuccess:()=>{x.success("Blackout saved"),l({start_date:"",end_date:"",reason:"",hostId:"all",eventTypeId:"all"}),v()},onError:s=>x.error(s.message)}),m=C({mutationFn:s=>k({data:{workspaceId:o,id:s}}),onSuccess:()=>{x.success("Blackout removed"),v()},onError:s=>x.error(s.message)});return e.jsxs(B,{children:[e.jsxs(K,{children:[e.jsx(P,{className:"text-base",children:"Blackout dates"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Company shutdowns, holidays and vacations. Blocks a date range for the whole workspace, one calendar, or one host."})]}),e.jsxs(I,{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-2 md:grid-cols-5",children:[e.jsxs("div",{children:[e.jsx(_,{className:"text-xs",children:"From"}),e.jsx(b,{type:"date",value:n.start_date,onChange:s=>l(a=>({...a,start_date:s.target.value}))})]}),e.jsxs("div",{children:[e.jsx(_,{className:"text-xs",children:"To"}),e.jsx(b,{type:"date",value:n.end_date,onChange:s=>l(a=>({...a,end_date:s.target.value}))})]}),e.jsxs("div",{children:[e.jsx(_,{className:"text-xs",children:"Applies to host"}),e.jsxs(D,{value:n.hostId,onValueChange:s=>l(a=>({...a,hostId:s}
1)),children:[e.jsx(L,{children:e.jsx(O,{})}),e.jsxs(Q,{children:[e.jsx(q,{value:"all",children:"All hosts"}),i.map(s=>e.jsx(q,{value:s.id,children:s.display_name??s.user_id.slice(0,8)},s.id))]})]})]}),e.jsxs("div",{children:[e.jsx(_,{className:"text-xs",children:"Applies to calendar"}),e.jsxs(D,{value:n.eventTypeId,onValueChange:s=>l(a=>({...a,eventTypeId:s})),children:[e.jsx(L,{children:e.jsx(O,{})}),e.jsxs(Q,{children:[e.jsx(q,{value:"all",children:"All calendars"}),c.map(s=>e.jsx(q,{value:s.id,children:s.name},s.id))]})]})]}),e.jsxs("div",{children:[e.jsx(_,{className:"text-xs",children:"Reason"}),e.jsx(b,{value:n.reason,onChange:s=>l(a=>({...a,reason:s.target.value})),placeholder:"Company offsite"})]})]}),e.jsxs(j,{size:"sm",disabled:!n.start_date||r.isPending,onClick:()=>r.mutate(),children:[e.jsx(V,{className:"mr-2 h-4 w-4"}),"Add blackout"]}),p.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No blackout dates."}):e.jsx("div",{className:"divide-y rounded-md border",children:p.map(s=>e.jsxs("div",{className:"flex items-center justify-between gap-2 p-3",children:[e.jsxs("div",{className:"text-sm",children:[e.jsxs("span",{className:"font-medium",children:[s.start_date," â ",s.end_date]}),e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:[s.host_id?i.find(a=>a.id===s.host_id)?.display_name??"host":"all hosts"," · ",s.event_type_id?c.find(a=>a.id===s.event_type_id)?.name??"calendar":"all calendars",s.reason?` · ${s.reason}`:""]})]}),e.jsx(j,{size:"sm",variant:"ghost",onClick:()=>m.mutate(s.id),children:e.jsx(G,{className:"h-4 w-4"})})]},s.id))})]})]})}export{pe as component};
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.