import badgeDriverFactory from '../Badge/Badge.driver';
import * as DATA_ATTR from './DataAttr';
import dropdownLayoutDriverFactory from '../DropdownLayout/DropdownLayout.driver';
import { popoverLegacyDriverFactory } from '../Popover/Popover.driver';
import deprecationTestkitLog from '../utils/deprecationTestkitLog';
const badgeSelectDriverFactory = ({ element, eventTrigger }) => {
    deprecationTestkitLog('badgeSelectTestkitFactory legacy testkit is deprecated and will be removed in next major release. Please use the BadgeSelectTestkit unidriver testkit instead.');
    const popoverDriver = popoverLegacyDriverFactory({ element, eventTrigger });
    const badgeDriver = badgeDriverFactory({
        element: element.querySelector(`[data-hook="${DATA_ATTR.DATA_BADGE}"]`),
        eventTrigger,
    });
    return {
        /** Returns 'true' whether the element exists */
        exists: () => !!element,
        /** Gets badge text */
        text: badgeDriver.text,
        /** Click on an option */
        clickAtOption: index => {
            if (!popoverDriver.isContentElementExists()) {
                badgeDriver.click();
            }
            // Since the popover may be closed, we need to create the DropdownLayout driver every time
            const dropdownLayoutDriver = dropdownLayoutDriverFactory({
                element: popoverDriver
                    .getContentElement()
                    .querySelector(`[data-hook="${DATA_ATTR.DATA_DROPDOWN}"]`),
            });
            if (dropdownLayoutDriver.exists()) {
                dropdownLayoutDriver.clickAtOption(index);
            }
        },
    };
};
export default badgeSelectDriverFactory;
//# sourceMappingURL=BadgeSelect.driver.js.map