import { CustomTrainData } from "@/lib/CommonTypes";
import dayjs from "dayjs";
type CustomTrainDataDetector = (
  TrainNumber: string,
  allCustomTrainData?: any[]
) => CustomTrainData;
export const customTrainDataDetector: CustomTrainDataDetector = (
  TrainNumber,
  allCustomTrainData
) => {
  if (allCustomTrainData && allCustomTrainData.length > 0) {
    const customTrain = allCustomTrainData.find(
      (train) => train.TrainNumber === TrainNumber
    );
    if (customTrain) {
      return customTrain;
    }
  }
  const trainGetText = `?trainNum=${TrainNumber}&month=${dayjs().format(
    "M"
  )}&day=${dayjs().format("D")}`;
  switch (TrainNumber) {
    //しおかぜメイン
    //8000 ノーマル
    case "4M":
    case "6M":
    case "14M":
    case "16M":
    case "18M":
    case "26M":
    case "28M":
    case "30M":
    case "1M":
    case "3M":
    case "5M":
    case "13M":
    case "15M":
    case "17M":
    case "25M":
    case "27M":
    case "29M":
      return {
        type: "LTDEXP",
        trainName: "しおかぜ",
        img: "https://storage.haruk.in/s8000nr.png",
        infoUrl:
          "https://www.jr-shikoku.co.jp/01_trainbus/vehicle-info/shiokaze.html",
        trainNumDistance: 0,
        info: "いしづちと併結 / 8000系で運転",
        infogram: "Ｇ",
      };
    case "2M":
      return {
        type: "LTDEXP",
        trainName: "しおかぜ",
        img: "https://storage.haruk.in/s8000nr.png",
        infoUrl:
          "https://www.jr-shikoku.co.jp/01_trainbus/vehicle-info/shiokaze.html",
        trainNumDistance: 0,
        info: "8000系で運転",
        infogram: "Ｇ",
      };
    //8000 アンパン
    case "10M":
    case "22M":
    case "9M":
    case "21M":
      return {
        type: "LTDEXP",
        trainName: "しおかぜ",
        img: `https://n8n.haruk.in/webhook/anpanman-pictures.png${trainGetText}`,
        infoUrl: "https://www.jr-eki.com/aptrain/naani/yosan/train.html",
        trainNumDistance: 0,
        info: "いしづちと併結 / アンパンマン列車で運転",
        infogram: "Ｇ",
      };
    //8600
    case "8M":
    case "12M":
    case "20M":
    case "24M":
    case "7M":
    case "11M":
    case "19M":
    case "23M":
      return {
        type: "LTDEXP",
        trainName: "しおかぜ",
        img: "https://storage.haruk.in/s8600.png",
        infoUrl:
          "https://www.jr-shikoku.co.jp/01_trainbus/vehicle-info/shiokaze.html",
        trainNumDistance: 0,
        info: "いしづちと併結 / 8600系で運転",
        infogram: "Ｇ",
      };

    //いしづちメイン
    //8000 ノーマル

    case "1004M":
    case "1006M":
    case "1014M":
    case "1016M":
    case "1018M":
    case "1026M":
    case "1028M":
    case "1030M":
    case "1001M":
    case "1003M":
    case "1005M":
    case "1013M":
    case "1015M":
    case "1017M":
    case "1025M":
    case "1027M":
    case "1029M":
      return {
        type: "LTDEXP",
        trainName: "いしづち",
        img: "https://storage.haruk.in/s8000no.png",
        infoUrl:
          "https://www.jr-shikoku.co.jp/01_trainbus/vehicle-info/ishizuchi.html",
        trainNumDistance: 1000,
        info: "しおかぜと併結 / 8000系で運転",
        infogram: "",
      };

    //8000 アンパン
    case "1010M":
    case "1022M":
    case "1009M":
    case "1021M":
      return {
        type: "LTDEXP",
        trainName: "いしづち",
        img: `https://n8n.haruk.in/webhook/anpanman-pictures.png${trainGetText}`,
        infoUrl: "https://www.jr-eki.com/aptrain/naani/yosan/train.html",
        trainNumDistance: 1000,
        info: "しおかぜと併結 / アンパンマン列車で運転",
        infogram: "",
      };

    //8600
    case "1008M":
    case "1012M":
    case "1020M":
    case "1024M":
    case "1007M":
    case "1011M":
    case "1019M":
    case "1023M":
      return {
        type: "LTDEXP",
        trainName: "いしづち",
        img: "https://storage.haruk.in/s8600_isz.png",
        infoUrl:
          "https://www.jr-shikoku.co.jp/01_trainbus/vehicle-info/ishizuchi.html",
        trainNumDistance: 1000,
        info: "しおかぜと併結 / 8600系で運転",
        infogram: "",
      };

    //MEXP
    //8000
    case "1092M":
      return {
        type: "LTDEXP",
        trainName: "モーニングEXP高松",
        img: "https://storage.haruk.in/s8000nr.png",
        infoUrl:
          "https://www.jr-shikoku.co.jp/01_trainbus/vehicle-info/morning.html",
        trainNumDistance: null,
        info: "8000系で運転",
        infogram: "Ｇ",
      };
    //8600
    case "1091M":
      return {
        type: "LTDEXP",
        trainName: "モーニングEXP松山",
        img: "https://storage.haruk.in/s8600_isz.png",
        infoUrl:
          "https://www.jr-shikoku.co.jp/01_trainbus/vehicle-info/morning.html",
        trainNumDistance: null,
        info: "8600系で運転",
        infogram: "Ｇ",
      };
    //三桁いしづち
    //8000 アンパン
    case "1041M":
    case "1044M":
      return {
        type: "LTDEXP",
        trainName: "いしづち",
        img: `https://n8n.haruk.in/webhook/anpanman-pictures.png${trainGetText}`,
        infoUrl: "https://www.jr-eki.com/aptrain/naani/yosan/train.html",
        trainNumDistance: 940,
        info: "アンパンマン列車で運転",
        infogram: "Ｇ",
      };
    //8600
    case "1043M":
    case "1042M":
      return {
        type: "LTDEXP",
        trainName: "いしづち",
        img: "https://storage.haruk.in/s8600_isz.png",
        infoUrl:
          "https://www.jr-shikoku.co.jp/01_trainbus/vehicle-info/ishizuchi.html",
        trainNumDistance: 940,
        info: "8600系で運転",
        infogram: "",
      };
    case "1046M":
      return {
        type: "LTDEXP",
        trainName: "いしづち",
        img: "https://storage.haruk.in/s8600_isz.png",
        infoUrl:
          "https://www.jr-shikoku.co.jp/01_trainbus/vehicle-info/ishizuchi.html",
        trainNumDistance: 940,
        info: "8600系で運転",
        infogram: "Ｇ",
      };

    //南風 2700ノーマル
    case "34D":
    case "38D":
    case "40D":
    case "42D":
    case "46D":
    case "50D":
    case "52D":
    case "54D":
    case "58D":
    case "31D":
    case "35D":
    case "39D":
    case "41D":
    case "43D":
    case "47D":
    case "51D":
    case "53D":
    case "55D":
      return {
        type: "LTDEXP",
        trainName: "南風",
        img: "https://storage.haruk.in/s2700.png",
        infoUrl:
          "https://www.jr-shikoku.co.jp/01_trainbus/vehicle-info/nanpu.html",
        trainNumDistance: 30,
        info: "2700系で運転",
        infogram: "Ｇ",
      };

    //2700アンパン
    case "32D":
    case "36D":
    case "44D":
    case "48D":
    case "56D":
    case "33D":
    case "37D":
    case "45D":
    case "49D":
    case "57D":
      return {
        type: "LTDEXP",
        trainName: "南風",
        img: `https://n8n.haruk.in/webhook/anpanman-pictures.png${trainGetText}`,
        infoUrl: "https://www.jr-eki.com/aptrain/naani/dosan/train.html",
        trainNumDistance: 30,
        info: "アンパンマン列車で運転",
        infogram: "Ｇ",
      };

    //うずしお
    //2700
    case "3004D":
    case "3006D":
    case "3010D":
    case "3014D":
    case "3016D":
    case "3022D":
    case "3028D":
    case "3003D":
    case "3007D":
    case "3013D":
    case "3019D":
    case "3025D":
    case "3031D":
      return {
        type: "LTDEXP",
        trainName: "うずしお",
        img: "https://storage.haruk.in/s2700_uzu.png",
        infoUrl:
          "https://www.jr-shikoku.co.jp/01_trainbus/vehicle-info/uzushio.html",
        trainNumDistance: 3000,
        info: "2700系で運転",
        infogram: "",
      };

    //2700 二両編成

    case "3008D":
    case "3020D":
    case "3026D":
    case "3001D":
    case "3005D":
    case "3011D":
    case "3017D":
    case "3023D":
    case "3029D":
      return {
        type: "LTDEXP",
        trainName: "うずしお",
        img: "https://storage.haruk.in/s2700_uzu.png",
        infoUrl:
          "https://www.jr-shikoku.co.jp/01_trainbus/vehicle-info/uzushio.html",
        trainNumDistance: 3000,
        info: "2700系で運転",
        infogram: "",
      };

    //2600
    case "3002D":
    case "3012D":
    case "3018D":
    case "3024D":
    case "3030D":
    case "3009D":
    case "3015D":
    case "3021D":
    case "3027D":
    case "3033D":
      return {
        type: "LTDEXP",
        trainName: "うずしお",
        img: "https://storage.haruk.in/s2600.png",
        infoUrl:
          "https://www.jr-shikoku.co.jp/01_trainbus/vehicle-info/uzushio.html",
        trainNumDistance: 3000,
        info: "2600系で運転",
        infogram: "",
      };

    //マリンライナー
    case "3104M":
    case "3106M":
    case "3108M":
    case "3110M":
    case "3112M":
    case "3114M":
    case "3116M":
    case "3118M":
    case "3120M":
    case "3122M":
    case "3124M":
    case "3126M":
    case "3128M":
    case "3130M":
    case "3132M":
    case "3134M":
    case "3136M":
    case "3138M":
    case "3140M":
    case "3142M":
    case "3144M":
    case "3146M":
    case "3148M":
    case "3150M":
    case "3152M":
    case "3154M":
    case "3156M":
    case "3158M":
    case "3160M":
    case "3162M":
    case "3164M":
    case "3166M":
    case "3168M":
    case "3170M":
    case "3105M":
    case "3107M":
    case "3109M":
    case "3111M":
    case "3113M":
    case "3115M":
    case "3117M":
    case "3119M":
    case "3121M":
    case "3123M":
    case "3125M":
    case "3127M":
    case "3129M":
    case "3131M":
    case "3133M":
    case "3135M":
    case "3137M":
    case "3139M":
    case "3141M":
    case "3143M":
    case "3145M":
    case "3147M":
    case "3149M":
    case "3151M":
    case "3153M":
    case "3155M":
    case "3157M":
    case "3159M":
    case "3161M":
    case "3163M":
    case "3165M":
    case "3167M":
    case "3169M":
    case "3175M":
      return {
        type: "Rapid",
        trainName: "マリンライナー",
        img: "https://storage.haruk.in/s5001.png",
        infoUrl:
          "https://www.jr-shikoku.co.jp/01_trainbus/vehicle-info/marine.html",
        trainNumDistance: 3100,
        info: "",
        infogram: "Ｇ",
      };
    case "3102M":
    case "3101M":
    case "3103M":
    case "3171M":
    case "3173M":
      return {
        type: "Rapid",
        trainName: "マリンライナー",
        img: "https://storage.haruk.in/s5001k.png",
        infoUrl:
          "https://www.jr-shikoku.co.jp/01_trainbus/vehicle-info/marine.html",
        trainNumDistance: 3100,
        info: "",
        infogram: "",
      };
    //下りサンポート
    case "1219M":
      return {
        type: "Normal",
        trainName: "南風リレー",
        img: "",
        infoUrl: "",
        trainNumDistance: null,
        info: "	土曜・休日は多度津－琴平間運休",
        infogram: "",
      };

    case "111M":
    case "115M":
    case "117M":
    case "121M":
    case "123M":
    case "127M":
    case "131M":
    case "139M":
    case "147M":
    case "151M":
      return {
        type: "Rapid",
        trainName: "サンポート南風リレー",
        img: null,
        infoUrl: null,
        trainNumDistance: null,
        info: null,
        infogram: "",
      };
    case "5109M":
    case "5135M":
    case "5251M":
      return {
        type: "OneManRapid",
        trainName: "サンポート南風リレー",
        img: null,
        infoUrl: null,
        trainNumDistance: null,
        info: null,
        infogram: "",
      };
    case "137M":
      return {
        type: "Rapid",
        trainName: "サンポート",
        img: null,
        infoUrl: null,
        trainNumDistance: null,
        info: "土曜・休日運休",
        infogram: "",
      };
    //上りサンポート
    case "116M":
      return {
        type: "Normal",
        trainName: "南風リレー",
        img: null,
        infoUrl: null,
        trainNumDistance: null,
        info: null,
        infogram: "",
      };

    case "130M":
    case "132M":
    case "136M":
    case "140M":
    case "144M":
    case "146M":
    case "150M":
    case "156M":
      return {
        type: "Rapid",
        trainName: "サンポート南風リレー",
        img: "",
        infoUrl: "",
        trainNumDistance: null,
        info: "",
        infogram: "",
      };
    case "5118M":
    case "5120M":
    case "5124M":
    case "5126M":
    case "5252M":
      return {
        type: "OneManRapid",
        trainName: "サンポート南風リレー",
        img: null,
        infoUrl: null,
        trainNumDistance: null,
        info: null,
        infogram: "",
      };

    //サンライズ瀬戸
    case "5032M":
    case "5031M":
      return {
        type: "NightLTDEXP",
        trainName: "サンライズ瀬戸",
        img: "https://storage.haruk.in/w285.png",
        infoUrl:
          "https://www.jr-odekake.net/train/sunriseseto_izumo/index.html",
        trainNumDistance: null,
        info: "",
        infogram: "ブ",
      };
    case "8041M": //琴平延長高松迄
    case "8031M": //琴平延長高松以降
      return {
        type: "NightLTDEXP",
        trainName: "サンライズ瀬戸",
        img: "https://storage.haruk.in/w285.png",
        infoUrl:
          "https://www.jr-odekake.net/train/sunriseseto_izumo/index.html",
        trainNumDistance: null,
        info: "琴平延長運転日",
        infogram: "ブ",
      };

    //宇和海
    //2000 ノーマル
    case "1052D":
    case "1054D":
    case "1056D":
    case "1060D":
    case "1062D":
    case "1064D":
    case "1068D":
    case "1070D":
    case "1072D":
    case "1076D":
    case "1078D":
    case "1080D":
    case "1082D":
    case "1051D":
    case "1055D":
    case "1057D":
    case "1061D":
    case "1063D":
    case "1065D":
    case "1069D":
    case "1071D":
    case "1073D":
    case "1075D":
    case "1077D":
    case "1079D":
    case "1081D":
      return {
        type: "LTDEXP",
        trainName: "宇和海",
        img: "https://storage.haruk.in/s2000_uwa.png",
        infoUrl:
          "https://www.jr-shikoku.co.jp/01_trainbus/vehicle-info/uwakai.html",
        trainNumDistance: 1050,
        info: "2000系で運転",
        infogram: "",
      };
    //2000 アンパン込み
    case "1058D":
    case "1066D":
    case "1074D":
    case "1053D":
    case "1059D":
    case "1067D":
      return {
        type: "LTDEXP",
        trainName: "宇和海",
        img: `https://n8n.haruk.in/webhook/anpanman-pictures.png${trainGetText}`,
        infoUrl: "https://www.jr-eki.com/aptrain/naani/yosan/train.html",
        trainNumDistance: 1050,
        info: "アンパン列車で運転",
        infogram: "",
      };
    //しまんと
    case "2002D":
    case "2004D":
    case "2001D":
    case "2003D":
      return {
        type: "LTDEXP",
        trainName: "しまんと",
        img: "https://storage.haruk.in/s2700_smn.png",
        infoUrl:
          "https://www.jr-shikoku.co.jp/01_trainbus/vehicle-info/shimanto.html",
        trainNumDistance: 2000,
        info: "2700系で運転",
        infogram: "",
      };

    //あしずり 2000
    case "2074D":
    case "2076D":
    case "2080D":
    case "2082D":
    case "2071D":
    case "2073D":
    case "2079D":
    case "2081D":
      return {
        type: "LTDEXP",
        trainName: "あしずり",
        img: `https://n8n.haruk.in/webhook/anpanman-pictures.png${trainGetText}`,
        infoUrl:
          "https://www.jr-eki.com/aptrain/naani/first-generation/jikoku.html",
        trainNumDistance: 2070,
        info: "2000系で運転",
        infogram: "",
      };

    //あしずり 2700
    case "2078D":
    case "2084D":
    case "2075D":
    case "2077D":
      return {
        type: "LTDEXP",
        trainName: "あしずり",
        img: "https://storage.haruk.in/s2700_asi.png",
        infoUrl:
          "https://www.jr-shikoku.co.jp/01_trainbus/vehicle-info/ashizuri.html",
        trainNumDistance: 2070,
        info: "2700系で運転",
        infogram: "",
      };
    case "2072D":
    case "2083D":
      return {
        type: "LTDEXP",
        trainName: "あしずり",
        img: "https://storage.haruk.in/s2700_asi.png",
        infoUrl:
          "https://www.jr-shikoku.co.jp/01_trainbus/vehicle-info/ashizuri.html",
        trainNumDistance: 2070,
        info: "2700系で運転",
        infogram: "Ｇ",
      };

    //剣山
    case "4002D":
    case "4004D":
    case "4006D":
    case "4001D":
    case "4003D":
    case "4005D":
    case "4007D":
      return {
        type: "LTDEXP",
        trainName: "剣山",
        img: "https://storage.haruk.in/s185tu.png",
        infoUrl:
          "https://www.jr-shikoku.co.jp/01_trainbus/vehicle-info/tsurugisan.html",
        trainNumDistance: 4000,
        info: "キハ185系で運転",
        infogram: "",
      };

    //よしのがわトロッコ
    case "8452D":
    case "8451D":
      return {
        type: "LTDEXP",
        trainName: "よしのがわトロッコ",
        img: "https://storage.haruk.in/s185to_ai.png",
        infoUrl:
          "https://www.jr-shikoku.co.jp/01_trainbus/event_train/yoshino_torokko.html",
        trainNumDistance: null,
        info: "",
        infogram: "",
      };

    //岡山高松アントロ
    case "8176D":
    case "8179D":
    //岡山琴平アントロ
    case "8277D":
    case "8278D":
      return {
        type: "LTDEXP",
        trainName: "アンパンマントロッコ",
        img: "https://storage.haruk.in/s32to4.png",
        infoUrl:
          "https://www.jr-eki.com/aptrain/naani/torokko_seto/jikoku.html",
        trainNumDistance: null,
        info: "",
        infogram: "Ｇ",
      };

    //伊予灘ものがたり
    case "8091D":
    case "8093D":
      return {
        type: "LTDEXP",
        trainName: "伊予灘ものがたり",
        img: "https://storage.haruk.in/s185iyor.png",
        infoUrl: "https://iyonadamonogatari.com/",
        trainNumDistance: null,
        info: "",
        infogram: "Ｇ",
      };
    case "8092D":
    case "8094D":
      return {
        type: "LTDEXP",
        trainName: "伊予灘ものがたり",
        img: "https://storage.haruk.in/s185iyoy.png",
        infoUrl: "https://iyonadamonogatari.com/",
        trainNumDistance: null,
        info: "",
        infogram: "Ｇ",
      };

    //千年ものがたり
    case "8021D":
    case "8022D":
      return {
        type: "LTDEXP",
        trainName: "四国まんなか千年ものがたり",
        img: "https://storage.haruk.in/s185mm1.png",
        infoUrl: "https://www.jr-shikoku.co.jp/sennenmonogatari/",
        trainNumDistance: null,
        info: "",
        infogram: "Ｇ",
      };

    //夜明けものがたり
    case "8082D":
    case "8083D":
    case "8073D":
    case "8074D":
      return {
        type: "LTDEXP",
        trainName: "時代の夜明けのものがたり",
        img: "https://storage.haruk.in/s185ym1.png",
        infoUrl: "https://www.jr-shikoku.co.jp/yoakenomonogatari/index.html",
        trainNumDistance: null,
        info: "",
        infogram: "Ｇ",
      };
    case "9174M":
      return {
        type: "SPCL_Rapid",
        trainName: "マリンライナー94号",
        img: "https://storage.haruk.in/s5001.png",
        infoUrl:
          "https://www.jr-shikoku.co.jp/01_trainbus/vehicle-info/marine.html",
        trainNumDistance: null,
        info: "臨時列車 4/12,13,19のみ運転",
        infogram: "Ｇ",
      };
    case "9395D":
      return {
        type: "SPCL_Normal",
        trainName: "",
        img: "https://storage.haruk.in/s1500.png",
        infoUrl: null,
        trainNumDistance: null,
        info: "臨時列車 4/12,13,19のみ運転",
        infogram: "",
      };
    case "9662D":
    case "9665D":
      return {
        type: "SPCL_Normal",
        trainName: "れんげ号",
        img: "",
        infoUrl: null,
        trainNumDistance: null,
        info: "臨時列車 4/29のみ運転",
        infogram: "",
      };
    case "9664D":
    case "9663D":
      return {
        type: "SPCL_Normal",
        trainName: "わらぐろ号",
        img: "",
        infoUrl: null,
        trainNumDistance: null,
        info: "臨時列車 4/29のみ運転",
        infogram: "",
      };
    default:
      if (getJRF(TrainNumber) !== null) {
        return {
          type: "Freight",
          trainName: getJRF(TrainNumber),
          img: "https://storage.haruk.in/ef210a.png",
          infoUrl: null,
          trainNumDistance: null,
          info: "",
          infogram: "",
        };
      } else if (
        new RegExp(/^4[1-9]\d\d[DM]$/).test(TrainNumber) ||
        new RegExp(/^5[1-7]\d\d[DM]$/).test(TrainNumber) ||
        new RegExp(/^3[2-9]\d\d[DM]$/).test(TrainNumber)
      )
        return {
          type: "OneMan",
          trainName: "",
          img: null,
          infoUrl: null,
          trainNumDistance: null,
          info: null,
          infogram: "",
        };
      else if (
        new RegExp(/^[1-9]\d\d[DM]$/).test(TrainNumber) ||
        new RegExp(/^1[26]\d\d[DM]$/).test(TrainNumber) ||
        new RegExp(/^58\d\d[DM]$/).test(TrainNumber) ||
        new RegExp(/^6\d\d\d[DM]$/).test(TrainNumber)
      ) {
        return {
          type: "Normal",
          trainName: "",
          img: null,
          infoUrl: null,
          trainNumDistance: null,
          info: null,
          infogram: "",
        };
      } else {
        return {
          type: "Other",
          trainName: "",
          img: null,
          infoUrl: null,
          trainNumDistance: null,
          info: null,
          infogram: "",
        };
      }
  }
};
export const getJRF = (num: string) => {
  switch (num) {
    case "71":
      return "東京(タ)→高松(タ)";
    case "73":
    case "75":
      return "大阪(タ)→高松(タ)";
    case "3079":
      return "高松(タ)→伊予三島";
    case "3071":
    case "3077":
      return "高松(タ)→新居浜";
    case "3073":
      return "高松(タ)→松山貨物";
    case "70":
      return "高松(タ)→東京(タ)";
    case "74":
    case "76":
      return "高松(タ)→大阪(タ)";
    case "3078":
      return "伊予三島→高松(タ)";
    case "3070":
      return "新居浜→高松(タ)";
    case "3076":
      return "新居浜→高松(タ)";
    case "3072":
      return "松山貨物→高松(タ)";
    case "9070":
      return "臨時";
    default:
      return null;
  }
};
