"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import { useT } from "@open-mercato/shared/lib/i18n/context";
import { multiDayEventSpan } from "../../../lib/calendar/labels.js";
import { AllDayToggle, DateControl, LABEL_CLASS, TimeControl } from "./inputs.js";
const DATE_LABEL_TEXT = {
  starts: { key: "customers.calendar.editor.dates.starts", fallback: "Starts" },
  when: { key: "customers.calendar.editor.dates.when", fallback: "When" },
  sent: { key: "customers.calendar.editor.dates.sent", fallback: "Sent" },
  logged: { key: "customers.calendar.editor.dates.logged", fallback: "Logged" },
  due: { key: "customers.calendar.editor.dates.due", fallback: "Due" }
};
function DateTimeRow({
  label,
  date,
  time,
  showTime,
  locale,
  onDateChange,
  onTimeChange
}) {
  return /* @__PURE__ */ jsxs("div", { className: "flex w-full items-end gap-2.5", children: [
    /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-1.5", children: [
      /* @__PURE__ */ jsx("span", { className: LABEL_CLASS, children: label }),
      /* @__PURE__ */ jsx(DateControl, { value: date, onChange: onDateChange, ariaLabel: label, locale })
    ] }),
    showTime ? /* @__PURE__ */ jsx(TimeControl, { value: time, onChange: onTimeChange, ariaLabel: label }) : null
  ] });
}
function ScheduleSection({
  dateLabel,
  hasAllDay,
  hasEnd,
  allDay,
  date,
  startTime,
  endDate,
  endTime,
  locale,
  endsError,
  onAllDayChange,
  onDateChange,
  onStartTimeChange,
  onEndDateChange,
  onEndTimeChange
}) {
  const t = useT();
  const showTime = !(hasAllDay && allDay);
  const multiDaySpan = hasEnd && !endsError ? multiDayEventSpan(date, endDate) : 0;
  return /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-col gap-2.5", children: [
    hasAllDay ? /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center justify-between", children: [
      /* @__PURE__ */ jsx("span", { className: LABEL_CLASS, children: t("customers.calendar.editor.allDay", "All day") }),
      /* @__PURE__ */ jsx(AllDayToggle, { checked: allDay, onCheckedChange: onAllDayChange, label: t("customers.calendar.editor.allDay", "All day") })
    ] }) : null,
    /* @__PURE__ */ jsx(
      DateTimeRow,
      {
        label: t(DATE_LABEL_TEXT[dateLabel].key, DATE_LABEL_TEXT[dateLabel].fallback),
        date,
        time: startTime,
        showTime,
        locale,
        onDateChange,
        onTimeChange: onStartTimeChange
      }
    ),
    hasEnd ? /* @__PURE__ */ jsx(
      DateTimeRow,
      {
        label: t("customers.calendar.editor.dates.ends", "Ends"),
        date: endDate,
        time: endTime,
        showTime,
        locale,
        onDateChange: onEndDateChange,
        onTimeChange: onEndTimeChange
      }
    ) : null,
    endsError ? /* @__PURE__ */ jsx("p", { className: "text-xs text-status-error-text", children: endsError }) : null,
    multiDaySpan > 0 ? /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: t("customers.calendar.editor.multiDayHint", "Multi-day event \xB7 {count} days", { count: multiDaySpan }) }) : null
  ] });
}
export {
  ScheduleSection
};
//# sourceMappingURL=ScheduleSection.js.map
