<?php

namespace App\Http\Controllers\User;

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

class StafPendukungController extends Controller
{
    private $stafpendukungRepo;

    public function __construct(StafPendukungRepository $stafpendukungRepo)
    {
        $this->stafpendukungRepo = $stafpendukungRepo;
    }
    public function index()
    {
        //
        $menu = 'stafpendukung';
        $stafpendukung = $this->stafpendukungRepo->get();

        $data = [
            'stafpendukung' => $stafpendukung,
            'menu' => $menu
        ];

        return view('user.stafpendukung.index', $data);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
        return view('user.stafpendukung.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;
        $stafpendukung = $this->stafpendukungRepo->store($data);

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

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

        return redirect()->route('stafpendukung.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->stafpendukungRepo->findId(null, Crypt::decrypt($id));
        $this->stafpendukungRepo->destroy($model);

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

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