 
<?php $__env->startSection('content'); ?>

	<div class="row">
    	<div class="col-lg-12">
    		<h1 class="page-header">Switches</h1>
    	</div>
    </div>
    <div class="row">

        <div class="col-md-4">
            <div class="panel panel-default">
                <div class="panel-heading">
                    Total Active Switches
                </div>
                <div class="panel-body" style="background-color: #c1dde9;">
                    <div style="text-align: center; font-size: 4em;">
                        <strong><?php echo e($switches->count()); ?></strong>
                    </div>
                </div>
            </div>
            
        </div>
        <?php
            $switch_count_w_errors = 0;
            $last_full_update = null;
            foreach($switches as &$switch)
            {
                $switch->error_count = $switch->getErrors();
                if($switch->error_count > 0)
                {
                    $switch_count_w_errors++;
                }
                $switch->last_full_update = $switch->getLastUpdate();
                if(!$last_full_update && $switch->last_full_update)
                {
                    $last_full_update = strtotime($switch->last_full_update);
                }
                elseif($switch->last_full_update && $last_full_update > strtotime($switch->last_full_update))
                {
                    $last_full_update = strtotime($switch->last_full_update);
                }
            }
        ?>
        <div class="col-md-4">
            <div class="panel panel-default">
                <div class="panel-heading">
                    Active Switches w/ Errors
                </div>
                <div class="panel-body"
                    <?php if($switch_count_w_errors > 2): ?>
                        style="background-color: #ff6633;"
                    <?php elseif($switch_count_w_errors > 0): ?>
                        style="background-color: #ff9933;"
                    <?php else: ?>
                        style="background-color: #c1dde9;"
                    <?php endif; ?>
                >
                    <div style="text-align: center; font-size: 4em;">
                        <strong><?php echo e($switch_count_w_errors); ?></strong>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="panel panel-default">
                <div class="panel-heading">
                    Last Full Update
                </div>
                <div class="panel-body"
                    <?php if($last_full_update < strtotime('-48 hours')): ?>
                        style="background-color: #ff6633;"
                    <?php elseif($last_full_update < strtotime('-24 hours')): ?>
                        style="background-color: #ff9933;"
                    <?php else: ?>
                        style="background-color: #c1dde9;"
                    <?php endif; ?>
                >
                    <div style="text-align: center; font-size: 4em;">
                        <strong><?php echo e(date('Y-m-d', $last_full_update)); ?></strong>
                    </div>
                </div>
            </div>
            
        </div>
    </div>

        <div class="row">
		 <div class="col-lg-12">
            <div class="panel panel-default">
            	<?php if(session('status')): ?>
					<div class="alert alert-success">
						<?php echo e(session('status')); ?>

					</div>
				<?php endif; ?>
	
				<?php if(count($errors) > 0): ?>
					<div class="alert alert-danger">
						<strong>Whoops!</strong> There were some problems with your input.<br><br>
						<ul>
							<?php foreach($errors->all() as $error): ?>
								<li><?php echo e($error); ?></li>
							<?php endforeach; ?>
						</ul>
					</div>
				<?php endif; ?>
                <div class="panel-heading">
                   All Switches <a href="<?php echo e(url('uadmin/switches/add')); ?>" style="float: right;"><i class="fa fa-plus"></i></a>
                </div>
                <!-- /.panel-heading -->
                <div class="panel-body">
                    <div class="dataTable_wrapper">
                        <table class="table table-striped table-bordered table-hover" id="dataTables-example2">
                            <thead>
                                <tr>
                               		<th>ID</th>
                               		<th>Name</th>
                               		<th>Address</th>
                               		
                                    <th>Errors</th>
                               		<th>Action</th>
                                </tr>
                            </thead>
                            <tbody>
                            <?php $count = 0; ?>
                            <?php foreach($switches as $switch): ?>
                            <?php $count++; ?>
                            <?php if($count % 2 == 1): ?>
                                <tr class="odd">
                            <?php else: ?>
                            	<tr class="even">
                            <?php endif; ?>
                            		<td><a href="<?php echo e(url('uadmin/switches/ind/'.$switch->id)); ?>"><?php echo e($switch->id); ?></a></td>
                                    <td><a href="<?php echo e(url('uadmin/switches/ind/'.$switch->id)); ?>"><?php echo e($switch->name); ?></a></td>
                                    <td><?php echo e($switch->address); ?></td>
                                    
                                    
                                    <td
                                    <?php if($switch->error_count > 100): ?>
                                        style="background-color: #ff0000; font-weight: 600;"
                                    <?php elseif($switch->error_count > 64): ?>
                                        style="background-color: #ff2200; font-weight: 600;"
                                    <?php elseif($switch->error_count > 32): ?>
                                        style="background-color: #ff4400; font-weight: 600;"
                                    <?php elseif($switch->error_count > 16): ?>
                                        style="background-color: #ff6600; font-weight: 600;"
                                    <?php elseif($switch->error_count > 8): ?>
                                        style="background-color: #ff8800; font-weight: 600;"
                                    <?php elseif($switch->error_count > 4): ?>
                                        style="background-color: #ffaa00; font-weight: 600;"
                                    <?php elseif($switch->error_count > 2): ?>
                                        style="background-color: #ffcc00; font-weight: 600;"
                                    <?php elseif($switch->error_count > 0): ?>
                                        style="background-color: #ffee00; font-weight: 600;"
                                    <?php else: ?>
                                        style="background-color: #c1dde9;"
                                    <?php endif; ?>
                                    ><?php echo e($switch->error_count); ?></td>
                                    <td style="text-align: center;">
                                        <a href="<?php echo e(url('uadmin/switches/ind/'.$switch->id)); ?>">
                                            <i class="fa fa-eye"></i>
                                        </a>
                                    </td>
                                </tr>
                          	<?php endforeach; ?>
                               </tbody>
                        	</table>
                        </div>
                     </div>
                 </div>
             </div>
         </div>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('extras'); ?>

    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/t/bs/pdfmake-0.1.18,dt-1.10.11,b-1.1.2,b-flash-1.1.2,b-html5-1.1.2,b-print-1.1.2/datatables.min.css"/>
    
    
    <style>
    	a:hover{
    		text-decoration: none;
    	}
    	.odd .subBack {
    		background-color: #f0fcff;
    	}
    	.even .subBack {
    		background-color: #ecf7fa;
    	}
    	.floatLeft
    	{
    		float: left;
    	}

    </style>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('bottom'); ?>

	<script type="text/javascript" src="https://cdn.datatables.net/t/bs/pdfmake-0.1.18,dt-1.10.11,b-1.1.2,b-flash-1.1.2,b-html5-1.1.2,b-print-1.1.2/datatables.min.js"></script>

	
    
    <!-- Page-Level Demo Scripts - Tables - Use for reference -->
    <script>
    $(document).ready(function() {
    var table1 =    $('#dataTables-example2').dataTable( {
					"pageLength": 50,
					"order": [[ 3 , 'desc' ],[ 1, 'asc' ]],
					"stateSave" : false,
					"scrollX" : window.innerWidth < 800 ? true : false,


					
        } ); 
 


    });

    

    
    
    if ( typeof $.fn.dataTable == "function" && typeof $.fn.dataTableExt.fnVersionCheck == "function" && $.fn.dataTableExt.fnVersionCheck('1.9.2')/*older versions should work too*/ )
    {
        $.fn.dataTableExt.oApi.clearSearch = function ( oSettings )
        {
     
            var table = this;
             
            //any browser, must include your own file
            //var clearSearch = $('<img src="/images/delete.png" style="vertical-align:text-bottom;cursor:pointer;" alt="Delete" title="Delete"/>');
             
            //no image file needed, css embedding must be supported by browser
            var clearSearch = $('<i class="fa fa-times-circle-o fa-fw" style="vertical-align:text-bottom;cursor:pointer;color: gray;"></i>');
            $(clearSearch).click( function ()
                    {
                          table.fnFilter('');
                    });
            $(oSettings.nTableWrapper).find('div.dataTables_filter').append(clearSearch);
            $(oSettings.nTableWrapper).find('div.dataTables_filter label').css('margin-right', '-16px');//16px the image width
            $(oSettings.nTableWrapper).find('div.dataTables_filter input').css('padding-right', '16px');
        }
     
        //auto-execute, no code needs to be added
        $.fn.dataTable.models.oSettings['aoInitComplete'].push( {
            "fn": $.fn.dataTableExt.oApi.clearSearch,
            "sName": 'whatever'
        } );
    }

    </script> 

<?php $__env->stopSection(); ?>




<?php echo $__env->make('residential.templates.uadmin', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>