/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
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_timePicker_panel_props = require('./props.js');
var components_button_button = require('../../button/button.js');
var hooks_useConfig = require('../../../hooks/use-config.js');
var components_configProvider_useConfig = require('../../config-provider/useConfig.js');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/debounce');
require('lodash/range');
require('lodash/padStart');
require('../../../chunks/_commonjsHelpers.js');
require('../../../chunks/dayjs.min-12eb376c.js');
require('@babel/runtime/helpers/typeof');
require('../../../chunks/_commonjsHelpers-ea2bee21.js');
require('../props.js');
require('@ldesign/icons-vue');
require('../../loading/index.js');
require('../../loading/loading.js');
require('../../loading/icon/gradient.js');
require('vue');
require('../../../chunks/defineProperty-28395935.js');
require('../../../chunks/set-style.js');
require('../../../chunks/helper2.js');
require('@babel/runtime/helpers/toConsumableArray');
require('../../../config.js');
require('../../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../../utils/easing.js');
require('../../../utils/render-node.js');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../../utils/transfer-dom.js');
require('../../loading/props.js');
require('../../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('lodash');
require('../../config-provider/context.js');
require('../../../chunks/zh_CN.js');
require('../../../utils/mixins.js');
require('../../../utils/with-install.js');
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 _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);

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__default["default"](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__default["default"].extend(components_timePicker_panel_singlePanel.customParseFormat);
var TTimePickerPanel = VueCompositionAPI.defineComponent({
  name: "TimePickerPanel",
  props: _objectSpread(_objectSpread({}, components_timePicker_panel_props.panelProps()), {}, {
    handleConfirmClick: Function,
    onChange: Function,
    disableTime: Function
  }),
  components: {
    LButton: components_button_button["default"]
  },
  setup: function setup(props, ctx) {
    var panelClassName = hooks_useConfig.usePrefixClass("time-picker__panel");
    var triggerScroll = VueCompositionAPI.ref(false);

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

    var showNowTimeBtn = VueCompositionAPI.computed(function () {
      return !!props.steps.filter(function (v) {
        return v > 1;
      }).length;
    });
    var defaultValue = VueCompositionAPI.computed(function () {
      var 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"]();
    });

    var panelColUpdate = function panelColUpdate() {
      VueCompositionAPI.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.log.error("TimePicker", "preset: ".concat(props.presets, " \u9884\u8BBE\u503C\u5FC5\u987B\u662F\u6570\u7EC4!"));
        }
      } else {
        props.onChange(presetVal);
      }
    };

    VueCompositionAPI.onMounted(function () {
      panelColUpdate();
    });
    VueCompositionAPI.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(components_timePicker_panel_singlePanel.SinglePanel, {
      "props": _objectSpread({}, {
        value: this.value,
        onChange: this.handleChange,
        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
      })
    })]), this.isFooterDisplay ? h("div", {
      "class": "".concat(this.panelClassName, "-section-footer")
    }, [h("l-button", {
      "attrs": {
        "theme": "primary",
        "variant": "base",
        "size": "small"
      },
      "on": {
        "click": function click() {
          return _this.handleConfirmClick(_this.defaultValue);
        }
      }
    }, [this.global.confirm]), h("div", [!this.showNowTimeBtn ? h("l-button", {
      "attrs": {
        "theme": "primary",
        "variant": "text",
        "size": "small"
      },
      "on": {
        "click": function click() {
          return _this.onChange(dayjs__default["default"]().format(_this.format));
        }
      }
    }, [this.global.now]) : null, this.presets && Object.keys(this.presets).map(function (key) {
      return h("l-button", {
        "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]);
  }
});

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