import { PresetSelect as e } from "../preset-select/index.js";
import { useEffect as t, useEffectEvent as n, useRef as r, useState as i } from "react";
import { jsx as a } from "react/jsx-runtime";
import { resolveMonthAgoRange as o, resolveMonthStartToTodayRange as s, resolveMonthStartToYesterdayRange as c, resolveTodayRange as l, resolveYesterdayRange as u } from "@ryuzaki13/react-foundation-lib/formatters";
import { getPresetOption as d, normalizePresetIds as f, resolvePresetOptionsByIds as p } from "@ryuzaki13/react-foundation-lib/presets";
//#region src/date-range-preset-select/lib/dateRangePresets.ts
var m = Object.freeze([
	{
		id: "monthStartToYesterday",
		label: "С начала месяца по вчера",
		resolveRange: c
	},
	{
		id: "monthStartToToday",
		label: "С начала месяца по сегодня",
		resolveRange: s
	},
	{
		id: "today",
		label: "За сегодня",
		resolveRange: l
	},
	{
		id: "yesterday",
		label: "За вчера",
		resolveRange: u
	},
	{
		id: "monthAgo",
		label: "Месяц назад",
		resolveRange: o
	}
]), h = Object.freeze([
	"monthStartToYesterday",
	"monthStartToToday",
	"today",
	"yesterday"
]), g = new Set(m.map((e) => e.id));
function _(e) {
	return typeof e == "string" && g.has(e);
}
function v(e, t = []) {
	return f(e, _, t);
}
function y(e, t = m) {
	return p(e, t);
}
var b = Object.freeze(y(h));
function x(e, t = b) {
	return d(e, t);
}
function S(e, t = /* @__PURE__ */ new Date(), n = b) {
	let r = x(e, n);
	return r ? {
		id: r.id,
		label: r.label,
		range: r.resolveRange({ referenceDate: t })
	} : null;
}
function C(e, t = /* @__PURE__ */ new Date(), n = b) {
	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;
}
//#endregion
//#region src/date-range-preset-select/DateRangePresetSelect.tsx
function w(e) {
	if (!e) return "__empty__";
	let [t, n] = e.range;
	return [
		e.id,
		t?.getTime() ?? "null",
		n?.getTime() ?? "null"
	].join("|");
}
function T({ value: o, onChange: s, options: c = b, referenceDate: l, onRangeChange: u, ...d }) {
	let [f] = i(() => /* @__PURE__ */ new Date()), p = l?.getTime() ?? f.getTime(), m = !!u, h = r(""), g = n((e) => {
		if (!u) return;
		let t = S(e, new Date(p), c), n = w(t);
		n !== h.current && (h.current = n, u(t));
	});
	return t(() => {
		g(o);
	}, [
		m,
		c,
		p,
		o
	]), /* @__PURE__ */ a(e, {
		...d,
		options: c,
		value: o,
		onChange: s
	});
}
//#endregion
export { x as a, C as c, b as i, y as l, m as n, _ as o, h as r, v as s, T as t, S as u };

//# sourceMappingURL=date-range-preset-select-BLnY47cv.js.map