import GAME_OBJECTS_1  from "../GamePage/Chapter1/GAME_OBJECTS";
import GAME_OBJECTS_2 from "../GamePage/Chapter2/GAME_OBJECTS";
import GAME_OBJECTS_3 from "../GamePage/Chapter3/GAME_OBJECTS";

// m1_1 = 1, when: 收聽新聞廣播 (chapter1 -> radio)
// m1_2 = 1, when: 規劃防災演練日 (chapter1 -> calendar)
// m1_5 = 1, when: 瞭解避難場所與路線 (chapter1 -> map)
// s3 = 1, when: 鄰居/族人見面 (chapter1 -> door)
// house_strengthen = 1, when 達成 chapter 3 所有事項: 緊閉門窗(window)+盆栽移入室內(plant)+疏通排水溝(sewer)+修剪樹木枝幹(tree)+堆沙包 (sandbag)
// emergency_kit = 1. when: 購買 chapter 2 所有: 手電筒(flashlight)+水(water)+乾糧罐頭(can)+急救包(aidKit)+睡袋(sleepbag)+粗棉手套(gloves)+哨子(whistle)
// damage_posibility = 1, when: 選擇傳送以下訊息: [非常…] or [小怕]
//  = 1. when: 在收到村里長訊息後選擇: [感覺有點危險 撤離!!!] (chapter4 -> branch === b)


export const CHAPTER_1_MUST_DO = [
    {
        ...GAME_OBJECTS_1.radio,
        image: "/images/game/chapter1/static-objects/radio.png",
        key: "m1_1",
        category: "日常準備",
    },
    {
        ...GAME_OBJECTS_1.calendar,
        image: "/images/game/chapter1/static-objects/calendar.png",
        key: "m1_2",
        category: "日常準備",
    },
    {
        ...GAME_OBJECTS_1.map,
        image: "/images/game/chapter1/static-objects/map.png",
        key: "m1_5",
        category: "日常準備",
    },
    {
        ...GAME_OBJECTS_1.door,
        image: "/images/game/chapter1/static-objects/door.png",
        key: "s3",
        category: "日常準備",
    },
]

export const CHAPTER_2_MUST_DO = [
    {
        ...GAME_OBJECTS_2.flashlight,
        image: "/images/game/chapter2/static-objects/flashlight.png",
        key: "emergency_kit",
        category: "災前購物",
    },
    {
        ...GAME_OBJECTS_2.water,
        image: "/images/game/chapter2/static-objects/water.png",
        key: "emergency_kit",
        category: "災前購物",
    },
    {
        ...GAME_OBJECTS_2.can,
        image: "/images/game/chapter2/static-objects/can.png",
        key: "emergency_kit",
        category: "災前購物",
    },
    {
        ...GAME_OBJECTS_2.aidKit,
        image: "/images/game/chapter2/static-objects/aid-kit.png",
        key: "emergency_kit",
        category: "災前購物",
    },
    {
        ...GAME_OBJECTS_2.sleepbag,
        image: "/images/game/chapter2/static-objects/sleepbag.png",
        key: "emergency_kit",
        category: "災前購物",
    },
    {
        ...GAME_OBJECTS_2.gloves,
        image: "/images/game/chapter2/static-objects/gloves.png",
        key: "emergency_kit",
        category: "災前購物",
    },
    {
        ...GAME_OBJECTS_2.whistle,
        image: "/images/game/chapter2/static-objects/whistle.png",
        key: "emergency_kit",
        category: "災前購物",
    },
]

export const CHAPTER_3_MUST_DO = [
    {
        ...GAME_OBJECTS_3.window,
        image: "/images/game/chapter3/static-objects/window.png",
        key: "house_strengthen",
        category: "抗颱準備",
    },
    {
        ...GAME_OBJECTS_3.plant,
        image: "/images/game/chapter3/static-objects/plant.png",
        key: "house_strengthen",
        category: "抗颱準備",
    },
    {
        ...GAME_OBJECTS_3.sewer,
        image: "/images/game/chapter3/static-objects/sewer.png",
        key: "house_strengthen",
        category: "抗颱準備",
    },
    {
        ...GAME_OBJECTS_3.tree,
        image: "/images/game/chapter3/static-objects/tree.png",
        key: "house_strengthen",
        category: "抗颱準備",
    },
    {
        ...GAME_OBJECTS_3.sandbag,
        image: "/images/game/chapter3/static-objects/sandbag.png",
        key: "house_strengthen",
        category: "抗颱準備",
    },
]

export const CHAPTER_4_MUST_DO = [
    {
        number: 1,
        stars: 5,
        id: 'sticker',
        title: "貼圖選擇「非常」/「小怕」",
        image: "/images/game/chapter4/damage_posibility.png",
        key: "damage_posibility",
        category: "災害意識",
        importance: "提高對颱風風險的認知，認真看待防颱準備。"
    },
    {
        number: 2,
        stars: 5,
        id: 'evacuate',
        title: "選擇「感覺有點危險 撤離!!!」",
        image: "/images/game/chapter4/confirm_evacuate.png",
        key: "confirm_evacuate",
        category: "災害意識",
        importance: "當所處環境已經有危險時，撤離至安全的地方才是上策。"
    }
]



const getCompleteTasks = (data) => {
    // return done and missed
    let done = []
    let missed = []
    

    // check chapter 1 must do
    for (const task of CHAPTER_1_MUST_DO.sort((a, b) => a.number - b.number)) {
        if (data.chapter1.find((item) => item.id === task.id)) {
            done.push(task)
        } else {
            missed.push(task)
        }
    }

    // check chapter 2 must do
    for (const task of CHAPTER_2_MUST_DO.sort((a, b) => a.number - b.number)) {
        if (data.chapter2.find((item) => item.id === task.id)) {
            done.push(task)
        } else {
            missed.push(task)
        }
    }

    // check chapter 3 must do
    for (const task of CHAPTER_3_MUST_DO.sort((a, b) => a.number - b.number)) {
        if (data.chapter3.find((item) => item.id === task.id)) {
            done.push(task)
        } else {
            missed.push(task)
        }
    }

    // check chapter 4 must do
    if (data.chapter4.sticker.value === "非常" || data.chapter4.sticker.value === "小怕") {
        done.push(CHAPTER_4_MUST_DO[0])
    } else {
        missed.push(CHAPTER_4_MUST_DO[0])
    }
    if (data.chapter4.branch === "b") {
        done.push(CHAPTER_4_MUST_DO[1])
    } else {
        missed.push(CHAPTER_4_MUST_DO[1])
    }
    
    return {
        // ascending order
        done: done,
        missed: missed,
    }


};

export default getCompleteTasks


