<?php
$attributes = '';
if ($args['id']) {
    $attributes .= ' id="' . $args['id'] . '" ';
}

if ($args['name']) {
    $attributes .= ' name="' . $args['name'] . '" ';
}

if ($args['required']) {
    $attributes .= ' required';
}

if ($args['readonly']) {
    $attributes .= ' readonly';
}

$conditional = salesloo_field_get_conditional_data($args);

?>
<div class="salesloo-field <?php echo $args['direction']; ?>" <?php echo implode(' ', $conditional); ?>>
    <div class="salesloo-field-label">
        <label><?php echo $args['label']; ?></label>
    </div>
    <div class="salesloo-field-input">
        <div class="salesloo-field__radio">
            <?php echo $args['before']; ?>
            <input type="hidden" value="<?php echo $args['value']; ?>" name="<?php echo $args['name']; ?>" />
            <?php foreach ((array)$args['options'] as $value => $label) {
                $checked = $args['value'] == $value ? ' checked="checked"' : '';
                echo '<label><input type="radio" value="' . $value . '"' . $attributes . ' ' . $checked . '/><span>' . $label . '</span></label>';
            } ?>
            <?php echo $args['after']; ?>
        </div>
        <p class="description"><?php echo $args['description']; ?></p>
    </div>
</div>