package com.example.application.views.трапеция;

import MyFigures.RectangleI;
import MyFigures.TrapeziumI;
import com.example.application.views.MainLayout;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.html.H2;
import com.vaadin.flow.component.html.Image;
import com.vaadin.flow.component.html.Paragraph;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.theme.lumo.LumoUtility.Margin;

@PageTitle("Трапеция")
@Route(value = "empty2", layout = MainLayout.class)
public class ТрапецияView extends VerticalLayout {

    private TextField sideA;
    private TextField sideB;
    private TextField sides;
    private TextField height;
    private TextField perimeter;
    private TextField space;
    private Button calculatePerimeter;
    private Button calculateSpace;


    public ТрапецияView() {
        sideA = new TextField("Верхняя сторона");
        sideB = new TextField("Нижняя сторона");
        sides = new TextField("Боковые стороны");
        height = new TextField("Высота");
        perimeter = new TextField("Периметр");
        space = new TextField("Площадь");

        calculatePerimeter = new Button("Вычислить периметр");
        calculateSpace = new Button("Вычислить площадь");

        calculatePerimeter.addClickListener(e -> {
            TrapeziumI trapezium = new TrapeziumI(
                    Double.valueOf(sideA.getValue()),
                    Double.valueOf(sideB.getValue()),
                    Double.valueOf(sides.getValue()),
                    Double.valueOf(height.getValue()));
            perimeter.setValue(String.valueOf(trapezium.calculatePerimeter()));
        });

        calculateSpace.addClickListener(e -> {
            TrapeziumI trapezium = new TrapeziumI(
                    Double.valueOf(sideA.getValue()),
                    Double.valueOf(sideB.getValue()),
                    Double.valueOf(sides.getValue()),
                    Double.valueOf(height.getValue()));

            space.setValue(String.valueOf(trapezium.calculateSpace()));
        });

        setMargin(true);

        add(sideA, sideB, sides, height, perimeter, space, calculatePerimeter, calculateSpace);
    }

}
