{
  "schemaVersion": "1.0",
  "id": "child-settings",
  "title": "Tùy chọn của con",
  "purpose": "Child-only preferences và re-pair, không adult settings.",
  "roles": [
    "child"
  ],
  "group": "members-children",
  "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 preferences",
        "componentIds": [
          "screen-header",
          "child-settings-0",
          "child-settings-1",
          "child-settings-2",
          "screen-actions",
          "primary-navigation"
        ]
      },
      {
        "id": "actions",
        "order": 2,
        "type": "one primary + secondary controls"
      },
      {
        "id": "navigation",
        "order": 3,
        "type": "child-two-tabs"
      }
    ]
  },
  "components": [
    {
      "id": "screen-header",
      "type": "Header",
      "props": {
        "homeLabel": "Bông",
        "scopeGate": "C own preferences",
        "backTarget": "child-today",
        "settingsTarget": "child-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": "child-settings-0",
      "type": "ToggleGroup",
      "props": {
        "items": [
          [
            "enabled",
            "Nhắc việc của con",
            "Chỉ nhắc những việc con được giao.",
            true
          ],
          [
            "motion",
            "Chuyển động nhẹ",
            "Tôn trọng cài đặt giảm chuyển động của máy.",
            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": "Tùy chọn của con · ToggleGroup",
        "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": "child-settings-1",
      "type": "ChoiceGroup",
      "props": {
        "legend": "Giao diện",
        "name": "theme",
        "options": [
          [
            "light",
            "Sáng"
          ],
          [
            "dark",
            "Tối"
          ],
          [
            "system",
            "Theo thiết bị"
          ]
        ],
        "multiple": 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": "Tùy chọn của con · ChoiceGroup",
        "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": "child-settings-2",
      "type": "Notice",
      "props": {
        "text": "Nếu cần ghép lại, hãy nhờ phụ huynh. Con không thể đổi người quản lý.",
        "tone": ""
      },
      "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ùy chọn của con · Notice",
        "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": "screen-actions",
      "type": "ActionGroup",
      "props": {
        "actions": [
          {
            "id": "child-prefs",
            "label": "Lưu tùy chọn trên máy",
            "kind": "mutate",
            "target": null,
            "confirmationRequired": false
          },
          {
            "id": "navigate-1",
            "label": "Nhập mã ghép mới",
            "kind": "navigate",
            "target": "child-pair-redeem",
            "confirmationRequired": false
          },
          {
            "id": "link-child-today",
            "label": "Việc của con",
            "kind": "navigate",
            "target": "child-today",
            "confirmationRequired": false
          },
          {
            "id": "link-child-settings",
            "label": "Tùy chọn của con",
            "kind": "navigate",
            "target": "child-settings",
            "confirmationRequired": false
          },
          {
            "id": "link-child-achievements",
            "label": "Thành tích của con",
            "kind": "navigate",
            "target": "child-achievements",
            "confirmationRequired": false
          }
        ],
        "primaryCount": 1
      },
      "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
      }
    },
    {
      "id": "primary-navigation",
      "type": "Navigation",
      "props": {
        "items": [
          [
            "child-today",
            "Việc của con",
            "check"
          ],
          [
            "child-achievements",
            "Thành tích",
            "history"
          ]
        ],
        "active": "child-achievements"
      },
      "tokens": {
        "activeBackground": "{semantic.light.sage}",
        "activeDarkBackground": "{semantic.dark.sage}",
        "foreground": "{semantic.light.fg}",
        "darkForeground": "{semantic.dark.fg}"
      },
      "accessibility": {
        "label": "Điều hướng chính",
        "ariaCurrent": "page",
        "touchTarget": 48,
        "noColorOnly": true
      }
    }
  ],
  "fields": [
    {
      "id": "enabled",
      "label": "Nhắc việc của con",
      "control": "switch",
      "default": true,
      "validation": {
        "required": false,
        "mustBeTrue": false,
        "serverAllowlistRequired": true
      },
      "binding": "enabled"
    },
    {
      "id": "motion",
      "label": "Chuyển động nhẹ",
      "control": "switch",
      "default": false,
      "validation": {
        "required": false,
        "mustBeTrue": false,
        "serverAllowlistRequired": true
      },
      "binding": "motion"
    },
    {
      "id": "theme",
      "label": "Giao diện",
      "control": "radio",
      "options": [
        {
          "value": "light",
          "label": "Sáng"
        },
        {
          "value": "dark",
          "label": "Tối"
        },
        {
          "value": "system",
          "label": "Theo thiết bị"
        }
      ],
      "validation": {
        "required": true,
        "allowlist": [
          "light",
          "dark",
          "system"
        ],
        "minSelections": 1,
        "errorMessage": "Chọn ít nhất một mục phù hợp."
      },
      "binding": "theme",
      "accessibleErrorAssociation": "form error summary via role alert; native bind field-specific error ID"
    }
  ],
  "states": [
    {
      "id": "active",
      "when": "Child device valid",
      "visibleUI": "Only allowed preference keys",
      "availableActions": [
        "child-prefs",
        "navigate-1",
        "link-child-today",
        "link-child-settings",
        "link-child-achievements"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "expired",
      "when": "Child session hết hạn",
      "visibleUI": "Pair/rotation recovery; không vào email adult",
      "availableActions": [
        "navigate-1",
        "link-child-today",
        "link-child-settings",
        "link-child-achievements"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    }
  ],
  "actions": [
    {
      "id": "child-prefs",
      "label": "Lưu tùy chọn trên máy",
      "kind": "mutate",
      "targetScreenId": null,
      "permission": "C allowed preferences",
      "confirmationRequired": false,
      "contractRef": "PATCH /v1/me/preferences",
      "localBehavior": "Only validated draft/local domain where supported; remote adapters never report success.",
      "idempotency": "Stable actor/household/command key and canonical body; changed payload is a new confirmed intent."
    },
    {
      "id": "navigate-1",
      "label": "Nhập mã ghép mới",
      "kind": "navigate",
      "targetScreenId": "child-pair-redeem",
      "permission": "C own preferences",
      "confirmationRequired": false,
      "contractRef": "local draft/navigation",
      "localBehavior": "Only validated draft/local domain where supported; remote adapters never report success.",
      "idempotency": null
    },
    {
      "id": "link-child-today",
      "label": "Việc của con",
      "kind": "navigate",
      "targetScreenId": "child-today",
      "permission": "C own preferences",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    },
    {
      "id": "link-child-settings",
      "label": "Tùy chọn của con",
      "kind": "navigate",
      "targetScreenId": "child-settings",
      "permission": "C own preferences",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    },
    {
      "id": "link-child-achievements",
      "label": "Thành tích của con",
      "kind": "navigate",
      "targetScreenId": "child-achievements",
      "permission": "C own preferences",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    }
  ],
  "dataBindings": [
    {
      "source": "PATCH /v1/me/preferences",
      "shape": {
        "version": "integer",
        "weekday_budgets": "{weekday:1..7,effort_budget:integer}[] (SchedulePreferencesDto, schedule screens only)",
        "notifications": "NotificationPreferencesDto {locale:vi|en, enabled, quiet_start_local HH:mm|null, quiet_end_local HH:mm|null, version}",
        "theme": "device-local light|dark|system; not an API field"
      },
      "sample": {
        "version": 1,
        "weekday_budgets": [
          {
            "weekday": 1,
            "effort_budget": 4
          },
          {
            "weekday": 2,
            "effort_budget": 4
          },
          {
            "weekday": 3,
            "effort_budget": 4
          },
          {
            "weekday": 4,
            "effort_budget": 4
          },
          {
            "weekday": 5,
            "effort_budget": 4
          },
          {
            "weekday": 6,
            "effort_budget": 6
          },
          {
            "weekday": 7,
            "effort_budget": 6
          }
        ],
        "notifications": {
          "locale": "vi",
          "enabled": true,
          "quiet_start_local": "21:00",
          "quiet_end_local": "07:00",
          "version": 1
        },
        "theme": "light"
      },
      "sampleOnly": true,
      "actorConstraint": "exact actor allowlist",
      "envelope": "API refs use CommandEnvelope; local review context is not an API property."
    }
  ],
  "copy": {
    "heading": "Tùy chọn của con",
    "primary": "Lưu tùy chọn trên máy",
    "empty": null,
    "notices": [
      "Nếu cần ghép lại, hãy nhờ phụ huynh. Con không thể đổi người quản lý."
    ],
    "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/child-settings",
    "nativeRouteStatus": "proposed mapping, verify against implementing native navigator",
    "apiRefs": [
      "PATCH /v1/me/preferences"
    ],
    "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.",
      "Child DTO allowlist: own assignments/history + relevant room instructions; không adult contacts, invites, billing hoặc household aggregates."
    ],
    "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": "C own preferences",
    "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."
    }
  }
}
