// ========================================
// アクセサリーデータ定義
// ========================================

const ACCESSORIES = {
  'acc_lifesteal': {
    id: 'acc_lifesteal',
    name: 'ヴァンパイアチップ',
    desc: '与えたダメージの1%を吸収し、HPを回復する',
    icon: '🩸',
    rarity: 'legend',
    color: 'text-yellow-400',
    border: 'border-yellow-500',
    bg: 'bg-yellow-900/20',
    cost: 5000,
    effectText: 'ライフスティール 1%',
    // onDamageDealt(dmg, player, stats) → returns hpDelta
    onAttackHit: (dmg, player, stats) => {
      const heal = Math.floor(dmg * 0.01);
      return { healAmt: Math.min(heal, stats.hpMax - player.hp), logMsg: heal > 0 ? `【吸血】 ${heal} HP を吸収した！` : null };
    },
  },

  'acc_guardian': {
    id: 'acc_guardian',
    name: '守護の護符',
    desc: '低確率（15%）でダメージを完全無効化する',
    icon: '🛡️',
    rarity: 'rare',
    color: 'text-blue-400',
    border: 'border-blue-600',
    bg: 'bg-blue-900/20',
    cost: 1000,
    effectText: '15%の確率でダメージ無効化',
    // onReceiveDamage() → returns { blocked: bool }
    onReceiveDamage: () => {
      const blocked = Math.random() < 0.15;
      return { blocked, logMsg: blocked ? '【守護】 ダメージを完全に無効化した！' : null };
    },
  },

  'acc_pulse_heal': {
    id: 'acc_pulse_heal',
    name: '再生パルス',
    desc: '攻撃時、10%の確率で最大HPの50%を回復する',
    icon: '💚',
    rarity: 'epic',
    color: 'text-purple-400',
    border: 'border-purple-600',
    bg: 'bg-purple-900/20',
    cost: 3000,
    effectText: '10%の確率でHP50%回復（攻撃時）',
    // onAttackHit(dmg, player, stats) → returns hpDelta
    onAttackHit: (dmg, player, stats) => {
      if (Math.random() < 0.10) {
        const healAmt = Math.floor(stats.hpMax * 0.5);
        const actual = Math.min(healAmt, stats.hpMax - player.hp);
        return { healAmt: actual, logMsg: actual > 0 ? `【再生パルス】 HP が ${actual} 回復した！` : null };
      }
      return { healAmt: 0, logMsg: null };
    },
  },

  'acc_berserker': {
    id: 'acc_berserker',
    name: 'バーサーカーコア',
    desc: 'HPが90%以上のとき、攻撃力が1.7倍になる（パッシブ）',
    icon: '⚡',
    rarity: 'rare',
    color: 'text-blue-400',
    border: 'border-blue-500',
    bg: 'bg-blue-900/20',
    cost: 1500,
    effectText: 'HP90%以上で攻撃力×1.7',
    // onCalcStats(stats, player) → modifies stats in place
    onCalcStats: (stats, player) => {
      if (player.hp <= stats.hpMax * 0.9) {
        stats.atk = Math.floor(stats.atk * 1.7);
      }
    },
  },

  'acc_iron_will': {
    id: 'acc_iron_will',
    name: '鋼鉄の意志',
    desc: '致死ダメージを1度だけ耐え、最大HPの30%で生き残る。その後5回の敵攻撃を完全無効化し、さらに続く10回の自攻撃がATK×3・SPD×2になる（1戦闘に1回）',
    icon: '🏺',
    rarity: 'unique',
    color: 'text-cyan-300',
    border: 'border-cyan-500',
    bg: 'bg-cyan-900/20',
    cost: 7500,
    effectText: '致死無効(HP30%)→5回完全ガード→10回ATK×3/SPD×2',
    // Special: handled in App.jsx battle loop via ironWillUsed/Block/Rage refs
    isIronWill: true,
  },
  
  'acc_instakill': {
    id: 'acc_instakill',
    name: '死神の鎌',
    desc: '攻撃時、5%の確率で敵を即死させる（ボスには無効）',
    icon: '💀',
    rarity: 'unique',
    color: 'text-cyan-300',
    border: 'border-cyan-500',
    bg: 'bg-cyan-900/20',
    cost: 8000,
    effectText: '5%の確率で即死（非ボスのみ）',
    // onAttackHit(dmg, player, stats, enemy) → returns { healAmt, instakill, logMsg }
    onAttackHit: (dmg, player, stats, enemy) => {
      if (enemy && !enemy.isBoss && Math.random() < 0.05) {
        return { instakill: true, logMsg: `【処刑】 ${enemy.name} を一撃で葬り去った！` };
      }
      return { instakill: false };
    },
  },
};

// アクセサリーのレア度カラー取得ユーティリティ
const getAccessoryRarityStyle = (rarity) => {
  const map = {
    normal: 'text-gray-300 border-gray-600 bg-gray-800',
    rare:   'text-blue-400 border-blue-600 bg-blue-900/20',
    epic:   'text-purple-400 border-purple-600 bg-purple-900/20',
    legend: 'text-yellow-400 border-yellow-500 bg-yellow-900/20',
    unique: 'text-cyan-300 border-cyan-400 bg-cyan-950/40',
  };
  return map[rarity] || map.normal;
};
