import "./NotificationBadge.css";
import $bfWIi$intlStringsmjs from "./intlStrings.mjs";
import {useSpectrumContextProps as $5ce63c423902f47d$export$764f6146fadd77f7} from "../icons/useSpectrumContextProps.mjs";
import {jsx as $bfWIi$jsx} from "react/jsx-runtime";
import {filterDOMProps as $bfWIi$filterDOMProps} from "@react-aria/utils";
import {NumberFormatter as $bfWIi$NumberFormatter} from "@internationalized/number";
import {createContext as $bfWIi$createContext, forwardRef as $bfWIi$forwardRef} from "react";
import {useDOMRef as $bfWIi$useDOMRef} from "@react-spectrum/utils";
import {useLocalizedStringFormatter as $bfWIi$useLocalizedStringFormatter, useLocale as $bfWIi$useLocale} from "@react-aria/i18n";


function $parcel$interopDefault(a) {
  return a && a.__esModule ? a.default : a;
}
/*
 * Copyright 2025 Adobe. All rights reserved.
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy
 * of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */ 







const $bfb270fb056fefc5$export$9ab75c96ebaa396c = /*#__PURE__*/ (0, $bfWIi$createContext)(null);
const $bfb270fb056fefc5$var$badge = function anonymous(props, overrides) {
    let rules = " ";
    let width = false;
    let matches = String(overrides || '').matchAll(/(?:^|\s)(J|G|I|H|_u|_v|_s|__A|_d|_J|z|y|B|A|_P|_9|W|_l|_A|_z|_6|Z|N|L)[^\s]+/g);
    for (let p of matches){
        if (p[1] === "Z") width = true;
        rules += p[0];
    }
    if (props.isDisabled) rules += ' sk12';
    else rules += ' sd12';
    rules += ' uk12';
    rules += ' ucJ9TBTb12';
    rules += ' ud3Euai12';
    rules += ' uea12';
    rules += ' ugb12';
    rules += ' uhd12';
    rules += ' uje12';
    rules += ' u2NhKxcl12';
    rules += ' uic12';
    if (props.size === "XL") {
        rules += ' -_6BNtrc-c12';
        rules += ' vx12';
    } else if (props.size === "L") {
        rules += ' -_6BNtrc-b12';
        rules += ' vx12';
    } else if (props.size === "M") {
        rules += ' -_6BNtrc-a12';
        rules += ' vx12';
    } else if (props.size === "S") {
        rules += ' -_6BNtrc-a12';
        rules += ' vx12';
    }
    rules += ' xb12';
    rules += ' _xa12';
    rules += ' _Fd12';
    rules += ' _FnuYUweb12';
    if (props.isStaticColor) rules += ' ph12';
    else rules += ' px12';
    rules += ' plb12';
    rules += ' _jlf12';
    rules += ' _klb12';
    rules += ' hlb12';
    rules += ' mlb12';
    rules += ' llb12';
    rules += ' ila12';
    rules += ' _Ca12';
    rules += ' eb12';
    rules += ' gqMFGYc12';
    rules += ' FRuFGYc12';
    if (props.isSingleDigit) rules += ' fa12';
    else if (props.isIndicatorOnly) rules += ' fa12';
    if (!width) rules += ' ZK12';
    if (props.isDoubleDigit) rules += ' Sv12';
    if (props.isDoubleDigit) rules += ' Rv12';
    rules += ' oh12';
    rules += ' nh12';
    rules += ' kh12';
    rules += ' jh12';
    if (props.isStaticColor) rules += ' -g_-g_c12';
    else rules += ' -g_-g212';
    rules += ' -g_-lgb12';
    if (props.size === "XL") {
        if (props.isIndicatorOnly) rules += ' -F_-Fspvr8c12';
        else rules += ' -F_-Fm12';
    } else if (props.size === "L") {
        if (props.isIndicatorOnly) rules += ' -F_-Fspvr8c12';
        else rules += ' -F_-Ft12';
    } else if (props.size === "M") {
        if (props.isIndicatorOnly) rules += ' -F_-Fi12';
        else rules += ' -F_-FLb8KJ12';
    } else if (props.size === "S") {
        if (props.isIndicatorOnly) rules += ' -F_-Fi12';
        else rules += ' -F_-Fk12';
    }
    return rules;
};
const $bfb270fb056fefc5$export$529cab0ca6be204e = /*#__PURE__*/ (0, $bfWIi$forwardRef)(function Badge(props, ref) {
    let stringFormatter = (0, $bfWIi$useLocalizedStringFormatter)((0, ($parcel$interopDefault($bfWIi$intlStringsmjs))), '@react-spectrum/s2');
    [props, ref] = (0, $5ce63c423902f47d$export$764f6146fadd77f7)(props, ref, $bfb270fb056fefc5$export$9ab75c96ebaa396c);
    let { size: size = 'S', value: value, isDisabled: isDisabled = false, staticColor: staticColor, ...otherProps } = props;
    let domRef = (0, $bfWIi$useDOMRef)(ref);
    let { locale: locale } = (0, $bfWIi$useLocale)();
    let formattedValue = '';
    let isIndicatorOnly = false;
    let isSingleDigit = false;
    let isDoubleDigit = false;
    if (value == null) isIndicatorOnly = true;
    else if (value <= 0) throw new Error('Value cannot be negative or zero');
    else if (!Number.isInteger(value)) throw new Error('Value must be a positive integer');
    else {
        formattedValue = new (0, $bfWIi$NumberFormatter)(locale).format(Math.min(value, 99));
        let length = Math.log(value <= 99 ? value : 99) * Math.LOG10E + 1 | 0; // for positive integers (https://stackoverflow.com/questions/14879691/get-number-of-digits-with-javascript)
        if (length === 1) isSingleDigit = true;
        else if (length === 2) isDoubleDigit = true;
        if (value > 99) formattedValue = stringFormatter.format('notificationbadge.plus', {
            notifications: formattedValue
        });
    }
    let ariaLabel = props['aria-label'] || undefined;
    if (ariaLabel === undefined && isIndicatorOnly) ariaLabel = stringFormatter.format('notificationbadge.indicatorOnly');
    return /*#__PURE__*/ (0, $bfWIi$jsx)("span", {
        ...(0, $bfWIi$filterDOMProps)(otherProps, {
            labelable: true
        }),
        role: ariaLabel && 'img',
        "aria-label": ariaLabel,
        className: (props.UNSAFE_className || '') + $bfb270fb056fefc5$var$badge({
            size: size,
            isIndicatorOnly: isIndicatorOnly,
            isSingleDigit: isSingleDigit,
            isDoubleDigit: isDoubleDigit,
            isDisabled: isDisabled,
            isStaticColor: !!staticColor
        }, props.styles),
        style: props.UNSAFE_style,
        ref: domRef,
        children: formattedValue
    });
});


export {$bfb270fb056fefc5$export$9ab75c96ebaa396c as NotificationBadgeContext, $bfb270fb056fefc5$export$529cab0ca6be204e as NotificationBadge};
//# sourceMappingURL=NotificationBadge.mjs.map
