;(function($) {
    'use strict'

    B2C.dataTables = {
        init: function(options) {
            this._default = {
                target: '#js-datatable',
                config: {
                    responsive: true,
                    language: {
                        paginate: {
                            next:
                                '<img src="https://prep-community.musictribe.com/html/assets/pagination_arrow-next.png" />',

                            previous:
                                '<img src="https://prep-community.musictribe.com/html/assets/pagination_arrow-prev.png" />'
                        }
                    }
                }
            }

            this._options = $.extend(true, this._default, options)

            if (!$(this._options.target).length) return

            this.initDataTable()
        },

        initDataTable: function() {
            $(this._options.target).DataTable(this._options.config)
        }
    }

    const defaultDataTables = Object.create(B2C.dataTables),
        downloadCenterTables = Object.create(B2C.dataTables)

    defaultDataTables.init()
    downloadCenterTables.init({
        target: '#js-datatable-download-center',
        config: {
            // sDom: 'l' + 'fptip'
            sDom: 'l<"checkbox">fptip',
            drawCallback: function() {
                $('.checkbox').html(
                    '<div class="checkbox__container">' +
                        '<input type="checkbox" id="checkbox">' +
                        '<div class="checkbox__indicator"></div>' +
                        '</div>' +
                        '<label for="checkbox1" class="checkbox__label">Show Legacy Version</label>' +
                        '</div>'
                )

                $(`${downloadCenterTables._options.target}_paginate`).addClass(
                    'd-none d-sm-block'
                )
            }
        }
    })
})(jQuery)
