export default async function initCloudrainSow() {
  function debounce(fn, delay) {
    let timer;
    return (...args) => {
      // 判断定时器是否存在，清除定时器
      if (timer) {
        clearTimeout(timer);
      }

      // 重新调用setTimeout
      timer = setTimeout(() => {
        fn.apply(this, args);
      }, delay);
    };
  }

  function paddingZeros(str, len) {
    str = str.toString();
    if (str.length < len) {
      str = new Array(len - str.length).fill('0').join('') + str;
    }
    return str;
  }

  function timeFormat(date) {
    return `${date.getFullYear()}-${paddingZeros(date.getMonth() + 1, 2)}-${paddingZeros(date.getDate(), 2)} ${paddingZeros(date.getHours(), 2)}:${paddingZeros(date.getMinutes(), 2)}:${paddingZeros(date.getSeconds(), 2)}`;
  }

  function logScroll(version_name, repoPath, ID, max = "", lines = 60) {
    let container = document.querySelector(`#log${max}${version_name}`);
    let scrollTop = container.scrollTop;
    let scrollHeight = container.scrollHeight;
    let clientHeight = container.clientHeight;
    let scrollLeft = container.scrollLeft;
    if (
      (parseInt(scrollTop) + clientHeight == scrollHeight ||
        parseInt(scrollTop) + clientHeight + 1 == scrollHeight ||
        parseInt(scrollTop) + clientHeight - 1 == scrollHeight) &&
      scrollLeft === 0
    ) {
      let end_line = $(`#log${version_name} input[name=end_line${max}]`).val();
      $(`#log${max}${version_name} .ui.inverted.active.dimmer`).css({
        "background-color": "#fff",
        display: "block",
      });
      $.get(
        `/api/v1/repos/${repoPath}/${ID}/log?version_name=${version_name}&base_line=${end_line}&lines=${lines}&order=desc`,
        (data) => {
          $(`#log${max}${version_name} .ui.inverted.active.dimmer`).css(
            "display",
            "none"
          );
          if (data.Lines == 0) {
            if (max) {
              $("body").toast({
                class: "black",
                message: i18n.scrolled_logs_bottom_pls_retry,
              });
            } else {
              $(`.message${version_name} #header`).text(i18n.scrolled_logs_bottom);
              $(`.message${version_name}`).css("display", "block");
              setTimeout(function () {
                $(`.message${version_name}`).css("display", "none");
              }, 1000);
            }
          } else {
            if (end_line === data.EndLine) {
              return;
            } else {
              $(`#log${version_name} input[name=end_line${max}]`).val(
                data.EndLine
              );
              $(`#log${max}${version_name}`).append("<pre>" + data.Content);
            }
          }
        }
      ).fail(function (err) {
        $(`#log${max}${version_name} .ui.inverted.active.dimmer`).css(
          "display",
          "none"
        );
        console.log(err);
      });
    }
    if (scrollTop == 0 && scrollLeft == 0) {
      let start_line = $(
        `#log${version_name} input[name=start_line${max}]`
      ).val();
      $(`#log${max}${version_name} .ui.inverted.active.dimmer`).css({
        "background-color": "#fff",
        display: "block",
      });
      $.get(
        `/api/v1/repos/${repoPath}/${ID}/log?version_name=${version_name}&base_line=${start_line}&lines=${lines}&order=asc`,
        (data) => {
          $(`#log${max}${version_name} .ui.inverted.active.dimmer`).css(
            "display",
            "none"
          );
          if (data.Lines == 0) {
            if (max) {
              $("body").toast({
                class: "black",
                message: i18n.scrolled_logs_top_pls_retry,
              });
            } else {
              $(`.message${version_name} #header`).text(i18n.scrolled_logs_top);
              $(`.message${version_name}`).css("display", "block");
              setTimeout(function () {
                $(`.message${version_name}`).css("display", "none");
              }, 1000);
            }
          } else {
            $(`#log${version_name} input[name=start_line${max}]`).val(
              data.StartLine
            ); //如果变动就改变所对应的值
            $(`#log${max}${version_name}`).prepend("<pre>" + data.Content);
          }
        }
      ).fail(function (err) {
        $(`#log${max}${version_name} .ui.inverted.active.dimmer`).css(
          "display",
          "none"
        );
        console.log(err);
      });
    }
  }
  const fn = debounce(logScroll, 500);
  $(".log-scroll").scroll(function () {
    let version_name = $(this).data("version");
    let ID = $(`#accordion${version_name}`).data("jobid");
    let repoPath = $(`#accordion${version_name}`).data("repopath");
    fn(version_name, repoPath, ID);
  });
  function scrollAnimation(dom, currentY, targetY, currentX) {
    let needScrollTop = targetY - currentY;
    let _currentY = currentY;
    setTimeout(() => {
      // 一次调用滑动帧数，每次调用会不一样
      //取总距离的十分之一
      const dist = Math.ceil(needScrollTop / 10);
      _currentY += dist;
      //移动一个十分之一
      dom.scrollTo(currentX || 0, _currentY, "smooth");
      // 如果移动幅度小于十个像素，直接移动，否则递归调用，实现动画效果
      if (needScrollTop > 10 || needScrollTop < -10) {
        scrollAnimation(dom, _currentY, targetY);
      } else {
        dom.scrollTo(0, targetY, "smooth");
      }
    }, 1);
  }

  function logTop(e) {
    let max = e.currentTarget.getAttribute("data-max") || "";
    let lines = !!max ? 100 : 60;
    let version_name = $(this).data("version");
    let logContentDom = document.querySelector(`#log${max}${version_name}`);
    let ID = $(`#accordion${version_name}`).data("jobid");
    let repoPath = $(`#accordion${version_name}`).data("repopath");
    let start_line = $(`#log${version_name} input[name=end_line${max}]`).val();
    $(`#log_file${max}${version_name}`).siblings("pre").remove();
    $(`#log${max}${version_name} .ui.inverted.active.dimmer`).css({
      "background-color": "#fff",
      display: "block",
    });
    $.get(
      `/api/v1/repos/${repoPath}/${ID}/log?version_name=${version_name}&base_line=&lines=${lines}&order=asc`,
      (data) => {
        $(`#log${max}${version_name} .ui.inverted.active.dimmer`).css(
          "display",
          "none"
        );
        $(`#log${version_name} input[name=end_line${max}]`).val(data.EndLine); //如果变动就改变所对应的值
        $(`#log${version_name} input[name=start_line${max}]`).val(
          data.StartLine
        );
        $(`#log${max}${version_name}`).prepend("<pre>" + data.Content);
        if (data.Lines == 0) {
          if (max) {
            $("body").toast({
              class: "black",
              message: i18n.scrolled_logs_top_pls_retry,
            });
          } else {
            $(`.message${version_name} #header`).text(i18n.scrolled_logs_top);
            $(`.message${version_name}`).css("display", "block");
            setTimeout(function () {
              $(`.message${version_name}`).css("display", "none");
            }, 1000);
          }
        }
        $.get(
          `/api/v1/repos/${repoPath}/${ID}/log?version_name=${version_name}&base_line=${data.StartLine}&lines=${lines}&order=asc`,
          (data) => {
            $(`#log${max}${version_name} .ui.inverted.active.dimmer`).css(
              "display",
              "none"
            );
            if (data.Lines == 0) {
              if (max) {
                $("body").toast({
                  class: "black",
                  message: i18n.scrolled_logs_top_pls_retry,
                });
              } else {
                $(`.message${version_name} #header`).text(i18n.scrolled_logs_top);
                $(`.message${version_name}`).css("display", "block");
                setTimeout(function () {
                  $(`.message${version_name}`).css("display", "none");
                }, 1000);
              }
            } else {
              if (start_line === data.StartLine || start_line === "") {
                return;
              } else {
                $(`#log${version_name} input[name=start_line${max}]`).val(
                  data.StartLine
                );
                $(`#log${max}${version_name}`).prepend("<pre>" + data.Content);
              }
            }
          }
        ).fail(function (err) {
          $(`#log${max}${version_name} .ui.inverted.active.dimmer`).css(
            "display",
            "none"
          );
          console.log(err);
        });
        scrollAnimation(logContentDom, logContentDom.scrollTop, 10);
      }
    ).fail((err) => {
      $(`#log${max}${version_name} .ui.inverted.active.dimmer`).css(
        "display",
        "none"
      );
      throw err;
    });
  }
  function logBottom(e) {
    let max = e.currentTarget.getAttribute("data-max") || "";
    let lines = !!max ? 100 : 60;
    let version_name = $(this).data("version");
    let logContentDom = document.querySelector(`#log${max}${version_name}`);
    let ID = $(`#accordion${version_name}`).data("jobid");
    let repoPath = $(`#accordion${version_name}`).data("repopath");
    $(`#log_file${max}${version_name}`).siblings("pre").remove();
    let end_line = $(`#log${version_name} input[name=end_line${max}]`).val();
    $(`#log${max}${version_name} .ui.inverted.active.dimmer`).css({
      "background-color": "#fff",
      display: "block",
    });
    $.get(
      `/api/v1/repos/${repoPath}/${ID}/log?version_name=${version_name}&base_line=&lines=${lines}&order=desc`,
      (data) => {
        $(`#log${max}${version_name} .ui.inverted.active.dimmer`).css(
          "display",
          "none"
        );
        if (!data.CanLogDownload) {
          $(`#${version_name}-log-down`)
            .removeClass("ti-download-file")
            .addClass("disabled");
          $(`.max-full-log${version_name} #${version_name}-log-down`)
            .removeClass("ti-download-file")
            .addClass("disabled");
        } else {
          $(`#${version_name}-log-down`)
            .addClass("ti-download-file")
            .removeClass("disabled");
          $(`.max-full-log${version_name} #${version_name}-log-down`)
            .addClass("ti-download-file")
            .removeClass("disabled");
        }
        $(`#log${version_name} input[name=end_line${max}]`).val(data.EndLine); //如果变动就改变所对应的值
        if ($(this)[0].hasAttribute("data-tab")) {
          $(`#log${version_name} input[name=end_line-max]`).val(data.EndLine);
          $(`#log${version_name} input[name=start_line-max]`).val(
            data.StartLine
          );
          $(`#log${version_name} input[name=start_line-max-copy]`).val(
            data.StartLine
          );
        }
        $(`#log${version_name} input[name=start_line${max}]`).val(
          data.StartLine
        );
        $(`#log${max}${version_name}`).append("<pre>" + data.Content);
        $.get(
          `/api/v1/repos/${repoPath}/${ID}/log?version_name=${version_name}&base_line=${data.EndLine}&lines=${lines}&order=desc`,
          (data) => {
            $(`#log${max}${version_name} .ui.inverted.active.dimmer`).css(
              "display",
              "none"
            );
            if (data.Lines == 0) {
              if (max) {
                $("body").toast({
                  class: "black",
                  message: i18n.scrolled_logs_bottom_pls_retry,
                });
              } else {
                $(`.message${version_name} #header`).text(i18n.scrolled_logs_bottom);
                $(`.message${version_name}`).css("display", "block");
                setTimeout(function () {
                  $(`.message${version_name}`).css("display", "none");
                }, 1000);
              }
            } else {
              if (end_line === data.EndLine || end_line === "") {
                return;
              } else {
                $(`#log${version_name} input[name=end_line${max}]`).val(
                  data.EndLine
                );
                if ($(this)[0].hasAttribute("data-tab")) {
                  $(`#log${version_name} input[name=end_line-max]`).val(
                    data.EndLine
                  );
                }
                $(`#log${max}${version_name}`).append("<pre>" + data.Content);
              }
            }
          }
        ).fail(function (err) {
          $(`#log${max}${version_name} .ui.inverted.active.dimmer`).css(
            "display",
            "none"
          );
          console.log(err);
        });

        let test = $(`#log_file${version_name}`).nextAll();
        test.length !== 0 &&
          $(`#log${version_name} input[name=init_log]`).val(test[0].innerHTML);

        scrollAnimation(
          logContentDom,
          logContentDom.scrollTop + 1,
          logContentDom.scrollHeight - logContentDom.clientHeight - 10
        );
      }
    ).fail((err) => {
      $(`#log${max}${version_name} .ui.inverted.active.dimmer`).css(
        "display",
        "none"
      );
      throw err;
    });
  }
  $(".log_top").click(logTop);
  $(".log_bottom").click(logBottom);

  // $(".log-scroll-max").scroll();

  $(".full-log-dialog").click(function () {
    let version_name = $(this).data("version");
    let log_type = $(this).data("log-type") || "";
    let logContentDom = document.querySelector(`#log-max${version_name}`);
    $(`.ui.modal.max-full-log${version_name}`)
      .modal({
        closable: false,
        onShow: function () {
          $(".ui.dimmer.modals").css({
            "background-color": "rgb(136, 136, 136,0.7)",
          });
          $(".log-scroll-max .ui.inverted.active.dimmer").css(
            "display",
            "none"
          );
          $(".file-info #log-file-title").text(
            $(".full-log-dialog").data("log")
          );
          $(".file-info #log-file-exit").text(
            $(".full-log-dialog").data("exit")
          );
          $(".file-info .log-file-down").text(
            $(".full-log-dialog").data("log-down")
          );
          $(".file-info .log-file-down").text(
            $(".full-log-dialog").data("log-down")
          );
          $(`.max-full-log${version_name} #${version_name}-log-down`).attr(
            "href",
            $(".full-log-dialog").data("href")
          );
          $(`.max-full-log${version_name} .log_top-max`).attr(
            "title",
            $(".full-log-dialog").data("scroll-top")
          );
          $(`.max-full-log${version_name} .log_bottom-max`).attr(
            "title",
            $(".full-log-dialog").data("scroll-bottom")
          );
        },
        onVisible: function () {
          $(`#log-max${version_name}`).append(
            "<pre>" + $(`#log${version_name} input[name=init_log]`).val()
          );
          scrollAnimation(
            logContentDom,
            logContentDom.scrollTop + 1,
            logContentDom.scrollHeight - logContentDom.clientHeight
          );
          if (log_type !== "c2Net") {
            $(".log-scroll-max").bind("scroll", function () {
              let version_name = $(this).data("version");
              let ID = $(`#accordion${version_name}`).data("jobid");
              let repoPath = $(`#accordion${version_name}`).data("repopath");
              fn(version_name, repoPath, ID, "-max", 100);
            });
          }

          $(".log_bottom-max").bind("click", logBottom);
          $(".log_top-max").bind("click", logTop);
        },
        onHide: function () {
          let startLine = $(
            `#log${version_name} input[name=start_line-max-copy]`
          ).val();
          $(`#log_file-max${version_name}`).siblings("pre").remove();
          $(`#log${version_name} input[name=start_line-max]`).val(startLine);

          $(".log-scroll-max").unbind("scroll");
          $(".log_bottom-max").unbind("click");
          $(".log_top-max").unbind("click");
        },
      })
      .modal("show");
  });

  function loadLog(version_name) {
    document.getElementById("mask").style.display = "block";
    $.get(
      `/api/v1/repos/${userName}/${repoPath}/grampus/train-job/${jobID}/log?version_name=${version_name}&lines=50&order=asc`,
      (data) => {
        $("input[name=end_line]").val(data.EndLine);
        $("input[name=start_line]").val(data.StartLine);
        $(`#log_file${version_name}`).text(data.Content);
        document.getElementById("mask").style.display = "none";
      }
    ).fail(function (err) {
      document.getElementById("mask").style.display = "none";
      console.log(err);
    });
  }
  $(".refresh-status").click(function (e) {
    let version_name = $(this).data("version");
    let ID = $(`#accordion${version_name}`).data("jobid");
    let repoPath = $(`#accordion${version_name}`).data("repopath");
    refreshStatusShow(version_name, ID, repoPath);
    e.stopPropagation();
  });
  $(".stop-show-version").click(function (e) {
    const ID = this.dataset.jobid;
    const repoPath = this.dataset.repopath;
    const version_name = this.dataset.version;
    const url = `/api/v1/repos/${repoPath}/${ID}/stop_version`;
    $.post(url, { version_name: version_name }, (data) => {
      if (data.StatusOK === 0) {
        $(`#${version_name}-stop`).removeClass("blue");
        $(`#${version_name}-stop`).addClass("disabled");
        refreshStatusShow(version_name, ID, repoPath);
      }
    }).fail(function (err) {
      console.log(err);
    });
    e.stopPropagation();
  });
  $(".delete-show-version").click(function (e) {
    const ID = this.dataset.jobid;
    const repoPath = this.dataset.repopath;
    const version_name = this.dataset.version;
    const url = `/api/v1/repos/${repoPath}/${ID}/del_version`;
    $(".ui.basic.modal")
      .modal({
        onApprove: function () {
          $.post(url, { version_name: version_name }, (data) => {
            if (data.StatusOK === 0) {
              if (data.VersionListCount === 0) {
                location.href = `/${repoPath}`;
              } else {
                $("#accordion" + version_name).remove();
              }
              refreshStatusShow(version_name, ID, repoPath);
            } else {
              return;
            }
          }).fail(function (err) {
            console.log(err);
          });
        },
      })
      .modal("show");

    e.stopPropagation();
  });
  $('.ui.pointing.secondary.menu .item:eq(0)').click(function(e) {
    const self = $(this);
    setTimeout(function() {
      self.closest('.accordion').find('.refresh-status').trigger('click');
    }, 20);
    
  });
  function refreshStatusShow(version_name, ID, repoPath) {
    $.get(
      `/api/v1/repos/${repoPath}/${ID}?version_name=${version_name}`,
      (data) => {
        //accroding下的状态
        $(`#${version_name}-status-span span`).text(data.JobStatus);
        //accroding下的状态图标
        $(`#${version_name}-status-span i`).attr("class", data.JobStatus);
        //accroding下的运行时长
        $(`#${version_name}-duration-span`).text(data.JobDuration);
        //配置信息详情页的状态
        data.StartTime !== undefined && data.StartTime > 0 && $(`#${version_name}-startTime`).text(timeFormat(new Date(data.StartTime * 1000)));
        //配置信息详情页的状态
        $(`#${version_name}-status`).text(data.JobStatus);
        //配置信息详情页的状态
        $(`#${version_name}-duration`).text(data.JobDuration);
        //配置信息详情页的状态
        $(`#${version_name}-ai_center`).text(data.AiCenter);
      }
    ).fail(function (err) {
      console.log(err);
    });
    const accordionEl = $(`#accordion${version_name}`);
    const activeTab = accordionEl.find('.ui.pointing.secondary.menu .item:not(:eq(0)).active');
    activeTab.trigger('click');
  }
  //
  $(".content-pad").on("click", ".load-model-file", function () {
    let downloadFlag = $(this).data("download-flag") || "";
    let gpuFlag = $(this).data("gpu-flag") || "";
    let version_name = $(this).data("version");
    let parents = $(this).data("parents");
    let filename = $(this).data("filename");
    let init = $(this).data("init") || "";
    let path = $(this).data("path");
    $(`#dir_list${version_name}`).empty();
    let url = `/api/v1/repos${path}?version_name=${version_name}&parentDir=${parents}`;
    $.get(url, (data) => {
      if (data.StatusOK == 0) { // 成功 0
        if (data.Dirs) {
          data.Dirs.length !==0 && $(`#${version_name}-result-down`).show()
          renderDir(path, data, version_name, downloadFlag, gpuFlag);
        }
        if (init === "init") {
          $(`input[name=model${version_name}]`).val("");
          $(`input[name=modelback${version_name}]`).val(version_name);
          $(`#file_breadcrumb${version_name}`).empty();
          let htmlBread = "";
          if (version_name) {
            htmlBread += `<div class='active section'>${version_name}</div>`;
          } else {
            htmlBread += `<div class='active section'>result</div>`;
          }
          htmlBread += "<div class='divider'> / </div>";
          $(`#file_breadcrumb${version_name}`).append(htmlBread);
        } else {
          renderBrend(
            path,
            version_name,
            parents,
            filename,
            init,
            downloadFlag,
            gpuFlag
          );
        }
      } else if (data.StatusOK == 1) { // 处理中 1
        $(`#file_breadcrumb${version_name}`).empty();
        $(`#dir_list${version_name}`).html(`<div style="height:200px;display:flex;justify-content:center;align-items:center;font-size:14px;color:rgb(16, 16, 16);">
          <style>
          @-webkit-keyframes spinning {
            0% { -webkit-transform: rotate(0deg); }
            100% { -webkit-transform: rotate(360deg); }
          }          
          </style>
          <div style="display:flex;justify-content:center;align-items:center;height:24px;width:24px;margin-right:5px;animation-duration:3s;animation-iteration-count:infinite;animation-name:spinning;animation-timing-function:linear;animation-fill-mode:backwards;">
            <svg xmlns="http://www.w3.org/2000/svg" class="styles__StyledSVGIconPathComponent-sc-16fsqc8-0 iKfgJk svg-icon-path-icon fill" viewBox="0 0 48 48" width="16" height="16"><defs data-reactroot=""></defs><g><g><rect width="48" height="48" fill="white" fill-opacity="0.01" stroke-linejoin="round" stroke-width="4" stroke="none" fill-rule="evenodd"></rect><g transform="translate(7.000000, 3.500000)"><path d="M0,0.5 L34,0.5" stroke-linecap="round" stroke-linejoin="round" stroke-width="4" stroke="#333" fill="none" fill-rule="evenodd"></path><path d="M0,40.5 L34,40.5" stroke-linecap="round" stroke-linejoin="round" stroke-width="4" stroke="#333" fill="none" fill-rule="evenodd"></path><path d="M30,20.4999965 C27.3333333,33.8388874 23,40.5055541 17,40.4999965 C11,40.494439 6.66666667,33.8277723 4,20.4999965 L30,20.4999965 Z" fill="none" fill-rule="nonzero" transform="translate(17.000000, 30.499998) rotate(180.000000) translate(-17.000000, -30.499998) " stroke-linejoin="round" stroke-width="4" stroke="#333"></path><path d="M30,0.5 C27.3333333,13.8388909 23,20.5055575 17,20.5 C11,20.4944425 6.66666667,13.8277758 4,0.5 L30,0.5 Z" fill="none" fill-rule="nonzero" stroke-linejoin="round" stroke-width="4" stroke="#333"></path></g></g></g></svg>
          </div>          
          <span>${i18n['file_sync_ing']}</span>
        </div>`);
      } else if (data.StatusOK == 2) { // 失败 2
        $(`#file_breadcrumb${version_name}`).empty();
        $(`#dir_list${version_name}`).html(`<div style="height:200px;display:flex;justify-content:center;align-items:center;font-size:14px;color:rgb(16, 16, 16);">          
          <div style="display:flex;justify-content:center;align-items:center;height:24px;width:24px;margin-right:5px;">
          <svg xmlns="http://www.w3.org/2000/svg" class="styles__StyledSVGIconPathComponent-sc-16fsqc8-0 iKfgJk svg-icon-path-icon fill" viewBox="64 64 896 896" width="16" height="16"><defs data-reactroot=""></defs><g><path d="M464 720a48 48 0 1 0 96 0 48 48 0 1 0-96 0zm16-304v184c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V416c0-4.4-3.6-8-8-8h-48c-4.4 0-8 3.6-8 8zm475.7 440l-416-720c-6.2-10.7-16.9-16-27.7-16s-21.6 5.3-27.7 16l-416 720C56 877.4 71.4 904 96 904h832c24.6 0 40-26.6 27.7-48zm-783.5-27.9L512 239.9l339.8 588.2H172.2z"></path></g></svg>
          </div>
          <span>${i18n['file_sync_fail']}</span>
        </div>`);
      } else if (data.StatusOK == 3) { // 无文件 3
        $(`#file_breadcrumb${version_name}`).empty();
        $(`#dir_list${version_name}`).html(`<div style="height:200px;display:flex;justify-content:center;align-items:center;font-size:14px;color:rgb(16, 16, 16);">          
          <div style="display:flex;justify-content:center;align-items:center;height:24px;width:24px;margin-right:5px;">
            <svg xmlns="http://www.w3.org/2000/svg" class="styles__StyledSVGIconPathComponent-sc-16fsqc8-0 iKfgJk svg-icon-path-icon fill" viewBox="0 0 24 24" width="16" height="16"><defs data-reactroot=""></defs><g><circle cx="15.5" cy="9.5" r="1.5"></circle><circle cx="8.5" cy="9.5" r="1.5"></circle><path d="M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm0-6c-2.33 0-4.32 1.45-5.12 3.5h1.67c.69-1.19 1.97-2 3.45-2s2.75.81 3.45 2h1.67c-.8-2.05-2.79-3.5-5.12-3.5z"></path></g></svg>
          </div>
          <span>${i18n['no_file_to_download']}</span>
        </div>`);
      } else if (data.StatusOK == 4) { // 任务未结束 4
        $(`#file_breadcrumb${version_name}`).empty();
        $(`#dir_list${version_name}`).html(`<div style="height:200px;display:flex;justify-content:center;align-items:center;font-size:14px;color:rgb(16, 16, 16);">          
          <div style="display:flex;justify-content:center;align-items:center;height:24px;width:24px;margin-right:5px;">
            <svg xmlns="http://www.w3.org/2000/svg" class="styles__StyledSVGIconPathComponent-sc-16fsqc8-0 iKfgJk svg-icon-path-icon fill" viewBox="0 0 32 32" width="16" height="16"><defs data-reactroot=""></defs><g><path d="M16 29.333c-7.364 0-13.333-5.969-13.333-13.333s5.969-13.333 13.333-13.333 13.333 5.969 13.333 13.333-5.969 13.333-13.333 13.333zM16 26.667c5.891 0 10.667-4.776 10.667-10.667s-4.776-10.667-10.667-10.667v0c-5.891 0-10.667 4.776-10.667 10.667s4.776 10.667 10.667 10.667v0zM17.333 16h5.333v2.667h-8v-9.333h2.667v6.667z"></path></g></svg>
          </div>
          <span>${i18n['task_not_finished']}</span>
        </div>`);
      }
    }).fail(function (err) {
      console.log(err, version_name);
    });
  });
  function renderSize(value) {
    if (null == value || value == "") {
      return "0 Bytes";
    }
    var unitArr = new Array(
      "Bytes",
      "KB",
      "MB",
      "GB",
      "TB",
      "PB",
      "EB",
      "ZB",
      "YB"
    );
    var index = 0;
    var srcsize = parseFloat(value);
    index = Math.floor(Math.log(srcsize) / Math.log(1024));
    var size = srcsize / Math.pow(1024, index);
    size = size.toFixed(0); //保留的小数位数
    return size + unitArr[index];
  }
  function renderBrend(
    path,
    version_name,
    parents,
    filename,
    init,
    downloadFlag,
    gpuFlag
  ) {
    if (init == "folder") {
      let htmlBrend = "";
      let sectionName = $(
        `#file_breadcrumb${version_name} .active.section`
      ).text();
      let parents1 = $(`input[name=model${version_name}]`).val();
      let filename1 = $(`input[name=modelback${version_name}]`).val();
      if (parents1 === "") {
        $(`#file_breadcrumb${version_name} .active.section`).replaceWith(
          `<a class='section load-model-file' data-download-flag='${downloadFlag}' data-gpu-flag='${gpuFlag}' data-path='${path}' data-version='${version_name}' data-parents='${parents1}' data-filename='' data-init='init'>${sectionName}</a>`
        );
      } else {
        $(`#file_breadcrumb${version_name} .active.section`).replaceWith(
          `<a class='section load-model-file' data-download-flag='${downloadFlag}' data-gpu-flag='${gpuFlag}' data-path='${path}' data-version='${version_name}' data-parents='${parents1}' data-filename='${filename1}'>${sectionName}</a>`
        );
      }

      htmlBrend += `<div class='active section'>${filename}</div>`;
      htmlBrend += "<div class='divider'> / </div>";
      $(`#file_breadcrumb${version_name}`).append(htmlBrend);
      $(`input[name=model${version_name}]`).val(parents);
      $(`input[name=modelback${version_name}]`).val(filename);
    } else {
      $(`input[name=model${version_name}]`).val(parents);
      $(`input[name=modelback${version_name}]`).val(filename);

      let selectEle = $(`#file_breadcrumb${version_name} a.section`).filter(
        (index, item) => {
          return item.text == filename;
        }
      );
      selectEle.nextAll().remove();
      selectEle.after("<div class='divider'> / </div>");
      selectEle.replaceWith(`<div class='active section'>${filename}</div>`);
    }
  }

  function renderDir(path, data, version_name, downloadFlag, gpuFlag) {
    let html = "";
    html += "<div class='ui grid' style='margin:0;'>";
    html += "<div class='row' style='padding: 0;'>";
    html += "<div class='ui sixteen wide column' style='padding:1rem;'>";
    html += "<div class='dir list'>";
    html += "<table id='repo-files-table' class='ui single line table pad20'>";
    html += "<tbody>";
    // html += "</tbody>"
    for (let i = 0; i < data.Dirs.length; i++) {
      let dirs_size = renderSize(data.Dirs[i].Size);
      html += "<tr>";
      html += "<td class='name six wid'>";
      html += "<span class='truncate'>";
      html += "<span class='octicon octicon-file-directory'>";
      html += "</span>";
      if (data.Dirs[i].IsDir) {
        html += `<a  class='load-model-file' data-download-flag='${downloadFlag}' data-gpu-flag='${gpuFlag}' data-path='${path}' data-version='${version_name}' data-parents='${data.Dirs[i].ParenDir}' data-filename='${data.Dirs[i].FileName}' data-init='folder'>`;
        html +=
          "<span class='fitted'><i class='folder icon' width='16' height='16' aria-hidden='true'></i>" +
          data.Dirs[i].FileName +
          "</span>";
      } else {
        if (downloadFlag) {
          if (gpuFlag) {
            if (path.includes("model_list")) {
              html += `<a href="${location.href}/download_model?version_name=${version_name}&fileName=${data.Dirs[i].FileName}&parentDir=${data.Dirs[i].ParenDir}&jobName=${data.task.JobName}">`;
            } else {
              html += `<a href="${location.href}/result_download?version_name=${version_name}&fileName=${data.Dirs[i].FileName}&parentDir=${data.Dirs[i].ParenDir}&jobName=${data.task.JobName}">`;
            }
          } else {
            if (path.includes("model_list")) {
              html += `<a href="${location.href}/model_download?version_name=${version_name}&file_name=${data.Dirs[i].FileName}&parent_dir=${data.Dirs[i].ParenDir}">`;
            } else {
              html += `<a href="${location.href}/result_download?version_name=${version_name}&file_name=${data.Dirs[i].FileName}&parent_dir=${data.Dirs[i].ParenDir}">`;
            }
          }
        } else {
          html += `<a class="disabled">`;
        }
        html +=
          "<span class='fitted'><i class='file icon' width='16' height='16' aria-hidden='true'></i>" +
          data.Dirs[i].FileName +
          "</span>";
      }
      html += "</a>";
      html += "</span>";
      html += "</td>";
      html += "<td class='message1 seven wide'>";
      if (data.Dirs[i].IsDir) {
        html += "<span class='truncate has-emoji'></span>";
      } else {
        html +=
          "<span class='truncate has-emoji'>" + `${dirs_size}` + "</span>";
      }

      html += "</td>";

      html += "<td class='text right age three wide'>";
      html +=
        "<span class='truncate has-emoji'>" + data.Dirs[i].ModTime + "</span>";
      html += "</td>";
      html += "</tr>";
    }
    html += "</tbody>";
    html += "</table>";
    html += "</div>";
    html += "</div>";
    html += "</div>";
    html += "</div>";
    $(`#dir_list${version_name}`).append(html);
  }
}
