package com.rugvedsarika.landarea.ui

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.rugvedsarika.landarea.R
import com.rugvedsarika.landarea.databinding.FragmentSketchpadBinding

class SketchpadFragment : Fragment() {

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

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

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        
        binding.toggleGroup.addOnButtonCheckedListener { _, checkedId, isChecked ->
            if (isChecked) {
                binding.sketchView.setEraserMode(checkedId == R.id.btnErase)
            }
        }

        binding.btnUndo.setOnClickListener {
            binding.sketchView.undo()
        }

        binding.btnClear.setOnClickListener {
            binding.sketchView.clear()
        }
    }

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