@php
  use App\General\SettingsClass;
  use Illuminate\Support\Facades\DB;
  use App\Models\User;
  

  $logoPath = null;
  $companyName = env('APP_NAME', 'WMS');
  $companyAddress = '';
  $companyCity = '';
  $companyState = '';
  $companyPostCode = '';
  $companyCountry = '';
  $companyPhone = 'Contact Information';
  $companyEmail = env('EMAIL_ADDRESS', 'support@example.com');
  
  // Get admin settings data
    $admin = User::where('user_type', config('constants.user_types.admin'))->first();
    if ($admin) {
      $settings = DB::table('adminsettings')
          ->where('customer_id', $admin->id)
          ->get();
          
      // Transform into key-value pairs for easier access
      $settingsData = [];
      foreach ($settings as $setting) {
          $settingsData[$setting->key] = $setting->value;
      }
      
      // Get logo
      if (isset($settingsData['brand_logo_dark'])) {
          $logoPath = $settingsData['brand_logo_dark'];
      }
      
      // Get company information
      if (isset($settingsData['company_company_name'])) {
          $companyName = $settingsData['company_company_name'];
      }
      if (isset($settingsData['company_company_address'])) {
          $companyAddress = $settingsData['company_company_address'];
      }
      
      if (isset($settingsData['company_company_city'])) {
          $companyCity = $settingsData['company_company_city'];
      }
      
      if (isset($settingsData['company_company_state'])) {
          $companyState = $settingsData['company_company_state'];
      }
      
      if (isset($settingsData['company_company_post_code'])) {
          $companyPostCode = $settingsData['company_company_post_code'];
      }
      
      if (isset($settingsData['company_company_country'])) {
          $companyCountry = $settingsData['company_company_country'];
      }
      
      if (isset($settingsData['company_company_telephone'])) {
          $companyPhone = $settingsData['company_company_telephone'];
      }
      
      if (isset($settingsData['company_company_email'])) {
          $companyEmail = $settingsData['company_company_email'];
      }
    }
  
  
  // Format full address
  $fullAddress = $companyAddress;
  if (!empty($companyCity)) {
      $fullAddress .= ', ' . $companyCity;
  }
  if (!empty($companyState)) {
      $fullAddress .= ', ' . $companyState;
  }
  if (!empty($companyPostCode)) {
      $fullAddress .= ' ' . $companyPostCode;
  }
  if (!empty($companyCountry)) {
      $fullAddress .= ', ' . $companyCountry;
  } 
  
  // Status configuration defaults in case they're not provided
  if (!isset($status_config)) {
    $status_config = [
      'subject' => $subject ?? 'Payment Notification',
      'status_text' => 'Unknown',
      'color' => '#6B7280', // Gray
      'background' => 'linear-gradient(135deg, #F3F4F6 0%, #E5E7EB 100%)',
      'icon' => '📄',
      'message' => 'Payment status information.',
      'action_required' => false,
      'action_message' => ''
    ];
  }
