<?php

namespace App\Http\Controllers\Admin;

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

class ContactController extends Controller
{
    public function edit()
    {
        $contact = Contact::current();
        return view('admin.contact.edit', compact('contact'));
    }

    public function update(Request $request)
    {
        $validated = $request->validate([
            'nama_kantor'   => 'required|string|max:255',
            'alamat'        => 'nullable|string',
            'telepon'       => 'nullable|string|max:50',
            'whatsapp'      => 'nullable|string|max:50',
            'email'         => 'nullable|email|max:255',
            'jam_pelayanan' => 'nullable|string|max:255',
            'latitude'      => 'nullable|numeric|between:-90,90',
            'longitude'     => 'nullable|numeric|between:-180,180',
        ]);

        $contact = Contact::current();
        $contact->update($validated);

        return back()->with('success', 'Informasi kontak berhasil diperbarui.');
    }
}
