<?php

use App\Http\Controllers\AdminController;
use App\Models\User;
use App\Models\Topic;
use App\Models\Answers;
use App\Models\Question;
use Illuminate\Support\Facades\Auth;

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\QuizController;
use App\Http\Controllers\QuestionsController;
use App\Http\Controllers\AllReportController;
use App\Http\Controllers\TopReportController;
use App\Http\Controllers\PWASettingController;
use App\Http\Controllers\DeleteAccountController;
use App\Http\Controllers\ResetPasswordController;
use App\Http\Controllers\SettingController;
use App\Http\Controllers\TopicController;



/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

// Route::get('/', function () {
//     return view('welcome');
// });


Route::redirect('/', 'home');

Auth::routes();

Route::get('/home', function(){
  $topics = Topic::all();
  $questions = Question::all();
  return view('home', compact('topics', 'questions'));
});




  Route::get('/redirect', function () {
    $query = http_build_query([
        'client_id' => '1',
        'redirect_uri' => 'http://example.com/callback',
        'response_type' => 'token', 
        'scope' => '',
    ]);

    return redirect('http://your-app.com/oauth/authorize?'.$query);
});

// Route::group(['middleware'=> 'isadmin'], function(){

  Route::get('/admin', function(){


    $user =App\Models\User::where('role', '!=', 'A')->count();
    $question = App\Models\Question::count();
    $quiz = App\Models\Topic::count();
    $user_latest = App\Models\User::where('id', '!=', Auth::id())->orderBy('created_at', 'desc')->get();
    $answer = App\Models\Answers::count();
    return view('admin.dashboard', compact('user', 'question', 'answer', 'quiz', 'user_latest'));
  });
 

  Route::resource('/admin/topics', TopicController::class);
  Route::get('/topics', [App\Http\Controllers\HomeController::class, 'index'])->name('topics');
  Route::resource('views/admin/questions', QuestionsController::class);
  Route::post('/admin/questions/import_questions', 'QuestionsController@importExcelToDB')->name('import_questions');
  Route::resource('/admin/answers', 'AnswersController');
  
  Route::post('/AllUsersDestroy', [App\Http\Controllers\DestroyAllController::class,'AllUsersDestroy'])->name('AllUsersDestroy');


 
// });



// Password reset routes
// Route::get('admin/forgot-password', [ResetPasswordController::class, 'showForgotPasswordForm'])->name('password.request');
// Route::post('admin/forgot-password', [ResetPasswordController::class, 'sendResetLinkEmail'])->name('password.email');
// Route::get('admin/reset-password/{token}', [ResetPasswordController::class, 'showResetForm'])->name('password.reset');
// Route::post('admin/reset-password', [ResetPasswordController::class, 'reset'])->name('password.update');

   /*---pwa Controller start--*/
   Route::get('admin/pwa-setting', [PWASettingController::class, 'show'])->name('pwa.show');
   Route::post('/pwa-setting', [PWASettingController::class, 'store'])->name('pwa.store');
   /*---pwa Controller end--*/

Route::get('admin/user-requests', [DeleteAccountController::class, 'useraccountdelete'])->name('user-requests');
Route::post('admin/users-bulk-delete', [DeleteAccountController::class, 'bulk_delete'])->name('users-bulk-delete');
Route::delete('admin/user-delete/{id}', [DeleteAccountController::class, 'delete'])->name('user-delete');

Route::get('/admin/edit_profile', [UserController::class,'edit_profile']);
Route::post('/admin/update_profile', [UserController::class,'update_profile'])->name('user.update_profile');
Route::post('/admin/update_password', [UserController::class,'updatePassword'])->name('user.update_password');

Route::resource('/admin/users', UserController::class);
Route::get('/admin/profile', function(){
  if (Auth::check()) {
    return view('admin.users.profile');
  } else {
    return redirect('/');
  }
});
Route::Post('/user/update', [App\Http\Controllers\UserController::class,'update'])->name('user.update');

Route::resource('/admin/Quiz', QuizController::class);
Route::post('admin/delete-account-request', [DeleteAccountController::class ,'store'])->name('delete.user.account');
Route::get('/admin/my_reports', [App\Http\Controllers\MyReportsController::class,'index'])->name('my_report');
Route::get('/admin/my_reports/{my_reports}', [App\Http\Controllers\MyReportsController::class,'show'])->name('my_report_show');

Route::get('start_quiz/{id}', function($id){
  $topic = App\Models\Topic::findOrFail($id);
  return view('main_quiz', compact('topic'));
})->name('start_quiz');

Route::resource('start_quiz/{id}/quiz', 'App\Http\Controllers\MainQuizController');

Route::get('start_quiz/{id}/finish', function($id){
  $topic = App\Models\Topic::findOrFail($id);
  $count_questions = App\Models\Question::where('topic_id', $id)->count();
  $answers = App\Models\Answers::where('topic_id', $id)->get();
  return view('finish', compact('topic', 'answers', 'count_questions'));

});
Auth::routes();

Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::resource('/admin/all_reports', AllReportController::class);
Route::resource('/admin/top_report', TopReportController::class);
Route::resource('/admin/settings', SettingController::class);
Route::resource('/admin/topics', TopicController::class);


