import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
import CompanyBarChartFinancialTab from "../../../CompanyBarChartFinancialTab";
import CompanyCombinedChartFinancialTab from "../../../CompanyCombinedChartFinancialTab";
import CompanyLineChartFinancialTab from "../../../CompanyLineChartFinancialTab";
import Loader from "../../../Loader";
import "./../style.scss";
const MultiChart = ({ selected, chartDetails, aspectRatio, }) => {
    const renderLoader = () => (_jsx("div", { className: "companyViewFinancialSummary-Loader", children: _jsx(Loader, { height: "32", width: "32" }) }));
    const renderError = () => (_jsx("div", { children: _jsx("span", { className: "companyViewFinancialSummary-DataNA", children: "Not Available" }) }));
    const safeParseFloat = (value) => {
        const parsed = parseFloat(value);
        return isNaN(parsed) ? 0 : parsed;
    };
    const QoQlatestValue = (((1 + safeParseFloat(chartDetails.Revenue.QoQlatest) / 100) *
        (1 + safeParseFloat(chartDetails.earning.QoQlatest) / 100) - 1) * 100).toFixed(2);
    const QoQlatest = QoQlatestValue === "0.00" ? "--" : QoQlatestValue.toString();
    switch (selected) {
        case "Stock Performance":
            return (_jsx(_Fragment, { children: chartDetails.stockPerformanceLoading ? (renderLoader()) : chartDetails.stockPerformanceError ? (renderError()) : (_jsx(CompanyLineChartFinancialTab, { aspectRatio: aspectRatio, beta: chartDetails.stockPerformance.beta, peRatio: chartDetails.stockPerformance.peRatio, ePS: chartDetails.stockPerformance.ePS, priceSales: chartDetails.stockPerformance.priceSales, weekChange: chartDetails.stockPerformance.weekChange, marketCap: chartDetails.stockPerformance.marketCap, stockPerformance: chartDetails.stockPerformance.stockPerformance })) }));
        case "Revenue":
            return (_jsx(_Fragment, { children: chartDetails.revenueAndEarningLoading ? (renderLoader()) : chartDetails.revenueAndEarningError ? (renderError()) : (_jsx(CompanyBarChartFinancialTab, { aspectRatio: aspectRatio, revenues: chartDetails.Revenue.revenues, QoQlatest: chartDetails.Revenue.QoQlatest, QoQ12Month: chartDetails.Revenue.QoQ12Month })) }));
        case "Earnings":
            return (_jsx(_Fragment, { children: chartDetails.revenueAndEarningLoading ? (renderLoader()) : chartDetails.revenueAndEarningError ? (renderError()) : (_jsx(CompanyBarChartFinancialTab, { aspectRatio: aspectRatio, revenues: chartDetails.earning.revenues, QoQlatest: chartDetails.earning.QoQlatest, QoQ12Month: chartDetails.earning.QoQ12Month })) }));
        default:
            return (_jsx(_Fragment, { children: chartDetails.revenueAndEarningLoading ? (renderLoader()) : chartDetails.revenueAndEarningError ? (renderError()) : (_jsx(CompanyCombinedChartFinancialTab, { aspectRatio: aspectRatio, revenues: chartDetails.Revenue.revenues, QoQlatest: QoQlatest, QoQ12Month: chartDetails.Revenue.QoQ12Month || "--", earnings: chartDetails.earning.revenues })) }));
    }
};
export default MultiChart;
