<?= $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>Ticket: <?= $ticket_info->subject ?></span>
        </div>

        <div class="_links">
            <a class="button" href="<?= __redirect("user/ticket") ?>">Come back</a>
        </div>
        <div class="chat">
            <div class="chatBlock">
                <div class="chatBlock-ava">
                    <a href="#"><img src="<?= __files('images/ava_1.png') ?>" alt=""></a>
                </div>
                <div class="chatBlock-content">
                    <div class="chatBlock-content_name">
                        <?= $ticket_info->name ?>
                    </div>
                    <div class="chatBlock-content_text">
                        <?php if ($ticket_info->image) : ?>
                            <center>
                                <div class="image">
                                    <img src="<?= __resources('ticket/' . $ticket_info->image) ?>" alt="Imagem Ticket" class="w-max object-contain">
                                </div>
                            </center>
                        <?php endif; ?>
                        <?= $ticket_info->message ?>
                    </div>
                    <div class="chatBlock-content_date">
                        <?= date('d/m/y - H:i', strtotime($ticket_info->date)) ?>
                    </div>
                </div>
            </div>

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


            <div>
                <?php if ($tickets_answered) : foreach ($tickets_answered as $answered) : ?>
                        <?php if ($answered->name != "Suporte") : ?>
                            <div class="chatBlock chatBlock-user">
                                <div class="chatBlock-ava">
                                    <a href="#"><img src="<?= __files('images/ava-popup.png') ?>" alt=""></a>
                                </div>
                                <div class="chatBlock-content">
                                    <div class="chatBlock-content_name">
                                        <?= $answered->name ?>
                                    </div>
                                    <div class="chatBlock-content_text">
                                        <?= $answered->message ?>
                                    </div>
                                    <div class="chatBlock-content_date">
                                        <?= date('d/m/y - H:i', strtotime($answered->date)) ?>
                                    </div>
                                </div>
                            </div>
                        <?php else : ?>
                            <div class="chatBlock">
                                <div class="chatBlock-ava">
                                    <a href="#"><img src="<?= __files('images/ava_1.png') ?>" alt=""></a>
                                </div>
                                <div class="chatBlock-content">
                                    <div class="chatBlock-content_name">
                                        <?= $answered->name ?>
                                    </div>
                                    <div class="chatBlock-content_text">
                                        <?= $answered->message ?>
                                    </div>
                                    <div class="chatBlock-content_date">
                                        <?= date('d/m/y - H:i', strtotime($answered->date)) ?>
                                    </div>
                                </div>
                            </div>
                        <?php endif; ?>
                    <?php endforeach;
                else : ?>
                    <div class="p-1 bg-yellow-300 text-sm rounded-full text-black text-center w-full">Não há respostas no momento</div>
                <?php endif; ?>
            </div>

            <?php if ($ticket_info->status != 2) : ?>
                <form action="<?= __redirect("user/auth/ticket/new/to/respond/{$ticket_info->slug}") ?>" method="post">
                    <?= __csrf(); ?>
                    <input type="hidden" name="id_ticket" value="<?= $ticket_info->id ?>">
                    <div class="chatBlock">
                        <div class="chatBlock-ava">
                            <a href="#"><img src="<?= __files('images/ava_1.png') ?>" alt=""></a>
                        </div>
                        <div class="chatBlock-content">
                            <textarea placeholder="Text message..." name="message" required minlength="10" maxlength="1000"></textarea>
                            <button>Send Message</button>
                        </div>
                    </div>
                </form>
            <?php endif; ?>
        </div>
    </div>
</main>