import 'package:app_hit_a_wod/src/blocs/legal.bloc.dart';
import 'package:app_hit_a_wod/src/providers/user-subscriptions.provider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_neumorphic/flutter_neumorphic.dart';
import 'package:provider/provider.dart';
import 'package:rxdart/rxdart.dart';

import '../../styles.dart';

class LegalPage extends StatelessWidget {
  const LegalPage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final UserSubscriptionsProvider us_provider = Provider.of<UserSubscriptionsProvider>(context);
    final LegalBloc bloc = LegalBloc(
      context: context,
      company_id: us_provider.currentActiveSubscription.company.id
    );
    return neuScaffoldDetail(
      context: context,
      title: Text("Términos y Condiciones", style: Theme.of(context).textTheme.subhead.copyWith(fontWeight: FontWeight.w500, fontSize: 18)),
      action: FlatButton(
        child: Text(''),
        onPressed: () {}
      ),
      body: SingleChildScrollView(
        padding: EdgeInsets.symmetric(horizontal: 20),
        child: Container(
          padding: EdgeInsets.symmetric(vertical:20.0),
          width: double.infinity,
          child: Column(
            children: <Widget>[
              StreamBuilder(
                stream: CombineLatestStream.combine3(bloc.terminosStream, bloc.politicaStream, bloc.avisoStream, (String terminos, String politica, String aviso) => {"terminos": terminos, "politica": politica, "aviso": aviso}),
                builder: (BuildContext context, AsyncSnapshot<dynamic> data) {
                  if(data.connectionState == ConnectionState.active && data.hasData) {
                    final String terminos = data.data["terminos"];
                    final String politica = data.data["politica"];
                    final String aviso = data.data["aviso"];
                    return Container(
                      child: Column(
                        children: <Widget>[
                          Text("Términos y Condiciones", style: Theme.of(context).textTheme.title.copyWith(fontSize: 25.0),),
                          SizedBox(height: 30.0,),
                          Html(data: terminos, defaultTextStyle: Theme.of(context).textTheme.body1),
                          SizedBox(height: 20.0,),
                          Text("Política de Privacidad", style: Theme.of(context).textTheme.title.copyWith(fontSize: 25.0),),
                          SizedBox(height: 30.0,),
                          Html(data: politica, defaultTextStyle: Theme.of(context).textTheme.body1),
                          SizedBox(height: 20.0,),
                          Text("Aviso Legal", style: Theme.of(context).textTheme.title.copyWith(fontSize: 25.0),),
                          SizedBox(height: 30.0,),
                          Html(data: aviso, defaultTextStyle: Theme.of(context).textTheme.body1),
                        ],
                      ),
                    );
                  } else {
                    return neuSkeletonCard(1000, double.infinity);
                  }
                }
              )
              
            ]
          )
        )
      )
    );
  }
}