
// 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 [小怕]
// confirm_evacuate = 1. when: 在收到村里長訊息後選擇: [感覺有點危險 撤離!!!] (chapter4 -> branch === b)
import GAME_OBJECTS_CHAPTER_1 from "../GamePage/Chapter1/GAME_OBJECTS"
import GAME_OBJECTS_CHAPTER_2 from "../GamePage/Chapter2/GAME_OBJECTS"
import GAME_OBJECTS_CHAPTER_3 from "../GamePage/Chapter3/GAME_OBJECTS"

const calculateScore = (data) => {
    let m1_1 = 0
    let m1_2 = 0
    let m1_5 = 0
    let s3 = 0
    let house_strengthen = 0
    let emergency_kit = 0
    let damage_posibility = 0
    let confirm_evacuate = 0

    // check m1_1
    if (data.chapter1.find(item => item.id === GAME_OBJECTS_CHAPTER_1.radio.id)) {
        m1_1 = 1
    }

    // check m1_2
    if (data.chapter1.find(item => item.id === GAME_OBJECTS_CHAPTER_1.calendar.id)) {
        m1_2 = 1
    }

    // check m1_5
    if (data.chapter1.find(item => item.id === GAME_OBJECTS_CHAPTER_1.map.id)) {
        m1_5 = 1
    }

    // check s3
    if (data.chapter1.find(item => item.id === GAME_OBJECTS_CHAPTER_1.door.id)) {
        s3 = 1
    }

    // check house_strengthen
    let checkHouseStrengthenItems = [
        GAME_OBJECTS_CHAPTER_3.window.id,
        GAME_OBJECTS_CHAPTER_3.plant.id,
        GAME_OBJECTS_CHAPTER_3.sewer.id,
        GAME_OBJECTS_CHAPTER_3.tree.id,
        GAME_OBJECTS_CHAPTER_3.sandbag.id
    ]
    let tempHouseStrengthen = 0
    checkHouseStrengthenItems.forEach(checkItem => {
        if (data.chapter3.find(item => item.id === checkItem)) {
            tempHouseStrengthen += 1
        }
    })
    if (tempHouseStrengthen === checkHouseStrengthenItems.length) {
        house_strengthen = 1
    }

    // check emergency_kit
    let checkEmergencyKitItems = [
        GAME_OBJECTS_CHAPTER_2.flashlight.id,
        GAME_OBJECTS_CHAPTER_2.water.id,
        GAME_OBJECTS_CHAPTER_2.can.id,
        GAME_OBJECTS_CHAPTER_2.aidKit.id,
        GAME_OBJECTS_CHAPTER_2.sleepbag.id,
        GAME_OBJECTS_CHAPTER_2.gloves.id,
        GAME_OBJECTS_CHAPTER_2.whistle.id
    ]
    let tempEmergencyKit = 0
    checkEmergencyKitItems.forEach(checkItem => {
        if (data.chapter2.find(item => item.id === checkItem)) {
            tempEmergencyKit += 1
        }
    })
    if (tempEmergencyKit === checkEmergencyKitItems.length) {
        emergency_kit = 1
    }

    // check damage_posibility
    if (data.chapter4.sticker.value === "非常" || data.chapter4.sticker.value === "小怕") {
        damage_posibility = 1
    }

    // check 
    if (data.chapter4.branch === "b") {
        confirm_evacuate = 1
    }

    return {
        m1_1,
        m1_2,
        m1_5,
        s3,
        house_strengthen,
        emergency_kit,
        damage_posibility,
        confirm_evacuate
        
    }

}

export default calculateScore