<?php

namespace App\Http\Controllers\Operator;

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

use DB;

class CheckController extends Controller
{
    public function email(Request $request)
    {
        $email = strtolower($request->input('value'));
        $temp = strtolower($request->input('temp'));
        if($email == $temp)
        {
            echo '0';
            exit;
        }

        $cek = User::select('id')->Where(DB::raw('lower(email)'), $email)->count();
        if($cek > 0)
            echo '1';
        else
            echo '0';
    }

    public function nidn(Request $request)
    {
        $nidn = $request->input('value');
        $temp = $request->input('temp');
        if($nidn == $temp)
        {
            echo '0';
            exit;
        }

        $cek =  Biodata::join('users', 'users.id', '=', 'biodata.id')
                ->select('id')
                ->Where('noidentitas', $nidn)
                ->count();
        if($cek > 0)
            echo '2';
        else
            echo '0';
    }

    // public function kecamatan($kota)
    // {
    //     $modelKecamatan = new Kecamatan;
    //     $kecamatan = new KecamatanRepository($modelKecamatan);

    //     return $kecamatan->kecamatan($kota);
    // }

    // public function smu($kecamatan)
    // {
    //     $modelSmu = new KodeSmu;
    //     $smu = new SmuRepository($modelSmu);

    //     return $smu->smu($kecamatan);
    // }

    // public function kelompokJalur($jalur){
    //     $modelProdiJalur = new Kelompok;
    //     $modelPendaftar = new Pendaftar;
    //     $prodiJalur = new KelompokRepository($modelProdiJalur, $modelPendaftar);
    //     return $prodiJalur->kelompok('ajax', $jalur);
    //     //dd($prodiJalur->prodiJalurx($kelompok, $jalur));
    // }

    // public function prodiJalur($kelompok, $jalur){
    //     $modelProdiJalur = new ProdiJalur;
    //     $prodiJalur = new ProdiJalurRepository($modelProdiJalur);
    //     return $prodiJalur->prodiJalurx($kelompok, $jalur);
    //     //dd($prodiJalur->prodiJalurx($kelompok, $jalur));
    // }

    // public function spi($prodi)
    // {
    //     $modelSpi = new Spi;
    //     $spi = new SpiRepository($modelSpi);

    //     return $spi->spi($prodi);
    // }

    public function prodi(Request $request)
    {
        $value      = $request->get('value');

        if($value != '')
        {
            $data       = DB::table('prodi')->where('fakultas_id', $value)->select('id', 'nama')->get();
            $output     = '<option value="">- Pilih Data -</option>';

            foreach($data as $row)
            {
                $output .= '<option value="'.$row->id.'">'.$row->nama.'</option>';
            }
        }
        else
        {
            $output     = '';
        }

        echo $output;
    }

    // public function prodiunesa($fakultas)
    // {
    //     $modelProdiunesa = new ProdiUnesas;
    //     $prodiunesa = new ProdiUnesaRepository($modelProdiunesa);

    //     return $prodiunesa->prodiunesa($fakultas);
    // }
}
