<?php
    $socialSiteName = $settings->site_name ?? config('app.name', 'Savanna Courier');
    $socialTitle = $previewTitle ?? (($settings->site_title ?? null) ?: $socialSiteName);
    $socialDescription = $previewDescription ?? (($settings->description ?? null) ?: ($socialSiteName . ' is a global logistics service provider offering premium shipping, courier, and tracking services worldwide.'));
    
    // Use site logo as primary social image
    $logoPath = $settings->logo ?? '';
    $fallbackImagePath = 'temp/custom/images/social-preview.png';
    $socialImageVersion = '20260520';
    
    // Build absolute URL for site
    $siteRoot = rtrim((string) ($settings->site_address ?? ''), '/');
    if ($siteRoot === '') {
        $siteRoot = rtrim(url('/'), '/');
    }
    if (! preg_match('/^https?:\/\//i', $siteRoot)) {
        $siteRoot = 'https://' . ltrim($siteRoot, '/');
    }
    $siteRoot = preg_replace('/^http:\/\//i', 'https://', $siteRoot);
    
    // Build social image URL - use logo if available, fallback to default image
    if (!empty($logoPath)) {
        // Logo is stored in storage, build public URL
        $socialImage = $siteRoot . '/storage/' . $logoPath . '?v=' . $socialImageVersion;
    } else {
        $socialImage = $siteRoot . '/' . $fallbackImagePath . '?v=' . $socialImageVersion;
    }
    
    $socialUrl = $previewUrl ?? ($siteRoot . (request()->getPathInfo() === '/' ? '/' : request()->getPathInfo()));
    $socialImageAlt = $previewImageAlt ?? ($socialSiteName . ' - Premium Global Shipping Solutions');
?>

<!-- Primary Meta Tags -->
<title><?php echo e($socialTitle); ?></title>
<meta name="title" content="<?php echo e($socialTitle); ?>" />
<meta name="description" content="<?php echo e($socialDescription); ?>" />

<!-- Open Graph / Facebook -->
<link rel="canonical" href="<?php echo e($socialUrl); ?>" />
<meta property="og:type" content="website" />
<meta property="og:site_name" content="<?php echo e($socialSiteName); ?>" />
<meta property="og:title" content="<?php echo e($socialTitle); ?>" />
<meta property="og:description" content="<?php echo e($socialDescription); ?>" />
<meta property="og:url" content="<?php echo e($socialUrl); ?>" />
<meta property="og:image" content="<?php echo e($socialImage); ?>" />
<meta property="og:image:secure_url" content="<?php echo e($socialImage); ?>" />
<meta property="og:image:type" content="image/png" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta property="og:image:alt" content="<?php echo e($socialImageAlt); ?>" />

<!-- Twitter -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="<?php echo e($socialTitle); ?>" />
<meta name="twitter:description" content="<?php echo e($socialDescription); ?>" />
<meta name="twitter:image" content="<?php echo e($socialImage); ?>" />

<!-- Additional SEO Meta -->
<meta name="application-name" content="<?php echo e($socialSiteName); ?>" />
<meta name="theme-color" content="#f7931a" />
<?php /**PATH /home/kdcwrbdi/public_html/resources/views/partials/social-preview-meta.blade.php ENDPATH**/ ?>