export function useAppAuth() {
  function hasPermission(permission: string) {
    const appSettingsStore = useAppSettingsStore()
    const appAccountStore = useAppAccountStore()
    if (appSettingsStore.settings.app.account.auth) {
      return appAccountStore.permissions.includes(permission)
    }
    else {
      return true
    }
  }

  function auth(value: string | string[]) {
    let auth
    if (typeof value === 'string') {
      auth = value !== '' ? hasPermission(value) : true
    }
    else {
      auth = value.length > 0 ? value.some(item => hasPermission(item)) : true
    }
    return auth
  }

  function authAll(value: string[]) {
    return value.length > 0 ? value.every(item => hasPermission(item)) : true
  }

  return {
    auth,
    authAll,
  }
}
