<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="csrf-token" content="{{ csrf_token() }}">
        @php
            $assetBaseUrl = $assetBaseUrl ?? rtrim(request()->getSchemeAndHttpHost() . request()->getBasePath(), '/');
            $cssPath = public_path('support-desk.css');
            $jsPath = public_path('support-desk.js');
            $cssVersion = is_file($cssPath) ? filemtime($cssPath) : time();
            $jsVersion = is_file($jsPath) ? filemtime($jsPath) : time();
            $supportDeskConfig = [
                'appName' => $appName ?? config('app.name', 'Support Desk'),
                'apiBaseUrl' => $apiBaseUrl ?? url('/api'),
                'assetBaseUrl' => $assetBaseUrl,
                'embedMode' => $embedMode ?? false,
                'parentOrigin' => $parentOrigin ?? null,
                'embedHandshakeTimeoutMs' => $embedHandshakeTimeoutMs ?? 15000,
            ];
        @endphp
        <title>@yield('title', $appName ?? config('app.name', 'Support Desk'))</title>
        <link rel="preconnect" href="https://fonts.bunny.net">
        <link href="https://fonts.bunny.net/css?family=instrument-sans:400,500,600,700,800" rel="stylesheet" />
        <link rel="stylesheet" href="{{ $assetBaseUrl }}/support-desk.css?v={{ $cssVersion }}">
        @stack('head')
    </head>
    <body class="support-desk-body">
        @yield('body')

        <script>
            window.SupportDeskConfig = {!! json_encode($supportDeskConfig, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) !!};
        </script>
        <script src="{{ $assetBaseUrl }}/support-desk.js?v={{ $jsVersion }}" defer></script>
        @stack('scripts')
    </body>
</html>
