<?php 

$lang = 1;
$language = 'en';
$shortcode_id = $params['id'];

$language_locale = json_decode(get_post_meta( $shortcode_id, 'language_locale', true ));
$label_arr = array();
$locale = get_locale();
if ( !empty($language_locale)) {
    $language = defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : $language;
    $language = !defined('ICL_LANGUAGE_CODE') && $locale != '' ? substr($locale, 0, 2) : $language;

    if (!isset($language_locale->$language) || $language_locale->$language == null) {
        // $language = 'en';
        $label_arr = $language_locale->$language->labels;
    } else {
        $lang = $language_locale->$language == null ? $language_locale->en->id : $language_locale->$language->id;
        $label_arr = $language_locale->$language == null ? $language_locale->en->labels : $language_locale->$language->labels;
    }
}

$option_arr = json_decode(get_post_meta( $shortcode_id, 'options_data', true ));

// Get the meta value from the database and remove slashes
$terms_data_json = wp_unslash(get_post_meta($shortcode_id, 'terms_data', true));
// Replace "rn" with actual new lines
$terms_data_json_cleaned = preg_replace('/\brn\b/', "\n", $terms_data_json);
$terms_data_json_cleaned = preg_replace('/[[:cntrl:]]/', '', $terms_data_json_cleaned);  // Removes control characters
$terms_data = json_decode($terms_data_json_cleaned)->$language;

$domain_slug = get_post_meta( $shortcode_id, 'domain', true );
?>
<div class="gocars-terms-wrap" 
    data-domain="<?= $domain_slug; ?>"
    data-shortcode_type="terms" 
    id="gocars_terms-<?= $shortcode_id; ?>" 
    data-id="<?= $shortcode_id; ?>">
    <?php 
    $terms= str_replace('&nbsp;', ' ', html_entity_decode($terms_data));
    echo $terms; 
    ?>
</div>
