<?= $this->layout('_layout', ['title' => $title]); ?>

<main class="main">
    <?= $this->insert('includes/aside_info') ?>
    <div class="content">
        <div class="h2-title h2-title-content flex-s-c">
            <span>My Account</span>
        </div>

        <?= $this->insert('user/_user'); ?>
        <br>

        <div class="h2-title h2-title-content flex-s-c">
            <span>My Tickets</span>
        </div>

        <div>
            <div class="ticketTitle flex-s-c">
                <div class="ticketTitle-number">
                    Open
                </div>
                <a class="button" href="<?= __redirect("user/ticket/new") ?>">New ticket</a>
            </div>
            <div class="table-row table-scroll">
                <table class="tableTicket">
                    <thead>
                        <tr class="bg-white border-b">
                            <td width="100"><strong>#</strong></td>
                            <td width="300">Subject:</td>
                            <td>Date:</td>
                            <td></td>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        if ($ticket_open) :  $cont = 0;
                            foreach ($ticket_open as $answared) : $cont++; ?>
                                <tr>
                                    <td><strong>.<?= $cont ?></strong></td>
                                    <td><?= $answared->subject ?></td>
                                    <td><?= date('d/m/y H:i', strtotime($answared->date)) ?></td>
                                    <td><a href="<?= __redirect('user/ticket/view/' . $answared->slug) ?>"><span class="message-button">View Message</span></a>
                                    </td>
                                </tr>
                            <?php endforeach;
                        else : ?>
                            <tr>
                                <td class="warning" colspan="4" align="center"> There are no open ticket(s) at this time</td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
        <br>
        <div>
            <div class="ticketTitle flex-s-c">
                <div class="ticketTitle-number">
                    Answared
                </div>
            </div>
            <div class="table-row table-scroll">
                <table class="tableTicket">
                    <thead>
                        <tr class="bg-white border-b">
                            <td width="100"><strong>#</strong></td>
                            <td width="300">Subject:</td>
                            <td>Date:</td>
                            <td></td>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        if ($ticket_answered) :  $cont = 0;
                            foreach ($ticket_answered as $answared) : $cont++; ?>
                                <tr>
                                    <td><strong>.<?= $cont ?></strong></td>
                                    <td><?= $answared->subject ?></td>
                                    <td><?= date('d/m/y H:i', strtotime($answared->date)) ?></td>
                                    <td><a href="<?= __redirect('user/ticket/view/' . $answared->slug) ?>"><span class="message-button">View Message</span></a>
                                    </td>
                                </tr>
                            <?php endforeach;
                        else : ?>
                            <tr>
                                <td class="warning" colspan="4" align="center">There are no ticket(s) answered at this time</td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
        <br>
        <div>
            <div class="ticketTitle flex-s-c">
                <div class="ticketTitle-number">
                    Closed
                </div>
            </div>
            <div class="table-row table-scroll">
                <table class="tableTicket">
                    <thead>
                        <tr class="bg-white border-b">
                            <td width="100"><strong>#</strong></td>
                            <td width="300">Subject:</td>
                            <td>Date:</td>
                            <td></td>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        if ($ticket_closed) :  $cont = 0;
                            foreach ($ticket_closed as $closed) : $cont++; ?>
                                <tr>
                                    <td><strong>.<?= $cont ?></strong></td>
                                    <td><?= $closed->subject ?></td>
                                    <td><?= date('d/m/y H:i', strtotime($closed->date)) ?></td>
                                    <td><a href="<?= __redirect('user/ticket/view/' . $closed->slug) ?>"><span class="message-button">View Message</span></a>
                                    </td>
                                </tr>
                            <?php endforeach;
                        else : ?>
                            <tr>
                                <td class="warning" colspan="4" align="center">There are no closed ticket(s) at this time</td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>

    </div>
</main>