// SPDX-FileCopyrightText: 2026 Ololduck <ololduck@vit.am> and contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later

//! View for the report submission form.

use actix_web::HttpResponse;
use maud::{Markup, html};

use super::{Page, ViewCtx};

/// The report form page.
///
/// # Arguments
/// * `viewer` - The currently logged-in user's name, if any
/// * `target` - The main target URL (actor or note) to report
/// * `objects` - Additional object URLs to include in the report
/// * `is_remote` - Whether the target is on a remote instance
pub fn report_form(
    viewer: Option<&str>,
    target: &str,
    objects: &[String],
    is_remote: bool,
) -> HttpResponse {
    Page {
        title: "Frogue - Report".to_string(),
        ctx: ViewCtx::from_viewer(viewer),
        extra_head: None,
        body: ReportFormBody {
            target,
            objects,
            is_remote,
        },
    }
    .into_response()
}

struct ReportFormBody<'a> {
    target: &'a str,
    objects: &'a [String],
    is_remote: bool,
}

impl maud::Render for ReportFormBody<'_> {
    fn render(&self) -> Markup {
        html! {
            h1 { "Report Content" }

            form method="post" action="/report" {
                // Hidden field for target
                input type="hidden" name="target_url" value=(self.target);

                // Object URLs as checkboxes
                @if !self.objects.is_empty() {
                    fieldset {
                        legend { "Select objects to include in the report:" }
                        @for object_url in self.objects {
                            label {
                                input type="checkbox" name="object_urls" value=(object_url) checked;
                                (object_url)
                            }
                            br;
                        }
                    }
                }

                // Comment textarea
                fieldset {
                    legend { "Comment (optional)" }
                    textarea name="comment" rows="5" cols="50" placeholder="Please describe the issue..." {}
                }

                // Forward checkbox (default checked for remote targets)
                @if self.is_remote {
                    label {
                        input type="checkbox" name="forward" value="on" checked;
                        " Forward this report to the remote instance"
                    }
                    br;
                }

                button type="submit" { "Submit Report" }
            }
        }
    }
}
