/* global React, Icons */
const { useState: useStateRanking } = React;

/* =====================================================================
   比較表データ（1〜7位）
   nameTag / btnTag は広告主より提供のコードをそのまま使用（変更不可）
   ===================================================================== */
const MAIN_COMPANIES = [
  {
    rank: 1,
    service: "株式会社No.1",
    tag: "最短30分入金",
    feeLabel: "0.5〜15%",
    speedLabel: "最短30分",
    speedFast: true,
    amountRange: "50万〜1億円",
    contracts: "2社間/3社間",
    online: true,
    individual: true,
    reason: "業界最短水準の最短30分入金。手数料0.5%〜・審査通過率95%以上。電子契約でオンライン完結。",
    nameTag: `<a href="https://px.a8.net/svt/ejp?a8mat=4B3OR0+FREKHM+4EKW+5YJRM" rel="nofollow">ファクタリングなら株式会社No.1</a>
<img border="0" width="1" height="1" src="https://www18.a8.net/0.gif?a8mat=4B3OR0+FREKHM+4EKW+5YJRM" alt="">`,
    btnTag: `<a href="https://px.a8.net/svt/ejp?a8mat=4B3OR0+FREKHM+4EKW+5ZEMP" rel="nofollow">
<img border="0" width="120" height="60" alt="" src="https://www29.a8.net/svt/bgt?aid=260512524953&wid=022&eno=01&mid=s00000020552001005000&mc=1"></a>
<img border="0" width="1" height="1" src="https://www15.a8.net/0.gif?a8mat=4B3OR0+FREKHM+4EKW+5ZEMP" alt="">`,
  },
  {
    rank: 2,
    service: "トップ・マネジメント",
    tag: "電話相談も成果対象",
    feeLabel: "要相談",
    speedLabel: "最短即日",
    speedFast: true,
    amountRange: "要相談",
    contracts: "2社間",
    online: true,
    individual: true,
    reason: "電話相談も成果報酬対象でハードルが低い。個人事業主も対応（法人相手の売掛金がある場合）。3か月以上の長期支払いサイトにも対応。地方のお客様は成約時に交通費キャッシュバックあり。",
    nameTag: `<a href="https://px.a8.net/svt/ejp?a8mat=4B3OR0+GAGFUI+3JLM+BW8O2" rel="nofollow">トップ・マネジメント</a>
<img border="0" width="1" height="1" src="https://www17.a8.net/0.gif?a8mat=4B3OR0+GAGFUI+3JLM+BW8O2" alt="">`,
    btnTag: `<a href="https://px.a8.net/svt/ejp?a8mat=4B3OR0+GAGFUI+3JLM+626XT" rel="nofollow">
<img border="0" width="120" height="60" alt="" src="https://www21.a8.net/svt/bgt?aid=260512524985&wid=022&eno=01&mid=s00000016537001018000&mc=1"></a>
<img border="0" width="1" height="1" src="https://www11.a8.net/0.gif?a8mat=4B3OR0+GAGFUI+3JLM+626XT" alt="">`,
  },
  {
    rank: 3,
    service: "西日本ファクター",
    tag: "九州・地域密着",
    feeLabel: "2.8%〜",
    speedLabel: "最短1日",
    speedFast: false,
    amountRange: "30万〜3,000万円",
    contracts: "2社間/3社間",
    online: false,
    individual: true,
    reason: "手数料2.8%〜と業界最低水準。建設・運送・食品業の豊富な実績。取引先・銀行に知られない秘密厳守。",
    nameTag: `<a href="https://px.a8.net/svt/ejp?a8mat=4B3OR0+FUDQII+3XT0+5YJRM" rel="nofollow">ファクタリングなら西日本ファクター</a>
<img border="0" width="1" height="1" src="https://www14.a8.net/0.gif?a8mat=4B3OR0+FUDQII+3XT0+5YJRM" alt="">`,
    btnTag: `<a href="https://px.a8.net/svt/ejp?a8mat=4B3OR0+FUDQII+3XT0+61JSH" rel="nofollow">
<img border="0" width="120" height="60" alt="" src="https://www22.a8.net/svt/bgt?aid=260512524958&wid=022&eno=01&mid=s00000018378001015000&mc=1"></a>
<img border="0" width="1" height="1" src="https://www13.a8.net/0.gif?a8mat=4B3OR0+FUDQII+3XT0+61JSH" alt="">`,
  },
  {
    rank: 4,
    service: "アクセルファクター",
    tag: "審査通過率93.3%",
    feeLabel: "1.0〜12%",
    speedLabel: "最短2時間",
    speedFast: true,
    amountRange: "30万〜2億円超",
    contracts: "2社間/3社間",
    online: true,
    individual: true,
    reason: "審査通過率93.3%・累計20,000件超の実績。最短2時間で入金。2億円超の大口にも対応可能。",
    nameTag: `<a href="//af.moshimo.com/af/c/click?a_id=5553499&p_id=1861&pc_id=3615&pl_id=25882&url=https%3A%2F%2Faccelfacter.co.jp%2Flp12%2F%3Fcode%3Dmoaf12%26utm_term%3D%26utm_source%3Dmoaf12%26utm_medium%3Dcpc" rel="nofollow" referrerpolicy="no-referrer-when-downgrade" attributionsrc>即日資金調達アクセルファクター</a><img src="//i.moshimo.com/af/i/impression?a_id=5553499&p_id=1861&pc_id=3615&pl_id=25882" width="1" height="1" style="border:none;" alt="" loading="lazy">`,
    btnTag: `<a href="//af.moshimo.com/af/c/click?a_id=5553499&p_id=1861&pc_id=3615&pl_id=27094" rel="nofollow" referrerpolicy="no-referrer-when-downgrade" attributionsrc><img src="//image.moshimo.com/af-img/1125/000000027094.gif" width="125" height="125" style="border:none;"></a><img src="//i.moshimo.com/af/i/impression?a_id=5553499&p_id=1861&pc_id=3615&pl_id=27094" width="1" height="1" style="border:none;" loading="lazy">`,
  },
  {
    rank: 5,
    service: "ベストファクター",
    tag: "柔軟審査",
    feeLabel: "2〜20%",
    speedLabel: "最短即日",
    speedFast: true,
    amountRange: "30万〜1億円",
    contracts: "2社間",
    online: true,
    individual: true,
    reason: "年間10,580社が利用する信頼の実績。審査通過率92.25%。30万円の少額から対応。最短60分で審査完了。",
    nameTag: `<a href="//af.moshimo.com/af/c/click?a_id=5553496&p_id=3405&pc_id=8113&pl_id=48314" rel="nofollow" referrerpolicy="no-referrer-when-downgrade" attributionsrc>請求書買取ベストファクター</a><img src="//i.moshimo.com/af/i/impression?a_id=5553496&p_id=3405&pc_id=8113&pl_id=48314" width="1" height="1" style="border:none;" loading="lazy">`,
    btnTag: `<a href="//af.moshimo.com/af/c/click?a_id=5553496&p_id=3405&pc_id=8113&pl_id=48314" rel="nofollow" referrerpolicy="no-referrer-when-downgrade" attributionsrc>ベストファクター</a><img src="//i.moshimo.com/af/i/impression?a_id=5553496&p_id=3405&pc_id=8113&pl_id=48314" width="1" height="1" style="border:none;" loading="lazy">`,
  },
  {
    rank: 6,
    service: "BestPay",
    tag: "注文書対応",
    feeLabel: "5%〜",
    speedLabel: "最短翌日",
    speedFast: false,
    amountRange: "100万〜1億円",
    contracts: "2社間/注文書",
    online: false,
    individual: false,
    reason: "受注時の注文書・発注書を担保にした着手前資金化が可能。発注者の承諾不要。建設業の利用実績最多。",
    nameTag: `<a href="//af.moshimo.com/af/c/click?a_id=5553494&p_id=4185&pc_id=10616&pl_id=57087&url=https%3A%2F%2Fbest-pay.jp%3Fim%3D5u2e" rel="nofollow" referrerpolicy="no-referrer-when-downgrade" attributionsrc>注文書買取ファクタリング：BestPay</a><img src="//i.moshimo.com/af/i/impression?a_id=5553494&p_id=4185&pc_id=10616&pl_id=57087" width="1" height="1" style="border:none;" alt="" loading="lazy">`,
    btnTag: `<a href="//af.moshimo.com/af/c/click?a_id=5553494&p_id=4185&pc_id=10616&pl_id=57087" rel="nofollow" referrerpolicy="no-referrer-when-downgrade" attributionsrc>BestPay</a><img src="//i.moshimo.com/af/i/impression?a_id=5553494&p_id=4185&pc_id=10616&pl_id=57087" width="1" height="1" style="border:none;" loading="lazy">`,
  },
  {
    rank: 7,
    service: "えんナビ",
    tag: "365日対応",
    feeLabel: "5%〜",
    speedLabel: "最短1日",
    speedFast: false,
    amountRange: "30万〜5,000万円",
    contracts: "2社間",
    online: true,
    individual: true,
    reason: "24時間365日対応で審査通過率97%・顧客満足度93%の高評価。手数料5%〜で取引先に知られない秘密厳守。",
    nameTag: `<a href="https://px.a8.net/svt/ejp?a8mat=4B3OR0+GBNB22+44CA+5YRHE" rel="nofollow">ファクタリング【えんナビ】</a>
<img border="0" width="1" height="1" src="https://www11.a8.net/0.gif?a8mat=4B3OR0+GBNB22+44CA+5YRHE" alt="">`,
    btnTag: `<a href="https://px.a8.net/svt/ejp?a8mat=4B3OR0+GBNB22+44CA+61C2P" rel="nofollow">
<img border="0" width="120" height="60" alt="" src="https://www21.a8.net/svt/bgt?aid=260512524987&wid=022&eno=01&mid=s00000019225001014000&mc=1"></a>
<img border="0" width="1" height="1" src="https://www12.a8.net/0.gif?a8mat=4B3OR0+GBNB22+44CA+61C2P" alt="">`,
  },
  {
    rank: 8,
    service: "うりかけ堂",
    tag: "オンライン完結",
    feeLabel: "2%〜",
    speedLabel: "最短2時間",
    speedFast: true,
    amountRange: "30万円〜",
    contracts: "2社間/3社間",
    online: true,
    individual: true,
    reason: "クラウドで全国から完全オンライン完結。最短2時間入金。赤字・債務超過でも相談可。個人事業主利用率約50%。",
    nameTag: `<a href="https://px.a8.net/svt/ejp?a8mat=4B3OR0+G82PFE+4S8A+5YRHE" rel="nofollow">【うりかけ堂】</a>
<img border="0" width="1" height="1" src="https://www17.a8.net/0.gif?a8mat=4B3OR0+G82PFE+4S8A+5YRHE" alt="">`,
    btnTag: `<a href="https://px.a8.net/svt/ejp?a8mat=4B3OR0+G82PFE+4S8A+601S1" rel="nofollow">
<img border="0" width="120" height="60" alt="" src="https://www29.a8.net/svt/bgt?aid=260512524981&wid=022&eno=01&mid=s00000022321001008000&mc=1"></a>
<img border="0" width="1" height="1" src="https://www13.a8.net/0.gif?a8mat=4B3OR0+G82PFE+4S8A+601S1" alt="">`,
  },
];

