<?php

use App\Events\ChatMessage;
use App\Http\Controllers\ApproveEngineerController;
use App\Http\Controllers\ApproveFirmController;
use App\Http\Controllers\CategoriesController;
use App\Http\Controllers\CertificateController;
use App\Http\Controllers\ChatController;
use App\Http\Controllers\ClientProjectsController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\EducationController;
use App\Http\Controllers\EngineerController;
use App\Http\Controllers\EngineerProposalsController;
use App\Http\Controllers\EngineerServicesController;
use App\Http\Controllers\ExperienceController;
use App\Http\Controllers\FirmController;
use App\Http\Controllers\FirmProposalsController;
use App\Http\Controllers\FirmServicesController;
use App\Http\Controllers\FirmTypeController;
use App\Http\Controllers\LicenseController;
use App\Http\Controllers\MilestoneController;
use App\Http\Controllers\ServicesController;
use App\Http\Controllers\PortfolioProjectController;
use App\Http\Controllers\ProjectController;
use App\Http\Controllers\ProjectProposalsController;
use App\Http\Controllers\ProposalController;
use App\Http\Controllers\RegistrationController;
use App\Http\Controllers\ServiceController;
use App\Http\Controllers\SkillController;
use App\Http\Controllers\StripeController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\WalletController;
use App\Http\Controllers\WorkerProjectsController;
use App\Http\Helpers\StripeClient;
use App\Http\Middleware\UserMiddleware;
use App\Mail\ApproveEngineer;
use App\Models\Chat;
use App\Models\Contract;
use App\Models\Engineer;
use App\Models\exchangeRate as ModelsExchangeRate;
use App\Models\Firm;
use App\Models\HomePageContent;
use App\Models\Message;
use App\Models\Milestone;
use App\Models\PendingEngineer;
use App\Models\Project;
use App\Models\Proposal;
use App\Models\Service;
use App\Models\User;
use App\Notifications\ProposalAdded;
use Carbon\Carbon;
use Illuminate\Foundation\Application;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
use Inertia\Inertia;
use AshAllenDesign\LaravelExchangeRates\Classes\ExchangeRate;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\App;

