<?php
defined('_JEXEC') or die('Restricted access');

/**
* @package OS CCK
* @copyright 2020 OrdaSoft.
* @author Andrey Kvasnevskiy(akbet@mail.ru),Roman Akoev (akoevroman@gmail.com)
* @link http://ordasoft.com/cck-content-construction-kit-for-joomla.html
* @description OrdaSoft Content Construction Kit
*/

$fName = $field->db_field_name;
$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);
//$val_calc_price = ($price_fields != '') ? $price_fields : '';


if(isset($layout_params['fields'][$fName.'_add_icon_prefix_prefix']) && !empty($layout_params['fields'][$fName.'_add_icon_prefix_prefix'])){
    echo '<span class="fa '.$layout_params['fields'][$fName.'_add_icon_prefix_prefix'].'"></span>';
}
if(!empty($layout_params['fields'][$fName.'_prefix'])){
  echo '<span class="cck-prefix">'.$layout_params['fields'][$fName.'_prefix'].'</span>';
}
if(isset($layout_params['fields'][$fName.'_add_icon_prefix_suffix']) && !empty($layout_params['fields'][$fName.'_add_icon_prefix_suffix'])){
    echo '<span class="fa '.$layout_params['fields'][$fName.'_add_icon_prefix_suffix'].'"></span>';
}
    ?>
<span   

<?php if(isset($layout_params['fields']['description_'.$fName]) 
            && $layout_params['fields']['description_'.$fName]=='on' 
            && !empty($layout_params['fields'][$fName.'_tooltip']))
        {?>
    rel="tooltip" data-toggle="tooltip" data-placement="top" title="<?php echo $layout_params['fields'][$fName.'_tooltip'];?>"
        <?php } ?> >
    <span id="buy_requesr_calculated_price"></span>
</span>

<?php 
if(isset($layout_params['fields'][$fName.'_add_icon_suffix_prefix']) && !empty($layout_params['fields'][$fName.'_add_icon_suffix_prefix'])){
    echo '<span class="fa '.$layout_params['fields'][$fName.'_add_icon_suffix_prefix'].'"></span>';
}
if(!empty($layout_params['fields'][$fName.'_suffix'])){
  echo '<span class="cck-suffix">'.$layout_params['fields'][$fName.'_suffix'].'</span>';
}
if(isset($layout_params['fields'][$fName.'_add_icon_suffix_suffix']) && !empty($layout_params['fields'][$fName.'_add_icon_suffix_suffix'])){
    echo '<span class="fa '.$layout_params['fields'][$fName.'_add_icon_suffix_suffix'].'"></span>';
}
?>
<script type="text/javascript">
    //if(typeof calculate_number_format === 'undefined'){
    //    calculate_number_format = {}
    //}
    //calculate_number_format.<?php //echo $fName;?>// = '<?php //echo $numberFormatJson; ?>//';
//    window.addEventListener('load', ...)
    window.addEventListener('load',function(){
//        console.log('33333333333333', jQuerOs('div.instance_body[eiid=<?php echo $layout->parent_eiid; ?>]'))
        calculatedPrice<?php echo $layout->parent_eiid;?>();
        jQuerOs('.tracked').on('change', function(){
            setTimeout(function() {
    //            getBuyRentRequestCalculatedPrice('<?php echo $layout->type; ?>', '<?php echo $layout->parent_eiid; ?>');
            calculatedPrice<?php echo $layout->parent_eiid;?>();
            },300);
        })
    });
    
    
    function calculatedPrice<?php echo $layout->parent_eiid;?>(){
        var juri = '<?php echo JUri::root(); ?>'
        getBuyRentRequestCalculatedPrice('<?php echo $layout->type; ?>', '<?php echo $layout->parent_eiid; ?>', '<?php echo $layout->lid; ?>', '<?php echo $numberFormatJson; ?>', juri);
    }
</script>