<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Contacts;
use App\Models\Pages;
use Illuminate\Http\Request;

class ContactController extends Controller
{
    public function contactList()
    {
        $contacts = Pages::where('name', 'Contact')->first();

        $get_contacts = Contacts::query()->orderBy('id', 'DESC')->get();

        $decodedData = [];

        if ($contacts && !empty($contacts->content)) {
            $decodedData = json_decode($contacts->content, true);
        }
        return view('admin.contact.index', compact('decodedData', 'get_contacts','contacts'));
    }

    public function contactEdit($id)
    {
        $get_contact = Contacts::find($id);
        return view('admin.contact.update', compact('get_contact'));
    }

    public function contactUpdate(Request $request)
    {

        $contact_user = Contacts::where('email', $request->email)->first();
        $contact_user->status = 1;
        $contact_user->save();
        $email = $request->email;
        $message = 'Create Your Account';
        $register_link = $request->register_link;

        $view = view('email-admin-template.send_the_registration_link_to_the_use', compact(['email', 'message']))->render();

        $data = [
            'from' => 'Support@Theclubhouse.Com',
            'to' => $request->email,
            'subject' => "Register Link",
            'body' => $view,
        ];

        $mailer = new GeniusMailer();
        $mailer->sendCustomMail($data);
        return redirect()->back()->with('success', 'Register Link Successfully Send ');

    }
}
