// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    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) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import React from 'react';
import { parseReactVersion } from './utils';
const reactVersion = React.version;
parseReactVersion(reactVersion);
import { createRoot } from 'react-dom/client';
import { fromFlatCommunicationIdentifier } from "../../acs-ui-common/src";
import { CallComposite, createAzureCommunicationCallAdapter } from "../../react-composites/src/index-public";
import { initializeIcons } from '@fluentui/react';
/**
 * Loader function for the OutboundCallComposite that you can use in your application. This
 * function will load the CallComposite into the provided HTML element to make outbound calls.
 * The best use case for this is in a Node UI framework that is not React based.
 *
 * @public
 */
export const loadOutboundCallComposite = function (loaderArgs, htmlElement) {
    return __awaiter(this, void 0, void 0, function* () {
        var _a;
        initializeIcons();
        const { userId, credential, displayName, targetCallees, callAdapterOptions, callCompositeOptions } = loaderArgs;
        const formattedTargetCallees = typeof targetCallees[0] === 'string' ? targetCallees.map((callee) => {
            return fromFlatCommunicationIdentifier(callee);
        }) : undefined;
        const adapter = yield createAzureCommunicationCallAdapter({
            userId,
            displayName: displayName !== null && displayName !== void 0 ? displayName : 'anonymous',
            credential,
            targetCallees: (_a = formattedTargetCallees) !== null && _a !== void 0 ? _a : targetCallees,
            options: callAdapterOptions
        });
        if (!htmlElement) {
            throw new Error('Failed to find the root element');
        }
        createRoot(htmlElement).render(React.createElement(CallComposite, {
            options: callCompositeOptions,
            adapter
        }, null));
        return adapter;
    });
};
//# sourceMappingURL=outboundCallCompositeLoader.js.map