


        $(window).on('load', function() {
            if (feather) {
                feather.replace({
                    width: 14,
                    height: 14
                });
            }
        })
        document.addEventListener('DOMContentLoaded', function() {
          const skypeButton = document.getElementById('skypeButton');
        
          if (skypeButton) {
          const skypeAdd = document.getElementById('skypeButton').innerHTML;
            skypeButton.addEventListener('click', function() {
              const skypeURI = `skype:${skypeAdd}?chat`;
              window.location.href = skypeURI;
            });
          }
        });
        
        var timerID = setInterval(function() {
        now = new Date();
        timezone = now.getTimezoneOffset();
        day = now.getDay();
        hour = now.getUTCHours();
        min = now.getUTCMinutes();
        sec = now.getUTCSeconds();
        ms = now.getUTCMilliseconds();

        displayTime(hour, min, sec, day, "AM", -5, "time-atx", "day-atx");
        }, 1000);

        function displayTime(hour, min, sec, day, meridiem, offset, timeId, dayId) {

        hour = hour + offset;
        if (hour < 0) {
            hour = 24 + hour;
            day--;
        } else if (hour >= 24) {
            hour = hour - 24;
            day++;
        }


        if (hour > 12) {
            hour = hour - 12;
            meridiem = "PM";
        }
        if (hour === 0)
            hour = 12;

        if (hour < 10)
            hour = "0" + hour;
        if (min < 10)
            min = "0" + min;
        if (sec < 10)
            sec = "0" + sec;

        $('#dashHours').html(hour);
        $('#dashMin').html(min);
        $('#dashSec').html(sec);
    }
    


        $(document).ready(function() {
            "use strict"

            let search_btn = $("#search_btn");
            search_btn.click(function(e) {
                e.preventDefault();
                dataListView.draw();
            });
            // init table dom
            let Table = $("table");
            // init list view datatable
            let dataListView = $('.datatables-basic').DataTable({
                "pageLength": 50,
                lengthChange: true,
                sScrollX: "100%",
                autoWidth: true,
                "processing": true,
                "serverSide": true,
                "ajax": {
                    "url": "https://trackergenius.runterminal.com/affiliate/offer/search",
                    "dataType": "json",
                    "type": "POST",
                    "data": {
                        _token: "xVg5vlGiMwfiDk04qzHQhHjes4QkM1yoxS7WeOHB",
                        name: function() {
                            return $("#name").val();
                        },
                        country_id: function() {
                            let country_id = [];
                            $('#country_id option:selected').each(function() {
                                country_id.push($(this).val());
                            });
                            return JSON.stringify(country_id);
                        },
                        device_id: function() {
                            let device_id = [];
                            $('#device_id option:selected').each(function() {
                                device_id.push($(this).val());
                            });
                            return JSON.stringify(device_id);
                        },
                        category_id: function() {
                            let category_id = [];
                            $('#category_id option:selected').each(function() {
                                category_id.push($(this).val());
                            });
                            return JSON.stringify(category_id);
                        },
                    }
                },
                "columns": [{
                        "data": 'id',
                        orderable: true,
                        searchable: false
                    },
                    {
                        "data": "o_id"
                    },
                    {
                        "data": "o_id"
                    },
                    {
                        "data": "country",
                        orderable: true,
                        searchable: false
                    },
                    {
                        "data": "avatar",
                        orderable: false,
                        searchable: false
                    },
                    {
                        "data": "name",
                        orderable: false,
                        searchable: false
                    },
                    
                    {
                        "data": "category",
                        orderable: true,
                        searchable: false
                    },
                    {
                        "data": "device",
                        orderable: true,
                        searchable: false
                    },
                    {
                        "data": "payout",
                        orderable: false,
                        searchable: false
                    },
                    {
                        "data": "epc",
                        orderable: false,
                        searchable: false
                    },
                    {
                        "data": "Link",
                        orderable: false,
                        searchable: false
                    },
                    {
                        "data": "action",
                        orderable: false,
                        searchable: false
                    },
                ],

                searchDelay: 1500,
                columnDefs: [{
                        // For Responsive
                        className: 'control',
                        orderable: false,
                        responsivePriority: 1,
                        targets: 0
                    },
                    {
                        // For Checkboxes
                        targets: 1,
                        orderable: false,
                        responsivePriority: 3,
                        render: function(data) {
                            return (
                                '<div style="display: none" class="form-check"> <input class="form-check-input dt-checkboxes" type="checkbox" value="" id="' +
                                data +
                                '" /><label class="form-check-label" for="' +
                                data +
                                '"></label></div>'
                            );
                        },
                        checkboxes: {
                            selectAllRender: '<div style="display: none" class="form-check"> <input class="form-check-input" type="checkbox" value="" id="checkboxSelectAll" /><label class="form-check-label" for="checkboxSelectAll"></label></div>',
                            selectRow: true
                        }
                    },
                    {
                        targets: 2,
                        visible: false
                    },
                    {
                        // Actions
                        targets: -1,
                        title: 'Action',
                        orderable: false,
                        render: function(data, type, full) {
                            return (
                                '<a href="' + full['show'] +
                                '" class="text-success" style="margin-left: 10px" data-bs-toggle="tooltip" data-bs-placement="top" title="' +
                                "Show" + '">' +
                                feather.icons['eye'].toSvg({
                                    class: 'font-medium-4'
                                }) +
                                '</a>'
                            );
                        }
                    },
                    {
                        // Actions
                        targets: 4,
                        title: 'Image',
                        orderable: false,
                        render: function(data, type, full) {
                            return (
                                '<span class="position-relative text-center w-100 d-block">'+
                                    '<img class="hover_image" src="'+ full['avatar'] +'"  alt=""  style="height: 50px;width: 50px;">'+
                                    
                                '</span>'
                            );
                        }
                    },
                    {
                        // Actions
                        targets: -2,
                        title: 'Link',
                        orderable: false,
                        render: function(data, type, full) {
                            if(full['status_check'] === 'Approved' )
                            {
                                return (
                                '<button type="button" class="btn btn-primary btn-sm link-btn"  data-link="'  + full['click'] +  '"  data-bs-toggle="modal" data-bs-target="#linkModal" >Get Link</button>'
                                );
                            }else if(full['offer_permission'] == 1){
                                return (
                                    '<span class="btn btn-warning btn-sm">Requested</span>'
                                );
                            }else{
                                return (
                                '<div class="request_button_div_'  + full['click'] +  '"><button type="button" class="btn btn-info btn-sm request-btn"  data-id="'  + full['click'] +  '" data-image="'  + full['avatar'] +  '" data-url="'  + full['preview_url'] +  '"  data-name="'  + full['offer_name'] +  '"  data-category="'  + full['category'] +  '"  data-expire="'  + full['expire_date'] +  '" data-bs-toggle="modal" data-bs-target="#requestModel" >Apply</button></div>'
                                );
                            }
                            
                        }
                    }
                ],
                dom: '<"d-flex justify-content-between mx-0 row"<"col-4"l><"col-8"f>>t<"d-flex justify-content-between mx-0 row mb-2"<"col-8"i><"col-4"p>>',     
                language: {
                    paginate: {
                        // remove previous & next text from pagination
                        previous: '&nbsp;',
                        next: '&nbsp;'
                    },
                    sLengthMenu: "_MENU_",
                    sZeroRecords: "No Result",
                    sSearch: "<span class='search_label'>Search</span>",
                    sProcessing: "Processing...",
                    sInfo: "Show "
                },
                aLengthMenu: [
                    [10, 20, 50, 100],
                    [10, 20, 50, 100]
                ],
                select: {
                    style: "multi"
                },
                order: [
                    [2, "desc"]
                ],
                displayLength: 10,
                "drawCallback": function(settings) {
                    var api = this.api();
                    var rowCount = api.rows({ page: 'current' }).count();
                    var rows = api.rows({ page: 'current' }).nodes();
                    $(rows).removeClass('last_one Second_last thirdlast');
                    if (rowCount >= 1) {
                        $(rows[rowCount - 1]).addClass('last_row');
                    }
                    if (rowCount >= 2) {
                        $(rows[rowCount - 2]).addClass('second_last_row');
                    }
                    if (rowCount >= 3) {
                        $(rows[rowCount - 3]).addClass('third_last_row');
                    }
                    if (rowCount >= 4) {
                        $(rows[rowCount - 4]).addClass('fourth_last_row');
                    }
                }
            });

            // Select2 basic
            $(".select2").each(function() {
                let $this = $(this);
                $this.wrap('<div class="position-relative"></div>');
                $this.select2({
                    // the following code is used to disable x-scrollbar when click in select input and
                    // take 100% width in responsive also
                    dropdownAutoWidth: true,
                    width: '100%',
                    dropdownParent: $this.parent(),
                    placeholder: 'Choose One'
                });
            });

            // Select2 multiple
            $(".select2-multiple").each(function() {
                let $this = $(this);
                $this.wrap('<div class="position-relative"></div>');
                $this.select2({
                    // the following code is used to disable x-scrollbar when click in select input and
                    // take 100% width in responsive also
                    dropdownAutoWidth: true,
                    width: '100%',
                    dropdownParent: $this.parent(),
                    placeholder: 'Select Manager'
                });
            });

            // filter
        });
        $(document).on('click', '.link-btn', function () {
            var offer_id = $(this).data('link');
            $('.offer_id').val(offer_id);
            var selectedValue = $('#domain').val();
            let link = selectedValue + "/c?a=" + 60 + "&o=" +offer_id;
            $('#link_show').val(link);
        });
        
        $(document).on('click', '.request-btn-submit', function () {
            var offer_id = $('#request-form-id').val();
            var url = '/affiliate/offer/application/' + offer_id;
            var message = $('#application-message').val();
            $.ajax({
                url: url,
                method: "POST",
                data: {
                    application: message,
                    _token: "xVg5vlGiMwfiDk04qzHQhHjes4QkM1yoxS7WeOHB",
                },
                success: function(response) {
                    toastr.success('Request Sent Successfully','Success');
                    $('.request_button_div_'+offer_id).html('<span class="btn btn-warning btn-sm">Requested</span>')
                    $("#requestModel").modal('hide');
                },
                error: function(xhr, status, error) {
                    var errors = xhr.responseJSON.errors;
                    $.each(errors, function(key, value) {
                        toastr.error(value,'Error');
                    });
                }
            });
        });

       $(document).on('click', '.request-btn', function () {
            var offer_id = $(this).data('id');
            var name = $(this).data('name');
            var image = $(this).data('image');
            var url = $(this).data('url');
            var category = $(this).data('category');
            var expire = $(this).data('expire');
            var image = $(this).data('image');
            
            $('#modal_name').html(name);
            $('#modal_url').html(url);
            $('#modal_href').attr('href', url);
            $('#modal_category').html(category);
            $('#modal_date').html(expire);
            $('#modal_image').attr('src', image);
            var request_form_id = $('#request-form-id');
            
            
            request_form_id.val(offer_id);
            $('#application-message').val('');
        });
        $(document).on('change', '#domain', function () {
            var offer_id = $('.offer_id').val();
            var selectedValue = $('#domain').val();
            let link = selectedValue + "/c?a=" + 60 + "&o=" +offer_id;
            $('#link_show').val(link);
        });
            
    