import 'package:hmg_patient_app/models/get_dental_instructions_response_model.dart';
import 'package:hmg_patient_app/services/clinic_services/get_clinic_service.dart';
import 'package:hmg_patient_app/theme/colors.dart';
import 'package:hmg_patient_app/uitl/app_toast.dart';
import 'package:hmg_patient_app/uitl/gif_loader_dialog_utils.dart';
import 'package:hmg_patient_app/uitl/translations_delegate_base.dart';
import 'package:hmg_patient_app/uitl/utils_new.dart';
import 'package:hmg_patient_app/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/material.dart';

class DentalInstructionsPage extends StatefulWidget {
  const DentalInstructionsPage();

  @override
  State<DentalInstructionsPage> createState() => _DentalInstructionsPageState();
}

class _DentalInstructionsPageState extends State<DentalInstructionsPage> {
  GetDentalInstructionsResponseModel? getDentalInstructionsResponseModel;

  @override
  void initState() {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      getDentalInstructions();
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return AppScaffold(
      appBarTitle: TranslationBase.of(context).myinstructions,
      isShowAppBar: true,
      showNewAppBar: true,
      showNewAppBarTitle: true,
      isShowDecPage: false,
      backgroundColor: CustomColors.appBackgroudGrey2Color,
      body: Container(
        child: SingleChildScrollView(
          child: Padding(
            padding: const EdgeInsets.all(16.0),
            child: Column(
              children: [
                getDentalInstructionsResponseModel != null && getDentalInstructionsResponseModel!.data!.isNotEmpty
                    ? ListView.builder(
                        itemCount: getDentalInstructionsResponseModel!.data!.length,
                        shrinkWrap: true,
                        itemBuilder: (context, index) {
                          return Padding(
                            padding: EdgeInsets.only(top: 16.0, bottom: 16.0),
                            child: Text(
                              getDentalInstructionsResponseModel!.data![index].smsContent!,
                              style: TextStyle(
                                fontSize: 14.0,
                                letterSpacing: -0.56,
                                color: Color(0xff575757),
                              ),
                            ),
                          );
                        },
                      )
                    : Center(child: getNoDataWidget(context)),
              ],
            ),
          ),
        ),
      ),
    );
  }

  getDentalInstructions() {
    GifLoaderDialogUtils.showMyDialog(context);
    ClinicListService service = new ClinicListService();
    service.getDentalInstructions().then((res) {
      print(res["ProcedureNotificationResponse"]);
      getDentalInstructionsResponseModel = GetDentalInstructionsResponseModel.fromJson(res["ProcedureNotificationResponse"]);
      GifLoaderDialogUtils.hideDialog(context);
      setState(() {});
    }).catchError((err) {
      GifLoaderDialogUtils.hideDialog(context);
      print(err);
      AppToast.showErrorToast(message: err.toString());
    });
  }
}
