var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
class MailService {
    constructor(app) {
        this.app = app;
        this.Api = this.app.Api
            .extend()
            .setEndpoint(this.app.options.authEndpoint || 'mail');
    }
    quota() {
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.Api.get('/', {});
        });
    }
    send(mailingData, category = 'uncategorized', template = null, silent = null) {
        return __awaiter(this, void 0, void 0, function* () {
            return yield this.Api.post('/', {}, { mailingData, category, template, silent });
        });
    }
}

function mail(app) {
    // get the default app
    if (!app) {
        if (!window['$$$SHEETBASE_APPS']) {
            throw new Error('No app for mail component.');
        }
        app = window['$$$SHEETBASE_APPS'].getApp();
    }
    // return the instance
    if (!!app.Mail) {
        return app.Mail;
    }
    else {
        return new MailService(app);
    }
}
window['$$$SHEETBASE_COMPONENTS'].Mail = MailService;

export { MailService as Mail, mail };
//# sourceMappingURL=sheetbase-mail.js.map
