'use strict';

var chunkWA67GZSZ_js = require('./chunk-WA67GZSZ.js');
var React = require('react');
var clsx = require('clsx');
var useSWR = require('swr');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);
var useSWR__default = /*#__PURE__*/_interopDefault(useSWR);

function MusicPlayer({
  track,
  onPlay,
  onPause,
  onStop,
  onVolumeChange,
  onSeek,
  initialVolume = 0.7,
  className = "",
  compact = false,
  ultraCompact = false,
  hideVolumeControl = false,
  showTrackInfo = true,
  isPlaying,
  currentTime,
  duration,
  externalVolume
}) {
  const [volume, setVolume] = React.useState(externalVolume ?? initialVolume);
  const [isLoading, setIsLoading] = React.useState(false);
  const [error, setError] = React.useState();
  const progressRef = React.useRef(null);
  const volumeRef = React.useRef(null);
  const [isDraggingProgress, setIsDraggingProgress] = React.useState(false);
  const [isDraggingVolume, setIsDraggingVolume] = React.useState(false);
  React.useEffect(() => {
    if (externalVolume !== void 0) {
      setVolume(externalVolume);
    }
  }, [externalVolume]);
  const formatTime = (seconds) => {
    if (!seconds || isNaN(seconds)) return "0:00";
    const mins = Math.floor(seconds / 60);
    const secs = Math.floor(seconds % 60);
    return mins + ":" + secs.toString().padStart(2, "0");
  };
  const handlePlay = React.useCallback(() => {
    onPlay?.();
  }, [onPlay]);
  const handlePause = React.useCallback(() => {
    onPause?.();
  }, [onPause]);
  const handleStop = React.useCallback(() => {
    onStop?.();
  }, [onStop]);
  const handleVolumeChange = React.useCallback((newVolume) => {
    const clampedVolume = Math.max(0, Math.min(1, newVolume));
    setVolume(clampedVolume);
    onVolumeChange?.(clampedVolume);
  }, [onVolumeChange]);
  const handleSeek = React.useCallback((time) => {
    if (!duration || isNaN(duration)) return;
    const seekTime = Math.max(0, Math.min(duration, time));
    onSeek?.(seekTime);
  }, [duration, onSeek]);
  const handleProgressMouseDown = React.useCallback((e) => {
    if (!progressRef.current || !duration) return;
    setIsDraggingProgress(true);
    const rect = progressRef.current.getBoundingClientRect();
    const percent = (e.clientX - rect.left) / rect.width;
    const time = percent * duration;
    handleSeek(time);
  }, [duration, handleSeek]);
  const handleVolumeMouseDown = React.useCallback((e) => {
    if (!volumeRef.current) return;
    setIsDraggingVolume(true);
    const rect = volumeRef.current.getBoundingClientRect();
    const percent = (e.clientX - rect.left) / rect.width;
    handleVolumeChange(percent);
  }, [handleVolumeChange]);
  React.useEffect(() => {
    const handleMouseMove = (e) => {
      if (isDraggingProgress && progressRef.current && duration) {
        const rect = progressRef.current.getBoundingClientRect();
        const percent = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width));
        const time = percent * duration;
        handleSeek(time);
      }
      if (isDraggingVolume && volumeRef.current) {
        const rect = volumeRef.current.getBoundingClientRect();
        const percent = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width));
        handleVolumeChange(percent);
      }
    };
    const handleMouseUp = () => {
      setIsDraggingProgress(false);
      setIsDraggingVolume(false);
    };
    if (isDraggingProgress || isDraggingVolume) {
      document.addEventListener("mousemove", handleMouseMove);
      document.addEventListener("mouseup", handleMouseUp);
    }
    return () => {
      document.removeEventListener("mousemove", handleMouseMove);
      document.removeEventListener("mouseup", handleMouseUp);
    };
  }, [isDraggingProgress, isDraggingVolume, duration, handleSeek, handleVolumeChange]);
  const stopPropagation = React.useCallback((e) => {
    e.preventDefault();
    e.stopPropagation();
  }, []);
  if (ultraCompact) {
    return /* @__PURE__ */ React__default.default.createElement(
      "div",
      {
        className: clsx.clsx("flex items-center gap-2 bg-white/90 backdrop-blur-sm rounded-xl p-2 shadow-lg border border-purple-200", className),
        style: { width: hideVolumeControl ? "120px" : "192px" },
        onClick: stopPropagation,
        onMouseDown: stopPropagation,
        onMouseUp: stopPropagation,
        onTouchStart: stopPropagation,
        onTouchEnd: stopPropagation,
        onPointerDown: stopPropagation,
        onPointerUp: stopPropagation
      },
      /* @__PURE__ */ React__default.default.createElement("div", { className: clsx.clsx("flex items-center gap-1", hideVolumeControl ? "w-full justify-center" : "") }, /* @__PURE__ */ React__default.default.createElement(
        "button",
        {
          onClick: (e) => {
            stopPropagation(e);
            handleStop();
          },
          onMouseDown: stopPropagation,
          onMouseUp: stopPropagation,
          onTouchStart: stopPropagation,
          onTouchEnd: stopPropagation,
          onPointerDown: stopPropagation,
          onPointerUp: stopPropagation,
          className: "w-7 h-7 rounded-lg bg-gray-100 hover:bg-gray-200 border border-gray-300 flex items-center justify-center transition-colors",
          title: "\u505C\u6B62"
        },
        /* @__PURE__ */ React__default.default.createElement("div", { className: "w-2.5 h-2.5 bg-gray-600 rounded-sm" })
      ), /* @__PURE__ */ React__default.default.createElement(
        "button",
        {
          onClick: (e) => {
            stopPropagation(e);
            isPlaying ? handlePause() : handlePlay();
          },
          onMouseDown: stopPropagation,
          onMouseUp: stopPropagation,
          onTouchStart: stopPropagation,
          onTouchEnd: stopPropagation,
          onPointerDown: stopPropagation,
          onPointerUp: stopPropagation,
          className: clsx.clsx("w-8 h-8 rounded-lg border flex items-center justify-center transition-colors", isPlaying ? "bg-gradient-to-r from-purple-500 to-pink-500 hover:from-purple-600 hover:to-pink-600 text-white border-purple-400" : "bg-gradient-to-r from-green-500 to-blue-500 hover:from-green-600 hover:to-blue-600 text-white border-green-400 cursor-pointer"),
          title: isPlaying ? "\u6682\u505C" : "\u64AD\u653E"
        },
        isPlaying ? /* @__PURE__ */ React__default.default.createElement("div", { className: "flex gap-0.5" }, /* @__PURE__ */ React__default.default.createElement("div", { className: "w-1 h-3 bg-white rounded-sm" }), /* @__PURE__ */ React__default.default.createElement("div", { className: "w-1 h-3 bg-white rounded-sm" })) : /* @__PURE__ */ React__default.default.createElement("div", { className: "w-0 h-0 border-l-[6px] border-l-white border-t-[4px] border-t-transparent border-b-[4px] border-b-transparent ml-0.5" })
      )),
      !hideVolumeControl && /* @__PURE__ */ React__default.default.createElement("div", { className: "flex items-center gap-1 flex-1" }, /* @__PURE__ */ React__default.default.createElement("div", { className: "text-gray-500 text-xs" }, "\u{1F50A}"), /* @__PURE__ */ React__default.default.createElement(
        "div",
        {
          ref: volumeRef,
          className: "flex-1 h-2 bg-gray-200 rounded-full cursor-pointer relative",
          onMouseDown: handleVolumeMouseDown,
          onClick: stopPropagation,
          onTouchStart: stopPropagation,
          onTouchEnd: stopPropagation,
          onPointerDown: stopPropagation,
          onPointerUp: stopPropagation
        },
        /* @__PURE__ */ React__default.default.createElement(
          "div",
          {
            className: "h-full bg-gradient-to-r from-purple-400 to-pink-400 rounded-full",
            style: { width: volume * 100 + "%" }
          }
        ),
        /* @__PURE__ */ React__default.default.createElement(
          "div",
          {
            className: "absolute top-1/2 w-3 h-3 bg-white border-2 border-purple-400 rounded-full transform -translate-y-1/2 cursor-grab",
            style: { left: volume * 100 + "%", transform: "translateX(-50%) translateY(-50%)" }
          }
        )
      ))
    );
  }
  return /* @__PURE__ */ React__default.default.createElement(
    "div",
    {
      className: clsx.clsx("bg-white/90 backdrop-blur-sm rounded-xl p-4 shadow-lg border border-purple-200", className),
      style: { width: compact ? "280px" : "320px" },
      onClick: stopPropagation,
      onMouseDown: stopPropagation,
      onMouseUp: stopPropagation,
      onTouchStart: stopPropagation,
      onTouchEnd: stopPropagation,
      onPointerDown: stopPropagation,
      onPointerUp: stopPropagation
    },
    !compact && showTrackInfo && track && /* @__PURE__ */ React__default.default.createElement("div", { className: "mb-3" }, /* @__PURE__ */ React__default.default.createElement("h3", { className: "text-sm font-medium text-gray-800 truncate" }, track.name), /* @__PURE__ */ React__default.default.createElement("p", { className: "text-xs text-gray-500" }, "\u80CC\u666F\u97F3\u4E50")),
    !compact && /* @__PURE__ */ React__default.default.createElement("div", { className: "mb-3" }, /* @__PURE__ */ React__default.default.createElement(
      "div",
      {
        ref: progressRef,
        className: "w-full h-2 bg-gray-200 rounded-full cursor-pointer relative",
        onMouseDown: handleProgressMouseDown,
        onClick: stopPropagation,
        onTouchStart: stopPropagation,
        onTouchEnd: stopPropagation,
        onPointerDown: stopPropagation,
        onPointerUp: stopPropagation
      },
      /* @__PURE__ */ React__default.default.createElement(
        "div",
        {
          className: "h-full bg-gradient-to-r from-purple-400 to-pink-400 rounded-full transition-all duration-100",
          style: { width: duration > 0 ? currentTime / duration * 100 + "%" : "0%" }
        }
      ),
      /* @__PURE__ */ React__default.default.createElement(
        "div",
        {
          className: "absolute top-1/2 w-4 h-4 bg-white border-2 border-purple-400 rounded-full transform -translate-y-1/2 cursor-grab",
          style: {
            left: duration > 0 ? currentTime / duration * 100 + "%" : "0%",
            transform: "translateX(-50%) translateY(-50%)"
          }
        }
      )
    ), /* @__PURE__ */ React__default.default.createElement("div", { className: "flex justify-between text-xs text-gray-500 mt-1" }, /* @__PURE__ */ React__default.default.createElement("span", null, formatTime(currentTime)), /* @__PURE__ */ React__default.default.createElement("span", null, formatTime(duration)))),
    /* @__PURE__ */ React__default.default.createElement("div", { className: "flex items-center justify-center gap-3 mb-3" }, /* @__PURE__ */ React__default.default.createElement(
      "button",
      {
        onClick: (e) => {
          stopPropagation(e);
          handleStop();
        },
        onMouseDown: stopPropagation,
        onMouseUp: stopPropagation,
        onTouchStart: stopPropagation,
        onTouchEnd: stopPropagation,
        onPointerDown: stopPropagation,
        onPointerUp: stopPropagation,
        className: "w-10 h-10 rounded-full bg-gray-100 hover:bg-gray-200 border border-gray-300 flex items-center justify-center transition-colors",
        title: "\u505C\u6B62"
      },
      /* @__PURE__ */ React__default.default.createElement("div", { className: "w-4 h-4 bg-gray-600 rounded-sm" })
    ), /* @__PURE__ */ React__default.default.createElement(
      "button",
      {
        onClick: (e) => {
          stopPropagation(e);
          isPlaying ? handlePause() : handlePlay();
        },
        onMouseDown: stopPropagation,
        onMouseUp: stopPropagation,
        onTouchStart: stopPropagation,
        onTouchEnd: stopPropagation,
        onPointerDown: stopPropagation,
        onPointerUp: stopPropagation,
        className: clsx.clsx("w-12 h-12 rounded-full border-2 flex items-center justify-center transition-colors", isPlaying ? "bg-gradient-to-r from-purple-500 to-pink-500 hover:from-purple-600 hover:to-pink-600 text-white border-purple-400" : "bg-gradient-to-r from-green-500 to-blue-500 hover:from-green-600 hover:to-blue-600 text-white border-green-400 cursor-pointer"),
        title: isPlaying ? "\u6682\u505C" : "\u64AD\u653E"
      },
      isLoading ? /* @__PURE__ */ React__default.default.createElement("div", { className: "w-5 h-5 border-2 border-white border-t-transparent rounded-full animate-spin" }) : isPlaying ? /* @__PURE__ */ React__default.default.createElement("div", { className: "flex gap-1" }, /* @__PURE__ */ React__default.default.createElement("div", { className: "w-1.5 h-4 bg-white rounded-sm" }), /* @__PURE__ */ React__default.default.createElement("div", { className: "w-1.5 h-4 bg-white rounded-sm" })) : /* @__PURE__ */ React__default.default.createElement("div", { className: "w-0 h-0 border-l-[10px] border-l-white border-t-[7px] border-t-transparent border-b-[7px] border-b-transparent ml-1" })
    )),
    !hideVolumeControl && /* @__PURE__ */ React__default.default.createElement("div", { className: "flex items-center gap-3" }, /* @__PURE__ */ React__default.default.createElement("div", { className: "text-gray-500 text-sm" }, "\u{1F50A}"), /* @__PURE__ */ React__default.default.createElement(
      "div",
      {
        ref: volumeRef,
        className: "flex-1 h-2 bg-gray-200 rounded-full cursor-pointer relative",
        onMouseDown: handleVolumeMouseDown,
        onClick: stopPropagation,
        onTouchStart: stopPropagation,
        onTouchEnd: stopPropagation,
        onPointerDown: stopPropagation,
        onPointerUp: stopPropagation
      },
      /* @__PURE__ */ React__default.default.createElement(
        "div",
        {
          className: "h-full bg-gradient-to-r from-purple-400 to-pink-400 rounded-full",
          style: { width: volume * 100 + "%" }
        }
      ),
      /* @__PURE__ */ React__default.default.createElement(
        "div",
        {
          className: "absolute top-1/2 w-4 h-4 bg-white border-2 border-purple-400 rounded-full transform -translate-y-1/2 cursor-grab",
          style: { left: volume * 100 + "%", transform: "translateX(-50%) translateY(-50%)" }
        }
      )
    ), /* @__PURE__ */ React__default.default.createElement("div", { className: "text-xs text-gray-500 w-8 text-right" }, Math.round(volume * 100), "%")),
    error && /* @__PURE__ */ React__default.default.createElement("div", { className: "mt-2 text-xs text-red-500" }, error)
  );
}
function MikutapMusicPlayer({
  track,
  onPlay,
  onPause,
  onSeek,
  className = "",
  isPlaying,
  currentTime,
  duration
}) {
  const progressRef = React.useRef(null);
  const [isDraggingProgress, setIsDraggingProgress] = React.useState(false);
  const formatTime = (seconds) => {
    if (!seconds || isNaN(seconds)) return "0:00";
    const mins = Math.floor(seconds / 60);
    const secs = Math.floor(seconds % 60);
    return mins + ":" + secs.toString().padStart(2, "0");
  };
  const handlePlay = React.useCallback(() => {
    onPlay?.();
  }, [onPlay]);
  const handlePause = React.useCallback(() => {
    onPause?.();
  }, [onPause]);
  const handleSeek = React.useCallback((time) => {
    if (!duration || isNaN(duration)) return;
    const seekTime = Math.max(0, Math.min(duration, time));
    onSeek?.(seekTime);
  }, [duration, onSeek]);
  const handleProgressMouseDown = React.useCallback((e) => {
    if (!progressRef.current || !duration) return;
    setIsDraggingProgress(true);
    const rect = progressRef.current.getBoundingClientRect();
    const percent = (e.clientX - rect.left) / rect.width;
    const time = percent * duration;
    handleSeek(time);
  }, [duration, handleSeek]);
  React.useEffect(() => {
    const handleMouseMove = (e) => {
      if (isDraggingProgress && progressRef.current && duration) {
        const rect = progressRef.current.getBoundingClientRect();
        const percent = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width));
        const time = percent * duration;
        handleSeek(time);
      }
    };
    const handleMouseUp = () => {
      setIsDraggingProgress(false);
    };
    if (isDraggingProgress) {
      document.addEventListener("mousemove", handleMouseMove);
      document.addEventListener("mouseup", handleMouseUp);
    }
    return () => {
      document.removeEventListener("mousemove", handleMouseMove);
      document.removeEventListener("mouseup", handleMouseUp);
    };
  }, [isDraggingProgress, duration, handleSeek]);
  const stopPropagation = React.useCallback((e) => {
    e.preventDefault();
    e.stopPropagation();
  }, []);
  return /* @__PURE__ */ React__default.default.createElement(
    "div",
    {
      className: clsx.clsx("bg-gradient-to-r from-purple-900/95 to-pink-900/95 backdrop-blur-sm rounded-2xl p-4 shadow-2xl border border-purple-300/30", className),
      style: { width: "200px" },
      onClick: stopPropagation,
      onMouseDown: stopPropagation,
      onMouseUp: stopPropagation,
      onTouchStart: stopPropagation,
      onTouchEnd: stopPropagation,
      onPointerDown: stopPropagation,
      onPointerUp: stopPropagation
    },
    track && /* @__PURE__ */ React__default.default.createElement("div", { className: "mb-3 text-center" }, /* @__PURE__ */ React__default.default.createElement("div", { className: "text-white text-sm font-medium truncate mb-1" }, track.name), /* @__PURE__ */ React__default.default.createElement("div", { className: "text-purple-200 text-xs" }, "\u80CC\u666F\u97F3\u4E50")),
    /* @__PURE__ */ React__default.default.createElement("div", { className: "flex justify-center mb-3" }, /* @__PURE__ */ React__default.default.createElement(
      "button",
      {
        onClick: (e) => {
          stopPropagation(e);
          isPlaying ? handlePause() : handlePlay();
        },
        onMouseDown: stopPropagation,
        onMouseUp: stopPropagation,
        onTouchStart: stopPropagation,
        onTouchEnd: stopPropagation,
        onPointerDown: stopPropagation,
        onPointerUp: stopPropagation,
        className: clsx.clsx("w-12 h-12 rounded-full border-2 flex items-center justify-center transition-all duration-300 shadow-lg hover:scale-105", isPlaying ? "bg-gradient-to-r from-orange-400 to-red-500 hover:from-orange-500 hover:to-red-600 text-white border-orange-300 shadow-orange-500/50" : "bg-gradient-to-r from-green-400 to-emerald-500 hover:from-green-500 hover:to-emerald-600 text-white border-green-300 shadow-green-500/50"),
        title: isPlaying ? "\u6682\u505C" : "\u64AD\u653E"
      },
      isPlaying ? /* @__PURE__ */ React__default.default.createElement("div", { className: "flex gap-1" }, /* @__PURE__ */ React__default.default.createElement("div", { className: "w-1.5 h-4 bg-white rounded-sm" }), /* @__PURE__ */ React__default.default.createElement("div", { className: "w-1.5 h-4 bg-white rounded-sm" })) : /* @__PURE__ */ React__default.default.createElement("div", { className: "w-0 h-0 border-l-[10px] border-l-white border-t-[7px] border-t-transparent border-b-[7px] border-b-transparent ml-1" })
    )),
    /* @__PURE__ */ React__default.default.createElement("div", { className: "mb-2" }, /* @__PURE__ */ React__default.default.createElement(
      "div",
      {
        ref: progressRef,
        className: "w-full h-2 bg-white/20 rounded-full cursor-pointer relative overflow-hidden",
        onMouseDown: handleProgressMouseDown,
        onClick: stopPropagation,
        onTouchStart: stopPropagation,
        onTouchEnd: stopPropagation,
        onPointerDown: stopPropagation,
        onPointerUp: stopPropagation
      },
      /* @__PURE__ */ React__default.default.createElement(
        "div",
        {
          className: "h-full bg-gradient-to-r from-cyan-400 to-blue-500 rounded-full transition-all duration-100 shadow-sm",
          style: { width: duration > 0 ? currentTime / duration * 100 + "%" : "0%" }
        }
      ),
      /* @__PURE__ */ React__default.default.createElement(
        "div",
        {
          className: "absolute top-1/2 w-3 h-3 bg-white border-2 border-cyan-400 rounded-full transform -translate-y-1/2 cursor-grab shadow-lg",
          style: {
            left: duration > 0 ? currentTime / duration * 100 + "%" : "0%",
            transform: "translateX(-50%) translateY(-50%)"
          }
        }
      )
    ), /* @__PURE__ */ React__default.default.createElement("div", { className: "flex justify-between text-xs text-purple-200 mt-1" }, /* @__PURE__ */ React__default.default.createElement("span", null, formatTime(currentTime)), /* @__PURE__ */ React__default.default.createElement("span", null, formatTime(duration)))),
    /* @__PURE__ */ React__default.default.createElement("div", { className: "flex justify-center" }, /* @__PURE__ */ React__default.default.createElement("div", { className: clsx.clsx("flex items-center gap-2 text-xs px-3 py-1 rounded-full transition-all duration-300", isPlaying ? "bg-orange-500/20 text-orange-200 border border-orange-400/30" : "bg-gray-500/20 text-gray-300 border border-gray-400/30") }, /* @__PURE__ */ React__default.default.createElement("div", { className: clsx.clsx("w-2 h-2 rounded-full transition-all duration-300", isPlaying ? "bg-orange-400 animate-pulse" : "bg-gray-400") }), /* @__PURE__ */ React__default.default.createElement("span", null, isPlaying ? "\u64AD\u653E\u4E2D" : "\u5DF2\u6682\u505C")))
  );
}

