<?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 CompanyTypeController extends Controller
{

    protected  $route = 'configurations.company-type';
    public function index() {

        $exampledata = [
            [
                'id' => 1,
                'typeId' => 11,
                'description' => 'บริษัทเน็ตเบย์ จำกัด มหาชน',
                'name' => 'Netbay'
            ]
            ,  
            [
                'id' => 2,
                'typeId' => 12,
                'description' => 'บริษัทเน็ตเบย์ จำกัด มหาชน3',
                'name' => 'Netbay2'
            ],
            [
                'id' => 3,
                'typeId' => 14,
                'description' => 'บริษัทเน็ตเบย์ จำกัด มหาชน3',
                'name' => 'Netbay3'
            ],
            [
                'id' => 4,
                'typeId' => 12,
                'description' => 'บริษัทเน็ตเบย์ จำกัด มหาชน4',
                'name' => 'Netbay4'
            ],
            [
                'id' => 5,
                'typeId' => 11,
                'description' => 'บริษัทเน็ตเบย์ จำกัด มหาชน5',
                'name' => 'Netbay5'
            ],
            ];
        
            $companyTypes = PaginatorController::paginate($exampledata, 3);
            $url = '/configurations/company-type';
            $route = $this->route;
            $companyTypes->withPath(  $url );
          
            $searchBy = [ 
                "name" => "Name", 
                "description" => "Description", 
            ];
            return view('configurations.company-types.index', compact('companyTypes', 'url', 'route', 'searchBy'));
    }


    public function create()
    {
        $route = $this->route;
        return view('configurations.company-types.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()
    {
        $companyType =   [
            'id' => 1,
            'typeId' => 11,
            'description' => 'บริษัทเน็ตเบย์ จำกัด มหาชน',
            'name' => 'Netbay'
        ];
        
        return view('configurations.company-types.edit', [
            'companyType' => $companyType,
            '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.'));
    }
}
