<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Services\CustomerService;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Http;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {
        $auth_user = Auth::user();
        $api_url = config('api.url');
        if($auth_user['roles'] == 'teller'){
            if($auth_user['role_harian'] == 'teller'){
                $cawangan_info = Http::get(config('api.url') . '/api/cawangan/'. $auth_user['cawangan'])->json();
                return view('homepage.'.$auth_user['role_harian'].'.home',compact('cawangan_info','api_url'));
            }elseif($auth_user['role_harian'] == 'penilai'){
                $cawangan_info = Http::get(config('api.url') . '/api/cawangan/'. $auth_user['cawangan'])->json();
                $gadaian_semasa = Http::get(config('api.url') . '/api/gadaiansemasa/'. $auth_user['cawangan'])->json();
                $gadaian_belumserah = Http::get(config('api.url') . '/api/gadaiansemasa/belum_serah/'. $auth_user['cawangan'])->json();
                return view('homepage.'.$auth_user['role_harian'].'.home',compact('cawangan_info','gadaian_semasa','gadaian_belumserah','api_url'));
            }
        }
        elseif($auth_user['roles'] == 'pc' || $auth_user['roles'] == 'ppc'){
            $cawangan_info = Http::get(config('api.url') . '/api/cawangan/'. $auth_user['cawangan'])->json();
            return view('homepage.khazanah.home',compact('cawangan_info','api_url'));
        }
        elseif($auth_user['roles'] == 'operasi'){
            $cawangan_info = Http::get(config('api.url') . '/api/cawangan/'. $auth_user['cawangan'])->json();
            return view('homepage.'.$auth_user['roles'].'.home',compact('cawangan_info','api_url'));
        }
    }
}
