summaryrefslogtreecommitdiff
path: root/pages/toys.inc
blob: afcd5ef11920729406b349483b842567e1f4b962 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
<?php

require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title;

if (isset($_POST['deleteAction'])) {
    $data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/toys/toys.json"), true);

    $selected = null;
    $selectedIndex = -1;
    $id = $_POST['action'];

    foreach ($data as $index => $item) {
        if ($item["id"] === $id) {
            $selectedIndex = $index;
            $selected = $item;
            break;
        }
    }

    if ($selected === null) {
        header("Location: /-/toys");
        die();
    }

    unset($data[$selectedIndex]);
    file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/toys/toys.json", utf8_encode(json_encode($data)));
    header("Location: /-/toys/?d&id=" . $id);
    die();
}

if (isset($_POST['updateAction'])) {
    $data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/toys/toys.json"), true);

    $selected = null;
    $selectedIndex = -1;
    $id = $_POST['action'];

    foreach ($data as $index => $item) {
        if ($item["id"] === $id) {
            $selectedIndex = $index;
            $selected = $item;
            break;
        }
    }

    if ($selected === null) {
        header("Location: /-/toys");
        die();
    }

    if (isset($_POST["sexual"])) {
        $selected["sexual"] = true;
    } else {
        $selected["sexual"] = false;
    }

    if (isset($_POST["name"])) $selected["name"] = strip_tags(trim($_POST["name"]));
    if (isset($_POST["usage"])) $selected["usage"] = strip_tags(trim($_POST["usage"]));
    if (isset($_POST["irl"])) $selected["irl"] = strip_tags(trim($_POST["irl"]));
    if (isset($_POST["image"])) $selected["image"] = strip_tags(trim($_POST["image"]));
    if (isset($_POST["usage_img"])) $selected["usage_img"] = strip_tags(trim($_POST["usage_img"]));
    if (isset($_POST["keywords"])) $selected["keywords"] = array_map(function ($i) {
        return trim($i);
    }, explode(",", strip_tags(trim($_POST["keywords"]))));
    if (isset($_POST["description"])) $selected["description"] = strip_tags(trim($_POST["description"]));
    if (isset($_POST["water"])) $selected["water"] = match ($_POST["water"]) {
        "0" => "out",
        "1" => "in",
        "2" => "both",
        "3" => "playground"
    };

    if (isset($_POST["relations"])) {
        $ponies = [];

        foreach ($_POST["relations"] as $relation => $d) {
            $ponies[] = [
                "members" => explode("-", $relation),
                "deprecated" => isset($d["deprecated"]),
                "sexual" => isset($d["sexual"])
            ];
        }

        $selected["ponies"] = $ponies;
    }

    global $_PROFILE;
    if ($_PROFILE['login'] === "raindrops" && isset($_POST["verified"])) {
        $selected["verified"] = true;
    } else {
        unset($selected["verified"]);
    }

    if (isset($_POST["untested"])) {
        $selected["untested"] = true;
    } else {
        unset($selected["untested"]);
    }

    $data[$selectedIndex] = $selected;
    file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/toys/toys.json", utf8_encode(json_encode($data)));

    header("Location: /-/toys/" . $id);
    die();
}

if (isset($_POST['createAction'])) {
    require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/random.inc";
    $data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/toys/toys.json"), true);

    if (!isset($_POST["name"]) || !isset($_POST["water"])) {
        header("Location: /-/toys");
        die();
    }
    if (trim($_POST["name"]) === "" || !is_numeric($_POST["water"])) {
        header("Location: /-/toys");
        die();
    }

    $water = match ($_POST["water"]) {
        "0" => "out",
        "1" => "in",
        "2" => "both",
        "3" => "playground"
    };
    $name = strip_tags(trim($_POST["name"]));
    $id = random();

    $ponies = [];

    if (isset($_POST["relations"])) {
        foreach ($_POST["relations"] as $relation => $_) {
            $ponies[] = [
                "members" => explode("-", $relation),
                "deprecated" => false
            ];
        }
    }

    if (isset($_POST["sexual"])) {
        $sexual = true;
    } else {
        $sexual = false;
    }

    $data[] = [
        "id" => $id,
        "name" => $name,
        "water" => $water,
        "description" => null,
        "ponies" => $ponies,
        "usage" => null,
        "irl" => null,
        "image" => "",
        "usage_img" => "",
        "keywords" => [],
        "sexual" => $sexual
    ];

    file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/toys/toys.json", utf8_encode(json_encode($data)));
    header("Location: /-/toys/" . $id);
    die();
}

