<?php
defined('_JEXEC') or die('Restricted access');
/**
* @package OS CCK
* @copyright 2019 OrdaSoft.
* @author Andrey Kvasnevskiy(akbet@mail.ru),Roman Akoev (akoevroman@gmail.com), Vladislav Prikhodko (vlados.vp1@gmail.com)
* @link http://ordasoft.com/cck-content-construction-kit-for-joomla.html
* @description OrdaSoft Content Construction Kit
*/
$rand = rand();
$fName = $field->db_field_name;
if(isset($layout_params['fields']['showName_'.$fName]) &&
  $layout_params['fields']['showName_'.$fName] == 'on' && isset($layout_html)){
    
  $replace_fName = str_lreplace('_', '-', $fName);
//  $layout_html = str_replace('-', '_', $layout_html);
  $layout_html = str_replace($replace_fName.'-label-hidden', '', $layout_html);
}
$icon_alias_prefix = (isset($field_from_params[$fName.'_add_icon_alias_prefix'])) ? $field_from_params[$fName.'_add_icon_alias_prefix'] : '';
if($icon_alias_prefix != ''){
    $layout_html = str_replace($field->db_field_name.'_label_icon_prefix_hidden', 'fa '.$icon_alias_prefix, $layout_html);
}
$icon_alias_suffix = (isset($field_from_params[$fName.'_add_icon_alias_suffix'])) ? $field_from_params[$fName.'_add_icon_alias_suffix'] : '';
if($icon_alias_suffix != ''){
    $layout_html = str_replace($field->db_field_name.'_label_icon_suffix_hidden', 'fa '.$icon_alias_suffix, $layout_html);
}

$ordering_calculate = $layout_params['fields'][$fName.'_calculation_order'];

$field_digits_points = (isset($field_from_params[$fName.'_digits_points'])) ? $field_from_params[$fName.'_digits_points'] : 0;
$field_decimal_separator = (isset($field_from_params[$fName.'_decimal_separator'])) ? $field_from_params[$fName.'_decimal_separator'] : '.';
$field_thousands_separator = (isset($field_from_params[$fName.'_thousands_separator'])) ? $field_from_params[$fName.'_thousands_separator'] : '';
$numberFormat = array();
$numberFormat['digits_points'] = $field_digits_points;
$numberFormat['decimal_separator'] = $field_decimal_separator;
$numberFormat['thousands_separator'] = $field_thousands_separator;
$numberFormatJson = json_encode($numberFormat);
$fName = $field->db_field_name . $rand;
?>

<span <?php if(isset($layout_params['fields']['description_'.$field->db_field_name]) && $layout_params['fields']['description_'.$field->db_field_name]=='on' && !empty($layout_params['fields'][$field->db_field_name.'_tooltip']))
        {?>
rel="tooltip" data-toggle="tooltip" data-placement="top" title="<?php echo $layout_params['fields'][$field->db_field_name.'_tooltip'];?>"
    <?php } ?> >
  <?php
    if(isset($field_from_params[$field->db_field_name.'_add_icon_prefix_prefix']) && !empty($field_from_params[$field->db_field_name.'_add_icon_prefix_prefix'])){
        echo '<span class="fa '.$field_from_params[$field->db_field_name.'_add_icon_prefix_prefix'].'"></span>';
    }
    if(!empty($layout_params['fields'][$field->db_field_name.'_prefix'])){
      echo '<span class="cck-prefix">'.$layout_params['fields'][$field->db_field_name.'_prefix'].'</span>';
    }
    if(isset($field_from_params[$field->db_field_name.'_add_icon_prefix_suffix']) && !empty($field_from_params[$field->db_field_name.'_add_icon_prefix_suffix'])){
        echo '<span class="fa '.$field_from_params[$field->db_field_name.'_add_icon_prefix_suffix'].'"></span>';
    }
    if(isset($layout_params['fields']['showName_'.$field->db_field_name]) &&
      $layout_params['fields']['showName_'.$field->db_field_name] == 'on'){
      $layout_html = str_replace($field->db_field_name.'-label-hidden', '', $layout_html);
    }
    
        //echo 'NEW PRICE';
        ?>
    <div id="<?php echo $fName; ?>" class="calculated_price_value" ordering_calculate="<?php echo $ordering_calculate;?>">
        
    </div>
    <?php
    if(isset($field_from_params[$field->db_field_name.'_add_icon_suffix_prefix']) && !empty($field_from_params[$field->db_field_name.'_add_icon_suffix_prefix'])){
        echo '<span class="fa '.$field_from_params[$field->db_field_name.'_add_icon_suffix_prefix'].'"></span>';
    }
    if(!empty($layout_params['fields'][$field->db_field_name.'_suffix'])){
      echo '<span class="cck-suffix">'.$layout_params['fields'][$field->db_field_name.'_suffix'].'</span>';
    }
    if(isset($field_from_params[$field->db_field_name.'_add_icon_suffix_suffix']) && !empty($field_from_params[$field->db_field_name.'_add_icon_suffix_suffix'])){
        echo '<span class="fa '.$field_from_params[$field->db_field_name.'_add_icon_suffix_suffix'].'"></span>';
    }
  ?>
</span>
<script type="text/javascript">
    if(typeof calculate_number_format === 'undefined'){
        calculate_number_format = {}
    }
    calculate_number_format.<?php echo $fName;?> = '<?php echo $numberFormatJson; ?>';

    var eiid = '<?php echo $entityInstance->eiid; ?>';

    jQuerOs(window).on('load',function($) {
        var juri = '<?php echo JUri::root(); ?>'
        calculated_price('<?php echo $entityInstance->eiid; ?>', juri);
    })
    
    
</script>