using Content.Shared.Light;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;

namespace Content.Client.Light.Visualizers
{
    [UsedImplicitly]
    public sealed class LightBulbVisualizer : AppearanceVisualizer
    {
        public override void OnChangeData(AppearanceComponent component)
        {
            base.OnChangeData(component);

            var entities = IoCManager.Resolve<IEntityManager>();
            if (!entities.TryGetComponent(component.Owner, out SpriteComponent sprite))
                return;

            // update sprite state
            if (component.TryGetData(LightBulbVisuals.State, out LightBulbState state))
            {
                switch (state)
                {
                    case LightBulbState.Normal:
                        sprite.LayerSetState(0, "normal");
                        break;
                    case LightBulbState.Broken:
                        sprite.LayerSetState(0, "broken");
                        break;
                    case LightBulbState.Burned:
                        sprite.LayerSetState(0, "burned");
                        break;
                }
            }

            // also update sprites color
            if (component.TryGetData(LightBulbVisuals.Color, out Color color))
            {
                sprite.Color = color;
            }
        }
    }
}
