<div class="modal-content">
   <div class="modal-header">
      <h4 class="modal-title">{{__('expenses.expense-form.update-title')}}</h4>
   </div>
      <form class="simcy-form" action="{{ url('Expenses@update') }}" data-parsley-validate method="POST" loader="true">
   <div class="modal-body">
         <div class="form-group">
            <div class="row">
               <div class="col-md-12">
                  <label>{{__('expenses.expense-form.label.title')}}</label>
                  <input type="text" class="form-control" name="title" value="{{$expense->title}}" placeholder="{{__('expenses.expense-form.placeholder.title')}}" required>
                  <input type="hidden" name="csrf-token" value="{{csrf_token()}}" />
                  <input type="hidden" name="expenseid" value="{{$expense->id}}" />
               </div>
            </div>
         </div>
         <div class="form-group">
            <div class="row">
               <div class="col-md-12">
                  <label>{{__('expenses.expense-form.label.amount')}}</label>
                  <span class="input-prefix">{{ currency() }}</span>
                  <input type="number" class="form-control prefix" value="{{$expense->amount}}" name="amount" placeholder="{{__('expenses.expense-form.placeholder.amount')}}">
               </div>
            </div>
         </div>
         <div class="form-group">
            <div class="row">
               <div class="col-md-12">
                  <label>{{__('expenses.expense-form.label.account')}}</label>
                  <select class="form-control select2" name="account">
                     <option value="0" @if($expense->account == '0') selected @endif>
                        {{__('expenses.expense-form.account.other')}}</option>
                    @if(!empty($accounts))
                    @foreach($accounts as $account)
                     <option value="{{ $account->id }}" @if($expense->account == $account->id) selected @endif>
                        {{ $account->name }}</option>
                    @endforeach
                    @endif
                  </select>
               </div>
            </div>
         </div>
         <div class="form-group">
            <div class="row">
               <div class="col-md-12">
                   <label>{{__('expenses.expense-form.label.category')}}</label>
                   <select class="form-control select2" name="category">
                       @if(!empty($categories))
                           @foreach($categories as $category)
                               <option value="{{ $category->id }}" @if($expense->category == $category->id) selected @endif>
                                  {{ $category->name }} </option>
                           @endforeach
                       @endif
                       <option value="00" @if($expense->category == '0') selected @endif>
                        {{__('expenses.expense-form.category.other')}} </option>
                  </select>
               </div>
            </div>
         </div>
         <div class="form-group">
            <div class="row">
               <div class="col-md-12">
                  <label>{{__('expenses.expense-form.label.date')}}</label>
                  <input type="text" class="form-control datepicker-dynamic" value="{{date('m/d/Y', strtotime($expense->expense_date))}}" name="expense_date" placeholder="Date">
               </div>
            </div>
         </div>
         <div class="form-group">
            <div class="row">
                <div class="col-md-12">
                    <label>{{__('expenses.expense-form.label.note')}}</label>
                    <input type="text" class="form-control" name="note" value="{{ $expense->note }}" placeholder="{{__('expenses.expense-form.placeholder.note')}}">
                </div>
            </div>
        </div>

        @if ((env("ALLOW_ATTACHMENTS") == "Enabled") && empty($expense->attachment))
        <div class="form-group">
            <div class="row">
                <div class="col-md-12">
                    <label>{{__('expenses.expense-form.label.attachment')}}</label> 
                    <div name="croppie">
                        <input type="file" name="image_attachment" id="image_attachment" class="croppie" crop-width="800" crop-height="800" accept="image/*" onchange='expenseHideFileAttachment()'>
                    </div>
                <div name="file_attachment_label">
                    {{__('expenses.expense-form.label.pdf')}}</div>
                <input type="file" class="form-control" name="file_attachment" id="file_attachment" accept="application/pdf" onchange='expenseHideCroppie()'>
                </div>
            </div>
            <button type="button" class="btn btn-danger btn-sm" name="clearButton" onclick="expenseClearAttachment()" style="display: none">{{__('expenses.expense-form.label.clear')}}</button>
        </div>
        @endif


   </div>
   <div class="modal-footer">
   <button type="button" class="btn btn-default" data-dismiss="modal">{{__('expenses.button.close')}}</button>
   <button type="submit" class="btn btn-primary">{{__('expenses.button.update-expense')}}</button>
   </div>
   </form>
</div>
<script type="text/javascript">
   $('.datepicker-dynamic').datepicker({
          autoclose: true
      });

      croppify();
      
      function expenseHideCroppie() {
               $('[name=croppie]').hide();
               $('[name=file_attachment_label]').hide();
               $('[name=clearButton]').show();
        }
        function expenseHideFileAttachment() {
               $('[name=file_attachment]').hide();
               $('[name=file_attachment_label]').hide();
               $('[name=clearButton]').show();
        }

        function expenseClearAttachment() {

            $('[name=file_attachment]').val('');
            $('[name=image_attachment]').val('');
            $('[name=croppie]').show();
            $('[name=file_attachment]').show();
            $('[name=file_attachment_label]').show();
            $('[name=clearButton]').hide();

            $('[name=image_attachment]').removeClass('ready');
            $('[name=image_attachment]').html("");

            $('[class=croppie-output]').attr("src","data:image/png;base64,[encoded data, 7000 characters]");
        }
</script>