<script lang="ts">
	/* eslint svelte/no-at-html-tags: "off" */

	import SettingHint from '$lib/Settings/SettingHint.svelte';
	import Attributions from '$lib/Settings/Attributions.svelte';
	import { env } from '$env/dynamic/public';
	import HeadTitle from '$lib/HeadTitle.svelte';
	import Display from '$lib/Settings/Categories/Display.svelte';
	import Calculation from '$lib/Settings/Categories/Calculation.svelte';
	import Debug from '$lib/Settings/Categories/Debug.svelte';
	import Cache from '$lib/Settings/Categories/Cache.svelte';
	import Category from '$lib/Settings/Category.svelte';

	export let data;

	// const pruneUnresolved = async () => {
	// 	const unresolved = await chapterDatabase.chapters.where('chapters').equals(-1).toArray();
	// 	const ids = unresolved.map((m) => m.id);

	// 	manga.set('');
	// 	anime.set('');
	// 	await chapterDatabase.chapters.bulkDelete(ids);
	// };
</script>

<HeadTitle route="Settings" path="/settings" />

<blockquote>
	Have feedback or suggestions? Send a private message to
	<a href="https://anilist.co/user/fuwn" target="_blank">@fuwn</a> on AniList!
</blockquote>

{#if data.user === undefined}
	Please log in to modify settings.
{:else}
	<Category title="RSS Feeds" id="feeds">
		<button
			on:click={() =>
				navigator.clipboard.writeText(
					`https://${
						env.PUBLIC_ANILIST_REDIRECT_URI?.includes('192.168') ? '192.168.1.60:5173' : 'due.moe'
					}/feeds/activity-notifications?token=${data.user.accessToken}&refresh=${
						data.user.refreshToken
					}`
				)}
		>
			Copy to clipboard
		</button>
		Your AniList notifications RSS feed URL
		<SettingHint lineBreak>
			This <a href="https://en.wikipedia.org/wiki/RSS" target="_blank">RSS</a> feed will return the
			currently logged in AniList profile's notifications for remote consumption.
			<br />
			Do not share this link with <b>anyone</b>!
		</SettingHint>
	</Category>
	<Category title="Display"><Display /></Category>
	<Category title="Calculation"><Calculation /></Category>
	<Category title="Cache"><Cache /></Category>
	<Category id="debug">
		<summary
			>Debug<button class="smaller-button button-badge badge-info">{data.commit.slice(0, 7)}</button
			></summary
		>

		<Debug />
	</Category>
	<Category title="Attributions" open={false}><Attributions /></Category>
{/if}
