<?php

namespace App\Http\Controllers;

use App\Models\GeneralSetting;
use App\Models\Review;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class WelcomeController extends Controller
{
    public function index()
    {
        // ✅ If already logged in, go dashboard
        if (Auth::check()) {
            return redirect('/dashboard');
        }

        // ✅ General Settings (id=1)
        $settings = GeneralSetting::firstOrCreate(
            ['id' => 1],
            [
                'verify_fee'         => 300,
                'bondhonpay_api_key' => '',
                'site_name'          => 'TASK EARNING',
                'site_description'   => 'TASK EARNING - Professional Learning & Earning Platform',
                'background_color'   => '#f8fafc',
                'icon_color'         => '#f97316',
                'hover_color'        => '#ea580c',
                'text_color'         => '#0f172a',
                'facebook_link'      => null,
                'youtube_link'       => null,
                'whatsapp_link'      => null,
                'telegram_link'      => null,
                'support_general'    => null,
                'support_verify'     => null,
                'support_withdraw'   => null,
                'support_technical'  => null,
                'logo'               => null,
                'favicon'            => '/favicon.png',
                'banner'             => null,
                'reselling_banner'   => null,
            ]
        );

        $totalUsers = User::count();

        // ✅ Reviews pagination
        $reviews = Review::with('user')->latest()->paginate(10);

        return view('welcome', compact('settings', 'totalUsers', 'reviews'));
    }
}
