<script setup lang="ts">
import { onMounted, ref } from "vue";
import { useQuasar } from "quasar";
import { useRoute, useRouter } from "vue-router";
import { useCounterMixin } from "@/stores/mixin";

import type { ResponseTitle } from "@/modules/05_placement/interface/response/Receive";

import http from "@/plugins/http";
import config from "@/app.config";

const $q = useQuasar();
const route = useRoute();
const router = useRouter();
const mixin = useCounterMixin();

const paramsId = route.params.id;
const { messageError, showLoader, hideLoader } = mixin;

const title = ref<ResponseTitle>({
  fullname: "",
  organizationPositionOld: "",
  positionLevelOld: "",
  positionTypeOld: "",
});

onMounted(async () => {
  await fecthOther();
});

const fecthOther = async () => {
  showLoader();
  await http
    .get(config.API.otherByid(paramsId.toString()))
    .then((res: any) => {
      const data = res.data.result;
      console.log(data);

      title.value.fullname = `${data.firstName ?? "-"} ${data.lastName ?? "-"}`;
      title.value.organizationPositionOld = data.organizationPositionOld ?? "-";
      title.value.positionLevelOld = data.positionLevelOld ?? "-";
      title.value.positionTypeOld = data.positionTypeOld ?? "-";
    })
    .catch((e) => {
      messageError($q, e);
    })
    .finally(() => {
      hideLoader();
    });
};
</script>

<template>
  <div class="toptitle text-dark col-12 row items-center">
    <q-btn
      icon="mdi-arrow-left"
      unelevated
      round
      dense
      flat
      color="primary"
      class="q-mr-sm"
      @click="router.go(-1)"
    />
    รายละเอียดรายการอื่นๆ {{ title.fullname }}
  </div>
  <q-card bordered class="row col-12 text-dark">
    <div class="bg-grey-1 q-pa-sm col-12 row items-center text-primary">
      <div class="q-pl-sm text-weight-bold text-subtitle2">
        {{ title.fullname }}
      </div>
      <q-space />
      <q-btn
        outline
        color="blue"
        dense
        icon-right="mdi-open-in-new"
        class="q-px-sm"
        label="ดูข้อมูลทะเบียนประวัติ"
        @click="router.push(`/registry/${paramsId}`)"
      />
    </div>
    <div class="col-12"><q-separator /></div>
    <div class="row col-12 q-pa-md">
      <div class="col-12 row bg-white q-col-gutter-md">
        <div class="col-xs-3 col-sm-2 col-md-1 row">
          <!-- <q-img
            :src="responseData.avataPath"
            v-if="responseData.avataPath !== ''"
          /> -->
          <q-img src="@/assets/avatar_user.jpg" />
        </div>
        <div class="col-xs-6 col-sm-3 row items-center">
          <div class="col-12 q-pl-md">
            <div class="col-12 text-top">ตำแหน่งในสายงาน</div>
            <div class="col-12 text-detail">
              {{ title.positionTypeOld }}
            </div>
          </div>
        </div>
        <div class="col-xs-6 col-sm-3 row items-center">
          <div class="col-12">
            <div class="col-12 text-top">ระดับ</div>
            <div class="col-12 text-detail">
              {{ title.positionLevelOld }}
            </div>
          </div>
        </div>
        <div class="col-xs-6 col-sm-3 row items-center">
          <div class="col-12">
            <div class="col-12 text-top">สังกัด</div>
            <div class="col-12 text-detail">
              {{ title.organizationPositionOld }}
            </div>
          </div>
        </div>
      </div>
    </div>
  </q-card>
</template>

<style lang="scss" scope>
.q-img {
  border-radius: 5px;
  height: 70px;
}
.text-top {
  color: gray;
  font-weight: 400;
  padding-bottom: 3px;
}
.text-detail {
  font-weight: 500;
}
</style>
