"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.CLASSNAME_SEARCH_ICON = void 0;

var _react = _interopRequireDefault(require("react"));

var _propTypes = require("prop-types");

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _reduxForm = require("redux-form");

var _styles = require("@vincent_za/styles");

var _assets = require("@vincent_za/assets");

var _form = require("../../form");

var _component = _interopRequireDefault(require("../../Svg/component"));

var _component2 = require("../component");

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

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _templateObject4() {
  var data = _taggedTemplateLiteral(["\n  padding: 0 !important;\n  padding-bottom: ", " !important;\n  width: 10.4rem;\n  height: 1.5rem;\n  color: ", ";\n  background-color: transparent;\n"]);

  _templateObject4 = function _templateObject4() {
    return data;
  };

  return data;
}

function _templateObject3() {
  var data = _taggedTemplateLiteral(["\n  display: ", ";\n  margin-right: ", ";\n"]);

  _templateObject3 = function _templateObject3() {
    return data;
  };

  return data;
}

function _templateObject2() {
  var data = _taggedTemplateLiteral(["\n  display: block;\n  width: 1.4rem;\n  height: 1.4rem;\n\n  svg {\n    fill: ", ";\n\n    &:hover {\n      fill: ", ";\n    };\n  };\n"]);

  _templateObject2 = function _templateObject2() {
    return data;
  };

  return data;
}

function _templateObject() {
  var data = _taggedTemplateLiteral([""]);

  _templateObject = function _templateObject() {
    return data;
  };

  return data;
}

function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }

var CLASSNAME_SEARCH_ICON = 'field';
exports.CLASSNAME_SEARCH_ICON = CLASSNAME_SEARCH_ICON;

var FieldLabel = _styledComponents.default.label(_templateObject());

var SearchSvg = (0, _styledComponents.default)(_component.default)(_templateObject2(), function (props) {
  return props.isOpen ? _styles.GRAY_X11 : _styles.SONIC_SILVER;
}, _styles.GRAY_X11);

var FieldWrap = _styledComponents.default.div(_templateObject3(), function (props) {
  return props.isOpen ? 'flex' : 'none';
}, _styles.REM_UNIT_SM);

var TextFieldStyled = (0, _styledComponents.default)(_form.TextField)(_templateObject4(), _styles.REM_UNIT_XSM, _styles.GRAY_X11);

var TableSearch =
/*#__PURE__*/
function (_React$PureComponent) {
  _inherits(TableSearch, _React$PureComponent);

  function TableSearch(props) {
    var _this;

    _classCallCheck(this, TableSearch);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(TableSearch).call(this, props));

    _defineProperty(_assertThisInitialized(_this), "onSearchToggle", function () {
      _this.setState({
        isOpen: !_this.state.isOpen
      });
    });

    _this.state = {
      isOpen: false
    };
    return _this;
  }

  _createClass(TableSearch, [{
    key: "componentWillUnmount",
    value: function componentWillUnmount() {
      this.props.onSearchReset({
        searchQuery: ''
      });
    }
  }, {
    key: "render",
    value: function render() {
      var isOpen = this.state.isOpen;
      var _this$props = this.props,
          isVisible = _this$props.isVisible,
          fieldName = _this$props.fieldName,
          handleChange = _this$props.handleChange,
          className = _this$props.className;
      return _react.default.createElement(_component2.PageSectionActionWrap, {
        isVisible: isVisible,
        onChange: handleChange,
        className: className
      }, _react.default.createElement(FieldWrap, {
        isOpen: isOpen
      }, _react.default.createElement(_reduxForm.Field, {
        name: fieldName,
        component: TextFieldStyled,
        id: fieldName
      })), _react.default.createElement(FieldLabel, {
        htmlFor: fieldName,
        onClick: this.onSearchToggle
      }, _react.default.createElement(SearchSvg, {
        svg: _assets.searchSvg,
        isOpen: isOpen,
        className: CLASSNAME_SEARCH_ICON
      })));
    }
  }]);

  return TableSearch;
}(_react.default.PureComponent);

TableSearch.propTypes = {
  isVisible: _propTypes.bool,
  fieldName: _propTypes.string.isRequired,
  onSearchReset: _propTypes.func,
  handleChange: _propTypes.func,
  className: _propTypes.string
};
TableSearch.defaultProps = {
  isVisible: true,
  onSearchReset: function onSearchReset() {},
  handleChange: function handleChange() {},
  className: undefined
};

var _default = (0, _reduxForm.reduxForm)()(TableSearch);

exports.default = _default;