<!--
 * @Author: renxin renxin0828@163.com
 * @Date: 2023-03-21 17:30:00
 * @LastEditors: renxin renxin0828@163.com
 * @LastEditTime: 2023-03-31 15:33:57
 * @FilePath: \thingskit-front\src\layouts\default\header\components\AboutSoftwareModal.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<script lang="ts" setup>
  import { h } from 'vue';
  import { useI18n } from 'vue-i18n';
  import { Description, useDescription } from '/@/components/Description';
  import { BasicModal, useModal } from '/@/components/Modal';
  import { cacheCipher } from '/@/settings/encryptionSetting';
  import { AesEncryption } from '/@/utils/cipher';

  const encryption = new AesEncryption(cacheCipher);

  const { t } = useI18n();

  enum FiledKey {
    copyright = 'field1',
    website = 'filed2',
    authorization = 'field3',
  }

  // const handleEncode = (string: string) => {
  //   return encryption.encryptByAES(string);
  // };

  const handleDecode = (encodeString: string) => {
    return encryption.decryptByAES(encodeString);
  };

  const [register] = useModal();

  const [registerDes] = useDescription({
    bordered: false,
    column: 1,
    labelStyle: {
      width: '100px',
      textAlign: 'right',
      justifyContent: 'right',
      paddingRight: '20px',
    },
    data: {
      [FiledKey.copyright]: handleDecode(t('routes.aboutSoftware.copyright')),
      [FiledKey.website]: handleDecode(t('routes.aboutSoftware.website')),
      [FiledKey.authorization]: handleDecode(t('routes.aboutSoftware.authorization')),
    },
    schema: [
      {
        field: FiledKey.copyright,
        label: handleDecode(t('routes.aboutSoftware.copyrightLabel')),
      },
      {
        field: FiledKey.website,
        label: handleDecode(t('routes.aboutSoftware.websiteLabel')),
        render: (val: string) => {
          return h(
            'span',
            { class: 'text-blue-500 cursor-pointer', onClick: () => open(val) },
            val
          );
        },
      },
      {
        field: FiledKey.authorization,
        label: handleDecode(t('routes.aboutSoftware.authorizationLabel')),
        render: (val: string) => {
          // https://community.thingskit.com/question/20.html
          return h('div', {}, [
            h('span', val),
            h(
              'span',
              {
                class: 'text-blue-500 cursor-pointer',
                onClick: () => open('https://www.tofly.cn/'),
              },
              '点击前往'
            ),
          ]);
        },
      },
    ],
  });
</script>

<template>
  <BasicModal
    @register="register"
    :title="handleDecode(t('routes.aboutSoftware.aboutSoftware'))"
    width="50%"
    cancel-text="关闭"
    :show-ok-btn="false"
  >
    <Description @register="registerDes" />
  </BasicModal>
</template>
