<vn-crud-model 
    vn-id="model"
    url="TicketServices"
    link="{ticketFk: $ctrl.$stateParams.id}"
    data="$ctrl.services"
    auto-load="true">
</vn-crud-model>
<vn-watcher
    vn-id="watcher"
    data="$ctrl.services">
</vn-watcher>
<form name="form" ng-submit="$ctrl.onSubmit()" class="vn-w-md">
    <vn-card class="vn-pa-lg">
        <vn-horizontal ng-repeat="service in $ctrl.services track by $index">
            <vn-autocomplete
                vn-one
                vn-focus
                url="TicketServiceTypes"
                label="Description"
                show-field="name"
                value-field="name"
                ng-model="service.description">
                <append>
                    <vn-icon-button
                        icon="add_circle"
                        vn-tooltip="New service type"
                        ng-click="$ctrl.newServiceTypeDialog($index, $event)"
                        vn-acl="administrative"
                        style="padding: 0;">
                    </vn-icon-button>
                </append>
            </vn-autocomplete>
            <vn-input-number
                vn-one min="0"
                step="1" 
                label="Quantity"
                ng-model="service.quantity"
                rule="TicketService">
            </vn-input-number>
            <vn-input-number
                vn-one
                label="Price"
                ng-model="service.price"
                step="0.01">
            </vn-input-number>
            <vn-autocomplete vn-one
                url="TaxClasses"
                label="Tax class"
                show-field="description"
                value-field="id"
                ng-model="service.taxClassFk">
            </vn-autocomplete>
            <vn-auto>
                <vn-icon-button
                    pointer
                    vn-tooltip="Remove service"
                    icon="delete"
                    ng-click="model.remove($index)">
                </vn-icon-button>  
            </vn-auto>
        </vn-horizontal>
        <vn-icon-button
            vn-tooltip="Add service"
            vn-bind="+"
            icon="add_circle"
            ng-click="$ctrl.add()">
        </vn-icon-button>
    </vn-card>
    <vn-button-bar>
        <vn-submit label="Save"></vn-submit>
    </vn-button-bar>
</form>

<!-- Create service type dialog -->
<vn-dialog class="edit" 
    vn-id="createServiceTypeDialog"
    on-open="$ctrl.onNewServiceTypeOpen()"
    on-response="$ctrl.onNewServiceTypeResponse(response)">
    <tpl-body>
        <h5 class="vn-py-sm" translate>New service type</h5>
        <vn-horizontal>
            <vn-textfield
                vn-one
                label="Description"
                ng-model="$ctrl.newServiceType.name"
                vn-focus>
            </vn-textfield>
        </vn-horizontal>
    </tpl-body>
    <tpl-buttons>
        <input type="button" response="CANCEL" translate-attr="{value: 'Cancel'}"/>
        <button response="ACCEPT" translate>Create</button>
    </tpl-buttons>
</vn-dialog>