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

import { h as helper } from '../_chunks/dep-37d5b9c4.js';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, ref, toRefs, onMounted, onBeforeUnmount } from '@vue/composition-api';
import useVModel from '../hooks/useVModel.js';
import { renderTNodeJSXDefault } from '../utils/render-tnode.js';
import props from './props.js';
import { Popup } from '../popup/index.js';
import { useClickOutsider } from './utils/click-outsider.js';
import ColorPanel from './panel/index.js';
import DefaultTrigger from './trigger.js';
import { useBaseClassName } from './hooks.js';
import '@babel/runtime/helpers/typeof';
import 'vue';
import '../popup/popup.js';
import '@popperjs/core';
import '../config.js';
import '../utils/classnames.js';
import '../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../utils/easing.js';
import '../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import 'lodash/camelCase';
import '../_common/js/utils/set-style.js';
import '../popup/props.js';
import '../popup/container.js';
import '../utils/map-props.js';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import './style/index.js';
import '../popup/type.js';
import '@babel/runtime/helpers/toConsumableArray';
import '../config-provider/index.js';
import '../config-provider/config-provider.js';
import '../config-provider/type.js';
import '../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../hooks/useCommonClassName.js';
import './const.js';
import '../_common/js/color-picker/constants.js';
import './panel/header.js';
import 'tdesign-icons-vue';
import '../radio/index.js';
import '../radio/radio.js';
import '../radio/props.js';
import '../utils/event.js';
import '../radio/group.js';
import 'lodash/isNumber';
import '../radio/radio-group-props.js';
import '../radio/radio-button.js';
import '../radio/type.js';
import './panel/linear-gradient.js';
import './utils/index.js';
import '../_common/js/color-picker/index.js';
import '../_common/js/color-picker/cmyk.js';
import '../_common/js/color-picker/color.js';
import '@babel/runtime/helpers/classCallCheck';
import '@babel/runtime/helpers/createClass';
import 'tinycolor2';
import '../_common/js/color-picker/gradient.js';
import '../_common/js/color-picker/draggable.js';
import '../input-number/index.js';
import '../input-number/input-number.js';
import '@babel/runtime/helpers/asyncToGenerator';
import '@babel/runtime/regenerator';
import '../button/index.js';
import '../button/button.js';
import '../loading/index.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/helper.js';
import '../utils/transfer-dom.js';
import '../loading/props.js';
import '../loading/type.js';
import '../loading/plugin.js';
import '../button/props.js';
import '../utils/ripple.js';
import '../config-provider/config-receiver.js';
import '../utils/mixins.js';
import '../button/type.js';
import '../input/index.js';
import '../input/addon.js';
import '../input/input.js';
import 'lodash/kebabCase';
import '../input/props.js';
import '../input/input-group.js';
import '../input/type.js';
import '../input-number/props.js';
import '../input-number/type.js';
import './panel/base-props.js';
import './panel/saturation.js';
import '../select/index.js';
import '../select/select.js';
import 'lodash/isFunction';
import 'lodash/debounce';
import 'lodash/get';
import 'lodash/set';
import '../tag/index.js';
import '../tag/tag.js';
import '../tag/props.js';
import '../tag/check-tag.js';
import '../tag/check-tag-props.js';
import '../tag/type.js';
import '../common-components/fake-arrow.js';
import '../select/option.js';
import '../select/option-props.js';
import '../checkbox/index.js';
import '../checkbox/group.js';
import 'lodash/intersection';
import '../checkbox/checkbox.js';
import '../checkbox/props.js';
import '../checkbox/checkbox-group-props.js';
import '../checkbox/type.js';
import '../select/props.js';
import '../select/optionGroup.js';
import '../select/option-group-props.js';
import '../select/type.js';
import './panel/hue.js';
import './panel/slider.js';
import './panel/alpha.js';
import './panel/format/index.js';
import 'lodash/upperCase';
import './panel/format/inputs.js';
import 'lodash/throttle';
import './panel/format/config.js';
import './panel/swatches.js';
import 'lodash';
import '../hooks/useDefaultValue.js';

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(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 _ColorPicker = defineComponent({
  name: "TColorPicker",
  components: {
    TPopup: Popup,
    ColorPanel: ColorPanel,
    DefaultTrigger: DefaultTrigger
  },
  props: _objectSpread({}, props),
  setup: function setup(props2) {
    var baseClassName = useBaseClassName();
    var visible = ref(false);

    var setVisible = function setVisible(value2) {
      return visible.value = value2;
    };

    var _toRefs = toRefs(props2),
        value = _toRefs.value;

    var _useVModel = useVModel(value, props2.defaultValue, props2.onChange, "change"),
        _useVModel2 = _slicedToArray(_useVModel, 2),
        innerValue = _useVModel2[0],
        setInnerValue = _useVModel2[1];

    var handleChange = function handleChange(value2, context) {
      setInnerValue(value2, context);
    };

    var handlePaletteChange = function handlePaletteChange(context) {
      props2.onPaletteBarChange(context);
    };

    var refTrigger = ref();
    var refColorPanel = ref();

    var _useClickOutsider = useClickOutsider(),
        addClickOutsider = _useClickOutsider.addClickOutsider,
        removeClickOutsider = _useClickOutsider.removeClickOutsider;

    onMounted(function () {
      return addClickOutsider([refTrigger.value, refColorPanel.value], function () {
        return setVisible(false);
      });
    });
    onBeforeUnmount(function () {
      removeClickOutsider();
    });
    return {
      baseClassName: baseClassName,
      innerValue: innerValue,
      visible: visible,
      refTrigger: refTrigger,
      refColorPanel: refColorPanel,
      setVisible: setVisible,
      setInnerValue: setInnerValue,
      handleChange: handleChange,
      handlePaletteChange: handlePaletteChange
    };
  },
  render: function render() {
    var _this = this;

    var h = arguments[0];
    var popupProps = this.popupProps,
        disabled = this.disabled,
        innerValue = this.innerValue,
        baseClassName = this.baseClassName,
        setVisible = this.setVisible,
        handleChange = this.handleChange,
        handlePaletteChange = this.handlePaletteChange;

    var renderPopupContent = function renderPopupContent() {
      if (disabled) {
        return null;
      }

      return h("color-panel", helper([{
        "props": _objectSpread({}, _objectSpread(_objectSpread({}, _this.$props), {}, {
          value: innerValue
        })),
        "attrs": {
          "togglePopup": setVisible
        }
      }, {
        "on": {
          change: handleChange,
          handlePaletteChange: handlePaletteChange
        }
      }, {
        "ref": "refColorPanel"
      }]));
    };

    var popProps = _objectSpread(_objectSpread({
      placement: "bottom-left"
    }, popupProps || {}), {}, {
      trigger: "click",
      attach: "body",
      overlayClassName: [baseClassName],
      visible: this.visible,
      overlayStyle: {
        padding: 0
      }
    });

    return h("t-popup", {
      "props": _objectSpread({}, _objectSpread({}, popProps)),
      "attrs": {
        "content": renderPopupContent
      }
    }, [h("div", {
      "attrs": {
        "className": "".concat(baseClassName, "__trigger")
      },
      "on": {
        "click": function click() {
          return setVisible(!_this.visible);
        }
      },
      "ref": "refTrigger"
    }, [renderTNodeJSXDefault(this, "default", h("default-trigger", {
      "attrs": {
        "color": this.innerValue,
        "disabled": disabled,
        "input-props": this.inputProps,
        "handleTriggerChange": this.setInnerValue
      }
    }))])]);
  }
});

export { _ColorPicker as default };
//# sourceMappingURL=color-picker.js.map
