﻿import { widgetName, widgetDisplayName, widgetCategory } from "./constants";
import { defaultCustomFilterStartTime, defaultCustomFilterEndTime, defaultPageSize } from "./constants";
import { IWidgetOrder, IWidgetHandler } from "@paperbits/common/editing";
import { ReportsByApiModel } from "./reportsByApiModel";

/**
 * Handlers giving the editor required context to manupulate the widget. For example,
 * it describes how the widget gets created, how it responds to drag'n'drop events,
 * what contextual commands is supports, etc.
 */
export class ReportsByApiHandlers implements IWidgetHandler {
    /**
     * This method invoked when the widget gets added to the content.
     */
    public async getWidgetOrder(): Promise<IWidgetOrder> {
        const widgetOrder: IWidgetOrder = {
            name: widgetName,
            category: widgetCategory,
            requires: [],
            displayName: widgetDisplayName,
            iconClass: "paperbits-puzzle-10",

            /**
             * This method invoked when the widget gets added to the content.
             */
            createModel: async () => { 
                const model = new ReportsByApiModel();
                model.pageSize = defaultPageSize;
                model.customFilterStartTime = defaultCustomFilterStartTime;
                model.customFilterEndTime = defaultCustomFilterEndTime;
                return model;
            }
        };

        return widgetOrder;
    }
}