synpad 0.1.0

A full-featured Matrix chat client built with Dioxus
use dioxus::prelude::*;

use crate::pages::chat_export::ChatExportDialog;
use crate::pages::devtools::DevToolsDialog;
use crate::room::call::call_button::CallButtons;
use crate::room::invite_dialog::InviteDialog;
use crate::room::share_room_dialog::ShareRoomDialog;
use crate::room::widgets::integration_manager::IntegrationManagerDialog;
use crate::notifications::push_rules::PushRulesDialog;
use crate::state::app_state::{AppState, RightPanelView};
use crate::utils::room_helpers::format_member_count;

/// Room header component showing room name, topic, and action buttons.
#[component]
pub fn RoomHeader(
    room_id: String,
    room_name: String,
    room_topic: Option<String>,
    member_count: u64,
    is_encrypted: bool,
    on_search_toggle: EventHandler<()>,
) -> Element {
    let mut state = use_context::<Signal<AppState>>();
    let mut show_invite = use_signal(|| false);
    let mut show_export = use_signal(|| false);
    let mut show_share = use_signal(|| false);
    let mut show_widgets = use_signal(|| false);
    let mut show_push_rules = use_signal(|| false);
    let mut show_devtools = use_signal(|| false);

    let toggle_members = move |_| {
        let current = state.read().right_panel.clone();
        if matches!(current, RightPanelView::MemberList) {
            state.write().right_panel = RightPanelView::Closed;
        } else {
            state.write().right_panel = RightPanelView::MemberList;
        }
    };

    let toggle_info = move |_| {
        let current = state.read().right_panel.clone();
        if matches!(current, RightPanelView::RoomInfo) {
            state.write().right_panel = RightPanelView::Closed;
        } else {
            state.write().right_panel = RightPanelView::RoomInfo;
        }
    };

    rsx! {
        header {
            class: "room-header",

            div {
                class: "room-header__info",
                div {
                    class: "room-header__name-row",
                    if is_encrypted {
                        span {
                            class: "room-header__encrypted-icon",
                            title: "Encrypted",
                            "🔒"
                        }
                    }
                    h2 {
                        class: "room-header__name",
                        "{room_name}"
                    }
                }
                if let Some(ref topic) = room_topic {
                    p {
                        class: "room-header__topic",
                        title: "{topic}",
                        "{topic}"
                    }
                }
            }

            div {
                class: "room-header__actions",

                // VoIP call buttons
                CallButtons {
                    room_id: room_id.clone(),
                }

                // Invite button
                button {
                    class: "room-header__action-btn",
                    title: "Invite user",
                    onclick: move |_| show_invite.set(true),
                    "+"
                }

                // Search button
                button {
                    class: "room-header__action-btn",
                    title: "Search in room",
                    onclick: move |_| on_search_toggle.call(()),
                    "🔍"
                }

                // Members button
                button {
                    class: "room-header__action-btn",
                    title: "{format_member_count(member_count)}",
                    onclick: toggle_members,
                    "👥 {member_count}"
                }

                // Share room button
                button {
                    class: "room-header__action-btn",
                    title: "Share room",
                    onclick: move |_| show_share.set(true),
                    "🔗"
                }

                // Export button (#62)
                button {
                    class: "room-header__action-btn",
                    title: "Export chat",
                    onclick: move |_| show_export.set(true),
                    "📥"
                }

                // Widgets/integrations button
                button {
                    class: "room-header__action-btn",
                    title: "Integrations",
                    onclick: move |_| show_widgets.set(true),
                    "🧩"
                }

                // Devtools button
                button {
                    class: "room-header__action-btn",
                    title: "Developer tools",
                    onclick: move |_| show_devtools.set(true),
                    "</>"
                }

                // Notification settings button
                button {
                    class: "room-header__action-btn",
                    title: "Notification settings",
                    onclick: move |_| show_push_rules.set(true),
                    "🔔"
                }

                // Room info button
                button {
                    class: "room-header__action-btn",
                    title: "Room info",
                    onclick: toggle_info,
                    ""
                }
            }

            // Invite dialog
            if *show_invite.read() {
                InviteDialog {
                    room_id: room_id.clone(),
                    on_close: move |_| show_invite.set(false),
                }
            }

            // Share room dialog
            if *show_share.read() {
                ShareRoomDialog {
                    room_id: room_id.clone(),
                    room_name: room_name.clone(),
                    on_close: move |_| show_share.set(false),
                }
            }

            // Chat export dialog (#62)
            if *show_export.read() {
                ChatExportDialog {
                    room_id: room_id.clone(),
                    room_name: room_name.clone(),
                    on_close: move |_| show_export.set(false),
                }
            }

            // Widget/integration manager
            if *show_widgets.read() {
                IntegrationManagerDialog {
                    room_id: room_id.clone(),
                    on_close: move |_| show_widgets.set(false),
                }
            }

            // Developer tools dialog
            if *show_devtools.read() {
                DevToolsDialog {
                    room_id: room_id.clone(),
                    on_close: move |_| show_devtools.set(false),
                }
            }

            // Push rules dialog
            if *show_push_rules.read() {
                PushRulesDialog {
                    room_id: room_id.clone(),
                    room_name: room_name.clone(),
                    on_close: move |_| show_push_rules.set(false),
                }
            }
        }
    }
}