- @p_product_ref = @p_product.p_product_refs.first

.wrapper
  =render :partial => "public/p_products/shop_top"


  .container.product_show{:style =>"padding:40px 0px"}

    .back_link
      -if params[:c]
        =link_to public_p_products_sub_cat_path(:p_product_sub_cat_ids => (params[:c] if params[:c])) do
          =ic :"arrow-alt-circle-left"
          =qit "return-product", "Retour à la liste des produits"
      -else
        =link_to public_p_products_path() do
          =ic :"arrow-alt-circle-left"
          =qit "return-product", "Retour à la liste des produits"
    .row.spaced-grid
      .col-md-4{:style =>"padding:0 10px"}
        .left_image.img
          -if @p_product.p_product_images.count > 1
            =image_tag "", :id => "product_img" #if @p_product.default_image and @p_product.default_image.image_file
          -else
            =image_tag @p_product.default_image.image_file.file.large.url, :id => "product_img" if @p_product.default_image and @p_product.default_image.image_file
          -if @p_product.p_product_images.count > 1
            .more_images
              -@p_product.p_product_images.order("position").each do |p_product_image|
                -if p_product_image.image_file
                  =link_to "#", :onclick => "$('#product_img').attr('src', $(this).data('image'));return false;", :data => {:image => p_product_image.image_file.file.large.url}, :class => (p_product_image.p_product_ref ? "ref-#{p_product_image.p_product_ref_id}" : "ref-all") do
                    =image_tag p_product_image.image_file.file.square.url

              .clear

            :scss
              .more_images{
                img{
                    width:80px;margin-top:10px;margin-right:10px;
                display:block;float:left;
                }
              }
      
      
      .col-md-8{:style =>"padding:0 10px"}
      
      
      
        .content
          %h1=@p_product.name

          %p
            Catégorie : 
            =@p_product_ref.cc_cat_name
            %br/
            Unité de vente : 
            =@p_product_ref.uv
            %br/
            PCB : 
            =@p_product_ref.capacite

          =raw @p_product.description

          %br
        
          %p
            Notre prix de référence :
            =number_to_currency @p_product_ref.get_price_for_shop(current_p_customer)
          
          
            -if @p_product.price_calc == "Kg" 
              -if @p_product_ref.weight.to_f != 0.0
                ="-"
                Conditionnement de 
                =@p_product_ref.weight
                Kg
            
                %br
                Prix au KG :
                =number_to_currency( @p_product_ref.get_price_for_shop(current_p_customer) / @p_product_ref.weight)
        
          %p
            -pl_for_price = current_p_customer_sheet.price_line_block.price_lines.new(:p_product_ref_id => @p_product_ref.id, :qte => 1)
          
            Votre prix pour une unité
            -if @p_product.price_calc == "Kg" 
              -if @p_product_ref.weight.to_f != 0.0
                ="(#{@p_product_ref.weight}Kg)"
              
            =":"
            =number_to_currency(my_price = pl_for_price.tot_amount_ht)
          
          
            -if @p_product.price_calc == "Kg" 
              -if @p_product_ref.weight.to_f != 0.0
                ="-"
                Prix au KG :
                =number_to_currency( @p_product_ref.get_price_for_shop(current_p_customer) / @p_product_ref.weight)
          
        

          =render :partial => "public/price_lines/form"


        .clear
    
  .container{:style =>"padding:40px 0px;padding-top:0;margin-top:-30px;"}
  


    .intensite_cacao{:class => "d-flex justify-content mt-5"}
      %p{:class => "font-weight-bold"} Intensité du cacao : &nbsp;
      %p #{@p_product.intensite_cacao}
    .arome{:class => "d-flex justify-content"}
      - arome = @p_product.p_product_arome_ids
      %p{:class => "font-weight-bold"} Arômes : &nbsp;
      -arome.each do |arome|
        - PArome.where(id: arome).each do |parome|
          #{parome.name},
    .origine{:class => "table-responsive"}
      %table{:class => "table table-bordered"}
        %thead
          %tr
            %th{:class => "text-center"}
              Origine
            %th{:class => "text-center"}
              Fabrication
            %th{:class => "text-center"}
              Utilisation
        %tbody
          %tr
            %td{:class => "text-center"}
              -origine = @p_product.p_product_origine_ids
              -origine.each do |origine|
                -POrigine.where(id: origine).each do |porigine|
                  #{porigine.name}
                  %br
            %td{:class => "text-center"}=@p_product.country
            %td{:class => "text-center"}=@p_product.utilisation_text
    .table-responsive
      %table{:class => "table table-bordered"}
        %thead
          %tr
            %th{:class => "text-center"}
              Températures (en mouvement)
            %th{:class => "text-center"}
              Ingrédients
            %th{:class => "text-center"}
              Valeurs nutritionnelles par 100G
        %tbody
          %tr
            %td
              .chart.chart-xs
                %canvas#chartjs-temp
            %td{:class => "text-center"}
              -ingredients = @p_product.p_product_ingredient_ids
              -PProductIngredient.where(p_product_id: @p_product.id).each do |ingredient|
                -Ingredient.where(id: ingredient.ingredient_id).each do |i|
                  #{i.name} #{ingredient.qte}%
                  %br
            %td{:class => "text-center"}
              -nutris = @p_product.p_product_nutri_ids
              -PProductNutri.where(p_product_id: @p_product.id).each do |nutri|
                -PNutri.where(id: nutri.p_nutri_id).each do |pn|
                  #{pn.name} #{nutri.qte}g #{nutri.ar}%
                  %br



  <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
  :javascript
    $(function() {
      // Bar chart
      new Chart(document.getElementById("chartjs-temp"), {
        type: "line",
        data: {
          labels: labels,
          datasets: [
            {
              label: "N-1",
              backgroundColor: "transparent",
              borderColor: "#718197",
              hoverBackgroundColor: "#718197",
              hoverBorderColor: "#718197",
              data: [48, 50, 28, 29, 32, 33],
              barPercentage: .75,
              categoryPercentage: .5

            },
        ]

        },
        options: {
          maintainAspectRatio: false,
          legend: {
            display: true
          },
          scales: {
            yAxes: [{
              gridLines: {
                display: false
              },
              stacked: false,

            }],
            xAxes: [{
              stacked: false,
              gridLines: {
                color: "transparent"
              }
            }]
          }
        }
      });
    });
