<template>
    <div class="bg-white w-full">
        <div class="w-full">
            <!-- Content -->
            <div class="p-4">
                <div class="space-y-6">
                    <!-- 输入变量 -->
                    <InputVariables v-model="formData.inputVariables" />

                    <!-- 代码编辑器 -->
                    <CodeEditor v-model="formData.code" v-model:language="formData.language"
                        value-format="javascript" />

                    <!-- 输出变量 -->
                    <OutputVariables v-model="formData.outputVariables" />

                    <!-- 测试配置 -->
                    <TestConfig v-model="formData.testConfig" />

                    <!-- 异常处理 -->
                    <ErrorHandling v-model="formData.errorHandler" />
                </div>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { reactive } from 'vue'
import InputVariables from '@/components/SetterCommon/Code/InputVariables.vue'
import CodeEditor from '@/components/SetterCommon/Code/CodeEditor.vue'
import OutputVariables from '@/components/SetterCommon/Code/OutputVariables.vue'
import TestConfig from '@/components/SetterCommon/Code/TestConfig.vue'
import ErrorHandling from '@/components/SetterCommon/Code/ErrorHandling.vue'
interface Variable {
    id: string
    name: string
}

interface OutputVariable {
    id: string
    name: string
    type: string
}

interface TestConfigData {
    retryEnabled: boolean
    maxRetries: number
    retryInterval: number
}

interface ErrorHandler {
    errorHandling: string
    errorCodeReturn: string,
    language: string
}

// const props = withDefaults(defineProps<{
// }>(), {
// })
//
// const emit = defineEmits<{
// }>()

const formData = reactive({
    // 输入变量, 变量默认值
    inputVariables: [
        // { id: 'var_1', name: 'arg1' },
    ] as Variable[],
    // 代码内容
    code: ``,
    // 编程语言
    language: 'javascript',
    // 输出变量
    outputVariables: [
        // { id: 'output_1', name: 'result', type: 'String' }
    ] as OutputVariable[],
    // 测试配置
    testConfig: {
        retryEnabled: false,
        maxRetries: 0,
        retryInterval: 100,
    } as TestConfigData,
    // 错误补救
    errorHandler: {
        errorHandling: 'none',
        errorCodeReturn: '',
        language: 'javascript',
    } as ErrorHandler
})
</script>
