define('@cardstack/identitymind/components/kyc-form', ['exports', 'ember-concurrency', '@cardstack/identitymind/templates/components/kyc-form'], function (exports, _emberConcurrency, _kycForm) {
  'use strict';

  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  var testing = Ember.testing;


  var fields = {
    bfn: {
      name: "First Name",
      hint: "User's first name",
      required: true
    },
    bln: {
      name: "Last Name",
      hint: "User's last name",
      required: true
    },
    tea: {
      name: "Email Address",
      hint: "User's email address",
      type: "email",
      required: true
    },
    dob: {
      name: "Date of Birth",
      hint: "User's date of birth",
      type: "date",
      required: true
    },
    sco: {
      name: "Country of Citizenship",
      hint: "Country of which user is a citizen",
      type: 'country',
      required: true
    },
    bsn: {
      name: "Address",
      hint: "User's street address, including house number, street name, and apartment number",
      required: true
    },
    bz: {
      name: "Zip Code",
      hint: "User's zip code"
    },
    bc: {
      name: "City",
      hint: "User's city",
      required: true
    },
    bs: {
      name: "State / Province",
      hint: "User's state or province, use official postal state/region abbreviations whenever possible (e.g. CA for California)."
    },
    bco: {
      name: "Country",
      hint: "User's current country of residence",
      type: 'country',
      required: true
    }
  };

  var docUploadFields = {
    scanData: {
      name: 'Document Scan Front',
      hint: "Scan of front side of identity document",
      type: "file",
      required: true
    },
    backsideImageData: {
      name: "Document Scan Back",
      hint: "Scan of back side of identity document",
      type: "file"
    },
    faceImageData: {
      name: "Face Image",
      hint: "Picture of user's face with identity document in frame",
      type: "file",
      required: true
    }
  };

  exports.default = Ember.Component.extend({
    classNames: ['kyc-form'],
    store: Ember.inject.service(),
    router: Ember.inject.service(),
    cardstackSession: Ember.inject.service(),

    layout: _kycForm.default,
    fields: fields,
    docUploadFields: docUploadFields,
    didValidate: false,
    postSubmit: null,
    hasErrors: null,

    defaultFirstName: '',
    defaultLastName: '',
    defaultEmail: '',

    submitKyc: (0, _emberConcurrency.task)( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
      var model, _ref, validations, willSaveModel, postSubmit, hasErrors;

      return regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              model = this.get('model');
              _context.next = 3;
              return model.validate();

            case 3:
              _ref = _context.sent;
              validations = _ref.validations;


              this.set('didValidate', true);

              if (!validations.get('isValid')) {
                _context.next = 21;
                break;
              }

              this.set('submittingKyc', true);

              model.set('user', this.get('cardstackSession.user'));
              model.set('man', model.get('bfn') + ' ' + model.get('bln'));
              willSaveModel = this.get('willSaveModel');

              if (!(typeof willSaveModel === 'function')) {
                _context.next = 14;
                break;
              }

              _context.next = 14;
              return willSaveModel(model);

            case 14:
              _context.next = 16;
              return model.save();

            case 16:
              postSubmit = this.get('postSubmit');


              if (typeof postSubmit === 'function') {
                postSubmit();
              }

              this.set('submittingKyc', false);
              _context.next = 23;
              break;

            case 21:
              hasErrors = this.get('hasErrors');


              if (typeof hasErrors === 'function') {
                hasErrors();
              }

            case 23:
            case 'end':
              return _context.stop();
          }
        }
      }, _callee, this);
    })).drop(),

    assignFile: (0, _emberConcurrency.task)( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(field, event) {
      var file, reader, dataUri;
      return regeneratorRuntime.wrap(function _callee2$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              file = testing ? event.detail.testingFiles[0] : event.target.files[0];
              reader = new FileReader();
              _context2.next = 4;
              return new Ember.RSVP.Promise(function (resolve) {
                reader.addEventListener("load", function () {
                  resolve(reader.result);
                }, false);
                reader.readAsDataURL(file);
              });

            case 4:
              dataUri = _context2.sent;


              this.set('model.' + field, dataUri);

            case 6:
            case 'end':
              return _context2.stop();
          }
        }
      }, _callee2, this);
    })),

    init: function init() {
      this.model = this.get('store').createRecord('identitymind-verification');

      this.model.setProperties({
        bfn: this.get('defaultFirstName'),
        bln: this.get('defaultLastName'),
        tea: this.get('defaultEmail')
      });

      this._super.apply(this, arguments);
    }
  });
});