const SourcesColumn = {
    name: 'SourcesColumn',
    components: {
        LinksyButton,
        LinksyDropdown
    },
    props: {
        item: Object,
        expand: Boolean,
        enableTitle: { type: Boolean, default: false},
       	isSelectableAnchor: { type: Boolean, default: false},
       	isSelectableLink: { type: Boolean, default: false},
       	selectedSearchType: String,
        isItemSelected: Function
    },
    directives: {
        'linksy-dom-text': LinksyDOMText,
        'linksy-tooltip': LinksyTooltip,
    },
    data() {
        return {
            active: false,
            opened: false,
        }
    },
    computed: {
        allLinksSelectedInColumn() {
            return this.item.anchors.every(anchor => this.isItemSelected(this.item, anchor, true));
        },
    },
    methods: {
        handleSelectAll() {
            this.$emit("onSelectAll", this.item);
        },
		onSelect(anchor, isTableBased) {
			this.$emit("onSelect", this.item, anchor, isTableBased);
		},
        totalResults() {
            return this.item.anchors.length;
        },
        isArray(value) {
			return Array.isArray(value);
		}
    },
    template: `
    <div class="columns" style="max-height: 350px; overflow-y: auto; overflow-x: hidden;">
        <div class="column expanded">
            <div v-if="isSelectableLink && selectedSearchType !== 'DUPLICATE'">
                <div class="link-anchor-container d-flex align-items-center gap-2" @click="onSelect(item.anchors[0], false)">
                    <span class="linksy-checkbox" :class="{'checked': isItemSelected(item, item.anchors[0], false), 'is-disabled': isProcessing}" />
                    <a class="fs-16px text-primary text-decoration-none text-wrap">
                        {{ item.link }}
                    </a>
                </div>
                <hr class="m-0" />
            </div>

            <div v-if="selectedSearchType === 'DUPLICATE'" class="item-title column-name d-flex justify-content-between align-items-center position-relative w-100" >
                <h4 class="m-0 fw-medium">{{item.source}}</h4>
                <div class="item-direct-links position-absolute">
                    <a :href="item.view_link" target="_blank">View</a>
                    <a :href="item.edit_link" target="_blank">Edit</a>
                </div>
            </div>
            <div class="db-column-content">
                <div v-for="(anchor, index) in item.anchors">
                    <div class="column-name border-bottom-0 d-flex flex-column gap-2" :key="index">
                        <div v-if="isSelectableLink && selectedSearchType !== 'DUPLICATE'" class="item-title d-flex justify-content-between align-items-center position-relative w-100" >
                            <h4 class="m-0 fw-medium text-wrap">{{item.source}}</h4>
                            <div class="item-direct-links position-absolute">
                                <a :href="item.view_link" target="_blank">View</a>
                                <a :href="item.edit_link" target="_blank">Edit</a>
                            </div>
                        </div>
						<h5 class="d-flex align-items-center gap-2 m-0" @click="onSelect(anchor, false)">
							<span v-if="isSelectableAnchor || selectedSearchType === 'DUPLICATE'" class="linksy-checkbox" :class="{'checked': isItemSelected(item, anchor, false), 'is-disabled': isProcessing}" />
							<div v-if="selectedSearchType !== 'DUPLICATE'">
								<span class="fw-medium fs-16px" v-linksy-dom-text>"{{anchor.anchor}}"</span>
							</div>

                            <h5 v-else class="m-0 d-flex align-items-start gap-2">
                                <a :href="anchor.link" target="_blank" class="fw-medium fs-16px text-primary text-wrap text-decoration-none">"{{anchor.link}}"</a >
                            </h5>
						</h5>
                    </div>
                    <hr class="m-0" v-if="index != item.anchors.length - 1" />
                </div>
            </div>

            <div class="sticky-buttons-container position-sticky bottom-0 z-1">
                <hr v-if="item.anchors.length > 1" class="m-0" />

				<div v-if="item.anchors.length > 1" class="action-buttons">
					<linksy-button @click="handleSelectAll" variant="white" class="d-flex align-items-center gap-2">
						<span class="linksy-checkbox" :class="{'checked': allLinksSelectedInColumn}"></span>
						Select all
					</linksy-button>
				</div>
            </div>
        </div>
    </div>
    `,
}