<?php
session_start(['gc_maxlifetime' => 14400, 'cookie_httponly' => true]);
ob_start();
include('member_session.php');
include('../coach/includes/TCPDF/tcpdf.php');

$member_id = $_SESSION['memberid'] ?? 0;

$file = $_POST['file'] ?? $_GET['file'] ?? "";
$type = $_POST['type'] ?? $_GET['type'] ?? "";

if ($type === 'print_baseline') {

    include '../coach/objects/baseline_bodycomposition.class.php';
    include '../coach/objects/baseline_measurement.class.php';
    include '../coach/objects/baseline_screen.class.php';

    $body_composition = new Baseline_bodycomposition();
    $measurement = new Baseline_measurement();
    $screen = new Baseline_screen();

    // safer param
    $member_id = (int)$member_id;
    $param = [["member_id = $member_id"]];

    $body_comp_list = $body_composition->GetList($param, 'baseline_bodycompositionid', false);
    $measurement_list = $measurement->GetList($param, 'baseline_measurementid', false);
    $screen_list = $screen->GetList($param, 'baseline_screenid', false);

    class MYPDF extends TCPDF {}

    include '../coach/includes/pdf_files/baseline_pdf.php';

} elseif ($type === 'print_goals') {

    include '../coach/objects/goals.class.php';

    $goals = new Goals();

    $member_id = (int)$member_id;
    $param = [["member_id = $member_id"]];

    $goal_list = $goals->GetList($param, 'goalsid', false);

    class MYPDF extends TCPDF {}

    include '../coach/includes/pdf_files/goals_pdf.php';

} else {
    include('member-header.php');
}
?>

<style>
    .success { background-color: #ccffcc; }

    #daily_log_id { width: 75%; margin: 5px 0px 52px 0px; }

    .success {
        background-color: #4592e0;
        height: 25px;
        text-align: center;
        color: #ffffff;
    }

    #accountability_chart_form label.error { color: red; }

    #thd {
        text-align: center;
        font-weight: bold;
    }

    td {
        padding: 10px 15px;
    }

    .text-center {
        text-align: center;
    }

    .text-upper {
        text-transform: uppercase;
    }

    .mandatory {
        color: red;
        font-size: 14px;
    }

    .btn {
        background-color: #c0c0c0;
    }

    @media (max-width: 768px) {
        #daily_log_id {
            width: 90%;
            margin: 5px 0px 52px 0px;
        }
    }
</style>



