export default <LibMixins>{

    data(){
        return {
            value:true,
            useModal:'',
            animate:false,
            drawModal:{},
            useModals:['login','register'],
        }
    },

    watch:{
        modal:{
            handler:function () {
                if (this.modal) {
                    return this.openModal(this.modal);
                }
            },
            immediate:true
        },

    },

    provide(){
        return {
            openModal:(name,draw?:boolean)=> this.openModal(name,draw),
            setLoginParams:(data:Record<string, any>)=> this.$refs.$login && this.$refs.$login.setLoginParams(data)
        }
    },

    methods:{

        close(){
            if (this.value) {
                this.value = false;
            }
        },

        openModal(name:string,draw:boolean=true){

            let animate:boolean = this.useModal !== '';

            if (name !== this.useModal) {

                if (draw !== this.drawModal[this.useModal]) {
                    this.drawModal[this.useModal] = draw;
                }

                if (this.drawModal[name] !== true) {
                    this.drawModal[name] = true;
                }

                this.useModal = name;

                if (this.animate !== animate) {
                    this.animate = animate;
                }
            }

        }

    }

}