var _excluded = ["className", "country", "inline", "title"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React from 'react';
import styled, { css, useTheme } from 'styled-components';
import flags from './flags';
import { assert } from '../../../common/utils';
import { CleanSvg } from './CleanSvg';
var FLAGS_WITH_WHITE_BACKGROUND = ['fi', 'jp', 'ru'];
export var StyledSvg = styled(CleanSvg).withConfig({
  displayName: "FlagBase__StyledSvg",
  componentId: "sc-1d4wcvo-0"
})(["", ""], function (_ref) {
  var inline = _ref.inline,
    $height = _ref.$height,
    $width = _ref.$width;
  return css(["height:", "px;width:", "px;user-select:none;flex-shrink:0;", ""], $height, $width, inline ? "display: inline-block;\n          vertical-align: middle;\n          position: relative;\n          bottom: 1px;" : 'display: block;');
});
export var FlagBase = function FlagBase(_ref2) {
  var className = _ref2.className,
    country = _ref2.country,
    inline = _ref2.inline,
    title = _ref2.title,
    rest = _objectWithoutProperties(_ref2, _excluded);
  assert(Boolean(country), 'Flag: You need to supply a country code');
  var FlagPathComponent = country ? flags[country.toLowerCase()] : null;
  var theme = useTheme();
  if (!FlagPathComponent) {
    return null;
  }
  var grayBorder = FLAGS_WITH_WHITE_BACKGROUND.includes(country.toLowerCase()) && !theme.isDarkMode;
  return React.createElement(StyledSvg, _extends({
    className: className,
    preserveAspectRatio: "xMidYMid meet",
    focusable: "false",
    role: "img",
    inline: inline,
    viewBox: "0 0 14 14"
  }, rest), React.createElement(FlagPathComponent, {
    borderColor: grayBorder ? theme.color.flagBorder : null,
    title: title
  }));
};