<template>
  <div class="container">
    <UploadBox ref="uploadBoxRef" @file-content="updateResult" />
    <accessoryThree ref="accessoryThreeRef" @json-content="updateJsonData" />

    <!-- 分析按钮及弹窗 -->
    <div class="analysis-btn-wrapper">
      <el-button
        type="primary"
        class="analysis-btn"
        @click="dialogVisible = true"
      >
        开始分析
      </el-button>

      <el-dialog
        v-model="dialogVisible"
        title="信息"
        width="640"
        :before-close="handleClose"
      >
        <el-form label-width="100px" label-position="right">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="风场名称：">
                <el-input v-model="windinput" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="风机名称：">
                <el-input v-model="faninput" placeholder="请输入" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="叶片编号：">
                <el-input v-model="bladeinput" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="叶片品牌：">
                <el-input v-model="bladeBrandInput" placeholder="请输入" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="叶片长度：">
                <el-input
                  v-model="bladeLengthInput"
                  @input="(val) => onInput('bladeLengthInput', val)"
                  placeholder="请输入"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="最大弦长：">
                <el-input
                  v-model="ratedPowerInput"
                  @input="(val) => onInput('ratedPowerInput', val)"
                  placeholder="请输入"
                />
              </el-form-item>
            </el-col>

            <!-- 材料单独一行 -->
            <el-col :span="24">
              <el-form-item label="材料：">
                <el-input
                  v-model="materialInput"
                  placeholder="请输入"
                  style="width: 520px"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>

        <template #footer>
          <div
            class="dialog-footer"
            style="text-align: center; margin-top: 10px"
          >
            <el-button type="primary" @click="Confirm">确定</el-button>
          </div>
        </template>
      </el-dialog>
    </div>
  </div>
</template>

<script lang="ts" setup>
// === 上传 STFTData / ZhuData ===
function handleJsonContent(data: any) {
  uploadedData.value = {
    STFTData: data.STFTData || [],
    zhudata: data.ZhuData || [],
  };
  ElMessage.success("STFTData / ZhuData 已上传");
}

// 上传回调（保持原样）
function updateResult(content: string) {
  uploadedContent.value = content;
  ElMessage.success("结果文件已上传");
}

function updateJsonData(data: any) {
  if (Array.isArray(data)) {
    uploadedJsonData.value = data;
  } else if (data.TimeDomainData) {
    uploadedJsonData.value = data.TimeDomainData;
  }
  ElMessage.success("时域数据已上传");
}
</script>
