tabArray.forEach((element) => {
    var significantResults = getSignificanceMatrix(baseArray, element);
    slidesignificance_12_1.push(significantResults);
});

var slideMerged_12_1 = [];

for (let i = 0; i < countryTable.length; i++) {
    let originalRow = countryTable[i];
    let significanceRow = slidesignificance_12_1[i];
    let newRow = [];

    for (let j = 0; j < originalRow.length; j++) {
        let cell = originalRow[j];
        let baseText = typeof cell === 'object' ? cell.text : cell;
        let baseOptions = (typeof cell === 'object' && cell.options) ? cell.options : {};

        let significance = (j === 0) ? "" : ((significanceRow && significanceRow[j - 1]) || "");

        let textParts = [];

        // Check if baseText is a string like "31%A"
        if (typeof baseText === "string") {
            // Match: number%, then letters (e.g., "31%A" or "12%AB")
            const match = baseText.match(/^(\d+%)\s*([A-Za-z]+)?$/);

            if (match) {
                textParts.push({ text: match[1], options: { fontSize: baseOptions.fontSize || 8 } }); // percent
                if (match[2]) {
                    textParts.push({
                        text: match[2],
                        options: { fontSize: 6, superscript: true }
                    }); // superscript letters
                }
            } else {
                // fallback if doesn't match pattern
                textParts.push({ text: baseText, options: { fontSize: baseOptions.fontSize || 8 } });
            }
        } else if (Array.isArray(baseText)) {
            textParts = [...baseText]; // If already in parts
        }

        // If significance exists (from matrix), add as superscript
        if (significance) {
            textParts.push({
                text: significance,
                options: { fontSize: 6, superscript: true }
            });
        }

        newRow.push({
            text: textParts,
            options: {
                ...baseOptions,
                border: [
                    { pt: 0, color: "FFFFFF" },
                    { pt: 0, color: "FFFFFF" },
                    { pt: 0.5, color: "cccccc" },
                    { pt: 0, color: "FFFFFF" }
                ]
            }
        });
    }

    slideMerged_12_1.push(newRow);
}

countryTable = slideMerged_12_1;
