{
  "id": "mod_vat_invoice_calculator",
  "type": "module",
  "version": "1.1",
  "context": {
    "title": "VAT Invoice Calculator",
    "icon": "🧾",
    "layout": "phone"
  },
  "state": {
    "items": [],
    "description": "",
    "quantity": "1",
    "unitPrice": "",
    "vatRate": "21",
    "editingIndex": -1,
    "deleteIndex": -1,
    "showDeleteAlert": false,
    "formError": "",
    "storageError": "",
    "showSavedToast": false,
    "focused": ""
  },
  "dependencies": [
    {
      "repository": {
        "local": {
          "id": "vat_invoice_calculator_store",
          "config": {}
        }
      }
    },
    {
      "service": {
        "audio": {
          "id": "vat_invoice_audio"
        }
      }
    }
  ],
  "children": [
    {
      "id": "invoice_root_scroll",
      "type": "scroll",
      "style": {
        "layout": {
          "maxWidth": "infinity",
          "maxHeight": "infinity"
        },
        "common": {
          "background": {
            "gradient": {
              "linear": {
                "colors": [
                  "#101817",
                  "#172421",
                  "#20302B"
                ],
                "startPoint": "top",
                "endPoint": "bottom"
              }
            }
          }
        },
        "scroll": {
          "dismissesKeyboard": "interactively"
        }
      },
      "children": [
        {
          "id": "invoice_content",
          "type": "vstack",
          "context": {
            "_spacing": 20,
            "_alignment": "leading",
            "netTotal": "{{ sum(map(${items}, @{item}.quantity * @{item}.unitPrice)) }}",
            "vatTotal": "{{ sum(map(${items}, @{item}.quantity * @{item}.unitPrice * @{item}.vatRate / 100)) }}",
            "grossTotal": "{{ @{netTotal} + @{vatTotal} }}"
          },
          "style": {
            "layout": {
              "maxWidth": "infinity",
              "padding": {
                "top": 16,
                "bottom": 32,
                "leading": 16,
                "trailing": 16
              }
            }
          },
          "children": [
            {
              "id": "invoice_intro_card",
              "type": "hstack",
              "context": {
                "_spacing": 12,
                "_alignment": "center"
              },
              "style": {
                "layout": {
                  "maxWidth": "infinity",
                  "padding": 18
                },
                "common": {
                  "background": {
                    "gradient": {
                      "linear": {
                        "colors": [
                          "#315C50",
                          "#24463E"
                        ],
                        "startPoint": "topLeading",
                        "endPoint": "bottomTrailing"
                      }
                    }
                  },
                  "foreground": "white",
                  "cornerRadius": 20
                },
                "shadow": {
                  "color": {
                    "color": "black",
                    "opacity": 0.22
                  },
                  "radius": 12,
                  "y": 6
                }
              },
              "children": [
                {
                  "id": "invoice_intro_icon",
                  "type": "image",
                  "context": {
                    "_source": "sf://doc.text.fill"
                  },
                  "style": {
                    "layout": {
                      "width": 32,
                      "height": 32
                    },
                    "common": {
                      "foreground": "white"
                    }
                  }
                },
                {
                  "id": "invoice_intro_texts",
                  "type": "vstack",
                  "context": {
                    "_spacing": 3,
                    "_alignment": "leading"
                  },
                  "style": {
                    "layout": {
                      "maxWidth": "infinity"
                    }
                  },
                  "children": [
                    {
                      "id": "invoice_intro_heading",
                      "type": "text",
                      "context": {
                        "_text": "Build your invoice"
                      },
                      "style": {
                        "common": {
                          "font": "headline",
                          "foreground": "white"
                        }
                      }
                    },
                    {
                      "id": "invoice_intro_caption",
                      "type": "text",
                      "context": {
                        "_text": "Amounts use your device currency. The initial VAT rate is 21%, and you can change it for every item."
                      },
                      "style": {
                        "common": {
                          "font": "caption",
                          "foreground": {
                            "color": "white",
                            "opacity": 0.78
                          }
                        }
                      }
                    }
                  ]
                }
              ]
            },
            {
              "id": "invoice_item_form",
              "type": "vstack",
              "context": {
                "_spacing": 12,
                "_alignment": "leading"
              },
              "style": {
                "layout": {
                  "maxWidth": "infinity",
                  "padding": 18
                },
                "common": {
                  "background": {
                    "material": "regular"
                  },
                  "foreground": {
                    "color": "primary"
                  },
                  "cornerRadius": 20
                },
                "shadow": {
                  "color": {
                    "color": "black",
                    "opacity": 0.18
                  },
                  "radius": 12,
                  "y": 6
                }
              },
              "children": [
                {
                  "id": "invoice_form_header",
                  "type": "hstack",
                  "context": {
                    "_spacing": 9,
                    "_alignment": "center"
                  },
                  "children": [
                    {
                      "id": "invoice_form_header_icon",
                      "type": "image",
                      "context": {
                        "_source": "{{ ${editingIndex} >= 0 ? 'sf://pencil.circle.fill' : 'sf://plus.circle.fill' }}"
                      },
                      "style": {
                        "layout": {
                          "width": 22,
                          "height": 22
                        },
                        "common": {
                          "foreground": "mint"
                        }
                      }
                    },
                    {
                      "id": "invoice_form_header_text",
                      "type": "text",
                      "context": {
                        "_text": "{{ ${editingIndex} >= 0 ? 'Edit line item' : 'Add line item' }}"
                      },
                      "style": {
                        "common": {
                          "font": "headline",
                          "foreground": {
                            "color": "primary"
                          }
                        }
                      }
                    }
                  ]
                },
                {
                  "id": "invoice_description_field",
                  "type": "textfield",
                  "context": {
                    "_label": "Description",
                    "_text": "${description}",
                    "_focused": "${focused}",
                    "_debounce": 0
                  },
                  "style": {
                    "textField": {
                      "standard": "roundedBorder",
                      "submitLabel": "next"
                    },
                    "common": {
                      "foreground": {
                        "color": "primary"
                      },
                      "background": "{{ notEmpty(${formError}) && empty(trim(${description})) ? { 'color': 'red', 'opacity': 0.1 } : { 'color': 'clear' } }}"
                    },
                    "layout": {
                      "maxWidth": "infinity"
                    }
                  },
                  "events": {
                    "onChange": {
                      "observed": "description",
                      "actions": [
                        {
                          "state": {
                            "id": "act_clear_description_error",
                            "input": {
                              "formError": ""
                            }
                          }
                        }
                      ]
                    }
                  }
                },
                {
                  "id": "invoice_numeric_fields",
                  "type": "hstack",
                  "context": {
                    "_spacing": 10,
                    "_alignment": "top"
                  },
                  "style": {
                    "layout": {
                      "maxWidth": "infinity"
                    }
                  },
                  "children": [
                    {
                      "id": "invoice_quantity_field",
                      "type": "textfield",
                      "context": {
                        "_label": "Quantity",
                        "_text": "${quantity}",
                        "_keyboard": "decimalPad",
                        "_focused": "${focused}",
                        "_debounce": 0
                      },
                      "style": {
                        "textField": {
                          "standard": "roundedBorder"
                        },
                        "common": {
                          "foreground": {
                            "color": "primary"
                          },
                          "background": "{{ notEmpty(${formError}) && (empty(${quantity}) || cast(${quantity}, 'double') <= 0) ? { 'color': 'red', 'opacity': 0.1 } : { 'color': 'clear' } }}"
                        },
                        "layout": {
                          "maxWidth": "infinity"
                        }
                      },
                      "events": {
                        "onChange": {
                          "observed": "quantity",
                          "actions": [
                            {
                              "state": {
                                "id": "act_clear_quantity_error",
                                "input": {
                                  "formError": ""
                                }
                              }
                            }
                          ]
                        }
                      }
                    },
                    {
                      "id": "invoice_unit_price_field",
                      "type": "textfield",
                      "context": {
                        "_label": "Unit price",
                        "_text": "${unitPrice}",
                        "_keyboard": "decimalPad",
                        "_focused": "${focused}",
                        "_debounce": 0
                      },
                      "style": {
                        "textField": {
                          "standard": "roundedBorder"
                        },
                        "common": {
                          "foreground": {
                            "color": "primary"
                          },
                          "background": "{{ notEmpty(${formError}) && (empty(${unitPrice}) || cast(${unitPrice}, 'double') < 0) ? { 'color': 'red', 'opacity': 0.1 } : { 'color': 'clear' } }}"
                        },
                        "layout": {
                          "maxWidth": "infinity"
                        }
                      },
                      "events": {
                        "onChange": {
                          "observed": "unitPrice",
                          "actions": [
                            {
                              "state": {
                                "id": "act_clear_price_error",
                                "input": {
                                  "formError": ""
                                }
                              }
                            }
                          ]
                        }
                      }
                    },
                    {
                      "id": "invoice_vat_rate_field",
                      "type": "textfield",
                      "context": {
                        "_label": "VAT %",
                        "_text": "${vatRate}",
                        "_keyboard": "decimalPad",
                        "_focused": "${focused}",
                        "_debounce": 0
                      },
                      "style": {
                        "textField": {
                          "standard": "roundedBorder"
                        },
                        "common": {
                          "foreground": {
                            "color": "primary"
                          },
                          "background": "{{ notEmpty(${formError}) && (empty(${vatRate}) || cast(${vatRate}, 'double') < 0 || cast(${vatRate}, 'double') > 100) ? { 'color': 'red', 'opacity': 0.1 } : { 'color': 'clear' } }}"
                        },
                        "layout": {
                          "maxWidth": "infinity"
                        }
                      },
                      "events": {
                        "onChange": {
                          "observed": "vatRate",
                          "actions": [
                            {
                              "state": {
                                "id": "act_clear_vat_error",
                                "input": {
                                  "formError": ""
                                }
                              }
                            }
                          ]
                        }
                      }
                    }
                  ]
                },
                {
                  "id": "invoice_form_error_conditional",
                  "type": "conditional",
                  "context": {
                    "_condition": "{{ notEmpty(${formError}) }}",
                    "_trueComponent": {
                      "id": "invoice_form_error_text",
                      "type": "label",
                      "context": {
                        "_title": "${formError}",
                        "_image": "sf://exclamationmark.triangle.fill"
                      },
                      "style": {
                        "common": {
                          "font": "caption",
                          "foreground": "red"
                        }
                      }
                    },
                    "_falseComponent": {
                      "id": "invoice_form_helper_text",
                      "type": "text",
                      "context": {
                        "_text": "Quantity must be above zero. VAT can be any rate from 0% to 100%."
                      },
                      "style": {
                        "common": {
                          "font": "caption",
                          "foreground": {
                            "color": "secondary"
                          }
                        }
                      }
                    }
                  }
                },
                {
                  "id": "invoice_form_actions",
                  "type": "hstack",
                  "context": {
                    "_spacing": 10,
                    "_alignment": "center"
                  },
                  "style": {
                    "layout": {
                      "maxWidth": "infinity"
                    }
                  },
                  "children": [
                    {
                      "id": "invoice_save_item_button",
                      "type": "button",
                      "context": {
                        "_label": "{{ ${editingIndex} >= 0 ? 'Update item' : 'Add item' }}",
                        "_image": "{{ ${editingIndex} >= 0 ? 'sf://checkmark.circle.fill' : 'sf://plus.circle.fill' }}"
                      },
                      "style": {
                        "button": {
                          "standard": {
                            "type": "borderedProminent",
                            "shape": "capsule"
                          }
                        },
                        "layout": {
                          "maxWidth": "infinity",
                          "minHeight": 48
                        }
                      },
                      "events": {
                        "onTap": [
                          {
                            "state": {
                              "id": "act_validate_item",
                              "input": {
                                "formError": "{{ switch(empty(trim(${description})), 'Enter a description.', empty(${quantity}) || cast(${quantity}, 'double') <= 0, 'Enter a quantity above zero.', empty(${unitPrice}) || cast(${unitPrice}, 'double') < 0, 'Enter a valid unit price.', empty(${vatRate}) || cast(${vatRate}, 'double') < 0 || cast(${vatRate}, 'double') > 100, 'Enter a VAT rate from 0 to 100.', '') }}",
                                "focused": ""
                              }
                            }
                          },
                          {
                            "condition": {
                              "id": "act_item_valid_guard",
                              "input": "{{ notEmpty(trim(${description})) && notEmpty(${quantity}) && cast(${quantity}, 'double') > 0 && notEmpty(${unitPrice}) && cast(${unitPrice}, 'double') >= 0 && notEmpty(${vatRate}) && cast(${vatRate}, 'double') >= 0 && cast(${vatRate}, 'double') <= 100 }}",
                              "output": {
                                "success": [
                                  {
                                    "state": {
                                      "id": "act_commit_item",
                                      "input": {
                                        "items": "{{ ${editingIndex} >= 0 ? setAt(${items}, ${editingIndex}, { 'description': trim(${description}), 'quantity': cast(${quantity}, 'double'), 'unitPrice': cast(${unitPrice}, 'double'), 'vatRate': cast(${vatRate}, 'double') }) : ${items} + { 'description': trim(${description}), 'quantity': cast(${quantity}, 'double'), 'unitPrice': cast(${unitPrice}, 'double'), 'vatRate': cast(${vatRate}, 'double') } }}",
                                        "description": "",
                                        "quantity": "1",
                                        "unitPrice": "",
                                        "vatRate": "21",
                                        "editingIndex": -1,
                                        "formError": "",
                                        "storageError": "",
                                        "showSavedToast": true,
                                        "focused": ""
                                      },
                                      "output": {
                                        "success": [
                                          {
                                            "repo": {
                                              "id": "repo_persist_item_change",
                                              "input": {
                                                "repositoryId": "vat_invoice_calculator_store",
                                                "operation": "create",
                                                "params": {
                                                  "collection": "invoice",
                                                  "documentId": "current",
                                                  "rewrite": true,
                                                  "body": {
                                                    "items": "${items}"
                                                  }
                                                }
                                              },
                                              "output": {
                                                "success": [
                                                  {
                                                    "service": {
                                                      "id": "service_item_saved_haptic",
                                                      "input": {
                                                        "serviceId": "vat_invoice_audio",
                                                        "params": {
                                                          "sound": "none",
                                                          "haptic": "success"
                                                        }
                                                      }
                                                    }
                                                  },
                                                  {
                                                    "interval": {
                                                      "id": "timer_hide_saved_toast",
                                                      "input": {
                                                        "delay": 2
                                                      },
                                                      "output": {
                                                        "success": [
                                                          {
                                                            "interval": {
                                                              "id": "timer_hide_saved_toast",
                                                              "input": {
                                                                "cancel": true
                                                              }
                                                            }
                                                          },
                                                          {
                                                            "state": {
                                                              "id": "act_hide_saved_toast",
                                                              "input": {
                                                                "showSavedToast": false
                                                              }
                                                            }
                                                          }
                                                        ]
                                                      }
                                                    }
                                                  }
                                                ],
                                                "failure": [
                                                  {
                                                    "state": {
                                                      "id": "act_item_persist_failed",
                                                      "input": {
                                                        "storageError": "{{ 'Could not save this invoice' + (notEmpty(@{repo_persist_item_change.message}) ? ': ' + @{repo_persist_item_change.message} : '. Check device storage and try again.') }}",
                                                        "showSavedToast": false
                                                      }
                                                    }
                                                  }
                                                ]
                                              }
                                            }
                                          }
                                        ]
                                      }
                                    }
                                  }
                                ],
                                "failure": [
                                  {
                                    "service": {
                                      "id": "service_item_validation_haptic",
                                      "input": {
                                        "serviceId": "vat_invoice_audio",
                                        "params": {
                                          "sound": "none",
                                          "haptic": "warning"
                                        }
                                      }
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        ]
                      }
                    },
                    {
                      "id": "invoice_cancel_edit_conditional",
                      "type": "conditional",
                      "context": {
                        "_condition": "{{ ${editingIndex} >= 0 }}",
                        "_trueComponent": {
                          "id": "invoice_cancel_edit_button",
                          "type": "button",
                          "context": {
                            "_label": "Clear",
                            "_image": "sf://xmark.circle"
                          },
                          "style": {
                            "button": {
                              "standard": {
                                "type": "bordered",
                                "shape": "capsule"
                              }
                            },
                            "layout": {
                              "minHeight": 48
                            }
                          },
                          "events": {
                            "onTap": [
                              {
                                "state": {
                                  "id": "act_cancel_item_edit",
                                  "input": {
                                    "description": "",
                                    "quantity": "1",
                                    "unitPrice": "",
                                    "vatRate": "21",
                                    "editingIndex": -1,
                                    "formError": "",
                                    "focused": ""
                                  }
                                }
                              }
                            ]
                          }
                        },
                        "_falseComponent": {
                          "id": "invoice_cancel_edit_empty",
                          "type": "empty"
                        }
                      }
                    }
                  ]
                }
              ]
            },
            {
              "id": "invoice_saved_toast",
              "type": "label",
              "context": {
                "_title": "Invoice saved",
                "_image": "sf://checkmark.circle.fill"
              },
              "style": {
                "layout": {
                  "padding": {
                    "top": 9,
                    "bottom": 9,
                    "leading": 14,
                    "trailing": 14
                  }
                },
                "common": {
                  "background": {
                    "material": "ultraThin"
                  },
                  "foreground": {
                    "color": "primary"
                  },
                  "cornerRadius": 18,
                  "font": "subheadline",
                  "opacity": "{{ ${showSavedToast} ? 1 : 0 }}",
                  "scale": "{{ ${showSavedToast} ? 1 : 0.92 }}"
                },
                "animation": {
                  "kind": "spring",
                  "value": "${showSavedToast}",
                  "duration": 0.35,
                  "bounce": 0.25
                }
              }
            },
            {
              "id": "invoice_storage_error_conditional",
              "type": "conditional",
              "context": {
                "_condition": "{{ notEmpty(${storageError}) }}",
                "_trueComponent": {
                  "id": "invoice_storage_error_card",
                  "type": "label",
                  "context": {
                    "_title": "${storageError}",
                    "_image": "sf://exclamationmark.triangle.fill"
                  },
                  "style": {
                    "layout": {
                      "maxWidth": "infinity",
                      "padding": 14
                    },
                    "common": {
                      "background": {
                        "color": "red",
                        "opacity": 0.14
                      },
                      "foreground": {
                        "light": "#651515",
                        "dark": "#FFD7D7"
                      },
                      "cornerRadius": 14,
                      "font": "caption"
                    }
                  }
                },
                "_falseComponent": {
                  "id": "invoice_storage_error_empty",
                  "type": "empty"
                }
              }
            },
            {
              "id": "invoice_items_section",
              "type": "vstack",
              "context": {
                "_spacing": 10,
                "_alignment": "leading"
              },
              "style": {
                "layout": {
                  "maxWidth": "infinity"
                }
              },
              "children": [
                {
                  "id": "invoice_items_header",
                  "type": "hstack",
                  "context": {
                    "_spacing": 8,
                    "_alignment": "center"
                  },
                  "children": [
                    {
                      "id": "invoice_items_header_icon",
                      "type": "image",
                      "context": {
                        "_source": "sf://list.bullet.rectangle.fill"
                      },
                      "style": {
                        "layout": {
                          "width": 20,
                          "height": 20
                        },
                        "common": {
                          "foreground": "mint"
                        }
                      }
                    },
                    {
                      "id": "invoice_items_header_text",
                      "type": "text",
                      "context": {
                        "_text": "{{ count(${items}) == 1 ? '1 line item' : cast(count(${items}), 'str') + ' line items' }}"
                      },
                      "style": {
                        "common": {
                          "font": "headline",
                          "foreground": "white"
                        }
                      }
                    }
                  ]
                },
                {
                  "id": "invoice_items_empty_or_list",
                  "type": "conditional",
                  "context": {
                    "_condition": "{{ empty(${items}) }}",
                    "_trueComponent": {
                      "id": "invoice_items_empty_card",
                      "type": "vstack",
                      "context": {
                        "_spacing": 10,
                        "_alignment": "center"
                      },
                      "style": {
                        "layout": {
                          "maxWidth": "infinity",
                          "padding": {
                            "top": 26,
                            "bottom": 26,
                            "leading": 20,
                            "trailing": 20
                          }
                        },
                        "common": {
                          "background": {
                            "material": "regular"
                          },
                          "foreground": {
                            "color": "primary"
                          },
                          "cornerRadius": 20
                        }
                      },
                      "children": [
                        {
                          "id": "invoice_items_empty_icon",
                          "type": "image",
                          "context": {
                            "_source": "sf://doc.badge.plus"
                          },
                          "style": {
                            "layout": {
                              "width": 42,
                              "height": 42
                            },
                            "common": {
                              "foreground": "mint"
                            }
                          }
                        },
                        {
                          "id": "invoice_items_empty_text",
                          "type": "text",
                          "context": {
                            "_text": "Add the first line item above."
                          },
                          "style": {
                            "common": {
                              "font": "subheadline",
                              "foreground": {
                                "color": "primary"
                              }
                            }
                          }
                        }
                      ]
                    },
                    "_falseComponent": {
                      "id": "invoice_items_list",
                      "type": "vstack",
                      "context": {
                        "_spacing": 10,
                        "_alignment": "leading"
                      },
                      "style": {
                        "layout": {
                          "maxWidth": "infinity"
                        }
                      },
                      "children": [
                        {
                          "id": "invoice_items_dynamic",
                          "type": "dynamic",
                          "context": {
                            "_data": "${items}"
                          },
                          "prototype": {
                            "id": "invoice_item_row",
                            "type": "vstack",
                            "context": {
                              "_spacing": 10,
                              "_alignment": "leading",
                              "rowNet": "{{ @{item}.quantity * @{item}.unitPrice }}",
                              "rowVat": "{{ @{rowNet} * @{item}.vatRate / 100 }}",
                              "rowGross": "{{ @{rowNet} + @{rowVat} }}"
                            },
                            "style": {
                              "layout": {
                                "maxWidth": "infinity",
                                "padding": 16
                              },
                              "common": {
                                "background": {
                                  "material": "regular"
                                },
                                "foreground": {
                                  "color": "primary"
                                },
                                "cornerRadius": 18
                              },
                              "shadow": {
                                "color": {
                                  "color": "black",
                                  "opacity": 0.16
                                },
                                "radius": 9,
                                "y": 4
                              },
                              "animation": {
                                "kind": "spring",
                                "value": "{{ count(${items}) }}",
                                "duration": 0.35,
                                "bounce": 0.25
                              },
                              "swipe": {
                                "trailing": {
                                  "allowsFullSwipe": false,
                                  "content": {
                                    "id": "invoice_swipe_delete_button",
                                    "type": "button",
                                    "style": {
                                      "common": {
                                        "tint": "red"
                                      }
                                    },
                                    "children": [
                                      {
                                        "id": "invoice_swipe_delete_icon",
                                        "type": "image",
                                        "context": {
                                          "_source": "sf://trash"
                                        },
                                        "style": {
                                          "layout": {
                                            "width": 20,
                                            "height": 20,
                                            "padding": 12
                                          },
                                          "common": {
                                            "foreground": "white"
                                          }
                                        }
                                      }
                                    ],
                                    "events": {
                                      "onTap": [
                                        {
                                          "state": {
                                            "id": "act_prepare_item_delete",
                                            "input": {
                                              "deleteIndex": "@{index}",
                                              "showDeleteAlert": true
                                            }
                                          }
                                        }
                                      ]
                                    }
                                  }
                                }
                              },
                              "modal": {
                                "alert": {
                                  "isPresented": "${showDeleteAlert}",
                                  "title": "Delete line item?",
                                  "message": "This removes the selected item from the invoice.",
                                  "actions": [
                                    {
                                      "id": "invoice_confirm_delete_button",
                                      "type": "button",
                                      "context": {
                                        "_label": "Delete"
                                      },
                                      "style": {
                                        "common": {
                                          "foreground": "red"
                                        }
                                      },
                                      "events": {
                                        "onTap": [
                                          {
                                            "state": {
                                              "id": "act_confirm_item_delete",
                                              "input": {
                                                "items": "{{ removeAt(${items}, ${deleteIndex}) }}",
                                                "description": "{{ ${editingIndex} == ${deleteIndex} ? '' : ${description} }}",
                                                "quantity": "{{ ${editingIndex} == ${deleteIndex} ? '1' : ${quantity} }}",
                                                "unitPrice": "{{ ${editingIndex} == ${deleteIndex} ? '' : ${unitPrice} }}",
                                                "vatRate": "{{ ${editingIndex} == ${deleteIndex} ? '21' : ${vatRate} }}",
                                                "editingIndex": "{{ ${editingIndex} == ${deleteIndex} ? -1 : ${editingIndex} > ${deleteIndex} ? ${editingIndex} - 1 : ${editingIndex} }}",
                                                "deleteIndex": -1,
                                                "showDeleteAlert": false,
                                                "storageError": "",
                                                "focused": ""
                                              },
                                              "output": {
                                                "success": [
                                                  {
                                                    "repo": {
                                                      "id": "repo_persist_item_delete",
                                                      "input": {
                                                        "repositoryId": "vat_invoice_calculator_store",
                                                        "operation": "create",
                                                        "params": {
                                                          "collection": "invoice",
                                                          "documentId": "current",
                                                          "rewrite": true,
                                                          "body": {
                                                            "items": "${items}"
                                                          }
                                                        }
                                                      },
                                                      "output": {
                                                        "success": [
                                                          {
                                                            "service": {
                                                              "id": "service_item_deleted_haptic",
                                                              "input": {
                                                                "serviceId": "vat_invoice_audio",
                                                                "params": {
                                                                  "sound": "none",
                                                                  "haptic": "error"
                                                                }
                                                              }
                                                            }
                                                          }
                                                        ],
                                                        "failure": [
                                                          {
                                                            "state": {
                                                              "id": "act_delete_persist_failed",
                                                              "input": {
                                                                "storageError": "{{ 'The item was removed, but the invoice could not be saved' + (notEmpty(@{repo_persist_item_delete.message}) ? ': ' + @{repo_persist_item_delete.message} : '. Check device storage and try again.') }}"
                                                              }
                                                            }
                                                          }
                                                        ]
                                                      }
                                                    }
                                                  }
                                                ]
                                              }
                                            }
                                          }
                                        ]
                                      }
                                    },
                                    {
                                      "id": "invoice_keep_item_button",
                                      "type": "button",
                                      "context": {
                                        "_label": "Keep item"
                                      },
                                      "events": {
                                        "onTap": [
                                          {
                                            "state": {
                                              "id": "act_cancel_item_delete",
                                              "input": {
                                                "deleteIndex": -1,
                                                "showDeleteAlert": false
                                              }
                                            }
                                          }
                                        ]
                                      }
                                    }
                                  ]
                                }
                              }
                            },
                            "children": [
                              {
                                "id": "invoice_item_row_top",
                                "type": "hstack",
                                "context": {
                                  "_spacing": 10,
                                  "_alignment": "center"
                                },
                                "children": [
                                  {
                                    "id": "invoice_item_description_stack",
                                    "type": "vstack",
                                    "context": {
                                      "_spacing": 3,
                                      "_alignment": "leading"
                                    },
                                    "style": {
                                      "layout": {
                                        "maxWidth": "infinity"
                                      }
                                    },
                                    "children": [
                                      {
                                        "id": "invoice_item_description",
                                        "type": "text",
                                        "context": {
                                          "_text": "@{item.description}"
                                        },
                                        "style": {
                                          "common": {
                                            "font": {
                                              "kind": "body",
                                              "weight": "semibold"
                                            },
                                            "foreground": {
                                              "color": "primary"
                                            }
                                          },
                                          "text": {
                                            "lineLimit": 2
                                          }
                                        }
                                      },
                                      {
                                        "id": "invoice_item_formula",
                                        "type": "text",
                                        "context": {
                                          "_text": "{{ cast(@{item.quantity}, 'str') + ' × ' + cast(@{item.unitPrice}, 'str') + ' · VAT ' + cast(@{item.vatRate}, 'str') + '%' }}"
                                        },
                                        "style": {
                                          "common": {
                                            "font": "caption",
                                            "foreground": {
                                              "color": "secondary"
                                            }
                                          }
                                        }
                                      }
                                    ]
                                  },
                                  {
                                    "id": "invoice_item_edit_button",
                                    "type": "button",
                                    "style": {
                                      "button": {
                                        "standard": {
                                          "type": "bordered",
                                          "shape": "circle"
                                        }
                                      },
                                      "layout": {
                                        "width": 44,
                                        "height": 44
                                      }
                                    },
                                    "children": [
                                      {
                                        "id": "invoice_item_edit_icon",
                                        "type": "image",
                                        "context": {
                                          "_source": "sf://pencil"
                                        },
                                        "style": {
                                          "layout": {
                                            "width": 17,
                                            "height": 17
                                          },
                                          "common": {
                                            "foreground": "mint"
                                          }
                                        }
                                      }
                                    ],
                                    "events": {
                                      "onTap": [
                                        {
                                          "state": {
                                            "id": "act_begin_item_edit",
                                            "input": {
                                              "description": "@{item.description}",
                                              "quantity": "{{ cast(@{item.quantity}, 'str') }}",
                                              "unitPrice": "{{ cast(@{item.unitPrice}, 'str') }}",
                                              "vatRate": "{{ cast(@{item.vatRate}, 'str') }}",
                                              "editingIndex": "@{index}",
                                              "formError": "",
                                              "focused": ""
                                            }
                                          }
                                        }
                                      ]
                                    }
                                  },
                                  {
                                    "id": "invoice_item_delete_button",
                                    "type": "button",
                                    "style": {
                                      "button": {
                                        "standard": {
                                          "type": "bordered",
                                          "shape": "circle"
                                        }
                                      },
                                      "layout": {
                                        "width": 44,
                                        "height": 44
                                      }
                                    },
                                    "children": [
                                      {
                                        "id": "invoice_item_delete_icon",
                                        "type": "image",
                                        "context": {
                                          "_source": "sf://trash"
                                        },
                                        "style": {
                                          "layout": {
                                            "width": 17,
                                            "height": 17
                                          },
                                          "common": {
                                            "foreground": "red"
                                          }
                                        }
                                      }
                                    ],
                                    "events": {
                                      "onTap": [
                                        {
                                          "state": {
                                            "id": "act_prepare_item_delete_button",
                                            "input": {
                                              "deleteIndex": "@{index}",
                                              "showDeleteAlert": true
                                            }
                                          }
                                        }
                                      ]
                                    }
                                  }
                                ]
                              },
                              {
                                "id": "invoice_item_amounts",
                                "type": "hstack",
                                "context": {
                                  "_spacing": 8,
                                  "_alignment": "center"
                                },
                                "style": {
                                  "layout": {
                                    "maxWidth": "infinity"
                                  }
                                },
                                "children": [
                                  {
                                    "id": "invoice_item_net_column",
                                    "type": "vstack",
                                    "context": {
                                      "_spacing": 2,
                                      "_alignment": "leading"
                                    },
                                    "style": {
                                      "layout": {
                                        "maxWidth": "infinity"
                                      }
                                    },
                                    "children": [
                                      {
                                        "id": "invoice_item_net_label",
                                        "type": "text",
                                        "context": {
                                          "_text": "Net"
                                        },
                                        "style": {
                                          "common": {
                                            "font": "caption",
                                            "foreground": {
                                              "color": "secondary"
                                            }
                                          }
                                        }
                                      },
                                      {
                                        "id": "invoice_item_net_value",
                                        "type": "text",
                                        "context": {
                                          "_text": "@{rowNet}",
                                          "_format": {
                                            "number": {
                                              "style": "currency",
                                              "currencyCode": "#{currency}",
                                              "minimumFractionDigits": 2,
                                              "maximumFractionDigits": 2
                                            }
                                          }
                                        },
                                        "style": {
                                          "common": {
                                            "font": "subheadline",
                                            "foreground": {
                                              "color": "primary"
                                            }
                                          }
                                        }
                                      }
                                    ]
                                  },
                                  {
                                    "id": "invoice_item_vat_column",
                                    "type": "vstack",
                                    "context": {
                                      "_spacing": 2,
                                      "_alignment": "leading"
                                    },
                                    "style": {
                                      "layout": {
                                        "maxWidth": "infinity"
                                      }
                                    },
                                    "children": [
                                      {
                                        "id": "invoice_item_vat_label",
                                        "type": "text",
                                        "context": {
                                          "_text": "VAT"
                                        },
                                        "style": {
                                          "common": {
                                            "font": "caption",
                                            "foreground": {
                                              "color": "secondary"
                                            }
                                          }
                                        }
                                      },
                                      {
                                        "id": "invoice_item_vat_value",
                                        "type": "text",
                                        "context": {
                                          "_text": "@{rowVat}",
                                          "_format": {
                                            "number": {
                                              "style": "currency",
                                              "currencyCode": "#{currency}",
                                              "minimumFractionDigits": 2,
                                              "maximumFractionDigits": 2
                                            }
                                          }
                                        },
                                        "style": {
                                          "common": {
                                            "font": "subheadline",
                                            "foreground": {
                                              "color": "primary"
                                            }
                                          }
                                        }
                                      }
                                    ]
                                  },
                                  {
                                    "id": "invoice_item_gross_column",
                                    "type": "vstack",
                                    "context": {
                                      "_spacing": 2,
                                      "_alignment": "trailing"
                                    },
                                    "style": {
                                      "layout": {
                                        "maxWidth": "infinity"
                                      }
                                    },
                                    "children": [
                                      {
                                        "id": "invoice_item_gross_label",
                                        "type": "text",
                                        "context": {
                                          "_text": "Gross"
                                        },
                                        "style": {
                                          "common": {
                                            "font": "caption",
                                            "foreground": {
                                              "color": "secondary"
                                            }
                                          }
                                        }
                                      },
                                      {
                                        "id": "invoice_item_gross_value",
                                        "type": "text",
                                        "context": {
                                          "_text": "@{rowGross}",
                                          "_format": {
                                            "number": {
                                              "style": "currency",
                                              "currencyCode": "#{currency}",
                                              "minimumFractionDigits": 2,
                                              "maximumFractionDigits": 2
                                            }
                                          }
                                        },
                                        "style": {
                                          "common": {
                                            "font": {
                                              "kind": "subheadline",
                                              "weight": "semibold"
                                            },
                                            "foreground": "mint"
                                          }
                                        }
                                      }
                                    ]
                                  }
                                ]
                              }
                            ]
                          }
                        }
                      ]
                    }
                  }
                }
              ]
            },
            {
              "id": "invoice_totals_card",
              "type": "vstack",
              "context": {
                "_spacing": 12,
                "_alignment": "leading"
              },
              "style": {
                "layout": {
                  "maxWidth": "infinity",
                  "padding": 20
                },
                "common": {
                  "background": {
                    "gradient": {
                      "linear": {
                        "colors": [
                          "#2E5B4F",
                          "#1D3D35"
                        ],
                        "startPoint": "topLeading",
                        "endPoint": "bottomTrailing"
                      }
                    }
                  },
                  "foreground": "white",
                  "cornerRadius": 22
                },
                "shadow": {
                  "color": {
                    "color": "black",
                    "opacity": 0.24
                  },
                  "radius": 14,
                  "y": 8
                },
                "animation": {
                  "kind": "spring",
                  "value": "{{ count(${items}) }}",
                  "duration": 0.4,
                  "bounce": 0.2
                }
              },
              "children": [
                {
                  "id": "invoice_totals_header",
                  "type": "hstack",
                  "context": {
                    "_spacing": 8,
                    "_alignment": "center"
                  },
                  "children": [
                    {
                      "id": "invoice_totals_icon",
                      "type": "image",
                      "context": {
                        "_source": "sf://sum"
                      },
                      "style": {
                        "layout": {
                          "width": 20,
                          "height": 20
                        },
                        "common": {
                          "foreground": "white"
                        }
                      }
                    },
                    {
                      "id": "invoice_totals_heading",
                      "type": "text",
                      "context": {
                        "_text": "Invoice totals"
                      },
                      "style": {
                        "common": {
                          "font": "headline",
                          "foreground": "white"
                        }
                      }
                    }
                  ]
                },
                {
                  "id": "invoice_net_total_row",
                  "type": "hstack",
                  "context": {
                    "_spacing": 8,
                    "_alignment": "center"
                  },
                  "children": [
                    {
                      "id": "invoice_net_total_label",
                      "type": "text",
                      "context": {
                        "_text": "Net amount"
                      },
                      "style": {
                        "common": {
                          "font": "body",
                          "foreground": {
                            "color": "white",
                            "opacity": 0.78
                          }
                        }
                      }
                    },
                    {
                      "id": "invoice_net_total_spacer",
                      "type": "spacer"
                    },
                    {
                      "id": "invoice_net_total_value",
                      "type": "text",
                      "context": {
                        "_text": "@{netTotal}",
                        "_format": {
                          "number": {
                            "style": "currency",
                            "currencyCode": "#{currency}",
                            "minimumFractionDigits": 2,
                            "maximumFractionDigits": 2
                          }
                        }
                      },
                      "style": {
                        "common": {
                          "font": {
                            "kind": "body",
                            "weight": "semibold"
                          },
                          "foreground": "white"
                        }
                      }
                    }
                  ]
                },
                {
                  "id": "invoice_vat_total_row",
                  "type": "hstack",
                  "context": {
                    "_spacing": 8,
                    "_alignment": "center"
                  },
                  "children": [
                    {
                      "id": "invoice_vat_total_label",
                      "type": "text",
                      "context": {
                        "_text": "VAT amount"
                      },
                      "style": {
                        "common": {
                          "font": "body",
                          "foreground": {
                            "color": "white",
                            "opacity": 0.78
                          }
                        }
                      }
                    },
                    {
                      "id": "invoice_vat_total_spacer",
                      "type": "spacer"
                    },
                    {
                      "id": "invoice_vat_total_value",
                      "type": "text",
                      "context": {
                        "_text": "@{vatTotal}",
                        "_format": {
                          "number": {
                            "style": "currency",
                            "currencyCode": "#{currency}",
                            "minimumFractionDigits": 2,
                            "maximumFractionDigits": 2
                          }
                        }
                      },
                      "style": {
                        "common": {
                          "font": {
                            "kind": "body",
                            "weight": "semibold"
                          },
                          "foreground": "white"
                        }
                      }
                    }
                  ]
                },
                {
                  "id": "invoice_totals_divider",
                  "type": "divider"
                },
                {
                  "id": "invoice_gross_total_row",
                  "type": "hstack",
                  "context": {
                    "_spacing": 8,
                    "_alignment": "bottom"
                  },
                  "children": [
                    {
                      "id": "invoice_gross_total_label",
                      "type": "text",
                      "context": {
                        "_text": "Gross total"
                      },
                      "style": {
                        "common": {
                          "font": {
                            "kind": "title3",
                            "weight": "semibold"
                          },
                          "foreground": "white"
                        }
                      }
                    },
                    {
                      "id": "invoice_gross_total_spacer",
                      "type": "spacer"
                    },
                    {
                      "id": "invoice_gross_total_value",
                      "type": "text",
                      "context": {
                        "_text": "@{grossTotal}",
                        "_format": {
                          "number": {
                            "style": "currency",
                            "currencyCode": "#{currency}",
                            "minimumFractionDigits": 2,
                            "maximumFractionDigits": 2
                          }
                        }
                      },
                      "style": {
                        "common": {
                          "font": {
                            "kind": "largeTitle",
                            "weight": "bold"
                          },
                          "foreground": "white"
                        },
                        "text": {
                          "lineLimit": 1,
                          "minimumScaleFactor": 0.65
                        }
                      }
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "events": {
    "onAppear": [
      {
        "repo": {
          "id": "repo_load_invoice",
          "input": {
            "repositoryId": "vat_invoice_calculator_store",
            "operation": "read",
            "params": {
              "collection": "invoice",
              "documentId": "current"
            }
          },
          "output": {
            "success": [
              {
                "state": {
                  "id": "act_restore_invoice",
                  "input": {
                    "items": "@{repo_load_invoice.items}",
                    "storageError": "",
                    "showSavedToast": false,
                    "focused": ""
                  }
                }
              }
            ],
            "failure": []
          }
        }
      }
    ]
  }
}