<?php
date_default_timezone_set("Asia/Jakarta");
?>
<style>
    .trSelect {
        cursor: pointer;
    }
</style>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            Data Rekam Medis
            <small>Klinik</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li class="active">Berkas</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <!-- riki -->
        <div class="box box-primary">
            <div class="box-header with-border">
                <h3 class="box-title">Pencarian CPPT dengan MR <u><?= $_GET['mr']; ?></u></h3>
                <div class="box-tools pull-right">
                    <button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
                    <button class="btn btn-box-tool" data-widget="remove"><i class="fa fa-remove"></i></button>
                </div>
            </div><!-- /.box-header -->
            <div class="box-body">
                <table id="example1" class="table table-striped table-bordered table-hover">
                    <thead>
                        <tr>
                            <th>No.</th>
                            <th>No.MR</th>
                            <th>Nama</th>
                            <th>Tanggal CPPT Terbit</th>
                            <th>Keterangan</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $no = 1;
                        foreach ($cppt as $data) :
                        ?>
                            <tr class="trSelect" data-href="<?= base_url('rekamMedis/detailBerkasCppt/' . $data['IdHeader']); ?>">
                                <td><?= $no++; ?>.</td>
                                <td><?= $data['PatientCode']; ?></td>
                                <td><?= $data['FirstName']; ?></td>
                                <td><?= date('d F Y', strtotime($data['DateHeader'])); ?></td>
                                <td>
                                    <?php
                                    if ($data['Note'] == '1') {
                                        echo "Berjalan";
                                    } else {
                                        echo "Selesai";
                                    }
                                    ?>
                                </td>
                            </tr>
                        <?php
                        endforeach;
                        ?>
                    </tbody>
                </table>
            </div><!-- /.box-body -->
            <div class="box-footer">
                <small>Daftar Pasien <?= date('d F Y'); ?> - @Klinik <?= date('Y'); ?></small>
            </div>
        </div><!-- /.box -->

    </section><!-- /.content -->
</div><!-- /.content-wrapper -->

<script>
    document.addEventListener("DOMContentLoaded", () => {
        const rows = document.querySelectorAll("tr[data-href]");
        rows.forEach(row => {
            row.addEventListener("click", () => {
                window.location.href = row.dataset.href;
            });
        });
    });
</script>