import { defineComponent as N, useSlots as j, ref as I, computed as r, unref as o, openBlock as s, createBlock as v, withCtx as d, createElementVNode as U, toDisplayString as g, normalizeStyle as H, createVNode as b, isRef as K, createElementBlock as W, Fragment as G, renderList as P, createTextVNode as L, createCommentVNode as Y, mergeProps as Z, createSlots as $, renderSlot as q, normalizeProps as J, guardReactiveProps as Q } from "vue";
import { InputGroup as X, FormItemRest as ee, Select as oe, SelectOption as te, DatePicker as ae } from "@aplus-frontend/antdv";
import { getTimeFormatToZone as ne } from "@aplus-frontend/utils";
import u from "dayjs";
import { isNil as w, omit as le } from "lodash-unified";
import "../../hooks/index.mjs";
import "../../render/index.mjs";
import { useDateTimezone as re } from "../hooks/use-date-timezone.mjs";
import { useDefaultPlaceholder as de } from "../hooks/use-default-placeholder.mjs";
import { useReadModeRender as ue } from "../hooks/use-read-mode-render.mjs";
import { ApFieldDatePresetFormats as ie, PRESET_FORMAT_MAP as R, PRESET_FORMAT_PICK_MAP as se, PRESET_FORMAT_TIME_MAP as me } from "./constant.mjs";
import { formatDayWithTimezone as pe } from "./helper.mjs";
import { useControllableValue as fe } from "../../hooks/useControllableValue.mjs";
import ce from "../../render/render.mjs";
const Fe = /* @__PURE__ */ N({
  name: "ApFieldDate",
  __name: "index",
  props: {
    mode: { default: "edit" },
    class: {},
    style: {},
    emptyText: { default: "--" },
    customReadMode: {},
    dropdownClassName: {},
    dropdownAlign: {},
    popupStyle: {},
    transitionName: {},
    placeholder: {},
    allowClear: { type: Boolean, default: !0 },
    autofocus: { type: Boolean, default: void 0 },
    disabled: { type: Boolean, default: void 0 },
    tabindex: {},
    open: { type: Boolean, default: void 0 },
    defaultOpen: { type: Boolean, default: void 0 },
    inputReadOnly: { type: Boolean, default: void 0 },
    id: {},
    presets: {},
    suffixIcon: { type: [Object, String, Number, Boolean, null, Array], default: void 0 },
    clearIcon: { type: [Object, String, Number, Boolean, null, Array], default: void 0 },
    getPopupContainer: {},
    panelRender: {},
    inputRender: {},
    onOpenChange: {},
    onPanelChange: {},
    onFocus: {},
    onBlur: {},
    onMousedown: {},
    onMouseup: {},
    onMouseenter: {},
    onMouseleave: {},
    onClick: {},
    onContextmenu: {},
    onKeydown: {},
    role: {},
    name: {},
    autocomplete: {},
    direction: {},
    showToday: { type: Boolean, default: void 0 },
    showTime: { type: [Boolean, Object], default: void 0 },
    picker: {},
    prefixCls: {},
    defaultPickerValue: {},
    disabledDate: {},
    showWeek: { type: Boolean },
    dateRender: {},
    monthCellRender: {},
    renderExtraFooter: {},
    onSelect: {},
    locale: {},
    size: {},
    bordered: { type: Boolean, default: void 0 },
    variant: {},
    showNow: { type: Boolean, default: void 0 },
    disabledTime: {},
    defaultOpenValue: {},
    showHour: { type: Boolean, default: void 0 },
    showMinute: { type: Boolean, default: void 0 },
    showSecond: { type: Boolean, default: void 0 },
    use12Hours: { type: Boolean, default: void 0 },
    hourStep: {},
    minuteStep: {},
    secondStep: {},
    hideDisabledOptions: { type: Boolean, default: void 0 },
    disabledHours: {},
    disabledMinutes: {},
    disabledSeconds: {},
    valueFormat: {},
    value: {},
    defaultValue: {},
    "onUpdate:value": {},
    onChange: {},
    onOk: {},
    format: { default: "Y-D" },
    shownFormat: {},
    formatBegins: { type: Boolean, default: !0 },
    timezone: {}
  },
  emits: ["update:value"],
  setup(m, { expose: C, emit: S }) {
    const O = j(), e = m, T = S, y = I(), { value: h, updateValue: B } = fe(
      e,
      T
    ), F = de("Date", e), { currentTimezone: i } = re(e), l = r(
      () => ie.indexOf(e.format) > -1
    ), _ = r(() => e.shownFormat ? e.shownFormat : l.value ? R[e.format] : e.format), p = r(
      () => l.value ? R[e.format] : e.format
    ), f = r(() => {
      if (w(o(h)))
        return;
      let t = u(o(h));
      return e.timezone && (t = u(ne(o(h), i.value))), t;
    }), { renderer: x } = ue(e, f), A = r(() => o(l) ? e.picker ?? se[e.format] : e.picker), M = r(() => {
      const t = o(l) ? me[e.format] : {};
      return {
        ...le(e, [
          "value",
          "defaultValue",
          "onChange",
          "onOk",
          "format",
          "onUpdate:value",
          "mode"
        ]),
        placeholder: o(F),
        ...t
      };
    }), k = (t, n, a = !0) => pe(i.value)(t, n, a);
    function D(t) {
      if (w(t)) {
        B(null);
        return;
      }
      const n = u(t);
      B(
        k(
          n,
          o(l) ? o(p) : void 0,
          e.formatBegins
        )
      );
    }
    function V(t, n) {
      const a = u(t), c = t ? k(
        a,
        o(l) ? o(p) : void 0,
        e.formatBegins
      ) : null;
      e.onChange?.(c, n);
    }
    function z(t) {
      const n = u(t), a = t ? k(
        n,
        o(l) ? o(p) : void 0,
        e.formatBegins
      ) : null;
      e.onOk?.(a);
    }
    return C({
      focus: () => y.value?.focus(),
      blur: () => y.value?.blur()
    }), (t, n) => m.mode === "read" ? (s(), v(o(ce), {
      key: 0,
      renderer: o(x)
    }, {
      default: d(() => [
        U("span", null, g(f.value ? o(u)(f.value).format(p.value) : m.emptyText), 1)
      ]),
      _: 1
    }, 8, ["renderer"])) : (s(), v(o(X), {
      key: 1,
      compact: "",
      style: H({
        display: Array.isArray(e.timezone) && e.timezone.length ? "flex" : "block"
      })
    }, {
      default: d(() => [
        b(o(ee), null, {
          default: d(() => [
            Array.isArray(e.timezone) && e.timezone.length ? (s(), v(o(oe), {
              key: 0,
              value: o(i),
              "onUpdate:value": n[0] || (n[0] = (a) => K(i) ? i.value = a : null),
              "default-active-first-option": "",
              "dropdown-match-select-width": !1,
              style: { "max-width": "50%" },
              disabled: m.disabled
            }, {
              default: d(() => [
                (s(!0), W(G, null, P(e.timezone, (a) => (s(), v(o(te), {
                  key: a?.value,
                  value: a?.value
                }, {
                  default: d(() => [
                    L(g(a?.label ?? a?.value), 1)
                  ]),
                  _: 2
                }, 1032, ["value"]))), 128))
              ]),
              _: 1
            }, 8, ["value", "disabled"])) : Y("", !0)
          ]),
          _: 1
        }),
        b(o(ae), Z({
          ref_key: "datePickerRef",
          ref: y
        }, M.value, {
          value: f.value,
          format: _.value,
          picker: A.value,
          "onUpdate:value": D,
          onChange: V,
          onOk: z
        }), $({ _: 2 }, [
          P(O, (a, c) => ({
            name: c,
            fn: d((E) => [
              q(t.$slots, c, J(Q(E || {})))
            ])
          }))
        ]), 1040, ["value", "format", "picker"])
      ]),
      _: 3
    }, 8, ["style"]));
  }
});
export {
  Fe as default
};
