package com.example.recyclerviewproject;

import android.os.Bundle;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    List<Item> list;

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

        RecyclerView recyclerView = findViewById(R.id.rvlist);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));

        list = new ArrayList<>();
        list.add(new Item("שישיית טושים משומשים", 4, R.drawable.sixmarkers));
        list.add(new Item("מחשב נייד וינדוס", 1600, R.drawable.laptop));
        list.add(new Item("שלט למזגן", 50, R.drawable.remote));
        list.add(new Item("כיסא מורה במצב טוב", 150, R.drawable.teacherchair));
        list.add(new Item("לוח מחיק נייד", 400, R.drawable.whiteboard));

        recyclerView.setAdapter(new ItemsAdapter(list, new OnAdapterClickedListener() {
            @Override
            public void onItemClick(int position) {
                Toast.makeText(MainActivity.this, list.get(position).getItemName()+" שמחירו "+list.get(position).getItemPrice()+" שקלים", Toast.LENGTH_SHORT).show();
            }
        }));
    }
}