import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:tone_snap/components/base_scrollbar.dart';
import 'package:tone_snap/components/get_bind_widget.dart';
import 'package:tone_snap/data/models/music_model.dart';
import 'package:tone_snap/modules/sideb/add_to_playlist_bottom_sheet/add_to_playlist_bottom_sheet_controller.dart';
import 'package:tone_snap/modules/sideb/widgets/playlist_item.dart';
import 'package:tone_snap/res/themes/app_colors.dart';

class AddToPlaylistBottomSheetView extends StatelessWidget {
  AddToPlaylistBottomSheetView({super.key, required this.musicModel});

  final controller = Get.put(AddToPlaylistBottomSheetController());
  final MusicModel musicModel;

  @override
  Widget build(BuildContext context) {
    controller.setMusicModel(musicModel);
    return GetBindWidget(
      bind: controller,
      child: Container(
        width: 1.sw,
        height: 0.6.sh,
        padding: EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom),
        decoration: const BoxDecoration(
          color: Color(0xFF282A2C),
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(18), topRight: Radius.circular(18),
          ),
        ),
        child: Column(
          children: [
            _buildIndicator(),
            _buildCreatePlaylist(),
            _buildList(),
          ],
        ),
      ),
    );
  }

  Widget _buildIndicator() {
    return Container(
      width: 28,
      height: 4,
      margin: const EdgeInsets.symmetric(vertical: 8).h,
      decoration: BoxDecoration(
        color: const Color(0xFF555555),
        borderRadius: BorderRadius.circular(20),
      ),
    );
  }

  Widget _buildCreatePlaylist() {
    return GestureDetector(
      onTap: controller.createPlayList,
      child: Container(
        margin: const EdgeInsets.symmetric(vertical: 10).h,
        padding: EdgeInsets.symmetric(vertical: 10.w, horizontal: 16.h),
        decoration: BoxDecoration(
          color: seedColor,
          borderRadius: BorderRadius.circular(8).r,
        ),
        child: Text(
          'Create Playlist',
          style: TextStyle(
            color: Colors.black,
            fontSize: 14.sp,
            fontWeight: FontWeight.w500,
          ),
        ),
      ),
    );
  }

  Widget _buildList() {
    return Expanded(
      child: BaseScrollbar(
        child: Obx(() {
          return ListView.builder(
            itemCount: controller.playlists.length,
            itemBuilder: (context, index) {
              return PlaylistItem(
                index: 0,
                playlistModel: controller.playlists[index],
                onTapItem: () => controller.onTapItem(controller.playlists[index]),
              );
            },
          );
        }),
      ),
    );
  }
}
