import 'dart:convert';

import 'package:flutter/services.dart';

class O2Emoji {
  static final O2Emoji instance = O2Emoji._internal();
  factory O2Emoji() => instance;
  O2Emoji._internal();

  EmojiJsonData? _emojiJsonData;

  static final emojiList = {
    "[01]": "assets/emoji/im_emotion_01.png",
    "[02]": "assets/emoji/im_emotion_02.png",
    "[03]": "assets/emoji/im_emotion_03.png",
    "[04]": "assets/emoji/im_emotion_04.png",
    "[05]": "assets/emoji/im_emotion_05.png",
    "[06]": "assets/emoji/im_emotion_06.png",
    "[07]": "assets/emoji/im_emotion_07.png",
    "[08]": "assets/emoji/im_emotion_08.png",
    "[09]": "assets/emoji/im_emotion_09.png",
    "[10]": "assets/emoji/im_emotion_10.png",
    "[11]": "assets/emoji/im_emotion_11.png",
    "[12]": "assets/emoji/im_emotion_12.png",
    "[13]": "assets/emoji/im_emotion_13.png",
    "[14]": "assets/emoji/im_emotion_14.png",
    "[15]": "assets/emoji/im_emotion_15.png",
    "[16]": "assets/emoji/im_emotion_16.png",
    "[17]": "assets/emoji/im_emotion_17.png",
    "[18]": "assets/emoji/im_emotion_18.png",
    "[19]": "assets/emoji/im_emotion_19.png",
    "[20]": "assets/emoji/im_emotion_20.png",
    "[21]": "assets/emoji/im_emotion_21.png",
    "[22]": "assets/emoji/im_emotion_22.png",
    "[23]": "assets/emoji/im_emotion_23.png",
    "[24]": "assets/emoji/im_emotion_24.png",
    "[25]": "assets/emoji/im_emotion_25.png",
    "[26]": "assets/emoji/im_emotion_26.png",
    "[27]": "assets/emoji/im_emotion_27.png",
    "[28]": "assets/emoji/im_emotion_28.png",
    "[29]": "assets/emoji/im_emotion_29.png",
    "[30]": "assets/emoji/im_emotion_30.png",
    "[31]": "assets/emoji/im_emotion_31.png",
    "[32]": "assets/emoji/im_emotion_32.png",
    "[33]": "assets/emoji/im_emotion_33.png",
    "[34]": "assets/emoji/im_emotion_34.png",
    "[35]": "assets/emoji/im_emotion_35.png",
    "[36]": "assets/emoji/im_emotion_36.png",
    "[37]": "assets/emoji/im_emotion_37.png",
    "[38]": "assets/emoji/im_emotion_38.png",
    "[39]": "assets/emoji/im_emotion_39.png",
    "[40]": "assets/emoji/im_emotion_40.png",
    "[41]": "assets/emoji/im_emotion_41.png",
    "[42]": "assets/emoji/im_emotion_42.png",
    "[43]": "assets/emoji/im_emotion_43.png",
    "[44]": "assets/emoji/im_emotion_44.png",
    "[45]": "assets/emoji/im_emotion_45.png",
    "[46]": "assets/emoji/im_emotion_46.png",
    "[47]": "assets/emoji/im_emotion_47.png",
    "[48]": "assets/emoji/im_emotion_48.png",
    "[49]": "assets/emoji/im_emotion_49.png",
    "[50]": "assets/emoji/im_emotion_50.png",
    "[51]": "assets/emoji/im_emotion_51.png",
    "[52]": "assets/emoji/im_emotion_52.png",
    "[53]": "assets/emoji/im_emotion_53.png",
    "[54]": "assets/emoji/im_emotion_54.png",
    "[55]": "assets/emoji/im_emotion_55.png",
    "[56]": "assets/emoji/im_emotion_56.png",
    "[57]": "assets/emoji/im_emotion_57.png",
    "[58]": "assets/emoji/im_emotion_58.png",
    "[59]": "assets/emoji/im_emotion_59.png",
    "[60]": "assets/emoji/im_emotion_60.png",
    "[61]": "assets/emoji/im_emotion_61.png",
    "[62]": "assets/emoji/im_emotion_62.png",
    "[63]": "assets/emoji/im_emotion_63.png",
    "[64]": "assets/emoji/im_emotion_64.png",
    "[65]": "assets/emoji/im_emotion_65.png",
    "[66]": "assets/emoji/im_emotion_66.png",
    "[67]": "assets/emoji/im_emotion_67.png",
    "[68]": "assets/emoji/im_emotion_68.png",
    "[69]": "assets/emoji/im_emotion_69.png",
    "[70]": "assets/emoji/im_emotion_70.png",
    "[71]": "assets/emoji/im_emotion_71.png",
    "[72]": "assets/emoji/im_emotion_72.png",
    "[73]": "assets/emoji/im_emotion_73.png",
    "[74]": "assets/emoji/im_emotion_74.png",
    "[75]": "assets/emoji/im_emotion_75.png",
    "[76]": "assets/emoji/im_emotion_76.png",
    "[77]": "assets/emoji/im_emotion_77.png",
    "[78]": "assets/emoji/im_emotion_78.png",
    "[79]": "assets/emoji/im_emotion_79.png",
    "[80]": "assets/emoji/im_emotion_80.png",
    "[81]": "assets/emoji/im_emotion_81.png",
    "[82]": "assets/emoji/im_emotion_82.png",
    "[83]": "assets/emoji/im_emotion_83.png",
    "[84]": "assets/emoji/im_emotion_84.png",
    "[85]": "assets/emoji/im_emotion_85.png",
    "[86]": "assets/emoji/im_emotion_86.png",
    "[87]": "assets/emoji/im_emotion_87.png"
  };

