"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const utils = require("./utils.js");
const index = require("../icon/index.js");
const props = require("../utils/props.js");
const create = require("../utils/create.js");
const constant = require("../utils/constant.js");
const [name] = create.createNamespace("calendar-header");
var stdin_default = Vue.defineComponent({
  name,
  props: {
    date: Date,
    minDate: Date,
    maxDate: Date,
    title: String,
    subtitle: String,
    showTitle: Boolean,
    showSubtitle: Boolean,
    firstDayOfWeek: Number,
    switchMode: props.makeStringProp("none")
  },
  emits: ["clickSubtitle", "panelChange"],
  setup(props2, {
    slots,
    emit
  }) {
    const prevMonthDisabled = Vue.computed(() => props2.date && props2.minDate && utils.compareMonth(utils.getPrevMonth(props2.date), props2.minDate) < 0);
    const prevYearDisabled = Vue.computed(() => props2.date && props2.minDate && utils.compareMonth(utils.getPrevYear(props2.date), props2.minDate) < 0);
    const nextMonthDisabled = Vue.computed(() => props2.date && props2.maxDate && utils.compareMonth(utils.getNextMonth(props2.date), props2.maxDate) > 0);
    const nextYearDisabled = Vue.computed(() => props2.date && props2.maxDate && utils.compareMonth(utils.getNextYear(props2.date), props2.maxDate) > 0);
    const renderTitle = () => {
      if (props2.showTitle) {
        const text = props2.title || utils.t("title");
        const title = slots.title ? slots.title() : text;
        return Vue.createVNode("div", {
          "class": utils.bem("header-title")
        }, [title]);
      }
    };
    const onClickSubtitle = (event) => emit("clickSubtitle", event);
    const onPanelChange = (date) => emit("panelChange", date);
    const renderAction = (isNext) => {
      const showYearAction = props2.switchMode === "year-month";
      const monthSlot = slots[isNext ? "next-month" : "prev-month"];
      const yearSlot = slots[isNext ? "next-year" : "prev-year"];
      const monthDisabled = isNext ? nextMonthDisabled.value : prevMonthDisabled.value;
      const yearDisabled = isNext ? nextYearDisabled.value : prevYearDisabled.value;
      const monthIconName = isNext ? "arrow" : "arrow-left";
      const yearIconName = isNext ? "arrow-double-right" : "arrow-double-left";
      const onMonthChange = () => onPanelChange((isNext ? utils.getNextMonth : utils.getPrevMonth)(props2.date));
      const onYearChange = () => onPanelChange((isNext ? utils.getNextYear : utils.getPrevYear)(props2.date));
      const MonthAction = Vue.createVNode("view", {
        "class": utils.bem("header-action", {
          disabled: monthDisabled
        }),
        "onClick": monthDisabled ? void 0 : onMonthChange
      }, [monthSlot ? monthSlot({
        disabled: monthDisabled
      }) : Vue.createVNode(index.Icon, {
        "class": {
          [constant.HAPTICS_FEEDBACK]: !monthDisabled
        },
        "name": monthIconName
      }, null)]);
      const YearAction = showYearAction && Vue.createVNode("view", {
        "class": utils.bem("header-action", {
          disabled: yearDisabled
        }),
        "onClick": yearDisabled ? void 0 : onYearChange
      }, [yearSlot ? yearSlot({
        disabled: yearDisabled
      }) : Vue.createVNode(index.Icon, {
        "class": {
          [constant.HAPTICS_FEEDBACK]: !yearDisabled
        },
        "name": yearIconName
      }, null)]);
      return isNext ? [MonthAction, YearAction] : [YearAction, MonthAction];
    };
    const renderSubtitle = () => {
      if (props2.showSubtitle) {
        const title = slots.subtitle ? slots.subtitle({
          date: props2.date,
          text: props2.subtitle
        }) : props2.subtitle;
        const canSwitch = props2.switchMode !== "none";
        return Vue.createVNode("div", {
          "class": utils.bem("header-subtitle", {
            "with-switch": canSwitch
          }),
          "onClick": onClickSubtitle
        }, [canSwitch ? [renderAction(), Vue.createVNode("div", {
          "class": utils.bem("header-subtitle-text")
        }, [title]), renderAction(true)] : title]);
      }
    };
    const renderWeekDays = () => {
      const {
        firstDayOfWeek
      } = props2;
      const weekdays = utils.t("weekdays");
      const renderWeekDays2 = [...weekdays.slice(firstDayOfWeek, 7), ...weekdays.slice(0, firstDayOfWeek)];
      return Vue.createVNode("div", {
        "class": utils.bem("weekdays")
      }, [renderWeekDays2.map((text) => Vue.createVNode("span", {
        "class": utils.bem("weekday")
      }, [text]))]);
    };
    return () => Vue.createVNode("div", {
      "class": utils.bem("header")
    }, [renderTitle(), renderSubtitle(), renderWeekDays()]);
  }
});
exports.default = stdin_default;
