<?php
$this->load->helper('report');
if (!function_exists('app_font_pdf')) {
    $CI =& get_instance();
    $CI->load->helper('settings');
}
$pdf_font = app_font_pdf();
$today_display = isset($today) ? $today : date('d-m-Y');
if (preg_match('/^\d{4}-\d{2}-\d{2}/', (string) $today_display)) {
    $today_display = date('d-m-Y', strtotime($today_display));
}
$rows = isset($report) && is_array($report) ? $report : array();
$patron_photo = isset($patron_photo) ? (string) $patron_photo : '';
$this->load->view('report_pdf/pdf_header');
?>
<style>
    @page {
        margin: 24px 28px 28px 28px;
    }

    .ndc-sheet {
        font-family: '<?php echo htmlspecialchars($pdf_font); ?>', DejaVu Sans, Arial, sans-serif;
        color: #1a1a1a;
        width: 100%;
        box-sizing: border-box;
        margin: 18px 0 0 0;
        padding: 0;
    }

    .ndc-frame {
        border: 1.5px solid #2c3e50;
        padding: 22px 26px 28px;
        box-sizing: border-box;
        min-height: 380px;
    }

    .ndc-top {
        width: 100%;
        border-collapse: collapse;
        margin: 0 0 6px 0;
        table-layout: fixed;
    }

    .ndc-top td {
        border: none;
        vertical-align: top;
        padding: 0;
    }

    .ndc-photo-cell {
        text-align: right;
        width: 110px;
    }

    .ndc-photo {
        width: 88px;
        height: 108px;
        border: 1px solid #555;
        display: inline-block;
    }

    .ndc-photo-box {
        width: 88px;
        height: 108px;
        border: 1px solid #bbb;
        display: inline-block;
        background: #f7f7f7;
    }

    .ndc-org {
        text-align: center;
        font-size: 15px;
        font-weight: bold;
        letter-spacing: 1px;
        text-transform: uppercase;
        margin: 10px 0 4px 0;
        color: #1b2a41;
    }

    .ndc-rule {
        width: 46%;
        margin: 0 auto 14px auto;
        border: none;
        border-top: 1px solid #2c3e50;
        height: 0;
    }

    .ndc-title {
        text-align: center;
        font-size: 16px;
        font-weight: bold;
        text-transform: uppercase;
        letter-spacing: 0.8px;
        margin: 0 0 18px 0;
        text-decoration: underline;
    }

    .ndc-date-line {
        text-align: right;
        font-size: 12px;
        margin: 0 0 22px 0;
        color: #222;
    }

    .ndc-body {
        font-size: 13px;
        line-height: 1.85;
        text-align: justify;
        margin: 0 8px 0 8px;
    }

    .ndc-name {
        font-weight: bold;
        font-style: italic;
        text-decoration: underline;
        padding: 0 2px;
    }

    .ndc-sign-block {
        width: 100%;
        border-collapse: collapse;
        margin-top: 70px;
        table-layout: fixed;
    }

    .ndc-sign-block td {
        border: none;
        padding: 0;
        vertical-align: bottom;
    }

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

    .ndc-sign-line {
        border: none;
        border-top: 1px solid #333;
        width: 78%;
        margin: 0 auto 6px auto;
        height: 0;
    }

    .ndc-sign-label {
        font-size: 12px;
        font-weight: bold;
        line-height: 1.4;
    }
</style>

<?php foreach ($rows as $row) {
    $row = is_array($row) ? $row : (array) $row;
    $name = '';
    if (isset($row['Name']) && trim((string) $row['Name']) !== '') {
        $name = trim((string) $row['Name']);
    } elseif (isset($row['name']) && trim((string) $row['name']) !== '') {
        $name = trim((string) $row['name']);
    }

    $designation = '';
    if (isset($row['Designation']) && trim((string) $row['Designation']) !== '') {
        $designation = trim((string) $row['Designation']);
    } elseif (isset($row['designation']) && trim((string) $row['designation']) !== '') {
        $designation = trim((string) $row['designation']);
    }

    $name_design = $name;
    if ($designation !== '') {
        $name_design = $name !== '' ? ($name . ', ' . $designation) : $designation;
    }
    if ($name_design === '') {
        $name_design = '________________';
    }
?>
<div class="ndc-sheet">
    <div class="ndc-frame">
        <table class="ndc-top" width="100%" cellspacing="0" cellpadding="0">
            <tr>
                <td style="width:auto;">&nbsp;</td>
                <td class="ndc-photo-cell">
                    <?php if ($patron_photo !== '') { ?>
                        <img class="ndc-photo" src="<?php echo htmlspecialchars($patron_photo, ENT_QUOTES, 'UTF-8'); ?>" alt="Patron photo">
                    <?php } else { ?>
                        <span class="ndc-photo-box">&nbsp;</span>
                    <?php } ?>
                </td>
            </tr>
        </table>

        <!-- <p class="ndc-org">Knowledge Resource Centre</p> -->
        <!-- <hr class="ndc-rule"> -->
        <p class="ndc-title">No Dues Certificate</p>
        <p class="ndc-date-line">Date: <?php echo htmlspecialchars((string) $today_display); ?></p>

        <p class="ndc-body">
            This is to certify that Smt./Shri.
            <span class="ndc-name"><?php echo htmlspecialchars($name_design); ?></span>
            has <strong>NIL</strong> publications due in his/her account.
        </p>

        <table class="ndc-sign-block" width="100%" cellspacing="0" cellpadding="0">
            <tr>
                <td style="width:58%;">&nbsp;</td>
                <td class="ndc-sign-right">
                    <hr class="ndc-sign-line">
                    <div class="ndc-sign-label">Circulation Section</div>
                </td>
            </tr>
        </table>
    </div>
</div>
<?php } ?>
