<?php
use App\Models\Followup;
use App\Models\Job;
use App\Models\Course;
use App\Models\Company;
use App\Models\Cookies;
use App\Models\Setting;
use Carbon\CarbonPeriod;
use App\Models\Candidate;
use Illuminate\Support\Str;
use msztorc\LaravelEnv\Env;
use Modules\Seo\Entities\Seo;
use Illuminate\Support\Carbon;
use Torann\GeoIP\Facades\GeoIP;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\File;
use Illuminate\Support\ViewErrorBag;
use Modules\Location\Entities\Country;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Storage;
use Modules\Language\Entities\Language;
use Stevebauman\Location\Facades\Location;
use Stichoza\GoogleTranslate\GoogleTranslate;
use AmrShawky\LaravelCurrency\Facade\Currency;
use Laravolt\Avatar\Facade as Avatar;
use App\Models\CourseCategory;
use function Clue\StreamFilter\fun;
use App\Models\Review;
use App\Models\Admin;
use App\Models\Source;
use App\Models\Countries;
use App\Http\Controllers\WhatsappTemplateController;
use App\Models\User;
use Illuminate\Support\Facades\Crypt;
use Spatie\Permission\Models\Permission;
use Illuminate\Support\Facades\DB;

// =====================================================
// ===================Image Function====================
// =====================================================
if (!function_exists('uploadImage')) {
    function uploadImage($file, $path)
    {
        $fileName = time() . '_' . uniqid() . '.' . $file->getClientOriginalExtension();
        $file->move(public_path('/uploads/' . $path . '/'), $fileName);

        return "uploads/$path/" . $fileName;
    }
}

/**
 * image delete
 *
 * @param string $image
 * @return void
 */
if (!function_exists('deleteFile')) {
    function deleteFile(?string $image)
    {
        $imageExists = file_exists($image);

        if ($imageExists) {
            if ($imageExists != 'backend/image/default.png') {
                @unlink($image);
            }
        }
    }
}

/**
 * image delete
 *
 * @param string $image
 * @return void
 */
if (!function_exists('deleteImage')) {
    function deleteImage(?string $image)
    {
        $imageExists = file_exists($image);
      
        if ($imageExists) {
            if ($image != 'backend/image/default.png') {
                // dd($image);
                @unlink($image);
            }
        }
    }
}

/**
 * @param UploadedFile $file
 * @param null $folder
 * @param string $disk
 * @param null $filename
 * @return false|string
 */
if (!function_exists('uploadOne')) {
    function uploadOne(UploadedFile $file, $folder = null, $disk = 'public', $filename = null)
    {
        $name = !is_null($filename) ? $filename : uniqid('FILE_') . dechex(time());

        return $file->storeAs(
            $folder,
            $name . "." . $file->getClientOriginalExtension(),
            $disk
        );
    }
}

/**
 * @param null $path
 * @param string $disk
 */
if (!function_exists('deleteOne')) {
    function deleteOne($path = null, $disk = 'public')
    {
        Storage::disk($disk)->delete($path);
    }
}

if (!function_exists('uploadFileToStorage')) {
    function uploadFileToStorage($file, string $path)
    {
        $file_name = $file->hashName();
        Storage::putFileAs($path, $file,  $file_name);
        return $path . '/' .  $file_name;
    }
}

if (!function_exists('uploadFileToPublic')) {
    function uploadFileToPublic($file, string $path)
    {
        if ($file && $path) {
            $url = $file->move('uploads/' . $path, $file->hashName());
        } else {
            $url = null;
        }

        return $url;
    }
}

// =====================================================
// ===================Env Function====================
// =====================================================
if (!function_exists('envReplace')) {
    function envReplace($name, $value)
    {
        $path = base_path('.env');
        if (file_exists($path)) {
            file_put_contents($path, str_replace(
                $name . '=' . env($name),
                $name . '=' . $value,
                file_get_contents($path)
            ));
        }

        if (file_exists(App::getCachedConfigPath())) {
            Artisan::call("config:cache");
        }
    }
}

if (!function_exists('setEnv')) {
    function setEnv($key, $value)
    {
        if ($key && $value) {
            $env = new Env();
            $env->setValue($key, $value);
        }

        if (file_exists(App::getCachedConfigPath())) {
            Artisan::call("config:cache");
        }
    }
}

if (!function_exists('checkSetEnv')) {

    function checkSetEnv($key, $value)
    {
        if ((env($key) != $value)) {
            setEnv($key, $value);
        }
    }
}

if (!function_exists('error')) {
    function error($name, $class = 'is-invalid')
    {
        $errors = session()->get('errors', app(ViewErrorBag::class));

        return $errors->has($name) ? $class : '';
    }
}

if (!function_exists('allowLaguageChanage')) {
    function allowLaguageChanage()
    {
        return Setting::first()->language_changing ? true : false;
    }
}

// ========================================================
// ===================Response Function====================
// ========================================================

/**
 * Response success data collection
 *
 * @param object $data
 * @param string $responseName
 * @return \Illuminate\Http\Response
 */
if (!function_exists('responseData')) {
    function responseData(?object $data, string $responseName = 'data')
    {
        return response()->json([
            'success' => true,
            $responseName => $data,
        ], 200);
    }
}

/**
 * Response success data collection
 *
 * @param string $msg
 * @return \Illuminate\Http\Response
 */
if (!function_exists('responseSuccess')) {
    function responseSuccess(string $msg = "Success")
    {
        return response()->json([
            'success' => true,
            'message' => $msg,
        ], 200);
    }
}

/**
 * Response error data collection
 *
 * @param string $msg
 * @param int $code
 * @return \Illuminate\Http\Response
 */
if (!function_exists('responseError')) {
    function responseError(string $msg = 'Something went wrong, please try again', int $code = 404)
    {
        return response()->json([
            'success' => false,
            'message' => $msg,
        ], $code);
    }
}

/**
 * Response success flash message.
 *
 * @param string $msg
 * @return \Illuminate\Http\Response
 */
if (!function_exists('flashSuccess')) {
    function flashSuccess(string $msg)
    {
        session()->flash('success', $msg);
    }
}


/**
 * Response error flash message.
 *
 * @param string $msg
 * @return \Illuminate\Http\Response
 */
if (!function_exists('flashError')) {
    function flashError(string $message = null)
    {
        if (!$message) {
            $message = __('something_went_wrong');
        }

        return session()->flash('error', $message);
    }
}

