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/network_image_widget.dart';
import 'package:tone_snap/data/models/music_model.dart';
import 'package:tone_snap/modules/sideb/widgets/music_appbar.dart';

import 'love_songs_controller.dart';

class LoveSongsView extends StatelessWidget {
  LoveSongsView({super.key});

  final controller = Get.find<LoveSongsController>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      body: SafeArea(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            const MusicAppbar(
              title: 'Love Songs',
            ),
            _buildTotal(),
            _buildListView(),
          ],
        ),
      ),
    );
  }

  Widget _buildTotal() {
    return Padding(
      padding: EdgeInsets.only(top: 34.h, bottom: 10.h, left: 18.w, right: 18.w),
      child: Text(
        '${controller.loveList.length} Songs',
        style: TextStyle(
          color: Colors.white,
          fontSize: 18.sp,
          overflow: TextOverflow.ellipsis,
        ),
      ),
    );
  }

  Widget _buildListView() {
    return Expanded(
      child: BaseScrollbar(
        child: ListView.builder(
          itemCount: controller.loveList.length,
          itemBuilder: (context, index) {
            return _buildItem(controller.loveList[index]);
          },
        ),
      ),
    );
  }

  Widget _buildItem(MusicModel model) {
    return InkWell(
      onTap: (){},
      child: Padding(
        padding: EdgeInsets.symmetric(vertical: 8.h, horizontal: 18.w),
        child: Row(
          children: [
            NetworkImageWidget(
              url: '',
              width: 60.w,
              height: 60.w,
              radius: 8.r,
            ),
            SizedBox(width: 14.w),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    'There For You',
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 14.sp,
                    ),
                  ),
                  SizedBox(height: 4.h),
                  Text(
                    '234 songs',
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                      color: const Color(0xFF999999),
                      fontSize: 12.sp,
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
