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

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

        $exampledata = [
            [
                'id' => 1,
                'profile_name' => 'ABCD',
                'xml_user_id' => 'TH000123456789',
                'active' => 'Y'
            ],
            [
                'id' => 1,
                'profile_name' => 'AXRD',
                'xml_user_id' => 'GR000199996789',
                'active' => 'N'
            ],
            [
                'id' => 1,
                'profile_name' => 'AVRD',
                'xml_user_id' => 'TH000123556789',
                'active' => 'Y'
            ],
            [
                'id' => 1,
                'profile_name' => 'TCDE',
                'xml_user_id' => 'LA000135836789',
                'active' => 'N'
            ],
            [
                'id' => 1,
                'profile_name' => 'SEUV',
                'xml_user_id' => 'LG000121235989',
                'active' => 'Y'
            ],
        ];

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

        $searchBy = [
            "profile_name" => "Profile",
            "xml_user_id" => "XML User ID",
        ];
        return view('configurations.company-profiles.index', compact('companyProfiles', 'url', 'route', 'searchBy'));
    }


    public function create()
    {
        $route = $this->route;
        return view('configurations.company-profiles.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-profiles.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.'));
    }
}
