package App::SCS::Plugin::Core::PagePlugin::Template;

use Moo;

with 'App::SCS::Role::PagePlugin';

has templates => (is => 'ro', required => 1);

has name => (is => 'ro', required => 1);

sub filter_html_zoom {
  my ($self, $zoom) = @_;
  my $template_page = $self->templates->get({ path => $self->name })
    or die "No such template ${\$self->name}";
  my $template_zoom = HTML::Zoom->from_html($template_page->html);
  my @ev;
  $template_zoom->collect('*[data-replace]', { into => \@ev })
                ->then
                ->${\sub {
                    my $sel = $ev[0]->{attrs}{'data-replace'};
                    $zoom->collect($self, { into => \my @replace })->run;
                    shift->replace(\@replace);
                  }}
}

1;
