/**
 * Add Source Modal Component
 * Modal dialog for adding new online sources
 * Shared between Model and Material tabs
 */
Vue.component('add-source-modal', {
  props: {
    type: {
      type: String,
      required: true,
      validator: function(value) {
        return ['model', 'material', 'door', 'handle'].indexOf(value) !== -1;
      }
    }
  },
  computed: {
    modalId() {
      return `${this.type}SourceOnline`;
    },
    
    nameInputId() {
      return `${this.type}AddNameInput`;
    },
    
    urlInputId() {
      return `${this.type}AddUrlInput`;
    }
  },
  methods: {
    translated(key) {
      return this.$root.translated(key);
    },
    
    handleAddSource() {
      this.$emit('add-source');
    }
  },
  template: `
    <div class="modal fade" tabindex="-1" role="dialog" :id="modalId">
      <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content custom-menu">
          <div class="modal-header">
            <h5 class="modal-title">{{ translated('addSource') }}</h5>
            <button 
              type="button" 
              class="btn btn-sm btn-icon-only btn-danger" 
              data-dismiss="modal"
              aria-label="Close"
            >
              <i class="modus-icons">close</i>
            </button>
          </div>
          <div class="modal-body">
            <div class="form-group">
              <label :for="nameInputId">{{ translated('name') }}</label>
              <input 
                class="form-control" 
                :id="nameInputId" 
                :placeholder="translated('giveName')"
              />
              <label :for="urlInputId" class="mt-3">{{ translated('urlPath') }}</label>
              <input 
                class="form-control" 
                :id="urlInputId" 
                placeholder="https://..."
              />
            </div>
            <div class="d-flex my-3">
              <button 
                type="button" 
                class="btn btn-primary ml-auto"
                @click="handleAddSource"
              >
                {{ translated('add') }}
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>
  `
});