// src/music/adapters/kugou.ts
var kugouAdapter = {
  parseSearchResult(data) {
    const root = typeof data === "string" ? JSON.parse(data) : data;
    const info = root.data?.data?.info || root.data?.info || root.info || [];
    const total = root.data?.data?.total || root.data?.total || info.length;
    return {
      tracks: info.map((item) => {
        let pic = item.pic || "";
        if (item.trans_param?.union_cover) {
          pic = item.trans_param.union_cover.replace("{size}", "400");
        }
        return {
          id: item.hash || item.id,
          name: item.songname || item.filename || "Unknown",
          artist: item.singername || "Unknown Artist",
          album: item.album_name || item.album || "",
          pic,
          url: item.url,
          lrc: item.lrc,
          source: "kugou",
          isVip: item.privilege >= 8,
          playable: item.status !== 0
        };
      }),
      total
    };
  },
  parseGetSongUrl(data) {
    return data.url?.url || data.url?.backup_url?.[0] || null;
  },
  parseGetLyric(data) {
    const root = typeof data === "string" ? JSON.parse(data) : data;
    return root.lyric || root.lrc || root.data?.lyric || root.data || "";
  }
};

// src/music/adapters/netease.ts
var neteaseAdapter = {
  parseSearchResult(data) {
    const root = typeof data === "string" ? JSON.parse(data) : data;
    const songs = root.result?.songs || root.songs || (Array.isArray(root) ? root : []);
    return {
      tracks: songs.map((item) => ({
        id: item.id,
        name: item.name,
        artist: Array.isArray(item.artist) ? item.artist.join(", ") : item.artist,
        album: item.album?.name || item.album,
        pic: item.pic || item.album?.picUrl,
        url: item.url,
        lrc: item.lrc,
        source: "netease",
        isVip: item.fee === 1 || item.fee === 4,
        playable: item.noCopyrightRcmd === null
      })),
      total: root.result?.songCount || songs.length
    };
  },
  parseGetSongUrl(data) {
    const root = typeof data === "string" ? JSON.parse(data) : data;
    const item = root.data?.[0] || root[0] || root;
    return item.url || null;
  },
  parseGetLyric(data) {
    const root = typeof data === "string" ? JSON.parse(data) : data;
    return root.lyric || root.lrc || root.data?.lyric || "";
  }
};

