/**
 * tdesign v0.41.7
 * (c) 2022 tdesign
 * @license MIT
 */

'use strict';

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

var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var dayjs = require('dayjs');
var timePicker_panel_panelCol = require('../../_chunks/dep-648ca8b7.js');
var utils_mixins = require('../../utils/mixins.js');
var configProvider_configReceiver = require('../../config-provider/config-receiver.js');
var timePicker_interface = require('../interface.js');
var timePicker_constant = require('../constant.js');
var timePicker_panel_props = require('./props.js');
var button_button = require('../../button/button.js');
require('@babel/runtime/helpers/defineProperty');
require('vue');
require('lodash/debounce');
require('../../_chunks/dep-1641a31f.js');
require('../../config.js');
require('lodash/mergeWith');
require('../../config-provider/context.js');
require('lodash/merge');
require('../../_common/js/global-config/default-config.js');
require('../../_common/js/global-config/locale/zh_CN.js');
require('../props.js');
require('../../_chunks/dep-99705d51.js');
require('../../utils/classnames.js');
require('../../loading/index.js');
require('../../loading/loading.js');
require('../../loading/icon/gradient.js');
require('../../_common/js/loading/circle-adapter.js');
require('../../_common/js/utils/set-style.js');
require('../../_common/js/utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../utils/easing.js');
require('../../utils/render-tnode.js');
require('@babel/runtime/helpers/typeof');
require('../../utils/transfer-dom.js');
require('../../loading/props.js');
require('../../utils/withInstall.js');
require('lodash/capitalize');
require('../../loading/plugin.js');
require('../../button/props.js');
require('../../utils/ripple.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);

var name = "".concat(timePicker_constant.componentName, "__panel");
dayjs__default["default"].extend(timePicker_panel_panelCol.customParseFormat);
var PickerPanel = utils_mixins["default"](configProvider_configReceiver["default"]("timePicker")).extend({
  name: name,
  data: function data() {
    return {
      panel: null,
      isSetup: false
    };
  },
  components: {
    PanelCol: timePicker_panel_panelCol.PanelCol,
    TButton: button_button["default"]
  },
  props: timePicker_panel_props.panelProps(),
  computed: {
    sectionComponentName: function sectionComponentName() {
      return "".concat(name, "-section");
    },
    classNames: function classNames() {
      return this.rangePicker ? [name, this.sectionComponentName] : [name];
    },
    colValues: function colValues() {
      return this.value.map(function (el) {
        return el || dayjs__default["default"]();
      });
    },
    rangePicker: function rangePicker() {
      return this.colValues.length > 1;
    },
    formatField: function formatField() {
      var match = this.format.match(/(a\s+|A\s+)?(h+|H+)?:?(m+)?:?(s+)?(\s+a|\s+A)?/);

      var _match = _slicedToArray__default["default"](match, 6),
          startAChart = _match[1],
          hour = _match[2],
          minute = _match[3],
          second = _match[4],
          endAChart = _match[5];

      return {
        startAChart: startAChart,
        hour: hour,
        minute: minute,
        second: second,
        endAChart: endAChart
      };
    },
    cols: function cols() {
      var _this$formatField = this.formatField,
          startAChart = _this$formatField.startAChart,
          hour = _this$formatField.hour,
          minute = _this$formatField.minute,
          second = _this$formatField.second,
          endAChart = _this$formatField.endAChart;
      var res = [];
      startAChart && res.push(timePicker_interface.EPickerCols.meridiem);
      hour && res.push(timePicker_interface.EPickerCols.hour);
      minute && res.push(timePicker_interface.EPickerCols.minute);
      second && res.push(timePicker_interface.EPickerCols.second);
      endAChart && res.push(timePicker_interface.EPickerCols.meridiem);
      return res;
    },
    localeMeridiems: function localeMeridiems() {
      return [this.global.anteMeridiem, this.global.postMeridiem];
    },
    showNowTime: function showNowTime() {
      return !this.rangePicker && this.steps.filter(function (step) {
        return step !== 1;
      }).length < 1;
    }
  },
  watch: {
    isShowPanel: function isShowPanel(val) {
      if (val) {
        this.panelColUpdate();
      }
    }
  },
  mounted: function mounted() {
    this.panelColUpdate();
  },
  methods: {
    panelColUpdate: function panelColUpdate() {
      var _this = this;

      setTimeout(function () {
        var _this$$refs$panelCol_, _this$$refs$panelCol_2;

        (_this$$refs$panelCol_ = _this.$refs.panelCol_0) === null || _this$$refs$panelCol_ === void 0 ? void 0 : _this$$refs$panelCol_.updateTimeScrollPos();
        (_this$$refs$panelCol_2 = _this.$refs.panelCol_1) === null || _this$$refs$panelCol_2 === void 0 ? void 0 : _this$$refs$panelCol_2.updateTimeScrollPos();
      });
    },
    scrollToTime: function scrollToTime(colIndex, col, time, behavior) {
      var scroller = this.$refs["panelCol_".concat(colIndex)];
      scroller && scroller.scrollToTime(col, time, behavior);
    },
    renderFooter: function renderFooter() {
      var h = this.$createElement;
      var confirmAction = this.confirmBtnClick.bind(this);
      return h("div", {
        "class": "".concat(this.sectionComponentName, "-footer")
      }, [h("t-button", {
        "attrs": {
          "theme": "primary",
          "variant": "base"
        },
        "on": {
          "click": confirmAction
        }
      }, [this.t(this.global.confirm)]), this.showNowTime && h("t-button", {
        "attrs": {
          "theme": "primary",
          "variant": "text"
        },
        "on": {
          "click": this.nowAction
        }
      }, [this.t(this.global.now)])]);
    },
    renderBody: function renderBody() {
      var h = this.$createElement;
      return h("div", {
        "class": "".concat(this.sectionComponentName, "-body")
      }, [this.renderSinglePicker(0), this.rangePicker && this.renderSinglePicker(1)]);
    },
    renderSinglePicker: function renderSinglePicker(index) {
      var _this2 = this;

      var h = this.$createElement;
      var val = this.colValues[index];
      var ref = "panelCol_".concat(index);
      return h("panel-col", {
        "ref": ref,
        "attrs": {
          "value": val,
          "cols": this.cols,
          "steps": this.steps,
          "hideDisabledTime": this.hideDisabledTime,
          "disableTime": this.disableTime,
          "format": this.format,
          "localeMeridiems": this.localeMeridiems
        },
        "on": {
          "time-pick": function timePick(col, time) {
            return _this2.handleTimePick(col, time, index);
          }
        }
      });
    },
    confirmBtnClick: function confirmBtnClick(e) {
      this.$emit("sure", e);
    },
    nowAction: function nowAction() {
      this.$emit("now-action");
      this.panelColUpdate();
    },
    handleTimePick: function handleTimePick(col, time, index) {
      this.$emit("time-pick", col, time, index, this.colValues[index]);
    }
  },
  render: function render() {
    var h = arguments[0];
    var isFooterDisplay = this.isFooterDisplay,
        classNames = this.classNames;
    return h("div", {
      "class": classNames
    }, [this.renderBody(), isFooterDisplay ? this.renderFooter() : null]);
  }
});

exports["default"] = PickerPanel;
//# sourceMappingURL=index.js.map
