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 {
  Block,
  Section,
  Headline,
  Text,
  Container,
  Grid,
  GridItem,
} from "@sc/plugins/webcomponents/v2";

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

const FtrGroup = ({ data }) => {
  const { title, text } = data;

  return (
    <Container
      style={{
        border: "1px solid #DDD",
        borderRadius: 3,
        backgroundColor: "#EEE",
        margin: 50,
      }}
    >
      <Grid>
        <GridItem xs={2}>
          <Text style={{ ...style.TEXT, fontWeight: "bold" as "bold" }}>
            {title}
          </Text>
        </GridItem>
        <GridItem xs={10}>
          <Text style={{ ...style.TEXT, textAlign: "left", fontSize: "12pt" }}>
            {text}
          </Text>
        </GridItem>
      </Grid>
    </Container>
  );
};

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={{ padding: 50 }}>
            <Grid spacing={5}>
              <GridItem xs={4}>
                <Container style={{ padding: 40 }}>
                  {doIShow(content, "main_headline") && (
                    <Headline
                      name="Main Headline"
                      id="main_headline"
                      style={{
                        ...style.HEADLINE,
                        ...get(content, "main_headline.style", {}),
                      }}
                    >
                      Arranged in a way that reflects are
                    </Headline>
                  )}
                  {doIShow(content, "sub_headline") && (
                    <Text
                      name="Sub Headline"
                      id="sub_headline"
                      style={{
                        ...style.TEXT,
                        ...get(content, "sub_headline.style", {}),
                      }}
                    >
                      {get(content, "sub_headline.html", "...")}
                    </Text>
                  )}
                </Container>
              </GridItem>
              <GridItem xs={4}>
                <ImagePlaceholder
                  type={ImagePlaceholderTypes.NONE}
                  style={{
                    backgroundColor: theme.backgroundColor,
                    width: "100%",
                    height: "100%",
                  }}
                />
              </GridItem>
              <GridItem xs={4}>
                <Container style={{ padding: 40 }}>
                  {doIShow(content, "main_headline") && (
                    <Headline
                      name="Main Headline"
                      id="main_headline"
                      style={{
                        ...style.HEADLINE,
                        ...get(content, "main_headline.style", {}),
                      }}
                    >
                      Unlike low fidelity wireframes
                    </Headline>
                  )}
                  {doIShow(content, "sub_headline") && (
                    <Text
                      name="Sub Headline"
                      id="sub_headline"
                      style={{
                        ...style.TEXT,
                        ...get(content, "sub_headline.style", {}),
                      }}
                    >
                      {get(content, "sub_headline.html", "...")}
                    </Text>
                  )}
                </Container>
              </GridItem>
            </Grid>
          </Container>
        </Container>
      </Section>
    </Block>
  );
};

export default Layout;
