<template>
    <div
        v-if="site"
        class="content site"
    >
        <div class="content-inner">
            <div class="header">
                <a
                    v-if="site.url"
                    :href="site.url"
                    target="_blank"
                    rel="noopener noreferrer"
                    class="title"
                >
                    <object
                        :data="`/img/logos/${site.network.slug}/${site.slug}.png`"
                        :title="site.name"
                        type="image/png"
                        class="logo"
                    ><h2>{{ site.name }}</h2></object>

                    <Icon
                        icon="new-tab"
                        class="icon-href"
                    />
                </a>

                <span class="link">
                    <span class="networklogo-container">
                        Part of
                        <a
                            :href="`/network/${site.network.slug}`"
                            class="networklogo-link"
                        >
                            <object
                                :data="`/img/logos/${site.network.slug}/network.png`"
                                :title="site.network.name"
                                type="image/png"
                                class="networklogo"
                            >{{ site.network.name }}</object>
                        </a>
                    </span>
                </span>
            </div>

            <p class="description">{{ site.description }}</p>

            <h3 class="heading">Latest releases</h3>

            <ul class="nolist scenes">
                <li
                    v-for="release in releases"
                    :key="`release-${release.id}`"
                >
                    <ReleaseTile :release="release" />
                </li>
            </ul>
        </div>
    </div>
</template>

<script>
import ReleaseTile from '../tile/release.vue';

async function mounted() {
    [this.site] = await this.$store.dispatch('fetchSites', this.$route.params.siteSlug);
    this.releases = await this.$store.dispatch('fetchSiteReleases', this.$route.params.siteSlug);

    this.pageTitle = this.site.name;
}

export default {
    components: {
        ReleaseTile,
    },
    data() {
        return {
            site: null,
            releases: null,
            pageTitle: null,
        };
    },
    mounted,
};
</script>

<style lang="scss" scoped>
@import 'theme';

.header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
}

.title {
    display: inline-flex;
    align-items: top;
    margin: 0 1rem 0 0;

    &:hover .icon {
        fill: $primary;
    }
}

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

.link {
    display: flex;
    flex-shrink: 0;
    flex-direction: column;
    align-items: flex-end;
}

.logo {
    width: 15rem;
    max-height: 8rem;
    object-fit: contain;
    margin: 0 .5rem 1rem 0;
}

.networklogo-container {
    display: flex;
    align-items: center;
}

.networklogo {
    color: $text;
    width: 15rem;
    max-height: 6rem;
    font-weight: bold;
    object-fit: contain;
    object-position: 100% 0;
    margin: 0 0 0 .5rem;
}

.sites,
.scenes {
    display: grid;
    grid-gap: 1rem;
    margin: 0 0 1rem 0;
}

.sites {
    grid-template-columns: repeat(auto-fit, 15rem);
}
</style>
