/**
 * 全局分页大小管理
 * 默认 10 条/页，用户可在系统设置中修改，存储在 localStorage
 */

const STORAGE_KEY = 'hr-page-size'

export const DEFAULT_PAGE_SIZE = 10

/** 获取当前分页大小 */
export function getPageSize(): number {
  const val = localStorage.getItem(STORAGE_KEY)
  const n = val ? parseInt(val, 10) : NaN
  return Number.isFinite(n) && n > 0 ? n : DEFAULT_PAGE_SIZE
}

/** 设置分页大小 */
export function setPageSize(size: number): void {
  localStorage.setItem(STORAGE_KEY, String(size))
  window.dispatchEvent(new CustomEvent('page-size-changed'))
}
