// Author: fengshengxiong
// Date: 2024/6/21
// Description: 首页单曲Item

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:tone_snap/components/network_image_widget.dart';
import 'package:tone_snap/data/models/music_model.dart';
import 'package:tone_snap/generated/assets.dart';
import 'package:tone_snap/modules/sideb/more_bottom_sheet/more_bottom_sheet_view.dart';
import 'package:tone_snap/utils/obj_util.dart';

class BrowseItemAtv extends StatelessWidget {
  const BrowseItemAtv({super.key, required this.musicModel, required this.onTap});

  final MusicModel musicModel;
  final Function() onTap;

  @override
  Widget build(BuildContext context) {
    return Material(
      color: Colors.transparent,
      child: InkWell(
        onTap: onTap,
        child: SizedBox(
          height: 60.w,
          child: Row(
            children: [
              _buildCover(),
              _buildContent(),
              _buildMore(),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildCover() {
    return NetworkImageWidget(
      url: musicModel.coverUrl,
      width: 60.w,
      height: 60.w,
      radius: 8.r,
    );
  }

  Widget _buildContent() {
    return Expanded(
      child: Padding(
        padding: const EdgeInsets.only(left: 12).w,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              ObjUtil.getStr(musicModel.title),
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
              style: TextStyle(
                color: Colors.white,
                fontSize: 14.sp,
              ),
            ),
            SizedBox(height: 4.h),
            Text(
              ObjUtil.getStr(musicModel.subtitle),
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
              style: TextStyle(
                color: const Color(0xFF666666),
                fontSize: 12.sp,
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildMore() {
    return Padding(
      padding: const EdgeInsets.only(right: 12).w,
      child: ClipOval(
        child: Material(
          color: Colors.transparent,
          child: InkWell(
            onTap: onTapMore,
            child: Padding(
              padding: const EdgeInsets.all(4).w,
              child: Image.asset(
                Assets.sideBMore,
                width: 24.w,
                height: 24.w,
              ),
            ),
          ),
        ),
      ),
    );
  }

  void onTapMore() {
    Get.bottomSheet(
      MoreBottomSheetView(
        musicModel: musicModel.obs,
      ),
    );
  }
}
