<?php

namespace App\Http\Controllers;

use App\Services\DummyDataService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class RiwayatController extends Controller
{
    public function offlineIndex()
    {
        $user = Auth::user();
        if (!$user) $user = (object) ['id' => 1]; 

        $dataOffline = DummyDataService::getRiwayatOffline($user);
        
        $riwayatOffline = collect($dataOffline)
            ->sortBy([
                ['status', 'asc'],           
                ['tanggal_pinjam', 'desc']   
            ])
            ->values()
            ->all();

        return view('riwayat.offline', [
            'pageTitle' => 'Riwayat Peminjaman Offline',
            'riwayatOffline' => $riwayatOffline,
        ]);
    }

    public function onlineIndex()
    {
        $dataOnline = DummyDataService::getRiwayatOnline();

        $riwayatOnline = collect($dataOnline)
            ->sortBy([
                ['status', 'asc'],         
                ['tanggal_baca', 'desc']   
            ])
            ->values()
            ->all();

        return view('riwayat.online', [
            'pageTitle' => 'Riwayat Baca Online',
            'riwayatOnline' => $riwayatOnline,
        ]);
    }
}