<template>
  <div class="hello bg-warning p-5">
    <h1>{{ msg }}</h1>
    This is the home page
    <p class="badge bg-dark text-white">{{ getName }}</p>
    
    <form>
      <div class="mb-3">
        <label  class="form-label">Enter Name to set:</label>
        <input type="email" class="form-control"  aria-describedby="emailHelp" v-model="temp_name">
      </div>      
      <button  class="btn btn-primary" @click.prevent="setname()">Set name</button>
    </form>

  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  props: {
    msg: String
  },
  data(){
    return {
      temp_name:null
    }
  },
  methods: {
    setname(){
      this.$store.commit('setName',{name:this.temp_name});
      this.$store.commit('addAlert',{message:"Name set to "+this.temp_name, title:"Name Set", type:"danger"});
    }
  },
  computed:{
    getName(){
      return this.$store.getters.getName;
      
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
