{
  "id": "weather_ny_widget",
  "type": "module",
  "version": "1.0",
  "context": {
    "title": "NY Weather",
    "icon": "🗽",
    "layout": "widget"
  },
  "state": {
    "isLoading": true,
    "error": "",
    "weather": {},
    "updatedAt": 0
  },
  "dependencies": [
    {
      "repository": {
        "remote": {
          "id": "ny_weather_api",
          "config": {
            "endPoint": "https://api.open-meteo.com/v1/forecast"
          }
        }
      }
    }
  ],
  "children": [
    {
      "id": "widget_root",
      "type": "zstack",
      "context": {
        "_alignment": "center"
      },
      "style": {
        "layout": {
          "maxWidth": "infinity",
          "maxHeight": "infinity",
          "padding": 12
        }
      },
      "children": [
        {
          "id": "widget_card",
          "type": "vstack",
          "context": {
            "_spacing": 10,
            "_alignment": "leading",
            "conditionLabel": "{{ switch(${weather.current.weather_code} < 2, 'Clear', ${weather.current.weather_code} < 4, 'Partly cloudy', ${weather.current.weather_code} < 50, 'Fog', ${weather.current.weather_code} < 70, 'Rain', ${weather.current.weather_code} < 80, 'Snow', 'Storm') }}",
            "conditionIcon": "{{ switch(${weather.current.weather_code} < 2, 'sf://sun.max.fill', ${weather.current.weather_code} < 4, 'sf://cloud.sun.fill', ${weather.current.weather_code} < 50, 'sf://cloud.fog.fill', ${weather.current.weather_code} < 70, 'sf://cloud.rain.fill', ${weather.current.weather_code} < 80, 'sf://cloud.snow.fill', 'sf://cloud.bolt.rain.fill') }}"
          },
          "style": {
            "layout": {
              "maxWidth": "infinity",
              "maxHeight": "infinity",
              "padding": 16
            },
            "common": {
              "background": {
                "gradient": {
                  "linear": {
                    "colors": [
                      "#0F3D91",
                      "#1E6FD9",
                      "#69B7FF"
                    ],
                    "startPoint": "topLeading",
                    "endPoint": "bottomTrailing"
                  }
                }
              },
              "foreground": {
                "color": "white"
              },
              "cornerRadius": 24
            },
            "shadow": {
              "color": {
                "color": "black",
                "opacity": 0.2
              },
              "radius": 16,
              "x": 0,
              "y": 8
            }
          },
          "children": [
            {
              "id": "top_row",
              "type": "hstack",
              "context": {
                "_spacing": 8,
                "_alignment": "center"
              },
              "style": {
                "layout": {
                  "maxWidth": "infinity"
                }
              },
              "children": [
                {
                  "id": "city_stack",
                  "type": "vstack",
                  "context": {
                    "_spacing": 2,
                    "_alignment": "leading"
                  },
                  "style": {
                    "layout": {
                      "maxWidth": "infinity"
                    }
                  },
                  "children": [
                    {
                      "id": "city_label",
                      "type": "text",
                      "context": {
                        "_text": "New York"
                      },
                      "style": {
                        "common": {
                          "font": {
                            "kind": "headline",
                            "weight": "bold"
                          },
                          "foreground": {
                            "color": "white"
                          }
                        }
                      }
                    },
                    {
                      "id": "updated_label",
                      "type": "text",
                      "context": {
                        "_text": "${updatedAt}",
                        "_format": {
                          "date": {
                            "style": "custom",
                            "pattern": "'Updated' HH:mm"
                          }
                        }
                      },
                      "style": {
                        "common": {
                          "font": "caption",
                          "foreground": {
                            "color": {
                              "color": "white",
                              "opacity": 0.78
                            }
                          }
                        }
                      }
                    }
                  ]
                },
                {
                  "id": "status_chip",
                  "type": "hstack",
                  "context": {
                    "_spacing": 6,
                    "_alignment": "center"
                  },
                  "style": {
                    "layout": {
                      "padding": {
                        "top": 6,
                        "bottom": 6,
                        "leading": 10,
                        "trailing": 10
                      }
                    },
                    "common": {
                      "background": {
                        "color": {
                          "color": "white",
                          "opacity": 0.18
                        }
                      },
                      "foreground": {
                        "color": "white"
                      },
                      "cornerRadius": 999
                    }
                  },
                  "children": [
                    {
                      "id": "status_chip_icon",
                      "type": "image",
                      "context": {
                        "_source": "@{conditionIcon}"
                      },
                      "style": {
                        "layout": {
                          "width": 14,
                          "height": 14
                        },
                        "common": {
                          "foreground": {
                            "color": "white"
                          }
                        }
                      }
                    },
                    {
                      "id": "status_chip_text",
                      "type": "text",
                      "context": {
                        "_text": "@{conditionLabel}"
                      },
                      "style": {
                        "common": {
                          "font": "caption",
                          "foreground": {
                            "color": "white"
                          }
                        }
                      }
                    }
                  ]
                }
              ]
            },
            {
              "id": "content_switch",
              "type": "conditional",
              "context": {
                "_condition": "${isLoading}",
                "_trueComponent": {
                  "id": "loading_view",
                  "type": "vstack",
                  "context": {
                    "_spacing": 10,
                    "_alignment": "center"
                  },
                  "style": {
                    "layout": {
                      "maxWidth": "infinity",
                      "maxHeight": "infinity"
                    }
                  },
                  "children": [
                    {
                      "id": "loading_icon",
                      "type": "progress",
                      "context": {
                        "_value": 0,
                        "_total": 1
                      },
                      "style": {
                        "common": {
                          "tint": "white"
                        }
                      }
                    },
                    {
                      "id": "loading_text",
                      "type": "text",
                      "context": {
                        "_text": "Loading forecast"
                      },
                      "style": {
                        "common": {
                          "font": "caption",
                          "foreground": {
                            "color": {
                              "color": "white",
                              "opacity": 0.84
                            }
                          }
                        }
                      }
                    }
                  ]
                },
                "_falseComponent": {
                  "id": "loaded_switch",
                  "type": "conditional",
                  "context": {
                    "_condition": "{{ notEmpty(${error}) }}",
                    "_trueComponent": {
                      "id": "error_view",
                      "type": "vstack",
                      "context": {
                        "_spacing": 10,
                        "_alignment": "center"
                      },
                      "style": {
                        "layout": {
                          "maxWidth": "infinity",
                          "maxHeight": "infinity"
                        }
                      },
                      "children": [
                        {
                          "id": "error_icon",
                          "type": "image",
                          "context": {
                            "_source": "sf://cloud.slash.fill"
                          },
                          "style": {
                            "layout": {
                              "width": 32,
                              "height": 32
                            },
                            "common": {
                              "foreground": {
                                "color": "white"
                              }
                            }
                          }
                        },
                        {
                          "id": "error_text",
                          "type": "text",
                          "context": {
                            "_text": "${error}"
                          },
                          "style": {
                            "common": {
                              "font": "caption",
                              "foreground": {
                                "color": {
                                  "color": "white",
                                  "opacity": 0.9
                                }
                              }
                            },
                            "text": {
                              "multilineTextAlignment": "center",
                              "lineLimit": 3
                            }
                          }
                        }
                      ]
                    },
                    "_falseComponent": {
                      "id": "weather_view",
                      "type": "vstack",
                      "context": {
                        "_spacing": 12,
                        "_alignment": "leading"
                      },
                      "style": {
                        "layout": {
                          "maxWidth": "infinity",
                          "maxHeight": "infinity"
                        }
                      },
                      "children": [
                        {
                          "id": "hero_row",
                          "type": "hstack",
                          "context": {
                            "_spacing": 10,
                            "_alignment": "center"
                          },
                          "style": {
                            "layout": {
                              "maxWidth": "infinity"
                            }
                          },
                          "children": [
                            {
                              "id": "hero_temp_stack",
                              "type": "vstack",
                              "context": {
                                "_spacing": 2,
                                "_alignment": "leading"
                              },
                              "style": {
                                "layout": {
                                  "maxWidth": "infinity"
                                }
                              },
                              "children": [
                                {
                                  "id": "temp_text",
                                  "type": "text",
                                  "context": {
                                    "_text": "{{ cast(${weather.current.temperature_2m}, 'int') + '°C' }}"
                                  },
                                  "style": {
                                    "common": {
                                      "font": {
                                        "kind": "largeTitle",
                                        "weight": "bold"
                                      },
                                      "foreground": {
                                        "color": "white"
                                      }
                                    },
                                    "text": {
                                      "lineLimit": 1,
                                      "minimumScaleFactor": 0.7
                                    }
                                  }
                                },
                                {
                                  "id": "feels_like_text",
                                  "type": "text",
                                  "context": {
                                    "_text": "{{ 'Feels like ' + cast(${weather.current.apparent_temperature}, 'int') + '°C' }}"
                                  },
                                  "style": {
                                    "common": {
                                      "font": "caption",
                                      "foreground": {
                                        "color": {
                                          "color": "white",
                                          "opacity": 0.8
                                        }
                                      }
                                    }
                                  }
                                }
                              ]
                            },
                            {
                              "id": "hero_icon",
                              "type": "image",
                              "context": {
                                "_source": "@{conditionIcon}"
                              },
                              "style": {
                                "layout": {
                                  "width": 54,
                                  "height": 54
                                },
                                "common": {
                                  "foreground": {
                                    "color": "white"
                                  }
                                }
                              }
                            }
                          ]
                        },
                        {
                          "id": "stats_grid",
                          "type": "grid",
                          "context": {
                            "_gridType": "lazyVGrid",
                            "_spacing": 8
                          },
                          "style": {
                            "grid": {
                              "columns": [
                                {
                                  "kind": "flexible",
                                  "minimum": 80,
                                  "maximum": 220,
                                  "spacing": 8
                                },
                                {
                                  "kind": "flexible",
                                  "minimum": 80,
                                  "maximum": 220,
                                  "spacing": 8
                                }
                              ]
                            },
                            "layout": {
                              "maxWidth": "infinity"
                            }
                          },
                          "children": [
                            {
                              "id": "high_card",
                              "type": "vstack",
                              "context": {
                                "_spacing": 4,
                                "_alignment": "leading"
                              },
                              "style": {
                                "layout": {
                                  "maxWidth": "infinity",
                                  "padding": 10
                                },
                                "common": {
                                  "background": {
                                    "color": {
                                      "color": "white",
                                      "opacity": 0.14
                                    }
                                  },
                                  "foreground": {
                                    "color": "white"
                                  },
                                  "cornerRadius": 16
                                }
                              },
                              "children": [
                                {
                                  "id": "high_label",
                                  "type": "label",
                                  "context": {
                                    "_title": "High",
                                    "_image": "sf://arrow.up"
                                  },
                                  "style": {
                                    "common": {
                                      "font": "caption",
                                      "foreground": {
                                        "color": {
                                          "color": "white",
                                          "opacity": 0.78
                                        }
                                      }
                                    }
                                  }
                                },
                                {
                                  "id": "high_value",
                                  "type": "text",
                                  "context": {
                                    "_text": "{{ cast(${weather.daily.temperature_2m_max[0]}, 'int') + '°' }}"
                                  },
                                  "style": {
                                    "common": {
                                      "font": {
                                        "kind": "title3",
                                        "weight": "bold"
                                      },
                                      "foreground": {
                                        "color": "white"
                                      }
                                    }
                                  }
                                }
                              ]
                            },
                            {
                              "id": "low_card",
                              "type": "vstack",
                              "context": {
                                "_spacing": 4,
                                "_alignment": "leading"
                              },
                              "style": {
                                "layout": {
                                  "maxWidth": "infinity",
                                  "padding": 10
                                },
                                "common": {
                                  "background": {
                                    "color": {
                                      "color": "white",
                                      "opacity": 0.14
                                    }
                                  },
                                  "foreground": {
                                    "color": "white"
                                  },
                                  "cornerRadius": 16
                                }
                              },
                              "children": [
                                {
                                  "id": "low_label",
                                  "type": "label",
                                  "context": {
                                    "_title": "Low",
                                    "_image": "sf://arrow.down"
                                  },
                                  "style": {
                                    "common": {
                                      "font": "caption",
                                      "foreground": {
                                        "color": {
                                          "color": "white",
                                          "opacity": 0.78
                                        }
                                      }
                                    }
                                  }
                                },
                                {
                                  "id": "low_value",
                                  "type": "text",
                                  "context": {
                                    "_text": "{{ cast(${weather.daily.temperature_2m_min[0]}, 'int') + '°' }}"
                                  },
                                  "style": {
                                    "common": {
                                      "font": {
                                        "kind": "title3",
                                        "weight": "bold"
                                      },
                                      "foreground": {
                                        "color": "white"
                                      }
                                    }
                                  }
                                }
                              ]
                            },
                            {
                              "id": "rain_card",
                              "type": "vstack",
                              "context": {
                                "_spacing": 4,
                                "_alignment": "leading"
                              },
                              "style": {
                                "layout": {
                                  "maxWidth": "infinity",
                                  "padding": 10
                                },
                                "common": {
                                  "background": {
                                    "color": {
                                      "color": "white",
                                      "opacity": 0.14
                                    }
                                  },
                                  "foreground": {
                                    "color": "white"
                                  },
                                  "cornerRadius": 16
                                }
                              },
                              "children": [
                                {
                                  "id": "rain_label",
                                  "type": "label",
                                  "context": {
                                    "_title": "Rain",
                                    "_image": "sf://drop.fill"
                                  },
                                  "style": {
                                    "common": {
                                      "font": "caption",
                                      "foreground": {
                                        "color": {
                                          "color": "white",
                                          "opacity": 0.78
                                        }
                                      }
                                    }
                                  }
                                },
                                {
                                  "id": "rain_value",
                                  "type": "text",
                                  "context": {
                                    "_text": "{{ cast(${weather.daily.precipitation_probability_max[0]}, 'int') + '%' }}"
                                  },
                                  "style": {
                                    "common": {
                                      "font": {
                                        "kind": "title3",
                                        "weight": "bold"
                                      },
                                      "foreground": {
                                        "color": "white"
                                      }
                                    }
                                  }
                                }
                              ]
                            },
                            {
                              "id": "wind_card",
                              "type": "vstack",
                              "context": {
                                "_spacing": 4,
                                "_alignment": "leading"
                              },
                              "style": {
                                "layout": {
                                  "maxWidth": "infinity",
                                  "padding": 10
                                },
                                "common": {
                                  "background": {
                                    "color": {
                                      "color": "white",
                                      "opacity": 0.14
                                    }
                                  },
                                  "foreground": {
                                    "color": "white"
                                  },
                                  "cornerRadius": 16
                                }
                              },
                              "children": [
                                {
                                  "id": "wind_label",
                                  "type": "label",
                                  "context": {
                                    "_title": "Wind",
                                    "_image": "sf://wind"
                                  },
                                  "style": {
                                    "common": {
                                      "font": "caption",
                                      "foreground": {
                                        "color": {
                                          "color": "white",
                                          "opacity": 0.78
                                        }
                                      }
                                    }
                                  }
                                },
                                {
                                  "id": "wind_value",
                                  "type": "text",
                                  "context": {
                                    "_text": "{{ cast(${weather.current.wind_speed_10m}, 'int') + ' km/h' }}"
                                  },
                                  "style": {
                                    "common": {
                                      "font": {
                                        "kind": "title3",
                                        "weight": "bold"
                                      },
                                      "foreground": {
                                        "color": "white"
                                      }
                                    }
                                  }
                                }
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          ]
        }
      ]
    }
  ],
  "events": {
    "onAppear": [
      {
        "state": {
          "id": "ny_weather_start",
          "input": {
            "isLoading": true,
            "error": ""
          },
          "output": {
            "success": [
              {
                "repo": {
                  "id": "ny_weather_fetch",
                  "input": {
                    "repositoryId": "ny_weather_api",
                    "operation": "read",
                    "params": {
                      "body": {
                        "latitude": 40.7128,
                        "longitude": -74.006,
                        "current": "temperature_2m,apparent_temperature,weather_code,wind_speed_10m",
                        "daily": "temperature_2m_max,temperature_2m_min,precipitation_probability_max",
                        "temperature_unit": "celsius",
                        "wind_speed_unit": "kmh",
                        "timezone": "America/New_York",
                        "forecast_days": 1
                      }
                    }
                  },
                  "output": {
                    "success": [
                      {
                        "state": {
                          "id": "ny_weather_apply",
                          "input": {
                            "weather": "@{ny_weather_fetch}",
                            "updatedAt": "#{now}",
                            "isLoading": false,
                            "error": ""
                          }
                        }
                      }
                    ],
                    "failure": [
                      {
                        "state": {
                          "id": "ny_weather_error",
                          "input": {
                            "isLoading": false,
                            "error": "{{ 'Weather unavailable' + (notEmpty(@{ny_weather_fetch.message}) ? ': ' + @{ny_weather_fetch.message} : '. Check your network and try again.') }}"
                          }
                        }
                      }
                    ]
                  }
                }
              }
            ]
          }
        }
      }
    ]
  }
}