@extends('Templates/templateAdmin')

@section('Main-content')
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1>{{ $numberProject->company_project_description }}</h1>
                    <input type="hidden" value="{{$numberProject->company_projects_id}}" id="receiveNumberProject">
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item"><a href="{{ route('home') }}">Dashboard</a></li>
                        <li class="breadcrumb-item"><a href="./preparadas.html">Preparadas</a></li>
                        <li class="breadcrumb-item active">{{ $numberProject->company_project_description }}</li>
                    </ol>
                </div><!-- /.col -->
            </div>
        </div><!-- /.container-fluid -->
    </section>
    <!-- /.content-header -->


    <!-- Main content -->
    <section class="content">
        <div class="container-fluid">
            <div class="row justify-content-center">
                <div class="col-md-12">

                    <!-- Card box criar instalção -->
                    <form>
                        <div class="row">
                            <div class="col-sm-6" id="BotaoDetalhesObra">
                                <a href="#" type="button" class="btn btn-block bg-gradient-primary btn-lg">Detalhes
                                    da Obra</a>
                            </div>
                            <div class="col-sm-6" id="BotaoArticulado">
                                <a href="#" type="button"
                                    class="btn btn-block bg-gradient-primary btn-lg">Articulado</a>
                            </div>
                            <div class="col-sm-6" id="BotaoPostosDeTrabalho">
                                <a href="#" type="button" class="btn btn-block bg-gradient-primary btn-lg">Postos de
                                    Trabalho</a>
                            </div>
                        </div>
                        <br><br>

                        <div class="card card-primary" id="CardDetalhesObra">
                            <div class="card-header">
                                <h3 class="card-title">Detalhes da Obra</h3>
                                <div class="card-tools">
                                </div>
                                <!-- /.card-tools -->
                            </div>
                            <!-- /.card-header -->

                            <div class="card-body p-0">
                                <table class="table table-striped text-center">
                                    <tbody>
                                        <tr>
                                            <td>Descrição da obra:</td>
                                            <td>{{ $numberProject->company_project_description }}</td>
                                        </tr>
                                        <tr>
                                            <td>N.ºobra ISPT:</td>
                                            <td>{{ $numberProject->project_ispt_number }}</td>
                                        </tr>
                                        <tr>
                                            <td>Resp.ISPT:</td>
                                            <td>{{ $numberProject->project_ispt_responsible }}</td>
                                        </tr>
                                        <tr>
                                            <td>Cliente :</td>
                                            <td>Cliente1</td>
                                        </tr>
                                        <tr>
                                            <td>N.ºobra Cliente :</td>
                                            <td>{{ $numberProject->project_company_number }}</td>
                                        </tr>
                                        <tr>
                                            <td>Resp.Cliente:</td>
                                            <td>{{ $numberProject->project_company_responsible }}</td>
                                        </tr>
                                        <tr>
                                            <td>Data de Inicio :</td>
                                            <td>{{ $numberProject->date_started }}</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                            <!-- /.card-body -->

                            <div class="card-footer">
                                <div class="float-right">

                                    {{-- <a href="#" type="button" class="btn btn-primary">Editar</a> --}}
                                    <button type="button" class="btn btn-primary" data-toggle="modal"
                                        data-target="#ModalTransferForArticulated">
                                        Editar
                                    </button>
                                </div>
                            </div>
                        </div>
                        <!-- /.card -->
                    </form>
                    <!-- /.Card box criar instalção -->

                    <!-- Card box criar equipamentos -->
                    <form>
                        <!-- Articulado -->
                        <div class="card card-primary" id="CardArticuladoObra">
                            <div class="card-header">
                                <h3 class="card-title">Articulado</h3>
                                <div class="card-tools">
                                    <!-- <button type="button" class="btn btn-tool" data-card-widget="collapse"><i
                                                                        class="fas fa-plus"></i>
                                                                </button> -->
                                </div>
                                <!-- /.card-tools -->
                            </div>
                            <!-- /.card-header -->


                            <div class="card-body">
                                <!-- Table articulado de obra -->
                                <div class="card">
                                    <div class="card-header">
                                        <h3 class="card-title">Equipamentos da obra</h3>
                                    </div>
                                    <!-- /.card-header -->
                                    <div class="card-body">
                                        <div class="table-responsive">
                                            <div class="row text-center">

                                                <div class="form-group col-sm-3">
                                                    <label>Tipo de Equipamento </label>
                                                    <select id="tipo_valvulasList" name="equipmentTypeId"
                                                        class="form-control">
                                                        <option value='#' selected>Mostrar Todos</option>
                                                        @foreach ($equipmentsTypes as $equipmentsType)
                                                            <option value="{{ $equipmentsType->equipment_type_id }}">
                                                                {{ $equipmentsType->equipment_type_name }}</option>
                                                        @endforeach
                                                    </select>
                                                </div>

                                                <div class="col-sm-3">
                                                    <div class="form-group">
                                                        <label> Fabricas </label>
                                                        <select id="UnitsList" class="form-control">
                                                            <option value='#' selected>Mostrar Todos</option>
                                                            @foreach ($units as $unit)
                                                                <option value="{{ $unit->unit_id }}">
                                                                    {{ $unit->unit_name }}</option>
                                                            @endforeach
                                                        </select>
                                                    </div>
                                                </div>

                                                <div class="col-sm-3">
                                                    <div class="form-group">
                                                        <label>Ambitos </label>
                                                        <select class="form-control" name="EquipmentAmbit"
                                                            id="AmbitsEquipments_list" required>
                                                            <option value="#" hidden>Mostrar Todos</option>
                                                        </select>
                                                    </div>
                                                </div>

                                                <div class="col-sm-3">
                                                    <div class="form-group">
                                                        <label>Inspeção de Equipamentos </label>
                                                        <select id="inspecValvula" class="form-control">
                                                            <option value="#">Mostrar Todos</option>
                                                            <option value="Sim">Sim </option>
                                                            <option value="Nao">Nao </option>
                                                        </select>
                                                    </div>
                                                </div>

                                            </div>
                                            <br>

                                            <table id="myTable" class="table table-bordered table-striped">
                                                <thead>
                                                    <tr>
                                                        <th>Tag</th>
                                                        <th>Tipo Equipamento</th>
                                                        <th>Fabrica</th>
                                                        <th>Ambito</th>
                                                        <th>Inspecionar</th>
                                                    </tr>
                                                </thead>
                                            </table>
                                            <!-- /. Table-->
                                        </div>
                                        <!--/table obra-->
                                    </div>
                                    <!-- /.card-body -->
                                    <div class="card-footer">
                                        <div class="float-right">
        
                                            {{-- <a href="#" type="button" class="btn btn-primary">Editar</a> --}}
                                            <button type="button" class="btn btn-primary" data-toggle="modal"
                                                data-target="#ModalTransferForArticulated">
                                                Editar
                                            </button>
                                        </div>
                                    </div>
                                </div>
                                <!-- ./card -->
                            </div>
                            {{-- card-body --}}

                            <!-- TEM DE TER FOOTER  -->
                        </div>
                        <!--/.CardArticuladoObra -->
                    </form>
                    <!-- /.card -->
                    <!-- /.Card box criar equipamentos -->

                    <form>
                        <div class="card card-primary" id="CardPostosDeTrabalhoObra">
                            <div class="card-header">
                                <h3 class="card-title">Postos de Trabalho</h3>

                                <div class="card-tools">
                                    <!-- <button type="button" class="btn btn-tool" data-card-widget="collapse">
                                                                    <i class="fas fa-plus"></i>
                                                                </button> -->
                                </div>
                                <!-- /.card-tools -->
                            </div>
                            <!-- /.card-header -->
                            <div class="card-body">

                                <!-- Criar tarefa -->
                                <div class="card card-primary collapsed-card">

                                    <!-- /.card-header -->
                                    <div class="card-body">
                                        <div class="card ">
                                            <div class="form-group col-md-12">
                                                <div class="card">
                                                    <div class="form-group">
                                                        <label>Selecione o Numero de Postos Pretendidos :
                                                        </label>
                                                        <input class="form-control" type="number" id="numberPosts">
                                                    </div>
                                                </div>
                                                <!-- <p id="receiveNumberPosts"></p> -->
                                                <table class="table table-bordered table-striped">
                                                    <thead>
                                                        <tr>
                                                            <th>Postos de Trabalho</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody id="receiveNumberPosts">
                                                        <!-- Vai receber o Numero de Oficinas -->
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                    <!-- /.card-body -->

                                </div>
                                <!--/Criar tarefa-->
                                <div class="card">
                                    <div class="card-header">
                                        <h3 class="card-title">Listas de Postos de Obra</h3>
                                    </div>
                                    <div class="card-body">
                                        <div class="table-responsive">

                                            <table id="TablePreparedProjectWorkstation" class="table table-bordered table-striped">
                                                <thead>
                                                    <tr>
                                                        <th>Postos de Trabalho</th>
                                                        <th>Tarefas Elementares</th>
                                                        <th>Tarefas Complementares</th>
                                                    </tr>
                                                </thead>
                                            </table>
                                        </div>
                                        <!--/articulado de obra-->
                                    </div>
                                    <!-- /.card-body -->
                                    <div class="card-footer">
                                        <div class="float-right">
        
                                            {{-- <a href="#" type="button" class="btn btn-primary">Editar</a> --}}
                                            <button type="button" class="btn btn-primary" data-toggle="modal"
                                                data-target="#ModalTransferForArticulated">
                                                Editar
                                            </button>
                                        </div>
                                    </div>
                                </div>
                                <!-- modal Remover -->
                                <div class="modal fade" id="modal-ViewOfices">
                                    <div class="modal-dialog modal-xl">
                                        <div class="modal-content">
                                            <div class="modal-header bg-primary">
                                                <h4 class="modal-title">Posto de Trabalho X</h4>
                                                <button type="button" class="close" data-dismiss="modal"
                                                    aria-label="Close">
                                                    <span aria-hidden="true">x</span>
                                                </button>
                                            </div>
                                            <div class="modal-body">
                                                <section class="content">
                                                    <div class="container-fluid">
                                                        <div class="row text-center">
                                                            <div class="col-sm-6">
                                                                <div class="card card-success">
                                                                    <div class="card-header">
                                                                        <h3 class="card-title">
                                                                            Tarefas Elementares PSV</h3>
                                                                        <div class="card-tools">
                                                                            <button type="button" class="btn btn-tool"
                                                                                data-card-widget="collapse"><i
                                                                                    class="fas fa-minus"></i>
                                                                            </button>
                                                                        </div>
                                                                    </div>
                                                                    <div class="card-body">
                                                                        <!-- Tabela de Checkbox -->
                                                                        <div>
                                                                            <p>TE1 - Desmontar da linha
                                                                                <input type="checkbox"
                                                                                    class="checkboxChoseTasksOficesPSV"
                                                                                    value="TE1">
                                                                            </p>
                                                                            <p>TE2 - Descontaminar
                                                                                <input type="checkbox"
                                                                                    class="checkboxChoseTasksOficesPSV"
                                                                                    value="TE2" checked>
                                                                            </p>
                                                                            <p>TE3 - Pré-teste
                                                                                <input type="checkbox"
                                                                                    class="checkboxChoseTasksOficesPSV"
                                                                                    value="TE3">
                                                                            </p>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>

                                                            <div class="col-sm-6">
                                                                <div class="card card-primary">
                                                                    <div class="card-header">
                                                                        <h3 class="card-title">
                                                                            Tarefas Elementares ISV</h3>
                                                                        <div class="card-tools">
                                                                            <button type="button" class="btn btn-tool"
                                                                                data-card-widget="collapse"><i
                                                                                    class="fas fa-minus"></i>
                                                                            </button>
                                                                        </div>
                                                                    </div>
                                                                    <div class="card-body">
                                                                        <!-- Tabela de Checkbox -->
                                                                        <div>
                                                                            <p>TE1 - Desmontar da linha
                                                                                <input type="checkbox"
                                                                                    class="checkboxChoseTasksOficesISV"
                                                                                    value="TE1">
                                                                            </p>
                                                                            <p>TE2 - Descontaminar
                                                                                <input type="checkbox"
                                                                                    class="checkboxChoseTasksOficesISV"
                                                                                    value="TE2">
                                                                            </p>
                                                                            <p>TE5 - Limpeza e lavagem
                                                                                dos componentes
                                                                                <input type="checkbox"
                                                                                    class="checkboxChoseTasksOficesISV"
                                                                                    value="TE5">
                                                                            </p>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>

                                                            <!-- Divisória Para Metade -->
                                                            <div class="col-sm-6">
                                                                <div class="card card-warning">
                                                                    <div class="card-header">
                                                                        <h3 class="card-title">
                                                                            Tarefas Elementares CV</h3>
                                                                        <div class="card-tools">
                                                                            <button type="button" class="btn btn-tool"
                                                                                data-card-widget="collapse"><i
                                                                                    class="fas fa-minus"></i>
                                                                            </button>
                                                                        </div>
                                                                    </div>
                                                                    <div class="card-body">
                                                                        <!-- Tabela de Checkbox -->
                                                                        <div>
                                                                            <p>TE12 - Inspeção visual
                                                                                <input type="checkbox"
                                                                                    class="checkboxChoseTasksOficesCV"
                                                                                    value="TE12" checked>
                                                                            </p>
                                                                            <p>TE1 - Desmontar da linha
                                                                                <input type="checkbox"
                                                                                    class="checkboxChoseTasksOficesCV"
                                                                                    value="TE1">
                                                                            </p>
                                                                            <p>TE14 - Ensaio
                                                                                <input type="checkbox"
                                                                                    class="checkboxChoseTasksOficesCV"
                                                                                    value="TE14">
                                                                            </p>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>

                                                            <div class="col-sm-6">
                                                                <div class="card card-info collapsed-card">
                                                                    <div class="card-header">
                                                                        <h3 class="card-title">
                                                                            Outras Tarefas</h3>
                                                                        <div class="card-tools">
                                                                            <button type="button" class="btn btn-tool"
                                                                                data-card-widget="collapse">
                                                                                <i class="fas fa-plus"></i>
                                                                            </button>
                                                                        </div>
                                                                    </div>
                                                                    <div class="card-body">
                                                                        <!-- Tabela de Checkbox -->
                                                                        <div>
                                                                            <p>TE1 - Desmontar da linha
                                                                                <input type="checkbox" id="">
                                                                            </p>
                                                                            <p>TE12 - Inspeção visual
                                                                                <input type="checkbox" id="">
                                                                            </p>
                                                                            <p>TE14 - Ensaio
                                                                                <input type="checkbox" id="">
                                                                            </p>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>

                                                        </div>
                                                    </div>
                                                </section>
                                                <!-- Tabelas das Tarefas selecionadas -->
                                                <div class="card">
                                                    <h3>Tarefas Selecionadas para o Postos X:</h3>
                                                    <div class="row">
                                                        <div class="col-sm-4 text-center"
                                                            id="ReceiveCheckboxChoseTasksOficesPSV">
                                                        </div>
                                                        <div class="col-sm-4 text-center"
                                                            id="ReceiveCheckboxChoseTasksOficesCV">
                                                        </div>
                                                        <div class="col-sm-4 text-center"
                                                            id="ReceiveCheckboxChoseTasksOficesISV">
                                                        </div>
                                                    </div>
                                                </div>

                                                <div class="modal-footer justify-content-between">
                                                    <!-- Vai ficar o Footer -->
                                                    <button class="btn btn-danger">Cancelar</button>
                                                    <button class="btn btn-primary">Guardar</button>
                                                </div>
                                            </div>
                                            <!-- /.modal-content --
                                                                     /.modal-dialog -->
                                        </div>
                                        <!-- /.modal remover-->

                                    </div>
                                    <!-- /.Modal, Postos de Trabalho -->
                                </div>
                                <!-- /.card -->
                            </div>
                            <!-- /.card-body -->
                    </form>
                </div>
            </div>
        </div>
    </section>
    <!-- ./content -->

    <!-- Modal -->
    <div class="modal fade" id="ModalTransferForArticulated" tabindex="-1" role="dialog"
        aria-labelledby="ModalTransferForArticulated" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="ModalTransferForArticulatedLabel">Mudar Projeto para Articulado</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <P>Para Editar uma obra Preparada, a obra ira Voltar para o articulado, Deseja Editar ?</P>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
                    <form action="{{ route('EditProjectForArticulated') }}" method="get">
                        @csrf
                        <input type="hidden" name="ProjectId" value="{{ $numberProject->company_projects_id }}">
                        <button type="submit" class="btn btn-primary">Editar</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
