<?php

namespace App\Controllers;

use App\Repositories\BrandRepository;
use App\Repositories\MobileRepository;
use App\Repositories\VendorRepository;

class admin
{

    public function login(){
        view("/admin/sign-in");
    }
    public function dashboard(){
        is_logged_in();
        $vendor = new VendorRepository();
        $data = [
            "user" => $_SESSION['user'],
            "reports" => $vendor->all(),
        ];
        view("/admin/users",$data);
    }
    public function products() {
        is_logged_in();
        $mobile = new MobileRepository();
        $brand  = new BrandRepository();
        $all = $mobile->all();
        foreach ($all as $key => $value ) {
            $value["brand_id"] = $brand->findById($value["brand_id"])["name"];
            $all[$key] = $value;
        }
        $data = [
            "reports" => $all,
            "user" => $_SESSION['user'],
        ];
        view("/admin/products",$data);
    }
    public function addProduct(){
        is_logged_in();
        $brand = new BrandRepository();
        $data = [
            "brands" => $brand->all(),
            "user" => $_SESSION['user'],
        ];
        view("/admin/add-product",$data);
    }
}