package it.integry.integrywmsnative.ui.filter_chips;

import android.content.Context;
import android.content.res.ColorStateList;

import androidx.core.content.ContextCompat;

import com.google.android.material.chip.Chip;

import it.integry.integrywmsnative.R;
import it.integry.integrywmsnative.core.di.BindableString;
import it.integry.integrywmsnative.core.expansion.RunnableArgs;

public class FilterChipView extends Chip {

    public BindableString primaryText = new BindableString();

    private final Context mContext;
    private Runnable onResetClicked;

    private final ColorStateList defaultChipBackgroundColor;
    private final ColorStateList defaultChipTextColor;

    public FilterChipView(Context context, String text, RunnableArgs<FilterChipView> onClicked) {
        super(context);
        this.mContext = context;
        super.setText(text);

        this.defaultChipBackgroundColor = getChipBackgroundColor();
        this.defaultChipTextColor = getTextColors();

//        setShapeAppearanceModel(
//                getShapeAppearanceModel()
//                        .withCornerSize(4)
//                        .toBuilder()
//                        .build());
//
//        setChipMinHeight(getChipMinHeight() * 1.25f);

        setOnCloseIconClickListener(v -> {
            if (onResetClicked != null) onResetClicked.run();
        });
        setOnClickListener(v -> onClicked.run(this));

    }


    public void enableCloseIcon() {
        setCloseIconVisible(true);
        setTextColor(ContextCompat.getColor(this.mContext, android.R.color.white));
        setChipBackgroundColor(ColorStateList.valueOf(ContextCompat.getColor(this.mContext, R.color.colorPrimary)));
        setCloseIconTint(ColorStateList.valueOf(ContextCompat.getColor(this.mContext, android.R.color.white)));
    }

    public void disableCloseIcon() {
        setCloseIconVisible(false);
        setTextColor(defaultChipTextColor);
        setChipBackgroundColor(defaultChipBackgroundColor);
//        setCloseIconTint(ColorStateList.valueOf(ContextCompat.getColor(this.mContext, R.color.colorPrimary)));
    }


    public Runnable getOnResetClicked() {
        return onResetClicked;
    }

    public FilterChipView setOnResetClicked(Runnable onResetClicked) {
        this.onResetClicked = onResetClicked;
        return this;
    }
}
