package com.unibuy.smartdevice;

import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
import android.view.WindowInsetsController;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.unibuy.smartdevice.exception.Logs;
import com.unibuy.smartdevice.tools.HandlerMain;
import com.unibuy.smartdevice.tools.Tools;

public abstract class FragmentAbstract extends Fragment {
    private String name;
    private Context ctx;
    private Logs logs;
    private Tools tools;
    private boolean useStartOnSwitchFragment;
    private HandlerMain handlerMain;
    private HandlerMain srcHandlerMain;

    public Context getCtx() {
        return ctx;
    }

    public Logs getLogs() {
        return logs;
    }

    public Tools getTools() {
        return tools;
    }

    public HandlerMain getHandlerMain() {
        return handlerMain;
    }
    public HandlerMain getSrcHandlerMain() {
        return srcHandlerMain;
    }

    public void setUseStartOnSwitchFragment(boolean useStartOnSwitchFragment) {
        this.useStartOnSwitchFragment = useStartOnSwitchFragment;
    }

    public boolean isUseStartOnSwitchFragment() {
        return useStartOnSwitchFragment;
    }

    protected abstract String setName();
    protected abstract Context setCtx();
    protected abstract Class<?> setCls();
    protected abstract HandlerMain setHandlerMain();

    public FragmentAbstract(HandlerMain srcHandlerMain) {
        useStartOnSwitchFragment = false;
        this.srcHandlerMain = srcHandlerMain;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        name = setName();
        ctx = setCtx();
        this.logs = new Logs(setCls());
        this.tools = new Tools(getCtx(), logs);
        this.handlerMain = setHandlerMain();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    public abstract void startOnSwitchFragment();
    public abstract void stopOnSwitchFragment();
}
