import React from "react";
import styled, { css } from "styled-components";

import { Div, Span } from "../../base";

import { getColor, getMargin, getPadding, theme } from "../../styled-config";

const padding = (props) => {
  if (props.right) {
    return css`
      padding-right: ${getPadding(props, "divider", "default")};
    `;
  }
  return css`
    padding-right: ${getPadding(props, "divider", "default")};
    padding-left: ${getPadding(props, "divider", "default")};
  `;
};

const border = (props) =>
  css`
    border-bottom: 0.0625rem solid ${getColor(props, "divider", "color")};
  `;

const marning = (props) =>
  css`
    margin-bottom: ${getMargin(props, "divider", "default")};
  `;

const Body = styled(Div)`
  display: flex;
  alignitems: center;
`;

const Border = styled(Div)`
  flex-grow: 1;
  ${(props) => border(props)}
  ${(props) => marning(props)}
`;

const Content = styled(Span)`
  ${(props) => padding(props)};
`;

const Divider = ({ children }) => {
  return (
    <Body>
      <Border />
      <Content>{children}</Content>
      <Border />
    </Body>
  );
};

Divider.defaultProps = {
  theme,
};

const DividerStart = ({ children }) => {
  return (
    <Body>
      <Content right>{children}</Content>
      <Border />
    </Body>
  );
};

DividerStart.defaultProps = {
  theme,
};

export { Divider, DividerStart };
