<!-- Begin Page Content -->
<div class="container-fluid">

    <!-- Page Heading -->
    <h1 class="h3 mb-2 text-gray-800">All Dishes</h1>
    <!-- DataTales Example -->
    <div class="card shadow mb-4">
        <div class="card-header py-3">
            <button class="btn btn-primary" onclick="location.href = '<?php echo(base_url()); ?>dashboard/adddishes'">Add New Dish</button>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                    <thead>
                        <tr>
                            <th>Title</th>
                            <th>Image</th>
                            <th>Resturent</th>
                            <th>Rating</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                        <th>Title</th>
                        <th>Image</th>
                        <th>Resturent</th>
                        <th>Rating</th>
                        <th>Actions</th>
                        </tr>
                    </tfoot>
                    <tbody>
                        <?php
                           if (!empty($specialities)) {
                              $count = 1;
                              foreach ($specialities as $id => $speciality) {
                                

                        ?>
                        <tr>
                            <td style="width: 40%;"> <?php echo output($speciality['name']); ?></td>
                            <td>
                                <?php if ($speciality['image'] != "") { ?>

                                <img src="<?php echo output($speciality['image']); ?>" class="img-thumbnail" width="100" height="100" >
                                <?php } else { ?>
                                <img class="img-thumbnail" src="http://placehold.jp/100x100.png">
                                <?php } ?>
                            </td>

                            <td style="width: 40%;"> <?php echo getresname($speciality['res_id']); ?></td>

                            
                            <td style="width: 40%;"> 
                            <?php 
                            $x=0; 
                            if(isset($speciality['rating'])){
                            $rating=$speciality['rating']; 

                            foreach($rating as $r){
                                $x= $x+$r;
                            }

                            echo $x/count($rating)."/5";
                        }else{
                            echo $x;
                        }
                            
                            ?></td>
                            <td style="width: 20%;">
                            <a class="icon" style="text-decoration: none;" href="<?php echo base_url(); ?>dashboard/viewdish/<?php echo output($id); ?>">
                                    <button class="btn btn-success mt-2">View</button>
                                </a>
                            <a class="icon" style="text-decoration: none;" href="<?php echo base_url(); ?>dashboard/editdish/<?php echo output($id); ?>">
                                    <button class="btn btn-info mt-2">Update</button>
                                </a>
                                <a class="icon" style="text-decoration: none;" href="<?php echo base_url(); ?>dashboard/deletespeciality/<?php echo output($id); ?>">
                                    <button class="btn btn-danger mt-2">Delete</button>
                                </a>
                            </td>
                        </tr>
                        <?php } } ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

</div>
<!-- /.container-fluid -->