@endsection


{{-- Scripts --}}
@section('scriptsTemplateAdmin')
    <script>
        $(document).ready(function() {
            $('#tipo_valvulasList').on('change', function() {
                
                var equipmentTypeID = $(this).val();
                if (equipmentTypeID) {
                    $.ajax({
                        url: '/api/ambits/prepared' + equipmentTypeID,
                        type: 'GET',
                        success: function(data) {
                            $('#AmbitsEquipments_list').empty(); // Limpar o select de ambits
                            $('#AmbitsEquipments_list').append(
                                '<option value="#" selected>Mostrar Todos</option>'
                                ); // Opção para mostrar todos
                            $('#AmbitsEquipments_list').append(
                                '<option value="" hidden>Selecionar Tipo de Ambito...</option>'
                                );
                            $.each(data, function(key, value) {
                                $('#AmbitsEquipments_list').append('<option value="' +
                                    value.ambits_id + '">' + value
                                    .ambits_description + '</option>');
                            });
                        }
                    });
                } else {
                    $('#AmbitsEquipments_list')
                        .empty(); // Limpar o select de ambits se não há tipo de equipamento selecionado
                    $('#AmbitsEquipments_list').append(
                        '<option value="#" hidden>Mostrar Todos</option>');
                }
            });
        });
    </script>

