/**
 * tdesign v0.46.4
 * (c) 2022 tdesign
 * @license MIT
 */

import { h as helper } from '../../../_chunks/dep-a4bd011a.js';
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, computed, reactive, watch } from '@vue/composition-api';
import throttle from 'lodash/throttle';
import props from '../../props.js';
import '../../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 { Color } from '../../../_common/js/color-picker/color.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 '@babel/runtime/helpers/slicedToArray';
import '../../../select/select.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import 'lodash/isFunction';
import 'lodash/debounce';
import 'lodash/get';
import 'lodash/cloneDeep';
import 'lodash/isArray';
import '../../../hooks/useDefaultValue.js';
import '../../../hooks/useVModel.js';
import '../../../hooks/tnode.js';
import 'lodash/isEmpty';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../../../hooks/render-tnode.js';
import 'lodash/isString';
import 'lodash/isObject';
import '../../../config-provider/useConfig.js';
import '../../../config-provider/context.js';
import 'lodash/merge';
import 'lodash/mergeWith';
import '../../../_common/js/global-config/default-config.js';
import '../../../_common/js/global-config/locale/zh_CN.js';
import '../../../config-provider/type.js';
import '../../../select/props.js';
import '../../../loading/index.js';
import '../../../loading/loading.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 '../../../config-provider/config-receiver.js';
import 'vue';
import '../../../utils/mixins.js';
import '../../../utils/dom.js';
import 'raf';
import '../../../utils/easing.js';
import '../../../utils/render-tnode.js';
import '@babel/runtime/helpers/typeof';
import '../../../utils/transfer-dom.js';
import '../../../loading/props.js';
import '../../../utils/withInstall.js';
import 'lodash/capitalize';
import './style/css.js';
import '../../../loading/type.js';
import '../../../loading/plugin.js';
import '../../../config.js';
import '../../../popup/index.js';
import '../../../popup/popup.js';
import '@popperjs/core';
import '../../../utils/helper.js';
import '../../../popup/props.js';
import '../../../popup/container.js';
import '../../../utils/map-props.js';
import '../../../popup/type.js';
import '../../../tag/index.js';
import '../../../tag/tag.js';
import 'tdesign-icons-vue';
import '../../../tag/props.js';
import '../../../utils/event.js';
import '../../../tag/check-tag.js';
import '../../../tag/check-tag-props.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 '../../../hooks/useConfig.js';
import '../../../input/input.js';
import '../../../input/props.js';
import '../../../input/input-group.js';
import '../../../input/type.js';
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 '../../../hooks/useGlobalIcon.js';
import '../../../tag-input/type.js';
import '../../../select-input/useOverlayInnerStyle.js';
import '../../../select-input/type.js';
import '../../../common-components/fake-arrow.js';
import '../../../select/option.js';
import '../../../utils/ripple.js';
import '../../../select/option-props.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/type.js';
import '../../../hooks/useLazyLoad.js';
import '../../../_common/js/utils/observe.js';
import '../../../select/util.js';
import '../../../hooks/useCommonClassName.js';
import '../../../select/select-panel.js';
import '../../../hooks/useVirtualScroll.js';
import '../../../select/hooks/useSelectOptions.js';
import '../../../select/optionGroup.js';
import '../../../select/option-group-props.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/type.js';
import '../../../input-number/props.js';
import '../../../input-number/useInputNumber.js';
import '../../../_common/js/input-number/number.js';
import 'lodash/isNumber';
import '../../../_common/js/input-number/large-number.js';
import '../../../_common/js/log/log.js';
import '../../../_common/js/log/index.js';
import '../../../hooks/useFormDisabled.js';
import '../../../input-number/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 FormatInputs = defineComponent({
  name: "FormatInputs",
  components: {
    TSelect: Select,
    TOption: Option,
    TInput: Input,
    TInputNumber: InputNumber
  },
  inheritAttrs: false,
  props: _objectSpread(_objectSpread({}, props), {}, {
    color: {
      type: Object
    },
    handleFormatInputChange: {
      type: Function,
      "default": function _default() {
        return function () {};
      }
    }
  }),
  setup: function setup(props2) {
    var inputConfigs = computed(function () {
      var configs = _toConsumableArray(FORMAT_INPUT_CONFIG[props2.format]);

      if (props2.enableAlpha) {
        configs.push({
          type: "inputNumber",
          key: "a",
          min: 0,
          max: 100,
          format: function format(value) {
            return "".concat(value, "%");
          },
          flex: 1.15
        });
      }

      return configs;
    });
    var 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: ""
    });
    var lastModelValue = reactive({});

    var getFormatColorMap = function getFormatColorMap(type) {
      var color = props2.color;

      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
      };
    };

    var updateModelValue = function updateModelValue() {
      var format = props2.format,
          color = props2.color;
      var values = getFormatColorMap("encode")[format];
      values.a = Math.round(color.alpha * 100);
      Object.keys(values).forEach(function (key) {
        modelValues[key] = values[key];
        lastModelValue[key] = values[key];
      });
    };

    updateModelValue();
    var throttleUpdate = throttle(updateModelValue, 100);
    watch(function () {
      var _props2$color = props2.color,
          saturation = _props2$color.saturation,
          hue = _props2$color.hue,
          value = _props2$color.value,
          alpha = _props2$color.alpha;
      return [saturation, hue, value, alpha, props2.format];
    }, throttleUpdate);

    var handleChange = function handleChange(key, v) {
      if (v === lastModelValue[key]) {
        return;
      }

      var value = getFormatColorMap("decode")[props2.format];
      props2.handleFormatInputChange(value, modelValues.a / 100, key, v);
    };

    return {
      modelValues: modelValues,
      inputConfigs: inputConfigs,
      handleChange: handleChange
    };
  },
  render: function render() {
    var _this = this;

    var h = arguments[0];

    var inputProps = _objectSpread({}, this.inputProps || {});

    return h("div", {
      "class": "input-group"
    }, [this.inputConfigs.map(function (config) {
      return h("div", {
        "class": "input-group__item",
        "key": config.key,
        "style": {
          flex: config.flex || 1
        }
      }, [config.type === "input" ? h("t-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": function blur(v) {
            return _this.handleChange(config.key, v);
          },
          "enter": function enter(v) {
            return _this.handleChange(config.key, v);
          }
        },
        "model": {
          value: _this.modelValues[config.key],
          callback: function callback($$v) {
            _this.$set(_this.modelValues, config.key, $$v);
          }
        }
      }])) : h("t-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": function blur(v) {
            return _this.handleChange(config.key, v);
          },
          "enter": function enter(v) {
            return _this.handleChange(config.key, v);
          }
        },
        "model": {
          value: _this.modelValues[config.key],
          callback: function callback($$v) {
            _this.$set(_this.modelValues, config.key, $$v);
          }
        }
      }]))]);
    })]);
  }
});

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