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

class IopAgentPanel extends StatelessWidget {
  final ValueChanged<String>? onSubmit;
  final IopCapabilityPack? capabilities;

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

  List<AgentMessage> _buildMessages() {
    final introText = StringBuffer(
      'IOP agent surface is ready. Edge, Node, Runtime, and Execution capabilities can be registered here.',
    );

    if (capabilities != null && capabilities!.capabilities.isNotEmpty) {
      introText.write('\n\n**Registered Capabilities:**');
      for (final cap in capabilities!.capabilities) {
        introText.write('\n• **${cap.name}**: ${cap.description}');
      }
    }

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

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

