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

import { FormFieldTypes } from "@sc/modules/v2/CRUD/FormBuilder/types";
import { ComponentTypes } from "@sc/plugins/webcomponents/v2/types";

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

  const Container1 = () => (
    <Container style={{ padding: 40 }}>
      <FormBuilder
        fieldStyle={style.FORM_FIELD.style}
        inputStyle={style.FORM_FIELD.inputStyle}
        labelStyle={style.FORM_FIELD.labelStyle}
        data={[
          {
            type: FormFieldTypes.TEXT,
            name: "name",
            placeholder: "Full Name",
          },
          {
            type: FormFieldTypes.TEXT,
            name: "email",
            placeholder: "Email",
          },
          {
            type: FormFieldTypes.TEXT,
            name: "phone",
            placeholder: "Phone Number",
          },
        ]}
      />
      <Button
        style={{
          ...style.BUTTON.style,
          marginTop: 40,
        }}
        caption1="Next"
        caption1style={style.BUTTON.caption1}
      />
    </Container>
  );

  const Container2 = () => <div>Second Container</div>;

  return (
    <Block>
      <Section style={style.SECTION}>
        <Container
          style={{
            ...style.SECTION_INNER,
            maxWidth: get(data, "section.pageMargin"),
          }}
        >
          <Container
            style={{
              borderRadius: 5,
              border: `1px solid ${theme.backgroundColor}`,
            }}
          >
            <Switch
              style={{ width: 500, height: 300 }}
              globalStyle={{ color: "purple" }}
              actionItems={(switchContainer: any) => [
                {
                  type: ComponentTypes.BUTTON,
                  style: {
                    ...style.BUTTON.style,
                    width: "30%",
                    display: "inline-block",
                  },
                  caption1: "Action 1",
                  caption1style: style.BUTTON.caption1,
                  onClick: () => switchContainer(1),
                },
                {
                  type: ComponentTypes.BUTTON,
                  style: {
                    ...style.BUTTON.style,
                    width: "30%",
                    display: "inline-block",
                  },
                  caption1: "Action 2",
                  caption1style: style.BUTTON.caption1,
                  onClick: () => switchContainer(2),
                },
              ]}
              containerItems={[
                {
                  id: 1,
                  children: Container1,
                },
                {
                  id: 2,
                  style: { color: "red", fontSize: "36pt" },
                  children: Container2,
                },
              ]}
            />
          </Container>
        </Container>
      </Section>
    </Block>
  );
};

export default Layout;
