import { jsxs, jsx } from 'react/jsx-runtime';
import { forwardRef, useId, useMemo } from 'react';
import { F as FieldLabel } from './FieldLabel-Cm5A1Jcx.js';
import { B as ButtonToggle } from './ButtonToggle-DBGc7dIn.js';
import { T as Tooltip } from './Tooltip-BC8lnFhe.js';
import { F as Flex } from './Flex-Bb3iHExM.js';
import { H as Helper } from './Helper-B_VAFgGd.js';

import './DaysOfTheWeek.css';const styles = {
	"days-of-the-week-container": "_days-of-the-week-container_10v8m_1",
	"days-of-the-week": "_days-of-the-week_10v8m_1",
	"days-of-the-week-scroller": "_days-of-the-week-scroller_10v8m_15",
	"button-toggle-wrapper": "_button-toggle-wrapper_10v8m_23",
	"button-toggle": "_button-toggle_10v8m_23"
};

const DAYS = [
  { short: "Mo", full: "Monday" },
  { short: "Tu", full: "Tuesday" },
  { short: "We", full: "Wednesday" },
  { short: "Th", full: "Thursday" },
  { short: "Fr", full: "Friday" },
  { short: "Sa", full: "Saturday" },
  { short: "Su", full: "Sunday" }
];
const DaysOfTheWeek = forwardRef(
  (props, ref) => {
    const {
      selectedDays = [],
      onChange,
      disabled,
      firstDay = 7,
      hint,
      id: idProp,
      description,
      error,
      warning,
      errorMessage,
      errorAriaLive,
      label,
      required,
      moreInfo,
      labelProps
    } = props;
    const autoId = useId();
    const id = idProp ?? autoId;
    const labelUid = useId();
    const helperUid = useId();
    const hasHelperText = hint || error || warning || errorMessage || description;
    const orderedDays = useMemo(() => {
      const firstDayIndex = firstDay - 1;
      return [...DAYS.slice(firstDayIndex), ...DAYS.slice(0, firstDayIndex)];
    }, [firstDay]);
    const handleDayToggle = (index) => {
      const dayNumber = (index + firstDay - 1) % 7 + 1;
      const newSelectedDays = selectedDays.includes(dayNumber) ? selectedDays.filter((d) => d !== dayNumber) : [...selectedDays, dayNumber];
      onChange?.(newSelectedDays);
    };
    const isDayDisabled = (dayNumber) => {
      if (typeof disabled === "boolean") {
        return disabled;
      }
      if (Array.isArray(disabled)) {
        return disabled.includes(dayNumber);
      }
      return false;
    };
    return /* @__PURE__ */ jsxs("div", { className: styles["days-of-the-week-container"], children: [
      label ? /* @__PURE__ */ jsx(
        FieldLabel,
        {
          moreInfo,
          required,
          id: labelUid,
          htmlFor: id,
          ...labelProps,
          children: label
        }
      ) : null,
      /* @__PURE__ */ jsx("div", { ref, className: styles["days-of-the-week"], id, children: /* @__PURE__ */ jsx(Flex, { gap: 2, className: styles["days-of-the-week-scroller"], children: orderedDays.map((day, index) => {
        const dayNumber = (index + firstDay - 1) % 7 + 1;
        return /* @__PURE__ */ jsxs(Tooltip, { placement: "top", children: [
          /* @__PURE__ */ jsx(Tooltip.Trigger, { className: styles["button-toggle-wrapper"], children: /* @__PURE__ */ jsx(
            ButtonToggle,
            {
              checked: selectedDays.includes(dayNumber),
              onClick: () => handleDayToggle(index),
              disabled: isDayDisabled(dayNumber),
              className: styles["button-toggle"],
              id: label ? labelUid : void 0,
              "aria-describedby": hasHelperText ? helperUid : void 0,
              children: day.short
            }
          ) }),
          /* @__PURE__ */ jsx(Tooltip.Content, { children: day.full })
        ] }, day.short);
      }) }) }),
      hasHelperText ? /* @__PURE__ */ jsx(
        Helper,
        {
          id: helperUid,
          hint,
          description,
          error,
          warning,
          errorMessage,
          errorAriaLive
        }
      ) : null
    ] });
  }
);
DaysOfTheWeek.displayName = "DaysOfTheWeek";

export { DaysOfTheWeek as D };
//# sourceMappingURL=DaysOfTheWeek-Ci-SKebP.js.map