  static String getEmojiPath(String key) {
    return emojiList[key] ?? 'assets/emoji/im_emotion_01.png';
  }

  Future<String?> _loadEmojiJsonFile() async {
    return await rootBundle.loadString('assets/json/emoji.json');
  }

  Future<EmojiJsonData?> getEmojiJsonData() async {
    if (_emojiJsonData != null) {
      return _emojiJsonData;
    }
    String? jsonString = await _loadEmojiJsonFile();
    if (jsonString != null) {
      _emojiJsonData = EmojiJsonData.fromJson(json.decode(jsonString));
    }
    return _emojiJsonData;
  }

  
}

class EmojiJsonData {
  List<String>? smileOrPerson;
  List<String>? animals;
  List<String>? food;
  List<String>? activities;
  List<String>? travel;
  List<String>? objects;
  List<String>? symbol;

  EmojiJsonData(
      {this.smileOrPerson,
      this.animals,
      this.food,
      this.activities,
      this.travel,
      this.objects,
      this.symbol});

  EmojiJsonData.fromJson(Map<String, dynamic> jsonMap) {
    smileOrPerson = jsonMap['smileOrPerson'] == null ? null : List<String>.from(jsonMap["smileOrPerson"].map((x) => x));
    animals = jsonMap['animals'] == null ? null : List<String>.from(jsonMap["animals"].map((x) => x));
    food = jsonMap['food'] == null ? null : List<String>.from(jsonMap["food"].map((x) => x));
    activities = jsonMap['activities'] == null ? null : List<String>.from(jsonMap["activities"].map((x) => x));
    travel = jsonMap['travel'] == null ? null : List<String>.from(jsonMap["travel"].map((x) => x));
    objects = jsonMap['objects'] == null ? null : List<String>.from(jsonMap["objects"].map((x) => x));
    symbol = jsonMap['symbol'] == null ? null : List<String>.from(jsonMap["symbol"].map((x) => x));
  }

  Map<String, dynamic> toJson() => {
        "smileOrPerson": smileOrPerson,
        "animals": animals,
        "food": food,
        "activities": activities,
        "travel": travel,
        "objects": objects,
        "symbol": symbol,
      };
}

enum EmojiType {
  smileOrPerson,
  animals,
  food,
  activities,
  travel,
  objects,
  symbol
}
