import { defineComponent as g, ref as m, watch as y, computed as $, resolveComponent as r, openBlock as k, createElementBlock as B, createVNode as i, withCtx as v, createElementVNode as o, toDisplayString as D } from "vue";
import { Popover as E, Button as S, Input as O } from "ant-design-vue";
import { CalendarOutlined as w, DoubleLeftOutlined as M, DoubleRightOutlined as V } from "@ant-design/icons-vue";
import A from "dayjs";
const F = "G", P = g({
  name: `${F}SeasonPicker`,
  components: { CalendarOutlined: w, DoubleLeftOutlined: M, DoubleRightOutlined: V, Popover: E, Button: S, Input: O },
  props: {
    valueArr: {
      default: () => ["01-03", "04-06", "07-09", "10-12"],
      type: Array
    },
    value: {
      default: ""
    },
    valueFormat: {
      default: "YYYY-MM",
      type: String,
      validator: (e) => ["YYYY-MM", "YYYYQ", "YYYY-MM-DD"].includes(e)
    },
    getValue: {
      default: () => {
      },
      type: Function
    },
    disabled: {
      type: Boolean,
      default: !1
    }
  },
  setup(e, { emit: t }) {
    const u = m(""), d = m(0), c = m(!1), n = m((/* @__PURE__ */ new Date()).getFullYear()), Y = (l) => {
      c.value = l;
    }, p = () => {
      n.value = n.value * 1 - 1;
    }, C = () => {
      n.value = n.value * 1 + 1;
    }, b = (l) => {
      d.value = l + 1;
      const a = e.valueArr[l].split("-");
      e.getValue(n.value + a[0] + "-" + n.value + a[1]), c.value = !1, u.value = `${n.value}年${d.value}季度`;
      let s = "";
      e.valueFormat === "YYYY-MM" && (s = `${n.value}-${a[1]}`), e.valueFormat === "YYYYQ" && (s = `${n.value}Q${l + 1}`), e.valueFormat === "YYYY-MM-DD" && (s = A(`${n.value}-${Number(a[1]) + 1}-01`).subtract(1, "day").format(e.valueFormat)), t("input", s), t("change", s), t("update:value", s);
    }, _ = () => {
      t("input", ""), t("change", ""), t("update:value", "");
    };
    return y(() => e.value, () => {
      if (e.value) {
        const l = e.value.split("-");
        n.value = l[0].slice(0, 4);
        let a = null;
        e.valueFormat === "YYYYQ" ? (a = l[0].slice(4, 5), this.showValue = `${n.value}年${a}季度`) : (a = l[1], e.valueArr.forEach((s, h) => {
          s.indexOf(a) > -1 && (u.value = `${n.value}年${h + 1}季度`);
        }));
      }
    }, { immediate: !0 }), {
      year: n,
      showValue: u,
      showSeason: c,
      disabled: $(() => e.disabled),
      handleClickChange: Y,
      inputChange: _,
      prev: p,
      next: C,
      selectSeason: b
    };
  }
});
const I = (e, t) => {
  const u = e.__vccOpts || e;
  for (const [d, c] of t)
    u[d] = c;
  return u;
}, Q = { class: "ant-calendar-date-panel" }, L = { class: "ant-calendar-header" }, N = { class: "btn-year" }, R = {
  role: "button",
  class: "ant-calendar-ym-select"
}, U = { class: "ant-calendar-body" }, j = { class: "season" }, x = { class: "season" };
function G(e, t, u, d, c, n) {
  const Y = r("DoubleLeftOutlined"), p = r("Button"), C = r("DoubleRightOutlined"), b = r("CalendarOutlined"), _ = r("Input"), l = r("Popover");
  return k(), B("div", null, [
    i(l, {
      placement: "bottom",
      trigger: "click",
      visible: e.showSeason,
      onVisibleChange: e.handleClickChange
    }, {
      content: v(() => [
        o("div", Q, [
          o("div", L, [
            o("div", N, [
              i(p, {
                type: "text",
                class: "ant-calendar-prev-year-btn",
                onClick: e.prev
              }, {
                default: v(() => [
                  i(Y)
                ]),
                _: 1
              }, 8, ["onClick"]),
              o("span", R, D(e.year) + "年", 1),
              i(p, {
                type: "text",
                onClick: e.next,
                class: "ant-calendar-prev-year-btn"
              }, {
                default: v(() => [
                  i(C)
                ]),
                _: 1
              }, 8, ["onClick"])
            ])
          ]),
          o("div", U, [
            o("div", j, [
              o("b", {
                class: "cell",
                onClick: t[0] || (t[0] = (a) => e.selectSeason(0))
              }, "第一季度"),
              o("b", {
                class: "cell",
                onClick: t[1] || (t[1] = (a) => e.selectSeason(1))
              }, "第二季度")
            ]),
            o("div", x, [
              o("b", {
                class: "cell",
                onClick: t[2] || (t[2] = (a) => e.selectSeason(2))
              }, "第三季度"),
              o("b", {
                class: "cell",
                onClick: t[3] || (t[3] = (a) => e.selectSeason(3))
              }, "第四季度")
            ])
          ])
        ])
      ]),
      default: v(() => [
        i(_, {
          placeholder: "请选择季度",
          allowClear: "",
          value: e.showValue,
          "onUpdate:value": t[4] || (t[4] = (a) => e.showValue = a),
          disabled: e.disabled,
          onChange: e.inputChange
        }, {
          suffix: v(() => [
            i(b, { style: { color: "rgba(0, 0, 0, 0.45)" } })
          ]),
          _: 1
        }, 8, ["value", "disabled", "onChange"])
      ]),
      _: 1
    }, 8, ["visible", "onVisibleChange"])
  ]);
}
const f = /* @__PURE__ */ I(P, [["render", G], ["__scopeId", "data-v-068f36ec"]]);
f.install = function(e, t) {
  e.component(t || f.name, f);
};
const K = {
  title: "SeasonPicker 季度选择器",
  parts: "UI组件",
  category: "数据描述",
  status: "100%",
  // TODO: 组件若开发完成则填入"100%"，并删除该注释
  install(e) {
    e.component(f.name, f);
  }
};
export {
  f as SeasonPicker,
  K as default
};
