import{f as p}from"./index-DFVuS8SP.js";const b=1,A=.25;function $(e){const t=e.getDay();return["sunday","monday","tuesday","wednesday","thursday","friday","saturday"][t]}function w(e,t){const r=$(e),n=t.find(s=>s.day===r);return!n||n.enabled!==!0?!1:S(n).length>0}function N(e,t){const r=t.find(s=>s.day===e);if(!r||r.enabled!==!0)return null;const n=S(r);return n.length===0?null:{enabled:!0,windows:n}}function O(e,t){const r=N(e,t);if(!r)return null;const n=r.windows.map(i=>D(i.from)),s=r.windows.map(i=>D(i.to)),a=Math.min(...n),o=Math.max(...s);return{enabled:!0,from:T(a),to:T(o)}}function D(e){const[t,r]=e.split(":").map(Number);return t*60+r}function T(e){const t=(e%1440+1440)%1440,r=Math.floor(t/60),n=t%60;return`${r.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`}function W(e,t,r,n,s){const a=u=>{if(!u)return"";if(/^\d{1,2}:\d{2}$/.test(u))return u;const m=u.match(/(\d{1,2}):(\d{2})\s*(AM|PM)/i);if(m){let f=parseInt(m[1],10);const y=parseInt(m[2],10),g=m[3].toUpperCase();return g==="PM"&&f!==12&&(f+=12),g==="AM"&&f===12&&(f=0),`${f.toString().padStart(2,"0")}:${y.toString().padStart(2,"0")}`}return u},o=a(e),i=a(t);if(!o||!i)return"Please select both start and end times";const c=u=>{const[m,f]=u.split(":").map(Number),y=m>=12?"PM":"AM";return`${m%12||12}:${f.toString().padStart(2,"0")} ${y}`},l=new Date(`${p(r,"yyyy-MM-dd")}T${o}:00`),d=new Date(`${p(r,"yyyy-MM-dd")}T${i}:00`);if(Number.isNaN(l.getTime())||Number.isNaN(d.getTime()))return"Please select a valid time range.";d<=l&&d.setDate(d.getDate()+1);const h=H(l,d);for(const u of h){const m=N(u.dayOfWeek,n);if(!m)return`This venue is not available on ${u.dayLabel}. Please select a different time range.`;if(!x(m.windows).some(g=>u.startMinutes>=g.start&&u.endMinutes<=g.end)){const g=m.windows.map(M=>`${c(M.from)} - ${c(M.to)}`).join(", ");return`Selected time is outside availability hours for ${u.dayLabel} (${g}).`}}return null}function S(e){return Array.isArray(e.windows)&&e.windows.length>0?e.windows.filter(t=>typeof(t==null?void 0:t.from)=="string"&&typeof(t==null?void 0:t.to)=="string").map(t=>({from:t.from,to:t.to})):typeof e.from=="string"&&typeof e.to=="string"?[{from:e.from,to:e.to}]:[]}function x(e){const t=e.map(n=>{const s=D(n.from),a=D(n.to);return s===a?null:a<s?{start:s,end:1440}:{start:s,end:a}}).filter(n=>n!=null).sort((n,s)=>n.start-s.start),r=[];for(const n of t){const s=r[r.length-1];if(!s){r.push({...n});continue}n.start<=s.end?s.end=Math.max(s.end,n.end):r.push({...n})}return r}function H(e,t){const r=[];let n=new Date(e);for(;n<t;){const s=new Date(n);s.setHours(0,0,0,0);const a=new Date(s);a.setDate(a.getDate()+1);const o=new Date(Math.max(n.getTime(),e.getTime())),i=new Date(Math.min(a.getTime(),t.getTime())),c=o.getHours()*60+o.getMinutes(),l=i.getTime()===a.getTime()?24*60:i.getHours()*60+i.getMinutes(),d=$(s),h=d.charAt(0).toUpperCase()+d.slice(1);r.push({dayOfWeek:d,dayLabel:h,startMinutes:c,endMinutes:l}),n=a}return r}function P(e){const t=A;return Math.round(e/t)*t}function k(e){if(!Number.isFinite(e)||e<=0)return"0";const t=P(e);return Math.abs(t-Math.round(t))<1e-9?String(Math.round(t)):String(Number(t.toFixed(2)))}function I(e){const t=k(e),r=Number(t);return`${t} hr${r===1?"":"s"}`}function E(e){return!Number.isFinite(e)||e<0?"Please select a valid start and end time.":e<b?`Minimum booking duration is ${b} hour. Please extend your end time.`:null}function v(e,t){const r=new Date;r.setHours(0,0,0,0);const n=new Date(r);if(typeof t=="number"&&t>0){const o=Math.ceil(t/24);n.setDate(n.getDate()+o)}const s=new Date(r),a=typeof e=="number"&&e>0?e:365;return s.setDate(s.getDate()+a),s.setHours(23,59,59,999),{minDate:n,maxDate:s}}function R(e,t,r){try{const[n,s,a]=e.split("-").map(Number),o=new Date(n,s-1,a);if(o.setHours(0,0,0,0),Number.isNaN(o.getTime()))return!1;const{minDate:i,maxDate:c}=v(t,r);return o>=i&&o<=c}catch{return!1}}function z(e){const{bookingWindowDays:t,minimumLeadTimeHours:r,schedule:n,blockedDates:s=[]}=e,{minDate:a,maxDate:o}=v(t,r);return{minDate:a,maxDate:o,disabledDates:c=>{const l=new Date(c.getFullYear(),c.getMonth(),c.getDate()).getTime();if(l<a.getTime()||l>o.getTime())return!0;const d=p(c,"yyyy-MM-dd");return s.includes(d)?!0:!w(c,n)}}}export{b as M,w as a,E as b,$ as c,N as d,O as e,I as f,z as g,R as i,T as m,P as r,D as t,W as v};