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,
  Button,
  Grid,
  GridItem,
  FormField,
} from "@sc/plugins/webcomponents/v2";

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

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: 700, margin: "0 auto" }}>
            {doIShow(content, "pre_headline") && (
              <Headline
                name="Pre Headline"
                id="pre_headline"
                style={{
                  ...style.PRE_HEADLINE,
                  ...get(content, "pre_headline.style", {}),
                }}
              >
                {get(content, "pre_headline.html", "...")}
              </Headline>
            )}
            {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>
            )}

            <Grid
              spacing={4}
              style={{ maxWidth: 500, margin: "0 auto", marginTop: 0 }}
            >
              <GridItem xs={8}>
                {doIShow(content, "input") && (
                  <FormField
                    type="Text"
                    name="email"
                    placeholder="Enter Your Email"
                    style={style.FORM_FIELD.style}
                    inputStyle={style.FORM_FIELD.inputStyle}
                  />
                )}
              </GridItem>
              <GridItem xs={4}>
                {doIShow(content, "cta_button") && (
                  <Button
                    style={style.BUTTON.style}
                    caption1="Get Started"
                    caption1style={style.BUTTON.caption1}
                  />
                )}
              </GridItem>
            </Grid>
            {doIShow(content, "privacy_reminder") && (
              <Headline
                name="Privacy Reminder"
                id="privacy_reminder"
                style={{
                  ...style.TEXT,
                  ...get(content, "privacy_reminder.style", {}),
                }}
              >
                {get(content, "privacy_reminder.html", "...")}
              </Headline>
            )}
          </Container>
        </Container>
      </Section>
    </Block>
  );
};

export default Layout;
