<!DOCTYPE html>
<html lang="ja">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
        <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1/i18n/jquery.ui.datepicker-ja.min.js"></script>
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous" />
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/themes/base/jquery-ui.min.css" />
        <link href="./style.css" rel="stylesheet" />
        <title>伊地知ニジカ放送局 - ニジカ返答ログ</title>
    </head>

    <body>
        <div class="container my-5">
            <div class="accordion mb-5" id="accordion-filter">
                <div class="accordion-item">
                    <h2 class="accordion-header">
                        <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapse-filter" aria-expanded="true" aria-controls="collapse-filter">
                            絞り込み
                        </button>
                    </h2>

                    <div id="collapse-filter" class="accordion-collapse collapse show" data-bs-parent="#accordion-filter">
                        <div class="accordion-body mx-5">
                            <div>
                                <div class="row d-flex align-items-center my-2">
                                    <div class="col-4 fw-bold">
                                        順序
                                    </div>

                                    <div class="col-3 form-check">
                                        <input class="form-check-input" type="radio" name="order" id="order-desc"<?= $asc ? '' : ' checked="checked"' ?> />

                                        <label class="form-check-label" for="order-desc">
                                            新しい順
                                        </label>
                                    </div>

                                    <div class="col-3 form-check">
                                        <input class="form-check-input" type="radio" name="order" id="order-asc"<?= $asc ? ' checked="checked"' : '' ?> />

                                        <label class="form-check-label" for="order-asc">
                                            古い順
                                        </label>
                                    </div>
                                </div>

                                <div class="row d-flex align-items-center my-2">
                                    <div class="col-4 fw-bold">
                                        日時ニジカ
                                    </div>

                                    <div class="col input-group">
                                        <input type="text" class="form-control" placeholder="YYYY-MM-DD" id="filter-date-start"
                                               value="<?= $date_start ?>" />
                                        <span class="input-group-text">〜</span>
                                        <input type="text" class="form-control" placeholder="YYYY-MM-DD" id="filter-date-end"
                                               value="<?= $date_end ?>" />
                                    </div>
                                </div>

                                <div class="row d-flex align-items-center my-2">
                                    <div class="col-4 fw-bold">
                                        フリーワード
                                    </div>

                                    <div class="col">
                                        <input type="text" class="form-control" placeholder="ぬ゛ぅ゛ぅ゛ぅ゛ぅ゛ぅ゛ん゛" id="filter-keyword" 
                                               value="<?= $keyword ?>"/>
                                    </div>
                                </div>
                            </div>

                            <div class="d-grid gap-2 mt-3">
                                <button type="button" class="btn btn-primary" id="btn-filter">絞り込む</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <?php if (count ($log_data) > 0): ?>
                <div class="mb-4">
                    <?php require 'pagination.cmp.php' ?>
                </div>

                <div>
                    <?php foreach (array_slice ($log_data,
                                                ($page - 1) * $length,
                                                $length,
                                                true) as $record): ?>
                        <div class="mb-4">
                            <div>
                                <?= $record['date_time'] ?>
                            </div>

                            <div>
                                <img src="<?= $record['chat_icon'] ?>" />
                                <?= $record['chat_name'] ?>
                            </div>

                            <div style="color: blue">
                                &gt; <span style="font-style: italic"><?= $record['chat_message'] ?></span>
                            </div>

                            <div>
                                <?= $record['answer'] ?>
                            </div>
                        </div>
                    <?php endforeach ?>
                </div>

                <div class="mt-5">
                    <?php require 'pagination.cmp.php' ?>
                </div>
            <?php else: ?>
                何も見つかりませんでしたぬ゛ぅ゛ぅ゛ぅ゛ぅ゛ん゛
            <?php endif ?>
        </div>

        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
        <script src="./script.js" type="text/javascript"></script>
    </body>
</html>

