<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 :can-cancel="false" v-model="isLoading" is-full-page />
  </div>
</template>

<script>
import axios from 'axios'

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

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

<style></style>
