<h4>{{i18n 'discourse_subscriptions.admin.products.title'}}</h4>

<form class="form-horizontal">
  <p>
    <label for="name">{{i18n 'discourse_subscriptions.admin.products.product.name'}}</label>
    {{input type="text" name="name" value=model.product.name}}
  </p>
  <p>
    <label for="description">
      {{i18n 'discourse_subscriptions.admin.products.product.description'}}
    </label>
    {{textarea name="description" value=model.product.metadata.description class="discourse-subscriptions-admin-textarea"}}
    <div class="control-instructions">
      {{i18n 'discourse_subscriptions.admin.products.product.description_help'}}
    </div>
  </p>
  <p>
    <label for="statement_descriptor">
      {{i18n 'discourse_subscriptions.admin.products.product.statement_descriptor'}}
    </label>
    {{input type="text" name="statement_descriptor" value=model.product.statement_descriptor}}
    <div class="control-instructions">
      {{i18n 'discourse_subscriptions.admin.products.product.statement_descriptor_help'}}
    </div>
  </p>
  <p>
    <label for="active">{{i18n 'discourse_subscriptions.admin.products.product.active'}}</label>
    {{input type="checkbox" name="active" checked=model.product.active}}
    <div class="control-instructions">
      {{i18n 'discourse_subscriptions.admin.products.product.active_help'}}
    </div>
  </p>
</form>

{{#unless model.product.isNew}}
  <h4>{{i18n 'discourse_subscriptions.admin.plans.title'}}</h4>

  <p>
    <table class="table discourse-patrons-table">
      <thead>
        <th>{{i18n 'discourse_subscriptions.admin.plans.plan.nickname'}}</th>
        <th>{{i18n 'discourse_subscriptions.admin.plans.plan.interval'}}</th>
        <th>{{i18n 'discourse_subscriptions.admin.plans.plan.created_at'}}</th>
        <th>{{i18n 'discourse_subscriptions.admin.plans.plan.group'}}</th>
        <th>{{i18n 'discourse_subscriptions.admin.plans.plan.active'}}</th>
        <th class="td-right">{{i18n 'discourse_subscriptions.admin.plans.plan.amount'}}</th>
        <th class="td-right">
          {{#link-to "adminPlugins.discourse-subscriptions.products.show.plans.show" model.product.id "new" class="btn"}}
            {{i18n 'discourse_subscriptions.admin.plans.operations.add'}}
          {{/link-to}}
        </th>
      </thead>
      {{#each model.plans as |plan|}}
        <tr>
          <td>{{plan.nickname}}</td>
          <td>{{plan.interval}}</td>
          <td>{{format-unix-date plan.created}}</td>
          <td>{{plan.metadata.group_name}}</td>
          <td>{{plan.active}}</td>
          <td class="td-right">{{format-currency plan.currency plan.amountDollars}}</td>
          <td class="td-right">
            {{#link-to "adminPlugins.discourse-subscriptions.products.show.plans.show" model.product.id plan.id class="btn no-text btn-icon"}}
              {{d-icon "far-edit"}}
            {{/link-to}}
            {{d-button
              action=(route-action "destroyPlan")
              actionParam=plan
              icon="trash-alt"
              class="btn-danger btn no-text btn-icon"}}
          </td>
        </tr>
      {{/each}}

      {{#unless model.plans}}
        <tr>
          <td colspan="8">
            <hr>
            {{i18n 'discourse_subscriptions.admin.products.product.plan_help'}}
          </td>
        </tr>
      {{/unless}}
    </table>
  </p>
{{/unless}}

<div class="pull-right">
  {{d-button label="cancel" action=(action "cancelProduct") icon="times"}}
  {{#if model.product.isNew}}
    {{d-button label="discourse_subscriptions.admin.products.operations.create" action="createProduct" icon="plus" class="btn btn-primary"}}
  {{else}}
    {{d-button label="discourse_subscriptions.admin.products.operations.update" action="updateProduct" icon="check" class="btn btn-primary"}}
  {{/if}}
</div>

{{outlet}}
