<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class EventsController extends Controller
{
    public function index(Request $request)
    {
        $perPageItems = 12;
        $page = $request->get("p");
        $page = (!$page || $page < 1) ? 1 : $page;
        $pageOffset = $perPageItems * ($page - 1);

        $dataRows = \App\Models\Event::where('is_front_show', '=', true)
            ->orderBy('post_at', 'desc')
            ->select('id', 'title', 'venue', 'contact', 'photos', 'post_at');

        return view('events', [
            'dataRows' => $dataRows->skip($pageOffset)->take($perPageItems)->get(),
            'dataCurrentPage' => $page,
            'dataPerPageItems' => $perPageItems,
            'dataTotalCount' => $dataRows->count(),
        ]);
    }
    
    public function detail(Request $request, $id)
    {
        $dataRow = \App\Models\Event::where('id', '=', $id)
            ->where('is_front_show', '=', true);
        
        return view('events_detail', [
            'dataRow' => $dataRow->first(),
        ]);
    }
}
