<template>
    <v-layout>
        
            <v-checkbox
                v-model="init_value"
                @change="changeLahBrooo"
                
                hide-details class="shrink mr-2"
            ></v-checkbox>
        
        
            <v-text-field
                :label="__label"
                placeholder="Alasan"
                outline
                :disabled=x_disabled
                :error-messages="init_error ? x_error_messages : ''"
                :error_count="init_error ? x_error_count : 0 "
                :error=init_error
                :hide-details=!init_error
                v-model=init_note
            ></v-text-field>

            
        
    </v-layout>
</template>

<script>
module.exports = {
    props : ['label', 'value', 'is_error', 'note'],
    mounted: function() {
      this.$nextTick( function() {
         this.init_note = this.note ? this.note : "";
         this.init_value = this.value;
      })
   },

    data () {
        return {
            init_value : false,
            init_note : ""
        }
        
    },

    methods : {
        changeLahBrooo (n, o) {
            if (n)  {
                this.init_note = "";
                // this.init_error = false;
            } /* else {
                if (this.init_note.length < 1)
                    this.init_error = true;
                else
                    this.init_error = false;
            }*/

            var prm = {checked: n, note: this.init_note, error: this.init_error};
            this.$emit('x_change',prm);
            console.log('emit change');
            
            // this.x_note = "aaaaaaaaaaaaaaaaaaa"
            // alert(this.x_note)
        }
    },
    computed : {
        __label () {
            if (this.label)
                return this.label;

            return "";
        },

        x_disabled () {
            // return false;
            if (this.init_value === "true" || this.init_value === true)
                return true;
            return false;

        },

        init_error () {
            
            if ((this.init_value === "false" || this.init_value === false) && this.init_note.length < 1)
                return true;

            else {
                // this.x_note = "";
                return false;
            }


        },

        x_error_count () {
            // return 0;
            if (this.init_error)
                return 1;

            return 0;
        },

        x_error_messages () {
            if (this.init_error)
                return ["Kolom ini harus diisi !"];

            return [];
        },
        
        x_note () {
            
            if (this.note)
            return this.note;

            return "";
            
        }
    }
}
</script>
