'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var preact = require('preact');
var hooks = require('preact/hooks');
var api = require('./api.js');

/**
 * Returns the `I18nTranslate` interface used to translate strings.
 */
function useTranslate() {
  const {
    i18n
  } = api.useApi();
  const translate = hooks.useCallback((...args) => {
    const translation = i18n.translate(...args);
    if (!Array.isArray(translation)) {
      return translation;
    }
    return translation.map((part, index) => {
      if (preact.isValidElement(part)) {
        return preact.cloneElement(part, {
          key: index
        });
      }
      return part;
    });
  }, [i18n]);
  return translate;
}

exports.useTranslate = useTranslate;
