export function useAttendancePermission() {
  const { hasPermission } = usePermission();
  const { permissions } = useCleaningPermission();
  const { userAppRole } = useLocalSetup();

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

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

  const canManageAttendanceSettings = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(
      userAppRole.value,
      permissions,
      "attendance-mgmt",
      "manage-attendance-settings"
    );
  });

  const canViewOwnAttendance = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(
      userAppRole.value,
      permissions,
      "my-attendance",
      "see-own-attendance"
    );
  });

  const canCheckInOut = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(
      userAppRole.value,
      permissions,
      "my-attendance",
      "check-in-out"
    );
  });

  return {
    canViewAllAttendance,
    canViewAttendanceDetails,
    canManageAttendanceSettings,
    canViewOwnAttendance,
    canCheckInOut,
  };
}
