<mg-ajax path="Clients/{{patch.params.id}}" options="vnPatch"></mg-ajax>
<vn-watcher
    vn-id="watcher"
    data="$ctrl.client"
    form="form"
    save="patch">
</vn-watcher>
<vn-crud-model
    auto-load="true"
    url="ContactChannels"
    data="contactChannels">
</vn-crud-model>
<form name="form" vn-http-submit="$ctrl.onSubmit()" class="vn-w-md">
    <vn-card class="vn-pa-lg">
        <vn-horizontal>
            <vn-textfield
                vn-one
                label="Comercial Name"
                ng-model="$ctrl.client.name"
                rule
                vn-focus>
            </vn-textfield>
            <vn-autocomplete
                vn-one
                ng-model="$ctrl.client.businessTypeFk"
                url="BusinessTypes"
                show-field="description"
                value-field="code"
                label="Business type">
            </vn-autocomplete>
        </vn-horizontal>
        <vn-horizontal>
            <vn-textfield
                vn-one
                label="Contact"
                ng-model="$ctrl.client.contact"
                rule>
            </vn-textfield>
            <vn-textfield
                vn-one
                label="Email"
                ng-model="$ctrl.client.email"
                rule
                info="You can save multiple emails">
            </vn-textfield>
        </vn-horizontal>
        <vn-horizontal>
            <vn-textfield
                vn-one
                label="Phone"
                ng-model="$ctrl.client.phone"
                rule>
            </vn-textfield>
            <vn-textfield
                vn-one
                label="Mobile"
                ng-model="$ctrl.client.mobile"
                rule>
            </vn-textfield>
        </vn-horizontal>
        <vn-horizontal>
            <vn-worker-autocomplete
                vn-one
                ng-model="$ctrl.client.salesPersonFk"
                departments="['VT', 'shopping']"
                show-field="nickname"
                label="Salesperson"
                vn-acl="salesAssistant">
            </vn-worker-autocomplete>
            <vn-autocomplete
                vn-one
                ng-model="$ctrl.client.contactChannelFk"
                data="contactChannels"
                label="Channel">
            </vn-autocomplete>
        </vn-horizontal>
        <vn-horizontal>
            <vn-autocomplete
                ng-model="$ctrl.client.transferorFk"
                url="Clients"
                search-function="$ctrl.transferorSearchFunction($search)"
                where="{id: {neq: $ctrl.client.id}}"
                show-field="name"
                value-field="id"
                label="Previous client"
                info="In case of a company succession, specify the grantor company"
                rule>
            </vn-autocomplete>
        </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>