// src/music/adapters/tencent.ts
var tencentAdapter = {
  parseSearchResult(data) {
    const root = typeof data === "string" ? JSON.parse(data) : data;
    const songData = root.data?.data?.song || root.data?.song || root.data || root;
    const list = songData.list || root.songs || [];
    const total = songData.totalnum || root.total || list.length;
    return {
      tracks: list.map((item) => {
        const artist = Array.isArray(item.singer) ? item.singer.map((s) => s.name).join(", ") : item.singer?.[0]?.name || item.artist || "Unknown";
        let pic = item.pic;
        if (!pic && item.album?.mid) {
          pic = "https://y.gtimg.cn/music/photo_new/T002R300x300M000" + item.album.mid + ".jpg";
        }
        return {
          id: item.mid || item.id || item.songid,
          name: item.name || item.title || item.songname,
          artist,
          album: item.album?.name || item.albumname || item.album,
          pic: pic || "",
          url: item.url,
          lrc: item.lrc,
          source: "tencent",
          isVip: item.pay?.pay_play === 1,
          playable: item.action?.switch !== 0
        };
      }),
      total
    };
  },
  parseGetSongUrl(data) {
    const root = data;
    const urlData = root.url.url;
    let finalUrl = Object.values(urlData)[0];
    console.log("finalUrl2", finalUrl);
    return finalUrl.startsWith("http") ? finalUrl : "http://" + finalUrl;
  },
  parseGetLyric(data) {
    const root = typeof data === "string" ? JSON.parse(data) : data;
    return root.lyric || root.lrc || root.data?.lyric || "";
  }
};

