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 _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 _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;
}
import React, { forwardRef } from "react";
import { cx, safeUseId } from "../../../../utils";
import { classes } from "../../tokens";
import { useSegmentInner } from "../../SegmentProvider/SegmentProvider";
import { base as sizeCSS } from "./variations/_size/base";
import { base as viewCSS } from "./variations/_view/base";
import { base as disabledCSS } from "./variations/_disabled/base";
import { base as pilledCSS } from "./variations/_pilled/base";
import { StyledIcon, base } from "./SegmentIconItem.styles";
export var segmentIconItemRoot = function segmentIconItemRoot(Root) {
    return /*#__PURE__*/ forwardRef(function(props, outerRef) {
        var style = props.style, size = props.size, _props_view = props.view, view = _props_view === void 0 ? 'default' : _props_view, className = props.className, id = props.id, icon = props.icon, value = props.value, pilled = props.pilled, customHandleSelect = props.customHandleSelect, ariaLabelExternal = props['aria-label'], rest = _object_without_properties(props, [
            "style",
            "size",
            "view",
            "className",
            "id",
            "icon",
            "value",
            "pilled",
            "customHandleSelect",
            'aria-label'
        ]);
        var _useSegmentInner = useSegmentInner(), disabledGroup = _useSegmentInner.disabledGroup, handleSelect = _useSegmentInner.handleSelect, selectedSegmentItems = _useSegmentInner.selectedSegmentItems;
        var uniqId = safeUseId();
        var segmentId = id || "label-".concat(uniqId);
        var pilledClass = pilled ? classes.segmentPilled : undefined;
        var isSelected = selectedSegmentItems === null || selectedSegmentItems === void 0 ? void 0 : selectedSegmentItems.includes(value);
        var selectedClass = isSelected ? classes.selectedSegmentItem : undefined;
        var handleSelectSegment = function handleSelectSegment(event) {
            if (disabledGroup) {
                return;
            }
            customHandleSelect === null || customHandleSelect === void 0 ? void 0 : customHandleSelect(event);
            handleSelect === null || handleSelect === void 0 ? void 0 : handleSelect(value);
        };
        return /*#__PURE__*/ React.createElement(Root, _object_spread({
            view: view,
            size: size,
            id: segmentId,
            ref: outerRef,
            "aria-label": ariaLabelExternal || value,
            value: value,
            pilled: pilled,
            className: cx(selectedClass, pilledClass, className),
            onClick: handleSelectSegment,
            tabIndex: disabledGroup ? -1 : 0,
            disabled: disabledGroup,
            style: style
        }, rest), /*#__PURE__*/ React.createElement(StyledIcon, null, icon));
    });
};
export var segmentIconItemConfig = {
    name: 'SegmentIconItem',
    tag: 'button',
    layout: segmentIconItemRoot,
    base: base,
    variations: {
        size: {
            css: sizeCSS
        },
        view: {
            css: viewCSS
        },
        disabled: {
            css: disabledCSS,
            attrs: true
        },
        pilled: {
            css: pilledCSS,
            attrs: true
        }
    },
    defaults: {
        view: 'default',
        size: 'xs'
    }
};
