(function( wp ) {
  const { __ } = wp.i18n;
  const { registerBlockType, getBlockType } = wp.blocks;
  const { createElement: el } = wp.element;

// Avoid double registration in cases where the script is loaded twice by the editor.
  if (getBlockType && getBlockType('foodord/card')) {
    return;
  }

  registerBlockType('foodord/card', {
    title: __('FoodOrd Card', 'foodord'),
    icon: 'cart',
    category: 'widgets',
    edit: function Edit() {
      return el(
        'div',
        { className: 'wr-card wr-card--editor' },
        el('div', { className: 'wr-card__header' }, el('h2', { className: 'wr-card__title' }, __('Your order', 'foodord'))),
        el('div', { className: 'wr-card__body' },
          el('div', { className: 'wr-card__empty' },
            el('p', { className: 'wr-card__empty-text' }, __('Your cart is empty', 'foodord')),
            el('p', { className: 'wr-card__empty-subtext' }, __('Add items to get started', 'foodord'))
          )
        ),
        el('div', { className: 'wr-card__footer' },
          el('button', { className: 'wr-card__cta', disabled: true, 'aria-disabled': 'true', type: 'button' }, __('Checkout', 'foodord'))
        )
      );
    },
    save: function Save() {
      return null; // dynamic block
    }
  });
})( window.wp );
