<template>
	<div class="sc-workflow-design">
		<div class="zoom-scale">
			<el-button circle icon="plus" :disabled="zoom >= 150" @click="onZoom(1)" />
			<span>{{ zoom }}%</span>
			<el-button circle icon="minus" :disabled="zoom <= 40" @click="onZoom(-1)" />
		</div>
		<div class="box-scale" :style="`transform: scale(${zoom / 100})`">
			<node-wrap v-if="nodeConfig" v-model="nodeConfig" :disabled="disabled"></node-wrap>
		</div>
		<use-select
			v-if="selectVisible"
			v-bind="active_selectOpts"
			ref="useselect"
			@update:selected="update_activeSelected"
			@closed="selectVisible = false"
		></use-select>
	</div>
</template>

<script>
import nodeWrap from './nodeWrap'
import useSelect from './select'
// import promoter from '@/components/scWorkflow/nodes/promoter.vue'

export default {
	name: 'ScWorkflow',
	components: {
		// promoter,
		nodeWrap,
		useSelect
	},
	provide() {
		return {
			select: this.selectHandle,
			getRootConfig: this.getCurrentConfig,
			getProcessForm: this.getProcessForm
		}
	},
	props: {
		modelValue: { type: Object, default: () => {} },
		disabled: {
			type: Boolean,
			default: false
		},
		processForm: {
			type: Object,
			default: () => ({})
		}
	},
	data() {
		return {
			zoom: 100,
			nodeConfig: this.modelValue,
			selectVisible: false,
			active_selectOpts: {
				// maxSelected
				// minSelected
			},
			activeSelected: [] /*,
			end_nodeConfig: {
				nodeName: '结束'
				// nodeName: '发起人',
				// type: 0,
				// nodeAssigneeList: []
			}*/
		}
	},
	watch: {
		modelValue(val) {
			this.nodeConfig = val
		},
		nodeConfig(val) {
			this.$emit('update:modelValue', val)
		}
	},
	mounted() {},
	methods: {
		getCurrentConfig() {
			return this.nodeConfig
		},
		getProcessForm() {
			return this.processForm || {}
		},
		update_activeSelected(newSelected) {
			this.activeSelected.splice(0, this.activeSelected.length, ...newSelected)
		},
		selectHandle(type, params) {
			// params: { assignees:{name, id}[], maxSelected: number, minSelected: number, ...others}
			this.active_selectOpts = params
			this.activeSelected = params.assignees
			this.selectVisible = true
			this.$nextTick(() => {
				this.$refs.useselect.open(type, params.assignees)
			})
		},
		onZoom(n) {
			this.zoom += 10 * n
			if (this.zoom <= 40) {
				this.zoom = 40
			} else if (this.zoom >= 150) {
				this.zoom = 150
			}
		}
	}
}
</script>

<style lang="scss">
$bg_color: #f6f8f9;
.sc-workflow-design {
	height: 100%;
	background: $bg_color;
	//width: 100%;
	.box-scale {
		transform-origin: 50% 0px 0px;
	}

	.zoom-scale {
		z-index: 999;
		position: fixed;
		top: 178px;
		right: 40px;

		span {
			margin: 0 10px;
			font-size: 15px;
			color: #7a7a7a;
			width: 50px;
		}
	}
}
.sc-workflow-design .box-scale {
	display: inline-block;
	position: relative;
	width: 100%;
	min-height: 100%;
	padding: 54.5px 0;
	align-items: flex-start;
	justify-content: center;
	flex-wrap: wrap;
	min-width: min-content;
	background: $bg_color;
}

