<script setup lang="ts">
import { reactive, ref } from 'vue';
import user from "@/services/user.service";
import { useAuthStore } from '@/stores/auth.store';
import { routeToSearchPage } from '@/router';

interface FormState {
  username: string;
  password: string;
  remember: boolean;
}

// 授权store
const authStore = useAuthStore();

const formState = reactive<FormState>({
  username: '',
  password: '',
  remember: true,
});

const loading = ref(false);

const onFinish = (values: any) => {
  loading.value = true;
  let param = {
    mobilePhone: values.username,
    password: values.password,
    type: 1
  }
  user.login(param).then((resp) => {
    authStore.setCurrentUser(resp.data.data);
    authStore.setToken(resp.data.data.token);
    routeToSearchPage();
    loading.value = false;
  }).catch((err) => {
    loading.value = false;
    console.log(err);
  })
};

const onFinishFailed = (errorInfo: any) => {
  console.log('Failed:', errorInfo);
};

</script>

<template>
  <div class="login-main">
    <a-row type="flex">
      <a-col class="left" :flex="1">
        <!-- <h1 class="login-title">技淘平台智慧产权大脑</h1> -->
         <p class="login-banner">
          <img src="@/assets/imgs/login-banner.png" />
        </p>
      </a-col>
      <a-col class="right" :flex="1">
        <h1>Think Logically.</h1>
        <h1>Create Reasoningly.</h1>

        <h2 style="margin-top: 100px;">用户登录</h2>
        <div class="login-form-wrapper">
          <a-form
            :model="formState"
            name="basic"
            :wrapper-col="{ span: 24 }"
            autocomplete="off"
            @finish="onFinish"
            @finishFailed="onFinishFailed"
          >
            <!-- <div class="kede-input" style="margin-top: 20px; background: transparent;">
              <a-input v-model:value="formState.username" placeholder="请输入用户名" />
            </div>
            <div class="kede-input" style="margin-top: 20px; background: transparent;">
              <a-input-password v-model:value="formState.password" placeholder="请输入密码" />
            </div>
            <div style="margin-top: 20px;">
              <a-button type="primary" html-type="submit" block :loading="loading">登&nbsp;&nbsp;&nbsp;&nbsp;录</a-button>
            </div> -->

            <a-form-item class="kede-input" name="username" :rules="[{ required: true, message: '请输入用户名' }]">
              <a-input v-model:value="formState.username" placeholder="请输入用户名" />
            </a-form-item>

            <a-form-item class="kede-input" name="password" :rules="[{ required: true, message: '请输入密码' }]">
              <a-input-password v-model:value="formState.password" placeholder="请输入密码" />
            </a-form-item>

            <a-form-item>
              <a-button type="primary" html-type="submit" block :loading="loading">登&nbsp;&nbsp;&nbsp;&nbsp;录</a-button>
            </a-form-item>
          </a-form>
          <!-- <p class="forgot-password-wrap">
            <a href="#">忘记密码？</a>
          </p> -->
        </div>
      </a-col>
    </a-row>
  </div>
</template>

<style scoped lang="scss">
.login-main {
  height: 100vh;
  //background-color: #00A09A;

  .left {
    text-align: center;
    padding-top: 100px;
    // background: url(@/assets/imgs/login-banner.png) no-repeat;
    // background-size: 100% 100%;
    background: radial-gradient(circle, #0D2148, #00051E);

    .login-title {
      color: #00A09A;
    }

    .login-banner {
      margin: 0 auto;
      width: 300px;

      img {
        width: 180%;
        position: relative;
        right: 45%;
        bottom: 20px;
      }
    }
  }

  .right {
    height: 100vh;
    padding-top: 100px;
    padding-left: 60px;
    background-color: #040E2B;

    h1, h2 {
      color: #FFFFFF;
    }

    .login-form-wrapper {
      width: 400px;

      color: white;

      .kede-input::v-deep {
        * {
          background: transparent;
          color: white;
        }
      }
    }
  }
}

.forgot-password-wrap {
  text-align: right;

  // a {
  //   color: #ffffff;

  //   &:hover {
  //   text-decoration: underline;
  //   }
  // }
}
</style>
