package com.example.elva.ui.onboarding

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.example.elva.databinding.FragmentOnboardingPageBinding

class OnboardingPageFragment : Fragment() {

    private var _binding: FragmentOnboardingPageBinding? = null
    private val binding get() = _binding!!

    private var pagePosition: Int = 0

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            pagePosition = it.getInt(ARG_POSITION)
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        _binding = FragmentOnboardingPageBinding.inflate(inflater, container, false)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        // Устанавливаем контент в зависимости от позиции
        when (pagePosition) {
            0 -> {
                binding.textTitle.text = getString(com.example.elva.R.string.onboarding_title_1)
                binding.textDescription.text = getString(com.example.elva.R.string.onboarding_description_1)
            }
            1 -> {
                binding.textTitle.text = getString(com.example.elva.R.string.onboarding_title_2)
                binding.textDescription.text = getString(com.example.elva.R.string.onboarding_description_2)
            }
            2 -> {
                binding.textTitle.text = getString(com.example.elva.R.string.onboarding_title_3)
                binding.textDescription.text = getString(com.example.elva.R.string.onboarding_description_3)
            }
            3 -> {
                binding.textTitle.text = getString(com.example.elva.R.string.onboarding_title_4)
                binding.textDescription.text = getString(com.example.elva.R.string.onboarding_description_4)
            }
            4 -> {
                binding.textTitle.text = getString(com.example.elva.R.string.onboarding_title_5)
                binding.textDescription.text = getString(com.example.elva.R.string.onboarding_description_5)
            }
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }

    companion object {
        private const val ARG_POSITION = "position"

        fun newInstance(position: Int) = OnboardingPageFragment().apply {
            arguments = Bundle().apply {
                putInt(ARG_POSITION, position)
            }
        }
    }
}

