<?php

use App\Models\EducationCity;
use App\Models\EducationQualification;
use App\Models\PrimaryEducation;
use App\Models\QuestionAnswer;
use App\Models\User;
use App\Models\VideoInterviewCategories;
use Illuminate\Http\Request;
use App\Models\RoleQuestionsAnswers;
use App\Models\Settings;

function allStatuses($module, $status = null)
{

//    dd($status);

    $return_data = "";
    $displayStatus =
        array(
            "general" => array('Active' => 'Active', 'Inactive' => 'Inactive'),
        );

    if ($module && $status) {
        $return_data = $displayStatus[$module][$status];
    } else {
        $return_data = $displayStatus[$module];
    }
    return $return_data;

}

function checkvalidUser($user_id)
{
    if (empty(Auth::user())) {
        $userInfo = User::where('id', base64_decode($user_id))->first();
        if ($userInfo->role_id == 404) {
            return 1;
        }
        return 2;
    } else {
        $user = Auth::user();
        if ($user->role_id == 404) {
            Auth::logout();
            return 3;
        }
    }
}

function getCategories()
{
    $records = VideoInterviewCategories::pluck('name', 'id');
    return $records;
}

function getRoleAnswers($qid, $uid)
{
    $answer = RoleQuestionsAnswers::where(['question_id' => $qid, 'user_id' => $uid])->first();
    if (empty($answer)) {
        $answer = "Not Submitted";
    } else {
        $answer = $answer->answer;
    }
    return $answer;
}

function getUserAnswers($qid, $uid, $flag)
{
    $answer = QuestionAnswer::where(['ques_id' => $qid, 'user_id' => $uid])->first();
    if (empty($answer)) {
        $answer = "Not Submitted";
    } else {
        if ($flag == 2) {
            $recordinfo = PrimaryEducation::where(['id' => $answer->answer])->first();
            if (empty($recordinfo)) {
                $answer = '-';
            } else {
                $answer = $recordinfo->city;
            }
        } elseif ($flag == 6 || $flag == 9) {
            $recordinfo = EducationCity::where(['id' => $answer->answer])->first();
            if (empty($recordinfo)) {
                $answer = '-';
            } else {
                $answer = $recordinfo->city;
            }
        } elseif ($flag == 3) {
            $recordinfo = EducationQualification::where(['id' => $answer->answer])->first();
            if (empty($recordinfo)) {
                $answer = '-';
            } else {
                $answer = $recordinfo->qualification;
            }
        } else {
            $answer = $answer->answer;
        }
    }
    return $answer;
}

function getBreadcrumbs($parameters, $title, $url = null)
{
    if ($url) {
        $img = $url;
    } else {
        $img = '/plugins/images/heading-title-bg.jpg';
    }
    $html = '<div class="breadcrumbs">
        <div class="col-sm-4">
            <div class="page-header float-left">
                <div class="page-title">
                    <h1> ' . $title . '</h1>
                </div>
            </div>
        </div>
        <div class="col-sm-8">
            <div class="page-header float-right">
                <div class="page-title">
                    <ol class="breadcrumb text-right">';
    foreach ($parameters as $key => $value) {
        if (is_array($value)) {

            $route = $key;
            $name = '';
            $options = array();

            foreach ($value as $akey => $avalue) {
                if ($akey == 'name') {
                    $name = $avalue;
                } else {
                    $options = $avalue;
                }
            }

            $url = route($route, $options);

            if (!next($parameters)) {
                $html .= '<li class="active">' . $name . '</li>';

            } else {
                $html .= '<li><a href=' . $url . '>' . $name . '</a></li>';
            }

        } else {
            if (!next($parameters)) {
                $html .= '<li class="active">' . $value . '</li>';
            } else {
                $url = route($key);
                $html .= '<li><a href=' . $url . '>' . $value . '</a></li>';
            }
        }
    }
    $html .= '</ol>
                </div>
            </div>
        </div>
    </div>';
    return $html;
}


