#! /usr/bin/env raku

use Transit::Network;

unit sub MAIN ($file where $file ~~ /\.def$/ && $file.IO.f && $file.IO.r);

my @rows = $file.IO.lines.reverse;

my $max-down = 1;
my $max-up   = 1;
my $first-stop;
my $last-stop;

for @rows -> $row
{
  next unless $row;
  next if $row.substr(0,1) eq "#";

  my ($id, $down, $up, $name) = $row.split(/\s+/, 4);

  $first-stop = $name;
  $last-stop  = $name unless $last-stop;

  $max-down = max($max-down, $down.chars);
  $max-up   = max($max-up,   $up.chars);
}

say "#";
say "# $last-stop - $first-stop";
say "# ", "-" x 30;

for @rows -> $row
{
  next unless $row;
  next if $row.substr(0,1) eq "#";

  my ($id, $down, $up, $name) = $row.split(/\s+/, 4);

  say "$id $up", " " x ($max-up - $up.chars), " ", $down, " " x ($max-down - $down.chars), " ", $name;
}
