import addItemDriverFactory from '../AddItem/AddItem.driver';
import { dataAttributes, dataHooks } from './constants';
import { tooltipLegacyDriverFactory } from '../Tooltip/Tooltip.driver';
const imageViewerDriverFactory = ({ element, wrapper, eventTrigger }) => {
    const byHook = dataHook => element.querySelector(`[data-hook="${dataHook}"]`);
    const hasDataAttribute = (dataAttr, el) => el.getAttribute(dataAttr) === 'true';
    const addItemDriver = () => addItemDriverFactory({
        element: byHook(dataHooks.addItem),
        eventTrigger,
    });
    const getTooltipDriver = dataHook => tooltipLegacyDriverFactory({
        element: element.querySelector(`[data-hook="${dataHook}"]`),
        eventTrigger,
    });
    const getImageElement = () => byHook(dataHooks.image);
    const getPreviousImageElement = () => byHook(dataHooks.previousImage);
    const isImagesContainerElementVisible = () => hasDataAttribute(dataAttributes.containerVisible, byHook(dataHooks.imagesContainer));
    const isImageElementVisible = imgElement => hasDataAttribute(dataAttributes.imageVisible, imgElement);
    const hoverElement = () => eventTrigger.mouseOver(element);
    const showButtons = hoverElement;
    return {
        exists: () => !!element,
        getElement: () => element, // for backward compatibility
        element: () => element, // same as unidriver language
        updateExists: () => !!byHook(dataHooks.update),
        updateButtonExists: () => !!byHook(dataHooks.update),
        removeButtonExists: () => !!byHook(dataHooks.remove),
        downloadButtonExists: () => !!byHook(dataHooks.download),
        moreButtonExists: () => !!byHook(dataHooks.more),
        clickAdd: () => addItemDriver().click(),
        clickUpdate: () => {
            showButtons();
            eventTrigger.click(byHook(dataHooks.update));
        },
        clickDownload: () => {
            showButtons();
            eventTrigger.click(byHook(dataHooks.download));
        },
        clickRemove: () => {
            showButtons();
            eventTrigger.click(byHook(dataHooks.remove));
        },
        getContainerStyles: () => element.getAttribute('style'),
        getAddTooltipContent: () => addItemDriver().getTooltipContent(),
        getUpdateTooltipContent: () => getTooltipDriver(dataHooks.updateTooltip).getTooltipText(),
        getDownloadTooltipContent: () => getTooltipDriver(dataHooks.downloadTooltip).getTooltipText(),
        getRemoveTooltipContent: () => getTooltipDriver(dataHooks.removeTooltip).getTooltipText(),
        getMoreTooltipContent: () => getTooltipDriver(dataHooks.moreTooltip).getTooltipText(),
        isDisabled: () => element.getAttribute('data-disabled') === 'true',
        isAddItemVisible: () => !!byHook(dataHooks.addItem),
        isLoaderVisible: () => !!byHook(dataHooks.loader),
        isImageLoaded: () => hasDataAttribute(dataAttributes.imageLoaded, element),
        isImageVisible: () => {
            const image = getImageElement();
            return (!!image &&
                isImageElementVisible(image) &&
                isImagesContainerElementVisible());
        },
        isPreviousImageVisible: () => {
            const previousImage = getPreviousImageElement();
            return (!!previousImage &&
                isImageElementVisible(previousImage) &&
                isImagesContainerElementVisible());
        },
        getImageUrl: () => {
            const imageUrl = getImageElement();
            return imageUrl && imageUrl.getAttribute('src');
        },
        getPreviousImageUrl: () => {
            const previousImage = getPreviousImageElement();
            return previousImage && previousImage.getAttribute('src');
        },
        hover: () => hoverElement(),
        // Status
        /** Return true if the given status is displayed */
        hasStatus: status => {
            const statusEl = element.querySelector(`[data-hook='${dataHooks.errorTooltip}']`);
            return (statusEl && statusEl.getAttribute('data-status')) === status;
        },
        /** If there's a status message, returns its text value */
        getStatusMessage: () => getTooltipDriver('status-indicator-tooltip').getTooltipText(0),
    };
};
export default imageViewerDriverFactory;
//# sourceMappingURL=ImageViewer.driver.js.map