"use strict";

exports.__esModule = true;
exports.UrlPropType = exports.SrcPropType = exports.PathPropType = exports.HexPropType = exports.FilesPropType = exports.ColorPropType = void 0;
var _propTypes = _interopRequireDefault(require("prop-types"));
var _split = _interopRequireDefault(require("lodash/fp/split"));
var _trim = _interopRequireDefault(require("lodash/fp/trim"));
var _includes = _interopRequireDefault(require("lodash/fp/includes"));
var _every = _interopRequireDefault(require("lodash/fp/every"));
var _stringMatching = _interopRequireDefault(require("extended-proptypes/lib/validators/stringMatching"));
var _color = _interopRequireDefault(require("extended-proptypes/lib/validators/color"));
var _hex = _interopRequireDefault(require("extended-proptypes/lib/validators/hex"));
var _isEmpty = _interopRequireDefault(require("lodash/fp/isEmpty"));
var _head = _interopRequireDefault(require("lodash/fp/head"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const URL_REGEXP = /^(http(s)?:\/\/.)[-a-zA-Z0-9@:%._\\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)$/;
const UrlPropType = exports.UrlPropType = (0, _stringMatching.default)(URL_REGEXP);
const PATH_REGEXP = /^\/([-a-zA-Z0-9@:%_\\+.~#?&//=]*)$/;
const PathPropType = exports.PathPropType = (0, _stringMatching.default)(PATH_REGEXP);
const SrcPropType = exports.SrcPropType = _propTypes.default.oneOfType([UrlPropType, PathPropType]);
const FilesPropType = (props, propName, componentName) => {
  const validFilesTypes = ['image/jpeg', 'image/png', 'image/svg+xml', 'image/*', 'application/pdf', 'application/zip', 'text/csv'];
  const propValue = props[propName];
  const filesTypes = (0, _split.default)(',', propValue);
  const isValid = (0, _isEmpty.default)((0, _head.default)(filesTypes)) || (0, _every.default)(type => (0, _includes.default)((0, _trim.default)(type), validFilesTypes), filesTypes);
  if (isValid) return null;
  return new Error(`Invalid prop value: ${propValue}, at component: ${componentName}. Expected a valid image type: image/jpeg, image/png, image/* image/svg+xml or application/pdf.`);
};
exports.FilesPropType = FilesPropType;
const ColorPropType = exports.ColorPropType = _color.default;
const HexPropType = exports.HexPropType = _hex.default;
//# sourceMappingURL=proptypes.js.map