<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\KritikSaran;

class KritikSaranController extends Controller
{
    public function index()
    {
        return view('kritiksaran');
    }

    public function store(Request $request)
    {
        // Validasi input
        $request->validate([
            'nama' => 'required',
            'email' => 'required|email',
            'jenis' => 'required|in:kritik,saran',
            'pesan' => 'required|min:10'
        ]);

        // Simpan kritik & saran
        KritikSaran::create([
            'user_id' => auth()->id(),
            'nama' => $request->nama,
            'email' => $request->email,
            'jenis' => $request->jenis,
            'pesan' => $request->pesan
        ]);

        return redirect()->back()->with('success', 'Terima kasih atas feedback Anda!');
    }

    public function show($id)
    {
        // Menampilkan detail feedback
        $feedback = KritikSaran::findOrFail($id);
        
        return view('kritik-saran.show', compact('feedback'));
    }

    public function destroy($id)
    {
        // Hapus feedback
        $feedback = KritikSaran::findOrFail($id);
        $feedback->delete();

        return redirect()->route('kritik-saran.index')
                        ->with('success', 'Feedback berhasil dihapus');
    }
}