{#if loading}
{:else if loadError} {:else} {#if isOwnerMember} {:else if !canEdit} {/if}
{i18n.t("settings.permissions.roleHeading")}

{i18n.t("settings.permissions.roleHint")}

{#each PERMISSION_ROLES as role (role.id)} {@const selected = activeRole === role.id} {/each}
{#if activeRole === CUSTOM_ROLE_ID}

{roleLabel(CUSTOM_ROLE_ID)} — {roleDescription(CUSTOM_ROLE_ID)}

{/if}
{#if advancedOpen}

{i18n.t("settings.permissions.fineTuneHint")}

{#if !readOnly}
{/if}
{#if visibleSections.length === 0}

{i18n.t("settings.permissions.noMatches")}

{/if} {#each visibleSections as section (section.id)}

{sectionLabel(section.id)}

{#if searching} {#each section.entries as entry (entry.key)} {@const allowed = entryAllowed(entry)} {@const locked = !entry.plan_allowed}
toggle(entry.key, !allowed)} /> {#if locked} {i18n.t("settings.permissions.planLocked")} {/if}
{/each} {:else} {#each sectionPermissionTree(section) as node (node.root.key)} {@const root = node.root} {@const allowed = entryAllowed(root)} {@const locked = !root.plan_allowed} {@const hasChildren = node.children.length > 0} {@const childrenOpen = Boolean(fineTuneOpen[root.key])}
toggle(root.key, !allowed)} /> {#if locked} {i18n.t("settings.permissions.planLocked")} {/if} {#if hasChildren} {/if}
{#if hasChildren && childrenOpen}
{#each node.children as entry (entry.key)} {@const childAllowed = entryAllowed(entry)} {@const childLocked = !entry.plan_allowed}
toggle(entry.key, !childAllowed)} /> {#if childLocked} {i18n.t("settings.permissions.planLocked")} {/if}
{/each}
{/if}
{/each} {/if}
{/each}
{/if}
{/if}
{#snippet footer()} {#if !readOnly} {/if} {/snippet}