/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @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 customParseFormat = require('../../_chunks/dep-6e3fbdd7.js');
var _common_js_timePicker_const = require('../../_common/js/time-picker/const.js');
var button_button = require('../../button/button.js');
var hooks_useConfig = require('../../hooks/useConfig.js');
var _common_js_log_log = require('../../_common/js/log/log.js');
var timePicker_panel_singlePanel = require('./single-panel.js');
var timePicker_panel_props = require('./props.js');
var configProvider_useConfig = require('../../config-provider/useConfig.js');
require('../../_chunks/dep-7c884501.js');
require('../../loading/index.js');
require('../../utils/withInstall.js');
require('vue');
require('lodash/capitalize');
require('../../loading/directive.js');
require('lodash/isObject');
require('lodash/mapKeys');
require('lodash/isEqual');
require('../../loading/plugin.js');
require('../../config.js');
require('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../utils/easing.js');
require('../../loading/loading.js');
require('../../utils/render-tnode.js');
require('@babel/runtime/helpers/typeof');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../utils/transfer-dom.js');
require('../../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../../config-provider/context.js');
require('lodash/merge');
require('../../_common/js/global-config/default-config.js');
require('../../_common/js/global-config/locale/zh_CN.js');
require('../../utils/mixins.js');
require('../../loading/props.js');
require('../../loading/icon/gradient.js');
require('../../_common/js/loading/circle-adapter.js');
require('../../_common/js/utils/set-style.js');
require('../../_common/js/utils/helper.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isNumber');
require('lodash/isArray');
require('../../utils/ripple.js');
require('../../button/props.js');
require('lodash/debounce');
require('lodash/range');
require('lodash/padStart');
require('../../_common/js/time-picker/utils.js');
require('../props.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(customParseFormat.customParseFormat);
var _TimePickerPanel = VueCompositionAPI.defineComponent({
  name: "TTimePickerPanel",
  props: _objectSpread(_objectSpread({}, timePicker_panel_props.panelProps()), {}, {
    handleConfirmClick: Function,
    onChange: Function,
    onPick: Function,
    disableTime: Function
  }),
  setup: function setup(props, ctx) {
    var panelClassName = hooks_useConfig.usePrefixClass("time-picker__panel");
    var triggerScroll = VueCompositionAPI.ref(false);
    var _useConfig = 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;
      var formattedValue = dayjs__default["default"](props.value, props.format);
      if (props.value && formattedValue.isValid()) return formattedValue;
      if (isStepsSet) return dayjs__default["default"]().hour(0).minute(0).second(0);
      return dayjs__default["default"]().hour(0).minute(0).second(0).format(props.format);
    });
    var panelColUpdate = function panelColUpdate() {
      VueCompositionAPI.nextTick(function () {
        triggerScroll.value = true;
      });
    };
    var resetTriggerScroll = function resetTriggerScroll() {
      triggerScroll.value = false;
    };
    var handleChange = function handleChange(v, e) {
      var _props$onPick, _props$onChange;
      (_props$onPick = props.onPick) === null || _props$onPick === void 0 ? void 0 : _props$onPick.call(props, v, e);
      ctx.emit("pick", v, e);
      (_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 _common_js_log_log["default"].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(timePicker_panel_singlePanel["default"], {
      "props": _objectSpread({}, {
        value: dayjs__default["default"](this.value, this.format).isValid() ? this.value : this.defaultValue,
        onChange: this.handleChange,
        onPick: this.onPick,
        format: this.format || _common_js_timePicker_const.DEFAULT_FORMAT,
        steps: this.steps || _common_js_timePicker_const.DEFAULT_STEPS,
        triggerScroll: this.triggerScroll,
        disableTime: this.disableTime,
        resetTriggerScroll: this.resetTriggerScroll,
        isShowPanel: this.isShowPanel
      })
    })]), this.isFooterDisplay ? h("div", {
      "class": "".concat(this.panelClassName, "-section-footer")
    }, [h(button_button["default"], {
      "attrs": {
        "theme": "primary",
        "variant": "base",
        "size": "small"
      },
      "on": {
        "click": function click() {
          return _this.handleConfirmClick(_this.defaultValue);
        }
      }
    }, [this.global.confirm]), h("div", [!this.showNowTimeBtn ? h(button_button["default"], {
      "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(button_button["default"], {
        "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"] = _TimePickerPanel;
//# sourceMappingURL=time-picker-panel.js.map
