"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get radioboxConfig () {
        return radioboxConfig;
    },
    get radioboxRoot () {
        return radioboxRoot;
    }
});
var _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
var _utils = require("../../utils");
var _Checkboxstyles = require("../Checkbox/Checkbox.styles");
var _base = require("./variations/_view/base");
var _base1 = require("./variations/_size/base");
var _base2 = require("./variations/_disabled/base");
var _base3 = require("./variations/_focused/base");
var _Radioboxstyles = require("./Radiobox.styles");
var _Radioboxtokens = require("./Radiobox.tokens");
function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _getRequireWildcardCache(nodeInterop) {
    if (typeof WeakMap !== "function") return null;
    var cacheBabelInterop = new WeakMap();
    var cacheNodeInterop = new WeakMap();
    return (_getRequireWildcardCache = function(nodeInterop) {
        return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
    })(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
    if (!nodeInterop && obj && obj.__esModule) {
        return obj;
    }
    if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
        return {
            default: obj
        };
    }
    var cache = _getRequireWildcardCache(nodeInterop);
    if (cache && cache.has(obj)) {
        return cache.get(obj);
    }
    var newObj = {
        __proto__: null
    };
    var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
    for(var key in obj){
        if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
            var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
            if (desc && (desc.get || desc.set)) {
                Object.defineProperty(newObj, key, desc);
            } else {
                newObj[key] = obj[key];
            }
        }
    }
    newObj.default = obj;
    if (cache) {
        cache.set(obj, newObj);
    }
    return newObj;
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
function ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);
    if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);
        if (enumerableOnly) {
            symbols = symbols.filter(function(sym) {
                return Object.getOwnPropertyDescriptor(object, sym).enumerable;
            });
        }
        keys.push.apply(keys, symbols);
    }
    return keys;
}
function _object_spread_props(target, source) {
    source = source != null ? source : {};
    if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
    } else {
        ownKeys(Object(source)).forEach(function(key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
        });
    }
    return target;
}
function _object_without_properties(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys, key, i;
    if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
        sourceKeys = Reflect.ownKeys(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
        return target;
    }
    target = _object_without_properties_loose(source, excluded);
    if (Object.getOwnPropertySymbols) {
        sourceKeys = Object.getOwnPropertySymbols(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
    }
    return target;
}
function _object_without_properties_loose(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
    for(i = 0; i < sourceKeys.length; i++){
        key = sourceKeys[i];
        if (excluded.indexOf(key) >= 0) continue;
        if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
        target[key] = source[key];
    }
    return target;
}
var radioboxRoot = function radioboxRoot(Root) {
    return /*#__PURE__*/ (0, _react.forwardRef)(function(props, ref) {
        var size = props.size, view = props.view, focused = props.focused, disabled = props.disabled, id = props.id, label = props.label, description = props.description, style = props.style, className = props.className, _props_singleLine = props.singleLine, singleLine = _props_singleLine === void 0 ? false : _props_singleLine, ariaLabelExternal = props['aria-label'], rest = _object_without_properties(props, [
            "size",
            "view",
            "focused",
            "disabled",
            "id",
            "label",
            "description",
            "style",
            "className",
            "singleLine",
            'aria-label'
        ]);
        var uniqId = (0, _utils.safeUseId)();
        var uniqLabelId = "label-".concat(uniqId);
        var uniqDescriptionId = "description-".concat(uniqId);
        var radioboxId = id || "input-".concat(uniqId);
        var ariaLabel = (0, _react.useMemo)(function() {
            return ariaLabelExternal || (0, _utils.extractTextFrom)(label);
        }, [
            ariaLabelExternal,
            label
        ]);
        var isLabelAriaHidden = typeof label === 'string';
        var canFocused = focused ? 0 : -1;
        var hasContent = label || description;
        var singleLineClass = singleLine ? _Radioboxtokens.classes.singleLine : undefined;
        var onlyDescriptionClass = !label && description ? _Radioboxtokens.classes.onlyDescription : undefined;
        return /*#__PURE__*/ _react.default.createElement(Root, {
            view: view,
            size: size,
            disabled: disabled,
            focused: focused,
            style: style,
            className: className,
            tabIndex: -1
        }, /*#__PURE__*/ _react.default.createElement(_Checkboxstyles.StyledInput, _object_spread_props(_object_spread({}, rest), {
            id: radioboxId,
            ref: ref,
            type: "radio",
            disabled: disabled,
            "aria-label": ariaLabel,
            "aria-describedby": uniqDescriptionId,
            tabIndex: canFocused
        })), /*#__PURE__*/ _react.default.createElement(_Checkboxstyles.StyledContentWrapper, {
            htmlFor: radioboxId,
            className: singleLineClass
        }, /*#__PURE__*/ _react.default.createElement(_Checkboxstyles.StyledTriggerWrapper, null, /*#__PURE__*/ _react.default.createElement(_Checkboxstyles.StyledTrigger, {
            className: _Radioboxtokens.classes.radioboxTrigger
        }, /*#__PURE__*/ _react.default.createElement(_Radioboxstyles.StyledEllipse, null))), hasContent && /*#__PURE__*/ _react.default.createElement(_Checkboxstyles.StyledContent, {
            className: singleLineClass
        }, label && /*#__PURE__*/ _react.default.createElement(_Checkboxstyles.StyledLabel, {
            className: (0, _utils.cx)(singleLineClass, onlyDescriptionClass),
            id: uniqLabelId,
            "aria-hidden": isLabelAriaHidden
        }, label), description && /*#__PURE__*/ _react.default.createElement(_Checkboxstyles.StyledDescription, {
            className: singleLineClass,
            id: uniqDescriptionId
        }, description))));
    });
};
var radioboxConfig = {
    name: 'Radiobox',
    tag: 'div',
    layout: radioboxRoot,
    base: _Radioboxstyles.base,
    variations: {
        size: {
            css: _base1.base
        },
        view: {
            css: _base.base
        },
        disabled: {
            css: _base2.base
        },
        focused: {
            css: _base3.base
        }
    },
    defaults: {
        size: 'm',
        view: 'accent'
    }
};
