<template>
	<template v-if="!jobList || jobList.length == 0">
		<a-empty style="height: 100vh;">
			<template #description>
				无收藏信息
			</template>
		</a-empty>
	</template>
	<template v-else>
		<a-row :gutter="[10,20]">
			<a-col span="8" v-for="(item, index) in jobList">
				<a-card :title="item.job_name">
					<template #extra>
						<a-button @click="cancelCollect(item.id,item.job_id)" type="primary">取消收藏</a-button>
					</template>
					<a-row>
						<a-col span="20">
							<div>企业名称：{{item.company_name}}</div>
							<div>收藏时间：{{item.created_at}}</div>
						</a-col>
						<a-col span="4">
							<a-popover trigger="click" placement="rightTop">
								<template #content>
									<job-detail v-if="detail_record" :detail_record="detail_record"></job-detail>
								</template>
								<a-button @click="detail(item.job_id)">详情</a-button>
							</a-popover>
						</a-col>
					</a-row>


				</a-card>
			</a-col>
		</a-row>
	</template>
</template>

<script setup lang="ts">
	import { ref, computed, onMounted, defineEmits, createVNode } from 'vue';
	import { GetJobseekListfavorite, PostJobseekDelfavorite } from '@/apis/models';
	import JobDetail from '@/components/jobseeker/invite/detail/index.vue'
	import { warnToast, successToast } from '@/utils/toastHelper';
	import { useCommon } from '@/hooks/useCommon';
	let { store, commomParams, dayjs, richOption, ExclamationCircleOutlined, Modal, showOtherModal1 } = useCommon();
	let loading = ref<Boolean>(true);
	let jobList = ref([]);
	let total = ref<Number>(0)


	const searchData = (data : object) => {
		commomParams.value.search = data
		getData();
	}

	const clearData = (data : object) => {
		if (data) {
			commomParams.value.search = data
		} else {
			commomParams.value.search = {
				page: 1,
				pagesize: 12,
				sort: 'id',
				sortby: 'asc',
				keyword: ''
			}
		}
		getData();
	}


	const getPage = (page, pageSize) => {
		commomParams.value.search.page = page;
		commomParams.value.search.pagesize = pageSize;
		getData();
	}
	const getData = async () => {
		try {
			loading.value = true;
			let res = await GetJobseekListfavorite(commomParams.value.search);
			loading.value = false;
			jobList.value = res.data.jobapplicantfavorites;
			commomParams.value.page = {
				current: commomParams.value.search.page,
				pageSize: commomParams.value.search.pagesize,
				total: res.data.total,
				pageSizeOptions: ['10', '20', '30', '40'],
				hideOnSinglePage: false,
				showSizeChanger: true
			};
		} catch {
			loading.value = false;
		}
	}

	const cancelCollect = (id : Number, job_id : Number) => {
		Modal.confirm({
			title: `是否要取消收藏该职位`,
			centered: true,
			icon: createVNode(ExclamationCircleOutlined),
			onOk() {
				PostJobseekDelfavorite({ id: id, job_id: job_id }).then(res => {
					successToast('已取消收藏')
					getData();
				})
			},
			onCancel() {

			},
		});
	}

	let detail_record = ref<Object>(null)
	const detail = (record) => {
		detail_record.value = record;
	}


	onMounted(() => {
		getData();
	})
</script>

<style lang="less" scoped>
	.job-box {
		display: flex;
		flex-direction: column;
		justify-content: space-around;
		// align-items: center;
		width: 100%;

		.job-title {
			padding: 20px;
			background-color: #ffffff;

			.aaaa {
				display: flex;
				justify-content: space-between;
			}
		}

		.job-company {
			padding: 20px;
			background-color: #cccccc;

			.aaaa {
				display: flex;
				justify-content: space-between;
			}
		}

	}

	.mt10 {
		margin-bottom: 10px;
	}
</style>