<?php

namespace App\Http\Controllers; 
use Illuminate\Http\Request;
use App\Models\Settings;
use App\Mail\ContactMail;
use Illuminate\Support\Facades\Mail;

class SettingsController extends Controller
{
    public function getAll()
    {
         $content = Settings::all();
         
         $op = array();
         $i = 0;
         foreach($content as $con)
         {
             if($con->type == "image")
             {
                 $con->value = env('UPLOAD_URL').$con->value;
             }
            $op[str_replace(".", "_",$con->key)] = $con->value; 
         }
         
         return response()->json($op);
    } 
    public function getSettings()
    {
         $content = Settings::all();
         
         $op = array();
         $i = 0;
         foreach($content as $con)
         {
            $op[str_replace(".", "_",$con->key)] = $con->value; 
         }
         
         return $op;
    } 
    
    public function send_contact()
    {
        $settings = $this->getSettings();
        
        $details['name'] = request('name');
        $details['email'] = request('email');
        $details['message'] = request('message');
        $details['logo'] = $settings['site_logo'];
        
        $mail =  Mail::to($settings['site_contact_email'])->send(new ContactMail($details));
        
        $opt = array();
        $opt['message'] = "";
        $opt['error'] = false;  
         
        return response()->json($opt);
    }
}
