<template>
  <v-layout row justify-center>
    <v-dialog v-model="dialog_fna" persistent max-width="40%">
      <v-card>
        <v-card-title>
          <span class="headline">FNA</span>
        </v-card-title>
        <v-card-text>
            <v-layout mb-2 row>
              <v-flex xs12>
                  <v-select
                      class="mini-select"
                      item-text="name"
                      return-object
                      outline
                      :items="doctors"
                      v-model="selected_doctor"
                      hide-details
                      label="Dokter"
                  ></v-select>
                  <p v-if="error_doctor" class="error pl-2 pr-2" style="color:#fff">Dokternya siapa ? jangan lupa ya ...</p>
              </v-flex>
            </v-layout>
            <v-layout wrap>
              <v-flex xs12>
                <v-layout v-for="result in results"  mb-2 row>
                    <v-flex xs12>
                        <v-textarea
                            auto-grow
                            :label="result.label"
                            outline
                            rows="2"
                            v-model="result.result"
                            hide-details
                        ></v-textarea>
                    </v-flex>
                </v-layout>
              </v-flex>
            </v-layout>
        </v-card-text>
        <v-card-actions>
          <v-spacer></v-spacer>
          <v-btn color="blue darken-1" flat @click="dialog_fna = false">Tutup</v-btn>
          <v-btn color="blue darken-1" @click="saveResult_Fna" flat >Simpan</v-btn>
        </v-card-actions>
      </v-card>
    </v-dialog>
  </v-layout>
</template>

 <script>
 module.exports = {
   mounted() {
      //this.$store.dispatch("re_fna/get_doctors",{token:''})
   },
   data() {
      return {
        error_doctor:false
        
      };
   },
    computed: {
        dialog_fna: {
            get() {
                return this.$store.state.re_fna.dialog_fna
            },
            set(val) {
                this.$store.commit("re_fna/update_dialog_fna", val)
            }
        },
        results: {
            get() {
                return this.$store.state.re_fna.results
            },
            set(val) {
                this.$store.commit("re_fna/update_results", val)
            }
        },
        doctors(){
          return this.$store.state.re_fna.doctors
        },
        selected_doctor: {
            get() {
                return this.$store.state.re_fna.selected_doctor
            },
            set(val) {
                this.$store.commit("re_fna/update_selected_doctor", val)
            }
        }
    },
    methods: {
        saveResult_Fna(){
            if(_.isEmpty(this.selected_doctor) || this.selected_doctor == '0'){
              this.error_doctor = true

            }else
              this.$store.dispatch("re_fna/saveresult_fna",{doctor:this.selected_doctor.id,results:this.results})
            }
        }
    
 }
</script>
