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

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


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

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

$conditional = salesloo_field_get_conditional_data($args);

$image_url = $args['value'];

if (intval($args['value']) > 0) {
    $image_url = wp_get_attachment_url($args['value']);

    if (empty($image_url)) {
        $image_url = $args['value'];
    }
}

?>
<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__image">
            <?php echo $args['before']; ?>
            <img src="<?php echo $image_url; ?>" />
            <input type="hidden" <?php echo $attributes; ?>>
            <a href="#" class="button" data-choose="Choose Image" data-update="Insert file URL">Choose Image</a>
            <?php echo $args['after']; ?>
        </div>
        <p class="description"><?php echo $args['description']; ?></p>
    </div>
</div>