import { Gtk } from "astal/gtk4";
import Power from "./modules/Power";
import Audio from "./modules/Audio/Audio";
import Bluetooth from "./modules/Bluetooth/Bluetooth";
import Brightness from "./modules/Brightness/Brightness";
import Player from "./modules/Player/Player";
import { BatteryBox } from "./modules/Battery";
import { exec } from "astal";
import Network from "./modules/Networking/Network";

const QuickActions = () => {
    const popover = new Gtk.Popover({ cssClasses: ["quick-actions-wrapper"] });
    popover.set_child(renderQuickActions());
    return popover;
};

const renderQuickActions = () => {
    const user = exec("/bin/sh -c whoami");
    const profile = exec("/bin/fish -c get-profile-picture");
    const cwd = exec("pwd");
    const um = Power.UserMenu();

    return (
        <box visible cssClasses={["quick-actions", "popover-box"]} vertical>
            <centerbox
                startWidget={
                    <button
                        onClicked={() => um.popup()}
                        cssClasses={["stealthy-button"]}
                        child={
                            <box>
                                {um}
                                <Gtk.Frame
                                    cssClasses={["avatar-icon"]}
                                    child={
                                        <image
                                            file={
                                                profile !== ""
                                                    ? profile
                                                    : cwd +
                                                    "/no-avatar-icon.jpg"
                                            }
                                        ></image>
                                    }
                                ></Gtk.Frame>
                                <label label={user}></label>
                            </box>
                        }
                    ></button>
                }
                endWidget={
                    <box
                        hexpand={false}
                    >
                        <BatteryBox></BatteryBox>
                        <Power.Power></Power.Power>
                    </box>
                }
            ></centerbox>
            <Gtk.Separator marginTop={10} marginBottom={20}></Gtk.Separator>
            <box>
                <Bluetooth.BluetoothModule></Bluetooth.BluetoothModule>
                <Network.Network></Network.Network>
            </box>
            <Gtk.Separator marginTop={10} marginBottom={10}></Gtk.Separator>
            <Brightness.BrightnessModule></Brightness.BrightnessModule>
            <Audio.AudioModule></Audio.AudioModule>
            <Player.PlayerModule></Player.PlayerModule>
        </box>
    );
};

// TODO: Expose additional functions to be usable through CLI
export default {
    QuickActions,
};
