import { Assertions, Chain, FocusTools, Logger, Step, UiFinder, Waiter } from '@ephox/agar';
import { Value } from '@ephox/sugar';
import * as AlloyTriggers from 'ephox/alloy/api/events/AlloyTriggers';
import * as NativeEvents from 'ephox/alloy/api/events/NativeEvents';
export default (doc, gui, typeahead) => {
    const sWaitForMenu = (label) => Logger.t(label, Waiter.sTryUntil('Waiting for menu to appear', UiFinder.sExists(gui.element, '.selected-menu'), 100, 4000));
    const sAssertTextSelection = (label, start, finish) => Logger.t(label + ' sAssertTextSelection', Step.sync(() => {
        const node = typeahead.element.dom;
        Assertions.assertEq(label + ' start cursor', start, node.selectionStart);
        Assertions.assertEq(label + ' finish cursor', finish, node.selectionEnd);
    }));
    const sTriggerInputEvent = (label) => Logger.t(label + ' sTriggerInputEvent', Step.sync(() => {
        AlloyTriggers.emit(typeahead, NativeEvents.input());
    }));
    const sWaitForNoMenu = (label) => Logger.t(label, Waiter.sTryUntil('Waiting for menu to go away', UiFinder.sNotExists(gui.element, '.selected-menu'), 100, 1000));
    const sAssertFocusOnTypeahead = (label) => Logger.t(label, FocusTools.sTryOnSelector('Focus should be on typeahead', doc, 'input'));
    const sAssertValue = (label, expected) => Logger.t(label + ' sAssertValue', Chain.asStep(typeahead.element, [
        Chain.mapper(Value.get),
        Assertions.cAssertEq('Checking value of typeahead', expected)
    ]));
    return {
        sWaitForMenu,
        sWaitForNoMenu,
        sAssertTextSelection,
        sAssertFocusOnTypeahead,
        sTriggerInputEvent,
        sAssertValue
    };
};
//# sourceMappingURL=TestTypeaheadSteps.js.map