/**
 * 发送按钮默认色板：用 Ant Design token 的实色保证相对 colorBgContainer 的对比度，
 * 随亮色 / 暗色主题切换。半透明 token 先与 colorBgContainer 叠算再比对比度、再混合。
 */ function _array_like_to_array(arr, len) {
    if (len == null || len > arr.length) len = arr.length;
    for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
    return arr2;
}
function _array_with_holes(arr) {
    if (Array.isArray(arr)) return arr;
}
function _iterable_to_array_limit(arr, i) {
    var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
    if (_i == null) return;
    var _arr = [];
    var _n = true;
    var _d = false;
    var _s, _e;
    try {
        for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
            _arr.push(_s.value);
            if (i && _arr.length === i) break;
        }
    } catch (err) {
        _d = true;
        _e = err;
    } finally{
        try {
            if (!_n && _i["return"] != null) _i["return"]();
        } finally{
            if (_d) throw _e;
        }
    }
    return _arr;
}
function _non_iterable_rest() {
    throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _sliced_to_array(arr, i) {
    return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _unsupported_iterable_to_array(o, minLen) {
    if (!o) return;
    if (typeof o === "string") return _array_like_to_array(o, minLen);
    var n = Object.prototype.toString.call(o).slice(8, -1);
    if (n === "Object" && o.constructor) n = o.constructor.name;
    if (n === "Map" || n === "Set") return Array.from(n);
    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
var SHORT_HEX = /^#([0-9a-f]{3})$/i;
var LONG_HEX6 = /^#([0-9a-f]{6})$/i;
var LONG_HEX8 = /^#([0-9a-f]{8})$/i;
var RGBA = /^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(?:\s*[,/]\s*([\d.]+))?\s*\)/i;
var clamp = function clamp(n, min, max) {
    return Math.min(max, Math.max(min, n));
};
var compositeOn = function compositeOn(fr, fg, fb, a, br, bg, bb) {
    var u = clamp(a, 0, 1);
    return {
        r: Math.round(fr * u + br * (1 - u)),
        g: Math.round(fg * u + bg * (1 - u)),
        b: Math.round(fb * u + bb * (1 - u))
    };
};
/**
 * 不透明色：#rgb #rrggbb、rgb(,,) 无 alpha
 */ var parseOpaqueRgb = function parseOpaqueRgb(color) {
    var t = color.trim();
    var shortM = t.match(SHORT_HEX);
    if (shortM) {
        var _shortM__split = _sliced_to_array(shortM[1].split(''), 3), a = _shortM__split[0], b = _shortM__split[1], c = _shortM__split[2];
        return {
            r: parseInt(a + a, 16),
            g: parseInt(b + b, 16),
            b: parseInt(c + c, 16)
        };
    }
    var long6 = t.match(LONG_HEX6);
    if (long6) {
        return {
            r: parseInt(long6[1].slice(0, 2), 16),
            g: parseInt(long6[1].slice(2, 4), 16),
            b: parseInt(long6[1].slice(4, 6), 16)
        };
    }
    var m = t.match(/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/i);
    if (m) {
        return {
            r: Number(m[1]),
            g: Number(m[2]),
            b: Number(m[3])
        };
    }
    return null;
};
/**
 * 任意色值在 `onBackground` 上呈现的有效 sRGB（含 rgba / 8 位 hex 叠色）
 */ var toRgbOnBackground = function toRgbOnBackground(color, onBackground) {
    var t = color.trim();
    var bg = parseOpaqueRgb(onBackground);
    if (!bg) {
        return null;
    }
    var long8 = t.match(LONG_HEX8);
    if (long8) {
        var r = parseInt(long8[1].slice(0, 2), 16);
        var g = parseInt(long8[1].slice(2, 4), 16);
        var b = parseInt(long8[1].slice(4, 6), 16);
        var a = parseInt(long8[1].slice(6, 8), 16) / 255;
        return compositeOn(r, g, b, a, bg.r, bg.g, bg.b);
    }
    var rgbaM = t.match(RGBA);
    if (rgbaM) {
        var r1 = Number(rgbaM[1]);
        var g1 = Number(rgbaM[2]);
        var b1 = Number(rgbaM[3]);
        var a1 = rgbaM[4] === undefined ? 1 : Number(rgbaM[4]);
        if (a1 >= 1 - 1e-6) {
            return {
                r: r1,
                g: g1,
                b: b1
            };
        }
        return compositeOn(r1, g1, b1, a1, bg.r, bg.g, bg.b);
    }
    return parseOpaqueRgb(t);
};
var toRgbString = function toRgbString(rgb) {
    return "rgb(".concat(rgb.r, ",").concat(rgb.g, ",").concat(rgb.b, ")");
};
var relativeLuminance = function relativeLuminance(r, g, b) {
    var _map = _sliced_to_array([
        r,
        g,
        b
    ].map(function(c) {
        var s = c / 255;
        return s <= 0.04045 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4);
    }), 3), rs = _map[0], gs = _map[1], bs = _map[2];
    return 0.2126 * rs + 0.7152 * gs + 0.0722 * bs;
};
var contrastRatio = function contrastRatio(c1, c2) {
    var a = toRgbOnBackground(c1, c2);
    var b = toRgbOnBackground(c2, c2);
    if (!a || !b) {
        return null;
    }
    var l1 = relativeLuminance(a.r, a.g, a.b);
    var l2 = relativeLuminance(b.r, b.g, b.b);
    var L1 = Math.max(l1, l2);
    var L2 = Math.min(l1, l2);
    return (L1 + 0.05) / (L2 + 0.05);
};
/**
 * 线性 sRGB 混合两色（先相对 `mixBase` 还原为实色），输出不透明 rgb()
 */ var mixSrgb = function mixSrgb(fg, bg, t, mixBase) {
    var a = toRgbOnBackground(fg, mixBase);
    var b = toRgbOnBackground(bg, mixBase);
    if (!a || !b) {
        return fg;
    }
    var u = clamp(t, 0, 1);
    var m = function m(x, y) {
        return Math.round(x * u + y * (1 - u));
    };
    return toRgbString({
        r: m(a.r, b.r),
        g: m(a.g, b.g),
        b: m(a.b, b.b)
    });
};
var MIN_MUTED_ICON_CONTRAST = 2.4;
var MIN_MUTED_FILL_CONTRAST = 1.4;
var DEFAULT_LIGHT_SOLID = '#ffffff';
/**
 * 基于当前主题 token 生成默认可发送 / 未激活填充与图标色
 */ export function getSendButtonPalette(token) {
    var colorBgContainer = token.colorBgContainer, colorPrimary = token.colorPrimary, colorTextLightSolid = token.colorTextLightSolid;
    var textTertiary = token.colorTextTertiary;
    var fillTertiary = token.colorFillTertiary;
    var lightSolid = colorTextLightSolid || DEFAULT_LIGHT_SOLID;
    var fillMuted = fillTertiary;
    var cFill = contrastRatio(fillMuted, colorBgContainer);
    for(var i = 0; i < 6 && cFill !== null && cFill < MIN_MUTED_FILL_CONTRAST; i += 1){
        fillMuted = mixSrgb(colorPrimary, colorBgContainer, 0.1 + i * 0.06, colorBgContainer);
        cFill = contrastRatio(fillMuted, colorBgContainer);
    }
    if (cFill === null) {
        fillMuted = mixSrgb(colorPrimary, colorBgContainer, 0.1, colorBgContainer);
    }
    var iconMuted = textTertiary;
    var cIcon = contrastRatio(iconMuted, colorBgContainer);
    for(var j = 0; j < 6 && cIcon !== null && cIcon < MIN_MUTED_ICON_CONTRAST; j += 1){
        var mixT = 0.55 - j * 0.08;
        iconMuted = mixSrgb(colorPrimary, colorBgContainer, Math.max(0, mixT), colorBgContainer);
        cIcon = contrastRatio(iconMuted, colorBgContainer);
    }
    if (cIcon === null) {
        iconMuted = mixSrgb(colorPrimary, colorBgContainer, 0.45, colorBgContainer);
    }
    var fillFinal = toRgbOnBackground(fillMuted, colorBgContainer);
    var iconFinal = toRgbOnBackground(iconMuted, colorBgContainer);
    return {
        backgroundActive: colorPrimary,
        backgroundMuted: fillFinal ? toRgbString(fillFinal) : fillMuted,
        iconActive: lightSolid,
        iconMuted: iconFinal ? toRgbString(iconFinal) : iconMuted
    };
}
var tuneFillTowardContainer = function tuneFillTowardContainer(source, colorBgContainer, hintPrimary) {
    var fill = mixSrgb(source, colorBgContainer, 0.1, colorBgContainer);
    var c = contrastRatio(fill, colorBgContainer);
    for(var i = 0; i < 6 && c !== null && c < MIN_MUTED_FILL_CONTRAST; i += 1){
        fill = mixSrgb(i % 2 === 0 ? hintPrimary : source, colorBgContainer, 0.12 + i * 0.05, colorBgContainer);
        c = contrastRatio(fill, colorBgContainer);
    }
    var rgb = toRgbOnBackground(fill, colorBgContainer);
    return rgb ? toRgbString(rgb) : fill;
};
var tuneIconTowardContainer = function tuneIconTowardContainer(source, colorBgContainer, hintPrimary) {
    var icon = mixSrgb(source, colorBgContainer, 0.4, colorBgContainer);
    var c = contrastRatio(icon, colorBgContainer);
    for(var j = 0; j < 6 && c !== null && c < MIN_MUTED_ICON_CONTRAST; j += 1){
        icon = mixSrgb(j % 2 === 0 ? hintPrimary : source, colorBgContainer, 0.5 - j * 0.07, colorBgContainer);
        c = contrastRatio(icon, colorBgContainer);
    }
    var rgb = toRgbOnBackground(icon, colorBgContainer);
    return rgb ? toRgbString(rgb) : icon;
};
/**
 * 合并默认色板与用户 `colors`；与原先 background/backgroundHover、icon/iconHover 语义一致
 */ export function resolveSendButtonDisplayColors(basePalette, colors, token) {
    var _ref, _colors_backgroundHover, _ref1, _colors_iconHover;
    if (!colors) {
        return basePalette;
    }
    var colorBgContainer = token.colorBgContainer, colorPrimary = token.colorPrimary;
    var backgroundActive = (_ref = (_colors_backgroundHover = colors.backgroundHover) !== null && _colors_backgroundHover !== void 0 ? _colors_backgroundHover : colors.background) !== null && _ref !== void 0 ? _ref : basePalette.backgroundActive;
    var iconActive = (_ref1 = (_colors_iconHover = colors.iconHover) !== null && _colors_iconHover !== void 0 ? _colors_iconHover : colors.icon) !== null && _ref1 !== void 0 ? _ref1 : basePalette.iconActive;
    return {
        backgroundActive: backgroundActive,
        backgroundMuted: colors.background ? tuneFillTowardContainer(colors.background, colorBgContainer, colorPrimary) : basePalette.backgroundMuted,
        iconActive: iconActive,
        iconMuted: colors.icon ? tuneIconTowardContainer(colors.icon, colorBgContainer, colorPrimary) : basePalette.iconMuted
    };
}
