<script src="<?= getBaseUrl() ?>assets/plugins/jquery/jquery.min.js"></script>

<!-- Content Header (Page header) -->
<?php App\Controllers\BackendController::createService()->showBreadCrumbs( $arrmixBreadCrumbData ) ?>
<!-- /.content-header -->

<!-- Main content -->
<section class="content">
    <div class="container-fluid">
        <div class="js-show-alert-message">
            <?php App\Controllers\BackendController::createService()->showAlertMessage( $arrmixFlashData ) ?>
        </div>

        <div class="card card-info">
            <div class="card-header">
                <h3 class="card-title"><?= $strCardTitle; ?></h3>
            </div>
            <form role="form" method="post" name="form" id="js-form-user-profile" action="<?= getBaseUrl() ?>spanning-tree/edit?used_config_file=<?= $intUsedConfigFile ?>">
                <div class="card-body">
                    <div class="row">
                        <div class="col-4 form-group">
                            <label class="control-label" for="js-mode">Mode Settings: &nbsp;</label>
                            <span><?= ( SPT_MODE_RSTP ==  $arrmixNetworkSettingsDetails['mode_settings'] ) ? 'RSTP' : 'STP' ?></span>
                        </div>    
                        <div class="col-4 form-group">
                            <label class="control-label" for="js-mode-setting-status">Mode Settings Status: &nbsp;</label>
                            <span class="badge badge-<?= ( SPT_MODE_ENABLED ==  $arrmixNetworkSettingsDetails['mode_settings_status'] ) ? 'success' : 'danger' ?>"><?= ( SPT_MODE_ENABLED ==  $arrmixNetworkSettingsDetails['mode_settings_status'] ) ? 'Enabled' : 'Disabled' ?></span>
                        </div>    
                    </div> 

                    <div class="row">
                        <div class="col-4 form-group">
                            <label class="control-label label-required" for="js-priority">Priority</label>
                            <input type="text" class="form-control" id="js-priority" name="priority" placeholder="Priority" value="<?= ( true == isset( $arrmixSpanningTreeDetails ) ) ? $arrmixSpanningTreeDetails['priority'] : \App\Models\SpanningTreeModel::DEFAULT_PRIORITY ?>">
                            <?= getValidationError( 'priority' ) ?>
                        </div>
                        
                        <div class="col-5 form-group">
                            <label class="control-label label-required" for="js-maximum-age">Maximum Age</label>
                            <input type="text" class="form-control" id="js-maximum-age" name="maximum_age" placeholder="Maximum Age" value="<?= ( true == isset( $arrmixSpanningTreeDetails ) ) ? $arrmixSpanningTreeDetails['maximum_age'] : \App\Models\SpanningTreeModel::DEFAULT_MAXIMUM_AGE ?>">
                            <?= getValidationError( 'maximum_age' ) ?>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-4 form-group">
                            <label class="control-label label-required" for="js-hello-time">Hello Time</label>
                            <input type="text" class="form-control" id="js-hello-time" name="hello_time" placeholder="Hello Time" value="<?= ( true == isset( $arrmixSpanningTreeDetails ) ) ? $arrmixSpanningTreeDetails['hello_time'] : \App\Models\SpanningTreeModel::DEFAULT_HELLO_TIME ?>">
                            <?= getValidationError( 'hello_time' ) ?>
                        </div>
                        
                        <div class="col-4 form-group">
                            <label class="control-label label-required" for="js-forward-delay">Forward Delay</label>
                            <input type="text" class="form-control" id="js-forward-delay" name="forward_delay" placeholder="Forward Delay" value="<?= ( true == isset( $arrmixSpanningTreeDetails ) ) ? $arrmixSpanningTreeDetails['forward_delay'] : \App\Models\SpanningTreeModel::DEFAULT_FORWARD_DELAY ?>">
                            <?= getValidationError( 'forward_delay' ) ?>
                        </div>
                    </div>
                    
                    <div class="row">
                        <div class="col-4 form-group">
                            <label class="control-label label-required" for="js-primary-port">Primary Port</label>
                            <select class="form-control" name="primary_port" id="js-primary-port">
                                <option value="" selected="selected" disabled="disabled">Select Option</option>
                                <option value="<?= LAN1 ?>" <?= ( true == isset( $arrmixSpanningTreeDetails ) && ( $arrmixSpanningTreeDetails['primary_port'] == LAN1 ) ) ? 'selected="selected"' : set_select( 'primary_port', LAN1 ); ?>>
                                    LAN1
                                </option>
                                <option value="<?= LAN2 ?>" <?= ( true == isset( $arrmixSpanningTreeDetails ) && ( $arrmixSpanningTreeDetails['primary_port'] == LAN2 ) ) ? 'selected="selected"' : set_select( 'primary_port', LAN2 ); ?>>
                                    LAN2
                                </option>
                            </select>
                            <?= getValidationError( 'primary_port' ) ?>                            
                        </div>
                        <div class="col-4 form-group">
                            <label class="control-label label-required" for="js-seconday-port">Secondary Port</label>
                            <input type="text" class="form-control" name="secondary_port" value="<?= ( true == isset( $arrmixSpanningTreeDetails )  ) ? ( LAN1 == $arrmixSpanningTreeDetails['secondary_port'] ) ? 'LAN1' : 'LAN2' : set_value( 'secondary_port' ) ?>" id="js-secondary-port" readonly>
                            <?= getValidationError( 'secondary_port' ) ?>                            
                        </div>
                    </div>

                    <!-- /.card-body -->
                </div>    
                <!-- /.card-body -->

                <div class="card-footer">
                    <button type="submit" class="btn btn-outline-success">Submit</button>
                    <a href="<?= getBaseUrl() ?>spanning-tree/view" class="btn btn-outline-danger"> Cancel</a>
                </div>
            </form>
        </div>
            
    </div><!-- /.container-fluid -->
</section>

<script>
    $(document).ready(function() {

        $( '#js-primary-port' ).on( 'change', function() { 

            var strPrimaryPort = $( this ).val();

            if( 'LAN1' == strPrimaryPort ) {
                var strSecondaryPort = 'LAN2';
            } else {
                var strSecondaryPort = 'LAN1';
            }

            $( '#js-secondary-port' ).val( strSecondaryPort );
        } );
    });

</script>