import React, { forwardRef, useMemo } from "react";
import { safeUseId, cx, extractTextFrom } from "../../utils";
import { StyledContentWrapper, StyledDescription, StyledInput, StyledLabel, StyledContent, StyledTrigger, StyledTriggerWrapper } from "../Checkbox/Checkbox.styles";
import { base as viewCSS } from "./variations/_view/base";
import { base as sizeCSS } from "./variations/_size/base";
import { base as disabledCSS } from "./variations/_disabled/base";
import { base as focusedCSS } from "./variations/_focused/base";
import { StyledEllipse, base } from "./Radiobox.styles";
import { classes } from "./Radiobox.tokens";
export const radioboxRoot = (Root)=>/*#__PURE__*/ forwardRef((props, ref)=>{
        const { size, view, focused, disabled, id, label, description, style, className, singleLine = false, 'aria-label': ariaLabelExternal, ...rest } = props;
        const uniqId = safeUseId();
        const uniqLabelId = `label-${uniqId}`;
        const uniqDescriptionId = `description-${uniqId}`;
        const radioboxId = id || `input-${uniqId}`;
        const ariaLabel = useMemo(()=>ariaLabelExternal || extractTextFrom(label), [
            ariaLabelExternal,
            label
        ]);
        const isLabelAriaHidden = typeof label === 'string';
        const canFocused = focused ? 0 : -1;
        const hasContent = label || description;
        const singleLineClass = singleLine ? classes.singleLine : undefined;
        const onlyDescriptionClass = !label && description ? classes.onlyDescription : undefined;
        return /*#__PURE__*/ React.createElement(Root, {
            view: view,
            size: size,
            disabled: disabled,
            focused: focused,
            style: style,
            className: className,
            tabIndex: -1
        }, /*#__PURE__*/ React.createElement(StyledInput, {
            ...rest,
            id: radioboxId,
            ref: ref,
            type: "radio",
            disabled: disabled,
            "aria-label": ariaLabel,
            "aria-describedby": uniqDescriptionId,
            tabIndex: canFocused
        }), /*#__PURE__*/ React.createElement(StyledContentWrapper, {
            htmlFor: radioboxId,
            className: singleLineClass
        }, /*#__PURE__*/ React.createElement(StyledTriggerWrapper, null, /*#__PURE__*/ React.createElement(StyledTrigger, {
            className: classes.radioboxTrigger
        }, /*#__PURE__*/ React.createElement(StyledEllipse, null))), hasContent && /*#__PURE__*/ React.createElement(StyledContent, {
            className: singleLineClass
        }, label && /*#__PURE__*/ React.createElement(StyledLabel, {
            className: cx(singleLineClass, onlyDescriptionClass),
            id: uniqLabelId,
            "aria-hidden": isLabelAriaHidden
        }, label), description && /*#__PURE__*/ React.createElement(StyledDescription, {
            className: singleLineClass,
            id: uniqDescriptionId
        }, description))));
    });
export const radioboxConfig = {
    name: 'Radiobox',
    tag: 'div',
    layout: radioboxRoot,
    base,
    variations: {
        size: {
            css: sizeCSS
        },
        view: {
            css: viewCSS
        },
        disabled: {
            css: disabledCSS
        },
        focused: {
            css: focusedCSS
        }
    },
    defaults: {
        size: 'm',
        view: 'accent'
    }
};
