package com.example.pap_teste;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import com.bumptech.glide.Glide;
import com.google.android.material.button.MaterialButton;

public class RestaurantDetailActivity extends AppCompatActivity {

    public static final String EXTRA_RESTAURANT_ID = "extra_restaurant_id";
    public static final String EXTRA_RESTAURANT_NAME = "extra_restaurant_name";
    public static final String EXTRA_RESTAURANT_IMAGE = "extra_restaurant_image";
    public static final String EXTRA_RESTAURANT_CUISINE = "extra_restaurant_cuisine";
    public static final String EXTRA_RESTAURANT_RATING = "extra_restaurant_rating";
    public static final String EXTRA_RESTAURANT_DESC = "extra_restaurant_desc";
    public static final String EXTRA_RESTAURANT_ADDRESS = "extra_restaurant_address";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_restaurant_detail);

        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setTitle("");
        }

        ImageView coverImage = findViewById(R.id.restaurantCover);
        TextView nameText = findViewById(R.id.detailName);
        TextView cuisineText = findViewById(R.id.detailCuisine);
        TextView ratingText = findViewById(R.id.detailRating);
        TextView descText = findViewById(R.id.detailDescription);
        TextView addressText = findViewById(R.id.detailAddress);
        MaterialButton btnReserve = findViewById(R.id.btnReserveNow);

        // Get data from intent
        String name = getIntent().getStringExtra(EXTRA_RESTAURANT_NAME);
        String image = getIntent().getStringExtra(EXTRA_RESTAURANT_IMAGE);
        String cuisine = getIntent().getStringExtra(EXTRA_RESTAURANT_CUISINE);
        double rating = getIntent().getDoubleExtra(EXTRA_RESTAURANT_RATING, 0.0);
        String desc = getIntent().getStringExtra(EXTRA_RESTAURANT_DESC);
        String address = getIntent().getStringExtra(EXTRA_RESTAURANT_ADDRESS);

        nameText.setText(name);
        cuisineText.setText(cuisine);
        ratingText.setText(String.format("%.1f ★", rating));
        descText.setText(desc);
        addressText.setText(address);

        Glide.with(this).load(image).into(coverImage);

        btnReserve.setOnClickListener(v -> {
            Intent intent = new Intent(this, ReservationActivity.class);
            intent.putExtra(EXTRA_RESTAURANT_ID, getIntent().getStringExtra(EXTRA_RESTAURANT_ID));
            intent.putExtra(EXTRA_RESTAURANT_NAME, getIntent().getStringExtra(EXTRA_RESTAURANT_NAME));
            startActivity(intent);
        });

        toolbar.setNavigationOnClickListener(v -> onBackPressed());
    }
}
