package com.example.pap_teste;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class EstablishmentDashboardActivity extends AppCompatActivity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                EdgeToEdge.enable(this);
                setContentView(R.layout.activity_establishment_dashboard);
                ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.establishmentRoot), (v, insets) -> {
                        Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
                        v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
                        return insets;
                });

                TextView txtTitle = findViewById(R.id.txtEstabTitle);
                TextView txtSubtitle = findViewById(R.id.txtEstabSubtitle);
                TextView txtRole = findViewById(R.id.txtEstabRole);

                String actionMode = getIntent().getStringExtra(MainActivity.EXTRA_ACTION_MODE);
                String displayName = getIntent().getStringExtra(MainActivity.EXTRA_DISPLAY_NAME);
                String role = getIntent().getStringExtra(MainActivity.EXTRA_ROLE);

                boolean isNewAccount = "CRIAR".equalsIgnoreCase(actionMode);
                txtTitle.setText(displayName != null ? displayName : "Estabelecimento");
                txtRole.setText(String.format("Função: %s", role != null ? role : "ADMIN"));
                txtSubtitle.setText(isNewAccount
                                ? "Perfil criado. Configure horários, mesas e abra reservas."
                                : "Dashboard operacional. Acompanhe as reservas em tempo real.");

                Button btnOpenWalkIns = findViewById(R.id.btnAbrirEspera);
                Button btnStaff = findViewById(R.id.btnGestaoStaff);
                Button btnGerirMesas = findViewById(R.id.btnGerirMesas);
                Button btnDetails = findViewById(R.id.btnDetalhesReservas);
                Button btnSettings = findViewById(R.id.btnDefinicoes);
                Button btnBack = findViewById(R.id.btnVoltar);

                btnOpenWalkIns.setOnClickListener(v -> startActivity(new Intent(this, ListaEsperaActivity.class)));

                btnStaff.setOnClickListener(v -> startActivity(new Intent(this, GestaoStaffActivity.class)));

                btnGerirMesas.setOnClickListener(v -> startActivity(new Intent(this, GerirMesasActivity.class)));

                btnDetails.setOnClickListener(v -> startActivity(new Intent(this, DetalhesReservasActivity.class)));

                btnSettings.setOnClickListener(v -> {
                        Intent intent = new Intent(this, DefinicoesAdminActivity.class);
                        intent.putExtra(MainActivity.EXTRA_EMAIL, getIntent().getStringExtra(MainActivity.EXTRA_EMAIL));
                        startActivity(intent);
                });

                if (btnBack != null) {

                        btnBack.setOnClickListener(v -> finish());
                }
        }
}
