<template>
  <a-tooltip <% if (enableTranslation) { %>:title="t('layout.header.tooltipLock')"<% } else { %>title="t$t('layout.header.tooltipLock')$t$"<% } %> placement="bottom" :mouseEnterDelay="0.5" @click="handleLock">
    <Icon icon="ant-design:lock-outlined" />
  </a-tooltip>
  <LockModal ref="modalRef" v-if="lockModalVisible" @register="register" />
</template>
<script lang="ts">
  import { useModal } from '@/components/Modal';
  import { getRefPromise } from '@/utils/util';
  import { createAsyncComponent } from '@/utils/factory/createAsyncComponent';
  <%_ if (enableTranslation) { _%>
  import { useI18n } from '@/hooks/web/useI18n';
  <%_ } _%>

  export default defineComponent({
    name: 'LockScreen',
    inheritAttrs: false,
    components: {
      LockOutlined,
      LockModal: createAsyncComponent(() => import('./lock/LockModal.vue')),
    },
    setup() {
      <%_ if (enableTranslation) { _%>
      const { t } = useI18n();
      <%_ } _%>
      const [register, { openModal }] = useModal();

      const lockModalVisible = ref(false);
      const modalRef = ref(null);
      async function handleLock() {
        lockModalVisible.value = true;
        await getRefPromise(modalRef);
        openModal(true);
      }

      return {
        <%_ if (enableTranslation) { _%>
        t,
        <%_ } _%>
        register,
        handleLock,
        lockModalVisible,
        modalRef,
      };
    },
  });
</script>
