"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NestedMenuButton = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const react_native_1 = require("react-native");
const react_native_2 = require("@fluentui/react-native");
const MenuButtonLegacyTestStyles_1 = require("./MenuButtonLegacyTestStyles");
const testData_1 = require("./testData");
const iconExamples_1 = require("../Common/iconExamples");
const NestedMenuButton = () => {
    const [lastMenuItemClicked, setLastMenuItemClicked] = React.useState(null);
    const [focusOnMount, setShouldFocusOnMount] = React.useState(true);
    const toggleFocusOnMount = React.useCallback((value) => setShouldFocusOnMount(value), [setShouldFocusOnMount]);
    const [focusOnContainer, setShouldFocusOnContainer] = React.useState(false);
    const toggleFocusOnContainer = React.useCallback((value) => setShouldFocusOnContainer(value), [setShouldFocusOnContainer]);
    const onItemClick = React.useCallback((key) => {
        setLastMenuItemClicked(key);
    }, [setLastMenuItemClicked]);
    const [showSubmenu, setShowSubmenu] = React.useState(false);
    const [isSubmenuVisible, setIsSubmenuVisible] = React.useState(false);
    const [lastSubmenuItemClicked, setSubmenuLastItemClicked] = React.useState(null);
    const toggleShowSubmenu = React.useCallback(() => {
        setShowSubmenu(!showSubmenu);
        setIsSubmenuVisible(!isSubmenuVisible);
    }, [showSubmenu, isSubmenuVisible, setShowSubmenu, setIsSubmenuVisible]);
    const onShowSubmenu = React.useCallback(() => {
        setIsSubmenuVisible(true);
    }, [setIsSubmenuVisible]);
    const onDismissSubmenu = React.useCallback(() => {
        setShowSubmenu(false);
    }, [setShowSubmenu]);
    const onSubmenuItemClick = React.useCallback((key) => {
        setSubmenuLastItemClicked(key);
    }, [setSubmenuLastItemClicked]);
    const nestedMenuItems = [
        ...testData_1.menuItems,
        {
            hasSubmenu: true,
            itemKey: '4',
            text: 'SubmenuItem svg icon',
            componentRef: React.useRef(null),
            icon: testData_1.iconProps,
            onHoverIn: toggleShowSubmenu,
            showSubmenu,
            submenuProps: {
                onShow: onShowSubmenu,
                setShowMenu: toggleShowSubmenu,
                onDismiss: onDismissSubmenu,
                onItemClick: onSubmenuItemClick,
            },
            submenuItems: [
                {
                    icon: testData_1.iconProps,
                    text: 'SubmenuItem svg icon',
                    itemKey: '1',
                },
                {
                    itemKey: '2',
                    text: 'SubmenuItem 2',
                    disabled: true,
                },
                {
                    itemKey: '3',
                    text: 'SubmenuItem 3',
                },
            ],
        },
        {
            itemKey: '5',
            text: 'Menu Item',
        },
        {
            hasSubmenu: true,
            itemKey: '6',
            text: 'SubmenuItem',
            componentRef: React.useRef(null),
            submenuProps: {
                onItemClick: onSubmenuItemClick,
            },
            submenuItems: [
                {
                    text: 'SubmenuItem 1',
                    itemKey: '1',
                },
                {
                    itemKey: '2',
                    text: 'SubmenuItem 2',
                },
                {
                    itemKey: '3',
                    text: 'SubmenuItem 3',
                },
            ],
        },
    ];
    const rasterImageProps = {
        rasterImageSource: {
            src: iconExamples_1.testImage,
        },
        width: 12,
        height: 12,
    };
    return (React.createElement(react_native_1.View, null,
        React.createElement(react_native_1.View, { style: MenuButtonLegacyTestStyles_1.viewWrapperStyle },
            React.createElement(react_native_1.View, { style: MenuButtonLegacyTestStyles_1.columnStyle },
                React.createElement(react_native_1.View, { style: MenuButtonLegacyTestStyles_1.rowStyle },
                    React.createElement(react_native_1.Text, null, "Should Focus on Mount"),
                    React.createElement(react_native_1.Switch, { value: focusOnMount, onValueChange: toggleFocusOnMount })),
                React.createElement(react_native_1.View, { style: MenuButtonLegacyTestStyles_1.rowStyle },
                    React.createElement(react_native_1.Text, null, "Should Focus on Container"),
                    React.createElement(react_native_1.Switch, { value: focusOnContainer, onValueChange: toggleFocusOnContainer }))),
            React.createElement(react_native_2.Separator, { vertical: true }),
            React.createElement(react_native_1.View, { style: MenuButtonLegacyTestStyles_1.columnStyle },
                React.createElement(react_native_1.Text, null,
                    React.createElement(react_native_1.Text, null, "Last Menu Item Clicked: "),
                    lastMenuItemClicked > 0 ? React.createElement(react_native_1.Text, { style: MenuButtonLegacyTestStyles_1.textColor }, lastMenuItemClicked) : React.createElement(react_native_1.Text, { style: MenuButtonLegacyTestStyles_1.textColor }, "none")),
                React.createElement(react_native_1.Text, null,
                    React.createElement(react_native_1.Text, null, "Last Submenu Item Clicked: "),
                    lastSubmenuItemClicked > 0 ? React.createElement(react_native_1.Text, { style: MenuButtonLegacyTestStyles_1.textColor }, lastSubmenuItemClicked) : React.createElement(react_native_1.Text, { style: MenuButtonLegacyTestStyles_1.textColor }, "none")),
                React.createElement(react_native_2.MenuButton, { startIcon: rasterImageProps, content: "Press for Nested MenuButton", menuItems: nestedMenuItems, onItemClick: onItemClick })))));
};
exports.NestedMenuButton = NestedMenuButton;
//# sourceMappingURL=NestedMenuButtonTest.js.map