import 'package:flutter/material.dart';
import 'package:hub/components/organism_components/schedule_visit_detail/schedule_visit_detail_widget.dart';
import 'package:hub/components/templates_components/view_visit_detail/view_visit_detail_widget.dart';
import 'package:hub/components/templates_components/visit_details_modal_template_component/visit_details_modal_template_component_model.dart';
import 'package:hub/flutter_flow/flutter_flow_model.dart';

class VisitDetailsModalTemplateComponentWidget extends StatefulWidget {
  const VisitDetailsModalTemplateComponentWidget({
    super.key,
    this.visitStatusStr,
    this.visitStartDateStr,
    this.visitEndDateStr,
    this.visitReasonStr,
    this.visitLevelStr,
    this.visitTempStr,
    this.visitObsStr,
    this.visitorStrList,
    this.visitorJsonList,
    this.visitorImgPath,
    this.visitorImgList,
    this.visitIdStr,
    this.updateToggleIdx,
    this.repeatVisitSchedule,
    this.visitStatusColor,
  });

  final String? visitStatusStr;
  final String? visitStartDateStr;
  final String? visitEndDateStr;
  final String? visitReasonStr;
  final String? visitLevelStr;
  final String? visitTempStr;
  final String? visitObsStr;
  final String? visitorStrList;
  final List<dynamic>? visitorJsonList;
  final String? visitorImgPath;
  final List<String>? visitorImgList;
  final String? visitIdStr;
  final Future Function()? updateToggleIdx;
  final Future Function()? repeatVisitSchedule;
  final Color? visitStatusColor;

  @override
  State<VisitDetailsModalTemplateComponentWidget> createState() =>
      _VisitDetailsModalTemplateComponentWidgetState();
}

class _VisitDetailsModalTemplateComponentWidgetState
    extends State<VisitDetailsModalTemplateComponentWidget> {
  late VisitDetailsModalTemplateComponentModel _model;

  @override
  void setState(VoidCallback callback) {
    super.setState(callback);
    _model.onUpdate();
  }

  @override
  void initState() {
    super.initState();
    _model =
        createModel(context, () => VisitDetailsModalTemplateComponentModel());
  }

  @override
  void dispose() {
    _model.maybeDispose();

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Builder(
      builder: (context) {
        if (widget.visitStatusStr != null && widget.visitStatusStr != '') {
          return wrapWithModel(
            model: _model.viewVisitDetailModel,
            updateCallback: () => setState(() {}),
            updateOnChange: true,
            child: ViewVisitDetailWidget(
              visitorImgPath: widget.visitorImgPath,
              visitStartDate: widget.visitStartDateStr!,
              visitEndDate: widget.visitEndDateStr!,
              visitReasonStr: widget.visitReasonStr!,
              visitLevelStr: widget.visitLevelStr!,
              visitTempStr: widget.visitTempStr!,
              visitObsStr: widget.visitObsStr!,
              visitStatusStr: widget.visitStatusStr!,
              visitorStrList: widget.visitorStrList!,
              visitorJsonList: widget.visitorJsonList,
              visitIdStr: widget.visitIdStr!,
              visitStatusColor: widget.visitStatusColor!,
            ),
          );
        } else {
          return wrapWithModel(
            model: _model.scheduleVisitDetailModel,
            updateCallback: () => setState(() {}),
            updateOnChange: true,
            child: ScheduleVisitDetailWidget(
              visitorStrList: widget.visitorStrList!,
              visitorImgPath: widget.visitorImgPath,
              visitStartDate: widget.visitStartDateStr!,
              visitEndDate: widget.visitEndDateStr!,
              visitResonStr: widget.visitReasonStr!,
              visitLevelStr: widget.visitLevelStr!,
              visitTempStr: widget.visitTempStr!,
              visitObsStr: widget.visitObsStr!,
              visitorJsonList: widget.visitorJsonList!,
            ),
          );
        }
      },
    );
  }
}
