<?php

namespace App\Http\Controllers\admin;

use App\Http\Controllers\Controller;
use App\Models\PrivacyPolicy;
use Illuminate\Http\Request;

class AdminPrivacyPolicyController extends Controller
{
    public function index()
    {
        $privacypolicy = PrivacyPolicy::first();
        return view('backoffice.privacy_policy.index', compact('privacypolicy'));
    }

    public function store(Request $request)
    {
        $request->validate([
            'title' => 'required|string',
            'banner' => 'required|string',
            'description' => 'nullable|string',
        ]);

        $data = $request->only(['title', 'banner', 'description']);

        $privacypolicy = PrivacyPolicy::first();

        if ($privacypolicy) {
            $privacypolicy->update($data);
        } else {
            PrivacyPolicy::create($data);
        }

        return redirect()->back()->with('success', 'About Us page saved successfully!');
    }
}
