/**
 * tdesign v0.39.1-alpha.1
 * (c) 2022 tdesign
 * @license MIT
 */

import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import dayjs from 'dayjs';
import { c as customParseFormat, P as PanelCol } from '../../_chunks/dep-dd9d9e20.js';
import mixins from '../../utils/mixins.js';
import getConfigReceiverMixins from '../../config-provider/config-receiver.js';
import { EPickerCols } from '../interface.js';
import { componentName } from '../constant.js';
import { panelProps } from './props.js';
import TButton from '../../button/button.js';
import '@babel/runtime/helpers/defineProperty';
import 'vue';
import 'lodash/debounce';
import '../../_chunks/dep-8526eb74.js';
import '../../config.js';
import 'lodash/mergeWith';
import '../../config-provider/context.js';
import 'lodash/merge';
import '../../_common/js/global-config/default-config.js';
import '../../_common/js/global-config/locale/zh_CN.js';
import '../../config-provider/type.js';
import '../type.js';
import '../props.js';
import '../../_chunks/dep-1ec74b8b.js';
import '../../utils/classnames.js';
import '../../loading/index.js';
import '../../loading/loading.js';
import '../../loading/icon/gradient.js';
import '../../_common/js/loading/circle-adapter.js';
import '../../_common/js/utils/set-style.js';
import '../../_common/js/utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../utils/easing.js';
import '../../utils/render-tnode.js';
import '@babel/runtime/helpers/typeof';
import 'lodash/isObject';
import '../../utils/transfer-dom.js';
import '../../loading/props.js';
import '../../utils/withInstall.js';
import 'lodash/capitalize';
import './style/css.js';
import '../../loading/type.js';
import '../../loading/plugin.js';
import '../../button/props.js';
import '../../utils/ripple.js';

var name = "".concat(componentName, "__panel");
dayjs.extend(customParseFormat);
var PickerPanel = mixins(getConfigReceiverMixins("timePicker")).extend({
  name: name,
  data: function data() {
    return {
      panel: null,
      isSetup: false
    };
  },
  components: {
    PanelCol: PanelCol,
    TButton: TButton
  },
  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();
      });
    },
    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(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(EPickerCols.meridiem);
      hour && res.push(EPickerCols.hour);
      minute && res.push(EPickerCols.minute);
      second && res.push(EPickerCols.second);
      endAChart && res.push(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]);
  }
});

export { PickerPanel as default };
//# sourceMappingURL=index.js.map
