(function() {
    'use strict';
    var website = openerp.website;
    var _t = openerp._t;

    website.add_template_file('/kingfisher/static/src/xml/kingfisher.xml');

    website.snippet.options.kingfisher_product_slider = website.snippet.Option.extend({

        start: function(editMode) {
            var self = this;
            this._super();
            this.$target.removeClass("hidden");
			 this.$target.find(".owl-carousel").empty();
            if (!editMode) {
                self.$el.find(".oe_product_slider").on("click", _.bind(self.product_slider, self));
            }
        },

        drop_and_build_snippet: function() {
            var self = this;
            this._super();
            if (this.product_slider()) {
                this.product_slider().fail(function() {
                    self.editor.on_remove();
                });
            }
        },
		clean_for_save: function(){
				$('.oe_product_slider .slider_product_slider .owl-carousel').empty();
		},

        product_slider: function() {
            var self = this;
            self.$modal = $(openerp.qweb.render("kingfisher.product_slider_block"));
            self.$modal.appendTo('body');
            self.$modal.modal();
            var $product_count = self.$modal.find("#product-count"),
                $slider_type = self.$modal.find("#slider_type"),
                $product_label = self.$modal.find("#product-label"),
                $cancel = self.$modal.find("#cancel"),
                $sub_data = self.$modal.find("#sub_data");

            $sub_data.on('click', function() {
                var type = '';
                self.$target.attr("data-product-count", $product_count.val());
                self.$target.attr("data-slider-type", $slider_type.val());
                self.$target.attr('data-product-label', $product_label.val());
                if ($slider_type.val() == "is_features") {
                    if ($product_label.val()) {
                        type = $product_label.val();
                    } else {
                        type = "FEATURES PRODUCT";
                    }
                }
                else {
                    if ($product_label.val()) {
                        type = $product_label.val();
                    } else {
                        type = "NEW ARRIVALS";
                    }
                }

                self.$target.empty().append('<div class="container"><div class="slider_product_slider"><div class="col-md-12"><h3 class="section-title style1"><span>' + type + '</span></h3>  </div></div></div>');
            });
        },

    });
    website.snippet.options.kingfisher_brand_slider = website.snippet.Option.extend({

        start: function(editMode) {
            var self = this;
            this._super();
            this.$target.removeClass("hidden");
            if (!editMode) {
                self.$el.find(".oe_brand_slider").on("click", _.bind(self.brand_slider, self));
            }
        },

        drop_and_build_snippet: function() {
            var self = this;
            this._super();
            if (this.brand_slider()) {
                this.brand_slider().fail(function() {
                    self.editor.on_remove();
                });
            }
        },
		clean_for_save: function(){
				$('.oe_brand_slider  .owl-carousel').empty();
		},

        brand_slider: function() {
            var self = this;
            self.$modal = $(openerp.qweb.render("kingfisher.brand_slider_block"));
            self.$modal.appendTo('body');
            self.$modal.modal();
            var $product_label = self.$modal.find("#product-label"),
                $cancel = self.$modal.find("#cancel"),
                $sub_data = self.$modal.find("#sub_data");

            $sub_data.on('click', function() {
                var type = '';
                self.$target.attr('data-product-label', $product_label.val());
 				type = $product_label.val();

                self.$target.empty().append('<div class="container"><div class="row our-brands"><div class="col-md-12"><h3 class="section-title style1"><span>' + type + '</span></h3>  </div></div></div>');
            });
        },

    });

})();
