<?php

namespace App\Controllers\user;

use App\Models\UserModel;

use App\Models\KontakModel;
use App\Models\ProfileModel;
use App\Models\GalleryModel;
use App\Controllers\BaseController;


class GaleriController extends BaseController
{
    public function index()
    {



        $userModel = new UserModel();

        $kontakModel = new KontakModel();
        $galeriModel = new GalleryModel();
        $profileModel = new ProfileModel();


        // Ambil data
        $user = $userModel->findAll();
        $profileData = $profileModel->first();
        $kontakData = $kontakModel->first();
        $galeriData = $galeriModel->orderBy('id_galeri', 'DESC')->findAll();
        // Tampilkan view dengan data profile dan user
        return view('user/galeri/index', [
            'profileData' => $profileData,
            'kontakData' => $kontakData,
            'galeriData' => $galeriData,
            'user' => $user,


        ]);
    }
    public function detail($id)
    {
        if (empty($id) || !is_numeric($id)) {
            session()->setFlashdata('error', 'Data tidak valid');
            return redirect()->to(base_url('galeri'))->with('error', 'ID tidak valid.');
        }
        $userModel = new UserModel();
        $kontakModel = new KontakModel();
        $galeriModel = new GalleryModel();
        $profileModel = new ProfileModel();

        // Ambil data guru berdasarkan ID
        $user = $userModel->findAll();
        $profileData = $profileModel->first();
        $kontakData = $kontakModel->first();
        $galeriData = $galeriModel->find($id);

        if (!$galeriData) {
            session()->setFlashdata('error', 'Data tidak ditemukan');
            return redirect()->to(base_url('galeri'))->with('error', 'Galeri tidak ditemukan.');
        }



        return view('user/galeri/detail', [
            'profileData' => $profileData,
            'kontakData' => $kontakData,
            'galeriData' => $galeriData,
            'user' => $user,
        ]);
    }
}