<template>
    <component :is="Default || 'div'">
        <div class="container mx-auto mt-20">
            <div class="flex flex-col gap-5 mb-6">
                <h1 class="text-2xl font-bold text-black dark:text-white">{{ t('Customer Data') }}</h1>

                <div v-if="!customerStore.hasAccount" class="flex flex-col items-center justify-center py-12">
                    <div class="text-center flex flex-col items-center justify-center mb-6">
                        <UIcon name="mdi:domain" class="text-[60px] text-gray-400 dark:text-gray-500" />
                        <p class="mt-4 text-lg text-gray-600 dark:text-gray-400">{{ t('No customer account found') }}
                        </p>
                        <p class="text-sm text-gray-500 dark:text-gray-500">{{ t('Create an account to manage your company data') }}</p>
                    </div>
                    <UButton color="primary" @click="goToCreateAccount"
                        class="bg-(--accent-blue-light) dark:bg-(--accent-blue-dark) text-white hover:bg-(--accent-blue-dark) dark:hover:bg-(--accent-blue-light)">
                        <UIcon name="mdi:add-bold" />
                        {{ t('Create Account') }}
                    </UButton>
                </div>

                <div v-else class="flex flex-col gap-3">
                    <div class="grid grid-cols-2 gap-5">
                        <div
                            class="bg-(--second-light) dark:bg-(--main-dark) rounded-lg border border-(--border-light) dark:border-(--border-dark) p-4">
                            <h2 class="text-xl font-semibold text-black dark:text-white mb-4 flex items-center gap-2">
                                <UIcon name="mdi:domain"
                                    class="text-[24px] text-(--accent-blue-light) dark:text-(--accent-blue-dark)" />
                                {{ t('Company Information') }}
                            </h2>
                            <div class="grid grid-cols-1 gap-10">
                                <div class="grid grid-cols-1 md:grid-cols-2 gap-2">
                                    <div>
                                        <label
                                            class="block text-sm font-medium text-gray-500 dark:text-gray-400 mb-1">{{ t('Company Name') }}</label>
                                        <p class="text-black dark:text-white">{{ customerStore.customer?.companyName || '-'}}
                                        </p>
                                    </div>
                                    <div>
                                        <label
                                            class="block text-sm font-medium text-gray-500 dark:text-gray-400 mb-1">{{
                                            t('Company Email') }}</label>
                                        <p class="text-black dark:text-white">{{ customerStore.customer?.companyEmail || '-'}}
                                        </p>
                                    </div>
                                    <div>
                                        <label
                                            class="block text-sm font-medium text-gray-500 dark:text-gray-400 mb-1">{{ t('REGON')}}</label>
                                        <p class="text-black dark:text-white">{{ customerStore.customer?.regon || '-' }}
                                        </p>
                                    </div>
                                    <div>
                                        <label
                                            class="block text-sm font-medium text-gray-500 dark:text-gray-400 mb-1">{{t('NIP')}}</label>
                                        <p class="text-black dark:text-white">{{ customerStore.customer?.nip || '-' }}
                                        </p>
                                    </div>
                                    <div>
                                        <label
                                            class="block text-sm font-medium text-gray-500 dark:text-gray-400 mb-1">{{t('VAT')}}</label>
                                        <p class="text-black dark:text-white">{{ customerStore.customer?.vat || '-' }}
                                        </p>
                                    </div>
                                </div>
                                <div>
                                    <h2
                                        class="text-xl font-semibold text-black dark:text-white mb-2 flex items-center gap-2">
                                        <UIcon name="mdi:map-marker"
                                            class="text-[24px] text-(--accent-blue-light) dark:text-(--accent-blue-dark)" />
                                        {{ t('Addresses') }}
                                    </h2>
                                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                                        <div>
                                            <label
                                                class="block text-sm font-medium text-gray-500 dark:text-gray-400 mb-2">{{ t('Company Address') }}</label>
                                            <div v-if="companyAddress"
                                                class="p-4 bg-white dark:bg-(--black) rounded-md border border-(--border-light) dark:border-(--border-dark)">
                                                <p class="text-black dark:text-white">{{ companyAddress.street }}</p>
                                                <p class="text-black dark:text-white">{{ companyAddress.zipCode }},
                                                    {{ companyAddress.city }}</p>
                                                <p class="text-black dark:text-white">{{ companyAddress.country }}</p>
                                            </div>
                                            <p v-else class="text-gray-400 dark:text-gray-500">-</p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="flex justify-end">
                        <UButton color="primary" variant="outline"
                            class="text-(--accent-blue-light) dark:text-(--accent-blue-dark) border-(--accent-blue-light) dark:border-(--accent-blue-dark)"
                            @click="goToCreateAccount">
                            <UIcon name="ic:sharp-edit" />
                            {{ t('Edit Account') }}
                        </UButton>
                    </div>
                </div>
            </div>
        </div>
    </component>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { useRouter } from 'vue-router'
import { useCustomerStore } from '@/stores/customer'
import { useAddressStore } from '@/stores/address'
import { useI18n } from 'vue-i18n'
import Default from '@/layouts/default.vue'
const router = useRouter()
const customerStore = useCustomerStore()
const addressStore = useAddressStore()
const { t } = useI18n()

const companyAddress = computed(() => {
    const id = customerStore.customer?.companyAddressId
    return id ? addressStore.getAddressById(id) : null
})

function goToCreateAccount() {
    router.push({ name: 'profile-details-add-info' })
}
</script>