<?= $this->extend('layouts/master') ?>

<?= $this->section('title') ?>
Gestión de Organización
<?= $this->endSection() ?>

<?= $this->section('css') ?><?= $this->endSection() ?>

<?= $this->section('pageContent') ?>
        <div class="container-fluid py-4">

    <!-- HEADER -->
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h3 class="fw-bold mb-1">Organización:  <?=$organizacion["nombre"]?></h3>
            <!--<span class="badge bg-primary">Activa</span>
            <span class="badge bg-light text-dark">Territorial</span>-->
        </div>
       
    </div>

    <!-- NAV TABS -->
    <ul class="nav nav-tabs mb-4" id="orgTabs">
        <li class="nav-item">
            <a class="nav-link active" data-bs-toggle="tab" href="#tab-ficha">
                <i class="ti ti-info-circle me-1"></i> Ficha
            </a>
        </li>

    
        <li class="nav-item">
            <a class="nav-link" data-bs-toggle="tab" href="#tab-representantes">
                <i class="ti ti-users me-1"></i> Usuarios
            </a>
        </li>
    </ul>

    <!-- TAB CONTENT -->
    <div class="tab-content">

        <!-- ###########################
             TAB 1: FICHA
        ###############################-->
        <div class="tab-pane fade show active" id="tab-ficha">
            <div class="card shadow-sm">
                <div class="card-header bg-white">
                    <h5 class="card-title mb-0">Información de la Organización</h5>
                </div>
                <div class="card-body">

                      <?=view('modulos/render',[
                        "respuesta_id"=>$organizacion["ficha_id"],
                        "formulario_id"=>1,
                        'readonly'     => true // o false
                      ])?>
                </div>
            </div>
        </div>

    

        <!-- ###########################
             TAB 3: REPRESENTANTES
        ###############################-->
        <div class="tab-pane fade" id="tab-representantes">
            <div class="card shadow-sm">
                <div class="card-header bg-white d-flex justify-content-between align-items-center">
                    <h5 class="card-title mb-0">Usuarios asociados a tu organización</h5>
                    <button class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#modalRepresentante">
                        <i class="ti ti-user-plus me-1"></i> Agregar Representante
                    </button>
                </div>
                <div class="card-body">

                    <div class="list-group">

                       

                        <?php 
                          foreach ($usuarios as $key => $usuario) {
                            ?>
                             <!-- Representante -->
                            <div class="list-group-item d-flex justify-content-between align-items-center">
                                <div>
                                    <h6 class="fw-bold mb-0"><?=$usuario["nombre"]?></h6>
                                    <small class="text-muted"><?=ucfirst($usuario["cargo"])?> · Rut: <?=$usuario["rut"]?></small>
                                </div>
                                <div>
                                   <!-- <button class="btn btn-light btn-sm"><i class="ti ti-edit"></i></button>
                                    <button class="btn btn-light btn-sm"><i class="ti ti-trash"></i></button>-->
                                </div>
                            </div>
                            <?php
                          }
                        ?>

                    </div>

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

    </div>
</div>


<!-- MODAL REPRESENTANTE -->
<div class="modal fade" id="modalRepresentante" tabindex="-1">
  <div class="modal-dialog modal-md modal-dialog-centered">
    <div class="modal-content">
      
      <div class="modal-header">
        <h5 class="modal-title fw-bold">
          <i class="ti ti-user-plus me-2"></i>Agregar Representante
        </h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
      </div>

      <div class="modal-body">

        <div
          class="alert alert-primary"
          role="alert"
        >
          <h4 class="alert-heading">Atención</h4>
          <p>Para crear un nuevo usuario debe realizar una solicitud en el apartado "Gestión de Tickets"</p>
          <hr />
          <a href="<?=site_url('gestion-tickets')?>" class="btn btn-primary btn-sm">Enviar un ticket</a>
        </div>
        

      </div>

      <div class="modal-footer">
        <button class="btn btn-light" data-bs-dismiss="modal">Cancelar</button>
      
      </div>

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




<?= $this->endSection() ?>