---
import BaseLayout from '../layouts/BaseLayout.astro';
import { site } from '../lib/site';

const runwayPattern = /^Runway\s+(\d+)\s+-\s+([^\s]+)\s+LDA\s+\(([^)]+)\)\s+Code\s+(\d+)\s+\(([^)]+)\)$/;

const runwayRows = site.runwayFacts
  .map((fact) => {
    const match = fact.match(runwayPattern);

    if (!match) return null;

    const [, runway, lda, surface, code, circuits] = match;
    return { runway, lda, surface, code, circuits };
  })
  .filter((row): row is { runway: string; lda: string; surface: string; code: string; circuits: string } => row !== null);

const otherFacts = site.runwayFacts.filter((fact) => !fact.match(runwayPattern));
---

<BaseLayout title="Pilot Info" description="Essential information for pilots planning a visit to Swansea Airport.">
  <div class="container prose">
    <p class="eyebrow">Pilot info</p>
    <h1 class="section-title">Communications</h1>
    <p>
      Swansea Airport operates a Air / Ground Communication Service, callsign Swansea Radio on 119.705. This service is staffed by volunteers and may not be operational at all times.
      </p>
     <p>
When the Tower is unavailable, this will be NOTAMed and blind calls to Swansea Traffic shall be made on the Air / Ground frequency
    </p>

    <h2>Runway Information</h2>
    <div class="runway-table-wrap">
      <table class="runway-facts-table">
        <thead>
          <tr>
            <th scope="col">Runway</th>
            <th scope="col">LDA</th>
            <th scope="col">Surface</th>
            <th scope="col">Code</th>
            <th scope="col">Circuits</th>
          </tr>
        </thead>
        <tbody>
          {runwayRows.map((runway) => (
            <tr>
              <td>{runway.runway}</td>
              <td>{runway.lda}</td>
              <td>{runway.surface}</td>
              <td>{runway.code}</td>
              <td>{runway.circuits}</td>
            </tr>
          ))}
        </tbody>
      </table>
    </div>

    {otherFacts.length > 0 && (
      <ul>
        {otherFacts.map((fact) => <li>{fact}</li>)}
      </ul>
    )}

    <p>Circuits at 1000ft agl. Overhead joins not permitted when Parachuting is active.



  </p>

    <h2>Arrival essentials</h2>
    <div class="cards-grid">
      <article class="card">
        <h3>PPR</h3>
        <p>Pre-landing fogging is presented prominently here and can be linked to the relevant Directus content or booking workflow.</p>
      </article>
      <article class="card">
        <h3>Book out</h3>
        <p>Departure procedures and any required outbound reporting remain in the same controlled page structure.</p>
      </article>
      <article class="card">
        <h3>Fuel and services</h3>
        <p>Fuel prices are shown on the homepage and can be reused here with the same data source.</p>
      </article>
    </div>
  </div>
</BaseLayout>
