export function useAreaPermission() {
  const { hasPermission } = usePermission();
  const { permissions } = useCleaningPermission();

  const { userAppRole } = useLocalSetup();

  const canViewAreas = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(userAppRole.value, permissions, "area-mgmt", "see-all-areas");
  });

  const canCreateArea = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(userAppRole.value, permissions, "area-mgmt", "add-area");
  });

  const canUpdateArea = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(userAppRole.value, permissions, "area-mgmt", "update-area");
  });

  const canViewAreaDetails = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(userAppRole.value, permissions, "area-mgmt", "see-area-details");
  });

  const canImportArea = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(userAppRole.value, permissions, "area-mgmt", "import-areas");
  });

  const canDeleteArea = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(userAppRole.value, permissions, "area-mgmt", "delete-area");
  });

  return {
    canViewAreas,
    canCreateArea,
    canUpdateArea,
    canViewAreaDetails,
    canImportArea,
    canDeleteArea,
  };
}
