package com.wisewoods.base.base;

import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.IdRes;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.wisewoods.base.utils.ImgUtils;

import org.jetbrains.annotations.NotNull;

public class BaseVH extends BaseViewHolder {
    public BaseVH(@NotNull View view) {
        super(view);
    }

    @NotNull
    @Override
    public BaseVH setText(int viewId, @Nullable CharSequence value) {
        super.setText(viewId, value);
        return this;
    }

    @NotNull
    @Override
    public BaseVH setTextColor(int viewId, int color) {
        super.setTextColor(viewId, color);
        return this;
    }

    @NotNull
    @Override
    public BaseVH setTextColorRes(int viewId, int colorRes) {
        super.setTextColorRes(viewId, colorRes);
        return this;
    }

    @NotNull
    @Override
    public BaseVH setBackgroundResource(int viewId, int backgroundRes) {
        super.setBackgroundResource(viewId, backgroundRes);
        return this;
    }

    @NotNull
    @Override
    public BaseVH setGone(int viewId, boolean isGone) {
        super.setGone(viewId, isGone);
        return this;
    }

    @NotNull
    @Override
    public BaseVH setVisible(int viewId, boolean isVisible) {
        super.setVisible(viewId, isVisible);
        return this;
    }

    @NotNull
    @Override
    public BaseVH setImageResource(int viewId, int imageResId) {
        super.setImageResource(viewId, imageResId);
        return this;
    }

    public BaseVH setProgress(@IdRes int viewId, int progress) {
        ((ProgressBar) getView(viewId)).setProgress(progress);
        return this;
    }

    public BaseVH setNetUrl(@IdRes int viewId, String url, int error) {
        ImageView view = getView(viewId);
        ImgUtils.load(view.getContext(), url, error, view);
        return this;
    }

    public BaseVH setNetUrl(@IdRes int viewId, String url) {
        ImageView view = getView(viewId);
        ImgUtils.load(view.getContext(), url, view);
        return this;
    }

    public BaseVH setTextLeft(@IdRes int viewId, int imageResId) {
        TextView view = getView(viewId);
        Drawable drawable = view.getResources().getDrawable(imageResId);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        view.setCompoundDrawables(drawable, null, null, null);
        return this;
    }

    public BaseVH setTextTop(@IdRes int viewId, int imageResId) {
        TextView view = getView(viewId);
        Drawable drawable = view.getResources().getDrawable(imageResId);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        view.setCompoundDrawables(null, drawable, null, null);
        return this;
    }

    public BaseVH setTextRight(@IdRes int viewId, int imageResId) {
        TextView view = getView(viewId);
        Drawable drawable = view.getResources().getDrawable(imageResId);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        view.setCompoundDrawables(null, null, drawable, null);
        return this;
    }

    public BaseVH setTextBottom(@IdRes int viewId, int imageResId) {
        TextView view = getView(viewId);
        Drawable drawable = view.getResources().getDrawable(imageResId);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        view.setCompoundDrawables(null, null, null, drawable);
        return this;
    }
}
