<template>
  <b-modal id="sales-consultant-crm" :no-close-on-backdrop="true" size="sm">
    <template v-slot:modal-header="{  }">
      <b-container>
        <b-row class="d-flex justify-content-between mb-2 mt-1">
          <b-col class="d-flex modal-text-color ml-2" cols="8">
            <div class="d-flex align-self-center justify-content-center rounded-div mr-2 mt-1">
              <font-awesome-icon icon="exclamation-circle" class="align-self-center" />
            </div>
            <div class="pt-1">
              <div class="akkurat-bold max-header-text">CRM</div>
            </div>
          </b-col>
          <b-col class="d-flex justify-content-end mr-2 mt-1">
            <span class="close-icon" @click="closeModal">
              <font-awesome-icon icon="times" class="align-self-center" />
            </span>
          </b-col>
        </b-row>
      </b-container>
    </template>
      <b-container>
        <b-row class="justify-content-center mb-2">
          <b-col cols="12">
            <div class="text-left label">
              <label for="marketDefinition">Motivos</label>
            </div>

            <b-form-select
                v-model="selectedMotive"
                :options="motives"
                id="marketDefinition"
                class="radius-theme"
              />
      
          </b-col>
        </b-row>
        <b-row>
          <b-col cols="12">
            <label>Anotação:</label>
            <b-form-textarea no-resize v-model="description">
            </b-form-textarea>
          </b-col>
        </b-row>
      </b-container>

    <template v-slot:modal-footer="{  }">
      <b-container>
        <b-row>
          <b-col cols="12" class="d-flex justify-content-center my-3 px-3">
            <b-button
                class="mr-2 btn shadow-none border-0 btn-default btn-red"
                @click="closeModal"
              >
                Cancelar
            </b-button>
            
            <b-button
              class="mr-2 btn shadow-none border-0 btn-default"
              @click="done"
            >
              Salvar
            </b-button>
          </b-col>
        </b-row>
      </b-container>
    </template>
  </b-modal>
</template>

<script>
import SalesConsultantStatusService from "@/services/resources/SalesConsultantStatusService";
import SalesConsultantCrmService from "@/services/resources/SalesConsultantCrmService";

const service = SalesConsultantCrmService.build();

export default {
  name: 'accept-credit-card',
  props:{
    sales_consultant_id:{
      type: Number
    }
  },
  data: () => ({
    selectedMotive: 'SELECIONE UMA OPÇÃO',
    motives: [],
    description: ''
  }),
  methods: {
    closeModal() {
      this.$bvModal.hide('sales-consultant-crm');
    },
     done(){

      if(this.selectedMotive != 'SELECIONE UMA OPÇÃO'){

        let data = {
          sales_consultant_id: this.sales_consultant_id,
          motive: this.selectedMotive,
          description: this.description
        };

        service
        .create(data)
        .then(response => {
          this.description = '';
          this.selectedMotive = 'SELECIONE UMA OPÇÃO';
          this.$bvModal.hide('sales-consultant-crm');
        })
        .catch(err => {
          
        });
      }
    },
    load(){
      service
        .search()
        .then(response => {
          this.motives = response;
          this.motives.unshift('SELECIONE UMA OPÇÃO');
        })
        .catch(err => {
          
        });
    }
    
  },
  mounted(){
    this.load();
  }
};
</script>

<style scoped lang="scss">
@import '../../../../../assets/css/main.scss';


.item-attachment{
  height: 150px;
  overflow: hidden;
  cursor: pointer;
}

.modal-text-color {
  color: #3E3E3E;
}

.min-header-text {
  letter-spacing: 0.2px;
  font-size: 9px;
}

.max-header-text {
  letter-spacing: 0.4px;
  font-size: 16px;
}


.close-icon {
  color: #979797;
  font-size: 20px;
}

.btn-default {
  border-radius: 20px;
  width: 100%;
  max-width: 192px;
  height: 35px;
  background: #278937;
}

.btn-red {
  background: #CB2D2D;
}

</style>
