% layout 'admin';
% title 'Transactions';
% content_for javascript => begin
% end
% if ( my $error = flash 'error' ) {
  <div class="alert alert-danger" role="alert">
    <strong>Error!</strong> <%= $error %>
  </div>
% } elsif ( my $success = flash 'success' ) {
  <div class="alert alert-success" role="alert">
    <strong>Success!</strong> <%= $success %>
  </div>
% }
<div class="card mb-3">
  <h3 class="card-header d-flex justify-content-between">
    Transaction Details
    <form class="form-inline" action="<%= url_for . '/delete' %>" method="post">
      <div class="form-group">
        <button class="btn btn-danger" type="submit">Delete Transaction</button>
      </div>
    </form>
  </h3>
  <div class="card-body">
    <form>
      <div class="form-group">
        <label for="buyer">Buyer</label>
        <input id="buyer" type="text" class="form-control" placeholder="Buyer ID" name="buyer" value="<%= $transaction->buyer->name %>" disabled>
      </div>
      <div class="form-group">
        <label for="seller">Seller</label>
        <input id="seller" type="text" class="form-control" placeholder="Seller ID" name="seller" value="<%= $transaction->seller->name %>" disabled>
      </div>
      <div class="form-group">
        <label for="value">Value</label>
        <input id="value" type="text" class="form-control" placeholder="Value" name="value" value="<%= sprintf '£%.2f', $transaction->value / 100000 %>" disabled>
      </div>
      <div class="form-group">
        <label for="value">Essential Purchase</label>
        <select id="lis" class="form-control" name="essential" disabled>
          <option value="0"<%= !$transaction->essential ? '' : ' selected' %>>Non Essential</option>
          <option value="1"<%= $transaction->essential ? ' selected' : '' %>>Essential</option>
        </select>
      </div>
      <div class="form-group">
        <label for="text">Category</label>
        <input id="category" type="text" class="form-control" placeholder="Uncategorised" name="category" value="<%= defined $transaction->category ? $transaction->category->category->name : 'Uncategorised' %>" disabled>
      </div>
      <div class="form-group">
        <label for="submitted_at">Submitted At</label>
        <input id="submitted_at" type="text" class="form-control" placeholder="Submitted At" name="submitted_at" value="<%= format_human_datetime $transaction->submitted_at %>" disabled>
      </div>
      <div class="form-group">
        <label for="purchase_time">Purchase Time</label>
        <input id="purchase_time" type="text" class="form-control" placeholder="Purchase Time" name="purchase_time" value="<%= format_human_datetime $transaction->purchase_time %>" disabled>
      </div>
      <div class="form-group d-flex justify-content-center">
        <img class="mw-100" src="<%= url_for . '/image' %>"/>
      </div>
    </form>
  </div>
</div>
