
import 'package:flutter/material.dart';
import 'package:flutter_wisetronic/generated/l10n.dart';
import 'package:flutter_wisetronic/widgets/general/breadcrumbs.dart';
import '../../widgets/general/download_item.dart';
import '../../store/store.dart';
import '../../utils/util_web.dart' if (dart.library.io) '../../utils/util_io.dart';

class DesktopDownloadApps extends StatefulWidget {
  final Map<String, dynamic> data;

  DesktopDownloadApps(this.data, {Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return DesktopDownloadAppsState();
  }
  
}

class DesktopDownloadAppsState extends State<DesktopDownloadApps> {
  double sideSpace = 0;
  double mainSpace = 1200;

  @override
  Widget build(BuildContext context) {
    if (widget.data == null) {
      return Container();
    }
    if (MediaQuery.of(context).size.width <= 1200) {
      mainSpace = MediaQuery.of(context).size.width;
      sideSpace = 0;
    } else {
      mainSpace = 1200;
      sideSpace = (MediaQuery.of(context).size.width - 1200) / 2;
    }
    Column col = Column(
      children: [
        Container(
          child: Util.showImage(
              'https:${widget.data['download-image']['image']}'
          ),
        ),
      ],
      mainAxisAlignment: MainAxisAlignment.start,
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisSize: MainAxisSize.max,
    );
    List<Widget> apps = _getApps();
    Wrap wrap = Wrap(
      children: [],
    );
    for (int i = 0; i < apps.length; i++) {
      wrap.children.add(apps[i]);
    }
    col.children.add(wrap);
    Widget view = SingleChildScrollView(
      child: Row(
        children: [
          Container(
            width: sideSpace,
          ),
          Container(
            width: mainSpace,
            child: col,
          ),
          Container(
            width: sideSpace,
          ),
        ],
      ),
    );
    // return Column(
    //   mainAxisAlignment: MainAxisAlignment.start,
    //   crossAxisAlignment: CrossAxisAlignment.start,
    //   children: [
    //     BreadCrumbs(true, breadCrumbs: [
    //       BreadCrumb(S.of(context).downloads, null)
    //     ],),
    //     Expanded(child: view),
    //   ],
    // );
    return view;
  }

  List<Widget> _getApps() {
    List<Widget> apps = [];
    for (int i = 0; i < (widget.data['apps'] as List).length; i++) {
      apps.add(DownloadItem((widget.data['apps'] as List)[i], width: mainSpace / 2.0,));
    }
    return apps;
  }
}