import 'package:flutter/material.dart';
import 'package:syncrow_web/utils/color_manager.dart';

class DialogFooter extends StatelessWidget {
  final VoidCallback onCancel;
  final VoidCallback? onConfirm;
  final bool isConfirmEnabled;
  final int? dialogWidth;

  const DialogFooter({
    super.key,
    required this.onCancel,
    required this.onConfirm,
    required this.isConfirmEnabled,
    this.dialogWidth,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: const BoxDecoration(
        border: Border(
          top: BorderSide(
            color: ColorsManager.greyColor,
          ),
        ),
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          DialogFooterButton(
            text: 'Cancel',
            onTap: onCancel,
          ),
          if (isConfirmEnabled) ...[
            Container(width: 1, height: 50, color: ColorsManager.greyColor),
            DialogFooterButton(
              text: 'Confirm',
              onTap: onConfirm,
              textColor: isConfirmEnabled
                  ? ColorsManager.primaryColorWithOpacity
                  : Colors.red,
            ),
          ],
        ],
      ),
    );
  }
}

class DialogFooterButton extends StatelessWidget {
  const DialogFooterButton({
    required this.text,
    required this.onTap,
    this.textColor,
    super.key,
  });

  final String text;
  final VoidCallback? onTap;
  final Color? textColor;

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: TextButton(
        style: TextButton.styleFrom(
          foregroundColor: ColorsManager.primaryColorWithOpacity,
          disabledForegroundColor: ColorsManager.primaryColor,
        ),
        onPressed: onTap,
        child: Text(
          text,
          style: Theme.of(context).textTheme.bodyMedium?.copyWith(
                color: textColor ?? ColorsManager.textGray,
              ),
        ),
      ),
    );
  }
}
