//DATA//
  profile: DB.FindOne(refid, { collection: "profile" })
  profiles: DB.Find(null, { collection: "profile" })
  rival: DB.Find(refid, { collection: "rival" })

-
  let rival_list=[["", "None", "0000-0000"]];
  profiles.forEach((res) => {
    rival_list.push([res.refid, res.name, res.idstr])
  });

  let my_sp_rival = [], my_dp_rival = [];
  rival.forEach((res) => {
    if (res.play_style == 1) my_sp_rival[res.index] = res.rival_refid;
    else if (res.play_style == 2) my_dp_rival[res.index] = res.rival_refid;
  });

div
  .card
    .card-header
      p.card-header-title
        span.icon
          i.mdi.mdi-account-edit
        | Rivals
    .card-content
      form(method="post" action="/emit/iidxUpdateRival")
        .field
          input(type="text" name="refid", value=refid readonly hidden)
          label.label SP Rivals
          .body
            .control
              .select
                select(name="sp_rival1")
                  each i in rival_list
                    if my_sp_rival[0] != null
                      option(selected=(i[0]==my_sp_rival[0]) value=i[0]) #{i[1]} [#{i[2]}]
                    else
                      option(value=i[0]) #{i[1]} [#{i[2]}]
            .control
              .select
                select(name="sp_rival2")
                  each i in rival_list
                    if my_sp_rival[1] != null
                      option(selected=(i[0]==my_sp_rival[1]) value=i[0]) #{i[1]} [#{i[2]}]
                    else
                      option(value=i[0]) #{i[1]} [#{i[2]}]
            .control
              .select
                select(name="sp_rival3")
                  each i in rival_list
                    if my_sp_rival[2] != null
                      option(selected=(i[0]==my_sp_rival[2]) value=i[0]) #{i[1]} [#{i[2]}]
                    else
                      option(value=i[0]) #{i[1]} [#{i[2]}]
            .control
              .select
                select(name="sp_rival4")
                  each i in rival_list
                    if my_sp_rival[3] != null
                      option(selected=(i[0]==my_sp_rival[3]) value=i[0]) #{i[1]} [#{i[2]}]
                    else
                      option(value=i[0]) #{i[1]} [#{i[2]}]
            .control
              .select
                select(name="sp_rival5")
                  each i in rival_list
                    if my_sp_rival[4] != null
                      option(selected=(i[0]==my_sp_rival[4]) value=i[0]) #{i[1]} [#{i[2]}]
                    else
                      option(value=i[0]) #{i[1]} [#{i[2]}]
        .field
          label.label DP Rivals
          .body
            .control
              .select
                select(name="dp_rival1")
                  each i in rival_list
                    if my_dp_rival[0] != null
                      option(selected=(i[0]==my_dp_rival[0]) value=i[0]) #{i[1]} [#{i[2]}]
                    else
                      option(value=i[0]) #{i[1]} [#{i[2]}]
            .control
              .select
                select(name="dp_rival2")
                  each i in rival_list
                    if my_dp_rival[1] != null
                      option(selected=(i[0]==my_dp_rival[1]) value=i[0]) #{i[1]} [#{i[2]}]
                    else
                      option(value=i[0]) #{i[1]} [#{i[2]}]
            .control
              .select
                select(name="dp_rival3")
                  each i in rival_list
                    if my_dp_rival[2] != null
                      option(selected=(i[0]==my_dp_rival[2]) value=i[0]) #{i[1]} [#{i[2]}]
                    else
                      option(value=i[0]) #{i[1]} [#{i[2]}]
            .control
              .select
                select(name="dp_rival4")
                  each i in rival_list
                    if my_dp_rival[3] != null
                      option(selected=(i[0]==my_dp_rival[3]) value=i[0]) #{i[1]} [#{i[2]}]
                    else
                      option(value=i[0]) #{i[1]} [#{i[2]}]
            .control
              .select
                select(name="dp_rival5")
                  each i in rival_list
                    if my_dp_rival[4] != null
                      option(selected=(i[0]==my_dp_rival[4]) value=i[0]) #{i[1]} [#{i[2]}]
                    else
                      option(value=i[0]) #{i[1]} [#{i[2]}]
        .field
            button.button.is-primary(type="submit") 
              span.icon
                i.mdi.mdi-check
              span Submit
