<?php

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Log;
use Illuminate\Http\Request;


/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});


Route::get('/pdf', function () {
    $filePath = storage_path('pdfs/65d6f2cebb6f0.pdf');
    $fileContents = file_get_contents(storage_path('app/' . $filePath));


    if (!Storage::exists($filePath)) {
        abort(404, 'File not found.');
    }

    $fileContents = Storage::get($filePath);
    $response = Response::make($fileContents, 200);
    $response->header('Content-Type', 'application/pdf');

    return $response;
});

// Route::get('/pdf/{filename}', function ($filename) {
//     log::info($filename);
//     $path = public_path('pdfs/' . $filename);

//     if (file_exists($path)) {
//         return response()->file($path);
//     } else {
//         abort(404);
//     }
// });

Route::get('/pdfview', [PdfController::class, 'viewPdf']);


Route::get('/check', function () {
    $imageUrl = 'pdfs/65d6f2cebb6f0.pdf';
    $content  = storage_path('app/'.  $imageUrl);
        log::info($content);
    $link = 'file:///'.$content;
    log::info($link);

//    dd('file:///'.$content);
//    return $link;
//    return $this->response->jsonResponse(false, $link, 201);

 });

Route::get('/mail', function () {
    return view('emails.ordermail');
 });


//  Route::get('/check', function () {
//     log::info($imageUrl);
//     //$contents  = Storage::get('storage/app/pdfs/65d6f2cebb6f0.pdf');
//     $content  = storage_path('app/pdfs/65d6f2cebb6f0.pdf');


//     //file:///opt/Projects/wizzio_lattest/api/wizzio-api_26-09-2023/wizzio-api/storage/app/pdfs/65d6f2cebb6f0.pdf
//   //  return view('welcome',['content' => 'contents']);
//    dd('file:///'.$content);
//  });


// Route::get('storage/{filename}', function () {
//     $path = storage_path('app/public/' . $filename);

//     if (!File::exists($path)) {
//         abort(404);
//     }

//     $file = File::get($path);
//     $type = File::mimeType($path);

//     $response = Response::make($file, 200);
//     $response->header("Content-Type", $type);

//     return $response;
// });

