package ch.spherIC.recurvebowsight.ui.equipment;

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

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import ch.spherIC.recurvebowsight.R;
import ch.spherIC.recurvebowsight.databinding.FragmentEquipmentAddListBinding;

public class AddEquipmentFragment extends Fragment {

    private FragmentEquipmentAddListBinding binding;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        AddEquipmentViewModel homeViewModel = new ViewModelProvider(this).get(AddEquipmentViewModel.class);
        binding = FragmentEquipmentAddListBinding.inflate(inflater, container, false);
        View root = binding.getRoot();

        View view = root.findViewById(R.id.card_view_riser_border);
        view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                float alpha = 1.0f;
                int horzMargin = v.getResources().getDimensionPixelSize(R.dimen.nav_header_horizontal_spacing);
                int vertMargin = v.getResources().getDimensionPixelSize(R.dimen.nav_header_vertical_spacing);
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    alpha = 0.9f;
                    horzMargin = v.getResources().getDimensionPixelSize(R.dimen.nav_header_horizontal_spacing_onclick);
                    vertMargin = v.getResources().getDimensionPixelSize(R.dimen.nav_header_vertical_spacing_onclick);
                }
                View setupCardView = v.findViewById(R.id.card_view_riser_setup);
                setupCardView.setAlpha(alpha);

                ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) v.getLayoutParams();
                layoutParams.setMargins(horzMargin, vertMargin, horzMargin, vertMargin);
                v.requestLayout();
                return true;
            }
        });


        final TextView textView = binding.textEquipment;
        homeViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);
        return root;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }


}