<script setup lang="ts">
import { ref, onMounted, reactive, watch } from "vue";
import { useRouter } from "vue-router";
import { useQuasar } from "quasar";
import type { QTableProps } from "quasar";

import config from "@/app.config";
import http from "@/plugins/http";
import { useCounterMixin } from "@/stores/mixin";
import { useKpiDataStore } from "@/modules/08_KPI/store";

import type { DataProfile } from "@/interface/Main";
import type {
  DataOptions,
  MainListKpi,
  PaginationType,
} from "@/modules/08_KPI/interface/index/Main";
import type {
  RoundKpiResponse,
  EvaOptionType,
} from "@/modules/08_KPI/interface/response/index";

import DialogHeader from "@/components/DialogHeader.vue";

const $q = useQuasar();
const mixin = useCounterMixin();
const store = useKpiDataStore();
const router = useRouter();
const { showLoader, hideLoader, messageError, date2Thai, dialogConfirm } =
  mixin;

/** Table*/
const rows = ref<MainListKpi[]>([]);
const visibleColumns = ref<string[]>([
  "createdAt",
  "year",
  "durationKPI",
  "evaluationStatus",
  "evaluationResults",
]);
const columns = ref<QTableProps["columns"]>([
  {
    name: "createdAt",
    align: "left",
    label: "วันที่สร้างแบบประเมิน",
    sortable: true,
    field: "createdAt",
    headerStyle: "font-size: 14px",
    style: "font-size: 14px",
    format: (v) => date2Thai(v),
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "year",
    align: "left",
    label: "ปีงบประมาณ",
    sortable: true,
    field: "year",
    headerStyle: "font-size: 14px",
    style: "font-size: 14px",
    format: (v) => v + 543,
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "durationKPI",
    align: "left",
    label: "รอบการประเมิน",
    sortable: true,
    field: "durationKPI",
    headerStyle: "font-size: 14px",
    style: "font-size: 14px",
    format: (v) => (v == "OCT" ? "รอบที่ 2 ตุลาคม" : "รอบที่ 1 เมษายน"),
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "evaluationStatus",
    align: "left",
    label: "สถานะการประเมิน",
    sortable: true,
    field: "evaluationStatus",
    headerStyle: "font-size: 14px",
    style: "font-size: 14px",
    format: (v) => store.convertStatus(v),
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
  {
    name: "evaluationResults",
    align: "left",
    label: "ผลการประเมิน",
    sortable: true,
    field: "evaluationResults",
    headerStyle: "font-size: 14px",
    style: "font-size: 14px",
    format: (v) => store.convertResults(v),
    sort: (a: string, b: string) =>
      a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
  },
]);

/** List*/
const year = ref<number>(new Date().getFullYear());
const round = ref<string>("");
const filterKeyword = ref<string>("");
const roundMainOp = ref<DataOptions[]>([]);
const roundDialgOp = ref<DataOptions[]>([]);

const evaluatorIdOp = ref<DataOptions[]>([]);
const commanderIdOp = ref<DataOptions[]>([]);
const commanderHighOp = ref<DataOptions[]>([]);

const evaluatorIdMainOp = ref<DataOptions[]>([]);
const commanderIdMainOp = ref<DataOptions[]>([]);
const commanderHighMainOp = ref<DataOptions[]>([]);

const statusOp = ref<DataOptions[]>(store.statusOptions);
const resultOp = ref<DataOptions[]>(store.resultsOptions);

/** Dialog*/
const modalDialog = ref<boolean>(false);
const yearDialog = ref<number | null>(null);
const formRound = reactive({
  kpiPeriodId: { id: "", name: "", isClosed: false },
  profileId: "",
  prefix: "",
  firstName: "",
  lastName: "",
  evaluatorId: "",
  commanderId: "",
  commanderHighId: "",
  position: "",
  posLevelName: "",
  posTypeName: "",
  posExecutiveName: "",
});

/** pagetion*/
const formQuery = reactive({
  page: 1,
  pageSize: 10,
  status: "",
  results: "",
});
const total = ref<number>(0);
const totalList = ref<number>(1);
const isRoundClose = ref<boolean>(false);

const pagination = ref({
  sortBy: "desc",
  descending: false,
  page: 1,
  rowsPerPage: 10,
});

/**
 * ดึงข้อมูลรอบการประเมิน
 * @param type
 */
async function fetchRoundOption(type: string) {
  const y = type === "main" ? year.value : yearDialog.value;
  showLoader();
  await http
    .get(
      config.API.kpiPeriod + `?page=${1}&pageSize=${10}&keyword=${""}&year=${y}`
    )
    .then(async (res) => {
      const data = res.data.result.data;
      const list = data.map((e: RoundKpiResponse) => ({
        id: e.id,
        name:
          e.durationKPI === "OCT"
            ? "รอบที่ 2 ตุลาคม"
            : e.durationKPI === "APR"
            ? "รอบที่ 1 เมษายน"
            : "",
        isClosed: !e.isActive,
      }));
      if (type === "main") {
        roundMainOp.value = list;
        round.value = "";
        await fetchList();
      } else {
        roundDialgOp.value = list;
        formRound.kpiPeriodId = { id: "", name: "", isClosed: false };
      }
    })
    .catch((err) => {
      messageError($q, err);
    })
    .finally(() => {
      hideLoader();
    });
}

/**
 *  fetch รายการขอรับประเมินผลการปฏิบัติราชการระดับบุคคล
 */
async function fetchList() {
  showLoader();
  let queryParams = {
    page: formQuery.page,
    pageSize: formQuery.pageSize,
    kpiPeriodId: round.value,
    status: formQuery.status === "" ? undefined : formQuery.status,
    results: formQuery.results === "" ? undefined : formQuery.results,
  };
  await http
    .get(config.API.kpiEvaluation, {
      params: queryParams,
    })
    .then(async (res) => {
      const data = await res.data.result;
      total.value = data.total;
      totalList.value = Math.ceil(data.total / formQuery.pageSize);
      rows.value = data.data;
    })
    .catch((err) => {
      messageError($q, err);
    })
    .finally(() => {
      hideLoader();
    });
}

/** เลือกรอบการประเมิน */
function changRound() {
  formQuery.page = 1;
  fetchList();
}

/** ไปหน้ารายละเอียด */
function redirectViewDetail(id: string) {
  store.tabMain = "1";
  router.push(`/KPI/${id}`);
}

/** สร้างแบบประเมิน */
async function onClickAddList() {
  await getProfile();
  modalDialog.value = true;
}

/** ปิด Dialog  */
function onCloseDialog() {
  modalDialog.value = false;
  formRound.kpiPeriodId = { id: "", name: "", isClosed: false };
  yearDialog.value = null;
}

/** บันทึกข้อมูลที่สร้าง */
function onSubmit() {
  dialogConfirm($q, () => {
    showLoader();
    http
      .post(config.API.kpiEvaluation, {
        kpiPeriodId: formRound.kpiPeriodId.id,
        profileId: formRound.profileId,
        prefix: formRound.prefix,
        firstName: formRound.firstName,
        lastName: formRound.lastName,
        position: formRound.position,
        posLevelName: formRound.posLevelName,
        posTypeName: formRound.posTypeName,
        posExecutiveName: formRound.posExecutiveName,

        evaluatorId: formRound.evaluatorId,
        commanderId: formRound.commanderId == "" ? null : formRound.commanderId,
        commanderHighId:
          formRound.commanderHighId == "" ? null : formRound.commanderHighId,
      })
      .then((res) => {
        const id = res.data.result;
        redirectViewDetail(id);
        onCloseDialog();
      })
      .catch((err) => {
        messageError($q, err);
      })
      .finally(() => {
        hideLoader();
      });
  });
}

/** ดึงข้อมูล */
async function getProfile() {
  if (store.dataProfile.profileId) {
    assignProfileToForm(store.dataProfile);
  } else {
    await http
      .get(config.API.profilePosition())
      .then(async (res) => {
        const data = await res.data.result;
        store.dataProfile = data;
        assignProfileToForm(data);
      })
      .catch((e) => {
        messageError($q, e);
      });
  }
}

function assignProfileToForm(profile: DataProfile) {
  formRound.profileId = profile.profileId ? profile.profileId : "";
  formRound.prefix = profile.prefix ? profile.prefix : "";
  formRound.firstName = profile.firstName ? profile.firstName : "";
  formRound.lastName = profile.lastName ? profile.lastName : "";
  formRound.position = profile.position ? profile.position : "";
  formRound.posLevelName = profile.posLevelName ? profile.posLevelName : "";
  formRound.posTypeName = profile.posTypeName ? profile.posTypeName : "";
  formRound.posExecutiveName = profile.posExecutiveName
    ? profile.posExecutiveName
    : "";
}

/** เช็ครอบการประเมิน ปิด */
function checkClosed() {
  isRoundClose.value = formRound.kpiPeriodId.isClosed;
}

/**
 * function updatePagination
 * @param newPagination ข้อมูล Pagination ใหม่
 */
function updatePagination(newPagination: PaginationType) {
  formQuery.page = 1;
  formQuery.pageSize = newPagination.rowsPerPage;
}

/** ดึงข้อมูล option */
function getOrgOp() {
  http
    .get(config.API.Kpiorg)
    .then((res) => {
      const data = res.data.result;
      evaluatorIdMainOp.value = data.caregiver.map((i: EvaOptionType) => ({
        id: i.id,
        name: `${i.prefix ? i.prefix : ""}${i.firstName ? i.firstName : ""} ${
          i.lastName ? i.lastName : ""
        }`,
      }));
      commanderIdMainOp.value = data.commander.map((i: EvaOptionType) => ({
        id: i.id,
        name: `${i.prefix ? i.prefix : ""}${i.firstName ? i.firstName : ""} ${
          i.lastName ? i.lastName : ""
        }`,
      }));
      commanderHighMainOp.value = data.chairman.map((i: EvaOptionType) => ({
        id: i.id,
        name: `${i.prefix ? i.prefix : ""}${i.firstName ? i.firstName : ""} ${
          i.lastName ? i.lastName : ""
        }`,
      }));
    })
    .catch((e) => {
      messageError($q, e);
    });
}

/**
 * ฟังชั่น ฟิลเตอร์ จาก ค่า input
 * @param val ค่าที่รับมาจาก input
 * @param update
 * @param refData
 */
function filterOption(val: string, update: Function, refData: string) {
  switch (refData) {
    case "evaluatorIdOp":
      update(() => {
        evaluatorIdOp.value = evaluatorIdMainOp.value.filter(
          (v: DataOptions) => v.name.indexOf(val) > -1
        );
      });
      break;
    case "commanderIdOp":
      update(() => {
        commanderIdOp.value = commanderIdMainOp.value.filter(
          (v: DataOptions) => v.name.indexOf(val) > -1
        );
      });
      break;
    case "commanderHighOp":
      update(() => {
        commanderHighOp.value = commanderHighMainOp.value.filter(
          (v: DataOptions) => v.name.indexOf(val) > -1
        );
      });
      break;

    case "status":
      update(() => {
        statusOp.value = store.statusOptions.filter(
          (v: DataOptions) => v.name.indexOf(val) > -1
        );
      });
      break;
    case "result":
      update(() => {
        resultOp.value = store.resultsOptions.filter(
          (v: DataOptions) => v.name.indexOf(val) > -1
        );
      });
      break;
    default:
      break;
  }
}

watch(
  () => formQuery.pageSize,
  () => {
    fetchList();
  }
);

onMounted(async () => {
  await Promise.all([fetchRoundOption("main"), getOrgOp()]);
});
</script>

<template>
  <div class="col-12 row justify-center">
    <div class="col-xs-12 col-sm-12 col-md-11">
      <div class="toptitle text-white col-12 row items-center">
        <q-btn
          icon="mdi-arrow-left"
          unelevated
          round
          dense
          flat
          color="primary"
          class="q-mr-sm"
          @click="router.push(`/`)"
        />
        รายการขอรับประเมินผลการปฏิบัติราชการระดับบุคคล
      </div>

      <div class="col-12">
        <q-card bordered class="q-pa-md">
          <div class="col-12 q-col-gutter-sm">
            <div class="row col-12 q-col-gutter-sm">
              <div class="col-xs-12 col-md-1">
                <datepicker
                  v-model="year"
                  :locale="'th'"
                  autoApply
                  year-picker
                  :enableTimePicker="false"
                  @update:model-value="
                    (formQuery.page = 1), fetchRoundOption('main')
                  "
                >
                  <template #year="{ year }">{{ year + 543 }}</template>
                  <template #year-overlay-value="{ value }">{{
                    parseInt(value + 543)
                  }}</template>
                  <template #trigger>
                    <q-input
                      dense
                      lazy-rules
                      outlined
                      hide-bottom-space
                      :model-value="!!year ? year + 543 : null"
                      :label="`${'ปีงบประมาณ'}`"
                    >
                      <template v-slot:prepend>
                        <q-icon
                          name="event"
                          class="cursor-pointer"
                          style="color: var(--q-primary)"
                        >
                        </q-icon>
                      </template>
                    </q-input>
                  </template>
                </datepicker>
              </div>

              <div class="col-xs-2 col-md-2">
                <q-btn
                  flat
                  round
                  color="primary"
                  icon="add"
                  @click="onClickAddList"
                >
                  <q-tooltip> เพิ่มข้อมูล </q-tooltip>
                </q-btn>
              </div>

              <q-space />
              <div class="col-xs-12 col-md-2">
                <q-select
                  v-model="visibleColumns"
                  multiple
                  outlined
                  dense
                  options-dense
                  :display-value="$q.lang.table.columns"
                  emit-value
                  map-options
                  :options="columns"
                  option-value="name"
                  style="min-width: 140px"
                />
              </div>
            </div>

            <div class="col-12">
              <q-card bordered class="col-12 filter-card q-pa-sm">
                <div class="items-center col-12 row q-col-gutter-sm">
                  <div class="col-xs-12 col-md-2">
                    <q-select
                      v-model="round"
                      outlined
                      label="รอบการประเมิน"
                      dense
                      option-label="name"
                      option-value="id"
                      :options="roundMainOp"
                      emit-value
                      map-options
                      @update:model-value="changRound"
                    />
                  </div>

                  <div class="col-xs-12 col-md-3">
                    <q-select
                      v-model="formQuery.status"
                      label="สถานะการประเมิน"
                      class="select_ellipsis2"
                      dense
                      emit-value
                      map-options
                      :options="statusOp"
                      option-value="id"
                      option-label="name"
                      lazy-rules
                      hide-bottom-space
                      outlined
                      use-input
                      input-debounce="0"
                      @update:model-value="(formQuery.page = 1), fetchList()"
                      :clearable="formQuery.status !== ''"
                      @clear="
                        (formQuery.status = ''),
                          (statusOp = store.statusOptions)
                      "
                      @filter="(inputValue: string,
                    doneFn: Function) => filterOption(inputValue, doneFn, 'status'
                    )"
                      ><template v-slot:no-option>
                        <q-item>
                          <q-item-section class="text-grey">
                            ไม่มีข้อมูล
                          </q-item-section>
                        </q-item>
                      </template>
                    </q-select>
                  </div>
                  <div class="col-xs-12 col-md-3">
                    <q-select
                      v-model="formQuery.results"
                      label="ผลการประเมิน"
                      class="select_ellipsis3"
                      dense
                      emit-value
                      map-options
                      :options="resultOp"
                      option-value="id"
                      option-label="name"
                      lazy-rules
                      hide-bottom-space
                      outlined
                      @update:model-value="(formQuery.page = 1), fetchList()"
                      use-input
                      @clear="
                        (formQuery.results = ''),
                          (resultOp = store.resultsOptions)
                      "
                      input-debounce="0"
                      :clearable="formQuery.results !== ''"
                      @filter="(inputValue: string,
                  doneFn: Function) => filterOption(inputValue, doneFn, 'result'
                  )"
                      ><template v-slot:no-option>
                        <q-item>
                          <q-item-section class="text-grey">
                            ไม่มีข้อมูล
                          </q-item-section>
                        </q-item>
                      </template>
                    </q-select>
                  </div>
                </div>
              </q-card>
            </div>

            <div class="col-12">
              <d-table
                ref="table"
                :columns="columns"
                :rows="rows"
                :filter="filterKeyword"
                row-key="id"
                flat
                bordered
                :paging="true"
                dense
                :rows-per-page-options="[10, 25, 50, 100]"
                :visible-columns="visibleColumns"
                v-model:pagination="pagination"
                @update:pagination="updatePagination"
              >
                <template v-slot:header="props">
                  <q-tr :props="props">
                    <q-th
                      v-for="col in props.cols"
                      :key="col.name"
                      :props="props"
                    >
                      <span class="text-weight-medium">{{ col.label }}</span>
                    </q-th>
                  </q-tr>
                </template>
                <template v-slot:body="props">
                  <q-tr :props="props" class="cursor-pointer">
                    <q-td
                      v-for="col in props.cols"
                      :key="col.id"
                      @click="redirectViewDetail(props.row.id)"
                    >
                      <div>
                        {{ col.value ? col.value : "-" }}
                      </div>
                    </q-td>
                  </q-tr>
                </template>
                <template #item="props">
                  <div class="q-pa-xs col-xs-12 col-sm-6 col-md-4 col-lg-3">
                    <q-card bordered flat>
                      <q-list @click="redirectViewDetail(props.row.id)">
                        <q-item v-for="col in props.cols" :key="col.name">
                          <q-item-section>
                            <q-item-label caption>{{ col.label }}</q-item-label>

                            <q-item-label>
                              {{ col.value ? col.value : "-" }}</q-item-label
                            >
                          </q-item-section>
                        </q-item>
                      </q-list>
                    </q-card>
                  </div>
                </template>
                <template v-slot:pagination="scope">
                  ทั้งหมด {{ total }} รายการ
                  <q-pagination
                    v-model="formQuery.page"
                    active-color="primary"
                    color="dark"
                    :max="Number(totalList)"
                    size="sm"
                    boundary-links
                    direction-links
                    :max-pages="5"
                    @update:model-value="fetchList"
                  ></q-pagination>
                </template>
              </d-table>
            </div>
          </div>
        </q-card>
      </div>
    </div>
  </div>

  <q-dialog v-model="modalDialog" persistent>
    <q-card
      class="col-12"
      :style="$q.screen.gt.xs ? 'width: 20vw' : 'width: 100vw'"
    >
      <q-form greedy @submit.prevent @validation-success="onSubmit">
        <DialogHeader :tittle="'สร้างแบบประเมินผลฯ'" :close="onCloseDialog" />
        <q-separator />
        <q-card-section class="q-pa-none scroll" style="max-height: 80vh">
          <div class="row q-pa-md q-col-gutter-md">
            <div class="col-12">
              <datepicker
                menu-class-name="modalfix"
                v-model="yearDialog"
                :locale="'th'"
                autoApply
                year-picker
                :enableTimePicker="false"
                @update:model-value="fetchRoundOption('dialog')"
              >
                <template #year="{ year }">{{ year + 543 }}</template>
                <template #year-overlay-value="{ value }">{{
                  parseInt(value + 543)
                }}</template>
                <template #trigger>
                  <q-input
                    dense
                    lazy-rules
                    outlined
                    hide-bottom-space
                    :model-value="!!yearDialog ? yearDialog + 543 : null"
                    :label="`${'ปีงบประมาณ'}`"
                    :rules="[
                      (val:string) =>
                        !!val || `${'กรุณาเลือกปีงบประมาณ'}`,
                    ]"
                  >
                    <template v-slot:prepend>
                      <q-icon
                        name="event"
                        class="cursor-pointer"
                        style="color: var(--q-primary)"
                      >
                      </q-icon>
                    </template>
                  </q-input>
                </template>
              </datepicker>
            </div>

            <div class="col-12">
              <q-select
                :readonly="yearDialog === null"
                v-model="formRound.kpiPeriodId"
                outlined
                label="รอบการประเมิน"
                dense
                option-label="name"
                option-value="id"
                :options="roundDialgOp"
                hide-bottom-space
                lazy-rules
                :rules="[(val:DataOptions) => !!val.id || `${'กรุณาเลือกรอบการประเมิน'}`]"
                @update:model-value="checkClosed"
              />
            </div>

            <div class="col-12">
              <q-select
                v-model="formRound.evaluatorId"
                outlined
                label="ผู้ประเมิน"
                dense
                option-label="name"
                option-value="id"
                :options="
                  evaluatorIdOp.filter(
                    (i) =>
                      i.id !== formRound.commanderId &&
                      i.id !== formRound.commanderHighId
                  )
                "
                emit-value
                map-options
                hide-bottom-space
                lazy-rules
                :rules="[
                  (val:string) =>
                    !!val || `${'กรุณาเลือกผู้ประเมิน'}`,
                ]"
                use-input
                @filter="(inputValue:string,
                    doneFn:Function) => filterOption(inputValue, doneFn,'evaluatorIdOp'
                    ) "
              >
                <template v-slot:no-option>
                  <q-item>
                    <q-item-section class="text-grey">
                      ไม่มีข้อมูล
                    </q-item-section>
                  </q-item>
                </template>
              </q-select>
            </div>
            <div class="col-12">
              <q-select
                v-model="formRound.commanderId"
                outlined
                label="ผู้บังคับบัญชาเหนือขึ้นไป"
                dense
                option-label="name"
                option-value="id"
                :options="
                  commanderIdOp.filter(
                    (i) =>
                      i.id !== formRound.evaluatorId &&
                      i.id !== formRound.commanderHighId
                  )
                "
                emit-value
                map-options
                use-input
                @filter="(inputValue:string,
                    doneFn:Function) => filterOption(inputValue, doneFn,'commanderIdOp'
                    ) "
              >
                <template v-if="formRound.commanderId" v-slot:append>
                  <q-icon
                    name="cancel"
                    @click.stop.prevent="formRound.commanderId = ''"
                    class="cursor-pointer"
                  />
                </template>
                <template v-slot:no-option>
                  <q-item>
                    <q-item-section class="text-grey">
                      ไม่มีข้อมูล
                    </q-item-section>
                  </q-item>
                </template>
              </q-select>
            </div>
            <div class="col-12">
              <q-select
                v-model="formRound.commanderHighId"
                outlined
                label="ผู้บังคับบัญชาเหนือขึ้นไปอีกชั้นหนึ่ง"
                dense
                option-label="name"
                option-value="id"
                :options="
                  commanderHighOp.filter(
                    (i) =>
                      i.id !== formRound.evaluatorId &&
                      i.id !== formRound.commanderId
                  )
                "
                emit-value
                map-options
                use-input
                @filter="(inputValue:string,
                    doneFn:Function) => filterOption(inputValue, doneFn,'commanderHighOp'
                    ) "
              >
                <template v-if="formRound.commanderHighId" v-slot:append>
                  <q-icon
                    name="cancel"
                    @click.stop.prevent="formRound.commanderHighId = ''"
                    class="cursor-pointer"
                  />
                </template>
                <template v-slot:no-option>
                  <q-item>
                    <q-item-section class="text-grey">
                      ไม่มีข้อมูล
                    </q-item-section>
                  </q-item>
                </template>
              </q-select>
            </div>
          </div>
        </q-card-section>
        <q-separator />
        <q-card-actions align="right" class="bg-white text-teal">
          <div v-if="isRoundClose" class="text-red q-px-sm">
            รอบการประเมินนี้ปิดแล้ว
          </div>

          <q-space />
          <q-btn
            :disable="isRoundClose"
            label="บันทึก"
            color="secondary"
            type="submit"
            ><q-tooltip>บันทึกข้อมูล</q-tooltip></q-btn
          >
        </q-card-actions>
      </q-form>
    </q-card>
  </q-dialog>
</template>
<style scoped lang="scss">
.icon-color {
  color: #4154b3;
}

.custom-table2 {
  max-height: 64vh;

  .q-table tr:nth-child(odd) td {
    background: white;
  }

  .q-table tr:nth-child(even) td {
    background: #f8f8f8;
  }

  .q-table thead tr {
    background: #ecebeb;
  }

  .q-table thead tr th {
    position: sticky;
  }

  .q-table td:nth-of-type(2) {
    z-index: 3 !important;
  }

  .q-table th:nth-of-type(2),
  .q-table td:nth-of-type(2) {
    position: sticky;
    left: 0;
    z-index: 1;
  }

  /* this will be the loading indicator */
  .q-table thead tr:last-child th {
    /* height of all previous header rows */
    top: 48px;
  }

  .q-table thead tr:first-child th {
    top: 0;
  }
}
</style>
