<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-slave-device" action="<?= getBaseUrl() ?>device-settings/com-settings/<?= true == isset( $arrmixSlaveDeviceDetails ) ? 'edit-slave-device?slv_id=' . $arrmixSlaveDeviceDetails['slv_id'] : 'add-slave-device' ?>">
                <div class="card-body">
                    <div class="row">
                        <div class="col-4 form-group">
                            <label class="control-label label-required" for="js-slave-id">Slave Id</label>
                            <select class="form-control js-select2" name="slv_id">
                                <option selected="selected" disabled="disabled">Select Option</option>
                                <?php 
                                    for( $intCounter = 1; $intCounter <=255; $intCounter++ ) { 
                                        
                                        $strSelected = '';
                                        if( true == isset( $arrmixSlaveDeviceDetails ) && $arrmixSlaveDeviceDetails['slv_id'] == $intCounter ) {
                                            $strSelected = 'selected="selected"';
                                        }

                                        $strDisabled = '';
                                        if( false == isVal( $strSelected ) && true == isValArr( $arrintSlaveIds ) && true == in_array( $intCounter, $arrintSlaveIds ) ) {
                                            $strDisabled = 'disabled="disabled"';
                                        }
                                ?>
                                            <option value="<?= $intCounter ?>" <?= $strSelected . $strDisabled ?> <?= set_select( 'slv_id', $intCounter ); ?>><?= $intCounter; ?></option>    
                                <?php } ?>    
                            </select>
                            <?= getValidationError( 'slv_id' ) ?>
                        </div>

                        <div class="col-4 form-group">
                            <label class="control-label label-required" for="js-register-address">Register Address</label>
                            <input type="text" class="form-control" id="js-register-address" name="reg_add" placeholder="Register Address" value="<?= ( true == isset( $arrmixSlaveDeviceDetails ) ) ? $arrmixSlaveDeviceDetails['reg_add'] : set_value( 'reg_add' ) ?>">
                            <?= getValidationError( 'reg_add' ) ?>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-4 form-group">
                            <label class="control-label label-required" for="js-function-code">Function Code</label>
                            <input type="text" class="form-control" id="js-function-code" name="fun_code" placeholder="Function Code" value="<?= ( true == isset( $arrmixSlaveDeviceDetails ) ) ? $arrmixSlaveDeviceDetails['fun_code'] : set_value( 'fun_code' ) ?>">
                            <?= getValidationError( 'fun_code' ) ?>
                        </div>

                        <div class="col-4 form-group">
                            <label class="control-label label-required" for="js-no-of-registers">Number of Register</label>
                            <input type="text" class="form-control" id="js-no-of-registers" name="no_of_reg" placeholder="Number of Register" value="<?= ( true == isset( $arrmixSlaveDeviceDetails ) ) ? $arrmixSlaveDeviceDetails['no_of_reg'] : set_value( 'no_of_reg' ) ?>">
                            <?= getValidationError( 'no_of_reg' ) ?>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-4 form-group">
                            <label class="control-label label-required" for="js-slave-read">Read</label>
                            <input type="text" class="form-control" id="js-slave-read" name="slv_rd" placeholder="Read" value="<?= ( true == isset( $arrmixSlaveDeviceDetails ) ) ? $arrmixSlaveDeviceDetails['slv_rd'] : set_value( 'slv_rd' ) ?>">
                            <?= getValidationError( 'slv_rd' ) ?>
                        </div>

                        <div class="col-4 form-group">
                            <label class="control-label label-required" for="js-request-interval">Request Interval</label>
                            <select class="form-control js-select2" name="req_intv">
                                <option selected="selected" disabled="disabled">Select Option</option>
                                <?php 
                                    for( $intCounter = 1; $intCounter <=3600; $intCounter++ ) { 
                                        
                                        $strSelected = '';
                                        if( true == isset( $arrmixSlaveDeviceDetails ) && $arrmixSlaveDeviceDetails['req_intv'] == $intCounter ) {
                                            $strSelected = 'selected="selected"';
                                        }
                                ?>
                                            <option value="<?= $intCounter ?>" <?= $strSelected?> <?= set_select( 'req_intv', $intCounter ); ?>><?= $intCounter; ?></option>    
                                <?php } ?>    
                            </select>
                            <?= getValidationError( 'req_intv' ) ?>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-4 form-group">
                            <label class="control-label label-required" for="js-slave-data-type">Data Type</label>
                            <select class="form-control" name="data_type">
                            <?php 
                                foreach( \App\Models\SlaveDevicesModel::$s_arrstrDataTypes as $strDataTypeKey => $strDataTypeValue ) { 
                                    
                                    $strSelected = '';
                                    if( true == isset( $arrmixSlaveDeviceDetails ) && $arrmixSlaveDeviceDetails['data_type'] == $strDataTypeKey ) {
                                        $strSelected = 'selected="selected"';
                                    }
                            ?>
                                    <option value="<?= $strDataTypeKey ?>" <?= $strSelected?> <?= set_select( 'data_type', $strDataTypeKey ); ?>><?= $strDataTypeValue; ?></option>    
                            <?php } ?>    
                            </select>
                            <?= getValidationError( 'data_type' ) ?>
                        </div>
                    </div>
                    <!-- /.card-body -->
                </div>    
                <!-- /.card-body -->

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

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

</script>