using System;
using UnityEngine;
using VContainer;

public class PlatformManager : MonoBehaviour
{
    private GameObject currentPlatfrom;
    [Inject] private PlatformPool pool;
    [Inject] private InputReader inputReader;
    [Inject] private StartScreenController startScreenController;
    private int yPos=0;

    public int rotspeed = 1;


    void Start()
    {
        ShowInitialPlatforms();
    }
    private void OnEnable()
    {
        inputReader.OnDragValueChanged += DragPerformed;
    }
    private void OnDisable()
    {
        inputReader.OnDragValueChanged -= DragPerformed;
    }
    public void ShowInitialPlatforms()
    {
        
       foreach(var platfrom in pool.platformPool)
        {
            platfrom.gameObject.SetActive(true);
            platfrom.transform.position = new Vector3(0,yPos,0);
            yPos--;
        }
    }
    public void BuildPlatform()
    {
        currentPlatfrom = pool.GetPlatformFromPool();
        if(currentPlatfrom!=null)
        {
            currentPlatfrom.transform.position = new Vector3(0,yPos,0);
            currentPlatfrom.SetActive(true);
            yPos--;
        }
        
    }
    private void DragPerformed(Vector2 drag)
    {
        if(startScreenController.hasGameStarted)
        {
            float rotAmount = -drag.normalized.x * rotspeed;

#if UNITY_EDITOR || UNITY_STANDALONE
            if (inputReader.isclicked)
            {
                transform.Rotate(0, rotAmount, 0);
            }
#else
    transform.Rotate(0, rotAmount, 0);
#endif
        }

    }

}
