<link rel="stylesheet" href="<?php echo base_url(); ?>assets/sistema/css/calendario/ekattor.css"/>
<script src="<?php echo base_url();?>assets/sistema/js/calendario/ekattor.js" type="text/javascript"></script>
<script src="<?php echo base_url();?>assets/sistema/js/calendario/pt-br.js" type="text/javascript"></script>
<style type="text/css">
    .compromisso {
        display: inline-block;
        width: 10px;
        height: 10px;
        border-radius: 8px;
        margin-right: 5px;
    }

</style>
<div class="row">
    <div class="col-md-9">
        <div class="row-fluid">
            <div class="box">
                <div class="box-header" style="padding-bottom: 3%; backgroun-color: #fff;">

                    <div>
                        Planejamento
                        <span id="infoAgendaTooltip" class="fa fa-question-circle" title=""
                              style="margin-left: 10px;"></span>
                        <div class="pull-right">
                            <span class="compromisso event-success"></span> Preventiva
                            <span class="compromisso event-info" style="margin-left: 20px;"></span> Corretiva
                            <span class="compromisso event-warning" style="margin-left: 20px;"></span> Outros

                            <a href="#adicionarAgenda" class="btn btn-s-md btn-success" data-animation="swell"
                               data-plugin="custommodal"
                               data-overlaySpeed="100" data-overlayColor="#36404a"><i class="fa fa-plus"></i> Planejar</a>

                        </div>
                    </div>

                </div>


                <div class="box-content">
                    <div id="fullcalendar">
                    </div>
                </div>
            </div>

        </div>
    </div>
    <div class="col-md-3">
        <div class="panel panel-default">
            <div class="panel-heading">
                Planejamento
                <div class="input-group margn-t-sm">
                    <input id="input-busca-agenda" type="text" class="form-control" placeholder="Buscar Dados"
                           style="font-weight: normal;">
                    <span class="input-group-btn">
                                        <button id="btn-buscar-agenda" class="btn btn-primary" type="button">Filtrar
                                        </button>
                                    </span>
                </div>
            <div class="panel-body">
                <ul id="eventList" class="activities-list list-unstyled nicescroll height-lg margn-l-negative-sm"
                    tabindex="5000" style="overflow: hidden; outline: none;">

                    <?php foreach ($compromissos as $r):

                        $classeBarra = '';
                        $classeTexto = '';
                        if ($r->TP_AGENDA == "manutencao") {
                            $classeBarra = "success-activity";
                            $classeTexto = "text-success";
                        }

                        if ($r->TP_AGENDA == "corretiva") {
                            $classeBarra = "info-activity";
                            $classeTexto = "text-info";
                        }

                        if ($r->TP_AGENDA == "Outros") {
                            $classeBarra = "warning-activity";
                            $classeTexto = "text-warning";
                        }
                        ?>

                        <li class="<?php echo $classeBarra; ?>"><span
                                    class="time"><?php echo date(('d/m/Y'), strtotime($r->DT_AGENDA)) ?>
                                - <?php echo $r->hsInicioAgenda ?> </span>

                            <span class="<?php echo $classeTexto; ?>"><?php echo $r->PREFIXO . ' - ' . $r->nome ?></span>
                            <a class="btn btn-secondary btn-outline" href="#modalConfirmarExclusao" id="lnkAgendaExcluir"
                               agendaExcluir="<?php echo $r->ID_AGENDA; ?>"
                               data-toggle="modal" >
                                <span class="fa fa-trash-o"></span>
                            </a>

                            <a href="#gerarManutencao" class="btn btn-secondary btn-outline" data-animation="rotatedown" data-plugin="custommodal"
                               id="lnkGerarOS"
                               agendaItem=<?php echo $r->ID_AGENDA; ?>
                               data-overlaySpeed="100" data-overlayColor="#36404a"><i class="fa fa-wrench" style="color: blue"></i></a>
                        </li>

                    <?php endforeach ?>


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


<?php $this->load->view("sistema/modais/agenda/adicionarAgendaModal"); ?>
<?php $this->load->view("sistema/modais/manutencao/gerenciarManutencaoModal"); ?>

<div id="dialog" class="panel panel-default" title="Informações" style="display:none">
    <form>
        <fieldset>

            <label for="Id">Compromisso</label>
            <textarea cols=40 rows=3 name="title" id="title" class="text ui-widget-content ui-corner-all"></textarea>
        </fieldset>
    </form>
