import * as React from "react";
import { get } from "lodash";

import { style } from "./style";
import { default as defaultData } from "./data.json";

import { doIShow, combineData } from "../../utils";
import { ImagePlaceholder, ImagePlaceholderTypes } from "../../Placeholders";
import theme from "../../theme";

import {
  Block,
  Section,
  Headline,
  Text,
  Container,
  Button,
} from "@sc/plugins/webcomponents/v2";

type LayoutProps = {
  data: any;
};

const Layout: React.FC<LayoutProps> = ({ data }) => {
  const initialContent = {
    main_headline: {
      html: "Headline Goes Here",
    },
    sub_headline: {
      html: "Sub Headline Text Content Goes Here",
    },
  };

  const content = combineData(initialContent, defaultData, data);

  return (
    <Block>
      <Section style={style.SECTION}>
        <Container
          style={{
            ...style.SECTION_INNER,
            maxWidth: get(data, "section.pageMargin"),
          }}
        >
          <Container style={{ maxWidth: 900, margin: "0 auto" }}>
            <ImagePlaceholder
              type={ImagePlaceholderTypes.NONE}
              style={{
                height: 400,
                maxWidth: 450,
                margin: "40px auto",
                backgroundColor: theme.backgroundColor,
              }}
            />
            {doIShow(content, "main_headline") && (
              <Headline
                name="Main Headline"
                id="main_headline"
                style={{
                  ...style.HEADLINE,
                  ...get(content, "main_headline.style", {}),
                }}
              >
                {get(content, "main_headline.html", "...")}
              </Headline>
            )}
            <Container style={{ textAlign: "center" }}>
              <Button
                style={style.BUTTON.style}
                caption1="Start"
                caption1style={style.BUTTON.caption1}
              />
            </Container>
          </Container>
        </Container>
      </Section>
    </Block>
  );
};

export default Layout;
