import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useCallback, useMemo } from 'react';
import { Link, Selector, Sep } from './MultiDropdown.styles.js';
export function useDropdownOptions(options, selectedKeys) {
    return useMemo(()=>{
        const hash = (selectedKeys || []).reduce((acc, cur)=>{
            acc[cur] = true;
            return acc;
        }, {});
        const main = options.map((option)=>{
            const selected = !!hash[option.key];
            return {
                ...option,
                selected
            };
        });
        return [
            ...main,
            {
                key: '--divider--',
                text: '-',
                itemType: 1,
                selected: false
            },
            {
                key: '--actions--',
                text: '',
                itemType: 2,
                data: true,
                selected: false
            }, 
        ];
    }, [
        options,
        selectedKeys
    ]);
}
export function useOptionRenderer(options, onSelectAllOrNone) {
    const handleSelectAll = useCallback(()=>onSelectAllOrNone?.(options), [
        onSelectAllOrNone,
        options
    ]);
    const handleSelectNone = useCallback(()=>onSelectAllOrNone?.([]), [
        onSelectAllOrNone
    ]);
    const handleRenderOption = useCallback((option)=>{
        if (option?.data) {
            return /*#__PURE__*/ _jsxs(Selector, {
                children: [
                    /*#__PURE__*/ _jsx(Link, {
                        onClick: handleSelectAll,
                        children: "All"
                    }),
                    /*#__PURE__*/ _jsx(Sep, {
                        children: "|"
                    }),
                    /*#__PURE__*/ _jsx(Link, {
                        onClick: handleSelectNone,
                        children: "None"
                    })
                ]
            });
        } else {
            return /*#__PURE__*/ _jsx("span", {
                children: option?.text
            });
        }
    }, [
        handleSelectAll,
        handleSelectNone
    ]);
    return handleRenderOption;
}