/**
 * Response warning flash message.
 *
 * @param string $msg
 * @return \Illuminate\Http\Response
 */
if (!function_exists('flashWarning')) {
    function flashWarning(string $message = null, bool $custom = false)
    {
        if (!$message) {
            $message = __('something_went_wrong');
        }

        if ($custom) {
            return session()->flash('warning', $message);
        } else {
            return session()->flash('warning', $message);
        }
    }
}

// ========================================================
// ===================Others Function====================
// ========================================================
if (!function_exists('setting')) {
    function setting($fields = null, $append = false)
    {
        if ($fields) {
            $type = gettype($fields);

            if ($type == 'string') {
                $data = $append ? Setting::first($fields) : Setting::value($fields);
            } elseif ($type == 'array') {
                $data = Setting::first($fields);
            }
        } else {
            $data = Setting::first();
        }

        if ($append) {
            $data = $data->makeHidden(['dark_logo_url', 'light_logo_url', 'favicon_image_url']);
        }

        return $data;
    }
}

if (!function_exists('autoTransLation')) {
    function autoTransLation($lang, $text)
    {
        $tr = new GoogleTranslate($lang);
        $afterTrans = $tr->translate($text);
        return $afterTrans;
    }
}

/**
 * user permission check
 *
 * @param string $permission
 * @return boolean
 */
if (!function_exists('userCan')) {
    function userCan($permission)
    {
       
    //    $users = auth('admin')->user();
        // if(@$users->user_wise_permission == 1){
        //    $permissions = Permission::where('name', $permission)->first();
        // //    dd($permissions->id);
        //    $modelPermissions = DB::table('model_has_permissions')
        //    ->where('permission_id', $permissions->id)
        //    ->where('model_id', $users->id)->first();
            
        //     if(@$modelPermissions->permission_id){
        //         return true;
        //     }else{
        //         return false;
        //     }

        // }
        $users = auth('admin')->user();
        if (@$users->user_wise_permission == 1) {
            $permissions = Permission::where('name', $permission)->first();

            if ($permissions) {
                $modelPermissions = DB::table('model_has_permissions')
                    ->where('permission_id', $permissions->id)
                    ->where('model_id', $users->id)->first();

                if ($modelPermissions && @$modelPermissions->permission_id) {
                    return true;
                } else {
                    return false;
                }
            }
        }
        return auth('admin')->user()->can($permission);
    }
}

if (!function_exists('pdfUpload')) {
    function pdfUpload(?object $file, string $path): string
    {
        $filename = time() . '.' . $file->extension();
        $filePath = public_path('uploads/' . $path);
        $file->move($filePath, $filename);

        return $filePath . $filename;
    }
}

if (!function_exists('remainingDays')) {

    function remainingDays($deadline)
    {
        $now = Carbon::now();
        $cDate = Carbon::parse($deadline);
        return $now->diffInDays($cDate);
    }
}

if (!function_exists('jobStatus')) {
    function jobStatus($deadline)
    {
        $now = Carbon::now();
        $cDate = Carbon::parse($deadline);

        if ($now->greaterThanOrEqualTo($cDate)) {
            return 'Expire';
        } else {
            return 'Active';
        }
    }
}

if (!function_exists('socialMediaShareLinks')) {

    function socialMediaShareLinks(string $path, string $provider)
    {
        switch ($provider) {
            case 'facebook':
                $share_link = 'https://www.facebook.com/sharer/sharer.php?u=' . $path;
                break;
            case 'twitter':
                $share_link = 'https://twitter.com/intent/tweet?text=' . $path;
                break;
            case 'pinterest':
                $share_link = 'http://pinterest.com/pin/create/button/?url=' . $path;
                break;
        }
        return $share_link;
    }
}

if (!function_exists('livejob')) {

    function livejob()
    {
        $jobs = Job::withoutEdited()->openPosition();

        $selected_country = session()->get('selected_country');

        if ($selected_country && $selected_country != null && $selected_country != 'all') {
            $country = selected_country()->name;
            $jobs->where('country', 'LIKE', "%$country%");
        } else {

            $setting = Setting::first();
            if ($setting->app_country_type == 'single_base') {
                if ($setting->app_country) {

                    $country = Country::where('id', $setting->app_country)->first();
                    if ($country) {
                        $jobs->where('country', 'LIKE', "%$country->name%");
                    }
                }
            }
        }

        return $jobs->count();
    }
}

if (!function_exists('companies')) {
   
    function companies()
    {
        return 0;
        // $companies = Company::count();
        // return $companies;
    }
}

if (!function_exists('newjob')) {

    function newjob()
    {
        $newjobs = Job::where('status', 'active')->where('created_at', '>=', Carbon::now()->subDays(7)->toDateString())->count();
        return $newjobs;
    }
}

if (!function_exists('candidate')) {
    function candidate()
    {
        $candidates = Candidate::count();
        return $candidates;
    }
}
if (!function_exists('linkActive')) {
    function linkActive($route, $class = 'active')
    {
        return request()->routeIs($route) ? $class : '';
    }
}

if (!function_exists('candidateNotifications')) {
    function candidateNotifications()
    {
        return auth()->user()->notifications()->take(6)->get();
    }
}

if (!function_exists('candidateNotificationsCount')) {

    function candidateNotificationsCount()
    {

        return auth()->user()->notifications()->count();
    }
}

if (!function_exists('candidateUnreadNotifications')) {

    function candidateUnreadNotifications()
    {
        return auth()->user()->unreadNotifications()->count();
    }
}

if (!function_exists('companyNotifications')) {

    function companyNotifications()
    {

        return auth()->user()->notifications()->take(6)->get();
    }
}

if (!function_exists('companyNotificationsCount')) {
    function companyNotificationsCount()
    {
        return auth()->user()->notifications()->count();
    }
}

if (!function_exists('companyUnreadNotifications')) {

    function companyUnreadNotifications()
    {

        return auth()->user()->unreadNotifications()->count();
    }
}

if (!function_exists('defaultCurrencySymbol')) {
    function defaultCurrencySymbol()
    {
        return config('zakirsoft.app_currency_symbol');
    }
}

if (!function_exists('currencyAmountShort')) {

    function currencyAmountShort($amount)
    {
        $num = $amount * getCurrencyRate();
        $units = ['', 'K', 'M', 'B', 'T'];
        for ($i = 0; $num >= 1000; $i++) {
            $num /= 1000;
        }

        return round($num, 0) . $units[$i];
    }
}

