<template>
    <cs-btn 
        :tooltip="tooltip"
        :icon="icon"
        :caption="btnCaption"
        :position="position"
        :outlined="outlined"
        :color="color"
        
        :click="OnClick"

        @keypresstab="$emit('keypresstab', $event)"
    />
</template>

<script>
    export default {

        props: {
            form: {default: null},
            tooltip: {default: 'Închide formularul'},
            caption: {default: 'Renunță'},
            icon: {default: 'mdi-close'},
            position: {default: 'bottom'},
            outlined: {default: true},
            color: {default: null},
            click: {default: null},
        },

        computed: {
            btnCaption() {
                if(this.caption)
                {
                    return this.caption;
                }
                
                if(this.form)
                {
                    return this.caption;
                }
                return this.icon ? null : 'Închide';
            }
        },

        methods: {
            OnClick(e) {
                if(this.form && _.isFunction(this.form.Hide))
                {
                    return this.form.Hide();
                }

                if(_.isFunction(this.click))
                {
                    return this.click();
                }

                this.$emit('click', e);

            }
        },

        
        components: {
            CsBtn: require('./CsBtn').default,
        },

        name: 'CsBtnCancel',
    }
</script>