<div class="col-md-12 d-flex">

    <div class="card flex-fill w-100">
        <div class="card-header">
            <div class="card-actions float-end">
                <div class="btn-group float-end" role="group">
                    <button type="button" class="btn btn-success"
                            data-toggle="modal" data-target="#exchangeModal" data-action="create_exchange">
                        <i class="bi bi-plus-square"></i>
                    </button>
                </div>
            </div>
            <h5 class="card-title mb-0">Exchange Instances</h5>
        </div>

        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-hover table-sm">
                    <thead>
                    <tr>
                        <th>Name</th>
                        <th>Type</th>
                        <th>Configuration</th>
                        <th>Actions</th>
                    </tr>
                    </thead>
                    <tbody>
                    {{#exchanges}}
                    <tr>
                        <td>{{.getName()}}</td>
                        <td>{{.getClass().getSimpleName()}}</td>
                        <td>{{.getDeviceConfig()}}</td>
                        <td>
                            <form method="POST">
                                <input type="hidden" name="id" value="{{.getId()}}">

                                <div class="btn-toolbar pull-right">
                                    <button type="button" class="btn btn-default btn-xs" data-toggle="modal"
                                            data-target="#exchangeModal"
                                            data-action="modify_exchange"
                                            data-id="{{.getId()}}"
                                            data-name="{{.getName()}}"
                                            data-type="{{.getType()}}"
                                            {{#.getDeviceConfigurator().getConfiguration()}}
                                            data-{{.getName()}}="{{.getString()}}"
                                            {{/.getDeviceConfigurator().getConfiguration()}}
                                    >
                                    <span class="glyphicon glyphicon-pencil"></span>
                                    </button>

                                    <button type="submit" class="btn btn-danger btn-xs" name="action" value="remove_exchange">
                                        <span class="glyphicon glyphicon-trash"></span>
                                    </button>
                                </div>
                            </form>
                        </td>
                    </tr>
                    {{/exchanges}}
                    </tbody>
                </table>
            </div>
        </div>
    </div>

</div>

<!------------- MODALS --------------->
<script>
    $(function(){
        initDynamicModalForm("exchangeModal");
    });
</script>

<div class="modal fade" id="exchangeModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span>&times;</span></button>
                <h4 class="modal-title">Exchange</h4>
            </div>
            <form method="POST">
                <div class="modal-body">
                    <input type="hidden" id="action" name="action">
                    <input type="hidden" id="id" name="id">
                    <div class="form-group">
                        <label class="control-label">Name:</label>
                        <input type="text" class="form-control" name="name">
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="reset" class="btn btn-default" data-dismiss="modal">Cancel</button>
                    <button type="submit" class="btn btn-primary">Save</button>
                </div>
            </form>
        </div>
    </div>
</div>

