import styled from 'styled-components'

import Attribute from './Attribute'
import StyleManager from './StyleManager'

const Container = styled.div`
  position: sticky;
  top: 0;
  width: 300px;
  max-height: 100vh;
  padding-bottom: 10px;
  background: #333;
  color : #fff;
  overflow: auto;
`

const Title = styled.h2`
  font-size: 20px;
  line-height: 24px;
  text-align: center;
  padding: 10px;
  border-bottom: 1px solid #f9f9f9;
`

function Editor({ props }) {
  const id = props.id;
  const attributes = props.attributes;
  const styles = props.styles;
  const hasAttributes = attributes && Object.keys(attributes).length > 0;
  const hasStyles = styles && Object.keys(styles).length > 0;

  return (
    <>
      <Container>
        <Title>Editor</Title>
        {hasAttributes && <Attribute id={id} props={attributes} />}
        {hasStyles && <StyleManager id={id} props={styles} />}
      </Container>
    </>
  )
}

export default Editor