import React from 'react';
import type { AppState } from '../types';
interface Step6ConclusionProps {
appState: AppState | null;
t: any;
}
const MatrixTable: React.FC<{ data: { [row: string]: { [col: string]: string } }, title: string }> = ({ data, title }) => {
if (!data || Object.keys(data).length === 0) {
return
No data available for {title}.
;
}
// Robustly get all unique column headers from all rows
const columnSet = new Set();
Object.values(data).forEach(rowData => {
if (rowData && typeof rowData === 'object') {
Object.keys(rowData).forEach(col => columnSet.add(col));
}
});
const columns = Array.from(columnSet).sort();
const rows = Object.keys(data);
return (
{title}
|
{columns.map(col => {col} | )}
{rows.map(row => (
| {row} |
{columns.map(col => {
// Safely access cell data to prevent crashes on malformed data
const cellData = data[row]?.[col] || ' ';
return (
{cellData}
|
);
})}
))}
);
};
type ProductMatrixItem = { product: string; availability: { competitor: string; has_offering: boolean }[] };
type IndustryMatrixItem = { industry: string; availability: { competitor: string; has_offering: boolean }[] };
const transformMatrixData = (matrixData: (ProductMatrixItem[] | IndustryMatrixItem[]) | undefined): { [row: string]: { [col: string]: string } } => {
const tableData: { [row: string]: { [col: string]: string } } = {};
if (!matrixData || !Array.isArray(matrixData) || matrixData.length === 0) {
return tableData;
}
const allCompetitors = new Set();
matrixData.forEach(row => {
if (row && Array.isArray(row.availability)) {
row.availability.forEach(item => {
if (item && typeof item.competitor === 'string') {
allCompetitors.add(item.competitor);
}
});
}
});
const competitorList = Array.from(allCompetitors).sort();
matrixData.forEach(row => {
if (!row) return;
const rowKey = 'product' in row ? row.product : ('industry' in row ? row.industry : undefined);
if (typeof rowKey !== 'string' || !rowKey) {
return;
}
const availabilityMap = new Map();
if (Array.isArray(row.availability)) {
row.availability.forEach(item => {
if (item && typeof item.competitor === 'string') {
availabilityMap.set(item.competitor, item.has_offering);
}
});
}
const rowObject: { [col: string]: string } = {};
competitorList.forEach(competitor => {
rowObject[competitor] = availabilityMap.get(competitor) ? '✓' : ' ';
});
tableData[rowKey] = rowObject;
});
return tableData;
};
const Step6Conclusion: React.FC = ({ appState, t }) => {
if (!appState || !appState.conclusion) return {t.generating}
;
const { conclusion, company } = appState;
const productMatrixForTable = transformMatrixData(conclusion.product_matrix);
const industryMatrixForTable = transformMatrixData(conclusion.industry_matrix);
return (
{t.title}
{t.subtitle}
{t.summary}
{conclusion.summary}
{t.opportunities(company.name)}
{conclusion.opportunities}
{t.nextQuestions}
{(conclusion.next_questions || []).map((q, i) => - {q}
)}
);
};
export default Step6Conclusion;