import 'package:flutter/material.dart';
import 'package:hub/components/templates_components/details_component/details_component_widget.dart';
import 'package:hub/features/storage/index.dart';
import 'package:hub/flutter_flow/flutter_flow_model.dart';
import 'package:hub/flutter_flow/flutter_flow_theme.dart';
import 'package:hub/flutter_flow/internationalization.dart';
import 'package:hub/pages/vehicles_on_the_property/vehicles_on_the_property.dart';

class VisitsModel extends FlutterFlowModel<VehicleOnTheProperty> {
  static VisitsModel? _instance;

  VisitsModel._internal({this.onRefresh});

  factory VisitsModel({VoidCallback? onRefresh}) =>
      _instance ??= VisitsModel._internal(onRefresh: onRefresh);

  static void resetInstance() => _instance = null;
  late final VoidCallback? onRefresh;

  late final String devUUID;
  late final String cliUUID;

  dynamic item;

  @override
  void initState(BuildContext context) {
    resetInstance();

    initAsync();
  }

  @override
  void dispose() {}

  Future<void> initAsync() async {
    devUUID = (await StorageHelper().get(ProfileStorageKey.devUUID.key)) ?? '';
    cliUUID =
        (await StorageHelper().get(ProfileStorageKey.clientUUID.key)) ?? '';
    onRefresh?.call();
  }

  Widget buildVisitDetails({
    required dynamic item,
    required BuildContext context,
    required VisitsModel model,
  }) {
    return DetailsComponentWidget(
      buttons: [],
      labelsHashMap: Map<String, String>.from({
        if (item['VTA_NOME'] != null && item['VTA_NOME'] != '')
          '${FFLocalizations.of(context).getVariableText(
            ptText: "Nome",
            enText: "Name",
          )}:': item['VTA_NOME'].toString().toUpperCase(),
        if (item['MOT_DESCRICAO'] != null && item['MOT_DESCRICAO'] != '')
          '${FFLocalizations.of(context).getVariableText(
            ptText: "Motivo",
            enText: "Reason",
          )}:': item['MOT_DESCRICAO'].toString().toUpperCase(),
        if (item['VTA_DTINICIO'] != null && item['VTA_DTINICIO'] != '')
          '${FFLocalizations.of(context).getVariableText(
            ptText: "Data de Início",
            enText: "Start Date",
          )}:': item['VTA_DTINICIO'].toString().toUpperCase(),
        if (item['VTA_VALIDADE'] != null && item['VTA_VALIDADE'] != '')
          '${FFLocalizations.of(context).getVariableText(
            ptText: "Validade",
            enText: "Validity",
          )}:': item['VTA_VALIDADE'].toString().toUpperCase(),
        if (item['VTA_FIXA'] != null && item['VTA_FIXA'] != '')
          '${FFLocalizations.of(context).getVariableText(
            ptText: "Entrada Única",
            enText: "Single Entry",
          )}:': item['VTA_FIXA'] == false
              ? FFLocalizations.of(context).getVariableText(
                  ptText: "Sim",
                  enText: "Yes",
                )
              : FFLocalizations.of(context).getVariableText(
                  ptText: "Não",
                  enText: "No",
                ),
      }),
      imagePath:
          'https://freaccess.com.br/freaccess/getImage.php?devUUID=${devUUID}&cliID=${cliUUID}&atividade=getFoto&Documento=${item['VDO_DOCUMENTO']}&tipo=E',
      statusHashMap: [
        Map<String, Color>.from({
          if (item['VTA_FIXA'] != null)
            FFLocalizations.of(context).getVariableText(
              ptText: item['VTA_FIXA'] ? "Entrada Recorrente" : "Entrada Única",
              enText: item['VTA_FIXA'] ? "Recurrent Entry" : "Single Entry",
            ): item['VTA_FIXA'] == false
                ? FlutterFlowTheme.of(context).success
                : FlutterFlowTheme.of(context).warning,
        })
      ],
    );
  }
}
