import { jsx as V } from "@emotion/react/jsx-runtime";
import { useModuleSkeleton as h } from "@m4l/core";
import { useMemo as D, useCallback as u } from "react";
import { useComponentSize as v } from "../../../../hooks/useComponentSize/index.js";
import { DAYS_OF_MONTH_PICKER_CLASSES as x } from "../../constants.js";
import { DayButtonStyled as z } from "../../slots/DaysOfMonthPickerSlots.js";
const N = (y) => {
  const {
    value: s,
    onChange: a,
    multiple: l = !1,
    disabledDays: m = [],
    disabled: i = !1,
    readOnly: r = !1,
    size: w
  } = y, d = h(), { currentSize: f } = v(w), A = D(
    () => ({
      disabled: i,
      readOnly: r
    }),
    [i, r]
  ), C = D(() => {
    const e = [];
    for (let t = 1; t <= 31; t++)
      e.push(t);
    return e;
  }, []), b = u(
    (e) => s === void 0 ? !1 : l ? Array.isArray(s) && s.includes(e) : s === e,
    [s, l]
  ), c = u(
    (e) => i || m.includes(e),
    [i, m]
  ), p = u(
    (e) => {
      if (!(c(e) || r || d))
        if (l) {
          const t = Array.isArray(s) ? s : [];
          if (t.includes(e)) {
            const o = t.filter((S) => S !== e);
            a?.(o);
          } else {
            const o = [...t, e];
            a?.(o);
          }
        } else
          a?.(s === e ? void 0 : e);
    },
    [l, s, a, c, r, d]
  ), k = u(
    (e) => {
      const t = b(e), n = c(e), o = {
        selected: t,
        disabled: n,
        readOnly: r,
        size: f
      }, S = e.toString().padStart(2, "0"), O = t ? `Día ${e} seleccionado` : `Día ${e} no seleccionado`;
      return /* @__PURE__ */ V(
        z,
        {
          label: S,
          variant: "text",
          disabled: n,
          onClick: () => p(e),
          ownerState: o,
          "aria-label": O,
          "aria-pressed": t,
          "aria-disabled": n || r,
          role: "button",
          tabIndex: n || r ? -1 : 0,
          className: x.day
        },
        e
      );
    },
    [
      b,
      c,
      r,
      p,
      f
    ]
  );
  return {
    days: C,
    ownerState: A,
    currentSize: f,
    isSkeleton: d,
    renderDay: k
  };
};
export {
  N as useDaysOfMonthPicker
};
