<?php
/*
 * print css with cheking value is empty or not
 *
 */

function dexen_print_css($props = '', $values = array(), $vkey = '', $pre_fix = '', $post_fix = '') {
    if (isset($values[$vkey]) && !empty($values[$vkey])) {
        print wp_kses_post($props . ":" . $pre_fix . $values[$vkey] . $post_fix . ";\n");
    }
}

function dexen_color_brightness($colourstr, $steps, $darken = false) {
    $colourstr = str_replace('#', '', $colourstr);
    $rhex = substr($colourstr, 0, 2);
    $ghex = substr($colourstr, 2, 2);
    $bhex = substr($colourstr, 4, 2);

    $r = hexdec($rhex);
    $g = hexdec($ghex);
    $b = hexdec($bhex);
    if ($darken) {
        $steps = $steps * -1;
    }
    $r = max(0, min(255, $r + $steps));
    $g = max(0, min(255, $g + $steps));
    $b = max(0, min(255, $b + $steps));
    $hex = "#";
    $hex .= str_pad(dechex($r), 2, "0", STR_PAD_LEFT);
    $hex .= str_pad(dechex($g), 2, "0", STR_PAD_LEFT);
    $hex .= str_pad(dechex($b), 2, "0", STR_PAD_LEFT);

    return $hex;
}
function dexen_rgb_opacity($colourstr, $opacity=1) {
  $colourstr = str_replace('#', '', $colourstr);
  $rhex = substr($colourstr, 0, 2);
  $ghex = substr($colourstr, 2, 2);
  $bhex = substr($colourstr, 4, 2);

  $r = hexdec($rhex);
  $g = hexdec($ghex);
  $b = hexdec($bhex);
  $rgb = 'rgba('.$r.','. $g.','.$b.','.$opacity.')';
  return $rgb;
}
 

function dexen_get_custom_styles() {
    global $dexen_options;
    $redix_opt_prefix = 'dexen_';
    $dexen_main_color  ='';
    $dexen_second_color  ='';
    $button_text_color  ='';

    ob_start();

    if ( (isset($dexen_options[$redix_opt_prefix . 'preloder_image'])) && (!empty($dexen_options[$redix_opt_prefix . 'preloder_image']))) {
      $preloder_image  = $dexen_options[$redix_opt_prefix . 'preloder_image']['url'] ;
      ?>
    .preloader {
        background-image: url(<?php echo esc_url($preloder_image);?>);
    }
<?php
   }
     if ( (isset($dexen_options[$redix_opt_prefix . 'footer_background_image'])) && (!empty($dexen_options[$redix_opt_prefix . 'footer_background_image']))) {
        $footer_background_image  = $dexen_options[$redix_opt_prefix . 'footer_background_image']['url'] ;
        ?>
      .site-footer:before {
          background-image: url(<?php echo esc_url($footer_background_image);?>);
      }
 <?php
     }
 
    ?>


<?php
    $dexen_custom_css = ob_get_clean();
    return $dexen_custom_css;
}
