<?php

namespace App\Http\Controllers;

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

class JadwalHarianController extends Controller
{
    public function index()
{
    $jadwals = JadwalHarian::all();
    return view('jadwalharian.index', compact('jadwals'));
}

    public function create()
    {
        return view('jadwalharian.create');
    }

    public function store(Request $request)
    {
        JadwalHarian::create([
            'waktu' => $request->waktu,
            'imam' => $request->imam,
            'muadzin' => $request->muadzin,
        ]);

        return redirect()->route('jadwalharian.index')->with('success', 'Jadwal Harian berhasil ditambahkan.');
    }

    public function edit($id)
    {
        $jadwal = JadwalHarian::findOrFail($id);
        return view('jadwalharian.edit', compact('jadwal'));
    }

    public function update(Request $request, $id)
    {
        $jadwal = JadwalHarian::findOrFail($id);

        $jadwal->update([
            'waktu' => $request->waktu,
            'imam' => $request->imam,
            'muadzin' => $request->muadzin,
        ]);

        return redirect()->route('jadwalharian.index')->with('success', 'Jadwal Harian berhasil diperbarui.');
    }

    public function destroy($id)
    {
        $jadwal = JadwalHarian::findOrFail($id);
        $jadwal->delete();

        return redirect()->route('jadwalharian.index')->with('success', 'Jadwal Harian berhasil dihapus.');
    }
}
