import{r as m,ac as R,bR as P,bQ as S,bG as O,w as F,ah as z,bH as $,j as t,ae as B,c as E,D as A,M as H,R as M,B as k,T as v}from"./main-TIUJvpaR.js";import{u as I}from"./use-current-date-time-BdzpdEnL.js";import{u as L}from"./use-date-formatter-hhGEq_P-.js";import{D as N}from"./DateRange-LhM59-62.js";import{D as Z}from"./dialog-footer-yCpPZGPO.js";import{u as G,t as Q,D as U,a as V,C as q}from"./use-base-date-picker-state-DYQU3Rut.js";function J(a){const o=I(),[e,f]=m.useState(!a.value&&!a.defaultValue),s=a.onChange,[n,i]=R(a.value||o,a.defaultValue||o,r=>{f(!1),s==null||s(r)}),{min:d,max:l,granularity:b,timezone:g,calendarIsOpen:h,setCalendarIsOpen:c,closeDialogOnSelection:p}=G(n,a),D=m.useCallback(()=>{f(!0),i(o),s==null||s(null),c(!1)},[o,i,s,c]),[u,x]=m.useState(()=>[P(n)]),C=m.useCallback(r=>{d&&r.compare(d)<0?r=d:l&&r.compare(l)>0&&(r=l);const j=n?n.set(r):Q(r,g);i(j),x([P(j)]),f(!1)},[i,d,l,n,g]),T=m.useCallback(r=>!e&&S(n,r),[n,e]),y=m.useCallback(r=>({onClick:()=>{C==null||C(r),p&&(c==null||c(!1))}}),[C,c,p]);return{selectedValue:n,setSelectedValue:i,calendarIsOpen:h,setCalendarIsOpen:c,dayIsActive:T,dayIsHighlighted:()=>!1,dayIsRangeStart:()=>!1,dayIsRangeEnd:()=>!1,getCellProps:y,calendarDates:u,setCalendarDates:x,isPlaceholder:e,clear:D,setIsPlaceholder:f,min:d,max:l,granularity:b,timezone:g,closeDialogOnSelection:p}}function K({showCalendarFooter:a,...o}){const e=J(o),f=m.useRef(null),s=I(),n=a&&t.jsx(Z,{padding:"px-14 pb-14",startAction:t.jsx(k,{disabled:e.isPlaceholder,variant:"text",color:"primary",onClick:()=>{e.clear()},children:t.jsx(v,{message:"Clear"})}),children:t.jsx(k,{variant:"text",color:"primary",onClick:()=>{e.setSelectedValue(s),e.setCalendarIsOpen(!1)},children:t.jsx(v,{message:"Today"})})}),i=t.jsx(A,{offset:8,placement:"bottom-start",isOpen:e.calendarIsOpen,onOpenChange:e.setCalendarIsOpen,type:"popover",triggerRef:f,returnFocusToTrigger:!1,moveFocusToDialog:!1,children:t.jsxs(H,{size:"auto",children:[t.jsx(M,{className:"flex items-start gap-40",padding:a?"px-24 pt-20 pb-10":null,children:t.jsx(q,{state:e,visibleMonths:1})}),n]})}),d={onClick:l=>{l.stopPropagation(),l.preventDefault(),W(l)?e.setCalendarIsOpen(!1):e.setCalendarIsOpen(!0)}};return t.jsxs(m.Fragment,{children:[t.jsx(U,{ref:f,wrapperProps:d,endAdornment:t.jsx(N,{className:E(o.disabled&&"text-disabled")}),...o,children:t.jsx(V,{segmentProps:d,state:e,value:e.selectedValue,onChange:e.setSelectedValue,isPlaceholder:e.isPlaceholder})}),i]})}function te(a){const{min:o,max:e}=a,f=O(),s=a.timezone||f,{trans:n}=F(),{format:i}=L({timeZone:s}),{field:{onChange:d,onBlur:l,value:b=null,ref:g},fieldState:{invalid:h,error:c}}=z({name:a.name,rules:{validate:u=>{if(!u)return;const x=$(u,s);if(o&&x.compare(o)<0)return n({message:"Enter a date after :date",values:{date:i(u)}});if(e&&x.compare(e)>0)return n({message:"Enter a date before :date",values:{date:i(u)}})}}}),p=b?$(b,s):null,D={onChange:u=>{d(u&&u.toAbsoluteString())},onBlur:l,value:p,invalid:h,errorMessage:c==null?void 0:c.message,inputRef:g};return t.jsx(K,{...B(D,a)})}function W(a){return["hour","minute","dayPeriod"].includes(a.currentTarget.ariaLabel||"")}export{te as F};
