<template>
    <div :class="curClassName" :style="curStyle">
        <i-input size='large' :prefix='defaultIcon' v-model="curValue" :type="defaultType" :disabled="disabled"
            :readonly="readonly" :placeholder="curCaption">
        </i-input>
    </div>
</template>

<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator';

@Component({
})
export default class AppLoginInput extends Vue {

    /**
     * 模型
     *
     * @type {any}
     * @memberof AppLoginInput
     */
    @Prop() public layoutModelDetails: any;

    /**
     * 值
     *
     * @type {string}
     * @memberof AppLoginInput
     */
    @Prop() public value!: string;

    /**
     * 名称
     *
     * @type {string}
     * @memberof AppLoginInput
     */
    @Prop() public name!: string;

    /**
     * 默认图标
     *
     * @type {string}
     * @memberof AppLoginInput
     */
    @Prop() public defaultIcon?: string;

    /**
     * 默认类型
     *
     * @type {string}
     * @memberof AppLoginInput
     */
    @Prop() public defaultType?: string;

    /**
     * 下标
     *
     * @type {number}
     * @memberof AppLoginInput
     */
    @Prop() public index?: number;

    /**
     * 项名称
     *
     * @type {*}
     * @memberof AppLoginInput
     */
    get itemName() {
        return (this.index || this.index === 0) ? `${this.name}_${this.index}` : this.name;
    }

    /**
     * 标题
     *
     * @memberof AppLoginInput
     */
    get curCaption() {
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            return layoutModel.caption;
        }
    }

    /**
     * 当前容器样式
     * 
     * @memberof AppLoginInput
     */
    get curStyle() {
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            return layoutModel.getElementStyle();
        }
    }

    /**
     * 类名
     *
     * @memberof AppLoginInput
     */
    get curClassName() {
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            return `app-login-input ${this.itemName} ${layoutModel.sysCss}`;
        }
    }

    /**
     * 禁用
     * 
     * @memberof AppLoginInput
     */
    get disabled() {
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            return layoutModel.disabled;
        }
    }

    /**
     * 只读
     * 
     * @memberof AppLoginInput
     */
    get readonly() {
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            return layoutModel.readonly;
        }
    }

    /**
     * 当前值
     *
     * @type {any}
     * @memberof AppLoginInput
     */
    get curValue() {
        return this.value;
    }

    /**
     * 值变化
     *
     * @memberof AppLoginInput
     */
    set curValue(val: any) {
        this.$emit('valueChange', { name: this.name, value: val });
    }

}
</script>
<style lang="scss">
@import "./app-login-input.scss";
</style>