<?php
$tt_page_info = array(
  'Page_Info' =>   array(
    'Title' => 'অনুসন্ধান করুণ ',
    'Description' =>'',
    'Keyword' => '',
  ),
  'Social_og' => array(
    'Image' => '',
    'Type' => 'website',
    'URL' => 'search/',
  ),
);

require_once('./header.php'); // Include Footer
?>
<section class="tt-gray py-4">
  <div class="container">

      <div class="row g-3">
        <?php

        $category_ads_1 = showAds($advancenews['SearchAds1'], $advancenews['SearchAdsCtl']);
        if ($category_ads_1 != '') {
          ?>
          <div class=" col-12">
            <?php echo $category_ads_1 ?>
          </div>
          <?php
        }
         ?>

        <div class="col-md-8">
            <div>
                <h4 class="m-0">অনুসন্ধান করুণ</h4>
            </div>
            <div class="tt-white p-2 mt-3">
              <form class="d-flex g-2" action="<?php echo $site_domain ?>search/" method="get">
                <input type="search" name="q" value="<?php echo $search ?>" placeholder="কী খুঁজতে চান ?" class="form-control form-control-lg rounded-0">
                <button type="submit" class="btn btn-lg rounded-0 tt-primary-bg text-white"><i class="bi bi-search"></i>   </button>
              </form>
            </div>

            <?php
            $category_ads_2 = showAds($advancenews['SearchAds2'], $advancenews['SearchAdsCtl']);
            if ($category_ads_2 != '') {
              ?>
              <div class="mt-3">
                <?php echo $category_ads_2 ?>
              </div>
              <?php
            }
            if ($search !='') {
              $the_item_post =  getSearchArticles($search, 12);

              if (!empty($the_item_post)) {
                $count_the_item_post = 1;
                echo '<div class=" row g-3  mt-3 " id="news-container">';
                foreach ($the_item_post as $the_it_post) {
                    ?>
                        <div class="col-md-12 col-6 ">
                          <div class=" tt-white ">
                            <div class="row g-2 align-items-center ">
                              <div class="col-md-4  col-12 mt-0 ">
                               <a href="<?php echo articleLink($the_it_post['PostId']) ?>"  class="p-2 d-block tt-white prothom-songbad-post-style ">
                                 <div class="position-relative  overflow-hidden">
                                   <img class="w-100 ps-post-line-img"  src="<?php echo $advancenews['ArticlePreloader'] ?>"  data-src="<?php echo articleImg($the_it_post['PostId']) ?>" alt="<?php echo $the_it_post['PostTitle'] ?>">
                                 </div>
                               </a>
                              </div>
                              <div class="col-md-8 col-12 mt-0 ps-md-0 pt-0 p-3 pt-md-3">
                                <a href="<?php echo articleLink($the_it_post['PostId']) ?>"  class=" mb-2 d-block tt-white prothom-songbad-post-style ">
                                  <h1 class="news-title-2 m-0 tt-text"><?php echo $the_it_post['PostTitle'] ?></h1>
                                  <div class="d-none d-md-block">
                                    <p class="summery-2  mb-0 my-1">
                                      <?php echo  strip_tags($the_it_post['PostContent']) ?>
                                    </p>
                                  </div>
                                </a>
                                <a href="<?php echo articleCategory($the_it_post['PostId'],'url') ?>">
                                  <h4 class="m-0 p_post_cat1 d-inline fs-6"><?php echo articleCategory($the_it_post['PostId'],'name') ?></h4>
                                </a> | <?php echo dokanDate($the_it_post['PostDatePublic']) ?>
                              </div>
                            </div>
                          </div>
                        </div>
                        <?php
                        if ($count_the_item_post == 6) {
                          $category_ads_3 = showAds($advancenews['SearchAds3'], $advancenews['SearchAdsCtl']);
                          if ($category_ads_3 != '') {
                            ?>
                            <div class=" col-12">
                              <?php echo $category_ads_3 ?>
                            </div>
                            <?php
                          }
                        }
                        ?>
                    <?php
                  $count_the_item_post++;
                }
                echo '</div>';
                ?>
               <div class="row mb-2">
                    <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>
                <?php
              }else {
                ?>
                <div class="row my-3">
                  <div class="col-12">
                    <?php echo  noPost(); ?>
                  </div>
                </div>
                <?php
              }
            }
           ?>
        </div>
        <div class="col-md-4">
          <?php
          $category_ads_8 = showAds($advancenews['SearchAds8'], $advancenews['SearchAdsCtl']);
          if ($category_ads_8 != '') {
            ?>
            <div class="mt-0 mb-2 ">
              <?php echo $category_ads_8 ?>
            </div>
            <?php
          }
          ?>
          <div class="most-recent mt-1">
            <?php require_once('template-part/most-recent-1.php');  ?>

            <?php
            $category_ads_9 = showAds($advancenews['SearchAds9'], $advancenews['SearchAdsCtl']);
            if ($category_ads_9 != '') {
              ?>
              <div class=" my-3 ">
                <?php echo $category_ads_9 ?>
              </div>
              <?php
            }
            ?>

            <div class="tt-white border">
              <?php require_once('template-part/local-news-1.php'); ?>
            </div>
            <?php
            $category_ads_10 = showAds($advancenews['SearchAds10'], $advancenews['SearchAdsCtl']);
            if ($category_ads_10 != '') {
              ?>
              <div class=" my-3 ">
                <?php echo $category_ads_10 ?>
              </div>
              <?php
            }
            ?>
          </div>
        </div>
      </div>

  </div>
</section>
<script>
let page=3;
var data_type="ttsp";
data_id="<?php echo $search ?>";
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>
<?php
require_once('./footer.php'); // Include Footer
?>
