/* eslint-disable react-hooks/rules-of-hooks */ import { useState } from "react";
/**
 * This is used to dynamically allow controlling hooks by providing a `value` +
 * `setValue` or defaulting to uncontrolled behavior with local state.
 *
 * @internal
 * @since 6.0.0
 */ export function useEnsuredState(options) {
    const { name = "value", value, setValue, defaultValue } = options;
    if (typeof value !== "undefined" && typeof setValue !== "undefined") {
        return [
            value,
            setValue
        ];
    }
    if (typeof value !== "undefined" || typeof setValue !== "undefined") {
        const pascalName = name.charAt(0).toUpperCase() + name.substring(1);
        throw new Error(`Both a \`${name}\` and \`set${pascalName}\` must be defined for controlled components.`);
    }
    if (typeof defaultValue === "undefined") {
        const pascalName = name.charAt(0).toUpperCase() + name.substring(1);
        throw new Error(`A \`default${pascalName}\` must be defined for uncontrolled components.`);
    }
    return useState(defaultValue);
}

//# sourceMappingURL=useEnsuredState.js.map