import 'package:agent_shell/agent_shell.dart';
import 'package:flutter/material.dart';

import 'oto_console_contract.dart';

class OtoAgentPanel extends StatelessWidget {
  final ValueChanged<String>? onSubmit;
  final OtoCapabilityPack? capabilities;

  const OtoAgentPanel({super.key, this.onSubmit, this.capabilities});

  List<AgentMessage> _buildMessages() {
    final introText = StringBuffer(
      'OTO agent surface is ready. Runner, pipeline, execution, log, and artifact capabilities can be registered here.',
    );

    if (capabilities != null && capabilities!.capabilities.isNotEmpty) {
      introText.write('\n\nRegistered capabilities:');
      for (final capability in capabilities!.capabilities) {
        introText.write('\n- ${capability.name}: ${capability.description}');
      }
    }

    return [
      AgentMessage(
        id: 'oto-agent-intro',
        role: AgentMessageRole.assistant,
        text: introText.toString(),
      ),
    ];
  }

  @override
  Widget build(BuildContext context) {
    return AgentShell(
      messages: _buildMessages(),
      busy: false,
      placeholder: 'Ask about OTO builds',
      onSubmit: onSubmit,
    );
  }
}
