import 'package:flutter/material.dart';
import 'package:fotodocumentation/dto/customer_dto.dart';
import 'package:fotodocumentation/pages/ui_utils/dialog/delete_dialog.dart';

class CustomerRowItem extends StatelessWidget {
  final CustomerListDto dto;
  final Future<DeleteDialogResult> Function(CustomerListDto) doDelete;
  final Future<void> Function(CustomerListDto)? doSelect;

  const CustomerRowItem({super.key, required this.dto, required this.doDelete, this.doSelect});

  @override
  Widget build(BuildContext context) {
    return ListTile(
      leading: CircleAvatar(
        backgroundColor: Colors.grey[300],
        child: Text(
          dto.name.isNotEmpty ? dto.name[0].toUpperCase() : '?',
          style: TextStyle(
            color: Colors.grey[700],
            fontWeight: FontWeight.bold,
          ),
        ),
      ),
      title: Text(dto.name),
      subtitle: Text('CustomerNumber: ${dto.customerNumber}'),
      
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(8),
      ),
      onTap: () async => await _doSelect(context),
    );
  }

  Future<void> _doSelect(BuildContext context) async {
    if (doSelect != null) {
      await doSelect!(dto);
    }
  }
}
