<template>
  <div class="AccessMiningPoolMain" v-loading="tutorialLoading">
    <section v-if="openAPI" class="openAPI">
      <section v-if="$isMobile">
        <!-- <div class="currencySelect">
          <div class="nav">
            <div class="nav-item" id="menu1" @click.stop="toggleDropdown">
              <img
                class="itemImg"
                :src="activeItem.imgUrl || ``"
                :alt="activeItem.label || ``"
              />
              <span style="text-transform: capitalize">
                {{ activeItem.label || `` }}</span
              >
              <i class="arrow"></i>
              <div class="dropdown">
                <div
                  class="option"
                  v-for="item in currencyList"
                  :key="item.value"
                  @click.stop="changeMenuName($event, item)"
                  :class="{ optionActive: $route.path.includes(item.path) }"
                >
                  <img
                    class="dropdownCoin"
                    :src="item.imgUrl"
                    :alt="item.value"
                  />
                  <div class="dropdownText">{{ item.label }}</div>
                </div>
              </div>
            </div>
          </div>
        </div> -->

        <section class="menu2" v-if="!contentShow">
          <ul>
            <li
              :class="{ active: activeCoin == item.coin }"
              @click="clickJump(item)"
              v-for="item in navList"
              :key="item.id"
            >
              <img class="img2" :src="item.titleUrl" alt="coin" />
              <span>
                {{ item.title }}
              </span>
            </li>
          </ul>
        </section>
<!-- 
        <section>
          <keep-alive>
            <router-view :key="$route.fullPath" />
          </keep-alive>
        </section> -->

        <!-- 显示内容 -->
        <section class="tutorialContent" v-else>
          <p class="backMenu" @click="backMenu">{{ $t("course.backMenu") || "返回挖矿教程目录" }} </p>
          <section class="rightContent">
            <div v-if="tutorialLoading" class="loading-container">
              <span class="loading-text">{{
                $t("home.loadingContent") || "正在加载内容..."
              }}</span>
            </div>
            <div
              v-else-if="info && info.trim()"
              class="dynamic-content"
              v-html="info"
            ></div>
            <div v-else class="no-content">
              <p>{{ $t("home.noContent") || "暂无内容" }}</p>
            </div>
          </section>

          <!-- <router-view></router-view> -->
        </section>
      </section>

      <section class="AccessMiningPool" v-else>
        <section class="menu">
          <ul>
            <li
              :class="{ active: activeCoin == item.coin }"
              @click="clickJump(item)"
              v-for="item in navList"
              :key="item.id"
            >
              <img :src="item.titleUrl" alt="coin" />
              <span>
                {{ item.title }}
              </span>
            </li>
            <!-- <li
           
             :class="{ active: currentRoutePath == item.path }"
              @click="clickJump(item)"
              v-for="item in currencyList"
              :key="item.value"
            >
              <img :src="item.imgUrl" :alt="item.value" loading="lazy" />
              <span>
                {{ $t(item.name) }}
              </span>
            </li> -->
          </ul>
        </section>
        <section class="tutorialContent">
          <section class="rightContent">
            <div v-if="tutorialLoading" class="loading-container">
              <span class="loading-text">{{
                $t("home.loadingContent") || "正在加载内容..."
              }}</span>
            </div>
            <div
              v-else-if="info && info.trim()"
              class="dynamic-content"
              v-html="info"
            ></div>
            <div v-else class="no-content">
              <p>{{ $t("home.noContent") || "暂无内容" }}</p>
            </div>
          </section>

          <!-- <router-view></router-view> -->
        </section>
      </section>
    </section>
    <section v-else>
      <div class="notOpen">
        <p>{{ $t(`course.notOpenCurrency`) }}</p>
        <div class="imgBox">
          <img
            src="../../assets/404_images/notOpen.png"
            alt="Not open"
            loading="lazy"
          />
        </div>
      </div>
    </section>
  </div>
</template>

