<?php

namespace App\Http\Controllers\front;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\AboutModel;
use App\Models\AchievementsModel;
use App\Models\Newsletter;
use App\Models\PartnersModel;
use App\Models\ServicesModel;
use App\Models\SubServices;
use App\Models\SubServicesElement;
use App\Models\SubServicesImages;
use Termwind\Components\Element;
use Session;

class HomeController extends Controller
{
    public function index_en()
    {
        $info_about = AboutModel::find(1);
        $info_achievement = AchievementsModel::find(1);
        $info_partners = PartnersModel::select()->get();
        $info_services = ServicesModel::select()->get();

        return view('front.en.index', compact('info_about', 'info_achievement', 'info_partners', 'info_services'));
    }
    public function index_ar()
    {
        $info_about = AboutModel::find(1);
        $info_achievement = AchievementsModel::find(1);
        $info_partners = PartnersModel::select()->get();
        $info_services = ServicesModel::select()->get();

        return view('front.ar.index', compact('info_about', 'info_achievement', 'info_partners', 'info_services'));
    }

    public function en_services_index($id)
    {

        $info_services = ServicesModel::select()->get();
        $info_services_elemment = ServicesModel::select()->where('id', $id)->first();
        $subservices = SubServices::select()->where('services_id', $id)->get();
        foreach ($subservices as $subservice) {

            $subservice['elements'] = SubServicesElement::select()->where('sub_services_id', $subservice->id)->get();
            $subservice['images'] = SubServicesImages::select()->where('sub_services_id', $subservice->id)->get();
        }
        $info_partners = PartnersModel::select()->get();
        
        return view('front.en.services', compact('info_services', 'subservices', 'info_partners', 'info_services_elemment', 'id'));
    }
    public function ar_services_index($id)
    {
        $info_services = ServicesModel::select()->get();
        $info_services_elemment = ServicesModel::select()->where('id', $id)->first();

        $subservices = SubServices::select()->where('services_id', $id)->get();
        foreach ($subservices as $subservice) {

            $subservice['elements'] = SubServicesElement::select()->where('sub_services_id', $subservice->id)->get();
            $subservice['images'] = SubServicesImages::select()->where('sub_services_id', $subservice->id)->get();
        }
        $info_partners = PartnersModel::select()->get();
        

        return view('front.ar.services', compact('info_services', 'subservices', 'info_partners', 'info_services_elemment', 'id'));
    }

    public function newsletter(Request $request){


        $this->validate($request, [
            'message'             => 'required',
            
            
        ]);
        Newsletter::create([
            'message'          => $request->message,  
                     
        ]);

        return response()->json('success');
        
      
    }
}