<!-- @format -->

<script lang="ts" setup>
import { useData } from "./useData"

const { tableData, total, getTableList, changePage, page_size } = useData({
  type: "2",
})

function tableRowClassName({ rowIndex }: any) {
  if (rowIndex % 2 === 0) return "warning-row"
  return ""
}
getTableList()
</script>

<template>
  <div>
    <el-table
      :data="tableData"
      style="width: 100%"
      :row-class-name="tableRowClassName"
    >
      <el-table-column prop="billNo" label="Order No." width="180">
        <template #default="{ row }">
          <nuxt-link
            :to="`/orders/${row.id}`"
            class="hover:underline text-#0068FF"
          >
            {{ row.billNo }}
          </nuxt-link>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="brandQuantity" label="Brand Qty." width="180" /> -->
      <el-table-column
        prop="merchandiseQuantity"
        label="Products"
        width="180"
      />

      <el-table-column prop="totalPrice" label="Order Total" width="180" />
      <el-table-column label="Status" width="180">
        <template #default="{ row }">
          {{ row.state === "1" ? "Submitted" : "Cancelled" }}
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="Created Time" width="180" />
      <el-table-column fixed="right" label="Action" min-width="240">
        <template #default="{ row }">
          <el-button
            class="!text-#C58C64 !h-40px !b-unset !bg-transparent hover:!bg-transparent hover:!text-#C58C64 hover:!underline"
          >
            <nuxt-link :to="`/orders/${row.id}`"> View details </nuxt-link>
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div v-if="tableData.length" class="mt-25px flex justify-end">
      <el-pagination
        :page-size="page_size"
        class="custom-pagination"
        :pager-count="10"
        layout="prev, pager, next"
        :total="total"
        @change="changePage"
      />
    </div>
  </div>
</template>

<style lang="less" scoped>
::v-deep(.el-table) {
  color: #333;

  .el-table__header-wrapper {
    .el-table__header {
      height: 50px;

      .el-table__cell {
        color: #333;
        font-weight: 400 !important;
        background-color: #fff2e1;
      }
    }
  }

  .el-table__row {
    height: 68px;

    &.warning-row {
      --el-table-tr-bg-color: #f7f7f7;
    }
  }
}
</style>
