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

import { h as helper } from '../../../../chunks/helper.js';
import { defineComponent, computed, reactive, watch } from '@vue/composition-api';
import throttle from 'lodash/throttle';
import props from '../../props.js';
import { Color } from '../../utils/index.js';
import { Select, Option } from '../../../select/index.js';
import { Input } from '../../../input/index.js';
import { InputNumber } from '../../../input-number/index.js';
import { FORMAT_INPUT_CONFIG } from './config.js';
import '../../../../chunks/_commonjsHelpers.js';
import '../../../../chunks/defineProperty-838e4192.js';
import '../../../../utils/with-install.js';
import 'vue';
import 'lodash';
import '../../../../config.js';
import '../../../select/select.js';
import 'lodash/isFunction';
import 'lodash/debounce';
import 'lodash/get';
import 'lodash/cloneDeep';
import 'lodash/isArray';
import 'lodash/isObject';
import '../../../../chunks/index.js';
import '../../../../chunks/log.js';
import '../../../../chunks/_commonjsHelpers-2e6815bd.js';
import '../../../../hooks/use-default-value.js';
import '../../../../hooks/use-vmodel.js';
import 'lodash/kebabCase';
import '../../../../hooks/lnode.js';
import 'lodash/isEmpty';
import 'lodash/camelCase';
import '../../../../hooks/render-lnode.js';
import '../../../config-provider/useConfig.js';
import '../../../config-provider/context.js';
import '../../../../chunks/zh_CN.js';
import '../../../config-provider/type.js';
import '../../../loading/index.js';
import '../../../loading/loading.js';
import '../../../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../../../utils/easing.js';
import '../../../../utils/render-node.js';
import '../../../../utils/transfer-dom.js';
import '../../../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../../../../utils/mixins.js';
import '../../../loading/props.js';
import '../../../loading/icon/gradient.js';
import '../../../../chunks/set-style.js';
import '../../../../chunks/helper2.js';
import '../../../loading/style/css.js';
import '../../../loading/type.js';
import '../../../loading/plugin.js';
import '../../../popup/index.js';
import '../../../../utils/map-props.js';
import '../../../popup/popup.js';
import '@popperjs/core';
import '../../../../utils/helper.js';
import '../../../popup/props.js';
import '../../../popup/container.js';
import '../../../popup/style/css.js';
import '../../../popup/type.js';
import '../../../tag/index.js';
import '../../../tag/tag.js';
import '@ldesign/icons-vue';
import '../../../../utils/event.js';
import '../../../tag/props.js';
import '../../../tag/check-tag.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/hooks/use-single.js';
import 'lodash/pick';
import '../../../../hooks/use-config.js';
import '../../../input/input.js';
import '../../../input/props.js';
import '../../../input/group.js';
import '../../../input/style/css.js';
import '../../../input/type.js';
import '../../../select-input/hooks/use-multiple.js';
import '../../../tag-input/index.js';
import '../../../tag-input/tag-input.js';
import '../../../../hooks/use-global-icon.js';
import '../../../tag-input/props.js';
import '../../../tag-input/hooks/use-tag-scroll.js';
import '../../../tag-input/hooks/use-tag-list.js';
import '../../../tag-input/hooks/use-hover.js';
import '../../../tag-input/hooks/use-drag-sorter.js';
import '../../../tag-input/style/css.js';
import '../../../tag-input/type.js';
import '../../../select-input/hooks/use-overlay-innerstyle.js';
import '../../../select-input/style/css.js';
import '../../../select-input/type.js';
import '../../../common/fake-arrow.js';
import '../../../../hooks/use-form-disabled.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/style/css.js';
import '../../../checkbox/type.js';
import '../../../../hooks/use-lazy-load.js';
import '../../../../chunks/observe.js';
import '../../../../hooks/use-common-classname.js';
import '../../../select/utils.js';
import '../../../select/props.js';
import '../../../select/select-panel.js';
import '../../../../hooks/use-virtual-scroll.js';
import '../../../select/hooks/use-select-options.js';
import '../../../select/option-group.js';
import '../../../select/style/css.js';
import '../../../select/type.js';
import '../../../input-number/input-number.js';
import '../../../button/index.js';
import '../../../button/button.js';
import '../../../button/props.js';
import '../../../button/style/css.js';
import '../../../button/type.js';
import '../../../input-number/props.js';
import '../../../input-number/hooks/use-input-number.js';
import '../../../../chunks/isObjectLike-c22c7e3b.js';
import '../../../../chunks/isArray-cd7357b9.js';
import '../../../../chunks/isNumber-c4eb560e.js';
import '../../../input-number/style/css.js';
import '../../../input-number/type.js';

var FormatInputs = defineComponent({
  name: "FormatInputs",
  components: {
    LSelect: Select,
    LOption: Option,
    LInput: Input,
    LInputNumber: InputNumber
  },
  inheritAttrs: false,
  props: {
    ...props,
    color: {
      type: Object
    },
    handleFormatInputChange: {
      type: Function,
      default: () => () => {}
    }
  },
  setup(props2) {
    const inputConfigs = computed(() => {
      const configs = [...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 = 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 = reactive({});
    const getFormatColorMap = type => {
      const {
        color
      } = props2;
      if (type === "encode") {
        return {
          HSV: color.getHsva(),
          HSL: color.getHsla(),
          RGB: color.getRgba(),
          CMYK: color.getCmyk(),
          CSS: {
            css: color.css
          },
          HEX: {
            hex: color.hex
          }
        };
      }
      return {
        HSV: Color.object2color(modelValues, "HSV"),
        HSL: Color.object2color(modelValues, "HSL"),
        RGB: Color.object2color(modelValues, "RGB"),
        CMYK: 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(updateModelValue, 100);
    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([{}, 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([{}, 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);
        }
      }
    }]))]))]);
  }
});

export { FormatInputs as default };
//# sourceMappingURL=inputs.js.map
