<?php include(APPPATH . 'views/layout/template-top.php'); ?>
<?php include(APPPATH . 'views/layout/header.php'); ?>
<!-- Main Container -->
<div class="main-container">
    <div class="xs-pd-20-10">
        <div class="min-height-200px">
            <!-- Page Header -->
            <div class="page-header mb-30">
                <div class="row">
                    <div class="col-md-6 col-sm-12">
                        <div class="title">
                            <h4>Branches Management</h4>
                        </div>
                        <nav aria-label="breadcrumb" role="navigation">
                            <ol class="breadcrumb">
                                <li class="breadcrumb-item"><a href="<?php echo base_url(); ?>">Home</a></li>
                                <li class="breadcrumb-item active" aria-current="page">Branches</li>
                            </ol>
                        </nav>
                    </div>
                    <div class="col-md-6 col-sm-12 text-right">
                        <a href="<?php echo base_url('branches/add'); ?>" class="btn btn-primary">
                            <i class="fa fa-plus"></i> Add New Branch
                        </a>
                    </div>
                </div>
            </div>

            <!-- Branches Table -->
            <div class="card-box mb-30">
                <div class="pd-20">
                    <h4 class="text-blue h4 mb-0">All Branches</h4>
                </div>
                <div class="pb-20">
                    <div class="table-responsive">
                        <table class="table table-striped hover nowrap" id="branchesDataTable" style="width:100%">
                            <thead>
                                <tr>
                                    <th>No.</th>
                                    <th>Branch Name</th>
                                    <th>Branch Code</th>
                                    <th>City</th>
                                    <th>Status</th>
                                    <th class="datatable-nosort">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php if(!empty($branches)): ?>
                                    <?php $i=1; foreach($branches as $branch): ?>
                                        <tr>
                                            <td><strong><?php echo $i++; ?></strong></td>
                                            <td><strong><?php echo $branch->branch_name; ?></strong></td>
                                            <td><?php echo $branch->branch_code; ?></td>
                                            <td><?php echo $branch->branch_city; ?></td>
                                            <td>
                                                <?php if($branch->status == 'Active'): ?>
                                                    <span class="badge badge-success"><?php echo $branch->status; ?></span>
                                                <?php else: ?>
                                                    <span class="badge badge-danger"><?php echo $branch->status; ?></span>
                                                <?php endif; ?>
                                            </td>
                                            <td>
                                                <a href="<?php echo base_url('branches/edit/'.$branch->branch_id); ?>" class="btn btn-sm btn-primary"><i class="fa fa-pencil"></i> Edit</a>
                                            </td>
                                        </tr>
                                    <?php endforeach; ?>
                                <?php else: ?>
                                    <tr>
                                        <td colspan="5" class="text-center">No branches found</td>
                                    </tr>
                                <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <?php include(APPPATH . 'views/layout/footer.php'); ?>
    </div>
</div>
<?php include(APPPATH . 'views/layout/template-bottom.php'); ?>
