(function() {

    'use strict';

    var website = openerp.website;
    website.openerp_website = {};

    website.snippet.animationRegistry.kingfisher_pro_product_category_slider = website.snippet.Animation.extend({

        selector: ".oe_pro_cat_slider",
        start: function(editable_mode) {
            var self = this;
            if (editable_mode) {
                $('.oe_pro_cat_slider .owl-carousel').empty();
            }
            if (!editable_mode) {
                var slider_type = self.$target.attr('data-prod-cat-slider-type');
                $.post("/kingfisher_pro/pro_get_dynamic_slider", {
                    'slider-type': self.$target.attr('data-prod-cat-slider-type') || '',
                }).then(function(data) {
                    if (data) {
                        self.$target.empty();
                        self.$target.append(data);
                        $(".oe_pro_cat_slider").removeClass('hidden');

                        openerp.jsonRpc('/kingfisher_pro/pro_image_effect_config', 'call', {
                            'slider_type': slider_type
                        }).done(function(res) {
                            $('div#' + res.s_id).owlCarousel({
                                margin: 10,
                                responsiveClass: true,
                                items: res.counts,
                                loop: true,
                                autoPlay: res.auto_rotate && res.auto_play_time,
                                stopOnHover: true,
                                navigation: true,
                                responsive: {
                                    0: {
                                        items: 1,
                                    },
                                    420: {
                                        items: 2,
                                    },
                                    768: {
                                        items: 3,
                                    },
                                    1000: {
                                        items: res.counts,
                                    },
                                    1500: {
                                        items: res.counts,
                                    }
                                },
                            });
                        });
                    }
                });
            }
        }
    });

    website.snippet.animationRegistry.kingfisher_pro_brand_custom_slider = website.snippet.Animation.extend({

        selector: ".king_pro_brand_slider",
        start: function(editable_mode) {
            var self = this;
            if (editable_mode) {
                $('.king_pro_brand_slider .owl-carousel').empty();
            }
            if (!editable_mode) {
                $.post("/king_pro/get_brand_slider", {
                    'product_count': self.$target.attr('data-brand-count') || 0,
                    'product_label': self.$target.attr('data-product-label') || '',
                }).then(function(data) {
                    if (data) {
                        self.$target.empty();
                        self.$target.append(data);
                        $(".king_pro_brand_slider").removeClass('hidden');

                        $('div#kingfisher_pro_brand_slider').owlCarousel({
                            margin: 10,
                            responsiveClass: true,
                            items: 5,
                            loop: true,
                            autoPlay: 7000,
                            stopOnHover: true,
                            navigation: true,
                            responsive: {
                                0: {
                                    items: 1,
                                },
                                420: {
                                    items: 2,
                                },
                                768: {
                                    items: 3,
                                },
                                1000: {
                                    items: 5,
                                },
                                1500: {
                                    items: 6,
                                }
                            },
                        });
                    }
                });
            }
        }
    });

    website.snippet.animationRegistry.kingfisher_pro_blog_custom_snippet = website.snippet.Animation.extend({

        selector: ".king_pro_blog_slider",
        start: function(editable_mode) {
            var self = this;
            if (editable_mode) {
                $('.king_pro_blog_slider .owl-carousel').empty();
            }
            if (!editable_mode) {
                var slider_type = self.$target.attr('data-blog-slider-type');
                $.post("/kingfisher_pro/blog_get_dynamic_slider", {
                    'slider-type': self.$target.attr('data-blog-slider-type') || '',
                }).then(function(data) {
                    if (data) {
                        self.$target.empty();
                        self.$target.append(data);
                        $(".king_pro_blog_slider").removeClass('hidden');

                        openerp.jsonRpc('/kingfisher_pro/blog_image_effect_config', 'call', {
                            'slider_type': slider_type
                        }).done(function(res) {

                            $('div#' + res.s_id).owlCarousel({
                                margin: 10,
                                responsiveClass: true,
                                items: res.counts,
                                loop: true,
                                autoPlay: res.auto_rotate && res.auto_play_time,
                                stopOnHover: true,
                                navigation: true,
                                responsive: {
                                    0: {
                                        items: 1,
                                    },
                                    420: {
                                        items: 2,

                                    },
                                    768: {
                                        items: res.counts,
                                    },
                                    1000: {
                                        items: res.counts,
                                    },
                                    1500: {
                                        items: res.counts,
                                    }
                                },
                            });
                        });

                    }
                });
            }
        }
    });

    website.snippet.animationRegistry.kingfisher_pro_multi_cat_custom_snippet = website.snippet.Animation.extend({

        selector: ".oe_multi_category_slider",
        start: function(editable_mode) {
            var self = this;
            if (editable_mode) {
                $('.oe_multi_category_slider .owl-carousel').empty();
            }
            if (!editable_mode) {
                var slider_type = self.$target.attr('data-multi-cat-slider-type');
                $.post("/kingfisher_pro/product_multi_get_dynamic_slider", {
                    'slider-type': self.$target.attr('data-multi-cat-slider-type') || '',
                }).then(function(data) {
                    if (data) {
                        self.$target.empty();
                        self.$target.append(data);
                        $(".oe_multi_category_slider").removeClass('hidden');

                        openerp.jsonRpc('/kingfisher_pro/product_multi_image_effect_config', 'call', {
                            'slider_type': slider_type
                        }).done(function(res) {
                            $('.multi_hide .owl-carousel').owlCarousel({
                                margin: 10,
                                responsiveClass: true,
                                items: 4,
                                loop: true,
                                autoPlay: res.sliding_speed,
                                stopOnHover: true,
                                navigation: true,
                                responsive: {
                                    0: {
                                        items: 1,
                                    },
                                    420: {
                                        items: 2,
                                    },
                                    768: {
                                        items: 3,
                                    },
                                    1000: {
                                        items: 4,
                                    },
                                    1500: {
                                        items: 5,
                                    }
                                },
                            });
                        });

                    }
                });
            }
        }
    });

})();