import{r as a,j as o}from"./vendor-react-CVHocMAO.js";import{at as c,N as y,cF as S,cG as R,c7 as I,X as T,F as Y,cH as z,cf as q}from"./index-Daf0Yezg.js";const G=({value:r,onChange:p,placeholder:j="Select date",className:C,disabled:x=!1,allowPastDates:N=!1,minDate:l,maxDate:D,disabledDates:g,id:P,plannerHighlights:s})=>{const[u,i]=a.useState(!1),[F,f]=a.useState(()=>r?c(r):l?c(l):c(new Date)),n=a.useRef(null),d=a.useRef(null),[b,w]=a.useState(!1),O=e=>e?y(e,"MM/dd/yyyy"):"",h=e=>{e.stopPropagation(),e.preventDefault(),p(null),i(!1)},k=e=>{e&&(f(c(e)),p(e),i(!1))};a.useEffect(()=>{r&&f(c(r))},[r]);const v=e=>{i(e),e&&n.current&&requestAnimationFrame(()=>{n.current&&n.current.blur()})};a.useEffect(()=>{if(u&&b&&n.current){const e=setTimeout(()=>{n.current&&n.current.blur()},100);return()=>clearTimeout(e)}},[u,b]);const E=a.useMemo(()=>{const e=(s==null?void 0:s.cartDatesYmd)??[],t=s==null?void 0:s.partyDateYmd;return{plannerFromCart:m=>e.includes(y(m,"yyyy-MM-dd")),plannerFromParty:m=>{const M=y(m,"yyyy-MM-dd");return!!t&&M===t&&!e.includes(M)}}},[s]);return a.useEffect(()=>{(()=>{if(d.current){const t=d.current.closest('[role="dialog"]');w(t!==null)}else setTimeout(()=>{if(n.current){const t=n.current.closest('[role="dialog"]');w(t!==null)}},0)})()},[]),o.jsx("div",{ref:d,children:o.jsxs(S,{open:u,onOpenChange:v,modal:!1,children:[o.jsx(R,{asChild:!0,children:o.jsxs("button",{ref:n,id:P,type:"button",disabled:x,className:Y("w-full pl-10 pr-10 py-2.5 rounded-lg border border-gray-300","focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent","disabled:bg-gray-100 disabled:cursor-not-allowed","text-base sm:text-sm text-left relative","hover:border-gray-400 transition-colors",!r&&"text-gray-500",C),children:[o.jsx("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-400",children:o.jsx(I,{className:"h-4 w-4"})}),o.jsx("span",{className:"block truncate",children:r?O(r):j}),r&&!x&&o.jsx("div",{onClick:h,className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 cursor-pointer",children:o.jsx(T,{className:"h-4 w-4"})})]})}),o.jsx(z,{className:"w-auto p-0 max-w-[calc(100vw-2rem)] overflow-auto",align:"start",side:"bottom",sideOffset:8,collisionPadding:16,onEscapeKeyDown:e=>{i(!1)},onPointerDownOutside:e=>{const t=e.target;t.closest("[data-radix-popover-trigger]")&&e.preventDefault(),t.closest('[role="dialog"]')&&!t.closest("[data-radix-dialog-overlay]")&&e.preventDefault()},children:o.jsx(q,{mode:"single",month:F,onMonthChange:f,modifiers:s?E:void 0,plannerHighlightDay:!!s,selected:r?new Date(r.getFullYear(),r.getMonth(),r.getDate()):void 0,onSelect:e=>{if(e){const t=new Date(e.getFullYear(),e.getMonth(),e.getDate());k(t)}},disabled:e=>{if(!N){const t=new Date;if(t.setHours(0,0,0,0),e<t)return!0}if(l){const t=new Date(l);if(t.setHours(0,0,0,0),e<t)return!0}if(D){const t=new Date(D);if(t.setHours(23,59,59,999),e>t)return!0}return g?g(e):!1}})})]})})};export{G as D};