/**
 * NOTICE OF LICENSE
 *
 * This source file is subject to a commercial license from SOLEDIS
 * Use, copy, modification or distribution of this source file without written
 * license agreement from the SOLEDIS GROUP is strictly forbidden.
 *    ___  ___  _    ___ ___ ___ ___
 *   / __|/ _ \| |  | __|   \_ _/ __|
 *   \__ \ (_) | |__| _|| |) | |\__ \
 *   |___/\___/|____|___|___/___|___/
 *
 *  @author    SOLEDIS <prestashop@groupe-soledis.com>
 *  @copyright 2020 SOLEDIS
 *  @license   All Rights Reserved
 */

$(document).ready(function () {
    if ($('#sld-characteristics').length > 0) {
        // 1.7.x
        if ($('.product-features').length) {
            $('#sld-characteristics').addClass('sld-characteristics-genuine');
            displaySldCharacteristics();
        }
        // 1.6.x
        else if ($('.table-data-sheet').length) {
            $('.table-data-sheet:first').parents('section.page-product-box').replaceWith($('#sld-characteristics'));
        }
    }
});


$( document ).on( "ajaxComplete", function( event, xhr, settings ) {
  if ($('#sld-characteristics.sld-characteristics-clone').length === 0 && $('#sld-characteristics.sld-characteristics-genuine').length > 0) {
        displaySldCharacteristics();
  }
});

function displaySldCharacteristics(){
    var theColorIs = $('.product-features dl.data-sheet dd.value').css("background");
    $('.groupfeature-title').css('background', theColorIs);
    $('.name.feat-name').css('background', 'none');
    if($('.product-features').length > 0 && $('.sld-characteristics-genuine').length > 0){
        $('.product-features')[0].style.display = 'none';
        var clone = $('#sld-characteristics.sld-characteristics-genuine').clone();
        clone.insertAfter( ".product-out-of-stock" ).removeClass('sld-characteristics-genuine').addClass('sld-characteristics-clone');
    }
    $('.groupfeature-container').each(function () {
      $(this).find('.feat-name span').each(function () {
        var uniqueClass = $.trim($(this).attr('class'));
        var first = $(this).closest('.groupfeature-container').find("."+uniqueClass).first();
        first.show();
        first.parent().addClass('sld-feat-display');
      });
    });
}