<route lang="yaml">
style:
  navigationBarTitleText: 个人动态
  navigationBarBackgroundColor: '#fff'
</route>
<script setup lang="ts">
import SectionHeading from '@/components/section-heading.vue'
import { createCircle } from '../../../core/libs/requests'
import { useUserStore } from '../../../store'
import { storeToRefs } from 'pinia'
import { useToast } from 'wot-design-uni'

const userStore = useUserStore()
const { userInfo } = storeToRefs(userStore)
const { error } = useToast()
const content = ref('')
const fileList = ref([])
const action = ref(`${import.meta.env.VITE_SERVER_BASEURL}/app-api/infra/file/upload`)
const handleChange = ({ fileList: files }) => {
  fileList.value = files
  console.log(fileList.value)
}
const handleSubmit = async () => {
  const { code, msg } = await createCircle({
    stylistId: userInfo.value.userId,
    stylistName: userInfo.value.nickname,
    bannerUrls: fileList.value.map(({ response }) => JSON.parse(response).data),
    tagName: '',
    headUrl: userInfo.value.avatar,
    circleDesc: content.value,
    circleType: '1',
  })
  if (code !== 0) {
    error(msg)
  }
  uni.showToast({
    title: '发布成功',
  })
}
onMounted(() => {
  console.log(action.value)
})
</script>
<template>
  <div class="flex-grow bg-white p-3.5 flex flex-col">
    <wd-textarea v-model="content" placeholder="分享你此刻的想法" />

    <!-- <div class="flex items-center">
      <img
        class="w-[100px] h-[100px] rounded-lg overflow-hidden"
        src="https://via.placeholder.com/100x100"
      />
      <div class="w-[100px] h-[100px] bg-[#f3f3f3] justify-center items-center inline-flex">
        <div class="w-7 h-7 relative flex-col justify-start items-start flex"></div>
      </div>
    </div> -->
    <wd-upload
      :file-list="fileList"
      image-mode="aspectFill"
      :action="action"
      @change="handleChange"
    ></wd-upload>
    <SectionHeading
      title="标签"
      custom-class="my-6"
      path="/pages/publish/tags/index"
    ></SectionHeading>
    <div class="flex-1"></div>
    <div class="w-full">
      <wd-button type="primary" :round="false" block @click="handleSubmit">发布</wd-button>
    </div>
  </div>
</template>