// src/music/adapters/xiami.ts
var xiamiAdapter = {
  parseSearchResult(data) {
    const root = typeof data === "string" ? JSON.parse(data) : data;
    const result = root.data?.result || root.result || root;
    const songs = result.songs || (Array.isArray(root) ? root : []);
    return {
      tracks: songs.map((item) => ({
        id: item.id?.toString() || "",
        name: item.name || "Unknown",
        artist: Array.isArray(item.ar) ? item.ar.map((a) => a.name).join(", ") : item.artist || "Unknown Artist",
        album: item.al?.name || item.album || "",
        pic: item.al?.picUrl || item.pic || "",
        url: item.url,
        lrc: item.lrc,
        source: "xiami",
        // 这里的逻辑参考提供的数据结构
        isVip: item.fee === 1 || item.fee === 8,
        playable: item.copyright !== 0
      })),
      total: result.songCount || songs.length
    };
  },
  parseGetSongUrl(data) {
    const root = typeof data === "string" ? JSON.parse(data) : data;
    const item = root.data?.[0] || root.data || root[0] || root;
    return item.url || null;
  },
  parseGetLyric(data) {
    const root = typeof data === "string" ? JSON.parse(data) : data;
    return root.lyric || root.lrc || root.data?.lyric || root.data || "";
  }
};

