<?php
$footer_settings = array();
try {
    $footer_db = getDBConnection();
    $footer_stmt = $footer_db->query("SELECT setting_key, setting_value FROM system_settings");
    while ($row = $footer_stmt->fetch(PDO::FETCH_ASSOC)) {
        $footer_settings[$row['setting_key']] = $row['setting_value'];
    }
} catch (Exception $e) {
    $footer_settings = array(
        'company_address' => 'Riyadh, Saudi Arabia',
        'company_phone' => '0501234567',
        'notification_email' => 'info@allura.com',
        'working_hours_start' => '08:00',
        'working_hours_end' => '18:00',
        'working_days' => '["sunday","monday","tuesday","wednesday","thursday","friday","saturday"]'
    );
}

$start_time = date('g:i A', strtotime($footer_settings['working_hours_start'] ?? '08:00'));
$end_time = date('g:i A', strtotime($footer_settings['working_hours_end'] ?? '18:00'));
$working_days = json_decode($footer_settings['working_days'] ?? '[]', true);

$weekday_hours = $start_time . ' - ' . $end_time;

$weekend_hours = '2:00 PM - 10:00 PM';
?>

<footer class="site-footer">
  <div class="footer-content">
      <div class="footer-section">
        <h3><i class="fas fa-link"></i> Quick Links</h3>
        <ul>
          <li><a href="/allura/home.php"><i class="fas fa-home"></i> Home</a></li>
          <li><a href="/allura/service.php"><i class="fas fa-tshirt"></i> Services</a></li>
          <li><a href="/allura/contact.php"><i class="fas fa-envelope"></i> Contact</a></li>
          <li><a href="/allura/about.php"><i class="fas fa-info-circle"></i> About</a></li>
        </ul>
      </div>

      <div class="footer-section">
        <h3><i class="fas fa-user"></i> Account</h3>
        <ul>
          <li><a href="/allura/cart.php"><i class="fas fa-shopping-cart"></i> Cart</a></li>
          <li><a href="/allura/php/profile.php"><i class="fas fa-user-circle"></i> My Profile</a></li>
        </ul>
      </div>

      <div class="footer-section">
        <h3><i class="fas fa-clock"></i> Working Hours</h3>
        <ul>
          <?php if ($weekday_hours): ?>
          <li><i class="fas fa-calendar-day"></i> Sunday - Thursday</li>
          <li class="hours-time"><?php echo htmlspecialchars($weekday_hours); ?></li>
          <?php endif; ?>
          <?php if ($weekend_hours): ?>
          <li><i class="fas fa-calendar-week"></i> Friday - Saturday</li>
          <li class="hours-time"><?php echo htmlspecialchars($weekend_hours); ?></li>
          <?php endif; ?>
        </ul>
      </div>

      <div class="footer-section">
        <h3><i class="fas fa-phone"></i> Contact Info</h3>
        <ul>
          <li><br><a href="tel:<?php echo htmlspecialchars($footer_settings['company_phone']); ?>">
            <i class="fas fa-phone-alt"></i> <?php echo htmlspecialchars($footer_settings['company_phone']); ?>
          </a></li>
          <li><br><a href="mailto:<?php echo htmlspecialchars($footer_settings['notification_email']); ?>">
            <i class="fas fa-envelope"></i> <?php echo htmlspecialchars($footer_settings['notification_email']); ?>
          </a></li>
          <li><br><i class="fas fa-map-marker-alt"></i> <?php echo htmlspecialchars($footer_settings['company_address']); ?></li>
        </ul>
      </div>
    </div>
  </div>

  <div class="footer-bottom">
    <div class="footer-bottom-content">
      <p>&copy; <?php echo date("Y"); ?> Allura Dry Clean. All rights reserved.</p>
      <div class="footer-badges">
        <span class="badge"><i class="fas fa-shield-alt"></i> Secure Service</span>
        <span class="badge"><i class="fas fa-leaf"></i> Eco-Friendly</span>
        <span class="badge"><i class="fas fa-award"></i> Quality Guaranteed</span>
      </div>
    </div>
  </div>
</footer>