<style scoped>
.bg-img {
  background-image: linear-gradient(rgba(0, 0, 0, 0) 30%, rgba(0, 0, 0, 1) 90%), url("@images/auth/auth_img00.svg");
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 50rem;
  padding: 6rem 0;
}
.area {
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(0.6rem);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4rem;
  font-family: Abel;
  color: #000;
}
.card {
  background-color: #fff;
  border-radius: 0;
  padding: 1rem 4rem;
}
.card-header {
  background-color: transparent;
  border: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-header img {
  width: 30%;
}
.card-body h1 {
  font-family: 'Noto Serif';
  font-size: 1.8rem;
  font-weight: bold;
  text-align: center;
  padding-top: 6rem;
}
.card-body h5 {
  color: #3d3d3d;
  font-size: 0.8rem;
  font-weight: bold;
  text-align: center;
  padding-top: 0.8rem;
  padding-bottom: 2rem;
}
.row {
  --bs-gutter-x: 0;
}
label {
  font-size: 1rem;
  font-weight: bold;
}
.form-control {
  background-color: #f5f7fa;
  border: 0;
  font-size: 0.8rem;
  font-weight: bold;
  padding: 0.6rem 1rem;
}
.btn-reset {
  width: 100%;
  background-color: #000;
  color: #fff;
  font-size: 1rem;
  font-weight: bold;
  border: 1px #000 solid;
  border-radius: 0.6rem;
  margin-top: 1.5rem;
  padding: 0.5rem 0;
  transition: 0.3s;
}
.btn-reset:hover {
  background-color: #fff;
  color: #000;
}
.text {
  color: #000;
  font-size: 1rem;
  font-weight: bold;
}
.gotoLogin {
  color: #000 !important;
  font-size: 1rem;
  font-weight: bold;
  -webkit-text-stroke: 0.5px #000;
}
.goto-area {
  margin-top: 6rem;
}
@media (max-width: 768px) {
  .area {
    padding: 4rem 2rem;
  }
  .card {
    padding: 1rem 2rem;
  }
}

/* #region ========= area2 */
.area2 {
  background-color: #000;
  min-height: 10rem;
}
/* #endregion */
</style>
<template>
  <div class="bg-img">
    <div class="area col-12 col-md-9 col-xl-7">
      <div class="card col-md-9 col-xl-7">
        <div class="card-header">
          <img src="@images/auth/auth_img01.svg" alt="logo" />
        </div>
        <div class="card-body p-0">
          <h1>重設密碼</h1>
          <h5>請設定您的新密碼，密碼長度至少為8個字元，且必須包含至少一個數字、一個英文字母！</h5>
          <form action="javascript:void(0)" class="row" method="post" @submit="resetPassword">
            <div class="mb-3" v-if="Object.keys(validationErrors).length > 0">
              <div class="alert alert-danger">
                <ul class="mb-0">
                  <li class="text" v-for="(value, key) in validationErrors" :key="key">
                    {{ value[0] }}
                  </li>
                </ul>
              </div>
            </div>

            <label for="password" class="p-0">新密碼</label>
            <div class=" d-flex p-0">
              <input
                type="password"
                v-model="data.password"
                name="password"
                id="password"
                class="form-control mt-1 mb-3"
                required
              />
            </div>

            <label for="password_confirmation" class="p-0">確認密碼</label>
            <div class=" d-flex p-0">
              <input
                type="password"
                v-model="data.password_confirmation"
                name="password_confirmation"
                id="password_confirmation"
                class="form-control mt-1 mb-3"
                required
              />
            </div>

            <div class="text-center mt-3">
              <button
                type="submit"
                class="btn-reset"
              >
                重設
              </button>
            </div>
          </form>

          <div class="text-center goto-area">
            <router-link to="/login" class="gotoLogin">回登入頁</router-link>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="area2"></div>
</template>
<script>
import { api } from "@/global/axios";
import { sendSuccessSwal, sendFailedSwal } from "@/global/swal";
export default {
  name: "login",
  data() {
    return {
      data: {
        token: this.$route.params.token,
        email: this.$route.query.email,
        password: "",
        password_confirmation: "",
      },
      validationErrors: [],
    };
  },
  methods: {
    resetPassword() {
      api.post('/api/password/reset', this.data)
        .then(response => {
          sendSuccessSwal(() => window.location.href = "/login");
        })
        .catch(error => {
          this.validationErrors = error.response.data.errors;
          console.log(this.validationErrors);
        });
    }
  },
};
</script>
