<?php
require_once('config.php');
require_once('inc/header.php');
?>
  <main id="main" class="main">
    <?php
    if ($the_user['admin_access'] != 'Video Editor') {
      ?>
      <div class="row">
        <div class="col-6 align-items-center">
          <div class="pagetitle mb-3">
            <h1><?php echo $page_title ?></h1>
          </div>
        </div>
      </div>
      <?php
    }
    ?>
    <section class="section dashboard">
      <div class="row">

        <!-- Left side columns -->
        <div class="col-lg-8">
          <div class="row">
            <!-- Sales Card -->
            <div class="col-xxl-4 col-md-6">
              <div class="card info-card sales-card  bg-gradient-start-3 border">
                <div class="card-body">
                  <h5 class="card-title">All Article</h5>
                  <div class="d-flex align-items-center">
                    <div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
                      <i class="bi bi-newspaper"></i>
                    </div>
                    <div class="ps-3">
                      <h6><?php echo count(showAllttdata("mahamudfutureit_article")) ?></h6>
                      <a href="article.php" class="text-muted small pt-2 ps-1">Show Articles</a>
                    </div>
                  </div>
                </div>

              </div>
            </div><!-- End Sales Card --> 
            <!-- Revenue Card -->
            <div class="col-xxl-4 col-md-6">
              <div class="card info-card revenue-card  bg-gradient-start-1 border">
                <div class="card-body">
                  <h5 class="card-title">Published Articles</h5>
                  <div class="d-flex align-items-center">
                    <div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
                      <i class="bi bi-pencil-square"></i>
                    </div>
                    <div class="ps-3">
                      <h6><?php echo count(showAllttdata("mahamudfutureit_article", "WHERE PostStatus ='published' ORDER BY  PostDate  DESC ")) ?></h6>
                      <a href="article.php?from=published" class="text-muted small pt-2 ps-1">Show Articles</a>
                    </div>
                  </div>
                </div>

              </div>
            </div><!-- End Revenue Card -->

            <!-- Customers Card -->
            <div class="col-xxl-4 col-xl-12">
              <div class="card info-card customers-card bg-gradient-start-2 border ">
                <div class="card-body">
                  <h5 class="card-title">Pending Articles</h5>
                  <div class="d-flex align-items-center">
                    <div class="card-icon rounded-circle d-flex align-items-center justify-content-center">
                      <i class="bi bi-info-circle"></i>
                    </div>
                    <div class="ps-3">
                      <h6><?php echo count(showAllttdata("mahamudfutureit_article", "WHERE PostStatus ='pending' ORDER BY  PostDate  DESC ")) ?></h6>
                      <a href="article.php?from=pending" class="text-muted small pt-2 ps-1">Show Articles</a>
                    </div>
                  </div>

                </div>
              </div>

            </div><!-- End Customers Card -->

            <!-- Website Traffic -->
            <div class="col-12">
              <div class="card">
                <div class="card-body">
                  <h5 class="card-title">Website Traffic </h5>
                  <!-- Line Chart -->
                  <div id="reportsChart" style="min-height: 365px;"></div>
                  <?php
                  $visitor_dates =  [];
                  for ($i = 7; $i >= 0; $i--) {
                      $visitor_dates[] = date('Y-m-d', strtotime("-$i days"));
                  }
                  ?>
                  <script>
                    document.addEventListener("DOMContentLoaded", () => {
                      new ApexCharts(document.querySelector("#reportsChart"), {
                        series: [{
                          name: 'Views',
                          data: [
                            <?php
                            foreach ($visitor_dates as $this_vdate) {
                              $get_action_visitor = getSingleValue('mahamudfutureit_visitor', 'date', $this_vdate, 'visitor');
                              if ($get_action_visitor !='') {
                                echo $get_action_visitor.',';
                              }else {
                                echo "0,";
                              }
                            }
                            ?>
                          ],
                        } ],
                        chart: {
                          height: 350,
                          type: 'area',
                          toolbar: {
                            show: false
                          },
                        },
                        markers: {
                          size: 4
                        },
                        colors: ['#4154f1', '#2eca6a', '#ff771d'],
                        fill: {
                          type: "gradient",
                          gradient: {
                            shadeIntensity: 1,
                            opacityFrom: 0.3,
                            opacityTo: 0.4,
                            stops: [0, 90, 100]
                          }
                        },
                        dataLabels: {
                          enabled: true
                        },
                        stroke: {
                          curve: 'smooth',
                          width: 2
                        },
                        xaxis: {
                          type: 'date',
                          categories: <?php echo json_encode($visitor_dates); ?>
                        },
                        tooltip: {
                          x: {
                            format: 'dd/MM/yy HH:mm'
                          },
                        }
                      }).render();
                    });
                  </script>
                  <!-- End Line Chart -->

                </div>

              </div>
            </div><!-- End Reports -->

          </div>
        </div><!-- End Left side columns -->

        <!-- Right side columns -->
        <div class="col-lg-4">

          <!-- Recent Activity -->
          <div class="card">

            <div class="card-body">
              <h5 class="card-title">Recent Articles  </h5>

              <div class="activity">
                <?php
                  $tt_article_post = showAllttdata("mahamudfutureit_article", " ORDER BY  PostDate  DESC LIMIT 10 ");
                  foreach (  $tt_article_post as $the_post) {
                    ?>
                    <div class="activity-item d-flex">
                      <div class="activite-label"><?php echo articleTimeEN($the_post['PostDatePublic']) ?></div>
                      <i class="bi bi-circle-fill activity-badge <?php
                          if ($the_post['PostStatus'] == 'pending') {
                            echo "text-warning";
                          }elseif ($the_post['PostStatus'] == 'published') {
                            echo "text-success";
                          }elseif ($the_post['PostStatus'] == 'rejected') {
                            echo "text-danger";
                          }
                       ?> align-self-start"></i>
                      <div class="activity-content">
                          <a target="_blank" href="<?php echo articleLink($the_post['PostId']) ?>" class="fw-normal text-dark "><?php echo $the_post['PostTitle'] ?></a>
                      </div>
                    </div>
                    <?php
                  }
                ?>

              </div>

            </div>
          </div>

        </div><!-- End Right side columns -->

      </div>
    </section>
  </main>
  <?php require_once('inc/footer.php'); ?>
