<template>
  <div class="p-fill-order">
    <h3 class="ptc-title">Fill Order</h3>
    <component :is="Component" @go="go" />
  </div>
</template>

<script lang="ts">
import { defineComponent, onUnmounted } from 'vue'
import { initProducts } from './store'

export default defineComponent({
  name: 'FillOrder',
  beforeRouteEnter(to, from, next) {
    initProducts().then(next)
  },
})
</script>

<script setup lang="ts">
import { ref, computed, watch } from 'vue'
import { useRoute } from 'vue-router'
import StepOne from './StepOne.vue'
import StepTwo from './StepTwo.vue'
import StepThree from './StepThree.vue'
import { state, resetState } from './store'

const step = ref(0)
const Component = computed(() => [StepOne, StepTwo, StepThree][step.value])
const { from, invitee } = useRoute().query as any

state.form.from = from
state.form.invitor = invitee

// 此处不直接传入resetState是有必要的，否则resetState在整个应用生命周期只会执行一次
onUnmounted(() => resetState())

watch(step, () => window.scrollTo(0, 0))

function go(delta = 1) {
  step.value += delta
}
</script>

<style lang="scss">
.p-fill-order {
  background: #f7f7f7;

  .detail {
    display: flex;
    align-items: flex-end;
    .s1,
    .s2 {
      font-size: 40px;
      font-weight: bold;
      color: #1a1a1a;
    }
    .s2 {
      margin: 0 20px 0 48px;
    }
    .s3 {
      font-size: 28px;
      color: #1a1a1a;
    }
    .s4 {
      margin-left: auto;
      font-size: 32px;
      font-weight: bold;
      color: $primary-color;
    }
  }
}
</style>