<?php if (!empty($remoteClient) && $remoteClient == 1 && !empty($remote_client) && in_array("baseline_details_list", $remote_client)) { ?>
    <script>
        window.location.href = "member_homepage.php";
    </script>
<?php } ?>

    <!-- Mobile Top Bar (logo centered) -->
    <div class="mobile-top-bar">
        <img src="./assets/images/logo.png" alt="Brand Logo">
    </div>

    <div class="app-layout">
        <!-- Desktop Sidebar -->
        <?php include('menu.php'); ?>

        <!-- Main Content -->
        <main class="main-content">
            <!-- Page Header -->
            <header class="page-header">
                <div class="page-header-meta">
                    <div>
                        <h1 class="page-header-title">Baselines</h1>
                        <p class="page-header-subtitle">View baseline metrics and goals</p>
                    </div>
                </div>
            </header>

            <div class="body-content">

                <!-- Body Content -->
                <div class="tp-cards-grid">

                    <!-- Baselines -->
                    <div class="link-card link-card-doc">
                        <div class="link-card-icon">
                            <svg width="40" height="40" viewBox="0 0 40 40" fill="none"
                                xmlns="http://www.w3.org/2000/svg">
                                <path
                                    d="M9.99996 36.6666C9.1159 36.6666 8.26806 36.3154 7.64294 35.6903C7.01782 35.0652 6.66663 34.2173 6.66663 33.3333V6.66659C6.66663 5.78254 7.01782 4.93469 7.64294 4.30957C8.26806 3.68445 9.1159 3.33326 9.99996 3.33326H23.3333C23.8609 3.3324 24.3834 3.43593 24.8708 3.63787C25.3583 3.83982 25.8009 4.13619 26.1733 4.50992L32.1533 10.4899C32.528 10.8624 32.8252 11.3055 33.0278 11.7935C33.2303 12.2816 33.3342 12.8049 33.3333 13.3333V33.3333C33.3333 34.2173 32.9821 35.0652 32.357 35.6903C31.7319 36.3154 30.884 36.6666 30 36.6666H9.99996Z"
                                    stroke="black" stroke-width="1.33333" stroke-linecap="round"
                                    stroke-linejoin="round" />
                                <path
                                    d="M23.3334 3.33325V11.6666C23.3334 12.1086 23.509 12.5325 23.8215 12.8451C24.1341 13.1577 24.558 13.3333 25 13.3333H33.3334"
                                    stroke="black" stroke-width="1.33333" stroke-linecap="round"
                                    stroke-linejoin="round" />
                                <path d="M13.3334 21.6667H16.6667" stroke="black" stroke-width="1.33333"
                                    stroke-linecap="round" stroke-linejoin="round" />
                                <path d="M23.3334 21.6667H26.6667" stroke="black" stroke-width="1.33333"
                                    stroke-linecap="round" stroke-linejoin="round" />
                                <path d="M13.3334 28.3333H16.6667" stroke="black" stroke-width="1.33333"
                                    stroke-linecap="round" stroke-linejoin="round" />
                                <path d="M23.3334 28.3333H26.6667" stroke="black" stroke-width="1.33333"
                                    stroke-linecap="round" stroke-linejoin="round" />
                            </svg>
                        </div>
                        <div class="link-card-content">
                            <h3 class="link-card-title">Baselines</h3>
                            <p class="link-card-desc">View your baseline data</p>
                        </div>
                        <div class="link-card-doc-actions">
                            <a href="member_baseline_details_list.php?type=print_baseline&member_id=<?php echo htmlspecialchars($member_id); ?>&file=baseline_pdf_print"
                               target="_blank" class="doc-btn doc-btn-view" title="View PDF">
                                <i class="fa fa-eye"></i><span>View</span>
                            </a>
                            <a href="member_baseline_details_list.php?type=print_baseline&member_id=<?php echo htmlspecialchars($member_id); ?>&file=baseline_pdf"
                               target="_blank" class="doc-btn doc-btn-download" title="Download PDF">
                                <i class="fa fa-download"></i><span>Download</span>
                            </a>
                        </div>
                    </div>

                    <!-- Goals -->
                    <div class="link-card link-card-doc">
                        <div class="link-card-icon">
                            <svg width="40" height="40" viewBox="0 0 40 40" fill="none"
                                xmlns="http://www.w3.org/2000/svg">
                                <path
                                    d="M20 36.6666C29.2047 36.6666 36.6666 29.2047 36.6666 19.9999C36.6666 10.7952 29.2047 3.33325 20 3.33325C10.7952 3.33325 3.33331 10.7952 3.33331 19.9999C3.33331 29.2047 10.7952 36.6666 20 36.6666Z"
                                    stroke="black" stroke-width="1.33333" stroke-linecap="round"
                                    stroke-linejoin="round" />
                                <path
                                    d="M20 30C25.5228 30 30 25.5228 30 20C30 14.4772 25.5228 10 20 10C14.4772 10 10 14.4772 10 20C10 25.5228 14.4772 30 20 30Z"
                                    stroke="black" stroke-width="1.33333" stroke-linecap="round"
                                    stroke-linejoin="round" />
                                <path
                                    d="M20 23.3334C21.841 23.3334 23.3334 21.841 23.3334 20.0001C23.3334 18.1591 21.841 16.6667 20 16.6667C18.1591 16.6667 16.6667 18.1591 16.6667 20.0001C16.6667 21.841 18.1591 23.3334 20 23.3334Z"
                                    stroke="black" stroke-width="1.33333" stroke-linecap="round"
                                    stroke-linejoin="round" />
                            </svg>
                        </div>
                        <div class="link-card-content">
                            <h3 class="link-card-title">Goals</h3>
                            <p class="link-card-desc">View your goals and targets</p>
                        </div>
                        <div class="link-card-doc-actions">
                            <a href="member_baseline_details_list.php?type=print_goals&member_id=<?php echo htmlspecialchars($member_id); ?>&file=goals_pdf_print"
                               target="_blank" class="doc-btn doc-btn-view" title="View PDF">
                                <i class="fa fa-eye"></i><span>View</span>
                            </a>
                            <a href="member_baseline_details_list.php?type=print_goals&member_id=<?php echo htmlspecialchars($member_id); ?>&file=goals_pdf"
                               target="_blank" class="doc-btn doc-btn-download" title="Download PDF">
                                <i class="fa fa-download"></i><span>Download</span>
                            </a>
                        </div>
                    </div>

                </div>

            </div>
        </main>
    </div>

    <!-- Mobile Bottom Navigation -->
    <div id="mobile-nav-placeholder"></div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
    <script src="./js/layout.js"></script>

<?php
include('member-footer.php');
?>