import GlAlert from '../../../../../../base/alert/alert';
import GlIcon from '../../../../../../base/icon/icon';
import GlPopover from '../../../../../../base/popover/popover';
import GlTruncate from '../../../../../../utilities/truncate/truncate';
import { translate } from '../../../../../../../utils/i18n';
import { CONTEXT_ITEM_CATEGORY_ISSUE, CONTEXT_ITEM_CATEGORY_MERGE_REQUEST, CONTEXT_ITEM_CATEGORY_FILE, CONTEXT_ITEM_CATEGORY_LOCAL_GIT } from '../constants';
import { formatMergeRequestId, formatIssueId, formatGitItemSecondaryText, getContextItemIcon, getContextItemTypeLabel } from '../utils';
import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';

var script = {
  name: 'DuoChatContextItemPopover',
  components: {
    GlTruncate,
    GlAlert,
    GlIcon,
    GlPopover
  },
  props: {
    /**
     * The context contextItem to display in the popover.
     */
    contextItem: {
      type: Object,
      required: true
    },
    /**
     * The target element ID for the popover.
     */
    target: {
      type: String,
      required: true
    },
    /**
     * The placement of the popover relative to the target.
     */
    placement: {
      type: String,
      default: 'bottom',
      required: false
    }
  },
  computed: {
    id() {
      const isIssuable = this.contextItem.category === CONTEXT_ITEM_CATEGORY_ISSUE || this.contextItem.category === CONTEXT_ITEM_CATEGORY_MERGE_REQUEST;
      return isIssuable ? this.contextItem.metadata.iid : null;
    },
    formattedId() {
      switch (this.contextItem.category) {
        case CONTEXT_ITEM_CATEGORY_ISSUE:
          return formatIssueId(this.id);
        case CONTEXT_ITEM_CATEGORY_MERGE_REQUEST:
          return formatMergeRequestId(this.id);
        default:
          return '';
      }
    },
    title() {
      return this.contextItem.metadata.title || '';
    },
    filePath() {
      return this.contextItem.category === CONTEXT_ITEM_CATEGORY_FILE ? this.contextItem.metadata.relativePath || '' : null;
    },
    filePathArray() {
      var _this$filePath;
      return (_this$filePath = this.filePath) === null || _this$filePath === void 0 ? void 0 : _this$filePath.split('/');
    },
    gitDetails() {
      return this.contextItem.category === CONTEXT_ITEM_CATEGORY_LOCAL_GIT ? formatGitItemSecondaryText(this.contextItem) : null;
    },
    isEnabled() {
      return this.contextItem.metadata.enabled !== false;
    },
    disabledMessage() {
      return Array.isArray(this.contextItem.metadata.disabledReasons) && this.contextItem.metadata.disabledReasons.length > 0 ? this.contextItem.metadata.disabledReasons.join(', ') : translate('DuoChatContextItemPopover.DisabledReason', 'This item is disabled');
    },
    iconName() {
      return getContextItemIcon(this.contextItem);
    },
    itemTypeLabel() {
      return getContextItemTypeLabel(this.contextItem);
    }
  },
  methods: {
    translate
  }
};

/* script */
const __vue_script__ = script;

/* template */
var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('gl-popover',{attrs:{"target":_vm.target,"triggers":"hover focus","placement":_vm.placement,"title":_vm.title,"custom-class":"gl-duo-chat-item-popover"},scopedSlots:_vm._u([{key:"title",fn:function(){return [_c('div',[_c('div',{staticClass:"gl-heading-3 gl-mb-1 gl-mt-2 gl-leading-1",attrs:{"data-testid":"chat-context-popover-title"}},[_vm._v("\n        "+_vm._s(_vm.title)+"\n      ")]),_vm._v(" "),(_vm.itemTypeLabel)?_c('div',{staticClass:"gl-font-normal gl-text-subtle"},[_vm._v(_vm._s(_vm.itemTypeLabel))]):_vm._e()])]},proxy:true}])},[_vm._v(" "),_c('div',[(_vm.filePath)?_c('div',[_c('gl-icon',{attrs:{"name":"document","size":12,"variant":"subtle"}}),_vm._v(" "),_c('span',{staticClass:"gl-break-all"},[_vm._v(_vm._s(_vm.contextItem.metadata.project))]),_vm._v(" "),_vm._l((_vm.filePathArray),function(pathPart,index){return _c('span',{key:pathPart,staticClass:"gl-break-all"},[_vm._v(_vm._s(pathPart)+_vm._s(index + 1 < _vm.filePathArray.length ? '/' : ''))])})],2):(_vm.gitDetails)?_c('div',{staticClass:"gl-flex gl-items-center",attrs:{"data-testid":"git-details"}},[_c('gl-icon',{staticClass:"gl-mr-1 gl-shrink-0",attrs:{"name":_vm.iconName,"size":12,"variant":"subtle"}}),_vm._v(" "),_c('gl-truncate',{staticClass:"gl-min-w-0",attrs:{"text":_vm.gitDetails}})],1):_c('div',[(_vm.iconName)?_c('gl-icon',{attrs:{"name":_vm.iconName,"size":12,"variant":"subtle"}}):_vm._e(),_vm._v(" "),_c('span',{staticClass:"gl-break-all"},[_vm._v(_vm._s(_vm.contextItem.metadata.project))]),_vm._v(" "),(_vm.id)?_c('span',{staticClass:"gl-break-all"},[_vm._v(_vm._s(_vm.formattedId))]):_vm._e()],1),_vm._v(" "),(!_vm.isEnabled)?_c('gl-alert',{staticClass:"gl-mb-1 gl-mt-3 gl-p-4 gl-text-sm",attrs:{"variant":"danger","data-testid":"chat-context-popover-disabled","dismissible":false,"show-icon":false}},[_vm._v("\n      "+_vm._s(_vm.disabledMessage)+"\n    ")]):_vm._e()],1)])};
var __vue_staticRenderFns__ = [];

  /* style */
  const __vue_inject_styles__ = undefined;
  /* scoped */
  const __vue_scope_id__ = undefined;
  /* module identifier */
  const __vue_module_identifier__ = undefined;
  /* functional template */
  const __vue_is_functional_template__ = false;
  /* style inject */
  
  /* style inject SSR */
  
  /* style inject shadow dom */
  

  
  const __vue_component__ = __vue_normalize__(
    { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
    __vue_inject_styles__,
    __vue_script__,
    __vue_scope_id__,
    __vue_is_functional_template__,
    __vue_module_identifier__,
    false,
    undefined,
    undefined,
    undefined
  );

export default __vue_component__;
