"use strict";
(function ($) {
    $.view_tool_import_sample_tour = function (element, options) {
        let defaults = {

        };
        let plugin = this;
        plugin.settings = {}
        let $element = $(element);
        plugin.init = function () {
            plugin.settings = $.extend({}, defaults, options);
            $element.find('.btn-get-product').click(function (e) {
                let $btn_get=$(this);
                $btn_get.prop('disabled',true);
                plugin.get_product();
            });



        }
        plugin.get_product= function get_product(){
            let data={
                "task":"tool.import_sample_tour"
            };
            $.ajax({
                type: "GET",
                dataType: "json",
                url: wpbookinghotel_root_url+wpbookinghotel_api_task,
                data:data,
                beforeSend: function () {

                },
                error: function (xhr) {

                },
                complete: function () {

                },
                success: function (response) {
                    console.log("response", response);
                    if (response.result === "success") {
                        $('ul.list-product').empty();
                        let list_product=response.data;
                        $.each(list_product,function (index, item) {
                            let $li=$(`<li>${item}</li>`);
                            $li.appendTo('ul.list-product');
                        });
                        if(response.done===1){
                            alert('da xong roi');
                            $btn_get.prop('disabled',false);
                        }else{
                            get_product();
                        }

                    }
                }
            });

        }

        plugin.example_function = function () {
        }


        plugin.init();
    }
    $.fn.view_tool_import_sample_tour = function (options) {
        return this.each(function () {
            if (undefined == $(this).data('view_tool_import_sample_tour')) {
                let plugin = new $.view_tool_import_sample_tour(this, options);
                $(this).data('view_tool_import_sample_tour', plugin);
            }
        });
    }
})(jQuery);
