import * as React from 'react';
import { AgGridModulesDocsLink } from '../Utilities/Constants/DocumentationLinkConstants';
import { AdaptableLogger } from './AdaptableLogger';
import { AdaptableAgGrid } from './AdaptableAgGrid';
import { getDefaultAdaptableOptions } from '../AdaptableOptions/DefaultAdaptableOptions';
import { renderReactRoot as defaultRenderReactRoot } from '../renderReactRoot';
import AdaptableWizardView from '../View/AdaptableWizardView';
export class Adaptable {
    /**
     * Initializer for Adaptable
     *
     * @param adaptableOptions the AdaptableOptions
     * @param agGridConfig AG Grid
     * @returns a Promise containing the AdaptableAPI object in order to enable run-time access to Adaptable's properties and functions
     */
    static init(adaptableOptions, agGridConfig) {
        if (!agGridConfig?.modules?.length) {
            AdaptableLogger.consoleErrorBase(`No AG Grid modules were provided, thus limiting AdapTables features significantly!\n\nRead further info here:${AgGridModulesDocsLink}`);
        }
        return AdaptableAgGrid._initInternal({ ...agGridConfig, adaptableOptions, variant: 'vanilla' });
    }
}
export class AdaptableNoCodeWizard {
    init;
    adaptableOptions;
    extraOptions;
    agGridModules;
    /**
     * @param adaptableOptions
     */
    constructor(adaptableOptions, extraOptions = {}, agGridOptions) {
        const defaultInit = async ({ gridOptions, adaptableOptions, agGridModules, }) => {
            return await Adaptable.init(adaptableOptions, { gridOptions, modules: agGridModules });
        };
        this.adaptableOptions = adaptableOptions;
        this.init = extraOptions.onInit || defaultInit;
        this.extraOptions = extraOptions;
        this.agGridModules = [];
        this.render();
    }
    render(container) {
        let id = getDefaultAdaptableOptions().containerOptions.adaptableContainer || 'adaptable';
        if (!container) {
            let containerOptionsContainer = this.adaptableOptions.containerOptions?.adaptableContainer;
            if (containerOptionsContainer) {
                if (typeof containerOptionsContainer === 'string') {
                    id = containerOptionsContainer ?? id;
                }
                else {
                    container = containerOptionsContainer;
                }
            }
        }
        container = container || document.getElementById(id);
        if (!container) {
            throw new Error('Cannot find container in which to render Adaptable No Code Wizard');
        }
        // this allows people to customize the wizard dimensions & styling
        // when it's visible
        container.classList.add('adaptable--in-wizard');
        const unmount = defaultRenderReactRoot(React.createElement(AdaptableWizardView, {
            adaptableOptions: this.adaptableOptions,
            ...this.extraOptions,
            onInit: (adaptableOptions, gridOptions) => {
                container.classList.remove('adaptable--in-wizard');
                unmount();
                this.init({
                    adaptableOptions,
                    gridOptions: gridOptions,
                    agGridModules: [...this.agGridModules],
                });
            },
        }), container);
    }
}
