<?php

namespace App\Http\Controllers;

use App\Models\Auth\Biodata;
use App\Models\Pengumuman;
use App\Models\Sms;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class DashboardController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
        $title   = 'Dashboard PKM';
        $pengumuman = $pengumuman = Pengumuman::query()->first();

        if(Auth::user()->hasrole(['mahasiswa'])){
            $user = Auth::user()->rBiodata->noidentitas;

            $dataMhs = GetDataApiController::getAccount($user);
            $faks = Sms::where('id_sms', $dataMhs['data_mahasiswa']['id_sms'])->first();
            $person['fakultas'] = $faks->parent->nm_lemb;

            $biodata = Biodata::where('noidentitas', $user)->first();

            $biodata->update($person);
        }

        $data = [
            'title'   => $title,
            'pengumuman'  => $pengumuman,
        ];

        return view('backend.index', $data);
    }

}
