import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { DriveIcon } from "@powerhousedao/connect/components";
import { connectConfig } from "@powerhousedao/connect/config";
import { ConnectSidebar, ConnectTooltipProvider, SidebarAddDriveItem, SidebarItem, } from "@powerhousedao/design-system/connect";
import { logout, openRenown, setSelectedDrive, showPHModal, useDrives, useInspectorEnabled, useSelectedDriveSafe, } from "@powerhousedao/reactor-browser";
import { useUser } from "@powerhousedao/reactor-browser/connect";
import { ErrorBoundary } from "./error-boundary.js";
export function Sidebar() {
    const user = useUser();
    const drives = useDrives();
    const [selectedDrive] = useSelectedDriveSafe();
    const inspectorEnabled = useInspectorEnabled();
    const connectDebug = localStorage.getItem("CONNECT_DEBUG") === "true";
    const onClickSettings = () => {
        showPHModal({ type: "settings" });
    };
    const onAddDriveClick = () => {
        showPHModal({ type: "addDrive" });
    };
    const onInspectorClick = () => {
        showPHModal({ type: "inspector" });
    };
    const etherscanUrl = user?.address
        ? `https://etherscan.io/address/${user.address}`
        : "";
    return (_jsx(ConnectTooltipProvider, { children: _jsx(ConnectSidebar, { id: "sidebar", onClick: () => setSelectedDrive(undefined), onClickSettings: onClickSettings, onInspectorClick: inspectorEnabled ? onInspectorClick : undefined, address: user?.address, onLogin: openRenown, onDisconnect: logout, etherscanUrl: etherscanUrl, showDebug: connectDebug, onDebugClick: () => showPHModal({ type: "debugSettings" }), children: _jsxs(ErrorBoundary, { variant: "text", fallbackMessage: "There was an error loading drives", loggerContext: ["Connect", "Sidebar"], children: [drives?.map((drive, index) => (_jsx(SidebarItem, { title: drive.header.name, onClick: () => setSelectedDrive(drive), active: selectedDrive?.header.id === drive.header.id, icon: _jsx(DriveIcon, { drive: drive }) }, index))), connectConfig.drives.addDriveEnabled && (_jsx(SidebarAddDriveItem, { onClick: onAddDriveClick }))] }) }) }));
}
//# sourceMappingURL=sidebar.js.map