<table class="table table-sm table-bordered table-striped">
    <thead>
        <th width="150px">ID</th>
        <th width="250px">User</th>
        <th width="100px">Divisi</th>
        <th>Unit</th>
        <th>Email</th>
        <th width="50px">Level</th>
        <th>Jabatan</th>
        <th>Atasan</th>
        <th width="35px">Opsi</th>
    </thead>
    <tbody>
        <?php
        $i = 1;
        foreach ($dir as $d) {
            $team = $this->M_masterdata->get_team($d['emp_id']);
            echo "<tr>";
            echo "<td><b>" . $d['emp_id'] . "</b></td>";
            echo "<td><b>" . $d['FullName'] . "</b></td>";
            echo "<td><b>" . $d['Division'] . "</b></td>";
            echo "<td></td>";
            echo "<td><b>" . $d['Email'] . "</b></td>";
            echo "<td><b>DIREKTUR</b></td>";
            echo "<td><b>" . $d['strJobPosition'] . "</b></td>";
            echo "<td></td>";
            //echo "<td><b>" . $d['stsAktif'] . "</b></td>";
            echo "<td><div class='btn-group' role='group' aria-label='Basic outlined example'>
                                <button data-toggle='tooltip' title='Tambah team' onclick='add_emp(\"" . $d['emp_id'] . "\",\"" . $d['FullName'] . "\"," . $d['Level'] . ")' type='button' class='btn btn-outline-primary btn-sm'><i class='bi bi-person-plus'></i></button>                
                                <button onclick='disable_user(\"" . $d['emp_id'] . "\",\"" . $d['FullName'] . "\")' data-toggle='tooltip' title='Non-Aktifkan User' type='button' class='btn btn-outline-danger btn-sm'><i class='bi bi-person-x'></i></button>                                
                            </div></td>";
            echo "</tr>";
            foreach ($team as $t) {
                $unitkerja = $this->db->get_where('tb_emp_unit', ['emp_id' => $t['emp_id']])->result_array();

                if ($t['dir'] == $d['emp_id']) {
                    if ($t['stsAktif'] == 0) {
                        echo "<tr>";
                        echo "<td style='color:red;'>" . $t['emp_id'] . "</td>";
                        echo "<td style='color:red;'>" . $t['FullName'] . "</td>";
                        echo "<td style='color:red;'>" . $t['Division'] . "</td>";
                        echo "<td ondblclick='add_unit()' style='color:red;'>";
                        foreach ($unitkerja as $uk) {
                            if (isset($uk['unit'])) {
                                echo $uk['unit'] . "<br>";
                            }
                        }
                        echo "</td>";
                        echo "<td style='color:red;'>" . $t['Email'] . "</td>";
                        echo "<td style='color:red;'>" . $t['Level'] . "</td>";
                        echo "<td style='color:red;'>" . $t['strJobPosition'] . "</td>";
                        echo "<td style='color:red;'>" . $t['atasan'] . "</td>";
                        echo "<td></td>";
                        /*
                        if ($t['Level'] == 'ADMIN') {
                            echo "<td style='text-align: right;'><div class='btn-group' role='group' aria-label='Basic outlined example'>                                                                
                                <button data-toggle='tooltip' title='Update User' type='button' class='btn btn-outline-primary btn-sm'><i class='bi bi-pencil'></i></button>
                            </div></td>";
                        } else {
                            echo "<td style='text-align: right;'><div class='btn-group' role='group' aria-label='Basic outlined example'>
                                <button data-toggle='tooltip' title='Tambah team' onclick='add_emp(\"" . $t['emp_id'] . "\",\"" . $t['FullName'] . "\"," . $t['Lvl'] . ")' type='button' class='btn btn-outline-primary btn-sm'><i class='bi bi-person-plus'></i></button>                                                
                                <button data-toggle='tooltip' title='Update User' type='button' class='btn btn-outline-primary btn-sm'><i class='bi bi-pencil'></i></button>
                            </div></td>";
                        }*/
                        echo "</tr>";
                    }
                    if ($t['stsAktif'] == 1) {
                        echo "<tr>";
                        echo "<td>" . $t['emp_id'] . "</td>";
                        echo "<td>" . $t['FullName'] . "</td>";
                        echo "<td>" . $t['Division'] . "</td>";
                        echo "<td ondblclick='add_unit()'>";
                        foreach ($unitkerja as $uk) {
                            if (isset($uk['unit'])) {
                                echo $uk['unit'] . "<br>";
                            }
                        }
                        echo "</td>";
                        echo "<td>" . $t['Email'] . "</td>";
                        echo "<td>" . $t['Level'] . "</td>";
                        echo "<td>" . $t['strJobPosition'] . "</td>";
                        echo "<td>" . $t['atasan'] . "</td>";
                        //echo "<td>" . $t['stsAktif'] . "</td>";
                        if ($t['Level'] == 'ADMIN') {
                            echo "<td style='text-align: right;'><div class='btn-group' role='group' aria-label='Basic outlined example'>                                
                                <button onclick='disable_user(\"" . $t['emp_id'] . "\",\"" . $t['FullName'] . "\")' data-toggle='tooltip' title='Non-Aktifkan User' type='button' class='btn btn-outline-danger btn-sm'><i class='bi bi-person-x'></i></button>
                                <button onclick='edit_emp(\"" . $t['emp_id'] . "\",\"" . $t['FullName'] . "\",\"" . $t['Email'] . "\",\"" . $t['strPassword'] . "\",\"" . $t['Division'] . "\"," . $t['Lvl'] . ",\"" . $t['strJobPosition'] . "\",\"" . $t['ApprovalLine'] . "\")' data-toggle='tooltip' title='Update User' type='button' class='btn btn-outline-primary btn-sm'><i class='bi bi-pencil'></i></button>
                            </div></td>";
                        } else {
                            echo "<td style='text-align: right;'><div class='btn-group' role='group' aria-label='Basic outlined example'>
                                <button data-toggle='tooltip' title='Tambah team' onclick='add_emp(\"" . $t['emp_id'] . "\",\"" . $t['FullName'] . "\"," . $t['Lvl'] . ")' type='button' class='btn btn-outline-primary btn-sm'><i class='bi bi-person-plus'></i></button>                
                                <button onclick='disable_user(\"" . $t['emp_id'] . "\",\"" . $t['FullName'] . "\")' data-toggle='tooltip' title='Non-Aktifkan User' type='button' class='btn btn-outline-danger btn-sm'><i class='bi bi-person-x'></i></button>
                                <button onclick='edit_emp(\"" . $t['emp_id'] . "\",\"" . $t['FullName'] . "\",\"" . $t['Email'] . "\",\"" . $t['strPassword'] . "\",\"" . $t['Division'] . "\"," . $t['Lvl'] . ",\"" . $t['strJobPosition'] . "\",\"" . $t['ApprovalLine'] . "\")' data-toggle='tooltip' title='Update User' type='button' class='btn btn-outline-primary btn-sm'><i class='bi bi-pencil'></i></button>
                            </div></td>";
                        }
                        echo "</tr>";
                    }
                }
            }
            $i++;
        }
        ?>
    </tbody>
</table>

<script>
    $(function() {
        $('[data-toggle="tooltip"]').tooltip();
    });
</script>