"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConversationEmbed = exports.SpotterEmbed = void 0;
const tslib_1 = require("tslib");
const isUndefined_1 = tslib_1.__importDefault(require("lodash/isUndefined"));
const errors_1 = require("../errors");
const types_1 = require("../types");
const ts_embed_1 = require("./ts-embed");
const utils_1 = require("../utils");
/**
 * Embed ThoughtSpot AI Conversation.
 * @group Embed components
 * @example
 * ```js
 * const conversation = new SpotterEmbed('#tsEmbed', {
 *   worksheetId: 'worksheetId',
 *   searchOptions: {
 *     searchQuery: 'searchQuery',
 *   },
 * });
 * conversation.render();
 * ```
 * @version SDK: 1.37.0 | ThoughtSpot: 10.9.0.cl
 */
class SpotterEmbed extends ts_embed_1.TsEmbed {
    constructor(container, viewConfig) {
        viewConfig.embedComponentType = 'conversation';
        super(container, viewConfig);
        this.viewConfig = viewConfig;
    }
    getIframeSrc() {
        const { worksheetId, searchOptions, disableSourceSelection, hideSourceSelection, dataPanelV2, showSpotterLimitations, hideSampleQuestions, } = this.viewConfig;
        const path = 'insights/conv-assist';
        if (!worksheetId) {
            this.handleError(errors_1.ERROR_MESSAGE.SPOTTER_EMBED_WORKSHEED_ID_NOT_FOUND);
        }
        const queryParams = this.getBaseQueryParams();
        queryParams[types_1.Param.SpotterEnabled] = true;
        if (!(0, isUndefined_1.default)(disableSourceSelection)) {
            queryParams[types_1.Param.DisableSourceSelection] = !!disableSourceSelection;
        }
        if (!(0, isUndefined_1.default)(hideSourceSelection)) {
            queryParams[types_1.Param.HideSourceSelection] = !!hideSourceSelection;
        }
        if (!(0, isUndefined_1.default)(dataPanelV2)) {
            queryParams[types_1.Param.DataPanelV2Enabled] = !!dataPanelV2;
        }
        if (!(0, isUndefined_1.default)(showSpotterLimitations)) {
            queryParams[types_1.Param.ShowSpotterLimitations] = !!showSpotterLimitations;
        }
        if (!(0, isUndefined_1.default)(hideSampleQuestions)) {
            queryParams[types_1.Param.HideSampleQuestions] = !!hideSampleQuestions;
        }
        let query = '';
        const queryParamsString = (0, utils_1.getQueryParamString)(queryParams, true);
        if (queryParamsString) {
            query = `?${queryParamsString}`;
        }
        const tsPostHashParams = this.getThoughtSpotPostUrlParams({
            worksheet: worksheetId,
            query: (searchOptions === null || searchOptions === void 0 ? void 0 : searchOptions.searchQuery) || '',
        });
        return `${this.getEmbedBasePath(query)}/embed/${path}${tsPostHashParams}`;
    }
    async render() {
        await super.render();
        const src = this.getIframeSrc();
        await this.renderIFrame(src);
        return this;
    }
}
exports.SpotterEmbed = SpotterEmbed;
/**
 * Embed ThoughtSpot AI Conversation.
 * @deprecated from SDK: 1.38.0 | ThoughtSpot: 10.10.0.cl
 * Use {@link SpotterEmbed} instead
 * @group Embed components
 * @example
 * ```js
 * const conversation = new SpotterEmbed('#tsEmbed', {
 *   worksheetId: 'worksheetId',
 *   searchOptions: {
 *     searchQuery: 'searchQuery',
 *   },
 * });
 * conversation.render();
 * ```
 * @version SDK: 1.37.0 | ThoughtSpot: 10.9.0.cl
 */
class ConversationEmbed extends SpotterEmbed {
    constructor(container, viewConfig) {
        viewConfig.embedComponentType = 'conversation';
        super(container, viewConfig);
        this.viewConfig = viewConfig;
    }
}
exports.ConversationEmbed = ConversationEmbed;
//# sourceMappingURL=conversation.js.map