"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.TransactionHeaderView = void 0;
const symbol_sdk_1 = require("symbol-sdk");
class TransactionHeaderView {
    /**
     * Creates an instance of TransactionHeaderView.
     * @param {Transaction} tx
     * @param {Profile} profile
     */
    constructor(tx, profile) {
        this.tx = tx;
        this.profile = profile;
    }
    /**
     * @static
     * @param {Transaction} transaction
     * @param {Profile} profile
     * @returns {ITransactionHeaderView}
     */
    static get(transaction, profile) {
        return new TransactionHeaderView(transaction, profile).render();
    }
    /**
     * @private
     * @returns {ITransactionHeaderView}
     */
    render() {
        var _a, _b, _c, _d;
        return {
            ['Title']: this.title,
            ['Hash']: (_a = this.tx.transactionInfo) === null || _a === void 0 ? void 0 : _a.hash,
            ['Max fee']: this.tx.maxFee.compact().toLocaleString(),
            ['Height (Block)']: (_b = this.tx.transactionInfo) === null || _b === void 0 ? void 0 : _b.height.compact().toLocaleString(),
            ['Index']: (_c = this.tx.transactionInfo) === null || _c === void 0 ? void 0 : _c.index,
            ['Network type']: symbol_sdk_1.NetworkType[this.tx.networkType],
            ['Deadline']: this.formattedDeadline,
            ['Signer']: (_d = this.tx.signer) === null || _d === void 0 ? void 0 : _d.address.pretty(),
        };
    }
    /**
     * Creates a full-width and vertically centered cell with the transaction type
     * @readonly
     * @protected
     * @type {Cell} Table title
     */
    get title() {
        return {
            content: symbol_sdk_1.TransactionType[this.tx.type],
            colSpan: 2,
            hAlign: 'center',
        };
    }
    /**
     * Human readable deadline
     * @readonly
     * @protected
     * @type {string}
     */
    get formattedDeadline() {
        const { deadline } = this.tx;
        if (this.profile) {
            const localDateTime = deadline.toLocalDateTime(this.profile.epochAdjustment);
            return `${localDateTime.toLocalDate()} ${localDateTime.toLocalTime()}`;
        }
        else {
            return deadline.adjustedValue + '';
        }
    }
}
exports.TransactionHeaderView = TransactionHeaderView;
