import {
  getTimeOptions
} from "./chunk-NWJSLIQ3.js";
import {
  Select
} from "./chunk-X2GMDZ7M.js";
import {
  Flex
} from "./chunk-25HMMI7R.js";
import {
  __objRest,
  __spreadProps,
  __spreadValues
} from "./chunk-CRTRMMJ7.js";

// src/molecules/time-select.tsx
import { useMemo } from "react";
import { format } from "date-fns";
import { jsx, jsxs } from "react/jsx-runtime";
var getOptionValue = (date, timeValue) => {
  if (date && timeValue) {
    if (format(date, "yyyyMMdd") === format(timeValue, "yyyyMMdd")) {
      return format(date, "HH:mm");
    }
  }
};
function TimeSelect(_a) {
  var _b = _a, {
    value,
    maxTime,
    minTime,
    time
  } = _b, rest = __objRest(_b, [
    "value",
    "maxTime",
    "minTime",
    "time"
  ]);
  const timeOptions = useMemo(() => {
    return getTimeOptions();
  }, []);
  const [minOption, maxOption] = useMemo(() => {
    return [getOptionValue(minTime, time), getOptionValue(maxTime, time)];
  }, [maxTime, minTime, time]);
  return /* @__PURE__ */ jsxs(Select.Root, __spreadProps(__spreadValues({ value }, rest), { children: [
    /* @__PURE__ */ jsx(Flex, { direction: "column", width: "100%", children: /* @__PURE__ */ jsx(Select.Trigger, { placeholder: "-        ", style: { minWidth: "100px" }, children: value }) }),
    /* @__PURE__ */ jsx(Select.Content, { children: timeOptions.map((option) => {
      const visible = (!minOption || option >= minOption) && (!maxOption || option <= maxOption);
      if (!visible) {
        return null;
      }
      return /* @__PURE__ */ jsx(Select.Item, { value: option, children: option }, option);
    }) })
  ] }));
}

export {
  TimeSelect
};
//# sourceMappingURL=chunk-7PF6I4RN.js.map