package com.auto.clicker.autoclicker.ui.activity.menu;

import android.os.Bundle;
import android.view.LayoutInflater;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.auto.clicker.autoclicker.R;
import com.auto.clicker.autoclicker.databinding.ActivityHowToUseBinding;
import com.auto.clicker.autoclicker.databinding.HowTabBinding;
import com.auto.clicker.autoclicker.ui.adapter.menu.HowAdapter;
import com.google.android.material.tabs.TabLayoutMediator;

public class HowToUseActivity extends AppCompatActivity {
    private ActivityHowToUseBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        binding = ActivityHowToUseBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        initPagerAdapter();
        initTabs();

        binding.howViewpager.setCurrentItem(0, false);
    }

    private void initPagerAdapter() {
        HowAdapter adapter = new HowAdapter(this);
        binding.howViewpager.setAdapter(adapter);
    }

    private void initTabs() {
        new TabLayoutMediator(binding.howTablayout, binding.howViewpager, (tab, idx) -> {
            com.auto.clicker.autoclicker.databinding.HowTabBinding tabViewBinding = HowTabBinding.inflate(LayoutInflater.from(this));
            tab.setCustomView(tabViewBinding.getRoot());
            decorateTab(tabViewBinding, idx);
        }).attach();
    }

    private void decorateTab(HowTabBinding tabBinding, int position) {
        String text = "";
        if (position == 0) {
            text = "Single-Point";
        } else if (position == 1) {
            text = "Multi-Point";
        }
        tabBinding.textCustom.setText(text);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        binding = null;
    }
}