/* 個人事業主・フリーランス向け（10〜12位） */
const SOLO_COMPANIES = [
  {
    rank: 10,
    service: "No.1 個人事業主特化",
    tag: "個人事業主専門",
    feeLabel: "1%〜",
    speedLabel: "最短即日",
    amountRange: "10万〜5,000万円",
    feature: "個人事業主・フリーランス専門のファクタリングサービス。手数料1%〜と業界最低水準。オンライン完結で最短即日入金。",
    nameTag: `<a href="https://px.a8.net/svt/ejp?a8mat=4B3OR0+FP0U2I+4EKW+BX3J6" rel="nofollow">個人事業主特化ファクタリング</a>
<img border="0" width="1" height="1" src="https://www15.a8.net/0.gif?a8mat=4B3OR0+FP0U2I+4EKW+BX3J6" alt="">`,
    btnTag: `<a href="https://px.a8.net/svt/ejp?a8mat=4B3OR0+FP0U2I+4EKW+BX3J6" rel="nofollow">個人事業主特化ファクタリング</a>
<img border="0" width="1" height="1" src="https://www15.a8.net/0.gif?a8mat=4B3OR0+FP0U2I+4EKW+BX3J6" alt="">`,
  },
  {
    rank: 11,
    service: "QuQuMo online",
    tag: "WEB完結・低手数料",
    feeLabel: "1〜14.8%",
    speedLabel: "最短2時間",
    amountRange: "制限なし",
    feature: "WEB完結で申込から入金まで最短2時間。手数料1〜14.8%。クラウドサイン（弁護士ドットコム社）による電子契約で安心。法人・個人事業主・フリーランス全対応。",
    nameTag: `<a href="https://px.a8.net/svt/ejp?a8mat=4B3OR0+G3B8L6+4JGG+BWVTE" rel="nofollow">QuQuMo online</a>
<img border="0" width="1" height="1" src="https://www12.a8.net/0.gif?a8mat=4B3OR0+G3B8L6+4JGG+BWVTE" alt="">`,
    btnTag: `<a href="https://px.a8.net/svt/ejp?a8mat=4B3OR0+G3B8L6+4JGG+BWVTE" rel="nofollow">QuQuMo online</a>
<img border="0" width="1" height="1" src="https://www12.a8.net/0.gif?a8mat=4B3OR0+G3B8L6+4JGG+BWVTE" alt="">`,
  },
  {
    rank: 12,
    service: "ペイトナー",
    tag: "スマホ完結",
    feeLabel: "一律10%",
    speedLabel: "即日（365日）",
    amountRange: "1万円〜",
    feature: "申請5分のスマホ完結・面談不要。手数料一律10%の明朗会計。365日即日入金。職種を問わず利用可。",
    nameTag: `<a href="https://px.a8.net/svt/ejp?a8mat=4B3OR0+G3WO6Y+4PF6+609HU" rel="nofollow">フリーランスの請求書を先払い 【ペイトナー】</a>
<img border="0" width="1" height="1" src="https://www11.a8.net/0.gif?a8mat=4B3OR0+G3WO6Y+4PF6+609HU" alt="">`,
    btnTag: `<a href="https://px.a8.net/svt/ejp?a8mat=4B3OR0+G3WO6Y+4PF6+5YRHE" rel="nofollow">【ペイトナー】</a>
<img border="0" width="1" height="1" src="https://www15.a8.net/0.gif?a8mat=4B3OR0+G3WO6Y+4PF6+5YRHE" alt="">`,
  },
];

