import 'package:flutter/cupertino.dart';
import 'package:hmg_qline/utilities/enums.dart';
import 'package:intl/intl.dart';

extension ScreenOrientationEnumExt on int {
  ScreenOrientationEnum toScreenOrientationEnum() {
    if (this == 1) {
      return ScreenOrientationEnum.portraitUp;
    } else if (this == 2) {
      return ScreenOrientationEnum.portraitDown;
    } else if (this == 3) {
      return ScreenOrientationEnum.landscapeRight;
    } else if (this == 4) {
      return ScreenOrientationEnum.landscapeLeft;
    } else {
      return ScreenOrientationEnum.portraitUp;
    }
  }
}

extension DateFormatExt on int {
  String toFormattedDateTimeFromInt() {
    return DateFormat('hh:mm a').format(DateTime.fromMillisecondsSinceEpoch(this));
  }

  DateTime toDateTimeFromInt() {
    return DateTime.fromMillisecondsSinceEpoch(this);
  }
}

extension NavigationExt on BuildContext {
  navigateReplaceTo(String route) {
    Navigator.pushReplacementNamed(this, route);
  }

  popView() => Navigator.of(this).pop();
}

extension ScreenOrientationExt on ScreenOrientationEnum {
  int getTurnsByOrientation() {
    switch (this) {
      case ScreenOrientationEnum.portraitUp:
        return 0;
      case ScreenOrientationEnum.portraitDown:
        return 2;
      case ScreenOrientationEnum.landscapeRight:
        return 1;
      case ScreenOrientationEnum.landscapeLeft:
        return 3;
      default:
        return 0;
    }
  }
}

extension QTypeEnumExtension on int {
  QTypeEnum toQTypeEnum() {
    switch (this) {
      case 1:
        return QTypeEnum.appointment;
      case 2:
        return QTypeEnum.lab;
      case 3:
        return QTypeEnum.rad;
      case 4:
        return QTypeEnum.general;
      case 5:
        return QTypeEnum.pharmacy;
      default:
        return QTypeEnum.lab;
    }
  }
}

extension QTypeExtension on QTypeEnum {
  // Convert the QType enum to its corresponding integer ID
  int getQTypeIDFromEnum() {
    return index + 1; // enum index starts from 0, so we add 1 to match your values.
  }
}

extension ScreenTypeExtension on int {
  // Convert int to ScreenType enum
  ScreenTypeEnum toScreenTypeEnum() {
    switch (this) {
      case 1:
        return ScreenTypeEnum.waitingAreaScreen;
      case 2:
        return ScreenTypeEnum.roomLevelScreen;
      case 3:
        return ScreenTypeEnum.receptionScreen;
      case 4:
        return ScreenTypeEnum.dashboardScreen;
      case 5:
        return ScreenTypeEnum.kioskScreen;
      default:
        return ScreenTypeEnum.waitingAreaScreen;
    }
  }
}

extension ScreenTypeIDExtension on ScreenTypeEnum {
  // Convert the ScreenType enum to its corresponding integer ID
  int getScreenTypeIDFromEnum() {
    return index + 1; // enum index starts from 0, so we add 1 to match your values.
  }
}

extension IntToLanguageEnum on int {
  LanguageEnum toLanguageEnum() {
    switch (this) {
      case 1:
        return LanguageEnum.english;
      case 2:
        return LanguageEnum.arabic;
      default:
        return LanguageEnum.english;
    }
  }
}

extension LanguageEnumToInt on LanguageEnum {
  int enumToInt() {
    switch (this) {
      case LanguageEnum.english:
        return 1;
      case LanguageEnum.arabic:
        return 2;
      default:
        return 1;
    }
  }
}

extension LanguageEnumToString on LanguageEnum {
  String enumToString() {
    switch (this) {
      case LanguageEnum.english:
        return "en";
      case LanguageEnum.arabic:
        return "ar";
      default:
        return "en";
    }
  }
}
