<?php
$tt_page_info = array(
  'Page_Info' =>   array(
    'Title' =>'আর্কাইভ',
    'Description' =>'' ,
    'Keyword' => '',
  ),
  'Social_og' => array(
    'Image' => '',
    'Type' => 'website',
    'URL' => 'archive/',
  ),
);
require_once('./header.php'); // Include Footer
?>
<section class="py-4">
   <div class="container">
    <div class="row g-4 mt-3">
      <div class="col-lg-8">
        <h1 class="h3 fw-bold tt-primary-color">আর্কাইভ দেখুন </h1>
        <div class="archive_box">
          <div class="input-group mb-3">
            <input id="archive-date" value="<?php echo $the_post_date ?>" type="date" class="form-control" aria-describedby="search-archive">
            <a href="<?php echo $site_domain . 'archive/' . $the_post_date ?>" class="input-group-text" id="search-archive">
              <i class="bi bi-search"></i> &nbsp; আর্কাইভ থেকে খুঁজুন
            </a>
          </div> 
        </div>
        <div id="news-container">
          <?php
          $archive_article = showAllttdata("mahamudfutureit_article", "WHERE PostDayPublic = '$the_post_date' AND PostStatus = 'published' AND PostDatePublic <= '$the_time' ORDER BY PostDatePublic DESC LIMIT 16 OFFSET 0");
          if (!empty($archive_article)) {
            foreach ($archive_article as $the_article) {
              ?>
                <div>
                  <a href="<?php echo articleLink($the_article['PostId']) ?>" class="d-block  prothom-songbad-post-style  ">
                     <div class="row g-2 align-items-center">
                         <div class="col-4">
                           <div class="position-relative overflow-hidden rounded-2">
                             <img class="w-100 ps-post-line-img "  src="<?php echo $advancenews['ArticlePreloader'] ?>"  data-src="<?php echo articleImg($the_article['PostId']) ?>" alt="<?php echo $the_article['PostTitle'] ?>">
                           </div>
                         </div>
                         <div class="col-8">
                           <h1 class=" news-title-2 m-0 tt-text"><?php echo $the_article['PostTitle'] ?></h1>
                           <p class="summery-2"><?php echo str_replace('&nbsp;', '&#160;',  articleContentClean(strip_tags($the_article['PostContent']))) ?></p>
                         </div>
                     </div>
                   </a>
                </div>
                <hr>
              <?php
            }
          }else {
            ?>
            <?php echo  noPost(); ?>
            <style media="screen">
              .loader_btn{
                display: none;
              }
            </style>
            <?php
          }
           ?>
        </div>
        <div class="row mb-2 loader_btn">
             <div id="loader"  class="col-md-12 text-center py-3" style="display: none;"><img src="<?php echo $site_domain ?>assets/image/loading-post.gif" style=" height:40px;"></div>
             <div class="col-12 text-center py-3">
                 <button class="btn btn-more-details tt-white tt-text" id="load-more-button"> আরো পড়ুন  </button>
             </div>
        </div>
      </div>
      <div class="col-lg-4">
        <div class="most-recent ">
          <?php require_once('template-part/most-recent-2.php');  ?>
        </div>
        <div class="mahamudfutureit-archive mt-2">
          <?php require_once('template-part/archive.php');  ?>
        </div>
      </div>
    </div>
  </div>
</section>
<script>
let page=2;
var data_type="ttarp";
data_id="<?php echo $the_post_date ?>";
let isLoading=!1;

function loadMoreNews() {
    if (isLoading) {
        return;
    }

    isLoading = true;
    $('#loader').show();

    $.ajax({
        url: '<?php echo $site_domain ?>ajax_master/load-post/',
        type: 'POST',
        data: {
            page: page ,
            data_id : data_id,
            data_type :data_type,

            },
        success: function(data) {
            const newsContainer = $('#news-container');
            newsContainer.append(data);

            page++;
            isLoading = false;
            $('#loader').hide();
            lazyLoadImages();
        },
        error: function(error) {
            isLoading = false;
            $('#loader').hide();
        }
    });
}
$('#load-more-button').click(function() {
    loadMoreNews();
});
</script>
<script>
  const dateInput = document.getElementById('archive-date');
  const searchLink = document.getElementById('search-archive');

  dateInput.addEventListener('change', function() {
    const selectedDate = this.value;  // format: YYYY-MM-DD
    if (selectedDate) {
      searchLink.href = '<?php echo $site_domain ?>archive/' + selectedDate;
    } else {
      // fallback to some default if needed
      searchLink.href = '<?php echo $site_domain ?>archive/<?php echo $the_post_date ?>';
    }
  });
</script>
<?php
require_once('./footer.php'); // Include Footer
?>
