import 'package:flutter/material.dart';
import '../models/chat_message.dart';
import 'chat_bubble.dart';

class ChatBox extends StatelessWidget {
  final ScrollController scrollController;
  final List<ChatMessage> messages;
  const ChatBox({
    super.key,
    required this.scrollController,
    required this.messages,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      constraints: const BoxConstraints(
        minHeight: 60,
      ),
      child: ListView.builder(
        controller: scrollController,
        itemCount: messages.length,
        reverse: true,
        padding: const EdgeInsets.symmetric(horizontal: 12),
        shrinkWrap: true,
        itemBuilder: (context, index) {
          final message = messages[messages.length - 1 - index];
          final isTop = index == messages.length - 1;
          final isBottom = index == 0;
          return Padding(
            padding: EdgeInsets.only(
              top: isTop ? 0 : 6,
              bottom: isBottom ? 0 : 6,
            ),
            child: ChatBubble(message: message),
          );
        },
      ),
    );
  }
}
