<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\MassDestroyLitmasSidangRequest;
use App\Http\Requests\StoreLitmasSidangRequest;
use App\Http\Requests\UpdateLitmasSidangRequest;
use App\IdentitasKlien;
use App\LitmasSidang;

class LitmasSidangController extends Controller
{
    public function index()
    {
        abort_unless(\Gate::allows('litmas_sidang_access'), 403);

        $litmasSidangs = LitmasSidang::all();

        return view('admin.litmasSidangs.index', compact('litmasSidangs'));
    }

    public function create()
    {
        abort_unless(\Gate::allows('litmas_sidang_create'), 403);

        $namas = IdentitasKlien::all()->pluck('nama', 'id')->prepend(trans('global.pleaseSelect'), '');

        return view('admin.litmasSidangs.create', compact('namas'));
    }

    public function store(StoreLitmasSidangRequest $request)
    {
        abort_unless(\Gate::allows('litmas_sidang_create'), 403);

        $litmasSidang = LitmasSidang::create($request->all());

        return redirect()->route('admin.litmas-sidangs.index');
    }

    public function edit(LitmasSidang $litmasSidang)
    {
        abort_unless(\Gate::allows('litmas_sidang_edit'), 403);

        $namas = IdentitasKlien::all()->pluck('nama', 'id')->prepend(trans('global.pleaseSelect'), '');

        $litmasSidang->load('nama');

        return view('admin.litmasSidangs.edit', compact('namas', 'litmasSidang'));
    }

    public function update(UpdateLitmasSidangRequest $request, LitmasSidang $litmasSidang)
    {
        abort_unless(\Gate::allows('litmas_sidang_edit'), 403);

        $litmasSidang->update($request->all());

        return redirect()->route('admin.litmas-sidangs.index');
    }

    public function show(LitmasSidang $litmasSidang)
    {
        abort_unless(\Gate::allows('litmas_sidang_show'), 403);

        $litmasSidang->load('nama');

        return view('admin.litmasSidangs.show', compact('litmasSidang'));
    }

    public function destroy(LitmasSidang $litmasSidang)
    {
        abort_unless(\Gate::allows('litmas_sidang_delete'), 403);

        $litmasSidang->delete();

        return back();
    }

    public function massDestroy(MassDestroyLitmasSidangRequest $request)
    {
        LitmasSidang::whereIn('id', request('ids'))->delete();

        return response(null, 204);
    }
}
