<?php

namespace App\Http\Controllers\User;

use App\Http\Controllers\Controller;
use App\Models\Biodata;
use Illuminate\Http\Request;

class PenelitianSumberDanaController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('user.penelitiansumber.index');
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('user.penelitiansumber.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        dd($request->all());
    }

    /**
     * Display the specified resource.
     *
     * @param int $id
     *
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param int $id
     *
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
    }

    /**
     * Update the specified resource in storage.
     *
     * @param int $id
     *
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param int $id
     *
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
    }

    public function getRowAnggota(Request $request)
    {
        $data['no'] = $request->no;
        $data['nama'] = $request->nama;
        $data['keanggotaan'] = $request->keanggotaan;
        $data['prodi'] = $request->prodi;
        $data['nidn'] = encrypt($request->nidn);

        $dosen = Biodata::query()->where('nidn', $request->nidn)->first();

        if (!is_null($dosen) && $request->name == 'dosen') {
            $data['name'] = $request->name;
            $data['nama'] = $request->nama;
            $data['jenis'] = encrypt($dosen->jenis);
        } elseif (is_null($dosen) && $request->name == 'non_dosen') {
            $data['name'] = $request->name;
            $data['jenis'] = encrypt('l');
        }

        return view('user.penelitiansumber.row_anggota', $data);
    }
}
