import { jsx } from "react/jsx-runtime";
import { useState, useEffect } from "react";
import { DSControlledDateRangePicker } from "@elliemae/ds-controlled-form";
import {
  Controller
} from "react-hook-form";
const WrappedDateRangePicker = ({
  field: { value, onChange, ...restProps },
  ...rest
}) => {
  const [fromDateString, setFromDateString] = useState(
    value[0]
  );
  const [toDateString, setToDateString] = useState(
    value[1]
  );
  useEffect(() => {
    onChange([fromDateString, toDateString]);
  }, [fromDateString, toDateString]);
  return /* @__PURE__ */ jsx(
    DSControlledDateRangePicker,
    {
      ...restProps,
      fromDate: fromDateString,
      onFromDateChange: setFromDateString,
      toDate: toDateString,
      onToDateChange: setToDateString,
      ...rest
    }
  );
};
const DateRangePicker = ({
  name,
  defaultValue = ["", ""],
  rules = {},
  ...rest
}) => /* @__PURE__ */ jsx(
  Controller,
  {
    name,
    defaultValue,
    rules,
    render: ({ field }) => /* @__PURE__ */ jsx(WrappedDateRangePicker, { field, ...rest })
  }
);
export {
  DateRangePicker
};
