import 'package:fluttertoast/fluttertoast.dart';
import 'package:intl/intl.dart';

extension StringExtensions on String {
  String get addTranslation => this;

  void get showToast => Fluttertoast.showToast(msg: this);

  String get toServiceRequestCardFormat {
    DateTime dateTime = DateTime.tryParse(this);
    return "${DateFormat('dd MMM, yyyy').format(dateTime)}\n${DateFormat('hh:mm a').format(dateTime)}";
  }

  String get toServiceRequestDetailsFormat {
    try {
      DateTime dateTime = DateTime.tryParse(this);
      return "${DateFormat('dd MMM, yyyy').format(dateTime)} ${DateFormat('hh:mm a').format(dateTime)}";
    } catch (e) {
      return "";
    }
  }

  String get toFirstActionFormat {
    try {
      DateTime dateTime = DateTime.tryParse(this);
      return "${DateFormat('yyyy-MM-dd').format(dateTime)} ${DateFormat('hh:mm a').format(dateTime)}";
    } catch (e) {
      return "";
    }
  }

  String get toAssetDetailsFormat {
    try {
      DateTime dateTime = DateTime.tryParse(this);
      return DateFormat('dd MMM, yyyy').format(dateTime);
    } catch (e) {
      return "-";
    }
  }

  String get getFileName {
    try {
      if (this.contains("fileName=")) {
        String sub = this.substring(this.indexOf("fileName="), this.length);
        sub = sub.replaceAll("fileName=", "");
        return sub;
      } else {
        return this;
      }
    } catch (e) {
      return this;
    }
  }
}
