import 'package:flutter/cupertino.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:nut_player_example/src/features/main_screen/domain/json_bloc/json_bloc.dart';
import 'package:nut_player_example/src/features/main_screen/domain/url_bloc/url_bloc.dart';
import '../../../common/repository/settings_repository.dart';
import '../domain/main_bloc/main_bloc.dart';

class Buttons extends StatelessWidget {

  const Buttons({super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.end,
      children: [

        // КНОПКА ПОСМОТРЕТЬ ДЕМО
        Container(
            width: double.infinity,
            margin: const EdgeInsets.only(top: 25, left: 16, right: 16, bottom: 5),
            child: Builder(
              builder: (context) {
                var urlState = context.watch<UrlBloc>().state;
                var jsonState = context.watch<JsonBloc>().state;
                return CupertinoButton(
                    key: const Key('WatchDemoButtonID'),
                    color: (urlState.isFinal || jsonState.isFinal) ? CupertinoColors.link : CupertinoColors.systemGrey2,
                    borderRadius: BorderRadius.circular(12),
                    onPressed: () {
                      context.read<MainBloc>().add(OpenPlayerEvent(jsonState, urlState, context.read<SettingsRepository>().isLoop));
                    },
                    child: const Text(
                      'Посмотреть демо',
                      textAlign: TextAlign.center,
                      style: TextStyle(
                          decoration: TextDecoration.none,
                          color: CupertinoColors.white,
                          fontSize: 17,
                          fontWeight: FontWeight.w600),
                    ));
              }
            )),

        //КНОПКА НАСТРОЙКИ ПЛЕЕРА
        Container(
          alignment: Alignment.bottomCenter,
          width: double.infinity,
          margin: const EdgeInsets.symmetric(vertical: 5, horizontal: 16),
          child: CupertinoButton(
            key: const Key('PlayerSettingButtonID'),
            onPressed: () {
              context.read<MainBloc>().add(OpenSettingsEvent());
            },
            child: const Text(
              'Настройки плеера',
              textAlign: TextAlign.center,
              style: TextStyle(
                  decoration: TextDecoration.none,
                  color: CupertinoColors.link,
                  fontSize: 17,
                  fontWeight: FontWeight.w600),
            ),
          ),
        )
      ],
    );
  }
}