<?php

namespace App\Exports;

use App\Planestudios;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;

class PlanEstudiosExport implements FromView
{
    protected $claveOfi;
    protected $nombre;
    protected $reticula;
    protected $nivEsc;

    public function __construct(String $claveOfi, String $nombre, String $reticula, String $nivEsc)
    {
        $this->claveOfi = $claveOfi;
        $this->nombre = $nombre;
        $this->reticula = $reticula;
        $this->nivEsc = $nivEsc;
    }

    public function view(): View
    {
        if ($this->claveOfi == "" && $this->nombre == "" && $this->reticula == "" && $this->nivEsc == "") {
            return view("plan_estudios.tabla", ['planEst' => Planestudios::where('status_planest', '1')->get()]);
        } else {
            $PlanEst = Planestudios::where('status_planest', '1');
            if ($this->claveOfi != "") {
                $claveOfi = $this->claveOfi;
                $PlanEst = $PlanEst->where('claveOfi_planest', 'like', '%' . $claveOfi . '%');
            }
            if ($this->nombre != "") {
                $nombre = $this->nombre;
                $PlanEst = $PlanEst->where('nombre_planest', 'like', '%' . $nombre . '%');
            }
            if ($this->reticula != "") {
                $reticula = $this->reticula;
                $PlanEst = $PlanEst->where('reticula_planest', 'like', '%' . $reticula . '%');
            }
            if ($this->nivEsc != "") {
                $nivEsc = $this->nivEsc;
                $PlanEst = $PlanEst->where('nivesc_planest', 'like', '%' . $nivEsc . '%');
            }
            $PlanEst = $PlanEst->get();
            return view('plan_estudios.tabla', ['planEst' => $PlanEst]);
        }
    }
}
