<?php

namespace App\Http\Controllers\Configuration;

use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Redirect;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\User;
use App\Http\Controllers\Utils\PaginatorController;
use stdClass;

class MenuController extends Controller
{

    protected  $route = 'configurations.menu';
    public function index()
    {

        $exampledata = [
            [
                'id' => 1,
                'mId' => 6,
                'name' => 'User Management',
                'type' => 'S',
                'parentMenu' => 1,
                'order' => 4
            ],
            [
                'id' => 1,
                'mId' => 4,
                'name' => 'Menu Management',
                'type' => 'M',
                'parentMenu' => 1,
                'order' => 3
            ],
            [
                'id' => 1,
                'mId' => 8,
                'name' => 'Company Management',
                'type' => 'M',
                'parentMenu' => 1,
                'order' => 2
            ],
            [
                'id' => 1,
                'mId' => 9,
                'name' => 'Import Declaration',
                'type' => 'S',
                'parentMenu' => 1,
                'order' => 3
            ],  [
                'id' => 1,
                'mId' => 6,
                'name' => 'Vessel',
                'type' => 'S',
                'parentMenu' => 1,
                'order' => 5
            ],  [
                'id' => 1,
                'mId' => 26,
                'name' => 'Database',
                'type' => 'M',
                'parentMenu' => 3,
                'order' => 5
            ]
        ];

        $menues = PaginatorController::paginate($exampledata, 3);
        $url = '/configurations/menu';
        $route = $this->route;
        $menues->withPath($url);

        $searchBy = [ 
            "name" => "Name",
            "type" => "Type"
        ];
        return view('configurations.menues.index', compact('menues', 'url', 'route', 'searchBy'));
    }


    public function create()
    {
        $route = $this->route;
        return view('configurations.menues.create', compact('route'));
    }

    // public function store(Request $request)
    // {
    //     return redirect()->route('configurations.company')
    //         ->withSuccess(__('Company created successfully.'));
    //     }
    // }

    // public function show(User $user)
    // {
    //     return view('configurations.companyType.show', [
    //         'user' => $user
    //     ]);
    // }

    public function edit()
    {
        $menu =   [
            'id' => 1,
            'mId' => 26,
            'name' => 'Database',
            'type' => 'M',
            'parentMenu' => 3,
            'order' => 5
        ];

        return view('configurations.menues.edit', [
            'menu' => $menu,
            'route' => $this->route
        ]);
    }

    // public function update(Request $request, User $user)
    // {
    //     $rules = array(
    //         'name'       => 'required',
    //         'email'      => 'required|email',
    //     );
    //     $validator = Validator::make($request->all(), $rules);

    //     // process the login
    //     if ($validator->fails()) {
    //         return Redirect::back()
    //             ->withErrors($validator)
    //             ->withInput();
    //     } else {
    //         $user->name = $request->input('name');
    //         $user->email = $request->input('email');
    //         $user->save();

    //     return redirect()->route('configurations.company')
    //         ->withSuccess(__('Company updated successfully.'));
    //     }
    // }
    public function destroy()
    {
        // $user->delete();

        return redirect()->route('configurations.company')
            ->withSuccess(__('Company deleted successfully.'));
    }
}
