import { defineComponent as q, useSlots as J, ref as Q, computed as s, unref as t, isVNode as X, createVNode as R, Fragment as k, openBlock as u, createBlock as h, withCtx as g, createElementBlock as D, createTextVNode as S, toDisplayString as C, resolveDynamicComponent as ee, normalizeStyle as oe, isRef as te, renderList as w, createCommentVNode as ne, mergeProps as ae, createSlots as re, renderSlot as le, normalizeProps as ue, guardReactiveProps as de } from "vue";
import { SwapRightOutlined as ie } from "@ant-design/icons-vue";
import { InputGroup as se, Select as fe, SelectOption as pe, DatePicker as me } from "@aplus-frontend/antdv";
import { getTimeFormatToZone as T } from "@aplus-frontend/utils";
import d from "dayjs";
import { isNil as _, omit as A, isString as m, isFunction as ce } from "lodash-unified";
import "../../render/index.mjs";
import "../../hooks/index.mjs";
import { omitUndefined as ye } from "../../utils/index.mjs";
import { ApFieldDatePresetFormats as ve, PRESET_FORMAT_MAP as F, PRESET_FORMAT_PICK_MAP as he, PRESET_FORMAT_TIME_MAP as ge } from "../date/constant.mjs";
import { formatDayWithTimezone as ke } from "../date/helper.mjs";
import { useDateTimezone as Se } from "../hooks/use-date-timezone.mjs";
import { useDefaultPlaceholder as Ce } from "../hooks/use-default-placeholder.mjs";
import { useDefaultPresets as Pe } from "../hooks/use-default-presets.mjs";
import { useReadModeRender as Be } from "../hooks/use-read-mode-render.mjs";
import { useControllableValue as Oe } from "../../hooks/useControllableValue.mjs";
import Re from "../../render/render.mjs";
const De = {
  key: 0
}, We = /* @__PURE__ */ q({
  name: "ApFieldDateRange",
  __name: "index",
  props: {
    mode: {
      default: "edit"
    },
    class: {},
    style: {},
    emptyText: {
      default: "--"
    },
    customReadMode: {},
    id: {},
    defaultPickerValue: {},
    placeholder: {},
    disabled: {
      type: [Boolean, Array],
      default: void 0
    },
    disabledTime: {},
    ranges: {},
    separator: {
      type: [Object, String, Number, Boolean, null, Array],
      default: void 0
    },
    allowEmpty: {},
    onCalendarChange: {},
    onFocus: {},
    onBlur: {},
    onMousedown: {},
    onMouseup: {},
    onMouseenter: {},
    onMouseleave: {},
    onClick: {},
    direction: {},
    autocomplete: {},
    activePickerIndex: {},
    dateRender: {},
    panelRender: {},
    dropdownClassName: {},
    dropdownAlign: {},
    popupStyle: {},
    transitionName: {},
    allowClear: {
      type: Boolean,
      default: !0
    },
    autofocus: {
      type: Boolean,
      default: void 0
    },
    tabindex: {},
    open: {
      type: Boolean,
      default: void 0
    },
    defaultOpen: {
      type: Boolean,
      default: void 0
    },
    inputReadOnly: {
      type: Boolean,
      default: void 0
    },
    suffixIcon: {
      type: [Object, String, Number, Boolean, null, Array],
      default: void 0
    },
    clearIcon: {
      type: [Object, String, Number, Boolean, null, Array],
      default: void 0
    },
    getPopupContainer: {},
    inputRender: {},
    onOpenChange: {},
    onContextmenu: {},
    onKeydown: {},
    role: {},
    name: {},
    picker: {},
    prefixCls: {},
    disabledDate: {},
    showWeek: {
      type: Boolean
    },
    monthCellRender: {},
    locale: {},
    size: {},
    bordered: {
      type: Boolean,
      default: void 0
    },
    variant: {},
    showTime: {
      type: [Boolean, Object],
      default: void 0
    },
    showNow: {
      type: Boolean,
      default: void 0
    },
    order: {
      type: Boolean,
      default: void 0
    },
    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: {},
    timezone: {},
    readModeSeparator: {},
    presets: {
      type: [Array, Boolean, Object]
    }
  },
  emits: ["update:value"],
  setup(P, {
    expose: x,
    emit: z
  }) {
    const o = P, N = z, b = J(), B = Q(), i = s(() => ve.indexOf(o.format) > -1), c = s(() => i.value ? F[o.format] : o.format), {
      value: y,
      updateValue: M
    } = Oe(o, N), E = s(() => o.shownFormat ? o.shownFormat : i.value ? F[o.format] : o.format), V = Ce("DateRange", o), {
      currentTimezone: l
    } = Se(o), {
      presets: j,
      changeCurrentDate: I
    } = Pe({
      ...o,
      timezone: l
    }), f = (e, a, n = !0) => ke(l.value)(e, a, n), v = s(() => {
      const e = t(y);
      if (_(e) || !e?.length)
        return e;
      const a = l.value ? T(t(y)[0], l.value) : t(y)?.[0], n = o.timezone ? T(t(y)[1], l.value) : t(y)?.[1];
      return [d(a), d(n)];
    }), {
      renderer: U
    } = Be(o, v), H = s(() => t(i) ? o.picker ?? he[o.format] : o.picker), K = s(() => {
      const e = t(i) ? ge[o.format] : {};
      return {
        ...ye(A(o, ["value", "onUpdate:value", "onChange", "onOk", "format", "mode", "presets"])),
        placeholder: t(V),
        presets: t(j),
        ...e
      };
    });
    function W(e) {
      if (!e) {
        M(e);
        return;
      }
      let a = m(e[0]) ? d(e[0]) : e[0], n = m(e[1]) ? d(e[1]) : e[1];
      const r = t(i) ? t(c) : void 0;
      M([f(a, r), f(n, r, !1)]);
    }
    function G(e) {
      const a = m(e[0]) ? d(e[0]) : e[0], n = m(e[1]) ? d(e[1]) : e[1], r = t(i) ? t(c) : void 0, p = e[0] ? f(a, r) : null, O = e[1] ? f(n, r, !1) : null;
      o.onOk?.([p, O]);
    }
    function L(e) {
      e && I(), o.onOpenChange?.(e);
    }
    function Y(e, a) {
      if (_(e)) {
        o.onChange?.(e, a);
        return;
      }
      const n = m(e[0]) ? d(e[0]) : e[0], r = m(e[1]) ? d(e[1]) : e[1], p = t(i) ? t(c) : void 0, O = e[0] ? f(n, p) : null, $ = e[1] ? f(r, p, !1) : null;
      o.onChange?.([O, $], a);
    }
    const Z = s(() => {
      const e = o.readModeSeparator;
      if (e)
        return X(e) || ce(e) ? o.readModeSeparator : R(k, null, [o.readModeSeparator]);
      const a = b.readModeSeparator?.();
      return a ? R(k, null, [a]) : ie;
    });
    return x({
      focus: B.value?.focus(),
      blur: B.value?.blur()
    }), (e, a) => P.mode === "read" ? (u(), h(t(Re), {
      key: 0,
      renderer: t(U)
    }, {
      default: g(() => [v.value ? (u(), D("span", De, [S(C(v.value[0]?.format(c.value)) + " ", 1), (u(), h(ee(Z.value))), S(" " + C(v.value[1]?.format(c.value)), 1)])) : (u(), D(k, {
        key: 1
      }, [S(C(P.emptyText), 1)], 64))]),
      _: 1
    }, 8, ["renderer"])) : (u(), h(t(se), {
      key: 1,
      compact: "",
      style: oe({
        display: Array.isArray(o.timezone) && o.timezone.length ? "flex" : "block"
      })
    }, {
      default: g(() => [Array.isArray(o.timezone) && o.timezone.length ? (u(), h(t(fe), {
        key: 0,
        value: t(l),
        "onUpdate:value": a[0] || (a[0] = (n) => te(l) ? l.value = n : null),
        "default-active-first-option": "",
        "dropdown-match-select-width": !1
      }, {
        default: g(() => [(u(!0), D(k, null, w(o.timezone, (n) => (u(), h(t(pe), {
          key: n?.value,
          value: n?.value
        }, {
          default: g(() => [S(C(n?.label ?? n?.value), 1)]),
          _: 2
        }, 1032, ["value"]))), 128))]),
        _: 1
      }, 8, ["value"])) : ne("", !0), R(t(me).RangePicker, ae({
        ref_key: "rangePickerRef",
        ref: B
      }, K.value, {
        value: v.value,
        picker: H.value,
        format: E.value,
        "onUpdate:value": W,
        onChange: Y,
        onOk: G,
        onOpenChange: L
      }), re({
        _: 2
      }, [w(t(A)(b, "readModeSeparator"), (n, r) => ({
        name: r,
        fn: g((p) => [le(e.$slots, r, ue(de(p || {})))])
      }))]), 1040, ["value", "picker", "format"])]),
      _: 3
    }, 8, ["style"]));
  }
});
export {
  We as default
};
