<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Repositories\Interfaces\SiteSettingInterface;
use Illuminate\Http\Request;

class SiteSettingController extends Controller
{
    protected $settingRepo;

    public function __construct(SiteSettingInterface $settingRepo)
    {
        $this->settingRepo = $settingRepo;
    }

    public function edit()
    {
        $setting = $this->settingRepo->get();
        return view('Admin.SiteSetting.edit', compact('setting'));
    }

    public function update(Request $request)
    {
        $request->validate([
            'phone_number_1' => 'nullable|string|max:255',
            'phone_number_2' => 'nullable|string|max:255',
            'email'          => 'nullable|email|max:255',
            'email_2'        => 'nullable|email|max:255',
            'address_1'      => 'nullable|string|max:500',
            'address_2'      => 'nullable|string|max:500',
            'facebook'       => 'nullable|url|max:255',
            'instagram'      => 'nullable|url|max:255',
            'youtube'        => 'nullable|url|max:255',
            'whatsapp'       => 'nullable|string|max:255',
        ]);

        $data = $request->only([
            'phone_number_1', 'phone_number_2', 'email', 'email_2',
            'address_1', 'address_2', 'facebook', 'instagram', 'youtube', 'whatsapp'
        ]);

        $this->settingRepo->update($data);

        return redirect()->route('site-setting.edit')->with('success', 'Settings updated successfully.');
    }
}
