package com.example.pantallacompra

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.pantallacompra.databinding.ActivityMainBinding
import com.google.firebase.database.DatabaseReference
import com.google.firebase.database.FirebaseDatabase

class MainActivity : AppCompatActivity() {
    private lateinit var binding: ActivityMainBinding
    private lateinit var eventosReferences : DatabaseReference
    private lateinit var salasReference: DatabaseReference
    private lateinit var asientosReference: DatabaseReference
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding= ActivityMainBinding.inflate(layoutInflater)
        eventosReferences= FirebaseDatabase.getInstance().getReference("Eventos")
        salasReference= FirebaseDatabase.getInstance().getReference("Salas")
        asientosReference= FirebaseDatabase.getInstance().getReference("Asientos")

        setContentView(R.layout.activity_main)
        cargarAsientos(asientosReference)

        val boton = findViewById<Button>(R.id.nextBtn)

        boton.setOnClickListener{
            val intent = Intent(this, EventList::class.java)
            startActivity(intent)
        }
    }

    fun insertData(eventosReference: DatabaseReference, salasReference: DatabaseReference, asientosReference: DatabaseReference){
        cagarEventos(eventosReference)
        cargarSalas(salasReference)
        cargarAsientos(asientosReference)
    }

    fun cagarEventos(database: DatabaseReference){
        //SE INSERTAN DATOS DE LOS EVENTOS EN LA BD
        val event1 = Event("Los caligaris","Musical",120,"Concierto")
        val event2= Event("Champions","futbol",100,"deportes")
        val event3= Event("Rhiana Show","Musical",120,"Concierto")
        val event4= Event("Potros Furiosos","Pelicula",120,"Entretenimiento")
        val event5= Event("Trans Show","futbol",120,"Entretenimiento")
        val event6= Event("Michael Jackson","Musical",120,"Concierto")
        database.child(event1.nombre.toString()).setValue(event1)
        database.child(event2.nombre.toString()).setValue(event2)
        database.child(event3.nombre.toString()).setValue(event3)
        database.child(event4.nombre.toString()).setValue(event4)
        database.child(event5.nombre.toString()).setValue(event5)
        database.child(event6.nombre.toString()).setValue(event6)
    }

    fun cargarSalas(database: DatabaseReference){
        //SE INSERTAN DATOS DE LAS SALAS EN LA BD
        val sala1=Sala(1,"los caligaris")
        val sala2=Sala(2,"Champions")
        val sala3=Sala(3,"Potros Furiosos")
        val sala4=Sala(4,"Trnas Show")

        database.child(sala1.n0Sala.toString()).setValue(sala1)
        database.child(sala2.n0Sala.toString()).setValue(sala2)
        database.child(sala3.n0Sala.toString()).setValue(sala3)
        database.child(sala4.n0Sala.toString()).setValue(sala4)
    }
    fun cargarAsientos(database: DatabaseReference){
        val asientoA1=Asiento("A1",10,"Chafa","Libre",1)
        val asientoA2=Asiento("A2",10,"Chafa","Libre",1)
        val asientoA3=Asiento("A3",10,"Chafa","Libre",1)
        val asientoB1=Asiento("B1",10,"Regular","Libre",1)
        val asientoB2=Asiento("B2",10,"Regular","Libre",1)
        val asientoB3=Asiento("B3",10,"Regular","Libre",1)

        database.child(asientoA1.noAsiento.toString()).setValue(asientoA1)
        database.child(asientoA2.noAsiento.toString()).setValue(asientoA2)
        database.child(asientoA3.noAsiento.toString()).setValue(asientoA3)
        database.child(asientoB1.noAsiento.toString()).setValue(asientoB1)
        database.child(asientoB2.noAsiento.toString()).setValue(asientoB2)
        database.child(asientoB3.noAsiento.toString()).setValue(asientoB3)
    }
}