import { useMemo } from 'react';
import { usePractitionerServiceContext, useAuthServiceContext } from '../../../../../services';
import { AppSpinner } from '../../../../../components';
import { roleForOrganization } from '../../../../../utils/practitionerRoleOrgScope';
import EditPractitionerRolePage from './PractitionerRolePage/PractitionerRolePage.tsx';
// The Roles & Specialties tab is the practitioner's identity-role form.
//
//
// THIS FILE'S OWN HEADER USED TO SAY "a practitioner holds ONE PractitionerRole", AND THAT WAS THE
// BUG WRITTEN DOWN. It is true PER ORGANIZATION and false across them: a `PractitionerRole` means
// "this person works at THIS organization", so a practitioner at two practices holds two of them.
//
// The old `roles?.[0]` therefore opened whichever role happened to come back first. For a multi-org
// practitioner viewed in Org B's context that can be ORG A'S ROLE - so an admin at B edits A's record
// believing it is their own. Scope to the organization in view, always.
const PractitionerRolesPage = () => {
const { practitionerState } = usePractitionerServiceContext();
const { currentOrganization } = useAuthServiceContext();
const currentOrganizationId = currentOrganization?.id;
const orgRoleId = useMemo(
() => roleForOrganization(practitionerState?.roles, currentOrganizationId)?.id,
[practitionerState?.roles, currentOrganizationId],
);
if (!practitionerState) {
return ;
}
// 'new' ONLY when this practitioner genuinely has no role AT THIS ORGANIZATION - which is the
// correct outcome for someone who works elsewhere and is being added here. It is reached by the
// org filter finding nothing, never by an unfiltered list being empty, so it can no longer stand
// in for "we picked someone else's role".
return ;
};
export default PractitionerRolesPage;