<vn-crud-model
    url="Zones"
    data="zones"
    order="name"
    auto-load="true">
</vn-crud-model>
<form name="form">
    <vn-card class="vn-w-md vn-pa-lg">
        <vn-horizontal>
            <vn-autocomplete 
                vn-one
                vn-id="client"
                required="true"
                url="Clients"
                label="Client"
                show-field="name"
                value-field="id"
                search-function="{or: [{id: $search}, {name: {like: '%'+ $search +'%'}}]}"
                ng-model="$ctrl.clientId"
                initial-data="$ctrl.clientId"
                order="id">
                <tpl-item>
                    #{{id}} - {{::name}}
                </tpl-item>
            </vn-autocomplete>
            <vn-autocomplete vn-one
                required="true"
                url="Warehouses"
                label="Warehouse"
                show-field="name"
                value-field="id"
                ng-model="$ctrl.warehouseId">
            </vn-autocomplete>
        </vn-horizontal>
        <vn-horizontal>
            <vn-autocomplete 
                vn-one
                required="true"
                data="$ctrl.addresses"
                label="Address"
                show-field="nickname"
                value-field="id" 
                ng-model="$ctrl.addressId"
                order="isActive DESC">
                <tpl-item class="address" ng-class="::{inactive: !isActive}">
                    <span class="inactive" translate>{{::!isActive ? '(Inactive)' : ''}}</span>
                    {{::nickname}}
                    <span ng-show="city || province || street">
                        , {{::street}}, {{::city}}, {{::province.name}} - {{::agencyMode.name}}
                    </span>
                </tpl-item>
                <append>
                    <vn-icon-button
                        ui-sref="client.card.address.edit({id: $ctrl.clientId, addressId: $ctrl.addressId})"
                        icon="edit"
                        vn-tooltip="Edit address">
                    </vn-icon-button>
                </append>
            </vn-autocomplete>
            <vn-textfield
                vn-one
                label="Alias"
                required="true"
                ng-model="$ctrl.ticket.nickname">
            </vn-textfield>
        </vn-horizontal>
        <vn-horizontal>
            <vn-autocomplete 
                vn-one
                required="true"
                url="Companies"
                label="Company"
                show-field="code"
                value-field="id"
                ng-model="$ctrl.ticket.companyFk"
                initial-data="$ctrl.ticket.companyFk">
            </vn-autocomplete>
            <vn-autocomplete
                vn-one
                vn-id="agencyMode"
                url="AgencyModes/byWarehouse"
                label="Agency"
                show-field="name"
                value-field="id"
                ng-model="$ctrl.agencyModeId"
                where-function="$ctrl.agencyModeWhere()">
            </vn-autocomplete>
            <vn-autocomplete
                vn-one
                required="true"
                url="Zones/includingExpired"
                label="Zone"
                show-field="name"
                value-field="id"
                ng-model="$ctrl.zoneId"
                vn-acl="productionBoss"
                where-function="$ctrl.zoneWhere()">
                <tpl-item>
                    <span>{{::name}} - Max. {{::hour | date: 'HH:mm'}} h.</span>
                </tpl-item>
            </vn-autocomplete>
        </vn-horizontal>
        <vn-horizontal>
            <vn-date-picker
                vn-one
                required="true"
                label="Shipped" 
                ng-model="$ctrl.shipped">
            </vn-date-picker>
            <vn-input-time
                vn-one
                required="true"
                label="Shipped hour" 
                ng-model="$ctrl.shipped">
            </vn-input-time>
            <vn-date-picker
                vn-one
                required="true"
                label="Landed" 
                ng-model="$ctrl.landed">
            </vn-date-picker>
        </vn-horizontal>
    </vn-card>
</form>