const AjaxMixin = {
    mixins: [AjaxLoaderMixin, Data],
    props: [
        'ajaxOnLoad',
        'ajaxOnAction',
        'ajaxAutoReloadInterval',
        'ajaxProviderAction',
        'ajaxData'
    ],
    data: function () {
        return {
            ajaxOnLoad_: false,
            ajaxOnAction_: false,
            ajaxAutoReloadInterval_: 0,
            ajaxProviderAction_: '',
            ajaxData_: []
        };
    },
    created()
    {
        if (this.ajaxOnLoad_)
        {
            this.runAjaxOnAction_();
        }
        
        if (this.ajaxAutoReloadInterval_)
        {
            setInterval(this.runAjaxOnAction_, this.ajaxAutoReloadInterval_);
        }
    },
    methods: {
        runAjaxOnAction_: function (data) {
            return this.loadDataFromServer_({
                formData: {
                    ...this.data_,
                    ...data,
                },
                providerAction: this.ajaxProviderAction_
            }, this.ajaxData_,).then(typeof this.ajaxLoaded_ === 'function' ? this.ajaxLoaded_ : null);
        }
    },
}