<?php
/**
 * @version		   1.9.10
 * @package        Joomla
 * @subpackage	   Edocman
 * @author         Tuan Pham Ngoc
 * @copyright	   Copyright (C) 2018-2023 Ossolution Team
 * @license        GNU/GPL, see LICENSE.php
 */
// no direct access
defined( '_JEXEC' ) or die ;
use Joomla\CMS\Language\Text;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Toolbar\ToolbarHelper;

$bootstrapHelper	= new EDocmanHelperBootstrap(EDocmanHelperHtml::getAdminBootstrapHelper());
$rowFluidClass		= $bootstrapHelper->getClassMapping('row-fluid');
$span12Class		= $bootstrapHelper->getClassMapping('span12');
ToolbarHelper::title(Text::_('EDOCMAN_IMPORT_DOCUMENTS'),'upload');
ToolbarHelper::save('save', Text::_('Import'));
ToolbarHelper::cancel('cancel');	 
?>

<style>
.import-container {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    margin: 20px 0;
}

.import-options-card {
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.import-options-title {
    font-size: 18px;
    font-weight: 600;
    color: #495057;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #007cba;
}

.form-row {
    display: flex;
    align-items: flex-start;
    margin-bottom: 20px;
    gap: 20px;
}

.form-label {
    min-width: 120px;
    font-weight: 500;
    color: #495057;
    padding-top: 8px;
    text-align: right;
}

.form-control-wrapper {
    flex: 1;
    max-width: 400px;
}

.form-control, .form-select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 14px;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.form-control:focus, .form-select:focus {
    border-color: #007cba;
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(0, 124, 186, 0.25);
}

.form-help {
    flex: 1;
    font-size: 13px;
    color: #6c757d;
    line-height: 1.4;
    padding-top: 8px;
}

.access-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.radio-group {
    display: flex;
    gap: 20px;
    margin-bottom: 15px;
}

.radio-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.radio-item input[type="radio"] {
    margin: 0;
}

.access-content {
    padding: 15px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    background: #f8f9fa;
}

@media (max-width: 768px) {
    .form-row {
        flex-direction: column;
        gap: 10px;
    }
    
    .form-label {
        text-align: left;
        min-width: auto;
    }
    
    .form-control-wrapper {
        max-width: none;
    }
}
</style>

<form action="index.php?option=com_edocman&view=import" method="post" name="adminForm" id="adminForm">
    <div class="import-container">
        <div class="import-options-card">
            <h3 class="import-options-title"><?php echo Text::_('EDOCMAN_IMPORT_OPTIONS'); ?></h3>
            
            <!-- Folder Selection -->
            <div class="form-row">
                <label class="form-label"><?php echo Text::_('Folder'); ?></label>
                <div class="form-control-wrapper">
                    <?php echo $this->lists['folder']; ?>
                </div>
                <div class="form-help">
                    Choose the where your documents are stored and you want to import. If you want to scan the root folder (the <strong>Document path</strong> in the configuration), leave this field empty
                </div>
            </div>

            <!-- File Extensions -->
            <div class="form-row">
                <label class="form-label" for="exts"><?php echo Text::_('EDOCMAN_FILE_EXT'); ?></label>
                <div class="form-control-wrapper">
                    <input class="form-control" type="text" name="exts" id="exts" maxlength="250" 
                           value="<?php echo htmlspecialchars($this->config->allowed_file_types); ?>" 
                           placeholder="doc, docx, pdf, jpg, png..." />
                </div>
                <div class="form-help">
                    <?php echo Text::_('EDOCMAN_CHOOSE_IMPORT_FILE'); ?>
                </div>
            </div>

            <!-- Category Selection -->
            <div class="form-row">
                <label class="form-label"><?php echo Text::_('EDOCMAN_CATEGORY'); ?></label>
                <div class="form-control-wrapper">
                    <?php echo EdocmanHelper::getChoicesJsSelect($this->lists['category_id']); ?>
                </div>
                <div class="form-help">
                    <?php echo Text::_('EDOCMAN_CHOOSE_CATEGORY_IMPORT'); ?>
                </div>
            </div>

            <?php if(!$this->config->access_level_inheritance): ?>
            <!-- Access Level -->
            <div class="form-row">
                <label class="form-label"><?php echo Text::_('EDOCMAN_ACCESS'); ?></label>
                <div class="form-control-wrapper">
                    <div class="access-controls">
                        <div class="radio-group">
                            <div class="radio-item">
                                <input type="radio" name="accesspicker" id="preset_radio" value="0" checked 
                                       onchange="updateRadioButton(this.value)" />
                                <label for="preset_radio"><?php echo Text::_('EDOCMAN_PRESETS'); ?></label>
                            </div>
                            <div class="radio-item">
                                <input type="radio" name="accesspicker" id="groups_radio" value="1" 
                                       onchange="updateRadioButton(this.value)" />
                                <label for="groups_radio"><?php echo Text::_('EDOCMAN_GROUPS'); ?></label>
                            </div>
                        </div>
                        
                        <div id="presetsdiv" class="access-content">
                            <?php echo $this->lists['access']; ?>
                        </div>
                        
                        <div id="groupsdiv" class="access-content" style="display:none;">
                            <?php echo $this->lists['groups']; ?>
                        </div>
                    </div>
                </div>
                <div class="form-help">
                    <?php echo Text::_('EDOCMAN_CHOOSE_ACCESS_LEVEL_IMPORT'); ?>
                </div>
            </div>
            <?php endif; ?>
        </div>
    </div>

    <?php echo HTMLHelper::_('form.token'); ?>
    <input type="hidden" name="task" value="" />
</form>

<script type="text/javascript">
function updateRadioButton(select_item) {
    const presetsDiv = document.getElementById('presetsdiv');
    const groupsDiv = document.getElementById('groupsdiv');
    
    if(select_item == '0') {
        presetsDiv.style.display = 'block';
        groupsDiv.style.display = 'none';
    } else {
        presetsDiv.style.display = 'none';
        groupsDiv.style.display = 'block';
    }
}

// Initialize form styling for dropdowns
document.addEventListener('DOMContentLoaded', function() {
    // Add form-select class to select elements
    const selects = document.querySelectorAll('select');
    selects.forEach(function(select) {
        if (!select.classList.contains('form-select')) {
            select.classList.add('form-select');
        }
    });
});
</script>
