<template>
<div class="col-lg-12">
  <div class="card">
    <div class="card-body">
      <h2 class="card-title">부서별 근태현황</h2>
      <div class="sch-form-wrap">
        <div class="input-group">
          <select name="" id="" class="form-select">
          <option value="">년도</option>
        </select>
          <select name="" id="" class="form-select">
          <option value="">월</option>
        </select>
          <select name="" id="" class="form-select">
          <option value="">구분</option>
        </select>
        <div class="sch-input">
              <input type="text" class="form-control">
              <button class="ico-sch"><SearchOutlined /></button>
            </div>
        </div>
      </div>
     
      <!-- Table  -->
      <div class="tbl-wrap">
        <table id="myTable" class="tbl data buseo">
          <!-- 동적으로 <th> 생성 -->
          <thead>
            <tr>
              <th>부서 </th>
              <th>직급</th>
              <th>이름</th>
              <th>지각</th>
              <th>조기퇴근</th>
              <th>결근</th>
              <th>출장</th>
              <th>주말출근</th>
              <th>대체휴가</th>
              <th>휴가</th>
              <th>공가</th>
              <th>병가</th>
            </tr>
          </thead>
          <!-- 동적으로 <td> 생성 -->
          <tbody>
            <tr v-for="(item, index) in listData" :key="index"  @click="goToAttendancePage(item)">
              <td>{{ item.department }}</td>
    <td>{{ item.position }}</td>
    <td>{{ item.name }}</td>
    <td>{{ item.late }}</td>
    <td>{{ item.earlyLeave }}</td>
    <td>{{ item.absence }}</td>
    <td>{{ item.businessTrip }}</td>
    <td>{{ item.weekendWork }}</td>
    <td>{{ item.substituteHoliday }}</td>
    <td>{{ item.vacation }}</td>
    <td>{{ item.publicHoliday }}</td>
    <td>{{ item.sickLeave }}</td>
  </tr>
          </tbody>
        </table>
  
      </div>
      <div class="pagination">
        <ul>
      <!-- 왼쪽 화살표 (이전 페이지) -->
      <li 
        class="arrow" 
        :class="{ disabled: currentPage === 1 }" 
        @click="changePage(currentPage - 1)"
      >
      &lt;
      </li>

      <!-- 페이지 번호 -->
      <li 
        v-for="page in totalPages" 
        :key="page" 
        :class="{ active: currentPage === page }" 
        @click="changePage(page)"
      >
        {{ page }}
      </li>

      <!-- 오른쪽 화살표 (다음 페이지) -->
      <li 
        class="arrow" 
        :class="{ disabled: currentPage === totalPages }" 
        @click="changePage(currentPage + 1)"
      >
      &gt;
      </li>
    </ul>
  </div>
      
    </div>
  </div>
</div>
</template>

<script>
import { ref } from 'vue';
import { SearchOutlined } from '@ant-design/icons-vue';
export default {
  data() {
    return {
      showOptions: false,
      currentPage: 1,
      totalPages: 3,
      photoicon: "/client/resources/img/photo_icon.png",
      // 데이터 초기화
      years: [2023, 2024, 2025], // 연도 목록
      months: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], // 월 목록
      selectedYear: '',
      selectedMonth: '',
      listData: [
      {
        department: '인사팀',
        position: '팀장',
        name: '홍길동',
        late: 2,
        earlyLeave: 1,
        absence: 0,
        businessTrip: 1,
        weekendWork: 0,
        substituteHoliday: 1,
        vacation: 5,
        publicHoliday: 0,
        sickLeave: 1,
      },
      {
        department: '개발팀',
        position: '사원',
        name: '김철수',
        late: 1,
        earlyLeave: 0,
        absence: 1,
        businessTrip: 0,
        weekendWork: 2,
        substituteHoliday: 0,
        vacation: 3,
        publicHoliday: 1,
        sickLeave: 0,
      },
      // 추가 데이터...
    ],
      filteredData: [],
    };
  },
  components:{
    SearchOutlined
  },
  computed: {
  },
  methods: {
    goToAttendancePage(item) {
      this.$router.push({ name: 'AttendanceDetail', query: { id: item.id } });
    },
    changePage(page) {
      if (page < 1 || page > this.totalPages) return;
      this.currentPage = page;
      this.$emit('page-changed', page); // 필요 시 부모에 알림
    },
    async onClickSubmit() {
      // `useMutation` 훅을 사용하여 mutation 함수 가져오기
      const { mutate, onDone, onError } = useMutation(mygql);

      try {
        const result = await mutate();
        console.log(result);
      } catch (error) {
        console.error('Mutation error:', error);
      }
    },
    goToPage(type) {
  if (type === '휴가') {
    this.$router.push('/HyugaDetail.page');
  } else if (type === '출장') {
    this.$router.push('/ChuljangDetail.page');
  }
},
    getStatusClass(status) {
      if (status === '승인') return 'status-approved';
      if (status === '대기') return 'status-pending';
      return '';
    },
    isPastPeriod(period) {
    // 예: '2025-05-01 ~ 2025-05-03' → 종료일 추출
    const endDateStr = period.split('~')[1]?.trim();
    if (!endDateStr) return false;

    const endDate = new Date(endDateStr);
    const today = new Date();

    // 현재 날짜보다 과거면 true
    return endDate < today;
  }
  },
  created() {
  },
  mounted() {


  },
};
</script>

<style scoped></style>
