<template>
	<view>
		<cu-custom bgColor="bg-cyan" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">提示词</block>
		</cu-custom>
		
		<view class="cu-bar bg-white margin-top-xs">
			<view class="action sub-title">
				<text class="text-xl text-bold text-cyan text-shadow">收藏</text>
				<text class="text-ABC text-cyan">Favorite</text>
			</view>
		</view>
		<PromptList :promptList="promptFavor" @toggle-favor="getPromptFavor"></PromptList>
		
		<view class="cu-bar bg-white margin-top-xs">
			<view class="action sub-title">
				<text class="text-xl text-bold text-cyan text-shadow">常用</text>
				<text class="text-ABC text-cyan">Common</text>
			</view>
			<view class="action">
				<text class="text-cyan" @tap="$squni.navigateTo('/pages/main/prompt/prompt-list')">查看更多></text>
			</view>
		</view>
		<PromptList :promptList="promptCommon" @toggle-favor="getPromptFavor"></PromptList>
	</view>
</template>

<script>
	import PromptList from '@/components/prompt-list/prompt-list.vue'
	import { findPromptListApi } from '@/api/chat.js'
	export default {
		components: { PromptList },
		data() {
			return {
				promptFavor: [],
				promptCommon: []
			}
		},
		created() {
			findPromptListApi({ commonOpt: 1 }).then(({ status, data }) => {
				if (status === 'success') {
					this.promptCommon = data
				}
			})
		},
		onShow() {
			this.getPromptFavor()
		},
		methods: {
			getPromptFavor () {
				if (this.$store.getters.favorPromptList.length <= 0) {
					return
				}
				findPromptListApi({ ids: this.$store.getters.favorPromptList }).then(({ status, data }) => {
					if (status === 'success') {
						let map = {}
						data.forEach(x => map[x.id] = x)
						let list = []
						for(let id of this.$store.getters.favorPromptList) {
							list.push(map[id])
						}
						this.promptFavor = list
					}
				})
			}
		}
	}
</script>

<style lang="scss">
</style>
