.center.row.boutique_body
  %h1{:style => "text-align:left;"} Détail d'un produit
  .clear
  .product_show
  
    .row
    
      .col_image
        =image_tag @product.default_image.image_file.file.large.medium.url, :id => "product_default_image", :data => {:zoom_image => @product.default_image.image_file.file.url } if @product.default_image
      
        -if @product.product_images.count > 1
          .product_images
            -@product.product_images.order(:position).each do |product_image|
              =link_to image_tag(product_image.image_file.file.square.url), "#", :onclick => "$('#product_default_image').attr('data-zoom-image', $(this).data('zoom-url'));$('#product_default_image').attr('src', $(this).data('large-url'));$('#product_default_image').data('elevateZoom').swaptheimage($(this).data('large-url'), $(this).data('zoom-url')); return false;", :data => {:large_url => product_image.image_file.file.large.medium.url, :zoom_url => product_image.image_file.file.url}
      
      .col_description
        .product_description
          %h1= @product_lang.title
          =simple_format @product_lang.description
          -nbr_products = ProductOrderProduct.joins(:product_order).where(:product_orders => {:completed_finish => true},:product_id => @product.id).sum("product_order_products.qty")
          
          
          
          
          .price
            -if !@product.price_reduced_ht?
              = number_to_currency(@product.price_ht, locale: :fr)
            -else
              = number_to_currency(@product.price_reduced_ht, locale: :fr)
            HT
            
            %div
              %span{:style => "font-weight:normal;"}
                = number_to_currency(@product.price_ttc, locale: :fr)
                TTC
              

          -if @product.price_reduced_ht?
            .price_reduced
              %span.strip
                = number_to_currency(@product.price_ttc, locale: :fr)
          
          
          
          
          
          
          -@porduct_order_product = ProductOrderProduct.new(product_id: @product.id )
          -@porduct_order_product.product_option_id =  @product.product_options_in_stock.first.id if @product.product_options_in_stock.first
          -@porduct_order_product.product_size_id =  @product.product_sizes_in_stock(@porduct_order_product.product_option_id).first.id if @product.product_sizes_in_stock(@porduct_order_product.product_option_id).first
        
        
        
          -if @product.product_stocks.where("stock_th > 0").count > 0
            = form_for [:public, @porduct_order_product], :remote => true do |f|
              = f.hidden_field :product_id
  
              .product_options
                -@product.product_options_in_stock.each do |product_option|
                
                  =link_to product_option.lang(I18n.locale).name, "#", :onclick => "$('#product_option_id').val($(this).data('id'));option_active();update_size_in_stocks($(this).data('sizes-in-stock'));return false;", :data => {:id => product_option.id, :sizes_in_stock =>  @product.product_sizes_in_stock_id(product_option.id)}, :id => "product_option_link_#{product_option.id}", :class => "product_option_link"
                
      
              = f.hidden_field :product_option_id, :id => "product_option_id"
          

                  
  
              #product_sizes.product_sizes
                -@product.product_sizes_in_stock(:all).each do |product_size|
                  =link_to product_size.name, "#", :onclick => "$('#product_size_id').val($(this).data('id'));size_active();return false;", :data => {:id => product_size.id }, :id => "product_size_link_#{product_size.id}", :class => "product_size_link "+("in_stock" if @product.product_sizes_in_stock_id(@porduct_order_product.product_option_id).include?(product_size.id)).to_s
              
            
            
        
              = f.hidden_field :product_size_id, :id => "product_size_id"
          
            
        
              = f.submit "Ajouter à la commande", :class => "add_to_cart btn"
              %br
              %br
              %div
                .clock{:style => "margin:2em;display:inline-block;width:auto;margin:0;margin-left:-5px;"}
                <script type="text/javascript">
                =raw "var clock_max = #{nbr_products};"
                </script>
                :javascript
                  var countup;
              
                      
                          var clock = $('.clock').FlipClock(0, {
                              clockFace: 'Counter',
                              minimumDigits: 1,
                              callbacks:{
                                init:function (){

                                }
                              }
                          });
                  if(clock_max > 0){
                  countup = setInterval(function() {
                      clock.increment();
                          if(clock.getTime().time >= clock_max) {
                          clock.stop();
                          clearInterval(countup);
                          }     
                  }, 0);}
                %div{:style => "padding:10px 15px;display:inline-block;text-transform:uppercase;font-weight:bold;font-size:25px;line-height:30px;position:relative;top:-10px;padding-left:3px;"}
                  déjà
                  %br
                  commandés
                  %br
                  depuis 2018
    
    
              :coffeescript
                @size_active = ->
                  $(".product_size_link").removeClass("active")
                  $("#product_size_link_"+ $("#product_size_id").val()).addClass("active")
              :javascript
                size_active();
      
              :coffeescript
                @option_active = ->
                  $(".product_option_link").removeClass("active")
                  $("#product_option_link_"+ $("#product_option_id").val()).addClass("active")
              :javascript
                option_active();
      
              :coffeescript
                @update_size_in_stocks =(ids) ->
                  $(".product_size_link").removeClass("in_stock")
                  $.each ids, (index, value) ->
                    $("#product_size_link_"+ value).addClass("in_stock")
                  $(".in_stock").first().click()
        
              :javascript
                //update_size_in_stocks([1,2]);
      
              :scss
                .product_sizes a{
                  display:none;
                  &.in_stock{
                    display:inline-block;
                  }
                }
      
          -else
            .no_stock
              Ce produit n'est plus en stock.