/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

'use strict';

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

var helper = require('../../../../chunks/helper.js');
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
var throttle = require('lodash/throttle');
var components_colorPicker_props = require('../../props.js');
var color = require('../../../../chunks/color.js');
require('@babel/runtime/helpers/classCallCheck');
require('@babel/runtime/helpers/createClass');
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('@babel/runtime/helpers/slicedToArray');
require('../../../../chunks/defineProperty-28395935.js');
require('@babel/runtime/helpers/typeof');
require('../../../select/select.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('lodash/isFunction');
require('lodash/debounce');
require('lodash/get');
require('lodash/cloneDeep');
require('lodash/isArray');
require('../../../../hooks/use-default-value.js');
require('../../../../hooks/use-vmodel.js');
require('../../../../hooks/lnode.js');
require('lodash/isEmpty');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../../../hooks/render-lnode.js');
require('lodash/isString');
require('lodash/isObject');
require('../../../config-provider/useConfig.js');
require('../../../config-provider/context.js');
require('lodash');
require('../../../../chunks/zh_CN.js');
require('../../../select/props.js');
require('../../../loading/index.js');
require('../../../loading/loading.js');
require('../../../loading/icon/gradient.js');
require('vue');
require('../../../../chunks/set-style.js');
require('../../../../chunks/helper2.js');
require('../../../../config.js');
require('../../../../utils/dom.js');
require('raf');
require('../../../../utils/easing.js');
require('../../../../utils/render-node.js');
require('../../../../utils/transfer-dom.js');
require('../../../loading/props.js');
require('../../../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../../../../utils/mixins.js');
require('../../../../utils/with-install.js');
require('../../../loading/plugin.js');
require('../../../popup/index.js');
require('../../../popup/popup.js');
require('@popperjs/core');
require('../../../../utils/helper.js');
require('../../../popup/props.js');
require('../../../popup/container.js');
require('../../../../utils/map-props.js');
require('../../../tag/index.js');
require('../../../tag/tag.js');
require('@ldesign/icons-vue');
require('../../../tag/props.js');
require('../../../../utils/event.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('../../../select-input/hooks/use-multiple.js');
require('../../../select-input/hooks/use-overlay-innerstyle.js');
require('../../../common/fake-arrow.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('../../../../hooks/use-common-classname.js');
require('../../../select/select-panel.js');
require('../../../../hooks/use-virtual-scroll.js');
require('../../../select/hooks/use-select-options.js');
require('../../../input/input.js');
require('../../../input/props.js');
require('../../../input/group.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-2443c6ff.js');
require('../../../../chunks/_commonjsHelpers-ea2bee21.js');
require('../../../../chunks/isArray-b0f0e351.js');
require('../../../../chunks/log.js');
require('../../../../hooks/use-form-disabled.js');
require('../../../../hooks/use-global-icon.js');

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

var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var throttle__default = /*#__PURE__*/_interopDefaultLegacy(throttle);

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__default["default"](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 = 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: _objectSpread(_objectSpread({}, components_colorPicker_props["default"]), {}, {
    color: {
      type: Object
    },
    handleFormatInputChange: {
      type: Function,
      "default": function _default() {
        return function () {};
      }
    }
  }),
  setup: function setup(props2) {
    var inputConfigs = VueCompositionAPI.computed(function () {
      var configs = _toConsumableArray__default["default"](components_colorPicker_panel_format_config.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 = 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: ""
    });
    var lastModelValue = VueCompositionAPI.reactive({});

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

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

    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__default["default"](updateModelValue, 100);
    VueCompositionAPI.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("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": 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("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": 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);
          }
        }
      }]))]);
    })]);
  }
});

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