<!DOCTYPE html>
<html lang="<?php echo e(str_replace('_', '-', app()->getLocale())); ?>" dir="<?php echo e(session('is_rtl', false) ? 'rtl' : 'ltr'); ?>">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <?php
            // 1. Fetch Global Settings Securely
            $settings = \Illuminate\Support\Facades\Cache::rememberForever('app_settings', function () {
                return \Illuminate\Support\Facades\Schema::hasTable('settings') 
                    ? \App\Models\Setting::pluck('value', 'key')->toArray() 
                    : [];
            });
            
            $appName = config('app.name', 'OwnStore');
            $defaultDesc = $settings['seo_meta_description'] ?? 'Global B2B/B2C Marketplace';
            $defaultKeywords = $settings['seo_meta_keywords'] ?? 'marketplace, b2b, wholesale, shop';
            
            $defaultImage = \Illuminate\Support\Facades\Storage::disk('public')->exists('settings/og_image.png')
                ? asset('storage/settings/og_image.png') . '?v=' . time()
                : asset('placeholder.jpg'); 
                
            $favicon = \Illuminate\Support\Facades\Storage::disk('public')->exists('settings/favicon.png')
                ? asset('storage/settings/favicon.png') . '?v=' . time()
                : asset('favicon.ico');

            // 2. Extract Dynamic SEO Props from Inertia Controllers
            $seo = $page['props']['seo'] ?? [];
            
            $title = isset($seo['title']) ? $seo['title'] . ' | ' . $appName : $appName;
            $description = $seo['description'] ?? $defaultDesc;
            $keywords = $seo['keywords'] ?? $defaultKeywords;
            $url = $seo['url'] ?? request()->url();
            $type = $seo['type'] ?? 'website';
            
            // 3. Handle Multiple Images (For Pinterest & Facebook Carousel)
            $images = $seo['images'] ?? [];
            if (is_string($images)) {
                $images = [$images];
            }
            if (empty($images)) {
                $images = [$defaultImage];
            }
        ?>

        <!-- Basic SEO -->
        <title inertia><?php echo e($title); ?></title>
        <meta name="description" content="<?php echo e($description); ?>">
        <meta name="keywords" content="<?php echo e($keywords); ?>">
        
        <!-- Open Graph / Facebook / Pinterest / WhatsApp -->
        <meta property="og:site_name" content="<?php echo e($appName); ?>">
        <meta property="og:type" content="<?php echo e($type); ?>">
        <meta property="og:url" content="<?php echo e($url); ?>">
        <meta property="og:title" content="<?php echo e($title); ?>">
        <meta property="og:description" content="<?php echo e($description); ?>">
        
        <!-- Loop through all images for Pinterest / Facebook -->
        <?php $__currentLoopData = $images; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $image): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <meta property="og:image" content="<?php echo e($image); ?>">
            <meta property="og:image:secure_url" content="<?php echo e($image); ?>">
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

        <!-- Twitter Card -->
        <meta name="twitter:card" content="summary_large_image">
        <meta name="twitter:url" content="<?php echo e($url); ?>">
        <meta name="twitter:title" content="<?php echo e($title); ?>">
        <meta name="twitter:description" content="<?php echo e($description); ?>">
        <meta name="twitter:image" content="<?php echo e($images[0]); ?>">

        <!-- Favicon -->
        <link rel="icon" type="image/x-icon" href="<?php echo e($favicon); ?>">

        <!-- PWA Integration -->
        <?php if(($settings['pwa_enable'] ?? '0') === '1'): ?>
            <link rel="manifest" href="/manifest.json">
            <meta name="theme-color" content="<?php echo e($settings['pwa_theme_color'] ?? '#000000'); ?>">
            <link rel="apple-touch-icon" href="<?php echo e(\Illuminate\Support\Facades\Storage::disk('public')->exists('settings/pwa_icon.png') ? asset('storage/settings/pwa_icon.png') : asset('placeholder.png')); ?>">
            
            <!-- Modern PWA Standard (Fixes Warning) -->
            <meta name="mobile-web-app-capable" content="yes">
            <!-- Legacy iOS Fallback -->
            <meta name="apple-mobile-web-app-capable" content="yes">
            <meta name="apple-mobile-web-app-status-bar-style" content="black">
            
            <!-- Register Service Worker -->
            <script>
                if ('serviceWorker' in navigator) {
                    window.addEventListener('load', () => {
                        navigator.serviceWorker.register('/sw.js').then(registration => {
                            console.log('PWA ServiceWorker registered successfully.');
                        }).catch(err => {
                            console.log('PWA ServiceWorker registration failed: ', err);
                        });
                    });
                }
            </script>
        <?php endif; ?>

        <!-- Fonts -->
        <link rel="preconnect" href="https://fonts.bunny.net">
        <link href="https://fonts.bunny.net/css?family=figtree:400,500,600,700,800,900&display=swap" rel="stylesheet" />
        
        <!-- === CUSTOM HEADER SCRIPTS === -->
        <?php if(!empty($settings['custom_header_script'])): ?>
            <?php echo $settings['custom_header_script']; ?>

        <?php endif; ?>

        <!-- Scripts -->
        <?php echo app('Tighten\Ziggy\BladeRouteGenerator')->generate(); ?>
        <?php echo app('Illuminate\Foundation\Vite')->reactRefresh(); ?>
        <?php echo app('Illuminate\Foundation\Vite')(['resources/js/app.jsx', "resources/js/Pages/{$page['component']}.jsx"]); ?>
        <?php if (!isset($__inertiaSsrDispatched)) { $__inertiaSsrDispatched = true; $__inertiaSsrResponse = app(\Inertia\Ssr\Gateway::class)->dispatch($page); }  if ($__inertiaSsrResponse) { echo $__inertiaSsrResponse->head; } ?>
    </head>
    <body class="font-sans antialiased">
        <?php if (!isset($__inertiaSsrDispatched)) { $__inertiaSsrDispatched = true; $__inertiaSsrResponse = app(\Inertia\Ssr\Gateway::class)->dispatch($page); }  if ($__inertiaSsrResponse) { echo $__inertiaSsrResponse->body; } elseif (config('inertia.use_script_element_for_initial_page')) { ?><script data-page="app" type="application/json"><?php echo json_encode($page); ?></script><div id="app"></div><?php } else { ?><div id="app" data-page="<?php echo e(json_encode($page)); ?>"></div><?php } ?>

    <!-- === CUSTOM FOOTER SCRIPTS === -->
        <?php if(!empty($settings['custom_footer_script'])): ?>
            <?php echo $settings['custom_footer_script']; ?>

        <?php endif; ?>
    </body>
</html><?php /**PATH C:\laragon\www\laravel\resources\views/app.blade.php ENDPATH**/ ?>