package com.artisanic.helper.artadapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;

import com.artisanic.helper.ArtApp;
import com.artisanic.helper.artmanager.ArtUtils;
import com.artisanic.helper.artui.ArtCameraActivity;
import com.artisanic.helper.test.R;

import java.util.List;

public class ListAdapter extends RecyclerView.Adapter<ListAdapter.HomeVH> {

    private Context mCon;
    private List<String> data;

    public ListAdapter(Context mCon, List<String> bitmapList) {
        this.mCon = mCon;
        data = bitmapList;
    }

    @NonNull
    @Override
    public HomeVH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_list, parent, false);
        return new HomeVH(view);
    }

    @Override
    public void onBindViewHolder(@NonNull HomeVH holder, int position) {
        String imagePath = data.get(position);
        Log.d("---------tt","---------name="+imagePath);
        Bitmap bitmap = ArtUtils.loadImageFromAssets(mCon, imagePath);
        holder.previewIm.setImageBitmap(bitmap);

        // 适配你的 CameraActivity：仅传递 Key_Camera 参数（与你原有逻辑一致）
        holder.cardView.setOnClickListener(v -> {
            Intent intent = new Intent(mCon, ArtCameraActivity.class);
            intent.putExtra(ArtApp.Key_Camera, imagePath); // 传递完整图片路径
            mCon.startActivity(intent);
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public static class HomeVH extends RecyclerView.ViewHolder {
        private ImageView previewIm;
        private CardView cardView;

        public HomeVH(@NonNull View itemView) {
            super(itemView);
            previewIm = itemView.findViewById(R.id.imPreview);
            cardView = itemView.findViewById(R.id.card_view);
        }
    }
}