<template>
  <LayoutContainer v-intersect="onIntersect">
    <v-row>
      <v-col cols="12">
        <div class="banner-container">
          <img
            :src="imageSrc"
            :alt="imageAlt"
            :class="['cover-image', reverseImage ? 'reverse' : '']"
          />

          <div v-if="logoSrc" class="details-square">
            <v-row>
              <div class="content-row">
                <img
                  v-if="iconSrc !== null"
                  :src="iconSrc"
                  alt="Icône instruments de musique"
                  class="custom-icon"
                />
                <p class="description">
                  {{ squareText }}
                </p>
              </div>
            </v-row>
          </div>

          <div
            v-if="logoSrc"
            :class="'logo-square' + (logoAltTheme ? ' alt-theme' : '')"
          >
            <img :src="logoSrc" :alt="logoAlt" />
          </div>

          <div class="image-text mt-12">
            <slot name="watermark" />
          </div>
        </div>
      </v-col>
    </v-row>
  </LayoutContainer>
</template>

<script setup lang="ts">
import type { PropType } from 'vue'
import { useLayoutStore } from '~/stores/layoutStore'

defineProps({
  imageSrc: {
    type: String,
    required: true,
  },
  imageAlt: {
    type: String,
    default: '',
  },
  squareText: {
    type: String,
    default:
      "École de musique, d'art, de danse, de cirque, conservatoires et MJC",
  },
  logoSrc: {
    type: String as PropType<string | null>,
    required: false,
    default: null,
  },
  logoAlt: {
    type: String,
    required: false,
    default: '',
  },
  logoAltTheme: {
    type: Boolean,
    default: false,
  },
  iconSrc: {
    type: String as PropType<string | null>,
    required: false,
    default: null,
  },
  reverseImage: {
    type: Boolean,
    default: false,
  },
})

const layoutStore = useLayoutStore()
const onIntersect = (isIntersecting: boolean) => {
  layoutStore.setIsBannerVisible(isIntersecting)
}
</script>

<style scoped lang="scss">
.banner-container {
  position: relative;
  overflow: hidden;
  min-height: 400px;
  max-height: 400px;

  .image-text {
    position: absolute;
    top: 40px;
    left: 20px;
    color: white;
    font-size: 3rem;
    width: 30rem;
    font-style: italic;
    font-weight: 300;
    line-height: 40px;
  }

  @media (max-width: 600px) {
    min-height: 0;
  }
}

.cover-image {
  width: 100%;
  min-height: 400px;
  max-height: 400px;
  object-fit: cover;
  object-position: center var(--banner-center-image);
  transition: transform 0.2s;
  margin: 0 auto;

  @media (max-width: 600px) {
    min-height: 235px;
  }
}

.reverse {
  transform: scaleX(-1);
}

.custom-icon {
  width: 3rem;
  height: 3rem;
  margin-top: 0.5rem;
}

.details-square {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 13rem;
  height: 10rem;
  background: var(--secondary-color);

  @media (max-width: 600px) {
    width: 50%;
  }
}

.logo-square {
  position: absolute;
  bottom: 0;
  right: 13rem;
  width: 13rem;
  height: 10rem;

  img {
    width: 100%;
    margin-top: 2.5rem;
  }

  @media (max-width: 600px) {
    right: 50%;
    width: 50%;
  }
}
.logo-square:not(.alt-theme) {
  background: var(--primary-color);
}

.description {
  color: var(--on-secondary-color);
  font-weight: 300;
  font-size: 0.8rem;
  text-align: center;
  display: flex;
  align-items: center;
  margin: 0.5rem 2rem 1rem;
}

.content-row {
  margin-top: 2rem;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
  height: 100%;
}

.icon {
  margin-left: 2rem;
  margin-right: 2rem;
}
</style>
