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

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

  const canCreateEquipmentItem = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(
      userAppRole.value,
      permissions,
      "checkout-item-mgmt",
      "create-checkout"
    );
  });

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

  const canApproveEquipmentItem = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(
      userAppRole.value,
      permissions,
      "checkout-item-mgmt",
      "approve-checkout"
    );
  });

  const canDisapproveEquipmentItem = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(
      userAppRole.value,
      permissions,
      "checkout-item-mgmt",
      "disapprove-checkout"
    );
  });

  const canViewEquipmentItemDetails = computed(() => {
    if (!userAppRole.value) return true;
    if (userAppRole.value.permissions.includes("*")) return true;
    return hasPermission(
      userAppRole.value,
      permissions,
      "checkout-item-mgmt",
      "view-checkout-details"
    );
  });

  return {
    canViewAllEquipmentItems,
    canCreateEquipmentItem,
    canUpdateEquipmentItem,
    canApproveEquipmentItem,
    canDisapproveEquipmentItem,
    canViewEquipmentItemDetails,
  };
}
