<?php
$items = array();
$x = null;
?>
<?=
$form->field($model, 'action')->dropDownList([
    '' => '',
    'accept' => 'accept',
    'add-dst-to-address-list' => 'add-dst-to-address-list',
    'add-src-to-address-list' => 'add-src-to-address-list',
    'dst-nat' => 'dst-nat',
    'jump' => 'jump',
    'log' => 'log',
    'masquerade' => 'masquerade',
    'netmap' => 'netmap',
    'passthrough' => 'passthrough',
    'redirect' => 'redirect',
    'return' => 'return',
    'same' => 'same',
    'src-nat' => 'src-nat',
]);
?>
<?= $form->field($model, 'log_prefix')->label('Log Prefix'); ?>

<div id="addresslist">
    <?= $form->field($model, 'address_list')->label('Address List'); ?>
</div>

<div id="addresslisttimeout">
    <?= $form->field($model, 'address_list_timeout')->label('Timeout'); ?>
</div>

<div id="toaddresses">
    <?= $form->field($model, 'to_addresses')->label('To addresses'); ?>
</div>

<div id="toports">
    <?= $form->field($model, 'to_ports')->label('To Ports'); ?>
</div>

<div id="jumptarget">
    <?= $form->field($model, 'jump_target')->label('Jump Target'); ?>
</div>

<?php
$script = <<< JS
    
    $(document).ready(function () {
       
    $.viewMap = {
            'accept': $([]),
            'add-dst-to-address-list': $('#addresslist, #addresslisttimeout'),
            'add-src-to-address-list': $('#addresslist, #addresslisttimeout'),
            'dst-nat': $('#toaddresses, #toports'),
            'jump': $('#jumptarget'),
            'log': $([]),
            'masquerade': $([]),
            'netmap': $('#toaddresses, #toports'),
            'passthrough': $([]),
            'redirect': $('#toports'),
            'return': $([]),
            'same':  $('#toaddresses, #toports'),
            'src-nat':  $('#toaddresses, #toports'),
            
    };
         
            $('#nat-action').change(function () {

    $.each($.viewMap, function () {
    $(this).hide();
    });
            $.viewMap[$(this).val()].show();
    });
       
    });
        
JS;
$this->registerJs($script, \yii\web\View::POS_END);
?>
