package com.datarecovery.master.module.mine;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.atmob.app.lib.base.BaseFragment;
import com.datarecovery.master.R;
import com.datarecovery.master.databinding.FragmentMineBinding;
import com.datarecovery.master.dialog.CommonSureDialog;
import com.gyf.immersionbar.ImmersionBar;

import dagger.hilt.android.AndroidEntryPoint;


@AndroidEntryPoint
public class MineFragment extends BaseFragment<FragmentMineBinding> {


    private MineViewModel mineViewModel;
    private CommonSureDialog exitDialog;
    private CommonSureDialog logoutDialog;

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
        initObserver();
    }

    private void initObserver() {
        mineViewModel.getShowExitDialog().observe(getViewLifecycleOwner(), o -> showExitDialog());
        mineViewModel.getShowLogoutDialog().observe(getViewLifecycleOwner(), o -> showLogoutDialog());
    }

    private void initView() {

    }

    public void showExitDialog() {
        if (exitDialog == null) {
            exitDialog = new CommonSureDialog(requireContext());
            exitDialog.setDialogTitle(R.string.dialog_kind_tips).setDialogContent(R.string.dialog_exit_content);
            exitDialog.setOnDialogClickListener(() -> mineViewModel.onAccountExit());
        }
        exitDialog.show();
    }

    public void showLogoutDialog() {
        if (logoutDialog == null) {
            logoutDialog = new CommonSureDialog(requireContext());
            logoutDialog.setDialogTitle(R.string.dialog_logout_tips).setDialogContent(R.string.dialog_logout_content);
            logoutDialog.setOnDialogClickListener(() -> mineViewModel.onAccountLogout());
        }
        logoutDialog.show();
    }

    @Override
    protected void initViewModel() {
        super.initViewModel();
        mineViewModel = getViewModelProvider().get(MineViewModel.class);
        binding.setMineViewModel(mineViewModel);
    }

    @Override
    protected void configImmersion(@NonNull ImmersionBar immersionBar) {
        immersionBar.statusBarDarkFont(true);
    }
}
