<div class="card-nody">
    <h5>{{ 'File'|trans }}</h5>


    <form method="post" action="{{ '/api/admin/servicedownloadable/config_save'|link }}" class="api-form" data-api-msg="Settings updated">

        <div class="row mb-3">
            <label class="col-md-3 form-label">
                {{ 'Keep Orders Updated'|trans }}
            </label>
            <div class="col-md-6">
                <div class="form-check form-check-inline">
                    <input class="form-check-input" type="radio" name="update_orders" value="1" {% if product.config.update_orders == '1' %} checked {% endif %} {% if product.config.update_orders == '' %} checked {% endif %} required>
                    <label class="form-check-label">Yes</label>
                </div>
                <div class="form-check form-check-inline">
                    <input class="form-check-input" type="radio" name="update_orders" value="0" {% if product.config.update_orders == '0' %} checked {% endif %} required>
                    <label class="form-check-label">No</label>
                </div>
            </div>
        </div>
        <input type="hidden" name="id" value="{{ product.id }}">
        <input type="submit" value="{{ 'Save config'|trans }}" class="btn btn-primary w-100" id="bb-upload-button">
    </form>
    <form method="post" action="" class="" enctype="multipart/form-data" target="uploadframe" id="bb-upload-form">
        <input type="hidden" name="CSRFToken" value="{{ CSRFToken }}"/>
        {% if product.config.filename  %}
        <div class="mb-3 row">
            <label class="form-label col-3 col-form-label">{{ 'Currently uploaded file'|trans }}:</label>
            <div class="col">
                {{ product.config.filename  }}
            </div>
        </div>
        {% endif %}

        <div class="mb-3 row">
            <label class="form-label col-3 col-form-label">{{ 'Upload new file'|trans }}:</label>
            <div class="col">
                <input class="form-control" type="file" name="file_data" id="file_data">
            </div>
        </div>



        <input type="hidden" name="id" value="{{ product.id }}">
        <input type="submit" value="{{ 'Upload'|trans }}" class="btn btn-primary w-100" id="bb-upload-button">
    </form>
</div>

<script>
$(function() {
    $('body').append('<iframe id="uploadframe" name="uploadframe" style="display:none" />');

    $('#bb-upload-form').on('submit', function() {
        $(this).attr('action', bb.restUrl('admin/servicedownloadable/upload'));

        iframe = $('#uploadframe').load(function() {
            response = iframe.contents().find('body');
            data = $.parseJSON(response.text());

            if (data.error) {
                bb.error(data.error.message, data.error.code);
            }

            if (data.result) {
                FOSSBilling.message("{{ 'File was uploaded'|trans }}");
            }

            setTimeout(function() {
                response.html('');
            }, 1);
        });
    });
});
</script>
