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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
var input_index = require('../input/index.js');
var inputNumber_index = require('../input-number/index.js');
var colorPicker_hooks = require('./hooks.js');
var _common_js_colorPicker_color = require('../_common/js/color-picker/color.js');
require('../input/addon.js');
require('vue');
require('../config.js');
require('../input/input.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/typeof');
require('tdesign-icons-vue');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
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('../utils/classnames.js');
require('../utils/event.js');
require('../input/props.js');
require('../utils/render-tnode.js');
require('../input/input-group.js');
require('../utils/map-props.js');
require('../utils/withInstall.js');
require('lodash/capitalize');
require('../input-number/input-number.js');
require('../_chunks/dep-99705d51.js');
require('@babel/runtime/helpers/asyncToGenerator');
require('@babel/runtime/regenerator');
require('../button/index.js');
require('../button/button.js');
require('../loading/index.js');
require('../loading/loading.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('../utils/dom.js');
require('raf');
require('lodash/isString');
require('../utils/easing.js');
require('../utils/transfer-dom.js');
require('../loading/props.js');
require('../loading/plugin.js');
require('../button/props.js');
require('../utils/ripple.js');
require('../input-number/props.js');
require('../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('@babel/runtime/helpers/classCallCheck');
require('@babel/runtime/helpers/createClass');
require('tinycolor2');
require('../_common/js/color-picker/cmyk.js');
require('../_common/js/color-picker/gradient.js');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);

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; }
var DefaultTrigger = VueCompositionAPI.defineComponent({
  name: "DefaultTrigger",
  components: {
    TInput: input_index.Input,
    TInputNumber: inputNumber_index.InputNumber
  },
  inheritAttrs: false,
  props: {
    color: {
      type: String,
      "default": ""
    },
    disabled: {
      type: Boolean,
      "default": false
    },
    inputProps: {
      type: Object,
      "default": function _default() {
        return {
          autoWidth: true
        };
      }
    },
    handleTriggerChange: {
      type: Function,
      "default": function _default() {
        return function () {};
      }
    }
  },
  setup: function setup(props) {
    var baseClassName = colorPicker_hooks.useBaseClassName();
    var value = VueCompositionAPI.ref(props.color);
    VueCompositionAPI.watch(function () {
      return [props.color];
    }, function () {
      return value.value = props.color;
    });

    var handleChange = function handleChange(input) {
      if (input === props.color) {
        return;
      }

      if (!_common_js_colorPicker_color.Color.isValid(input)) {
        value.value = props.color;
      } else {
        value.value = input;
      }

      props.handleTriggerChange(value.value);
    };

    return {
      baseClassName: baseClassName,
      value: value,
      handleChange: handleChange
    };
  },
  render: function render() {
    var _this = this;

    var h = arguments[0];
    var baseClassName = this.baseClassName;
    var inputSlots = {
      label: function label() {
        return h("div", {
          "class": ["".concat(baseClassName, "__trigger--default__color"), "".concat(baseClassName, "--bg-alpha")]
        }, [h("span", {
          "class": ["color-inner"],
          "style": {
            background: _this.value
          }
        })]);
      }
    };
    return h("div", {
      "class": "".concat(baseClassName, "__trigger--default")
    }, [h("t-input", {
      "props": _objectSpread({}, _objectSpread({}, this.inputProps)),
      "scopedSlots": inputSlots,
      "attrs": {
        "disabled": this.disabled
      },
      "on": {
        "blur": this.handleChange
      },
      "model": {
        value: _this.value,
        callback: function callback($$v) {
          _this.value = $$v;
        }
      }
    })]);
  }
});

exports["default"] = DefaultTrigger;
//# sourceMappingURL=trigger.js.map
