import { registerBlockType } from '@wordpress/blocks';
import { createElement } from '@wordpress/element';

import metadata from '../blocks/exchange-rates/block.json';
import { Edit } from './blocks/exchange-rates/edit';

import converterMetadata from '../blocks/currency-converter/block.json';
import { ConverterEdit } from './blocks/currency-converter/edit';

import './blocks/shared/style.css';
import './blocks/exchange-rates/style.css';
import './blocks/currency-converter/style.css';

/**
 * Block icon – RiCurrencyFill (Remix Icon).
 * Source: assets/icons/currency-converter.svg
 */
const blockIcon = createElement(
  'svg',
  { xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 24 24', width: 24, height: 24 },
  createElement('path', {
    fill: 'currentColor',
    d: 'M17.005 16.003h2v-12h-10v2h8zm0 2v2.999c0 .553-.45 1-1.007 1H4.012a1 1 0 0 1-1.007-1l.002-13.998c0-.553.45-1.001 1.007-1.001h2.99v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1zm-10-2v2h2v1h2v-1h.5a2.5 2.5 0 0 0 0-5h-3a.5.5 0 0 1 0-1h4.5v-2h-2v-1h-2v1h-.5a2.5 2.5 0 0 0 0 5h3a.5.5 0 0 1 0 1z',
  })
);

/**
 * Converter icon – IcTwotoneCurrencyExchange (Material Two-Tone).
 * Source: assets/icons/exchange-rates.svg
 */
const converterIcon = createElement(
  'svg',
  { xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 24 24', width: 24, height: 24 },
  createElement('path', {
    fill: 'currentColor',
    d: 'M12.89 11.1c-1.78-.59-2.64-.96-2.64-1.9c0-1.02 1.11-1.39 1.81-1.39c1.31 0 1.79.99 1.9 1.34l1.58-.67c-.15-.45-.82-1.92-2.54-2.24V5h-2v1.26c-2.48.56-2.49 2.86-2.49 2.96c0 2.27 2.25 2.91 3.35 3.31c1.58.56 2.28 1.07 2.28 2.03c0 1.13-1.05 1.61-1.98 1.61c-1.82 0-2.34-1.87-2.4-2.09l-1.66.67c.63 2.19 2.28 2.78 2.9 2.96V19h2v-1.24c.4-.09 2.9-.59 2.9-3.22c0-1.39-.61-2.61-3.01-3.44M3 21H1v-6h6v2H4.52c1.61 2.41 4.36 4 7.48 4a9 9 0 0 0 9-9h2c0 6.08-4.92 11-11 11c-3.72 0-7.01-1.85-9-4.67zm-2-9C1 5.92 5.92 1 12 1c3.72 0 7.01 1.85 9 4.67V3h2v6h-6V7h2.48C17.87 4.59 15.12 3 12 3a9 9 0 0 0-9 9z',
  })
);

registerBlockType(metadata as never, {
  icon: blockIcon,
  edit: Edit,
  save: () => null
});

registerBlockType(converterMetadata as never, {
  icon: converterIcon,
  edit: ConverterEdit,
  save: () => null
});
