<?php
/**
 * ------------------------------------------------------------------------
 * WT Kunena Birthdays Module
 * ------------------------------------------------------------------------
 * Copyright (C) 2009-2025 Wave Theme. All Rights Reserved.
 * @license - GNU/GPL, http://www.gnu.org/licenses/gpl.html
 * Author: Wave Theme Template Club
 * Websites: http://www.wavetheme.com - http://www.9themestore.com
 * ------------------------------------------------------------------------
 */

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Language\Text;
use Kunena\Forum\Libraries\Route\KunenaRoute;

$doc = Factory::getDocument();
$wa = $doc->getWebAssetManager();
$wa->registerAndUseStyle('mod_wt_kunena_birthdays.style', 'modules/mod_wt_kunena_birthdays/media/css/style.css');

$now = Factory::getDate();

$layoutType = $params->get('layout_type', 'layout-1');
$avatarSize = $params->get('avatar_sizes', '40px');
$avatarStyle = $params->get('avatar_styles', '50%');
$showNames = $params->get('show_names', 1);
$nameType = $params->get('name_type', 'username');
$customMsg = $params->get('custom_message');
?>

<div class="wt-kunena-birthdays <?php echo $layoutType; ?>">

  <div class="wt-date-wrapper">
    <div class="wt-date-inner">
      <?php
      $day = $now->format('j');
      $monthYear = $now->format('F Y');
      ?>
      <span class="wt-date-title"><i class="fa-solid fa-cake"></i><?php echo Text::_('MOD_WT_KUNENA_BIRTHDAYS_TODAY') . ': '; ?></span>
      <span class="wt-date"><span class="wt-day"><?php echo $day; ?></span> <span class="wt-month-year"><?php echo $monthYear; ?></span></span>
    </div>
  </div>

  <div class="wt-info-wrapper">
    <?php if ($customMsg) : ?>
      <div class="wt-custom-msg"><?php echo $customMsg; ?></div>
    <?php endif; ?>

    <?php if ($list === 'error_nokunena') : ?>
      <p class="alert alert-warning"><?php echo Text::_('MOD_WT_KUNENA_BIRTHDAYS_KUNENA_NOT_INSTALLED'); ?></p>
    <?php elseif ($list === 'error_nousers') : ?>
      <p class="alert alert-info"><?php echo Text::_('MOD_WT_KUNENA_BIRTHDAYS_NO_BIRTHDAYS'); ?></p>
    <?php else : ?>
      <ul class="wt-users-list">
        <?php foreach ($list as $user) :
          $avatar = $user->avatar ?: '';
          $initial = ModWTKunenaBirthdaysHelper::getInitial($user->username);
          $bgColor = ModWTKunenaBirthdaysHelper::getColorFromUser($user->username);
          $profileLink = ModWTKunenaBirthdaysHelper::getProfileLink($user->id);
          $isOnline = $user->online ? true : false;
          $name = $nameType === 'username' ? $user->username : $user->name;
          $tooltip = $name . ' - ' . Factory::getDate($user->birthdate ?: '1970-01-01')->format('j F');
        ?>
          <li>
            <a href="<?php echo $profileLink; ?>" class="avatar-link" title="<?php echo htmlspecialchars($tooltip); ?>">
              <?php $avatarPath = $avatar ? 'media/kunena/avatars/' . $avatar : ''; ?>

              <?php if ($avatar) : ?>
                <img src="<?php echo htmlspecialchars(Uri::root() . $avatarPath); ?>" alt="<?php echo htmlspecialchars($name); ?>" class="avatar-img" style="border-radius: <?php echo $avatarStyle ?>; width:<?php echo $avatarSize; ?>; height: <?php echo $avatarSize; ?>;" />
              <?php else : ?>
                <div class="avatar-initial" style="background-color: <?php echo $bgColor; ?>; border-radius: <?php echo $avatarStyle ?>; width:<?php echo $avatarSize; ?>; height: <?php echo $avatarSize; ?>;"><?php echo $initial; ?></div>
              <?php endif; ?>

              <?php if ($isOnline) : ?>
                <span class="kuser-status online-status"></span>
              <?php else: ?>
                <span class="kuser-status"></span>
              <?php endif; ?>
            </a>
            <?php if ($showNames) : ?>
              <div class="user-name"><?php echo htmlspecialchars($name); ?></div>
            <?php endif; ?>
          </li>
        <?php endforeach; ?>
      </ul>
    <?php endif; ?>
  </div>

</div>