<?php
$userRole = session()->get('role'); // assuming you store it as 'role'
$quickTourUrl = base_url('/help_center'); // default

switch ($userRole) {
  case 'parent':
    $quickTourUrl = base_url('/parent');
    break;
  case 'teacher':
    $quickTourUrl = base_url('/teacher');
    break;
  case 'teacher_assistant':
    $quickTourUrl = base_url('/teacher');
    break;
}
?>
<link rel="stylesheet" href="<?= base_url('assets/css/landing_page.css') ?>">

<footer class="footer mt-auto custom-footer text-white py-4">
  <div class="container">
    <div class="row align-items-start justify-content-between">
      <!-- Contact Info -->
      <div class="col-md-6 col-12 mb-3 mb-md-0 text-md-start">
        <ul class="list-unstyled mb-0 info-list">
          <li class="info-title"></li>
          <li><i class="fa fa-map-marker-alt me-2"></i>5 Courthouse Lane, Chelmsford, MA 01824</li>
          <li><i class="fa fa-phone-alt me-2"></i>+1 978-364-0219</li>
          <li><i class="fa fa-envelope me-2"></i>alrahma.isgl@gmail.com</li>
        </ul>
      </div>

      <!-- Policy Links: centered on small, right on md+ -->
      <div class="col-md-4 col-12 text-center text-md-end">
        <ul class="list-unstyled mb-0 info-list">
          <li class="info-title text-center text-md-end"></li>
          <li>
            <a href="<?= base_url('privacy_policy.pdf') ?>" target="_blank" rel="noopener noreferrer"
              class="pdf-link" data-filename="privacy_policy.pdf">
              <i class="fas fa-file-pdf me-1"></i>Privacy Policy
            </a>
          </li>
          <li>
            <a href="<?= base_url('terms_of_service.pdf') ?>" target="_blank" rel="noopener noreferrer"
              class="pdf-link" data-filename="terms_of_service.pdf">
              <i class="fas fa-file-pdf me-1"></i>Terms of Service
            </a>
          </li>
          <li>
            <a href="<?= base_url('account_creation_guide.pdf') ?>" target="_blank" rel="noopener noreferrer"
              class="pdf-link" data-filename="account_creation_guide.pdf">
              <i class="fas fa-file-pdf"></i>How To Create An Account
            </a>
          </li>
        </ul>
      </div>
    </div>
  </div>
  <br>
  <p class="text-center text-white">© 2026 Al Rahma Sunday School by ISGL. All Rights Reserved.</p>
</footer>

<script>
  document.addEventListener('DOMContentLoaded', function() {
    // Check if PDF files exist and add error handling
    document.querySelectorAll('.pdf-link').forEach(link => {
      const pdfUrl = link.getAttribute('href');

      // Test if the PDF exists
      fetch(pdfUrl, {
          method: 'HEAD'
        })
        .then(response => {
          if (!response.ok) {
            // File doesn't exist or is inaccessible
            link.style.opacity = '0.7';
            link.title = 'File might be temporarily unavailable';
            console.warn('PDF might be missing:', pdfUrl);

            // Modify click behavior to show helpful message
            link.addEventListener('click', function(e) {
              if (!confirm('The PDF file might be temporarily unavailable. Try to open it anyway?')) {
                e.preventDefault();
              }
            });
          }
        })
        .catch(error => {
          console.error('Error checking PDF:', pdfUrl, error);
          link.style.opacity = '0.7';
          link.title = 'File check failed';
        });
    });
  });
</script>