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 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;
}
import React, { forwardRef, useRef, useContext } from "react";
import { useForkRef } from "../../../../../hooks";
import { cx } from "../../../../../utils";
import { TabsContext } from "../../..";
import { useTabItem } from "../../../hooks/useTabItem";
import { classes } from "../../../tokens";
import { ActionContent, base, LeftContent, RightContent, StyledContent, TabItemValue } from "./VerticalTabItem.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";
export var verticalTabItemRoot = function verticalTabItemRoot(Root) {
    return /*#__PURE__*/ forwardRef(function(props, outerRef) {
        var size = props.size, view = props.view, selected = props.selected, _props_disabled = props.disabled, disabled = _props_disabled === void 0 ? false : _props_disabled, children = props.children, value = props.value, contentLeft = props.contentLeft, contentRight = props.contentRight, actionContent = props.actionContent, onIndexChange = props.onIndexChange, itemIndex = props.itemIndex, tabIndex = props.tabIndex, className = props.className, onClick = props.onClick, tmp = props.maxItemWidth, maxWidth = tmp === void 0 ? 'auto' : tmp, rest = _object_without_properties(props, [
            "size",
            "view",
            "selected",
            "disabled",
            "children",
            "value",
            "contentLeft",
            "contentRight",
            "actionContent",
            "onIndexChange",
            "itemIndex",
            "tabIndex",
            "className",
            "onClick",
            "maxItemWidth"
        ]);
        var innerRef = useRef(null);
        var ref = useForkRef(outerRef, innerRef);
        var refs = useContext(TabsContext);
        var role = 'tab';
        var selectedClass = selected ? classes.selectedTabsItem : undefined;
        var truncateClass = maxWidth !== 'auto' ? classes.tabsTruncate : undefined;
        var _useTabItem = useTabItem({
            refs: refs,
            innerRef: innerRef,
            itemIndex: itemIndex,
            selected: selected,
            disabled: disabled,
            onIndexChange: onIndexChange,
            onClick: onClick,
            orientation: rest.orientation
        }), hasKeyNavigation = _useTabItem.hasKeyNavigation, navigationTabIndex = _useTabItem.navigationTabIndex, onItemFocus = _useTabItem.onItemFocus, handleClick = _useTabItem.handleClick;
        return /*#__PURE__*/ React.createElement(Root, _object_spread_props(_object_spread({
            ref: ref,
            disabled: disabled,
            role: role,
            view: view,
            size: size,
            onFocus: onItemFocus,
            tabIndex: hasKeyNavigation ? navigationTabIndex : tabIndex,
            className: cx(selectedClass, truncateClass, className),
            onClick: handleClick
        }, rest), {
            style: _object_spread_props(_object_spread({}, rest.style), {
                maxWidth: maxWidth
            })
        }), /*#__PURE__*/ React.createElement(React.Fragment, null, contentLeft && /*#__PURE__*/ React.createElement(LeftContent, {
            className: classes.tabLeftContent
        }, contentLeft), /*#__PURE__*/ React.createElement(StyledContent, {
            className: classes.tabContent
        }, children), !contentRight && value && /*#__PURE__*/ React.createElement(TabItemValue, null, value), !value && contentRight && /*#__PURE__*/ React.createElement(RightContent, {
            className: classes.tabRightContent
        }, contentRight), actionContent && /*#__PURE__*/ React.createElement(ActionContent, null, actionContent)));
    });
};
export var verticalTabItemConfig = {
    name: 'VerticalTabItem',
    tag: 'button',
    layout: verticalTabItemRoot,
    base: base,
    variations: {
        size: {
            css: sizeCSS
        },
        view: {
            css: viewCSS
        },
        disabled: {
            css: disabledCSS,
            attrs: true
        }
    },
    defaults: {
        view: 'divider'
    }
};
