import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { DriveIcon } from "@powerhousedao/connect";
import { connectConfig } from "@powerhousedao/connect/config";
import { ConnectSidebar, Icon, SidebarAddDriveItem, SidebarItem, } from "@powerhousedao/design-system";
import { logout, openRenown, setSelectedDrive, showPHModal, useDrives, useSelectedDriveSafe, } from "@powerhousedao/reactor-browser";
import { useUser } from "@powerhousedao/reactor-browser/connect";
import { logger } from "document-drive";
import { ErrorBoundary } from "react-error-boundary";
export function Sidebar() {
    const user = useUser();
    const drives = useDrives();
    const [selectedDrive] = useSelectedDriveSafe();
    const connectDebug = localStorage.getItem("CONNECT_DEBUG") === "true";
    const onClickSettings = () => {
        showPHModal({ type: "settings" });
    };
    const onAddDriveClick = () => {
        showPHModal({ type: "addDrive" });
    };
    const headerContent = (_jsxs("div", { className: "flex h-full items-center", children: [_jsx(Icon, { name: "Connect", className: "!h-[30px] !w-[100px] cursor-pointer", onClick: () => setSelectedDrive(undefined) }), connectDebug && (_jsx("button", { "aria-label": "Home", id: "connect-debug-button", className: "ml-6", onClick: () => showPHModal({ type: "debugSettings" }), children: _jsx("img", { src: "settings.png", className: "h-5 text-gray-600" }) }))] }));
    const etherscanUrl = user?.address
        ? `https://etherscan.io/address/${user.address}`
        : "";
    return (_jsx(ConnectSidebar, { id: "sidebar", onClick: () => setSelectedDrive(undefined), onClickSettings: onClickSettings, headerContent: headerContent, address: user?.address, onLogin: openRenown, onDisconnect: logout, etherscanUrl: etherscanUrl, children: _jsxs(ErrorBoundary, { fallback: _jsx("div", { className: "text-center", children: "There was an error loading drives" }), onError: logger.error, 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