<script setup lang="ts">
import { evepraisalAxiosInstance } from '@/market/appraisal/evepraisal';

interface Props {
    name: string;
}

const modelValue = defineModel({ default: '' });
defineProps<Props>();

const loadFromId = async (e: Event) => {
    const input = e.target as HTMLInputElement;
    const id = input.value;

    if (!id) {
        return;
    }
    const response = await evepraisalAxiosInstance.get(`/a/${id}.json`);

    if (response.status !== 200) {
        return;
    }

    modelValue.value = JSON.stringify(response.data);
    input.value = '';
}
</script>

<template>
    <div class="flex-1 mx-1">
        <span>{{ name }}</span><input type="text" class="ms-2" @change="loadFromId" placeholder="id evepraisal" />
        <textarea class="mt-1" v-model="modelValue" />
    </div>
</template>