{{-- Chart-of-accounts create/edit modal form. --}}
@php $isEdit = $account->exists; @endphp
<div class="modal-dialog" role="document">
  <div class="modal-content">
    <form class="medacc-form"
        action="{{ $isEdit ? route('medacc.coa.update', $account->id) : route('medacc.coa.store') }}"
        method="POST">
      {{ csrf_field() }}
      @if($isEdit) {{ method_field('PUT') }} @endif
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">{{ $isEdit ? __('medaccounting::lang.edit_account') : __('medaccounting::lang.add_account') }}</h4>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-md-4 form-group">
            <label>@lang('medaccounting::lang.account_code') *</label>
            <input type="text" name="code" class="form-control" required value="{{ $account->code }}"
                @if($isEdit && $account->is_system) readonly @endif>
          </div>
          <div class="col-md-8 form-group">
            <label>@lang('medaccounting::lang.account_name') *</label>
            <input type="text" name="name" class="form-control" required value="{{ $account->name }}">
          </div>
        </div>
        <div class="row">
          <div class="col-md-6 form-group">
            <label>@lang('medaccounting::lang.account_type') *</label>
            <select name="type" class="form-control" required @if($isEdit && $account->is_system) disabled @endif>
              @foreach($types as $type)
                <option value="{{ $type }}" @selected($account->type === $type)>@lang('medaccounting::lang.type_' . $type)</option>
              @endforeach
            </select>
            @if($isEdit && $account->is_system)
              <input type="hidden" name="type" value="{{ $account->type }}">
            @endif
          </div>
          <div class="col-md-6 form-group">
            <label>@lang('medaccounting::lang.sub_type')</label>
            <input type="text" name="sub_type" class="form-control" value="{{ $account->sub_type }}"
                placeholder="current_asset, fixed_asset, …">
          </div>
        </div>
        <div class="row">
          <div class="col-md-8 form-group">
            <label>@lang('medaccounting::lang.parent_account')</label>
            <select name="parent_id" class="form-control">
              <option value="">@lang('medaccounting::lang.none')</option>
              @foreach($parents as $id => $label)
                <option value="{{ $id }}" @selected((int) $account->parent_id === (int) $id)>{{ $label }}</option>
              @endforeach
            </select>
          </div>
          <div class="col-md-4">
            <label class="checkbox-inline" style="margin-top:28px;">
              <input type="checkbox" name="is_active" value="1" @checked(! $isEdit || $account->is_active)>
              @lang('medaccounting::lang.active')
            </label>
          </div>
        </div>
        <div class="form-group">
          <label>@lang('medaccounting::lang.description')</label>
          <textarea name="description" class="form-control" rows="2">{{ $account->description }}</textarea>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">@lang('medaccounting::lang.cancel')</button>
        <button type="submit" class="btn btn-primary">@lang('medaccounting::lang.save')</button>
      </div>
    </form>
  </div>
</div>
