use dioxus::prelude::*;

use crate::components::copy_button::CopyButton;

#[component]
pub fn CodeSnippet(
    code: String,
    #[props(default)] file_path: String,
    #[props(default)] line_number: u32,
) -> Element {
    rsx! {
        div { class: "code-snippet-wrapper",
            div { class: "code-snippet-header",
                if !file_path.is_empty() {
                    span {
                        style: "font-size: 12px; color: var(--text-secondary); font-family: monospace;",
                        "{file_path}"
                        if line_number > 0 {
                            ":{line_number}"
                        }
                    }
                }
                CopyButton { value: code.clone(), small: true }
            }
            pre { class: "code-block", "{code}" }
        }
    }
}
