using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityCommunity.UnitySingleton;
using UnityEngine.UIElements;
using System.Drawing;
using System.Xml.Linq;

public class CameraManager : MonoSingleton<CameraManager>
{
    [SerializeField] private Camera _camera;
    [SerializeField] private Vector3 _positionOffset = new Vector3(0,0,0);
    [SerializeField] private float orthographicSizeOffset = 0;
    public Camera Camera => _camera;
    public Vector3 Position 
    { 
        get { return transform.position; }
        set { _camera.transform.position = value; } 
    }
    public float OrthographicSize { get { return _camera.orthographicSize; } set { _camera.orthographicSize = value; } }
    public void SetOrthographicSize()
    {
        float unitToScreenXRatio = 1.082667f;
        Vector3 boardSize = LevelManager.CurrentLevel.BoardData.Size;
        OrthographicSize = (float)Mathf.Max(boardSize.x, boardSize.y) 
            * unitToScreenXRatio
            + (orthographicSizeOffset * boardSize.x);
    }
    public void SetPosition()
    {
        Vector3 boardSize = LevelManager.CurrentLevel.BoardData.Size;
        Vector3 spaceBetweenTiles = StaticBoardManager.SpaceBetweenTiles(LevelManager.CurrentLevel.ShapeType);
        Vector3 cameraCenterPosition = new Vector3(
            (float)(boardSize.x - 1) * 0.5f,
            -(float)(boardSize.y - 1) * 0.5f * spaceBetweenTiles.y,
            -990f);
        if (LevelManager.CurrentLevel.ShapeType == EShapeType.Hexagon2 && boardSize.y > 1)
        {
            cameraCenterPosition.x -= 0.25f;
        }
        cameraCenterPosition.y -= boardSize.y * _positionOffset.y;
        Position = cameraCenterPosition;
    }
}
