<script lang="tsx">
  import { SearchOutlined } from '@ant-design/icons-vue';
  import AppSearchModal from './AppSearchModal.vue';
  <%_ if (enableTranslation) { _%>
  import { useI18n } from '@/hooks/web/useI18n';
  <%_ } _%>

  export default defineComponent({
    name: 'AppSearch',
    setup() {
      const showModal = ref(false);
      <%_ if (enableTranslation) { _%>
      const { t } = useI18n();
      <%_ } _%>

      function changeModal(show: boolean) {
        showModal.value = show;
      }

      return () => {
        return (
          <div class="p-1" onClick={changeModal.bind(null, true)}>
            <a-tooltip>
              {{
                title: () => <% if (enableTranslation) { %>t('common.searchText')<% } else { %>'t$t('common.searchText')$t$'<% } %>,
                default: () => <SearchOutlined />,
              }}
            </a-tooltip>
            <AppSearchModal onClose={changeModal.bind(null, false)} visible={unref(showModal)} />
          </div>
        );
      };
    },
  });
</script>
