/**
 * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.com). All Rights Reserved.
 *
 * This software is the property of WSO2 Inc. and its suppliers, if any.
 * Dissemination of any information or reproduction of any material contained
 * herein in any form is strictly forbidden, unless permitted by WSO2 expressly.
 * You may not alter or remove any copyright or other notice from copies of this content."
 */

import { TestableComponentInterface } from "@wso2is/core/models";
import React, { FunctionComponent, ReactElement } from "react";
import { TryoutWebOIDCComponent } from "./tryout-web-oidc-component";
import { TryoutWebSAMLComponent } from "./tryout-web-saml-component";
import { ApplicationInterface } from "../../../../../features/applications/models";
import { ApplicationTemplatesEnum } from "../application-constants";

/**
 * Proptypes for the TryoutComponentFactory.
 */
interface TryoutComponentFactoryInterface extends TestableComponentInterface {
    application: ApplicationInterface;
    template: string;
}

/**
 * Tryout Component Factory.
 *
 * @param {TryoutComponentFactoryInterface} props - Props injected to the component.
 *
 * @return {React.ReactElement}
 */
export const TryoutComponentFactory: FunctionComponent<TryoutComponentFactoryInterface> = (
    props: TryoutComponentFactoryInterface
): ReactElement => {

    const {
        application,
        template,
        [ "data-testid" ]: testId
    } = props;

    switch (template) {
        case ApplicationTemplatesEnum.OIDC:
            return (
                <TryoutWebOIDCComponent
                    application={ application }
                    data-testid={ testId }
                />
            );
        case ApplicationTemplatesEnum.SAML:
            return (
                <TryoutWebSAMLComponent
                    application={ application }
                    data-testid={ testId }
                />
            );
        default:
            return null;
    }
};

/**
 * Default props for the TryoutComponentFactory.
 */
TryoutComponentFactory.defaultProps = {
    "data-testid": "tryout-component-factory"
};
