<?php

namespace App\Exports;

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

class MateriaExport implements FromView
{
    protected $nombre;
    protected $clave;
    protected $planest;

    public function __construct(String $nombre, String $clave, String $planest)
    {
        $this->nombre = $nombre;
        $this->clave = $clave;
        $this->planest = $planest;
    }
    public function view(): View
    {
        if ($this->nombre == "" && $this->clave == "" && $this->planest == "") {
            return view("materia.tabla", ['mat' => Materia::where('status_mat', '1')->get()]);
        } else {
            $mat = Materia::where('status_mat', '1');
            if ($this->nombre != "") {
                $nombre = $this->nombre;
                $mat = $mat->where('nombre_mat', 'like', '%' . $nombre . '%');
            }
            if ($this->clave != "") {
                $clave = $this->clave;
                $mat = $mat->where('clave_mat', 'like', '%' . $clave . '%');
            }
            if ($this->planest != "") {
                $planest = $this->planest;
                $mat = $mat->where('cve_planest', 'like', '%' . $planest . '%');
            }
            $mat = $mat->get();
            return view('materia.tabla', ['mat' => $mat]);
        }
    }
}