/**
 * Remove the decimal numbers and shorten
 *
 * @param   number $amount
 * @return  string
 */
if (!function_exists('zeroDecimal')) {
    function zeroDecimal($amount)
    {
        $units = ['', 'K', 'M', 'B', 'T'];
        for ($i = 0; $amount >= 1000; $i++) {
            $amount /= 1000;
        }

        return round($amount, 0) . $units[$i];
    }
}

/**
 * Currency exchange
 *
 * @param $amount
 * @param $from
 * @param $to
 * @param $round
 *
 * @return number
 */
if (!function_exists('currencyExchange')) {
    function currencyExchange($amount, $from = null, $to = null, $round = 2)
    {
        $from = currentCurrencyCode();
        $to = config('zakirsoft.currency', 'USD');

        return AmrShawky\Currency::convert()
            ->from($from)
            ->to($to)
            ->amount($amount)
            ->round($round)
            ->get();
    }
}

if (!function_exists('currencyConversion')) {
    function currencyConversion($amount, $from = null, $to = null, $round = 2)
    {
        $from = $from ?? config('zakirsoft.currency');
        $to = $to ?? 'USD';

        if ($amount) {
            return Currency::convert()
                ->from($from)
                ->to($to)
                ->amount($amount)
                ->round($round)
                ->get();
        }

        return 0;
    }
}

/**
 * Currency rate store in session
 *
 * @return void
 */
if (!function_exists('currencyRateStore')) {
    function currencyRateStore()
    {
        if (session()->has('currency_rate')) {
            $currency_rate = session('currency_rate');
            $from = config('zakirsoft.currency');
            $to = currentCurrencyCode();

            if ($currency_rate['from'] != $from || $currency_rate['to'] != $to) {
                $rate = AmrShawky\Currency::convert()->from($from)->to($to)->amount(1)->get();
                session(['currency_rate' => ['from' => $from, 'to' => $to, 'rate' => $rate]]);
            }
        } else {
            $from = config('zakirsoft.currency');
            $to = currentCurrencyCode();

            $rate = AmrShawky\Currency::convert()->from($from)->to($to)->amount(1)->get();
            session(['currency_rate' => ['from' => $from, 'to' => $to, 'rate' => $rate]]);
        }
    }
}

/**
 * Get currency rate
 *
 * @return number
 */
if (!function_exists('getCurrencyRate')) {
    function getCurrencyRate()
    {
        if (session()->has('currency_rate')) {
            $currency_rate = session('currency_rate');
            $rate = $currency_rate['rate'];
            return $rate;
        } else {
            return 1;
        }
    }
}

/**
 * Get current Currency
 *
 * @return object
 */
if (!function_exists('currentCurrency')) {
    function currentCurrency()
    {
        return session('current_currency') ?? Modules\Currency\Entities\Currency::where('code', config('jobpilot.currency'))->first();
    }
}

/**
 * Get current Currency code
 *
 * @return string
 */
if (!function_exists('currentCurrencyCode')) {
    function currentCurrencyCode()
    {
        if (session()->has('current_currency')) {
            $currency = session('current_currency');
            return $currency->code;
        }

        return config('zakirsoft.currency');
    }
}

if (!function_exists('currentLanguage')) {

    function currentLanguage()
    {
        return session('current_lang');
    }
}

if (!function_exists('langDirection')) {

    function langDirection()
    {
        return session('current_lang')->direction ?? Language::where('code', config('zakirsoft.default_language'))->value('direction');
    }
}

if (!function_exists('metaData')) {

    function metaData($page)
    {
        $current_language = currentLanguage(); // current session language
        $language_code = $current_language ? $current_language->code : 'en'; // language code or default one
        $page = Seo::where('page_slug', $page)->first(); // get page
        $exist_content = $page->contents()->where('language_code', $language_code)->first(); // get page content orderBy page && language
        $content = '';
        if ($exist_content) {
            $content = $exist_content;
        } else {
            $content = $page->contents()->where('language_code', 'en')->first();
        }

        return $content; // return response
    }
}

if (!function_exists('storePlanInformation')) {

    function storePlanInformation()
    {
        session()->forget('user_plan');
        session(['user_plan' => auth('user')->user()->company->userPlan]);
    }
}

if (!function_exists('formatTime')) {

    function formatTime($date, $format = 'F d, Y H:i A')
    {
        return Carbon::parse($date)->format($format);
    }
}

if (!function_exists('inspireMe')) {

    function inspireMe()
    {
        Artisan::call('inspire');
        return Artisan::output();
    }
}

if (!function_exists('getUnsplashImage')) {
    function getUnsplashImage()
    {
        $url = "https://source.unsplash.com/random/1920x1280/?park,mountain,ocean,sunset,travel";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Must be set to true so that PHP follows any "Location:" header
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        $a = curl_exec($ch); // $a will contain all headers
    }
}

if (!function_exists('adminNotifications')) {
    function adminNotifications()
    {
        return auth('admin')->user()->notifications()->take(10)->get();
    }
}

if (!function_exists('adminUnNotifications')) {

    function adminUnNotifications()
    {
        return auth('admin')->user()->unreadNotifications()->count();
    }
}

if (!function_exists('checkMailConfig')) {

    function checkMailConfig()
    {
        $status = config('mail.mailers.smtp.transport') && config('mail.mailers.smtp.host') && config('mail.mailers.smtp.port') && config('mail.mailers.smtp.username') && config('mail.mailers.smtp.password') && config('mail.mailers.smtp.encryption') && config('mail.from.address') && config('mail.from.name');

        !$status ? flashError(__('mail_not_sent_for_the_reason_of_incomplete_mail_configuration')) : '';

        return $status ? 1 : 0;
    }
}

if (!function_exists('openJobs')) {

    function openJobs()
    {
        return Job::where('status', 'active')->where('deadline', '>=', Carbon::now()->toDateString())->count();
    }
}

