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35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
window.onload = function () {
    let cookies = document.cookie.split(";");
    for (let i = 0; i < cookies.length; i++) {
        let cookie = cookies[i];
        let eqPos = cookie.indexOf("=");
        let name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
        document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/";
    }
    var IMAGE_PATH = "../static/images/";
    document.cookie = "RoomIndex=0";
    //初始化数
    var BedNum = 0, MasterNum = 0, SecondNum = 0, GuestNum = 0, StudyNum = 0, ChildNum = 0, LivingNum = 0;
    var KitchenNum = 0, BalconyNum = 0, BathNum = 0, DiningNum = 0, StorageNum = 0, EntranceNum = 0, Wall_inNum = 0;
    // document.getElementById("BedRoom").onclick = function () {
    //     var curInd = changeRoomIndexCookie();
    //     ++BedNum;
    //     document.getElementById("BedRoom_val").innerHTML = BedNum;
    //     newElement("BedRoom", BedNum, curInd);
    // }
    // document.getElementById("MasterRoom").onclick = function () {
    //     var curInd = changeRoomIndexCookie();
    //     ++MasterNum;
    //     ++BedNum;
    //     newElement("MasterRoom", MasterNum, curInd);
    //     document.getElementById("MasterRoom_val").innerHTML = MasterNum;
    //     document.getElementById("BedRoom_val").innerHTML = BedNum;
    // }
    // document.getElementById("SecondRoom").onclick = function () {
    //     var curInd = changeRoomIndexCookie();
    //     ++SecondNum;
    //     ++BedNum;
    //     newElement("SecondRoom", SecondNum, curInd);
    //     document.getElementById("SecondRoom_val").innerHTML = SecondNum;
    //     document.getElementById("BedRoom_val").innerHTML = BedNum;
    // }
    // document.getElementById("GuestRoom").onclick = function () {
    //     var curInd = changeRoomIndexCookie();
    //     ++GuestNum;
    //     ++BedNum;
    //     newElement("GuestRoom", GuestNum, curInd);
    //     document.getElementById("GuestRoom_val").innerHTML = GuestNum;
    //     document.getElementById("BedRoom_val").innerHTML = BedNum;
    // }
    // document.getElementById("StudyRoom").onclick = function () {
    //     var curInd = changeRoomIndexCookie();
    //     ++StudyNum;
    //     ++BedNum;
    //     newElement("StudyRoom", StudyNum, curInd);
    //     document.getElementById("StudyRoom_val").innerHTML = StudyNum;
    //     document.getElementById("BedRoom_val").innerHTML = BedNum;
    // }
    // document.getElementById("ChildRoom").onclick = function () {
    //     var curInd = changeRoomIndexCookie();
    //     ++ChildNum;
    //     ++BedNum;
    //     newElement("ChildRoom", ChildNum, curInd);
    //     document.getElementById("ChildRoom_val").innerHTML = ChildNum;
    //     document.getElementById("BedRoom_val").innerHTML = BedNum;
    // }
    // document.getElementById("LivingRoom").onclick = function () {
    //     var curInd = changeRoomIndexCookie();
    //     ++LivingNum;
    //     newElement("LivingRoom", LivingNum, curInd);
    //     document.getElementById("LivingRoom_val").innerHTML = LivingNum;
    // }
    // document.getElementById("Kitchen").onclick = function () {
    //     var curInd = changeRoomIndexCookie();
    //     ++KitchenNum;
    //     newElement("Kitchen", KitchenNum, curInd);
    //     document.getElementById("Kitchen_val").innerHTML = KitchenNum;
    // }
    // document.getElementById("Balcony").onclick = function () {
    //     var curInd = changeRoomIndexCookie();
    //     ++BalconyNum;
    //     newElement("Balcony", BalconyNum, curInd);
    //     document.getElementById("Balcony_val").innerHTML = BalconyNum;
    // }
    // document.getElementById("BathRoom").onclick = function () {
    //     var curInd = changeRoomIndexCookie();
    //     ++BathNum;
    //     newElement("BathRoom", BathNum, curInd);
    //     document.getElementById("BathRoom_val").innerHTML = BathNum;
    // }
    // document.getElementById("DiningRoom").onclick = function () {
    //     var curInd = changeRoomIndexCookie();
    //     ++DiningNum;
    //     newElement("DiningRoom", DiningNum, curInd);
    //     document.getElementById("DiningRoom_val").innerHTML = DiningNum;
    // }
    // document.getElementById("Storage").onclick = function () {
    //     var curInd = changeRoomIndexCookie();
    //     ++StorageNum;
    //     newElement("Storage", StorageNum, curInd);
    //     document.getElementById("Storage_val").innerHTML = StorageNum;
    // }
    // document.getElementById("Entrance").onclick = function () {
    //     var curInd = changeRoomIndexCookie();
    //     ++EntranceNum;
    //     newElement("Entrance", EntranceNum, curInd);
    //     document.getElementById("Entrance_val").innerHTML = EntranceNum;
    // }
    // document.getElementById("Wallin").onclick = function () {
    //     var curInd = changeRoomIndexCookie();
    //     ++Wall_inNum;
    //     newElement("Wallin", Wall_inNum, curInd);
    //     document.getElementById("Wallin_val").innerHTML = Wall_inNum;
    // }

    var animationDiv = document.getElementById('animationDiv');
    var addButton = document.getElementById('add');
    var removeSVG = '<?xml version="1.0" encoding="utf-8"?><svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 22 22" style="enable-background:new 0 0 22 22;" xml:space="preserve"><g><g><path class="fill" d="M16.1,3.6h-1.9V3.3c0-1.3-1-2.3-2.3-2.3h-1.7C8.9,1,7.8,2,7.8,3.3v0.2H5.9c-1.3,0-2.3,1-2.3,2.3v1.3c0,0.5,0.4,0.9,0.9,1v10.5c0,1.3,1,2.3,2.3,2.3h8.5c1.3,0,2.3-1,2.3-2.3V8.2c0.5-0.1,0.9-0.5,0.9-1V5.9C18.4,4.6,17.4,3.6,16.1,3.6z M9.1,3.3c0-0.6,0.5-1.1,1.1-1.1h1.7c0.6,0,1.1,0.5,1.1,1.1v0.2H9.1V3.3z M16.3,18.7c0,0.6-0.5,1.1-1.1,1.1H6.7c-0.6,0-1.1-0.5-1.1-1.1V8.2h10.6L16.3,18.7L16.3,18.7z M17.2,7H4.8V5.9c0-0.6,0.5-1.1,1.1-1.1h10.2c0.6,0,1.1,0.5,1.1,1.1V7z"/></g><g><g><path class="fill" d="M11,18c-0.4,0-0.6-0.3-0.6-0.6v-6.8c0-0.4,0.3-0.6,0.6-0.6s0.6,0.3,0.6,0.6v6.8C11.6,17.7,11.4,18,11,18z"/></g><g><path class="fill" d="M8,18c-0.4,0-0.6-0.3-0.6-0.6v-6.8C7.4,10.2,7.7,10,8,10c0.4,0,0.6,0.3,0.6,0.6v6.8C8.7,17.7,8.4,18,8,18z"/></g><g><path class="fill" d="M14,18c-0.4,0-0.6-0.3-0.6-0.6v-6.8c0-0.4,0.3-0.6,0.6-0.6c0.4,0,0.6,0.3,0.6,0.6v6.8C14.6,17.7,14.3,18,14,18z"/></g></g></g></svg>';
    var checkSVG = ' <?xml version="1.0" encoding="utf-8"?><svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 22 22" style="enable-background:new 0 0 22 22;" xml:space="preserve"><circle  cx=11 cy=11 class="noFill" stroke="rgb(47, 167, 77)" r="10" width="23" height="23"/><g><path class="fill" d="M9.7,14.4L9.7,14.4c-0.2,0-0.4-0.1-0.5-0.2l-2.7-2.7c-0.3-0.3-0.3-0.8,0-1.1s0.8-0.3,1.1,0l2.1,2.1l4.8-4.8c0.3-0.3,0.8-0.3,1.1,0s0.3,0.8,0,1.1l-5.3,5.3C10.1,14.3,9.9,14.4,9.7,14.4z"/></g></svg>';


    completedList = document.getElementById('completed');
    todoList = document.getElementById('todo');


// Core Functions

    function addItem(roomname) {
        if (itemTextBox.value) {
            newElement(itemTextBox.value);
            itemTextBox.value = "";
        }

        document.getElementById('add').classList.toggle("rotate");
        addAnimation();

    }


    function fade(element) {
        element.classList.remove('invisible');

    }


    function checkItem() {
        checkButton = this;
        checkAnimateDiv = this.children[1];
        console.log(checkAnimateDiv);
        checkElement = this.parentElement.parentElement;


        if (!(checkElement.classList.contains('checked'))) {
            selectRoomType(checkElement.innerText, this.id);
            checkElement.classList.add('checked');
            checkAnimation(checkAnimateDiv);

            //checkElement.classList.add('invisible');

            setTimeout(function () {
                completedList.appendChild(checkElement);

            }, 100);

            setTimeout(function () {
                DOMCleaner(checkAnimateDiv);

            }, 500);
        } else {
            checkElement.classList.remove('checked');
            deleteAnimation(checkElement);
            todoList.insertBefore(checkElement, todoList.firstChild);

            var points = d3.select("body").selectAll("circle");

            var curInd = this.id.split("_")[1];

            points.each(function (d, i) {
                var tmpInd = this.id.split("_")[1];
                if (tmpInd == curInd) {
                    d3.select(this).remove();
                }
            });
        }


    }


    function DOMCleaner(item) {
        while (item.firstChild) {
            //item.removeChild(item.firstChild);
            item.firstChild.remove();
        }
    }

    function removeItem(name, deleteButton) {
        deleteElement = deleteButton.parentElement.parentElement;
        deleteElement.classList.add('deleted');
        deleteAnimation(deleteElement);
        switch (name) {
            case "BedRoom":
                var a = --BedNum;
                break;
            case "MasterRoom":
                var a = --MasterNum;
                --BedNum;
                break;
            case "SecondRoom":
                var a = --SecondNum;
                --BedNum;
                break;
            case "GuestRoom":
                var a = --GuestNum;
                --BedNum;
                break;
            case "StudyRoom":
                var a = --StudyNum;
                --BedNum;
                break;
            case "ChildRoom":
                var a = --ChildNum;
                --BedNum;
                break;
            case "Kitchen":
                var a = --KitchenNum;
                break;
            case "DiningRoom":
                var a = --DiningNum;
                break;
            case "BathRoom":
                var a = --BathNum;
                break;
            case "Balcony":
                var a = --BalconyNum;
                break;
            case "Entrance":
                var a = --EntranceNum;
                break;
            case "Wallin":
                var a = --Wall_inNum;
                break;
            case "Storage":
                var a = --StorageNum;
                break;
            case "LivingRoom":
                var a = --LivingNum;
                break;

            default:
                break
        }
        var id = name + "_val";
        document.getElementById(id).innerHTML = a;
        document.getElementById("BedRoom_val").innerHTML = BedNum;

        setTimeout(function () {
            deleteElement.remove();
        }, 500);


    }


    function newElement(name, value, curInd) {

        var item_image = document.createElement('img');
        item_image.src = IMAGE_PATH + name + ".png";
        item_image.classList.add('showrmitem');

        var item = document.createElement('li');

        item.innerHTML = name;
        item.appendChild(item_image);
        item.classList.add('invisible');


        var buttonsDiv = document.createElement('div');
        buttonsDiv.classList.add('buttons');

        var deleteButton = document.createElement('button');
        deleteButton.classList.add('deleteButton');
        deleteButton.id = "Delete_" + curInd;
        deleteButton.innerHTML = removeSVG;
        deleteButton.onclick = function () {
            if (d3.select("body").selectAll("circle").length > 0) {
                var points = d3.select("body").selectAll("circle");
                var curInd = this.id.split("_")[1];

                points.each(function (d, i) {
                    var tmpInd = this.id.split("_")[1];
                    if (tmpInd == curInd) {
                        d3.select(this).remove();
                    }
                });
            }


            removeItem(name, deleteButton);
        }


        var checkButton = document.createElement('button');
        checkButton.classList.add('checkButton');
        checkButton.innerHTML = checkSVG;
        checkButton.id = "Check_" + curInd;

        var checkAnimateDiv = document.createElement('div');
        checkAnimateDiv.id = "checkAnimateDiv";
        checkButton.appendChild(checkAnimateDiv);

        checkButton.addEventListener('click', checkItem);

        buttonsDiv.appendChild(deleteButton);
        buttonsDiv.appendChild(checkButton);

        item.appendChild(buttonsDiv);


        //todoList.prepend(item);
        todoList.insertBefore(item, todoList.firstChild);
        setTimeout(function () {
            fade(item);
        }, 100);


    }


// Visual


    /* Add Button Animation */
    function addAnimation() {
        const Burst1 = new mojs.Burst({
            parent: animationDiv,
            top: '50%',
            left: '50%',
            radius: {0: 80},
            count: 8,
            children: {
                shape: 'circle',
                fill: {'red': 'blue'},
                strokeWidth: 1,
                duration: 600,
                stroke: {'red': 'blue'}
            }
        });


        const Burst2 = new mojs.Burst({
            parent: animationDiv,
            top: '50%',
            left: '50%',
            radius: {0: 100},
            count: 4,
            children: {
                shape: 'rect',
                fill: 'white',
                strokeWidth: 1,
                duration: 300,
                stroke: 'white'
            }
        });


        const circle1 = new mojs.Shape({
            radius: {0: 40},
            parent: animationDiv,
            fill: 'none',
            stroke: 'white',
            strokeWidth: 15,
            duration: 300,
            opacity: {1: 0}
        });

        const circle2 = new mojs.Shape({
            radius: {0: 50},
            parent: animationDiv,
            fill: 'none',
            stroke: 'red',
            strokeWidth: 5,
            duration: 400,
            opacity: {1: 0}
        });


        const circle3 = new mojs.Shape({
            radius: {0: 60},
            parent: animationDiv,
            fill: 'none',
            stroke: 'blue',
            strokeWidth: 5,
            duration: 500,
            opacity: {1: 0}
        });

        const circle4 = new mojs.Shape({
            radius: {0: 70},
            parent: animationDiv,
            fill: 'white',

            stroke: 'white',
            strokeWidth: 5,
            duration: 600,
            opacity: {1: 0}
        });

        const timeline = new mojs.Timeline({

            repeat: 0
        }).add(circle4, circle1, circle2, circle3, Burst1, Burst2);

        timeline.play();
    }

    /* Delete item animation */

    function checkAnimation(checkItem) {
        const circle1 = new mojs.Shape({
            radius: {0: 1000},
            parent: checkItem,
            fill: '#7bef28',
            stroke: 'white',
            strokeWidth: 10,
            duration: 500,
            opacity: {1: 0}
        });

        const circle2 = new mojs.Shape({
            radius: {0: 200},
            parent: checkItem,
            fill: 'none',
            stroke: 'white',
            strokeWidth: 30,
            duration: 300,
            opacity: {1.7: 0}
        });

        const circle3 = new mojs.Shape({
            radius: {0: 400},
            parent: checkItem,
            fill: 'none',
            stroke: '#230e5780',
            strokeWidth: 10,
            duration: 400,
            opacity: {1: 0}

        });


        const timelineX = new mojs.Timeline({
            repeat: 0,

        }).add(circle1, circle2, circle3);

        timelineX.play();


    }




    function changeRoomIndexCookie() {
        var arr, reg = new RegExp("(^| )RoomIndex=([^;]*)(;|$)");

        var curIndex = -1;
        if (arr = document.cookie.match(reg))
            curIndex = arr[2];

        document.cookie = "RoomIndex=" + (parseInt(curIndex) + 1);

        return curIndex;
    }
}