<vn-crud-model
    auto-load="true"
    url="Warehouses"
    data="warehouses">
</vn-crud-model>
<vn-descriptor-content
    module="item"
    description="$ctrl.item.name"
    summary="$ctrl.$.summary">
    <slot-menu>
        <vn-item
            ng-click="regularize.show()"
            name="regularizeStock"
            translate>
            Regularize stock
        </vn-item>
        <vn-item
            ng-click="clone.show()"
            name="cloneItem"
            translate>
            Clone
        </vn-item>
    </slot-menu>
    <slot-before>
        <div class="photo" text-center>
            <img vn-id="photo"
                ng-src="{{$root.imagePath('catalog', '200x200', $ctrl.item.id)}}"
                zoom-image="{{$root.imagePath('catalog', '1600x900', $ctrl.item.id)}}"
                on-error-src/>
            <vn-float-button ng-click="uploadPhoto.show('catalog', $ctrl.item.id)"
                icon="edit"
                vn-visible-by="catalogPhotos">
            </vn-float-button>
        </div>
        <vn-horizontal class="item-state">
            <vn-one>
                <p translate>Visible</p>
                <p>{{$ctrl.visible | dashIfEmpty}}</p>
            </vn-one>
            <vn-one>
                <p translate>Available</p>
                <p>{{$ctrl.available | dashIfEmpty}}</p>
            </vn-one>
            <vn-one>
                <p>
                    <vn-icon
                        ng-if="$ctrl.showIcon"
                        icon="info_outline"
                        vn-tooltip="{{$ctrl.warehouseText}}"
                        pointer>
                    </vn-icon>
                </p>
            </vn-one>
        </vn-horizontal>
    </slot-before>
    <slot-body>
        <div class="attributes">
            <vn-label-value
                label="Buyer">
                <span
                    ng-click="workerDescriptor.show($event, $ctrl.item.itemType.worker.id)"
                    class="link">
                    {{$ctrl.item.itemType.worker.user.name}}
                </span>
            </vn-label-value>
            <vn-label-value
                label="{{$ctrl.item.tag5}}"
                ng-if="$ctrl.item.value5"
                value="{{$ctrl.item.value5}}">
            </vn-label-value>
            <vn-label-value
                label="{{$ctrl.item.tag6}}"
                ng-if="$ctrl.item.value6"
                value="{{$ctrl.item.value6}}">
            </vn-label-value>
            <vn-label-value
                label="{{$ctrl.item.tag7}}"
                ng-if="$ctrl.item.value7"
                value="{{$ctrl.item.value7}}">
            </vn-label-value>
            <vn-label-value
                label="{{$ctrl.item.tag8}}"
                ng-if="$ctrl.item.value8"
                value="{{$ctrl.item.value8}}">
            </vn-label-value>
        </div>
        <div class="icons">
            <vn-icon
                vn-tooltip="Item inactive"
                icon="icon-unavailable"
                ng-if="$ctrl.item.isActive == false">
            </vn-icon>
        </div>
        <div class="quicklinks">
            <div ng-transclude="btnOne"></div>
            <div ng-transclude="btnTwo"></div>
            <div ng-transclude="btnThree"></div>
        </div>
    </slot-body>
</vn-descriptor-content>
<vn-dialog
    vn-id="regularize"
    on-open="$ctrl.warehouseFk = $ctrl.vnConfig.warehouseFk"
    on-close="$ctrl.clearRegularizeDialog()"
    on-accept="$ctrl.saveRegularize()"
    message="Regularize stock">
    <tpl-body>
        <vn-textfield
            label="Type the visible quantity"
            ng-model="$ctrl.quantity"
            vn-focus>
        </vn-textfield>
        <vn-autocomplete
            label="Warehouse"
            ng-model="$ctrl.warehouseFk"
            data="warehouses"
            show-field="name"
            value="id">
        </vn-autocomplete>
    </tpl-body>
    <tpl-buttons>
        <input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
        <button response="accept" translate>Save</button>
    </tpl-buttons>
</vn-dialog>
<vn-confirm
    vn-id="clone"
    on-accept="$ctrl.onCloneAccept()"
    question="Do you want to clone this item?"
    message="All it's properties will be copied">
</vn-confirm>
<vn-worker-descriptor-popover
    vn-id="workerDescriptor">
</vn-worker-descriptor-popover>
<vn-popup vn-id="summary">
    <vn-item-summary item="$ctrl.item"></vn-item-summary>
</vn-popup>

<!-- Upload photo dialog -->
<vn-upload-photo
    vn-id="uploadPhoto"
    on-response="$ctrl.onUploadResponse()">
</vn-upload-photo>