{{!log "chat-message" this}}
{{!log "rollTarget" rollTarget}}
{{!log "rollData" rollData}}
<div class="{{cssClass}} prismrpg-chat-card">
  <div class="chat-header">
    <div class="chat-portrait">
      <img src="{{actingCharImg}}" data-tooltip="{{actingCharName}}" />
    </div>
    <div class="chat-title">
      <div class="actor-name">{{actingCharName}}</div>
      <div class="roll-name">{{upperFirst rollName}}</div>
      {{#if (match rollType "attack")}}
        <div class="roll-type-badge attack">Attack Roll</div>
      {{/if}}
      {{#if badResult}}
        <div class="bad-result">{{localize "PRISMRPG.Label.otherResult"}}: {{badResult}}</div>
      {{/if}}
    </div>
  </div>

  <div class="chat-content">
    {{#if rollTarget.weapon}}
      <div class="weapon-info-card">
        <div class="weapon-header">
          <strong class="weapon-name">{{rollTarget.weapon.name}}</strong>
          {{#if rollTarget.weapon.system.isImplement}}
            <span class="badge implement">Implement</span>
          {{/if}}
          {{#if rollData.attackAttribute}}
            <span class="attribute-used">
              ({{#if (eq rollData.attackAttribute "str")}}Strength{{else}}Dexterity{{/if}})
            </span>
          {{/if}}
        </div>

        <div class="weapon-stats">
          {{#if rollTarget.weapon.system.weaponGroup}}
            <div class="stat-item">
              <i class="fas fa-shield-halved"></i>
              <span>{{rollTarget.weapon.system.weaponGroup}}</span>
            </div>
          {{/if}}
          {{#if rollTarget.weapon.system.apc}}
            <div class="stat-item apc">
              <i class="fas fa-bolt"></i>
              <span>{{rollTarget.weapon.system.apc}} APC</span>
            </div>
          {{/if}}
          {{#if rollTarget.weapon.system.damage}}
            <div class="stat-item damage">
              <i class="fas fa-dice-d20"></i>
              <span>{{rollTarget.weapon.system.damage}}</span>
            </div>
          {{/if}}
          {{#if rollTarget.weapon.system.damageType}}
            <div class="stat-item">
              <i class="fas fa-burst"></i>
              <span>
                {{#if rollTarget.weapon.system.damageType.piercing}}P{{/if}}{{#if rollTarget.weapon.system.damageType.bludgeoning}}{{#if rollTarget.weapon.system.damageType.piercing}}/{{/if}}B{{/if}}{{#if rollTarget.weapon.system.damageType.slashing}}{{#if (or rollTarget.weapon.system.damageType.piercing rollTarget.weapon.system.damageType.bludgeoning)}}/{{/if}}S{{/if}}
              </span>
            </div>
          {{/if}}
          {{#if (or (gt rollTarget.weapon.system.shortRange 0) (gt rollTarget.weapon.system.longRange 0))}}
            <div class="stat-item range">
              <i class="fas fa-bow-arrow"></i>
              <span>
                {{#if (gt rollTarget.weapon.system.shortRange 0)}}{{rollTarget.weapon.system.shortRange}}{{/if}}{{#if (and (gt rollTarget.weapon.system.shortRange 0) (gt rollTarget.weapon.system.longRange 0))}}/{{/if}}{{#if (gt rollTarget.weapon.system.longRange 0)}}{{rollTarget.weapon.system.longRange}}{{/if}}ft
              </span>
            </div>
          {{/if}}
          {{#if (gt rollTarget.weapon.system.reloadAPC 0)}}
            <div class="stat-item reload">
              <i class="fas fa-rotate"></i>
              <span>Reload {{rollTarget.weapon.system.reloadAPC}}</span>
            </div>
          {{/if}}
        </div>
      </div>
    {{/if}}

    {{#if (eq rollType "spell-cast")}}
      <div class="spell-info-card">
        <div class="spell-header">
          <strong class="spell-name">Spell Cast</strong>
          {{#if (gt rollData.upcastLevel 0)}}
            <span class="badge upcast">+{{rollData.upcastLevel}} Levels</span>
          {{/if}}
        </div>
        <div class="spell-stats">
          {{#if rollData.mentalCharacteristic}}
            <div class="stat-item characteristic">
              <i class="fas fa-brain"></i>
              <span>{{rollData.mentalCharacteristic}} ({{rollData.mentalCharValue}})</span>
            </div>
          {{/if}}
          <div class="stat-item mana">
            <i class="fas fa-flask"></i>
            <span>{{rollData.totalManaCost}} Mana</span>
          </div>
          <div class="stat-item apc">
            <i class="fas fa-bolt"></i>
            <span>{{rollData.totalAPC}} APC</span>
          </div>
          {{#if (gt rollData.manaUpkeep 0)}}
            <div class="stat-item upkeep">
              <i class="fas fa-repeat"></i>
              <span>{{rollData.manaUpkeep}}/round</span>
            </div>
          {{/if}}
        </div>
      </div>
    {{/if}}

    {{#if (eq rollType "skill")}}
      {{#if rollData.skillSubAttributeLabel}}
        <div class="skill-info-card">
          <div class="skill-header">
            <strong class="skill-name">Skill Check</strong>
          </div>
          <div class="skill-stats">
            <div class="stat-item subattribute">
              <i class="fas fa-diagram-project"></i>
              <span>{{rollData.skillSubAttributeLabel}} (+{{rollData.skillSubAttributeValue}})</span>
            </div>
          </div>
        </div>
      {{/if}}
    {{/if}}

    {{#if rollData.letItFly}}
      <div class="special-badge">Let It Fly!</div>
    {{/if}}
    {{#if rollData.pointBlank}}
      <div class="special-badge">Point Blank</div>
    {{/if}}
    {{#if rollData.beyondSkill}}
      <div class="special-badge">Beyond Skill Range</div>
    {{/if}}
    {{#if (and rollData.attackerAim (ne rollData.attackerAim "0"))}}
      <div class="aiming-info">
        <i class="fas fa-crosshairs"></i> Aiming: {{rollData.attackerAim}}
      </div>
    {{/if}}

    <div class="formula-display">
      <i class="fas fa-calculator"></i> {{titleFormula}}
    </div>

    {{#if (eq rollType "save")}}
      {{#if rollTarget.abilityModifier}}
        <div class="modifier-info">
          <span>Ability Mod: {{#if (gt rollTarget.abilityModifier 0)}}+{{/if}}{{rollTarget.abilityModifier}}</span>
          <span>Save Bonus: {{#if (gt rollTarget.saveProficiency 0)}}+{{/if}}{{rollTarget.saveProficiency}}</span>
        </div>
      {{/if}}
    {{/if}}

    {{#each diceResults as |result|}}
      <div class="dice-breakdown">
        <i class="fas fa-dice"></i> {{result.dice}}: {{result.value}}
      </div>
    {{/each}}

    {{#if (eq rollType "weapon-attack")}}
      <button class="roll-damage-button" type="button" data-actor-id="{{actorId}}" data-weapon-id="{{rollTarget.weapon._id}}">
        <i class="fa-regular fa-face-head-bandage"></i>
        Roll Damage
      </button>
    {{/if}}
  </div>

  {{#unless isPrivate}}
    <div class="roll-result">
      <div class="result-total">
        <span class="total-label">Result</span>
        <span class="total-value">{{total}}</span>
      </div>
      {{#if D30result}}
        <div class="d30-result">
          <i class="fas fa-dice-d20"></i> D30: {{D30result}}
        </div>
      {{/if}}
    </div>
  {{/unless}}

  {{#if isSave}}
    <div class="result-badge {{resultType}}">
      {{#if isPrivate}}
        ?
      {{else}}
        {{#if (eq resultType "success")}}
          <i class="fas fa-check-circle"></i> {{localize "PRISMRPG.Roll.success"}}
        {{else}}
          <i class="fas fa-times-circle"></i> {{localize "PRISMRPG.Roll.failure"}}
        {{/if}}
      {{/if}}
    </div>
  {{/if}}

  {{#if isResource}}
    <div class="result-badge {{resultType}}">
      {{#if isPrivate}}
        ?
      {{else}}
        {{#if (eq resultType "success")}}
          <i class="fas fa-check-circle"></i> {{localize "PRISMRPG.Roll.success"}}
        {{else}}
          <i class="fas fa-times-circle"></i> {{localize "PRISMRPG.Roll.failure"}}{{#if isFailure}} ({{localize "PRISMRPG.Roll.resourceLost"}}){{/if}}
        {{/if}}
      {{/if}}
    </div>
  {{/if}}

  {{#if isDamage}}
    {{#if (and isGM hasTarget)}}
      <div class="damage-info">
        {{{localize "PRISMRPG.Roll.displayArmor" targetName=targetName targetArmor=targetArmor realDamage=realDamage}}}
      </div>
    {{/if}}
  {{/if}}
</div>