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";

type FtrGroupProps = {
  name?: string;
  data: any;
};
const FtrGroup: React.FC<FtrGroupProps> = ({ 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={{ maxWidth: 650, margin: "0 auto" }}>
            {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>
            )}
            {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>

          <Container style={{ padding: 50 }}>
            <Grid>
              <GridItem xs={4}>
                <FtrGroup
                  name="feature"
                  data={{
                    title: "01",
                    text: "Some tools allow the incorporation",
                  }}
                />
                <FtrGroup
                  name="feature"
                  data={{
                    title: "02",
                    text: "High fidelity wireframes can include actual",
                  }}
                />
                <FtrGroup
                  name="feature"
                  data={{
                    title: "03",
                    text: "Different values in color can be represented",
                  }}
                />
              </GridItem>
              <GridItem xs={4}>
                <ImagePlaceholder type={ImagePlaceholderTypes.MOBILE03} />
              </GridItem>
              <GridItem xs={4}>
                <FtrGroup
                  name="feature"
                  data={{
                    title: "04",
                    text: "Page layout is where these components",
                  }}
                />
                <FtrGroup
                  name="feature"
                  data={{
                    title: "05",
                    text: "Modern design incorporates various",
                  }}
                />
                <FtrGroup
                  name="feature"
                  data={{
                    title: "06",
                    text: "Depicts the relationship between these",
                  }}
                />
              </GridItem>
            </Grid>
          </Container>
        </Container>
      </Section>
    </Block>
  );
};

export default Layout;
