import 'package:comwell_key_app/common/components/comwell_text_field.dart';
import 'package:comwell_key_app/themes/light_theme.dart';
import 'package:comwell_key_app/utils/l10n_utils.dart';
import 'package:flutter/material.dart';

class BillDownloadModal extends StatelessWidget {
  final TextEditingController emailController;
  final String initialEmail;
  final VoidCallback onDownload;

  BillDownloadModal(
      {super.key, required this.onDownload, required this.initialEmail})
      : emailController = TextEditingController(text: initialEmail);

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    final bottomInset = MediaQuery.of(context).viewInsets.bottom;
    
    return ClipRRect(
      borderRadius: const BorderRadius.only(
        topLeft: Radius.circular(16),
        topRight: Radius.circular(16),
      ),
      child: Container(
        color: Colors.white,
        child: SafeArea(
          child: SingleChildScrollView(
            padding: EdgeInsets.only(
              left: 16,
              right: 16,
              top: 16,
              bottom: 16 + bottomInset,
            ),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(context.strings.download_bill, style: theme.textTheme.titleLarge),
                    IconButton(
                      onPressed: () {
                        Navigator.pop(context);
                      },
                      icon: Icon(Icons.close, color: colorHeadlineText, size: 24),
                      style: IconButton.styleFrom(
                        backgroundColor: sandColor[40],
                        shape: const CircleBorder(),
                        elevation: 0,
                        minimumSize: const Size(40, 40),
                      ),
                    ),
                  ],
                ),
                const SizedBox(height: 16),
                ComwellTextField(
                    fieldName: context.strings.bill_email_placeholder,
                    initialValue: initialEmail,
                    readOnly: false,
                    controller: emailController),
                const SizedBox(height: 24),
                const Divider(color: colorDivider),
                const SizedBox(height: 16),
                SizedBox(
                  width: double.infinity,
                  child: ElevatedButton(
                      onPressed: onDownload,
                      child: Text(context.strings.send_to_email,
                          style: theme.textTheme.headlineSmall
                              ?.copyWith(color: Colors.white))),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}