<?php
$this->load->view('report_pdf/pdf_header');
$show_title = !isset($show_title) ? true : (bool) $show_title;
$show_sign = !isset($show_sign) ? true : (bool) $show_sign;
$report = isset($report) ? $report : array();
$weed_members = isset($weed_members) && is_array($weed_members) ? array_values($weed_members) : array();
$member_count = count($weed_members);
$has_members = $member_count > 0;
$sign_left_html = function_exists('app_weed_out_signatory_left_html') ? app_weed_out_signatory_left_html() : '';
$sign_right_html = function_exists('app_weed_out_signatory_right_html') ? app_weed_out_signatory_right_html() : '';
$has_sign = $show_sign && ($sign_left_html !== '' || $sign_right_html !== '');
?>
<style>
    @page {
        /* Extra bottom room for member boxes + handwritten signature gap + footer names */
        margin: 22px 18px <?php echo $has_members ? '130px' : '62px'; ?> 18px;
    }

    .weed-table {
        width: 100%;
        border-collapse: collapse;
        margin-bottom: <?php echo $has_members ? '140px' : '64px'; ?>;
    }

    /* Member checkboxes — leave clear space below for committee signatures */
    .weed-members {
        position: fixed;
        left: 0;
        right: 0;
        bottom: <?php echo $has_sign ? '95px' : '70px'; ?>;
        width: 100%;
        border-collapse: collapse;
        table-layout: fixed;
    }

    .weed-members td {
        border: none;
        vertical-align: middle;
        padding: 0 8px 0 4px;
        text-align: left;
        font-size: 11px;
        line-height: 1.2;
        font-weight: bold;
        text-transform: uppercase;
    }

    .weed-member-label {
        font-weight: bold;
        font-size: 11px;
        text-transform: uppercase;
        white-space: nowrap;
    }

    .weed-sign {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 18px;
        width: 100%;
        margin-top: 0;
        border-collapse: collapse;
    }

    .weed-sign td {
        border: none;
        vertical-align: top;
        padding: 0;
        font-size: 11px;
        line-height: 1.45;
        font-weight: 600;
    }

    .weed-sign-left {
        text-align: left;
        width: 42%;
    }

    .weed-sign-right {
        text-align: right;
        width: 42%;
    }

    .weed-sign-mid {
        width: 16%;
    }
</style>

<?php if ($show_title) { ?>
<p style="text-align:center;font-size:14px;margin:5px 0;">
    <b>List of publications proposed for weedout on <?php echo date("d/m/Y", strtotime($today)); ?></b>
</p>

<p style="text-align:left;font-size:13px;margin:5px 0;">
    Total Records : <?php echo report_pdf_total_rows($report, isset($pdf_total_rows) ? $pdf_total_rows : null); ?>
</p>
<?php } ?>
<div id="content">
<br>
<table class="weed-table" style="border-collapse: collapse;width:100%;text-align:left;" border="1">
    <tr>
        <th>SNO</th>
        <th>Acc No</th>
        <th>Title</th>
        <th>Author</th>
        <th>Publisher Name</th>
        <th>Publisher Year</th>
        <th>Cost</th>
        <th>Acc Date</th>
        <th>Item Type</th>
    </tr>
    <?php foreach ($report as $row) { ?>
    <tr>
        <td><?php echo htmlspecialchars((string) $row->S_No); ?></td>
        <td><?php echo htmlspecialchars((string) $row->Acc_No); ?></td>
        <td><?php echo htmlspecialchars((string) $row->Title); ?></td>
        <td><?php echo htmlspecialchars((string) $row->Author); ?></td>
        <td><?php echo htmlspecialchars((string) $row->Publisher_Name); ?></td>
        <td><?php echo htmlspecialchars((string) $row->Publisher_Year); ?></td>
        <td><?php echo htmlspecialchars((string) $row->Cost); ?></td>
        <td><?php echo htmlspecialchars((string) $row->Acc_Date); ?></td>
        <td><?php echo htmlspecialchars((string) (isset($row->Item_Type) ? $row->Item_Type : '')); ?></td>
    </tr>
    <?php } ?>
</table>
</div>

<?php if ($has_members) { ?>
<table class="weed-members" width="100%" cellspacing="0" cellpadding="0">
    <tr>
        <?php foreach ($weed_members as $code) {
            $label = strtoupper(trim((string) $code));
            ?>
            <td>
                <span class="weed-member-label"><?php echo htmlspecialchars($label); ?></span>
            </td>
        <?php } ?>
    </tr>
</table>
<?php } ?>

<?php if ($has_sign) { ?>
<table class="weed-sign" width="100%" cellspacing="0" cellpadding="0">
    <tr>
        <td class="weed-sign-left">
            <?php echo $sign_left_html; ?>
        </td>
        <td class="weed-sign-mid">&nbsp;</td>
        <td class="weed-sign-right">
            <?php echo $sign_right_html; ?>
        </td>
    </tr>
</table>
<?php } ?>
