import React from 'react';

import Button from '../components/Button';
import Icon from '../components/Icon';
import ExpansionPanel from '../components/ExpansionPanel';

import useActions from '../actions';
import useStore from '../store';
import { BtnWrapper } from '../global/toolStyled';

const CreateForm: React.FunctionComponent = () => {
  const [{ sidebarState }, dispatch] = useStore();
  const { setSidebar } = useActions(dispatch);

  const onClickSidebar = (state: string): void => {
    if (state === sidebarState) {
      setSidebar('');
    } else {
      setSidebar(state);
    }
  };

  return (
    <ExpansionPanel
      label={(
        <Button shouldFitContainer align="left" onClick={(): void => { onClickSidebar('create-form'); }}>
          <Icon glyph="create-form" style={{ marginRight: '10px' }} />
          Create Form
        </Button>
      )}
      isActive={sidebarState === 'create-form'}
    >
      <BtnWrapper>
        <Button shouldFitContainer align="left">
          <Icon glyph="text-field" style={{ marginRight: '10px' }} />
          Text Field
        </Button>
      </BtnWrapper>
      <BtnWrapper>
        <Button shouldFitContainer align="left">
          <Icon glyph="checkbox" style={{ marginRight: '10px' }} />
          Check box
        </Button>
      </BtnWrapper>
      <BtnWrapper>
        <Button shouldFitContainer align="left">
          <Icon glyph="radio-button" style={{ marginRight: '10px' }} />
          Radio Button
        </Button>
      </BtnWrapper>
    </ExpansionPanel>
  );
};

export default CreateForm;
