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

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

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

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

const form = ref({
  id: '',
  uid: '',
  client: '',
  clientId: '',
  organization: '',
  organizationId: '',
  name: '',
  description: '',
  isActive: true,
  hostAddress: '',
  hostPort: '',
  proxyAddress: '',
  proxyLogon: '',
  proxyPassword: '',
  proxyPort: '',
  shippingProcessorClass: '',
  servicePath: '',
  processing: false,
  alert: {
    status: '',
    message: '',
    processing: false
  }
})

const retrieve = async () => {
  const res = await $fetch('/api/materials/shipping-processor-configurations/'+route.params.id, {
    headers: useRequestHeaders(['cookie'])
  })
  if(res) {
    form.value = {
      id: route.params.id,
      uid: res?.uid || '',
      client: res?.AD_Client_ID?.identifier || '',
      clientId: res?.AD_Client_ID?.id || '',
      organization: res?.AD_Org_ID?.identifier || '',
      organizationId: res?.AD_Org_ID?.id || '',
      name: res?.Name || '',
      description: res?.Description || '',
      isActive: res?.IsActive ?? true,
      hostAddress: res?.HostAddress || '',
      hostPort: res?.HostPort || '',
      proxyAddress: res?.ProxyAddress || '',
      proxyLogon: res?.ProxyLogon || '',
      proxyPassword: res?.ProxyPassword || '',
      proxyPort: res?.ProxyPort || '',
      shippingProcessorClass: res?.ShippingProcessorClass || '',
      servicePath: res?.ServicePath || '',
      processing: false,
      alert: {
        status: '',
        message: '',
        processing: false
      }
    }
  }
}
onMounted(retrieve)

const back = () => {
  router.push('/materials/shipping-processor-configurations')
}

const breadCrumb = computed(() => ([
  { link: '#', text: 'Materials'},
  { link: '/materials/shipping-processor-configurations', text: 'Shipping Processor Configurations'},
  { link: '#', text: 'View Shipping Processor Configuration Details', active: true}
]))
</script>

<template>
  <Head>
    <Title>View Shipping Processor Configuration 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 color-inherit"></span> Back
            </button>
          </div>
        </div>
        <div>
          <div class="columns is-gapless is-multiline mb-3 mt-0">
            <div class="column is-half mb-2 d-flex gap-10px">
              <div class="w-180px d-flex justify-between gap-10px">
                <strong>Tenant</strong>
                <strong>:</strong>
              </div>
              <div>{{ clientName }}</div>
            </div>
            <div class="column is-half mb-2 d-flex gap-10px">
              <div class="w-180px d-flex justify-between gap-10px">
                <strong>Organization</strong>
                <strong>:</strong>
              </div>
              <div>{{ form.organization }}</div>
            </div>
            <div class="column is-half mb-2 d-flex gap-10px">
              <div class="w-180px d-flex justify-between gap-10px">
                <strong>Name</strong>
                <strong>:</strong>
              </div>
              <div>{{ form.name }}</div>
            </div>
            <div class="column is-half mb-2 d-flex gap-10px">
              <div class="w-180px d-flex justify-between gap-10px">
                <strong>Search Key</strong>
                <strong>:</strong>
              </div>
              <div>{{ form.value }}</div>
            </div>
            <div class="column is-half mb-2 d-flex gap-10px">
              <div class="w-180px d-flex justify-between gap-10px">
                <strong>Description</strong>
                <strong>:</strong>
              </div>
              <div>{{ form.description }}</div>
            </div>
            <div class="column is-half mb-2 d-flex gap-10px">
              <div class="w-180px d-flex justify-between gap-10px">
                <strong>Host Address</strong>
                <strong>:</strong>
              </div>
              <div>{{ form.hostAddress }}</div>
            </div>
            <div class="column is-half mb-2 d-flex gap-10px">
              <div class="w-180px d-flex justify-between gap-10px">
                <strong>Host Port</strong>
                <strong>:</strong>
              </div>
              <div>{{ form.hostPort }}</div>
            </div>
            <div class="column is-half mb-2 d-flex gap-10px">
              <div class="w-180px d-flex justify-between gap-10px">
                <strong>Proxy Address</strong>
                <strong>:</strong>
              </div>
              <div>{{ form.proxyAddress }}</div>
            </div>
            <div class="column is-half mb-2 d-flex gap-10px">
              <div class="w-180px d-flex justify-between gap-10px">
                <strong>Proxy Port</strong>
                <strong>:</strong>
              </div>
              <div>{{ form.proxyPort }}</div>
            </div>
            <div class="column is-half mb-2 d-flex gap-10px">
              <div class="w-180px d-flex justify-between gap-10px">
                <strong>Proxy Logon</strong>
                <strong>:</strong>
              </div>
              <div>{{ form.proxyLogon }}</div>
            </div>
            <div class="column is-half mb-2 d-flex gap-10px">
              <div class="w-180px d-flex justify-between gap-10px">
                <strong>Proxy Password</strong>
                <strong>:</strong>
              </div>
              <div>{{ form.proxyPassword }}</div>
            </div>
            <div class="column is-half mb-2 d-flex gap-10px">
              <div class="w-180px d-flex justify-between gap-10px">
                <strong>Service Path</strong>
                <strong>:</strong>
              </div>
              <div>{{ form.servicePath }}</div>
            </div>
            <div class="column is-half mb-2 d-flex gap-10px">
              <div class="w-180px d-flex justify-between gap-10px">
                <strong>Shipping Processor Class</strong>
                <strong>:</strong>
              </div>
              <div>{{ form.shippingProcessorClass }}</div>
            </div>
            <div class="column is-full 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>