<?php

namespace App\Controllers\Admin;

use App\Controllers\BaseController;
use App\Models\Common_model;

class MyProfile extends BaseController
{
    protected $common;
    protected $table = 'tbl_users';

    public function __construct()
    {
        $this->common = new Common_model();
    }

    public function index()
    {
        if (!session()->get('isLoggedIn')) {
            return redirect()->to('/')->with('error', 'Please login');
        }

        $userId = session()->get('user_id');

        $user = $this->common->getData(
            $this->table,
            'id,name,username,mobile_number,role,added_date_time',
            ['id' => $userId]
        );

        if (empty($user)) {
            return redirect()->back()->with('error', 'User not found');
        }

        $data['user'] = $user[0];

        return view('admin/my_profile', $data);
    }
}
