<form class="{{cssClass}}" autocomplete="off">

  {{!-- Sheet Header --}}
  <header class="sheet-header">
    <div class="header-fields">
      <div class="flexrow">
        <img class="profile-img" src="{{img}}" data-edit="img" title="{{name}}" />
        <div class="flexcol">
          <h1 class="charname margin-right"><input name="name" type="text" value="{{name}}" placeholder="Name" /></h1>
        </div>
      </div>
    </div>
  </header>

  {{!-- Sheet Tab Navigation --}}
  <nav class="sheet-tabs tabs" data-group="primary">
    <a class="item" data-tab="main">Main</a>
    <a class="item" data-tab="skills">Skills</a>
    <a class="item" data-tab="perks">Perks</a>
    <a class="item" data-tab="combat">Combat</a>
    <a class="item" data-tab="equipment">Equipment</a>
    <a class="item" data-tab="biodata">Biography</a>
  </nav>

  {{!-- Sheet Body --}}
  <section class="sheet-body">

    {{!-- Skills Tab --}}
    <div class="tab main" data-group="primary" data-tab="main">

      <div class="flexrow">
        <ul class="stat-list alternate-list item-list">
          {{#each system.attributes as |attr key|}}
          <li class="item stat flexrow list-item list-item-shadow">
            <label class="item-field-label-medium">{{attr.label}}</label>
            <input type="text" class="item-field-label-short padd-right" name="system.attributes.{{key}}.value" value="{{attr.value}}" data-dtype="Number"/>
          {{/each}}
          </li>
        </ul>

        <ul class="stat-list alternate-list item-list">
          {{#each system.derivated as |deriv key|}}
          <li class="item stat flexrow list-item list-item-shadow">
            <label class="item-field-label-medium">{{deriv.label}}</label>
            <label class="item-field-label-short">{{deriv.value}}</label>
            <input type="text" class="item-field-label-short padd-right" name="system.derivated.{{key}}.bonus" value="{{deriv.bonus}}" data-dtype="Number"/>
          {{/each}}
          </li>
        </ul>

        <ul class="stat-list alternate-list item-list">
          {{#each system.secondary as |second key|}}
          <li class="item stat flexrow list-item list-item-shadow">
            <label class="item-field-label-medium">{{second.label}}</label>
            <input type="text" class="item-field-label-short padd-right" name="system.secondary.{{key}}.value" value="{{second.value}}" data-dtype="Number"/>
            {{#if second.maxeditable}}
              <label class="item-field-label-short">&nbsp;/&nbsp;</label>
              <input type="text" class="item-field-label-short padd-right" name="system.secondary.{{key}}.max" value="{{second.max}}" data-dtype="Number"/>
            {{else}}
              <label class="item-field-label-short">&nbsp;/&nbsp;{{second.max}}</label>
            {{/if}}
            <input type="text" class="item-field-label-short padd-right" name="system.secondary.{{key}}.bonus" value="{{second.bonus}}" data-dtype="Number"/>
          {{/each}}
          </li>
          <li class="item stat flexrow list-item list-item-shadow">
            <label class="item-field-label-medium">Rerolls : </label>
            <input type="text" class="item-field-label-short padd-right" name="system.various.rerolls.value" value="{{system.various.rerolls.value}}" data-dtype="Number"/>
          </li>
        </ul>

      </div>
    </div>
    
    {{!-- Skills Tab --}}
    <div class="tab skills" data-group="primary" data-tab="skills">

      <ul class="alternate-list item-list">
        <li class="item flexrow list-item items-title-bg">
          <span class="item-name-label-header-long2">
            <h3><label class="items-title-text">Skills</label></h3>
          </span>
          <span class="item-field-label-medium">
            <label class="short-label">Base</label>
          </span>
          <span class="item-field-label-long">
            <label class="short-label">Derivated</label>
          </span>
          <span class="item-field-label-medium">
            <label class="short-label">Bonus</label>
          </span>
          <span class="item-field-label-medium">
            <label class="short-label">Total</label>
          </span>
          <span class="item-field-label-medium">
            <label class="short-label">Used?</label>
          </span>
          <span class="item-field-label-medium">
            <label class="short-label">&nbsp;</label>
          </span>
        </li>
        {{#each skills as |skill key|}}
        <li class="item flexrow list-item list-item-shadow" data-item-id="{{skill._id}}">
          <a class="item-edit item-name-img" title="Edit Item"><img class="sheet-competence-img" src="{{skill.img}}" />
          </a>
          <span class="item-field-label-vlong2"><a class="roll-skill">{{skill.name}}</a></span>
          <span class="item-field-label-medium">{{skill.system.value}}</span>
          <span class="item-field-label-long">{{skill.derivated.label}} ({{skill.derivated.value}})</span>
          <span class="item-field-label-medium">{{skill.system.bonus}}</span>
          <span class="item-field-label-medium">{{skill.total}}%</span>
          <label class="attribute-value checkbox"><input type="checkbox" class="skill-used-id"  {{checked skill.system.used}}/></label>
          <div class="item-controls item-controls-fixed">
            <a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
          </div>
        </li>
        {{/each}}
      </ul>

    </div>

    {{!-- Perks Tab --}}
    <div class="tab perks" data-group="primary" data-tab="perks">

      <ul class="alternate-list item-list">
        <li class="item flexrow list-item items-title-bg">
          <span class="item-name-label-header-long2">
            <h3><label class="items-title-text">Perks</label></h3>
          </span>
          <span class="item-field-label-medium">
            <label class="short-label">&nbsp;</label>
          </span>
        </li>
        {{#each perks as |perk key|}}
        <li class="item flexrow list-item list-item-shadow" data-item-id="{{perk._id}}">
          <a class="item-edit item-name-img" title="Edit Item"><img class="sheet-competence-img" src="{{perk.img}}" />
          </a>
          <span class="item-field-label-vlong2">{{perk.name}}</span>
          <div class="item-controls item-controls-fixed">
            <a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
          </div>
        </li>
        {{/each}}
      </ul>

    </div>

    {{!-- Combat Tab --}}
    <div class="tab combat" data-group="primary" data-tab="combat">
      <div class="flexcol">

        <div>
          <ul class="stat-list alternate-list">
            <li class="item flexrow list-item items-title-bg">
              <span class="item-name-label-header-long">
                <h3><label class="items-title-text">Weapons</label></h3>
              </span>
              <span class="item-field-label-short">
                <label class="short-label">Type</label>
              </span>
              <span class="item-field-label-long">
                <label class="short-label">Skill</label>
              </span>
              <span class="item-field-label-medium">
                <label class="short-label">Damage</label>
              </span>
            </li>
            {{#each equippedWeapons as |weapon key|}}
            <li class="item flexrow list-item list-item-shadow" data-item-id="{{weapon._id}}">
              <a class="item-edit item-name-img" title="Edit Item"><img class="sheet-competence-img"
                  src="{{weapon.img}}" /></a>
              <span class="item-name-label-long"><a class ="roll-weapon">{{weapon.name}}</a></span>

              <span class="item-field-label-short">{{upperFirst weapon.system.weapontype}}</span>

              <span class="item-field-label-long">{{weapon.system.skill}}</span>

              <span class="item-field-label-long">{{weapon.system.damage}}</span>



              <div class="item-filler">&nbsp;</div>
              <div class="item-controls item-controls-fixed">
                <a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
              </div>
            </li>
            {{/each}}
          </ul>
        </div>

      </div>
    </div>


    {{!-- Lore Tab --}}
    <div class="tab lore" data-group="primary" data-tab="lore">

      <div class="flexcol">

        <ul class="stat-list alternate-list">
          <li class="item flexrow list-item items-title-bg">
            <span class="item-name-label-header">
              <h3><label class="items-title-text">Lore</label></h3>
            </span>
            <span class="item-field-label-medium">
              <label class="short-label">Lore</label>
            </span>
            <span class="item-field-label-short">
              <label class="short-label">Circle</label>
            </span>
            <span class="item-field-label-medium">
              <label class="short-label">Range</label>
            </span>
          </li>

          {{#each spells as |spell key|}}
          <li class="item stat flexrow list-item list-item-shadow" data-item-id="{{spell._id}}">
            <a class="item-edit item-name-img" title="Edit Item"><img class="sheet-competence-img"
                src="{{spell.img}}" /></a>
            <span class="item-name-label">
              <a class="power-roll">{{spell.name}}</a>
            </span>
            <span class="item-field-label-medium">{{spell.system.lore}}</span>
            <span class="item-field-label-short">{{spell.system.circle}}</span>
            <span class="item-field-label-medium">{{spell.system.range}}</span>
            <div class="item-filler">&nbsp;</div>
            <div class="item-controls item-controls-fixed">
              <a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
            </div>  
          </li>
          {{/each}}

        </ul>

      </div>
    </div>

    {{!-- Equipement Tab --}}
    <div class="tab equipment" data-group="primary" data-tab="equipment">

      <div class="flexrow">
        <h3>Encumbrance</h3>
        <span class="small-label">Current : {{encCurrent}}</span>
        <span class="small-label">Capacity : {{encCapacity}}</span>
      </div>

      <ul class="item-list alternate-list">
        <li class="item flexrow list-item items-title-bg">
          <span class="item-name-label-header">
            <h3><label class="items-title-text">Money</label></h3>
          </span>
          <span class="item-field-label-long">
            <label class="short-label">Qty</label>
          </span>
          <span class="item-field-label-medium">
            <label class="short-label">Weight</label>
          </span>
          <span class="item-field-label-medium">
            <label class="short-label">IDR</label>
          </span>
          <div class="item-filler">&nbsp;</div>
          <div class="item-controls item-controls-fixed">
            <a class="item-control item-add" data-type="money" title="Create Item"><i class="fas fa-plus"></i></a>
          </div>
        </li>
        {{#each moneys as |money key|}}
        <li class="item flexrow list-item list-item-shadow" data-item-id="{{money._id}}">
          <a class="item-edit item-name-img" title="Edit Item"><img class="sheet-competence-img"
              src="{{money.img}}" /></a>
          <span class="item-name-label">{{money.name}}</span>

          <span class="item-field-label-long"><label>
              {{money.system.quantity}}
              (<a class="quantity-minus plus-minus-button"> -</a>/<a class="quantity-plus plus-minus-button">+</a>)
            </label>
          </span>
          <span class="item-field-label-medium">
            <label>{{money.system.weight}}</label>
          </span>
          <span class="item-field-label-medium">
            {{#if money.system.idrDice}}
            <a class="roll-idr" data-dice-value="{{money.data.idrDice}}">{{money.system.idrDice}}</a>
            {{else}}
            &nbsp;-&nbsp;
            {{/if}}
          </span>

          <div class="item-filler">&nbsp;</div>
          <div class="item-controls item-controls-fixed">
            <a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
          </div>
        </li>
        {{/each}}
      </ul>

      <ul class="item-list alternate-list">
        <li class="item flexrow list-item items-title-bg">
          <span class="item-name-label-header">
            <h3><label class="items-title-text">Weapons</label></h3>
          </span>
          <span class="item-field-label-short">
            <label class="short-label">Attack</label>
          </span>
          <span class="item-field-label-short">
            <label class="short-label">Damage</label>
          </span>
          <div class="item-controls item-controls-fixed">
            <a class="item-control item-add" data-type="weapon" title="Create Item"><i class="fas fa-plus"></i></a>
          </div>
        </li>
        {{#each weapons as |weapon key|}}
        <li class="item flexrow list-item list-item-shadow" data-item-id="{{weapon._id}}">
          <a class="item-edit item-name-img" title="Edit Item"><img class="sheet-competence-img"
              src="{{weapon.img}}" /></a>
          <span class="item-name-label">{{weapon.name}}</span>
          <span class="item-field-label-short"><label>{{weapon.system.ability}}</label></span>
          <span class="item-field-label-short"><label>{{weapon.system.damage}}</label></span>

          <div class="item-filler">&nbsp;</div>
          <div class="item-controls item-controls-fixed">
            <a class="item-control item-equip" title="Worn">{{#if weapon.system.equipped}}<i
                class="fas fa-circle"></i>{{else}}<i class="fas fa-genderless"></i>{{/if}}</a>
            <a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
          </div>
        </li>
        {{/each}}
      </ul>

      <ul class="item-list alternate-list">
        <li class="item flexrow list-item items-title-bg">
          <span class="item-name-label-header">
            <h3><label class="items-title-text">Armors</label></h3>
          </span>
          <span class="item-field-label-short">
            <label class="short-label">Type</label>
          </span>
          <span class="item-field-label-short">
            <label class="short-label">Absorption</label>
          </span>

          <div class="item-filler">&nbsp;</div>
          <div class="item-controls item-controls-fixed">
            <a class="item-control item-add" data-type="armor" title="Create Item"><i class="fas fa-plus"></i></a>
          </div>
        </li>
        {{#each armors as |armor key|}}
        <li class="item list-item flexrow list-item-shadow" data-item-id="{{armor._id}}">
          <a class="item-edit item-name-img" title="Edit Item"><img class="sheet-competence-img"
              src="{{armor.img}}" /></a>
          <span class="item-name-label">{{armor.name}}</span>
          <span class="item-field-label-short">{{upper armor.system.armortype}}</span>
          <span class="item-field-label-short">{{armor.system.absorprionroll}}</span>

          <div class="item-filler">&nbsp;</div>
          <div class="item-controls item-controls-fixed">
            <a class="item-control item-equip" title="Worn">{{#if armor.system.equipped}}<i
                class="fas fa-circle"></i>{{else}}<i class="fas fa-genderless"></i>{{/if}}</a>
            <a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
          </div>
        </li>
        {{/each}}
      </ul>

      <ul class="item-list alternate-list">
        <li class="item flexrow list-item items-title-bg">
          <span class="item-name-label-header">
            <h3><label class="items-title-text">Shields</label></h3>
          </span>
          <span class="item-field-label-short">
            <label class="short-label">Dice</label>
          </span>
          <div class="item-filler">&nbsp;</div>
          <div class="item-controls item-controls-fixed">
            <a class="item-control item-add" data-type="shield" title="Create Item"><i class="fas fa-plus"></i></a>
          </div>
        </li>
        {{#each shields as |shield key|}}
        <li class="item flexrow list-item list-item-shadow" data-item-id="{{shield._id}}">
          <a class="item-edit item-name-img" title="Edit Item"><img class="sheet-competence-img"
              src="{{shield.img}}" /></a>
          <span class="item-name-label">{{shield.name}}</span>
          <span class="item-field-label-short">{{shield.system.levelDice}}</span>

          <div class="item-filler">&nbsp;</div>
          <div class="item-controls item-controls-fixed">
            <a class="item-control item-equip" title="Worn">{{#if shield.system.equipped}}<i
                class="fas fa-circle"></i>{{else}}<i class="fas fa-genderless"></i>{{/if}}</a>
            <a class="item-control item-delete" title="Delete Item"><i class="fas fa-trash"></i></a>
          </div>
        </li>
        {{/each}}
      </ul>

      <ul class="item-list alternate-list">
        <li class="item flexrow list-item items-title-bg">
          <span class="item-name-label-header">
            <h3><label class="items-title-text">Equipment</label></h3>
          </span>
          <span class="item-field-label-long">
            <label class="short-label">Quantity</label>
          </span>
          <div class="item-filler">&nbsp;</div>
          <div class="item-controls item-controls-fixed">
            <a class="item-control item-add" data-type="equipment" title="Create Item"><i class="fas fa-plus"></i></a>
          </div>

        </li>
        {{#each containersTree as |equip key|}}
        {{> systems/fvtt-crucible-rpg/templates/partial-actor-equipment.html equip=equip level=1}}
        <ul class="item-list list-item-shadow2 list-item-margin1">
          {{#each equip.data.contents as |subgear key|}}
          {{> systems/fvtt-crucible-rpg/templates/partial-actor-equipment.html equip=subgear level=2}}
          {{/each}}
        </ul>
        {{/each}}
      </ul>

      <hr>

    </div>

    {{!-- Biography Tab --}}
    <div class="tab biodata" data-group="primary" data-tab="biodata">
      <div class="grid grid-2col">
        <div>
          <ul class="item-list alternate-list">
            <li class="item flexrow">
              <label class="generic-label">Origin</label>
              <input type="text" class="" name="system.biodata.origin" value="{{data.biodata.origin}}"
                data-dtype="String" />
            </li>
            <li class="item flexrow">
              <label class="generic-label">Age</label>
              <input type="text" class="" name="system.biodata.age" value="{{data.biodata.age}}" data-dtype="String" />
            </li>
            <li class="item flexrow">
              <label class="generic-label">Height</label>
              <input type="text" class="" name="system.biodata.height" value="{{data.biodata.height}}" data-dtype="String" />
            </li>
            <li class="item flexrow">
              <label class="generic-label">Eyes</label>
              <input type="text" class="" name="system.biodata.eyes" value="{{data.biodata.eyes}}" data-dtype="String" />
            </li>
            <li class="item flexrow">
              <label class="generic-label">Hair</label>
              <input type="text" class="" name="system.biodata.hair" value="{{data.biodata.hair}}" data-dtype="String" />
            </li>
          </ul>
        </div>
       <div>
          <ul>
            <li class="flexrow item">
              <label class="generic-label">Size</label>
              <select class="competence-base flexrow" type="text" name="system.biodata.size" value="{{data.biodata.size}}" data-dtype="Number">
                {{#select data.biodata.size}}
                <option value="1">Tiny</option>
                <option value="2">Small</option>
                <option value="3">Medium</option>
                <option value="4">Large</option>
                <option value="5">Huge</option>
                <option value="6">Gargantuan</option>
                {{/select}}
              </select> 
            </li>
            <li class="flexrow item">
              <label class="generic-label">Sex</label>
              <input type="text" class="" name="system.biodata.sex" value="{{data.biodata.sex}}" data-dtype="String" />
            </li>
            <li class="flexrow item">
              <label class="generic-label">Preferred Hand</label>
              <input type="text" class="" name="system.biodata.preferredhand" value="{{data.biodata.preferredhand}}"
                data-dtype="String" />
            </li>
            <li class="flexrow item" data-item-id="{{race._id}}">
              <label class="generic-label">Race</label>
              <a class="item-edit"><img class="stat-icon" src="{{race.img}}"></a>
              <input type="text" class="" name="system.biodata.racename" value="{{data.biodata.racename}}" data-dtype="String" />
            </li>
          </ul>
        </div>
      </div>


      <hr>
      <h3>Background : </h3>
      <div class="form-group editor">
        {{editor description target="system.biodata.description" button=true owner=owner
        editable=editable}}
      </div>
      <hr>
      <h3>Notes : </h3>
      <div class="form-group editor">
        {{editor notes target="system.biodata.notes" button=true owner=owner editable=editable}}
      </div>
      <hr>
      </article>
    </div>

  </section>
</form>