import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:tone_snap/components/get_bind_widget.dart';
import 'package:tone_snap/data/models/playlist_model.dart';
import 'package:tone_snap/generated/assets.dart';
import 'package:tone_snap/modules/sideb/more_playlist_bottom_sheet/more_playlist_bottom_sheet_controller.dart';

class MorePlaylistBottomSheetView extends StatelessWidget {
  MorePlaylistBottomSheetView({super.key, required this.playlistModel});

  final controller = Get.put(MorePlaylistBottomSheetController());
  final PlaylistModel playlistModel;

  @override
  Widget build(BuildContext context) {
    controller.setPlaylistModel(playlistModel);
    return GetBindWidget(
      bind: controller,
      child: IntrinsicHeight(
        child: Container(
          width: 1.sw,
          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(),
              _buildTitle(),
              _buildItem('Edit', Assets.sideBMoreEdit, controller.onTapEdit),
              _buildItem('Delete', Assets.sideBMoreRemove, controller.onTapRemove),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildTitle() {
    return Padding(
      padding: EdgeInsets.symmetric(vertical: 10.h, horizontal: 18.w),
      child: Align(
        alignment: Alignment.centerLeft,
        child: Text(
          playlistModel.title,
          textAlign: TextAlign.start,
          style: TextStyle(
            color: Colors.white,
            fontSize: 14.sp,
          ),
        ),
      ),
    );
  }

  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 _buildItem(String label, String img, Function() onTap) {
    return Material(
      color: Colors.transparent,
      child: InkWell(
        onTap: onTap,
        child: Padding(
          padding: EdgeInsets.symmetric(horizontal: 18.w, vertical: 12.h),
          child: Row(
            children: [
              Image.asset(
                img,
                width: 24.w,
                height: 24.w,
              ),
              SizedBox(width: 12.w),
              Expanded(
                child: Text(
                  label,
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 14.sp,
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
