<template>
  <!-- SUB Contents -->
  <div class="ui--content-wrapper">
    <sdl-breadcrumb></sdl-breadcrumb>
    <!-- SEARCH Area -->
    <!--
    <div class="ui--search-container clearfix">
      <div class="col-10 float-start">
        <div class="row">
          <div class="col-12">
            <div class="row">
              <label class="col-2 col-form-label text-end">제목</label>
              <div class="col-10 form-inline">
                <input class="form-control" type="text" v-model="searchKeyword" @keydown.enter="onSearch()" />
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="col-2 float-end text-end">
        <button class="btn btn-primary btn-search" type="button" @click="onSearch()">
          {{ $t('sdl.common.label.search') }}
        </button>
      </div>
    </div>
    -->
    <!-- LIST Header & buttons -->
    <div class="ui--list-heading clearfix">
      <span class="ui--text-total"><strong>Total</strong> {{ $filters.numberFormat(records) }}</span>
    </div>
    <!-- TABLE  Area-->
    <table class="table table-bordered ui--table">
      <colgroup>
        <col style="width:20%" />
        <col />
        <col style="width:20%" />
        <col style="width:20%" />
        <col style="width:20%" />
      </colgroup>
      <thead>
        <tr>
          <th scope="col">{{ $t('sdl.approval.label.documentType') }}</th>
          <th scope="col">{{ $t('sdl.board.label.classificationDesc') }}</th>
          <th scope="col">{{ $t('sdl.approval.label.BODYMODIFY') }}</th>
          <th scope="col">{{ $t('sdl.approval.label.ROUTEMODIFY') }}</th>
          <th scope="col">{{ $t('sdl.approval.label.useARBITRARY') }}</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="grid in gridList" :key="grid.docType" @click="rowClick(grid.docType, grid.internalApproval)" class="cursor-pointer">
          <td class="text-center">{{ grid.docType }}</td>
          <td class="text-left">{{ $filters.cutString(grid.description, 100) }}</td>
          <td class="text-center">{{ grid.bodyModify }}</td>
          <td class="text-center">{{ grid.routeModify }}</td>
          <td class="text-center">{{ grid.arbitrary }}</td>
        </tr>
      </tbody>
    </table>
    <!-- // TABLE  Area-->
    <!-- Pagination Area-->
    <!--
    <sdl-pagination
      :current-page="currentPage"
      :total-rows="records"
      :per-page="pageSize"
      @change="onSearch"
      align="center"
    />
    -->
    <!--  // Pagination Area-->
  </div>
</template>

<script>
import axios from 'axios';
import { SDLUtil, StringUtil } from '@/utils';
import StoreParams from '@/mixin/StoreParams';

export default {
  data() {
    return {
      gridList: [],
      records: 0, // total number of data
      currentPage: 1, // current page number
      pageSize: 10, // Number of lists per page
      searchPeriod: {},
      searchKeyword: '',
    };
  },
  mixins: [StoreParams],
  methods: {
    init() {
      const storeParams = this.getStoreParameter();
      if (storeParams) {
        this.searchKeyword = storeParams.searchKeyword;
        this.onSearch(storeParams.pageIndex);
      } else {
        this.onSearch();
      }
    },
    onSearch(pageIndex = 1) {
      this.currentPage = pageIndex;
      const params = {
        searchKeyword: this.searchKeyword,
        pageIndex: this.currentPage,
        pageSize: this.pageSize,
      };
      this.setStoreParameter(params);
      // Loading bar execution
      SDLUtil.showLoadingBar(true);
      axios
        .get(`${SDLUtil.API_URL}/approval/approval-doc-types?${StringUtil.queryStringfy(params)}`)
        .then(response => {
          // console.log(response);
          this.gridList = response.data;
          this.records = response.data.length;

          // Loading bar hidden
          SDLUtil.showLoadingBar(false);
        })
        .catch(error => {
          SDLUtil.showLoadingBar(false);
          console.log(error);
          SDLUtil.errorAlert(error);
        });
    },
    rowClick(docType, internalApproval) {
      this.$router.push({ path: `${this.$CONTEXT}/admin/approval/dynamicApprPathDtl/${docType}`, query: {internalApproval: `${internalApproval}`} });
    },
  },
  created() {
    this.init();
  },
};
</script>

<style scoped></style>
