import { PresetSelect as e } from "../preset-select/index.js";
import { useEffect as t, useEffectEvent as n, useMemo as r } from "react";
import { isRecord as i } from "@ryuzaki13/react-foundation-lib/validators";
import { countCalendarDaysInDateRange as a, normalizeText as o, toPositiveInteger as s } from "@ryuzaki13/react-foundation-lib/formatters";
import { jsx as c } from "react/jsx-runtime";
import { getPresetOption as l, normalizePresetIds as u, resolvePresetOptionsByIds as d } from "@ryuzaki13/react-foundation-lib/presets";
//#region src/period-select/lib/constants.ts
var f = "period-select", p = "day", m = 31, h = 26, g = Object.freeze([
	{
		id: "day",
		label: "по дням"
	},
	{
		id: "week",
		label: "по неделям"
	},
	{
		id: "month",
		label: "по месяцам"
	}
]), _ = Object.freeze([
	"day",
	"week",
	"month"
]), v = new Set(g.map((e) => e.id));
function y(e) {
	return typeof e == "string" && v.has(e);
}
function b(e, t = _) {
	return u(e, y, t);
}
function x(e, t = g) {
	return d(e, t);
}
function S(e, t = g) {
	return l(e, t);
}
function C(e) {
	return y(e) ? e : "day";
}
function w({ maxDayRangeDays: e, maxWeekRangeWeeks: t } = {}) {
	let n = s(e), r = s(t);
	return g.map((e) => e.id === "day" && n !== void 0 ? {
		...e,
		maxRangeDays: n
	} : e.id === "week" && r !== void 0 ? {
		...e,
		maxRangeDays: r * 7
	} : { ...e });
}
function T(e, t) {
	let n = s(e.maxRangeDays);
	if (n === void 0 || t === void 0) return !1;
	let r = a(t);
	return r !== null && r > n;
}
function E(e, t, n) {
	if (t.length === 0) return;
	let r = e === void 0 ? -1 : t.findIndex((t) => t.id === e), i = r >= 0 ? t[r] : void 0;
	return i && !T(i, n) ? i.id : (r >= 0 ? t.slice(r + 1) : t).find((e) => !T(e, n))?.id ?? t.find((e) => !T(e, n))?.id;
}
function D(e) {
	if (!i(e)) return;
	let t = o(e.start), n = o(e.end);
	return t && n ? {
		start: t,
		end: n
	} : void 0;
}
//#endregion
//#region src/period-select/PeriodSelect.tsx
function O({ value: i, onChange: a, options: o, dateRange: s, maxDayRangeDays: l, maxWeekRangeWeeks: u, ...d }) {
	let f = r(() => o ?? w({
		maxDayRangeDays: l,
		maxWeekRangeWeeks: u
	}), [
		l,
		u,
		o
	]), p = r(() => E(i, f, s), [
		s,
		f,
		i
	]), m = n(() => {
		p === void 0 || p === i || a(p);
	});
	return t(() => {
		m();
	}, [p, i]), /* @__PURE__ */ c(e, {
		...d,
		options: f,
		value: p,
		onChange: a,
		getOptionDisabled: (e) => T(e, s)
	});
}
//#endregion
export { m as DEFAULT_PERIOD_SELECT_MAX_DAY_RANGE_DAYS, h as DEFAULT_PERIOD_SELECT_MAX_WEEK_RANGE_WEEKS, p as DEFAULT_PERIOD_SELECT_PRESET_ID, _ as DEFAULT_PERIOD_SELECT_PRESET_IDS, f as PERIOD_SELECT_COMPONENT_ID, g as PERIOD_SELECT_OPTIONS, O as PeriodSelect, w as createPeriodSelectOptions, S as getPeriodSelectOption, T as isPeriodSelectOptionDisabled, y as isPeriodSelectPresetId, D as normalizePeriodSelectDateRangeConnectors, b as normalizePeriodSelectPresetIds, E as resolvePeriodSelectAvailableValue, C as resolvePeriodSelectDefaultValue, x as resolvePeriodSelectOptionsByIds };

//# sourceMappingURL=index.js.map