<?php echo $this->Element('kadry_menu_ajax'); ?>
<div class="row">
    <div class="col-xs-12">
        <div class="box box-primary">
            <div class="box-body table-responsive table-fixed-height" style="max-height: 42vh!important;">
                <table id="PracownicyTable" class="table hover-rows custom-table" data-start-sort="1"
                       data-start-sort-direction="asc" data-start-height="30vh">
                    <thead>
                    <tr class="text-uppercase">
                        <th width="1%">Numer</th>
                        <th>Nazwisko i imię</th>
                        <th>Komórka</th>
                        <th>Stanowisko</th>
                        <th>Pion</th>
                        <?php if($employees['bCzyKolumnaInformacjaODodatkach'] == 'true'): ?>
                            <th>Dodatki</th>
                        <?php endif; ?>
                        <th>Data</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($employees['bPracownicy']['bPracownik'] as $k => $employee): ?>
                        <tr class="clickable-row" data-key="<?php echo $employee['bNumerEwidencyjny']; ?>"
                            data-employee="<?php echo $employee['bNazwiskoImie']; ?>"
                            data-date-to="<?php echo(!empty($employee['bUmowaDo']) ? $employee['bUmowaDo'] : 'Brak'); ?>">
                            <td class="info-addon"><?php echo $employee['bNumerEwidencyjny']; ?></td>
                            <td><?php echo $employee['bNazwiskoImie']; ?></td>
                            <td><?php echo !empty($employee['bKomorka']) ? $employee['bKomorka'] : ''; ?></td>
                            <td><?php echo !empty($employee['bStanowisko']) ? $employee['bStanowisko'] : ''; ?></td>
                            <td><?php echo !empty($employee['bPion']) ? $employee['bPion'] : ''; ?></td>
                            <?php if($employees['bCzyKolumnaInformacjaODodatkach'] == 'true'): ?>
                                <td><?php echo htmlspecialchars_decode($employee['bInformacjaODodatkach']); ?></td>
                            <?php endif; ?>
                            <td><span
                                    class="span-date"><?php echo !empty($employee['bDataPrzyjecia']) ? $employee['bDataPrzyjecia'] : ''; ?></span>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
        <style>
            #PracownikContainer .box-body {
                max-height: 39vh !important;
            }

            @media (max-width: 1585px) {
                #PracownikContainer .box-body {
                    max-height: 33vh !important;
                }
            }
        </style>
        <div class="box box-danger" id="PracownikContainer" style="margin-bottom: 0px;">
            <?php echo $this->Element('table_loading'); ?>
            <div class="box-body table-responsive table-fixed-height" data-container="table">
                <div class="no-data"><p>Wybierz pracownika</p></div>
            </div>
        </div>
    </div>
</div>
<div class="row more-info-container">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <h2 class="box-title">Informacje dodatkowe</h2>
            </div>
            <div class="box-body" id="more-info-container">

            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.page-name:first-of-type').html('<?php echo $pageName; ?>');
    })
</script>

<script>
    $(document).ready(function () {
        var a_action = "<?php echo $a_action ?>";
        if (a_action != undefined && a_action != null && a_action.length > 0) {
            $('[data-action][data-active]').attr('data-active', 0);
            $('[data-action="' + a_action + '"][data-active]').attr('data-active', 1);
        }

        $(document).on('click', '.clickable-row td, [data-action][data-active]', function () {
            var $row = $('.clickable-row.active');
            var module_name = $('[data-action][data-active="1"]').find('span').html();
            var e_name = $row.data('employee');
            var e_number = $row.data('key');
            var e_date_to = $row.data('date-to');

            if (module_name.length > 0 && e_name != undefined && e_name.length > 0) {
                if(e_date_to == 'Brak') {
                    $('.page-name:first-of-type').html(module_name + " - " + e_name + "(" + e_number + ")");
                } else {
                    $('.page-name:first-of-type').html(module_name + " - " + e_name + "(" + e_number + "), umowa do: " + e_date_to);
                }
            }
        });

        // setTimeout(function () {
        //     $('.clickable-row[data-employee]').eq(0).addClass('active').find('td').eq(0).trigger('click');
        // });

        $(document).on('change, keyup, keypress', '#DataTables_Table_0_filter input, #PracownicyTable_filter input', function () {
            $('.clickable-row').attr('data-active', '0').removeClass('active');
            $('#PracownikContainer .box-body').html('').append('<div class="no-data"><p>Wybierz pracownika</p></div>');
        });
    });
</script>

<?php echo $this->element('alert_close'); ?>
