<template>
	<div
		v-if="user"
		class="user"
	>
		<div class="header">
			<h2 class="username">{{ user.username }}</h2>
		</div>

		<section
			v-if="user.stashes?.length > 0"
			class="section"
		>
			<h3 class="heading">Stashes</h3>

			<ul class="stashes nolist">
				<li
					v-for="stash in user.stashes"
					:key="stash.id"
					class="stash"
				>
					<h4 class="stash-name">{{ stash.name }}</h4>

					<ul
						v-if="stash.scenes?.length > 0"
						class="stash-section stash-scenes nolist"
					>
						<li
							v-for="item in stash.scenes"
							:key="item.id"
						><Scene :release="item.scene" /></li>
					</ul>

					<ul
						v-if="stash.actors?.length > 0"
						class="stash-section stash-actors nolist"
					>
						<li
							v-for="item in stash.actors"
							:key="item.id"
						><Actor :actor="item.actor" /></li>
					</ul>
				</li>
			</ul>
		</section>
	</div>
</template>

<script>
import Actor from '../actors/tile.vue';
import Scene from '../releases/scene-tile.vue';

async function mounted() {
	this.user = await this.$store.dispatch('fetchUser', this.$route.params.username);
	this.pageTitle = this.user?.username;
}

export default {
	components: {
		Actor,
		Scene,
	},
	data() {
		return {
			user: this.$route.params.username === this.$store.state.auth.user?.username
				? this.$store.state.auth.user
				: null,
			pageTitle: null,
		};
	},
	mounted,
};
</script>

<style lang="scss" scoped>
.header {
	padding: .5rem 1rem;
	background: var(--profile);
}

.username {
	margin: 0;
	font-size: 1.5rem;
	color: var(--text-light);
}

.section {
	padding: 1rem;
	margin: 0 0 1rem 0;
}

.heading {
	color: var(--primary);
}

.stash {
	width: 100%;
	background: var(--background);
	margin: 0 0 1rem 0;
	box-shadow: 0 0 3px var(--shadow-weak);
}

.stash-name {
	color: var(--shadow-strong);
	padding: 1rem .5rem 0 .5rem;
	margin: 0;
}

.stash-section {
	padding: 1rem .5rem;

	&:not(:last-child) {
		border-bottom: solid 1px var(--shadow-hint);
	}
}

.stash-actors,
.stash-scenes {
    display: grid;
    flex-grow: 1;
    grid-gap: .5rem;
	box-sizing: border-box;
}

.stash-actors {
    grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
}

.stash-scenes {
    grid-template-columns: repeat(auto-fill, minmax(22rem, 1fr));
}
</style>
