<template>
  <div class="columns is-vcentered">
    <div class="column">
      <b-button
        type="is-info"
        @click="
          $alertsGenericos.imprimirWarning(
            $buefy,
            '¿Esta segur@ de querer reenviar la contraseña de este operador?',
            updatePassword
          )
        "
        expanded
        rounded
      >
        Reenviar Contraseña
      </b-button>
    </div>

    <b-loading :is-full-page="true" v-model="isLoading" :can-cancel="false" />
  </div>
</template>

<script>
import axios from 'axios'

export default {
  data() {
    return {
      isLoading: false,
    }
  },
  props: {
    admin: { type: Object, required: true },
    updateIsLoading: { type: Function, required: true },
    operador: { type: Object, required: true },
  },
  methods: {
    updatePassword() {
      const data = {
        id_operador: this.operador.id_operador,
      }

      this.isLoading = true
      axios
        .put(
          `${process.env.api}/operador/update-password`,
          data,
          this.admin.token
        )
        .then((res) => {
          this.isLoading = false
          this.$alertsGenericos.imprimirMensaje(this.$buefy, res.data.message)
        })
        .catch((err) => {
          this.isLoading = false
          this.$alertsGenericos.imprimirError(this.$buefy, err.response.data)
        })
    },
  },
}
</script>

<style></style>
