import 'dart:math';

import 'package:intl/intl.dart';

class NameBeautify {

  static final Map<String, String> Longify = {

    "ctr": "Centre",
    "stn": "Station",
    "tn": "Town",

  };

  static String beautifyStopName(String label) {

    String stopName = label.toUpperCase();

    // remove <>
    stopName = stopName.replaceAll("<>", "");

    // remove any parathesese pairs as well as the contents (), [], {}, <>, ><
    stopName = stopName.replaceAll(RegExp(r'\(.*\)'), '');
    stopName = stopName.replaceAll(RegExp(r'\[.*\]'), '');
    stopName = stopName.replaceAll(RegExp(r'\{.*\}'), '');
    // stopName = stopName.replaceAll(RegExp(r'\<.*\>'), '');
    stopName = stopName.replaceAll(RegExp(r'\>.*\<'), '');


    // remove any special characters except & and /
    stopName = stopName.replaceAll(RegExp(r'[^a-zA-Z0-9&/ ]'), '');

    // remove any double spaces
    stopName = stopName.replaceAll(RegExp(r'  '), ' ');

    // remove any spaces at the start or end of the string
    stopName = stopName.trim();

    // replace any short words with their long form
    for (String phrase in Longify.keys) {
      stopName = stopName.replaceAll(RegExp(phrase, caseSensitive: false), Longify[phrase]!);
    }


    stopName = stopName.toLowerCase();
    // Capitalify the first letter of each word
    try {
      stopName = stopName.split(' ').map((word) => word[0].toUpperCase() + word.substring(1)).join(' ');
    } catch (e) {}

    return stopName;

  }

  static String getShortTime(){

    // return the HH:MM with AM and PM and make sure that the hour is 12 hour format and it always double digits. IE 01, 02 etc
    DateTime now = DateTime.now();
    String formatted = DateFormat('hh:mm a').format(now);
    return formatted;
  }

  static String getLongTime() {
    DateTime now = DateTime.now();
    String formattedTime = DateFormat('HH:mm:ss  dd.MM.yyyy').format(now);
    return formattedTime;
  }

}