<template>
  <ChartsContainer title="出勤投入">
    <div ref="content" style="height: 100%;">
      <div class="content-row" v-if="type">
        <div class="content-row-list">
          <div class="content-row-item">
            <div>{{ props.type === 'personal' ? '出勤天数' : '人均出勤天数' }}</div>
            <div>{{ rowTableItem.avgWorkingDays }}天</div>
          </div>
          <div class="content-row-item">
            <div>{{  props.type === 'personal' ? '岗时长' : '人均上岗时长' }}</div>
            <div>{{ rowTableItem.avgWorkingHours }}h</div>
          </div>
        </div>
      </div>
      <el-table v-else v-auto-scroll :data="tableData" border style="width: 100%" height="100%">
        <el-table-column prop="dimension" label="统计维度" min-width="100" />
        <el-table-column prop="avgWorkingDays" label="人均出勤天数" />
        <el-table-column prop="avgWorkingHours" label="人均上岗时长" min-width="100" />
      </el-table>
    </div>
  </ChartsContainer>
</template>

<script setup>
import ChartsContainer from '../ChartsContainer.vue';
import { ref } from 'vue';
import { getAttendanceStatistics, getModuleMetrics } from '@/api/item/items'
import { useTimeOut } from '../pageItems/useTimeOut'
const props = defineProps({
  type: {
    type: String,
    default: '' // team, department, station
  }
})
const tableData = ref([])
const rowTableItem = ref({
  
})
const params = inject('provideParams')
useTimeOut(() => {
  if (props.type !== 'team' && props.type !== 'personal' ) {
    params.value.deptId && getAttendanceStatistics({ deptId: params.value.deptId }).then(res => {
      tableData.value = res
      rowTableItem.value = (res || [ {} ])[ 0 ]
    })
  } else {
    params.value.deptId && getModuleMetrics(
      props.type === 'personal' ? { userId: params.value.deptId, userTypeStr: props.type } : { deptId: params.value.deptId, userTypeStr: props.type }
    ).then(res => {
    const { moduleResults = {
      attendance: {
        workingDate: {},
        workingHours: {},
      }
    } } = res.data
    if (props.type === 'personal') {
      rowTableItem.value = {
        avgWorkingDays: moduleResults.attendance.workingDate,
        avgWorkingHours: moduleResults.attendance.workingHours
      }
    } else {
      rowTableItem.value = {
        avgWorkingDays: moduleResults.attendance.workingDate.averagePersonnel,
        avgWorkingHours: moduleResults.attendance.workingHours.averagePersonnel
      }
    }
    
  })
  }
  
}, [ params ])

</script>

<style lang="scss" scoped>
.content-row {
  display: flex;
  flex-direction: column;
  height: 100%;

  .content-row-title {
    font-size: 14px;
    color: #77DBF4;
    height: 30px;
  }

  .content-row-list {
    display: flex;
    flex: 1;
    flex-direction: column;
    justify-content: space-evenly;
    row-gap: 15px;
  }

  .content-row-item {
    flex: 1;
    background: url('../../../../../assets/images/rowBg.png') no-repeat;
    background-position: -10px;
    background-size: calc(100% + 20px) 100%;
    overflow: hidden;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    font-size: 16px;
    border-radius: 5px;
    padding: 0 15px;
    font-weight: bold;
    max-height: 64px;
  }
}
</style>