<template>
    <div class="sketch">
		<div class="detailText">{{$t('DesignPrintOperation.CurrentSketch')}}</div>
		<div class="select_sketch" v-if="selectDetail.id">
			<!-- <img :src="selectDetail?.sketchString?selectDetail?.sketchString:selectDetail.path" alt=""> -->
			<img :src="selectDetail.path" alt="">
			<!-- <img :src="selectDetail.sketchString || selectDetail.path" alt=""> -->
			<!-- <i :title="$t('DesignDetail.editSketchTitle')" class="fi fi-rs-pencil-paintbrush" @click.stop="openAddDetail"></i> -->
		</div>
		<div class="select_sketch" v-else>
			<div>
				<i class="fi fi-rr-picture centent"></i>
			</div>
		</div>
		<selectList @selectImgItem="selectImgItem" source="detail" ref="selectList" level1Type="Sketchboard" type="sketch" :catecoryList="sketchCatecoryList"></selectList>
    </div>
</template>
<script lang="ts">
import { defineComponent,computed,ref,provide,nextTick,createVNode,toRefs, reactive} 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 { useI18n } from 'vue-i18n'
// import sketchCategory from "@/component/HomePage/sketchCategory.vue";
import selectList from './module/selectList.vue'

export default defineComponent({
    components:{
		selectList,
    },
	emit:['addDetail'],
    setup(props,{emit}) {
        const store = useStore();
		const detailData = reactive({
			selectTitle:'current',
			selectDetail:computed(()=>store.state.DesignDetail.selectDetail),
			designDetail:computed(()=>store.state.DesignDetail.designDetail),
			sketchCatecoryList:computed(()=>{
				return store.state.Workspace.probjects.positionList
			}),
			currentDetailType:computed(()=>store.state.DesignDetail.currentDetailType)
		})
		const getDetailListData = reactive({
			total:0,
			pageSize:10,
			currentPage:1,
		})
		const getDetailListDom = reactive({
			selectList:null as any,
		})
		const openCurrent = ()=>{
			detailData.selectTitle = 'current'
		}
		const openUpload = ()=>{
			detailData.selectTitle = 'upload'
		}
		const sketchSysToLibrary = ()=>{
			if(getDetailListDom.selectList.selectTitle == 'library')return
			getDetailListDom.selectList.openLibrary()
		}
		const hasDuplicateId = (id:any)=>{
			let arr = detailData.designDetail.clothes
			for (let i = 0; i < arr.length; i++) {
				if (arr[i].id === id) {
				return true;
				}
			}
			return false;
		}
		const selectImgItem = (data:any)=>{
			let randomNum = Math.floor(100 + Math.random() * 900);
			let id = data.id
			id = Number(data.id + (randomNum + ''))
			if(hasDuplicateId(id)){
				selectImgItem(data)
				return
			}
			if(data?.imgUrl)data.url = data.imgUrl
			let value = {
				data,
				id,
			}
			if(detailData.currentDetailType == 'sketch'){
				detailData.selectDetail.sketchString = ''
			}
			store.commit('DesignDetail/setNewDetail',value)
		}
		const openAddDetail = ()=>{
			emit('addDetail')
		}
        return{
			...toRefs(detailData),
			...toRefs(getDetailListData),
			...toRefs(getDetailListDom),

			openCurrent,
			openUpload,
			sketchSysToLibrary,
			selectImgItem,
			openAddDetail,
        }
    },

	provide() {
		return {
		}
	},
		
})
</script>
<style lang="less" scoped>
    .sketch{
		// width: 34rem;
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		> .detailText{
			margin-bottom: 1rem;
			text-align: left;
		}
		> .select_sketch{
			width: 100%;
			height: 23.5rem;
			padding: 1rem 0;
			text-align: center;
			border-radius: .5rem;
			border: 1px solid #000;
			// border: 1px dashed transparent;
			border-radius: 1.5rem;
			position: relative;
        	background: linear-gradient(#fff, #fff) padding-box,repeating-linear-gradient(-45deg,#fff 0,#fff 0.3em,	#000 0,#000 0.6em);
			margin-bottom: 1.4rem;
			> img{
				width: 100%;
				height: 100%;
				object-fit: contain;
			}
			> i{
				position: absolute;
				left: auto;
				right: 1rem;
				top: 2rem;
				font-size: 2rem;
				cursor: pointer;
			}
			> div{
				height: 100%;
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: center;
				> i{
					font-size: 10rem;
				}
			}
		}
		> .switch_type_list{
			display: flex;
			margin-bottom: 2.5rem;
			> .switch_type_item:last-child{
				margin-right: 0;
			}
			> .switch_type_item{
				position: relative;
				cursor: pointer;
				margin-right: 6.5rem;
			}
			> .switch_type_item::before {
                    position: absolute;
                    content: "";
                    display: block;
                    background: #000;
                    height: calc(.4rem*1.2);
                    left: 50%;
                    transform: translateX(-50%);
                    bottom: -.5rem;
                    width: 0px;
                    transition: 0.3s all;
                }
			> .select_swtich {
				color: #000;
				font-weight: 600;
			}
			> .select_swtich::before {
				width: 100%;
			}
		}
		> .sketch_content_list{
			flex: 1;
			overflow: hidden;
			> .content_item{
				height: 100%;
				margin-top: 1rem;
			}
		}
	}
</style>