<?php

namespace App\Http\Controllers\User;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class KontrakKerjaController extends Controller
{
    private $kontrakkerjaRepo;

    public function __construct(KontrakKerjaRepository $kontrakkerjaRepo)
    {
        $this->kontrakkerjaRepo = $kontrakkerjaRepo;
    }

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

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

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

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

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

        Alert::success('Berhasil', 'Unit Bisnis berhasil disimpan');

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

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

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