package com.example.application.views.прямоугольник;

import com.example.application.views.MainLayout;
import com.vaadin.flow.component.Key;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.router.RouteAlias;

import java.awt.*;

import MyFigures.*;


@PageTitle("Прямоугольник")
@Route(value = "hello", layout = MainLayout.class)
@RouteAlias(value = "", layout = MainLayout.class)
public class ПрямоугольникView extends HorizontalLayout {

    private TextField width;
    private TextField height;
    private TextField perimeter;
    private TextField space;
    private Button calculatePerimeter;
    private Button calculateSpace;


    public ПрямоугольникView() {
        width = new TextField("Ширина");
        height = new TextField("Высота");
        perimeter = new TextField("Периметр");
        space = new TextField("Площадь");

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

        calculatePerimeter.addClickListener(e -> {
            RectangleI rect = new RectangleI(Double.valueOf(width.getValue()), Double.valueOf(height.getValue()));
            perimeter.setValue(String.valueOf(rect.calculatePerimeter()));
        });

        calculateSpace.addClickListener(e -> {
            RectangleI rect = new RectangleI(Double.valueOf(width.getValue()), Double.valueOf(height.getValue()));
            space.setValue(String.valueOf(rect.calculateSpace()));
        });

        setMargin(true);

        add(width, height, perimeter, space, calculatePerimeter, calculateSpace);
    }

}
