<script setup lang="ts">
import emptyImage from './image/no-data.png'
import { formatTimezone } from '@/utils/tools'

const props = defineProps({
  data: Object
})

const activeNames = ref<number[]>([])

const containerStatusData: any = ref([])
watch(
  () => props.data,
  (newVal) => {
    if (newVal) {
      containerStatusData.value = newVal
      if (containerStatusData.value.length === 1) {
        activeNames.value = [0]
      }
    } else {
      containerStatusData.value = []
    }
  },
  {
    immediate: true,
    deep: true
  }
)
</script>

<template>
  <div class="container-status">
    <el-collapse class="container" v-if="containerStatusData.length !== 0" v-model="activeNames">
      <el-collapse-item
        :title="containers.label"
        v-for="(containers, name) in containerStatusData"
        :key="name"
        :name="name"
      >
        <template #title>
          <div class="title">
            Container <span>{{ containers.label }}</span>
          </div>
        </template>
        <div class="step-item" v-for="(item, index) in containers.content" :key="item.title">
          <div class="step-data">
            <div class="step-dot-icon"></div>
            <div class="info">
              <div class="left-info">
                <div class="title">{{ item.title }}</div>
                <div class="date">{{ formatTimezone(item.date, item.timezone) }}</div>
              </div>
              <div class="right-country">{{ item.country }}</div>
            </div>
          </div>
          <div class="line" v-if="index + 1 !== containers.content.length"></div>
        </div>
      </el-collapse-item>
    </el-collapse>
    <div v-else class="empty-content" style="">
      <el-image :src="emptyImage" alt="empty"></el-image>
      <div class="empty-text" style="">No data</div>
    </div>
    <div class="footer">
      Tracking on carrier website:
      <a href="http://www.rcjgroup.com/" target="_blank" class="link">http://www.rcjgroup.com/</a>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.container-status {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: auto;
  .container {
    height: 394px;
    padding-bottom: 8px;
    overflow: auto;
  }
  .empty-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 394px;
    .el-image {
      width: 200px;
      height: 200px;
      margin-top: 20px;
      object-fit: cover;
    }
    .empty-text {
      margin-top: 8px;
      color: #b5b9bf;
    }
  }
  .footer {
    line-height: 38px;
    color: #999;
    font-size: 12px;
    text-align: center;
    border-top: 1px solid var(--color-border);
    overflow: hidden;
    .link {
      text-decoration: none;
      color: var(--color-theme);
    }
  }
}
</style>
<style lang="scss">
.container-status {
  .el-collapse {
    height: auto;
    border-bottom: 0;
  }
  .el-collapse-item__content {
    padding: 30px 16px 38px;
    border-top: 1px solid var(--color-border);
  }
  .el-collapse-item__header {
    height: 40px;
    padding-left: 16px;
    padding-right: 8px;
    line-height: 50px;
    & > .title {
      font-size: 16px;
      span {
        margin-left: 4px;
        font-weight: 700;
        color: var(--color-neutral-1);
      }
    }
  }
  .step-data {
    display: flex;
    gap: 8px;
    height: 8px;
    width: 100%;
    .step-dot-icon {
      height: 8px;
      width: 8px;
      background-color: var(--color-neutral-1);
      border-radius: 50%;
    }
    .info {
      flex: 1;
      display: flex;
      height: 52px;
      margin-top: -22px;
      background-color: var(--color-table-header-bg);
      border: 1px solid var(--color-border);
      border-radius: 6px;
      color: var(--color-neutral-1);
      .left-info {
        flex: 1;
        display: flex;
        flex-direction: column;
        padding: 8px 10px;
        border-right: 1px solid var(--color-border);
        .title {
          font-size: 14px;
          line-height: 18px;
          font-weight: 700;
        }
        .date {
          font-size: 12px;
        }
      }
      .right-country {
        width: 94px;
        padding: 0 24px;
        line-height: 52px;
        font-weight: 700;
      }
    }
  }
  .line {
    height: 60px;
    width: 0;
    margin-left: 3px;
    border-left: 1px solid var(--color-neutral-1);
  }
}
</style>
