<?php

$pageTitle =
    'Liên hệ khách hàng - PET SPA';

$pageStyles = [
    'owner.css'
];

$activeOwnerPage =
    'contacts';


require_once BASE_PATH . '/app/helpers/Status.php';
$statusNames = ['new' => status_label('contact', 'new'), 'reading' => status_label('contact', 'reading'), 'replied' => status_label('contact', 'replied'), 'closed' => status_label('contact', 'closed')];


require BASE_PATH
    . '/app/views/layouts/header.php';

require BASE_PATH
    . '/app/views/layouts/navbar.php';

?>

<main class="owner-area">

<div class="container-fluid">

<div class="row g-4">

<div class="col-xl-2 col-lg-3">

<?php require BASE_PATH
    . '/app/views/layouts/owner-sidebar.php';
?>

</div>


<div class="col-xl-10 col-lg-9">

<div class="owner-page-header">

<div>

<h1>
    Liên hệ
</h1>

<p>
    Tin nhắn khách hàng gửi cho PET SPA.
</p>

</div>

</div>


<section class="owner-card mb-4">

<form
    method="GET"
    class="row g-3"
>

<input
    type="hidden"
    name="url"
    value="owner/contacts"
>


<div class="col-md-7">

<input
    type="text"
    name="search"
    class="form-control"
    placeholder="Tên, điện thoại, email, chủ đề..."
    value="<?= htmlspecialchars(
        $search
    ) ?>"
>

</div>


<div class="col-md-3">

<select
    name="status"
    class="form-select"
>

<option value="">
    Tất cả
</option>

<?php foreach (
    $statusNames
    as $key => $label
): ?>

<option
    value="<?= $key ?>"
    <?= $status === $key
        ? 'selected'
        : ''
    ?>
>
    <?= htmlspecialchars(
        $label
    ) ?>
</option>

<?php endforeach; ?>

</select>

</div>


<div class="col-md-2">

<button class="btn btn-dark w-100">
    Lọc
</button>

</div>

</form>

</section>


<section class="owner-card">

<div class="table-responsive">

<table class="table align-middle owner-table">

<thead>

<tr>
    <th>Khách hàng</th>
    <th>Chủ đề</th>
    <th>Liên hệ</th>
    <th>Trạng thái</th>
    <th>Ngày gửi</th>
    <th></th>
</tr>

</thead>


<tbody>

<?php foreach (
    $contacts
    as $contact
): ?>

<tr>

<td>

<strong>
    <?= htmlspecialchars(
        $contact['full_name']
    ) ?>
</strong>

</td>


<td>

<?= htmlspecialchars(
    $contact['subject']
    ?: 'Không có chủ đề'
) ?>

</td>


<td>

<?= htmlspecialchars(
    $contact['phone']
    ?: $contact['email']
    ?: '-'
) ?>

</td>


<td>

<span
    class="contact-status contact-status-<?= htmlspecialchars(
        $contact['status']
    ) ?>"
>
    <?= htmlspecialchars(
        $statusNames[
            $contact['status']
        ]
    ) ?>
</span>

</td>


<td>

<?= date(
    'd/m/Y H:i',
    strtotime(
        $contact['created_at']
    )
) ?>

</td>


<td>

<a
    href="<?= BASE_URL ?>/?url=owner/contact&id=<?= (int)
        $contact['id']
    ?>"
    class="btn btn-sm btn-light"
>
    Xem
</a>

</td>

</tr>

<?php endforeach; ?>


<?php if (empty($contacts)): ?>

<tr>

<td
    colspan="6"
    class="text-center text-muted py-5"
>
    Chưa có liên hệ.
</td>

</tr>

<?php endif; ?>

</tbody>

</table>

</div>

</section>

</div>

</div>

</div>

</main>


<?php

require BASE_PATH
    . '/app/views/layouts/footer.php';

?>
