import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:test_sa/controllers/localization/localization.dart';
import 'package:test_sa/controllers/providers/api/device_transfer_provider.dart';
import 'package:test_sa/controllers/providers/api/user_provider.dart';
import 'package:test_sa/controllers/providers/settings/setting_provider.dart';
import 'package:test_sa/models/subtitle.dart';
import 'package:test_sa/views/app_style/colors.dart';
import 'package:test_sa/views/widgets/buttons/app_back_button.dart';
import 'package:test_sa/views/widgets/device_trancfer/device_transfer_list.dart';
import 'package:test_sa/views/widgets/loaders/loading_manager.dart';
class TrackDeviceTransferPage extends StatefulWidget {
  static const String id = "/track-device-transfer";

  const TrackDeviceTransferPage({Key key}) : super(key: key);

  @override
  State<TrackDeviceTransferPage> createState() => _TrackDeviceTransferPageState();
}

class _TrackDeviceTransferPageState extends State<TrackDeviceTransferPage>
    with TickerProviderStateMixin{
  DeviceTransferProvider _deviceTransferProvider;
  UserProvider _userProvider;
  SettingProvider _settingProvider;
  @override
  Widget build(BuildContext context) {
    _deviceTransferProvider = Provider.of<DeviceTransferProvider>(context);
    _userProvider = Provider.of<UserProvider>(context);
    _settingProvider = Provider.of<SettingProvider>(context);
    Subtitle _subtitle = AppLocalization.of(context).subtitle;

    return Scaffold(
      body: SafeArea(
        child: LoadingManager(
          isLoading: _deviceTransferProvider.isLoading,
          isFailedLoading: _deviceTransferProvider.items == null,
          stateCode: _deviceTransferProvider.stateCode,
          onRefresh: () async {
            _deviceTransferProvider.reset();
            await _deviceTransferProvider.getRequests(
              user: _userProvider.user,
              host: _settingProvider.host,
            );
          },
          child: Stack(
            children: [
              Column(
                children: [
                  Container(
                    color:AColors.primaryColor,
                    padding: const EdgeInsets.symmetric(horizontal: 0,vertical: 4),
                    child: Column(
                      children: [
                        Row(
                          children: [
                            ABackButton(),
                            Expanded(
                              child: Center(
                                child: Text(
                                  "Device Transfer",
                                  style: Theme.of(context).textTheme.headline6.copyWith(
                                      color: AColors.white,
                                      fontStyle: FontStyle.italic
                                  ),
                                ),
                              ),
                            ),
                            const SizedBox(width: 48,)
                          ],
                        ),

                      ],
                    ),
                  ),
                  Expanded(
                    child: DeviceTransferList(
                      nextPage: _deviceTransferProvider.nextPage,
                      onLazyLoad: () async {
                        await _deviceTransferProvider.getRequests(
                          user: _userProvider.user,
                          host: _settingProvider.host,
                        );
                      },
                      items: _deviceTransferProvider.items,
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}
