<template>
  <ToolShell ref="shell" placeholder="Enter a domain or IP and click Whois">
    <template #default="{ running }">
      <input v-model="target" type="text" placeholder="Domain or IP" class="px-3 py-1.5 text-sm rounded bg-[#161b22] border border-[#30363d] text-[#e0e0e0] outline-none focus:border-[#58a6ff] flex-1" @keydown.enter="lookup" />
      <button class="px-4 py-1.5 text-sm font-bold rounded bg-[#58a6ff] text-black cursor-pointer disabled:opacity-40" :disabled="running" @click="lookup">Whois</button>
    </template>
  </ToolShell>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { invoke } from "@tauri-apps/api/core";
import ToolShell from "./ToolShell.vue";

const props = defineProps<{ sessionId: string }>();
const target = ref("");
const shell = ref<InstanceType<typeof ToolShell> | null>(null);

async function lookup(): Promise<void> {
  if (!target.value) return;
  shell.value?.execute(() =>
    invoke<string>("tool_whois", { sessionId: props.sessionId, target: target.value })
  );
}
</script>
