/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

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

var VueCompositionAPI = require('@vue/composition-api');
var iconsVue = require('@ldesign/icons-vue');
var lodash = require('lodash');
var components_select_index = require('../../select/index.js');
var color = require('../../../chunks/color.js');
var components_colorPicker_hooks_index = require('../hooks/index.js');
var hooks_useConfig = require('../../../hooks/use-config.js');
var hooks_useGlobalIcon = require('../../../hooks/use-global-icon.js');
var hooks_useCommonClassname = require('../../../hooks/use-common-classname.js');
var components_button_index = require('../../button/index.js');
var components_colorPicker_panel_baseProps = require('./base-props.js');
var components_configProvider_useConfig = require('../../config-provider/useConfig.js');
require('../../../utils/with-install.js');
require('vue');
require('../../../config.js');
require('../../select/select.js');
require('../../../chunks/helper.js');
require('lodash/isFunction');
require('lodash/debounce');
require('lodash/get');
require('lodash/cloneDeep');
require('lodash/isArray');
require('lodash/isObject');
require('../../../chunks/log.js');
require('../../../chunks/_commonjsHelpers-2e6815bd.js');
require('../../../hooks/use-default-value.js');
require('../../../hooks/use-vmodel.js');
require('lodash/kebabCase');
require('../../../hooks/lnode.js');
require('lodash/isEmpty');
require('lodash/camelCase');
require('../../../hooks/render-lnode.js');
require('../../loading/index.js');
require('../../loading/loading.js');
require('../../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../../utils/easing.js');
require('../../../utils/render-node.js');
require('../../../utils/transfer-dom.js');
require('../../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../../config-provider/context.js');
require('../../../chunks/zh_CN.js');
require('../../../utils/mixins.js');
require('../../loading/props.js');
require('../../loading/icon/gradient.js');
require('../../../chunks/defineProperty-838e4192.js');
require('../../../chunks/set-style.js');
require('../../../chunks/helper2.js');
require('../../loading/plugin.js');
require('../../popup/index.js');
require('../../../utils/map-props.js');
require('../../popup/popup.js');
require('@popperjs/core');
require('../../../utils/helper.js');
require('../../popup/props.js');
require('../../popup/container.js');
require('../../input/index.js');
require('../../input/input.js');
require('../../../utils/event.js');
require('../../input/props.js');
require('../../input/group.js');
require('../../tag/index.js');
require('../../tag/tag.js');
require('../../tag/props.js');
require('../../tag/check-tag.js');
require('../../select-input/index.js');
require('../../select-input/select-input.js');
require('../../select-input/props.js');
require('../../select-input/hooks/use-single.js');
require('lodash/pick');
require('../../select-input/hooks/use-multiple.js');
require('../../tag-input/index.js');
require('../../tag-input/tag-input.js');
require('../../tag-input/props.js');
require('../../tag-input/hooks/use-tag-scroll.js');
require('../../tag-input/hooks/use-tag-list.js');
require('../../tag-input/hooks/use-hover.js');
require('../../tag-input/hooks/use-drag-sorter.js');
require('../../select-input/hooks/use-overlay-innerstyle.js');
require('../../common/fake-arrow.js');
require('../../../hooks/use-form-disabled.js');
require('../../select/option.js');
require('../../../utils/ripple.js');
require('../../checkbox/index.js');
require('../../checkbox/group.js');
require('lodash/intersection');
require('../../checkbox/checkbox.js');
require('../../checkbox/props.js');
require('../../../hooks/use-lazy-load.js');
require('../../../chunks/observe.js');
require('../../select/utils.js');
require('../../select/props.js');
require('../../select/select-panel.js');
require('../../../hooks/use-virtual-scroll.js');
require('../../select/hooks/use-select-options.js');
require('../../select/option-group.js');
require('../../button/button.js');
require('../../button/props.js');

