<?php
/**
 * Paws & Care Premium Customizer Repeater - Customizer Registration
 *
 * @package paws-and-care
 */

if (!defined('ABSPATH')) {
    exit;
}

/**
 * Sanitize repeater control input
 *
 * @param string $input JSON encoded input.
 * @return string Sanitized JSON encoded output.
 */
function paws_and_care_repeater_sanitize($input)
{
    $input_decoded = json_decode($input, true);

    if (!empty($input_decoded)) {
        foreach ($input_decoded as $boxk => $box) {
            foreach ($box as $key => $value) {

                switch ($key) {
                    case 'icon_value':
                        $input_decoded[$boxk][$key] = sanitize_key($value);
                        break;

                    case 'link':
                    case 'link2':
                        $input_decoded[$boxk][$key] = esc_url_raw($value);
                        break;

                    default:
                        $input_decoded[$boxk][$key] = wp_kses_post(force_balance_tags($value));
                }
            }
        }
        return json_encode($input_decoded);
    }
    return $input;
}
