<?php 
    $data = array();
    $data['title'] = "Site ErişimRaporu | ".$App->title;
    $data['links'] = [];
    $data['styles'] = ['/admin/public/assets/css/jstable.css'];
    $data['header']['scripts'] = [];
    $data['version'] = $App->version;
    $data['csrf_token'] = $csrf_generator->create();
    $data['sidebar_menu'] = $menu->get(array('position'=>'sidebar'));
    $data['sidebar_active_menu'] = $menu->getActiveMenuItemId(trim($_SERVER['REQUEST_URI']));
    $data['footer']['scripts'] = ['/admin/public/assets/js/jstable.min.js'];
    $menu_items = $menu->get(array('position'=>'footer'));
    foreach($menu_items as $item){
        if($item['col'] == "1"){
            $data['menu']['footer']["1"][] = $item;
        }
        if($item['col'] == "2"){
            $data['menu']['footer']["2"][] = $item;
        }
        if($item['col'] == "3"){
            $data['menu']['footer']["3"][] = $item;
        }
        if($item['col'] == "4"){
            $data['menu']['footer']["4"][] = $item;
        }
    }

    $data['breadcrumbs'] = array();
    $data['breadcrumbs'][] = array(
        'text' => "Pano",
        'href' => "/admin",
        'index' => 1
    );
    $data['breadcrumbs'][] = array(
        'text' => "Site Analitikleri",
        'href' => "/admin/analytics/views",
        'index' => 2
    );
    
    $googleDataApi  	  = new GoogleDataApi();
    $report               = $googleDataApi->getViewReport();
?>
<?php include DIR_VIEWS."parts/header.php"; ?>
        <main class="content">
            <div class="container-fluid">
                <div class="card">
                    <div class="card-header">
                        <h5 class="card-title">Erişim Raporu</h5>
                    </div>
                    <div class="table-responsive">
                        <table class="table table-striped table-hover table-bordered mb-0" id="views-table">
                            <thead>
                                <tr>
                                    <th>Adres</th>
                                    <th>Görüntüleme</th>
                                    <th>Kullanıcı</th>
                                    <th>Yeni Ziyaretçi</th>
                                    <th data-bs-toggle="tooltip" title="Kullanıcı Başına Görüntüleme">VPU</th>
                                    <th data-bs-toggle="tooltip" title="Ortalama Etkileşim Süresi">AET</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                    if(count($report)>0) {
                                        foreach($report as $row) {
                                            echo "<tr>
                                                        <td><a href=\"".$row['unifiedPageScreen']."\" target=\"_blank\">".$row['unifiedScreenName']."</a></td>
                                                        <td>".$row['screenPageViews']."</td>
                                                        <td>".$row['totalUsers']."</td>
                                                        <td>".$row['newUsers']."</td>
                                                        <td>".$row['screenPageViewsPerSession']."</td>
                                                        <td>".$row['averageSessionDuration']."</td>
                                                    </tr>";
                                        }
                                    }else{
                                        echo "<tr class=\"text-center\"><td colspan=\"6\">Hiçbir kayıt bulunamadı!</td></tr>";
                                    }
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </main>
<?php include DIR_VIEWS."parts/footer.php"; ?>
<script>
    var table = new JSTable("#views-table", {
        serverSide : false,
        perPage : 15,
        labels: {
            placeholder: "Ara...",
            perPage: "sayfa başına kayıt",
            noRows: "Hiçbir kayıt bulunamadı!",
            info: "{rows} kayıttan {start} - {end} arası görüntüleniyor",
            loading: "Yükleniyor...",
            infoFiltered: "{rows} kayıttan {start} - {end} arası görüntüleniyor ({rowsTotal} kayıt arasından filtrelendi)"
        },
        layout: {
            top: "{search}",
            bottom: "{info}{pager}"
        }
    });
</script>