function Dropdowns($module, $flag = null)
{

    $return_data =
        array(
            "phonePrefixCodes" => array(
                '44' => 'UK (+44)',
                '1' => 'USA (+1)',
                '213' => 'Algeria (+213)',
                '376' => 'Andorra (+376)',
                '244' => 'Angola (+244)',
                '1264' => 'Anguilla (+1264)',
                '1268' => 'Antigua & Barbuda (+1268)',
                '54' => 'Argentina (+54)',
                '374' => 'Armenia (+374)',
                '297' => 'Aruba (+297)',
                '61' => 'Australia (+61)',
                '43' => 'Austria (+43)',
                '994' => 'Azerbaijan (+994)',
                '1242' => 'Bahamas (+1242)',
                '973' => 'Bahrain (+973)',
                '880' => 'Bangladesh (+880)',
                '1246' => 'Barbados (+1246)',
                '375' => 'Belarus (+375)',
                '32' => 'Belgium (+32)',
                '501' => 'Belize (+501)',
                '229' => 'Benin (+229)',
                '1441' => 'Bermuda (+1441)',
                '975' => 'Bhutan (+975)',
                '591' => 'Bolivia (+591)',
                '387' => 'Bosnia Herzegovina (+387)',
                '267' => 'Botswana (+267)',
                '55' => 'Brazil (+55)',
                '673' => 'Brunei (+673)',
                '359' => 'Bulgaria (+359)',
                '226' => 'Burkina Faso (+226)',
                '257' => 'Burundi (+257)',
                '855' => 'Cambodia (+855)',
                '237' => 'Cameroon (+237)',
                '1' => 'Canada (+1)',
                '238' => 'Cape Verde Islands (+238)',
                '1345' => 'Cayman Islands (+1345)',
                '236' => 'Central African Republic (+236)',
                '56' => 'Chile (+56)',
                '86' => 'China (+86)',
                '57' => 'Colombia (+57)',
                '269' => 'Comoros (+269)',
                '242' => 'Congo (+242)',
                '682' => 'Cook Islands (+682)',
                '506' => 'Costa Rica (+506)',
                '385' => 'Croatia (+385)',
                '53' => 'Cuba (+53)',
                '90392' => 'Cyprus North (+90392)',
                '357' => 'Cyprus South (+357)',
                '42' => 'Czech Republic (+42)',
                '45' => 'Denmark (+45)',
                '253' => 'Djibouti (+253)',
                '1809' => 'Dominica (+1809)',
                '1809' => 'Dominican Republic (+1809)',
                '593' => 'Ecuador (+593)',
                '20' => 'Egypt (+20)',
                '503' => 'El Salvador (+503)',
                '240' => 'Equatorial Guinea (+240)',
                '291' => 'Eritrea (+291)',
                '372' => 'Estonia (+372)',
                '251' => 'Ethiopia (+251)',
                '500' => 'Falkland Islands (+500)',
                '298' => 'Faroe Islands (+298)',
                '679' => 'Fiji (+679)',
                '358' => 'Finland (+358)',
                '33' => 'France (+33)',
                '594' => 'French Guiana (+594)',
                '689' => 'French Polynesia (+689)',
                '241' => 'Gabon (+241)',
                '220' => 'Gambia (+220)',
                '7880' => 'Georgia (+7880)',
                '49' => 'Germany (+49)',
                '233' => 'Ghana (+233)',
                '350' => 'Gibraltar (+350)',
                '30' => 'Greece (+30)',
                '299' => 'Greenland (+299)',
                '1473' => 'Grenada (+1473)',
                '590' => 'Guadeloupe (+590)',
                '671' => 'Guam (+671)',
                '502' => 'Guatemala (+502)',
                '224' => 'Guinea (+224)',
                '245' => 'Guinea - Bissau (+245)',
                '592' => 'Guyana (+592)',
                '509' => 'Haiti (+509)',
                '504' => 'Honduras (+504)',
                '852' => 'Hong Kong (+852)',
                '36' => 'Hungary (+36)',
                '354' => 'Iceland (+354)',
                '91' => 'India (+91)',
                '62' => 'Indonesia (+62)',
                '98' => 'Iran (+98)',
                '964' => 'Iraq (+964)',
                '353' => 'Ireland (+353)',
                '972' => 'Israel (+972)',
                '39' => 'Italy (+39)',
                '1876' => 'Jamaica (+1876)',
                '81' => 'Japan (+81)',
                '962' => 'Jordan (+962)',
                '7' => 'Kazakhstan (+7)',
                '254' => 'Kenya (+254)',
                '686' => 'Kiribati (+686)',
                '850' => 'Korea North (+850)',
                '82' => 'Korea South (+82)',
                '965' => 'Kuwait (+965)',
                '996' => 'Kyrgyzstan (+996)',
                '856' => 'Laos (+856)',
                '371' => 'Latvia (+371)',
                '961' => 'Lebanon (+961)',
                '266' => 'Lesotho (+266)',
                '231' => 'Liberia (+231)',
                '218' => 'Libya (+218)',
                '417' => 'Liechtenstein (+417)',
                '370' => 'Lithuania (+370)',
                '352' => 'Luxembourg (+352)',
                '853' => 'Macao (+853)',
                '389' => 'Macedonia (+389)',
                '261' => 'Madagascar (+261)',
                '265' => 'Malawi (+265)',
                '60' => 'Malaysia (+60)',
                '960' => 'Maldives (+960)',
                '223' => 'Mali (+223)',
                '356' => 'Malta (+356)',
                '692' => 'Marshall Islands (+692)',
                '596' => 'Martinique (+596)',
                '222' => 'Mauritania (+222)',
                '269' => 'Mayotte (+269)',
                '52' => 'Mexico (+52)',
                '691' => 'Micronesia (+691)',
                '373' => 'Moldova (+373)',
                '377' => 'Monaco (+377)',
                '976' => 'Mongolia (+976)',
                '1664' => 'Montserrat (+1664)',
                '212' => 'Morocco (+212)',
                '258' => 'Mozambique (+258)',
                '95' => 'Myanmar (+95)',
                '264' => 'Namibia (+264)',
                '674' => 'Nauru (+674)',
                '977' => 'Nepal (+977)',
                '31' => 'Netherlands (+31)',
                '687' => 'New Caledonia (+687)',
                '64' => 'New Zealand (+64)',
                '505' => 'Nicaragua (+505)',
                '227' => 'Niger (+227)',
                '234' => 'Nigeria (+234)',
                '683' => 'Niue (+683)',
                '672' => 'Norfolk Islands (+672)',
                '670' => 'Northern Marianas (+670)',
                '47' => 'Norway (+47)',
                '968' => 'Oman (+968)',
                '680' => 'Palau (+680)',
                '507' => 'Panama (+507)',
                '675' => 'Papua New Guinea (+675)',
                '595' => 'Paraguay (+595)',
                '51' => 'Peru (+51)',
                '63' => 'Philippines (+63)',
                '48' => 'Poland (+48)',
                '351' => 'Portugal (+351)',
                '1787' => 'Puerto Rico (+1787)',
                '974' => 'Qatar (+974)',
                '262' => 'Reunion (+262)',
                '40' => 'Romania (+40)',
                '7' => 'Russia (+7)',
                '250' => 'Rwanda (+250)',
                '378' => 'San Marino (+378)',
                '239' => 'Sao Tome & Principe (+239)',
                '966' => 'Saudi Arabia (+966)',
                '221' => 'Senegal (+221)',
                '381' => 'Serbia (+381)',
                '248' => 'Seychelles (+248)',
                '232' => 'Sierra Leone (+232)',
                '65' => 'Singapore (+65)',
                '421' => 'Slovak Republic (+421)',
                '386' => 'Slovenia (+386)',
                '677' => 'Solomon Islands (+677)',
                '252' => 'Somalia (+252)',
                '27' => 'South Africa (+27)',
                '34' => 'Spain (+34)',
                '94' => 'Sri Lanka (+94)',
                '290' => 'St. Helena (+290)',
                '1869' => 'St. Kitts (+1869)',
                '1758' => 'St. Lucia (+1758)',
                '249' => 'Sudan (+249)',
                '597' => 'Suriname (+597)',
                '268' => 'Swaziland (+268)',
                '46' => 'Sweden (+46)',
                '41' => 'Switzerland (+41)',
                '963' => 'Syria (+963)',
                '886' => 'Taiwan (+886)',
                '7' => 'Tajikstan (+7)',
                '66' => 'Thailand (+66)',
                '228' => 'Togo (+228)',
                '676' => 'Tonga (+676)',
                '1868' => 'Trinidad & Tobago (+1868)',
                '216' => 'Tunisia (+216)',
                '90' => 'Turkey (+90)',
                '7' => 'Turkmenistan (+7)',
                '993' => 'Turkmenistan (+993)',
                '1649' => 'Turks & Caicos Islands (+1649)',
                '688' => 'Tuvalu (+688)',
                '256' => 'Uganda (+256)',
                '380' => 'Ukraine (+380)',
                '971' => 'United Arab Emirates (+971)',
                '598' => 'Uruguay (+598)',
                '7' => 'Uzbekistan (+7)',
                '678' => 'Vanuatu (+678)',
                '379' => 'Vatican City (+379)',
                '58' => 'Venezuela (+58)',
                '84' => 'Vietnam (+84)',
                '84' => 'Virgin Islands - British (+1284)',
                '84' => 'Virgin Islands - US (+1340)',
                '681' => 'Wallis & Futuna (+681)',
                '969' => 'Yemen (North)(+969)',
                '967' => 'Yemen (South)(+967)',
                '260' => 'Zambia (+260)',
                '263' => 'Zimbabwe (+263)',
            ),
        );

    if ($module && $flag) {
        $return_data = $return_data[$module][$flag];
    } else {
        $return_data = $return_data[$module];
    }
    return $return_data;

}

