<?php

namespace App\Http\Controllers\Admin;

use App\Helpers\Helper;
use App\Http\Controllers\Controller;

use Illuminate\Support\Facades\DB;
//modal
;
use Carbon\Carbon;
use Illuminate\Support\Str;
use Auth;

//UTILS
use App\Utils\DashboardUtil;

//MODEL
use App\Model\Logistik\ManajemenKantong;
use App\Model\Master\Reagen;
use App\Model\Master\ItemKantongs;
use App\Model\Master\MasterJenisKantong;
use App\Model\Master\MerkReagen;
use App\Model\Master\Reagens;
use GuzzleHttp\Psr7\Request;

class DashboardController extends Controller
{
    /**
     * Title untuk judul di web
     * route digunakan untuk tempat resource (file path) + routing (route/web) diusahain sama ya biar gak ngubah"
     */
    private $title = 'Admin';
    private $route = 'admin.dashboard.'; //path awal foldernya ajah
    protected $DashboardUtil;
    public function __construct(DashboardUtil $DashboardUtil)
    {
        $this->DashboardUtil = $DashboardUtil;
        DB::enableQueryLog();
    }

    public function index()
    {
        // $petugas_udd_id                 = Auth::user()->petugas->unit_donor_darah_id;
        // $kantongLogistik_last_30_days   = ManajemenKantong::getData30Days($status_kantongs = 1, $status_kantong_item = 1, $petugas_udd_id, $param_order = 'created_at', $imltd = null, $kgd = null);
        // $kantongAftap_last_30_days      = ManajemenKantong::getData30Days($status_kantongs = 1, $status_kantong_item = 2, $petugas_udd_id, $param_order = 'created_at', $imltd = null, $kgd = null);
        // $kantongBelumImltd_last_30_days = ManajemenKantong::getData30Days($status_kantongs = 3, $status_kantong_item = 3, $petugas_udd_id, $param_order = 'updated_at', $imltd = 'is_lulus_imltd', $kgd = null);
        // $kantongBelumKgd_last_30_days   = ManajemenKantong::getData30Days($status_kantongs = 3, $status_kantong_item = 3, $petugas_udd_id, $param_order = 'updated_at', $imltd = null, $kgd = 'is_konfirmasi_golongan_darah');
        // $kantongRelease_last_1_years    = $this->DashboardUtil->getDataLast1Years(9, $petugas_udd_id, 'updated_at');                                                                                                            //param, status id 9 release

        // $kantongLogistik   = ManajemenKantong::getKantong($status_kantongs = 1,$status_kantong_item = 1, $petugas_udd_id, $imtld = null, $kgd = null);
        // $kantongAftap      =  ManajemenKantong::where('kantong_items.status_id', '=', 2)
        //                         ->where('kantong_items.is_pemindahan_aftap', '=', 1)
        //                         ->where('kantongs.status_id', '=', 1)
        //                         ->where('kantong_items.unit_donor_darah_id', Auth::user()->petugas->unit_donor_darah_id)
        //                         ->join('kantong_items', 'kantongs.id', 'kantong_items.kantong_id')
        //                         ->groupBy('kantong_id')
        //                         ->get();
        // $kantongBelumImltd =  ItemKantongs::selectRaw('
        //                     kantong_items.id,
        //                     kantong_items.no_kantong,
        //                     kantong_items.kantong_id
        //                     ')
        //                     ->leftjoin('hasil_imltds', 'hasil_imltds.kantong_item_id','=','kantong_items.id')
        //                     ->join('kantongs', 'kantongs.id','kantong_items.kantong_id')
        //                     ->where('hasil_imltds.id',null)
        //                     ->where('kantongs.status_id',3)
        //                     ->where('kantong_items.is_sah', 1 )
        //                     ->whereNull('is_lulus_imltd')
        //                     ->where('kantong_items.unit_donor_darah_id', Auth::user()->petugas->unit_donor_darah_id)
        //                     ->groupBy('kantong_items.kantong_id')->orderBy('kantong_items.created_at', 'asc')->get();
        // $kantongBelumKgd   = ManajemenKantong::getKantong($status_kantongs = 3,$status_kantong_item = null, $petugas_udd_id, $imltd = null, $kgd = 'is_konfirmasi_golongan_darah');
        // $belum_aftap       = ManajemenKantong::getKantong($status_kantongs = 1,$status_kantong_item = 11, $petugas_udd_id, $imltd = null, $kgd = null);

        $data = [
            //bawaan
            'title'             => $this->title,
            'route'             => $this->route,
            // 'kantongLogistik'   => count($kantongLogistik),
            // 'kantongAftap'      => count($kantongAftap),
            // 'kantongBelumImltd' => count($kantongBelumImltd),
            // 'kantongBelumKgd'   => count($kantongBelumKgd),
            // 'count_logistik'    => $kantongLogistik,
            // 'count_aftap'       => $kantongAftap,
            // 'belum_aftap'       => $belum_aftap,
            // 'jenis_kantong'     => MasterJenisKantong::All(),
            // 'master_reagen'     => Reagen::where('unit_donor_darah_id', Auth::user()->petugas->unit_donor_darah_id)->get(),
            // 'reagens'           => Reagens::where('reagens.unit_donor_darah_id', Auth::user()->petugas->unit_donor_darah_id)
            //                     ->join('master_reagens', 'reagens.master_reagen_id', 'master_reagens.id')
            //                     ->get(),
            // 'merk_reagen' => MerkReagen::all(),
        ];
        // dd($data['reagens']);
        return view($this->route . 'index', $data);
    }
}
