<?php

namespace App\Http\Controllers;

use Illuminate\Http\Response;

class ImageController extends Controller
{
    /**
     * Serve buka.jpg or tutup.jpg from storage/app/images/
     * Safe for shared hosting — no symlinks required.
     */
    public function panel(string $mode)
    {
        $mode = strtolower($mode);
        if (!in_array($mode, ['buka', 'tutup'])) {
            abort(404);
        }

        $path = storage_path("app/images/{$mode}.jpg");

        if (!file_exists($path)) {
            abort(404, "Image not found: {$mode}.jpg");
        }

        return response()->file($path, [
            'Content-Type'  => 'image/jpeg',
            'Cache-Control' => 'public, max-age=3600',
        ]);
    }
}
