import { FieldSchema, StructureSchema } from '@ephox/boulder';
import { Throttler } from '@ephox/katamari';
import * as Fields from '../../data/Fields';
import * as StreamingState from './StreamingState';
const setup = (streamInfo, streamState) => {
    const sInfo = streamInfo.stream;
    const throttler = Throttler.last(streamInfo.onStream, sInfo.delay);
    streamState.setTimer(throttler);
    return (component, simulatedEvent) => {
        throttler.throttle(component, simulatedEvent);
        if (sInfo.stopEvent) {
            simulatedEvent.stop();
        }
    };
};
export default [
    FieldSchema.requiredOf('stream', StructureSchema.choose('mode', {
        throttle: [
            FieldSchema.required('delay'),
            FieldSchema.defaulted('stopEvent', true),
            Fields.output('streams', {
                setup,
                state: StreamingState.throttle
            })
        ]
    })),
    FieldSchema.defaulted('event', 'input'),
    FieldSchema.option('cancelEvent'),
    Fields.onStrictHandler('onStream')
];
//# sourceMappingURL=StreamingSchema.js.map