<%_ const valueVar = inArray ? 'item' : 'value'; %>
<%_ if (!property.type) { _%>
  <%_ if (property.constant) { _%>
  <p><%= property.constant %></p>
  <%_ } _%>
<%_ } else { _%>
  <GoAFormItem mb="m" label="<%= property.title || key %>" helpText="<%= property.description %>">
  <%_ switch(property.type) { 
    case 'string': _%>
    <%_ if (property.enum) { _%>
      <GoADropdown 
        name="<%= key %>"
        disabled={isReadOnly || inReview}
        onChange={(name,updated) => <%- inArray ? `onArrayItemChange(onChange, value, '${parent}', idx, ` : 'onChange(' %>{ ...<%= valueVar %>, [name]: updated })}
        value={`${<%= valueVar %>.<%= key %> || ''}`}
      >
        <%_ property.enum.forEach((enumValue) => { _%>
          <GoADropdownItem value="<%= enumValue %>" label="<%= enumValue %>" />
        <%_ }); _%>
      </GoADropdown>
    <%_ } else { _%>
      <%_ switch(property.format) { 
        case 'date-time': _%>
        <GoAInputDateTime
          name="<%= key %>"
          disabled={isReadOnly || inReview}
          value={<%= valueVar %>.<%= key %> ? new Date(<%= valueVar %>.<%= key %> as string) : null}
          onChange={(name, updated) => <%- inArray ? `onArrayItemChange(onChange, value, '${parent}', idx, ` : 'onChange(' %>{ ...<%= valueVar %>, [name]: (updated as Date)?.toISOString() })}
        />
      <%_ break;
        case 'date': _%>
        <GoAInputDate
          name="<%= key %>"
          disabled={isReadOnly || inReview}
          value={<%= valueVar %>.<%= key %> ? new Date(<%= valueVar %>.<%= key %> as string) : null}
          onChange={(name, updated) => <%- inArray ? `onArrayItemChange(onChange, value, '${parent}', idx, ` : 'onChange(' %>{ ...<%= valueVar %>, [name]: (updated as Date)?.toISOString() })}
        />
      <%_ break;
        case 'time': _%>
        <GoAInputTime
          name="<%= key %>"
          step={1}
          disabled={isReadOnly || inReview}
          value={<%= valueVar %>.<%= key %> ? new Date(<%= valueVar %>.<%= key %> as string) : null}
          onChange={(name, updated) => <%- inArray ? `onArrayItemChange(onChange, value, '${parent}', idx, ` : 'onChange(' %>{ ...<%= valueVar %>, [name]: (updated as Date)?.toISOString() })}
        />
      <%_ break;
        case 'uri': _%>
        <% if (!inArray) { %>
          {files['<%= key %>'] ? (
            isReadOnly || inReview ? (
              <FormFile property="<%= key %>" file={files['<%= key %>']} />
            ) : (
              <GoAFileUploadCard
                filename={files['<%= key %>'].filename}
                size={files['<%= key %>'].size}
                progress={files['<%= key %>'].progress}
                onDelete={() => onFileChange('<%= key %>', files['<%= key %>'])}
              />
            )
          ) : (
            !isReadOnly &&
            !inReview && (
              <GoAFileUploadInput
                variant="dragdrop"
                onSelectFile={(file) =>
                  onFileChange('<%= key %>', files['<%= key %>'], file)
                }
              />
            )
          )}
        <% } %>
      <%_ break;
        default: _%>
        <% if (property.maxLength > 100) { %>
          <GoATextArea
            disabled={isReadOnly || inReview}
            error={errors[`<%= path %>`]}
            placeholder="<%= property?.examples?.join(', ') || '' %>"
            onChange={(name, updated) => <%- inArray ? `onArrayItemChange(onChange, value, '${parent}', idx, ` : 'onChange(' %>{ ...<%= valueVar %>, [name]: updated })}
            value={`${<%= valueVar %>.<%= key %> || ''}`}
            name="<%= key %>"
          />
        <% } else { %>
          <GoAInput
            type="text"
            disabled={isReadOnly || inReview}
            error={errors[`<%= path %>`]}
            placeholder="<%= property?.examples?.join(', ') || '' %>"
            <%_ if (property?.maxLength !== undefined) { _%>
              maxLength={<%= property?.maxLength %>}
            <%_ } _%>
            onChange={(name, updated) => <%- inArray ? `onArrayItemChange(onChange, value, '${parent}', idx, ` : 'onChange(' %>{ ...<%= valueVar %>, [name]: updated })}
            value={`${<%= valueVar %>.<%= key %> || ''}`}
            name="<%= key %>"
          />
        <% } %>
      <%_ break;
        } _%>
    <%_ } _%>
  <%_ break;
    case 'integer':
    case 'number': _%>
    <GoAInput
      type="number"
      disabled={isReadOnly || inReview}
      error={errors[`<%= path %>`]}
      placeholder="<%= property?.examples || []%>"
      onChange={(name, updated) => <%- inArray ? `onArrayItemChange(onChange, value, '${parent}', idx, ` : 'onChange(' %>{ ...<%= valueVar %>, [name]: parseFloat(updated) })}
      value={`${<%= valueVar %>.<%= key %> || ''}`}
      name="<%= key %>"
      <%_ if (property?.maximum !== undefined) { _%>
        max={<%= property.maximum %>}
      <%_ } _%>
      <%_ if (property?.minimum !== undefined) { _%>
        min={<%= property.minimum %>}
      <%_ } _%>
      <%_ if (property?.multipleOf !== undefined) { _%>
        step={<%= property.multipleOf %>}
      <%_ } _%>
    />
  <%_ break;
    case 'boolean': _%>
    <GoACheckbox
      disabled={isReadOnly || inReview}
      checked={<%= valueVar %>.<%= key %> as any || false}
      onChange={(name, updated) => <%- inArray ? `onArrayItemChange(onChange, value, '${parent}', idx, ` : 'onChange(' %>{ ...<%= valueVar %>, [name]: updated })}          
      name="<%= key %>"
    />
  <%_ break;
    case 'array': _%>
    <% if (!inArray && property.items?.type === 'object') { %>
      <fieldset>
        <legend><%= property.items.title || key %></legend>
        <p><%= property.items.description %></p>
        {(<%= valueVar %>.<%= key %> as Record<string, unknown>[])?.map((item, idx) => (
          <div key={idx}>
            <% Object.entries(property.items.properties || {}).map(([key, property]) => { %>
              <%- include(`${includesPath}/input-template.ejs`, {key, property, parent: path, path: path + ".[${idx}]." + key, inArray: true, includesPath}); %>
            <% }); %>
            {!inReview && <GoAButtonGroup alignment="end">
              <GoAButton
                disabled={isReadOnly}
                type="tertiary"
                onClick={() => {
                  const update = [...(<%= valueVar %>.<%= key %> as [] || [])];
                  update.splice(idx, 1);
                  <%- inArray ? `onArrayItemChange(onChange, value, '${parent}', idx, ` : 'onChange(' %>{ ...<%= valueVar %>, <%= key %>: update })
                }}
              >
                Remove
              </GoAButton>
            </GoAButtonGroup>}
            <GoADivider mb="l" />
          </div>
        ))}
        {!inReview && <GoAButtonGroup alignment="end">
          <GoAButton
            disabled={isReadOnly}
            type="tertiary"
            onClick={() =>
              <%- inArray ? `onArrayItemChange(onChange, value, '${parent}', idx, ` : 'onChange(' %>{ ...<%= valueVar %>, <%= key %>: [...(<%= valueVar %>.<%= key %> as [] || []), {}] })
            }
          >
            Add
          </GoAButton>
        </GoAButtonGroup>}
      </fieldset>
    <% } %>
  <%_ break;
    default:
    break; _%>
  <%_ } _%>
  </GoAFormItem>
<%_ } _%>
