<script setup>
import { date } from 'alga-js'
const router = useRouter()
const route = useRoute()

definePageMeta({
  middleware: ['auth', 'org']
})

const clients = useCookie('logship_clients')
const clientId = useCookie('logship_client_id')

const clientName = computed(() => {
  return clients.value?.filter(i => i.id == clientId.value)?.[0]?.name || 0
})

const form = ref({
  id: '',
  organization: '',
  isActive: true,
  name: '',
  description: '',
  help: '',
})

const retrieve = async () => {
  const res = await $fetch('/api/requests/request-resolutions/'+route.params.id, {
    headers: useRequestHeaders(['cookie'])
  })
  if(res) {
    form.value = {
      id: route.params.id,
      organization: res?.AD_Org_ID?.identifier || '',
      isActive: res?.IsActive ?? true,
      name: res?.Name || '',
      description: res?.Description || '',
      help: res?.Help || '',
    }
  }

}
onMounted(retrieve)

const back = () => {
  router.push('/requests/request-resolutions')
}

const breadCrumb = computed(() => ([
  { link: '#', text: 'Requests'},
  { link: '/requests/request-resolutions', text: 'Request Resolutions'},
  { link: '#', text: 'View Request Resolution Details', active: true}
]))
</script>

<template>
  <Head>
    <Title>View Request Resolution Details</Title>
  </Head>

  <NuxtLayout name="new-dash">
    <NewBreadCrumb :items="breadCrumb" />
    <div>
      <div class="banner">
        <div class="d-flex justify-between mb-3">
          <h4></h4>
          <div class="d-flex gap-0.75rem">
            <button type="button" @click="back" class="button">
              <span class="tf-icon ti ti-chevron-left ti-xs me-1"></span> Back
            </button>
          </div>
        </div>
        <div>
          <div class="row mb-3 mt-0">
            <div class="col-md-6 mb-2 d-flex gap-10px">
              <div class="w-150px d-flex justify-between gap-10px">
                <strong>Tenant</strong>
                <strong>:</strong>
              </div>
              <div>{{ clientName }}</div>
            </div>
            <div class="col-md-6 mb-2 d-flex gap-10px">
              <div class="w-150px d-flex justify-between gap-10px">
                <strong>Organization</strong>
                <strong>:</strong>
              </div>
              <div>{{ form.organization }}</div>
            </div>
            <div class="col-md-6 mb-2 d-flex gap-10px">
              <div class="w-150px d-flex justify-between gap-10px">
                <strong>Name</strong>
                <strong>:</strong>
              </div>
              <div>{{ form.name }}</div>
            </div>
            <div class="col-md-6 mb-2 d-flex gap-10px">
              <div class="w-150px d-flex justify-between gap-10px">
                <strong>Description</strong>
                <strong>:</strong>
              </div>
              <div>{{ form.description }}</div>
            </div>
            <div class="col-md-6 mb-2 d-flex gap-10px">
              <div class="w-150px d-flex justify-between gap-10px">
                <strong>Comment/Help</strong>
                <strong>:</strong>
              </div>
              <div>{{ form.help }}</div>
            </div>
            <div class="col-md-12 mb-3">
              <label class="label d-block mb-2 fw-bold">Status :</label>
              <div class="check">
                <input type="checkbox" v-model="form.isActive" class="checkInput" id="isActive" :checked="form.isActive" disabled>
                <label class="checkLabel" for="isActive">Active</label>
              </div>
            </div>

          </div>

        </div>
      </div>

    </div>
  </NuxtLayout>
</template>