package App::SCS::LatestPageSet;

use Moo;

has _parent => (is => 'ro', required => 1, init_arg => 'parent');
has _max_entries => (is => 'ro', required => 1, init_arg => 'max_entries');

sub flatten {
  my ($self) = @_;
  my @sorted = sort {
    $b->created cmp $a->created
  } $self->_parent->flatten;
  my $max = $self->_max_entries||0;
  $max && @sorted > $max ? @sorted[0..$max-1] : @sorted;
}

sub map {
  my ($self, $mapper) = @_;
  [ map $mapper->($_), $self->flatten ]
}

1;
