import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:hallo_doctor_doctor_app/app/styles/styles.dart';
import 'package:hallo_doctor_doctor_app/app/models/withdraw_method_model.dart';
import 'package:hallo_doctor_doctor_app/app/models/bank_withdraw_method_model.dart';

class WithdrawMethodTile extends StatelessWidget {
  const WithdrawMethodTile({
    Key? key,
    required this.withdrawMethod,
    required this.onTap,
  }) : super(key: key);

  final WithdrawMethod withdrawMethod;
  final VoidCallback onTap;
  @override
  Widget build(BuildContext context) {
    final bool isBank = withdrawMethod is BankWithdrawMethod;
    final String methodType = isBank ? 'Bank' : 'Paypal';
    final Widget methodIcon = isBank
        ? Icon(Icons.account_balance, size: 24, color: Colors.blue)
        : Image.asset(
            'assets/images/paypal_logo.png',
            width: 24,
            height: 24,
          );

    String subtitle = '';
    if (isBank) {
      final bankMethod = withdrawMethod as BankWithdrawMethod;
      subtitle = '${bankMethod.bankName} - ${bankMethod.accountNumber}';
    } else {
      subtitle = withdrawMethod.email ?? '';
    }

    return InkWell(
      onTap: onTap,
      child: Container(
        margin: EdgeInsets.only(bottom: 8),
        height: 68,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(8),
          boxShadow: [
            BoxShadow(
              color: Color(0x04000000),
              blurRadius: 10,
              spreadRadius: 10,
              offset: Offset(0.0, 8.0),
            ),
          ],
          color: Colors.white,
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Row(
              children: <Widget>[
                SizedBox(width: 12),
                Container(
                  width: 44,
                  height: 44,
                  decoration: BoxDecoration(
                    shape: BoxShape.circle,
                    color: Styles.whiteGreyColor,
                  ),
                  child: Center(
                    child: methodIcon,
                  ),
                ),
                SizedBox(width: 12),
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Text(
                      withdrawMethod.name ?? '',
                      style: GoogleFonts.nunito(
                        fontSize: 14,
                        fontWeight: FontWeight.w700,
                        color: Colors.black,
                      ),
                    ),
                    Text(
                      methodType,
                      style: GoogleFonts.nunito(
                        fontSize: 12,
                        fontWeight: FontWeight.w700,
                        color: Colors.grey,
                      ),
                    ),
                  ],
                ),
              ],
            ),
            Padding(
              padding: const EdgeInsets.only(right: 16.0),
              child: Text(
                subtitle,
                style: GoogleFonts.nunito(
                  fontSize: 12,
                  fontWeight: FontWeight.w700,
                  color: Styles.greyTextColor,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
