<?php
// Copyright 1999-2021. Plesk International GmbH. All rights reserved.
?>
<?php $selectElement = $this->element->getElement('uploadType'); ?>
<?php $selectId = $selectElement->getId(); ?>

<div class='form-row'>
    <div class='field-name'><?php echo $this->elementPart($selectElement)->label() ?></div>
    <div class='field-value'>
        <div class="text-value">

                <div class="indent-box">
                    <input type="radio" class="radio" value="file" id="<?php echo "{$selectId}-file"; ?>"
                        name="<?php echo $selectElement->getFullyQualifiedName(); ?>"
                        <?php echo ('file' == $selectElement->getValue()) ? 'checked="checked"' : ''; ?>
                    />
                    <div class="indent-box-content">
                    <?php $fileElement = $this->element->getElement('file'); ?>
                    <label for="<?php echo "{$selectId}-file"; ?>"><?php echo $selectElement->getMultiOption('file'); ?></label>
                    <div id="<?php echo "{$selectId}-file-row"; ?>"
                         class='form-row<?php echo $fileElement->hasErrors() ? ' error' : '';?>'>
                        <div><?php echo $fileElement->renderFile(); ?></div>
                            <span class='field-errors'<?php echo $fileElement->hasErrors() ? '' : ' style="display:none;"';?>>
                                <?php echo $this->elementPart($fileElement)->errors();?>
                            </span>
                        </div>
                    </div>
                </div>

            <div class="indent-box">
                <input type="radio" class="radio" value="catalog" id="<?php echo "{$selectId}-catalog"; ?>"
                    name="<?php echo $selectElement->getFullyQualifiedName(); ?>"
                    <?php echo ('catalog' == $selectElement->getValue()) ? 'checked="checked"' : ''; ?>
                />
                <div class="indent-box-content">
                    <?php $catalogElement = $this->element->getElement('catalog'); ?>
                    <label for="<?php echo "{$selectId}-catalog"; ?>"><?php echo $selectElement->getMultiOption('catalog'); ?></label>
                    <div id="<?php echo "{$selectId}-catalog-row"; ?>"
                        class='form-row<?php echo $catalogElement->hasErrors() ? ' error' : '';?>'>
                        <?php echo $this->elementPart($catalogElement)->content(); ?>
                        <span class='field-errors'<?php echo $catalogElement->hasErrors() ? '' : ' style="display:none;"';?>>
                            <span class="error-hint"><?php echo current($catalogElement->getErrorMessages()); ?></span>
                        </span>
        </div>
    </div>

</div>
        </div>
    </div>
</div>


<script type="text/javascript">
//<![CDATA[
Jsw.namespace('AdminPanel');

AdminPanel.ApsPackage = {
    updateUploadTypeControlsState: function() {
        if (document.getElementById('package-uploadType-file').checked) {
            document.getElementById('file').disabled = false;
            document.getElementById('package-uploadType-catalog-row').style.display = 'none';
        } else {
            document.getElementById('file').disabled = true;
            document.getElementById('package-uploadType-catalog-row').style.display = '';
        }
    }
}

Jsw.onReady(function() {
    AdminPanel.ApsPackage.updateUploadTypeControlsState();
    document.getElementById('package-uploadType-file').addEventListener('click', AdminPanel.ApsPackage.updateUploadTypeControlsState);
    document.getElementById('package-uploadType-catalog').addEventListener('click', AdminPanel.ApsPackage.updateUploadTypeControlsState);
});
//]]>
</script>
