package com.atmob.voiceai.module.clonevoice;

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

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.widget.NestedScrollView;

import com.atmob.app.lib.base.BaseFragment;
import com.atmob.common.ui.SizeUtil;
import com.atmob.voiceai.databinding.FragmentCloneVoiceBinding;
import com.gyf.immersionbar.ImmersionBar;

import dagger.hilt.android.AndroidEntryPoint;

@AndroidEntryPoint
public class CloneVoiceFragment extends BaseFragment<FragmentCloneVoiceBinding> {


    private CloneVoiceViewModel cloneVoiceViewModel;

    private int maxScrollY;

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

    private void initView() {
        initScrollView();
    }

    private void initScrollView() {
        maxScrollY = (int) SizeUtil.dp2px(89);
        binding.scrollView.setOnScrollChangeListener((NestedScrollView.OnScrollChangeListener) (v, scrollX, scrollY, oldScrollX, oldScrollY) -> {
            if (scrollY > maxScrollY) {
                binding.vStatusBar.setAlpha(1f);
                binding.vMenu.setAlpha(1f);
            } else {
                binding.vStatusBar.setAlpha(scrollY * 1f / maxScrollY);
                binding.vMenu.setAlpha(scrollY * 1f / maxScrollY);
            }
        });
    }

    private void initObserver() {

    }

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


    @Override
    protected void initViewModel() {
        super.initViewModel();
        cloneVoiceViewModel = getViewModelProvider().get(CloneVoiceViewModel.class);
        binding.setCloneVoiceViewModel(cloneVoiceViewModel);
    }
}
