<template>
  <div class="layout">
    <header class="header">
      <div class="header__container">
        <Icon class="cursor-pointer w-6 h-6" name="lucide:arrow-left" @click="previewStep" />

        <h3>
          Шаг {{ currentCheckoutStep?.step }} из {{ checkoutSteps?.length }}
          &nbsp;&bull;&nbsp;
          {{ t(`checkoutSteps.${currentCheckoutStep?.title}`) }}
        </h3>
      </div>
    </header>

    <main class="main" :style="showFooter ? 'margin-bottom: 54px' : 'margin-bottom: 0'">
      <UContainer class="container">
        <slot />
      </UContainer>
    </main>

    <footer class="footer" :class="{ 'footer--hidden': !showFooter }" />
  </div>
</template>

<script setup lang="ts">
import { useMediaQuery } from '@vueuse/core'
import { useCheckout } from '~/composables/useCheckout'

const route = useRoute()
const { t } = useI18n()
const isMobile = useMediaQuery('(max-width: 1280px)', {
  ssrWidth: 768,
})
const showFooter = computed(() => route.path !== '/checkout/delivery' && isMobile.value)

const { previewStep, currentCheckoutStep, checkoutSteps } = useCheckout()
</script>

<style lang="scss" scoped>
.layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.container {
  --ui-container: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0;
}

.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: 54px;

  &__container {
    height: 100%;
    display: flex;
    flex-direction: row;
    align-items: center;
    text-align: center;
    padding: 0 16px;
  }

  h3 {
    flex: auto;
  }
}

.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: 70px;
  background-color: #0f172b;

  &--hidden {
    display: none;
  }
}

.main {
  flex: 1;
  margin-top: 54px;
  margin-bottom: 64px;

  &__hide-footer {
    margin-bottom: 0 !important;
  }
}
</style>
