<script lang="ts" setup>
import { useI18n } from '@/composables/useI18n'

const props = defineProps<{
	hasExecutionData: boolean
	isRunning: boolean
	finalResultText: string
	finalResultValue: unknown
}>()

const { t } = useI18n()

const editorValue = () => props.finalResultText || '-'
</script>

<template>
	<div class="tab-pane tab-pane--scroll">
		<div v-if="!hasExecutionData" class="empty-state">
			{{ t('pages.runWorkflow.resultPanel.empty') }}
		</div>
		<div v-else-if="isRunning && !finalResultText" class="running-state">
			<div class="running-state__header">
				<div class="running-state__signal">
					<span></span>
					<span></span>
					<span></span>
				</div>
				<div>
					<div class="running-state__title">
						{{ t('pages.runWorkflow.resultPanel.runningTitle') }}
					</div>
					<div class="running-state__desc">
						{{ t('pages.runWorkflow.resultPanel.runningDesc') }}
					</div>
				</div>
			</div>
			<div class="running-state__skeleton">
				<div class="skeleton-line skeleton-line--lg"></div>
				<div class="skeleton-line"></div>
				<div class="skeleton-line"></div>
				<div class="skeleton-line skeleton-line--sm"></div>
			</div>
		</div>
		<div v-else class="panel" :class="{ 'panel--running': isRunning }">
			<div class="section-title">{{ t('pages.runWorkflow.resultPanel.output') }}</div>
			<div class="editor-shell">
				<div v-if="isRunning" class="editor-shell__scanner"></div>
				<CodeEditor
					:model-value="editorValue()"
					language="json"
					:tools="true"
					:read-only="true"
					:allow-change-language="false"
					:height="300"
				/>
			</div>
		</div>
	</div>
</template>

<style lang="less" scoped>
.tab-pane {
	height: 100%;
	min-height: 0;
	margin-top: 16px;
}

.tab-pane--scroll {
	padding: 0 16px 16px;
	overflow-y: auto;
}

.empty-state {
	padding: 24px 16px;
	border-radius: 12px;
	background: #f8fafc;
	color: #667085;
	line-height: 1.6;
}

.running-state {
	position: relative;
	padding: 18px 16px;
	border-radius: 16px;
	overflow: hidden;
	background:
		radial-gradient(circle at top left, rgba(59, 130, 246, 0.16), transparent 38%),
		linear-gradient(180deg, #f8fbff 0%, #eef5ff 100%);
	border: 1px solid #cfe0ff;
	box-shadow:
		0 14px 28px rgba(37, 99, 235, 0.08),
		inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.running-state::after {
	content: '';
	position: absolute;
	inset: 0;
	background: linear-gradient(
		110deg,
		transparent 0%,
		rgba(255, 255, 255, 0.55) 45%,
		transparent 70%
	);
	transform: translateX(-100%);
	animation: shimmer 2s linear infinite;
	pointer-events: none;
}

.running-state__header {
	display: flex;
	align-items: center;
	gap: 14px;
	margin-bottom: 18px;
}

.running-state__signal {
	display: flex;
	align-items: flex-end;
	gap: 5px;
	height: 28px;
}

.running-state__signal span {
	width: 6px;
	border-radius: 999px;
	background: linear-gradient(180deg, #2563eb 0%, #60a5fa 100%);
	animation: bounce 0.9s ease-in-out infinite;
}

.running-state__signal span:nth-child(1) {
	height: 12px;
}

.running-state__signal span:nth-child(2) {
	height: 22px;
	animation-delay: 0.15s;
}

.running-state__signal span:nth-child(3) {
	height: 16px;
	animation-delay: 0.3s;
}

.running-state__title {
	font-size: 14px;
	font-weight: 600;
	color: #1d4ed8;
}

.running-state__desc {
	margin-top: 4px;
	font-size: 12px;
	color: #5b6b8a;
}

.running-state__skeleton {
	display: grid;
	gap: 10px;
}

.skeleton-line {
	position: relative;
	height: 12px;
	border-radius: 999px;
	background: rgba(148, 163, 184, 0.18);
	overflow: hidden;
}

.skeleton-line::after {
	content: '';
	position: absolute;
	inset: 0;
	background: linear-gradient(
		90deg,
		transparent 0%,
		rgba(255, 255, 255, 0.92) 50%,
		transparent 100%
	);
	transform: translateX(-100%);
	animation: shimmer 1.8s ease-in-out infinite;
}

.skeleton-line--lg {
	width: 92%;
}

.skeleton-line--sm {
	width: 58%;
}

.panel {
	padding: 14px;
	border-radius: 16px;
	background: linear-gradient(180deg, #f8fafc 0%, #f4f7fb 100%);
	border: 1px solid #e4e7ec;
	box-shadow:
		0 8px 24px rgba(15, 23, 42, 0.04),
		inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.panel--running {
	border-color: #bfdbfe;
	box-shadow:
		0 10px 30px rgba(37, 99, 235, 0.08),
		inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.section-title {
	margin-right: auto;
	font-size: 14px;
	font-weight: 600;
	color: #344054;
	margin-bottom: 12px;
}

.editor-shell {
	position: relative;
	border-radius: 14px;
	overflow: hidden;
	background: #fff;
	border: 1px solid #d0d5dd;
}

.editor-shell__scanner {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	height: 56px;
	background: linear-gradient(180deg, rgba(96, 165, 250, 0.18) 0%, rgba(96, 165, 250, 0) 100%);
	transform: translateY(-100%);
	animation: scan 2.4s linear infinite;
	pointer-events: none;
	z-index: 1;
}

@keyframes shimmer {
	100% {
		transform: translateX(100%);
	}
}

@keyframes bounce {
	0%,
	100% {
		transform: scaleY(0.75);
		opacity: 0.6;
	}

	50% {
		transform: scaleY(1);
		opacity: 1;
	}
}

@keyframes scan {
	100% {
		transform: translateY(320px);
	}
}
</style>
