<script setup>
import Api from "../../api/index.js";
import {useSystemStore} from "../../pinia/SystemStore/index.js";

const emits = defineEmits(['success']);
const SystemStore = useSystemStore();

const upload = (e) => {
    const file = e.target.files[0];
    const api = SystemStore.isRoot ? Api.system.uploadFile : Api.system.uploadFile2;
    api(file).then(({data}) => {
        emits('success', data);
    });
}

const createInput = () => {
    const input = document.createElement('input');
    input.type = 'file';
    input.multiple = true;
    input.onchange = upload;
    input.style.display = 'none';
    document.body.append(input);
    input.click();
}
</script>

<template>
    <div @click="createInput">
        <slot></slot>
    </div>
</template>

<style scoped lang="scss">

</style>
