package com.house.wallpapers.myfragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.house.wallpapers.myactivity.RateUsDialog;
import com.house.wallpapers.databinding.FragmentSettingBinding;

public class FragmentSetting extends Fragment {

    private FragmentSettingBinding vb;

    public static FragmentSetting newInstance() {
        return new FragmentSetting();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        // 绑定布局
        vb = FragmentSettingBinding.inflate(inflater, container, false);

        // 初始化沉浸式布局
        initEdgeToEdge();

        // 初始化点击事件（仅保留评分相关）
        initClickListeners();

        return vb.getRoot();
    }

    /**
     * 初始化沉浸式布局（保持原有逻辑）
     */
    private void initEdgeToEdge() {
        if (getActivity() != null) {
            ViewCompat.setOnApplyWindowInsetsListener(vb.main, (v, insets) -> {
                Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
                v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
                return insets;
            });
        }
    }

    /**
     * 初始化点击事件（仅保留评分功能）
     */
    private void initClickListeners() {
        // 评分按钮（右侧箭头）
        TextView tvRateUs = vb.tvRateUs;
        tvRateUs.setOnClickListener(v -> {
            if (getActivity() != null) {
                new RateUsDialog(getActivity()).show();
            }
        });

        // 评分选项整体点击（可选，增强交互）
        vb.llRateUs.setOnClickListener(v -> {
            if (getActivity() != null) {
                new RateUsDialog(getActivity()).show();
            }
        });
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        // 释放绑定，避免内存泄漏
        vb = null;
    }
}