/**
 * ldesign v0.2.22
 * (c) 2022/12/7 16:21 built by swimly
 * @license MIT
 */

import { defineComponent, ref, computed, nextTick, onMounted, watch } from '@vue/composition-api';
import dayjs from 'dayjs';
import { c as customParseFormat, S as SinglePanel, D as DEFAULT_FORMAT, a as DEFAULT_STEPS } from '../../../chunks/single-panel.js';
import '../../../chunks/index.js';
import LButton from '../../button/button.js';
import { usePrefixClass } from '../../../hooks/useConfig.js';
import { panelProps } from './props.js';
import { useConfig } from '../../config-provider/useConfig.js';
import { l as log } from '../../../chunks/log.js';
import 'lodash/debounce';
import 'lodash/range';
import 'lodash/padStart';
import '../../../chunks/_commonjsHelpers.js';
import '../../../chunks/dayjs.min-0f6442fd.js';
import '../../../chunks/_commonjsHelpers-fe796db6.js';
import '@ldesign/icons-vue';
import '../../loading/index.js';
import '../../../utils/withInstall.js';
import 'vue';
import 'lodash/capitalize';
import '../../../config.js';
import '../../loading/loading.js';
import '../../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../../utils/easing.js';
import '../../../utils/render-node.js';
import 'lodash';
import '../../../utils/transfer-dom.js';
import '../../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../../config-provider/context.js';
import 'lodash/merge';
import '../../../chunks/zh_CN.js';
import '../../config-provider/type.js';
import '../../../utils/mixins.js';
import '../../loading/props.js';
import '../../loading/icon/gradient.js';
import '../../../chunks/defineProperty-19da3d4c.js';
import '../../../chunks/set-style.js';
import '../../../chunks/helper2.js';
import '../../loading/style/css.js';
import '../../loading/type.js';
import '../../loading/plugin.js';
import '../../../utils/ripple.js';
import '../../button/props.js';
import '../props.js';

dayjs.extend(customParseFormat);
var TTimePickerPanel = defineComponent({
  name: "TimePickerPanel",
  components: {
    LButton
  },
  props: {
    ...panelProps(),
    handleConfirmClick: Function,
    onChange: Function,
    onPick: Function,
    disableTime: Function
  },
  setup(props, ctx) {
    const panelClassName = usePrefixClass("time-picker__panel");
    const triggerScroll = ref(false);
    const {
      global
    } = useConfig("timePicker");
    const showNowTimeBtn = computed(() => !!props.steps.filter(v => v > 1).length);
    const defaultValue = computed(() => {
      const isStepsSet = showNowTimeBtn.value;
      if (props.value) return dayjs(props.value, props.format);
      if (isStepsSet) return dayjs().hour(0).minute(0).second(0);
      return dayjs();
    });
    const panelColUpdate = () => {
      nextTick(() => {
        triggerScroll.value = true;
      });
    };
    const resetTriggerScroll = () => {
      triggerScroll.value = false;
    };
    const handleChange = v => {
      props.onPick?.(v);
      ctx.emit("pick", v);
      props.onChange?.(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.error("TimePicker", `preset: ${props.presets} \u9884\u8BBE\u503C\u5FC5\u987B\u662F\u6570\u7EC4!`);
      } else {
        props.onChange(presetVal);
      }
    };
    onMounted(() => {
      panelColUpdate();
    });
    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(SinglePanel, {
      "props": {
        ...{
          value: this.value,
          onChange: this.handleChange,
          onPick: this.onPick,
          format: this.format || DEFAULT_FORMAT,
          steps: this.steps || 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().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": () => this.handlePresetClick?.(this.presets[key])
      }
    }, [key]))])]) : null]);
  }
});

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