<div class="textbook-table">
  <div class="tool">
    <div class="search">
      <nz-input-group style="width: 280px" [nzPrefix]="prefixTemplateUser">
        <input
          type="text"
          nz-input
          placeholder="输入教材名称 / ISBN / 作者名搜索"
          [(ngModel)]="searchValue"
          (ngModelChange)="onSearch($event)"
        />
      </nz-input-group>
      <ng-template #prefixTemplateUser
        ><span nz-icon nzType="search"></span
      ></ng-template>
    </div>
    @if (filterObj?.btns?.verify && count != 0) {
    <div
      class="sbt"
      (click)="submitted()"
    >
      提交推荐教材列表
    </div>
    }
  </div>
  <nz-table
    #tableData
    [nzData]="textbookList"
    [nzTotal]="count"
    [nzPageSize]="limit"
    [nzPageIndex]="pageIndex"
    style="margin: 10px 0"
    [nzLoading]="loading"
    nzSize="middle"
    [nzFrontPagination]="false"
    [nzScroll]="{ x: (maxWidth || '1200') + 'px' }"
    nzTableLayout="fixed"
    (nzPageIndexChange)="pageIndexChange($event)"
  >
    @if(filterObj?.showMore){
    <thead>
      <tr>
        @if (filterObj.isCheck) {
        <th
          nzWidth="50px"
          nzLeft
          [nzChecked]="checkedAll"
          [nzIndeterminate]="false"
          nzLabel="Select all"
          (nzCheckedChange)="onAllChecked($event)"
        ></th>
        <th nzEllipsis nzWidth="80px">申报编号</th>
        }@else{
        <th nzEllipsis nzWidth="120px" nzLeft>申报编号</th>
        }
        <th nzEllipsis nzWidth="120px">教材名称</th>
        <th nzEllipsis nzWidth="120px">ISBN</th>
        <th nzEllipsis nzWidth="180px">第一主编/作者</th>
        <th
          nzEllipsis
          nzWidth="120px"
          [nzShowFilter]="true"
          [nzFilters]="listOfColumns.lang.listOfFilter"
          (nzFilterChange)="listOfColumns.lang.onChange($event)"
        >
          主要语种类型
        </th>
        <th
          nzEllipsis
          nzWidth="180px"
          [nzShowFilter]="true"
          [nzFilters]="listOfColumns.majorPoniter.listOfFilter"
          (nzFilterChange)="listOfColumns.majorPoniter.onChange($event)"
        >
          所属学科专业类
        </th>
        <th
          nzEllipsis
          nzWidth="180px"
          [nzShowFilter]="true"
          [nzFilters]="listOfColumns.editionUnit.listOfFilter"
          (nzFilterChange)="listOfColumns.editionUnit.onChange($event)"
        >
          出版单位
        </th>
        <th
          nzEllipsis
          nzWidth="180px"
          [nzShowFilter]="true"
          [nzFilters]="listOfColumns.approval.listOfFilter"
          (nzFilterChange)="listOfColumns.approval.onChange($event)"
        >
          重点立项教材
        </th>
        <th
          nzEllipsis
          nzWidth="180px"
          [nzShowFilter]="true"
          [nzFilters]="listOfColumns.carrierShape.listOfFilter"
          (nzFilterChange)="listOfColumns.carrierShape.onChange($event)"
        >
          载体形式
        </th>
        <th
          nzEllipsis
          nzWidth="180px"
          [nzShowFilter]="true"
          [nzFilters]="listOfColumns.department.listOfFilter"
          (nzFilterChange)="listOfColumns.department.onChange($event)"
        >
          申报部门
        </th>
        <th nzEllipsis nzWidth="50px" nzRight>操作</th>
      </tr>
    </thead>
    @if (textbookList.length > 0) {
    <tbody>
      @for (data of textbookList; track data.id) {
      <tr>
        @if (filterObj.isCheck) {
        <td
          nzEllipsis
          nzLeft
          [nzChecked]="setOfCheckedId.has(data.id)"
          (nzCheckedChange)="onItemChecked(data.id, $event)"
        ></td>
        <td nzEllipsis (click)="toUrl(path + '/' + data.id)">
          {{ data?.get("code") }}
        </td>
        }@else {
        <td nzEllipsis nzLeft>
          {{ data?.get("code") }}
        </td>
        }
        <td nzEllipsis class="activeTd" (click)="toUrl(path + '/' + data.id)">
          {{ data?.get("title") || "-" }}
        </td>
        <td nzEllipsis>
          {{ data?.get("ISBN") || "-" }}
        </td>
        <td nzEllipsis>
          {{ data?.get("author") || "-" }}
        </td>
        <td nzEllipsis>
          {{ data?.get("lang") || "-" }}
        </td>
        <td nzEllipsis>
          {{ data?.get("majorPoniter") || "-" }}
        </td>
        <td nzEllipsis>
          {{ data?.get("editionUnit") || "-" }}
        </td>
        <td nzEllipsis>
          {{ data?.get("approval") || "-" }}
        </td>
        <td nzEllipsis>
          {{ data?.get("carrierShape") || "-" }}
        </td>
        <td nzEllipsis>
          {{ data?.get("department")?.get("name") || "-" }}
        </td>
        <td nzEllipsis nzRight>
          @if(manage){
          <button
            nz-button
            nz-dropdown
            [nzDropdownMenu]="menu"
            [nzPlacement]="'bottomLeft'"
          >
            <span nz-icon nzType="ellipsis" nzTheme="outline"></span>
          </button>
          <nz-dropdown-menu #menu="nzDropdownMenu">
            <ul nz-menu>
              @if(filterObj.btns.edit){
              <li nz-menu-item>
                <button
                  (click)="toUrl('/nav-author/manage/apply', { id: data.id })"
                  nz-button
                  nzType="link"
                  style="color: #231c1f"
                >
                  <span nz-icon nzType="edit" nzTheme="outline"></span>编辑教材
                </button>
              </li>
              }@if(filterObj.btns.review){
              <li nz-menu-item>
                <button
                  nz-button
                  (click)="
                    toUrl('/nav-admin/manage/textbook/details/' + data.id)
                  "
                  nzType="link"
                  style="color: #231c1f"
                >
                  <span nz-icon nzType="read" nzTheme="outline"></span>预览教材
                </button>
              </li>
              } @if(filterObj.btns.star){
              <li nz-menu-item>
                <button
                  (click)="updateStatus(data, true)"
                  nz-button
                  nzType="link"
                  style="color: #231c1f"
                >
                  <span nz-icon nzType="star" nzTheme="outline"></span>加入推荐
                </button>
              </li>
              } @if(filterObj.btns.export){
              <li nz-menu-item>
                <button
                  (click)="exportProcess(data)"
                  nz-button
                  nzType="link"
                  style="color: #231c1f"
                >
                  <span nz-icon nzType="export" nzTheme="outline"></span
                  >导出申报书及附件
                </button>
              </li>
              } @if(filterObj.btns.reject){
              <li nz-menu-item>
                <button
                  (click)="reject(data)"
                  nz-button
                  nzType="link"
                  style="color: #231c1f"
                >
                  <span nz-icon nzType="rollback" nzTheme="outline"></span
                  >退回教材
                </button>
              </li>
              } @if(filterObj.btns.remove){
              <li nz-menu-item>
                <button
                  (click)="updateStatus(data, false)"
                  nz-button
                  nzType="link"
                  style="color: #231c1f"
                >
                  <span
                    nz-icon
                    nzType="vertical-align-bottom"
                    nzTheme="outline"
                  ></span
                  >移除推荐
                </button>
              </li>
              } @if(filterObj.btns.submit){
              <li nz-menu-item>
                <button
                  nz-button
                  (click)="submit(data)"
                  nzType="link"
                  style="color: #231c1f"
                >
                  <span nz-icon nzType="upload" nzTheme="outline"></span
                  >提交教材
                </button>
              </li>
              } @if(filterObj.btns.isDelete){
              <li nz-menu-item>
                <button
                  (click)="del(data)"
                  nz-button
                  nzType="link"
                  style="color: #231c1f"
                >
                  <span nz-icon nzType="delete" nzTheme="outline"></span
                  >删除教材
                </button>
              </li>
              }
            </ul>
          </nz-dropdown-menu>
          } @else { - }
        </td>
      </tr>
      }
    </tbody>
    } }@else {
    <thead>
      <tr>
        @if (filterObj.isCheck) {
        <th
          nzWidth="50px"
          nzLeft
          [nzChecked]="checkedAll"
          [nzIndeterminate]="false"
          nzLabel="Select all"
          (nzCheckedChange)="onAllChecked($event)"
        ></th>
        @if (!filterObj?.btns?.submit) {
        <th nzEllipsis nzWidth="80px">申报编号</th>
        }
        <th nzEllipsis nzWidth="120px">教材名称</th>
        }@else if(filterObj?.btns?.submit){
        <th nzEllipsis nzLeft nzWidth="120px">教材名称</th>
        }@else {
        <th nzEllipsis nzWidth="80px" nzLeft>申报编号</th>
        <th nzEllipsis nzWidth="120px">教材名称</th>
        }
        <th nzEllipsis nzWidth="50px">册数</th>
        <th nzEllipsis nzWidth="120px">第一主编/作者</th>
        <th nzEllipsis nzWidth="80px">所属单位</th>
        <th nzEllipsis nzWidth="120px">所属本科专业</th>
        <th nzEllipsis nzWidth="80px">主要语种类型</th>
        <th nzEllipsis nzWidth="80px">ISBN</th>
        <th nzEllipsis nzWidth="120px">出版单位</th>
        <th nzEllipsis nzWidth="50px" nzRight>操作</th>
      </tr>
    </thead>
    @if (textbookList.length > 0) {
    <tbody>
      @for (data of textbookList; track data.id) {
      <tr>
        @if (filterObj.isCheck) {
        <td
          nzEllipsis
          nzLeft
          [nzChecked]="setOfCheckedId.has(data.id)"
          (nzCheckedChange)="onItemChecked(data.id, $event)"
        ></td>
        @if (!filterObj?.btns?.submit) {
        <td nzEllipsis class="activeTd" (click)="toUrl(path + '/' + data.id)">
          {{ data?.get("code") }}
        </td>
        }
        <td nzEllipsis class="activeTd" (click)="toUrl(path + '/' + data.id)">
          {{ data?.get("title") || "-" }}
        </td>
        }@else if(filterObj?.btns?.submit){
        <td
          nzEllipsis
          nzLeft
          class="activeTd"
          (click)="toUrl(path + '/' + data.id)"
        >
          {{ data?.get("title") || "-" }}
        </td>
        } @else {
        <td nzEllipsis nzLeft>
          {{ data?.get("code") }}
        </td>
        <td nzEllipsis class="activeTd" (click)="toUrl(path + '/' + data.id)">
          {{ data?.get("title") || "-" }}
        </td>
        }

        <td nzEllipsis>
          {{
            data?.get("type") == "单册"
              ? "单册"
              : data?.get("typeNumber") || "-"
          }}
        </td>
        <td nzEllipsis>
          {{ data?.get("author") || "-" }}
        </td>
        <td nzEllipsis>
          {{ data?.get("unit") || "-" }}
        </td>
        <td nzEllipsis>
          {{ data?.get("major")?.name || "-" }}
        </td>
        <td nzEllipsis>
          {{ data?.get("lang") || "-" }}
        </td>

        <td nzEllipsis>
          {{ data?.get("ISBN") || "-" }}
        </td>
        <td nzEllipsis>
          {{ data?.get("editionUnit") || "-" }}
        </td>
        <td nzEllipsis nzRight>
          @if(manage){
          <button
            nz-button
            nz-dropdown
            [nzDropdownMenu]="menu"
            [nzPlacement]="'bottomLeft'"
          >
            <span nz-icon nzType="ellipsis" nzTheme="outline"></span>
          </button>
          <nz-dropdown-menu #menu="nzDropdownMenu">
            <ul nz-menu>
              @if(filterObj.btns.edit){
              <li nz-menu-item>
                <button
                  (click)="toUrl('/nav-author/manage/apply', { id: data.id })"
                  nz-button
                  nzType="link"
                  style="color: #231c1f"
                >
                  <span nz-icon nzType="edit" nzTheme="outline"></span>编辑教材
                </button>
              </li>
              }@if(filterObj.btns.review){
              <li nz-menu-item>
                <button
                  nz-button
                  (click)="
                    toUrl('/nav-admin/manage/textbook/details/' + data.id)
                  "
                  nzType="link"
                  style="color: #231c1f"
                >
                  <span nz-icon nzType="read" nzTheme="outline"></span>预览教材
                </button>
              </li>
              } @if(filterObj.btns.star){
              <li nz-menu-item>
                <button
                  (click)="updateStatus(data, true)"
                  nz-button
                  nzType="link"
                  style="color: #231c1f"
                >
                  <span nz-icon nzType="star" nzTheme="outline"></span>加入推荐
                </button>
              </li>
              } @if(filterObj.btns.export){
              <li nz-menu-item>
                <button
                  (click)="exportProcess(data)"
                  nz-button
                  nzType="link"
                  style="color: #231c1f"
                >
                  <span nz-icon nzType="export" nzTheme="outline"></span
                  >导出申报书及附件
                </button>
              </li>
              } @if(filterObj.btns.reject){
              <li nz-menu-item>
                <button
                  (click)="reject(data)"
                  nz-button
                  nzType="link"
                  style="color: #231c1f"
                >
                  <span nz-icon nzType="rollback" nzTheme="outline"></span
                  >退回教材
                </button>
              </li>
              } @if(filterObj.btns.remove){
              <li nz-menu-item>
                <button
                  (click)="updateStatus(data, false)"
                  nz-button
                  nzType="link"
                  style="color: #231c1f"
                >
                  <span
                    nz-icon
                    nzType="vertical-align-bottom"
                    nzTheme="outline"
                  ></span
                  >移除推荐
                </button>
              </li>
              } @if(filterObj.btns.submit){
              <li nz-menu-item>
                <button
                  nz-button
                  (click)="submit(data)"
                  nzType="link"
                  style="color: #231c1f"
                >
                  <span nz-icon nzType="upload" nzTheme="outline"></span
                  >提交教材
                </button>
              </li>
              } @if(filterObj.btns.isDelete){
              <li nz-menu-item>
                <button
                  (click)="del(data)"
                  nz-button
                  nzType="link"
                  style="color: #231c1f"
                >
                  <span nz-icon nzType="delete" nzTheme="outline"></span
                  >删除教材
                </button>
              </li>
              }
              @if(filterObj.btns.restore){
                <li nz-menu-item>
                  <button
                    (click)="restore(data)"
                    nz-button
                    nzType="link"
                    style="color: #231c1f"
                  >
                    <span nz-icon nzType="undo" nzTheme="outline"></span
                    >恢复教材
                  </button>
                </li>
                }
            </ul>
          </nz-dropdown-menu>
          } @else { - }
        </td>
      </tr>
      }
    </tbody>
    } }
  </nz-table>
  @if (textbookList.length == 0) {
  <nz-empty nzNotFoundImage="/img/group-empty.png"></nz-empty>
  }
