import 'package:fis_common/index.dart';
import 'package:fis_ui/index.dart';
import 'package:flutter/material.dart';

class FChatMessage extends FStatelessWidget {
  FChatMessage({required this.text, this.avatar, this.isSelf = false});

  final String text;
  final String? avatar;
  final bool isSelf;

  @override
  FWidget build(BuildContext context) {
    FWidget circleAvatar;
    if (avatar.isNotNullOrEmpty) {
      circleAvatar = FCircleAvatar(
        backgroundImage: NetworkImage(avatar!),
      );
    } else {
      circleAvatar = FCircleAvatar(
        backgroundImage: AssetImage('assets/images/avatar_man.png'),
      );
    }
    return FContainer(
      margin: const EdgeInsets.only(left: 10.0, top: 10),
      width: double.infinity,
      child: FRow(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          if (!isSelf) ...[
            FContainer(
              margin: const EdgeInsets.only(right: 16.0),
              child: circleAvatar,
            ),
          ] else ...[
            FExpanded(child: FSizedBox())
          ],
          FContainer(
            alignment: isSelf ? Alignment.centerRight : Alignment.center,
            child: FText(
              text,
              style: TextStyle(color: Colors.grey[500]),
            ),
          ),
          if (isSelf) ...[
            FContainer(
              alignment: Alignment.centerRight,
              width: 40,
              margin: const EdgeInsets.only(right: 10.0, left: 10),
              child: circleAvatar,
            ),
          ],
        ],
      ),
    );
  }
}
