<?php

namespace App\Http\Livewire\Admin\Pages;

use App\Imports\StudentImport;
use App\Models\schclass;
use App\Models\Student;
use Illuminate\Http\Request;
use Livewire\Component;
use Maatwebsite\Excel\Facades\Excel;

class BulkStudent extends Component
{
    public $schClasses, $schclass_id;

    public function mount(){
        $schClasses = schclass::where('status', 1)->get();
        $this->schClasses = $schClasses;
    }

    public function templateUpload(Request $request){
        $request->validate([
            'studentlist' => 'required|mimes:csv',
        ]);
        Excel::import(new StudentImport, request()->file('studentlist'));
        return redirect()->back()->with('success', 'Students added successfully');
    }

    public function templateDownload(){
        return Excel::download(new Student, 'studentlist.csv', \Maatwebsite\Excel\Excel::CSV, [
            'Content-Type' => 'text/csv',
      ]);
    }
    public function render()
    {
        return view('livewire.admin.pages.bulk-student')->layout('layouts.adminApp');
    }
}