</div>

<div class="modal fade" id="modalConfirmarExclusao">
    <div class="modal-dialog">
        <div class="modal-content">
            <form action="" name="excluirItens" method="post">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h5 id="myModalLabel">Excluir Item</h5>
                </div>
                <div class="modal-body">
                    <input type="hidden" id="itemAExcluir" name="id" value=""/>

                    <h5 style="text-align: center">Deseja realmente excluir este Item?</h5>
                </div>
                <div class="modal-footer">
                    <button class="btn" data-dismiss="modal" aria-hidden="true">Cancelar</button>
                    <button class="btn btn-danger">Excluir</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    // Setup FullCalendar
    (function () {
        var date = new Date();
        var d = date.getDate();
        var m = date.getMonth();
        var y = date.getFullYear();


        $('#fullcalendar').fullCalendar({
            editable: false,
            defaultEventMinutes: '30',
            scrollTime: '08:00:00',
            weekends: true,
            defaultView: 'month',
            minTime:'08:00:00',
            maxTime:'20:00:00',
            draggable: true,
            header: {
                left: "prev,next",
                center: "title",
                left: "month,agendaWeek,agendaDay"
            },


            eventClick: function (calEvent, jsEvent, view) {

                $("#dialog").dialog({
                        autoOpen: false,
                    }
                );

                $("#name").val(calEvent.id);

                $("#title").val(calEvent.description);

                $('#dialog').dialog('open');

            },
            events: [
                <?php
                foreach($compromissos as $row):

                $color = '';
                $textColor = '';

                if ($row->TP_AGENDA == "manutencao") {
                    $color = "#70ba63";
                    $textColor = "text-success";
                }

                if ($row->TP_AGENDA == "corretiva") {
                    $color = "#01a0e6";
                    $textColor = "text-success";
                }

                if ($row->TP_AGENDA == "outros") {
                    $color = "#f2b635";
                    $textColor = "text-success";
                }

                ?>
                {
                    title: "<?php echo $row->PREFIXO.' | '.$row->PLACA.' | Garagem: '.$row->GARAGEM ?>",
                    start: '<?php echo $row->DT_AGENDA . ' ' . $row->hsInicioAgenda?>',
                    end: '<?php echo $row->DT_AGENDA . ' ' . $row->hsFimAgenda?>',
                    description: '<?php echo $row->nome?>',
                    color: '<?php echo $color ?>'

                },

                <?php
                endforeach
                ?>

            ]
        });
    }());


</script>

<script>
    $("#nomePaciente").autocomplete({
        source: "<?php echo base_url(); ?>agenda/autoCompletePaciente",
        minLength: 1,

        select: function (event, ui) {
            alert('ok');
            $("#morador_id").val(ui.item.id);
            console.log(event);
        }
    });
</script>


<script>
   $(document).on('click', '#lnkAgendaExcluir', function (event) {
        $('#itemAExcluir').val($(this).attr('agendaExcluir'));
        document.excluirItens.action = "<?php echo base_url() ?>//agenda/excluir"
    });

   $(document).on('click', '#lnkGerarOS', function (event) {
       $('#idAgendaItemAtualizar').val($(this).attr('agendaItem'));
       //document.excluirItens.action = "<?php //echo base_url() ?>////agenda/excluir"
   });

    $(document).on('click', '#lnkEditarCompromisso', function (event) {
        $("#idEditar").val($(this).attr('idPaciente'));
        $("#nomePacienteEditar").val($(this).attr('nomePaciente'));
        $("#fonePacienteEditar").val($(this).attr('fonePaciente'));
        $("#dtAgendaEditar").val($(this).attr('dtAgenda'));
        $("#hsInicioAgendaEditar").val($(this).attr('hsInicioAgenda'));
        $("#hsFimAgendaEditar").val($(this).attr('hsFimAgenda'));
        $("#dsAgendaEditar").val($(this).attr('dsAgenda'));
    });

    $(function () {
        $("#input-busca-agenda").keyup(function () {
            var texto = $(this).val();
            $("#eventList li").css("display", "block");
            $("#eventList li").each(function () {
                if ($(this).text().toUpperCase().indexOf(texto.toUpperCase()) < 0)
                    $(this).css("display", "none");
            });
        });
    });

</script>







