import DefineMap from 'can-define/map/map';
import Base from 'spectre-canjs/util/field/Field';
import parseFieldArray from 'spectre-canjs/util/field/parseFieldArray/parseFieldArray';
import mapToFields from 'spectre-canjs/util/field/mapToFields/mapToFields';

/** 
 * A <sp-subform-field /> component's ViewModel
 * @class ViewModel
 * @extends Field
 * @memberof sp-subform-field
 *
 */
export default Base.extend('SubformField', {
    /** @lends sp-subform-field.ViewModel.prototype */
    /**
     * The current value of the field. This is a json serialized value
     * paths.
     * @type {String}
     * @memberof sp-subform-field.ViewModel.prototype
     */
    value: {
        Value: DefineMap,
        Type: DefineMap,
        set (val) {
            if (this.value !== val) {
                this.dispatch('fieldchange', [{
                    value: val,
                    name: this.name
                }]);
            }
            return val;
        }
    },
    /**
     * The field properties to set up the form fields functionality, this is
     * set up automatically from the `fields` property or the `subobject`
     * if `fields` is not provided.
     * @type {Array<Field>}
     * @memberof sp-subform-field.ViewModel.prototype
     */
    formFields: {
        get () {
            if (this.fields && this.fields.length) {
                return parseFieldArray(this.fields);
            }
            return mapToFields(this.Type);
        }
    },
    /**
     * Called whenever a field changes its value to update this form's json
     * string value. Dispatches the `fieldchange` event with the serialized form object
     * @param  {Array} args the arguments dispatched from the event
     */
    saveField (args) {
        const [props] = args;
        this.value.assign(props.dirty.get());
        this.dispatch('fieldchange', [this]);
    }
});
@@ -972,32 +972,323 @@
 %0A    %7D,%0A    /**%0A
+     * An alternative property to using Type. Since Type is a DefineMap keyword, %0A     * subType is provided to allow for customizability between the field and%0A     * the map%0A     * @type %7BConstructor%7D %0A     * @memberof sp-subform-field.ViewModel.prototype%0A     */%0A    subType: '*',%0A    /**%0A
      * The field
@@ -1694,32 +1694,85 @@
 );%0A            %7D
+%0A%0A            const type = this.subType %7C%7C this.Type;
 %0A            ret
@@ -1788,21 +1788,16 @@
 Fields(t
-his.T
 ype);%0A  

add subType to subform-field as alternative to "Type"