import 'package:flutter/material.dart';
import 'package:qr_flutter/qr_flutter.dart';
import '../inter_family_bloc.dart';
import '../../../product/constant/icon/icon_constants.dart';
import '../../../product/extention/context_extention.dart';
import '../../../product/services/language_services.dart';

import 'groups_model.dart';

shareGroup(BuildContext context, Group group) {
  showGeneralDialog(
    barrierColor: Colors.black.withOpacity(0.5),
    transitionBuilder: (context, a1, a2, widget) {
      return Material(
        child: Scaffold(
          appBar: AppBar(
            title:
                Center(child: Text(appLocalization(context).share_group_title)),
            leading: IconButton(
              onPressed: () {
                Navigator.pop(context);
              },
              icon: IconConstants.instance.getMaterialIcon(Icons.arrow_back),
            ),
          ),
          body: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Center(
                child: QrImageView(
                  data: '${group.id}.${group.name!}',
                  size: 250,
                ),
              ),
              const SizedBox(height: 10),
              Text(group.name!),
              const SizedBox(height: 10),
              OutlinedButton(
                onPressed: () {},
                child: const Text('Capture and Save as Image'),
              ),
            ],
          ),
        ),
      );
    },
    transitionDuration: context.lowDuration,
    barrierDismissible: true,
    barrierLabel: '',
    context: context,
    pageBuilder: (context, animation1, animation2) {
      return const SizedBox();
    },
  );
}

showActionDialog(
    BuildContext context,
    String role,
    InterFamilyBloc interFamilyBloc,
    String dialogTitle,
    String dialogContent,
    Group group) {
  showDialog(
    context: context,
    builder: (dialogContext) {
      return AlertDialog(
        title: Center(child: Text(dialogTitle)),
        content: Text(dialogContent),
        actions: [
          TextButton(
            onPressed: () {
              Navigator.of(dialogContext).pop();
            },
            child: Text(appLocalization(context).cancel_button_content),
          ),
          TextButton(
            onPressed: () async {
              if (dialogTitle == appLocalization(context).delete_group_title) {
                Navigator.of(dialogContext).pop();
                await interFamilyBloc.deleteGroup(context, group.id!);
                interFamilyBloc.getAllGroup(role);
              } else {}
            },
            child: Text(
              appLocalization(context).confirm_button_content,
              style: const TextStyle(color: Colors.red),
            ),
          ),
        ],
      );
    },
  );
}
