package SCSite::SubListFilter;

use Moo;

with 'SCSite::Filter';

sub _filter_stream {
  my ($self, $stream, $config, $page) = @_;
  my $max = $config->{max_entries}||undef; # explicit undef (not 0)
  my %child =
    map +(exists $config->{$_} ? ($_ => $config->{$_}) : ()),
      qw(min_depth max_depth at_depth);
  $stream->select('.SubList')
         ->repeat_content($page->children(%child)->latest($max)->map(sub {
             my $o = shift;
             sub {
               $_->select('.entry.title')->replace_content($o->title)
                 ->select('.entry.subtitle')->replace_content($o->subtitle)
                 ->select('.entry.description')->replace_content($o->description)
                 ->select('.entry.published_at')->replace_content($o->published_at)
                 ->select('.entry.body')->replace_content(\$o->body)
                 ->select('.entry.link')->set_attribute(href => $o->path);
             }
          }));
}

1;
