import{r as p}from"./vendor-react-DX7tU9aY.js";import{j as a,z as b,X as t,A,M as E,al as I}from"./vendor-mui-core-CDEc-eG6.js";import{a as j}from"./vendor-hooks-BrgYeCrj.js";import{M as r}from"./index-DGZk149v.js";import{W as y}from"./vendor-ux-bFYdDLNG.js";import{t as C}from"./arrow-down.svg-Dz9H9vM-.js";import{L as O,D as H}from"./vendor-mui-x-Bk3pxGrO.js";import{A as R}from"./AdapterDayjs-Dj6vE8_r.js";function v({value:n=null,onChange:i,error:l=!1,helperText:c="",label:h="",timezone:e="",minDateTime:f=null}){const d=j(()=>{let s=r();return n&&(s=e?r(n).tz(e):r(n)),s},[n,e]),m=s=>{const T=e?r(s).tz(e):r(s);i(new Date(T.format("YYYY-MM-DD HH:mm:00")))};return a.jsx(O,{dateAdapter:R,children:a.jsx(b,{fullWidth:!0,error:l,children:a.jsx(H,{label:h,minDateTime:f,value:d,onChange:m,slotProps:{textField:{error:l,helperText:l?c:""}},format:"YYYY-MM-DD HH:mm"})})})}v.propTypes={value:t.oneOfType([t.string,t.instanceOf(Date)]),onChange:t.func.isRequired,error:t.bool,helperText:t.string,label:t.string,timezone:t.string,minDateTime:t.instanceOf(Date)};function U(n){return a.jsx(C,{...n,width:20,height:20})}const u={MINUTES_30:1800*1e3,HOUR_1:3600*1e3,HOURS_3:10800*1e3,DAY_1:1440*60*1e3,DAYS_7:10080*60*1e3,DAYS_30:720*60*60*1e3};function $({placeholder:n="",value:i="",onChange:l,timezone:c="",showError:h=!0}){const{t:e}=y(),[f,d]=p.useState(i||""),[m,s]=p.useState(null),[T,M]=p.useState(null),x=p.useMemo(()=>[{value:u.MINUTES_30,label:`30 ${e("common.minutes")}`},{value:u.HOUR_1,label:`1 ${e("common.hour")}`},{value:u.HOURS_3,label:`3 ${e("common.hours")}`},{value:u.DAY_1,label:`1 ${e("common.day")}`},{value:u.DAYS_7,label:`7 ${e("common.days")}`},{value:u.DAYS_30,label:`30 ${e("common.days")}`},{value:"custom",label:e("common.custom")}],[e]),Y=o=>{if(d(o),o==="custom"){const D=c?r().tz(c):r(),S=D.add(1,"day").toDate();M(D),s(S),l(S)}else l(new Date(Date.now()+o))},_=o=>{s(o),l(o)};p.useEffect(()=>{i&&(x.find(D=>r(D.value).isSame(i))||(d("custom"),s(i)))},[]);const g=j(()=>h?!!(!m||r(m).isBefore(r())):!1,[m,e]);return a.jsxs(a.Fragment,{children:[a.jsx(b,{fullWidth:!0,children:a.jsx(A,{select:!0,value:f,label:n||e("team.passport.passportExpireTime"),onChange:o=>Y(o.target.value),variant:"outlined",slotProps:{select:{IconComponent:U}},sx:{"& .MuiInputLabel-root":{width:"calc(100% - 46px)"}},children:x.map(o=>a.jsx(E,{value:o.value,children:o.label},o.value))})}),f==="custom"&&a.jsx(I,{children:a.jsx(v,{value:m,onChange:_,label:e("team.passport.customExpireTime"),timezone:c,error:!!g,helperText:g?e("team.passport.customExpireTimeIsInvalid"):void 0,minDateTime:T})})]})}$.propTypes={value:t.oneOfType([t.string,t.instanceOf(Date)]),onChange:t.func.isRequired,timezone:t.string,placeholder:t.string,showError:t.bool};export{$ as T};
