<vn-watcher
    vn-id="watcher"
    url="Clients/createWithUser"
    data="$ctrl.client"
    insert-mode="true"
    form="form">
</vn-watcher>
<form name="form" vn-http-submit="$ctrl.onSubmit()" class="vn-w-md">
    <vn-card class="vn-pa-lg">
        <vn-horizontal>
            <vn-textfield
                vn-two
                label="Comercial Name"
                ng-model="$ctrl.client.name"
                rule
                vn-focus>
            </vn-textfield>
            <vn-worker-autocomplete
                label="Salesperson"
                ng-model="$ctrl.client.salesPersonFk"
                departments="['VT']"
                show-field="nickname">
            </vn-worker-autocomplete>
        </vn-horizontal>
        <vn-horizontal>
            <vn-autocomplete
                vn-id="businessTypeFk"
                ng-model="$ctrl.client.businessTypeFk"
                url="BusinessTypes"
                show-field="description"
                value-field="code"
                label="Business type"
                rule>
            </vn-autocomplete>
            <vn-textfield
                label="Tax number"
                ng-model="$ctrl.client.fi"
                rule>
            </vn-textfield>
        </vn-horizontal>
        <vn-horizontal>
            <vn-textfield
                label="Business name"
                ng-model="$ctrl.client.socialName"
                rule>
            </vn-textfield>
        </vn-horizontal>
        <vn-horizontal>
            <vn-textfield
                vn-two
                label="Street"
                ng-model="$ctrl.client.street"
                rule>
            </vn-textfield>
        </vn-horizontal>
        <vn-horizontal>
            <vn-datalist
                label="Postcode"
                ng-model="$ctrl.client.postcode"
                selection="$ctrl.postcode"
                url="Postcodes/location"
                fields="['code','townFk']"
                order="code, townFk"
                value-field="code"
                show-field="code"
                rule>
                <tpl-item>
                    {{code}} - {{town.name}} ({{town.province.name}},
                    {{town.province.country.country}})
                </tpl-item>
                <append>
                    <vn-icon-button
                        icon="add_circle"
                        vn-tooltip="New postcode"
                        ng-click="postcode.open()"
                        vn-acl="deliveryAssistant"
                        vn-acl-action="remove">
                    </vn-icon-button>
                </append>
            </vn-datalist>
            <vn-datalist
                vn-id="town"
                label="City"
                ng-model="$ctrl.client.city"
                selection="$ctrl.town"
                url="Towns/location"
                fields="['id', 'name', 'provinceFk']"
                value-field="name">
                <tpl-item>
                    {{name}}, {{province.name}}
                    ({{province.country.country}})
                </tpl-item>
            </vn-datalist>
        </vn-horizontal>
        <vn-horizontal>
            <vn-autocomplete
                vn-id="province"
                label="Province"
                ng-model="$ctrl.client.provinceFk"
                selection="$ctrl.province"
                url="Provinces/location"
                fields="['id', 'name', 'countryFk']"
                rule>
                <tpl-item>{{name}} ({{country.country}})</tpl-item>
            </vn-autocomplete>
            <vn-autocomplete
                vn-id="country"
                label="Country"
                ng-model="$ctrl.client.countryFk"
                url="Countries"
                show-field="country">
            </vn-autocomplete>
        </vn-horizontal>
        <vn-horizontal>
            <vn-textfield
                label="Web user"
                ng-model="$ctrl.client.userName"
                rule>
            </vn-textfield>
            <vn-textfield
                label="Email"
                ng-model="$ctrl.client.email"
                rule
                info="You can save multiple emails">
            </vn-textfield>
        </vn-horizontal>
        <vn-horizontal>
            <vn-check
                label="Is equalizated"
                ng-model="$ctrl.client.isEqualizated">
            </vn-check>
        </vn-horizontal>
    </vn-card>
    <vn-button-bar>
        <vn-submit
            disabled="!watcher.dataChanged()"
            label="Create">
        </vn-submit>
        <vn-button
            class="cancel"
            label="Cancel"
            ui-sref="client.index">
        </vn-button>
    </vn-button-bar>
</form>
<!-- New postcode dialog -->
<vn-geo-postcode
    vn-id="postcode"
    on-response="$ctrl.onResponse($response)">
</vn-geo-postcode>