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 theme from "../../theme";

import {
  Block,
  Section,
  Headline,
  Text,
  Container,
  Grid,
  GridItem,
  Icon,
  Repeater,
} from "@sc/plugins/webcomponents/v2";

import { IconTypes } from "@sc/plugins/webcomponents/v2/Icon";

const ItmGroup = ({ data }) => {
  const { icon, title, text } = data;
  return (
    <Container
      style={{
        background: theme.backgroundColor,
        padding: 40,
        textAlign: "center",
        borderRadius: 5,
      }}
    >
      <Icon type={IconTypes[icon]} style={style.ICON} />
      <Text
        style={{
          ...style.TEXT,
          color: theme.foregroundColor,
          fontWeight: "bold" as "bold",
          textAlign: "center",
          padding: 15,
        }}
      >
        {title}
      </Text>
      <Text
        style={{
          ...style.TEXT,
          color: theme.foregroundColor,
          textAlign: "center",
        }}
      >
        {text}
      </Text>
    </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"),
          }}
        >
          <Grid>
            <GridItem xs={6}>
              <Container style={{ padding: 50 }}>
                {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>
                )}
                {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>
            </GridItem>
            <GridItem xs={6}>
              <Grid spacing={5}>
                <Repeater
                  data={[
                    {
                      icon: "Delete",
                      title: "Proven Strategy",
                      text: "Since wireframe renderings are",
                    },
                    {
                      icon: "Delete",
                      title: "Proven Strategy",
                      text: "Since wireframe renderings are",
                    },
                    {
                      icon: "Delete",
                      title: "Proven Strategy",
                      text: "Since wireframe renderings are",
                    },
                    {
                      icon: "Delete",
                      title: "Proven Strategy",
                      text: "Since wireframe renderings are",
                    },
                  ]}
                >
                  {(item) => (
                    <GridItem xs={6}>
                      <ItmGroup data={item} />
                    </GridItem>
                  )}
                </Repeater>
              </Grid>
            </GridItem>
          </Grid>
        </Container>
      </Section>
    </Block>
  );
};

export default Layout;
