'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _export = require('../../components/style/export');

var _sharedPropertyStyle = require('./shared-property-style');

var _sharedPropertyStyle2 = _interopRequireDefault(_sharedPropertyStyle);

var _md = require('react-icons/md');

var _browser = require('../../utils/browser');

var _uploadApi = require('../../utils/uploadApi');

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

function PropertyImage(_ref) {
  var value = _ref.value,
      onUpdate = _ref.onUpdate,
      configs = _ref.configs,
      sourceElement = _ref.sourceElement,
      internalState = _ref.internalState,
      state = _ref.state;


  var loadFloorPlanFromFile = function loadFloorPlanFromFile(event) {

    event.stopPropagation();
    (0, _browser.browserImageUpload)().then(function (data) {
      // const extname = path.resolve( data );
      // if(data.type.includes('image'))
      //   update(data.name)     

      console.log("dadta : ", data);

      _uploadApi.FileUploader.uploadFile('', data, function (res) {
        console.log("response : ", res);
      });
    });
  };

  var update = function update(val) {

    if (configs.hook) {
      return configs.hook(val, sourceElement, internalState, state).then(function (_val) {
        return onUpdate(_val);
      });
    }

    return onUpdate(val);
  };

  return _react2.default.createElement(
    'table',
    { className: 'PropertyImage', style: _sharedPropertyStyle2.default.tableStyle },
    _react2.default.createElement(
      'tbody',
      null,
      _react2.default.createElement(
        'tr',
        null,
        _react2.default.createElement(
          'td',
          { style: _sharedPropertyStyle2.default.firstTdStyle },
          _react2.default.createElement(
            _export.FormLabel,
            null,
            configs.label
          )
        ),
        _react2.default.createElement(
          'td',
          null,
          _react2.default.createElement(_export.FormTextInput, {
            value: value,
            onChange: function onChange(event) {
              return update(event.target.value);
            }
          })
        ),
        _react2.default.createElement(
          'td',
          null,
          _react2.default.createElement(
            'button',
            { onClick: loadFloorPlanFromFile, style: { marginTop: 6 } },
            _react2.default.createElement(_md.MdFileUpload, null)
          )
        )
      )
    )
  );
}

PropertyImage.propTypes = {
  value: _propTypes2.default.any.isRequired,
  onUpdate: _propTypes2.default.func.isRequired,
  configs: _propTypes2.default.object.isRequired,
  sourceElement: _propTypes2.default.object,
  internalState: _propTypes2.default.object,
  state: _propTypes2.default.object.isRequired
};