<?php

namespace App\Http\Controllers\Admin;

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

class ProgramController extends Controller
{
    public function index()
    {
        $programs = Program::all();
        return view('admin.program.index', compact('programs'));
    }

    public function edit($id)
    {
        // ubah $programs jadi $program (tunggal)
        $program = Program::findOrFail($id);
        return view('admin.program.edit', compact('program'));
    }

    public function update(Request $request, $id)
    {
        $request->validate([
            'judul' => 'required|string|max:255',
            'deskripsi' => 'required|string',
            'tanggal' => 'required|date',
        ]);

        // ubah $programs jadi $program
        $program = Program::findOrFail($id);
        $program->update([
            'judul' => $request->judul,
            'deskripsi' => $request->deskripsi,
            'tanggal' => $request->tanggal,
        ]);

        // teks “Kegiatan berhasil diupdate” bisa kamu ganti juga biar konsisten
        return redirect()->route('admin.program.index')->with('success', 'Program berhasil diupdate.');
    }
}
