import { baseUniDriverFactory } from '../utils/test-utils/unidriver';
import { mediaOverlayDriverFactory, } from '../MediaOverlay/MediaOverlay.uni.driver';
import { DATA_HOOKS } from './CardGalleryItem.constants';
import { dragHandleUniDriverFactory } from '../DragHandle/DragHandle.uni.driver';
const byHook = (base, dataHook) => base.$(`[data-hook="${dataHook}"]`);
const getTitle = (base) => byHook(base, DATA_HOOKS.Title);
const getBadge = (base) => byHook(base, DATA_HOOKS.Badge);
const getSettingsMenu = (base) => byHook(base, DATA_HOOKS.SettingsMenu);
const getSubtitle = (base) => byHook(base, DATA_HOOKS.Subtitle);
const getContainer = (base) => byHook(base, DATA_HOOKS.Container);
const getFooter = (base) => byHook(base, DATA_HOOKS.footer);
const getCustomFooter = (base) => byHook(base, DATA_HOOKS.customFooter);
const getOverlayDriver = (base) => {
    const hoverComponent = byHook(base, DATA_HOOKS.HoverComponent);
    return mediaOverlayDriverFactory(hoverComponent);
};
const hover = async (base) => getContainer(base).hover();
const getPrimaryAction = async (base) => {
    await hover(base);
    return byHook(base, DATA_HOOKS.PrimaryAction);
};
const getSecondaryAction = async (base) => {
    await hover(base);
    return byHook(base, DATA_HOOKS.SecondaryAction);
};
const cardGalleryItemDriverFactory = (base, body) => {
    const getDragHandle = () => dragHandleUniDriverFactory(base.$(`[data-hook="${DATA_HOOKS.dragHandle}"]`), body);
    return {
        ...baseUniDriverFactory(base),
        /** Gets the cards title. */
        getTitle: async () => {
            const title = getTitle(base);
            return (await title.exists()) ? title.text() : null;
        },
        /** Gets the badge node element. */
        getBadge: async () => {
            const badge = getBadge(base);
            return (await badge.exists()) ? badge.prop('firstChild') : null;
        },
        /** Gets the cards subtitle. */
        getSubtitle: async () => {
            const subtitle = getSubtitle(base);
            return (await subtitle.exists()) ? subtitle.text() : null;
        },
        /** Gets the background image URL. */
        getBackgroundImageUrl: async () => await getOverlayDriver(base).getMediaUrl(),
        /** Clicks on the primary action. */
        click: async () => (await getPrimaryAction(base)).click(),
        /** Clicks on the container. */
        clickOnContainer: async () => (await getContainer(base)).click(),
        /** Clicks on the footer. */
        clickFooter: async () => (await getFooter(base)).click(),
        /** Gets the primary action label. */
        getPrimaryActionLabel: async () => (await getPrimaryAction(base)).text(),
        /** Checks whether the primary action is clickable. */
        isPrimaryActionDisabled: async () => (await (await getPrimaryAction(base)).attr('aria-disabled')) === 'true',
        /** Clicks on the primary action button. */
        clickOnPrimaryAction: async () => (await getPrimaryAction(base)).click(),
        /** Gets the secondary action label. l*/
        getSecondaryActionLabel: async () => (await getSecondaryAction(base)).text(),
        /** Clicks on the secondary action. */
        clickOnSecondaryAction: async () => (await getSecondaryAction(base)).click(),
        /** Gets the the settingsMenu node. */
        getSettingsMenu: async () => {
            await hover(base);
            const settingsMenu = getSettingsMenu(base);
            return (await settingsMenu.exists())
                ? settingsMenu.prop('firstChild')
                : null;
        },
        /** Gets the background image element. */
        getBackgroundImageNode: async () => getOverlayDriver(base).getMediaNode(),
        /** Hovers the component. */
        hover: async () => hover(base),
        /** Indicates drag handle exists */
        dragHandleExists: () => getDragHandle().exists(),
        clickDragHandle: () => getDragHandle().click(),
        hoverDragHandle: () => getDragHandle().hover(),
        isDragHandleTooltipEnabled: () => getDragHandle().isTooltipEnabled(),
        getDragHandleTooltipContent: () => getDragHandle().getTooltipContent(),
        getCustomFooter: async () => (await getCustomFooter(base)).prop('firstChild'),
    };
};
export default cardGalleryItemDriverFactory;
//# sourceMappingURL=CardGalleryItem.uni.driver.js.map