{{ header }}{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="float-end">
        <button type="submit" form="form-affiliate" formaction="{{ save }}" title="{{ button_save }}" class="btn btn-primary"><i class="fa-solid fa-floppy-disk"></i></button>
        <a href="{{ back }}" title="{{ button_back }}" class="btn btn-light"><i class="fa-solid fa-reply"></i></a>
      </div>
      <h1>{{ heading_title }}</h1>
      <ol class="breadcrumb">
        {% for breadcrumb in breadcrumbs %}
          <li class="breadcrumb-item"><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
        {% endfor %}
      </ol>
    </div>
  </div>
  <div class="container-fluid">
    <div class="card">
      <div class="card-header"><i class="fa-solid fa-pencil"></i> {{ text_form }}</div>
      <div class="card-body">
        <form id="form-affiliate" action="{{ save }}" method="post" data-oc-toggle="ajax">
          <ul class="nav nav-tabs">
            <li class="nav-item"><a href="#tab-general" data-bs-toggle="tab" class="nav-link active">{{ tab_general }}</a></li>
            <li class="nav-item"><a href="#tab-history" data-bs-toggle="tab" class="nav-link">{{ tab_history }}</a></li>
            <li class="nav-item"><a href="#tab-transaction" data-bs-toggle="tab" class="nav-link">{{ tab_transaction }}</a></li>
            <li class="nav-item"><a href="#tab-report" data-bs-toggle="tab" class="nav-link">{{ tab_report }}</a></li>
          </ul>
          <div class="tab-content">
            <div id="tab-general" class="tab-pane active">
              <fieldset>
                <legend>{{ text_affiliate }}</legend>
                <div class="row mb-3">
                  <label for="input-customer" class="col-sm-2 col-form-label">{{ entry_customer }}</label>
                  <div class="col-sm-10">
                    <input type="text" name="customer" value="{{ customer }}" placeholder="{{ entry_customer }}" id="input-customer" data-oc-target="autocomplete-customer" class="form-control"{% if customer_id %} disabled{% endif %} required autocomplete="off"/>
                    <ul id="autocomplete-customer" class="dropdown-menu"></ul>
                    <div id="error-customer" class="invalid-feedback"></div>
                    <input type="hidden" name="customer_group_id" value="{{ customer_group_id }}" id="input-customer-group"/> <input type="hidden" name="customer_id" value="{{ customer_id }}" id="input-customer-id"/>
                  </div>
                </div>

                <div class="row mb-3">
                  <label for="input-company" class="col-sm-2 col-form-label">{{ entry_company }}</label>
                  <div class="col-sm-10">
                    <input type="text" name="company" value="{{ company }}" placeholder="{{ entry_company }}" id="input-company" class="form-control"/>
                  </div>
                </div>

                <div class="row mb-3">
                  <label for="input-website" class="col-sm-2 col-form-label">{{ entry_website }}</label>
                  <div class="col-sm-10">
                    <input type="text" name="website" value="{{ website }}" placeholder="{{ entry_website }}" id="input-website" class="form-control"/>
                  </div>
                </div>

                <div class="row mb-3">
                  <label for="input-tracking" class="col-sm-2 col-form-label">{{ entry_tracking }}</label>
                  <div class="col-sm-10">
                    <input type="text" name="tracking" value="{{ tracking }}" placeholder="{{ entry_tracking }}" id="input-tracking" class="form-control" required/>
                    <div class="form-text">{{ help_tracking }}</div>
                    <div id="error-tracking" class="invalid-feedback"></div>
                  </div>
                </div>

                <div class="row mb-3">
                  <label for="input-commission" class="col-sm-2 col-form-label">{{ entry_commission }}</label>
                  <div class="col-sm-10">
                    <input type="text" name="commission" value="{{ commission }}" placeholder="{{ entry_commission }}" id="input-commission" class="form-control"/>
                    <div class="form-text">{{ help_commission }}</div>
                  </div>
                </div>


                {% for custom_field in custom_fields %}
                  {% if custom_field.location == 'affiliate' %}

                    {% if custom_field.type == 'select' %}
                      <div class="row mb-3 custom-field custom-field-{{ custom_field.custom_field_id }}">
                        <label for="input-custom-field-{{ custom_field.custom_field_id }}" class="col-sm-2 col-form-label">{{ custom_field.name }}</label>
                        <div class="col-sm-10">
                          <select name="custom_field[{{ custom_field.custom_field_id }}]" id="input-custom-field-{{ custom_field.custom_field_id }}" class="form-select">
                            <option value="">{{ text_select }}</option>
                            {% for custom_field_value in custom_field.custom_field_value %}
                              <option value="{{ custom_field_value.custom_field_value_id }}"{% if affiliate_custom_field[custom_field.custom_field_id] and custom_field_value.custom_field_value_id == affiliate_custom_field[custom_field.custom_field_id] %} selected{% endif %}>{{ custom_field_value.name }}</option>
                            {% endfor %}
                          </select>
                          <div id="error-custom-field-{{ custom_field.custom_field_id }}" class="invalid-feedback"></div>
                        </div>
                      </div>
                    {% endif %}

                    {% if custom_field.type == 'radio' %}
                      <div class="row mb-3 custom-field custom-field-{{ custom_field.custom_field_id }}">
                        <label class="col-sm-2 col-form-label">{{ custom_field.name }}</label>
                        <div class="col-sm-10">
                          <div id="input-custom-field-{{ custom_field.custom_field_id }}" class="form-control" style="height: 150px; overflow: auto;">
                            {% for custom_field_value in custom_field.custom_field_value %}
                              <div class="form-check">
                                <input type="radio" name="custom_field[{{ custom_field.custom_field_id }}]" value="{{ custom_field_value.custom_field_value_id }}" id="input-custom-value-{{ custom_field_value.custom_field_value_id }}" class="form-check-input"{% if affiliate_custom_field[custom_field.custom_field_id] and custom_field_value.custom_field_value_id == affiliate_custom_field[custom_field.custom_field_id] %} checked{% endif %}/> <label for="input-custom-value-{{ custom_field_value.custom_field_value_id }}" class="form-check-label">{{ custom_field_value.name }}</label>
                              </div>
                            {% endfor %}
                          </div>
                          <div id="error-custom-field-{{ custom_field.custom_field_id }}" class="invalid-feedback"></div>
                        </div>
                      </div>
                    {% endif %}

                    {% if custom_field.type == 'checkbox' %}
                      <div class="row mb-3 custom-field custom-field-{{ custom_field.custom_field_id }}">
                        <label class="col-sm-2 col-form-label">{{ custom_field.name }}</label>
                        <div class="col-sm-10">
                          <div id="input-custom-field-{{ custom_field.custom_field_id }}" class="form-control" style="height: 150px; overflow: auto;">
                            {% for custom_field_value in custom_field.custom_field_value %}
                              <div class="form-check">
                                <input type="checkbox" name="custom_field[{{ custom_field.custom_field_id }}][]" value="{{ custom_field_value.custom_field_value_id }}" id="input-custom-value-{{ custom_field_value.custom_field_value_id }}" class="form-check-input"{% if affiliate_custom_field[custom_field.custom_field_id] and custom_field_value.custom_field_value_id in affiliate_custom_field[custom_field.custom_field_id] %} checked{% endif %}/> <label for="input-custom-value-{{ custom_field_value.custom_field_value_id }}" class="form-check-label">{{ custom_field_value.name }}</label>
                              </div>
                            {% endfor %}
                          </div>
                          <div id="error-custom-field-{{ custom_field.custom_field_id }}" class="invalid-feedback"></div>
                        </div>
                      </div>
                    {% endif %}

                    {% if custom_field.type == 'text' %}
                      <div class="row mb-3 custom-field custom-field-{{ custom_field.custom_field_id }}">
                        <label for="input-custom-field-{{ custom_field.custom_field_id }}" class="col-sm-2 col-form-label">{{ custom_field.name }}</label>
                        <div class="col-sm-10">
                          <input type="text" name="custom_field[{{ custom_field.custom_field_id }}]" value="{{ affiliate_custom_field[custom_field.custom_field_id] ? affiliate_custom_field[custom_field.custom_field_id] : custom_field.value }}" placeholder="{{ custom_field.name }}" id="input-custom-field-{{ custom_field.custom_field_id }}" class="form-control"/>
                          <div id="error-custom-field-{{ custom_field.custom_field_id }}" class="invalid-feedback"></div>
                        </div>
                      </div>
                    {% endif %}

                    {% if custom_field.type == 'textarea' %}
                      <div class="row mb-3 custom-field custom-field-{{ custom_field.custom_field_id }}">
                        <label for="input-custom-field-{{ custom_field.custom_field_id }}" class="col-sm-2 col-form-label">{{ custom_field.name }}</label>
                        <div class="col-sm-10">
                          <textarea name="custom_field[{{ custom_field.custom_field_id }}]" rows="5" placeholder="{{ custom_field.name }}" id="input-custom-field-{{ custom_field.custom_field_id }}" class="form-control">{{ affiliate_custom_field[custom_field.custom_field_id] ? affiliate_custom_field[custom_field.custom_field_id] : custom_field.value }}</textarea>
                          <div id="error-custom-field-{{ custom_field.custom_field_id }}" class="invalid-feedback"></div>
                        </div>
                      </div>
                    {% endif %}

                    {% if custom_field.type == 'file' %}
                      <div class="row mb-3 custom-field custom-field-{{ custom_field.custom_field_id }}">
                        <label class="col-sm-2 col-form-label">{{ custom_field.name }}</label>
                        <div class="col-sm-10">
                          <div class="input-group">
                            <button type="button" data-oc-toggle="upload" data-oc-url="{{ upload }}" data-oc-target="#input-custom-field-{{ custom_field.custom_field_id }}" data-oc-size-max="{{ config_file_max_size }}" data-oc-size-error="{{ error_upload_size }}" class="btn btn-primary"><i class="fa-solid fa-upload"></i> {{ button_upload }}</button>
                            <input type="text" name="custom_field[{{ custom_field.custom_field_id }}]" value="{{ affiliate_custom_field[custom_field.custom_field_id] ? affiliate_custom_field[custom_field.custom_field_id] }}" id="input-custom-field-{{ custom_field.custom_field_id }}" class="form-control" readonly/>
                            <button type="button" data-oc-toggle="download" data-oc-target="#input-custom-field-{{ custom_field.custom_field_id }}"{% if not affiliate_custom_field[custom_field.custom_field_id] %} disabled{% endif %} class="btn btn-outline-secondary"><i class="fa-solid fa-download"></i> {{ button_download }}</button>
                            <button type="button" data-oc-toggle="clear" title="{{ button_clear }}" data-oc-target="#input-custom-field-{{ custom_field.custom_field_id }}"{% if not affiliate_custom_field[custom_field.custom_field_id] %} disabled{% endif %} class="btn btn-outline-danger"><i class="fa-solid fa-eraser"></i></button>
                          </div>
                          <div id="error-custom-field-{{ custom_field.custom_field_id }}" class="invalid-feedback"></div>
                        </div>
                      </div>
                    {% endif %}

                    {% if custom_field.type == 'date' %}
                      <div class="row mb-3 custom-field custom-field-{{ custom_field.custom_field_id }}">
                        <label for="input-custom-field-{{ custom_field.custom_field_id }}" class="col-sm-2 col-form-label">{{ custom_field.name }}</label>
                        <div class="col-sm-10">
                          <input type="date" name="custom_field[{{ custom_field.custom_field_id }}]" value="{{ affiliate_custom_field[custom_field.custom_field_id] ? affiliate_custom_field[custom_field.custom_field_id] : custom_field.value }}" placeholder="{{ custom_field.name }}" id="input-custom-field-{{ custom_field.custom_field_id }}" class="form-control"/>
                          <div id="error-custom-field-{{ custom_field.custom_field_id }}" class="invalid-feedback"></div>
                        </div>
                      </div>
                    {% endif %}

                    {% if custom_field.type == 'time' %}
                      <div class="row mb-3 custom-field custom-field-{{ custom_field.custom_field_id }}">
                        <label for="input-custom-field-{{ custom_field.custom_field_id }}" class="col-sm-2 col-form-label">{{ custom_field.name }}</label>
                        <div class="col-sm-10">
                          <input type="time" name="custom_field[{{ custom_field.custom_field_id }}]" value="{{ affiliate_custom_field[custom_field.custom_field_id] ? affiliate_custom_field[custom_field.custom_field_id] : custom_field.value }}" placeholder="{{ custom_field.name }}" id="input-custom-field-{{ custom_field.custom_field_id }}" class="form-control"/>
                          <div id="error-custom-field-{{ custom_field.custom_field_id }}" class="invalid-feedback"></div>
                        </div>
                      </div>
                    {% endif %}

                    {% if custom_field.type == 'datetime' %}
                      <div class="row mb-3 custom-field custom-field-{{ custom_field.custom_field_id }}">
                        <label for="input-custom-field-{{ custom_field.custom_field_id }}" class="col-sm-2 col-form-label">{{ custom_field.name }}</label>
                        <div class="col-sm-10">
                          <input type="datetime-local" name="custom_field[{{ custom_field.custom_field_id }}]" value="{{ affiliate_custom_field[custom_field.custom_field_id] ? affiliate_custom_field[custom_field.custom_field_id] : custom_field.value }}" placeholder="{{ custom_field.name }}" id="input-custom-field-{{ custom_field.custom_field_id }}" class="form-control"/>
                          <div id="error-custom-field-{{ custom_field.custom_field_id }}" class="invalid-feedback"></div>
                        </div>
                      </div>
                    {% endif %}

                  {% endif %}
                {% endfor %}

                <div class="row mb-3">
                  <label class="col-sm-2 col-form-label">{{ entry_status }}</label>
                  <div class="col-sm-10">
                    <x-switch name="status" value="1" checked="{{ status }}" input-id="input-status" input-class="form-switch form-switch-lg"></x-switch>
                  </div>
                </div>
              </fieldset>
              <fieldset>
                <legend>{{ text_payment }}</legend>
                <div class="row mb-3">
                  <label for="input-tax" class="col-sm-2 col-form-label">{{ entry_tax }}</label>
                  <div class="col-sm-10">
                    <input type="text" name="tax" value="{{ tax }}" placeholder="{{ entry_tax }}" id="input-tax" class="form-control"/>
                  </div>
                </div>
                <div class="row mb-3">
                  <label class="col-sm-2 col-form-label">{{ entry_payment_method }}</label>
                  <div class="col-sm-10">
                    <div class="form-check">
                      <input type="radio" name="payment_method" value="cheque" id="input-payment-cheque" class="form-check-input"{% if payment_method == 'cheque' %} checked{% endif %}/> <label for="input-payment-cheque" class="form-check-label">{{ text_cheque }}</label>
                    </div>
                    <div class="form-check">
                      <input type="radio" name="payment_method" value="paypal" id="input-payment-paypal" class="form-check-input"{% if payment_method == 'paypal' %} checked{% endif %}/> <label for="input-payment-paypal" class="form-check-label">{{ text_paypal }}</label>
                    </div>
                    <div class="form-check">
                      <input type="radio" name="payment_method" value="bank" id="input-payment-bank" class="form-check-input"{% if payment_method == 'bank' %} checked{% endif %}/> <label for="input-payment-bank" class="form-check-label">{{ text_bank }}</label>
                    </div>
                    <div id="error-payment-method" class="invalid-feedback"></div>
                  </div>
                </div>
                <div id="payment-method"></div>
              </fieldset>
            </div>
            <div id="tab-history" class="tab-pane">
              <fieldset>
                <legend>{{ text_history }}</legend>
                <div id="history">{{ history }}</div>
              </fieldset>
              <br/>
              <fieldset>
                <legend>{{ text_history_add }}</legend>
                <div class="row mb-3">
                  <label for="input-history" class="col-sm-2 col-form-label">{{ entry_comment }}</label>
                  <div class="col-sm-10">
                    <textarea name="comment" rows="8" placeholder="{{ entry_comment }}" id="input-history" class="form-control"></textarea>
                  </div>
                </div>
              </fieldset>
              <div class="text-end">
                <button type="button" id="button-history" class="btn btn-primary"><i class="fa-solid fa-plus-circle"></i> {{ button_history_add }}</button>
              </div>
            </div>
            <div id="tab-transaction" class="tab-pane">
              <fieldset>
                <legend>{{ text_transaction }}</legend>
                <div id="transaction">{{ transaction }}</div>
              </fieldset>
              <br/>
              <fieldset>
                <legend>{{ text_transaction_add }}</legend>
                <div class="row mb-3">
                  <label for="input-transaction" class="col-sm-2 col-form-label">{{ entry_description }}</label>
                  <div class="col-sm-10">
                    <input type="text" name="description" value="" placeholder="{{ entry_description }}" id="input-transaction" class="form-control"/>
                  </div>
                </div>
                <div class="row mb-3">
                  <label for="input-amount" class="col-sm-2 col-form-label">{{ entry_amount }}</label>
                  <div class="col-sm-10">
                    <input type="text" name="amount" value="" placeholder="{{ entry_amount }}" id="input-amount" class="form-control"/>
                  </div>
                </div>
              </fieldset>
              <div class="text-end">
                <button type="button" id="button-transaction" class="btn btn-primary"><i class="fa-solid fa-plus-circle"></i> {{ button_transaction_add }}</button>
              </div>
            </div>
            <div id="tab-report" class="tab-pane">
              <fieldset>
                <legend>{{ text_report }}</legend>
                <div id="report">{{ report }}</div>
              </fieldset>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>
<template id="template-cheque">
  <div class="row mb-3">
    <label for="input-cheque" class="col-sm-2 col-form-label">{{ entry_cheque }}</label>
    <div class="col-sm-10">
      <input type="text" name="cheque" value="{{ cheque }}" placeholder="{{ entry_cheque }}" id="input-cheque" class="form-control" required/>
      <div id="error-cheque" class="invalid-feedback"></div>
    </div>
  </div>
</template>
<template id="template-paypal">
  <div class="row mb-3">
    <label for="input-paypal" class="col-sm-2 col-form-label">{{ entry_paypal }}</label>
    <div class="col-sm-10">
      <input type="text" name="paypal" value="{{ paypal }}" placeholder="{{ entry_paypal }}" id="input-paypal" class="form-control" required/>
      <div id="error-paypal" class="invalid-feedback"></div>
    </div>
  </div>
</template>
<template id="template-bank">
  <div class="row mb-3">
    <label for="input-bank-name" class="col-sm-2 col-form-label">{{ entry_bank_name }}</label>
    <div class="col-sm-10">
      <input type="text" name="bank_name" value="{{ bank_name }}" placeholder="{{ entry_bank_name }}" id="input-bank-name" class="form-control"/>
    </div>
  </div>
  <div class="row mb-3">
    <label for="input-bank-branch-number" class="col-sm-2 col-form-label">{{ entry_bank_branch_number }}</label>
    <div class="col-sm-10">
      <input type="text" name="bank_branch_number" value="{{ bank_branch_number }}" placeholder="{{ entry_bank_branch_number }}" id="input-bank-branch-number" class="form-control"/>
    </div>
  </div>
  <div class="row mb-3">
    <label for="input-bank-swift-code" class="col-sm-2 col-form-label">{{ entry_bank_swift_code }}</label>
    <div class="col-sm-10">
      <input type="text" name="bank_swift_code" value="{{ bank_swift_code }}" placeholder="{{ entry_bank_swift_code }}" id="input-bank-swift-code" class="form-control"/>
    </div>
  </div>
  <div class="row mb-3">
    <label for="input-bank-account-name" class="col-sm-2 col-form-label">{{ entry_bank_account_name }}</label>
    <div class="col-sm-10">
      <input type="text" name="bank_account_name" value="{{ bank_account_name }}" placeholder="{{ entry_bank_account_name }}" id="input-bank-account-name" class="form-control" required/>
      <div id="error-bank-account-name" class="invalid-feedback"></div>
    </div>
  </div>
  <div class="row mb-3">
    <label for="input-bank-account-number" class="col-sm-2 col-form-label">{{ entry_bank_account_number }}</label>
    <div class="col-sm-10">
      <input type="text" name="bank_account_number" value="{{ bank_account_number }}" placeholder="{{ entry_bank_account_number }}" id="input-bank-account-number" class="form-control" required/>
      <div id="error-bank-account-number" class="invalid-feedback"></div>
    </div>
  </div>
</template>
<script type="text/javascript" src="view/javascript/affiliate.js"></script>
{{ footer }}