// src/music/hooks/useMusic.ts
var fetcher = (url) => fetch(url).then((res) => res.json());
var ADAPTERS = {
  kugou: kugouAdapter,
  netease: neteaseAdapter,
  tencent: tencentAdapter,
  xiami: xiamiAdapter
};
function useMusic() {
  const [searchOptions, setSearchOptions] = React.useState(null);
  const { data: rawData, error: searchError, isLoading: isSearching } = useSWR__default.default(
    searchOptions ? "/api/music/search?keyword=" + encodeURIComponent(searchOptions.keyword) + "&source=" + (searchOptions.source || chunkWA67GZSZ_js.DEFAULT_MUSIC_SOURCE) + "&limit=" + (searchOptions.limit || 20) + "&offset=" + (searchOptions.offset || 0) + (searchOptions.miku ? "&miku=true" : "") : null,
    fetcher
  );
  const searchResult = React.useMemo(() => {
    if (!rawData?.data || !searchOptions) return void 0;
    const adapter = ADAPTERS[searchOptions.source || chunkWA67GZSZ_js.DEFAULT_MUSIC_SOURCE];
    if (adapter) {
      return adapter.parseSearchResult(rawData.data);
    }
    return void 0;
  }, [rawData, searchOptions]);
  const search = React.useCallback((options) => {
    setSearchOptions(options);
  }, []);
  const getSongUrl = React.useCallback(async (id, source = chunkWA67GZSZ_js.DEFAULT_MUSIC_SOURCE) => {
    try {
      const res = await fetch("/api/music/url?id=" + id + "&source=" + source);
      const json = await res.json();
      const adapter = ADAPTERS[source];
      console.log("json2", json.data, source, adapter);
      if (adapter && json.data) {
        console.log("getSongUrl2", json.data);
        return adapter.parseGetSongUrl(json.data) || void 0;
      }
      return json.data?.url;
    } catch (err) {
      console.error("[Music] Failed to get song URL:", err);
      return void 0;
    }
  }, []);
  const getLyric = React.useCallback(async (id, source = chunkWA67GZSZ_js.DEFAULT_MUSIC_SOURCE) => {
    try {
      const res = await fetch("/api/music/lyric?id=" + id + "&source=" + source);
      const json = await res.json();
      const adapter = ADAPTERS[source];
      if (adapter && json.data) {
        return adapter.parseGetLyric(json.data);
      }
      return json.data?.lyric;
    } catch (err) {
      console.error("[Music] Failed to get lyric:", err);
      return void 0;
    }
  }, []);
  return {
    search,
    searchResult,
    isSearching,
    searchError,
    getSongUrl,
    getLyric
  };
}

exports.MikutapMusicPlayer = MikutapMusicPlayer;
exports.MusicPlayer = MusicPlayer;
exports.kugouAdapter = kugouAdapter;
exports.neteaseAdapter = neteaseAdapter;
exports.tencentAdapter = tencentAdapter;
exports.useMusic = useMusic;
exports.xiamiAdapter = xiamiAdapter;
//# sourceMappingURL=chunk-TDCDEBGP.js.map
//# sourceMappingURL=chunk-TDCDEBGP.js.map