<?php

namespace App\Http\Controllers;

use App\CustomClass\Helper;
use App\Models\Client;
use Illuminate\Http\Request;
use URL;
use Illuminate\Support\Facades\Auth;
class InitializationController extends Controller
{
    public function initialize($account){
        $domain= Helper::get_domain(URL::to('/'));
        if(strtolower($account)=='www'){
            return redirect(env('APP_URL'));
        }
        $ac= Client::where('username',$account)->first();
        if($ac){
            $company_name= $ac->company_name;
        }else{
            echo "You are not registered! redirecting...";
            sleep(2);
            return redirect(env('APP_URL')."/registration");
        }
        if (Auth::check()) {
            if(Auth::user()->client->company_name==$company_name){
                return redirect(curl($account.".".$domain."/dashboard",false));
            }
        }

        return view('index')->with('company_name',$company_name);
    }
}