<script type="Text/javascript">
    $(document).ready(function() {
        $('#TablePreparedProjectWorkstation').DataTable({
            autoWidth: false,
            processing: true,
            serverSide: true,
            ajax: {
                url: '/api/receiveWorkstationProject/' + $('#receiveNumberProject').val()
            },
            columns: [{
                    data: 'name_workstations',
                    name: 'name_workstations'
                },
                {
                    data: 'nomenclature_workstation',
                    name: 'nomenclature_workstation'
                },
                {
                    data: 'workstations_Association_Tasks',
                    name: 'workstations_Association_Tasks'
                }
                
            ] 
        })
    })
    </script>

    <script>
        $(document).ready(function() {
            $('#myTable').DataTable({
                autoWidth: false,
                processing: true,
                serverSide: true,
                ajax: {
                    url: '/api/receiveEquipmentsProject/' + $('#receiveNumberProject').val(),
                    data: function(d) {
                        d.equipment_type_id = $('#tipo_valvulasList').val();
                        d.ambits_id = $('#AmbitsEquipments_list').val();
                    },
                },
                columns: [{
                        data: 'equipment_tag',
                        name: 'equipment_tag'
                    },
                    {
                        data: 'equipment_type',
                        name: 'equipment_type'
                    },
                    {
                        data: 'Unit',
                        name: 'Unit'
                    },
                    {
                        data: 'Ambits',
                        name: 'Ambits'
                    },
                    {
                        data: 'Inspec',
                        name: 'Inspec'
                    },

                ],
                rowId: 'equipment_id'
            });

            // Scripts para que com base no recebido , ele atualiza a pagina automaticamente
            $('#tipo_valvulasList').on('change', function() {
                // Atualiza a tabela quando o valor selecionado no select de tipo de válvulas for alterado
                $('#myTable').DataTable().ajax.reload();
            });
            $('#UnitsList').on('change', function() {
                // Atualiza a tabela quando o valor selecionado no select de tipo de válvulas for alterado
                $('#myTable').DataTable().ajax.reload();
            });
            $('#AmbitsEquipments_list').on('change', function() {
                // Atualiza a tabela quando o valor selecionado no select de tipo de válvulas for alterado
                $('#myTable').DataTable().ajax.reload();
            });
            $('#inspecValvula').on('change', function() {
                // Atualiza a tabela quando o valor selecionado no select de tipo de válvulas for alterado
                $('#myTable').DataTable().ajax.reload();
            });
        });
    </script>

    <script type="text/javascript">
        $(document).ready(function() {

            //Cards das div : Destricao - Articulado - Postos de Trabalho

            // ******** Estrutura do Layout da Página :
            $("#CardArticuladoObra").hide();
            $("#CardPostosDeTrabalhoObra").hide();

            //Botoes  : Destricao - Articulado - Postos de Trabalho
            $('#BotaoDetalhesObra').hide();

            $('#BotaoArticulado').on('click', function() {
                // Mostra o Card do Articulado e o Botao de detalhes 
                $('#CardArticuladoObra').show();
                $("#BotaoDetalhesObra").show();
                $('#BotaoPostosDeTrabalho').show();

                $('#BotaoArticulado').hide();
                $("#CardPostosDeTrabalhoObra").hide();
                $("#CardDetalhesObra").hide();
            });

            $('#BotaoDetalhesObra').on('click', function() {
                // Mostra o Card do Articulado e o Botao de detalhes 
                $('#CardDetalhesObra').show();
                $("#BotaoArticulado").show();
                $('#BotaoPostosDeTrabalho').show();

                $('#BotaoDetalhesObra').hide();
                $("#CardPostosDeTrabalhoObra").hide();
                $("#CardArticuladoObra").hide();
            });

            $('#BotaoPostosDeTrabalho').on('click', function() {
                // Mostra o Card do Articulado e o Botao de detalhes 
                $('#CardPostosDeTrabalhoObra').show();
                $("#BotaoArticulado").show();
                $("#BotaoDetalhesObra").show();

                $('#BotaoPostosDeTrabalho').hide();
                $("#CardDetalhesObra").hide();
                $("#CardArticuladoObra").hide();
            });
        })
    </script>

    <script>
        $(document).ready(function() {
            $("#numberPosts").on("input", function() {
                var num = parseInt($(this).val());
                var tablePosts = "<tr>";
                var AddHTML =
                    "<th style='text-align: center;'><a href='#' data-toggle='modal' data-target='#modal-ViewOfices'><i class='fa-solid fa-eye text-secondary'></i></a></th>";
                for (var i = 1; i <= num; i++) {
                    // Limitar o numero de postos 
                    if (num >= 30) {
                        num = 30;
                    }
                    tablePosts += "<th>" + "Posto" + i + "</th>" + AddHTML + "</tr>";
                }
                $("#receiveNumberPosts").html(tablePosts);
            });
        });
    </script>
  
@endsection

{{-- // ajax: {
    //     url: "{{ route('getData') }}",
    //     data: function(d) {
    //         // Adiciona o 'equipment_type_id' selecionado aos parâmetros da solicitação
    //         d.equipment_type_id = $('#tipo_valvulasList').val();
    //         d.unit_id = $('#UnitsList').val();
    //         d.ambits_id = $('#AmbitsEquipments_list').val();
    //         d.inspec = $('#inspecValvula').val();
    //     },
    // }, --}}