// 角色管理mock数据
export const roleMockData = {
  // 角色列表
  list: [
    {
      id: 1,
      name: '管理员',
      code: 'admin',
      description: '系统全部功能的访问权限',
      permissions: ['首页', '商品', '订单', '用户', '营销', '内容', '数据', '财务', '设置'],
      permissions_text: '首页、商品、订单、用户、营销、内容、数据、财务、设置',
      remark: '拥有所有权限',
      status: 'normal',
      status_text: '正常',
      rules: [
        '1',
        '90',
        '901',
        '300',
        '113',
        '125',
        '400',
        '154',
        '171',
        '172',
        '500',
        '501',
        '502',
        '503',
        '600',
        '601',
        '700',
        '701',
        '702',
        '703',
        '800',
        '801',
        '900',
        '901',
        '902',
        '903',
        '1000',
        '1002',
      ],
      create_time: '2025-01-10 10:00:00',
      update_time: '2025-01-15 14:30:00',
    },
    {
      id: 2,
      name: '店长',
      code: 'manager',
      description: '店铺管理、订单管理等核心功能',
      permissions: ['商品', '订单', '营销', '数据'],
      permissions_text: '商品、订单、营销、数据',
      remark: '店铺运营权限',
      status: 'normal',
      status_text: '正常',
      rules: [
        { id: 2, checked: true },
        { id: 3, checked: true },
        { id: 5, checked: true },
        { id: 7, checked: true },
      ],
      create_time: '2025-01-10 11:00:00',
      update_time: '2025-01-14 16:20:00',
    },
    {
      id: 3,
      name: '财务',
      code: 'finance',
      description: '财务管理、数据查看权限',
      permissions: ['财务', '数据'],
      permissions_text: '财务、数据',
      remark: '财务相关权限',
      status: 'normal',
      status_text: '正常',
      rules: [],
      create_time: '2025-01-10 12:00:00',
      update_time: '2025-01-13 09:15:00',
    },
    {
      id: 4,
      name: '客服',
      code: 'service',
      description: '用户管理、订单查看权限',
      permissions: ['用户', '订单'],
      permissions_text: '用户、订单',
      remark: '客服支持权限',
      status: 'normal',
      status_text: '正常',
      rules: [],
      create_time: '2025-01-11 09:30:00',
      update_time: '2025-01-12 15:45:00',
    },
    {
      id: 5,
      name: '运营',
      code: 'operation',
      description: '营销活动、内容管理权限',
      permissions: ['营销', '内容', '数据'],
      permissions_text: '营销、内容、数据',
      remark: '运营推广权限',
      status: 'normal',
      status_text: '正常',
      rules: [],
      create_time: '2025-01-11 14:20:00',
      update_time: '2025-01-14 11:30:00',
    },
    {
      id: 6,
      name: '小编',
      code: 'editor',
      description: '内容管理权限',
      permissions: ['内容'],
      permissions_text: '内容',
      remark: '内容编辑权限',
      status: 'normal',
      status_text: '正常',
      rules: [],
      create_time: '2025-01-12 10:15:00',
      update_time: '2025-01-13 16:20:00',
    },
    {
      id: 7,
      name: '统计员',
      code: 'analyst',
      description: '数据查看和分析权限',
      permissions: ['数据'],
      permissions_text: '数据',
      remark: '数据分析权限',
      status: 'disabled',
      status_text: '禁用',
      rules: [],
      create_time: '2025-01-12 15:30:00',
      update_time: '2025-01-14 10:45:00',
    },
    {
      id: 8,
      name: '仓库管理',
      code: 'warehouse',
      description: '商品库存管理权限',
      permissions: ['商品', '订单'],
      permissions_text: '商品、订单',
      remark: '仓库管理权限',
      status: 'normal',
      status_text: '正常',
      rules: [],
      create_time: '2025-01-13 08:45:00',
      update_time: '2025-01-15 12:10:00',
    },
  ],

  // 获取列表数据
  getList(params = {}) {
    const { page = 1, size = 10, name = '', status = 'all' } = params;

    let filteredData = [...this.list];

    // 搜索过滤
    if (name) {
      filteredData = filteredData.filter(
        (item) =>
          item.name.toLowerCase().includes(name.toLowerCase()) ||
          item.description.toLowerCase().includes(name.toLowerCase()),
      );
    }
    if (status && status !== 'all') {
      filteredData = filteredData.filter((item) => item.status === status);
    }

    // 分页
    const total = filteredData.length;
    const startIndex = (page - 1) * size;
    const endIndex = startIndex + size;
    const data = filteredData.slice(startIndex, endIndex);

    return {
      code: '200',
      message: '操作成功',
      data: {
        list: data,
        total: total,
        pageNum: page,
        pageSize: size,
        pages: Math.ceil(total / size),
        size: data.length,
        startRow: startIndex + 1,
        endRow: startIndex + data.length,
        hasNextPage: page < Math.ceil(total / size),
        hasPreviousPage: page > 1,
        isFirstPage: page === 1,
        isLastPage: page >= Math.ceil(total / size),
        firstPage: 1,
        lastPage: Math.ceil(total / size),
        navigatePages: 8,
        navigatepageNums: [],
        navigateFirstPage: 1,
        navigateLastPage: Math.ceil(total / size),
        nextPage: page < Math.ceil(total / size) ? page + 1 : 0,
        prePage: page > 1 ? page - 1 : 0,
      },
    };
  },

  // 获取详情数据
  getDetail(id) {
    const item = this.list.find((item) => item.id == id);
    if (!item) {
      return {
        code: '500',
        message: '记录不存在',
        data: null,
      };
    }

    return {
      code: '200',
      message: '操作成功',
      data: item,
    };
  },

  // 创建角色
  create(data) {
    const newRole = {
      id: Date.now(),
      ...data,
      create_time: new Date().toLocaleString('zh-CN'),
      update_time: new Date().toLocaleString('zh-CN'),
    };
    this.list.unshift(newRole);

    return {
      code: '200',
      message: '创建成功',
      data: newRole,
    };
  },

  // 更新角色
  update(id, data) {
    const index = this.list.findIndex((item) => item.id == id);
    if (index === -1) {
      return {
        code: '500',
        message: '记录不存在',
        data: null,
      };
    }

    this.list[index] = {
      ...this.list[index],
      ...data,
      update_time: new Date().toLocaleString('zh-CN'),
    };

    return {
      code: '200',
      message: '更新成功',
      data: this.list[index],
    };
  },

  // 删除角色
  delete(id) {
    const index = this.list.findIndex((item) => item.id == id);
    if (index === -1) {
      return {
        code: '500',
        message: '记录不存在',
        data: null,
      };
    }

    this.list.splice(index, 1);
    return {
      code: '200',
      message: '删除成功',
      data: null,
    };
  },
};
