﻿using Bolt;
using Ludiq;
using UnityEngine;

namespace InfinityCode.OnlineMapsBolt
{
    [UnitTitle("Reset Tileset Events")]
    public class ResetTilesetEvents : OnlineMapsBoltEventBase
    {
        [DoNotSerialize]
        [PortLabel("Camera Control")]
        public ValueInput OnCameraControl;

        [DoNotSerialize]
        [PortLabel("Mesh Updated")]
        public ValueInput OnMeshUpdated;

        [DoNotSerialize]
        [PortLabel("Smooth Zoom Begin")]
        public ValueInput OnSmoothZoomBegin;

        [DoNotSerialize]
        [PortLabel("Smooth Zoom Finish")]
        public ValueInput OnSmoothZoomFinish;

        [DoNotSerialize]
        [PortLabel("Smooth Zoom Init")]
        public ValueInput OnSmoothZoomInit;

        [DoNotSerialize]
        [PortLabel("Smooth Zoom Process")]
        public ValueInput OnSmoothZoomProcess;

        protected override void OnDefinition()
        {
            OnCameraControl = ValueInput("OnCameraControl", false);
            OnMeshUpdated = ValueInput("OnMeshUpdated", false);
            OnSmoothZoomBegin = ValueInput("OnSmoothZoomBegin", false);
            OnSmoothZoomFinish = ValueInput("OnSmoothZoomFinish", false);
            OnSmoothZoomInit = ValueInput("OnSmoothZoomInit", false);
            OnSmoothZoomProcess = ValueInput("OnSmoothZoomProcess", false);
        }

        protected override void OnEnter(Flow flow)
        {
            OnlineMapsTileSetControl control = OnlineMapsTileSetControl.instance;
            if (control == null)
            {
                Debug.Log("Tileset is null");
                return;
            }

            if (flow.GetValue<bool>(OnCameraControl) && OnlineMapsCameraOrbit.instance != null) OnlineMapsCameraOrbit.instance.OnCameraControl = null;
            if (flow.GetValue<bool>(OnMeshUpdated)) control.OnMeshUpdated = null;
            if (flow.GetValue<bool>(OnSmoothZoomBegin)) control.OnSmoothZoomBegin = null;
            if (flow.GetValue<bool>(OnSmoothZoomFinish)) control.OnSmoothZoomFinish = null;
            if (flow.GetValue<bool>(OnSmoothZoomInit)) control.OnSmoothZoomInit = null;
            if (flow.GetValue<bool>(OnSmoothZoomProcess)) control.OnSmoothZoomProcess = null;
        }
    }
}