'use strict';

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

var vue = require('vue');
var tinycolor = require('@ctrl/tinycolor');
require('../../../hooks/index2.js');
var index = require('../../../hooks/use-common-props/index2.js');
var index$1 = require('../../../hooks/use-namespace/index2.js');

function darken(color, amount = 20) {
  return color.mix("#fff", amount).toString();
}
function useButtonCustomStyle(props) {
  const _disabled = index.useDisabled();
  const ns = index$1.useNamespace("button");
  return vue.computed(() => {
    let styles = {};
    const buttonColor = props.color;
    if (buttonColor) {
      const color = new tinycolor.TinyColor(buttonColor);
      const activeBgColor = props.dark ? color.tint(20).toString() : darken(color, 20);
      if (props.plain) {
        styles = ns.cssVarBlock({
          "bg-color": props.dark ? darken(color, 90) : color.tint(90).toString(),
          "text-color": buttonColor,
          "border-color": props.dark ? darken(color, 50) : color.tint(50).toString(),
          "hover-text-color": `var(${ns.cssVarName("color-white")})`,
          "hover-bg-color": buttonColor,
          "hover-border-color": buttonColor,
          "active-bg-color": activeBgColor,
          "active-text-color": `var(${ns.cssVarName("color-white")})`,
          "active-border-color": activeBgColor
        });
        if (_disabled.value) {
          styles[ns.cssVarBlockName("disabled-bg-color")] = props.dark ? darken(color, 90) : color.tint(90).toString();
          styles[ns.cssVarBlockName("disabled-text-color")] = props.dark ? darken(color, 50) : color.tint(50).toString();
          styles[ns.cssVarBlockName("disabled-border-color")] = props.dark ? darken(color, 50) : color.tint(50).toString();
        }
      } else if (props.border) {
        const varMap = {
          "bg-color": `var(${ns.cssVarName("color-white")})`,
          "text-color": buttonColor,
          "border-color": buttonColor,
          "hover-text-color": buttonColor,
          "hover-bg-color": darken(color, 90),
          "hover-border-color": buttonColor,
          "active-text-color": `var(${ns.cssVarName("color-white")})`,
          "active-bg-color": buttonColor,
          "active-border-color": buttonColor,
          "disabled-bg-color": `var(${ns.cssVarName("color-white")})`,
          "disabled-border-color": darken(color, 50),
          "disabled-text-color": darken(color, 50)
        };
        Object.keys(varMap).map((e) => {
          styles[ns.cssVarBlockName(e)] = varMap[e];
        });
      } else {
        const hoverBgColor = props.dark ? darken(color, 30) : color.tint(20).toString();
        const textColor = color.isDark() ? `var(${ns.cssVarName("color-white")})` : `var(${ns.cssVarName("color-black")})`;
        styles = ns.cssVarBlock({
          "bg-color": buttonColor,
          "text-color": textColor,
          "border-color": buttonColor,
          "hover-bg-color": hoverBgColor,
          "hover-text-color": textColor,
          "hover-border-color": hoverBgColor,
          "active-bg-color": activeBgColor,
          "active-border-color": activeBgColor
        });
        if (_disabled.value) {
          const disabledButtonColor = props.dark ? darken(color, 50) : color.tint(50).toString();
          styles[ns.cssVarBlockName("disabled-bg-color")] = disabledButtonColor;
          styles[ns.cssVarBlockName("disabled-text-color")] = props.dark ? "rgba(255, 255, 255, 0.5)" : `var(${ns.cssVarName("color-white")})`;
          styles[ns.cssVarBlockName("disabled-border-color")] = disabledButtonColor;
        }
      }
    }
    return styles;
  });
}

exports.darken = darken;
exports.useButtonCustomStyle = useButtonCustomStyle;
//# sourceMappingURL=button-custom2.js.map
