import React from 'react';
import { ActionControl } from '../ActionControl/ActionControl';
import { Add } from '@wix/wix-ui-icons-common';
import { useWixPatternsContainer } from '@wix/bex-core/react';
import { useSelector } from '../../useSelector';
import { cairoPageCtaClicked } from '@wix/bex-core/bi';
import { useIsMobile } from '../../hooks/useIsMobile';
export function PrimaryActions({ subItems, ...props }) {
    const { initTask, translate: t, reportBi } = useWixPatternsContainer();
    useSelector(() => initTask.status);
    const isMobile = useIsMobile();
    const subItemsGrouped = subItems
        ? Array.isArray(subItems?.[0])
            ? subItems
            : [subItems]
        : subItems;
    return (React.createElement(ActionControl, { size: isMobile ? 'small' : undefined, fullWidth: isMobile, onPopoverClick: () => {
            reportBi(cairoPageCtaClicked({
                location: 'Collection Page Header',
                pageType: 'Collection',
                ctaName: props.biName ?? '',
                ctaType: 'primary page dropdown',
                additionalInfo: props.biAdditionalInfo,
            }));
        }, actionItem: {
            prefixIcon: React.createElement(Add, null),
            label: t('cairo.page.primary.cta'),
            dataHook: 'primary-actions',
            ...props,
            subItems: subItemsGrouped?.map((subItems) => subItems?.map((subItem) => ({
                ...subItem,
                onClick: () => {
                    reportBi(cairoPageCtaClicked({
                        location: 'Collection Page Header',
                        pageType: 'Collection',
                        ctaName: subItem.biName ?? '',
                        ctaType: 'primary page option',
                        additionalInfo: subItem.biAdditionalInfo,
                    }));
                    subItem.onClick?.();
                },
            }))),
            onClick: () => {
                reportBi(cairoPageCtaClicked({
                    location: 'Collection Page Header',
                    pageType: 'Collection',
                    ctaName: props.biName ?? '',
                    ctaType: 'primary page button',
                    additionalInfo: props.biAdditionalInfo,
                }));
                props.onClick?.();
            },
        } }));
}
//# sourceMappingURL=PrimaryActions.js.map