"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.StyledSvg = exports.FlagBase = void 0;
var _react = _interopRequireDefault(require("react"));
var _styledComponents = _interopRequireWildcard(require("styled-components"));
var _flags = _interopRequireDefault(require("./flags"));
var _utils = require("../../../common/utils");
var _CleanSvg = require("./CleanSvg");
var _excluded = ["className", "country", "inline", "title"];
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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; }
var FLAGS_WITH_WHITE_BACKGROUND = ['fi', 'jp', 'ru'];
var StyledSvg = exports.StyledSvg = (0, _styledComponents.default)(_CleanSvg.CleanSvg).withConfig({
  displayName: "FlagBase__StyledSvg",
  componentId: "sc-1d4wcvo-0"
})(["", ""], function (_ref) {
  var inline = _ref.inline,
    $height = _ref.$height,
    $width = _ref.$width;
  return (0, _styledComponents.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;');
});
var FlagBase = exports.FlagBase = function FlagBase(_ref2) {
  var className = _ref2.className,
    country = _ref2.country,
    inline = _ref2.inline,
    title = _ref2.title,
    rest = _objectWithoutProperties(_ref2, _excluded);
  (0, _utils.assert)(Boolean(country), 'Flag: You need to supply a country code');
  var FlagPathComponent = country ? _flags.default[country.toLowerCase()] : null;
  var theme = (0, _styledComponents.useTheme)();
  if (!FlagPathComponent) {
    return null;
  }
  var grayBorder = FLAGS_WITH_WHITE_BACKGROUND.includes(country.toLowerCase()) && !theme.isDarkMode;
  return _react.default.createElement(StyledSvg, _extends({
    className: className,
    preserveAspectRatio: "xMidYMid meet",
    focusable: "false",
    role: "img",
    inline: inline,
    viewBox: "0 0 14 14"
  }, rest), _react.default.createElement(FlagPathComponent, {
    borderColor: grayBorder ? theme.color.flagBorder : null,
    title: title
  }));
};