<?php

namespace App\Http\Controllers\User;

use Alert;
use App\Http\Controllers\Controller;
use App\Repositories\User\PenyelenggaraSeminarRepository;
use Crypt;
use Illuminate\Http\Request;

class PenyelenggaraanSeminarController extends Controller
{
    private $penyelenggaraseminarRepo;

    public function __construct(PenyelenggaraSeminarRepository $penyelenggaraseminarRepo)
    {
        $this->penyelenggaraseminarRepo = $penyelenggaraseminarRepo;
    }

    public function index()
    {
        //
        $menu = 'penyelenggaraseminar';
        $penyelenggaraseminar = $this->penyelenggaraseminarRepo->get();

        $data = [
            'penyelenggaraseminar' => $penyelenggaraseminar,
            'menu' => $menu
        ];
        return view('user.penyelenggara.index', $data);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
        return view('user.penyelenggara.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
        $data = $request->except('_token');
        $data['user_id'] = auth()->user()->id;
        $penyelenggaraseminar = $this->penyelenggaraseminarRepo->store($data);

        $data = [
            'penyelenggaraseminar' => $penyelenggaraseminar->id,
        ];

        Alert::success('Berhasil', 'Kontrak Kerja berhasil disimpan');

        return redirect()->route('penyelenggaraseminar.index', $data);
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
        $model = $this->penyelenggaraseminarRepo->findId(null, Crypt::decrypt($id));
        $this->penyelenggaraseminarRepo->destroy($model);

        Alert::success('Data berhasil dihapus')->persistent('Ok');

        return redirect()->route('penyelenggaraseminar.index');
    }
}