.sc-workflow-design {
	.node-wrap {
		display: inline-flex;
		width: 100%;
		flex-flow: column wrap;
		justify-content: flex-start;
		align-items: center;
		padding: 0px 50px;
		position: relative;
		z-index: 1;
		& + .node-wrap {
			.node-wrap-box.end-node:before {
				content: '';
			}
		}
	}
	.node-wrap-box {
		display: inline-flex;
		flex-direction: column;
		position: relative;
		width: 220px;
		min-height: 72px;
		flex-shrink: 0;
		background: rgb(255, 255, 255);
		border-radius: 4px;
		cursor: pointer;
		box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.1);
		&--disabled {
			cursor: default;
			/*.content {
        color: var(--el-text-color-disabled);
      }*/
			.title_label {
				&:hover {
					text-decoration-line: none !important;
				}
			}
		}
		// 已执行
		&--success {
			.title {
				background: var(--el-color-success) !important;
			}
		}
		// 执行中
		&--error {
			.title {
				background: var(--el-color-warning) !important;
			}
		}
		// 未执行
		&--info {
			.title {
				background: var(--el-color-info) !important;
			}
		}
		&.start-node,
		&.end-node {
			.title_label {
				&:hover {
					text-decoration-line: none;
				}
			}
		}
	}
	.node-wrap-box::before {
		content: '';
		position: absolute;
		top: -12px;
		left: 50%;
		transform: translateX(-50%);
		width: 0px;
		border-style: solid;
		border-width: 8px 6px 4px;
		border-color: rgb(202, 202, 202) transparent transparent;
		background: $bg_color;
	}
	.node-wrap-box.start-node:before,
	.node-wrap-box.end-node:before {
		content: none;
	}
	.node-wrap-box .title {
		height: 24px;
		line-height: 24px;
		color: #fff;
		padding-left: 16px;
		padding-right: 30px;
		border-radius: 4px 4px 0 0;
		position: relative;
		display: flex;
		align-items: center;
		&_label {
			display: inline-flex;
			align-items: center;
			&:hover {
				text-decoration-line: underline;
			}
			.edit-icon {
				margin-left: 4px;
			}
		}
	}
	.node-wrap-box .title .icon {
		margin-right: 5px;
	}
	.node-wrap-box .title .close {
		font-size: 15px;
		position: absolute;
		top: 50%;
		transform: translateY(-50%);
		right: 10px;
		display: none;
	}
	.node-wrap-box .content {
		position: relative;
		padding: 15px;
	}
	.node-wrap-box .content .placeholder {
		color: #999;
	}
	.node-wrap-box:hover .close {
		display: block;
	}
	.add-node-btn-box {
		width: 240px;
		display: inline-flex;
		flex-shrink: 0;
		position: relative;
		z-index: 1;
	}
	.add-node-btn-box:before {
		content: '';
		position: absolute;
		top: 0px;
		left: 0px;
		right: 0px;
		bottom: 0px;
		z-index: -1;
		margin: auto;
		width: 2px;
		height: 100%;
		background-color: rgb(202, 202, 202);
	}
	.add-node-btn {
		user-select: none;
		width: 240px;
		padding: 20px 0px 32px;
		display: flex;
		justify-content: center;
		flex-shrink: 0;
		flex-grow: 1;
	}
	.add-node-btn span {
	}
	.add-branch {
		justify-content: center;
		padding: 0px 10px;
		position: absolute;
		top: -16px;
		left: 50%;
		transform: translateX(-50%);
		transform-origin: center center;
		z-index: 1;
		display: inline-flex;
		align-items: center;
	}
	.branch-wrap {
		display: inline-flex;
		width: 100%;
		&--disabled {
			.branch-box {
				margin-top: 0;
			}
			.add-branch {
				display: none;
			}
			.auto-judge {
				cursor: default;
				&:hover {
					.close {
						display: none;
					}
					.priority-title {
						display: block;
						//display: none;
					}
					&:after {
						border: unset;
						box-shadow: unset;
					}
					.sort-left {
						display: none;
					}
					.sort-right {
						display: none;
					}
				}
			}
		}

		/*// 已执行
		&--success {
			.auto-judge:after {
				border: 1px solid var(--el-color-success) !important;
			}
			//.title {
			//  //background: var(--el-color-success) !important;
			//}
		}
		// 执行中
		&--error {
			.auto-judge:after {
				border: 1px solid var(--el-color-error) !important;
			}
			!*      .title {
        background: var(--el-color-error) !important;
      }*!
		}
		// 未执行
		&--info {
			.auto-judge:after {
				border: 1px solid var(--el-color-info) !important;
			}
			!*.title {
        background: var(--el-color-info) !important;
      }*!
		}*/
	}
	.branch-box-wrap {
		display: flex;
		flex-flow: column wrap;
		align-items: center;
		min-height: 270px;
		width: 100%;
		flex-shrink: 0;
	}
	.col-box {
		display: inline-flex;
		flex-direction: column;
		align-items: center;
		position: relative;
		background: $bg_color;
	}
	.branch-box {
		display: flex;
		overflow: visible;
		min-height: 180px;
		height: auto;
		border-bottom: 2px solid #ccc;
		border-top: 2px solid #ccc;
		position: relative;
		margin-top: 15px;
	}
	.branch-box .col-box::before {
		content: '';
		position: absolute;
		top: 0px;
		left: 0px;
		right: 0px;
		bottom: 0px;
		z-index: 0;
		margin: auto;
		width: 2px;
		height: 100%;
		background-color: rgb(202, 202, 202);
	}
	.condition-node {
		display: inline-flex;
		flex-direction: column;
		min-height: 220px;
	}
	.condition-node-box {
		padding-top: 30px;
		padding-right: 50px;
		padding-left: 50px;
		justify-content: center;
		align-items: center;
		flex-grow: 1;
		position: relative;
		display: inline-flex;
		flex-direction: column;
	}
	.condition-node-box::before {
		content: '';
		position: absolute;
		top: 0px;
		left: 0px;
		right: 0px;
		bottom: 0px;
		margin: auto;
		width: 2px;
		height: 100%;
		background-color: rgb(202, 202, 202);
	}
	.auto-judge {
		position: relative;
		width: 220px;
		min-height: 72px;
		background: rgb(255, 255, 255);
		border-radius: 4px;
		padding: 15px 15px;
		cursor: pointer;
		box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.1);
		// 已执行
		&--success:after {
			border: 1px solid var(--el-color-success) !important;
		}
		// 未执行
		&--info:after {
			border: 1px solid var(--el-color-info) !important;
		}
	}
	.auto-judge::before {
		content: '';
		position: absolute;
		top: -12px;
		left: 50%;
		transform: translateX(-50%);
		width: 0px;
		border-style: solid;
		border-width: 8px 6px 4px;
		border-color: rgb(202, 202, 202) transparent transparent;
		//background: rgb(245, 245, 247);
		background: $bg_color;
	}
	.auto-judge .title {
		line-height: 16px;
	}
	.auto-judge .title .node-title {
		color: var(--el-color-success);
		&.last-child-title {
			color: #999;
		}
	}
	.auto-judge .title .close {
		font-size: 15px;
		position: absolute;
		top: 15px;
		right: 15px;
		color: #999;
		display: none;
	}
	.auto-judge .title .priority-title {
		position: absolute;
		top: 15px;
		right: 15px;
		color: #999;
	}
	.auto-judge .content {
		position: relative;
		padding-top: 15px;
		&.last-child-title {
			padding-top: 5px;
			span {
				line-height: 1;
			}
		}
	}
	.auto-judge .content .placeholder {
		color: #999;
	}
	.auto-judge:hover {
		.close {
			display: block;
		}
		.priority-title {
			display: none;
		}
	}
	.top-left-cover-line,
	.top-right-cover-line {
		position: absolute;
		height: 3px;
		width: 50%;
		background-color: $bg_color;
		top: -2px;
	}
	.bottom-left-cover-line,
	.bottom-right-cover-line {
		position: absolute;
		height: 3px;
		width: 50%;
		background-color: $bg_color;
		bottom: -2px;
	}
	.top-left-cover-line {
		left: -1px;
	}
	.top-right-cover-line {
		right: -1px;
	}
	.bottom-left-cover-line {
		left: -1px;
	}
	.bottom-right-cover-line {
		right: -1px;
	}
	.end-node {
		//border-radius: 50%;
		//font-size: 14px;
		//color: rgba(25, 31, 37, 0.4);
		color: var(--el-text-color-disabled);
		//text-align: left;
	}
	/*.end-node-circle {
		width: 10px;
		height: 10px;
		margin: auto;
		border-radius: 50%;
		background: #dbdcdc;
	}
	.end-node-text {
		margin-top: 5px;
		text-align: center;
	}*/
	.auto-judge:hover {
		.sort-left {
			display: flex;
		}
		.sort-right {
			display: flex;
		}
	}
	.auto-judge .sort-left {
		position: absolute;
		top: 0;
		bottom: 0;
		z-index: 1;
		left: 0;
		display: none;
		justify-content: center;
		align-items: center;
		flex-direction: column;
	}
	.auto-judge .sort-right {
		position: absolute;
		top: 0;
		bottom: 0;
		z-index: 1;
		right: 0;
		display: none;
		justify-content: center;
		align-items: center;
		flex-direction: column;
	}
	.auto-judge .sort-left:hover,
	.auto-judge .sort-right:hover {
		background: #eee;
	}
	.auto-judge:after {
		pointer-events: none;
		content: '';
		position: absolute;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 2;
		border-radius: 4px;
		transition: all 0.1s;
	}
	.auto-judge:hover:after {
		border: 1px solid var(--el-color-primary);
		box-shadow: 0 0 6px 0 var(--el-color-primary-light-5);
	}
	.node-wrap-box:after {
		pointer-events: none;
		content: '';
		position: absolute;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 2;
		border-radius: 4px;
		transition: all 0.1s;
	}
	.node-wrap-box:not(.node-wrap-box--disabled):hover:after {
		border: 1px solid var(--el-color-primary);
		box-shadow: 0 0 6px 0 var(--el-color-primary-light-5);
	}
}