if (!function_exists('updateMap')) {
    function updateMap($data)
    {
        $location = session()->get('location');

        if ($location) {
            $region = array_key_exists("region", $location) ? $location['region'] : '';
            $country = array_key_exists("country", $location) ? $location['country'] : '';
            $address = Str::slug($region . '-' . $country);

            $data->update([
                'address' => $address,
                'neighborhood' => array_key_exists("neighborhood", $location) ? $location['neighborhood'] : '',
                'locality' => array_key_exists("locality", $location) ? $location['locality'] : '',
                'place' => array_key_exists("place", $location) ? $location['place'] : '',
                'district' => array_key_exists("district", $location) ? $location['district'] : '',
                'postcode' => array_key_exists("postcode", $location) ? $location['postcode'] : '',
                'region' => array_key_exists("region", $location) ? $location['region'] : '',
                'country' => array_key_exists("country", $location) ? $location['country'] : '',
                'long' => array_key_exists("lng", $location) ? $location['lng'] : '',
                'lat' => array_key_exists("lat", $location) ? $location['lat'] : '',
            ]);
            session()->forget('location');
        }

        return true;
    }
}

if (!function_exists('get_str')) {
    function get_str($str)
    {
        $str_get = Str::slug($str);
        return $str_get;
    }
}

if (!function_exists('selected_country')) {
    function selected_country()
    {
        $selected_country = session()->get('selected_country');
        $country = Country::find($selected_country);

        return $country;
    }
}

if (!function_exists('get_file_size')) {
    function get_file_size($file)
    {
        if (file_exists($file)) {
            $file_size = File::size($file) / 1024  / 1024;
            return round($file_size, 4) . ' MB';
        }

        return '0 MB';
    }
}


/**
 * Increases or decreases the brightness of a color by a percentage of the current brightness.
 *
 * @param   string  $hexCode        Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF`
 * @param   float   $adjustPercent  A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker.
 *
 * @return  string
 *
 * @author  maliayas
 */
if (!function_exists('adjustBrightness')) {
    function adjustBrightness($hexCode, $adjustPercent)
    {
        $hexCode = ltrim($hexCode, '#');

        if (strlen($hexCode) == 3) {
            $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2];
        }

        $hexCode = array_map('hexdec', str_split($hexCode, 2));

        foreach ($hexCode as &$color) {
            $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color;
            $adjustAmount = ceil($adjustableLimit * $adjustPercent);

            $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT);
        }

        return '#' . implode($hexCode);
    }
}

if (!function_exists('current_country_code')) {
    function current_country_code()
    {
        if (selected_country()) {
            $country_code = selected_country()->sortname;
        } else {
            $setting = Setting::first();

            if ($setting->app_country_type != 'multiple_base') {
                $country_code = Country::find($setting->app_country)->sortname;
            } else {
                return '';
            }
        }

        return $country_code;
    }
}

/**
 * Set ip wise country, currency and language
 *
 * @return  void
 */
if (!function_exists('setLocationCurrency')) {
    function setLocationCurrency()
    {
        $ip = request()->ip();
        // $ip = '103.102.27.0'; // Bangladesh
        // $ip = '105.179.161.212'; // Mauritius
        // $ip = '197.246.60.160'; // Egypt
        // $ip = '107.29.65.61'; // United States"
        // $ip = '46.39.160.0'; // Czech Republic
        // $ip = "94.112.58.11"; // Czechia



        if ($ip && $ip != '127.0.0.1') {
            $geo = GeoIP::getLocation($ip);

            // Set the currency
            if (!session()->has('current_currency')) {
                $currency = Modules\Currency\Entities\Currency::where('code', $geo->currency)->first() ?? Modules\Currency\Entities\Currency::where('code', config('zakirsoft.currency'))->first();

                if ($currency) {
                    session(['current_currency' => $currency]);
                } else {
                    session(['current_currency' => Modules\Currency\Entities\Currency::first()]);
                }
            }

            // Set the language
            if (!session()->has('current_lang')) {
                $path = base_path('public/json/country_currency_language.json');
                $country_language_currency = json_decode(file_get_contents($path), true);
                $key = array_search($geo->iso_code, array_column($country_language_currency, 'code'));
                $country_language_currency = $country_language_currency[$key];
                $lang_code = $country_language_currency['language']['code'];
                $language = Language::where('code', $lang_code)->first();

                if ($language) {
                    session(['current_lang' => $language]);
                } else {
                    session(['current_lang' => Language::where('code', config('zakirsoft.default_language'))->first()]);
                }
            }

            // Set the country
            // $selected_country = session('country_code');
            $selected_country = session('selected_country');

            if (!session()->has('selected_country')) {
                // if (!session()->has('country_code')) {
                if ($selected_country != 'all') {
                    if ($ip) {
                        $current_user_data = Location::get($ip);
                    }
                    if ($current_user_data) {
                        $user_country = $current_user_data->countryName;
                        if ($user_country) {
                            $database_country = Country::where('name', $user_country)->where('status', 1)->first();
                            if ($database_country) {
                                // $selected_country = session()->get('country_code');
                                $selected_country = session()->get('selected_country');
                                if (!$selected_country) {
                                    // session()->put('country_code', $database_country->sortname);
                                    session()->put('selected_country', $database_country->id);
                                    return true;
                                }
                            }
                        }
                    }
                }
            } else {
                // $selected_country = session('country_code');
                $selected_country = session('selected_country');
            }
        }
    }
}

/**
 * @param String $date
 * Date format
 */
if (!function_exists('getLanguageByCode')) {
    function getLanguageByCode($code)
    {
        return Language::where('code', $code)->value('name');
    }
}

/**
 * @param String $date
 * Date format
 */
if (!function_exists('currentLangCode')) {
    function currentLangCode()
    {
        if (session('current_lang')) {
            return session('current_lang')->code;
        } else {
            return Language::where('code', config('zakirsoft.default_language'))->value('code');
        }
    }
}

/**
 * @param String $date
 * Date format
 */
if (!function_exists('dateFormat')) {
    function dateFormat($date, $format = 'F Y')
    {
        return \Carbon\Carbon::createFromFormat($format, $date)->toDateTimeString();
    }
}

/* Currency position
 *
 * @param String $date
 */
if (!function_exists('currencyPosition')) {
    function currencyPosition($amount)
    {
        $symbol = config('jobpilot.currency_symbol');
        $position = config('jobpilot.currency_position');

        if ($position == 'left') {
            return $symbol . ' ' . $amount;
        } else {
            return $amount . ' ' . $symbol;
        }

        return $amount;
    }
}

/**
 * Authenticate candidate
 */
if (!function_exists('currentCandidate')) {
    function currentCandidate()
    {
        return auth('user')->user()->candidate;
    }
}

