'use strict';

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

var vue = require('vue');
var index = require('../../icon/index.js');
require('../../../directives/index.js');
require('../../../tokens/index.js');
require('../../../hooks/index.js');
require('../../../constants/index.js');
require('../../../utils/index.js');
var iconsVue = require('@element-plus/icons-vue');
var color = require('./color.js');
var useOption = require('./useOption.js');
var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
var index$1 = require('../../../directives/click-outside/index.js');
var validator = require('../../../utils/vue/validator.js');
var event = require('../../../constants/event.js');
var index$2 = require('../../../hooks/use-locale/index.js');
var index$3 = require('../../../hooks/use-namespace/index.js');
var form = require('../../../tokens/form.js');
var index$4 = require('../../../hooks/use-common-props/index.js');

const _sfc_main = vue.defineComponent({
  name: "PsColorPicker",
  components: {
    PsIcon: index.PsIcon,
    Close: iconsVue.Close,
    ArrowDown: iconsVue.ArrowDown
  },
  directives: {
    ClickOutside: index$1["default"]
  },
  props: {
    modelValue: String,
    showAlpha: Boolean,
    colorFormat: String,
    disabled: Boolean,
    size: {
      type: String,
      validator: validator.isValidComponentSize
    },
    popperClass: String,
    predefine: Array
  },
  emits: ["change", "active-change", event.UPDATE_MODEL_EVENT],
  setup(props, { emit }) {
    const { t } = index$2.useLocale();
    const ns = index$3.useNamespace("color");
    const elForm = vue.inject(form.formContextKey, {});
    const hue = vue.ref(null);
    const svPanel = vue.ref(null);
    const alpha = vue.ref(null);
    const popper = vue.ref(null);
    const color$1 = vue.reactive(new color["default"]({
      enableAlpha: props.showAlpha,
      format: props.colorFormat,
      value: props.modelValue
    }));
    const showPicker = vue.ref(false);
    const showPanelColor = vue.ref(false);
    const customInput = vue.ref("");
    const displayedColor = vue.computed(() => {
      if (!props.modelValue && !showPanelColor.value) {
        return "transparent";
      }
      return displayedRgb(color$1, props.showAlpha);
    });
    const colorSize = index$4.useSize();
    const colorDisabled = vue.computed(() => {
      return !!(props.disabled || elForm.disabled);
    });
    const currentColor = vue.computed(() => {
      return !props.modelValue && !showPanelColor.value ? "" : color$1.value;
    });
    function displayedRgb(color2, showAlpha) {
      if (!(color2 instanceof color["default"])) {
        throw new TypeError("color should be instance of _color Class");
      }
      const { r, g, b } = color2.toRgb();
      return showAlpha ? `rgba(${r}, ${g}, ${b}, ${color2.get("alpha") / 100})` : `rgb(${r}, ${g}, ${b})`;
    }
    vue.onMounted(() => {
      if (props.modelValue) {
        customInput.value = currentColor.value;
      }
    });
    vue.provide(useOption.OPTIONS_KEY, {
      currentColor
    });
    return {
      color: color$1,
      colorDisabled,
      colorSize,
      displayedColor,
      showPanelColor,
      showPicker,
      customInput,
      t,
      ns,
      hue,
      svPanel,
      alpha,
      popper
    };
  }
});
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  const _component_arrow_down = vue.resolveComponent("arrow-down");
  const _component_ps_icon = vue.resolveComponent("ps-icon");
  const _component_close = vue.resolveComponent("close");
  return vue.openBlock(), vue.createElementBlock("div", {
    class: vue.normalizeClass([
      _ctx.ns.b("picker"),
      _ctx.ns.is("disabled", _ctx.colorDisabled),
      _ctx.ns.bm("picker", _ctx.colorSize)
    ])
  }, [
    _ctx.colorDisabled ? (vue.openBlock(), vue.createElementBlock("div", {
      key: 0,
      class: vue.normalizeClass(_ctx.ns.be("picker", "mask"))
    }, null, 2)) : vue.createCommentVNode("v-if", true),
    vue.createElementVNode("div", {
      class: vue.normalizeClass(_ctx.ns.be("picker", "trigger"))
    }, [
      vue.createElementVNode("span", {
        class: vue.normalizeClass([_ctx.ns.be("picker", "color"), _ctx.ns.is("alpha", _ctx.showAlpha)])
      }, [
        vue.createElementVNode("span", {
          class: vue.normalizeClass(_ctx.ns.be("picker", "color-inner")),
          style: vue.normalizeStyle({
            backgroundColor: _ctx.displayedColor
          })
        }, [
          vue.withDirectives(vue.createVNode(_component_ps_icon, {
            class: vue.normalizeClass([_ctx.ns.be("picker", "icon"), _ctx.ns.is("icon-arrow-down")])
          }, {
            default: vue.withCtx(() => [
              vue.createVNode(_component_arrow_down)
            ]),
            _: 1
          }, 8, ["class"]), [
            [vue.vShow, _ctx.modelValue || _ctx.showPanelColor]
          ]),
          !_ctx.modelValue && !_ctx.showPanelColor ? (vue.openBlock(), vue.createBlock(_component_ps_icon, {
            key: 0,
            class: vue.normalizeClass([_ctx.ns.be("picker", "empty"), _ctx.ns.is("icon-close")])
          }, {
            default: vue.withCtx(() => [
              vue.createVNode(_component_close)
            ]),
            _: 1
          }, 8, ["class"])) : vue.createCommentVNode("v-if", true)
        ], 6)
      ], 2)
    ], 2)
  ], 2);
}
var ColorPicker = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["render", _sfc_render], ["__file", "/Users/meng/workspace/element-ps/packages/components/color-picker/src/index.vue"]]);

exports["default"] = ColorPicker;
//# sourceMappingURL=index.js.map
