"use strict";
/*
 *
 * Copyright 2018-present NEM
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.AggregateView = void 0;
const symbol_sdk_1 = require("symbol-sdk");
const transactionDetailView_factory_1 = require("../transactionDetailView.factory");
class AggregateView {
    /**
     * Creates an instance of AggregateView.
     * @param {AggregateTransaction} tx
     */
    constructor(tx) {
        this.tx = tx;
    }
    /**
     * Gets the view of an inner transaction
     * @protected
     * @returns {CellRecord}
     */
    getInnerTransactionViews() {
        const innerTransactionsViews = this.tx.innerTransactions.map((transaction) => (0, transactionDetailView_factory_1.transactionDetailViewFactory)(transaction));
        this.numberOfInnerTx = innerTransactionsViews.length;
        return {
            ...innerTransactionsViews.reduce((acc, view, index) => ({
                ...acc,
                [`title${index}`]: this.getInnerTransactionTitle(index),
                ...this.getPrefixedInnerTransactionView(view, index),
            }), {}),
        };
    }
    /**
     * Returns a full-width horizontally centered cell
     * With the inner transaction type and its position in the aggregate transaction
     * @private
     * @param {number} index
     * @returns {Cell}
     */
    getInnerTransactionTitle(index) {
        const txType = symbol_sdk_1.TransactionType[this.tx.innerTransactions[index].type];
        return {
            content: `Inner transaction ${index + 1} of ${this.numberOfInnerTx} - ${txType}`,
            colSpan: 2,
            hAlign: 'center',
        };
    }
    /**
     * Prefixes each CellRecord key of the inner transaction view
     * With its position in the aggregate transaction
     * @private
     * @param {CellRecord} view
     * @param {number} index
     * @returns {CellRecord}
     */
    getPrefixedInnerTransactionView(view, index) {
        return Object.entries(view)
            .map(([label, value]) => ({
            [`[Inner tx. ${index + 1} of ${this.numberOfInnerTx}] ${label}`]: value,
        }))
            .reduce((acc, item) => ({ ...acc, ...item }));
    }
}
exports.AggregateView = AggregateView;