/**
 * Authenticate candidate
 */
if (!function_exists('currentCompany')) {
    function currentCompany()
    {
        return auth('user')->user()->company;
    }
}

/* Get format number for currency
 *
 * @param String $path
 */
if (!function_exists('getFormattedNumber')) {
    function getFormattedNumber(
        $value,
        $currencyCode = 'USD',
        $locale = 'en_US',
        $style = NumberFormatter::DECIMAL,
        $precision = 0,
        $groupingUsed = true
    ) {
        if (session()->has('current_lang')) {
            $locale = currentLanguage()->code . '_us' ?? $locale;
        }

        $currencyCode = currentCurrencyCode();
        $formatter = new NumberFormatter($locale, $style);
        $formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, $precision);
        $formatter->setAttribute(NumberFormatter::GROUPING_USED, $groupingUsed);
        if ($style == NumberFormatter::CURRENCY) {
            $formatter->setTextAttribute(NumberFormatter::CURRENCY_CODE, $currencyCode);
        }

        return $formatter->format($value * getCurrencyRate());
    }
}

/**
 * Checks jobs status like highlighted or featured
 * @param string $date
 * @return boolean
 *
 */
if (!function_exists('isFuture')) {
    function isFuture($date = null): bool
    {

        if ($date) {
            return Carbon::parse($date)->isFuture();
        }

        return false;
    }
}

if (!function_exists("getEmailTemplateFormatFlagsByType")) {
    function getEmailTemplateFormatFlagsByType($type)
    {
        return \App\Http\Controllers\Admin\EmailTemplateController::getFormatterByType($type) ?? [];
    }
}

if (!function_exists("getFormattedTextByType")) {
    function getFormattedTextByType($type, $data = null)
    {
        return \App\Http\Controllers\Admin\EmailTemplateController::getFormattedTextByType($type, $data);
    }
}

/**
 * get formatted mail template
 * @param string $type
 * @param mixed $data
 * @return string formatted mail content
 */
if (!function_exists("getFormattedMail")) {
    function getFormattedMail($type, $data)
    {
        return \App\Http\Controllers\Admin\EmailTemplatesController::formatMessage($type, $data);
    }
}

/**
 * get list of available format flags
 * @param string $type
 * @return array list of available format flags
 */
if (!function_exists("getFormatFlagsByType")) {
    function getFormatFlagsByType($type)
    {
        return \App\Http\Controllers\Admin\EmailTemplatesController::getFormatByType($type)["search"] ?? [];
    }
}

/**
 * Create avatar image
 *
 * @param string $name
 * @param string $path
 * @return boolean
 *
 */
if (!function_exists('createAvatar')) {
    function createAvatar($name = null, $path = 'uploads/images'): string
    {
        if (!File::exists($path)) {
            File::makeDirectory($path, $mode = 0777, true, true);
        }

        $name = $name ? $name . '_' . time() . '_' . uniqid() : time() . '_' . uniqid();
        Avatar::create($name)->save("{$path}/{$name}.png");

        return "{$path}/{$name}.png";
    }
}


if (!function_exists('currencyValue')) {
    function currencyValue($amount)
    {
        if ($amount) {
            $inrValue = $amount / 100000;
            $inrFormatted = '₹' . number_format($inrValue, 2) . ' L';
            return $inrFormatted;
        }
        return '₹0';
    }
}
if (!function_exists('courseDuration')) {
    function courseDuration($id)
    {
        if (!empty($id)) {
            $minMonth = Course::where(['durationUnit' => 'months', 'course_categories_id' => $id])->whereNotNull('durationValue')->where('durationValue', '>', 0)->min('durationValue');
            $minValue = @$minMonth . 'M';
            if (empty($minMonth)) {
                $minMonth = Course::where(['durationUnit' => 'years', 'course_categories_id' => $id])->whereNotNull('durationValue')->where('durationValue', '>', 0)->min('durationValue');
                $minValue = $minMonth . 'Y';
            }
            $maxYear = Course::where(['durationUnit' => 'years', 'course_categories_id' => $id])->whereNotNull('durationValue')->where('durationValue', '>', 0)->max('durationValue');
            $maxValue = @$maxYear . 'Y';
            if (empty($maxYear)) {
                $maxYear = Course::where(['durationUnit' => 'months', 'course_categories_id' => $id])->whereNotNull('durationValue')->where('durationValue', '>', 0)->max('durationValue');
                $maxValue = $maxYear . 'M';
            }

            return $minValue . ' - ' . $maxValue;
        }
        return  '';
    }
}
if (!function_exists('categoryId')) {
    function categoryId($name)
    {
        if (!empty($name)) {
            $course = CourseCategory::where('name', $name)->first();
            return !empty($course) ? $course->id : '';
        }
        return '';
    }
}
if (!function_exists('formatNumber')) {
    function formatNumber($number)
    {
        $suffixes = ['', 'K', 'M', 'B', 'T'];
        $suffixIndex = 0;

        while ($number >= 1000 && $suffixIndex < count($suffixes) - 1) {
            $number /= 1000;
            $suffixIndex++;
        }

        return number_format($number, 0) . '' . $suffixes[$suffixIndex] . '+';
    }
}
if (!function_exists('rankFormat')) {
    function rankFormat($number)
    {
        if (is_numeric($number)) {
            $lastDigit = intval($number) % 10;
            $lastTwoDigits = intval($number) % 100;

            if ($lastTwoDigits >= 11 && $lastTwoDigits <= 13) {
                return $number . 'th';
            }

            switch ($lastDigit) {
                case 1:
                    return $number . '<sup>st</sup>';
                case 2:
                    return $number . '<sup>nd</sup>';
                case 3:
                    return $number . '<sup>rd</sup>';
                default:
                    return $number . '<sup>th</sup>';
            }
        }

        return $number;
    }
}
if (!function_exists('dateMonthFormat')) {
    function dateMonthFormat($d)
    {
        return date('d M, Y', strtotime($d));
    }
}

if (!function_exists('dateMonthFormat')) {
    function dateMonthFormat($d)
    {
        return date('d M, Y', strtotime($d));
    }
}
if (!function_exists('dateMonthTimeFormat')) {
    function dateMonthTimeFormat($d)
    {
        return date('d M, y h:i A', strtotime($d));
    }
}

if (!function_exists('dateMonthTimeFormatOne')) {
    function dateMonthTimeFormatOne($d)
    {
        return date('d', strtotime($d));
    }
}



