{
  "id": "developer_news_digest",
  "type": "module",
  "version": "1.2",
  "context": {
    "title": "Developer News Digest",
    "icon": "📰",
    "layout": "phone"
  },
  "state": {
    "articles": [],
    "bookmarks": [],
    "category": "All",
    "feedMode": "Latest",
    "isLoading": true,
    "error": "",
    "focused": "",
    "pendingDeleteId": "",
    "showDeleteAlert": false,
    "showToast": false,
    "toastText": ""
  },
  "dependencies": [
    {
      "repository": {
        "remote": {
          "id": "devnews_hn_api",
          "config": {
            "endPoint": "https://hn.algolia.com/api/v1"
          }
        }
      }
    },
    {
      "repository": {
        "local": {
          "id": "developer_news_digest_store",
          "config": {}
        }
      }
    },
    {
      "service": {
        "audio": {
          "id": "devnews_audio"
        }
      }
    },
    {
      "service": {
        "ai": {
          "id": "devnews_ai",
          "config": {
            "model": "low"
          }
        }
      }
    },
    {
      "component": {
        "id": "devnews_detail_screen",
        "type": "module",
        "version": "1.1",
        "state": {
          "aiSummary": "",
          "aiSummaryLoading": true
        },
        "children": [
          {
            "id": "devnews_detail_scroll",
            "type": "scroll",
            "style": {
              "layout": {
                "maxWidth": "infinity",
                "maxHeight": "infinity"
              }
            },
            "children": [
              {
                "id": "devnews_detail_content",
                "type": "vstack",
                "context": {
                  "_spacing": 18,
                  "_alignment": "leading"
                },
                "style": {
                  "layout": {
                    "maxWidth": "infinity",
                    "padding": {
                      "top": 18,
                      "bottom": 32,
                      "leading": 18,
                      "trailing": 18
                    }
                  }
                },
                "children": [
                  {
                    "id": "devnews_detail_meta_card",
                    "type": "hstack",
                    "context": {
                      "_spacing": 10,
                      "_alignment": "center"
                    },
                    "style": {
                      "layout": {
                        "maxWidth": "infinity",
                        "padding": 14
                      },
                      "common": {
                        "background": {
                          "material": "thin"
                        },
                        "foreground": {
                          "color": "primary"
                        },
                        "cornerRadius": 16
                      }
                    },
                    "children": [
                      {
                        "id": "devnews_detail_source_icon",
                        "type": "image",
                        "context": {
                          "_source": "sf://newspaper.fill"
                        },
                        "style": {
                          "layout": {
                            "width": 22,
                            "height": 22
                          },
                          "common": {
                            "foreground": "mint"
                          }
                        }
                      },
                      {
                        "id": "devnews_detail_source",
                        "type": "text",
                        "context": {
                          "_text": "Hacker News"
                        },
                        "style": {
                          "common": {
                            "font": "headline",
                            "foreground": {
                              "color": "primary"
                            }
                          }
                        }
                      },
                      {
                        "id": "devnews_detail_meta_spacer",
                        "type": "spacer"
                      },
                      {
                        "id": "devnews_detail_points",
                        "type": "label",
                        "context": {
                          "_title": "{{ cast(@{item.points} ?? 0, 'str') + ' points' }}",
                          "_image": "sf://arrow.up.circle.fill"
                        },
                        "style": {
                          "common": {
                            "font": "caption",
                            "foreground": {
                              "color": "secondary"
                            }
                          }
                        }
                      }
                    ]
                  },
                  {
                    "id": "devnews_detail_headline",
                    "type": "text",
                    "context": {
                      "_text": "@{item.title}"
                    },
                    "style": {
                      "common": {
                        "font": {
                          "kind": "title2",
                          "weight": "bold"
                        },
                        "foreground": {
                          "color": "primary"
                        }
                      },
                      "text": {
                        "lineSpacing": 3
                      }
                    }
                  },
                  {
                    "id": "devnews_detail_date_row",
                    "type": "hstack",
                    "context": {
                      "_spacing": 6,
                      "_alignment": "center"
                    },
                    "children": [
                      {
                        "id": "devnews_detail_date_icon",
                        "type": "image",
                        "context": {
                          "_source": "sf://clock"
                        },
                        "style": {
                          "layout": {
                            "width": 15,
                            "height": 15
                          },
                          "common": {
                            "foreground": {
                              "color": "secondary"
                            }
                          }
                        }
                      },
                      {
                        "id": "devnews_detail_date",
                        "type": "text",
                        "context": {
                          "_text": "{{ cast(@{item.created_at}, 'date') }}",
                          "_format": {
                            "date": {
                              "style": "datetime",
                              "dateStyle": "medium",
                              "timeStyle": "short"
                            }
                          }
                        },
                        "style": {
                          "common": {
                            "font": "subheadline",
                            "foreground": {
                              "color": "secondary"
                            }
                          }
                        }
                      }
                    ]
                  },
                  {
                    "id": "devnews_detail_summary_card",
                    "type": "vstack",
                    "context": {
                      "_spacing": 10,
                      "_alignment": "leading"
                    },
                    "style": {
                      "layout": {
                        "maxWidth": "infinity",
                        "padding": 18
                      },
                      "common": {
                        "background": {
                          "color": "surface"
                        },
                        "foreground": {
                          "color": "onSurface"
                        },
                        "cornerRadius": 18
                      },
                      "shadow": {
                        "color": {
                          "color": "black",
                          "opacity": 0.12
                        },
                        "radius": 10,
                        "y": 5
                      }
                    },
                    "children": [
                      {
                        "id": "devnews_detail_summary_heading",
                        "type": "label",
                        "context": {
                          "_title": "Summary",
                          "_image": "sf://text.alignleft"
                        },
                        "style": {
                          "common": {
                            "font": "headline",
                            "foreground": {
                              "color": "onSurface"
                            }
                          }
                        }
                      },
                      {
                        "id": "devnews_detail_summary",
                        "type": "text",
                        "context": {
                          "_text": "{{ notEmpty(${aiSummary}) ? ${aiSummary} : ${aiSummaryLoading} ? 'Generating a short AI summary from the article link…' : notEmpty(@{item.story_text}) ? @{item.story_text} : 'A summary could not be generated for this article.' }}"
                        },
                        "style": {
                          "common": {
                            "font": "body",
                            "foreground": {
                              "color": "onSurfaceVariant"
                            }
                          },
                          "text": {
                            "lineSpacing": 4
                          }
                        }
                      }
                    ]
                  },
                  {
                    "id": "devnews_detail_link_card",
                    "type": "vstack",
                    "context": {
                      "_spacing": 8,
                      "_alignment": "leading"
                    },
                    "style": {
                      "layout": {
                        "maxWidth": "infinity",
                        "padding": 18
                      },
                      "common": {
                        "background": {
                          "gradient": {
                            "linear": {
                              "colors": [
                                "#134E4A",
                                "#065F46"
                              ],
                              "startPoint": "topLeading",
                              "endPoint": "bottomTrailing"
                            }
                          }
                        },
                        "foreground": "white",
                        "cornerRadius": 18
                      },
                      "shadow": {
                        "color": {
                          "color": "black",
                          "opacity": 0.18
                        },
                        "radius": 10,
                        "y": 5
                      }
                    },
                    "children": [
                      {
                        "id": "devnews_detail_link_heading",
                        "type": "label",
                        "context": {
                          "_title": "Original article address",
                          "_image": "sf://doc.text.fill"
                        },
                        "style": {
                          "common": {
                            "font": "headline",
                            "foreground": "white"
                          }
                        }
                      },
                      {
                        "id": "devnews_detail_link",
                        "type": "text",
                        "context": {
                          "_text": "{{ notEmpty(@{item.url}) ? @{item.url} : 'https://news.ycombinator.com/item?id=' + @{item.objectID} }}"
                        },
                        "style": {
                          "common": {
                            "font": "footnote",
                            "foreground": {
                              "color": "white",
                              "opacity": 0.86
                            }
                          },
                          "text": {
                            "lineSpacing": 2
                          }
                        }
                      },
                      {
                        "id": "devnews_detail_link_note",
                        "type": "text",
                        "context": {
                          "_text": "This runtime displays article addresses as reference text; external browser handoff is not available."
                        },
                        "style": {
                          "common": {
                            "font": "caption",
                            "foreground": {
                              "color": "white",
                              "opacity": 0.68
                            }
                          }
                        }
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ],
        "events": {
          "onAppear": [
            {
              "service": {
                "id": "devnews_detail_ai_summary_request",
                "input": {
                  "serviceId": "devnews_ai",
                  "params": {
                    "model": "low",
                    "prompt": "{{ 'Read the article at this link and return a concise 2–3 sentence developer-news summary. Return only the summary: ' + (notEmpty(@{item.url}) ? @{item.url} : 'https://news.ycombinator.com/item?id=' + @{item.objectID}) }}"
                  }
                },
                "output": {
                  "success": [
                    {
                      "state": {
                        "id": "devnews_detail_apply_ai_summary",
                        "input": {
                          "aiSummary": "{{ @{devnews_detail_ai_summary_request.summary} ?? @{devnews_detail_ai_summary_request.text} ?? @{devnews_detail_ai_summary_request.content} ?? @{devnews_detail_ai_summary_request.response} ?? '' }}",
                          "aiSummaryLoading": false
                        }
                      }
                    }
                  ],
                  "failure": [
                    {
                      "state": {
                        "id": "devnews_detail_ai_summary_failure",
                        "input": {
                          "aiSummaryLoading": false
                        }
                      }
                    }
                  ]
                }
              }
            }
          ]
        }
      }
    }
  ],
  "children": [
    {
      "id": "devnews_navigation",
      "type": "navigation",
      "children": [
        {
          "id": "devnews_root",
          "type": "vstack",
          "context": {
            "_spacing": 0
          },
          "style": {
            "layout": {
              "maxWidth": "infinity",
              "maxHeight": "infinity"
            },
            "common": {
              "background": {
                "light": "#F1F5F4",
                "dark": "#0B1211"
              }
            },
            "modal": {
              "alert": {
                "isPresented": "${showDeleteAlert}",
                "title": "Remove bookmark?",
                "message": "This article will be removed from your saved list.",
                "actions": [
                  {
                    "id": "devnews_delete_confirm_button",
                    "type": "button",
                    "context": {
                      "_label": "Remove"
                    },
                    "style": {
                      "common": {
                        "foreground": "red"
                      }
                    },
                    "events": {
                      "onTap": [
                        {
                          "state": {
                            "id": "devnews_delete_bookmark",
                            "input": {
                              "bookmarks": "${bookmarks[objectID != ${pendingDeleteId}]}",
                              "showDeleteAlert": false,
                              "pendingDeleteId": "",
                              "toastText": "Bookmark removed",
                              "showToast": true
                            },
                            "output": {
                              "success": [
                                {
                                  "repo": {
                                    "id": "devnews_persist_after_delete",
                                    "input": {
                                      "repositoryId": "developer_news_digest_store",
                                      "operation": "create",
                                      "params": {
                                        "collection": "library",
                                        "documentId": "bookmarks",
                                        "rewrite": true,
                                        "body": {
                                          "items": "${bookmarks}"
                                        }
                                      }
                                    },
                                    "output": {
                                      "success": [
                                        {
                                          "service": {
                                            "id": "devnews_delete_haptic",
                                            "input": {
                                              "serviceId": "devnews_audio",
                                              "params": {
                                                "haptic": "error"
                                              }
                                            }
                                          }
                                        },
                                        {
                                          "interval": {
                                            "id": "devnews_delete_toast_timer",
                                            "input": {
                                              "delay": 2
                                            },
                                            "output": {
                                              "success": [
                                                {
                                                  "interval": {
                                                    "id": "devnews_delete_toast_timer",
                                                    "input": {
                                                      "cancel": true
                                                    }
                                                  }
                                                },
                                                {
                                                  "state": {
                                                    "id": "devnews_hide_delete_toast",
                                                    "input": {
                                                      "showToast": false
                                                    }
                                                  }
                                                }
                                              ]
                                            }
                                          }
                                        }
                                      ],
                                      "failure": [
                                        {
                                          "state": {
                                            "id": "devnews_delete_persist_error",
                                            "input": {
                                              "toastText": "Bookmark was removed, but local storage could not be updated.",
                                              "showToast": true
                                            }
                                          }
                                        }
                                      ]
                                    }
                                  }
                                }
                              ]
                            }
                          }
                        }
                      ]
                    }
                  },
                  {
                    "id": "devnews_delete_cancel_button",
                    "type": "button",
                    "context": {
                      "_label": "Keep"
                    },
                    "events": {
                      "onTap": [
                        {
                          "state": {
                            "id": "devnews_cancel_delete",
                            "input": {
                              "showDeleteAlert": false,
                              "pendingDeleteId": ""
                            }
                          }
                        }
                      ]
                    }
                  }
                ]
              }
            }
          },
          "children": [
            {
              "id": "devnews_controls_card",
              "type": "vstack",
              "context": {
                "_spacing": 12,
                "_alignment": "leading"
              },
              "style": {
                "layout": {
                  "maxWidth": "infinity",
                  "padding": 16
                },
                "common": {
                  "background": {
                    "material": "thin"
                  },
                  "foreground": {
                    "color": "primary"
                  },
                  "cornerRadius": 18
                },
                "shadow": {
                  "color": {
                    "color": "black",
                    "opacity": 0.12
                  },
                  "radius": 10,
                  "y": 5
                }
              },
              "children": [
                {
                  "id": "devnews_mode_header",
                  "type": "label",
                  "context": {
                    "_title": "View",
                    "_image": "sf://rectangle.grid.1x2.fill"
                  },
                  "style": {
                    "common": {
                      "font": "headline",
                      "foreground": {
                        "color": "primary"
                      }
                    }
                  }
                },
                {
                  "id": "devnews_mode_picker",
                  "type": "picker",
                  "context": {
                    "_label": "View",
                    "_selection": "${feedMode}",
                    "_options": [
                      "Latest",
                      "Top Today",
                      "Bookmarks"
                    ]
                  },
                  "style": {
                    "picker": "segmented",
                    "layout": {
                      "maxWidth": "infinity"
                    }
                  },
                  "events": {
                    "onChange": {
                      "observed": "feedMode",
                      "actions": [
                        {
                          "repo": {
                            "id": "devnews_save_mode_preference",
                            "input": {
                              "repositoryId": "developer_news_digest_store",
                              "operation": "create",
                              "params": {
                                "collection": "preferences",
                                "documentId": "feed",
                                "rewrite": true,
                                "body": {
                                  "category": "${category}",
                                  "feedMode": "${feedMode}"
                                }
                              }
                            }
                          }
                        },
                        {
                          "condition": {
                            "id": "devnews_mode_fetch_guard",
                            "input": "{{ ${feedMode} != 'Bookmarks' }}",
                            "output": {
                              "success": [
                                {
                                  "state": {
                                    "id": "devnews_mode_start_loading",
                                    "input": {
                                      "isLoading": true,
                                      "error": ""
                                    },
                                    "output": {
                                      "success": [
                                        {
                                          "repo": {
                                            "id": "devnews_mode_fetch",
                                            "input": {
                                              "repositoryId": "devnews_hn_api",
                                              "operation": "read",
                                              "params": {
                                                "subUrl": "{{ ${feedMode} == 'Top Today' ? '/search' : '/search_by_date' }}",
                                                "body": {
                                                  "tags": "story",
                                                  "query": "{{ ${category} == 'All' ? '' : ${category} }}",
                                                  "hitsPerPage": 50,
                                                  "numericFilters": "{{ ${feedMode} == 'Top Today' ? 'created_at_i>' + cast(cast(#{today}, 'int'), 'str') : '' }}"
                                                }
                                              }
                                            },
                                            "output": {
                                              "success": [
                                                {
                                                  "state": {
                                                    "id": "devnews_apply_mode_results",
                                                    "input": {
                                                      "articles": "@{devnews_mode_fetch.hits}",
                                                      "isLoading": false,
                                                      "error": ""
                                                    }
                                                  }
                                                }
                                              ],
                                              "failure": [
                                                {
                                                  "state": {
                                                    "id": "devnews_mode_fetch_error",
                                                    "input": {
                                                      "isLoading": false,
                                                      "error": "{{ 'Hacker News refresh failed' + (notEmpty(@{devnews_mode_fetch.message}) ? ': ' + @{devnews_mode_fetch.message} : '. Check your network and try again.') }}"
                                                    }
                                                  }
                                                }
                                              ]
                                            }
                                          }
                                        }
                                      ]
                                    }
                                  }
                                }
                              ]
                            }
                          }
                        }
                      ]
                    }
                  }
                },
                {
                  "id": "devnews_category_header",
                  "type": "label",
                  "context": {
                    "_title": "Technology category",
                    "_image": "sf://tag.fill"
                  },
                  "style": {
                    "common": {
                      "font": "headline",
                      "foreground": {
                        "color": "primary"
                      }
                    }
                  }
                },
                {
                  "id": "devnews_category_picker",
                  "type": "picker",
                  "context": {
                    "_label": "Category",
                    "_selection": "${category}",
                    "_options": [
                      "All",
                      "AI",
                      "Web",
                      "Mobile",
                      "Cloud",
                      "Security",
                      "Databases",
                      "DevOps"
                    ]
                  },
                  "style": {
                    "picker": "menu",
                    "layout": {
                      "maxWidth": "infinity"
                    }
                  },
                  "events": {
                    "onChange": {
                      "observed": "category",
                      "actions": [
                        {
                          "repo": {
                            "id": "devnews_save_category_preference",
                            "input": {
                              "repositoryId": "developer_news_digest_store",
                              "operation": "create",
                              "params": {
                                "collection": "preferences",
                                "documentId": "feed",
                                "rewrite": true,
                                "body": {
                                  "category": "${category}",
                                  "feedMode": "${feedMode}"
                                }
                              }
                            }
                          }
                        },
                        {
                          "condition": {
                            "id": "devnews_category_fetch_guard",
                            "input": "{{ ${feedMode} != 'Bookmarks' }}",
                            "output": {
                              "success": [
                                {
                                  "state": {
                                    "id": "devnews_category_start_loading",
                                    "input": {
                                      "isLoading": true,
                                      "error": ""
                                    },
                                    "output": {
                                      "success": [
                                        {
                                          "repo": {
                                            "id": "devnews_category_fetch",
                                            "input": {
                                              "repositoryId": "devnews_hn_api",
                                              "operation": "read",
                                              "params": {
                                                "subUrl": "{{ ${feedMode} == 'Top Today' ? '/search' : '/search_by_date' }}",
                                                "body": {
                                                  "tags": "story",
                                                  "query": "{{ ${category} == 'All' ? '' : ${category} }}",
                                                  "hitsPerPage": 50,
                                                  "numericFilters": "{{ ${feedMode} == 'Top Today' ? 'created_at_i>' + cast(cast(#{today}, 'int'), 'str') : '' }}"
                                                }
                                              }
                                            },
                                            "output": {
                                              "success": [
                                                {
                                                  "state": {
                                                    "id": "devnews_apply_category_results",
                                                    "input": {
                                                      "articles": "@{devnews_category_fetch.hits}",
                                                      "isLoading": false,
                                                      "error": ""
                                                    }
                                                  }
                                                }
                                              ],
                                              "failure": [
                                                {
                                                  "state": {
                                                    "id": "devnews_category_fetch_error",
                                                    "input": {
                                                      "isLoading": false,
                                                      "error": "{{ 'Hacker News refresh failed' + (notEmpty(@{devnews_category_fetch.message}) ? ': ' + @{devnews_category_fetch.message} : '. Check your network and try again.') }}"
                                                    }
                                                  }
                                                }
                                              ]
                                            }
                                          }
                                        }
                                      ]
                                    }
                                  }
                                }
                              ]
                            }
                          }
                        }
                      ]
                    }
                  }
                },
                {
                  "id": "devnews_source_note",
                  "type": "text",
                  "context": {
                    "_text": "Hacker News is the always-available source. Optional RSS/API sources require a normalized integration and are not enabled in this compact build."
                  },
                  "style": {
                    "common": {
                      "font": "caption",
                      "foreground": {
                        "color": "secondary"
                      }
                    },
                    "text": {
                      "lineSpacing": 2
                    }
                  }
                }
              ]
            },
            {
              "id": "devnews_error_state",
              "type": "conditional",
              "context": {
                "_condition": "{{ notEmpty(${error}) }}",
                "_trueComponent": {
                  "id": "devnews_error_banner",
                  "type": "hstack",
                  "context": {
                    "_spacing": 10,
                    "_alignment": "center"
                  },
                  "style": {
                    "layout": {
                      "maxWidth": "infinity",
                      "padding": 14
                    },
                    "common": {
                      "background": {
                        "color": "error",
                        "opacity": 0.14
                      },
                      "foreground": {
                        "color": "primary"
                      },
                      "cornerRadius": 14
                    }
                  },
                  "children": [
                    {
                      "id": "devnews_error_icon",
                      "type": "image",
                      "context": {
                        "_source": "sf://exclamationmark.triangle.fill"
                      },
                      "style": {
                        "layout": {
                          "width": 20,
                          "height": 20
                        },
                        "common": {
                          "foreground": "red"
                        }
                      }
                    },
                    {
                      "id": "devnews_error_text",
                      "type": "text",
                      "context": {
                        "_text": "${error}"
                      },
                      "style": {
                        "layout": {
                          "maxWidth": "infinity"
                        },
                        "common": {
                          "font": "caption",
                          "foreground": {
                            "color": "primary"
                          }
                        }
                      }
                    }
                  ]
                },
                "_falseComponent": {
                  "id": "devnews_error_empty",
                  "type": "empty"
                }
              }
            },
            {
              "id": "devnews_feed_scroll",
              "type": "scroll",
              "context": {
                "_isLoading": "${isLoading}",
                "_skeletonRows": 6
              },
              "style": {
                "layout": {
                  "maxWidth": "infinity",
                  "maxHeight": "infinity"
                },
                "scroll": {
                  "bounce": true
                }
              },
              "events": {
                "onRefresh": [
                  {
                    "condition": {
                      "id": "devnews_refresh_guard",
                      "input": "{{ ${feedMode} != 'Bookmarks' }}",
                      "output": {
                        "success": [
                          {
                            "state": {
                              "id": "devnews_refresh_start",
                              "input": {
                                "isLoading": true,
                                "error": ""
                              },
                              "output": {
                                "success": [
                                  {
                                    "repo": {
                                      "id": "devnews_refresh_fetch",
                                      "input": {
                                        "repositoryId": "devnews_hn_api",
                                        "operation": "read",
                                        "params": {
                                          "subUrl": "{{ ${feedMode} == 'Top Today' ? '/search' : '/search_by_date' }}",
                                          "body": {
                                            "tags": "story",
                                            "query": "{{ ${category} == 'All' ? '' : ${category} }}",
                                            "hitsPerPage": 50,
                                            "numericFilters": "{{ ${feedMode} == 'Top Today' ? 'created_at_i>' + cast(cast(#{today}, 'int'), 'str') : '' }}"
                                          }
                                        }
                                      },
                                      "output": {
                                        "success": [
                                          {
                                            "state": {
                                              "id": "devnews_refresh_apply",
                                              "input": {
                                                "articles": "@{devnews_refresh_fetch.hits}",
                                                "isLoading": false,
                                                "error": ""
                                              }
                                            }
                                          }
                                        ],
                                        "failure": [
                                          {
                                            "state": {
                                              "id": "devnews_refresh_error",
                                              "input": {
                                                "isLoading": false,
                                                "error": "{{ 'Hacker News refresh failed' + (notEmpty(@{devnews_refresh_fetch.message}) ? ': ' + @{devnews_refresh_fetch.message} : '. Check your network and try again.') }}"
                                              }
                                            }
                                          }
                                        ]
                                      }
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        ]
                      }
                    }
                  }
                ]
              },
              "children": [
                {
                  "id": "devnews_feed_stack",
                  "type": "vstack",
                  "context": {
                    "_spacing": 12,
                    "_alignment": "leading",
                    "displayItems": "{{ ${feedMode} == 'Bookmarks' ? ${bookmarks} : ${articles} }}"
                  },
                  "style": {
                    "layout": {
                      "maxWidth": "infinity",
                      "padding": {
                        "top": 14,
                        "bottom": 30,
                        "leading": 16,
                        "trailing": 16
                      }
                    }
                  },
                  "children": [
                    {
                      "id": "devnews_feed_heading_row",
                      "type": "hstack",
                      "context": {
                        "_spacing": 8,
                        "_alignment": "center"
                      },
                      "style": {
                        "layout": {
                          "maxWidth": "infinity"
                        }
                      },
                      "children": [
                        {
                          "id": "devnews_feed_heading_icon",
                          "type": "image",
                          "context": {
                            "_source": "{{ ${feedMode} == 'Top Today' ? 'sf://chart.line.uptrend.xyaxis' : ${feedMode} == 'Bookmarks' ? 'sf://bookmark.fill' : 'sf://clock.arrow.circlepath' }}"
                          },
                          "style": {
                            "layout": {
                              "width": 20,
                              "height": 20
                            },
                            "common": {
                              "foreground": "mint"
                            }
                          }
                        },
                        {
                          "id": "devnews_feed_heading",
                          "type": "text",
                          "context": {
                            "_text": "{{ ${feedMode} == 'Top Today' ? 'Popular stories published today' : ${feedMode} == 'Bookmarks' ? 'Saved articles' : 'Newest stories first' }}"
                          },
                          "style": {
                            "common": {
                              "font": "headline",
                              "foreground": {
                                "color": "primary"
                              }
                            }
                          }
                        },
                        {
                          "id": "devnews_feed_heading_spacer",
                          "type": "spacer"
                        },
                        {
                          "id": "devnews_feed_count",
                          "type": "text",
                          "context": {
                            "_text": "{{ cast(count(@{displayItems}), 'str') }}"
                          },
                          "style": {
                            "common": {
                              "font": "caption",
                              "foreground": {
                                "color": "secondary"
                              }
                            }
                          }
                        }
                      ]
                    },
                    {
                      "id": "devnews_empty_or_feed",
                      "type": "conditional",
                      "context": {
                        "_condition": "{{ empty(@{displayItems}) && !${isLoading} }}",
                        "_trueComponent": {
                          "id": "devnews_empty_card",
                          "type": "vstack",
                          "context": {
                            "_spacing": 12,
                            "_alignment": "center"
                          },
                          "style": {
                            "layout": {
                              "maxWidth": "infinity",
                              "padding": {
                                "top": 34,
                                "bottom": 34,
                                "leading": 20,
                                "trailing": 20
                              }
                            },
                            "common": {
                              "background": {
                                "color": "surface"
                              },
                              "foreground": {
                                "color": "onSurface"
                              },
                              "cornerRadius": 20
                            },
                            "shadow": {
                              "color": {
                                "color": "black",
                                "opacity": 0.1
                              },
                              "radius": 10,
                              "y": 5
                            }
                          },
                          "children": [
                            {
                              "id": "devnews_empty_icon",
                              "type": "image",
                              "context": {
                                "_source": "{{ ${feedMode} == 'Bookmarks' ? 'sf://bookmark' : 'sf://tray' }}"
                              },
                              "style": {
                                "layout": {
                                  "width": 44,
                                  "height": 44
                                },
                                "common": {
                                  "foreground": "mint"
                                }
                              }
                            },
                            {
                              "id": "devnews_empty_title",
                              "type": "text",
                              "context": {
                                "_text": "{{ ${feedMode} == 'Bookmarks' ? 'Save articles for later review' : 'No stories matched this view' }}"
                              },
                              "style": {
                                "common": {
                                  "font": "title3",
                                  "foreground": {
                                    "color": "onSurface"
                                  }
                                },
                                "text": {
                                  "multilineTextAlignment": "center"
                                }
                              }
                            },
                            {
                              "id": "devnews_empty_hint",
                              "type": "text",
                              "context": {
                                "_text": "{{ ${feedMode} == 'Bookmarks' ? 'Use the bookmark button on any feed card.' : 'Try All categories or pull down to refresh.' }}"
                              },
                              "style": {
                                "common": {
                                  "font": "subheadline",
                                  "foreground": {
                                    "color": "onSurfaceVariant"
                                  }
                                },
                                "text": {
                                  "multilineTextAlignment": "center"
                                }
                              }
                            }
                          ]
                        },
                        "_falseComponent": {
                          "id": "devnews_articles_dynamic",
                          "type": "dynamic",
                          "context": {
                            "_data": "@{displayItems}",
                            "_isLoading": "${isLoading}",
                            "_skeletonRows": 6
                          },
                          "prototype": {
                            "id": "devnews_article_card",
                            "type": "vstack",
                            "context": {
                              "_spacing": 10,
                              "_alignment": "leading",
                              "isSaved": "{{ count(${bookmarks[objectID == @{item.objectID}]}) > 0 }}",
                              "articleCategory": "{{ ${category} == 'All' ? 'Technology' : ${category} }}"
                            },
                            "style": {
                              "layout": {
                                "maxWidth": "infinity",
                                "padding": 18
                              },
                              "common": {
                                "background": {
                                  "color": "surface"
                                },
                                "foreground": {
                                  "color": "onSurface"
                                },
                                "cornerRadius": 18
                              },
                              "shadow": {
                                "color": {
                                  "color": "black",
                                  "opacity": 0.12
                                },
                                "radius": 10,
                                "y": 5
                              },
                              "swipe": {
                                "trailing": {
                                  "allowsFullSwipe": false,
                                  "content": {
                                    "id": "devnews_swipe_delete_button",
                                    "type": "button",
                                    "style": {
                                      "common": {
                                        "tint": "red"
                                      }
                                    },
                                    "children": [
                                      {
                                        "id": "devnews_swipe_delete_icon",
                                        "type": "image",
                                        "context": {
                                          "_source": "sf://trash"
                                        },
                                        "style": {
                                          "layout": {
                                            "width": 22,
                                            "height": 22
                                          }
                                        }
                                      }
                                    ],
                                    "events": {
                                      "onTap": [
                                        {
                                          "condition": {
                                            "id": "devnews_swipe_delete_guard",
                                            "input": "{{ ${feedMode} == 'Bookmarks' }}",
                                            "output": {
                                              "success": [
                                                {
                                                  "state": {
                                                    "id": "devnews_prepare_delete",
                                                    "input": {
                                                      "pendingDeleteId": "@{item.objectID}",
                                                      "showDeleteAlert": true
                                                    }
                                                  }
                                                }
                                              ]
                                            }
                                          }
                                        }
                                      ]
                                    }
                                  }
                                }
                              }
                            },
                            "children": [
                              {
                                "id": "devnews_article_meta",
                                "type": "hstack",
                                "context": {
                                  "_spacing": 8,
                                  "_alignment": "center"
                                },
                                "style": {
                                  "layout": {
                                    "maxWidth": "infinity"
                                  }
                                },
                                "children": [
                                  {
                                    "id": "devnews_article_category",
                                    "type": "label",
                                    "context": {
                                      "_title": "@{articleCategory}",
                                      "_image": "sf://tag.fill"
                                    },
                                    "style": {
                                      "layout": {
                                        "padding": {
                                          "top": 5,
                                          "bottom": 5,
                                          "leading": 9,
                                          "trailing": 9
                                        }
                                      },
                                      "common": {
                                        "background": {
                                          "color": "mint",
                                          "opacity": 0.16
                                        },
                                        "foreground": {
                                          "color": "primary"
                                        },
                                        "cornerRadius": 999,
                                        "font": "caption"
                                      }
                                    }
                                  },
                                  {
                                    "id": "devnews_article_source",
                                    "type": "text",
                                    "context": {
                                      "_text": "Hacker News"
                                    },
                                    "style": {
                                      "common": {
                                        "font": "caption",
                                        "foreground": {
                                          "color": "secondary"
                                        }
                                      }
                                    }
                                  },
                                  {
                                    "id": "devnews_article_meta_spacer",
                                    "type": "spacer"
                                  },
                                  {
                                    "id": "devnews_article_time",
                                    "type": "text",
                                    "context": {
                                      "_text": "{{ cast(@{item.created_at}, 'date') }}",
                                      "_format": {
                                        "date": "relative"
                                      }
                                    },
                                    "style": {
                                      "common": {
                                        "font": "caption",
                                        "foreground": {
                                          "color": "secondary"
                                        }
                                      }
                                    }
                                  }
                                ]
                              },
                              {
                                "id": "devnews_article_link",
                                "type": "link",
                                "destination": {
                                  "id": "devnews_article_detail_destination",
                                  "type": "module",
                                  "version": "1.2",
                                  "state": {},
                                  "children": [
                                    {
                                      "id": "devnews_detail_template_use",
                                      "type": "web",
                                      "context": {
                                        "_source": "{{ notEmpty(@{item.url}) ? @{item.url} : 'https://news.ycombinator.com/item?id=' + @{item.objectID} }}"
                                      },
                                      "style": {
                                        "layout": {
                                          "maxWidth": "infinity",
                                          "maxHeight": "infinity"
                                        }
                                      }
                                    }
                                  ]
                                },
                                "children": [
                                  {
                                    "id": "devnews_article_title_row",
                                    "type": "hstack",
                                    "context": {
                                      "_spacing": 10,
                                      "_alignment": "center"
                                    },
                                    "style": {
                                      "layout": {
                                        "maxWidth": "infinity",
                                        "minHeight": 44
                                      }
                                    },
                                    "children": [
                                      {
                                        "id": "devnews_article_title",
                                        "type": "text",
                                        "context": {
                                          "_text": "@{item.title}"
                                        },
                                        "style": {
                                          "layout": {
                                            "maxWidth": "infinity"
                                          },
                                          "common": {
                                            "font": {
                                              "kind": "body",
                                              "weight": "semibold"
                                            },
                                            "foreground": {
                                              "color": "onSurface"
                                            }
                                          },
                                          "text": {
                                            "lineLimit": 3,
                                            "lineSpacing": 2
                                          }
                                        }
                                      },
                                      {
                                        "id": "devnews_article_chevron",
                                        "type": "image",
                                        "context": {
                                          "_source": "sf://chevron.right"
                                        },
                                        "style": {
                                          "layout": {
                                            "width": 12,
                                            "height": 12
                                          },
                                          "common": {
                                            "foreground": {
                                              "color": "secondary"
                                            }
                                          }
                                        }
                                      }
                                    ]
                                  }
                                ]
                              },
                              {
                                "id": "devnews_article_footer",
                                "type": "hstack",
                                "context": {
                                  "_spacing": 10,
                                  "_alignment": "center"
                                },
                                "style": {
                                  "layout": {
                                    "maxWidth": "infinity"
                                  }
                                },
                                "children": [
                                  {
                                    "id": "devnews_article_popularity",
                                    "type": "label",
                                    "context": {
                                      "_title": "{{ cast(@{item.points} ?? 0, 'str') + ' points' }}",
                                      "_image": "sf://arrow.up.circle"
                                    },
                                    "style": {
                                      "common": {
                                        "font": "caption",
                                        "foreground": {
                                          "color": "secondary"
                                        }
                                      }
                                    }
                                  },
                                  {
                                    "id": "devnews_article_comments",
                                    "type": "label",
                                    "context": {
                                      "_title": "{{ cast(@{item.num_comments} ?? 0, 'str') + ' comments' }}",
                                      "_image": "sf://bubble.left"
                                    },
                                    "style": {
                                      "common": {
                                        "font": "caption",
                                        "foreground": {
                                          "color": "secondary"
                                        }
                                      }
                                    }
                                  },
                                  {
                                    "id": "devnews_article_footer_spacer",
                                    "type": "spacer"
                                  },
                                  {
                                    "id": "devnews_bookmark_button",
                                    "type": "button",
                                    "context": {
                                      "_label": ""
                                    },
                                    "style": {
                                      "button": {
                                        "custom": {
                                          "layout": {
                                            "width": 44,
                                            "height": 44
                                          },
                                          "common": {
                                            "background": {
                                              "color": "mint",
                                              "opacity": 0.14
                                            },
                                            "foreground": {
                                              "color": "primary"
                                            },
                                            "cornerRadius": 22
                                          }
                                        }
                                      },
                                      "animation": {
                                        "kind": "spring",
                                        "value": "@{isSaved}",
                                        "duration": 0.3,
                                        "bounce": 0.3
                                      }
                                    },
                                    "children": [
                                      {
                                        "id": "devnews_bookmark_icon",
                                        "type": "image",
                                        "context": {
                                          "_source": "{{ @{isSaved} ? 'sf://bookmark.fill' : 'sf://bookmark' }}"
                                        },
                                        "style": {
                                          "layout": {
                                            "width": 18,
                                            "height": 18
                                          },
                                          "common": {
                                            "foreground": "{{ @{isSaved} ? {'color': 'mint'} : {'color': 'secondary'} }}"
                                          }
                                        }
                                      }
                                    ],
                                    "events": {
                                      "onTap": [
                                        {
                                          "condition": {
                                            "id": "devnews_bookmark_toggle_guard",
                                            "input": "@{isSaved}",
                                            "output": {
                                              "success": [
                                                {
                                                  "state": {
                                                    "id": "devnews_request_saved_delete",
                                                    "input": {
                                                      "pendingDeleteId": "@{item.objectID}",
                                                      "showDeleteAlert": true
                                                    }
                                                  }
                                                }
                                              ],
                                              "failure": [
                                                {
                                                  "state": {
                                                    "id": "devnews_add_bookmark",
                                                    "input": {
                                                      "bookmarks": "{{ ${bookmarks} + [@{item}] }}",
                                                      "toastText": "Article bookmarked",
                                                      "showToast": true
                                                    },
                                                    "output": {
                                                      "success": [
                                                        {
                                                          "repo": {
                                                            "id": "devnews_persist_added_bookmark",
                                                            "input": {
                                                              "repositoryId": "developer_news_digest_store",
                                                              "operation": "create",
                                                              "params": {
                                                                "collection": "library",
                                                                "documentId": "bookmarks",
                                                                "rewrite": true,
                                                                "body": {
                                                                  "items": "${bookmarks}"
                                                                }
                                                              }
                                                            },
                                                            "output": {
                                                              "success": [
                                                                {
                                                                  "service": {
                                                                    "id": "devnews_bookmark_success_haptic",
                                                                    "input": {
                                                                      "serviceId": "devnews_audio",
                                                                      "params": {
                                                                        "haptic": "success"
                                                                      }
                                                                    }
                                                                  }
                                                                },
                                                                {
                                                                  "interval": {
                                                                    "id": "devnews_bookmark_toast_timer",
                                                                    "input": {
                                                                      "delay": 2
                                                                    },
                                                                    "output": {
                                                                      "success": [
                                                                        {
                                                                          "interval": {
                                                                            "id": "devnews_bookmark_toast_timer",
                                                                            "input": {
                                                                              "cancel": true
                                                                            }
                                                                          }
                                                                        },
                                                                        {
                                                                          "state": {
                                                                            "id": "devnews_hide_bookmark_toast",
                                                                            "input": {
                                                                              "showToast": false
                                                                            }
                                                                          }
                                                                        }
                                                                      ]
                                                                    }
                                                                  }
                                                                }
                                                              ],
                                                              "failure": [
                                                                {
                                                                  "state": {
                                                                    "id": "devnews_bookmark_persist_error",
                                                                    "input": {
                                                                      "toastText": "Bookmark added, but local storage could not be updated.",
                                                                      "showToast": true
                                                                    }
                                                                  }
                                                                }
                                                              ]
                                                            }
                                                          }
                                                        }
                                                      ]
                                                    }
                                                  }
                                                }
                                              ]
                                            }
                                          }
                                        }
                                      ]
                                    }
                                  }
                                ]
                              }
                            ]
                          }
                        }
                      }
                    }
                  ]
                }
              ]
            },
            {
              "id": "devnews_toast",
              "type": "text",
              "context": {
                "_text": "${toastText}"
              },
              "style": {
                "layout": {
                  "padding": {
                    "top": 10,
                    "bottom": 10,
                    "leading": 16,
                    "trailing": 16
                  }
                },
                "common": {
                  "background": {
                    "material": "regular"
                  },
                  "foreground": {
                    "color": "primary"
                  },
                  "cornerRadius": 18,
                  "font": "subheadline",
                  "opacity": "{{ ${showToast} ? 1.0 : 0.0 }}",
                  "scale": "{{ ${showToast} ? 1.0 : 0.92 }}"
                },
                "shadow": {
                  "color": {
                    "color": "black",
                    "opacity": 0.18
                  },
                  "radius": 8,
                  "y": 4
                },
                "animation": {
                  "kind": "spring",
                  "value": "${showToast}",
                  "duration": 0.35,
                  "bounce": 0.25
                }
              }
            }
          ]
        }
      ]
    }
  ],
  "events": {
    "onAppear": [
      {
        "repo": {
          "id": "devnews_load_preferences",
          "input": {
            "repositoryId": "developer_news_digest_store",
            "operation": "read",
            "params": {
              "collection": "preferences",
              "documentId": "feed"
            }
          },
          "output": {
            "success": [
              {
                "state": {
                  "id": "devnews_apply_preferences",
                  "input": {
                    "category": "{{ @{devnews_load_preferences.category} ?? 'All' }}",
                    "feedMode": "{{ @{devnews_load_preferences.feedMode} ?? 'Latest' }}"
                  }
                }
              }
            ],
            "failure": []
          }
        }
      },
      {
        "repo": {
          "id": "devnews_load_bookmarks",
          "input": {
            "repositoryId": "developer_news_digest_store",
            "operation": "read",
            "params": {
              "collection": "library",
              "documentId": "bookmarks"
            }
          },
          "output": {
            "success": [
              {
                "state": {
                  "id": "devnews_apply_bookmarks",
                  "input": {
                    "bookmarks": "{{ @{devnews_load_bookmarks.items} ?? [] }}"
                  }
                }
              }
            ],
            "failure": []
          }
        }
      },
      {
        "repo": {
          "id": "devnews_initial_fetch",
          "input": {
            "repositoryId": "devnews_hn_api",
            "operation": "read",
            "params": {
              "subUrl": "/search_by_date",
              "body": {
                "tags": "story",
                "hitsPerPage": 50
              }
            }
          },
          "output": {
            "success": [
              {
                "state": {
                  "id": "devnews_apply_initial_feed",
                  "input": {
                    "articles": "@{devnews_initial_fetch.hits}",
                    "isLoading": false,
                    "error": ""
                  }
                }
              }
            ],
            "failure": [
              {
                "state": {
                  "id": "devnews_initial_fetch_error",
                  "input": {
                    "isLoading": false,
                    "error": "{{ 'Hacker News could not be loaded' + (notEmpty(@{devnews_initial_fetch.message}) ? ': ' + @{devnews_initial_fetch.message} : '. Check your network and pull down to try again.') }}"
                  }
                }
              }
            ]
          }
        }
      }
    ]
  }
}