'use client';
"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: all[name]
    });
}
_export(exports, {
    useAccordionHeaderBase_unstable: function() {
        return useAccordionHeaderBase_unstable;
    },
    useAccordionHeader_unstable: function() {
        return useAccordionHeader_unstable;
    }
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
const _reactutilities = require("@fluentui/react-utilities");
const _reactaria = require("@fluentui/react-aria");
const _accordion = require("../../contexts/accordion");
const _reacticons = require("@fluentui/react-icons");
const _reactsharedcontexts = require("@fluentui/react-shared-contexts");
const _accordionItem = require("../../contexts/accordionItem");
const _reactmotion = require("@fluentui/react-motion");
const useAccordionHeader_unstable = (props, ref)=>{
    const { inline = false, size = 'medium', ...baseProps } = props;
    const state = useAccordionHeaderBase_unstable(baseProps, ref);
    const { dir } = (0, _reactsharedcontexts.useFluent_unstable)();
    // Calculate how to rotate the expand icon [>] (ChevronRightRegular)
    let expandIconRotation;
    if (state.expandIconPosition === 'end') {
        // If expand icon is at the end, the chevron points up [^] when open, and down [v] when closed
        expandIconRotation = state.open ? -90 : 90;
    } else {
        // Otherwise, the chevron points down [v] when open, and right [>] (or left [<] in RTL) when closed
        expandIconRotation = state.open ? 90 : dir !== 'rtl' ? 0 : 180;
    }
    if (state.expandIcon) {
        var _state_expandIcon;
        var _children;
        (_children = (_state_expandIcon = state.expandIcon).children) !== null && _children !== void 0 ? _children : _state_expandIcon.children = /*#__PURE__*/ _react.createElement(_reacticons.ChevronRightRegular, {
            style: {
                transform: `rotate(${expandIconRotation}deg)`,
                transition: `transform ${_reactmotion.motionTokens.durationNormal}ms ease-out`
            }
        });
    }
    return {
        ...state,
        inline,
        size
    };
};
const useAccordionHeaderBase_unstable = (props, ref)=>{
    const { icon, button, expandIcon, expandIconPosition = 'start', ...rest } = props;
    const { value, disabled, open } = (0, _accordionItem.useAccordionItemContext_unstable)();
    const requestToggle = (0, _accordion.useAccordionContext_unstable)((ctx)=>ctx.requestToggle);
    /**
   * force disabled state on button if accordion isn't collapsible
   * and this is the only item opened
   */ const disabledFocusable = (0, _accordion.useAccordionContext_unstable)((ctx)=>!ctx.collapsible && ctx.openItems.length === 1 && open);
    const buttonSlot = _reactutilities.slot.always(button, {
        elementType: 'button',
        defaultProps: {
            disabled,
            disabledFocusable,
            'aria-expanded': open,
            type: 'button'
        }
    });
    buttonSlot.onClick = (0, _reactutilities.useEventCallback)((event)=>{
        if ((0, _reactutilities.isResolvedShorthand)(button)) {
            var _button_onClick;
            (_button_onClick = button.onClick) === null || _button_onClick === void 0 ? void 0 : _button_onClick.call(button, event);
        }
        if (!event.defaultPrevented) {
            requestToggle({
                value,
                event
            });
        }
    });
    return {
        disabled,
        open,
        expandIconPosition,
        components: {
            root: 'div',
            button: 'button',
            expandIcon: 'span',
            icon: 'div'
        },
        root: _reactutilities.slot.always({
            ref: ref,
            ...rest
        }, {
            elementType: 'div'
        }),
        icon: _reactutilities.slot.optional(icon, {
            elementType: 'div'
        }),
        expandIcon: _reactutilities.slot.optional(expandIcon, {
            renderByDefault: true,
            defaultProps: {
                'aria-hidden': true
            },
            elementType: 'span'
        }),
        button: (0, _reactaria.useARIAButtonProps)(buttonSlot.as, buttonSlot)
    };
};
