use crate::models;
use leptos::prelude::*;

#[component]
#[tracing::instrument(skip_all)]
pub fn ProblemInfo(#[prop(into)] problem: Signal<models::Problem>) -> impl IntoView {
    tracing::trace!("Enter problem info");

    let name = Signal::derive(move || problem.read().name.clone());
    let set_by = Signal::derive(move || problem.read().set_by.clone());
    let method = Signal::derive(move || problem.read().method.to_string());

    view! {
        <div class="grid grid-rows-none gap-y-1 gap-x-0.5 grid-cols-[auto,1fr]">
            <NameValue name="Name:" value=name />
            <NameValue name="Method:" value=method />
            <NameValue name="Set By:" value=set_by />
        </div>
    }
}

#[component]
#[tracing::instrument(skip_all)]
fn NameValue(#[prop(into)] name: Signal<String>, #[prop(into)] value: Signal<String>) -> impl IntoView {
    view! {
        <p class="text-sm font-light mr-4 text-right text-orange-300">{name.get()}</p>
        <p class="text-white">{value.get()}</p>
    }
}
