import 'package:diplomaticquarterapp/config/size_config.dart';
import 'package:diplomaticquarterapp/models/FamilyFiles/GetAllSharedRecordByStatusResponse.dart';
import 'package:diplomaticquarterapp/services/family_files/family_files_provider.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class MyFamily extends StatefulWidget {
  @override
  _MyFamily createState() => _MyFamily();
}

class _MyFamily extends State<MyFamily> {
  bool isLoading = true;
  var familyFileProvider = FamilyFilesProvider();
  @override
  void initState() {
    isLoading = true;
    // checkUser(context);
    super.initState();
  }

  Widget build(BuildContext context) {
    return AppScaffold(
        appBarTitle: TranslationBase.of(context).myFamilyFiles,
        isShowAppBar: true,
        body: DefaultTabController(
            length: 2,
            child: SingleChildScrollView(
                padding: EdgeInsets.all(20),
                child: Container(
                    height: SizeConfig.realScreenHeight * .9,
                    width: SizeConfig.realScreenWidth,
                    child: Stack(
                      children: <Widget>[
                        TabBar(
                          indicatorColor: Colors.red,
                          tabs: [
                            Padding(
                                padding: EdgeInsets.all(6),
                                child:
                                    Text(TranslationBase.of(context).family)),
                            Padding(
                                padding: EdgeInsets.all(6),
                                child:
                                    Text(TranslationBase.of(context).request)),
                          ],
                        ),
                        TabBarView(
                          children: [myFamilyDetails(), myFamilyRequest()],
                        )
                      ],
                    )))));
  }

  Widget myFamilyDetails() {
    return Padding(
        padding: EdgeInsets.only(top: 40),
        child: Column(
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Expanded(
                    flex: 3, child: Text(TranslationBase.of(context).request)),
                Expanded(
                    flex: 2,
                    child: Text(
                      TranslationBase.of(context).switchUser,
                    )),
                Expanded(
                    flex: 1,
                    child: Text(
                      TranslationBase.of(context).deleteView,
                    )),
              ],
            ),
            FutureBuilder(
              future: getFamilyFiles(), // async work
              builder: (BuildContext context,
                  AsyncSnapshot<GetAllSharedRecordsByStatusResponse> snapshot) {
                switch (snapshot.connectionState) {
                  case ConnectionState.waiting:
                    return Padding(
                        padding: EdgeInsets.all(10),
                        child: Text('Loading....'));
                  default:
                    if (snapshot.hasError)
                      return Padding(
                          padding: EdgeInsets.all(10),
                          child: Text(snapshot.error));
                    else
                      return Column(
                          children: snapshot
                              .data.getAllSharedRecordsByStatusList
                              .map<Widget>((result) {
                        return Padding(
                            padding: EdgeInsets.all(10),
                            child: Row(
                              children: <Widget>[
                                Expanded(
                                    flex: 3, child: Text(result.patientName)),
                                Expanded(flex: 2, child: Icon(Icons.group)),
                                Expanded(flex: 1, child: Icon(Icons.delete)),
                              ],
                            ));
                      }).toList());
                }
              },
            )
          ],
        ));
  }

  Widget myFamilyRequest() {
    return Column(
      children: <Widget>[],
    );
  }

  Future<GetAllSharedRecordsByStatusResponse> getFamilyFiles() {
    return familyFileProvider.getSharedRecordByStatus();
  }
}
