<template>
    <el-dropdown trigger="click">
        <div class="el-dropdown-link" title="文件">
            <img :src="local_storage" alt="" class="header_right_icon left">
            <span class="header_right_title_span">文件</span>
        </div>
        <template #dropdown>
            <el-dropdown-menu>
                <el-dropdown-item class="header_menu_li" @click="cloudSave()"
                    style="color: #26a69a;">云端存储</el-dropdown-item>
                <el-dropdown-item class="header_menu_li" @click="importFile()" style="color: #26a69a;">导入</el-dropdown-item>
                <el-dropdown-item class="header_menu_li" @click="exportFile()" style="color: #26a69a;">导出</el-dropdown-item>
            </el-dropdown-menu>
        </template>
    </el-dropdown>
</template>
<script setup>
import { ref, watchEffect, defineProps } from 'vue'
import { ElMessage } from 'element-plus'
import local_storage from '../../assets/img/local_storage.png'
import '../../assets/css/header.css'
import store from '../../stores/blockly'
import { exportFileGlobal } from '../../gloabl/globalMethods'

const props = defineProps({
    exportImportFileName: {
        type: String
    }
})
const emit = defineEmits(["setFileName"])

const exportXml = store.useyXmlStore()
const importFileName = store.useImportFileNameStore()
const cloudSave = () => {
    console.log("云端存储")
}
const importFile = () => {
    console.log("导入xml文件", importFileName)
    importFileName.$patch({ fileName: "2222" })
    emit("setFileName", "22")
}
// console.log(getCurrentInstance().appContext.config.globalProperties)
// $exportFile(exportXml,props.exportImportFileName + '.xml')
const exportFile = () => {
    let name = props.exportImportFileName + '.xml'
    if (exportXml.xmlStr && exportXml.xmlStr != `<xml xmlns="https://developers.google.com/blockly/xml"></xml>`) {
        exportFileGlobal(exportXml.xmlStr, name)
    } else {
        ElMessage({
            message: '导出内容为空',
            type: 'warning',
        })
    }

    // let blob = new Blob([exportXml], { type: 'text/plain;charset=utf-8' })
    // // 创建一个指向Blob对象的URL
    // const textURL = window.URL.createObjectURL(blob);
    // // 创建一个临时的a标签用于触发下载
    // const link = document.createElement('a');
    // link.href = textURL;
    // link.download = props.exportImportFileName + '.xml'; // 指定下载文件的名称
    // document.body.appendChild(link); // 将a标签添加到文档中
    // // 触发点击事件以开始下载
    // link.click();

    // // 清理：移除a标签，释放创建的URL
    // document.body.removeChild(link);
    // window.URL.revokeObjectURL(textURL);
}

</script>
<style scoped lang="sass">

</style>