"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const shared_esmBundler = require("../../../../../@vue/shared/dist/shared.esm-bundler.js");
const index$1 = require("../../../hooks/use-locale/index.js");
const index = require("../../../hooks/use-namespace/index.js");
const index$3 = require("../../button/index.js");
const selectController = require("./select-controller.js");
const index$2 = require("../../select/index.js");
const Vue = require("vue");
const dayjs_min = require("../../../../../../_virtual/dayjs.min.js");
var select_controller_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ Vue.defineComponent({
  name: "SelectController",
  __name: "select-controller",
  props: selectController.selectControllerProps,
  emits: selectController.selectControllerEmits,
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const nsSelect = index.useNamespace("calendar-select");
    const { t, lang } = index$1.useLocale();
    const monthOptions = Array.from({ length: 12 }, (_, index2) => {
      const actualMonth = index2 + 1;
      return {
        value: actualMonth,
        label: shared_esmBundler.isFunction(props.formatter) ? props.formatter(actualMonth, "month") : actualMonth
      };
    });
    const yearValue = Vue.computed(() => props.date.year());
    const monthValue = Vue.computed(() => props.date.month() + 1);
    const yearOptions = Vue.computed(() => {
      const years = [];
      for (let i = -10; i < 10; i++) {
        const year = yearValue.value + i;
        if (year > 0) {
          const label = shared_esmBundler.isFunction(props.formatter) ? props.formatter(year, "year") : year;
          years.push({
            value: year,
            label
          });
        }
      }
      return years;
    });
    const handleYearChange = (year) => {
      emit("date-change", dayjs_min.default(new Date(year, monthValue.value - 1, 1)).locale(lang.value));
    };
    const handleMonthChange = (month) => {
      emit("date-change", dayjs_min.default(new Date(yearValue.value, month - 1, 1)).locale(lang.value));
    };
    const selectToday = () => {
      emit("date-change", "today");
    };
    return (_ctx, _cache) => {
      return Vue.openBlock(), Vue.createElementBlock(Vue.Fragment, null, [
        Vue.createVNode(Vue.unref(index$2.ElSelect), {
          "model-value": yearValue.value,
          size: "small",
          class: Vue.normalizeClass(Vue.unref(nsSelect).e("year")),
          "validate-event": false,
          options: yearOptions.value,
          onChange: handleYearChange
        }, null, 8, [
          "model-value",
          "class",
          "options"
        ]),
        Vue.createVNode(Vue.unref(index$2.ElSelect), {
          "model-value": monthValue.value,
          size: "small",
          class: Vue.normalizeClass(Vue.unref(nsSelect).e("month")),
          "validate-event": false,
          options: Vue.unref(monthOptions),
          onChange: handleMonthChange
        }, null, 8, [
          "model-value",
          "class",
          "options"
        ]),
        Vue.createVNode(Vue.unref(index$3.ElButton), {
          size: "small",
          onClick: selectToday
        }, {
          default: Vue.withCtx(() => [Vue.createTextVNode(Vue.toDisplayString(Vue.unref(t)("el.datepicker.today")), 1)]),
          _: 1
        })
      ], 64);
    };
  }
});
exports.default = select_controller_vue_vue_type_script_setup_true_lang_default;