if (!function_exists('TimeShowHourseMiniteAmPm')) {
    function TimeShowHourseMiniteAmPm($d)
    {
        return date('h:i:A', strtotime($d));
    }
}


if (!function_exists('ratingCalculate')) {
    function ratingCalculate($rating, $total_rating)
    {
        if($rating == 0 && $total_rating == 0){
            return $ratingOutOf5 = 0;
            
        }else{
            $ratingOutOf5 = round(($rating / $total_rating) * 5, 1);
            return $ratingOutOf5;
        }
        
     
    }
}

if (!function_exists('GetNameByZenId')) {
    function GetNameByZenId($id)
    {
       $data = Admin::where('zen_id',$id)->first();
       if($data != null){
        return $data['name'];
       }else{
        return "--";
       }
    }
}


if (!function_exists('reviewdata')) {
    function reviewdata($tt)
    {
     $review = Review::all();
     $countRating = $review->sum('star_rating');
     $total = $review->count('star_rating');
     $totalRating = $total*5;
     $data['total'] = $total*2;
     $data['reviewData'] =  ratingCalculate($countRating , $totalRating); 
     if($tt == "review"){
        return   $data['total'];
     }else if($tt = 'rating'){
        return  $data['reviewData'];
     }else{
        return $data;
     }
    
    }
}


if (!function_exists('romanNumeral')) {
function romanNumeral($number)
{
    $roman = '';
    $map = [
        'M' => 1000,
        'CM' => 900,
        'D' => 500,
        'CD' => 400,
        'C' => 100,
        'XC' => 90,
        'L' => 50,
        'XL' => 40,
        'X' => 10,
        'IX' => 9,
        'V' => 5,
        'IV' => 4,
        'I' => 1
    ];

    foreach ($map as $romanNumeral => $value) {
        while ($number >= $value) {
            $roman .= $romanNumeral;
            $number -= $value;
        }
    }

    return $roman;
}

}


if (!function_exists('isLighthouse')) {
    function isLighthouse()
    {
        $botRegexPattern = "(Cliqzbot|Lighthouse)";
        return preg_match("/{$botRegexPattern}/", $_SERVER['HTTP_USER_AGENT']);
    }
}

if (!function_exists('sendRegisterWhatsapp')) {
    function sendRegisterWhatsapp($data)
    {

        // dd($data);
        $controller = new WhatsappTemplateController;
        return $controller->send_whatsapp($data);

        //     $curl = curl_init();

        //     curl_setopt_array($curl, array(
        //         CURLOPT_URL => 'https://in-ccaas.ozonetel.com/api/v1/WhatsAppSendOzone/reply',
        //         CURLOPT_RETURNTRANSFER => true,
        //         CURLOPT_ENCODING => '',
        //         CURLOPT_MAXREDIRS => 10,
        //         CURLOPT_TIMEOUT => 0,
        //         CURLOPT_FOLLOWLOCATION => true,
        //         CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        //         CURLOPT_CUSTOMREQUEST => 'POST',
        //         CURLOPT_POSTFIELDS => '{
        //     "recipient":{"id":"'.$data['sendTo'].'"},
        //     "kookoo_id":"OZNTLWA:919773388140",
        //     "type": "template",
        //     "template": {
        //         "name": "login_notification_01",
        //         "language": "en",
        //         "parameters": 
        //         {
        //             "1":"'.$data['name'].'",
        //             "2":"'.$data['email'].'",
        //             "3":"'.$data['password'].'"
        //         }
        //     }
        // }',
        //         CURLOPT_HTTPHEADER => array(
        //             'Content-Type: application/json',
        //             'apikey: KK556a6e0479bd45587c89e93397d5303c',
        //             'Cookie: PHPSESSID=cbe516e6c90e58227977f80f4449a4e7'
        //         ),
        //     ));

        //     $response = curl_exec($curl);
        //     curl_close($curl);
        //     return $response;
    }
}


if (!function_exists('adminIdToNameGet')) {
    function adminIdToNameGet($id)
    {
        $admin_name = Admin::select('name')->where('id', $id)->first();
        if ($admin_name) {
            return $admin_name->name;
        } else {
            return '--';
        }
     
    }
}

if (!function_exists('countriesIdToNameGet')) {
    function countriesIdToNameGet($id)
    {
        $admin_name = Countries::select('name')->where('id', $id)->first();
        if ($admin_name) {
            return $admin_name->name;
        } else {
            return '--';
        }
     
    }
}


if (!function_exists('sourceToIcon')) {
    function sourceToIcon($name)
    {
        if($name){
            $source = Source::select('icon')->where('name', $name)->first();
            if (!empty(@$source->icon)) {
                return "<i class='$source->icon mr-1' data-toggle='tooltip' data-placement='top'
                title='$name'></i>";
            
            } else {
                return $name;
            } 

        }else{
            return '--';
        }
     
    }
}


if (!function_exists('sourceToIconWithCompaign_name')) {
    function sourceToIconWithCompaign_name($name,$campaign_name,$add_name)
    {
        if($name){

            $source = Source::select('icon')->where('name', $name)->first();
            if (!empty(@$source->icon)) {
                $tooltipTitle = "$name";
    
                if (!empty($campaign_name)) {
                    $tooltipTitle .= ", campaign: $campaign_name";
                }

                if (!empty($add_name)) {
                    $tooltipTitle .= ", Ad Name: $add_name";
                }
                $iconElement = "<i class='$source->icon mr-1' data-toggle='tooltip' data-placement='top' title='$tooltipTitle'></i>";
                
                return $iconElement;
             
            
            } else {
                return $name;
            } 

        }else{
            return '--';
        }
     
    }
}




