<script lang="ts">
import { defineComponent } from "vue";
export default defineComponent({
  name: "ModelTrainForm",
});
</script>

<script setup lang="ts">
import Icon from "@/components/Module/Icon/index.vue";
import {
  Form,
  FormItem,
  Row,
  Col,
  Upload,
  Select,
  SelectOption,
  Switch,
  Input,
  InputNumber,
  Textarea,
} from "ant-design-vue";
import { ref, onMounted } from "vue";

interface PropsType {
  formData: Record<string, any>;
  rules: Record<string, any>;
}

const props = withDefaults(defineProps<PropsType>(), {
  formData: () => {
    return {};
  },
  rules: () => {
    return {};
  },
});

const emits = defineEmits(["init"]);

const formRef = ref();

// 上传
const onUpload = (e: File) => {
  props.formData.file = e;
  console.log("props.formData", props.formData);
  return false;
};

defineExpose({
  formRef,
});

onMounted(() => {
  emits("init", formRef.value);
});

const prefix = "model-form";
</script>

<template>
  <div :class="prefix">
    <Form :model="props.formData" ref="formRef" layout="vertical" :rules="props.rules">
      <Row :gutter="[10, 24]">
        <Col :span="24">
          <FormItem label="模型压缩包" name="file" class="upload-row">
            <Upload
              :multiple="false"
              :before-upload="onUpload"
              :max-count="1"
              accept=".zip, .tar.gz, .tgz"
            >
              <div class="upload-box">
                <div class="upload-box-icon">
                  <Icon name="fileUpload" />
                </div>
                <div class="upload-box-title">点击上传</div>
              </div>
              <div class="upload-desc">支持.zip, .tar.gz, .tgz格式</div>
            </Upload>
          </FormItem>
        </Col>
        <Col :span="24">
          <FormItem label="模型名称" name="name">
            <Input v-model:value="props.formData.name" placeholder="请输入" />
          </FormItem>
        </Col>
        <Col :span="24">
          <FormItem label="python环境激活脚本" name="script">
            <Textarea
              v-model:value="props.formData.script"
              placeholder="请输入"
              :autoSize="{
                minRows: 3,
              }"
            />
          </FormItem>
        </Col>
        <!-- <Col :span="24">
          <FormItem label="启用状态" name="modelId">
            <Switch
              checked-children="启用"
              un-checked-children="停用"
              v-model:checked="props.formData.status"
            />
          </FormItem>
        </Col> -->
      </Row>
    </Form>
  </div>
</template>

<style lang="scss" scoped>
$prefix: "model-form";

.#{$prefix} {
  width: 100%;
  height: 100%;
  overflow: auto;
  overflow-x: hidden;

  &-wrapper {
    width: 100%;
    &:last-child {
      :deep(.ant-form-item) {
        margin-bottom: 0;
      }
    }
  }
  &-title {
    font-family:
      Source Han Sans,
      Source Han Sans;
    font-weight: 400;
    font-size: 14px;
    color: #374151;
    line-height: 20px;
    text-align: left;
    font-style: normal;
    text-transform: none;
    margin-bottom: 8px;
  }

  :deep(.ant-form-item) {
    margin-bottom: 0;
    // .ant-form-item-label {
    //   padding: 0;
    //   margin-bottom: 4px;
    //   label {
    //     font-family:
    //       Source Han Sans,
    //       Source Han Sans;
    //     font-weight: 350;
    //     font-size: 12px;
    //     color: #4b5563;
    //     line-height: 16px;
    //     text-align: left;
    //     font-style: normal;
    //     text-transform: none;
    //   }
    // }
  }
  &-row {
    display: flex;
    align-items: start;
    justify-content: start;
    gap: 16px;
    flex-wrap: wrap;
  }
  &-grid {
    &--full {
      width: 100%;
    }
    &--half {
      width: calc((100% - 16px) / 2);
    }
    &--third {
      width: calc((100% - 16px * 2) / 3);
    }
  }
  .no-row-gap {
    row-gap: 0;
  }
  .edit-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 10px;
    cursor: pointer;
    color: #979797;
    &:hover {
      color: #2563eb;
    }
  }
  .upload-row {
    .ant-upload-wrapper {
      display: block;
      :deep(.ant-upload) {
        width: 100%;
      }
    }
    .ant-upload-select {
      width: 100%;
      .upload-box {
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        font-size: 16px;
        color: #8a8a8a;
        width: 100%;
        aspect-ratio: 537 / 91;
        border-radius: 6px 6px 6px 6px;
        border: 1px solid #d9d9d9;
        background: rgba(200, 200, 200, 0.2);
        &-icon {
        }
        &-title {
        }
      }
    }
    .upload-desc {
      font-family:
        Source Han Sans,
        Source Han Sans;
      font-weight: 400;
      font-size: 12px;
      color: #c8c8c8;
      line-height: 26px;
      text-align: justify;
      font-style: normal;
      text-transform: none;
    }
  }
}
</style>
