import { useModuleSkeleton as h, useModuleDictionary as M } from "@m4l/core";
import { useMemo as D, useCallback as u } from "react";
import { useComponentSize as W } from "../../../hooks/useComponentSize/index.js";
import { getDaysOfWeekFromDictionary as w } from "../helpers/getDaysOfWeekFromDictionary.js";
const L = (k) => {
  const {
    value: t,
    onChange: a,
    disabledDays: n = [],
    disabled: s = !1,
    readOnly: o = !1,
    size: p,
    multiple: d = !0
  } = k, { currentSize: i } = W(p), y = h(), { getLabel: f } = M(), S = D(() => w(f), [f]), b = u(
    (e) => {
      if (o || s || n.includes(e))
        return;
      const r = t ?? [], m = r.includes(e);
      let l;
      d ? m ? l = r.filter((c) => c !== e) : l = [...r, e].sort((c, O) => c - O) : l = m ? [] : [e], a?.(l);
    },
    [o, s, n, t, d, a]
  ), g = u(
    (e) => (t ?? []).includes(e),
    [t]
  ), C = u(
    (e) => s || n.includes(e),
    [s, n]
  ), z = D(
    () => ({
      size: i,
      disabled: s,
      readOnly: o
    }),
    [i, s, o]
  );
  return {
    currentSize: i,
    isSkeleton: y,
    daysOfWeek: S,
    handleDayClick: b,
    isDaySelected: g,
    isDayDisabled: C,
    ownerState: z
  };
};
export {
  L as useDaysOfWeekPicker
};
