import{K as v,u as ne,O as ie,h as N}from"./OdysseyThemeProvider-Bh0Bu-2o.js";import{r as o}from"./index-NdkWRN8K.js";import{M as ae}from"./Button-BEA5U6Tg.js";import{u as ce}from"./useUniqueId-Bsgqe1tm.js";import{M as de}from"./Field-DH3L8v09.js";import{j as r}from"./jsx-runtime-CnH95YSl.js";import{D as le,a as me}from"./DatePicker-BwDkz3WT.js";import{I as ue}from"./InputAdornment-CdR3XT6f.js";import{u as fe,M as pe,d as he,a as De,b as ke}from"./useOdysseyDateFields-DPSkeXJj.js";const ge=()=>{const{t}=v();return new Map([["invalidDate",t("picker.error.invalid")],["maxDate",t("picker.error.maxdate")],["minDate",t("picker.error.mindate")]])},ye=t=>t.toUTC().toISO(),xe=({defaultValue:t,endAdornment:b,errorMessage:g,hasInitialFocus:M,hint:L,HintLinkComponent:U,id:C,inputRef:z,isDisabled:a=!1,isOptional:V=!1,isReadOnly:I,label:j,minDate:l,maxDate:m,onBlur:y,onChange:c,onFocus:O,timezone:S,value:u})=>{const f=ge(),[x,p]=o.useState(g),i=o.useRef(),F=o.useRef(null);o.useImperativeHandle(z,()=>({focus:()=>{var e;(e=F.current)==null||e.focus()}}),[]);const h=o.useCallback(e=>{const n=l&&e.toUTC()<l.toUTC(),s=m&&e.toUTC()>m.toUTC();return n||s?(n&&p(f.get("minDate")),s&&p(f.get("maxDate")),!1):!0},[f,l,m]);o.useEffect(()=>{u&&h(u),t&&h(t)},[h,t,l,m,u]);const P=o.useCallback(()=>{p(void 0),i.current=void 0},[i,p]),w=o.useCallback((e,n)=>{P();const{validationError:s}=n,E=(e==null?void 0:e.year.toString().length)===4;if(s){const D=f.get(s);D&&(i.current=D,e!=null&&e.isValid&&E&&p(D))}if(e!=null&&e.isValid&&!s){const D=ye(e);D&&h(e)&&(c==null||c(D))}},[h,P,f,c]),d=o.useCallback(e=>{i!=null&&i.current&&!x&&p(i.current),y==null||y(e)},[x,i,y]),A=!I&&!a,R=o.useCallback(({ariaDescribedBy:e,errorMessageElementId:n,id:s,labelElementId:E})=>r.jsx(le,{autoFocus:M,defaultValue:t,disabled:a,id:s,inputProps:{"aria-describedby":e,"aria-errormessage":n,"aria-labelledby":E},InputProps:{error:!!(x||g),endAdornment:r.jsx(r.Fragment,{children:A&&r.jsx(ue,{position:"end",children:b})})},inputRef:F,maxDate:m,minDate:l,name:s,onBlur:d,onChange:w,onFocus:O,readOnly:I,timezone:S,value:u,variant:"standard"}),[d,t,x,b,g,M,A,a,F,l,m,O,I,S,w,u]);return r.jsx(de,{errorMessage:x||g,fieldType:"single",hasVisibleLabel:!0,hint:L,HintLinkComponent:U,id:C,isDisabled:a,isOptional:V,label:j,renderFieldComponent:R})},G=o.memo(xe);G.displayName="DateField";/*!
 * Copyright (c) 2023-present, Okta, Inc. and/or its affiliates. All rights reserved.
 * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
 *
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and limitations under the License.
 */const Te=N.div({".MuiFormControl-root":{marginBlockEnd:0}}),be=N.div(({odysseyDesignTokens:t})=>({".MuiInput-root":{width:"100%",maxWidth:t.TypographyLineLengthMax}})),Me=N("div",{shouldForwardProp:t=>t!=="odysseyDesignTokens"})(({odysseyDesignTokens:t})=>({marginBlockStart:t.Spacing3})),Ce=({defaultValue:t,errorMessage:b,hint:g,HintLinkComponent:M,id:L,isDateEnabled:U=()=>!0,isDisabled:C,isOptional:z,isReadOnly:a,isMonthEnabled:V=()=>!0,isYearEnabled:I=()=>!0,label:j,minDate:l,maxDate:m,onBlur:y,onCalendarDateChange:c,onInputChange:O,timeZone:S,timeZonePickerLabel:u,timeZoneOptions:f,value:x})=>{const{i18n:p,t:i}=v(),F=o.useRef(null),h=ne(),P=ce(L),{closeCalendar:w,commonIcons:d,defaultedLanguageCode:A,formatDateTimeToUtcIsoDateString:R,formatDayOfWeek:e,inputValues:n,internalTimeZone:s,isOpen:E,localeText:D,minDate:W,maxDate:Z,onInputChange:Y,onTimeZoneChange:Q,popperElement:H,setPopperElement:$,shouldDisableDate:X,shouldDisableMonth:_,shouldDisableYear:ee,toggleCalendarVisibility:q}=fe({defaultValue:t,isDateEnabled:U,isMonthEnabled:V,isYearEnabled:I,minDate:l,maxDate:m,onInputChange:O,timeZone:S,value:x}),{language:te}=p,J=o.useRef(null);o.useEffect(()=>{$(J.current)},[$]);const oe=o.useCallback(k=>{if(k){const T=R(k);T&&(c==null||c({value:T,timeZone:s}))}},[R,s,c]),K=o.useCallback(({defaultValue:k,inputRef:T,value:B})=>r.jsx(G,{defaultValue:k,endAdornment:r.jsx(ae,{ariaLabel:i("picker.labels.date.choose"),label:"",onClick:q,size:"small",startIcon:r.jsx(d.CalendarIcon,{}),variant:"floating"}),errorMessage:b,hint:g,HintLinkComponent:M,id:P,inputRef:T,isDisabled:C,isOptional:z,isReadOnly:a,label:j,maxDate:Z,minDate:W,onBlur:y,onChange:Y,timezone:s,value:B}),[d,P,b,g,M,s,C,z,a,j,y,Y,W,Z,i,q]),re=o.useMemo(()=>({actionBar:pe,field:k=>K(k),leftArrowIcon:()=>r.jsx(d.ArrowLeftIcon,{}),rightArrowIcon:()=>r.jsx(d.ArrowRightIcon,{}),switchViewIcon:()=>r.jsx(d.ChevronDownIcon,{})}),[d,K]),se=o.useMemo(()=>({actionBar:({wrapperVariant:k,onAccept:T,onCancel:B})=>({actions:k==="desktop"?[]:["accept","cancel"],onAccept:T,onCancel:B}),popper:{anchorEl:H},toolbar:{toolbarPlaceholder:""}}),[H]);return r.jsx(ie,{themeOverride:he,children:r.jsxs(De,{defaultedLanguageCode:A,localeText:D,children:[r.jsx(Te,{children:r.jsx(be,{odysseyDesignTokens:h,ref:J,children:r.jsx(me,{dayOfWeekFormatter:e,defaultValue:n==null?void 0:n.defaultValue,disabled:C,fixedWeekNumber:6,inputRef:F,label:j,maxDate:Z,minDate:W,onChange:oe,onClose:w,open:E,readOnly:a,shouldDisableDate:X,shouldDisableMonth:_,shouldDisableYear:ee,slotProps:se,slots:re,timezone:s,value:n==null?void 0:n.value},te)})}),f&&u&&r.jsx(Me,{odysseyDesignTokens:h,children:r.jsx(ke,{isReadOnly:a,label:u,onTimeZoneChange:Q,timeZoneOptions:f,value:s})})]})})},Ie=o.memo(Ce);Ie.displayName="DatePicker";export{Ie as M};
