<?php include('include/headscript.php'); ?>
<?php
// Connessione al database e avvio sessione
$conn = new mysqli($servername, $username, $password, $database);

// Verifica connessione
if ($conn->connect_error) {
    die("Errore di connessione: " . $conn->connect_error);
}

// Recupera l'id utente loggato
$iduserlogin = $_SESSION['iduserlogin'];

// Calcolo del numero di immobili
$queryHomes = $conn->prepare("SELECT COUNT(*) AS total_homes FROM home");
$queryHomes->execute();
$resultHomes = $queryHomes->get_result();
$totalHomes = $resultHomes->fetch_assoc()['total_homes'];

// Calcolo del numero di persone
$queryOwners = $conn->prepare("SELECT COUNT(*) AS total_owners FROM property_owners");
$queryOwners->execute();
$resultOwners = $queryOwners->get_result();
$totalOwners = $resultOwners->fetch_assoc()['total_owners'];

// Numero di documenti (placeholder per ora)
// Calcolo del numero di documenti
$queryDocuments = $conn->prepare("
    SELECT COUNT(*) AS total_documents
    FROM doc_storage 
    LEFT JOIN home ON doc_storage.idhome = home.idhome
    WHERE home.iduser = ?
");
$queryDocuments->bind_param('i', $iduserlogin);
$queryDocuments->execute();
$resultDocuments = $queryDocuments->get_result();
$totalDocuments = $resultDocuments->fetch_assoc()['total_documents'];
?>


<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <?php include('include/seo.php'); ?>

    <meta http-equiv="X-UA-Compatible" content="IE=edge" />

    <link rel="shortcut icon" href="assets/images/favicon.ico">

    <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="assets/css/icons.css" rel="stylesheet" type="text/css">
    <link href="assets/css/style.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="https://cdn.materialdesignicons.com/5.4.55/css/materialdesignicons.min.css">

</head>
<style>
    /* Visualizza il pulsante mobile anche su desktop */
    .button-menu-mobile {
        display: inline-block !important;
    }

    /* Nascondi il quadrato rosso con la X su desktop */
    @media (min-width: 992px) {
        .button-menu-mobile {
            background-color: transparent;
            border: none;
            padding: 0;
            width: auto;
            height: auto;
        }

        .button-menu-mobile i.ion-close {
            display: none;
            /* Nasconde la X rossa */
        }

        .button-menu-mobile i.mdi-menu {
            display: inline-block;
            /* Mostra sempre le tre righe orizzontali */
        }
    }

    /* Stile per mobile: Mantieni il comportamento originale */
    @media (max-width: 991.98px) {
        .button-menu-mobile {
            background-color: #ff5e5e;
            /* Questo è il colore rosso originale */
            border-radius: 50%;
            width: 50px;
            height: 50px;
        }

        .button-menu-mobile i.ion-close {
            display: inline-block;
            /* Mostra la X rossa */
        }

        .button-menu-mobile i.mdi-menu {
            display: none;
            /* Nasconde le tre righe quando la barra è aperta */
        }
    }
</style>

<body class="fixed-left">

    <!-- Loader -->
    <div id="preloader">
        <div id="status">
            <div class="spinner"></div>
        </div>
    </div>

    <!-- Begin page -->
    <div id="wrapper">

        <?php include('include/navigationbar.php'); ?>

        <!-- Start right Content here -->

        <div class="content-page">
            <!-- Start content -->
            <div class="content">

                <?php include('include/topbar.php'); ?>

                <div class="page-content-wrapper ">

                    <div class="container-fluid">

                        <div class="row">
                            <div class="col-sm-12">
                                <div class="page-title-box">
                                    <div class="btn-group float-right">
                                        <ol class="breadcrumb hide-phone p-0 m-0">
                                            <li class="breadcrumb-item"><a href="#">CasaDoc</a></li>
                                            <li class="breadcrumb-item active">Dashboard</li>
                                        </ol>
                                    </div>
                                    <h4 class="page-title">Dashboard</h4>
                                </div>
                            </div>
                        </div>
                        <!-- end page title end breadcrumb -->
                        <div class="row">
                            <div class="col-lg-12">
                                <div class="row">
                                    <!-- Statistica: Numero di immobili -->
                                    <div class="col-lg-4">
                                        <div class="card shadow">
                                            <div class="card-body">
                                                <div class="icon-contain">
                                                    <div class="row">
                                                        <div class="col-2 align-self-center">
                                                            <i class="mdi mdi-home-outline" style="font-size: 2.5rem; color: #85c1e9;"></i>
                                                        </div>
                                                        <div class="col-10 text-right">
                                                            <h5 class="mt-0 mb-1"><?php echo $totalHomes; ?></h5>
                                                            <p class="mb-0 font-14" style="color: #5d6d7e;">Immobili inseriti</p>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <!-- Statistica: Numero di persone -->
                                    <div class="col-lg-4">
                                        <div class="card shadow">
                                            <div class="card-body">
                                                <div class="icon-contain">
                                                    <div class="row">
                                                        <div class="col-2 align-self-center">
                                                            <i class="mdi mdi-account-outline" style="font-size: 2.5rem; color: #82e0aa;"></i>
                                                        </div>
                                                        <div class="col-10 text-right">
                                                            <h5 class="mt-0 mb-1"><?php echo $totalOwners; ?></h5>
                                                            <p class="mb-0 font-14" style="color: #5d6d7e;">Proprietari registrati</p>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <!-- Statistica: Numero di documenti -->
                                    <!-- Statistica: Numero di documenti -->
                                    <div class="col-lg-4">
                                        <div class="card shadow">
                                            <div class="card-body">
                                                <div class="icon-contain">
                                                    <div class="row">
                                                        <div class="col-2 align-self-center">
                                                            <i class="mdi mdi-file-outline" style="font-size: 2.5rem; color: #f8c471;"></i>
                                                        </div>
                                                        <div class="col-10 text-right">
                                                            <h5 class="mt-0 mb-1"><?php echo $totalDocuments; ?></h5>
                                                            <p class="mb-0 font-14" style="color: #5d6d7e;">Documenti caricati</p>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>


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



                        <div class="row text-center mt-4">
                            <div class="col-lg-6 col-md-6 mb-4">
                                <a href="page-settings.php" class="btn btn-warning d-flex flex-column justify-content-center align-items-center py-5 shadow rounded-lg">
                                    <i class="mdi mdi-book-outline" style="font-size: 3rem;"></i>
                                    <span class="mt-2 fw-bold" style="font-size: 1.25rem;">Gestione Pagine</span>
                                </a>
                            </div>
                            <div class="col-lg-6 col-md-6 mb-4">
                                <a href="documents-settings.php" class="btn btn-danger d-flex flex-column justify-content-center align-items-center py-5 shadow rounded-lg">
                                    <i class="mdi mdi-file-cog-outline" style="font-size: 3rem;"></i>
                                    <span class="mt-2 fw-bold" style="font-size: 1.25rem;">Gestione Documenti</span>
                                </a>
                            </div>
                        </div>
                        <div class="row text-center mt-4">
                            <div class="col-lg-6 col-md-6 mb-4">
                                <a href="sharing-roles.php" class="btn btn-info d-flex flex-column justify-content-center align-items-center py-5 shadow rounded-lg">
                                    <i class="mdi mdi-book-outline" style="font-size: 3rem;"></i>
                                    <span class="mt-2 fw-bold" style="font-size: 1.25rem;">Ruoli Condivisione</span>
                                </a>
                            </div>
                            <div class="col-lg-6 col-md-6 mb-4">
                                <a href="sections.php" class="btn btn-success d-flex flex-column justify-content-center align-items-center py-5 shadow rounded-lg">
                                    <i class="mdi mdi-file-cog-outline" style="font-size: 3rem;"></i>
                                    <span class="mt-2 fw-bold" style="font-size: 1.25rem;">Sections</span>
                                </a>
                            </div>
                        </div>







                        <!-- end row -->

                    </div><!-- container -->

                </div> <!-- Page content Wrapper -->

            </div> <!-- content -->

            <?php include('include/footer.php'); ?>

        </div>
        <!-- End Right content here -->

    </div>
    <!-- END wrapper -->


    <!-- jQuery  -->
    <script src="assets/js/jquery.min.js"></script>
    <script src="assets/js/popper.min.js"></script>
    <script src="assets/js/bootstrap.min.js"></script>
    <script src="assets/js/modernizr.min.js"></script>
    <script src="assets/js/detect.js"></script>
    <script src="assets/js/fastclick.js"></script>
    <script src="assets/js/jquery.slimscroll.js"></script>
    <script src="assets/js/jquery.blockUI.js"></script>
    <script src="assets/js/waves.js"></script>
    <script src="assets/js/jquery.nicescroll.js"></script>
    <script src="assets/js/jquery.scrollTo.min.js"></script>

    <script src="assets/plugins/chart.js/chart.min.js"></script>
    <script src="assets/pages/dashboard.js"></script>

    <!-- App js -->
    <script src="assets/js/app.js"></script>


</body>

</html>