<?php defined('ALTUMCODE') || die() ?>

<div>
    <div class="form-group">
            <label for="provider"><?= l('admin_settings.sms.provider') ?></label>
            <select id="provider" name="provider" class="form-control form-control-lg">
                <option value="Farapayamak" <?= settings()->sms->provider == 'Farapayamak' ? 'selected="selected"' : null ?>>فراپیامک</option>
                <option value="Melipayamak" <?= settings()->sms->provider == 'Melipayamak' ? 'selected="selected"' : null ?>>ملی پیامک</option>
                <option value="Payamito" <?= settings()->sms->provider == 'Payamito' ? 'selected="selected"' : null ?>>پیامیتو</option>
                <option value="IpPanel" <?= settings()->sms->provider == 'IpPanel' ? 'selected="selected"' : null ?>>IpPanel</option>
                <option value="FarazSMS" <?= settings()->sms->provider == 'FarazSMS' ? 'selected="selected"' : null ?>>فراز اس ام اس</option>
                <option value="Kavenegar" <?= settings()->sms->provider == 'Kavenegar' ? 'selected="selected"' : null ?>>کاوه نگار</option>
                <option value="sms_ir" <?= settings()->sms->provider == 'sms_ir' ? 'selected="selected"' : null ?>>sms.ir</option>
            </select>
        </div>
    <!-- <div class="form-group">
            <label for="apiMode"><?= l('admin_settings.sms.apiMode') ?></label>
            <select id="apiMode" name="apiMode" class="form-control form-control-lg">
                <option value="1" <?= settings()->sms->apiMode ? 'selected="selected"' : null ?>><?= l('global.yes') ?></option>
                <option value="0" <?= !settings()->sms->apiMode ? 'selected="selected"' : null ?>><?= l('global.no') ?></option>
            </select>
        </div>-->
    
    <div class="form-group">
        <label for="from"><?= l('admin_settings.sms.from') ?></label>
        <input type="text" name="from" class="form-control form-control-lg" value="<?= settings()->sms->from ?>" />
        <small class="form-text text-muted"><?= l('admin_settings.sms.from_help') ?></small>
    </div>
    
    
    
    <!--<div class="form-group">
        <label for="bodyId"><?= l('admin_settings.sms.bodyId') ?></label>
        <input type="text" name="bodyId" class="form-control form-control-lg" value="<?= settings()->sms->bodyId ?>" />
        <small class="form-text text-muted"><?= l('admin_settings.sms.bodyId_help') ?></small>
    </div>-->
    
    <div class="form-group">
        <label for="apiKey"><?= l('admin_settings.sms.apiKey') ?></label>
        <input type="text" name="apiKey" class="form-control form-control-lg" value="<?= settings()->sms->apiKey ?>" />
        <small class="form-text text-muted"><?= l('admin_settings.sms.apiKey_help') ?></small>
    </div>
    
    <div class="form-group">
        <label for="username"><?= l('admin_settings.sms.username') ?></label>
        <input id="username" type="text" name="username" class="form-control form-control-lg" value="<?= settings()->sms->username ?>" />
    </div>

    <div class="form-group">
        <label for="password"><?= l('admin_settings.sms.password') ?></label>
        <input id="password" type="password" name="password" class="form-control form-control-lg" value="<?= settings()->sms->password ?>" />
    </div>
        <div class="custom-control custom-switch mb-3">
        <input id="status" name="status" type="checkbox" class="custom-control-input" <?= settings()->sms->status ? 'checked="checked"' : null ?>>
        <label class="custom-control-label" for="status"><?= l('admin_settings.sms.status') ?></label>
    </div>

</div>

<button type="submit" name="submit" class="btn btn-lg btn-block btn-primary mt-4"><?= l('global.update') ?></button>

<?php ob_start() ?>
<!--<script>
    'use strict';

   
    let mode_handler = () => {
        
        var e = document.querySelector('select[name="apiMode"]');
        var value = e.value;
        
        if(value==1)
        {
           document.querySelector('input[name="from"]').setAttribute('readonly', 'readonly');
           document.querySelector('input[name="bodyId"]').removeAttribute('readonly'); 
        }
        else
        {
           document.querySelector('input[name="from"]').removeAttribute('readonly'); 
           document.querySelector('input[name="bodyId"]').setAttribute('readonly', 'readonly');
        }
        
       
    }

    mode_handler();
    document.querySelector('select[name="apiMode"]').addEventListener('change', mode_handler);
    </script>-->
    
    
    <script>
        'use strict';

   
    let mode_handler = () => {
        
        var e = document.querySelector('select[name="provider"]');
        var value = e.value;
        
        if(value=="Kavenegar" || value == "sms_ir")
        {
           document.querySelector('input[name="username"]').setAttribute('readonly', 'readonly');
           document.querySelector('input[name="password"]').setAttribute('readonly', 'readonly');
           document.querySelector('input[name="apiKey"]').removeAttribute('readonly'); 
        }
        else
        {
           document.querySelector('input[name="username"]').removeAttribute('readonly');
           document.querySelector('input[name="password"]').removeAttribute('readonly');
           document.querySelector('input[name="apiKey"]').setAttribute('readonly', 'readonly'); 
        }
        
       
    }

    mode_handler();
    document.querySelector('select[name="provider"]').addEventListener('change', mode_handler);
    </script>
<?php \Altum\Event::add_content(ob_get_clean(), 'javascript') ?>

