import * as vscode from 'vscode';

export enum AgentStatus {
    Idle = 'Idle',
    Thinking = 'Thinking...',
    Executing = 'Executing Actions...',
    Error = 'Error',
    Success = 'Success'
}

export class StatusBarManager {
    private statusBarItem: vscode.StatusBarItem;

    constructor() {
        this.statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
        this.statusBarItem.command = 'g1nation.focusInput';
        this.updateStatus(AgentStatus.Idle);
        this.statusBarItem.show();
    }

    public updateStatus(status: AgentStatus, detail?: string) {
        let icon = '';
        switch (status) {
            case AgentStatus.Idle:
                icon = '$(pass)';
                this.statusBarItem.backgroundColor = undefined;
                break;
            case AgentStatus.Thinking:
                icon = '$(sync~spin)';
                this.statusBarItem.backgroundColor = new vscode.ThemeColor('statusBarItem.warningBackground');
                break;
            case AgentStatus.Executing:
                icon = '$(gear~spin)';
                this.statusBarItem.backgroundColor = new vscode.ThemeColor('statusBarItem.warningBackground');
                break;
            case AgentStatus.Error:
                icon = '$(error)';
                this.statusBarItem.backgroundColor = new vscode.ThemeColor('statusBarItem.errorBackground');
                break;
            case AgentStatus.Success:
                icon = '$(check)';
                this.statusBarItem.backgroundColor = undefined;
                break;
        }

        this.statusBarItem.text = `${icon} Astra: ${status}`;
        this.statusBarItem.tooltip = detail || `Current State: ${status}`;
        
        if (status === AgentStatus.Success || status === AgentStatus.Error) {
            setTimeout(() => this.updateStatus(AgentStatus.Idle), 5000);
        }
    }

    public dispose() {
        this.statusBarItem.dispose();
    }
}
