import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import { watch } from 'vue';
import useState from '../../_util/hooks/useState';
import { generateColor } from '../util';
function hasValue(value) {
  return value !== undefined;
}
var useColorState = function useColorState(defaultStateValue, option) {
  var defaultValue = option.defaultValue,
    color = option.value;
  var _useState = useState(function () {
      var mergeState;
      if (hasValue(color.value)) {
        mergeState = color.value;
      } else if (hasValue(defaultValue)) {
        mergeState = defaultValue;
      } else {
        mergeState = defaultStateValue;
      }
      return generateColor(mergeState);
    }),
    _useState2 = _slicedToArray(_useState, 2),
    colorValue = _useState2[0],
    setColorValue = _useState2[1];
  watch(option.value, function (value) {
    setColorValue(generateColor(value));
  });
  return [colorValue, setColorValue];
};
export default useColorState;