(function ($) {
    $.field_paymentbutton = function (element, options) {
        var defaults = {
            field_name: 0
        }
        var plugin = this;
        plugin.settings = {}
        var $element = $(element),
            element = element;

        plugin.init = function () {
            plugin.settings = $.extend({}, defaults, options);
            let field_name = plugin.settings.field_name;
            plugin.hide_payment_online();
            $element.find('.btn-select-payment').on('click',function (e) {
                let $self = $(this);
                let $payment_item = $self.closest('li.payment-item')
                let payment_id = $payment_item.data('payment_id');
                $element.find(`input[name="${field_name}"]`).val(payment_id);
            });
        };
        plugin.hide_payment_online = function (hidden) {
            let field_name = plugin.settings.field_name;
            $element.find('.list-payment li.payment-online').each(function (e) {
                if (hidden === true || hidden === 1) {
                    $(this).hide();
                } else {
                    $(this).show();
                }
            });
            $element.find(`input[name="${field_name}"]`).val("");
        };
        plugin.example_function = function () {
        };
        plugin.init();
    }
    $.fn.field_paymentbutton = function (options) {
        return this.each(function () {
            if (undefined == $(this).data('field_paymentbutton')) {
                var plugin = new $.field_paymentbutton(this, options);
                $(this).data('field_paymentbutton', plugin);
            }
        });
    }
})(jQuery);
