<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\News;
use App\Models\Categories;

class ClientController extends Controller
{
    public function clientDetails($category_id = null)
    {
        $newsM = new News();
        $catM = new Categories();

        $categories = $catM->allCategories();

        if ($category_id === null && !empty($categories)) {
            $category_id = $categories[0]->category_id;
        }

        $fiveGeneralNews = $newsM->getPage($category_id, 100, 0);

        if (empty($fiveGeneralNews)) {
            $fiveGeneralNews = collect();
        }

        $businessCat = Categories::where('category_name', 'business')->first();
        $business = $businessCat 
            ? $newsM::getSomeNews($businessCat->category_id, 20, 0) 
            : [];

        $financeCat = Categories::where('category_name', 'finance')->first();
        $finance = $financeCat 
            ? $newsM::getSomeNews($financeCat->category_id, 20, 0) 
            : [];

        $investmentCat = Categories::where('category_name', 'investment')->first();
        $investment = $investmentCat 
            ? $newsM::getSomeNews($investmentCat->category_id, 20, 0) 
            : [];

        $latest = $newsM->getNews(210, 0);

        return view('clientdetails', [
            'catM'            => $categories,
            'FiveGeneralnews' => $fiveGeneralNews,
            'investment'      => $investment,
            'finance'         => $finance,
            'business'        => $business, 
            'latest'          => $latest,
        ]);
    }

    public function termsConditions($category_id = null)
{
    $newsM = new News();
    $catM = new Categories();

    $categories = $catM->allCategories();

    if ($category_id === null && !empty($categories)) {
        $category_id = $categories[0]->category_id;
    }

    $fiveGeneralNews = $newsM->getPage($category_id, 100, 0);
    if (empty($fiveGeneralNews)) {
        $fiveGeneralNews = collect();
    }

    $businessCat = Categories::where('category_name', 'business')->first();
    $business = $businessCat ? $newsM::getSomeNews($businessCat->category_id, 20, 0) : [];

    $financeCat = Categories::where('category_name', 'finance')->first();
    $finance = $financeCat ? $newsM::getSomeNews($financeCat->category_id, 20, 0) : [];

    $investmentCat = Categories::where('category_name', 'investment')->first();
    $investment = $investmentCat ? $newsM::getSomeNews($investmentCat->category_id, 20, 0) : [];

    $latest = $newsM->getNews(210, 0);

    return view('terms-and-conditions', [
        'catM'            => $categories,
        'FiveGeneralnews' => $fiveGeneralNews,
        'investment'      => $investment,
        'finance'         => $finance,
        'business'        => $business, 
        'latest'          => $latest,
    ]);
}


public function privacyPolicy($category_id = null)
{
    $newsM = new News();
    $catM = new Categories();

    $categories = $catM->allCategories();

    if ($category_id === null && !empty($categories)) {
        $category_id = $categories[0]->category_id;
    }

    $fiveGeneralNews = $newsM->getPage($category_id, 100, 0);
    if (empty($fiveGeneralNews)) {
        $fiveGeneralNews = collect();
    }

    $businessCat = Categories::where('category_name', 'business')->first();
    $business = $businessCat ? $newsM::getSomeNews($businessCat->category_id, 20, 0) : [];

    $financeCat = Categories::where('category_name', 'finance')->first();
    $finance = $financeCat ? $newsM::getSomeNews($financeCat->category_id, 20, 0) : [];

    $investmentCat = Categories::where('category_name', 'investment')->first();
    $investment = $investmentCat ? $newsM::getSomeNews($investmentCat->category_id, 20, 0) : [];

    $latest = $newsM->getNews(210, 0);

    return view('privacy-policy', [
        'catM'            => $categories,
        'FiveGeneralnews' => $fiveGeneralNews,
        'investment'      => $investment,
        'finance'         => $finance,
        'business'        => $business, 
        'latest'          => $latest,
    ]);
}
public function contactUs($category_id = null)
{
    $newsM = new News();
    $catM = new Categories();

    $categories = $catM->allCategories();

    if ($category_id === null && !empty($categories)) {
        $category_id = $categories[0]->category_id;
    }

    $fiveGeneralNews = $newsM->getPage($category_id, 100, 0);
    if (empty($fiveGeneralNews)) {
        $fiveGeneralNews = collect();
    }

    $businessCat = Categories::where('category_name', 'business')->first();
    $business = $businessCat ? $newsM::getSomeNews($businessCat->category_id, 20, 0) : [];

    $financeCat = Categories::where('category_name', 'finance')->first();
    $finance = $financeCat ? $newsM::getSomeNews($financeCat->category_id, 20, 0) : [];

    $investmentCat = Categories::where('category_name', 'investment')->first();
    $investment = $investmentCat ? $newsM::getSomeNews($investmentCat->category_id, 20, 0) : [];

    $latest = $newsM->getNews(210, 0);

    return view('contact-us', [
        'catM'            => $categories,
        'FiveGeneralnews' => $fiveGeneralNews,
        'investment'      => $investment,
        'finance'         => $finance,
        'business'        => $business, 
        'latest'          => $latest,
    ]);
}
public function about($category_id = null)
{
    $newsM = new News();
    $catM = new Categories();

    $categories = $catM->allCategories();

    if ($category_id === null && !empty($categories)) {
        $category_id = $categories[0]->category_id;
    }

    $fiveGeneralNews = $newsM->getPage($category_id, 100, 0);
    if (empty($fiveGeneralNews)) {
        $fiveGeneralNews = collect();
    }

    $businessCat = Categories::where('category_name', 'business')->first();
    $business = $businessCat ? $newsM::getSomeNews($businessCat->category_id, 20, 0) : [];

    $financeCat = Categories::where('category_name', 'finance')->first();
    $finance = $financeCat ? $newsM::getSomeNews($financeCat->category_id, 20, 0) : [];

    $investmentCat = Categories::where('category_name', 'investment')->first();
    $investment = $investmentCat ? $newsM::getSomeNews($investmentCat->category_id, 20, 0) : [];

    $latest = $newsM->getNews(210, 0);

    return view('about', [
        'catM'            => $categories,
        'FiveGeneralnews' => $fiveGeneralNews,
        'investment'      => $investment,
        'finance'         => $finance,
        'business'        => $business, 
        'latest'          => $latest,
    ]);
}
public function author($category_id = null)
{
    $newsM = new News();
    $catM = new Categories();

    $categories = $catM->allCategories();

    if ($category_id === null && !empty($categories)) {
        $category_id = $categories[0]->category_id;
    }

    $fiveGeneralNews = $newsM->getPage($category_id, 100, 0);
    if (empty($fiveGeneralNews)) {
        $fiveGeneralNews = collect();
    }

    $businessCat = Categories::where('category_name', 'business')->first();
    $business = $businessCat ? $newsM::getSomeNews($businessCat->category_id, 20, 0) : [];

    $financeCat = Categories::where('category_name', 'finance')->first();
    $finance = $financeCat ? $newsM::getSomeNews($financeCat->category_id, 20, 0) : [];

    $investmentCat = Categories::where('category_name', 'investment')->first();
    $investment = $investmentCat ? $newsM::getSomeNews($investmentCat->category_id, 20, 0) : [];

    $latest = $newsM->getNews(210, 0);

    return view('author', [
        'catM'            => $categories,
        'FiveGeneralnews' => $fiveGeneralNews,
        'investment'      => $investment,
        'finance'         => $finance,
        'business'        => $business, 
        'latest'          => $latest,
    ]);
}
}
