<template>
  <div class="plans-container">
    <h2>Planos</h2>
    <div class="price-row">
      <div v-if="pending" class="loader"></div>
      <div v-else-if="error" class="error" role="alert">
        Erro ao tentar carregar a lista de planos
      </div>
      <div class="price-col" v-else v-for="plan in plans" :key="plan.nome">
        <p>{{ plan.nome }}</p>
        <h3>R$ {{ plan.valor }}<span>/ mês</span></h3>
        <ul v-for="reason in plan.reasons" :key="reason.name">
          <li>{{ reason }}</li>
        </ul>
        <button>Selecionar</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Plans",
  data() {
    return {
      plans: null,
      pending: true,
      error: false,
      data: null,
    };
  },
  mounted() {
    this.getAnimesList();
  },
  methods: {
    async getAnimesList() {
      this.pending = true;

/*       await fetch("https://www.mockachino.com/a5c0d330-8fb8-4a/plans")
        .then((res) => res.json())
        .then((data) => (this.plans = data.plans))
        .catch(() => (this.error = true)); */

      await fetch("http://192.168.0.68:9094/NTFlix/v1/stage/cadastro")
        .then((res) => res.json())
        .then((data) => (this.plans = data.plano.modalidades))
        .catch((e) => (console.log(e)));

      this.pending = false;
    },
  },
};
</script>

<style>
.plans-container {
  width: 100%;
  height: auto;
}

.plans-container h2 {
  padding: 35px 0;
  text-align: center;
}

.price-row {
  width: 90%;
  max-width: 1100px;
  margin: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  grid-gap: 25px;
}

.price-col {
  background: #1f283b;
  padding: 10% 15%;
  border-radius: 10px;
  color: #fff;
  text-align: center;
}

.price-col p {
  font-size: 22px;
}

.price-col h3 {
  font-size: 44px;
  margin: 20px 0 40px;
  font-weight: 500;
}

.price-col h3 span {
  font-size: 16px;
}

.price-col ul {
  /* text-align: left; */
  display: flex;
  flex-direction: column;
  margin: 20px 0;
  color: #ddd;
  list-style: none;
}

.price-col ul li {
  margin: 15px 0;
}

.price-col ul li::before {
  content: "\2022";
  color: #e33058;
  font-weight: bold;
  margin-right: 8px;
}

.price-col button {
  width: 100%;
  padding: 14px 0;
  background: transparent;
  color: #fff;
  font-size: 15px;
  border: 1px solid #e33058;
  border-radius: 6px;
  margin-top: 30px;
  cursor: pointer;
  transition: background 0.5s;
}

.price-col button:hover {
  background: #e33058;
}

.loader {
  border: 16px solid #f3f3f3; /* Light grey */
  border-top: 16px solid #3498db; /* Blue */
  border-radius: 50%;
  width: 120px;
  height: 120px;
  animation: spin 2s linear infinite;
  display: flex;
}

.error {
  border: 1px solid;
  margin: 10px 0px;
  padding: 15px 10px 15px 50px;
  background-repeat: no-repeat;
  background-position: 10px center;
  color: #d8000c;
  background-color: #ffbaba;
  background-image: url("https://i.imgur.com/GnyDvKN.png");
}
</style>
