<template>
  <div :class="[`tw-grid tw-grid-cols-1 md:tw-grid-cols-[${label_width}px_auto] xl:tw-grid-cols-[${label_width}px_auto] tw-gap-[10px]`]">
    <label v-if="label_width!=0" class="tw-mb-[10px] tw-font-normal" :for="select.id"><span>{{ $t(select.label)
    }}<span v-if="select.required" class="required">*</span></span></label>
    <select :class="[`tw-pr-[40px] tw-min-w-[${select_width}px]`,validation ? '' : 'tw-border-error-default']" :name="select.id" v-model="value"
      @change="inputVal">
      <option :value="0">{{ $t("Select option") }}</option>
      <option v-for="{ id, name } in selectList" :key="id" :value="id">
        {{ name }}
      </option>
    </select>
  </div>
</template>
<script>
export default {
  name: "ElementSelectNew",
  props: {
    select: {
      type: Object,
    },
    selectList: {
      type: Array,
    },
    default: {
      type: String,
    },
    validation: {
      type: Boolean,
    },
    isRow: {
      type: Boolean,
      default: () => false,
    },
    itemsCenter: {
      type: Boolean,
      default: () => false,
    },
    labelWidth:{
      type: Number,
      default: () => 90,
    },
    selectWidth:{
      type: Number,
      default: () => 200,
    }
  },
  data() {
    return {
      value: this.default ?? null,
      label_width: this.labelWidth,
      select_width: this.selectWidth
    };
  },
  mounted() { },
  watch: {
    default: {
      handler: function () {
        this.value = this.default;
      },
    },
    labelWidth:{
      handler: function () {
        this.label_width = this.labelWidth;
      },
    },
    selectWidth:{
      handler: function () {
        this.select_width = this.selectWidth;
      },
    }
  },
  methods: {
    inputVal() {
      this.$emit("change", this.value);
    },
  },
};
</script>
<style lang="scss" scoped>
select {
  -moz-appearance: none;
  /* Firefox */
  -webkit-appearance: none;
  /* Safari and Chrome */
  appearance: none;
  background-image: url("~/assets/svg/down-arrow.svg");
  background-size: 9px 6px;
  background-position: right 20px center;
  background-repeat: no-repeat;
}
</style>