<?php
$tt_page_info = array(
  'Page_Info' =>   array(
    'Title' =>    htmlentities($the_user ['UserName'], ENT_QUOTES, 'utf-8'),
    'Description' => '',
    'Keyword' => '',
  ),
  'Social_og' => array(
    'Image' => '',
    'Type' => 'website',
    'URL' => str_replace($site_domain, '', userProfile($the_user['UserID'])),
  ),
);

require_once('./header.php'); // Include Footer
?>
<style>
/* শুধু সোশ্যাল আইকনের জন্য CSS - বাকি ডিজাইন অক্ষত থাকবে */
.user-social-icon {
    display: flex;
    gap: 6px;
    margin-top: 5px;
    margin-bottom: 5px;
}
.user-social-icon a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #f0f2f5;
    color: #555;
    transition: all 0.2s ease;
    text-decoration: none;
    font-size: 14px;
}
.user-social-icon a:hover {
    background: #e0e0e0;
    transform: translateY(-1px);
    color: #000;
}
.user-social-icon i {
    font-size: 14px;
    line-height: 1;
}
.join-date {
    font-size: 13px;
    color: #666;
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.join-date i {
    font-size: 14px;
    color: #f39c12;
}
.join-date span {
    font-weight: 500;
    color: #333;
    margin-right: 3px;
}
</style>
<section class="py-4">
  <div class="container">
    <?php
    $category_ads_1 = showAds($advancenews['AuthorAds1'], $advancenews['AuthorAdsCtl']);
    if ($category_ads_1 != '') {
      ?>
      <div class="  mb-3">
        <?php echo $category_ads_1 ?>
      </div>
      <?php
    }
    ?>
    <hr>
    <div class="p-md-2  ">
      <div class="row justify-content-center">
        <div class="col-md-5">
          <div class=" ">
            <div class="row align-items-center ">
              <div class="col-md-3 col-4">
                <div class="mb-2">
                  <img src="<?php echo userAvater($the_user['UserID']) ?>" alt="<?php echo htmlentities($the_user['UserName'], ENT_QUOTES, 'utf-8'); ?>" class="w-100 rounded-circle">
                </div>
              </div>
              <div class="col-md-9 col-8">
                <h1 class="news-title-1"> <?php echo htmlentities($the_user['UserName'], ENT_QUOTES, 'utf-8'); ?> </h1>
                <?php
                if ($the_user['UserDesignation']) {
                  ?>
                  <h2 class="news-title-2 text-muted"> <?php echo htmlentities($the_user['UserDesignation'], ENT_QUOTES, 'utf-8'); ?> </h2>
                  <?php
                }
                ?>
                <div class="user-social-icon">
                  <?php
                  $user_sms = json_decode($the_user['UserSocial'], TRUE);
                  foreach ($user_social_medias as $sm_name => $sm_icon) {
                      $link_value = isset($user_sms[$sm_name]) ? $user_sms[$sm_name] : '';
                      if ($link_value !='') {
                        ?>
                        <a class="text-muted text-decoration-none" href="<?php echo htmlspecialchars($link_value); ?>" target="_blank">
                          <i class="<?php echo $sm_icon ?>"></i>
                        </a>
                        <?php
                      }
                  }
                  ?>
                </div>
                <?php
                // যোগদানের তারিখ বাংলায় দেখানো হচ্ছে
                if (!empty($the_user['JoinDate'])) {
                  $bangla_months = array(
                    'January' => 'জানুয়ারি',
                    'February' => 'ফেব্রুয়ারি',
                    'March' => 'মার্চ',
                    'April' => 'এপ্রিল',
                    'May' => 'মে',
                    'June' => 'জুন',
                    'July' => 'জুলাই',
                    'August' => 'আগস্ট',
                    'September' => 'সেপ্টেম্বর',
                    'October' => 'অক্টোবর',
                    'November' => 'নভেম্বর',
                    'December' => 'ডিসেম্বর'
                  );
                  $timestamp = strtotime($the_user['JoinDate']);
                  $day = date('j', $timestamp);
                  $month = date('F', $timestamp);
                  $year = date('Y', $timestamp);
                  $bangla_month = $bangla_months[$month];
                  $bangla_date = $day . ' ' . $bangla_month . ', ' . $year;
                  ?>
                  <div class="join-date">
                    <i class="fas fa-calendar-alt"></i>
                    <span>যোগদান:</span> <?php echo $bangla_date; ?>
                  </div>
                  <?php
                }
                ?>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <hr>

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

    <?php
    $this_user_id = $the_user['UserID'];
    $the_item_post =  getUserArticles($this_user_id, 9);

     if (!empty($the_item_post)) {
       $count_the_item_post = 1;
       echo '<div class="row mt-3 g-3" id="news-container">';
       foreach ($the_item_post as $the_it_post) {
         if ($count_the_item_post == 1) {
           ?>
             <div class="col-md-9">
               <div class=" ">
                 <a href="<?php echo articleLink($the_it_post['PostId']) ?>"  class="d-block  prothom-songbad-post-style ">
                   <div class="row align-items-center g-2  ">
                     <div class="col-md-5 order-2 order-md-1 col-12 mt-0 p-3 ">
                       <h1 class="news-title m-0 tt-text"><?php echo $the_it_post['PostTitle'] ?></h1>
                       <p class="summery-5">
                         <?php echo  strip_tags($the_it_post['PostContent']) ?>
                       </p>
                     </div>
                     <div class="col-md-7 order-1 order-md-2 col-12 mt-0 ">
                       <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_it_post['PostId']) ?>" alt="<?php echo $the_it_post['PostTitle'] ?>">
                       </div>
                     </div>
                   </div>
                 </a>
               </div>
             </div>
             <div class="col-md-3">
               <?php
               $category_ads_3 = showAds($advancenews['AuthorAds3'], $advancenews['AuthorAdsCtl']);
               if ($category_ads_3 != '') {
                 ?>
                 <div class=" ">
                   <?php echo $category_ads_3 ?>
                 </div>
                 <?php
               }
               ?>
             </div>
           <?php
         }else {
           ?>
           <div class="col-md-3 col-6">
             <a href="<?php echo articleLink($the_it_post['PostId']) ?>"  class="d-block  prothom-songbad-post-style">
               <div class="align-items-center">
                   <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_it_post['PostId']) ?>" alt="<?php echo $the_it_post['PostTitle'] ?>">
                   </div>
                   <div class="p-2">
                     <h1 class=" news-title-2 m-0 tt-text"><?php echo $the_it_post['PostTitle'] ?></h1>
                   </div>
               </div>
             </a>
           </div>
           <?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 mb-3">
         <div class="col-12">
           <?php echo  noPost(); ?>
         </div>
       </div>
       <?php
     }
   ?>
   <?php
   $category_ads_8 = showAds($advancenews['AuthorAds8'], $advancenews['AuthorAdsCtl']);
   if ($category_ads_8 != '') {
     ?>
     <div class=" ">
       <?php echo $category_ads_8 ?>
     </div>
     <?php
   }
   ?>

  </div>
</section>

<script>
let page=3;
var data_type="ttathp";
data_id=<?php echo $the_user['UserID'] ?>;
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
?>