<div tal:define="
       download_url view/download_url;
       exists python: view.value is not None;
       action view/action;
       allow_nochange view/allow_nochange;
       doc_type view/file_content_type;
       icon view/file_icon;
       filename view/filename;
     "
     tal:attributes="
       view/attributes;
     "
     i18n:domain="plone"
>
  <tal:if tal:define="
            up_id view/file_upload_id;
          "
          tal:condition="up_id"
  >
    <input name="${view/name}.file_upload_id"
           type="hidden"
           value="${up_id}"
    />
    <span>
      <tal:i18n i18n:translate="file_already_uploaded">File already uploaded:</tal:i18n>
        ${filename}
    </span>
  </tal:if>
  <span tal:condition="python:exists and download_url and action=='nochange'">
    <img alt="${doc_type}"
         src="${icon}"
         title="${filename}"
         tal:condition="icon"
    />
    <a href="${download_url}">${filename}</a>
    <span class="text-muted">
      &mdash;<tal:doc_type condition="doc_type">
        <span tal:replace="doc_type"
              i18n:translate=""
        >ContentType</span>,</tal:doc_type>
      ${view/file_size}
    </span>
  </span>
  <tal:block condition="allow_nochange">
    <div class="pat-checklist">
      <label>
        <input id="${view/id}-nochange"
               checked="${python:'checked' if action == 'nochange' else None}"
               name="${view/name}.action"
               onclick="document.getElementById('${view/id}-input').disabled=true;"
               type="radio"
               value="nochange"
        />
        <tal:i18n i18n:translate="file_keep">Keep existing file</tal:i18n>
      </label>
      <label tal:condition="not:view/field/required">
        <input id="${view/id}-remove"
               checked="${python:'checked' if action == 'remove' else None}"
               name="${view/name}.action"
               onclick="document.getElementById('${view/id}-input').disabled=true;"
               type="radio"
               value="remove"
        />
        <tal:i18n i18n:translate="file_remove">Remove existing file</tal:i18n>
      </label>
      <label>
        <input class="pat-depends"
               id="${view/id}-replace"
               checked="${python:'checked' if action == 'replace' else None}"
               name="${view/name}.action"
               onclick="document.getElementById('${view/id}-input').disabled=false"
               type="radio"
               value="replace"
        />
        <tal:i18n i18n:translate="file_replace">Replace with new file</tal:i18n>
      </label>
    </div>
  </tal:block>

  <input class="${python:view.error and 'is-invalid' or ''}"
         id="${view/id}-input"
         accept="${view/accept|nothing}"
         disabled="${view/disabled}"
         maxlength="${view/maxlength}"
         name="${view/name}"
         required="${python:view.required and 'required' or None}"
         size="${view/size}"
         type="file"
  />

</div>
