<?php 
include('authentication.php');
include('includes/header.php');
include('includes/topbar.php');
include('includes/sidebar.php');
?>


<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1>Mattress</h1>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item"><a href="#">Home</a></li>
                        <li class="breadcrumb-item active">Mattress</li>
                    </ol>
                </div>
            </div>
        </div><!-- /.container-fluid -->
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-12">


                    <div class="card">
                        <div class="card-header">
                            <div class="row">
                                <div class="col-sm-6">
                                    <h5 class="m-0">Mattress List</h5>
                                </div><!-- /.col -->
                                <div class="col-sm-6">
                                    <a href="add_mattress_pricing.php" class="btn btn-primary float-sm-right">Add Mattress Pricing</a>
                                </div><!-- /.col -->
                            </div>
                        
                        </div>
                        <!-- /.card-header -->
                        <div class="card-body">
                            <table id="example1" class="table table-bordered table-striped">
                                <thead>
                                    <tr>
                                        <th>S No.</th>
                                        <th>Mattress Name</th>
                                        <th>Size</th>
                                        <th>Thickness</th>
                                        <th>Price</th>
                                        <th>Warrenty</th>
                                        <th>Created At</th>
                                        <th>Action</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php 
                        $i = 1;
                        $ref = "MattressPricing/";
                        $fetchdata = $database->getReference($ref)->getValue();
                        if($fetchdata>0){
                            foreach ($fetchdata as $key => $row) {
                                ?>
                                    <tr>
                                        <td><?=$i?></td>
                                         <td>
                                            <?php 
                                             $ref1 = 'Mattress/'.$row['mattress'].'/';
                                              $matress_data = $database->getReference($ref1)->getValue();
                                              echo($matress_data['name']);
                                            ?>
                                            
                                          </td>
                                        <td><?=$row['size']?></td>
                                        <td><?=$row['thickness']?></td>
                                        <td><?=$row['price']?></td>
                                        <td><?=$row['warrenty']?></td>
                                      
                                        <td><?php echo date('d/m/Y', $row['created_at']/1000); ?></td>
                                        <td>
                                            <div class="row">
                                                <a href="add_mattress_pricing.php?id=<?=$key?>"
                                                    class="btn btn-info btn-sm">Edit</a>
                                                    
                                                    <a href="code.php?id=<?=$key?>&table_name=MattressPricing&file_name=mattress_pricing.php"
                                                    class="btn btn-danger btn-sm ml-3">Delete</a>
                                              
                                            </div>
                                        </td>
                                    </tr>
                                    <?php
                                    $name = "";
                                $i++;
                            }
                        }else{

                        }
                      
                      ?>
                                </tbody>
                                <tfoot>
                                    <tr>
                                        <th>S No.</th>
                                        <th>Mattress Name</th>
                                        <th>Size</th>
                                        <th>Thickness</th>
                                        <th>Price</th>
                                        <th>Warrenty</th>
                                        <th>Created At</th>
                                        <th>Action</th>
                                    </tr>
                                </tfoot>
                            </table>
                        </div>
                        <!-- /.card-body -->
                    </div>
                    <!-- /.card -->
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </div>
        <!-- /.container-fluid -->
    </section>
    <!-- /.content -->
</div>


<?php
include('includes/script.php');
?>
 <script src=
    "https://code.jquery.com/jquery-3.5.1.js">
  </script>
 
  <script>
    // Function to HTML encode the text
    // This creates a new hidden element,
    // inserts the given text into it
    // and outputs it out as HTML
    function htmlEncode(value) {
      return $('<div/>').text(value)
        .html();
    }
 
    $(function () {
 
      // Specify an onclick function
      // for the generate button
      $('#generate').click(function () {
 
        // Generate the link that would be
        // used to generate the QR Code
        // with the given data
        let finalURL =
'https://chart.googleapis.com/chart?cht=qr&chl=' +
          htmlEncode($('#content').val()) +
          '&chs=160x160&chld=L|0'
 
        // Replace the src of the image with
        // the QR code image
        $('.qr-code').attr('src', finalURL);
      });
    });
  </script>
<script>
$(document).ready(function() {
    $('.delete_btn').click(function(e) {
        e.preventDefault();
        var id = $(this).closest('tr').find('.id').text();
        console.log(id);
        $('#delete_id').val(id);
        $('#modal-danger').modal('show');

    });
});
</script>
<?php
include('includes/footer.php');
?>