<div id="root"></div>
:root {
  --white: #efefef;
  --white-alpha: rgba(239, 239, 239, .64);
  --grey: #d6d6d6;
  --gray: var(--grey);
  --black: #292f36;
  --pure-black: #131313;
  --pure-black-alpha: rgba(19, 19, 19, .64);
  --pure-black-alpha-light: rgba(19, 19, 19, .24);
  --pure-black-alpha-transparent: rgba(19, 19, 19, .12);
  
  --primary: #d63c6b;
  --primary-dk: #c41c4f;
  --accent: #5cc8ff;
  --accent-dk: #00a3f5;
  
  --transition: 300ms;
  --easing: cubic-bezier(1, 1, 1, 1);
  --easing-bounce-in: cubic-bezier(0, 0, .43, 1.3);
  --easing-bounce-out: cubic-bezier(.43, 1.3, 0, 0);
  font-size: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

*,
*:before,
*:after {
  box-sizing: border-box;
}

html,
body {
  position: relative;
  
  width: 100%;
  height: 100%;
  background-image: linear-gradient(to bottom right, var(--accent) 0%, var(--primary) 100%);
  background-repeat: no-repeat;
  background-attachment: fixed;
}

body {
  padding-top: 20px;
  user-select: none;
}

button {
  outline: none;
  border: 0;
  padding: 1rem;
  background-color: var(--black);
  
  font-size: 1.25rem;
  line-height: 1;
  color: var(--accent);

  transition: all var(--transition) var(--easing);
}

button:hover {
    color: var(--accent-dk);
  }

button.block {
    width: 100%;
  }

button.transparent {
    background-color: transparent;
  }

button.no-padding {
    padding: 0;
  }

button.long-text { font-size: 1rem; }

.react-calculator {
  position: relative;
  margin: 0 auto;
  width: 320px;
  
  box-shadow: 0 19px 38px var(--pure-black-alpha-light),
    0 15px 12px var(--pure-black-alpha-transparent);
}

body::-webkit-scrollbar, .editable-field::-webkit-scrollbar, .memory-bank::-webkit-scrollbar { width: .5rem; }

body::-webkit-scrollbar:horizontal, .editable-field::-webkit-scrollbar:horizontal, .memory-bank::-webkit-scrollbar:horizontal { height: .5rem; }

body::-webkit-scrollbar-track,
  body::-webkit-scrollbar:horizontal,
  .editable-field::-webkit-scrollbar-track,
  .editable-field::-webkit-scrollbar:horizontal,
  .memory-bank::-webkit-scrollbar-track,
  .memory-bank::-webkit-scrollbar:horizontal {
    background-color: var(--pure-black);
  }

body::-webkit-scrollbar-thumb,
  body::-webkit-scrollbar:horizontal,
  .editable-field::-webkit-scrollbar-thumb,
  .editable-field::-webkit-scrollbar:horizontal,
  .memory-bank::-webkit-scrollbar-thumb,
  .memory-bank::-webkit-scrollbar:horizontal {
    background-color: var(--primary);
  }

s
  body:hover::-webkit-scrollbar-thumb,
    s
  body:hover::-webkit-scrollbar:horizontal,
    s
  .editable-field:hover::-webkit-scrollbar-thumb,
    s
  .editable-field:hover::-webkit-scrollbar:horizontal,
    s
  .memory-bank:hover::-webkit-scrollbar-thumb,
    s
  .memory-bank:hover::-webkit-scrollbar:horizontal {
      background-color: var(--primary-dk);
    }

.editable-field {
  position: relative;
  width: 320px;
  height: 80px;
  z-index: 10;
  
  outline: none;
  box-shadow: 0 4px 2px -2px var(--pure-black-alpha);
  padding: .5rem;
  overflow-y: hidden;
  overflow-x: scroll;
  
  background-color: var(--pure-black-alpha);

  font-size: 2rem;
  line-height: 2;
  color: var(--primary);
  text-align: right;
  direction: rtl;
  white-space: nowrap;
}

.memory-bank {
  position: absolute;
  top: 80px;
  left: 0;
  z-index: 10;
  
  width: 100%;
  height: 0;
  overflow: hidden;
  padding: 0;
  
  background-color: var(--pure-black-alpha);
  color: var(--accent-dk);
  
  transition: height 150ms var(--easing),
    overflow 1ms var(--easing) 200ms,
    padding 1ms var(--easing) 200ms;
}

.memory-bank .toggle-close {
    position: absolute;
    top: 5px;
    right: 5px;
    padding: 2px 5px;
  }

.memory-bank .toggle-close .title {
      display: inline-block;
      transform: rotate(45deg);
    }

.memory-bank.visible {
    height: calc(100% - 80px);
    padding: 10px;
    overflow-y: auto;
    
    transition: height 200ms var(--easing),
      padding 1ms var(--easing);
  }

.button-set--functions,
  .button-set--equations {
    background-color: var(--black);
  }

.button-set--functions button, .button-set--equations button {
      display: inline-block;
      width: 80px;
      height: 80px;
      
      vertical-align: top;
      text-transform: uppercase;
      font-variant: small-caps;
      color: var(--primary);
    }

.button-set--functions button:hover, .button-set--equations button:hover {
        color: var(--primary-dk);
      }

.button-set--numbers {
    width: 240px;
    float: left;
    background-color: var(--black);
  }

.button-set--numbers button {
      display: block;
      position: relative;
      
      width: 80px;
      height: 80px;
      float: left;
      
      background-color: var(--black);
      
      transition: box-shadow var(--transition) var(--easing);
    }

.button-set--numbers button:last-child {        
        width: 100%;
      }

.button-set--functions {
    clear: left;
    float: left;
    width: 240px;
  }
const ee = new EventEmitter();
const App = React.createClass({ displayName: "App",
  render() {
    return /*#__PURE__*/(
      React.createElement("main", { className: "react-calculator" }, /*#__PURE__*/
      React.createElement(InputField, null), /*#__PURE__*/
      React.createElement(TotalRecall, null), /*#__PURE__*/
      React.createElement(ButtonSetNumbers, null), /*#__PURE__*/
      React.createElement(ButtonSetFunctions, null), /*#__PURE__*/
      React.createElement(ButtonSetEquations, null)));


  } });

const Button = React.createClass({ displayName: "Button",
  _handleClick() {
    let text = this.props.text,
    cb = this.props.clickHandler;

    if (cb) {
      cb.call(null, text);
    }
  },

  render() {
    return /*#__PURE__*/(
      React.createElement("button", { className: this.props.klass, onClick: this._handleClick }, /*#__PURE__*/
      React.createElement("span", { className: "title" }, this.props.text)));


  } });

const ContentEditable = React.createClass({ displayName: "ContentEditable",
  _handleClick() {
    const cb = this.props.clickHandler;

    if (cb) {
      cb.call(this);
    }
  },

  render() {
    return /*#__PURE__*/(
      React.createElement("div", { className: "editable-field", contentEditable: this.props.initEdit, spellcheck: this.props.spellCheck, onClick: this._handleClick },
      this.props.text));


  } });


const InputField = React.createClass({ displayName: "InputField",
  _updateField(newStr) {
    newStr = newStr.split ? newStr.split(' ').reverse().join(' ') : newStr;
    return this.setState({ text: newStr });
  },

  getInitialState() {
    this.props.text = this.props.text || '0';

    return { text: this.props.text };
  },

  componentWillMount() {
    ee.addListener('numberCruncher', this._updateField);
  },

  render() {
    return /*#__PURE__*/React.createElement(ContentEditable, { text: this.state.text, initEdit: "false", spellcheck: "false", clickHandler: this._clickBait });
  } });

const TotalRecall = React.createClass({ displayName: "TotalRecall",
  _toggleMemories() {
    this.setState({ show: !this.state.show });
  },

  _recallMemory(memory) {
    store.newInput = memory;
    ee.emitEvent('toggle-memories');
  },

  getInitialState() {
    return { show: false };
  },

  componentWillMount() {
    ee.addListener('toggle-memories', this._toggleMemories);
  },

  render() {
    let classNames = `memory-bank ${this.state.show ? 'visible' : ''}`;

    return /*#__PURE__*/(
      React.createElement("section", { className: classNames }, /*#__PURE__*/
      React.createElement(Button, { text: "+", clickHandler: this._toggleMemories, klass: "toggle-close" }),
      store.curMemories.map(mem => {
        return /*#__PURE__*/(
          React.createElement(Button, { klass: "block memory transparent", text: mem, clickHandler: this._recallMemory }));

      })));


  } });

const ButtonSetFunctions = React.createClass({ displayName: "ButtonSetFunctions",
  _showMemoryBank() {
    ee.emitEvent('toggle-memories');
  },

  _clear() {
    store.newInput = 0;
  },

  _contentClear() {
    let curInput = String(store.curInput),
    lessOne = curInput.substring(0, curInput.length - 1);

    return store.newInput = lessOne === '' ? 0 : lessOne;
  },

  render() {
    return /*#__PURE__*/(
      React.createElement("section", { className: "button-set--functions" }, /*#__PURE__*/
      React.createElement(Button, { klass: "long-text", text: "recall", clickHandler: this._showMemoryBank }), /*#__PURE__*/
      React.createElement(Button, { klass: "long-text", text: "clear", clickHandler: this._clear }), /*#__PURE__*/
      React.createElement(Button, { text: "\u2190", clickHandler: this._contentClear })));


  } });

const ButtonSetEquations = React.createClass({ displayName: "ButtonSetEquations",
  _eq(type) {
    store.newInput = `${store.curInput} ${type} `;
  },

  _equate() {
    store.newInput = eval(store.curInput);
  },

  render() {
    return /*#__PURE__*/(
      React.createElement("section", { className: "button-set--equations" }, /*#__PURE__*/
      React.createElement(Button, { text: "+", clickHandler: this._eq }), /*#__PURE__*/
      React.createElement(Button, { text: "-", clickHandler: this._eq }), /*#__PURE__*/
      React.createElement(Button, { text: "*", clickHandler: this._eq }), /*#__PURE__*/
      React.createElement(Button, { text: "/", clickHandler: this._eq }), /*#__PURE__*/
      React.createElement(Button, { text: "=", clickHandler: this._equate })));


  } });

const ButtonSetNumbers = React.createClass({ displayName: "ButtonSetNumbers",
  _number(num) {
    if (!store.curInput) {
      return store.newInput = num;
    }

    return store.newInput = `${store.curInput}${num}`;
  },

  render() {
    return /*#__PURE__*/(
      React.createElement("section", { className: "button-set--numbers" }, /*#__PURE__*/
      React.createElement(Button, { text: "1", clickHandler: this._number }), /*#__PURE__*/
      React.createElement(Button, { text: "2", clickHandler: this._number }), /*#__PURE__*/
      React.createElement(Button, { text: "3", clickHandler: this._number }), /*#__PURE__*/
      React.createElement(Button, { text: "4", clickHandler: this._number }), /*#__PURE__*/
      React.createElement(Button, { text: "5", clickHandler: this._number }), /*#__PURE__*/
      React.createElement(Button, { text: "6", clickHandler: this._number }), /*#__PURE__*/
      React.createElement(Button, { text: "7", clickHandler: this._number }), /*#__PURE__*/
      React.createElement(Button, { text: "8", clickHandler: this._number }), /*#__PURE__*/
      React.createElement(Button, { text: "9", clickHandler: this._number }), /*#__PURE__*/
      React.createElement(Button, { text: "0", clickHandler: this._number })));


  } });


let store = {
  input: 0,
  memory: [],
  get curInput() {
    return this.input;
  },

  get curMemories() {
    return this.memory.filter(m => m !== undefined);
  },

  set commitMemory(input) {
    this.memory.push(input);
  },

  set newInput(str) {
    let curInput = str,
    oldInput = this.curInput;

    if (this.curMemories.indexOf(oldInput) === -1) {
      this.commitMemory = oldInput;
    }

    this.input = curInput;
    ee.emitEvent('numberCruncher', [this.curInput]);
  } };


React.render( /*#__PURE__*/
React.createElement(App, null),
document.querySelector('body'));