---
import BaseLayout from '../layouts/BaseLayout.astro';
import FuelPricesWidget from '../components/FuelPricesWidget.astro';
import { getFuelPrices } from '../lib/directus';
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));
const fuelPrices = await getFuelPrices();
const fuelServiceNotes = [
  'Attended refuelling is available. Please advise on PPR, or after landing, if fuel is required.',
  'JET A1 is available gravity fed or pressurised. Rotors-running and out-of-hours fuel may be available by prior arrangement.',
];
---

<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">Operating hours</h1>
    <p><strong>Airport open:</strong> Monday to Sunday, 0900-1800 local time.</p>
    <p><strong>Licensed with fire cover:</strong> Friday, Saturday, and Sunday only. RFFS Cat A1.</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>
    <p>Please submit your PPR request before flying into Swansea.</p>

  
    <center><a class="button primary" href="/ppr/">Request PPR</a></center>
    <h2>Procedures</h2>
    <p>
      <img src="/images/SDMAP.png" alt="Swansea Airport procedures map" loading="lazy" />
    </p>

    <h3>Arrivals</h3>
    <p>
      Make your initial arrival call 10 NM from the ATZ. From the east, this is above Port Talbot.
      From the north, this is above Ammanford/Tycroes. From the west, this is just off the Gower
      coast approaching Rhossili. From the south, this is over the sea abeam Porthcawl.
    </p>
    <p>
      The Air/Ground service will advise if parachuting is in progress, as well as providing the
      usual joining information. If parachuting is in progress, <strong>no overhead joins are permitted</strong>
      and there is to be <strong>no dead-side flight within the ATZ</strong>.
    </p>
    <p>All joins are to be downwind or base leg joins only.</p>
    <p>
      <strong>Caution:</strong> Pilots should be aware of possible windshear on short final for
      Runway 10, especially when surface winds are above 10 kt.
    </p>
    <p>
      When already on frequency, parachuting will be notified by the Air/Ground service using the
      following message:
    </p>
    <blockquote>
      ALL STATIONS, THIS IS SWANSEA RADIO. PARACHUTING HAS COMMENCED ON THE NORTHERN/SOUTHERN PLA.
      NO OVERHEAD JOINS, NO DEAD SIDE FLIGHT.
    </blockquote>
    <p>
      When this is called, <strong>no overhead joins or dead-side flight is permitted in the ATZ</strong>.
    </p>

    <h3>Departures</h3>
    <p>
      <strong>All helicopters are to request start.</strong> This is to protect parachuting operations.
      If parachuting descent is already taking place, pilots will be advised to start only after the
      parachuting descent has completed.
    </p>
    <p>When parachuting is in progress, all departing aircraft should:</p>
    <ul>
      <li>Climb straight ahead until clear of the ATZ.</li>
      <li>Climb on the crosswind until clear of the ATZ.</li>
    </ul>
    <p>
      <strong>Helicopters are to adhere to the circuit patterns when parachuting is taking place.</strong>
    </p>
        <p>
      <strong>
        Be advised that these procedures form part of the rules of the aerodrome. Permission to use
        the aerodrome will be revoked if they are not adhered to.
      </strong>
    </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>
    )}


    <FuelPricesWidget contactHref="/contact/" fuelPrices={fuelPrices} sectionId="fuel" serviceNotes={fuelServiceNotes} />

   
  </div>
</BaseLayout>