function Medal({ rank }) {
  if (rank === 1) return (
    <div className="rank-medal rank-1">
      <Icons.Crown className="crown"/>
      1位
    </div>
  );
  if (rank === 2) return <div className="rank-medal rank-2">2位</div>;
  if (rank === 3) return <div className="rank-medal rank-3">3位</div>;
  return <div className="rank-medal rank-default">{rank}位</div>;
}

function Ranking() {
  const [density, setDensity] = useStateRanking("detailed");
  const compact = density === "compact";

  return (
    <section className="section ranking" id="ranking">
      <div className="container">

        {/* ===== メイン比較表（1〜7位）===== */}
        <div className="section-head">
          <div className="section-eyebrow">RANKING</div>
          <h2 className="section-title">
            <Icons.Star className="deco"/>
            ファクタリング会社 比較ランキング
            <Icons.Star className="deco"/>
          </h2>
          <p className="section-sub">資金繰り研究所が独自基準で審査した、信頼できる厳選8社</p>
        </div>

        <div className="ranking-meta">
          <span className="ranking-updated">
            <Icons.Calendar style={{width:14, height:14}}/> 更新日：2026年5月
          </span>
          <div className="density-toggle" role="tablist">
            <button className={!compact ? "active" : ""} onClick={() => setDensity("detailed")}>詳細表示</button>
            <button className={compact ? "active" : ""} onClick={() => setDensity("compact")}>コンパクト</button>
          </div>
        </div>

        <div className="table-wrap">
          <table className={`rtable ${compact ? "compact" : ""}`}>
            <thead>
              <tr>
                <th className="rank-cell">順位</th>
                <th>会社名</th>
                <th>手数料<span className="sub">（目安）</span></th>
                <th>入金<br/>スピード</th>
                <th>買取可能<br/>金額帯</th>
                <th>契約方式</th>
                <th>オンライン<br/>完結</th>
                <th>個人<br/>事業主</th>
                <th className="col-reason">おすすめポイント</th>
                <th>公式サイト</th>
              </tr>
            </thead>
            <tbody>
              {MAIN_COMPANIES.map(c => (
                <tr key={c.rank} className={c.rank === 1 ? "rank-row-1" : ""}>
                  <td><Medal rank={c.rank}/></td>
                  <td className="company-cell">
                    <span className="pr-badge">広告</span>
                    <div className="company-name-link" dangerouslySetInnerHTML={{ __html: c.nameTag }} />
                    <span className="company-tag">{c.tag}</span>
                  </td>
                  <td><span className="fee-num">{c.feeLabel}</span></td>
                  <td><span className={`speed-pill ${c.speedFast ? "" : "normal"}`}>{c.speedLabel}</span></td>
                  <td><span className="amount-range">{c.amountRange}</span></td>
                  <td style={{fontSize: 14, fontWeight: 600, color: "var(--ink-700)"}}>{c.contracts}</td>
                  <td>{c.online ? <span className="dot-yes">○</span> : <span className="dot-no">×</span>}</td>
                  <td>{c.individual ? <span className="dot-yes">○</span> : <span className="dot-no">×</span>}</td>
                  <td className="reason-cell">{c.reason}</td>
                  <td className="cta-cell">
                    <div className="btn-row-wrap" dangerouslySetInnerHTML={{ __html: c.btnTag }} />
                  </td>
                </tr>
              ))}
            </tbody>
          </table>
        </div>

        <div className="table-foot">
          <span className="legend"><span className="dot-yes">○</span>対応</span>
          <span className="legend"><span className="dot-no">×</span>非対応</span>
          <span>※手数料・入金スピード・買取可能金額は目安です。実際の条件は審査により決定されます。</span>
          <span>※本比較表はアフィリエイト広告を含みます。</span>
        </div>

        {/* ===== 個人事業主・フリーランス向け（10〜12位）===== */}
        <div className="solo-section">
          <div className="solo-head">
            <div className="section-eyebrow" style={{marginBottom: 8}}>FOR FREELANCE / 個人事業主</div>
            <h3 className="solo-title">個人事業主・フリーランス向け おすすめ3選</h3>
            <p className="section-sub">法人向けとは審査基準・手数料が異なる個人特化サービスを厳選しました</p>
          </div>
          <div className="solo-grid">
            {SOLO_COMPANIES.map(c => (
              <div key={c.rank} className="solo-card">
                <div className="solo-card-head">
                  <span className="pr-badge">広告</span>
                  <span className="solo-rank">{c.rank}位</span>
                  <span className="company-tag">{c.tag}</span>
                </div>
                <div className="solo-name" dangerouslySetInnerHTML={{ __html: c.nameTag }} />
                <div className="solo-stats">
                  <div className="solo-stat">
                    <div className="solo-stat-label">手数料</div>
                    <div className="solo-stat-val">{c.feeLabel}</div>
                  </div>
                  <div className="solo-stat">
                    <div className="solo-stat-label">入金スピード</div>
                    <div className="solo-stat-val">{c.speedLabel}</div>
                  </div>
                  <div className="solo-stat">
                    <div className="solo-stat-label">買取金額</div>
                    <div className="solo-stat-val">{c.amountRange}</div>
                  </div>
                </div>
                <p className="solo-feature">{c.feature}</p>
                <div className="solo-btn-wrap" dangerouslySetInnerHTML={{ __html: c.btnTag }} />
              </div>
            ))}
          </div>
          <p className="table-foot" style={{marginTop: 12}}>※本紹介はアフィリエイト広告を含みます。手数料・条件は審査により変動します。</p>
        </div>

      </div>
    </section>
  );
}
window.Ranking = Ranking;
