package com.example.countries;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;

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

import com.example.countries.databinding.ActivityMainBinding;

import java.util.ArrayList;


public class MainActivity extends AppCompatActivity {

    private ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);

        binding = ActivityMainBinding.inflate(getLayoutInflater());
        View view = binding.getRoot();
        setContentView(view);

        ArrayList<CountryModel> countries = new ArrayList<CountryModel>();
        countries.add(new CountryModel(
                R.string.serbia_title,
                R.string.serbia_city,
                R.string.serbia_description,
                R.drawable.serbia_flag));

        countries.add(new CountryModel(
                R.string.germany_title,
                R.string.germany_city,
                R.string.germany_description,
                R.drawable.germany_flag));

        countries.add(new CountryModel(
                R.string.uk_title,
                R.string.uk_city,
                R.string.uk_description,
                R.drawable.uk_flag));

        countries.add(new CountryModel(
                R.string.france_title,
                R.string.france_city,
                R.string.france_description,
                R.drawable.france_flag));

        countries.add(new CountryModel(
                R.string.italy_title,
                R.string.italy_city,
                R.string.italy_description,
                R.drawable.italy_flag));

        countries.add(new CountryModel(
                R.string.russia_title,
                R.string.russia_city,
                R.string.russia_description,
                R.drawable.russia_flag));

        countries.add(new CountryModel(
                R.string.japan_title,
                R.string.japan_city,
                R.string.japan_description,
                R.drawable.japan_flag));

        CountryAdapter adapter = new CountryAdapter(this, countries);
        binding.countryListView.setAdapter(adapter);

        binding.countryListView.setOnItemClickListener((parent, v, position, id) -> {
            CountryModel countrySelected = countries.get(position);

            Intent detailIntent = new Intent(MainActivity.this, DetailActivity.class);
            detailIntent.putExtra("COUNTRY", countrySelected);
            startActivity(detailIntent);
            overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
        });
    }
}