from ..policies import PARTICIPANT_POLICY
from ploneintranet.core import _
from ploneintranet.workspace.browser.workspace import BaseWorkspaceView


class WorkspaceMemberPicker(BaseWorkspaceView):
    """
    A modal with a user picker to select new members
    """


class WorkspaceChangeRole(BaseWorkspaceView):
    """
    A modal for changing the roles of users
    """

    def roles(self):
        ws_policy = self.context.participant_policy
        title = _(
            "workspace_default_role",
            default="Default role for this workspace (${role})",
            mapping={"role": PARTICIPANT_POLICY[ws_policy]["title"]},
        )
        yield {"id": ws_policy.title(), "title": title}
        for policy_id, policy_info in PARTICIPANT_POLICY.items():
            if policy_id == ws_policy:
                continue
            if policy_info.get("exclude_from_ui", False):
                continue
            yield {"id": policy_id.title(), "title": policy_info["title"]}
        yield {"id": "Admins", "title": _("Workspace Administrator")}