// if (!function_exists('get_stages_array')) {
//     function get_stages_array() {
//         // include 'stageArray.php';
//         $array = array(
//             array('id' => '1', 'name' => 'Inquiry'),
//             array('id' => '2', 'name' => 'Counselling'),
//             array('id' => '3', 'name' => 'Documents Received'),
//             array('id' => '4', 'name' => 'Document pending'),
//             array('id' => '5', 'name' => 'Post Documentation Counselling'),
//             array('id' => '6', 'name' => 'Additional Documents required'),
//             array('id' => '7', 'name' => 'Application submitted'),
//             array('id' => '8', 'name' => 'Dropped'),
//             array('id' => '9', 'name' => 'Student Backed out'),
//             array('id' => '10', 'name' => 'Offer Issued - Conditional'),
//             array('id' => '11', 'name' => 'Initial Fee Deposit'),
//             array('id' => '12', 'name' => 'University Interview Pending'),
//             array('id' => '13', 'name' => 'University Interview Cleared'),
//             array('id' => '14', 'name' => 'Offer Issued - Unconditional'),
//             array('id' => '15', 'name' => 'Tuition Fee Deposit'),
//             array('id' => '16', 'name' => 'Admission Letter Pending'),
//             array('id' => '17', 'name' => 'Admission Letter Issued'),
//             array('id' => '18', 'name' => 'Visa Filed'),
//             array('id' => '19', 'name' => 'Visa Granted'),
//             array('id' => '20', 'name' => 'Admitted') 
//           );
//         return $array;
//     }
// }

// if (!function_exists('get_stages_array')) {
//     function get_stages_array() {
//         // include 'stageArray.php';
//         $array = array(
//             array('id' => '1', 'name' => 'Inquiry'),
//             array('id' => '2', 'name' => 'Counselling'),
//             array('id' => '3', 'name' => 'Documents Received'),
//             array('id' => '4', 'name' => 'Document pending'),
//             array('id' => '5', 'name' => 'University to be suggested'),
//             array('id' => '6', 'name' => 'Universities suggested'),
//             array('id' => '12', 'name' => 'Student backed out / Dropped'),
//             array('id' => '7', 'name' => 'Application ready to submit'),  
//             array('id' => '7', 'name' => 'Application submitted'),
//             array('id' => '11', 'name' => 'Application Rejected'),
//             array('id' => '10', 'name' => 'Admission Letter Pending'),
//             array('id' => '8', 'name' => 'Offer Issued Conditional / Unconditional'), 
//             array('id' => '9', 'name' => 'Initial Fee / Tuition Fee Deposit'),
//             // array('id' => '12', 'name' => 'University Interview Pending'),
//             // array('id' => '13', 'name' => 'University Interview Cleared'),
//             // array('id' => '17', 'name' => 'Admission Letter Issued'),
//             // array('id' => '18', 'name' => 'Visa Filed'),
//             // array('id' => '19', 'name' => 'Visa Granted'),
//             array('id' => '20', 'name' => 'Admitted'),




          
//           );
//         return $array;
//     }
// }


if (!function_exists('get_stages_array')) {
    function get_stages_array() {
        // include 'stageArray.php';
        $array = array(
            array('id' => '1', 'name' => 'Inquiry'),
            array('id' => '2', 'name' => 'Counselling'),
            // array('id' => '3', 'name' => 'Documents Received'),
            // array('id' => '4', 'name' => 'Document pending'),
            array('id' => '5', 'name' => 'University to be suggested'),
            array('id' => '6', 'name' => 'Universities suggested'),
            array('id' => '7', 'name' => 'Application ready to submit'), 
            array('id' => '8', 'name' => 'Application submitted'),
            array('id' => '9', 'name' => 'Application Rejected'),
            array('id' => '10', 'name' => 'Application resubmitted'),
            array('id' => '11', 'name' => 'Admission Letter Pending'),
            // array('id' => '12', 'name' => 'Conditional Offer Received'),
            // array('id' => '13', 'name' => 'Un-conditional Offer Received'),
            // array('id' => '14', 'name' => 'Offer Issued Conditional / Unconditional'), 
            array('id' => '15', 'name' => 'Initial Fee / Tuition Fee Deposit'),
            // array('id' => '12', 'name' => 'University Interview Pending'),
            // array('id' => '13', 'name' => 'University Interview Cleared'),
            // array('id' => '17', 'name' => 'Admission Letter Issued'),
            // array('id' => '18', 'name' => 'Visa Filed'),
            // array('id' => '19', 'name' => 'Visa Granted'),
            array('id' => '16', 'name' => 'Admitted'),
            array('id' => '17', 'name' => 'Visa In Process'),
            array('id' => '18', 'name' => 'Visa Accepted'),
            array('id' => '19', 'name' => 'Visa Rejected'),
            array('id' => '20', 'name' => 'Student backed out / Dropped'),
            array('id' => '21', 'name' => 'Work Visa'),
            array('id' => '22', 'name' => 'Student Defered'),
            // array('id' => '23', 'name' => 'Offer Issued Conditional'),
            // array('id' => '24', 'name' => 'Offer Issued Unconditional'),
            // array('id' => '25', 'name' => 'Offer Accepted'),
            // array('id' => '26', 'name' => 'Offer Rejected'),

            array('id' => '23', 'name' => 'Offer Issued'),
            // array('id' => '24', 'name' => 'Offer Issued Unconditional'),
            array('id' => '25', 'name' => 'Offer Accepted'),
            array('id' => '26', 'name' => 'Offer Rejected'),
            array('id' => '28', 'name' => 'Loan'),
            array('id' => '27', 'name' => 'Test Preparation'),
  
          );
        return $array;
    }
}

if (!function_exists('get_followup_type_array')) {
    function get_followup_type_array() {
        // include 'stageArray.php';
        $array = array(
            array('id' => '1', 'name' => 'Inbound Call'),
            array('id' => '2', 'name' => 'Outbound Call'),
            array('id' => '3', 'name' => 'Chat'),
            array('id' => '4', 'name' => 'Email')
          );
        return $array;
    }
}

// if (!function_exists('getAssignId')) {
//     function getAssignId()
//     {
//         $assignTo = User::where('role', 'candidate')
//         ->latest()
//         ->pluck('assign_to')
//         ->first();

//         $assignToAdmin = Admin::where('assign_lead', '1')
//         ->latest()
//         ->pluck('id')
//         ->toArray();
    
      
       
//         if($assignTo){
//             if (!empty($assignToAdmin)) {
            
//                 if($assignToAdmin > 0){
//                   $index_assignTo = array_search($assignTo, $assignToAdmin);
//                   $keys = array_keys($assignToAdmin);
//                   $lastKey = end($keys);

//                   if($index_assignTo < $lastKey){
//                     return $assignToAdmin[$index_assignTo+1];
//                   }else{
//                     return $assignToAdmin[0];
//                   }
                
//                 }else{
//                     return $assignToAdmin[0];
//                 }
//             }else{
//                 return 0;
//             }
           
