Line data Source code
1 : // Copyright 2026 The terCAD team. All rights reserved.
2 : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
3 :
4 : import 'package:app_finance/_classes/herald/app_design.dart';
5 : import 'package:app_finance/_classes/herald/app_locale.dart';
6 : import 'package:app_finance/_classes/storage/app_data.dart';
7 : import 'package:app_finance/_configs/theme_helper.dart';
8 : import 'package:app_finance/_ext/build_context_ext.dart';
9 : import 'package:app_finance/design/wrapper/input_wrapper.dart';
10 : import 'package:material_ui/material_ui.dart';
11 :
12 : class IntegrationTarget {
13 : String? appAccount;
14 : String? category;
15 : DateTime from;
16 :
17 2 : IntegrationTarget({this.appAccount, this.category, required this.from});
18 : }
19 :
20 : class IntegrationAccountCard extends StatelessWidget {
21 : final String title;
22 : final String? subtitle;
23 : final IntegrationTarget target;
24 : final AppData state;
25 : final bool isDisabled;
26 : final VoidCallback onChanged;
27 : final VoidCallback onImport;
28 :
29 2 : const IntegrationAccountCard({
30 : super.key,
31 : required this.title,
32 : required this.target,
33 : required this.state,
34 : required this.onChanged,
35 : required this.onImport,
36 : this.subtitle,
37 : this.isDisabled = false,
38 : });
39 :
40 2 : @override
41 : Widget build(BuildContext context) {
42 2 : final textTheme = context.textTheme;
43 2 : return Card(
44 4 : margin: EdgeInsets.symmetric(vertical: ThemeHelper.getIndent()),
45 2 : child: Padding(
46 4 : padding: EdgeInsets.all(ThemeHelper.getIndent(2)),
47 2 : child: LayoutBuilder(
48 4 : builder: (context, constraints) => Column(
49 2 : crossAxisAlignment: AppDesign.getAlignment(),
50 2 : children: [
51 6 : Text(title, style: textTheme.titleMedium),
52 4 : if (subtitle != null) Text(subtitle!),
53 2 : ThemeHelper.hIndent,
54 2 : InputWrapper(
55 : type: NamedInputType.accountSelector,
56 4 : title: AppLocale.labels.account,
57 : isRequired: true,
58 8 : value: target.appAccount != null ? state.getByUuid(target.appAccount!) : null,
59 0 : onChange: (value) {
60 0 : target.appAccount = value?.uuid;
61 0 : onChanged();
62 : },
63 2 : state: state,
64 2 : width: constraints.maxWidth,
65 : ),
66 2 : InputWrapper(
67 : type: NamedInputType.budgetSelector,
68 4 : title: AppLocale.labels.budget,
69 : isRequired: true,
70 8 : value: target.category != null ? state.getByUuid(target.category!) : null,
71 0 : onChange: (value) {
72 0 : target.category = value?.uuid;
73 0 : onChanged();
74 : },
75 2 : state: state,
76 2 : width: constraints.maxWidth,
77 : ),
78 2 : InputWrapper(
79 : type: NamedInputType.dateSelector,
80 4 : title: AppLocale.labels.integrationDateFrom,
81 4 : value: target.from,
82 0 : onChange: (value) {
83 0 : target.from = value ?? target.from;
84 0 : onChanged();
85 : },
86 : ),
87 2 : ThemeHelper.hIndent,
88 2 : SizedBox(
89 : width: double.infinity,
90 2 : child: FilledButton.icon(
91 : icon: const Icon(Icons.download),
92 4 : onPressed: isDisabled ? null : onImport,
93 6 : label: Text(AppLocale.labels.integrationImport),
94 : ),
95 : ),
96 : ],
97 : ),
98 : ),
99 : ),
100 : );
101 : }
102 : }
|