<div class="container-fluid">

    <div>
        <h3>Manage Currencies</h3>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    <a href="#">Admin Panel</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 PayPal, stripe, 2checkout, etc. You can set the default payment currency for each payment method from <a data-ajax="?path=payment-settings" href="<?php echo 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 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>
                        <br>
                        <button type="submit" class="btn btn-primary m-t-15 waves-effect">Add</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>
                   <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>Action</th>
                                </tr>
                            </thead>
                            <tbody>
                               <?php
				               foreach ($music->config->currency_array  as $music->currency_key => $music->currency_value) {
				                  echo 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="SelectedDeleteModal" 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 that you want to remove the selected Currency(s)?
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary" onclick="DeleteSelected()" data-dismiss="modal">Delete</button>
                </div>
            </div>
        </div>
    </div>

<script>
    $('.check-all').on('click', function(event) {
        $('input:checkbox').not(this).prop('checked', this.checked);
    });
    $('.delete-checkbox, .check-all').change(function(event) {
        $('.delete-selected').attr('disabled', false);
        $('.delete-selected').find('span').text(' (' + $('.delete-checkbox:checked').length + ')');
    });
    $('.submit-selected').on('click', function(event) {
        event.preventDefault();
        $('#SelectedStatusModal').modal('show');
    });

    $('.delete-selected').on('click', function(event) {
        event.preventDefault();
        $('#SelectedDeleteModal').modal('show');
    });
    function DeleteSelected() {
        data = new Array();
        $('td input:checked').parents('tr').each(function () {
            data.push($(this).attr('data_selected'));
        });
        $('.delete-selected').attr('disabled', true);
        $('.delete-selected').text('Please wait..');
        $.post("{{LINK aj/ap/remove_multi_curreny}}", {ids: data}, function () {
            $.each( data, function( index, value ){
                $('#currency_' + value).remove();
            });
            $('.delete-selected').text('Delete Selected');
        });
    }

function delete_currency(currency,type = 'show') {
  if (type == 'hide') {
    $('#DeleteModal').find('.btn-primary').attr('onclick', "delete_currency('"+currency+"')");
    $('#DeleteModal').modal('show');
    return false;
  }
  $.post('{{CONFIG ajax_url}}/ap/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('{{CONFIG ajax_url}}/ap/select_currency', {currency: currency}, function(data, textStatus, xhr) {
    if (data.status == 200) {
            location.reload();
    }
  });
}
function Wo_SubmitCurrencyForm() {
  $('.edit-curreny-settings').submit();
}
$(function() {
var form_add_site_settings = $('form.add-curreny-settings');
form_add_site_settings.ajaxForm({
    url: '{{CONFIG ajax_url}}/ap/add-new-currency?hash_id=' + $('.main_session').val(),
    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('Save');
            $("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);
        }
        else{
            form_add_site_settings.find('.waves-effect').text('Save');
            $("html, body").animate({ scrollTop: 0 }, "slow");
            $('.add-curreny-settings-alert').html('<div class="alert alert-danger">Please check your details</div>');
            setTimeout(function () {
                $('.add-curreny-settings-alert').empty();
            }, 2000);
        }
    }
});

var form_edit_site_settings = $('form.edit-curreny-settings');
form_edit_site_settings.ajaxForm({
    url: '{{CONFIG ajax_url}}/ap/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);
        }
        else{
            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-danger">Please check your details</div>');
            setTimeout(function () {
                $('.edit-curreny-settings-alert').empty();
            }, 2000);
        }
    }
});
});

</script>
<div class="modal fade" id="defaultModal" 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">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">
                                <label class="form-label">Currency Code (e.g: USD)</label>
                                <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">
                                <label class="form-label">Currency Symbol (e.g: $)</label>
                                <input type="text" id="edit_currency_symbol" name="currency_symbol" class="form-control" placeholder="Currency Symbol (e.g: $)">
                            </div>
                        </div>
                        <div class="clearfix"></div>
                        <br><br>
                        <input type="hidden" name="currency_id" id="edit_currency_id">
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary" onclick="Wo_SubmitCurrencyForm();">SAVE CHANGES</button>
                </div>
            </div>
        </div>
    </div>

<!-- <div class="modal fade" id="defaultModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content ">
            <div class="modal-header">
                <h4 class="modal-title" id="defaultModalLabel">Edit Currency</h4>
            </div>
            <div class="modal-body">
                <div class="alert alert-success 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>
                    <br><br>
                    <input type="hidden" name="currency_id" id="edit_currency_id">
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" onclick="Wo_SubmitCurrencyForm();" class="btn-save btn btn-link waves-effect">SAVE CHANGES</button>
                <button type="button" class="btn btn-link waves-effect" data-dismiss="modal">CLOSE</button>
            </div>
        </div>
    </div>
</div> -->
