<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\User;
use App\Country;
use App\Models\MarketCountry;
use App\Models\ReferUser;
use Auth;
use Mail;
use Session;
use Hash;

class AdminController extends Controller
{
    
    public function __construct(){

        $this->middleware('admin');

    }


    public function dashboard()
    {
        $admin = Auth::guard('admin')->user();
        $register_teachers_list =User::where(
                'status',0
            )->where(
                'user_type',2
            )->orderBy(
                'name','ASC'
            )->get();

        $active_teachers_list =User::whereIn(
                'status',[1,2,3]
            )->where(
                'user_type',2
            )->orderBy(
                'name','ASC'
            )->get();

        $register_student_list =User::where(
                'user_type',1
            )->orderBy(
                'name','ASC'
            )->get();

          
        $market_countries = MarketCountry::where( 
                'status', 1
            )->select(
                'market_countries.*', \DB::raw('(SELECT name FROM countries WHERE market_countries.country_id = countries.id ) as sort')
            )->orderBy('sort')->get();
            
        $refer_users =ReferUser::orderBy('id','DESC')->get();

        $data =[
          'register_teachers_list'=>$register_teachers_list , 
          'active_teachers_list'=>$active_teachers_list, 
          'register_student_list'=>$register_student_list , 
          'market_countries'=>$market_countries,  
          'refer_users'=>$refer_users  
        ];
        return view('admin.admin_profile',$data);
    }


    public function load_country_list($text){ 
        $selected = MarketCountry::pluck('country_id')->toArray(); 
        if($text == '0'){
            $countries = Country::where('status', 1)->paginate(10);
        }else{
            $countries = Country::where('status', 1)->where('name','like', '%'.$text.'%')->paginate(10);
        }

        return view('admin.loadCountry', compact('countries','selected'));
    }

    
}