<script>
import IndexJs from "./index";
export default {
  mixins: [IndexJs],
  watch: {
    $route(to, from) {
      // 监听路由变化，处理组件更新
      this.handleRouteChange(to, from);
    },
  },
  methods: {
    handleRouteChange(to, from) {
      // 确保组件能够正确响应路由变化
      if (to.name !== from.name) {
        this.$nextTick(() => {
          // 强制更新组件
          this.$forceUpdate();
        });
      }
    },

    // clickJump(item) {
    //   if (!item || !item.path) return;

    //   const route = {
    //     name: item.path,
    //     params: {
    //       lang: this.$i18n.locale
    //     }
    //   };

    //   this.$router.push(route).catch(err => {
    //     if (err.name !== 'NavigationDuplicated') {
    //       console.error('Navigation failed:', err);
    //     }
    //   });
    // }
  },
};
</script>

<style lang="scss" scoped>
@media screen and (min-width: 220px) and (max-width: 1279px) {
  .AccessMiningPoolMain {
    width: 100%;
    // min-height: 100vh;
    background: transparent !important;
    // background-image: url(../../assets/img/miningAccount/top.png);
    // background-size: 100% 50%;
    // background-repeat: no-repeat;
    // background-position: 30% -15%;
    padding: 0;
    margin: 0;
    padding-top: 30px;
    display: flex;
    justify-content: center;
    overflow-y: auto;
    height: 100%;
    .mail {
      color: #5917c4;
    }
  }
  /* 移动端内容卡片与正文区域适配 */
  .tutorialContent {
    width: 98% !important; /* 贴近屏幕但保留安全间距 */
    padding: 0 !important;
    margin: 0 auto !important;
    box-shadow: 0 0 6px 1px rgba(0, 0, 0, 0.08) !important;
    border-radius: 8px !important;
    background: transparent !important;
    box-shadow: none !important;
  }
  .backMenu{
    color: #6924ff;
    font-size: 0.95rem !important;
    margin: 0 0 10px 2px !important;
    display: inline-block !important;
    text-decoration: underline;
    cursor: pointer;
  }
  .rightContent {
    margin-left: 0 !important; /* 取消桌面端的左侧外边距 */
    padding: 6px !important; /* 适度内边距 */
    // padding-right: 12px !important;
    overflow-x: hidden !important;
    font-size: 0.9rem !important; /* 移动端统一字号 */
    background: transparent !important;
  }
  /* 返回目录按钮在移动端的点击区域与排版 */
  .backMenu {
    font-size: 0.95rem !important;
    margin: 0 0 10px 2px !important;
    display: inline-block !important;
  }

  /* 富文本内容在移动端的表格适配：固定布局+自动换行 */
  .rightContent .dynamic-content {
    overflow-x: auto !important; /* 超出时允许横向滚动（兜底） */
    -webkit-overflow-scrolling: touch;
  }





  .rightContent .dynamic-content :deep(table) {
    /* 对含有 colspan/rowspan 的表格，固定布局会引发表头与列错位，这里改为自动布局 */
    table-layout: auto !important;
    width: 100% !important;
    border-collapse: collapse !important;
  }
  .rightContent .dynamic-content :deep(th) {//表格表头字号
      
      font-size: 0.7rem !important;
      word-break: break-word !important;
    }



  /* 表格单元格字号 */
  .rightContent .dynamic-content :deep(th),
  .rightContent .dynamic-content :deep(td) {
    word-break: break-word !important;
    white-space: normal !important;
    padding: 2px !important;
    font-size: 0.7rem !important; /* 表格单元格字号 */
    min-width: 0 !important; /* 覆盖外层全局 td 的最小宽度，避免小屏列被强撑导致错位 */
    vertical-align: left !important;
  }
  /* 步骤里的段落在移动端必须自动换行，禁止引发横向滚动条 */
  .rightContent .dynamic-content :deep(p) {
    max-width: 100% !important;
    white-space: normal !important;
    word-break: break-word !important; /* 优先按单词/字符断行 */
    overflow-wrap: anywhere !important; /* 极端长串也强制换行 */
    word-wrap: break-word !important; /* 旧版兼容 */
    font-size: 0.8rem !important;
  }
  .rightContent .dynamic-content :deep(a) {
    font-size: 0.8rem !important;
  }
  .rightContent .dynamic-content :deep(li) {
    font-size: 0.7rem !important;
  }

  .rightContent .dynamic-content :deep(pre) {
    font-size: 0.7rem !important;
  }

  .rightContent .dynamic-content :deep(font) {
    font-size: 0.9rem !important;
    min-width: 40px !important;
    display: inline-block !important;
  }
  .rightContent .dynamic-content :deep(h2) {
    font-size: 1rem !important;
  }

  .rightContent .dynamic-content :deep(h3) {
    font-size: 0.9rem !important;
  }






  .img2{
      width: 25px;
    }

  .menu2{
    max-height: 100vh;
    overflow-y: auto;
    background: transparent !important;
    ul{
      padding: 18px;
      margin-bottom: 20px;
      li{
        padding: 8px;
       text-decoration: underline;
       list-style: none;
      }
    }

    .active{
      background: transparent !important;
      color: rgba(0,0,0,1);
    }
    
  }
  .notOpen {
    width: 100%;
    display: inline-block !important;
    margin: 50px 00px;
    justify-content: center;
    padding: 0px 30px;

    p {
      // background: #D1C2E9;
      font-size: 20px !important;
      width: 100% !important;
      line-height: 50px;
      color: #6a24ff;
      text-align: center;
    }
    .imgBox {
      display: flex;
      justify-content: center;
      margin-top: 30px;
    }

    img {
      width: 80%;
    }
  }
  .currencySelect {
    display: flex;
    align-items: center;
    // margin-bottom: 15px;
    padding-left: 8px;
    font-size: 0.85rem;
    .el-menu-demo {
      width: 100%;
    }

    .el-menu {
      background: transparent;
    }
    // .title{
    //   width: 30%;
    // }
    .coinSelect {
      img {
        width: 25px;
      }
      span {
        text-transform: capitalize;
        margin-left: 5px;
      }
    }
  }
  .moveCurrencyBox {
    margin: 0;
    padding: 0;
    width: 100%;
    display: flex;
    min-height: 200px;
    flex-wrap: wrap;
    padding: 10px 20px;
    margin: 0 auto;
    background: #fff;

    li {
      list-style: none;
      //  width: calc(100% / 5);
      display: flex;
      flex-direction: column;
      align-items: center !important;
      margin-left: 10px;
      // background: #D2C4E8;
      // align-items: center;
      // overflow: hidden;
      padding: 5px 5px;
      box-sizing: border-box;
      // background: palegoldenrod;

      img {
        width: 25px;
      }
      p {
        min-width: 50px;
        margin-top: 8px;
        font-size: 0.85rem;
        word-wrap: break-word;
        word-break: break-all;
        text-align: center;
        text-transform: capitalize;
      }
    }
  }

  .mainTitle {
    padding: 0px 20px;
    span {
      font-size: 0.95rem;
      color: rgba(0, 0, 0, 0.7);
      font-weight: 600;
    }
  }
  .tableBox {
    margin: 0 auto;
    width: 96%;
    min-height: 300px;
    // background: palegoldenrod;
    overflow: hidden;
    border-radius: 8px;
    font-size: 0.9rem;
    margin-bottom: 20px;
    box-shadow: 0px 0px 5px 2px #ccc;
    margin-top: 10px;
    background: #fff;
    .table-title {
      height: 50px;
      background: #d2c4e8;
      display: flex;
      justify-content: space-around;
      align-items: center;
      font-weight: 600;
      padding-left: 0 !important;
      span {
        text-align: center;
      }
      span:nth-of-type(1) {
        width: 50% !important;
      }
      span:nth-of-type(2) {
        width: 50% !important;
        color: #ca094a;
        font-weight: bold;
        padding-right: 5px;
      }
    }
    .collapseTitle {
      width: 100%;
      display: flex;
      justify-content: space-around;
      align-items: center;
      padding-left: 0 !important;
      text-align: center;
      span {
        text-align: center;
      }

      span:nth-of-type(1) {
        width: 50% !important;
        display: flex;
        align-items: center;
        justify-content: center;
        img {
          margin-right: 5px;
        }
      }
      span:nth-of-type(2) {
        width: 50% !important;
        color: #ca094a;
        font-weight: bold;
      }
    }
    .belowTable {
      background: #f0e9f5;
      padding: 10px 0px;
      div {
        width: 100%;
        height: auto;
        text-align: left;
        padding-left: 8%;
        p:nth-of-type(1) {
          font-weight: 600;
        }
        p {
          word-wrap: break-word;

          .copy {
            padding: 0px 5px;
            display: inline-block;
            cursor: pointer;
            border: 1px solid #d1c2e9;
            border-radius: 5px;
            margin-left: 10px;
            font-size: 0.8rem;
          }
        }
      }
    }

    .paginationBox {
      text-align: center;
    }
  }
  #careful {
    padding: 0px 8px;
    font-size: 0.85rem;
    color: rgba(0, 0, 0, 0.7);
    line-height: 25px;
    .mail {
      color: #5917c4;
    }
  }
  .step {
    width: 99% !important;
    margin: 0 auto;
    margin-top: 3%;
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-sizing: border-box;
    padding: 15px !important;
    p {
      line-height: 25px !important;
    }
    .stepTitle {
      height: auto !important;
      width: 100%;
      border-bottom: 1px solid rgba(0, 0, 0, 0.1);
      line-height: 30px !important;
      font-size: 0.95rem !important;
      color: rgba(0, 0, 0, 0.6);
      font-weight: 600;
      word-wrap: break-word;
    }
    .textBox {
      padding: 10px !important;
      color: rgba(5, 32, 75, 0.6);
      font-weight: normal !important;
      font-size: 0.85rem !important;
    }
  }

  ::v-deep .el-collapse-item__content {
    padding: 0 !important;
  }
  .nav {
    // position: absolute;
    z-index: 1000;
    // height: 60px;
    // line-height: 60px;
    margin-right: 8px;
  }

  .nav-item {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0 10px;
    .itemImg {
      width: 20px;
      margin-right: 5px;
    }
    .arrow {
      margin-left: 5px;
      border: solid rgba(0, 0, 0, 0.3);
      border-width: 0 1px 1px 0;
      display: inline-block;
      padding: 3px;
      transform: rotate(45deg);
      transition: transform 0.3s;

      &.up {
        transform: rotate(-135deg);
      }
    }
  }
  .dropdown {
    position: absolute;
    top: 28px;
    left: 0;
    width: 362px;
    background: white;
    border: 1px solid #eee;
    border-radius: 4px;
    padding: 3px;
    display: none;
    flex-wrap: wrap;
    gap: 1px;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    z-index: 999999;

    &.show {
      display: flex;
    }

    .option {
      width: 70px;
      height: 70px;
      background: #f5f5f5;
      // display: flex;
      // align-items: center;
      // justify-content: center;
      cursor: pointer;
      transition: all 0.3s;
      border-radius: 4px;
      // flex-direction: column;
      // padding:5px;
      // padding-top: 5%;
      overflow: hidden;
      text-align: center;
      padding: 5px;
      text-overflow: ellipsis;

      &:hover {
        background: #e8e8e8;
        color: #6e3edb;
        border: 1px solid #9d8ac9;
      }
    }

    .optionActive {
      background: #e8e8e8;
      color: #6e3edb;
      border: 1px solid #9d8ac9;
    }
  }

  .dropdownCoin {
    width: 23px;
    margin: 0;
  }
  .dropdownText {
    width: 100%;
    font-size: 0.8rem;
    // word-wrap: break-word;
    text-align: center;
    margin: 0;
    word-break: break-word;
    margin-top: 5px;
  }
}

