import { computed } from 'vue';
import '..';
import { isPresetColor, isPresetStatusColor } from '../../_util/colors';
import { FastColor } from '@ant-design/fast-color';
export default function useColor(props) {
  return computed(() => {
    const {
      color,
      variant,
      bordered
    } = props;
    const isInverseColor = color === null || color === void 0 ? void 0 : color.endsWith('-inverse');
    // =================== Variant ===================
    let nextVariant;
    if (variant) {
      nextVariant = variant;
    } else if (isInverseColor) {
      nextVariant = 'solid';
    } else if (bordered === false) {
      nextVariant = 'filled';
    } else {
      nextVariant = 'filled';
    }
    // ==================== Color ====================
    const nextColor = isInverseColor ? color === null || color === void 0 ? void 0 : color.replace('-inverse', '') : color;
    // =============== Preset & Status ===============
    const nextIsPreset = isPresetColor(color);
    const nextIsStatus = isPresetStatusColor(color);
    // ================== Customize ==================
    // When `color` is not preset color,
    // dynamic calculate the color pair.
    const tagStyle = {};
    if (!nextIsPreset && !nextIsStatus && nextColor) {
      if (nextVariant === 'solid') {
        tagStyle.backgroundColor = color;
      } else {
        const hsl = new FastColor(nextColor).toHsl();
        hsl.l = 0.95;
        tagStyle.backgroundColor = new FastColor(hsl).toHexString();
        tagStyle.color = color;
        if (nextVariant === 'outlined') {
          tagStyle.borderColor = color;
        }
      }
    }
    return {
      mergedVariant: nextVariant,
      mergedColor: nextColor,
      isPreset: nextIsPreset,
      isStatus: nextIsStatus,
      customTagStyle: tagStyle
    };
  });
}