function curencnyLists($flag = null)
{


    $return_data =
        array(
            "AFN" => 'AFN(؋)',
            "ALL" => 'ALL(LEK)',
            "ANG" => 'ANG(Ƒ)',
            "ARS" => 'ARS($)',
            "AUD" => 'AUD($)',
            "AWG" => 'AWG(Ƒ)',
            "AZN" => 'AZN(МАН)',
            "BAM" => 'BAM(KM)',
            "BBD" => 'BBD($)',
            "BGN" => 'BGN(ЛВ)',
            "BMD" => 'BMD($)',
            "BND" => 'BND($)',
            "BOB" => 'BOB($B)',
            "BRL" => 'BRL(R$)',
            "BSD" => 'BSD($)',
            "BWP" => 'BWP(P)',
            "BYR" => 'BYR(P.)',
            "BZD" => 'BZD(BZ$)',
            "CAD" => 'CAD($)',
            "CHF" => 'CHF(CHF)',
            "CLP" => 'CLP($)',
            "CNY" => 'CNY(¥)',
            "COP" => 'COP($)',
            "CRC" => 'CRC(₡)',
            "CUP" => 'CUP(₱)',
            "CZK" => 'CZK(KČ)',
            "DKK" => 'DKK(KR)<',
            "OP " => 'DOP (RD$)',
            "EGP" => 'EGP(£)',
            "EUR" => 'EUR(€)',
            "FJD" => 'FJD($)',
            "FKP" => 'FKP(£)',
            "GBP" => 'GBP(£)',
            "GGP" => 'GGP(£)',
            "GHC" => 'GHC(¢)',
            "GIP" => 'GIP(£)',
            "GTQ" => 'GTQ(Q)',
            "GYD" => 'GYD($)',
            "HKD" => 'HKD($)',
            "HNL" => 'HNL(L)',
            "HRK" => 'HRK(KN)',
            "HUF" => 'HUF(FT)',
            "IDR" => 'IDR(RP)',
            "ILS" => 'ILS(₪)',
            "IMP" => 'IMP(£)',
            "INR" => 'INR(₹)',
            "IRR" => 'IRR(﷼)',
            "ISK" => 'ISK(KR)',
            "JEP" => 'JEP(£)',
            "JMD" => 'JMD(J$)',
            "JPY" => 'JPY(¥)',
            "KGS" => 'KGS(ЛВ)',
            "KHR" => 'KHR(៛)',
            "KPW" => 'KPW(₩)',
            "KRW" => 'KRW(₩)',
            "KYD" => 'KYD($)',
            "KZT" => 'KZT(ЛВ)',
            "LAK" => 'LAK(₭)',
            "LBP" => 'LBP(£)',
            "LKR" => 'LKR(₨)',
            "LRD" => 'LRD($)',
            "LTL" => 'LTL(LT)',
            "LVL" => 'LVL(LS)',
            "MKD" => 'MKD(ДЕН)',
            "MNT" => 'MNT(₮)',
            "MUR" => 'MUR(₨)',
            "MXN" => 'MXN($)',
            "MYR" => 'MYR(RM)',
            "MZN" => 'MZN(MT)',
            "NAD" => 'NAD($)',
            "NGN" => 'NGN(₦)',
            "NIO" => 'NIO(C$)',
            "NOK" => 'NOK(KR)',
            "NPR" => 'NPR(₨)',
            "NZD" => 'NZD($)',
            "OMR" => 'OMR(﷼)',
            "PAB" => 'PAB(B/.)',
            "PEN" => 'PEN(S/.)',
            "PKR" => 'PKR(₨)',
            "PLN" => 'PLN(ZŁ)',
            "PYG" => 'PYG(GS)',
            "QAR" => 'QAR(﷼)',
            "RON" => 'RON(LEI)',
            "RSD" => 'RSD(ДИН.)',
            "RUB" => 'RUB(РУБ)',
            "SAR" => 'SAR(﷼)',
            "SBD" => 'SBD($)',
            "SCR" => 'SCR(₨)',
            "SEK" => 'SEK(KR)',
            "SGD" => 'SGD($)',
            "SHP" => 'SHP(£)',
            "SOS" => 'SOS(S)',
            "SRD" => 'SRD($)',
            "SVC" => 'SVC($)',
            "SYP" => 'SYP(£)',
            "THB" => 'THB(฿)',
            "TRL" => 'TRL(£)',
            "TRY" => 'TRY(TL)',
            "TTD" => 'TTD(TT$)',
            "TVD" => 'TVD($)',
            "TWD" => 'TWD(NT$)',
            "UAH" => 'UAH(₴)',
            "USD" => 'USD($)',
            "UYU" => 'UYU($U)',
            "UZS" => 'UZS(ЛВ)',
            "VEF" => 'VEF(BS)',
            "VND" => 'VND(₫)',
            "XCD" => 'XCD($)',
            "YER" => 'YER(﷼)',
            "ZAR" => 'ZAR(R)',
            "ZWD" => 'ZWD(Z$)',
        );

    if (isset($return_data[$flag])) {
        $return_data = $return_data[$flag];
    } else {
        $return_data = $return_data;
    }
    return $return_data;

}

