'use strict';

exports.__esModule = true;

var _ramda = require('ramda');

var _ramda2 = _interopRequireDefault(_ramda);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _repeat = require('lodash/repeat');

var _repeat2 = _interopRequireDefault(_repeat);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var unsplashURLForKeywords = _ramda2.default.pipe(_ramda2.default.ifElse(_ramda2.default.is(String), function (keywords) {
	return '/800x600?' + keywords;
}, _ramda2.default.always('/800x600?')), _ramda2.default.concat('https://source.unsplash.com'));

var UnsplashImage = _react2.default.createClass({
	displayName: 'UnsplashImage',
	getInitialState: function getInitialState() {
		return {
			refreshCount: 0
		};
	},
	onRefresh: function onRefresh() {
		this.setState(function (_ref) {
			var refreshCount = _ref.refreshCount;
			return {
				refreshCount: refreshCount + 1
			};
		});
	},
	render: function render() {
		var _props = this.props,
		    category = _props.category,
		    text = _props.text;
		var refreshCount = this.state.refreshCount;

		var url = '' + unsplashURLForKeywords(category) + (0, _repeat2.default)(',', refreshCount);
		return _react2.default.createElement('img', { key: refreshCount, src: url, alt: text,
			style: { width: '100%', height: 'auto' },
			onClick: this.onRefresh
		});
	}
});

exports.default = UnsplashImage;
module.exports = exports['default'];