import 'package:driverapp/core/model/hospitals/hospitals_model.dart';
import 'package:driverapp/core/viewModels/hospital_view_model.dart';
import 'package:driverapp/widgets/data_display/text.dart';
import 'package:driverapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../base/base_view.dart';

//TODO This page for testing when come back it souled be change
class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return BaseView<HospitalViewModel>(
      onModelReady: (model) => model.getHospitals(),
      builder: (BuildContext context, HospitalViewModel model, Widget child) =>
          AppScaffold(
        baseViewModel: model,
        body: Column(
          children: <Widget>[
            InkWell(
              onTap: () {
                model.getHospitals();
              },
              child: Container(
                child: Texts('call api '),
              ),
            ),
            Expanded(
              child: _getHospitals(model.hospitals),
            )
          ],
        ),
      ),
    );
  }

  Widget _getHospitals(List<HospitalsModel> hospitals) => ListView.builder(
        itemCount: hospitals.length,
        itemBuilder: (BuildContext context, int index) => Container(
          child: Texts(hospitals[index].name),
        ),
      );
}
