import{c as e,i as t}from"./preload-helper-B45gAKPr.js";import{pn as n,t as r}from"./iframe-CMLjY6eW.js";import{a as i,b as a,d as o,f as s,t as c,u as l}from"./formatters-CvqCBcOp.js";import{a as u,i as d,n as f,o as p,s as m,t as h}from"./preset-select-BKJU7Z15.js";function g(e){return typeof e==`string`&&w.has(e)}function _(e,t=[]){return d(e,g,t)}function v(e,t=S){return m(e,t)}function y(e,t=T){return p(e,t)}function b(e,t=new Date,n=T){let r=y(e,n);return r?{id:r.id,label:r.label,range:r.resolveRange({referenceDate:t})}:null}function x(e,t=new Date,n=T){if(!Array.isArray(e))return null;let[r,i]=e;if(!(r instanceof Date)||!(i instanceof Date))return null;let a=r.getTime(),o=i.getTime();for(let e of n){let[n,r]=e.resolveRange({referenceDate:t});if(!(!(n instanceof Date)||!(r instanceof Date))&&n.getTime()===a&&r.getTime()===o)return e.id}return null}var S,C,w,T,E=t((()=>{c(),u(),S=Object.freeze([{id:`monthStartToYesterday`,label:`С начала месяца по вчера`,resolveRange:a},{id:`monthStartToToday`,label:`С начала месяца по сегодня`,resolveRange:i},{id:`today`,label:`За сегодня`,resolveRange:o},{id:`yesterday`,label:`За вчера`,resolveRange:l},{id:`monthAgo`,label:`Месяц назад`,resolveRange:s}]),C=Object.freeze([`monthStartToYesterday`,`monthStartToToday`,`today`,`yesterday`]),w=new Set(S.map(e=>e.id)),T=Object.freeze(v(C))}));function D(e){if(!e)return`__empty__`;let[t,n]=e.range;return[e.id,t?.getTime()??`null`,n?.getTime()??`null`].join(`|`)}function O({value:e,onChange:t,options:n=T,referenceDate:r,onRangeChange:i,...a}){let[o]=(0,k.useState)(()=>new Date),s=r?.getTime()??o.getTime(),c=!!i,l=(0,k.useRef)(``),u=(0,k.useEffectEvent)(e=>{if(!i)return;let t=b(e,new Date(s),n),r=D(t);r!==l.current&&(l.current=r,i(t))});return(0,k.useEffect)(()=>{u(e)},[c,n,s,e]),(0,A.jsx)(f,{...a,options:n,value:e,onChange:t})}var k,A,j=t((()=>{k=e(n(),1),h(),E(),A=r(),O.__docgenInfo={description:`Выбор пресета диапазона дат с вычислением диапазона без timezone-сдвига.`,methods:[],displayName:`DateRangePresetSelect`,props:{label:{required:!1,tsType:{name:`ReactNode`},description:``},description:{required:!1,tsType:{name:`string`},description:``},placeholder:{required:!1,tsType:{name:`string`},description:``},disabled:{required:!1,tsType:{name:`boolean`},description:``},size:{required:!1,tsType:{name:`union`,raw:`"xs" | "sm" | "md" | "lg" | "xl"`,elements:[{name:`literal`,value:`"xs"`},{name:`literal`,value:`"sm"`},{name:`literal`,value:`"md"`},{name:`literal`,value:`"lg"`},{name:`literal`,value:`"xl"`}]},description:``},value:{required:!0,tsType:{name:`V`},description:"Если начальное состояние может быть `null | undefined`\nзначит `onChange` тоже должен ументь сбрасывать.\nПоэтому такой контрол явно должен передавать `UiBaseProps<AnyType | undefined>`"},onChange:{required:!0,tsType:{name:`signature`,type:`function`,raw:`(value: T) => void`,signature:{arguments:[{type:{name:`C`},name:`value`}],return:{name:`void`}}},description:``},options:{required:!1,tsType:{name:`unknown`},description:``,defaultValue:{value:`Object.freeze(
	resolveDateRangePresetOptionsByIds(DEFAULT_DATE_RANGE_PRESET_IDS)
)`,computed:!0}},referenceDate:{required:!1,tsType:{name:`Date`},description:``},onRangeChange:{required:!1,tsType:{name:`signature`,type:`function`,raw:`(payload: DateRangePresetChangePayload | null) => void`,signature:{arguments:[{type:{name:`union`,raw:`DateRangePresetChangePayload | null`,elements:[{name:`DateRangePresetChangePayload`},{name:`null`}]},name:`payload`}],return:{name:`void`}}},description:``}}}}));export{_ as a,b as c,E as i,j as n,x as o,C as r,v as s,O as t};