var SwatchesPanel = VueCompositionAPI.defineComponent({
  name: "SwatchesPanel",
  components: {
    LSelect: components_select_index.Select,
    LOption: components_select_index.Option,
    LButton: components_button_index.Button
  },
  props: {
    ...components_colorPicker_panel_baseProps["default"],
    colors: {
      type: Array,
      default: () => []
    },
    title: {
      type: String,
      default: "\u7CFB\u7EDF\u8272\u5F69"
    },
    editable: {
      type: Boolean,
      default: false
    },
    handleSetColor: {
      type: Function,
      default: () => () => {}
    },
    handleAddColor: {
      type: Function,
      default: () => () => {}
    }
  },
  setup(props) {
    const baseClassName = components_colorPicker_hooks_index.useBaseClassName();
    const {
      t,
      global
    } = components_configProvider_useConfig.useConfig("colorPicker");
    const {
      global: confirmGlobal
    } = components_configProvider_useConfig.useConfig("popconfirm");
    const classPrefix = hooks_useConfig.usePrefixClass();
    const {
      DeleteIcon,
      AddIcon
    } = hooks_useGlobalIcon.useGlobalIcon({
      DeleteIcon: iconsVue.DeleteIcon,
      AddIcon: iconsVue.AddIcon
    });
    const {
      statusClassNames
    } = hooks_useCommonClassname["default"]();
    const visiblePopConfirm = VueCompositionAPI.ref(false);
    const colorInstance = VueCompositionAPI.computed(() => lodash.cloneDeep(props.color));
    const setVisiblePopConfirm = visible => {
      visiblePopConfirm.value = visible;
    };
    const handleClick = color => {
      props.handleSetColor(color);
    };
    const isEqualCurrentColor = color$1 => color.Color.compare(color$1, colorInstance.value.css);
    const selectedColorIndex = VueCompositionAPI.computed(() => props.colors.findIndex(color => isEqualCurrentColor(color)));
    const handleRemoveColor = () => {
      var _props$handleChange;
      const colors = [...props.colors];
      const 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,
      global,
      confirmGlobal,
      classPrefix,
      DeleteIcon,
      AddIcon,
      baseClassName,
      statusClassNames,
      selectedColorIndex,
      visiblePopConfirm,
      setVisiblePopConfirm,
      handleClick,
      isEqualCurrentColor,
      handleRemoveColor
    };
  },
  render() {
    const h = arguments[0];
    const {
      baseClassName,
      statusClassNames,
      title,
      editable,
      DeleteIcon,
      AddIcon
    } = this;
    const swatchesClass = `${baseClassName}__swatches`;
    const renderActions = () => {
      if (!editable) return null;
      return h("div", {
        "class": `${swatchesClass}--actions`
      }, [h("span", {
        "attrs": {
          "role": "button"
        },
        "class": `${baseClassName}__icon`,
        "on": {
          "click": () => this.handleAddColor()
        }
      }, [h(AddIcon)]), this.colors.length > 0 ? h("span", {
        "attrs": {
          "role": "button"
        },
        "class": `${baseClassName}__icon`,
        "on": {
          "click": () => this.handleRemoveColor()
        }
      }, [h(DeleteIcon)]) : null]);
    };
    return h("div", {
      "class": swatchesClass
    }, [h("h3", {
      "class": `${swatchesClass}--title`
    }, [h("span", [title]), renderActions()]), h("ul", {
      "class": [`${swatchesClass}--items`, "narrow-scrollbar"]
    }, [this.colors.map(color => h("li", {
      "class": [`${swatchesClass}--item`, this.isEqualCurrentColor(color) && editable ? statusClassNames.active : ""],
      "key": color,
      "on": {
        "click": () => {
          if (this.disabled) return;
          this.handleClick(color);
        }
      }
    }, [h("div", {
      "class": [`${swatchesClass}--color`, `${baseClassName}--bg-alpha`]
    }, [h("span", {
      "class": `${swatchesClass}--inner`,
      "style": {
        background: color
      }
    })])]))])]);
  }
});

exports["default"] = SwatchesPanel;
//# sourceMappingURL=swatches.js.map
