use App::Podviewer;

#| Show greeting message.
multi MAIN {
    my App::Podviewer $app .= new;
    my $open-pod = $app.show-greeting;
}

#| Display Pod file with provided CSS.
multi MAIN(
    Str $pod,      #= Path to Pod file
    Str :$css = '' #= CSS stylesheet
) {
    my App::Podviewer $app .= new: pod-file => $pod, :$css;
    show-file($app);
}

#| Choose Pod file from dialog and display it.
multi MAIN(
    :o(:$open)! #= Launch dialog to select Pod file
) {
    my App::Podviewer $app .= new;
    my ($pod, $is-interrupted) = $app.select-pod();
    $app.pod-file = $pod.subst(/\n+$/, '');
    show-file($app) unless $is-interrupted;
}

# Display HTML file and save it if requested.
sub show-file( App::Podviewer $app --> Nil ) {
    my ($generated-file, Bool $want-to-save) = $app.show-html();
    if $want-to-save {
        # get path and remove trailing newline from path.
        my ($file-path, $is-interrupted) = $app.save-html;
        unless $is-interrupted {
            copy($generated-file, $file-path.subst(/\n+$/,''))
        }
    }
}
