<?php

namespace App\Http\Controllers\Frontend;

use App\Http\Controllers\Controller;
use Illuminate\View\View;
use App\Helpers\SeoHelper;
use App\Models\ToolStats;

class ToolsController extends Controller
{
    public function tools(): View
    {
        if (
            toolsSetting('convert') == 0 
            && toolsSetting('compress') == 0 
            && toolsSetting('resize') == 0 
            && toolsSetting('rotate_reflect') == 0 
            && toolsSetting('watermark') == 0 
            && toolsSetting('preferences') == 0 
            && toolsSetting('effects') == 0 
            && toolsSetting('exif_cleaner') == 0 
            && toolsSetting('autoremove') == 0 
            && toolsSetting('password') == 0
        ) {
            return abort(404);
        }

        $statsModel = new ToolStats();
        $count = $statsModel->processCount();

        $seo = SeoHelper::pageSeo('tools');

        return view('frontend.tools.all.index', [
            'functions' => 'frontend.tools.all.function',
            'pageKey' => 'tools',
            'seoData' => $seo,
            'count'=> $count,
        ]);
    }

    public function convert(): View
    {
        if (toolsSetting('convert') == 0) {
            return abort(404);
        }

        $seo = SeoHelper::pageSeo('tools_convert');

        return view('frontend.tools.convert.index', [
            'functions' => 'frontend.tools.convert.function',
            'pageKey' => 'tools_convert',
            'seoData' => $seo,
        ]);
    }

    public function compress(): View
    {
        if (toolsSetting('compress') == 0) {
            return abort(404);
        }

        $seo = SeoHelper::pageSeo('tools_compress');

        return view('frontend.tools.compress.index', [
            'functions' => 'frontend.tools.compress.function',
            'pageKey' => 'tools_compress',
            'seoData' => $seo,
        ]);
    }

    public function resize(): View
    {
        if (toolsSetting('resize') == 0) {
            return abort(404);
        }

        $seo = SeoHelper::pageSeo('tools_resize');

        return view('frontend.tools.resize.index', [
            'functions' => 'frontend.tools.resize.function',
            'pageKey' => 'tools_resize',
            'seoData' => $seo,
        ]);
    }

    public function rotate_reflect(): View
    {
        if (toolsSetting('rotate_reflect') == 0) {
            return abort(404);
        }

        $seo = SeoHelper::pageSeo('tools_rotate_reflect');

        return view('frontend.tools.rotate_reflect.index', [
            'functions' => 'frontend.tools.rotate_reflect.function',
            'pageKey' => 'tools_rotate_reflect',
            'seoData' => $seo,
        ]);
    }

    public function watermark(): View
    {
        if (toolsSetting('watermark') == 0) {
            return abort(404);
        }

        $seo = SeoHelper::pageSeo('tools_watermark');

        return view('frontend.tools.watermark.index', [
            'functions' => 'frontend.tools.watermark.function',
            'pageKey' => 'tools_watermark',
            'seoData' => $seo,
        ]);
    }

    public function preferences(): View
    {
        if (toolsSetting('preferences') == 0) {
            return abort(404);
        }

        $seo = SeoHelper::pageSeo('tools_preferences');

        return view('frontend.tools.preferences.index', [
            'functions' => 'frontend.tools.preferences.function',
            'pageKey' => 'tools_preferences',
            'seoData' => $seo,
        ]);
    }

    public function effects(): View
    {
        if (toolsSetting('effects') == 0) {
            return abort(404);
        }

        $seo = SeoHelper::pageSeo('tools_effects');

        return view('frontend.tools.effects.index', [
            'functions' => 'frontend.tools.effects.function',
            'pageKey' => 'tools_effects',
            'seoData' => $seo,
        ]);
    }

    public function exif_cleaner(): View
    {
        if (toolsSetting('exif_cleaner') == 0) {
            return abort(404);
        }

        $seo = SeoHelper::pageSeo('tools_exif_cleaner');

        return view('frontend.tools.exif_cleaner.index', [
            'functions' => 'frontend.tools.exif_cleaner.function',
            'pageKey' => 'tools_exif_cleaner',
            'seoData' => $seo,
        ]);
    }

    public function autoremove(): View
    {
        if (toolsSetting('autoremove') == 0) {
            return abort(404);
        }

        $seo = SeoHelper::pageSeo('tools_autoremove');

        return view('frontend.tools.autoremove.index', [
            'functions' => 'frontend.tools.autoremove.function',
            'pageKey' => 'tools_autoremove',
            'seoData' => $seo,
        ]);
    }

    public function password(): View
    {
        if (toolsSetting('password') == 0) {
            return abort(404);
        }

        $seo = SeoHelper::pageSeo('tools_password');

        return view('frontend.tools.password.index', [
            'functions' => 'frontend.tools.password.function',
            'pageKey' => 'tools_password',
            'seoData' => $seo,
        ]);
    }

}
