"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RefreshControlHelper = (Cloudwise, Logger) => {
    return {
        attachToRender(refreshControl) {
            if (refreshControl.render !== undefined) {
                const renderOrig = refreshControl.render.bind(refreshControl);
                refreshControl.render = () => {
                    return this.renderRefreshControl(renderOrig);
                };
            }
        },
        renderRefreshControl(renderOrig) {
            let refreshControlRender = renderOrig();
            if (refreshControlRender && refreshControlRender.props && refreshControlRender.props.onRefresh) {
                return Object.assign(Object.assign({}, refreshControlRender), { props: Object.assign(Object.assign({}, refreshControlRender.props), { onRefresh: () => {
                            this.onRefresh(refreshControlRender);
                        } }) });
            }
            else {
                return refreshControlRender;
            }
        },
        onRefresh(refreshControl) {
            Logger.log("Enter Action - Swipe To Refresh");
            let action = Cloudwise.enterAction("Swipe to Refesh");
            if (refreshControl.props.onRefresh !== undefined) {
                refreshControl.props.onRefresh();
            }
            action.leaveAction();
        }
    };
};
