{
  "schemaVersion": "1.0",
  "id": "contribution-statistics",
  "title": "Công sức cùng nhà",
  "purpose": "Pro aggregate stats có filled encoding và nguồn dữ liệu mẫu rõ.",
  "roles": [
    "adult"
  ],
  "group": "history-pro",
  "variantOf": null,
  "layout": {
    "canvas": {
      "width": 390,
      "height": 844
    },
    "responsive": {
      "minimumWidth": 360,
      "maximumWidth": 430,
      "scroll": "vertical",
      "safeAreaBottom": true,
      "fontScale": "native dynamic type; reflow without clipping",
      "keyboard": "composer sticky within resized viewport; dialog scrolls; no fixed keyboard overlay"
    },
    "regions": [
      {
        "id": "header",
        "order": 0,
        "type": "safe-area/header",
        "height": "intrinsic"
      },
      {
        "id": "content",
        "order": 1,
        "type": "purpose-specific stats",
        "componentIds": [
          "screen-header",
          "contribution-statistics-0",
          "contribution-statistics-1",
          "contribution-statistics-2",
          "contribution-statistics-3",
          "screen-actions"
        ]
      },
      {
        "id": "actions",
        "order": 2,
        "type": "one primary + secondary controls"
      },
      {
        "id": "navigation",
        "order": 3,
        "type": "none"
      }
    ]
  },
  "components": [
    {
      "id": "screen-header",
      "type": "Header",
      "props": {
        "homeLabel": "Nhà Lá",
        "scopeGate": "A+Pro",
        "backTarget": "history",
        "settingsTarget": "settings"
      },
      "tokens": {
        "foreground": "{semantic.light.fg}",
        "darkForeground": "{semantic.dark.fg}"
      },
      "accessibility": {
        "label": "Thanh đầu màn hình",
        "readingOrder": 0,
        "focusOrder": "back then settings"
      }
    },
    {
      "id": "contribution-statistics-0",
      "type": "Field",
      "props": {
        "name": "from_local_date",
        "label": "Từ ngày",
        "type": "date",
        "value": "2026-10-08",
        "required": true,
        "min": null,
        "max": null,
        "options": null,
        "hint": null,
        "pattern": null
      },
      "tokens": {
        "background": "{semantic.light.surface}",
        "foreground": "{semantic.light.fg}",
        "darkBackground": "{semantic.dark.surface}",
        "darkForeground": "{semantic.dark.fg}",
        "bodySize": "{primitive.type.body}",
        "touchTarget": "{primitive.space.48}"
      },
      "accessibility": {
        "label": "Từ ngày",
        "readingOrder": 1,
        "colorOnly": false,
        "fontScaling": true,
        "minimumTouchTarget": 48,
        "instructions": "Đọc theo thứ tự; công bố nhãn trạng thái và lỗi, không chỉ màu."
      }
    },
    {
      "id": "contribution-statistics-1",
      "type": "Field",
      "props": {
        "name": "to_local_date",
        "label": "Đến ngày",
        "type": "date",
        "value": "2026-10-14",
        "required": true,
        "min": null,
        "max": null,
        "options": null,
        "hint": null,
        "pattern": null
      },
      "tokens": {
        "background": "{semantic.light.surface}",
        "foreground": "{semantic.light.fg}",
        "darkBackground": "{semantic.dark.surface}",
        "darkForeground": "{semantic.dark.fg}",
        "bodySize": "{primitive.type.body}",
        "touchTarget": "{primitive.space.48}"
      },
      "accessibility": {
        "label": "Đến ngày",
        "readingOrder": 2,
        "colorOnly": false,
        "fontScaling": true,
        "minimumTouchTarget": 48,
        "instructions": "Đọc theo thứ tự; công bố nhãn trạng thái và lỗi, không chỉ màu."
      }
    },
    {
      "id": "contribution-statistics-2",
      "type": "ContributionChart",
      "props": {
        "members": [
          {
            "id": "an",
            "net_points": 2
          },
          {
            "id": "minh",
            "net_points": 2
          },
          {
            "id": "bong",
            "net_points": 1
          }
        ],
        "encoding": "filled proportional bar",
        "sampleOnly": true
      },
      "tokens": {
        "background": "{semantic.light.surface}",
        "foreground": "{semantic.light.fg}",
        "darkBackground": "{semantic.dark.surface}",
        "darkForeground": "{semantic.dark.fg}",
        "bodySize": "{primitive.type.body}",
        "touchTarget": "{primitive.space.48}"
      },
      "accessibility": {
        "label": "Công sức cùng nhà · ContributionChart",
        "readingOrder": 3,
        "colorOnly": false,
        "fontScaling": true,
        "minimumTouchTarget": 48,
        "instructions": "Đọc theo thứ tự; công bố nhãn trạng thái và lỗi, không chỉ màu."
      }
    },
    {
      "id": "contribution-statistics-3",
      "type": "ToggleGroup",
      "props": {
        "items": [
          [
            "hide_board",
            "Ẩn bảng đóng góp",
            "Cả nhà vẫn có lịch sử việc của mình.",
            false
          ]
        ]
      },
      "tokens": {
        "background": "{semantic.light.surface}",
        "foreground": "{semantic.light.fg}",
        "darkBackground": "{semantic.dark.surface}",
        "darkForeground": "{semantic.dark.fg}",
        "bodySize": "{primitive.type.body}",
        "touchTarget": "{primitive.space.48}"
      },
      "accessibility": {
        "label": "Công sức cùng nhà · ToggleGroup",
        "readingOrder": 4,
        "colorOnly": false,
        "fontScaling": true,
        "minimumTouchTarget": 48,
        "instructions": "Đọc theo thứ tự; công bố nhãn trạng thái và lỗi, không chỉ màu."
      }
    },
    {
      "id": "screen-actions",
      "type": "ActionGroup",
      "props": {
        "actions": [
          {
            "id": "navigate-0",
            "label": "Xem quyền Pro",
            "kind": "navigate",
            "target": "pro-benefits",
            "confirmationRequired": false
          },
          {
            "id": "navigate-1",
            "label": "Lịch sử đầy đủ",
            "kind": "navigate",
            "target": "history",
            "confirmationRequired": false
          },
          {
            "id": "link-settings",
            "label": "Cài đặt",
            "kind": "navigate",
            "target": "settings",
            "confirmationRequired": false
          }
        ],
        "primaryCount": 0
      },
      "tokens": {
        "lightBackground": "{component.light.button.background}",
        "lightForeground": "{component.light.button.foreground}",
        "darkBackground": "{component.dark.button.background}",
        "darkForeground": "{component.dark.button.foreground}",
        "height": "{primitive.space.48}"
      },
      "accessibility": {
        "label": "Hành động của màn hình",
        "keyboard": true,
        "focusVisible": true,
        "disabledOnlyLowContrast": true
      }
    }
  ],
  "fields": [
    {
      "id": "from_local_date",
      "label": "Từ ngày",
      "control": "date",
      "default": "2026-10-08",
      "options": null,
      "validation": {
        "required": true,
        "trim": false,
        "type": "date",
        "min": null,
        "max": null,
        "pattern": null,
        "serverAuthoritative": true,
        "errorMessage": "Kiểm tra từ ngày."
      },
      "binding": "from_local_date",
      "keyboard": "date",
      "accessibleErrorAssociation": "form error summary via role alert; native bind field-specific error ID"
    },
    {
      "id": "to_local_date",
      "label": "Đến ngày",
      "control": "date",
      "default": "2026-10-14",
      "options": null,
      "validation": {
        "required": true,
        "trim": false,
        "type": "date",
        "min": null,
        "max": null,
        "pattern": null,
        "serverAuthoritative": true,
        "errorMessage": "Kiểm tra đến ngày."
      },
      "binding": "to_local_date",
      "keyboard": "date",
      "accessibleErrorAssociation": "form error summary via role alert; native bind field-specific error ID"
    },
    {
      "id": "hide_board",
      "label": "Ẩn bảng đóng góp",
      "control": "switch",
      "default": false,
      "validation": {
        "required": false,
        "mustBeTrue": false,
        "serverAllowlistRequired": true
      },
      "binding": "hide_board"
    }
  ],
  "states": [
    {
      "id": "granted",
      "when": "advanced_stats verified true",
      "visibleUI": "Range ≤366 ngày; net effort",
      "availableActions": [
        "navigate-0",
        "navigate-1",
        "link-settings"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "not-granted",
      "when": "FEATURE_REQUIRED",
      "visibleUI": "Không fetch premium data, history vẫn đọc",
      "availableActions": [
        "navigate-0",
        "navigate-1",
        "link-settings"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "empty",
      "when": "Không accepted events",
      "visibleUI": "Zero/no data thay vì chart fake",
      "availableActions": [
        "navigate-0",
        "navigate-1",
        "link-settings"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    }
  ],
  "actions": [
    {
      "id": "navigate-0",
      "label": "Xem quyền Pro",
      "kind": "navigate",
      "targetScreenId": "pro-benefits",
      "permission": "A+Pro",
      "confirmationRequired": false,
      "contractRef": "local draft/navigation",
      "localBehavior": "Only validated draft/local domain where supported; remote adapters never report success.",
      "idempotency": null
    },
    {
      "id": "navigate-1",
      "label": "Lịch sử đầy đủ",
      "kind": "navigate",
      "targetScreenId": "history",
      "permission": "A+Pro",
      "confirmationRequired": false,
      "contractRef": "local draft/navigation",
      "localBehavior": "Only validated draft/local domain where supported; remote adapters never report success.",
      "idempotency": null
    },
    {
      "id": "link-settings",
      "label": "Cài đặt",
      "kind": "navigate",
      "targetScreenId": "settings",
      "permission": "A+Pro",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    }
  ],
  "dataBindings": [
    {
      "source": "GET /v1/households/{hid}/stats",
      "shape": {
        "from_local_date": "date",
        "to_local_date": "date <=366 days",
        "members": "{member_id,display_name,net_points,approved_completions}[]"
      },
      "sample": {
        "from_local_date": "2026-10-08",
        "to_local_date": "2026-10-14",
        "members": [
          {
            "member_id": "an",
            "display_name": "An",
            "net_points": 2,
            "approved_completions": 1
          },
          {
            "member_id": "minh",
            "display_name": "Minh",
            "net_points": 2,
            "approved_completions": 1
          },
          {
            "member_id": "bong",
            "display_name": "Bông",
            "net_points": 1,
            "approved_completions": 1
          }
        ]
      },
      "sampleOnly": true,
      "actorConstraint": "exact actor allowlist",
      "envelope": "API refs use CommandEnvelope; local review context is not an API property."
    }
  ],
  "copy": {
    "heading": "Công sức cùng nhà",
    "primary": null,
    "empty": null,
    "notices": [],
    "locale": "vi",
    "demoLabel": "Bản thiết kế · dữ liệu mẫu · không kết nối dịch vụ"
  },
  "implementation": {
    "nativeRoute": "/design/contribution-statistics",
    "nativeRouteStatus": "proposed mapping, verify against implementing native navigator",
    "apiRefs": [
      "GET /v1/households/{hid}/stats"
    ],
    "newContractRefs": [],
    "notes": [
      "Tất cả ví dụ là dữ liệu thiết kế, không bằng chứng native/API/store đã chạy.",
      "Native route dưới đây là đề xuất mapping cho agent, không tuyên bố route source đã tồn tại.",
      "Mọi mutation dùng envelope {data,version,household_revision,replayed}, stable Idempotency-Key và expected_version khi sửa."
    ],
    "integrationStatus": "design complete; local static/draft interactions; native/API adapters pending",
    "sourceAuthority": [
      "docs/product-brief.md",
      "plans/261013-1409-sweepy-vietnam-mobile/mobile-flows.md",
      "plans/261013-1409-sweepy-vietnam-mobile/api-contracts.md",
      "packages/domain/src/contracts/phase2.ts",
      "packages/domain/src/index.ts",
      "packages/domain/src/contracts/phase3.ts",
      "packages/domain/src/contracts/billing.ts",
      "apps/mobile/src/lib/api.ts"
    ],
    "capability": "A+Pro",
    "errors": {
      "401": "Stop queue; adult login or child re-pair without parent account.",
      "403": "Do not retry lost capability. FEATURE_REQUIRED never grants Pro.",
      "409": "Fetch canonical scoped state; review/reconfirm new intent, do not rewrite old replay payload.",
      "422": "Field error with retained draft.",
      "429": "Respect Retry-After.",
      "503": "Backoff only retryable commands with original key."
    }
  }
}
