<mg-ajax path="Claims/updateClaim/{{patch.params.id}}" options="vnPatch"></mg-ajax>
<vn-watcher
    vn-id="watcher"
    data="$ctrl.claim"
    form="form"
    save="patch">
</vn-watcher>
<vn-crud-model
    auto-load="true"
    url="ClaimStates"
    data="claimStates">
</vn-crud-model>
<form name="form" ng-submit="$ctrl.onSubmit()" class="vn-w-md">
    <vn-card class="vn-pa-lg">
        <vn-horizontal>
            <vn-textfield
                label="Client"
                ng-model="$ctrl.claim.client.name"
                readonly="true">
            </vn-textfield>
            <vn-textfield
                label="Created" 
                field="::$ctrl.claim.created | date:'yyyy-MM-dd HH:mm'"
                readonly="true">
            </vn-textfield>
        </vn-horizontal>
        <vn-horizontal>
            <vn-autocomplete
                disabled="false"
                ng-model="$ctrl.claim.workerFk"
                url="Workers/activeWithRole"
                show-field="nickname"
                search-function="{firstName: $search}"
                where="{role: 'salesPerson'}"
                label="Attended by">
            </vn-autocomplete>
            <vn-autocomplete
                ng-model="$ctrl.claim.claimStateFk"
                data="claimStates"
                show-field="description"
                value-field="id"
                label="Claim state"
                order="priority ASC"
                vn-focus>
            </vn-autocomplete>
        </vn-horizontal>
        <vn-horizontal>
            <vn-input-number vn-one
                min="0"
                type="number"
                label="Packages received"
                ng-model="$ctrl.claim.packages">
            </vn-input-number>
        </vn-horizontal>
        <vn-horizontal>
            <vn-textarea
                label="Observation" 
                ng-model="$ctrl.claim.observation"
                rule>
            </vn-textarea>
        </vn-horizontal>
        <vn-horizontal>
            <vn-check
                class="vn-mr-md"
                label="Pick up"
                ng-model="$ctrl.claim.hasToPickUp"
                vn-acl="claimManager"
                info="When checked will notify to the salesPerson">
            </vn-check>
        </vn-horizontal>
    </vn-card>
    <vn-button-bar>
        <vn-submit
            disabled="!watcher.dataChanged()"
            label="Save">
        </vn-submit>
        <vn-button
            class="cancel"
            label="Undo changes"
            disabled="!watcher.dataChanged()"
            ng-click="watcher.loadOriginalData()">
        </vn-button>
    </vn-button-bar>
</form>