/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var VueCompositionAPI = require('@vue/composition-api');
var components_jumper_jumper = require('../../jumper/jumper.js');
var components_select_select = require('../../select/select.js');
var hooks_useConfig = require('../../../hooks/use-config.js');
var components_configProvider_useConfig = require('../../config-provider/useConfig.js');
require('lodash/isObject');
require('@ldesign/icons-vue');
require('../../../hooks/use-global-icon.js');
require('../../config-provider/context.js');
require('lodash');
require('../../../chunks/zh_CN.js');
require('../../button/index.js');
require('../../../utils/with-install.js');
require('vue');
require('../../../config.js');
require('../../button/button.js');
require('../../loading/index.js');
require('../../loading/loading.js');
require('../../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../../chunks/log.js');
require('../../../chunks/_commonjsHelpers-2e6815bd.js');
require('../../../utils/easing.js');
require('../../../utils/render-node.js');
require('../../../utils/transfer-dom.js');
require('../../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../../../utils/mixins.js');
require('../../loading/props.js');
require('../../loading/icon/gradient.js');
require('../../../chunks/defineProperty-838e4192.js');
require('../../../chunks/set-style.js');
require('../../../chunks/helper2.js');
require('../../loading/plugin.js');
require('../../../utils/ripple.js');
require('../../button/props.js');
require('../../jumper/props.js');
require('../../../chunks/helper.js');
require('lodash/isFunction');
require('lodash/debounce');
require('lodash/get');
require('lodash/cloneDeep');
require('lodash/isArray');
require('../../../hooks/use-default-value.js');
require('../../../hooks/use-vmodel.js');
require('lodash/kebabCase');
require('../../../hooks/lnode.js');
require('lodash/isEmpty');
require('lodash/camelCase');
require('../../../hooks/render-lnode.js');
require('../../popup/index.js');
require('../../../utils/map-props.js');
require('../../popup/popup.js');
require('@popperjs/core');
require('../../../utils/helper.js');
require('../../popup/props.js');
require('../../popup/container.js');
require('../../input/index.js');
require('../../input/input.js');
require('../../../utils/event.js');
require('../../input/props.js');
require('../../input/group.js');
require('../../tag/index.js');
require('../../tag/tag.js');
require('../../tag/props.js');
require('../../tag/check-tag.js');
require('../../select-input/index.js');
require('../../select-input/select-input.js');
require('../../select-input/props.js');
require('../../select-input/hooks/use-single.js');
require('lodash/pick');
require('../../select-input/hooks/use-multiple.js');
require('../../tag-input/index.js');
require('../../tag-input/tag-input.js');
require('../../tag-input/props.js');
require('../../tag-input/hooks/use-tag-scroll.js');
require('../../tag-input/hooks/use-tag-list.js');
require('../../tag-input/hooks/use-hover.js');
require('../../tag-input/hooks/use-drag-sorter.js');
require('../../select-input/hooks/use-overlay-innerstyle.js');
require('../../common/fake-arrow.js');
require('../../../hooks/use-form-disabled.js');
require('../../select/option.js');
require('../../checkbox/index.js');
require('../../checkbox/group.js');
require('lodash/intersection');
require('../../checkbox/checkbox.js');
require('../../checkbox/props.js');
require('../../../hooks/use-lazy-load.js');
require('../../../chunks/observe.js');
require('../../../hooks/use-common-classname.js');
require('../../select/utils.js');
require('../../select/props.js');
require('../../select/select-panel.js');
require('../../../hooks/use-virtual-scroll.js');
require('../../select/hooks/use-select-options.js');

