@extends('layouts.admin.theme')

@section('title', env('APP_NAME') . ' :: Arte Sacra - Edição de Opções')

@section('content')
    <div class="card shadow-sm">

        @php $headLine = "<i class='fa-solid fa-church'></i> Arte Sacra - Edição de Opções"; @endphp

        @include('components.buttons._headLineButtonsBackAdd', [
            "headLine" => __($headLine),
            "routeBack" => "admin.cultura.arteSacra.index",
            "routeBackParams" => [],
            "fontawesomeBack" => '<i class="fa-solid fa-rectangle-list"></i>',
            "nameBack" => __("Lista de Peças"),
            "routeAdd" => "admin.cultura.arteSacra.create",
            "routeAddParams" => [],
            "nameAdd" => __("Nova peça"),
            "permission" => "GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA",
            "tabs" => [
                [
                    'route' => 'admin.cultura.arteSacra.report', 
                    'class' => 'fa-list-check', 
                    'label' => 'Relatório Geral', 
                    'permission' => 'GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA',
                ],
                [
                    'route' => 'admin.cultura.arteSacra.trash', 
                    'class' => 'fa-trash', 
                    'label' => 'Lixeira', 
                    'permission' => 'DIRETOR_DE_ARTE_SACRA',
                ],
                [
                    'route' => 'admin.cultura.arteSacra.logs.usuarios', 
                    'class' => 'fa-user-secret', 
                    'label' => 'Logs de Usuários', 
                    'permission' => 'DIRETOR_DE_ARTE_SACRA',
                ],
            ],
        ])

        @include('errors.messageFlash')

        <div class="card-body">
            <div class="btn-group mb-3 flex-wrap bg-light d-flex justify-content-start p-3" role="group">
                <button type="button" class="btn btn-outline-primary filter-btn active me-2 mb-2" data-filter="classArte">
                    {{ __("Classes de Arte") }}
                </button>
                <button type="button" class="btn btn-outline-primary filter-btn me-2 mb-2" data-filter="designacao">
                    {{ __("Usos") }}
                </button>
                <button type="button" class="btn btn-outline-primary filter-btn me-2 mb-2" data-filter="modoAquisicao">
                    {{ __("Modos de Aquisição") }}
                </button>
                <button type="button" class="btn btn-outline-primary filter-btn me-2 mb-2" data-filter="proprietario">
                    {{ __("Proprietários ou Localizações") }}
                </button>
                <button type="button" class="btn btn-outline-primary filter-btn me-2 mb-2" data-filter="tecnica">
                    {{ __("Técnicas") }}
                </button>
                <button type="button" class="btn btn-outline-primary filter-btn me-2 mb-2" data-filter="material">
                    {{ __("Materiais") }}
                </button>
                <button type="button" class="btn btn-outline-primary filter-btn me-2 mb-2" data-filter="tiposAcervo">
                    {{ __("Tipos de Acervo") }}
                </button>
                <button type="button" class="btn btn-outline-primary filter-btn mb-2" data-filter="tombamento">
                    {{ __("Tombamentos") }}
                </button>
            </div>

            <div class="table-responsive mt-4">
                <table class="table text-center align-middle">
                    <thead>
                        <tr>
                            <th id="dynamicHeader" class="text-center">{{ __("Classes de Arte") }}</th>
                            <th class="text-center" style="width: 10%">{{ __("Status") }}</th>
                        </tr>
                    </thead>
                    <tbody>
                        
                        @php $index = 0 @endphp
                        @foreach ($classArtes as $classArte)
                            <tr class="filter-row classArte-row {{ $classArte->status == 0 ? 'bg-secondary text-white' : '' }}">
                                <td class="align-middle">
                                    @include('components.arteSacra._optionForm', [
                                        'value' => $classArte->classe,
                                        'id' => $classArte->id,
                                        'type' => 'classArte',
                                        'permission' => 'GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA',
                                    ])
                                </td>
                                <td class="align-middle">
                                    @include('components.buttons._status', [
                                        "index" => $index,
                                        "route" => "admin.cultura.arteSacra.options.toggleStatus",
                                        "id" => [$classArte->id, 'classArte'],
                                        "status" => $classArte->status,
                                        "permission" => "GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA",
                                    ])
                                </td>
                            </tr>
                            @php $index++; @endphp
                        @endforeach
                        
                        @include('components.arteSacra._addOption', [
                            'type' => 'classArte',
                            'title' => 'Nova Classes de Arte',
                            'permission' => 'GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA',
                        ])
                            
                        @php $index = 200 @endphp
                        @foreach ($designacoes as $designacao)
                            <tr class="filter-row designacao-row">
                                <td colaspan="2" class="align-middle">
                                    @include('components.arteSacra._optionForm', [
                                        'value' => $designacao->designacao,
                                        'id' => $designacao->id,
                                        'type' => 'designacao',
                                        'permission' => 'GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA',
                                    ])
                                </td>
                                <td class="align-middle">
                                    @include('components.buttons._status', [
                                        "index" => $index,
                                        "route" => "admin.cultura.arteSacra.options.toggleStatus",
                                        "id" => [$designacao->id, 'designacao'],
                                        "status" => $designacao->status,
                                        "permission" => "GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA",
                                    ])
                                </td>
                            </tr>
                            @php $index++; @endphp
                        @endforeach
                            
                        @include('components.arteSacra._addOption', [
                            'type' => 'designacao',
                            'title' => 'Novo Uso',
                            'permission' => 'GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA',
                        ])    
                         
                        @php $index = 400 @endphp
                        @foreach ($materiais as $material)
                            <tr class="filter-row material-row">
                                <td class="align-middle">
                                    @include('components.arteSacra._optionForm', [
                                        'value' => $material->material,
                                        'id' => $material->id,
                                        'type' => 'material',
                                        'permission' => 'GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA',
                                    ])
                                </td>
                                <td class="align-middle">
                                    @include('components.buttons._status', [
                                        "index" => $index,
                                        "route" => "admin.cultura.arteSacra.options.toggleStatus",
                                        "id" => [$material->id, 'material'],
                                        "status" => $material->status,
                                        "permission" => "GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA",
                                    ])
                                </td>
                            </tr>
                            @php $index++; @endphp
                        @endforeach
                            
                        @include('components.arteSacra._addOption', [
                            'type' => 'material',
                            'title' => 'Novo Material',
                            'permission' => 'GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA',
                        ])

                        @php $index = 600 @endphp
                        @foreach ($modosAquisicoes as $modoAquisicao)
                            <tr class="filter-row modoAquisicao-row">
                                <td class="align-middle">
                                    @include('components.arteSacra._optionForm', [
                                        'value' => $modoAquisicao->modo_aquisicao,
                                        'id' => $modoAquisicao->id,
                                        'type' => 'modoAquisicao',
                                        'permission' => 'GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA',
                                    ])
                                </td>
                                <td class="align-middle">
                                    @include('components.buttons._status', [
                                        "index" => $index,
                                        "route" => "admin.cultura.arteSacra.options.toggleStatus",
                                        "id" => [$modoAquisicao->id, 'modoAquisicao'],
                                        "status" => $modoAquisicao->status,
                                        "permission" => "GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA",
                                    ])
                                </td>
                            </tr>
                            @php $index++; @endphp
                        @endforeach
                            
                        @include('components.arteSacra._addOption', [
                            'type' => 'modoAquisicao',
                            'title' => 'Novo Modo de Aquisição',
                            'permission' => 'GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA',
                        ])

                        @php $index = 800 @endphp
                        @foreach ($proprietarios as $proprietario)
                            <tr class="filter-row proprietario-row">
                                <td class="align-middle">
                                    @include('components.arteSacra._optionForm', [
                                        'value' => $proprietario->proprietario,
                                        'id' => $proprietario->id,
                                        'type' => 'proprietario',
                                        'permission' => 'GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA',
                                    ])
                                </td>
                                <td class="align-middle">
                                    @include('components.buttons._status', [
                                        "index" => $index,
                                        "route" => "admin.cultura.arteSacra.options.toggleStatus",
                                        "id" => [$proprietario->id, 'proprietario'],
                                        "status" => $proprietario->status,
                                        "permission" => "GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA",
                                    ])
                                </td>
                            </tr>
                            @php $index++; @endphp
                        @endforeach
                        
                        @include('components.arteSacra._addOption', [
                            'type' => 'proprietario',
                            'title' => 'Novo Proprietario ou Localização',
                            'permission' => 'GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA',
                        ])

                        @php $index = 1000 @endphp
                        @foreach ($tecnicas as $tecnica)
                            <tr class="filter-row tecnica-row">
                                <td class="align-middle">
                                    @include('components.arteSacra._optionForm', [
                                        'value' => $tecnica->tecnica,
                                        'id' => $tecnica->id,
                                        'type' => 'proprietario',
                                        'permission' => 'GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA',
                                    ])
                                </td>
                                <td class="align-middle">
                                    @include('components.buttons._status', [
                                        "index" => $index,
                                        "route" => "admin.cultura.arteSacra.options.toggleStatus",
                                        "id" => [$tecnica->id, 'tecnica'],
                                        "status" => $tecnica->status,
                                        "permission" => "GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA",
                                    ])
                                </td>
                            </tr>
                            @php $index++; @endphp
                        @endforeach
                            
                        @include('components.arteSacra._addOption', [
                            'type' => 'tecnica',
                            'title' => 'Nova Tecnica',
                            'permission' => 'GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA',
                        ])

                        @php $index = 1200 @endphp
                        @foreach ($tiposAcervos as $tiposAcervo)
                            <tr class="filter-row tiposAcervo-row">
                                <td class="align-middle">
                                    @include('components.arteSacra._optionForm', [
                                        'value' => $tiposAcervo->tipo,
                                        'id' => $tiposAcervo->id,
                                        'type' => 'tiposAcervo',
                                        'permission' => 'GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA',
                                    ])
                                </td>
                                <td class="align-middle">
                                    @include('components.buttons._status', [
                                        "index" => $index,
                                        "route" => "admin.cultura.arteSacra.options.toggleStatus",
                                        "id" => [$tiposAcervo->id, 'tiposAcervo'],
                                        "status" => $tiposAcervo->status,
                                        "permission" => "GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA",
                                    ])
                                </td>
                            </tr>
                            @php $index++; @endphp
                        @endforeach
                        
                        @include('components.arteSacra._addOption', [
                            'type' => 'tiposAcervo',
                            'title' => 'Novo Tipo de Acervo',
                            'permission' => 'GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA',
                        ])

                        @php $index = 1400 @endphp
                        @foreach ($tombamentos as $tombamento)
                            <tr class="filter-row tombamento-row">
                                <td class="align-middle">
                                    @include('components.arteSacra._optionForm', [
                                        'value' => $tombamento->tombamento,
                                        'id' => $tombamento->id,
                                        'type' => 'tombamento',
                                        'permission' => 'GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA',
                                    ])
                                </td>
                                <td class="align-middle">
                                    @include('components.buttons._status', [
                                        "index" => $index,
                                        "route" => "admin.cultura.arteSacra.options.toggleStatus",
                                        "id" => [$tombamento->id, 'tombamento'],
                                        "status" => $tombamento->status,
                                        "permission" => "GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA",
                                    ])
                                </td>
                            </tr>
                            @php $index++; @endphp
                        @endforeach
                        
                        @include('components.arteSacra._addOption', [
                            'type' => 'tombamento',
                            'title' => 'Novo Tombamento',
                            'permission' => 'GERENCIADOR_DO_CADASTRO_DE_ARTE_SACRA',
                        ])
                    </tbody>
                </table>
            </div>

        </div>
    </div>

    <script>
        document.addEventListener("DOMContentLoaded", function() {
            $('.filter-row').hide();
            $('.classArte-row').show();

            $('.filter-btn').click(function() {

                const filter = $(this).data('filter');
                $('.filter-row').hide();
                $('.' + filter + '-row').show();
                $('.filter-btn').removeClass('active');
                $(this).addClass('active');
                const titulo = $(this).text().trim();
                $('#dynamicHeader').text(titulo);
            });
        });
    </script>
@endsection
