{
  "id": "mod_eu_cost_living",
  "type": "module",
  "version": "1.2",
  "context": {
    "title": "EU Cost of Living",
    "icon": "🇪🇺",
    "layout": "phone"
  },
  "state": {
    "includeSpain": true,
    "includeFrance": true,
    "includeGermany": true,
    "primaryCountry": "Spain",
    "category": "All items",
    "startYear": "2020",
    "endYear": "2025",
    "periods": [],
    "spainInflation": [],
    "franceInflation": [],
    "germanyInflation": [],
    "spainIndex": [],
    "franceIndex": [],
    "germanyIndex": [],
    "isLoading": false,
    "error": "",
    "hasData": false,
    "lastUpdated": 0,
    "showSavedToast": false
  },
  "dependencies": [
    {
      "repository": {
        "remote": {
          "id": "eurostat_inflation_api",
          "config": {
            "endPoint": "https://ec.europa.eu/eurostat/api/dissemination/statistics/1.0/data/prc_hicp_aind"
          }
        }
      }
    },
    {
      "repository": {
        "remote": {
          "id": "eurostat_index_api",
          "config": {
            "endPoint": "https://ec.europa.eu/eurostat/api/dissemination/statistics/1.0/data/prc_hicp_aind"
          }
        }
      }
    },
    {
      "repository": {
        "local": {
          "id": "eu_cost_living_cache_v1",
          "config": {}
        }
      }
    },
    {
      "service": {
        "audio": {
          "id": "eu_cost_audio"
        }
      }
    }
  ],
  "children": [
    {
      "id": "cost_root",
      "type": "scroll",
      "style": {
        "layout": {
          "maxWidth": "infinity",
          "maxHeight": "infinity"
        },
        "scroll": {
          "dismissesKeyboard": "interactively"
        },
        "common": {
          "background": {
            "light": "#F4F6F5",
            "dark": "#0D1210"
          }
        }
      },
      "children": [
        {
          "id": "cost_content",
          "type": "vstack",
          "context": {
            "_spacing": 20,
            "_alignment": "leading",
            "categoryCode": "{{ switch(${category} == 'Food', 'CP01', ${category} == 'Housing', 'CP04', ${category} == 'Energy', 'CP045', ${category} == 'Transport', 'CP07', ${category} == 'Restaurants', 'CP111', ${category} == 'Consumer goods', 'GOODS', 'CP00') }}",
            "primaryInflation": "{{ ${primaryCountry} == 'Spain' ? ${spainInflation} : ${primaryCountry} == 'France' ? ${franceInflation} : ${germanyInflation} }}",
            "primaryIndex": "{{ ${primaryCountry} == 'Spain' ? ${spainIndex} : ${primaryCountry} == 'France' ? ${franceIndex} : ${germanyIndex} }}",
            "latestInflation": "{{ last(@{primaryInflation}) ?? 0 }}",
            "latestIndex": "{{ last(@{primaryIndex}) ?? 0 }}",
            "previousIndex": "{{ count(@{primaryIndex}) > 1 ? @{primaryIndex}[-2] : 0 }}",
            "indexChange": "{{ @{previousIndex} != 0 ? ((@{latestIndex} - @{previousIndex}) / @{previousIndex}) * 100 : 0 }}",
            "trendData": "{{ map(${periods}, { 'period': @{item}, 'Spain': (${includeSpain} ? ${spainInflation}[@{index}] : null), 'France': (${includeFrance} ? ${franceInflation}[@{index}] : null), 'Germany': (${includeGermany} ? ${germanyInflation}[@{index}] : null) }) }}",
            "countryData": "{{ [ { 'country': 'Spain', 'inflation': (${includeSpain} ? (last(${spainInflation}) ?? 0) : null), 'index': (${includeSpain} ? (last(${spainIndex}) ?? 0) : null) }, { 'country': 'France', 'inflation': (${includeFrance} ? (last(${franceInflation}) ?? 0) : null), 'index': (${includeFrance} ? (last(${franceIndex}) ?? 0) : null) }, { 'country': 'Germany', 'inflation': (${includeGermany} ? (last(${germanyInflation}) ?? 0) : null), 'index': (${includeGermany} ? (last(${germanyIndex}) ?? 0) : null) } ] }}",
            "hasCountrySelection": "{{ ${includeSpain} || ${includeFrance} || ${includeGermany} }}"
          },
          "style": {
            "layout": {
              "maxWidth": "infinity",
              "padding": {
                "top": 16,
                "bottom": 32,
                "leading": 16,
                "trailing": 16
              }
            }
          },
          "children": [
            {
              "id": "intro_card",
              "type": "vstack",
              "context": {
                "_spacing": 10,
                "_alignment": "leading"
              },
              "style": {
                "layout": {
                  "maxWidth": "infinity",
                  "padding": 18
                },
                "common": {
                  "background": {
                    "gradient": {
                      "linear": {
                        "colors": [
                          "#174C3C",
                          "#26735A"
                        ],
                        "startPoint": "topLeading",
                        "endPoint": "bottomTrailing"
                      }
                    }
                  },
                  "foreground": "white",
                  "cornerRadius": 20
                },
                "shadow": {
                  "color": {
                    "color": "black",
                    "opacity": 0.2
                  },
                  "radius": 12,
                  "y": 6
                }
              },
              "children": [
                {
                  "id": "intro_icon",
                  "type": "image",
                  "context": {
                    "_source": "sf://chart.line.uptrend.xyaxis"
                  },
                  "style": {
                    "layout": {
                      "width": 28,
                      "height": 28
                    },
                    "common": {
                      "foreground": "white"
                    }
                  }
                },
                {
                  "id": "intro_text",
                  "type": "text",
                  "context": {
                    "_text": "Compare annual HICP inflation and price indices using Eurostat’s public dissemination API."
                  },
                  "style": {
                    "common": {
                      "font": "headline",
                      "foreground": "white"
                    },
                    "text": {
                      "lineSpacing": 2
                    }
                  }
                },
                {
                  "id": "scope_note",
                  "type": "text",
                  "context": {
                    "_text": "Phone view includes Spain, France and Germany. Choose any combination, a category and an annual period."
                  },
                  "style": {
                    "common": {
                      "font": "caption",
                      "foreground": {
                        "color": "white",
                        "opacity": 0.78
                      }
                    }
                  }
                }
              ]
            },
            {
              "id": "filters_card",
              "type": "vstack",
              "context": {
                "_spacing": 14,
                "_alignment": "leading"
              },
              "style": {
                "layout": {
                  "maxWidth": "infinity",
                  "padding": 18
                },
                "common": {
                  "background": {
                    "material": "regular"
                  },
                  "foreground": {
                    "light": "#15201C",
                    "dark": "#F2F7F4"
                  },
                  "cornerRadius": 20
                },
                "shadow": {
                  "color": {
                    "color": "black",
                    "opacity": 0.12
                  },
                  "radius": 10,
                  "y": 5
                }
              },
              "children": [
                {
                  "id": "filters_heading",
                  "type": "label",
                  "context": {
                    "_title": "Comparison settings",
                    "_image": "sf://slider.horizontal.3"
                  },
                  "style": {
                    "common": {
                      "font": "headline",
                      "foreground": {
                        "light": "#15201C",
                        "dark": "#F2F7F4"
                      }
                    }
                  }
                },
                {
                  "id": "country_helper",
                  "type": "text",
                  "context": {
                    "_text": "Countries"
                  },
                  "style": {
                    "common": {
                      "font": "caption",
                      "foreground": "secondary"
                    }
                  }
                },
                {
                  "id": "toggle_spain",
                  "type": "toggle",
                  "context": {
                    "_label": "Spain",
                    "_image": "sf://checkmark.circle",
                    "_isOn": "${includeSpain}"
                  }
                },
                {
                  "id": "toggle_france",
                  "type": "toggle",
                  "context": {
                    "_label": "France",
                    "_image": "sf://checkmark.circle",
                    "_isOn": "${includeFrance}"
                  }
                },
                {
                  "id": "toggle_germany",
                  "type": "toggle",
                  "context": {
                    "_label": "Germany",
                    "_image": "sf://checkmark.circle",
                    "_isOn": "${includeGermany}"
                  }
                },
                {
                  "id": "no_country_warning",
                  "type": "conditional",
                  "context": {
                    "_condition": "{{ !@{hasCountrySelection} }}",
                    "_trueComponent": {
                      "id": "no_country_warning_text",
                      "type": "text",
                      "context": {
                        "_text": "Select at least one country to refresh the dashboard."
                      },
                      "style": {
                        "common": {
                          "font": "caption",
                          "foreground": "red"
                        }
                      }
                    },
                    "_falseComponent": {
                      "id": "no_country_warning_empty",
                      "type": "empty"
                    }
                  }
                },
                {
                  "id": "primary_picker",
                  "type": "picker",
                  "context": {
                    "_label": "Focus country",
                    "_selection": "${primaryCountry}",
                    "_options": [
                      "Spain",
                      "France",
                      "Germany"
                    ]
                  },
                  "style": {
                    "picker": "menu"
                  }
                },
                {
                  "id": "category_picker",
                  "type": "picker",
                  "context": {
                    "_label": "HICP category",
                    "_selection": "${category}",
                    "_options": [
                      "All items",
                      "Food",
                      "Housing",
                      "Energy",
                      "Transport",
                      "Restaurants",
                      "Consumer goods"
                    ]
                  },
                  "style": {
                    "picker": "menu"
                  }
                },
                {
                  "id": "period_row",
                  "type": "hstack",
                  "context": {
                    "_spacing": 12,
                    "_alignment": "center"
                  },
                  "style": {
                    "layout": {
                      "maxWidth": "infinity"
                    }
                  },
                  "children": [
                    {
                      "id": "start_year_picker",
                      "type": "picker",
                      "context": {
                        "_label": "From",
                        "_selection": "${startYear}",
                        "_options": [
                          "2015",
                          "2016",
                          "2017",
                          "2018",
                          "2019",
                          "2020",
                          "2021",
                          "2022",
                          "2023",
                          "2024",
                          "2025"
                        ]
                      },
                      "style": {
                        "picker": "menu",
                        "layout": {
                          "maxWidth": "infinity"
                        }
                      }
                    },
                    {
                      "id": "end_year_picker",
                      "type": "picker",
                      "context": {
                        "_label": "To",
                        "_selection": "${endYear}",
                        "_options": [
                          "2015",
                          "2016",
                          "2017",
                          "2018",
                          "2019",
                          "2020",
                          "2021",
                          "2022",
                          "2023",
                          "2024",
                          "2025"
                        ]
                      },
                      "style": {
                        "picker": "menu",
                        "layout": {
                          "maxWidth": "infinity"
                        }
                      }
                    }
                  ]
                },
                {
                  "id": "period_warning",
                  "type": "conditional",
                  "context": {
                    "_condition": "{{ cast(${startYear}, 'int') > cast(${endYear}, 'int') }}",
                    "_trueComponent": {
                      "id": "period_warning_text",
                      "type": "text",
                      "context": {
                        "_text": "The start year must not be later than the end year."
                      },
                      "style": {
                        "common": {
                          "font": "caption",
                          "foreground": "red"
                        }
                      }
                    },
                    "_falseComponent": {
                      "id": "period_warning_empty",
                      "type": "empty"
                    }
                  }
                },
                {
                  "id": "refresh_button",
                  "type": "button",
                  "context": {
                    "_label": "{{ ${isLoading} ? 'Loading Eurostat data…' : 'Refresh dashboard' }}",
                    "_image": "sf://arrow.clockwise"
                  },
                  "style": {
                    "button": {
                      "standard": {
                        "type": "borderedProminent",
                        "shape": "capsule"
                      }
                    },
                    "layout": {
                      "maxWidth": "infinity",
                      "minHeight": 48
                    },
                    "common": {
                      "disabled": "{{ ${isLoading} || !@{hasCountrySelection} || cast(${startYear}, 'int') > cast(${endYear}, 'int') }}"
                    }
                  },
                  "events": {
                    "onTap": [
                      {
                        "state": {
                          "id": "start_eurostat_refresh",
                          "input": {
                            "isLoading": true,
                            "error": ""
                          },
                          "output": {
                            "success": [
                              {
                                "repo": {
                                  "id": "fetch_spain_inflation",
                                  "input": {
                                    "repositoryId": "eurostat_inflation_api",
                                    "operation": "read",
                                    "params": {
                                      "body": {
                                        "lang": "en",
                                        "freq": "A",
                                        "unit": "RCH_A_AVG",
                                        "geo": "ES",
                                        "coicop": "@{categoryCode}",
                                        "sinceTimePeriod": "${startYear}",
                                        "untilTimePeriod": "${endYear}"
                                      }
                                    }
                                  },
                                  "output": {
                                    "success": [
                                      {
                                        "repo": {
                                          "id": "fetch_france_inflation",
                                          "input": {
                                            "repositoryId": "eurostat_inflation_api",
                                            "operation": "read",
                                            "params": {
                                              "body": {
                                                "lang": "en",
                                                "freq": "A",
                                                "unit": "RCH_A_AVG",
                                                "geo": "FR",
                                                "coicop": "@{categoryCode}",
                                                "sinceTimePeriod": "${startYear}",
                                                "untilTimePeriod": "${endYear}"
                                              }
                                            }
                                          },
                                          "output": {
                                            "success": [
                                              {
                                                "repo": {
                                                  "id": "fetch_germany_inflation",
                                                  "input": {
                                                    "repositoryId": "eurostat_inflation_api",
                                                    "operation": "read",
                                                    "params": {
                                                      "body": {
                                                        "lang": "en",
                                                        "freq": "A",
                                                        "unit": "RCH_A_AVG",
                                                        "geo": "DE",
                                                        "coicop": "@{categoryCode}",
                                                        "sinceTimePeriod": "${startYear}",
                                                        "untilTimePeriod": "${endYear}"
                                                      }
                                                    }
                                                  },
                                                  "output": {
                                                    "success": [
                                                      {
                                                        "repo": {
                                                          "id": "fetch_spain_index",
                                                          "input": {
                                                            "repositoryId": "eurostat_index_api",
                                                            "operation": "read",
                                                            "params": {
                                                              "body": {
                                                                "lang": "en",
                                                                "freq": "A",
                                                                "unit": "INX_A_AVG",
                                                                "geo": "ES",
                                                                "coicop": "@{categoryCode}",
                                                                "sinceTimePeriod": "${startYear}",
                                                                "untilTimePeriod": "${endYear}"
                                                              }
                                                            }
                                                          },
                                                          "output": {
                                                            "success": [
                                                              {
                                                                "repo": {
                                                                  "id": "fetch_france_index",
                                                                  "input": {
                                                                    "repositoryId": "eurostat_index_api",
                                                                    "operation": "read",
                                                                    "params": {
                                                                      "body": {
                                                                        "lang": "en",
                                                                        "freq": "A",
                                                                        "unit": "INX_A_AVG",
                                                                        "geo": "FR",
                                                                        "coicop": "@{categoryCode}",
                                                                        "sinceTimePeriod": "${startYear}",
                                                                        "untilTimePeriod": "${endYear}"
                                                                      }
                                                                    }
                                                                  },
                                                                  "output": {
                                                                    "success": [
                                                                      {
                                                                        "repo": {
                                                                          "id": "fetch_germany_index",
                                                                          "input": {
                                                                            "repositoryId": "eurostat_index_api",
                                                                            "operation": "read",
                                                                            "params": {
                                                                              "body": {
                                                                                "lang": "en",
                                                                                "freq": "A",
                                                                                "unit": "INX_A_AVG",
                                                                                "geo": "DE",
                                                                                "coicop": "@{categoryCode}",
                                                                                "sinceTimePeriod": "${startYear}",
                                                                                "untilTimePeriod": "${endYear}"
                                                                              }
                                                                            }
                                                                          },
                                                                          "output": {
                                                                            "success": [
                                                                              {
                                                                                "state": {
                                                                                  "id": "apply_eurostat_results",
                                                                                  "input": {
                                                                                    "periods": "{{ values(@{fetch_spain_inflation.dimension.time.category.label}) }}",
                                                                                    "spainInflation": "{{ values(@{fetch_spain_inflation.value}) }}",
                                                                                    "franceInflation": "{{ values(@{fetch_france_inflation.value}) }}",
                                                                                    "germanyInflation": "{{ values(@{fetch_germany_inflation.value}) }}",
                                                                                    "spainIndex": "{{ values(@{fetch_spain_index.value}) }}",
                                                                                    "franceIndex": "{{ values(@{fetch_france_index.value}) }}",
                                                                                    "germanyIndex": "{{ values(@{fetch_germany_index.value}) }}",
                                                                                    "isLoading": false,
                                                                                    "hasData": "{{ count(values(@{fetch_spain_inflation.value})) > 0 || count(values(@{fetch_france_inflation.value})) > 0 || count(values(@{fetch_germany_inflation.value})) > 0 }}",
                                                                                    "lastUpdated": "#{now}",
                                                                                    "showSavedToast": true
                                                                                  },
                                                                                  "output": {
                                                                                    "success": [
                                                                                      {
                                                                                        "repo": {
                                                                                          "id": "cache_eurostat_results",
                                                                                          "input": {
                                                                                            "repositoryId": "eu_cost_living_cache_v1",
                                                                                            "operation": "create",
                                                                                            "params": {
                                                                                              "collection": "dashboard",
                                                                                              "documentId": "latest",
                                                                                              "rewrite": true,
                                                                                              "body": {
                                                                                                "periods": "${periods}",
                                                                                                "spainInflation": "${spainInflation}",
                                                                                                "franceInflation": "${franceInflation}",
                                                                                                "germanyInflation": "${germanyInflation}",
                                                                                                "spainIndex": "${spainIndex}",
                                                                                                "franceIndex": "${franceIndex}",
                                                                                                "germanyIndex": "${germanyIndex}",
                                                                                                "category": "${category}",
                                                                                                "startYear": "${startYear}",
                                                                                                "endYear": "${endYear}",
                                                                                                "lastUpdated": "${lastUpdated}"
                                                                                              }
                                                                                            }
                                                                                          },
                                                                                          "output": {
                                                                                            "success": [
                                                                                              {
                                                                                                "service": {
                                                                                                  "id": "refresh_success_haptic",
                                                                                                  "input": {
                                                                                                    "serviceId": "eu_cost_audio",
                                                                                                    "params": {
                                                                                                      "sound": "none",
                                                                                                      "haptic": "success"
                                                                                                    }
                                                                                                  },
                                                                                                  "output": {
                                                                                                    "failure": [
                                                                                                      {
                                                                                                        "state": {
                                                                                                          "id": "refresh_haptic_failure",
                                                                                                          "input": {
                                                                                                            "isLoading": false,
                                                                                                            "error": "Eurostat data was updated and cached, but the success feedback could not be played."
                                                                                                          }
                                                                                                        }
                                                                                                      }
                                                                                                    ]
                                                                                                  }
                                                                                                }
                                                                                              },
                                                                                              {
                                                                                                "interval": {
                                                                                                  "id": "hide_refresh_toast_timer",
                                                                                                  "input": {
                                                                                                    "delay": 2
                                                                                                  },
                                                                                                  "output": {
                                                                                                    "success": [
                                                                                                      {
                                                                                                        "interval": {
                                                                                                          "id": "hide_refresh_toast_timer",
                                                                                                          "input": {
                                                                                                            "cancel": true
                                                                                                          }
                                                                                                        }
                                                                                                      },
                                                                                                      {
                                                                                                        "state": {
                                                                                                          "id": "hide_refresh_toast",
                                                                                                          "input": {
                                                                                                            "showSavedToast": false
                                                                                                          }
                                                                                                        }
                                                                                                      }
                                                                                                    ]
                                                                                                  }
                                                                                                }
                                                                                              }
                                                                                            ],
                                                                                            "failure": [
                                                                                              {
                                                                                                "state": {
                                                                                                  "id": "cache_warning",
                                                                                                  "input": {
                                                                                                    "isLoading": false,
                                                                                                    "error": "Live data loaded, but the local cache could not be updated."
                                                                                                  }
                                                                                                }
                                                                                              }
                                                                                            ]
                                                                                          }
                                                                                        }
                                                                                      }
                                                                                    ]
                                                                                  }
                                                                                }
                                                                              }
                                                                            ],
                                                                            "failure": [
                                                                              {
                                                                                "state": {
                                                                                  "id": "germany_index_failure",
                                                                                  "input": {
                                                                                    "isLoading": false,
                                                                                    "error": "{{ 'Eurostat request failed' + (notEmpty(@{fetch_germany_index.message}) ? ': ' + @{fetch_germany_index.message} : '. Check your network and try again.') }}"
                                                                                  }
                                                                                }
                                                                              }
                                                                            ]
                                                                          }
                                                                        }
                                                                      }
                                                                    ],
                                                                    "failure": [
                                                                      {
                                                                        "state": {
                                                                          "id": "france_index_failure",
                                                                          "input": {
                                                                            "isLoading": false,
                                                                            "error": "{{ 'Eurostat request failed' + (notEmpty(@{fetch_france_index.message}) ? ': ' + @{fetch_france_index.message} : '. Check your network and try again.') }}"
                                                                          }
                                                                        }
                                                                      }
                                                                    ]
                                                                  }
                                                                }
                                                              }
                                                            ],
                                                            "failure": [
                                                              {
                                                                "state": {
                                                                  "id": "spain_index_failure",
                                                                  "input": {
                                                                    "isLoading": false,
                                                                    "error": "{{ 'Eurostat request failed' + (notEmpty(@{fetch_spain_index.message}) ? ': ' + @{fetch_spain_index.message} : '. Check your network and try again.') }}"
                                                                  }
                                                                }
                                                              }
                                                            ]
                                                          }
                                                        }
                                                      }
                                                    ],
                                                    "failure": [
                                                      {
                                                        "state": {
                                                          "id": "germany_inflation_failure",
                                                          "input": {
                                                            "isLoading": false,
                                                            "error": "{{ 'Eurostat request failed' + (notEmpty(@{fetch_germany_inflation.message}) ? ': ' + @{fetch_germany_inflation.message} : '. Check your network and try again.') }}"
                                                          }
                                                        }
                                                      }
                                                    ]
                                                  }
                                                }
                                              }
                                            ],
                                            "failure": [
                                              {
                                                "state": {
                                                  "id": "france_inflation_failure",
                                                  "input": {
                                                    "isLoading": false,
                                                    "error": "{{ 'Eurostat request failed' + (notEmpty(@{fetch_france_inflation.message}) ? ': ' + @{fetch_france_inflation.message} : '. Check your network and try again.') }}"
                                                  }
                                                }
                                              }
                                            ]
                                          }
                                        }
                                      }
                                    ],
                                    "failure": [
                                      {
                                        "state": {
                                          "id": "spain_inflation_failure",
                                          "input": {
                                            "isLoading": false,
                                            "error": "{{ 'Eurostat request failed' + (notEmpty(@{fetch_spain_inflation.message}) ? ': ' + @{fetch_spain_inflation.message} : '. Check your network and try again.') }}"
                                          }
                                        }
                                      }
                                    ]
                                  }
                                }
                              }
                            ]
                          }
                        }
                      }
                    ]
                  }
                }
              ]
            },
            {
              "id": "loading_state",
              "type": "conditional",
              "context": {
                "_condition": "${isLoading}",
                "_trueComponent": {
                  "id": "loading_card",
                  "type": "vstack",
                  "context": {
                    "_spacing": 12,
                    "_alignment": "center"
                  },
                  "style": {
                    "layout": {
                      "maxWidth": "infinity",
                      "padding": 24
                    },
                    "common": {
                      "background": {
                        "material": "regular"
                      },
                      "foreground": {
                        "light": "#15201C",
                        "dark": "#F2F7F4"
                      },
                      "cornerRadius": 20
                    }
                  },
                  "children": [
                    {
                      "id": "loading_progress",
                      "type": "progress"
                    },
                    {
                      "id": "loading_text",
                      "type": "text",
                      "context": {
                        "_text": "Loading annual HICP observations from Eurostat…"
                      },
                      "style": {
                        "common": {
                          "font": "subheadline",
                          "foreground": {
                            "light": "#15201C",
                            "dark": "#F2F7F4"
                          }
                        },
                        "text": {
                          "multilineTextAlignment": "center"
                        }
                      }
                    }
                  ]
                },
                "_falseComponent": {
                  "id": "loading_empty",
                  "type": "empty"
                }
              }
            },
            {
              "id": "error_state",
              "type": "conditional",
              "context": {
                "_condition": "{{ notEmpty(${error}) }}",
                "_trueComponent": {
                  "id": "error_card",
                  "type": "vstack",
                  "context": {
                    "_spacing": 8,
                    "_alignment": "leading"
                  },
                  "style": {
                    "layout": {
                      "maxWidth": "infinity",
                      "padding": 18
                    },
                    "common": {
                      "background": {
                        "light": "#FFF0F0",
                        "dark": "#321718"
                      },
                      "foreground": {
                        "light": "#5C1115",
                        "dark": "#FFD9DA"
                      },
                      "cornerRadius": 18
                    }
                  },
                  "children": [
                    {
                      "id": "error_label",
                      "type": "label",
                      "context": {
                        "_title": "Data unavailable",
                        "_image": "sf://exclamationmark.triangle.fill"
                      },
                      "style": {
                        "common": {
                          "font": "headline",
                          "foreground": {
                            "light": "#5C1115",
                            "dark": "#FFD9DA"
                          }
                        }
                      }
                    },
                    {
                      "id": "error_message",
                      "type": "text",
                      "context": {
                        "_text": "${error}"
                      },
                      "style": {
                        "common": {
                          "font": "caption",
                          "foreground": {
                            "light": "#5C1115",
                            "dark": "#FFD9DA"
                          }
                        }
                      }
                    }
                  ]
                },
                "_falseComponent": {
                  "id": "error_empty",
                  "type": "empty"
                }
              }
            },
            {
              "id": "dashboard_state",
              "type": "conditional",
              "context": {
                "_condition": "${hasData}",
                "_trueComponent": {
                  "id": "dashboard_stack",
                  "type": "vstack",
                  "context": {
                    "_spacing": 20,
                    "_alignment": "leading"
                  },
                  "style": {
                    "layout": {
                      "maxWidth": "infinity"
                    }
                  },
                  "children": [
                    {
                      "id": "latest_metrics_card",
                      "type": "vstack",
                      "context": {
                        "_spacing": 14,
                        "_alignment": "leading"
                      },
                      "style": {
                        "layout": {
                          "maxWidth": "infinity",
                          "padding": 18
                        },
                        "common": {
                          "background": {
                            "gradient": {
                              "linear": {
                                "colors": [
                                  "#193F35",
                                  "#2D6A57"
                                ],
                                "startPoint": "topLeading",
                                "endPoint": "bottomTrailing"
                              }
                            }
                          },
                          "foreground": "white",
                          "cornerRadius": 20
                        },
                        "shadow": {
                          "color": {
                            "color": "black",
                            "opacity": 0.2
                          },
                          "radius": 12,
                          "y": 6
                        },
                        "animation": {
                          "kind": "spring",
                          "value": "${primaryCountry}",
                          "duration": 0.35,
                          "bounce": 0.25
                        }
                      },
                      "children": [
                        {
                          "id": "latest_heading",
                          "type": "label",
                          "context": {
                            "_title": "{{ ${primaryCountry} + ' · ' + ${category} }}",
                            "_image": "sf://gauge.with.dots.needle.67percent"
                          },
                          "style": {
                            "common": {
                              "font": "headline",
                              "foreground": "white"
                            }
                          }
                        },
                        {
                          "id": "latest_period",
                          "type": "text",
                          "context": {
                            "_text": "{{ 'Annual data · ' + ${startYear} + '–' + ${endYear} }}"
                          },
                          "style": {
                            "common": {
                              "font": "caption",
                              "foreground": {
                                "color": "white",
                                "opacity": 0.75
                              }
                            }
                          }
                        },
                        {
                          "id": "metric_row",
                          "type": "hstack",
                          "context": {
                            "_spacing": 16,
                            "_alignment": "center"
                          },
                          "style": {
                            "layout": {
                              "maxWidth": "infinity"
                            }
                          },
                          "children": [
                            {
                              "id": "inflation_metric",
                              "type": "vstack",
                              "context": {
                                "_spacing": 4,
                                "_alignment": "leading"
                              },
                              "style": {
                                "layout": {
                                  "maxWidth": "infinity"
                                }
                              },
                              "children": [
                                {
                                  "id": "inflation_metric_label",
                                  "type": "text",
                                  "context": {
                                    "_text": "LATEST INFLATION"
                                  },
                                  "style": {
                                    "common": {
                                      "font": "caption",
                                      "foreground": {
                                        "color": "white",
                                        "opacity": 0.7
                                      }
                                    }
                                  }
                                },
                                {
                                  "id": "inflation_metric_value",
                                  "type": "text",
                                  "context": {
                                    "_text": "@{latestInflation}",
                                    "_format": {
                                      "number": {
                                        "style": "percent",
                                        "maximumFractionDigits": 1
                                      }
                                    }
                                  },
                                  "style": {
                                    "common": {
                                      "font": {
                                        "kind": "largeTitle",
                                        "weight": "bold"
                                      },
                                      "foreground": "white"
                                    }
                                  }
                                }
                              ]
                            },
                            {
                              "id": "index_metric",
                              "type": "vstack",
                              "context": {
                                "_spacing": 4,
                                "_alignment": "leading"
                              },
                              "style": {
                                "layout": {
                                  "maxWidth": "infinity"
                                }
                              },
                              "children": [
                                {
                                  "id": "index_metric_label",
                                  "type": "text",
                                  "context": {
                                    "_text": "PRICE INDEX"
                                  },
                                  "style": {
                                    "common": {
                                      "font": "caption",
                                      "foreground": {
                                        "color": "white",
                                        "opacity": 0.7
                                      }
                                    }
                                  }
                                },
                                {
                                  "id": "index_metric_value",
                                  "type": "text",
                                  "context": {
                                    "_text": "@{latestIndex}",
                                    "_format": {
                                      "number": {
                                        "style": "decimal",
                                        "maximumFractionDigits": 1
                                      }
                                    }
                                  },
                                  "style": {
                                    "common": {
                                      "font": {
                                        "kind": "title",
                                        "weight": "bold"
                                      },
                                      "foreground": "white"
                                    }
                                  }
                                },
                                {
                                  "id": "index_change_value",
                                  "type": "text",
                                  "context": {
                                    "_text": "{{ 'Change: ' + cast(@{indexChange}, 'int') + '%' }}"
                                  },
                                  "style": {
                                    "common": {
                                      "font": "caption",
                                      "foreground": {
                                        "color": "white",
                                        "opacity": 0.78
                                      }
                                    }
                                  }
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "id": "trend_chart_card",
                      "type": "vstack",
                      "context": {
                        "_spacing": 12,
                        "_alignment": "leading"
                      },
                      "style": {
                        "layout": {
                          "maxWidth": "infinity",
                          "padding": 18
                        },
                        "common": {
                          "background": {
                            "material": "regular"
                          },
                          "foreground": {
                            "light": "#15201C",
                            "dark": "#F2F7F4"
                          },
                          "cornerRadius": 20
                        },
                        "shadow": {
                          "color": {
                            "color": "black",
                            "opacity": 0.12
                          },
                          "radius": 10,
                          "y": 5
                        }
                      },
                      "children": [
                        {
                          "id": "trend_chart_title",
                          "type": "label",
                          "context": {
                            "_title": "Inflation trend",
                            "_image": "sf://chart.xyaxis.line"
                          },
                          "style": {
                            "common": {
                              "font": "headline",
                              "foreground": {
                                "light": "#15201C",
                                "dark": "#F2F7F4"
                              }
                            }
                          }
                        },
                        {
                          "id": "trend_chart",
                          "type": "chart",
                          "context": {
                            "_data": "@{trendData}",
                            "_series": [
                              {
                                "kind": "line",
                                "x": "period",
                                "y": "Spain",
                                "label": "Spain",
                                "color": "#F59E0B"
                              },
                              {
                                "kind": "line",
                                "x": "period",
                                "y": "France",
                                "label": "France",
                                "color": "#38BDF8"
                              },
                              {
                                "kind": "line",
                                "x": "period",
                                "y": "Germany",
                                "label": "Germany",
                                "color": "#86EFAC"
                              }
                            ],
                            "_xAxis": {
                              "type": "category",
                              "title": "Year"
                            },
                            "_yAxis": {
                              "type": "number",
                              "title": "Annual change (%)"
                            }
                          },
                          "style": {
                            "layout": {
                              "maxWidth": "infinity",
                              "height": 260
                            },
                            "chart": {
                              "legend": "bottom",
                              "gridLines": true,
                              "animated": true
                            }
                          }
                        }
                      ]
                    },
                    {
                      "id": "country_chart_card",
                      "type": "vstack",
                      "context": {
                        "_spacing": 12,
                        "_alignment": "leading"
                      },
                      "style": {
                        "layout": {
                          "maxWidth": "infinity",
                          "padding": 18
                        },
                        "common": {
                          "background": {
                            "material": "regular"
                          },
                          "foreground": {
                            "light": "#15201C",
                            "dark": "#F2F7F4"
                          },
                          "cornerRadius": 20
                        },
                        "shadow": {
                          "color": {
                            "color": "black",
                            "opacity": 0.12
                          },
                          "radius": 10,
                          "y": 5
                        }
                      },
                      "children": [
                        {
                          "id": "country_chart_title",
                          "type": "label",
                          "context": {
                            "_title": "Latest country comparison",
                            "_image": "sf://chart.bar.xaxis"
                          },
                          "style": {
                            "common": {
                              "font": "headline",
                              "foreground": {
                                "light": "#15201C",
                                "dark": "#F2F7F4"
                              }
                            }
                          }
                        },
                        {
                          "id": "country_inflation_chart",
                          "type": "chart",
                          "context": {
                            "_data": "@{countryData}",
                            "_series": [
                              {
                                "kind": "bar",
                                "x": "country",
                                "y": "inflation",
                                "label": "Inflation",
                                "color": "#4A8F73"
                              }
                            ],
                            "_xAxis": {
                              "type": "category"
                            },
                            "_yAxis": {
                              "type": "number",
                              "title": "Annual change (%)"
                            }
                          },
                          "style": {
                            "layout": {
                              "maxWidth": "infinity",
                              "height": 230
                            },
                            "chart": {
                              "legend": "none",
                              "gridLines": true,
                              "animated": true
                            }
                          }
                        }
                      ]
                    },
                    {
                      "id": "price_index_chart_card",
                      "type": "vstack",
                      "context": {
                        "_spacing": 12,
                        "_alignment": "leading"
                      },
                      "style": {
                        "layout": {
                          "maxWidth": "infinity",
                          "padding": 18
                        },
                        "common": {
                          "background": {
                            "material": "regular"
                          },
                          "foreground": {
                            "light": "#15201C",
                            "dark": "#F2F7F4"
                          },
                          "cornerRadius": 20
                        },
                        "shadow": {
                          "color": {
                            "color": "black",
                            "opacity": 0.12
                          },
                          "radius": 10,
                          "y": 5
                        }
                      },
                      "children": [
                        {
                          "id": "price_index_chart_title",
                          "type": "label",
                          "context": {
                            "_title": "Latest price-index comparison",
                            "_image": "sf://eurosign.circle.fill"
                          },
                          "style": {
                            "common": {
                              "font": "headline",
                              "foreground": {
                                "light": "#15201C",
                                "dark": "#F2F7F4"
                              }
                            }
                          }
                        },
                        {
                          "id": "price_index_chart",
                          "type": "chart",
                          "context": {
                            "_data": "@{countryData}",
                            "_series": [
                              {
                                "kind": "bar",
                                "x": "country",
                                "y": "index",
                                "label": "Price index",
                                "color": "#60A5FA"
                              }
                            ],
                            "_xAxis": {
                              "type": "category"
                            },
                            "_yAxis": {
                              "type": "number",
                              "title": "Index"
                            }
                          },
                          "style": {
                            "layout": {
                              "maxWidth": "infinity",
                              "height": 230
                            },
                            "chart": {
                              "legend": "none",
                              "gridLines": true,
                              "animated": true
                            }
                          }
                        }
                      ]
                    },
                    {
                      "id": "source_card",
                      "type": "vstack",
                      "context": {
                        "_spacing": 8,
                        "_alignment": "leading"
                      },
                      "style": {
                        "layout": {
                          "maxWidth": "infinity",
                          "padding": 18
                        },
                        "common": {
                          "background": {
                            "color": "surfaceVariant"
                          },
                          "foreground": {
                            "color": "onSurfaceVariant"
                          },
                          "cornerRadius": 18
                        }
                      },
                      "children": [
                        {
                          "id": "source_label",
                          "type": "label",
                          "context": {
                            "_title": "Source: Eurostat",
                            "_image": "sf://building.columns.fill"
                          },
                          "style": {
                            "common": {
                              "font": "headline",
                              "foreground": {
                                "color": "onSurfaceVariant"
                              }
                            }
                          }
                        },
                        {
                          "id": "source_period",
                          "type": "text",
                          "context": {
                            "_text": "{{ 'Dataset: prc_hicp_aind · Annual HICP · ' + ${startYear} + '–' + ${endYear} }}"
                          },
                          "style": {
                            "common": {
                              "font": "caption",
                              "foreground": {
                                "color": "onSurfaceVariant"
                              }
                            }
                          }
                        },
                        {
                          "id": "source_update_row",
                          "type": "hstack",
                          "context": {
                            "_spacing": 4,
                            "_alignment": "center"
                          },
                          "children": [
                            {
                              "id": "source_update_label",
                              "type": "text",
                              "context": {
                                "_text": "Retrieved"
                              },
                              "style": {
                                "common": {
                                  "font": "caption",
                                  "foreground": {
                                    "color": "onSurfaceVariant"
                                  }
                                }
                              }
                            },
                            {
                              "id": "source_update_date",
                              "type": "text",
                              "context": {
                                "_text": "${lastUpdated}",
                                "_format": {
                                  "date": {
                                    "style": "datetime",
                                    "dateStyle": "medium",
                                    "timeStyle": "short"
                                  }
                                }
                              },
                              "style": {
                                "common": {
                                  "font": "caption",
                                  "foreground": {
                                    "color": "onSurfaceVariant"
                                  }
                                }
                              }
                            }
                          ]
                        },
                        {
                          "id": "cache_note",
                          "type": "text",
                          "context": {
                            "_text": "The latest successful response is cached on this device. Use Refresh after changing countries, category or period."
                          },
                          "style": {
                            "common": {
                              "font": "caption",
                              "foreground": {
                                "color": "onSurfaceVariant"
                              }
                            }
                          }
                        }
                      ]
                    }
                  ]
                },
                "_falseComponent": {
                  "id": "empty_dashboard",
                  "type": "vstack",
                  "context": {
                    "_spacing": 12,
                    "_alignment": "center"
                  },
                  "style": {
                    "layout": {
                      "maxWidth": "infinity",
                      "padding": {
                        "top": 32,
                        "bottom": 32,
                        "leading": 20,
                        "trailing": 20
                      }
                    },
                    "common": {
                      "background": {
                        "material": "regular"
                      },
                      "foreground": {
                        "light": "#15201C",
                        "dark": "#F2F7F4"
                      },
                      "cornerRadius": 20
                    }
                  },
                  "children": [
                    {
                      "id": "empty_dashboard_icon",
                      "type": "image",
                      "context": {
                        "_source": "sf://chart.bar.doc.horizontal"
                      },
                      "style": {
                        "layout": {
                          "width": 46,
                          "height": 46
                        },
                        "common": {
                          "foreground": "#4A8F73"
                        }
                      }
                    },
                    {
                      "id": "empty_dashboard_text",
                      "type": "text",
                      "context": {
                        "_text": "Choose the comparison settings and refresh to load Eurostat observations."
                      },
                      "style": {
                        "common": {
                          "font": "subheadline",
                          "foreground": {
                            "light": "#15201C",
                            "dark": "#F2F7F4"
                          }
                        },
                        "text": {
                          "multilineTextAlignment": "center"
                        }
                      }
                    }
                  ]
                }
              }
            },
            {
              "id": "refresh_toast",
              "type": "text",
              "context": {
                "_text": "Eurostat data updated and cached"
              },
              "style": {
                "layout": {
                  "padding": {
                    "top": 9,
                    "bottom": 9,
                    "leading": 16,
                    "trailing": 16
                  }
                },
                "common": {
                  "background": {
                    "material": "regular"
                  },
                  "foreground": {
                    "light": "#174C3C",
                    "dark": "#A7F3D0"
                  },
                  "cornerRadius": 18,
                  "font": "subheadline",
                  "opacity": "{{ ${showSavedToast} ? 1 : 0 }}",
                  "scale": "{{ ${showSavedToast} ? 1 : 0.92 }}"
                },
                "animation": {
                  "kind": "spring",
                  "value": "${showSavedToast}",
                  "duration": 0.35,
                  "bounce": 0.25
                }
              }
            }
          ]
        }
      ]
    }
  ],
  "events": {
    "onAppear": [
      {
        "repo": {
          "id": "load_cached_dashboard",
          "input": {
            "repositoryId": "eu_cost_living_cache_v1",
            "operation": "read",
            "params": {
              "collection": "dashboard",
              "documentId": "latest"
            }
          },
          "output": {
            "success": [
              {
                "state": {
                  "id": "apply_cached_dashboard",
                  "input": {
                    "periods": "@{load_cached_dashboard.periods}",
                    "spainInflation": "@{load_cached_dashboard.spainInflation}",
                    "franceInflation": "@{load_cached_dashboard.franceInflation}",
                    "germanyInflation": "@{load_cached_dashboard.germanyInflation}",
                    "spainIndex": "@{load_cached_dashboard.spainIndex}",
                    "franceIndex": "@{load_cached_dashboard.franceIndex}",
                    "germanyIndex": "@{load_cached_dashboard.germanyIndex}",
                    "category": "@{load_cached_dashboard.category}",
                    "startYear": "@{load_cached_dashboard.startYear}",
                    "endYear": "@{load_cached_dashboard.endYear}",
                    "lastUpdated": "@{load_cached_dashboard.lastUpdated}",
                    "hasData": "{{ count(@{load_cached_dashboard.periods}) > 0 }}",
                    "isLoading": false
                  }
                }
              }
            ],
            "failure": [
              {
                "state": {
                  "id": "first_launch_defaults",
                  "input": {
                    "hasData": false,
                    "isLoading": false,
                    "error": ""
                  }
                }
              }
            ]
          }
        }
      }
    ]
  }
}