<div class="container-fluid">
    <div>
        <h3>Manage Currencies</h3>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    <a href="#">Home</a>
                </li>
                <li class="breadcrumb-item">
                    <a href="#">Settings</a>
                </li>
                <li class="breadcrumb-item active" aria-current="page">Manage Currencies</li>
            </ol>
        </nav>
    </div>
    <div class="alert alert-warning">
      <i class="fa fa-question-circle fa-fw"></i> Please note that not all currencies are supported by payment methods. If the currency you chose isn't supported, You can set the default payment currency for each payment method from <a href="<?php echo Wo_LoadAdminLinkSettings('payment-settings'); ?>"> Payment Settings.</a>
    </div>
    <!-- Vertical Layout -->
    <div class="row">
    	<div class="col-lg-12 col-md-12">
            <div class="card">
                <div class="card-body">
                    <h6 class="card-title">Add New Currency</h6>
                     <div class="add-curreny-settings-alert"></div>
                    <form class="add-curreny-settings" method="POST">
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Currency Code (e.g: USD)</label>
                                <input type="text" id="currency" name="currency" class="form-control">
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Currency Symbol (e.g: $)</label>
                                <input type="text" id="currency_symbol" name="currency_symbol" class="form-control">
                            </div>
                        </div>
                        <div class="clearfix"></div>
                        <input type="hidden" name="hash_id" value="<?php echo Wo_CreateSession();?>">
                        <button type="submit" class="btn btn-primary m-t-15 waves-effect">Add Currency</button>
                    </form>
                </div>
            </div>
        </div>
        <div class="col-lg-12 col-md-12">
            <div class="card">
                <div class="card-body">
                    <h6 class="card-title">Currencies</h6>
                   <input type="hidden" id="hash_id" name="hash_id" value="<?php echo Wo_CreateSession();?>">
                   <div class="clearfix"></div>
                   <div class="table-responsive1">
                        <table class="table table-bordered table-striped table-hover">
                            <thead>
                                <tr>
                                      <th>ID</th>
					                  <th>Currency Code</th>
					                  <th>Currency Symbol</th>
                                      <th>Status</th>
                                      <th><?php echo($wo['config']['currency']) ?> Exchange</th>
					                  <th>Action</th>
                                </tr>
                            </thead>
                            <tbody>
                               <?php 
				               foreach ($wo['config']['currency_array']  as $wo['currency_key'] => $wo['currency_value']) {
				                  echo Wo_LoadAdminPage('manage-currencies/list');
				                }
				               ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>
    <!-- #END# Vertical Layout -->

    <div class="modal fade" id="DeleteModal" tabindex="-1" role="dialog" aria-labelledby="exampleModal1Label" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModal1Label">Delete Currency?</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    Are you sure you want to delete this currency?
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary" data-dismiss="modal">Delete</button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="defaultModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content modal_content_back">
          <div class="modal-header">
            <h5 class="modal-title" id="defaultModalLabel">Edit Currency</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            <div class="edit-curreny-settings-alert"></div>
            <form class="edit-curreny-settings" method="POST">

                <div class="form-group form-float">
                    <div class="form-line">
                        <input type="text" id="edit_currency" name="currency" class="form-control" placeholder="Currency Code (e.g: USD)">
                    </div>
                </div>
                <div class="form-group form-float">
                    <div class="form-line">
                        <input type="text" id="edit_currency_symbol" name="currency_symbol" class="form-control" placeholder="Currency Symbol (e.g: $)">
                    </div>
                </div>
                <div class="clearfix"></div>
                <input type="hidden" name="currency_id" id="edit_currency_id">
                <input type="hidden" name="hash_id" value="<?php echo Wo_CreateSession();?>">
            </form>
          </div>
          <div class="modal-footer">
            <input type="hidden" id="c_id_">
            <button type="button" class="btn btn-primary modal_close_btn" data-dismiss="modal">CLOSE</button>
            <button type="button" class="btn btn-success" onclick="Wo_SubmitCurrencyForm();">SAVE CHANGES</button>
          </div>
        </div>
      </div>
    </div>

<script>

function delete_currency(currency,type = 'show') {
  if (type == 'hide') {
    $('#DeleteModal').find('.btn-primary').attr('onclick', "delete_currency('"+currency+"')");
    $('#DeleteModal').modal('show');
    return false;
  }
  $.post(Wo_Ajax_Requests_File() + '?f=admin_setting&s=remove__curreny', {currency: currency}, function(data, textStatus, xhr) {
    if (data.status == 200) {
        $('#currency_'+currency).remove();
    }
  });
}
function open_edit_currency(currency,currency_symbol,currency_id) {
  $('#defaultModal').modal('show');
  $('#edit_currency').val(currency);
  $('#edit_currency_symbol').val(currency_symbol);
  $('#edit_currency_id').val(currency_id);
}

function make_default(currency) {
  $.post(Wo_Ajax_Requests_File() + '?f=admin_setting&s=select_currency', {currency: currency}, function(data, textStatus, xhr) {
    if (data.status == 200) {
            location.reload();
    }
  });
}
function Wo_SubmitCurrencyForm() {
  $('.edit-curreny-settings').submit();
}

var form_add_site_settings = $('form.add-curreny-settings');
form_add_site_settings.ajaxForm({
    url: Wo_Ajax_Requests_File() + '?f=admin_setting&s=add_new_curreny',
    beforeSend: function() {
        form_add_site_settings.find('.waves-effect').text('Please wait..');
    },
    success: function(data) {
        if (data.status == 200) {
            form_add_site_settings.find('.waves-effect').text('Add Currency');
            $("html, body").animate({ scrollTop: 0 }, "slow");
            $('.add-curreny-settings-alert').html('<div class="alert alert-success"><i class="fa fa-check"></i> Currency successfully added</div>');
            setTimeout(function () {
                $('.add-curreny-settings-alert').empty();
                location.reload();
            }, 2000);
        }
    }
});

var form_edit_site_settings = $('form.edit-curreny-settings');
form_edit_site_settings.ajaxForm({
    url: Wo_Ajax_Requests_File() + '?f=admin_setting&s=edit_curreny',
    beforeSend: function() {
        form_edit_site_settings.find('.waves-effect').text('Please wait..');
    },
    success: function(data) {
        if (data.status == 200) {
            form_edit_site_settings.find('.waves-effect').text('SAVE CHANGES');
            $("html, body").animate({ scrollTop: 0 }, "slow");
            $('.edit-curreny-settings-alert').html('<div class="alert alert-success"><i class="fa fa-check"></i> Currency successfully edited</div>');
            setTimeout(function () {
                $('.edit-curreny-settings-alert').empty();
                location.reload();
            }, 2000);
        }
    }
});

</script>