<?php

namespace App\Http\Controllers\Webprofile\Front;

use App\Http\Controllers\Controller;
use App\Models\Webprofile\Design;
use App\Models\Webprofile\Menu;
use App\Models\Webprofile\Pages;
use Session;

class ErrorController extends Controller
{
    public function index()
    {
        $setting = webprofilesetting();

        if (!Session::has('selected_language')) {
            session(['selected_language' => 'id']);
        }

        if (Session::get('selected_language') == 'id') {
            $data = $this->getDataId($setting);

            return view('webprofile.front.'.$setting['theme'].'.page', $data);
        } elseif (Session::get('selected_language') == 'en') {
            $data = $this->getDataEn($setting);

            return view('webprofile.front.'.$setting['theme'].'.page', $data);
        } elseif (Session::get('selected_language') == 'de') {
            $data = $this->getDataDe($setting);

            return view('webprofile.front.'.$setting['theme'].'.page', $data);
        } elseif (Session::get('selected_language') == 'ar') {
            $data = $this->getDataSa($setting);

            return view('webprofile.front.'.$setting['theme'].'.page', $data);
        } elseif (Session::get('selected_language') == 'zh') {
            $data = $this->getDataZh($setting);

            return view('webprofile.front.'.$setting['theme'].'.page', $data);
        }
    }

    public function getDataId($setting)
    {
        $setting = webprofilesetting();
        $data = new Pages();
        $data->title = 'Page Not Found';
        $menu = Menu::orderby('urutan', 'asc')->get();
        $widget_right = Design::where('name_design', 'widget_right')->orderBy('urutan', 'ASC')->get();
        $widget_left = Design::where('name_design', 'widget_left')->orderBy('urutan', 'ASC')->get();
        $footer = Design::where('name_design', 'like', '%footer_row%')->get();

        $data = [
            'setting' => $setting,
            'data' => $data,
            'menu' => $menu,
            'widget_right' => $widget_right,
            'widget_left' => $widget_left,
            'footer' => $footer,
        ];

        return $data;
    }

    public function getDataEn($setting)
    {
        $setting = webprofilesetting();
        $data = new Pages();
        $data->title = 'Page Not Found';
        $menu = Menu::with(['rEn'])->orderby('urutan', 'asc')->get();
        $widget_right = Design::where('name_design', 'widget_right')->orderBy('urutan', 'ASC')->get();
        $widget_left = Design::where('name_design', 'widget_left')->orderBy('urutan', 'ASC')->get();
        $footer = Design::where('name_design', 'like', '%footer_row%')->get();

        $data = [
            'setting' => $setting,
            'data' => $data,
            'menu' => $menu,
            'widget_right' => $widget_right,
            'widget_left' => $widget_left,
            'footer' => $footer,
        ];

        return $data;
    }

    public function getDataDe($setting)
    {
        $setting = webprofilesetting();
        $data = new Pages();
        $data->title = 'Page Not Found';
        $menu = Menu::with(['rDe'])->orderby('urutan', 'asc')->get();
        $widget_right = Design::where('name_design', 'widget_right')->orderBy('urutan', 'ASC')->get();
        $widget_left = Design::where('name_design', 'widget_left')->orderBy('urutan', 'ASC')->get();
        $footer = Design::where('name_design', 'like', '%footer_row%')->get();

        $data = [
            'setting' => $setting,
            'data' => $data,
            'menu' => $menu,
            'widget_right' => $widget_right,
            'widget_left' => $widget_left,
            'footer' => $footer,
        ];

        return $data;
    }

    public function getDataSa($setting)
    {
        $setting = webprofilesetting();
        $data = new Pages();
        $data->title = 'Page Not Found';
        $menu = Menu::with(['rSa'])->orderby('urutan', 'asc')->get();
        $widget_right = Design::where('name_design', 'widget_right')->orderBy('urutan', 'ASC')->get();
        $widget_left = Design::where('name_design', 'widget_left')->orderBy('urutan', 'ASC')->get();
        $footer = Design::where('name_design', 'like', '%footer_row%')->get();

        $data = [
            'setting' => $setting,
            'data' => $data,
            'menu' => $menu,
            'widget_right' => $widget_right,
            'widget_left' => $widget_left,
            'footer' => $footer,
        ];

        return $data;
    }

    public function getDataZh($setting)
    {
        $setting = webprofilesetting();
        $data = new Pages();
        $data->title = 'Page Not Found';
        $menu = Menu::with(['rZh'])->orderby('urutan', 'asc')->get();
        $widget_right = Design::where('name_design', 'widget_right')->orderBy('urutan', 'ASC')->get();
        $widget_left = Design::where('name_design', 'widget_left')->orderBy('urutan', 'ASC')->get();
        $footer = Design::where('name_design', 'like', '%footer_row%')->get();

        $data = [
            'setting' => $setting,
            'data' => $data,
            'menu' => $menu,
            'widget_right' => $widget_right,
            'widget_left' => $widget_left,
            'footer' => $footer,
        ];

        return $data;
    }
}
