use leptos::prelude::*;
use crate::components::torrent::add_torrent::AddTorrentDialog;
use crate::components::ui::button::{Button};

#[component]
pub fn Toolbar() -> impl IntoView {
    let show_add_modal = signal(false);
    let is_mobile_menu_open = use_context::<RwSignal<bool>>().expect("mobile menu state not provided");

    view! {
        <div class="flex min-h-14 h-auto items-center border-b border-border bg-background px-4" style="padding-top: env(safe-area-inset-top);">
            // Sol kısım: Menü butonu + Add Torrent
            <div class="flex items-center gap-3">
                // Mobile Menu Trigger
                <button
                    class="inline-flex items-center justify-center size-9 rounded-md hover:bg-accent hover:text-accent-foreground lg:hidden"
                    on:click=move |_| is_mobile_menu_open.update(|v| *v = !*v)
                >
                    <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="w-5 h-5 stroke-current"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path></svg>
                </button>
                
                <Button
                    on:click=move |_| show_add_modal.1.set(true)
                    class="gap-2"
                >
                    <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="w-4 h-4 md:w-5 md:h-5">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15" />
                    </svg>
                    <span class="hidden sm:inline">"Add Torrent"</span>
                    <span class="sm:hidden">"Add"</span>
                </Button>
            </div>

            // Sağ kısım boşaltıldı (arama kutusu kaldırıldı)
            <div class="flex flex-1 items-center justify-end gap-2">
            </div>

            <Show when=move || show_add_modal.0.get()>
                <AddTorrentDialog on_close=Callback::new(move |()| show_add_modal.1.set(false)) />
            </Show>
        </div>
    }
}
