<?php

/* =========================================================
   COMPLETE BLISS - FULL TESTIMONIALS PAGE
========================================================= */

require_once
    __DIR__ .
    '/public-site/data/testimonials.php';


$totalTestimonials =
    count($testimonials);


/* =========================================================
   PAGINATION
========================================================= */

$testimonialsPerPage = 6;

$testimonialPage =
    isset($_GET['page'])
        ? max(1, (int) $_GET['page'])
        : 1;


$totalTestimonialPages =
    $totalTestimonials > 0
        ? (int) ceil(
            $totalTestimonials /
            $testimonialsPerPage
        )
        : 1;


if (
    $testimonialPage >
    $totalTestimonialPages
) {

    $testimonialPage =
        $totalTestimonialPages;

}


$testimonialOffset =
    ($testimonialPage - 1)
    * $testimonialsPerPage;


$currentTestimonials =
    array_slice(
        $testimonials,
        $testimonialOffset,
        $testimonialsPerPage
    );


require_once
    __DIR__ .
    '/public-site/includes/header.php';

require_once
    __DIR__ .
    '/public-site/includes/navbar.php';

?>


<main>


    <!-- =====================================================
         PAGE HERO
    ====================================================== -->

    <section class="cbx-testimonials-page-hero">

        <div class="cbx-container">


            <div class="cbx-testimonials-page-hero-content">


                <a
                    href="index.php#testimonials"
                    class="cbx-testimonials-page-back"
                >

                    <i class="fa-solid fa-arrow-left"></i>

                    Back to Home

                </a>


                <div class="cbx-testimonials-page-tag">

                    <i class="fa-solid fa-comments"></i>

                    MEMBER EXPERIENCES

                </div>


                <h1>

                    Real experiences.

                    <span>
                        Real voices.
                    </span>

                </h1>


                <p>
                    Read genuine feedback shared by people
                    who have experienced Complete Bliss.
                </p>



                <div class="cbx-testimonials-page-stats">


                    <div>

                        <strong>
                            <?= number_format(
                                $totalTestimonials
                            ) ?>
                        </strong>

                        <span>
                            Testimonials
                        </span>

                    </div>


                    <div>

                        <strong>
                            <?= number_format(
                                $totalTestimonialPages
                            ) ?>
                        </strong>

                        <span>
                            Pages
                        </span>

                    </div>


                    <div>

                        <strong>
                            <?= number_format(
                                $testimonialPage
                            ) ?>
                        </strong>

                        <span>
                            Current Page
                        </span>

                    </div>


                </div>


            </div>


        </div>

    </section>



    <!-- =====================================================
         TESTIMONIALS
    ====================================================== -->

    <section class="cbx-testimonials-page-body">

        <div class="cbx-container">


            <?php if (!empty($currentTestimonials)): ?>


                <!-- =========================================
                     TOOLBAR
                ========================================== -->

                <div class="cbx-testimonials-page-toolbar">


                    <div>

                        <span>
                            Showing
                        </span>


                        <strong>

                            <?= number_format(
                                $testimonialOffset + 1
                            ) ?>

                            –

                            <?= number_format(
                                min(
                                    $testimonialOffset
                                    + $testimonialsPerPage,
                                    $totalTestimonials
                                )
                            ) ?>

                        </strong>


                        <span>
                            of
                        </span>


                        <strong>
                            <?= number_format(
                                $totalTestimonials
                            ) ?>
                        </strong>


                        <span>
                            testimonials
                        </span>

                    </div>


                    <div class="cbx-testimonials-page-trust">

                        <i class="fa-solid fa-circle-check"></i>

                        Genuine shared experiences

                    </div>


                </div>



                <!-- =========================================
                     TESTIMONIAL GRID
                ========================================== -->

                <div class="cbx-testimonial-grid cbx-testimonials-full-grid">


                    <?php
                    foreach (
                        $currentTestimonials
                        as $testimonial
                    ):
                    ?>


                        <?php

                        $name =
                            trim(
                                $testimonial['name']
                                ?? 'Complete Bliss Member'
                            );


                        $location =
                            trim(
                                $testimonial['location']
                                ?? ''
                            );


                        $message =
                            trim(
                                $testimonial['message']
                                ?? ''
                            );


                        $rating =
                            max(
                                1,
                                min(
                                    5,
                                    (int)(
                                        $testimonial['rating']
                                        ?? 5
                                    )
                                )
                            );


                        if (
                            function_exists(
                                'mb_substr'
                            )
                        ) {

                            $initial =
                                strtoupper(
                                    mb_substr(
                                        $name,
                                        0,
                                        1
                                    )
                                );

                        } else {

                            $initial =
                                strtoupper(
                                    substr(
                                        $name,
                                        0,
                                        1
                                    )
                                );

                        }

                        ?>


                        <article class="cbx-testimonial-card">


                            <!-- QUOTE -->

                            <div class="cbx-testimonial-quote">

                                <i class="fa-solid fa-quote-left"></i>

                            </div>



                            <!-- STARS -->

                            <div
                                class="cbx-testimonial-stars"
                                aria-label="<?= $rating ?> out of 5 stars"
                            >


                                <?php
                                for (
                                    $star = 1;
                                    $star <= 5;
                                    $star++
                                ):
                                ?>

                                    <i
                                        class="<?= $star <= $rating
                                            ? 'fa-solid'
                                            : 'fa-regular' ?>
                                            fa-star"
                                    ></i>

                                <?php endfor; ?>


                            </div>



                            <!-- MESSAGE -->

                            <blockquote>

                                “<?= htmlspecialchars(
                                    $message
                                ) ?>”

                            </blockquote>



                            <!-- MEMBER -->

                            <div class="cbx-testimonial-member">


                                <div class="cbx-testimonial-avatar">

                                    <?= htmlspecialchars(
                                        $initial
                                    ) ?>

                                </div>


                                <div>

                                    <strong>

                                        <?= htmlspecialchars(
                                            $name
                                        ) ?>

                                    </strong>


                                    <?php if ($location !== ''): ?>

                                        <span>

                                            <i class="fa-solid fa-location-dot"></i>

                                            <?= htmlspecialchars(
                                                $location
                                            ) ?>

                                        </span>

                                    <?php endif; ?>


                                </div>


                                <div class="cbx-testimonial-verified">

                                    <i class="fa-solid fa-circle-check"></i>

                                    <small>
                                        Feedback
                                    </small>

                                </div>


                            </div>


                        </article>


                    <?php endforeach; ?>


                </div>



                <!-- =========================================
                     PAGINATION
                ========================================== -->

                <?php
                if (
                    $totalTestimonialPages > 1
                ):
                ?>


                    <nav
                        class="cbx-testimonial-pagination"
                        aria-label="Testimonials pagination"
                    >


                        <!-- PREVIOUS -->

                        <?php
                        if (
                            $testimonialPage > 1
                        ):
                        ?>

                            <a
                                href="testimonials.php?page=<?= $testimonialPage - 1 ?>"
                                class="cbx-testimonial-page-nav"
                            >

                                <i class="fa-solid fa-arrow-left"></i>

                                Previous

                            </a>

                        <?php else: ?>

                            <span
                                class="cbx-testimonial-page-nav disabled"
                            >

                                <i class="fa-solid fa-arrow-left"></i>

                                Previous

                            </span>

                        <?php endif; ?>



                        <!-- PAGE NUMBERS -->

                        <div class="cbx-testimonial-page-numbers">


                            <?php

                            $testimonialStartPage =
                                max(
                                    1,
                                    $testimonialPage - 2
                                );


                            $testimonialEndPage =
                                min(
                                    $totalTestimonialPages,
                                    $testimonialPage + 2
                                );

                            ?>


                            <?php
                            if (
                                $testimonialStartPage > 1
                            ):
                            ?>


                                <a
                                    href="testimonials.php?page=1"
                                >
                                    1
                                </a>


                                <?php
                                if (
                                    $testimonialStartPage > 2
                                ):
                                ?>

                                    <span>
                                        ...
                                    </span>

                                <?php endif; ?>


                            <?php endif; ?>



                            <?php
                            for (
                                $pageNumber =
                                    $testimonialStartPage;

                                $pageNumber <=
                                    $testimonialEndPage;

                                $pageNumber++
                            ):
                            ?>


                                <a
                                    href="testimonials.php?page=<?= $pageNumber ?>"
                                    class="<?= $pageNumber === $testimonialPage
                                        ? 'active'
                                        : '' ?>"
                                >

                                    <?= $pageNumber ?>

                                </a>


                            <?php endfor; ?>



                            <?php
                            if (
                                $testimonialEndPage <
                                $totalTestimonialPages
                            ):
                            ?>


                                <?php
                                if (
                                    $testimonialEndPage <
                                    $totalTestimonialPages - 1
                                ):
                                ?>

                                    <span>
                                        ...
                                    </span>

                                <?php endif; ?>


                                <a
                                    href="testimonials.php?page=<?= $totalTestimonialPages ?>"
                                >

                                    <?= $totalTestimonialPages ?>

                                </a>


                            <?php endif; ?>


                        </div>



                        <!-- NEXT -->

                        <?php
                        if (
                            $testimonialPage <
                            $totalTestimonialPages
                        ):
                        ?>

                            <a
                                href="testimonials.php?page=<?= $testimonialPage + 1 ?>"
                                class="cbx-testimonial-page-nav"
                            >

                                Next

                                <i class="fa-solid fa-arrow-right"></i>

                            </a>

                        <?php else: ?>

                            <span
                                class="cbx-testimonial-page-nav disabled"
                            >

                                Next

                                <i class="fa-solid fa-arrow-right"></i>

                            </span>

                        <?php endif; ?>


                    </nav>


                <?php endif; ?>



                <!-- =========================================
                     CTA
                ========================================== -->

                <div class="cbx-testimonials-page-cta">


                    <div class="cbx-testimonials-page-cta-icon">

                        <i class="fa-solid fa-heart"></i>

                    </div>


                    <div>

                        <span>
                            READY TO START YOUR OWN JOURNEY?
                        </span>

                        <h2>
                            Join Complete Bliss and work towards
                            something meaningful.
                        </h2>

                    </div>


                    <a href="register.php">

                        Become a Member

                        <i class="fa-solid fa-arrow-right"></i>

                    </a>


                </div>



            <?php else: ?>


                <!-- =========================================
                     EMPTY
                ========================================== -->

                <div class="cbx-testimonials-page-empty">


                    <div>

                        <i class="fa-solid fa-comments"></i>

                    </div>


                    <h2>
                        Member Stories Are Coming
                    </h2>


                    <p>
                        Genuine Complete Bliss testimonials
                        will be displayed here as they become
                        available.
                    </p>


                    <a href="index.php">

                        Return Home

                    </a>


                </div>


            <?php endif; ?>


        </div>

    </section>


</main>


<?php

require_once
    __DIR__ .
    '/public-site/includes/footer.php';

?>