<?php
// app/Http/Controllers/PWAController.php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;

class PWAController extends Controller
{
    /**
     * Get PWA manifest
     */
    public function manifest()
{
    $path = public_path('manifest.json');

    if (!\Illuminate\Support\Facades\File::exists($path)) {
        abort(404, 'PWA manifest not found');
    }

    return response(
        \Illuminate\Support\Facades\File::get($path),
        200
    )
    ->header('Content-Type', 'application/manifest+json; charset=UTF-8')
    ->header('Cache-Control', 'no-cache, no-store, must-revalidate')
    ->header('X-Content-Type-Options', 'nosniff');
}

    public function serviceWorker()
{
    $path = public_path('sw.js');

    if (!File::exists($path)) {
        abort(404, 'Service Worker not found');
    }

    return response(File::get($path), 200)
        ->header('Content-Type', 'application/javascript; charset=UTF-8')
        ->header('Cache-Control', 'no-cache, no-store, must-revalidate')
        ->header('Service-Worker-Allowed', '/')
        ->header('X-Content-Type-Options', 'nosniff');
}

    /**
     * Check PWA status
     */
    public function status()
    {
        return response()->json([
            'pwa_enabled' => true,
            'manifest_url' => asset('manifest.json'),
            'service_worker_url' => asset('sw.js'),
            'offline_page' => asset('offline.html')
        ]);
    }
}