import { default as WidgetApi } from '../api/WidgetApi';
import { ConfigOptions, WidgetConfig, WidgetResult, WithRequired } from '../types';
/**
* `Widgets` is a factory for creating widgets. It's possible to build your own widgets using the
* {@link WidgetApi} but most people will prefer to use these easy methods.
* @class
*/
export default class Widgets {
/**
* Instance of {@link WidgetApi}
*/
api: WidgetApi;
/**
* Tenant alias of SaaSquatch tenant
*/
tenantAlias: string;
/**
* SaaSquatch domain for API requests
* @default "https://app.referralsaasquatch.com"
*/
domain: string;
/**
* Hosted CDN for npm packages
* @default "https://fast.ssqt.io/npm"
*/
npmCdn: string;
/**
* Initialize a new {@link Widgets} instance.
*
* @param {ConfigOptions} config Config details
*
* @example
Browser example
* var widgets = new squatch.Widgets({tenantAlias:'test_12b5bo1b25125'});
*
* @example Browserify/Webpack example
* var Widgets = require('@saasquatch/squatch-js').Widgets;
* var widgets = new Widgets({tenantAlias:'test_12b5bo1b25125'});
*
* @example Babel+Browserify/Webpack example
* import {Widgets} from '@saasquatch/squatch-js';
* let widgets = new Widgets({tenantAlias:'test_12b5bo1b25125'});
*/
constructor(configin: ConfigOptions);
/**
* This function calls the {@link WidgetApi.upsertUser} method, and it renders
* the widget if it is successful. Otherwise it shows the "error" widget.
*
* @param {Object} config Config details
* @param {Object} config.user The user details
* @param {string} config.user.id The user id
* @param {string} config.user.accountId The user account id
* @param {WidgetType} config.widgetType The content of the widget
* @param {EngagementMedium} config.engagementMedium How to display the widget
* @param {string} config.jwt the JSON Web Token (JWT) that is used to validate the data (can be disabled)
* @param {HTMLElement | string | undefined} config.container Element to load the widget into
* @param {string | undefined} config.trigger Trigger element for opening the popup widget
*
* @return {Promise} json object if true, with a Widget and user details
*/
upsertUser(config: WithRequired): Promise<{
widget: any;
user: any;
}>;
/**
* This function calls the {@link WidgetApi.render} method, and it renders
* the widget if it is successful. Otherwise it shows the "error" widget.
*
* @param {Object} config Config details
* @param {Object} config.user The user details
* @param {string} config.user.id The user id
* @param {string} config.user.accountId The user account id
* @param {WidgetType} config.widgetType The content of the widget
* @param {EngagementMedium} config.engagementMedium How to display the widget
* @param {string} config.jwt the JSON Web Token (JWT) that is used
* to validate the data (can be disabled)
*
* @return {Promise} json object if true, with a Widget and user details
*/
render(config: WidgetConfig): Promise;
/**
* Autofills a referral code into an element when someone has been referred.
* Uses {@link WidgetApi.squatchReferralCookie} behind the scenes.
*
* @param selector Element class/id selector, or a callback function
* @returns
*/
autofill(selector: string | Function): Promise;
/**
* @hidden
* @param {Object} response The json object return from the WidgetApi
* @param {Object} config Config details
* @param {string} config.widgetType The widget type (REFERRER_WIDGET, CONVERSION_WIDGET)
* @param {string} config.engagementMedium (POPUP, EMBED)
* @returns {Widget} widget (PopupWidget or EmbedWidget)
*/
private _renderWidget;
private _renderPopupWidget;
private _renderEmbedWidget;
/**
* @hidden
* @param {Object} error The json object containing the error details
* @param {string} em The engagementMedium
* @returns {void}
*/
private _renderErrorWidget;
/**
* @hidden
* @param {string} rule A regular expression
* @returns {boolean} true if rule matches Url, false otherwise
*/
private static _matchesUrl;
}