@endphp

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>{{ $subject }}</title>
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet">
  <style>
    * {
      padding: 0;
      margin: 0;
      font-family: 'Inter', sans-serif !important;
      box-sizing: border-box;
    }
    
    body {
      background-color: #f8f9fa;
      padding: 20px 0;
    }
    
    #email-body {
      min-width: 600px;
      width: 600px;
      max-width: 600px;
      margin: 0 auto;
      background-color: #ffffff;
      font-family: 'Inter', sans-serif !important;
      box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
      border-radius: 8px;
      overflow: hidden;
    }
    
    #email-header {
      padding: 18px 25px;
      background: #fff !important;
      text-align: left;
      position: relative;
    }
    
    #email-header::after {
      content: '';
      position: absolute;
      top: 0;
      right: 0;
      width: 100px;
      height: 100%;
      background: #fff !important;
      transform: skew(-15deg);
      transform-origin: top right;
    }
    
    #email-header img {
      height: 54px;
      width: auto;
      display: inline-block;
    }
    
    #email-header h2 {
      color: white;
      margin: 0;
      font-weight: 700;
      font-size: 24px;
      text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    }
    
    #email-content {
      padding: 42px 34px;
      color: #333333;
    }
    
    .greeting-section {
      font-size: 14px;
      margin-bottom: 18px;
      color: #6b7280;
    }
    
    .greeting-section strong {
      color: #1f2937;
      font-weight: 600;
    }
    
    .notification-title {
      font-size: 22px;
      font-weight: 700;
      margin-bottom: 20px;
      color: {{ $status_config['color'] }};
      display: flex;
      align-items: center;
      gap: 10px;
    }
    
    .notification-title::before {
      content: "{{ $status_config['icon'] }}";
      font-size: 24px;
    }
    
    .alert-box {
      background: {{ $status_config['background'] }};
      border: 1px solid {{ $status_config['color'] }};
      border-radius: 8px;
      padding: 16px;
      margin-bottom: 24px;
      position: relative;
    }
    
    .alert-box::before {
      content: '';
      position: absolute;
      left: 0;
      top: 0;
      bottom: 0;
      width: 4px;
      background: {{ $status_config['color'] }};
      border-radius: 4px 0 0 4px;
    }
    
    .alert-box p {
      margin: 0;
      font-size: 14px;
      color: {{ $status_config['color'] }};
      font-weight: 500;
    }
    
    .info-card {
      background: #f9fafb;
      border: 1px solid #e5e7eb;
      border-radius: 8px;
      padding: 20px;
      margin-bottom: 20px;
      position: relative;
      transition: transform 0.2s ease;
    }
    
    .info-card:hover {
      transform: translateY(-2px);
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }
    
    .info-card h3 {
      color: #1f2937;
      margin-bottom: 12px;
      font-weight: 600;
      font-size: 16px;
      display: flex;
      align-items: center;
      gap: 8px;
    }
    
    .customer-details h3::before {
      content: '👤';
      font-size: 18px;
    }
    
    .order-details h3::before {
      content: '📋';
      font-size: 18px;
    }
    
    .info-card p {
      margin-bottom: 8px;
      font-size: 14px;
      color: #374151;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    
    .info-card p:last-child {
      margin-bottom: 0;
    }
    
    .info-card strong {
      font-weight: 600;
      color: #1f2937;
      min-width: 120px;
    }
    
    .info-value {
      font-weight: 500;
      color: #4b5563;
    }
    
    .amount-highlight {
      background: {{ $status_config['background'] }};
      color: {{ $status_config['color'] }} !important;
      padding: 4px 8px;
      border-radius: 4px;
      font-weight: 600;
    }
    
    .status-badge {
      display: inline-block;
      padding: 4px 12px;
      border-radius: 20px;
      font-size: 12px;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.5px;
      background: {{ $status_config['background'] }};
      color: {{ $status_config['color'] }};
      border: 1px solid {{ $status_config['color'] }};
    }
    
    .email-content-area p {
      font-size: 14px;
      margin-bottom: 15px;
      line-height: 1.6;
      color: #4b5563;
    }
    
    .action-required {
      background: linear-gradient(135deg, #FEE2E2 0%, #FECACA 100%);
      border: 1px solid #EF4444;
      border-radius: 8px;
      padding: 16px;
      margin: 24px 0;
      text-align: center;
    }
    
    .action-required p {
      color: #991B1B;
      font-weight: 600;
      margin-bottom: 8px;
    }
    
    .action-required small {
      color: #7F1D1D;
      font-size: 12px;
    }
    
    #email-footer {
      margin-top: 20px;
    }
    
    #tagline-section {
      background-color: #EDEDED;
      padding: 16px;
      text-align: center;
      font-size: 13px;
      color: #6b7280;
    }
    
    .big-tagline {
      margin-top: 8px;
      font-size: 14px;
      color: #374151;
    }
    
    .big-tagline a {
      color: #787f83;
      font-weight: 700;
      text-decoration: none;
    }
    
    .company-details {
      padding: 20px;
      text-align: center;
    }
    
    .footer-logo {
      height: 35px;
      margin-bottom: 12px;
    }
    
    .company-title {
      font-size: 14px;
      font-weight: 600;
      color: #1f2937;
      margin-bottom: 8px;
    }
    
    .company-address-contact {
      font-size: 12px;
      color: #6b7280;
      line-height: 1.5;
    }
    
    .divider {
      height: 1px;
      background: linear-gradient(90deg, transparent 0%, #e5e7eb 50%, transparent 100%);
      margin: 24px 0;
    }
  </style>
</head>
<body>
  <div id="email-body">
    <div id="email-header">
      @if(!empty($logoPath) && file_exists(public_path($logoPath)))
        <img src="{{ url($logoPath) }}" alt="WMS Logo" />
      @else
          <h2>{{ $companyName }}</h2>
      @endif
    </div>

    <div id="email-content">
      <div class="greeting-section">
        Hello, <strong>Admin</strong>
      </div>

      <div class="notification-title">
        {{ $subject }}
      </div>

      <div class="alert-box">
        <p>
          {{ $status_config['message'] }}
        </p>
      </div>

      <div class="info-card customer-details">
        <h3>Customer Information</h3>
        <p><strong>Name:</strong> <span class="info-value">{{ $customer_name }}</span></p>
        <p><strong>Email:</strong> <span class="info-value">{{ $customer_email }}</span></p>
      </div>

      <div class="info-card order-details">
        <h3>Order Details</h3>
        <p><strong>Order ID:</strong> <span class="info-value">{{ $order_id }}</span></p>
        <p><strong>Plan:</strong> <span class="info-value">{{ $plan_name }}</span></p>
        <p><strong>Amount:</strong> <span class="amount-highlight">{{ $price }} {{ $currency }}</span></p>
        <p><strong>Payment Type:</strong> <span class="info-value">{{ $payment_type }}</span></p>
        <p><strong>Status:</strong> <span class="status-badge">{{ $status_config['status_text'] }}</span></p>
        <p><strong>Recurring:</strong> <span class="info-value">{{ $is_recurring }}</span></p>
        <p><strong>Period:</strong> <span class="info-value">{{ $interval }} Month(s)</span></p>
        <p><strong>Date:</strong> <span class="info-value">{{ $date }}</span></p>
      </div>

      @if($status_config['action_required'])
        <div class="action-required">
          <p>⚠️ Action Required</p>
          <small>{{ $status_config['action_message'] }}</small>
        </div>
      @endif

      <div class="divider"></div>

      <div class="email-content-area">
        @php
          $statusTexts = [
            0 => 'This payment request requires your review and approval through the admin dashboard. Please verify the payment before approving the request.',
            1 => 'This payment has been automatically processed and the customer\'s account has been updated successfully. The customer has been notified via email.',
            2 => 'This payment has failed. You may need to contact the customer to arrange an alternative payment method.',
            3 => 'This payment has been refunded to the customer. The subscription or plan access may have been revoked.',
            4 => 'This payment request has been rejected. No further action is required.'
          ];
          
          $statusText = $statusTexts[$payment_status] ?? $statusTexts[0];
        @endphp
        
        <p>{{ $statusText }}</p>
        
        @if($status_config['action_required'])
          <p>Once processed, the customer will receive an appropriate confirmation email based on your action.</p>
        @else
          <p>No further action is required from your end.</p>
        @endif
      </div>
    </div>

    <div id="email-footer">
      <div id="tagline-section">
        <p>This is an auto-generated email. Please do not reply.</p>
        <p class="big-tagline">For questions or support, contact 
          <a href="mailto:{{ $companyEmail }}">{{ $companyEmail }}</a>
        </p>
      </div>

      <div class="company-details">
        @if(!empty($logoPath) && file_exists(public_path($logoPath)))
          <img src="{{ url($logoPath) }}" class="footer-logo" alt="Logo">
        @endif
        <div class="company-title">{{ $companyName }}</div>
        <div class="company-address-contact">
          {{ $fullAddress }}<br />
          Call: {{ $companyPhone }}
        </div>
      </div>
    </div>
  </div>
</body>
</html>