package application.views.круг;

import MyFigures.*;

import application.views.MainLayout;
import com.vaadin.flow.component.button.Button;
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;

@PageTitle("Круг")
@Route(value = "empty", layout = MainLayout.class)
public class КругView extends VerticalLayout {

    private TextField radius;
    private TextField perimeter;
    private TextField space;
    private Button calculatePerimeter;
    private Button calculateSpace;


    public КругView() {
        radius = new TextField("Радиус");
        perimeter = new TextField("Периметр");
        space = new TextField("Площадь");

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

        calculatePerimeter.addClickListener(e -> {
            MyCircle circle = new MyCircle(Double.valueOf(radius.getValue()));
            perimeter.setValue(String.valueOf(circle.calculatePerimeter()));
        });

        calculateSpace.addClickListener(e -> {
            MyCircle circle = new MyCircle(Double.valueOf(radius.getValue()));
            space.setValue(String.valueOf(circle.calculateSpace()));
        });

        setMargin(true);

        add(radius, perimeter, space, calculatePerimeter, calculateSpace);
    }

}
