import 'package:auto_size_text/auto_size_text.dart';
import 'package:hmg_patient_app/config/size_config.dart';
import 'package:hmg_patient_app/core/viewModels/project_view_model.dart';
import 'package:hmg_patient_app/theme/colors.dart';
import 'package:hmg_patient_app/uitl/app_toast.dart';
import 'package:hmg_patient_app/uitl/translations_delegate_base.dart';
import 'package:hmg_patient_app/uitl/utils.dart';
import 'package:hmg_patient_app/uitl/utils_new.dart';
import 'package:hmg_patient_app/widgets/buttons/defaultButton.dart';
import 'package:hmg_patient_app/widgets/data_display/medical/medical_profile_item.dart';
import 'package:hmg_patient_app/widgets/mobile-no/mobile_no.dart';
import 'package:hmg_patient_app/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class LiveCareCallTypeSelectPage extends StatefulWidget {
  Function onSelectedMethod;

  LiveCareCallTypeSelectPage({required this.onSelectedMethod});

  @override
  State<LiveCareCallTypeSelectPage> createState() => _LiveCareCallTypeSelectPageState();
}

class _LiveCareCallTypeSelectPageState extends State<LiveCareCallTypeSelectPage> {
  int selectedCallType = 1;
  String mobileNo = "";
  String countryCode = '966';
  late ProjectViewModel projectViewModel;

  @override
  Widget build(BuildContext context) {
    projectViewModel = Provider.of<ProjectViewModel>(context);
    mobileNo = Utils.getPhoneNumberWithoutZero(projectViewModel.authenticatedUserObject.user.mobileNumber!);
    return AppScaffold(
      appBarTitle: TranslationBase.of(context).selectCallType,
      isShowAppBar: true,
      showNewAppBar: true,
      showNewAppBarTitle: true,
      backgroundColor: CustomColors.appBackgroudGrey2Color,
      body: Padding(
        padding: EdgeInsets.all(21),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            GridView(
              gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 2 / 2, crossAxisSpacing: 12, mainAxisSpacing: 12),
              physics: NeverScrollableScrollPhysics(),
              shrinkWrap: true,
              children: [
                InkWell(
                  onTap: () {
                    setState(() {
                      selectedCallType = 1;
                    });
                  },
                  child: MedicalProfileItem(
                    title: TranslationBase.of(context).videoCall,
                    imagePath: 'video_call.svg',
                    subTitle: "",
                    isPngImage: false,
                    isShowBorder: selectedCallType == 1,
                  ),
                ),
                InkWell(
                  onTap: () {
                    setState(() {
                      selectedCallType = 2;
                    });
                  },
                  child: MedicalProfileItem(
                    title: TranslationBase.of(context).audioCall,
                    imagePath: 'audio_call.svg',
                    subTitle: "",
                    isPngImage: false,
                    isShowBorder: selectedCallType == 2,
                  ),
                ),
                InkWell(
                  onTap: () {
                    setState(() {
                      selectedCallType = 3;
                    });
                  },
                  child: MedicalProfileItem(
                    title: TranslationBase.of(context).phoneCall,
                    imagePath: 'phone_call.svg',
                    subTitle: "",
                    isPngImage: false,
                    isShowBorder: selectedCallType == 3,
                  ),
                ),
              ],
            ),
            if (selectedCallType == 3)
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  mHeight(32.0),
                  AutoSizeText(
                    TranslationBase.of(context).mobileNumber,
                    maxLines: 1,
                    minFontSize: 12,
                    style: TextStyle(
                      fontSize: SizeConfig.textMultiplier! * 2.0,
                      fontWeight: FontWeight.w600,
                      letterSpacing: -0.39,
                      height: 0.8,
                    ),
                  ),
                  mHeight(16.0),
                  PhoneNumberSelectorWidget(
                    onNumberChange: (value) => {
                      mobileNo = value,
                    },
                    onCountryChange: (value) => {
                      countryCode = value,
                    },
                    mobileNo: this.mobileNo,
                    isLiveCareTypeSelect: true,
                    isEnable: false,
                  ),
                ],
              ),
          ],
        ),
      ),
      bottomSheet: Container(
        color: CustomColors.white,
        padding: EdgeInsets.fromLTRB(12.0, 1.0, 12.0, 25.0),
        child: DefaultButton(
          TranslationBase.of(context).next,
          () {
            if (mobileNo.isNotEmpty) {
              Navigator.pop(context, [selectedCallType, mobileNo]);
              widget.onSelectedMethod(selectedCallType, mobileNo);
            } else {
              AppToast.showErrorToast(message: TranslationBase.of(context).enterMobileNumber);
            }
          },
          color: CustomColors.accentColor,
        ),
      ),
    );
  }
}
