@include('components.theme.pages.header')
<section>
    <div class="row mb-4">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header d-flex align-items-center">
                    <h6 class="m-0 font-weight-bold text-primary">Tabel Analisa Alternatif</h6>
                    <a href="{{ app_url('analisa-alternatif-form') }}" class="btn btn-sm btn-primary ml-auto">Kembali</a>
                </div>
                <div class="card-body">
                    <h4 class="mb-3">Matriks Perbandingan Berpasangan</h4>
                    <div class="table-responsive mb-1">
                        <table class="table table-bordered">
                            <thead class="thead-light">
                            <tr>
                                <th class="text-center">Alternatif</th>
                                <?php
                                for ($i = 0; $i <= ($data['n'] - 1); $i++) {
                                    echo "<th class='text-center'>" . getAlternatifNama($i) . "</th>";
                                }
                                ?>
                            </tr>
                            </thead>
                            <tbody>
                            <?php
                            for ($x = 0; $x <= ($data['n'] - 1); $x++) {
                                echo "<tr>";
                                echo "<td class='font-weight-bold'>" . getAlternatifNama($x) . "</td>";
                                for ($y = 0; $y <= ($data['n'] - 1); $y++) {
                                    echo "<td class='text-center'>" . round($data['matrik'][$x][$y], 5) . "</td>";
                                }
                                echo "</tr>";
                            }
                            ?>
                            </tbody>
                            <tfoot class="thead-light">
                            <tr>
                                <th class="text-center">Jumlah</th>
                                <?php
                                for ($i = 0; $i <= ($data['n'] - 1); $i++) {
                                    echo "<th class='text-center'>" . round($data['jmlmpb'][$i], 5) . "</th>";
                                }
                                ?>
                            </tr>
                            </tfoot>
                        </table>
                    </div>

                    <h4 class="mb-3">Matriks Nilai Alternatif</h4>
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead class="thead-light">
                            <tr>
                                <th>Alternatif</th>
                                <?php
                                for ($i = 0; $i <= ($data['n'] - 1); $i++) {
                                    echo "<th class='text-center'>" . getAlternatifNama($i) . "</th>";
                                }
                                ?>
                                <th class="align-middle">Jumlah</th>
                                <th class="text-center">Priority Vector</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php
                            for ($x = 0; $x <= ($data['n'] - 1); $x++) {
                                echo "<tr>";
                                echo "<td class='font-weight-bold'>" . getAlternatifNama($x) . "</td>";
                                for ($y = 0; $y <= ($data['n'] - 1); $y++) {
                                    echo "<td class='text-center'>" . round($data['matrikb'][$x][$y], 5) . "</td>";
                                }
                                echo "<td class='text-center'>" . round($data['jmlmnk'][$x], 5) . "</td>";
                                echo "<td class='text-center'>" . round($data['pv'][$x], 5) . "</td>";
                                echo "</tr>";
                            }
                            ?>
                            </tbody>
                            <tfoot class="thead-light">
                            <tr>
                                <th colspan="<?php echo ($data['n'] + 2) ?>">Principe Eigen Vector (λ maks)</th>
                                <th class="text-center"><?php echo (round($data['eigenVektor'], 5)) ?></th>
                            </tr>
                            <tr>
                                <th colspan="<?php echo ($data['n'] + 2) ?>">Consistency Index</th>
                                <th class="text-center"><?php echo (round($data['consIndex'], 5)) ?></th>
                            </tr>
                            <tr>
                                <th colspan="<?php echo ($data['n'] + 2) ?>">Consistency Ratio</th>
                                <th class="text-center"><?php echo (round(($data['consRatio'] * 100), 2)) ?> %</th>
                            </tr>
                            </tfoot>
                        </table>
                    </div>

                    @if($data['consRatio'] > 0.1)
                        <div class="alert alert-danger alert-dismissible fade show" role="alert">
                            <div><strong>Nilai Consistency Ratio melebihi 10% !!!</strong></div>
                            <div>Mohon input kembali tabel perbandingan...</div>
                            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <a href="javascript:history.back()" class="btn btn-light"><i class="fas fa-chevron-circle-left"></i> Kembali</a>
                    @endif
                </div>
            </div>
        </div>
    </div>
</section>
@include('components.theme.pages.footer')
