<template>
    <div>
        <div class="jams-list">
            <div class="jams-list__header">
                <div class="id">ID</div>
                <div class="vol">Объем, мл</div>
            </div>
            <div class="jams-list__add">
                <div class="id"><input type="text" v-model.trim="addId" /></div>
                <div class="vol">
                    <input type="number" v-model.number="addVol" />
                </div>
                <div class="add"><button @click="$emit('addJam', addId, addVol); addId=''; addVol=0;">+</button></div>
            </div>
            <div
                v-for="(jam, index) in jams"
                :key="jam.id"
                class="jams-list__row"
            >
                <div class="id">{{ jam.id }}</div>
                <div class="vol">{{ jam.vol }}</div>
                <div class="remove" @click="$emit('removeJam', index)">
                    &times;
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    props: ["jams"],
    emits: ["removeJam", "addJam"],
    data() {
        return {
            addId: "",
            addVol: 0,
        };
    },
};
</script>

<style lang="scss" scoped>
.jams-list {
    &__header,
    &__add,
    &__row {
        display: flex;
        padding: 0.5rem 1rem;
        border-bottom: 1px solid #ccc;

        &:last-child {
            border-bottom: none;
        }

        .id {
            width: 7rem;
            flex-shrink: 0;
        }
        .vol {
            flex-grow: 1;
        }
    }
    &__header {
        background: #ccc;
    }
    &__add {
        input {
            width: 100%;
            padding: 0.3rem 0.5rem;
            font-size: 1.15rem;
        }
        .add {
            flex-shrink: 0;
            button {
                appearance: none;
                width: 100%;
                padding: 0.3rem 0.5rem;
            font-size: 1.15rem;
        }
        }
    }
    &__row {
        .remove {
            flex-shrink: 0;
            width: 1rem;
            cursor: pointer;
            &:hover {
                color: #f00;
            }
        }
    }
}
</style>
