<!--
 * index.vue
 * Copyright (C) 2024 veypi <i@veypi.com>
 * 2024-06-07 17:46
 * Distributed under terms of the MIT license.
 -->
<template>
  <div>
    <div class="vbtn" v-if="preview_mode" @click="preview_mode = false">
      <OneIcon name='edit-square'>plus</OneIcon>
    </div>
    <Editor style="" v-if="core.id" :eid="core.id + '.des'" v-model="preview_mode" :content="content" @save="save">
    </Editor>
  </div>
</template>

<script lang="ts" setup>
import type { models } from '#imports';
import oaer from '@veypi/oaer'


let props = withDefaults(defineProps<{
  core: models.App,
}>(),
  {}
)

let preview_mode = ref(true)

let content = ref('编辑')

watch(computed(() => props.core.id), () => {
  sync()
})

const sync = () => {
  if (props.core.des) {
    console.log(props.core.des)
    oaer.fs().app.getFileContents("/net/go.mod", { format: 'text' }).then((e) => {
      content.value = e as string
    })
  }
}

const save = (des: string) => {
  oaer.fs().app.putFileContents("/info/des.md", des).then((e) => {
    console.log(e)
  })
  // oafs.upload([a], props.core.id).then(url => {
  //   api.app.update(props.core.id, { des: url[0] }).then(e => {
  //     preview_mode.value = true
  //     props.core.des = url[0]
  //   }).catch(e => {
  //     // msg.Warn("更新失败: " + e)
  //   })
  // }).catch(e => {
  //   // msg.Warn("更新失败: " + e)
  // })
}


onMounted(() => {
  sync()
})

</script>

<style scoped></style>