//         }else{
//             if (!empty($assignToAdmin)) {
//                 return $assignToAdmin[0];
//             }else{
//                 return 0;
//             }
//         }
     
//     }
// }


if (!function_exists('getAssignIdByCountry')) {
    function getAssignIdByCountry($country_id)
    {
        
        $assignTo = User::where('role', 'candidate')
            ->latest()
            ->pluck('assign_to')
            ->first();
            // dd($assignTo);

        $assignToAdmin = Admin::where('assign_lead', '1')
            ->whereNotNull('assign_country_id')
            ->whereRaw("FIND_IN_SET($country_id,assign_country_id)")
            ->pluck('id')
            ->toArray();

        if ($assignTo) {
            $nextAdminId = getNextAdminId($assignTo, $assignToAdmin);
            return $nextAdminId;
        } else {
            if (!empty($assignToAdmin)) {
                return $assignToAdmin[0];
            } else {
                return 0;
            }
        }
    }

    function getNextAdminId($assignTo, $adminIds)
    {
        if (empty($adminIds)) {
            return 0;
        }

        $currentIndex = array_search($assignTo, $adminIds);

        if ($currentIndex === false) {
            return $adminIds[0];
        }

        $nextIndex = ($currentIndex + 1) % count($adminIds);
        return $adminIds[$nextIndex];
    }
}

if (!function_exists('get_candidateApplicationStatus_array')) {
    function get_candidateApplicationStatus_array() {
        $array = array(
            array('id' => '1', 'name' => 'Requested From Student'),	
            array('id' => '2', 'name' => 'Application submitted'),	
            array('id' => '3', 'name' => 'Application Rejected'),
            array('id' => '4', 'name' => 'Application resubmitted'),
            array('id' => '5', 'name' => 'Conditional Offer Received'),	
            array('id' => '6', 'name' => 'Un-conditional Offer Received'),
            array('id' => '7', 'name' => 'Funds pending from Student'),
            array('id' => '8', 'name' => 'CAS Received'),
            array('id' => '9', 'name' => 'Visa In Process'),	
            array('id' => '10', 'name' => 'Visa Accepted'), 	
            array('id' => '11', 'name' => 'Visa Rejected'),
            array('id' => '12', 'name' => 'Case Closed'),
            array('id' => '13', 'name' => 'Application on Hold'),
            array('id' => '14', 'name' => 'Student Deferred'),
            array('id' => '15', 'name' => 'Offer Accepted'),
            array('id' => '16', 'name' => 'Offer Rejected'),
          
          );
        return $array;
    }
}

if (!function_exists('get_candidateApplicationPartner_array')) {
    function get_candidateApplicationPartner_array() {
        $array = array(
            'KC overseas' => array('id' => '1', 'name' => 'KC overseas', 'code' => 'KC'),	
          );
        return $array;
    }
}

if (!function_exists('sendWhatsapp')) {
    function sendWhatsapp($data)
    {
        $controller = new WhatsappTemplateController;
        return $controller->send_whatsapp($data);
    }
}

if (!function_exists('calculatePercentage')) {
    function calculatePercentage($numerator, $denominator) {
        if ($denominator != 0) {
            $number = ($numerator / $denominator) * 100;
            $formattedNumber = number_format($number, 1);
            return $formattedNumber;
        } else {
            return 0;
        }
    }
}

if (!function_exists('encryptID')) {
    function encryptID($id) {
        if ($id) {
            $encryptUserID = Crypt::encryptString($id);
            return $encryptUserID;
        } else {
            return Null;
        }
    }
}

if (!function_exists('getStageGroup')) {
    function getStageGroup($stageName) {
      
        if($stageName){

            $stageGroups = [
                'inquiry' => ['Inquiry', 'Counselling', 'University to be suggested', 'Universities suggested'],
                'application' => ['Application ready to submit', 'Application submitted', 'Application Rejected', 'Application resubmitted', 'Admission Letter Pending'],
                'offer' => ['Offer Issued', 'Offer Accepted', 'Offer Rejected'],
                'visa' => ['Visa Rejected', 'Visa Accepted', 'Visa In Process', 'Work Visa'],
                'feePayment' => ['Initial Fee / Tuition Fee Deposit'],
                'defered' => ['Student Defered'],
                'dropped' => ['Student backed out / Dropped'],
                'testPreparation' => ['Test Preparation'],
            ];
        
            foreach ($stageGroups as $group => $stages) {
                if (in_array($stageName, $stages)) {
                    return ucwords($group);
                }
            }

        }
       
    
        return "--"; // Return null if the stage name doesn't match any group
    }
}


if (!function_exists('checkleadManagerEnvRole')) {
    function checkleadManagerEnvRole() {
      
        @$roleNames = Auth()->user()->getRoleNames()->toArray();
        
        @$leadManagerEnvRole = env('LEAD_MANAGER_ROLE', 'lead manager');
        // dd(@$roleNames);
       
        if (Auth()->user()->id && in_array($leadManagerEnvRole, $roleNames)) {
            
            return true;
        }else{
            
            return false;
        }
      
    }
}

if (!function_exists('checkAdminAndDeveloperRole')) {
    function checkAdminAndDeveloperRole() {
      
        @$roleNames = Auth()->user()->getRoleNames()->toArray();
        @$leadManagerEnvRole = ['back end developer','superadmin'];
        if (Auth()->user()->id && array_intersect($leadManagerEnvRole, $roleNames)) {
            return true;
        }else{
            return false;
        }
      
    }
}

if (!function_exists('checkRmEnvRole')) {
    function checkRmEnvRole() {
      
        @$roleNames = Auth()->user()->getRoleNames()->toArray();
        $leadManagerEnvRole = explode(',', env('AVAILABLE_RM_ROLES', 'Operation Manager'));
        if (Auth()->user()->id && array_intersect($leadManagerEnvRole, $roleNames)) {
            return true;
            
        }else{
            return false;
        }
      
    }
    
}

if (!function_exists('checkTutorRole')) {
    function checkTutorRole() {
      
        @$roleNames = Auth()->user()->getRoleNames()->toArray();
        @$AVAILABLE_TUTOR_ROLES = explode(',', env('AVAILABLE_TUTOR_ROLES', 'Tutor'));
       
        if (Auth()->user()->id && array_intersect($AVAILABLE_TUTOR_ROLES, $roleNames)) {
            
            return true;
        }else{
            
            return false;
        }
      
    }
}











