/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, ref, computed } from '@vue/composition-api';
import { DeleteIcon, AddIcon } from '@ldesign/icons-vue';
import { cloneDeep } from 'lodash';
import { Select, Option } from '../../select/index.js';
import '../utils/index.js';
import { useBaseClassName } from '../hooks.js';
import { usePrefixClass } from '../../hooks/useConfig.js';
import { useGlobalIcon } from '../../hooks/useGlobalIcon.js';
import useCommonClassName from '../../hooks/useCommonClassName.js';
import { Button } from '../../button/index.js';
import baseProps from './base-props.js';
import { useConfig } from '../../config-provider/useConfig.js';
import { Color } from '../../_common/js/color-picker/color.js';
import '../../utils/withInstall.js';
import 'vue';
import 'lodash/capitalize';
import '../../select/select.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/typeof';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/isFunction';
import 'lodash/debounce';
import 'lodash/get';
import 'lodash/cloneDeep';
import 'lodash/isArray';
import 'lodash/isObject';
import '../../hooks/useDefaultValue.js';
import '../../hooks/useVModel.js';
import 'lodash/kebabCase';
import '../../hooks/tnode.js';
import 'lodash/isEmpty';
import 'lodash/camelCase';
import '../../hooks/render-tnode.js';
import 'lodash/isString';
import '../../loading/index.js';
import '../../loading/directive.js';
import 'lodash/mapKeys';
import 'lodash/isEqual';
import '../../loading/plugin.js';
import '../../config.js';
import '../../utils/dom.js';
import 'raf';
import '../../utils/easing.js';
import '../../loading/loading.js';
import '../../utils/render-tnode.js';
import '../../utils/transfer-dom.js';
import '../../config-provider/config-receiver.js';
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 '../../_chunks/dep-be599ec8.js';
import 'dayjs';
import '../../_chunks/dep-67ff4010.js';
import '../../config-provider/type.js';
import '../../utils/mixins.js';
import '../../loading/props.js';
import '../../loading/icon/gradient.js';
import '../../_common/js/loading/circle-adapter.js';
import '../../_common/js/utils/set-style.js';
import '../../_common/js/utils/helper.js';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import '../../loading/style/css.js';
import '../../loading/type.js';
import '../../popup/index.js';
import '../../utils/map-props.js';
import '../../popup/popup.js';
import '@popperjs/core';
import '../../utils/helper.js';
import '../../utils/event.js';
import '../../popup/props.js';
import '../../popup/container.js';
import '../../popup/utils.js';
import '../../popup/trigger.js';
import '../../popup/style/css.js';
import '../../popup/type.js';
import '../../popup/plugin.js';
import '../../input/index.js';
import '../../input/input.js';
import '../../_chunks/dep-c89aafbb.js';
import '../../_common/js/log/index.js';
import '../../_common/js/log/log.js';
import '../../input/props.js';
import '../../input/input-group.js';
import '../../input/style/css.js';
import '../../input/type.js';
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/style/css.js';
import '../../tag/type.js';
import '../../select-input/index.js';
import '../../select-input/select-input.js';
import '../../select-input/props.js';
import '../../select-input/useSingle.js';
import 'lodash/pick';
import '../../select-input/useMultiple.js';
import '../../tag-input/index.js';
import '../../tag-input/tag-input.js';
import '../../tag-input/props.js';
import '../../tag-input/hooks/useTagScroll.js';
import '../../tag-input/useTagList.js';
import '../../tag-input/hooks/useHover.js';
import '../../tag-input/hooks/useDragSorter.js';
import '../../tag-input/style/css.js';
import '../../tag-input/type.js';
import '../../tag-input/interface.js';
import '../../select-input/useOverlayInnerStyle.js';
import '../../select-input/style/css.js';
import '../../select-input/type.js';
import '../../common-components/fake-arrow.js';
import '../../hooks/useFormDisabled.js';
import '../../select/option.js';
import '../../utils/ripple.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/style/css.js';
import '../../checkbox/type.js';
import '../../hooks/useLazyLoad.js';
import '../../_common/js/utils/observe.js';
import '../../select/util.js';
import '../../select/option-props.js';
import '../../select/select-panel.js';
import '../../hooks/useVirtualScroll.js';
import '../../select/hooks/useSelectOptions.js';
import '../../select/props.js';
import '../../select/optionGroup.js';
import '../../select/option-group-props.js';
import '../../select/style/css.js';
import '../../select/type.js';
import '../../_common/js/color-picker/index.js';
import '../../_common/js/color-picker/cmyk.js';
import '../../_common/js/color-picker/draggable.js';
import '@babel/runtime/helpers/classCallCheck';
import '@babel/runtime/helpers/createClass';
import '../../_common/js/color-picker/gradient.js';
import 'tinycolor2';
import '../../button/button.js';
import '../../button/props.js';
import '../../button/style/css.js';
import '../../button/type.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 SwatchesPanel = defineComponent({
  name: "SwatchesPanel",
  components: {
    TSelect: Select,
    TOption: Option,
    TButton: Button
  },
  props: _objectSpread(_objectSpread({}, baseProps), {}, {
    colors: {
      type: Array,
      "default": function _default() {
        return [];
      }
    },
    title: {
      type: String,
      "default": "\u7CFB\u7EDF\u8272\u5F69"
    },
    editable: {
      type: Boolean,
      "default": false
    },
    handleSetColor: {
      type: Function,
      "default": function _default() {
        return function () {};
      }
    },
    handleAddColor: {
      type: Function,
      "default": function _default() {
        return function () {};
      }
    }
  }),
  setup: function setup(props) {
    var baseClassName = useBaseClassName();
    var _useConfig = useConfig("colorPicker"),
      t = _useConfig.t,
      global = _useConfig.global;
    var _useConfig2 = useConfig("popconfirm"),
      confirmGlobal = _useConfig2.global;
    var classPrefix = usePrefixClass();
    var _useGlobalIcon = useGlobalIcon({
        DeleteIcon: DeleteIcon,
        AddIcon: AddIcon
      }),
      DeleteIcon$1 = _useGlobalIcon.DeleteIcon,
      AddIcon$1 = _useGlobalIcon.AddIcon;
    var _useCommonClassName = useCommonClassName(),
      statusClassNames = _useCommonClassName.statusClassNames;
    var visiblePopConfirm = ref(false);
    var colorInstance = computed(function () {
      return cloneDeep(props.color);
    });
    var setVisiblePopConfirm = function setVisiblePopConfirm(visible) {
      visiblePopConfirm.value = visible;
    };
    var handleClick = function handleClick(color) {
      props.handleSetColor(color);
    };
    var isEqualCurrentColor = function isEqualCurrentColor(color) {
      return Color.compare(color, colorInstance.value.css);
    };
    var selectedColorIndex = computed(function () {
      return props.colors.findIndex(function (color) {
        return isEqualCurrentColor(color);
      });
    });
    var handleRemoveColor = function handleRemoveColor() {
      var _props$handleChange;
      var colors = _toConsumableArray(props.colors);
      var selectedIndex = selectedColorIndex.value;
      if (selectedIndex > -1) colors.splice(selectedIndex, 1);else colors.length = 0;
      (_props$handleChange = props.handleChange) === null || _props$handleChange === void 0 ? void 0 : _props$handleChange.call(props, colors);
      setVisiblePopConfirm(false);
    };
    return {
      t: t,
      global: global,
      confirmGlobal: confirmGlobal,
      classPrefix: classPrefix,
      DeleteIcon: DeleteIcon$1,
      AddIcon: AddIcon$1,
      baseClassName: baseClassName,
      statusClassNames: statusClassNames,
      selectedColorIndex: selectedColorIndex,
      visiblePopConfirm: visiblePopConfirm,
      setVisiblePopConfirm: setVisiblePopConfirm,
      handleClick: handleClick,
      isEqualCurrentColor: isEqualCurrentColor,
      handleRemoveColor: handleRemoveColor
    };
  },
  render: function render() {
    var _this = this;
    var h = arguments[0];
    var baseClassName = this.baseClassName,
      statusClassNames = this.statusClassNames,
      title = this.title,
      editable = this.editable,
      DeleteIcon = this.DeleteIcon,
      AddIcon = this.AddIcon;
    var swatchesClass = "".concat(baseClassName, "__swatches");
    var renderActions = function renderActions() {
      if (!editable) return null;
      return h("div", {
        "class": "".concat(swatchesClass, "--actions")
      }, [h("span", {
        "attrs": {
          "role": "button"
        },
        "class": "".concat(baseClassName, "__icon"),
        "on": {
          "click": function click() {
            return _this.handleAddColor();
          }
        }
      }, [h(AddIcon)]), _this.colors.length > 0 ? h("span", {
        "attrs": {
          "role": "button"
        },
        "class": "".concat(baseClassName, "__icon"),
        "on": {
          "click": function click() {
            return _this.handleRemoveColor();
          }
        }
      }, [h(DeleteIcon)]) : null]);
    };
    return h("div", {
      "class": swatchesClass
    }, [h("h3", {
      "class": "".concat(swatchesClass, "--title")
    }, [h("span", [title]), renderActions()]), h("ul", {
      "class": ["".concat(swatchesClass, "--items"), "narrow-scrollbar"]
    }, [this.colors.map(function (color) {
      return h("li", {
        "class": ["".concat(swatchesClass, "--item"), _this.isEqualCurrentColor(color) && editable ? statusClassNames.active : ""],
        "key": color,
        "on": {
          "click": function click() {
            if (_this.disabled) return;
            _this.handleClick(color);
          }
        }
      }, [h("div", {
        "class": ["".concat(swatchesClass, "--color"), "".concat(baseClassName, "--bg-alpha")]
      }, [h("span", {
        "class": "".concat(swatchesClass, "--inner"),
        "style": {
          background: color
        }
      })])]);
    })])]);
  }
});

export { SwatchesPanel as default };
//# sourceMappingURL=swatches.js.map
