import { Component, OnInit} from '@angular/core';
import { CompNavComponent } from '../comp-nav/comp-nav.component';
import {DomSanitizer} from '@angular/platform-browser';
import { RouterOutlet, Router } from '@angular/router';
import { CommonCompModule } from '../../services/common.modules';
import { MatIconRegistry, MatIconModule } from '@angular/material/icon';
import { textbookServer } from '../../services/textbook';
@Component({
  selector: 'app-comp-manage',
  standalone: true,
  imports: [CompNavComponent, RouterOutlet, CommonCompModule,MatIconModule],
  templateUrl: './comp-manage.component.html',
  styleUrls: ['./comp-manage.component.scss'],
})
export class CompManageComponent implements OnInit {
  MENU_ICON:string = `<svg width="18" height="20" viewBox="0 0 18 20" fill="none" xmlns="http://www.w3.org/2000/svg">
  <path d="M18 2H4C3.46957 2 2.96086 2.21071 2.58579 2.58579C2.21071 2.96086 2 3.46957 2 4C2 4.53043 2.21071 5.03914 2.58579 5.41421C2.96086 5.78929 3.46957 6 4 6H18V19C18 19.2652 17.8946 19.5196 17.7071 19.7071C17.5196 19.8946 17.2652 20 17 20H4C2.93913 20 1.92172 19.5786 1.17157 18.8284C0.421427 18.0783 0 17.0609 0 16V4C0 2.93913 0.421427 1.92172 1.17157 1.17157C1.92172 0.421427 2.93913 0 4 0H17C17.2652 0 17.5196 0.105357 17.7071 0.292893C17.8946 0.48043 18 0.734783 18 1V2Z" fill="url(#paint0_linear_5_11023)"/>
  <defs>
  <linearGradient id="paint0_linear_5_11023" x1="9" y1="-2.21282e-07" x2="25.5" y2="40" gradientUnits="userSpaceOnUse">
  <stop stop-color="#E04860"/>
  <stop offset="1" stop-color="#E99306"/>
  </linearGradient>
  </defs>
  </svg>
  `
  optionsMap: any = {
    "国家级管理员":[
      {
        name:'教材管理',
        id:'1',
        child:[
          {
            name:'报送合集',
            path:"/nav-admin/manage/collection",
            id:'1-1',
          },
          {
            name:'全部材料',
            id:'1-2',
          },
        ]
      },
      {
        name:'用户管理',
        id:'2',
        child:[
          {
            name:'用户审核',
            id:'2-1',
          },
          {
            name:'注册账户',
            path:"/nav-admin/manage/user",
            id:'2-2',
          },
          {
            name:'用户组管理',
            path:"/nav-admin/manage/role",
            id:'2-3',
          },
        ]
      },
      {
        name:'品牌化',
        id:'3',
        child:[
          {
            name:'登录框',
            id:'3-1',
          },
          {
            name:'消息设置',
            id:'3-2',
          },
        ]
      },
      {
        name:'字段管理',
        id:'4',
      },
    ],
    "省级教育行政部门":[
      {
        name:'省内合集',
        id:'1',
      },
    ],
    "流程管理员登录":[
      {
        name:'报送流程',
        id:'1',
      },
      {
        name:'用户管理',
        id:'2',
        child:[
          {
            name:'用户列表',
            id:'2-1',
          },
          {
            name:'用户组管理',
            id:'2-2',
          },
          {
            name:'邀请注册',
            id:'2-3',
          },
        ]
      }
    ],
    "省属高校联系人":[
      {
        name:'校内空间',
        id:'1',
      },
      {
        name:'用户管理',
        id:'2',
        child:[
          {
            name:'邀请注册',
            id:'2-1',
          },
          {
            name:'用户列表',
            id:'2-2',
          },
        ]
      },
      {
        name:'个人信息',
        id:'3',
      },
    ],
    "教材评审组成员":[
      {
        name:'报送流程',
        id:'1',
        path: '/nav-review/home/apply',
      },
      {
        name:'个人信息',
        id:'2',
        path: '/nav-review/profile',
      },
    ],
    "作者/教师/主编":[
      {
        name: '个人空间',
        id: '1',
        path: '/nav-author/manage/space',
      },
      {
        name: '回收站',
        id: '2',
        path: '/nav-author/manage/recycle',
        params: {
          isDeleted: true,
        },
      },
    ],
  } 
  active: string = localStorage.getItem('active') || '1';
  isCollapsed:boolean = false;

  constructor(
    public router: Router,
    public textbook:textbookServer,
    iconRegistry: MatIconRegistry, 
    sanitizer: DomSanitizer
  ) {
    iconRegistry.addSvgIconLiteral('menu', sanitizer.bypassSecurityTrustHtml(this.MENU_ICON));
   }

  ngOnInit() {
  }
  toggleCollapsed(): void {
    this.isCollapsed = !this.isCollapsed;
  }
  toUrl(child: any) {
    let cateid = child.id;
    this.active = cateid;
    localStorage.setItem('active', cateid);
    console.log(child);
    if (child.params) {
      this.router.navigate([child.path, child?.params]);
    } else {
      this.router.navigate([child.path]);
    }
  }
}
