<script lang="ts" context="module">
    import type {TableItem} from "../helperTypes/TableTypes";
    import { tableItems } from "./GlobalVariablesAndHelperFunctions.svelte"

    export function AddAnimeServiceToTable(animeItem: TableItem) {
        tableItems.update((table) => {
            if (table.length === 0) {
                table.push(animeItem)
            } else {
                for (const [index, tableItem] of table.entries()) {
                    if(tableItem.service === animeItem.service) {
                        table[index] = animeItem
                        return table
                    }
                }
                table.push(animeItem)
            }
            return table
        })
    }
</script>