{
  "component": {
    "id": "roles-permissions",
    "name": "Roles and permissions",
    "tier": "pro",
    "exampleId": "roles-permissions",
    "access": "pro",
    "requiresAuthorization": true
  },
  "source": {
    "demoModule": "src/roles-permissions-demo.tsx",
    "exportName": "RolesPermissionsDemo",
    "sha256": "399d2a813158f423a5affca4a544f4d75fa50a3ae4c7b73f286ebd698cce597b",
    "helperImports": [],
    "directComponentImports": [
      "roles-permissions"
    ],
    "sampleBoundary": "Existing local demo fixture with fictional data and callbacks. No live service, customer data, access key, or Pro source is included."
  },
  "install": {
    "command": "npx shadcn@latest add @tidal-pro/roles-permissions",
    "registryUrl": "https://tidalui.com/r/pro/roles-permissions.json",
    "namespace": "@tidal-pro",
    "access": "pro",
    "sourceDelivery": "server-gated",
    "requiresAuthorization": true,
    "tokenSource": "local-env",
    "tokenEnvName": "TIDALUI_TOKEN",
    "cli": {
      "package": "shadcn",
      "requested": "latest"
    }
  },
  "installPlan": [
    {
      "order": 1,
      "kind": "primary",
      "dependency": "@tidal-pro/roles-permissions",
      "purpose": "component",
      "command": "npx shadcn@latest add @tidal-pro/roles-permissions",
      "registryUrl": "https://tidalui.com/r/pro/roles-permissions.json",
      "access": "pro",
      "sourceDelivery": "server-gated",
      "requiresAuthorization": true
    }
  ],
  "imports": {
    "componentPath": "components/ui/roles-permissions.tsx",
    "exports": [
      "TidalPermissionMember",
      "TidalPermissionRole",
      "TidalRolesPermissions"
    ],
    "stylesheets": [
      "components/ui/tidal.css",
      "components/ui/roles-permissions.css"
    ],
    "scopeClass": "tidal-scope"
  },
  "dependencies": {
    "npm": [],
    "registry": [],
    "additionalRegistry": [],
    "installClosure": [
      "roles-permissions"
    ],
    "css": [
      "components/ui/tidal.css",
      "components/ui/roles-permissions.css"
    ],
    "demoCss": [],
    "consumerOwned": [
      "react",
      "react-dom"
    ]
  },
  "files": {
    "sourceFile": "/examples/roles-permissions.tsx",
    "demoStyles": [],
    "inlinedDemoStyles": [
      "src/roles-permissions-demo.css"
    ],
    "assets": []
  },
  "example": {
    "language": "tsx",
    "source": "\"use client\";\n\nimport \"./components/ui/tidal.css\";\n\nimport { useLayoutEffect, useMemo, useState } from \"react\";\n\nimport { TidalRolesPermissions, type TidalPermissionMember, type TidalPermissionRole } from \"./components/ui/roles-permissions\";\n\nimport \"./components/ui/roles-permissions.css\";\n\nfunction tidalExampleAvatarDataUri(seed: unknown) {\n  const text = String(seed).replace(/[^a-z0-9]/gi, \"\").slice(-2) || \"UI\";\n  const palette = [\"#333333\", \"#555555\", \"#777777\", \"#999999\", \"#bbbbbb\"];\n  const color = palette[Array.from(text).reduce((sum, character) => sum + character.charCodeAt(0), 0) % palette.length];\n  const svg = `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 96 96\"><rect width=\"96\" height=\"96\" rx=\"48\" fill=\"${color}\"/><circle cx=\"48\" cy=\"38\" r=\"17\" fill=\"white\" fill-opacity=\".92\"/><path d=\"M18 92c3-22 15-34 30-34s27 12 30 34\" fill=\"white\" fill-opacity=\".92\"/></svg>`;\n  return `data:image/svg+xml,${encodeURIComponent(svg)}`;\n}\n\nfunction tidalExampleImageDataUri(label: string) {\n  const safeLabel = label.replace(/[<>&]/g, \"\").slice(0, 28) || \"Sample image\";\n  const svg = `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 1200 675\"><defs><linearGradient id=\"g\" x1=\"0\" x2=\"1\" y1=\"0\" y2=\"1\"><stop stop-color=\"#171717\"/><stop offset=\"1\" stop-color=\"#555555\"/></linearGradient></defs><rect width=\"1200\" height=\"675\" fill=\"url(#g)\"/><circle cx=\"950\" cy=\"100\" r=\"260\" fill=\"white\" fill-opacity=\".08\"/><text x=\"80\" y=\"570\" fill=\"white\" font-family=\"system-ui,sans-serif\" font-size=\"64\" font-weight=\"700\">${safeLabel}</text></svg>`;\n  return `data:image/svg+xml,${encodeURIComponent(svg)}`;\n}\n\nconst tidalExampleStyles = \".tidal-scope .roles-permissions-demo,\\n.tidal-scope .roles-permissions-demo * {\\n  box-sizing: border-box;\\n}\\n\\n.tidal-scope .roles-permissions-demo {\\n  display: grid;\\n  width: min(100%, 920px);\\n  min-width: 0;\\n  gap: 12px;\\n}\\n\\n.tidal-scope .roles-permissions-demo-actions {\\n  display: flex;\\n  min-width: 0;\\n  align-items: center;\\n  justify-content: space-between;\\n  gap: 12px;\\n}\\n\\n.tidal-scope .roles-permissions-demo-actions output {\\n  min-width: 0;\\n  color: var(--t-muted);\\n  font-size: 11px;\\n  line-height: 1.4;\\n  overflow-wrap: anywhere;\\n}\\n\\n.tidal-scope .roles-permissions-demo-actions button {\\n  display: inline-flex;\\n  min-width: 44px;\\n  min-height: 44px;\\n  flex: 0 0 auto;\\n  align-items: center;\\n  justify-content: center;\\n  padding: 8px 13px;\\n  border: 1px solid var(--t-border);\\n  border-radius: var(--t-radius-control);\\n  color: var(--t-ink);\\n  background: var(--t-surface);\\n  font: inherit;\\n  font-size: 11px;\\n  font-weight: 720;\\n  cursor: pointer;\\n  transition:\\n    color 160ms,\\n    background-color 160ms,\\n    transform 140ms var(--t-ease-out);\\n}\\n\\n.tidal-scope .roles-permissions-demo-actions button:hover {\\n  color: var(--t-surface);\\n  background: var(--t-ink);\\n}\\n\\n.tidal-scope .roles-permissions-demo-actions button:active {\\n  transform: scale(0.97);\\n}\\n\\n.tidal-scope .roles-permissions-demo-actions button:focus-visible {\\n  outline: 2px solid var(--t-ink);\\n  outline-offset: 3px;\\n}\\n\\n@media (max-width: 520px) {\\n  .tidal-scope .roles-permissions-demo-actions {\\n    display: grid;\\n  }\\n\\n  .tidal-scope .roles-permissions-demo-actions button {\\n    width: 100%;\\n  }\\n}\\n\\n@media (prefers-reduced-motion: reduce) {\\n  .tidal-scope .roles-permissions-demo-actions button {\\n    transition: none;\\n  }\\n\\n  .tidal-scope .roles-permissions-demo-actions button:active {\\n    transform: none;\\n  }\\n}\";\n\nconst ROLES: readonly TidalPermissionRole[] = [\n  {\n    id: \"admin\",\n    label: \"Admin\",\n    description: \"Workspace controls and publishing.\",\n  },\n  {\n    id: \"editor\",\n    label: \"Editor\",\n    description: \"Creates and reviews project work.\",\n  },\n  {\n    id: \"viewer\",\n    label: \"Viewer\",\n    description: \"Reads shared project work.\",\n  },\n];\n\nconst PERMISSIONS = [\n  {\n    id: \"view-projects\",\n    groupId: \"content\",\n    groupLabel: \"Project work\",\n    label: \"View projects\",\n    description: \"Open shared project records.\",\n  },\n  {\n    id: \"edit-projects\",\n    groupId: \"content\",\n    groupLabel: \"Project work\",\n    label: \"Edit projects\",\n    description: \"Change notes and milestones.\",\n  },\n  {\n    id: \"publish-projects\",\n    groupId: \"content\",\n    groupLabel: \"Project work\",\n    label: \"Publish projects\",\n    description: \"Move approved work to published.\",\n  },\n  {\n    id: \"manage-members\",\n    groupId: \"workspace\",\n    groupLabel: \"Workspace\",\n    label: \"Manage members\",\n    description: \"Change sample member assignments.\",\n  },\n  {\n    id: \"review-billing\",\n    groupId: \"workspace\",\n    groupLabel: \"Workspace\",\n    label: \"Review billing\",\n    description: \"Read the sample billing summary.\",\n  },\n] as const;\n\nconst INITIAL_GRANTS: Readonly<Record<string, readonly string[]>> = {\n  admin: [\n    \"view-projects\",\n    \"edit-projects\",\n    \"publish-projects\",\n    \"manage-members\",\n    \"review-billing\",\n  ],\n  editor: [\"edit-projects\", \"publish-projects\"],\n  viewer: [],\n};\n\nconst INITIAL_MEMBERS: readonly TidalPermissionMember[] = [\n  {\n    id: \"ava\",\n    name: \"Ava Morgan\",\n    description: \"Project lead\",\n    roleId: \"admin\",\n    avatar: (\n      <img\n        src={tidalExampleAvatarDataUri(\"01\")}\n        alt=\"Ava Morgan\"\n        width=\"36\"\n        height=\"36\"\n      />\n    ),\n  },\n  {\n    id: \"noah\",\n    name: \"Noah Park\",\n    description: \"Design reviewer\",\n    roleId: \"editor\",\n    avatar: (\n      <img\n        src={tidalExampleAvatarDataUri(\"02\")}\n        alt=\"Noah Park\"\n        width=\"36\"\n        height=\"36\"\n      />\n    ),\n  },\n  {\n    id: \"mila\",\n    name: \"Mila Santos\",\n    description: \"Guest reviewer\",\n    roleId: \"viewer\",\n    avatar: (\n      <img\n        src={tidalExampleAvatarDataUri(\"03\")}\n        alt=\"Mila Santos\"\n        width=\"36\"\n        height=\"36\"\n      />\n    ),\n  },\n];\n\nfunction copyGrants(source: Readonly<Record<string, readonly string[]>>) {\n  return Object.fromEntries(\n    Object.entries(source).map(([roleId, permissionIds]) => [\n      roleId,\n      [...permissionIds],\n    ]),\n  );\n}\n\nexport function RolesPermissionsDemo() {\n  const [view, setView] = useState<\"matrix\" | \"list\">(\"matrix\");\n  const [grants, setGrants] = useState<Record<string, string[]>>(() =>\n    copyGrants(INITIAL_GRANTS),\n  );\n  const [members, setMembers] = useState<TidalPermissionMember[]>(() =>\n    INITIAL_MEMBERS.map((member) => ({ ...member })),\n  );\n  const [status, setStatus] = useState(\"Review the current sample access map.\");\n  const roles = useMemo(\n    () =>\n      ROLES.map((role) => ({\n        ...role,\n        memberCount: `${members.filter((member) => member.roleId === role.id).length} assigned`,\n      })),\n    [members],\n  );\n\n  useLayoutEffect(() => {\n    const media = window.matchMedia(\"(max-width: 599px)\");\n    const syncView = () => setView(media.matches ? \"list\" : \"matrix\");\n    syncView();\n    media.addEventListener(\"change\", syncView);\n    return () => media.removeEventListener(\"change\", syncView);\n  }, []);\n\n  const setPermission = (\n    roleId: string,\n    permissionId: string,\n    granted: boolean,\n  ) => {\n    setGrants((current) => {\n      const next = new Set(current[roleId] ?? []);\n      if (granted) next.add(permissionId);\n      else next.delete(permissionId);\n      return { ...current, [roleId]: [...next] };\n    });\n    const role = ROLES.find((candidate) => candidate.id === roleId);\n    const permission = PERMISSIONS.find(\n      (candidate) => candidate.id === permissionId,\n    );\n    setStatus(\n      `${String(permission?.label ?? permissionId)} ${granted ? \"enabled\" : \"disabled\"} for ${String(role?.label ?? roleId)}.`,\n    );\n  };\n\n  return (\n    <div className=\"roles-permissions-demo\">\n      <TidalRolesPermissions\n        title=\"Workspace access\"\n        description=\"Assign sample roles and inspect each role’s effective permissions.\"\n        roles={roles}\n        permissions={PERMISSIONS}\n        grants={grants}\n        inheritedGrants={{\n          editor: [\"view-projects\"],\n          viewer: [\"view-projects\"],\n        }}\n        members={members}\n        view={view}\n        onViewChange={(next) => {\n          setView(next);\n          setStatus(\n            `${next === \"matrix\" ? \"Matrix\" : \"Role list\"} view selected.`,\n          );\n        }}\n        onPermissionChange={(roleId, permissionId, granted) =>\n          setPermission(roleId, permissionId, granted)\n        }\n        onGroupChange={(roleId, _groupId, granted, permissionIds) => {\n          setGrants((current) => {\n            const next = new Set(current[roleId] ?? []);\n            permissionIds.forEach((permissionId) => {\n              if (granted) next.add(permissionId);\n              else next.delete(permissionId);\n            });\n            return { ...current, [roleId]: [...next] };\n          });\n          const role = ROLES.find((candidate) => candidate.id === roleId);\n          setStatus(\n            `${permissionIds.length} editable permissions ${granted ? \"enabled\" : \"disabled\"} for ${String(role?.label ?? roleId)}.`,\n          );\n        }}\n        onMemberRoleChange={(memberId, roleId) => {\n          setMembers((current) =>\n            current.map((member) =>\n              member.id === memberId ? { ...member, roleId } : member,\n            ),\n          );\n          const member = members.find((candidate) => candidate.id === memberId);\n          const role = ROLES.find((candidate) => candidate.id === roleId);\n          setStatus(\n            `${String(member?.name ?? memberId)} assigned to ${String(role?.label ?? roleId)}.`,\n          );\n        }}\n        footer={\n          <span>\n            Sample permissions. Changes stay in this preview and do not enforce\n            access.\n          </span>\n        }\n      />\n      <div className=\"roles-permissions-demo-actions\">\n        <output aria-live=\"polite\">{status}</output>\n        <button\n          type=\"button\"\n          onClick={() => {\n            setGrants(copyGrants(INITIAL_GRANTS));\n            setMembers(INITIAL_MEMBERS.map((member) => ({ ...member })));\n            setView(\n              window.matchMedia(\"(max-width: 599px)\").matches\n                ? \"list\"\n                : \"matrix\",\n            );\n            setStatus(\"Sample access map reset.\");\n          }}\n        >\n          Reset sample\n        </button>\n      </div>\n    </div>\n  );\n}\n\nexport default function AgentExample() {\n  return (\n    <div className=\"tidal-scope\" data-theme=\"light\" dir=\"ltr\">\n      <style>{tidalExampleStyles}</style>\n      <RolesPermissionsDemo />\n    </div>\n  );\n}\n",
    "sourceFile": "/examples/roles-permissions.tsx",
    "fixtureData": "Existing demo fixture data only; replace with consumer-owned data before production use."
  },
  "controlledState": [
    {
      "prop": "members",
      "type": "inferred-from-existing-demo",
      "initial": "(",
      "setter": "setMembers",
      "proposalCanBeRejected": false
    },
    {
      "prop": "view",
      "type": "inferred-from-existing-demo",
      "initial": "\"matrix\"",
      "setter": "setView",
      "proposalCanBeRejected": false
    }
  ],
  "events": [
    {
      "name": "onClick",
      "nativeType": "React synthetic event or native callback",
      "callerFirst": true,
      "preventable": true,
      "observedResult": "The existing demo callback remains the source of truth; this example does not call a live service."
    },
    {
      "name": "onGroupChange",
      "nativeType": "component callback",
      "callerFirst": true,
      "preventable": true,
      "observedResult": "The existing demo callback remains the source of truth; this example does not call a live service."
    },
    {
      "name": "onMemberRoleChange",
      "nativeType": "component callback",
      "callerFirst": true,
      "preventable": true,
      "observedResult": "The existing demo callback remains the source of truth; this example does not call a live service."
    },
    {
      "name": "onPermissionChange",
      "nativeType": "component callback",
      "callerFirst": true,
      "preventable": true,
      "observedResult": "The existing demo callback remains the source of truth; this example does not call a live service."
    },
    {
      "name": "onViewChange",
      "nativeType": "component callback",
      "callerFirst": true,
      "preventable": true,
      "observedResult": "The existing demo callback remains the source of truth; this example does not call a live service."
    }
  ],
  "nativeForm": {
    "participates": true,
    "names": [],
    "expectedFormData": {},
    "submitBehavior": "The existing demo's native form callback receives the submit event.",
    "resetBehavior": "Native reset behavior remains available where the demo renders a resettable control.",
    "disabledBehavior": "Disabled controls remain excluded from successful native form submission.",
    "readOnlyBehavior": "Read-only controls retain their value and remain inspectable by the consumer."
  },
  "accessibility": {
    "labelSource": "Consumer-provided label remains required where the component API requires one.",
    "semantics": "Preserve the component's native element and the semantics demonstrated by the source fixture.",
    "keyboard": [
      "Tab and Shift+Tab",
      "Enter or Space for native activation",
      "Arrow keys where the component exposes a composite control"
    ],
    "focusReturn": "Preserve browser focus order and visible focus.",
    "errorAnnouncement": "No error announcement path is present in this demo; the consumer owns validation messaging.",
    "reducedMotion": "Verify prefers-reduced-motion with the existing component transition path.",
    "forcedColors": "Verify visible borders, text, and focus in forced-colors mode."
  },
  "responsive": {
    "widths": [
      320,
      390,
      768,
      1260
    ],
    "shortViewport": "Check the example at a 300px viewport height with keyboard or portal content visible.",
    "overflow": "The page should not gain horizontal overflow; component-local scrolling must remain intentional.",
    "touchTargetMinPx": 44,
    "coarseInputFontPx": 16
  },
  "errors": [
    {
      "fixture": "No error fixture is exposed by the existing demo; inject a consumer-owned failure state before production use.",
      "visibleResult": "The consumer-visible result must remain explicit and must not be replaced by a silent console error.",
      "focusResult": "Focus must remain on the triggering control or move to the announced error according to the native pattern.",
      "ownership": "Consumer-owned sample state only; no network request or customer data is used."
    }
  ],
  "verification": {
    "commands": [
      "npx tsc --noEmit",
      "npx vite build"
    ],
    "lockfile": "Use the consumer project's committed lockfile.",
    "browser": [
      "Chromium 1260x800",
      "Chromium 390x844",
      "Keyboard and reduced-motion pass"
    ]
  },
  "validation": {
    "consumerFixture": {
      "tsc": "pass",
      "viteBuild": "pass",
      "resourceModel": "Generated usage plus only the component files and CSS delivered by the primary item and listed registry dependencies."
    },
    "registryArtifact": "server-gated"
  },
  "exceptions": []
}
