import { CheckboxUniDriver, InfoIconUniDriver, SidePanelUniDriver, TooltipUniDriver, SearchUniDriver, } from '@wix/design-system/dist/testkit/unidriver';
import { SlidingModalUniDriver } from '../SlidingModal/SlidingModal.uni.driver';
import { DragAndDropUniDriver } from '../DragAndDrop/DragAndDrop.uni.driver';
import { CustomFieldPopoverUniDriver } from '../CustomFieldsPanel/CustomFieldPopover.uni.driver';
import { CustomFieldsDisabledHintUniDriver } from '../CustomFields/CustomFieldsDisabledHint.uni.driver';
import { EmptyStateUniDriver } from '../EmptyState/EmptyState.uni.driver';
export function CustomColumnsPanelUniDriver(base, body) {
    const panelBase = () => base.$('[data-hook="custom-columns-panel"]');
    const panel = () => SidePanelUniDriver(panelBase(), body);
    const slidingModal = () => SlidingModalUniDriver(base.$('[data-hook="cairo-side-panel-modal"]'), body);
    const addItem = () => CustomFieldsDisabledHintUniDriver(base, body, {
        dataHook: 'custom-columns-data-extension-add-new',
    });
    const list = () => panelBase().$('[data-hook="custom-columns-list"]');
    const getDragAndDropDriver = () => DragAndDropUniDriver(list());
    const items = () => panelBase().$$('[data-hook="custom-columns-list"] > div');
    const getItemAtBase = (i) => items().get(i);
    const getItemByIdBase = (id) => list().$(`[data-hook="column-item-${id}"]`);
    const getSearch = () => SearchUniDriver(panelBase().$('[data-hook="custom-columns-search"]'), body);
    const getNoResults = () => EmptyStateUniDriver(panelBase().$('[data-hook="custom-columns-no-results-state"]'), body);
    const getCheckboxAt = (i) => {
        const getCheckboxBase = () => getItemAtBase(i).$('[data-hook="tableListItem-checkbox"]');
        return {
            wait: (timeout) => getItemAtBase(i).wait(timeout),
            getLabel: () => getItemAtBase(i).$('[data-hook="tableListItem-label"]').text(),
            getTooltipContent: () => CheckboxUniDriver(getCheckboxBase(), body).getTooltipContent(),
            isChecked: () => CheckboxUniDriver(getCheckboxBase(), body).isChecked(),
            isDisabled: () => CheckboxUniDriver(getCheckboxBase(), body).isDisabled(),
            click: () => CheckboxUniDriver(getCheckboxBase(), body).click(),
            exists: () => getCheckboxBase().exists(),
        };
    };
    const customFieldPopoverMenuAt = (i) => CustomFieldPopoverUniDriver(getItemAtBase(i), body);
    const getDragHandle = (base) => base.$('[data-hook="tableListItem-dragHandle"]');
    const getCheckboxById = (id) => {
        const getCheckboxBase = () => getItemByIdBase(id).$('[data-hook="tableListItem-checkbox"]');
        return {
            wait: (timeout) => getItemByIdBase(id).wait(timeout),
            getLabel: () => getItemByIdBase(id).$('[data-hook="tableListItem-label"]').text(),
            getTooltipContent: () => CheckboxUniDriver(getCheckboxBase(), body).getTooltipContent(),
            isChecked: () => CheckboxUniDriver(getCheckboxBase(), body).isChecked(),
            isDisabled: () => CheckboxUniDriver(getCheckboxBase(), body).isDisabled(),
            click: () => CheckboxUniDriver(getCheckboxBase(), body).click(),
            exists: () => getCheckboxBase().exists(),
        };
    };
    const addNewExists = () => addItem().exists();
    const clickAddNew = () => addItem().click();
    return {
        exists: () => panelBase().exists(),
        isOpen: () => Promise.all([slidingModal().isOpen(), panel().exists()]).then((arr) => arr.every(Boolean)),
        getTitle: () => panel().getTitleText(),
        getSubtitle: () => panel().getSubtitleText(),
        clickCloseButton: () => panel().clickClose(),
        closeButtonExists: () => panel().isCloseButtonExists(),
        checkOptions: async (ids) => {
            for (const id of ids) {
                const checkbox = getCheckboxById(id);
                await checkbox.wait();
                await checkbox.click();
            }
        },
        getCheckboxAt,
        getCheckboxById,
        dragHandleExistsAt: (i) => getDragHandle(getItemAtBase(i)).exists(),
        dragHandleLockedAt: async (i) => (await getDragHandle(getItemAtBase(i))
            .$('[data-hook="drag-handle-button"]')
            .attr('data-disabled')) === 'true',
        _dragHandleTooltipById: (id) => TooltipUniDriver(getItemByIdBase(id).$('[data-hook="tableListItem-dragHandle"]'), body),
        dragStart: async (sourceIndex) => getDragAndDropDriver().dragStart(await getItemAtBase(sourceIndex)),
        dragMove: () => getDragAndDropDriver().dragMove(),
        dragEnd: async (targetIndex) => getDragAndDropDriver().dragEnd(await getItemAtBase(targetIndex)),
        getCheckboxesCount: () => items().count(),
        getTitles: () => items().map((item) => item.$('[data-hook="tableListItem-label"]').text()),
        getCustomColumnInfoIconAt: (index) => InfoIconUniDriver(getItemAtBase(index).$('[data-hook="info-icon"]'), body),
        addNewExists,
        clickAddNew,
        getAddCustomFieldCTAButton: () => addItem(),
        customFieldPopoverMenuAt,
        getCustomFieldOptionsAt: (i) => customFieldPopoverMenuAt(i).getCustomFieldOptionsAt(),
        customFieldPopoverMenuExistsAt: (i) => customFieldPopoverMenuAt(i).exists(),
        _getDragAndDropDriver: getDragAndDropDriver,
        _getItemAtBase: getItemAtBase,
        // Search functionality
        searchExists: () => getSearch().inputDriver.exists(),
        enterSearchText: (value) => getSearch().inputDriver.enterText(value),
        clearSearchText: () => getSearch().inputDriver.clearText(),
        getSearchText: () => getSearch().inputDriver.getText(),
        clickSearchClear: () => getSearch().inputDriver.clickClear(),
        getSearchPlaceholder: () => getSearch().inputDriver.getPlaceholder(),
        // No results functionality
        noResultsExists: () => getNoResults().exists(),
        getNoResultsTitle: () => getNoResults().getTitleText(),
        getNoResultsSubtitle: () => panelBase().$('[data-hook="custom-columns-no-results-subtitle"]').text(),
        getNoResultsResetButton: () => getNoResults().getButton('custom-columns-no-results-reset-button'),
    };
}
//# sourceMappingURL=CustomColumnsPanel.uni.driver.js.map