package de.assecutor.votianlt.pages.view;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.html.Anchor;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.H5;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import de.assecutor.votianlt.pages.base.ui.component.ViewToolbar;
import com.vaadin.flow.router.HasDynamicTitle;
import com.vaadin.flow.router.Route;
import jakarta.annotation.security.PermitAll;

@Route(value = "impressum", layout = de.assecutor.votianlt.pages.base.ui.view.MainLayout.class)
@PermitAll
public class ImprintView extends VerticalLayout implements HasDynamicTitle {
    public ImprintView() {
        setSizeFull();
        setPadding(true);
        setSpacing(false);
        addClassName("form-page");

        VerticalLayout content = new VerticalLayout();
        content.setWidthFull();
        content.setPadding(false);
        content.setSpacing(false);

        ViewToolbar toolbar = new ViewToolbar(getTranslation("page.title.imprint"));
        content.add(toolbar);

        Div imprintCard = new Div();
        imprintCard.addClassNames("form-card", "form-shell");
        imprintCard.getStyle().set("max-width", "800px").set("margin", "0 auto");

        VerticalLayout imprintContent = new VerticalLayout();
        imprintContent.setPadding(false);
        imprintContent.setSpacing(false);
        imprintContent.getStyle().set("gap", "var(--lumo-space-l)");

        imprintContent.add(
                createSection("Assecutor Data Service GmbH",
                        createLinesBlock(createLine("Gerhart-Hauptmann-Weg 14"), createLine("21502 Geesthacht"),
                                createLine(getTranslation("imprint.country")),
                                createLine(getTranslation("imprint.phone") + ": +49 40 18 123 771 0"),
                                createEmailLine())),
                createSection(getTranslation("imprint.management"),
                        createLinesBlock(createLine("Carsten Annacker"), createLine("Gunnar Timm"))),
                createSection(getTranslation("imprint.registeredoffice"),
                        createLinesBlock(createLine("Gerhart-Hauptmann-Weg 14, 21502 Geesthacht"))),
                createSection(getTranslation("imprint.commercialregister"),
                        createLinesBlock(createLine("HRB 8595 HL"))),
                createSection(getTranslation("imprint.vatid"), createLinesBlock(createLine("DE261094748"))),
                createSection(getTranslation("imprint.imagecredits"),
                        createLinesBlock(createSectionHeading(getTranslation("imprint.backgroundimage")),
                                createLine("MAN Financial Services (EURO-Leasing), flickr"),
                                createLine(
                                        "(Creative Commons, Attribution-ShareAlike 2.0 Generic (CC BY-SA 2.0))"),
                                createExternalLink(
                                        "https://www.flickr.com/photos/mbwa_pr/15969764443/in/album-72157632488355514/"))));

        imprintCard.add(imprintContent);
        content.add(imprintCard);

        add(content);
    }

    private Component createSection(String title, Component body) {
        Div section = new Div();
        section.getStyle().set("text-align", "left");
        section.add(createSectionHeading(title), body);
        return section;
    }

    private H5 createSectionHeading(String title) {
        H5 heading = new H5(title);
        heading.getStyle().set("margin", "0 0 var(--lumo-space-s) 0");
        return heading;
    }

    private Div createLinesBlock(Component... lines) {
        Div block = new Div();
        block.getStyle().set("display", "flex").set("flex-direction", "column").set("gap", "4px");
        block.add(lines);
        return block;
    }

    private Span createLine(String text) {
        Span line = new Span(text);
        line.getStyle().set("display", "block");
        return line;
    }

    private Div createEmailLine() {
        Div line = new Div();
        line.getStyle().set("display", "block");
        line.add(new Span(getTranslation("imprint.email") + ": "));
        line.add(new Anchor("mailto:ahoi@assecutor.de", "ahoi@assecutor.de"));
        return line;
    }

    private Anchor createExternalLink(String href) {
        Anchor link = new Anchor(href, href);
        link.setTarget("_blank");
        return link;
    }

    @Override
    public String getPageTitle() {
        return getTranslation("page.title.imprint");
    }
}