global $pagename;
$parts = explode("/", $pagename);
$data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/toys/toys.json"), true);

$selected = null;

if (isset($parts[1])) {
    $id = $parts[1];

    foreach ($data as $item) {
        if ($item["id"] === $id) {
            $selected = $item;
            break;
        }
    }

    if ($selected === null) {
        header("Location: /-/toys/?nf&id=" . $id);
        die();
    } else {
        $title = $selected["name"] . " · " . $title;
    }
}

require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc';
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/util/keywords.inc';

if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/toys/toys.json")) file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/toys/toys.json", "[]");

global $_PROFILE;
global $pagename;
$parts = explode("/", $pagename);

?>

<style>
    @media (max-width: 800px) {
        #toy-grid-img {
            display: block !important;
        }
    }

    @media (max-width: 900px) {
        #toy-grid-img2 {
            display: block !important;
        }
    }
</style>

    <script src="/assets/editor/fuse.js"></script>

    <br>
    <div class="container">
        <div id="<?= isset($parts[1]) ? "page-content" : "" ?>">
            <?php if (isset($_GET['nf'])): ?>
                <div class="alert alert-danger alert-dismissible">
                    <button onclick='window.history.pushState({"html":null,"pageTitle":document.title},"", "/-/toys/");' type="button" class="btn-close" data-bs-dismiss="alert" style="filter: none !important;"></button>
                    <b>Error: </b> The requested toy (<code><?= strip_tags($_GET['id'] ?? "-") ?></code>) was not found, it may have been deleted or has never existed.
                </div>
            <?php endif; ?>

            <?php if (isset($_GET['d'])): ?>
                <div class="alert alert-success alert-dismissible">
                    <button onclick='window.history.pushState({"html":null,"pageTitle":document.title},"", "/-/toys");' type="button" class="btn-close" data-bs-dismiss="alert" style="filter: none !important;"></button>
                    <b>Success: </b> The toy with ID <code><?= strip_tags($_GET['id'] ?? "-") ?></code> has been successfully deleted.
                </div>
            <?php endif; ?>

            <?php if (isset($parts[1])): ?>

                <h2>
                    <span style="vertical-align: middle;"><?= $selected["name"] ?></span>
                    <a href="/-/toys" class="small btn btn-outline-light" style="float:right;margin-top:5px;vertical-align:middle;opacity:1 !important; color:white;">Back</a>
                </h2>

                <p>
                    <a onclick="event.target.blur();" data-bs-toggle="modal" data-bs-target="#editor" href="#">Edit</a> ·
                    <?php if (!isset($selected["verified"])): ?><span class="badge bg-warning rounded-pill text-black">Unverified</span><?php endif; ?>
                    <?php if ($selected["water"] === "in"): ?>
                        <span style="" class="badge rounded-pill bg-primary">Underwater</span>
                    <?php elseif ($selected["water"] === "out"): ?>
                        <span style="background-color:#d63384;" class="badge rounded-pill">Outside of water</span>
                    <?php else: ?>
                        <span style="" class="badge rounded-pill bg-primary">Underwater</span>
                        <span style="background-color:#d63384;" class="badge rounded-pill">Outside of water</span>
                    <?php endif; ?>
                </p>

            <div id="toy-grid-img" style="display: grid; grid-template-columns: 1fr <?php if (isset($selected["usage_img"]) && trim($selected["usage_img"]) !== ""): ?>2fr<?php endif; ?> !important; grid-gap: 20px;">
                <?php if (isset($selected["usage_img"]) && trim($selected["usage_img"]) !== ""): ?>
                <div>
                    <img src="<?= $selected["usage_img"] ?>" style="width: 100%; max-height: 100vh;">
                </div>
                <?php endif; ?>
                <div>

                <?php if (isset($selected["description"]) && trim($selected["description"]) !== ""): ?>
                <?= replaceKeyWords(str_replace("\n", "<br>", strip_tags($selected["description"]))); ?>
            <?php else: ?>
                <p><i>No description provided for this toy. Enter edit mode to add a description to this toy.</i></p>
            <?php endif; ?>

            <hr>

                <div style="margin-top:10px;"></div>

                <div id="toy-grid-img2" style="display: grid; grid-template-columns: <?php if (isset($selected["usage_img"]) && $selected["usage_img"] !== ""): ?>3fr <?php if (isset($selected["image"]) && trim($selected["image"]) !== ""): ?>1fr<?php endif; ?><?php else: ?>6fr <?php if (isset($selected["image"]) && trim($selected["image"]) !== ""): ?>1fr<?php endif; ?><?php endif; ?> !important; grid-gap: 20px;"><div>
                <b>Usage:</b><br>
                <?php if (isset($selected["usage"]) && trim($selected["usage"]) !== ""): ?>
                <?php

                $lines = explode("\n", strip_tags($selected["usage"]));

                if (count($lines) > 1) echo("<ul>");

                foreach ($lines as $line) {
                    if (count($lines) > 1) echo("<li>");

                    $parts = explode(":", $line);

                    if (count($parts) > 1 && strlen($parts[0]) < 30) {
                        $p0 = $parts[0]; array_shift($parts);
                        echo(replaceKeyWords("<b>" . $p0 . ":</b>" . implode(":", $parts)));
                    } else {
                        echo(replaceKeyWords(implode(":", $parts)));
                    }

                    if (count($lines) > 1) echo("</li>");
                }

                if (count($lines) > 1) echo("</ul>");

                ?>
            <?php else: ?>
                <p><i>No usage provided for this toy. Enter edit mode to add usage information to this toy.</i></p>
            <?php endif; ?>
                    <div style="margin-top:10px;"></div>

                    <b>Instructions to obtain in real life:</b><br>
                    <?php if (isset($selected["irl"]) && trim($selected["irl"]) !== ""): ?>
                    <?= replaceKeyWords(strip_tags($selected["irl"])) ?>
            <?php else: ?>
                    <p><i><?php if (isset($selected["image"]) && $selected["image"] !== ""): ?>This toy is obtainable in real life, but no instructions are provided.<?php else: ?>This toy is not obtainable in real life.<?php endif; ?></i></p>
            <?php endif; ?>

                </div>
            <?php if (isset($selected["image"]) && trim($selected["image"]) !== ""): ?>
                <div>
                    <img src="<?= $selected["image"] ?>" style="width: 100%; max-height: 100vh;">
                </div>
            <?php endif; ?>
                </div>


            <hr>

                <h4>Similar toys</h4>
                <div class="row">
                    <?php

                    $names = [];
                    $currentName = $selected["name"];
                    $namesByDistance = [];

                    foreach ($data as $action) {
                        if ($action["name"] !== $currentName) $names[$action["name"]] = [
                            "id" => $action["id"],
                            "water" => $action["water"],
                            "ponies" => $action["ponies"],
                            "sexual" => $action["sexual"],
                            "description" => $action["description"]
                        ];
                    }

                    foreach ($names as $name => $data) {
                        $namesByDistance[] = [
                            "name" => $name,
                            "distance" => levenshtein($currentName, $name),
                            "id" => $data["id"],
                            "description" => $data["description"],
                            "water" => $data["water"],
                            "ponies" => $data["ponies"],
                            "sexual" => $data["sexual"]
                        ];
                    }

                    uasort($namesByDistance, function ($a, $b) use ($selected) {
                        return $a["distance"] - $b["distance"];
                    });

                    foreach ($namesByDistance as $item) {
                        echo("<!-- " . $currentName . " <-> " . $item["name"] . " => " . $item["distance"] . ") -->");
                    }

                    $index = 0;
                    foreach ($namesByDistance as $item): if ($index < 3):
                        ?>
                        <div class="col-md-4" style="margin-bottom:20px;">
                            <a class="linked-card" href="/-/toys/<?= $item["id"] ?>"><div class="card">
                                    <div class="card-body">
                                        <h4 class="card-title"><?= $item["name"] ?></h4>
                                        <p class="card-text">
                                            <!--
                            <?php

                                            $uniquePonies = [];

                                            foreach ($item["ponies"] as $ponies) {
                                                foreach ($ponies["members"] as $member) {
                                                    if (isset($uniquePonies[$member]) && !$uniquePonies[$member]) {
                                                        $uniquePonies[$member] = false;
                                                    } else {
                                                        $uniquePonies[$member] = $ponies["deprecated"];
                                                    }
                                                }
                                            }

                                            foreach ($uniquePonies as $name => $deprecated): if (!$deprecated): ?>
                            <span data-bs-toggle="tooltip" title="<?= getMemberWithoutSystem($name)["display_name"] ?? getMemberWithoutSystem($name)["display_name"] ?>" style="display: inline-block;">
                                <img src="/assets/uploads/pt-<?= getMemberWithoutSystem($name)["name"] ?>.png" style="width:32px;">
                            </span>
                            <?php endif; endforeach; ?>
                            <?php foreach ($uniquePonies as $name => $deprecated): if ($deprecated): ?>
                                <span data-bs-toggle="tooltip" data-bs-html="true" title="<i><?= strip_tags(getMemberWithoutSystem($name)["display_name"] ?? getMemberWithoutSystem($name)["name"]) ?></i>" style="opacity:.5;display: inline-block;">
                                <img src="/assets/uploads/pt-<?= getMemberWithoutSystem($name)["name"] ?>.png" style="width:32px;">
                            </span>
                            <?php endif; endforeach; ?>-->
                                            <?= strlen(strip_tags($item["description"])) > 100 ? substr(strip_tags($item["description"]), 0, 100) . "…" : strip_tags($item["description"]) ?>
                                        </p>
                                        <?php if ($item["water"] === "in"): ?>
                                            <span style="" class="badge rounded-pill bg-primary">Underwater</span>
                                        <?php elseif ($item["water"] === "out"): ?>
                                            <span style="background-color:#d63384;" class="badge rounded-pill">Outside of water</span>
                                        <?php elseif ($item["water"] === "playground"): ?>
                                            <span class="badge rounded-pill" style="background-color:#20c997;">In playground</span>
                                        <?php else: ?>
                                            <span style="" class="badge rounded-pill bg-primary">Underwater</span>
                                            <span style="background-color:#d63384;" class="badge rounded-pill">Outside of water</span>
                                        <?php endif; ?>
                                    </div>
                                </div></a>
                        </div>
                        <?php $index++; endif; endforeach; ?>
                </div>

                <div class="modal fade" id="editor">
                    <div class="modal-dialog modal-xl">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h4 class="modal-title">Edit toy</h4>
                                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                            </div>

                            <div class="modal-body">
                                <form method="post" style="display:inline;">
                                    <input type="text" placeholder="Toy name" name="name" class="form-control" style="color:white;background:#111;border-color:#222;margin-bottom:10px;" value="<?= str_replace('"', '&quot;', $selected["name"]) ?>">
                                    <select name="water" class="form-select" style='color:white;background-color:#111;border-color:#222;background-image:url("data:image/svg+xml,%3csvg xmlns=&apos;http://www.w3.org/2000/svg&apos; viewBox=&apos;0 0 16 16&apos;%3e%3cpath fill=&apos;none&apos; stroke=&apos;%23ffffff&apos; stroke-linecap=&apos;round&apos; stroke-linejoin=&apos;round&apos; stroke-width=&apos;2&apos; d=&apos;M2 5l6 6 6-6&apos;/%3e%3c/svg%3e");'>
                                        <option value="0" <?= $selected["water"] === "out" ? "selected" : "" ?>>Usable outside the water</option>
                                        <option value="1" <?= $selected["water"] === "in" ? "selected" : "" ?>>Usable inside the water</option>
                                        <option value="2" <?= $selected["water"] === "both" ? "selected" : "" ?>>Usable both inside and outside</option>
                                    </select>

                                    <label style="margin-left:5px; display: none;">
                                        <input <?= ($selected["sexual"] ?? false) ? "checked" : "" ?> type="checkbox" name="sexual">
                                        Sexual toy
                                    </label>

                                    <label style="margin-left:5px; margin-top: 12px;">
                                        <input class="form-check-input" <?= ($selected["verified"] ?? false) ? "checked" : "" ?> <?= $_PROFILE['login'] !== "raindrops" ? "disabled" : "" ?> type="checkbox" name="verified">
                                        Mark as verified
                                    </label><br>

                                    <label style="margin-left:5px; display: none;">
                                        <input <?= ($selected["untested"] ?? false) ? "checked" : "" ?> type="checkbox" name="untested">
                                        Mark as untested
                                    </label>

                                    <hr>

                                    <textarea rows="5" name="description" class="form-control" style="resize: none;color:white;background:#111;border-color:#222;margin-bottom:10px;" placeholder="Description"><?= strip_tags($selected["description"] ?? "") ?></textarea>

                                    <textarea rows="5" placeholder="Toy usage" name="usage" class="form-control" style="resize: none;color:white;background:#111;border-color:#222;margin-bottom:10px;"><?= strip_tags($selected["usage"] ?? "") ?></textarea>

                                    <hr>

                                    <input type="text" placeholder="Keywords (comma-separated)" name="keywords" class="form-control" style="color:white;background:#111;border-color:#222;margin-bottom:10px;" value="<?= str_replace('"', '&quot;', implode(",", $selected["keywords"] ?? [])) ?>">

                                    <input type="text" placeholder="Instructions to obtain IRL" name="irl" class="form-control" style="color:white;background:#111;border-color:#222;margin-bottom:10px;" value="<?= str_replace('"', '&quot;', $selected["irl"] ?? "") ?>">

                                    <input type="text" placeholder="URL to IRL image" name="image" class="form-control" style="color:white;background:#111;border-color:#222;margin-bottom:10px;" value="<?= str_replace('"', '&quot;', $selected["image"] ?? "") ?>">

                                    <input type="text" placeholder="URL to usage image" name="usage_img" class="form-control" style="color:white;background:#111;border-color:#222;" value="<?= str_replace('"', '&quot;', $selected["usage_img"] ?? "") ?>">

                                    <br>
                                    <input type="hidden" name="updateAction">
                                    <input type="hidden" name="action" value="<?= $selected["id"] ?>">
                                    <input type="submit" class="btn btn-primary" value="Save">
                                </form>
                                <form method="post" style="display:inline;">
                                    <input type="hidden" name="deleteAction">
                                    <input type="hidden" name="action" value="<?= $selected["id"] ?>">
                                    <input type="submit" class="btn btn-danger" value="Delete">
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div></div>

            <?php else: ?>

                <h2>Toys database</h2>
                <?php $complete = count(array_filter($data, function ($i) {
                    return (isset($i["description"]) && trim($i["description"]) === "") || !isset($i["description"]);
                })); ?>
                <p><?= count($data) ?> toys<?php if ($complete > 0): ?> (<?= $complete ?> incomplete)<?php endif; ?></p>

            <input type="text" placeholder="Search for a toy..." class="form-control" style="margin-bottom:15px;color:white;background:#111;border-color:#222;" onchange="search();" onkeydown="search();" onkeyup="search();" id="search">

                <div id="list">
                    <div class="list-group">
                        <?php

                        $init = [];
                        foreach ($data as $value) {
                            $init[$value["name"]] = $value;
                        }

                        ksort($init);

                        $sorted = array_values($init);

                        foreach ($sorted as $item): ?>
                            <a href="/-/toys/<?= $item["id"] ?>" id="action-<?= $item["id"] ?>" style="display:grid;grid-template-columns: 1fr 0.2fr;" class="list-group-item list-group-item-action action-listing">
                                <div>
                                    <span class="<?= trim($item["description"]) === "" ? "text-danger" : "" ?>"><?= $item["name"] ?></span>
                                    <?php if (!isset($item["verified"])): ?><span class="badge bg-warning rounded-pill text-black">Unverified</span><?php endif; ?>
                                </div>
                            </a>
                        <?php endforeach; ?>
                    </div>
                </div>

                <div id="search-results" class="list-group"></div>

                <div id="page-content">
                    <hr>
                    <p>Not finding what you are looking for? <a onclick="event.target.blur(); document.getElementById('creator-title').focus();" href="#" data-bs-toggle="modal" data-bs-target="#creator">Add a toy.</a></p>
                </div>

                <script>
                    window.actions = JSON.parse(atob(`<?= base64_encode(json_encode(array_values(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/toys/toys.json"), true)))) ?>`));
                </script>

                <div class="modal fade" id="creator">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h4 class="modal-title">Add a new toy</h4>
                                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                            </div>

                            <div class="modal-body">
                                <form method="post">
                                    <input id="creator-title" type="text" placeholder="Toy name" name="name" class="form-control" style="color:white;background:#111;border-color:#222;margin-bottom:10px;">
                                    <select name="water" class="form-select" style='color:white;background-color:#111;border-color:#222;background-image:url("data:image/svg+xml,%3csvg xmlns=&apos;http://www.w3.org/2000/svg&apos; viewBox=&apos;0 0 16 16&apos;%3e%3cpath fill=&apos;none&apos; stroke=&apos;%23ffffff&apos; stroke-linecap=&apos;round&apos; stroke-linejoin=&apos;round&apos; stroke-width=&apos;2&apos; d=&apos;M2 5l6 6 6-6&apos;/%3e%3c/svg%3e");'>
                                        <option value="0" selected>Usable outside of the water</option>
                                        <option value="1">Usable inside of the water</option>
                                        <option value="2">Usable both inside and outside</option>
                                        <option value="3">Usable in a playground</option>
                                    </select>

                                    <p style="margin-top:10px;">You can add additional data (description, how to use) after adding the toy.</p>
                                    <input type="hidden" name="createAction">
                                    <input type="submit" class="btn btn-primary" value="Add">
                                </form>
                            </div>
                        </div>
                    </div>
                </div>

            <?php endif; ?>
        </div>
    </div>

    <!--suppress JSUnresolvedFunction -->
    <script>
        Array.from(document.getElementsByClassName("checkbox-input")).forEach((el) => {
            el.onchange = () => {
                let parent = el.parentElement;

                if (el.checked) {
                    parent.classList.add("checked");
                } else {
                    parent.classList.remove("checked");
                }
            }
        });

        const fuse = new Fuse(window.actions, {
            includeScore: true,
            keys: [
                {
                    name: 'name',
                    weight: 1
                },
                {
                    name: 'description',
                    weight: 1
                },
                {
                    name: 'example',
                    weight: 0.7
                },
                {
                    name: 'irl',
                    weight: 0.5
                }
            ]
        })

        function search() {
            let query = document.getElementById("search").value;
            let results = fuse.search(query).map((i) => {
                return {
                    id: i.item.id,
                    score: i.score
                };
            });

            let unfiltered = results;

            results = results.filter((i) => {
                return i.score < 0.7;
            });

            console.log("Before:", unfiltered, "After:", results);

            document.getElementById("list").style.display = "none";
            document.getElementById("search-results").style.display = "block";
            document.getElementById("search-results").innerHTML = "";

            for (let result of results) {
                document.getElementById("search-results").innerHTML += document.getElementById("action-" + result.id).outerHTML;
            }

            console.log(results);

            if (query.trim() === "") {
                document.getElementById("list").style.display = "block";
                document.getElementById("search-results").style.display = "none";
            }
        }

        function changeMixed() {
            let value = document.getElementById("editor-type").value;
            console.log(value);

            if (value === "2") {
                Array.from(document.getElementsByClassName("creator-relation")).forEach((el) => {
                    el.classList.add("mixed");
                });
            } else {
                Array.from(document.getElementsByClassName("creator-relation")).forEach((el) => {
                    el.classList.remove("mixed");
                });
            }
        }
    </script>

    <style>
        .modal-header {
            border-bottom: 1px solid #353738;
        }

        .modal-content {
            border: 1px solid rgba(255, 255, 255, .2);
            background-color: #111;
        }

        .btn-close {
            filter: invert(1);
        }

        .creator-relation {
            border-radius: 10px;
            padding: 5px 10px;
            opacity: .5;
        }

        .creator-relation.checked {
            background-color: rgba(255, 255, 255, .1);
            opacity: 1;
        }

        .creator-relation:hover {
            background-color: rgba(255, 255, 255, .1);
        }

        .creator-relation.checked:hover {
            background-color: rgba(255, 255, 255, .25) !important;
        }

        .creator-relation.checked .deprecated {
            display: block !important;
        }

        .creator-relation.mixed.checked .sexual {
            display: block !important;
        }

        .list-group-item {
            color: #fff;
            background-color: #222;
            border: 1px solid rgba(255, 255, 255, .125);
        }

        .list-group-item.disabled {
            color: #fff;
            background-color: #222;
            border-color: rgba(255, 255, 255, .125);
            opacity: .75;
        }

        .list-group-item:hover {
            background-color: #252525;
            color: #ddd;
        }

        .list-group-item:active, .list-group-item:focus {
            background-color: #272727;
            color: #bbb;
        }

        @media (max-width: 991px) {
            .action-listing {
                grid-template-columns: 1fr !important;
                text-align: center !important;
            }

            .action-listing > * {
                margin-bottom: 10px;
                text-align: center !important;
            }

            .action-listing > *:nth-last-child(1) {
                margin-bottom: 0 !important;
            }

            .action-listing img {
                width: 32px !important;
            }
        }
    </style>

<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/footer.inc'; ?>