import { Loader2 } from "lucide-react";
import clsx from "clsx";
import { Switch } from "../../components/ui/switch";
import { useMyProxies } from "../../hooks/useMyProxies.tsx";
import type { ActingAsTarget } from "../../services/AuthService.tsx";
import { TierChoices } from "./TierChoices";
import { BILLING_DEPENDENCY_NOTE, CHANGE_TIER_DESCRIPTIONS } from "./tierWords";
import "./careAccess.css";
interface OwnLinkAccessProps {
/** The link the signed-in person is acting through; the card on screen is this link. */
link: ActingAsTarget;
showHead?: boolean;
}
// A switched-in helper reading their own link. The grants read is the account owner's, so the helper's
// own effective authority comes from their own /my-proxies row, read-only.
const OwnLinkAccess = ({ link, showHead = true }: OwnLinkAccessProps) => {
const { proxies, isLoading, error, refetch } = useMyProxies();
const own = proxies.find(
(proxy) => proxy.relatedPersonId === link.relatedPersonId && proxy.subjectPatientId === link.subjectPatientId,
);
// A missing or unresolved row has no tier to show; careTier then is only a fail-closed default. A row
// kept from before a failed refresh is stale.
const shown = own && !own.tierUnresolved && !error ? own : undefined;
const subject = link.subjectName || "this person";
const problem = isLoading
? null
: error || !own
? "We couldn't load what you may do for " + subject + "."
: own.tierUnresolved
? "Your access for " + subject + " is still being set up, so it can't be shown yet."
: null;
const spinner = isLoading && ;
const id = link.relatedPersonId;
return (
{showHead && (
What you can do{spinner}
)}
{!showHead &&
What you may do{spinner}
}
{problem && (
{problem}
)}
undefined}
disabled
/>
{shown && (
Separately
{shown.careTier === "assist-only" && (
)}
{BILLING_DEPENDENCY_NOTE}
)}
This is your own access. It can't be changed here.