import 'dart:io';

import 'package:didvan/config/theme_data.dart';
import 'package:didvan/constants/app_icons.dart';
import 'package:didvan/services/media/media.dart';
import 'package:didvan/views/widgets/didvan/icon_button.dart';
import 'package:flutter/material.dart';

class AudioControllerButton extends StatelessWidget {
  final String? audioUrl;
  final File? audioFile;

  const AudioControllerButton({Key? key, this.audioUrl, this.audioFile})
      : super(key: key);

  bool get _nowPlaying =>
      MediaService.audioPlayerTag == audioUrl ||
      audioFile != null && MediaService.audioPlayerTag == audioFile!.path;

  @override
  Widget build(BuildContext context) {
    return DidvanIconButton(
      icon: MediaService.audioPlayer.playing == true && _nowPlaying
          ? DidvanIcons.pause_circle_solid
          : DidvanIcons.play_circle_solid,
      color: Theme.of(context).colorScheme.focusedBorder,
      onPressed: () {
        MediaService.handleAudioPlayback(
          audioSource: audioFile ?? audioUrl,
        );
      },
    );
  }
}
