<?php

namespace App\Controllers\View;

use CodeIgniter\Controller;
use App\Models\UserModel;
use CodeIgniter\Database\Exceptions\DatabaseException;

class InfoIconController extends Controller
{
    public function profileIcon()
    {
        $session = session();
        $userId = $session->get('user_id');

        if (!$userId) {
            return view('errors/html/error_401', ['message' => 'User not logged in']);
        }

        $userModel = new UserModel();
        $user = $userModel->getUserInfoById($userId);

        if ($user) {
            $data = [
                'userName' => $user['firstname'] . ' ' . $user['lastname'],
                'userInitials' => strtoupper($user['firstname'][0] . $user['lastname'][0])
            ];
        } else {
            $data = [
                'userName' => 'User not found',
                'userInitials' => '??'
            ];
        }

        return view('partials/header', $data);
//        return view('dashboard', ['content' => view('partials/user_icon', $data)]);

    }
}