import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/esm/inherits";

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

import { Component, createElement } from 'react';
import { Shipping as ShippingComponent } from './component';
import { faTruck } from '@fortawesome/free-solid-svg-icons';
var assign = Object.assign;
export var Shipping =
/*#__PURE__*/
function (_Component) {
  _inherits(Shipping, _Component);

  function Shipping(props) {
    var _this;

    _classCallCheck(this, Shipping);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(Shipping).call(this, props));
    _this.state = void 0;

    _this.handleChange = function (field) {
      return function (event) {
        var data = assign({}, _this.state.data);

        if (event.currentTarget.type === 'checkbox') {
          var _ref = event.currentTarget,
              checked = _ref.checked;
          data[field].checked = checked;
        }

        if (event.currentTarget.type === 'radio') {
          data[field].active = event.currentTarget.value;
        }

        _this.setState({
          data: data
        });
      };
    };

    _this.handleGroupChange = function (group) {
      return function (field) {
        return function (event) {
          var value = event.currentTarget.value;
          var data = assign({}, _this.state.data);
          data[group][field]['value'] = value;

          _this.setState({
            data: data
          });
        };
      };
    };

    _this.handleSubmit = function (e) {
      _this.props.onFormSubmit(_this.state.data);
    };

    _this.handleValidGroupFieldChange = function (group) {
      return function (field) {
        return function (valid) {
          // TODO To know which field is valid which is not
          _this.setState({
            valid: valid
          });
        };
      };
    };

    var titles = props.titles;
    _this.state = {
      data: {
        distribution: {
          id: '01',
          active: undefined,
          radios: [{
            title: titles.distribution.home,
            icon: faTruck,
            id: '11'
          }, {
            title: titles.distribution.personal,
            icon: faTruck,
            id: '12'
          }]
        },
        invoicing: {
          forname: {
            id: 'forname1',
            label: titles.address.forename,
            value: '',
            placeholder: 'Denisa',
            messages: {
              valid: '',
              invalid: ''
            }
          },
          surname: {
            id: 'surname1',
            label: titles.address.surname,
            value: '',
            placeholder: 'Juna',
            messages: {
              valid: '',
              invalid: ''
            }
          },
          company: {
            id: 'company',
            label: titles.address.company,
            value: '',
            placeholder: 'Somethings LTD',
            messages: {
              valid: '',
              invalid: ''
            }
          },
          vat: {
            id: 'vat',
            label: 'VAT',
            value: '',
            placeholder: '12345',
            messages: {
              valid: '',
              invalid: ''
            }
          },
          street: {
            id: 'street1',
            label: titles.address.street,
            value: 'Street 1',
            placeholder: 'Your Street',
            messages: {
              valid: '',
              invalid: ''
            }
          },
          streetNo: {
            id: 'streetNo1',
            label: titles.address.streetNo,
            value: '5',
            placeholder: 'Your Number Street',
            messages: {
              valid: '',
              invalid: ''
            }
          },
          postcode: {
            id: 'postcode1',
            label: titles.address.postcode,
            value: '123 45',
            placeholder: '111 11',
            messages: {
              valid: '',
              invalid: ''
            }
          },
          cities: {
            id: 'city1',
            label: titles.address.city,
            value: '',
            options: [{
              id: 'prague',
              title: 'Prague',
              value: 'PRG'
            }]
          },
          countries: {
            id: 'country1',
            label: titles.address.country,
            value: '',
            options: [{
              id: 'czechRepublic',
              title: 'Czech Republic',
              value: 'CZ'
            }]
          }
        },
        delivery: {
          forname: {
            id: 'forname2',
            label: titles.address.forename,
            value: '',
            placeholder: 'Denisa',
            messages: {
              valid: '',
              invalid: ''
            }
          },
          surname: {
            id: 'surname2',
            label: titles.address.surname,
            value: '',
            placeholder: 'Juna',
            messages: {
              valid: '',
              invalid: ''
            }
          },
          street: {
            id: 'street2',
            label: titles.address.street,
            value: 'Street 2',
            placeholder: 'Your Street',
            messages: {
              valid: '',
              invalid: ''
            }
          },
          streetNo: {
            id: 'streetNo2',
            label: titles.address.streetNo,
            value: '5',
            placeholder: 'Your Number Street',
            messages: {
              valid: '',
              invalid: ''
            }
          },
          postcode: {
            id: 'postcode2',
            label: titles.address.postcode,
            value: '123 45',
            placeholder: '111 11',
            messages: {
              valid: '',
              invalid: ''
            }
          },
          cities: {
            id: 'city2',
            label: titles.address.city,
            value: '',
            options: [{
              id: 'prague',
              title: 'Prague',
              value: 'PRG'
            }]
          },
          countries: {
            id: 'country2',
            label: titles.address.country,
            value: '',
            options: [{
              id: 'czechRepublic',
              title: 'Czech Republic',
              value: 'CZ'
            }]
          }
        },
        terms: {
          checked: false,
          id: 'terms',
          title: titles.terms
        },
        data: {
          checked: false,
          id: 'data',
          title: titles.data
        }
      },
      valid: false
    };
    return _this;
  }

  _createClass(Shipping, [{
    key: "render",
    value: function render() {
      var props = _objectSpread({}, this.state.data, {
        onGroupChange: this.handleGroupChange,
        onFieldChange: this.handleChange,
        onSubmit: this.handleSubmit,
        onValidGroupFieldChange: this.handleValidGroupFieldChange,
        valid: this.state.valid
      });

      return createElement(ShippingComponent, props);
    }
  }]);

  return Shipping;
}(Component);