package com.wisewoods.base.base;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewbinding.ViewBinding;

import com.blankj.utilcode.util.BarUtils;

import retrofit2.Call;

public abstract class BaseActivity<VB extends ViewBinding> extends AppCompatActivity {

    protected BaseActivity activity;
    protected VB binding;
    private BaseLogic<VB> logic;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        BarUtils.setStatusBarLightMode(this, true);
        activity = this;
        logic = new BaseLogic<>(this);
        logic.init();
        super.onCreate(savedInstanceState);
        logic.initData(null, null, savedInstanceState);
        binding = logic.getBinding();
        initData(savedInstanceState);
    }

    protected void showBarBack(TextView tvTitle, String text, ImageView ivBack) {
        tvTitle.setText(text);
        ivBack.setVisibility(View.VISIBLE);
        ivBack.setOnClickListener(v -> finish());
    }

    protected <T> Call<T> addCall(Call<T> call) {
        return logic.addCall(call);
    }

    @Override
    protected void onDestroy() {
        logic.onD();
        super.onDestroy();
    }

    protected boolean hasEvent() {
        return false;
    }

    protected abstract void initData(Bundle savedInstanceState);

    protected Object getLayout() {
        return logic.getLayout();
    }

    protected void showLoading() {
        if (logic != null) {
            logic.showLoading();
        }
    }

    protected void hideLoading() {
        if (logic != null) {
            logic.hideLoading();
        }
    }

    protected boolean isFastClick() {
        if (logic != null) {
            return logic.isFastClick();
        }
        return true;
    }

}
