<script setup lang="ts">
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import OrderLine from '@/components/OrderLine.vue'
import type { CartOnWay } from '@/types/overview'

const props = defineProps<{ carts: CartOnWay[] }>()
const { t } = useI18n()

const active = computed(() => props.carts.length > 0)
const partsOf = (c: CartOnWay) => c.orders.reduce((s, o) => s + o.qty, 0)
</script>

<template>
  <div class="lane" :class="{ active }">
    <span class="conn"></span>
    <span class="lc" :class="active ? 'on' : 'off'">
      {{ active ? t('lane.wagen', { n: carts.length }) : t('lane.none') }}
    </span>
    <div v-for="cart in carts" :key="cart.cartId" class="cart">
      <div class="chd">
        <span class="cid">{{ cart.cartId }}</span>
        <span class="cp">{{ t('lane.parts', { n: partsOf(cart) }) }}</span>
      </div>
      <div class="cbody">
        <OrderLine v-for="(o, i) in cart.orders" :key="i" :order-no="o.orderNo" :qty="o.qty" :color-index="o.colorIndex" />
      </div>
      <div class="cfoot">{{ t('lane.ovenIn', { n: cart.etaMin }) }}</div>
    </div>
  </div>
</template>

<style scoped>
.lane {
  position: relative;
  min-height: 132px;
  max-height: 236px;
  overflow-y: auto;
  padding-top: 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
}
.conn {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  transform: translateX(-50%);
  z-index: 0;
  background: repeating-linear-gradient(180deg, var(--way) 0 3px, transparent 3px 11px);
  background-size: 2px 11px;
  opacity: 0.3;
}
.lane.active .conn {
  opacity: 0.95;
  animation: flowdown 1.05s linear infinite;
}
.lc {
  position: absolute;
  left: 50%;
  top: 3px;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-size: 0.53rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  background: var(--ground);
  padding: 0 5px;
  z-index: 3;
}
.lc.on {
  color: var(--way);
}
.lc.off {
  color: var(--ink-faint);
}
.cart {
  position: relative;
  z-index: 2;
  border: 1px solid var(--line-2);
  border-top: 2px solid var(--way);
  border-radius: var(--r);
  background: var(--panel);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}
.chd {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  background: var(--panel-3);
  border-bottom: 1px solid var(--line);
}
.cid {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 800;
}
.cp {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--ink-dim);
}
.cbody {
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cfoot {
  padding: 4px 8px;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.62rem;
  color: var(--way);
}
</style>
