import { jsxs, jsx } from 'react/jsx-runtime';
import * as React from 'react';
import { useState, useId, isValidElement } from 'react';
import { c as cx } from './index-SvGbrGuT.js';
import { t as textFieldStyles } from './TextField.module-BP-hDP5m.js';
import { w as warnDeprecatedErrorUsage } from './utils-pudAMGnO.js';
import { F as FieldLabel } from './FieldLabel-DL0D6fvc.js';
import { I as Icon } from './Icon-Bcil6aBo.js';
import { Y as YearlessDateInputWithPicker } from './YearlessDateInputWithPicker-mW5KykHZ.js';
import { u as useLayoutPropsUtil } from './useLayoutPropsUtil-loxbyklF.js';
import { u as useOptionallyControlledState } from './useOptionallyControlledState-DbDuos5L.js';
import { H as Helper } from './Helper-B2UrgJvr.js';

import './DateFieldYearlessRange.css';const dateFieldYearlessRangeStyles = {
	"range-row": "_range-row_xox8l_1",
	"range-root": "_range-root_xox8l_12",
	"sr-only": "_sr-only_xox8l_23"
};

const SvgArrowForward = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: "1em", height: "1em", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("path", { d: "m12 4-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z" }));

const DateFieldYearlessRange = (props) => {
  const { layoutStyles, componentProps } = useLayoutPropsUtil(props);
  const {
    label,
    moreInfo,
    size,
    hideLabel = false,
    required,
    id: idProp,
    legendProps,
    errorAriaLive: _errorAriaLive,
    onFocus: onFocusProp,
    onBlur: onBlurProp,
    error,
    warning,
    disabled,
    disableHint,
    description,
    mode = "mm/dd",
    startLabel = "Start date",
    endLabel = "End date",
    disablePicker
  } = componentProps;
  const [value, setValue] = useOptionallyControlledState({
    controlledValue: props.value,
    defaultValue: props.defaultValue,
    onChange: props.onChange
  });
  const [openInfo, setOpenInfo] = useState(false);
  const handleFocus = (e) => {
    setOpenInfo(true);
    onFocusProp?.(e);
  };
  const handleBlur = (e) => {
    setOpenInfo(false);
    onBlurProp?.(e);
  };
  const labelUid = useId();
  const id = idProp ?? labelUid;
  const helperUid = useId();
  warnDeprecatedErrorUsage("DateFieldYearlessRange", error);
  const errorMessages = typeof error === "boolean" || error === void 0 ? void 0 : error;
  const handleStartDateChange = (startDate) => {
    setValue({
      ...value,
      startDate
    });
  };
  const handleEndDateChange = (endDate) => {
    setValue({
      ...value,
      endDate
    });
  };
  return /* @__PURE__ */ jsxs(
    "fieldset",
    {
      className: cx(
        textFieldStyles["textfield"],
        dateFieldYearlessRangeStyles["range-root"]
      ),
      "data-anv": "date-field-yearless-range",
      style: layoutStyles,
      children: [
        /* @__PURE__ */ jsx(
          FieldLabel,
          {
            el: "legend",
            moreInfo,
            moreInfoOpen: openInfo,
            required,
            ...legendProps,
            className: cx(
              legendProps?.className,
              hideLabel ? dateFieldYearlessRangeStyles["sr-only"] : void 0
            ),
            children: label
          }
        ),
        /* @__PURE__ */ jsxs("div", { className: dateFieldYearlessRangeStyles["range-row"], children: [
          /* @__PURE__ */ jsx(
            FieldLabel,
            {
              htmlFor: id + "-start",
              className: dateFieldYearlessRangeStyles["sr-only"],
              children: startLabel
            }
          ),
          /* @__PURE__ */ jsx(
            YearlessDateInputWithPicker,
            {
              id: id + "-start",
              size,
              error: !!error,
              required,
              disabled,
              mode,
              value: value?.startDate,
              onChange: (change) => handleStartDateChange(change.value),
              "aria-describedby": helperUid,
              disablePicker,
              onFocus: handleFocus,
              onBlur: handleBlur
            }
          ),
          /* @__PURE__ */ jsx(
            Icon,
            {
              svg: SvgArrowForward,
              className: dateFieldYearlessRangeStyles["range-arrow"]
            }
          ),
          /* @__PURE__ */ jsx(
            FieldLabel,
            {
              htmlFor: id + "-end",
              className: dateFieldYearlessRangeStyles["sr-only"],
              children: endLabel
            }
          ),
          /* @__PURE__ */ jsx(
            YearlessDateInputWithPicker,
            {
              id: id + "-end",
              size,
              error: !!error,
              required,
              disabled,
              mode,
              value: value?.endDate,
              onChange: (change) => handleEndDateChange(change.value),
              "aria-labelledby": labelUid,
              "aria-describedby": helperUid,
              disablePicker,
              onFocus: handleFocus,
              onBlur: handleBlur
            }
          )
        ] }),
        !disableHint || errorMessages || warning || description ? /* @__PURE__ */ jsx(
          Helper,
          {
            id: helperUid,
            hint: disableHint ? void 0 : `Format: ${mode}`,
            showCounter: false,
            error: typeof errorMessages === "string" || Array.isArray(errorMessages) ? errorMessages : void 0,
            warning,
            errorMessage: isValidElement(errorMessages) ? errorMessages : void 0,
            description
          }
        ) : null
      ]
    }
  );
};

export { DateFieldYearlessRange as D };
//# sourceMappingURL=DateFieldYearlessRange-COb8v2CG.js.map
