/**
 * 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 dayjs = require('dayjs');
var components_timePicker_panel_singlePanel = require('../../../chunks/single-panel.js');
var log = require('../../../chunks/log.js');
var components_button_button = require('../../button/button.js');
var hooks_useConfig = require('../../../hooks/use-config.js');
var components_timePicker_panel_props = require('./props.js');
var components_configProvider_useConfig = require('../../config-provider/useConfig.js');
require('lodash/debounce');
require('lodash/range');
require('lodash/padStart');
require('../../../chunks/_commonjsHelpers.js');
require('../../../chunks/dayjs.min-c4f4ce86.js');
require('../../../chunks/_commonjsHelpers-2e6815bd.js');
require('@ldesign/icons-vue');
require('../../loading/index.js');
require('../../../utils/with-install.js');
require('vue');
require('lodash');
require('../../../config.js');
require('../../loading/loading.js');
require('../../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../../utils/easing.js');
require('../../../utils/render-node.js');
require('../../../utils/transfer-dom.js');
require('../../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../../config-provider/context.js');
require('../../../chunks/zh_CN.js');
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('../props.js');

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

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

dayjs__default["default"].extend(components_timePicker_panel_singlePanel.customParseFormat);
var TTimePickerPanel = VueCompositionAPI.defineComponent({
  name: "TimePickerPanel",
  components: {
    LButton: components_button_button["default"]
  },
  props: {
    ...components_timePicker_panel_props.panelProps(),
    handleConfirmClick: Function,
    onChange: Function,
    onPick: Function,
    disableTime: Function
  },
  setup(props, ctx) {
    const panelClassName = hooks_useConfig.usePrefixClass("time-picker__panel");
    const triggerScroll = VueCompositionAPI.ref(false);
    const {
      global
    } = components_configProvider_useConfig.useConfig("timePicker");
    const showNowTimeBtn = VueCompositionAPI.computed(() => !!props.steps.filter(v => v > 1).length);
    const defaultValue = VueCompositionAPI.computed(() => {
      const isStepsSet = showNowTimeBtn.value;
      if (props.value) return dayjs__default["default"](props.value, props.format);
      if (isStepsSet) return dayjs__default["default"]().hour(0).minute(0).second(0);
      return dayjs__default["default"]();
    });
    const panelColUpdate = () => {
      VueCompositionAPI.nextTick(() => {
        triggerScroll.value = true;
      });
    };
    const resetTriggerScroll = () => {
      triggerScroll.value = false;
    };
    const handleChange = v => {
      var _props$onPick, _props$onChange;
      (_props$onPick = props.onPick) === null || _props$onPick === void 0 ? void 0 : _props$onPick.call(props, v);
      ctx.emit("pick", v);
      (_props$onChange = props.onChange) === null || _props$onChange === void 0 ? void 0 : _props$onChange.call(props, v);
      ctx.emit("change", v);
    };
    const handlePresetClick = presetValue => {
      const presetVal = typeof presetValue === "function" ? presetValue() : presetValue;
      if (typeof props.activeIndex === "number") {
        if (Array.isArray(presetVal)) props.onChange(presetVal[props.activeIndex]);else log.log.error("TimePicker", `preset: ${props.presets} \u9884\u8BBE\u503C\u5FC5\u987B\u662F\u6570\u7EC4!`);
      } else {
        props.onChange(presetVal);
      }
    };
    VueCompositionAPI.onMounted(() => {
      panelColUpdate();
    });
    VueCompositionAPI.watch(() => props.isShowPanel, () => {
      panelColUpdate();
    });
    return {
      showNowTimeBtn,
      panelClassName,
      triggerScroll,
      resetTriggerScroll,
      defaultValue,
      global,
      handleChange,
      handlePresetClick
    };
  },
  render() {
    const h = arguments[0];
    return h("div", {
      "class": this.panelClassName
    }, [h("div", {
      "class": `${this.panelClassName}-section-body`
    }, [h(components_timePicker_panel_singlePanel.SinglePanel, {
      "props": {
        ...{
          value: this.value,
          onChange: this.handleChange,
          onPick: this.onPick,
          format: this.format || components_timePicker_panel_singlePanel.DEFAULT_FORMAT,
          steps: this.steps || components_timePicker_panel_singlePanel.DEFAULT_STEPS,
          triggerScroll: this.triggerScroll,
          disableTime: this.disableTime,
          resetTriggerScroll: this.resetTriggerScroll,
          isShowPanel: this.isShowPanel
        }
      }
    })]), this.isFooterDisplay ? h("div", {
      "class": `${this.panelClassName}-section-footer`
    }, [h("l-button", {
      "attrs": {
        "theme": "primary",
        "variant": "base",
        "size": "small"
      },
      "on": {
        "click": () => this.handleConfirmClick(this.defaultValue)
      }
    }, [this.global.confirm]), h("div", [!this.showNowTimeBtn ? h("l-button", {
      "attrs": {
        "theme": "primary",
        "variant": "text",
        "size": "small"
      },
      "on": {
        "click": () => this.onChange(dayjs__default["default"]().format(this.format))
      }
    }, [this.global.now]) : null, this.presets && Object.keys(this.presets).map(key => h("l-button", {
      "key": key,
      "attrs": {
        "theme": "primary",
        "size": "small",
        "variant": "text"
      },
      "on": {
        "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]);
  }
});

exports["default"] = TTimePickerPanel;
//# sourceMappingURL=time-picker-panel.js.map