/*
|--------------------------------------------------------------------------
| 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 () {

    if(Auth::check()) {
        return redirect()->route('dashboard');
    }

    $content = HomePageContent::first();
    $engineerServices = Service::whereHasMorph('serviceable', Engineer::class)->with('serviceable.user')->withAvg('rates', 'rate')->orderBy('rates_avg_rate', 'desc')->take(5)->get();
    $firmServices = Service::whereHasMorph('serviceable', Firm::class)->with('serviceable.user')->withAvg('rates', 'rate')->orderBy('rates_avg_rate', 'desc')->take(5)->get();
    return Inertia::render("Welcome", [
        "canLogin" => Route::has("login"),
        "canRegister" => Route::has("register"),
        'content' => $content,
        'engineerServices' => $engineerServices,
        'firmServices' => $firmServices,

    ]);
})->name("welcome");

Route::get("/home", function () {

    $content = HomePageContent::first();
    $engineerServices = Service::whereHasMorph('serviceable', Engineer::class)->with('serviceable.user')->withAvg('rates', 'rate')->orderBy('rates_avg_rate', 'desc')->take(5)->get();
    $firmServices = Service::whereHasMorph('serviceable', Firm::class)->with('serviceable.user')->withAvg('rates', 'rate')->orderBy('rates_avg_rate', 'desc')->take(5)->get();
    return Inertia::render("Welcome", [
        "canLogin" => Route::has("login"),
        "canRegister" => Route::has("register"),
        'content' => $content,
        'engineerServices' => $engineerServices,
        'firmServices' => $firmServices,

    ]);
})->name("welcome-no-redirect");

Route::get("/about", function () {
    $content = \App\Models\AboutPageContent::first();
    $content->load(["values","founders"]);
    //dd($content);
    return Inertia::render("About",["content"=>$content]);
})->name("about");

Route::stripeWebhooks('/stripe-webhook');


Route::middleware([
    "auth:sanctum",
    config("jetstream.auth_session"),
    "verified",
])->group(function () {

    // =================== Dashboard Redirect ===================
    Route::get("/dashboard", function () {
        $user = Auth::user();
        if ($user->is_engineer) {
            return redirect()->route('engineer.dashboard');
        } elseif ($user->is_firm) {
            return redirect()->route('firm.dashboard');
        } else {
            return redirect()->route('client.dashboard');
        }
    })->name("dashboard");
    // =================== Dashboard Redirect ===================

    // =================== User ===================
    // User pages
    Route::prefix("u")
        ->as("user.")
        ->group(function () {
            Route::get("/", [UserController::class, "show"])->name("dashboard")->middleware(UserMiddleware::class);
            Route::get("/wallet", [WalletController::class, "index"])->name("wallet");
            Route::get("/wallet/{payment}", [WalletController::class, "show"])->name("wallet.payment.show");
            Route::post("/payout-request",[\App\Http\Controllers\PayoutRequestController::class,'store'])
            ->name('wallet.payout.request');
            Route::post('/billing',[\App\Http\Controllers\BillingDataController::class,'store'])->name('wallet.billing.store');
            Route::post('/notifications/clear',[UserController::class,'clearNotifications'])->name('notifications.clear');
            Route::get('/create-connected-account',[\App\Http\Controllers\BillingDataController::class,'createConnectedAccount'])->name('wallet.create.account');
            Route::get('/update-connected-account/{accountId}',[\App\Http\Controllers\BillingDataController::class,'update'])->name('wallet.update.account');
            Route::get('/delete-connected-account/{accountId}',[\App\Http\Controllers\BillingDataController::class,'destroy'])->name('wallet.delete.account');
            Route::get("/{slug}", [UserController::class, "show"])->name(
                "profile.slugged"
            );

        });



    // Client pages
    Route::middleware(UserMiddleware::class)->prefix("c")
        ->as("client.")
        ->group(function () {
            Route::get("/chat", function () {
                $chats = Auth::user()->chats()->orderBy('last_message_at','desc')->get();

                $chats->load("messages", 'user', 'worker', 'chatable');
                $chats->each(function ($chat) {
                    $chat->setMessagesAsRead();
                });

                // dd($chats);
                              return Inertia::render("Chat/Show", [
                    "chats" => $chats,
                    'is'=> 'user'
                ]);
            })->name("chat");

            Route::get("/my-projects", [
                ClientProjectsController::class,
                "index",
            ])->name("projects.index");

            Route::get("/dashboard", [
                DashboardController::class,
                "clientDashboard",
            ])->name("dashboard");
        });

    // Client projects
    Route::middleware(UserMiddleware::class)->prefix("client/projects")
        ->as("client.projects.")
        ->group(function () {
            Route::get("/create", [
                ClientProjectsController::class,
                "create",
            ])->name("create");

            Route::post("/create", [ProjectController::class, "store"])->name(
                "create"
            )->name("create");;

            Route::get("/update/{slug}", [
                ClientProjectsController::class,
                "edit",
            ])->name("edit");
            Route::post('rate/{slug}',[ProjectController::class,'rate'])->name('rate');
            Route::post("/update/{slug}", [
                ProjectController::class,
                "update",
            ])->name("update");

            Route::post("/draft", [ProjectController::class, "draft"])->name(
                "draft"
            );

            Route::delete("/delete/{slug}", [
                ProjectController::class,
                "destroy",
            ])->name("destroy");

            Route::post("/toggle-hidden/{slug}", [
                ProjectController::class,
                "toggleHidden",
            ])->name("toggle-hidden");

            Route::post("/toggle-save/{slug}", [
                ProjectController::class,
                "save",
            ])->withoutMiddleware(UserMiddleware::class)->name("toggle-save");

            Route::post('/invite-worker/{slug}',[
                ProjectController::class,
                'inviteWorker'
            ])->name('invite-worker');

            Route::get("/{slug}", [
                ClientProjectsController::class,
                "show",
            ])->name("show");

            Route::get("proposals/{proposal}", [
                ProjectProposalsController::class,
                "show",
            ])->name("proposals.show");
            Route::post('/proposals/{proposal}/toggle-save',[ProposalController::class,'save'])->name('proposals.toggle-save');
            Route::post("proposals/{proposal}/accept", [
                ProjectProposalsController::class,
                "accept",
            ])->name("proposals.accept");

            Route::post("proposals/{proposal}/decline", [
                ProjectProposalsController::class,
                "decline",
            ])->name("proposals.decline");

            Route::post("milestones/{milestone}/accept", [
                MilestoneController::class,
                "approve",
            ])->name("milestones.approve");
        });
    // Client Services
    Route::post("/service/orders",[\App\Http\Controllers\ServiceOrderController::class, 'store'])
        ->name('create.serviceOrder');
    Route::post("rate/{slug}",[ServiceController::class,'rate'])->name('rate.service');
    Route::post("toggle-save/{slug}",[ServiceController::class,'save'])->name('toggle-save.service');
    Route::get('service/orders/{service_order}',[\App\Http\Controllers\ServiceOrderController::class,'show'])->name('service.orders.show');
    // =================== User ===================

    // =================== Engineer ===================
    // Engineer pages
    Route::prefix("e")
        ->as("engineer.")
        ->group(function () {

            Route::get("/chat", function () {
                $chats = Auth::user()->engineer->chats()->orderBy('last_message_at','desc')->get();
                $chats->load("messages", 'user', 'worker', 'chatable');
                $chats->each(function ($chat) {
                    $chat->setMessagesAsRead();
                });
                return Inertia::render("Chat/Show", [
                    "chats" => $chats,
                    'is'=> 'worker'
                ]);
            })->name("chat");

            Route::get("/dashboard", [
                DashboardController::class,
                "engineerDashboard",
            ])->name("dashboard");

            Route::get("/my-services", [
                EngineerServicesController::class,
                "index",
            ])->name("services.index");

            Route::get("/proposals", [
                EngineerProposalsController::class,
                "index",
            ])->name("proposals.index");

            Route::get("projects/{project}", [
                WorkerProjectsController::class,
                "showEngineer",
            ])->name("projects.show");


            Route::post("contracts/sign/{contract}", [
                WorkerProjectsController::class,
                "WorkerSigned",
            ])->name("contract.sign");

            Route::get("/{slug}", [EngineerController::class, "show"])->name(
                "profile.slugged"
            );

            Route::get("/", [EngineerController::class, "show"])->name(
                "profile"
            );

            Route::get("/settings/edit", [
                EngineerController::class,
                "settings",
            ])->name("settings.show");
        });
    //Engineer profile information
    Route::prefix("engineer/profile-information")
        ->as("engineer-profile-information.")
        ->group(function () {
            Route::post("/", [EngineerController::class, "update"])->name(
                "update"
            );

            Route::post("/complete/{engineer}", [
                EngineerController::class,
                "complete",
            ])->name("complete");

            Route::post("/add/experience", [
                ExperienceController::class,
                "store",
            ])->name("add.experience");

            Route::post("/edit/experience/{id}", [
                ExperienceController::class,
                "update",
            ])->name("edit.experience");

            Route::delete("/delete/experience/{id}", [
                ExperienceController::class,
                "destroy",
            ])->name("delete.experience");

            Route::post("/add/education", [
                EducationController::class,
                "store",
            ])->name("add.education");

            Route::post("/edit/education/{id}", [
                EducationController::class,
                "update",
            ])->name("edit.education");

            Route::delete("/delete/education/{id}", [
                EducationController::class,
                "destroy",
            ])->name("delete.education");

            Route::post("/add/certificate", [
                CertificateController::class,
                "store",
            ])->name("add.certificate");

            Route::post("/edit/certificate/{id}", [
                CertificateController::class,
                "update",
            ])->name("edit.certificate");

            Route::delete("/delete/certificate/{id}", [
                CertificateController::class,
                "destroy",
            ])->name("delete.certificate");

            Route::post("/add/language", [
                EngineerController::class,
                "addMastery",
            ])->name("add.language");

            Route::post("/edit/language/{id}", [
                EngineerController::class,
                "updateMastery",
            ])->name("edit.language");

            Route::delete("/delete/language/{id}", [
                EngineerController::class,
                "destroyMastery",
            ])->name("delete.language");

            Route::post("/add/portfolio-project", [
                EngineerController::class,
                "addPortfolioProject",
            ])->name("add.portfolio-project");

            Route::post("/edit/portfolio-project/{id}", [
                PortfolioProjectController::class,
                "update",
            ])->name("edit.portfolio-project");

            Route::delete("/delete/portfolio-project/{id}", [
                PortfolioProjectController::class,
                "destroy",
            ])->name("delete.portfolio-project");
        });

    // Engineer Services
    Route::prefix("engineer/services")
        ->as("engineer.services.")
        ->group(function () {
            Route::get("/create", [
                EngineerServicesController::class,
                "create",
            ])->name("create");

            Route::post("/create", [ServiceController::class, "store"])->name(
                "create"
            );

            Route::get("/update/{slug}", [
                EngineerServicesController::class,
                "update",
            ])->name("edit");

            Route::post("/update/{slug}", [
                ServiceController::class,
                "update",
            ])->name("update");

            Route::post("/draft", [ServiceController::class, "draft"])->name(
                "draft"
            );

            Route::post("/toggle-pause/{slug}", [
                ServiceController::class,
                "togglePause",
            ])->name("toggle-pause");

            Route::delete("/delete/{slug}", [
                ServiceController::class,
                "destroy",
            ])->name("destroy");

            Route::get("/{slug}", [
                EngineerServicesController::class,
                "show",
            ])->name("show");

            Route::get("/order/{order}/accept", [
                ServiceController::class,
                "acceptOrder",
            ])->name("order.accept");

            Route::get("/order/{order}/decline", [
                ServiceController::class,
                "declineOrder",
            ])->name("order.decline");
        });
    // Engineer Projects & Proposals
    Route::prefix("engineer/proposals")
        ->as("engineer.proposals.")
        ->group(function () {
            Route::get("/create/{slug}", [
                EngineerProposalsController::class,
                "create",
            ])->name("create");

            Route::get("/{proposal}", [
                EngineerProposalsController::class,
                "show",
            ])->name("show");
        });
    // =================== Engineer ===================


    // =================== Firm ===================
    // Firm pages
    Route::prefix("f")
        ->as("firm.")
        ->group(function () {

            Route::get("/chat", function () {
                $chats = Auth::user()->firm->chats()->orderBy('last_message_at','desc')->get();
                $chats->load("messages", 'user', 'worker', 'chatable');
                $chats->each(function ($chat) {
                    $chat->setMessagesAsRead();
                });

                return Inertia::render("Chat/Show", [
                    "chats" => $chats,
                    'is'=> 'worker'
                ]);
            })->name("chat");
            Route::get("/my-services", [
                FirmServicesController::class,
                "index",
            ])->name("services.index");

            Route::get("projects/{project}", [
                WorkerProjectsController::class,
                "showFirm",
            ])->name("projects.show");

            Route::get("/my-proposals", [
                FirmProposalsController::class,
                "index",
            ])->name("proposals.index");

            Route::get("/settings/edit", [
                FirmController::class,
                "settings",
            ])->name("settings.show");
            Route::get("/", [FirmController::class, "show"])->name(
                "profile"
            );
            Route::get("/dashboard", [
                DashboardController::class,
                "firmDashboard",
            ])->name("dashboard");
            Route::get("/{slug}", [FirmController::class, "show"])->name(
                "profile.slugged"
            );

        });
    // Firm profile information
    Route::prefix("firm/profile-information")
        ->as("firm-profile-information.")
        ->group(function () {
            Route::post("/", [FirmController::class, "update"])->name(
                "update"
            );
            Route::post("/add/portfolio-project", [
                FirmController::class,
                "addPortfolioProject",
            ])->name("add.portfolio-project");

            Route::post("/edit/portfolio-project/{id}", [
                PortfolioProjectController::class,
                "update",
            ])->name("edit.portfolio-project");

            Route::delete("/delete/portfolio-project/{id}", [
                PortfolioProjectController::class,
                "destroy",
            ])->name("delete.portfolio-project");

            Route::post("/add/license", [
                LicenseController::class,
                "store",
            ])->name("add.license");

            Route::post("/edit/license/{id}", [
                LicenseController::class,
                "update",
            ])->name("edit.license");

            Route::delete("/delete/license/{id}", [
                LicenseController::class,
                "destroy",
            ])->name("delete.license");
        });
    // Firm Services
    Route::prefix("firm/services")
        ->as("firm.services.")
        ->group(function () {
            Route::get("/create", [
                FirmServicesController::class,
                "create",
            ])->name("create");

            Route::post("/create", [ServiceController::class, "store"])->name(
                "create"
            );

            Route::get("/update/{slug}", [
                FirmServicesController::class,
                "update",
            ])->name("edit");

            Route::post("/toggle-pause/{slug}", [
                ServiceController::class,
                "togglePause",
            ])->name("toggle-pause");

            Route::post("/update/{slug}", [
                ServiceController::class,
                "update",
            ])->name("update");

            Route::post("/draft", [ServiceController::class, "draft"])->name(
                "draft"
            );

            Route::delete("/delete/{slug}", [
                ServiceController::class,
                "destroy",
            ])->name("destroy");

            Route::get("/{slug}", [
                FirmServicesController::class,
                "show",
            ])->name("show");
        });

        Route::prefix("firm/proposals")
        ->as("firm.proposals.")
        ->group(function () {
            Route::get("/create/{slug}", [
                FirmProposalsController::class,
                "create",
            ])->name("create");

            Route::get("/{proposal}", [
                FirmProposalsController::class,
                "show",
            ])->name("show");
        });

        // =================== Firm ===================

    // =================== Proposals ===================
        // Proposals
        Route::prefix("proposals")
        ->as("proposals.")
        ->group(function () {
            Route::post("/create", [
                ProposalController::class,
                "store",
            ])->name("create");
        });
    // =================== Proposals ===================

    // =================== Payment ===================
    Route::prefix("payment")
        ->as("payment.")
        ->group(function () {
            Route::post('/milestone/{milestone}', [MilestoneController::class, 'pay'])->name('milestone.payment-form.show');
            Route::get("/success", function (Request $request) {
                // dd($request->all());
                return StripeClient::confirmPayment($request->session_id);
            })->name(
                "success"
            );
            Route::post("/failure", function () {
                dd('failure');
            })->name(
                "failure"
            );
        });
    // =================== Payment ===================

    Route::prefix("worker")
        ->as("worker.")
        ->group(function () {

            Route::post("/add/milestone", [
                WorkerProjectsController::class,
                "AddMilestoneDeliverable",
            ])->name("projects.milestones.add.deliverables");
        });
    Route::post("/chat/start-zoom-meeting", [
        ChatController::class,
        "createZoomLink",
    ])->name("chat.start-zoom-meeting");

});

Route::get('/milestone/pay/{milestone}', [MilestoneController::class, 'pay'])->name('milestone.pay');


// Route::prefix('pending_engineer')->group(['middleware' => config('jetstream.middleware', ['web'])], function () {

Route::post("/pending_engineer/request", [EngineerController::class, "store"])
    ->middleware(["guest:" . config("fortify.guard")])
    ->name("pending_engineer.request");

Route::post("/pending_firm/request", [FirmController::class, "store"])
    ->middleware(["guest:" . config("fortify.guard")])
    ->name("pending_firm.request");

Route::get("/finalize-registration", [RegistrationController::class, "complete"])
    ->middleware(["guest:" . config("fortify.guard")])
    ->name("complete.registration");


Route::get("/subscribe",[\App\Http\Controllers\NewsSubscriberController::class,'store'])
    ->name('subscribe');
// });

Route::post("/message/send", [
    ChatController::class,
    "sendMessage",
])->name("chat.send-message");

Route::post("/chat/start", [
    ChatController::class,
    "startChat",
])->name("chat.create");
Route::post("/chat/start/worker", [
    ChatController::class,
    "startChatFromWorker",
])->name("chat.create.worker");

Route::get("/services", [
    \App\Http\Controllers\ServiceController::class,
    "index",
])->name("services.index");


Route::middleware('service')->get("/services/{slug}", [
    \App\Http\Controllers\ServiceController::class,
    "show",
])->name("service.show");


Route::get("/projects/{slug}", [
    ProjectController::class,
    "show",
])->middleware('project')->name("project.show");

Route::get("/projects", [
    \App\Http\Controllers\ServiceController::class,
    "index",
])->name("projects.index");

Route::post("/categories/add", [CategoriesController::class, "store"])->name(
    "categories.store"
);

Route::post("/firm-types/add", [FirmTypeController::class, "store"])->name(
    "firm-type.store"
);

Route::post("/projects", [
    \App\Http\Controllers\ProjectController::class,
    "store",
]);
Route::get("/projects/new", [
    \App\Http\Controllers\ProjectController::class,
    "create",
]);
Route::get("/projects", [
    \App\Http\Controllers\ProjectController::class,
    "index",
])->name("projects.index");

Route::post("/proposals", [
    \App\Http\Controllers\ProposalController::class,
    "store",
]);
Route::get("/proposals/new", [
    \App\Http\Controllers\ProposalController::class,
    "create",
]);
Route::get("/proposals", function () {
    dd(
        \App\Models\Project::find(201)
            ->proposals()
            ->get()
    );
});

Route::get("verify-email", function () {
    return Inertia::render("Errors/VerifyEmail");
    // return view('email.verify-email');
})->name("verification.notice.muh")->middleware([
   'verify'
]);

Route::get("/approve-eng/{email}", function ($email) {
    $engineer = Engineer::where("email", $email)->firstOrFail();
    $engineer->verify();
    return "Sent email";
});

//test check add socials function
//Route::get('/checkSocials',function (){
//    Engineer::find(2)->addSocials(
//        [
//            'facebook'=>'bla',
//            'twitter'=>'bla',
//            //'bla'=>'bla', // to test tje allowed function
//        ]
//    );
//});

Route::get("/test-message/{chat}", function ($chat) {
    // get faker instance
    $faker = Faker\Factory::create();
    $sender = $faker->randomElement([[
        'sender' => 'user',
        'sender_uid' => 1,
    ], [
        'sender' => 'worker',
        'sender_uid' => Auth::id(),
    ]]);
    $message = [
        'message' => $faker->text,
        'chat_id' => $chat,
        ...$sender,
    ];

    $messageModel = Message::create($message);
    //TODO:: send mail if user not active
    $event = event(new ChatMessage($messageModel));
    dd($event, $messageModel);
});


Route::get("/test_redirect", function () {
    return Inertia::render("Verification/VerifyEmail");
});


Route::post("/projects", [
    \App\Http\Controllers\ProjectController::class,
    "store",
]);


Route::post("/register/engineer/finalize", [
    ApproveEngineerController::class,
    "store",
])
    ->middleware(["guest:" . config("fortify.guard")])
    ->name("approve.engineer.form");



Route::post("/register/firm/finalize", [ApproveFirmController::class, "store"])
    ->middleware(["guest:" . config("fortify.guard")])
    ->name("approve.firm.form");

Route::get("/stripe-payment", [StripeController::class, "handleGet"]);
Route::post("/stripe-payment", [StripeController::class, "handlePost"])->name(
    "stripe.payment"
);
Route::get('stripe-form', [StripeController::class, 'form'])->name('stripeForm');
Route::post('stripe-form/submit', [StripeController::class, 'submit'])->name('stripeSubmit');
Route::get('stripe-response/{id}', [StripeController::class, 'response'])->name('stripeResponse');

Route::get('/create-zoom-link',function () {
    return view("create_zoom_link");
});

Route::post('/meetings',[ChatController::class,'createZoomLink']);


Route::post('/skills/index', [SkillController::class, 'index'])->name('skills.index');
Route::post('/skills/store', [SkillController::class, 'store'])->name('skills.store');

Route::get('/pdf-test/{slug}', function($slug){
    
    $project= Project::where('slug',$slug)->first();
    $project->load(
        [
        "categories",
        "skills",
        "location",
        "invitedEngineers",
        "invitedFirms",
        "files",
        'languageMasteries',
        "proposals" => ["proposalable.user", "files", 'contract'],
        'contract',
        'user.location',
        ]
    );
    return view('test', compact('project'));
    // $html = view('test')->render();

    $pdf = Barryvdh\Snappy\Facades\SnappyPdf::class::loadView('test')
    ->setOption('enable-javascript', true)
    ->setOption('enable-local-file-access', true)
    ->setOption('no-stop-slow-scripts', true)
    ->setOption('javascript-delay', 3000)
    ->setPaper('a4');

    return $pdf->download('file.pdf');
    dd($pdf);

return new Response(
    // $snappy->getOutputFromHtml($html),
    200,
    array(
        'Content-Type'          => 'application/pdf',
        'Content-Disposition'   => 'attachment; filename="file.pdf"'
    )
);
} )->name('pdf.test');