<template>
  <div class="order-product-container mb-s">
    <BaseText class="product-name mb-s">
      {{ title }}
    </BaseText>

    <div class="inputs">
      <input-number
        :model-name="`quantity-${title}`"
        class="input-item quantity"
        :form-id="formId"
        :parent="parent"
        :label="$_tr('form.quantity')"
        :default-value="0"
        :rules="['required', 'min:0']"
        :min="0"
        :use-asterisk="false"
        :callback="value => +value"
        @onDataChange="handleQuantityChange"
      />

      <input-hidden
        model-name="title"
        :form-id="formId"
        :default-value="title"
        :rules="['required']"
      />

      <input-hidden
        model-name="category"
        :form-id="formId"
        :parent="parent"
        :default-value="category"
        :rules="['required']"
      />
    </div>
  </div>
</template>

<script>
import { BaseText } from 'inside-collection/atoms'

export default {
  name: 'SelectProductQuantity',
  $_i18nRootPath: 'customs.SUPPLIES.order',
  components: {
    BaseText
  },
  props: {
    uuid: {
      type: String,
      required: true
    },
    title: {
      type: String,
      required: true
    },
    category: {
      type: String,
      required: true
    },
    formId: {
      type: String,
      required: true
    },
    parent: {
      type: String,
      required: true
    }
  },
  methods: {
    handleQuantityChange(data) {
      this.$emit('onQuantityChange', {
        uuid: this.uuid,
        title: this.title,
        quantity: data.value
      })
    }
  }
}
</script>

<style lang="scss">
.order-product-container {
  display: inline-flex;
  width: 100%;
  justify-content: space-between;
  align-items: flex-end;

  .inputs {
    display: flex;

    .input-item {
      width: 56px;

      &.quantity {
        margin-right: var(--spacing-s);
        width: 64px;
      }
    }
  }
}
</style>
