<?php
use App\Core\Auth;
use function App\Core\{e, t, url};

$user = Auth::user();
$displayName = $user['display_name'] ?? $user['nickname'] ?? $user['username'] ?? 'User';
$avatar = $user['avatar'] ?? null;
?>
<div class="user-menu account-user-menu" data-user-menu>
    <button class="user-chip" data-dropdown type="button" aria-haspopup="true" aria-expanded="false">
        <span class="avatar">
            <?php if ($avatar): ?><img src="<?= e($avatar) ?>" alt=""><?php else: ?><?= e(strtoupper(substr((string) $displayName, 0, 1))) ?><?php endif; ?>
        </span>
        <span class="user-name"><?= e($displayName) ?></span>
        <span class="chevron" aria-hidden="true">v</span>
    </button>
    <div class="dropdown account-dropdown" role="menu">
        <div class="dropdown-head user-dropdown-head">
            <span class="avatar">
                <?php if ($avatar): ?><img src="<?= e($avatar) ?>" alt=""><?php else: ?><?= e(strtoupper(substr((string) $displayName, 0, 1))) ?><?php endif; ?>
            </span>
            <span>
                <strong><?= e($displayName) ?></strong>
                <small><?= e($user['username'] ?? 'zalorox') ?></small>
            </span>
        </div>
        <?php require BASE_PATH . '/app/Views/partials/account-preferences.php'; ?>
        <div class="dropdown-section account-links">
            <a class="dropdown-link" role="menuitem" href="<?= url('/kullanici/' . ($user['username'] ?? 'profil')) ?>"><?= e(t('profile')) ?></a>
            <a class="dropdown-link" role="menuitem" href="<?= url('/studyo') ?>"><?= e(t('studio')) ?></a>
            <button class="dropdown-link" type="button" data-open-notifications>Bildirimleri Oku</button>
            <a class="dropdown-link" role="menuitem" href="<?= url('/studyo/bildirimler') ?>"><?= e(t('notifications')) ?></a>
            <a class="dropdown-link" role="menuitem" href="<?= url('/studyo/mesajlar') ?>"><?= e(t('messages')) ?></a>
            <a class="dropdown-link" role="menuitem" href="<?= url('/studyo/ayarlar') ?>"><?= e(t('settings')) ?></a>
            <a class="dropdown-link" role="menuitem" href="<?= url('/studyo/mod-yukle') ?>"><?= e(t('upload_mod')) ?></a>
            <a class="dropdown-link" role="menuitem" href="<?= url('/studyo/muzik-yukle') ?>"><?= e(t('upload_music')) ?></a>
            <a class="dropdown-link" role="menuitem" href="<?= url('/studyo/kazanclarim') ?>"><?= e(t('earnings')) ?></a>
            <?php if (Auth::role('admin')): ?><a class="dropdown-link" role="menuitem" href="<?= url('/zpanel') ?>"><?= e(t('zpanel')) ?></a><?php endif; ?>
            <a class="dropdown-link is-danger" role="menuitem" href="<?= url('/cikis') ?>" data-confirm="<?= e(t('logout_confirm')) ?>" data-confirm-label="<?= e(t('logout')) ?>"><?= e(t('logout')) ?></a>
        </div>
    </div>
</div>