.tags-list {
	margin-top: 15px;
	width: 100%;
}
.add-node-popover-body {
	ul {
		padding: 0;
	}
}
.add-node-popover-body li {
	display: inline-block;
	width: 80px;
	text-align: center;
	padding: 10px 0;
}
.add-node-popover-body li i {
	border: 1px solid var(--el-border-color-light);
	width: 40px;
	height: 40px;
	border-radius: 50%;
	text-align: center;
	line-height: 38px;
	font-size: 18px;
	cursor: pointer;
}
.add-node-popover-body li i:hover {
	border: 1px solid var(--el-color-primary);
	background: var(--el-color-primary);
	color: #fff !important;
}
.add-node-popover-body li p {
	font-size: 12px;
	margin-top: 5px;
}
.node-wrap-drawer__title {
	padding-right: 40px;
}
.node-wrap-drawer__title label {
	cursor: pointer;
	font-size: 14px;
}
.node-wrap-drawer__title label:hover {
	border-bottom: 1px dashed var(--el-color-primary);
}
.node-wrap-drawer__title .node-wrap-drawer__title-edit {
	color: var(--el-color-primary);
	margin-left: 10px;
	vertical-align: middle;
}

.dark .sc-workflow-design {
	.box-scale {
		background: var(--el-bg-color);
	}
	/*.col-box {
    background: var(--el-bg-color);
  }*/
	.node-wrap-box,
	.auto-judge {
		background: #2b2b2b;
	}

	.top-left-cover-line,
	.top-right-cover-line,
	.bottom-left-cover-line,
	.bottom-right-cover-line {
		background-color: var(--el-bg-color);
	}
	.node-wrap-box::before,
	.auto-judge::before {
		background-color: var(--el-bg-color);
	}
	.branch-box .add-branch {
		background: var(--el-bg-color);
	}
	.end-node .end-node-text {
		color: #d0d0d0;
	}
	.auto-judge .sort-left:hover,
	.auto-judge .sort-right:hover {
		background: var(--el-bg-color);
	}
}

$header_height: 55px;
// drawer样式
.aDrawer {
	.el-drawer__header {
		display: flex;
		flex-shrink: 0;
		align-items: center;
		box-sizing: border-box;
		width: 100%;
		height: 48px;
		padding: 0 16px;
		margin-bottom: 0px;
		border-bottom: 1px solid var(--el-border-color-lighter);
		color: var(--el-overlay-color);
	}
	.el-drawer__body {
		box-sizing: border-box;
		height: 100%;
		padding: 12px 16px;
		overflow: auto;
		.el-main {
			padding: 0;
		}
		.el-footer {
			padding: 10px 0 0 0;
		}
	}
}

// 公用的样式
.svg-icon-box {
	position: absolute;
	bottom: -20px;
	right: 50%;
	background-color: rgb(255, 255, 255);
	padding: 10px;
	border-radius: 50%;
	margin-right: -18px;
	z-index: 99;
}
</style>