var TDateHeader = VueCompositionAPI.defineComponent({
  name: "LDatePickerHeader",
  props: {
    mode: {
      type: String,
      default: "date"
    },
    year: Number,
    month: Number,
    onMonthChange: Function,
    onYearChange: Function,
    onJumperClick: Function
  },
  setup(props) {
    const {
      classPrefix
    } = components_configProvider_useConfig.useConfig("classPrefix");
    const COMPONENT_NAME = hooks_useConfig.usePrefixClass("date-picker__header");
    const {
      global
    } = components_configProvider_useConfig.useConfig("datePicker");
    const yearOptions = VueCompositionAPI.ref(initOptions(props.year));
    const showMonthPicker = props.mode === "date" || props.mode === "week";
    const nearestYear = VueCompositionAPI.computed(() => {
      var _yearOptions$value$fi;
      return ((_yearOptions$value$fi = yearOptions.value.find(option => option.value - props.year <= 9 && option.value - props.year >= 0)) === null || _yearOptions$value$fi === void 0 ? void 0 : _yearOptions$value$fi.value) || props.year;
    });
    const monthOptions = VueCompositionAPI.computed(() => global.value.months.map((item, index) => ({
      label: item,
      value: index
    })));
    function initOptions(year) {
      const options = [];
      if (props.mode === "year") {
        const extraYear = year % 10;
        const minYear = year - extraYear - 100;
        const maxYear = year - extraYear + 100;
        for (let i = minYear; i <= maxYear; i += 10) options.push({
          label: `${i} - ${i + 9}`,
          value: i + extraYear
        });
      } else {
        options.push({
          label: `${year}`,
          value: year
        });
        for (let i = 1; i <= 10; i++) {
          options.push({
            label: `${year + i}`,
            value: year + i
          });
          options.unshift({
            label: `${year - i}`,
            value: year - i
          });
        }
      }
      return options;
    }
    function loadMoreYear(year, type) {
      const options = [];
      if (props.mode === "year") {
        const extraYear = year % 10;
        if (type === "add") {
          for (let i = year - extraYear + 10; i <= year - extraYear + 50; i += 10) options.push({
            label: `${i} - ${i + 9}`,
            value: i
          });
        } else {
          for (let i = year - extraYear - 1; i > year - extraYear - 50; i -= 10) options.unshift({
            label: `${i - 9} - ${i}`,
            value: i
          });
        }
      } else if (type === "add") {
        for (let i = year + 1; i <= year + 10; i++) options.push({
          label: `${i}`,
          value: i
        });
      } else {
        for (let i = year - 1; i > year - 10; i--) options.unshift({
          label: `${i}`,
          value: i
        });
      }
      return options;
    }
    const labelMap = {
      year: {
        prev: global.value.preDecade,
        current: global.value.now,
        next: global.value.nextDecade
      },
      month: {
        prev: global.value.preYear,
        current: global.value.now,
        next: global.value.nextYear
      },
      date: {
        prev: global.value.preMonth,
        current: global.value.now,
        next: global.value.nextMonth
      }
    };
    function handlePanelTopClick(e) {
      var _e$stopPropagation;
      e === null || e === void 0 ? void 0 : (_e$stopPropagation = e.stopPropagation) === null || _e$stopPropagation === void 0 ? void 0 : _e$stopPropagation.call(e);
      const firstYear = yearOptions.value[0].value;
      const options = loadMoreYear(firstYear, "reduce");
      yearOptions.value = [...options, ...yearOptions.value];
    }
    function handlePanelBottomClick(e) {
      var _e$stopPropagation2;
      e === null || e === void 0 ? void 0 : (_e$stopPropagation2 = e.stopPropagation) === null || _e$stopPropagation2 === void 0 ? void 0 : _e$stopPropagation2.call(e);
      const lastYear = yearOptions.value.slice(-1)[0].value;
      const options = loadMoreYear(lastYear, "add");
      yearOptions.value = [...yearOptions.value, ...options];
    }
    function handleScroll(_ref) {
      let {
        e
      } = _ref;
      if (e.target.scrollTop === 0) handlePanelTopClick(e);else if (e.target.scrollTop === e.target.scrollHeight - e.target.clientHeight) handlePanelBottomClick(e);
    }
    return {
      COMPONENT_NAME,
      labelMap,
      nearestYear,
      classPrefix,
      monthOptions,
      yearOptions,
      showMonthPicker,
      handleScroll,
      handlePanelTopClick,
      handlePanelBottomClick
    };
  },
  render() {
    const h = arguments[0];
    const {
      COMPONENT_NAME,
      labelMap,
      nearestYear,
      classPrefix,
      monthOptions,
      yearOptions,
      showMonthPicker,
      handlePanelTopClick,
      handlePanelBottomClick
    } = this;
    return h("div", {
      "class": COMPONENT_NAME
    }, [h("div", {
      "class": `${COMPONENT_NAME}-controller`
    }, [showMonthPicker && h(components_select_select["default"], {
      "class": `${COMPONENT_NAME}-controller-month`,
      "props": {
        ...{
          value: this.month,
          options: monthOptions,
          onChange: val => {
            var _this$onMonthChange;
            return (_this$onMonthChange = this.onMonthChange) === null || _this$onMonthChange === void 0 ? void 0 : _this$onMonthChange.call(this, val);
          },
          popupProps: {
            attach: triggerElement => triggerElement.parentNode,
            overlayClassName: `${COMPONENT_NAME}-controller-month-popup`
          }
        }
      }
    }), h(components_select_select["default"], {
      "class": `${COMPONENT_NAME}-controller-year`,
      "props": {
        ...{
          value: this.mode === "year" ? nearestYear : this.year,
          options: yearOptions,
          onChange: val => {
            var _this$onYearChange;
            return (_this$onYearChange = this.onYearChange) === null || _this$onYearChange === void 0 ? void 0 : _this$onYearChange.call(this, val);
          },
          popupProps: {
            onScroll: this.handleScroll,
            attach: triggerElement => triggerElement.parentNode,
            overlayClassName: `${COMPONENT_NAME}-controller-year-popup`
          },
          panelTopContent: () => h("div", {
            "class": `${classPrefix}-select-option`,
            "on": {
              "click": handlePanelTopClick
            }
          }, ["..."]),
          panelBottomContent: () => h("div", {
            "class": `${classPrefix}-select-option`,
            "on": {
              "click": handlePanelBottomClick
            }
          }, ["..."])
        }
      }
    })]), h(components_jumper_jumper["default"], {
      "props": {
        ...{
          tips: labelMap[this.mode],
          onChange: this.onJumperClick,
          size: "small"
        }
      }
    })]);
  }
});

exports["default"] = TDateHeader;
//# sourceMappingURL=Header.js.map
