<template>
  <div class="container">
    <div class="title">
      Edit Information
      <div></div>
    </div>
    <n-form ref="formRef" label-placement="left" label-align="left" :model="form" :rules="rules" size="large" require-mark-placement="left">
      <n-form-item :label="t('reportPop.phone')+'：'" path="contact">
        <n-input v-model:value="form.contact" type="number" :placeholder="t('reportPop.phonePlaceholder')" />
      </n-form-item>
      <n-form-item :label="t('reportPop.companyName')+'：'" path="companyName">
        <n-input v-model:value="form.companyName" type="text" :placeholder="t('reportPop.companyNamePlaceholder')" />
      </n-form-item>
      <n-form-item :label="t('reportPop.position')+'：'" path="addr">
        <n-input v-model:value="form.addr" type="text" :placeholder="t('reportPop.positionPlaceholder')" />
      </n-form-item>
      <n-form-item :label="t('reportPop.email')+'：'" path="email">
        <n-input v-model:value="form.email" type="text" :placeholder="t('reportPop.emailPlaceholder')" />
      </n-form-item>
    </n-form>
    <n-button class="login-btn" attr-type="button" type="info" color="#18A058" :disabled="submitLoading" @click="handleSure">
      {{ submitLoading ? t('reportPop.submitLoading') : t('reportPop.submit') }}
    </n-button>
  </div>
</template>

<script lang="ts" setup>
import { useI18n } from "#imports";
import { ref, reactive, onMounted } from "vue";
import {
  // NForm,
  // NFormItem,
  // NInput,
  // NButton,
  // FormRules,
  // FormItemRule,
  createDiscreteApi,
} from "naive-ui";
const emit = defineEmits(["closeSginDialog"]);
const props = defineProps({
  info: {
    type: Object,
    default: () => {},
  },
});
const { t } = useI18n();
const formRef = ref();
const submitLoading = ref(false);
const form = reactive({
  contact: "",
  companyName: "",
  addr: "",
  email: "",
});
const rules: FormRules = {
  contact: [
    {
      required: true,
      message: t("reportPop.phoneRequired"),
      trigger: ["input", "blur"],
    },
  ],
};
const handleSure = () => {
  formRef.value?.validate(async (errors: any) => {
    if (!errors) {
      submitLoading.value = true;
      try {
        const { code } = await updateInfo_Api(form);
        if (code === 200) {
          message.message.success(t("reportPop.submitSuccess"));
          emit("closeSginDialog", "success");
        }
      } catch (error) {}
      submitLoading.value = false;
    }
  });
};
// onMounted(() => {
for (let key in form) {
  form[key] = props.info[key];
}
// });
const message = createDiscreteApi(["message"]);
</script>

<style lang="scss" scoped>
@import "~/assets/css/tool.scss";
.container {
  padding: var(--size-30) var(--size-58) var(--size-45);
  background: #ffffff;
  border-radius: var(--size-20);
  .title {
    font-size: var(--size-38);
    font-family: Arial, Arial-Bold;
    font-weight: 700;
    text-align: center;
    color: #1a1a1a;
    > div {
      width: var(--size-71);
      height: var(--size-6);
      background: linear-gradient(90deg, #719d59 2%, #479f82 98%);
      border-radius: var(--size-3);
      margin: auto;
    }
  }
  .login-btn {
    width: 100%;
    height: var(--size-58);
    background: linear-gradient(90deg, #60ab91, #84a86c);
    border-radius: var(--size-8);
    font-size: var(--size-18);
    margin-top: var(--size-10);

    :deep(.n-button__content) {
      display: block;
    }
  }
  .n-form {
    margin-top: var(--size-30);
  }
  :deep(.n-form-item-blank) {
    border-bottom: var(--size-1) solid #e6e6e6;
  }
  :deep(.n-form-item-label) {
    color: #666666;
    font-size: var(--size-14);
    font-family: Microsoft YaHei, Microsoft YaHei-Regular;
    line-height: var(--size-20);
    padding: var(--size-10) var(--size-10) var(--size-10) 0;
    border-bottom: var(--size-1) solid #e6e6e6;
  }
  :deep(.n-form-item-label__text) {
    height: var(--size-30);
  }
  :deep(.n-input-wrapper) {
    font-size: var(--size-14);
    font-family: Microsoft YaHei, Microsoft YaHei-Regular;
    line-height: var(--size-20);
    padding: 0px 0 10px;
  }
  :deep(.n-form-item-blank--error .n-input) {
    --n-border-error: var(--size-1) solid transparent !important;
    --n-border-focus-error: var(--size-1) solid transparent !important;
    --n-border-hover-error: var(--size-1) solid transparent !important;
    --n-box-shadow-focus-error: var(--size-1) solid transparent !important;
  }
  :deep(input::-ms-reveal) {
    display: none;
  }
}
</style>
