<!DOCTYPE html>
<html lang="en"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="~{layout}">

<head>
    <title>My Timeline</title>
</head>

<body>
    <div layout:fragment="content">
        <div class="row">
            <div class="col-12">
                <div class="d-flex justify-content-between align-items-center mb-4">
                    <h2>
                        <i class="bi bi-person text-primary"></i>
                        My Timeline
                    </h2>
                    <div class="btn-group" role="group" aria-label="Timeline views">
                        <a th:href="@{/timeline}" class="btn btn-outline-primary">
                            <i class="bi bi-globe"></i> Public
                        </a>
                        <a th:href="@{/timeline/federated}" class="btn btn-outline-primary">
                            <i class="bi bi-people"></i> Following
                        </a>
                        <a th:href="@{/timeline/user}" class="btn btn-primary active">
                            <i class="bi bi-person"></i> My Timeline
                        </a>
                    </div>
                </div>

                <p class="text-muted mb-4">
                    Your fitness activities
                </p>

                <!-- Loading Indicator -->
                <div id="loadingIndicator" class="text-center py-5">
                    <div class="spinner-border text-primary" role="status">
                        <span class="visually-hidden">Loading...</span>
                    </div>
                    <p class="mt-2 text-muted">Loading timeline...</p>
                </div>

                <!-- Error Alert -->
                <div id="errorAlert" class="alert alert-danger d-none" role="alert">
                    <i class="bi bi-exclamation-triangle-fill"></i>
                    <span id="errorMessage"></span>
                </div>

                <!-- Timeline Activities -->
                <div id="timelineList" class="d-none">
                    <!-- Will be populated by JavaScript -->
                </div>

                <!-- Empty State -->
                <div id="emptyState" class="text-center py-5 d-none">
                    <i class="bi bi-inbox" style="font-size: 4rem; color: #d1d5db;"></i>
                    <h4 class="mt-3">No Activities Yet</h4>
                    <p class="text-muted">Upload your first FIT file to get started!</p>
                    <a th:href="@{/activities/upload}" class="btn btn-primary mt-3">
                        <i class="bi bi-cloud-upload"></i> Upload Activity
                    </a>
                </div>

                <!-- Pagination -->
                <nav id="pagination" aria-label="Timeline pagination" class="mt-4 d-none">
                    <ul class="pagination justify-content-center" id="paginationList">
                        <!-- Will be populated by JavaScript -->
                    </ul>
                </nav>
            </div>
        </div>
    </div>

    <!-- Custom Scripts -->
    <th:block layout:fragment="scripts">
        <script th:src="@{/js/timeline.js}"></script>
        <script th:inline="javascript">
            document.addEventListener('DOMContentLoaded', function() {
                // Redirect to login if not authenticated
                if (!FitPubAuth.isAuthenticated()) {
                    window.location.href = '/login';
                    return;
                }

                // Initialize timeline
                FitPubTimeline.init('user');
            });
        </script>
    </th:block>
</body>
</html>
