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

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, ref, computed, nextTick, onMounted, watch } from '@vue/composition-api';
import dayjs from 'dayjs';
import { c as customParseFormat } from '../../_chunks/dep-b98966c0.js';
import { DEFAULT_FORMAT, DEFAULT_STEPS } from '../../_common/js/time-picker/const.js';
import { panelProps } from './props.js';
import SinglePanel from './single-panel.js';
import TButton from '../../button/button.js';
import { usePrefixClass } from '../../hooks/useConfig.js';
import '../../_common/js/log/index.js';
import { useConfig } from '../../config-provider/useConfig.js';
import log from '../../_common/js/log/log.js';
import '../../_chunks/dep-a0d91f92.js';
import '../props.js';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/debounce';
import 'lodash/range';
import 'lodash/padStart';
import '../../_common/js/time-picker/utils.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/toConsumableArray';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../../config-provider/config-receiver.js';
import 'vue';
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 '../../utils/mixins.js';
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/camelCase';
import 'lodash/kebabCase';
import '../../utils/transfer-dom.js';
import '../../loading/props.js';
import '../../utils/withInstall.js';
import 'lodash/capitalize';
import './style/index.js';
import '../../loading/type.js';
import '../../loading/plugin.js';
import '../../config.js';
import '../../button/props.js';
import '../../utils/ripple.js';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
dayjs.extend(customParseFormat);
var _TimePickerPanel = defineComponent({
  name: "TimePickerPanel",
  props: _objectSpread(_objectSpread({}, panelProps()), {}, {
    handleConfirmClick: Function,
    onChange: Function,
    disableTime: Function
  }),
  setup: function setup(props, ctx) {
    var panelClassName = usePrefixClass("time-picker__panel");
    var triggerScroll = ref(false);

    var _useConfig = useConfig("timePicker"),
        global = _useConfig.global;

    var showNowTimeBtn = computed(function () {
      return !!props.steps.filter(function (v) {
        return v > 1;
      }).length;
    });
    var defaultValue = computed(function () {
      var isStepsSet = showNowTimeBtn.value;

      if (props.value) {
        return dayjs(props.value, props.format);
      }

      if (isStepsSet) {
        return dayjs().hour(0).minute(0).second(0);
      }

      return dayjs();
    });

    var panelColUpdate = function panelColUpdate() {
      nextTick(function () {
        triggerScroll.value = true;
      });
    };

    var resetTriggerScroll = function resetTriggerScroll() {
      triggerScroll.value = false;
    };

    var handleChange = function handleChange(v) {
      var _props$onChange;

      (_props$onChange = props.onChange) === null || _props$onChange === void 0 ? void 0 : _props$onChange.call(props, v);
      ctx.emit("change", v);
    };

    var handlePresetClick = function handlePresetClick(presetValue) {
      var presetVal = typeof presetValue === "function" ? presetValue() : presetValue;

      if (typeof props.activeIndex === "number") {
        if (Array.isArray(presetVal)) {
          props.onChange(presetVal[props.activeIndex]);
        } else {
          log.error("TimePicker", "preset: ".concat(props.presets, " \u9884\u8BBE\u503C\u5FC5\u987B\u662F\u6570\u7EC4!"));
        }
      } else {
        props.onChange(presetVal);
      }
    };

    onMounted(function () {
      panelColUpdate();
    });
    watch(function () {
      return props.isShowPanel;
    }, function () {
      panelColUpdate();
    });
    return {
      showNowTimeBtn: showNowTimeBtn,
      panelClassName: panelClassName,
      triggerScroll: triggerScroll,
      resetTriggerScroll: resetTriggerScroll,
      defaultValue: defaultValue,
      global: global,
      handleChange: handleChange,
      handlePresetClick: handlePresetClick
    };
  },
  render: function render() {
    var _this = this;

    var h = arguments[0];
    return h("div", {
      "class": this.panelClassName
    }, [h("div", {
      "class": "".concat(this.panelClassName, "-section-body")
    }, [h(SinglePanel, {
      "props": _objectSpread({}, {
        value: this.value,
        onChange: this.handleChange,
        format: this.format || DEFAULT_FORMAT,
        steps: this.steps || DEFAULT_STEPS,
        triggerScroll: this.triggerScroll,
        disableTime: this.disableTime,
        resetTriggerScroll: this.resetTriggerScroll
      })
    })]), this.isFooterDisplay ? h("div", {
      "class": "".concat(this.panelClassName, "-section-footer")
    }, [h(TButton, {
      "attrs": {
        "theme": "primary",
        "variant": "base",
        "size": "small"
      },
      "on": {
        "click": function click() {
          return _this.handleConfirmClick(_this.defaultValue);
        }
      }
    }, [this.global.confirm]), h("div", [!this.showNowTimeBtn ? h(TButton, {
      "attrs": {
        "theme": "primary",
        "variant": "text",
        "size": "small"
      },
      "on": {
        "click": function click() {
          return _this.onChange(dayjs().format(_this.format));
        }
      }
    }, [this.global.now]) : null, this.presets && Object.keys(this.presets).map(function (key) {
      return h(TButton, {
        "key": key,
        "attrs": {
          "theme": "primary",
          "size": "small",
          "variant": "text"
        },
        "on": {
          "click": function click() {
            var _this$handlePresetCli;

            return (_this$handlePresetCli = _this.handlePresetClick) === null || _this$handlePresetCli === void 0 ? void 0 : _this$handlePresetCli.call(_this, _this.presets[key]);
          }
        }
      }, [key]);
    })])]) : null]);
  }
});

export { _TimePickerPanel as default };
//# sourceMappingURL=time-picker-panel.js.map