</div>
<!-- 全选操作：批量操作 -->
@if (filterObj.isCheck && setOfCheckedId.size) {
<div class="batch-toolbar-modal" [style.left]="'calc(50% - '+ calc+'px)'">
  <div class="batch-toolbar">
    <div class="styles_counter__18S08">
      <span>已选</span>
      <span class="styles_num__178Wa">{{ setOfCheckedId.size }}</span>
    </div>
    @if(filterObj.btns.reject){
    <div class="batch-toolbar-actions">
      <div class="ant-space ant-space-horizontal ant-space-align-center">
        <div class="ant-space-item" style="margin-right: 16px">
          <button nz-button nzType="text" (click)="reject()">
            <span nz-icon nzTheme="outline" nzType="rollback"></span>
            批量退回
          </button>
        </div>
      </div>
    </div>
    } @if(filterObj.btns.star){
    <div class="styles_cancel__AARoT">
      <button nz-button nzType="text" (click)="updateStatus(undefined, true)">
        <span nz-icon nzType="star" nzTheme="outline"></span>
        批量推荐
      </button>
    </div>
    } 
    @if(filterObj.btns.remove){
    <div class="batch-toolbar-actions">
      <div class="ant-space ant-space-horizontal ant-space-align-center">
        <div class="ant-space-item" style="margin-right: 16px">
          <button
            nz-button
            nzType="text"
            (click)="updateStatus(undefined, false)"
          >
            <span
              nz-icon
              nzType="vertical-align-bottom"
              nzTheme="outline"
            ></span>
            移除推荐
          </button>
        </div>
      </div>
    </div>
    }
    @if(filterObj.btns.export){
      <div class="styles_cancel__AARoT">
        <button nz-button nzType="text" (click)="exportProcess()">
          <span nz-icon nzType="export" nzTheme="outline"></span>
          批量导出
        </button>
      </div>
      } 
    @if(filterObj.btns.isDelete){
    <div class="batch-toolbar-actions">
      <div class="ant-space ant-space-horizontal ant-space-align-center">
        <div class="ant-space-item" style="margin-right: 16px">
          <button nz-button nzType="text" (click)="del()">
            <span nz-icon nzType="delete" nzTheme="outline"></span>
            删除
          </button>
        </div>
      </div>
    </div>
    } @if(filterObj.btns.submit){
    <div class="styles_cancel__AARoT">
      <button nz-button nzType="text" (click)="submit()">
        <span nz-icon nzType="upload" nzTheme="outline"></span>
        批量提交
      </button>
    </div>
    }
    @if(filterObj.btns.restore){
      <div class="batch-toolbar-actions">
        <div class="ant-space ant-space-horizontal ant-space-align-center">
          <div class="ant-space-item" style="margin-right: 16px">
            <button nz-button nzType="text" (click)="restore()">
              <span nz-icon nzType="undo" nzTheme="outline"></span>
              恢复教材
            </button>
          </div>
        </div>
      </div>
      } 
    <div class="styles_cancel__AARoT">
      <button nz-button nzType="text" (click)="onAllChecked(false)">
        取消选中
      </button>
    </div>
  </div>
</div>
}

<div class="loading" [hidden]="!showLoading">
  <nz-spin nzSimple [nzSize]="'large'"></nz-spin>
</div>
