"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importStar(require("react"));
let globalId = 0;
function useGlobalId(idOverride) {
    // biome-ignore lint/correctness/useHookAtTopLevel: <>
    const [defaultId, setDefaultId] = (0, react_1.useState)(idOverride);
    const id = idOverride || defaultId;
    // biome-ignore lint/correctness/useHookAtTopLevel: <>
    (0, react_1.useEffect)(() => {
        if (defaultId == null) {
            // Fallback to this default id when possible.
            // Use the incrementing value for client-side rendering only.
            // We can't use it server-side.
            // If you want to use random values please consider the Birthday Problem: https://en.wikipedia.org/wiki/Birthday_problem
            globalId += 1;
            setDefaultId(`astral-ui-${globalId}`);
        }
    }, [defaultId]);
    return id;
}
// biome-ignore lint/suspicious/noExplicitAny: <downstream bundlers may remove unnecessary concatenation, but won't remove toString call -- Workaround for https://github.com/webpack/webpack/issues/14814>
const maybeReactUseId = react_1.default['useId'.toString()];
/**
 * Хук не предназначен для экспорта из пакета и необходим для решения проблемы совместимости с React 17.
 * Реализация скопирована из mui, так как из пакета она экспортируется с префиксом unstable:
 * import { unstable_useId } from '@mui/material';
 * https://github.com/mui/material-ui/blob/next/packages/mui-utils/src/useId/useId.ts
 * @example <div id={useId()} />
 * @param idOverride
 * @returns {string}
 */
function useId(idOverride) {
    if (maybeReactUseId !== undefined) {
        const reactId = maybeReactUseId();
        return idOverride ?? reactId;
    }
    // biome-ignore lint/correctness/useHookAtTopLevel: `React.useId` is invariant at runtime.
    return useGlobalId(idOverride);
}
exports.default = useId;
