<template>
	<div class="actor">
		<div class="actor-header">
			<h2 class="header-name">
				<span v-if="actor.entity">{{ actor.name }} ({{ actor.entity.name }})</span>
				<span v-else>{{ actor.name }}</span>

				<Gender
					:gender="actor.gender"
					class="header-gender"
				/>
			</h2>

			<li
				v-if="actor.aliases?.length"
				class="bio-item"
			>
				<dfn class="bio-label">Also known as</dfn>
				<span class="bio-value">
					<span
						v-for="alias in actor.aliases"
						:key="`alias-${alias.id}`"
						class="alias"
					>{{ alias.name }}</span>
				</span>
			</li>

			<Heart
				domain="actors"
				:item="actor"
				class="light"
			/>
		</div>

		<div class="content">
			<Bio :actor="actor" />

			<div
				class="photos nobar"
				:class="{ 'has-avatar': actor.avatar, 'has-photos': actor.avatar ? photos.length > 1 : photos.length > 0 }"
			>
				<img
					v-for="photo in photos"
					:key="`photo-${photo.id}`"
					:src="getPath(photo, 'thumbnail')"
					:width="photo.width"
					:height="photo.height"
					:style="{ 'background-image': `url('${getPath(photo, 'lazy')}')` }"
					:title="photo.credit && `© ${photo.credit}`"
					loading="lazy"
					class="photo"
					:class="{ avatar: photo.isAvatar }"
				>
			</div>

			<Scenes />
		</div>
	</div>
</template>

<script setup>
import { inject } from 'vue';

import getPath from '#/src/get-path.js';

import Bio from '#/components/actors/bio.vue';
import Gender from '#/components/actors/gender.vue';
import Scenes from '#/components/scenes/scenes.vue';
import Heart from '#/components/stashes/heart.vue';

const pageContext = inject('pageContext');
const { pageProps } = pageContext;
const { actor } = pageProps;

const photos = [
	actor.avatar && {
		...actor.avatar,
		isAvatar: true,
	},
	...actor.photos,
].filter(Boolean);
</script>

<style scoped>
.actor {
	display: flex;
	flex-direction: column;
	flex-grow: 1;
	position: relative;
}

.actor-header {
	width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
	position: sticky;
	top: 0;
	z-index: 2;
    color: var(--highlight-strong-30);
    background: var(--grey-dark-40);
}

.header-name {
    padding: .5rem 1rem;
    margin: 0;
    display: inline-flex;
    justify-content: space-between;
    flex-shrink: 0;
}

.header-social {
    overflow: hidden;
    white-space: nowrap;
    margin: 0 1rem 0 0;
}

.content {
	display: flex;
	flex-direction: column;
	flex-grow: 1;
	/* overflow-y: auto; */
}

.bookmarks {
	margin-right: .5rem;
}

.photos {
	display: flex;
	gap: 0.5rem;
	padding: .5rem;
	border-bottom: solid 1px var(--shadow-weak-40);
	background: var(--background-base-10);
	overflow-x: auto;

	&:not(.has-photos) {
		display: none;
	}
}

.photo {
	height: 14rem;
	width: auto;
	object-fit: cover;
	object-position: 50% 0;
	background-size: cover;
	background-position: center;
	box-shadow: 0 0px 3px var(--shadow-weak-30);

	&.avatar {
		display: none;
	}
}

@media(--compact) {
	.photos.has-avatar {
		display: flex;
	}

	.photo.avatar {
		display: inline-block;
	}
}

@media(--small) {
	.photo {
		height: 10rem;
	}
}
</style>
