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

'use strict';

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

var helper = require('../../../../chunks/helper.js');
var VueCompositionAPI = require('@vue/composition-api');
var throttle = require('lodash/throttle');
var components_colorPicker_props = require('../../props.js');
var color = require('../../../../chunks/color.js');
var components_select_index = require('../../../select/index.js');
var components_input_index = require('../../../input/index.js');
var components_inputNumber_index = require('../../../input-number/index.js');
var components_colorPicker_panel_format_config = require('./config.js');
require('../../../../chunks/defineProperty-838e4192.js');
require('../../../../utils/with-install.js');
require('vue');
require('lodash');
require('../../../../config.js');
require('../../../select/select.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('../../../config-provider/useConfig.js');
require('../../../config-provider/context.js');
require('../../../../chunks/zh_CN.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('../../../../utils/mixins.js');
require('../../../loading/props.js');
require('../../../loading/icon/gradient.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('../../../tag/index.js');
require('../../../tag/tag.js');
require('@ldesign/icons-vue');
require('../../../../utils/event.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('../../../../hooks/use-config.js');
require('../../../input/input.js');
require('../../../input/props.js');
require('../../../input/group.js');
require('../../../select-input/hooks/use-multiple.js');
require('../../../tag-input/index.js');
require('../../../tag-input/tag-input.js');
require('../../../../hooks/use-global-icon.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('../../../../hooks/use-common-classname.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('../../../input-number/input-number.js');
require('../../../button/index.js');
require('../../../button/button.js');
require('../../../button/props.js');
require('../../../input-number/props.js');
require('../../../input-number/hooks/use-input-number.js');
require('../../../../chunks/isObjectLike-c22c7e3b.js');
require('../../../../chunks/isArray-cd7357b9.js');
require('../../../../chunks/isNumber-c4eb560e.js');

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

var throttle__default = /*#__PURE__*/_interopDefaultLegacy(throttle);

var FormatInputs = VueCompositionAPI.defineComponent({
  name: "FormatInputs",
  components: {
    LSelect: components_select_index.Select,
    LOption: components_select_index.Option,
    LInput: components_input_index.Input,
    LInputNumber: components_inputNumber_index.InputNumber
  },
  inheritAttrs: false,
  props: {
    ...components_colorPicker_props["default"],
    color: {
      type: Object
    },
    handleFormatInputChange: {
      type: Function,
      default: () => () => {}
    }
  },
  setup(props2) {
    const inputConfigs = VueCompositionAPI.computed(() => {
      const configs = [...components_colorPicker_panel_format_config.FORMAT_INPUT_CONFIG[props2.format]];
      if (props2.enableAlpha) {
        configs.push({
          type: "inputNumber",
          key: "a",
          min: 0,
          max: 100,
          format: value => `${value}%`,
          flex: 1.15
        });
      }
      return configs;
    });
    const modelValues = VueCompositionAPI.reactive({
      r: 0,
      g: 0,
      b: 0,
      a: 0,
      c: 0,
      m: 0,
      y: 0,
      k: 0,
      h: 0,
      l: 0,
      s: 0,
      v: 0,
      hex: "",
      css: ""
    });
    const lastModelValue = VueCompositionAPI.reactive({});
    const getFormatColorMap = type => {
      const {
        color: color$1
      } = props2;
      if (type === "encode") {
        return {
          HSV: color$1.getHsva(),
          HSL: color$1.getHsla(),
          RGB: color$1.getRgba(),
          CMYK: color$1.getCmyk(),
          CSS: {
            css: color$1.css
          },
          HEX: {
            hex: color$1.hex
          }
        };
      }
      return {
        HSV: color.Color.object2color(modelValues, "HSV"),
        HSL: color.Color.object2color(modelValues, "HSL"),
        RGB: color.Color.object2color(modelValues, "RGB"),
        CMYK: color.Color.object2color(modelValues, "CMYK"),
        CSS: modelValues.css,
        HEX: modelValues.hex
      };
    };
    const updateModelValue = () => {
      const {
        format,
        color
      } = props2;
      const values = getFormatColorMap("encode")[format];
      values.a = Math.round(color.alpha * 100);
      Object.keys(values).forEach(key => {
        modelValues[key] = values[key];
        lastModelValue[key] = values[key];
      });
    };
    updateModelValue();
    const throttleUpdate = throttle__default["default"](updateModelValue, 100);
    VueCompositionAPI.watch(() => {
      const {
        saturation,
        hue,
        value,
        alpha
      } = props2.color;
      return [saturation, hue, value, alpha, props2.format];
    }, throttleUpdate);
    const handleChange = (key, v) => {
      if (v === lastModelValue[key]) return;
      const value = getFormatColorMap("decode")[props2.format];
      props2.handleFormatInputChange(value, modelValues.a / 100, key, v);
    };
    return {
      modelValues,
      inputConfigs,
      handleChange
    };
  },
  render() {
    const h = arguments[0];
    const inputProps = {
      ...(this.inputProps || {})
    };
    return h("div", {
      "class": "input-group"
    }, [this.inputConfigs.map(config => h("div", {
      "class": "input-group__item",
      "key": config.key,
      "style": {
        flex: config.flex || 1
      }
    }, [config.type === "input" ? h("l-input", helper.helper([{}, inputProps, {
      "attrs": {
        "align": "center",
        "size": "small",
        "disabled": this.disabled,
        "maxlength": this.format === "HEX" ? 9 : void 0,
        "title": this.modelValues[config.key]
      },
      "on": {
        "blur": v => this.handleChange(config.key, v),
        "enter": v => this.handleChange(config.key, v)
      },
      "model": {
        value: this.modelValues[config.key],
        callback: $$v => {
          this.$set(this.modelValues, config.key, $$v);
        }
      }
    }])) : h("l-input-number", helper.helper([{}, inputProps, {
      "attrs": {
        "align": "center",
        "theme": "normal",
        "size": "small",
        "disabled": this.disabled,
        "title": this.modelValues[config.key],
        "min": config.min,
        "max": config.max,
        "step": 1,
        "format": config.format
      },
      "on": {
        "blur": v => this.handleChange(config.key, v),
        "enter": v => this.handleChange(config.key, v)
      },
      "model": {
        value: this.modelValues[config.key],
        callback: $$v => {
          this.$set(this.modelValues, config.key, $$v);
        }
      }
    }]))]))]);
  }
});

exports["default"] = FormatInputs;
//# sourceMappingURL=inputs.js.map
