<template>
    <div class="modelindex">
		<div class="modelindex_left">
			<modelNav @canvasReload="()=>$emit('canvasReload')" @addSketch="()=>$emit('addSketch')" @deleteItem="deleteItem"></modelNav>
		</div>
		<div class="modelindex_right">
			<div class="detail_btn">
				<!-- 全屏 --> 
				<!-- <i class="fi fi-bs-expand-arrows-alt" @click="showDesignImgDetail('2')"></i> -->

				<i v-show="true" class="icon iconfont icon-chehui" @click="revocation"></i>
				<i v-show="true" class="icon iconfont icon-fanchehui" @click="oppositeRevocation"></i>
				<!-- 编辑 -->
				<i class="fi fi-rr-edit" :title="$t('DesignDetail.editTitle')" :class="{active:isEditPattern.value}" @click="showDesignImgDetail('edit')"></i>
				<!-- <i class="fi fi-rr-copy" :title="$t('DesignDetail.compareTitle')" :class="{active:imgDesignImg}" @click="mousedownDesignImg"></i> -->
				<!-- <i v-show="!body && !deleteShow" :title="$t('DesignDetail.DetailTitle')" class="fi fi-rr-trash" @click="deleteNav(0)"></i>
				<i v-show="!body && deleteShow" class="fi fi-br-check" @click="deleteNav(1)"></i> -->

				<!-- 层 -->
				<i class="fi fi-rr-copy" :title="$t('DesignDetail.compareTitle')" @mousedown="mousedownDesignImg" @mouseup="mousedownDesignImg" @touchstart="mousedownDesignImg" @touchend="mousedownDesignImg"></i>
				
			</div>
			<position ref="position" @canvasReload="()=>$emit('canvasReload')" :imgDesignImg=imgDesignImg></position>
		</div>
		
    </div>
</template>
<script lang="ts">
import { defineComponent,computed,ref,inject,onBeforeUnmount,createVNode,toRefs, reactive, onMounted} from 'vue'
// import setDesignItem from '@/component/Detail/setDesignItem2.vue'
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import { Https } from "@/tool/https";
import { useStore } from "vuex";
import { Modal,message } from 'ant-design-vue';
import { useI18n } from 'vue-i18n'
import position from './modelPosition.vue';
import modelNav from './modelNav.vue';
export default defineComponent({
    components:{
		position,modelNav
    },
	emits:['detailEdit','canvasReload','addSketch','revocation','oppositeRevocation'],
    setup(props,{emit}) {
		const {t} = useI18n()
        const store = useStore();
		const detailData = reactive({
			getCanvasIfEdit:inject('getCanvasIfEdit')as any,
		})
		const setRevocation:any = inject('setRevocation')
		const getDetailListData = reactive({
			designDetail:computed(()=>store.state.DesignDetail.designDetail),
			isEditPattern:inject('isEditPattern') as any,
			imgDesignImg:false,
		})
		const getDetailListDom = reactive({
			libraryList:null as any,
			position:null as any,
		})
		const getSubmitData = (value:any)=>{
			return getDetailListDom.position.getSubmitData(value)
		}
		const showDesignImgDetail = (str:any)=>{
			new Promise((resolve, reject) => {
				// if(
				// 	getDetailListData.isEditPattern.value&&
				// 	detailData?.getCanvasIfEdit?.fun&&detailData?.getCanvasIfEdit?.fun() > 0
				// ){
				// 	Modal.confirm({
				// 		title: t('collectionModal.jsContent2'),
				// 		icon: createVNode(ExclamationCircleOutlined),
				// 		okText: 'Yes',
				// 		cancelText: 'No',
				// 		mask:false,
				// 		centered:true,
				// 		onOk() {
				// 			resolve(true)
				// 			emit('detailEdit',str)
				// 		},
				// 		onCancel(){
				// 			resolve(false)
				// 		}
				// 	});
				// }else{
					resolve(true)
					emit('detailEdit',str)
				// }
			})
		}
		const deleteItem = ()=>{
			setRevocation()
		}
		const revocation = ()=>{//撤回
			emit('revocation')
			getDetailListDom.position.updataPosition()
		}
		const oppositeRevocation = ()=>{//反撤回
			emit('oppositeRevocation')
			getDetailListDom.position.updataPosition()
		}
	
		//图片按下样子
		const mousedownDesignImg = ()=>{
			getDetailListData.imgDesignImg = !getDetailListData.imgDesignImg
		}
		let time = null as any

		const handleResize = ()=>{
			clearTimeout(time)
			time = setTimeout(()=>{
				store.commit('DesignDetail/setDesignDetail',getDetailListData.designDetail)
				getDetailListDom.position.updataPosition()

			},1000)
		}
		onMounted(()=>{
			window.addEventListener('resize', handleResize);
		})
		onBeforeUnmount(()=>{
			window.removeEventListener('resize', handleResize);
		})
        return{
			...toRefs(detailData),
			...toRefs(getDetailListData),
			...toRefs(getDetailListDom),
			getSubmitData,
			showDesignImgDetail,
			revocation,
			deleteItem,
			oppositeRevocation,
			mousedownDesignImg,
        }
    },

	provide() {
		return {
		}
	},
		
})
</script>
<style lang="less" scoped>
    .modelindex{
		width: 100%;
		height: 100%;
		display: flex;
		// padding-top: 3rem;
		flex: 1;
		overflow: hidden;
		.modelindex_right,.modelindex_left{
			display: flex;
			flex-direction: column;
			align-items: center;

			justify-content: center;
		}
		> .modelindex_right{
			flex: 1;
			overflow: hidden;

			> .detail_btn{
				width: 100%;
				display: flex;
				justify-content: space-between;
				border-radius: 1rem;
				padding: .7rem ;
				flex-shrink: 0;
				overflow: hidden;
				// max-height: 4rem;
				position: relative;
				z-index: 99;
				> i{
					font-size: 2rem;
					cursor: pointer;
					// padding: 1.5rem;
					display: flex;
					align-items: center;
					border-radius: .6rem;
					overflow: hidden;
					transition: all .3s;
					width: 4rem;
					height: 4rem;
					justify-content: center;
					@media (min-width: 1024px) {
						font-size: 2.4rem;
					}
				}
				> i:hover{
					background: #000000;
					color: #fff;
				}
				> .active{
					background: #000000;
					color: #fff;
				}	
			}
		}
		.modelindex_left{
			justify-content: center;
		}
	
	}
</style>