<?php

/**
 * This file is part of JohnCMS Content Management System.
 *
 * @copyright JohnCMS Community
 * @license   https://opensource.org/licenses/GPL-3.0 GPL-3.0
 * @link      https://johncms.com JohnCMS Project
 */

/**
 * @var \Johncms\Users\User $item
 */
?>

<div class="user-row bg-white rounded-lg border border-gray-200 p-4 shadow-sm hover:shadow-md transition-shadow duration-200">
    <div class="flex items-start">
        <!-- User Avatar -->
        <div class="user-avatar mr-3 md:mr-4 relative flex-shrink-0">
            <div class="avatar-image w-12 h-12 md:w-14 md:h-14 rounded-full overflow-hidden border-2 border-white shadow-sm">
                <img src="<?= $this->avatar($item->id) ?>" class="w-full h-full object-cover" alt="<?= $item->name ?>">
            </div>
            <!-- Online Status Indicator -->
            <div class="user-status absolute -bottom-1 -right-1 w-3 h-3 md:w-4 md:h-4 rounded-full border-2 border-white shadow-sm <?= $item->is_online ? 'bg-green-500' : 'bg-gray-400' ?>"></div>
        </div>

        <!-- User Info -->
        <div class="flex-grow min-w-0">
            <div class="user-name flex flex-col sm:flex-row sm:items-center gap-1 sm:gap-2">
                <?php if ($user->id !== $item->id): ?>
                    <a href="<?= $item->profile_url ?>" 
                       class="user-login font-semibold text-gray-900 hover:text-blue-600 transition-colors duration-200 truncate">
                        <?= $item->name ?>
                    </a>
                <?php else: ?>
                    <span class="user-login font-semibold text-gray-900 truncate">
                        <?= $item->name ?>
                    </span>
                <?php endif; ?>
                <span class="text-gray-500 text-sm whitespace-nowrap">
                    <?= $item->display_date ?>
                </span>
            </div>
            
            <?php if (! empty($item->place_name)): ?>
                <div class="mt-1 text-gray-700 text-sm truncate">
                    <?= $item->place_name ?>
                </div>
            <?php endif; ?>
        </div>
    </div>

    <!-- Admin Information -->
    <?php if ($user->rights >= 3): ?>
        <div class="post-footer border-t border-gray-100 pt-3 mt-3">
            <div class="post-user-info flex flex-col sm:flex-row sm:items-center gap-2 text-xs text-gray-600">
                <?php if ($user->rights): ?>
                    <!-- IP Address -->
                    <div class="user-ip flex items-center gap-1">
                        <svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                        </svg>
                        <a href="<?= $item->search_ip_url ?>" 
                           class="hover:text-blue-600 transition-colors duration-200 font-mono">
                            <?= $item->ip ?>
                        </a>
                        <?php if (! empty($item->ip_via_proxy)): ?>
                            <span class="text-gray-400">/</span>
                            <a href="<?= $item->search_ip_via_proxy_url ?>" 
                               class="hover:text-blue-600 transition-colors duration-200 font-mono">
                                <?= $item->ip_via_proxy ?>
                            </a>
                        <?php endif; ?>
                    </div>

                    <!-- Browser Info -->
                    <div class="useragent flex items-center gap-1">
                        <svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9v-9m0-9v9"></path>
                        </svg>
                        <span class="truncate" title="<?= $item->browser ?>">
                            <?= $item->browser ?>
                        </span>
                    </div>
                <?php endif; ?>
            </div>
        </div>
    <?php endif; ?>
</div>