{{!--
  ApplicationV2 template for Consequences Dialog for attack rolls from hidden/undetected tokens
  Matches the visibility manager's design and styling with red theme
--}}

<div class="consequences-preview-content">
  {{!-- Attacking Token Information Panel --}}
  <div class="attacker-info">
    <div class="attacker-image">
      <img src="{{attackingToken.image}}" data-tooltip="{{attackingToken.name}}" />
    </div>
    <div class="attacker-details">
      <h3 class="attacker-name">{{attackingToken.name}}</h3>
      <p class="hint">
        {{#if attackData.isAttackRoll}}
          {{localize "PF2E_VISIONER.UI.ATTACK_CONSEQUENCES"}}
        {{else}}
          {{localize "PF2E_VISIONER.UI.ATTACK_CONSEQUENCES"}}
        {{/if}}
      </p>
    </div>
  </div>

  {{!-- Encounter Filter + Ignore Allies --}}
  <div class="encounter-filter-section">
    {{#if showEncounterFilter}}
  <label class="encounter-filter-checkbox">
      <input type="checkbox" {{#if encounterOnly}}checked{{/if}} data-action="toggleEncounterFilter" data-tooltip="{{localize 'PF2E_VISIONER.UI.ENCOUNTER_FILTER_TOOLTIP'}}" />
      <span class="encounter-filter-label">{{localize "PF2E_VISIONER.UI.ENCOUNTER_FILTER_TEXT"}}</span>
    </label>
    {{/if}}
  <label class="hide-foundry-hidden-filter-checkbox">
      <input type="checkbox" {{#if hideFoundryHidden}}checked{{/if}} data-action="toggleHideFoundryHidden" data-tooltip="{{localize 'PF2E_VISIONER.UI.HIDE_FOUNDRY_HIDDEN_TOOLTIP'}}" />
      <span class="encounter-filter-label">{{localize "PF2E_VISIONER.UI.HIDE_FOUNDRY_HIDDEN"}}</span>
    </label>
  <label class="ignore-allies-filter-checkbox">
      <input type="checkbox" {{#if ignoreAllies}}checked{{/if}} data-action="toggleIgnoreAllies" data-tooltip="{{localize 'PF2E_VISIONER.UI.IGNORE_ALLIES_TOOLTIP'}}" />
      <span class="encounter-filter-label">{{localize "PF2E_VISIONER.UI.IGNORE_ALLIES"}}</span>
    </label>
  <label class="filter-by-detection-checkbox">
      <input type="checkbox" {{#if filterByDetection}}checked{{/if}} data-action="toggleFilterByDetection" data-tooltip="{{localize 'PF2E_VISIONER.UI.FILTER_BY_DETECTION_TOOLTIP'}}" />
      <span class="encounter-filter-label">{{localize "PF2E_VISIONER.UI.FILTER_BY_DETECTION_LABEL"}}</span>
    </label>
  </div>

  {{!-- Results Table --}}
  {{#if bulkOverrideStates}}
  <div class="bulk-action-group">
    {{> "pf2e-visioner.bulk-override"}}
  </div>
  {{/if}}
  <div class="results-table-container">
    <table class="visibility-table consequences-results-table">
      <thead>
        <tr>
          <th class="token-image">{{localize "PF2E_VISIONER.UI.TOKEN"}}</th>
          <th class="token-name">{{localize "PF2E_VISIONER.UI.NAME"}}</th>
          <th class="visibility-change">{{localize "PF2E_VISIONER.UI.VISIBILITY_CHANGE"}}</th>
          <th class="actions">{{localize "PF2E_VISIONER.UI.ACTIONS"}}</th>
        </tr>
      </thead>
      <tbody>
        {{#each outcomes as |outcome|}}
          <tr class="token-row" data-token-id="{{outcome.target.id}}">
            <td class="token-image">
              <span class="token-img-wrapper">
                <img src="{{outcome.tokenImage}}" data-tooltip="{{outcome.target.name}}" width="28" height="28" />
                {{#if outcome.target.document.hidden}}
                  <span class="foundry-hidden-indicator" data-tooltip="{{localize 'PF2E_VISIONER.UI.FOUNDRY_HIDDEN'}}"><i class="fas fa-eye-slash"></i></span>
                {{/if}}
              </span>
            </td>
            <td class="token-name">
              <strong data-tooltip="{{outcome.target.name}}">{{outcome.target.name}}</strong>
            </td>
            <td class="visibility-change">
              <div class="visibility-change-with-override">
                <span class="old-visibility-state {{#if outcome.isOldStateAvsControlled}}avs-controlled{{/if}}">
                  {{{visibilityIcon outcome.currentVisibility}}}
                  {{#if outcome.isOldStateAvsControlled}}
                    </span>
                  {{#if outcome.isOldStateAvsControlled}}
                    <span class="avs-tag-small" data-tooltip="{{localize 'PF2E_VISIONER.UI.AVS_CONTROLLED'}}">
                      <i class="fas fa-bolt-auto"></i>
                    </span>
                  {{/if}}
                  {{/if}}
                </span>
                <i class="fas fa-arrow-right visibility-arrow"></i>
                <div class="override-icons" data-token-id="{{outcome.target.id}}">
                  {{#each outcome.availableStates as |state|}}
                    <button type="button" class="state-icon {{#if state.selected}}selected{{/if}} {{#if state.calculatedOutcome}}calculated-outcome{{/if}}" 
                            data-action="overrideState"
                            data-token-id="{{../outcome.target.id}}"
                            data-state="{{state.value}}"
                            data-tooltip="{{state.label}}">
                      {{{visibilityIcon state.value}}}
                    </button>
                  {{/each}}
                  <input type="hidden" name="override.{{outcome.target.id}}" value="{{outcome.overrideState}}" />
                </div>
              </div>
            </td>
            <td class="actions">
              {{#if outcome.hasActionableChange}}
                <button type="button" class="row-timer-toggle" data-token-id="{{outcome.target.id}}" data-tooltip="{{localize 'PF2E_VISIONER.TIMED_OVERRIDE.SET_DURATION_FOR_ROW'}}">
                  <i class="fas fa-clock"></i>
                </button>
                <button type="button" class="row-action-btn apply-change" data-action="applyChange" data-token-id="{{outcome.target.id}}" data-tooltip="{{localize 'PF2E_VISIONER.UI.APPLY_VISIBILITY_CHANGE'}}">
                  <i class="fas fa-check"></i>
                </button>
                <button type="button" class="row-action-btn revert-change" data-action="revertChange" data-token-id="{{outcome.target.id}}" data-tooltip="{{localize 'PF2E_VISIONER.UI.REVERT_TO_ORIGINAL'}}">
                  <i class="fas fa-undo"></i>
                </button>
              {{else}}
                <span class="no-action">{{localize "PF2E_VISIONER.UI.NO_CHANGE_LABEL"}}</span>
              {{/if}}
            </td>
          </tr>
        {{/each}}
      </tbody>
    </table>
  </div>

  {{!-- Bulk Actions --}}
  <div class="consequences-preview-dialog-bulk-actions-header">
    <div class="consequences-preview-dialog-bulk-actions-info">
      <span class="consequences-preview-dialog-changes-count">{{changesCount}}</span> of <span class="consequences-preview-dialog-total-count">{{totalCount}}</span> targets will have visibility changes.
    </div>
    <div class="consequences-preview-dialog-bulk-actions-buttons">
      <button type="button" class="bulk-action-btn apply-all" data-action="applyAll" data-tooltip="{{localize 'PF2E_VISIONER.UI.APPLY_ALL'}}">
        <i class="fas fa-check-circle"></i> {{localize 'PF2E_VISIONER.UI.APPLY_ALL'}}
      </button>
      <button type="button" class="bulk-action-btn revert-all" data-action="revertAll" data-tooltip="{{localize 'PF2E_VISIONER.UI.REVERT_ALL'}}" disabled>
        <i class="fas fa-undo"></i> {{localize 'PF2E_VISIONER.UI.REVERT_ALL'}}
      </button>
    </div>
  </div>
</div>
