"use strict";

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

var _toConsumableArray2 = require("babel-runtime/helpers/toConsumableArray");

var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);

var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require("babel-runtime/helpers/createClass");

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn");

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require("babel-runtime/helpers/inherits");

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require("react");

var _react2 = _interopRequireDefault(_react);

var _fdx = require("@whalecloud/fdx");

require("./index.less");

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

var SkuFilter = function (_Component) {
    (0, _inherits3["default"])(SkuFilter, _Component);

    function SkuFilter() {
        (0, _classCallCheck3["default"])(this, SkuFilter);
        return (0, _possibleConstructorReturn3["default"])(this, (SkuFilter.__proto__ || Object.getPrototypeOf(SkuFilter)).apply(this, arguments));
    }

    (0, _createClass3["default"])(SkuFilter, [{
        key: "removeCondition",
        value: function removeCondition(item) {
            var _props = this.props,
                onRemove = _props.onRemove,
                conditions = _props.conditions;

            var newDatas = conditions.filter(function (el) {
                return el.id !== item.id;
            });
            onRemove && onRemove([].concat((0, _toConsumableArray3["default"])(newDatas)), item);
        }
    }, {
        key: "clearAll",
        value: function clearAll() {
            this.props.onClear && this.props.onClear();
        }
    }, {
        key: "render",
        value: function render() {
            var _this2 = this;

            var _props2 = this.props,
                conditions = _props2.conditions,
                label = _props2.label,
                clearBtnLabel = _props2.clearBtnLabel;

            var hasConditions = conditions && conditions.length > 0;
            var template = _react2["default"].createElement("div", null);
            if (hasConditions) {
                template = _react2["default"].createElement(
                    _fdx.Row,
                    { className: "sku-filter" },
                    _react2["default"].createElement(
                        _fdx.Col,
                        null,
                        _react2["default"].createElement(
                            _fdx.Row,
                            null,
                            _react2["default"].createElement(
                                _fdx.Col,
                                null,
                                _react2["default"].createElement(
                                    "div",
                                    { className: "filter-container" },
                                    _react2["default"].createElement(
                                        _fdx.Row,
                                        null,
                                        _react2["default"].createElement(
                                            _fdx.Col,
                                            { className: "label-container" },
                                            _react2["default"].createElement(
                                                "span",
                                                null,
                                                label
                                            )
                                        ),
                                        _react2["default"].createElement(
                                            _fdx.Col,
                                            { span: 20 },
                                            conditions.map(function (item) {
                                                return _react2["default"].createElement(
                                                    "div",
                                                    { className: "tag-container", key: item.id },
                                                    _react2["default"].createElement(
                                                        _fdx.Tag,
                                                        { closable: true, visible: true, onClose: function onClose() {
                                                                _this2.removeCondition(item);
                                                            } },
                                                        item.label
                                                    )
                                                );
                                            }),
                                            _react2["default"].createElement(
                                                "span",
                                                { className: "clear-all-text", onClick: function onClick() {
                                                        _this2.clearAll();
                                                    } },
                                                clearBtnLabel
                                            )
                                        )
                                    )
                                )
                            )
                        )
                    )
                );
            }
            return template;
        }
    }]);
    return SkuFilter;
}(_react.Component);

exports["default"] = SkuFilter;

SkuFilter.defaultProps = {
    label: "Filtered By:",
    clearBtnLabel: "Clear All"
};
module.exports = exports['default'];