package de.fullrisk.citrusDev;

import io.wispforest.owo.ui.base.BaseOwoScreen;
import io.wispforest.owo.ui.component.UIComponents;
import io.wispforest.owo.ui.container.FlowLayout;
import io.wispforest.owo.ui.container.UIContainers;
import io.wispforest.owo.ui.core.*;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundEvents;
import de.fullrisk.citrusDev.ScalableLabel;
import de.fullrisk.citrusDev.ScalableButton;
import de.fullrisk.citrusDev.ScaleValue;

public class MyScreen extends BaseOwoScreen<FlowLayout> {

    public MyScreen() {
        super(Component.literal("Citrus Dev"));
        Minecraft.getInstance().getSoundManager().play(
                SimpleSoundInstance.forUI(SoundEvents.UI_TOAST_IN, 1.5F, 2)
        );
    }

    @Override
    protected OwoUIAdapter<FlowLayout> createAdapter() {
        return OwoUIAdapter.create(this, UIContainers::verticalFlow);
    }

    @Override
    protected void build(FlowLayout rootComponent) {
        rootComponent
                .horizontalAlignment(HorizontalAlignment.CENTER)
                .verticalAlignment(VerticalAlignment.CENTER);

        FlowLayout panel = UIContainers.verticalFlow(Sizing.content(), Sizing.content());
        panel.gap(6);
        panel.padding(Insets.of(12));

        panel.horizontalAlignment(HorizontalAlignment.CENTER);
        panel.verticalAlignment(VerticalAlignment.CENTER);
        panel.horizontalSizing(Sizing.fixed(0));
        panel.verticalSizing(Sizing.fixed(0));
        panel.horizontalSizing().animate(300, Easing.CUBIC, Sizing.fixed(250)).forwards();
        panel.verticalSizing().animate(300, Easing.CUBIC, Sizing.fixed(150)).forwards();

        var header = new ScalableLabel(Component.literal("Citrus Dev"));
        panel.child(header);

        var header_button = new ScalableButton(Component.literal("Click me"), btn -> {
            btn.setMessage(Component.literal("Clicked!"));
            Minecraft.getInstance().getSoundManager().play(
                    SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK.value(), 2.0F, 2)
            );
        });

        header_button.scale().animate(300, Easing.CUBIC, new ScaleValue(1f)).forwards();
        panel.child(header_button);
        header.scale().animate(300, Easing.CUBIC, new ScaleValue(2f)).forwards();


        Surface glassPanel = Surface.blur(5f, 15f)
                .and(Surface.flat(0x40FFFFFF))
                .and(Surface.outline(0xFFFFFFFF));

        panel.surface(glassPanel);

        var version = new ScalableLabel(Component.literal("Citrus-Dev v2.0"))
                .horizontalTextAlignment(HorizontalAlignment.RIGHT)
                .verticalTextAlignment(VerticalAlignment.BOTTOM);

        panel.child(version);
        rootComponent.child(panel);
    }



    @Override
    public boolean isPauseScreen() {
        return false;
    }
}