use leptos::prelude::*;
use super::unified::TableColumn;

#[component]
pub fn TableSSR(
    columns: Vec<TableColumn>,
    rows: Vec<Vec<String>>,
    class: &'static str,
) -> impl IntoView {
    view! {
        <div class={format!("ds-card overflow-hidden {}", class)}>
            <div class="overflow-x-auto">
                <table class="w-full">
                    <thead class="bg-white/5 border-b border-white/10">
                        <tr>
                            {columns.iter().map(|col| {
                                view! {
                                    <th class="px-6 py-3 text-left text-sm font-medium text-white">
                                        <div class="flex items-center gap-2">
                                            {col.header.clone()}
                                            {col.sortable.then(|| view! { <span class="text-white/40">"↕"</span> })}
                                        </div>
                                    </th>
                                }
                            }).collect::<Vec<_>>()}
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-white/10">
                        {rows.into_iter().map(|row| {
                            view! {
                                <tr class="hover:bg-white/5 transition-colors">
                                    {row.into_iter().map(|cell| {
                                        view! {
                                            <td class="px-6 py-4 text-sm text-white/80">
                                                {cell}
                                            </td>
                                        }
                                    }).collect::<Vec<_>>()}
                                </tr>
                            }
                        }).collect::<Vec<_>>()}
                    </tbody>
                </table>
            </div>
        </div>
    }
}