function get_settings()
{
    $settingsData = Settings::first();

    if (!empty($settingsData)) {
        if ($settingsData->logo != '') {
            $settingsData->logo_url = Settings::uploadDir('url') . '/' . $settingsData->logo;
        } else {

            $settingsData->logo_url = '/Hirextra_logo.png';
        }
        if ($settingsData->video_logo != '') {
            $settingsData->video_logo_url = Settings::uploadDir('url') . '/' . $settingsData->video_logo;
        } else {
            $settingsData->video_logo_url = '/Hirextra_logo.png';
        }

    }

    return $settingsData;
}

function role_job_types($flag = null)
{


    $return_data =
        array(
            "Full Time Permanent" => 'Full Time Permanent',
            "Full Time Part Time" => 'Full Time Part Time',
            "Full Time" => "Full Time",
            "Full Time Security Cleared" => "Full Time Security Cleared",
            "Full Time Duly Vetted" => "Full Time Duly Vetted",
            "Trainee – Full Time" => "Trainee – Full Time",
            "Hire to Train" => "Hire to Train",
            "Intern" => "Intern",
            "Apprentice" => "Apprentice",
            "WFH – Full Time" => "WFH – Full Time",
            "Full Time – Fixed Term" => "Full Time – Fixed Term",
            "Temporary" => "Temporary",
            "Contractor" => "Contractor",
            "Contract-To-Hire" => "Contract-To-Hire",
        );

    if (isset($return_data[$flag])) {
        $return_data = $return_data[$flag];
    } else {
        $return_data = $return_data;
    }
    return $return_data;

}

function questionTypes($module, $flag = null)
{

    $return_data =
        array(
            "types" => array(
                'textbox' => 'textbox',
                'radio' => 'radio',

            ),
        );

    if ($module && $flag) {
        $return_data = $return_data[$module][$flag];
    } else {
        $return_data = $return_data[$module];
    }
    return $return_data;

}

function templates($flag = null)
{

    $return_data =
        array(
            'template1' => 'template1',


        );

    if ($flag) {
        $return_data = $return_data[$flag];
    }
    return $return_data;

}

function g_print($array)
{
    echo '<pre>';
    print_r($array);
    echo '</pre>';
}

