<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Models\Apptitle;
use App\Models\SocialAuthSetting;
use App\Models\Seosetting;
use App\Models\IPLIST;
use Cookie;

class CaptchaipblockController extends Controller
{

    public function getCapchaType(){
        return response()->json([
            'GOOGLE_RECAPTCHA_KEY' => setting('GOOGLE_RECAPTCHA_KEY'),
            'RECAPTCH_ENABLE_CONTACT' => setting('RECAPTCH_ENABLE_CONTACT'),
            'CAPTCHATYPE' => setting('CAPTCHATYPE'),
        ]);
    }
    public function index(){
        $ip = IPLIST::where('ip', request()->getClientIp())->first();
        if($ip != null){
            if($ip->types == 'Locked'){
                $title = Apptitle::first();
                $data['title'] = $title;

                $socialAuthSettings = SocialAuthSetting::first();
                $data['socialAuthSettings'] = $socialAuthSettings;

                $seopage = Seosetting::first();
                $data['seopage'] = $seopage;
                $cookie = Cookie::make('name', 'value', 120);
                return response()->json(['error'=> 'captcha'], 309);
            }else{
                return redirect('/');
            }

        }else{
            return redirect('/');
        }
    }


    public function update(Request $request){

        $this->validate($request, [
            'captcha' => 'required',
            // 'g-recaptcha-response' => 'required_without:captcha',
            // 'captcha' => 'required_without:g-recaptcha-response',
        ]);

        $variable = $request->session()->put('redcaptcha', '123');

        return response(['success' => 'successFull']);

    }

    public function captchasreload(){

        return response()->json(['error'=> 'captcha'], 309);
    }
}