.AccessMiningPoolMain {
  width: 100%;
  height: 100%;
}
.openAPI {
  width: 100%;
  height: 100%;
}
.AccessMiningPool {
  width: 100%;
  // height: 100%;
  // min-height: 100vh;
  background: #fff;
  background-image: url(../../assets/img/miningAccount/top.png);
  background-size: 100% 65%;
  background-repeat: no-repeat;
  background-position: 30% -15%;
  padding: 0;
  margin: 0;
  padding-top: 60px;
  display: flex;
  justify-content: center;

  a {
    color: #8a2be2;
  }
}
.tutorialContent {
  width: 60%;
  // background: palegreen;
  box-shadow: 0px 0px 10px 3px rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  padding-top: 30px;
  height: 100%;
  overflow-y: auto;
  padding: 20px;
  padding-bottom: 30px;
}
.notOpen {
  // background: palegoldenrod;
  display: flex;
  margin-top: 10%;
  justify-content: center;
  p {
    // background: #D1C2E9;
    font-size: 25px;
    width: 25%;
    line-height: 50px;
    color: #6a24ff;
  }
}
.menu {
  width: 18%;
  // background: #D2C3EA
  margin-right: 30px;
  background: #ffffff;
  padding: 20px !important;
  border-radius: 8px;
  box-shadow: 0px 0px 10px 3px rgba(0, 0, 0, 0.1);
  min-height: 300px;
  // font-size: 0.9rem;
  ul {
    margin: 0;
    padding: 0;
    li {
      list-style: none;
      min-height: 40px;
      line-height: 20px;
      text-align: left;
      margin-top: 8px;
      cursor: pointer;
      display: flex;
      align-items: start;
      padding: 5px;
      transition: all 0.3s;
      display: flex;
      align-items: center;
      justify-content: left;
      img {
        width: 25px;
        margin-right: 5px;
      }
      span {
        font-size: 0.9rem;
      }
    }
    li:hover {
      text-decoration: underline;
    }
  }
}
.active {
  color: #6924ff;
  background: #d2c3ea;
  border-radius: 5px;
}
.table {
  width: 70%;
  box-shadow: 0px 0px 10px 3px rgba(0, 0, 0, 0.1);
  // margin: 0 auto;
  background: #fff;
  border-radius: 8px;
  padding: 50px;
  .mainTitle {
    font-size: 1.5em;
    width: 100%;
    margin: 0 auto;
    font-weight: 600;
    color: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: left;
    img {
      width: 30px;
      margin-right: 5px;
    }
    //   span{
    //     margin-left: 5PX;

    //   }
  }
  .theServer {
    width: 100%;
    // height: 500PX;
    margin: 0 auto;
    box-shadow: 0px 0px 3px 1px rgba(0, 0, 0, 0.1);
    padding: 10px 10px;
    margin-top: 20px;

    .title {
      width: 100%;
      padding-left: 3%;
      height: 50px;
      line-height: 50px;
      font-size: 1.3em;
      color: rgba(0, 0, 0, 0.6);
      font-weight: 600;
      border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    }
    ul {
      width: 100%;
      height: 90%;
      padding: 0;
      margin: 0;
      margin-top: 1%;
      li {
        list-style: none;
        height: 40px;
        line-height: 40px;
        background: #efefef;
        display: flex;
        justify-content: space-between;
        font-size: 0.9rem;
        span {
          display: inline-block;
          text-align: center;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          color: rgba(0, 0, 0, 0.7);
        }
        .coin {
          width: 18%;
          display: flex;
          align-items: center;
          justify-content: center;
          img {
            width: 25px;
            margin-right: 5px;
          }
          span {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
        }
        .quota {
          color: #ca094a;
          font-weight: 600;
        }
        .difficulty {
          width: 10%;
        }
        .port {
          width: 35%;

          i {
            font-size: 1em;
          }
          i:hover {
            color: #6924ff;
          }
        }
        i {
          cursor: pointer;
        }
      }
      li:nth-child(even) {
        background-color: #ffff; /* 甚至可以是你想要的任何颜色 */
      }
      .liTitle {
        width: 100%;
        height: 50px;
        line-height: 50px;
        background: #d2c3ea;
        color: #36246f;
        font-size: 0.95rem;
        // span{
        //     display: inline-block;

        //     text-align: center;

        // }
        .coin {
          width: 18%;
          display: flex;
          align-items: center;
          justify-content: center;
          img {
            width: 25px;
          }
          span {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
        }
        // .difficulty{
        //     width: 10%;
        // }
        .port {
          width: 35%;
        }
      }
    }
  }
  .careful {
    margin-top: 8px;
    font-size: 0.9rem;
    color: rgba(0, 0, 0, 0.7);
    a {
      color: #6924ff;
    }
  }
}
.step {
  width: 100%;

  margin: 0 auto;
  margin-top: 3%;
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-sizing: border-box;
  padding: 20px;
  p {
    line-height: 30px;
  }
  .stepTitle {
    height: 40px;
    width: 100%;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    line-height: 40px;
    font-size: 1rem;
    color: rgba(0, 0, 0, 0.6);
    font-weight: 600;
  }
  .textBox {
    padding: 20px;
    color: rgba(5, 32, 75, 0.6);
    font-weight: 600;
    font-size: 0.95rem;
  }
}

.rightContent {
  flex: 1;
  height: 100%;
  margin-left: 50px;
  overflow-y: auto;
  padding-right: 20px;
  background: #fff;
  .dynamic-content {
    width: 100%;
    margin: 0 auto;
    font-family: "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.7;
    color: #222;
    // 富文本样式
    :deep(table) {
      border-collapse: collapse;
      width: 100%;
      margin: 16px 0;
      font-size: 14px;
      text-align: center;
    }

    :deep(th),
    :deep(td) {
      border: 1px solid #d1d5db;
      padding: 8px 12px;
      text-align: center;
    }
    :deep(th) {
      background: #d2c3ea;
      font-weight: bold;
      text-align: center;
    }
    :deep(strong),
    :deep(b) {
      font-weight: bold !important;
      color: inherit !important;
      font-style: normal !important;
    }
    :deep(em),
    :deep(i) {
      font-style: italic !important;
      color: inherit !important;
    }
    :deep(a) {
      color: #661ffb !important;
      text-decoration: none !important;
      &:hover {
        text-decoration: underline !important;
      }
    }
    :deep(p) {
      text-align: justify !important;
      text-justify: inter-ideograph !important;
      text-indent: 0 !important;
      line-height: 2 !important;
      margin: 0.8em 0 !important;
      /* 英文按单词换行，避免拆词；超长连续单词在必要时断行 */
      white-space: normal !important;
      word-break: normal !important;
      overflow-wrap: break-word !important; /* 现代浏览器 */
      word-wrap: break-word !important; /* 旧版兼容 */
      hyphens: none;
    }
    :deep(div) {
      text-align: justify !important;
      text-justify: inter-ideograph !important;
      line-height: 2 !important;
      margin: 0.8em 0 !important;
      white-space: normal !important;
      word-break: normal !important;
      overflow-wrap: break-word !important; /* 现代浏览器 */
      word-wrap: break-word !important; /* 旧版兼容 */
      hyphens: none;
    }
  }

  .loading-container {
    text-align: center;
    padding: 40px 0;
    .loading-text {
      font-size: 16px;
      color: #666;
      vertical-align: middle;
    }
  }
  .no-content {
    text-align: center;
    padding: 40px 0;
    p {
      font-size: 16px;
      color: #999;
      margin: 0;
    }
  }
}
</style>