package com.ycgis.macall.personalcenter.p.presenter;

import android.content.Context;
import android.util.ArrayMap;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.ycgis.macall.personalcenter.R;

import java.util.Map;

/**
 * created by:   Macall
 * create time:  2024/3/16 17:51
 * copyright:    @ruansee.com
 * Describe:
 */
public class BtnSkip {
    private Map<Integer,Content> contentMap;
    private Context context;
    private int selColorId = R.color.colorWhite,defColorId = R.color.colorGrey8;

    public BtnSkip(Context context) {
        this.context = context;
        this.contentMap = new ArrayMap<>();
    }

    public BtnSkip setTextColor(int selColorId , int defColorId){
        this.defColorId = defColorId;
        this.selColorId = selColorId;
        return this;
    }

    public BtnSkip add(int index, Content content){
        contentMap.put(index,content);
        return this;
    }

    public void clean(){
        context = null;
        if (contentMap!=null){
            for (int key:contentMap.keySet()) {
                Content content = contentMap.get(key);
                if (content!=null){
                    content.clean();
                }
            }
            contentMap.clear();
        }

        contentMap = null;
    }

    public void unDateStatus(int index,boolean isSel){
        Content content = contentMap.get(index);
        if (content == null) return;
        content.setStatus(isSel);
    }

   public class Content{
        private TextView view;
        private ImageView image;
        private int selDrawable,defDrawable;

       public Content(TextView view, ImageView image, int selDrawable, int defDrawable) {
           this.view = view;
           this.image = image;
           this.selDrawable = selDrawable;
           this.defDrawable = defDrawable;
       }

       private void setStatus(boolean isSel){
            if (isSel){
                view.setTextColor(ContextCompat.getColor(context,selColorId));
                image.setImageDrawable(ContextCompat.getDrawable(context,selDrawable));
            }else {
                view.setTextColor(ContextCompat.getColor(context,defColorId));
                image.setImageDrawable(ContextCompat.getDrawable(context,defDrawable));
            }
        }

        public void clean(){
            view = null;
            selDrawable = 0;
            defColorId = 0;
        }
    }
}
