<template>
  <div class="page-container">
    <div v-if="!pending">
      <app-breadcrumb class="breadcrumb" :items="breadcrumbItems" />

      <div class="content">
        <!-- eslint-disable-next-line vue/no-v-html -->
        <div class="html-typography" v-html="companyProfile.content || ''" />
        <!-- <div v-if="!hydrated" v-html="companyProfile.content || ''" /> -->
        <!-- <div v-else> -->
        <!--   <html-renderer -->
        <!--     class="html-typography" -->
        <!--     :html="companyProfile.content || ''" -->
        <!--   /> -->
        <!-- </div> -->
      </div>

      <el-divider content-position="left">{{ $t('learn-more') }}</el-divider>
      <div class="button-group">
        <learn-more-card
          :title="$t('navigation.contact-info')"
          :icon="ElIconService"
          :to="$localePath('/support/contact-us')"
        />
        <learn-more-card
          :title="$t('navigation.address')"
          :icon="ElIconMapLocation"
          @click="openMap"
        />
      </div>
    </div>
    <div v-else class="loading">
      <el-skeleton :rows="5" animated />
    </div>
  </div>
</template>

<script setup lang="ts">
  const localePath = useLocalePath();
  const hydrated = ref(false);
  const breadcrumbItems = [
    { label: $t('navigation.home'), to: localePath('/') },
    { label: $t('navigation.about-us') },
  ];
  const { data: companyProfile, pending, error } = await useCompanyProfile();

  const openMap = () => {
    window.open(localePath('/locate'));
  };

  watch(error, (value) => {
    if (value) {
      logger.error('数据获取失败: ', value);
    }
  });

  const pageTitle = computed(() => $t('page-title.about-us'));
  useHead({
    title: pageTitle,
  });

  onMounted(() => {
    hydrated.value = true;
  });
</script>

<style scoped>
  .page-container {
    padding: 2rem 1rem;
    max-width: 1200px;
    margin: 0 auto;
  }

  .breadcrumb {
    padding: 1rem 1rem;
  }

  .content {
    padding: 1rem;
    margin-bottom: 2rem;
  }

  :deep(.el-divider__text) {
    color: var(--el-color-info);
    font-size: 1em;
  }

  .button-group {
    display: flex;
    justify-content: left;
    margin-top: 2rem;
    margin-left: 2rem;
    gap: 2rem;
  }

  .loading {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 1rem;
  }

  @media (max-width: 768px) {
    .button-group {
      align-items: center;
      margin-left: 0;
      gap: 0.5rem;
    }
  }
</style>
