import AComponent from '../a.js';
import Component from '../component.js';
import DivComponent from '../div.js';
import ImgComponent from '../img.js';
import CoEuiButton from './eui-button.js'
import CoEuiIconSvg from './eui-icon-svg.js';
import CoEuiLabel from './eui-label.js';


export default class CoEuiFilePreview extends Component {
    constructor(parent) {
        let selector = 'eui-file-preview';
        super(parent, selector);
        //https://citnet.tech.ec.europa.eu/CITnet/stash/projects/CSDR/repos/eui/browse/packages/components/eui-file-upload/file-preview/file-preview.component.html?at=master
    }

    get fileUploadPreviewDivCO() {
        return new DivComponent(this.currentPath).addPredicateClassContains('file-upload__preview');
    }
    get leftPreviewDivCO() {
        return new DivComponent(this.fileUploadPreviewDivCO).addPredicateClassContains('eui-file-upload__preview--left');
    }
    get leftPreviewImageDivCO() {
        return new DivComponent(this.leftPreviewDivCO).addPredicateClassContains('eui-file-upload__preview--left__image');
    }
    async hasPreviewAsImage() {
        return await (await this.leftPreviewImageDivCO.element()).isExisting();
    }
    get imageCO() {
        return new ImgComponent(this.leftPreviewImageDivCO);
    }
    async hasImage() {
        return await (await this.imageCO.element()).isExisting();
    }
    get previewAsImageSpanCO() {
        return new CoEuiIconSvg(this.leftPreviewImageDivCO);
    }
    async hasPreviewData() {
        return await (await this.previewAsImageSpanCO.element()).isExisting();
    }
    get loadingContainerDivCO() {
        return new DivComponent(this.leftPreviewImageDivCO).addPredicateClassContains('loading-container');
    }
    async isLoading() {
        return await (await this.loadingContainerDivCO.element()).isExisting();
    }
    get spinnerEuiIconCO() {
        return new CoEuiIconSvg(this.loadingContainerDivCO).addPredicateAttributeContains('size', '2xl');
    }
    get fileUploadPreviewIconDivCO() {
        return new DivComponent(this.leftPreviewDivCO).addSelectorPredicate('[not(contains(@class, "eui-file-upload__preview--left__image")) and not(contains(@class, "loading-container"))]');
    }
    async hasPreviewAsIcon() {
        return await (await this.fileUploadPreviewIconDivCO.element()).isExisting();
    }
    get previewAsIconSpanCO() {
        return new CoEuiIconSvg(this.fileUploadPreviewIconDivCO).addPredicateClassContains('eui-u-mr-s');
    }
    get fileUploadPreviewFilenameDivCO() {
        return new DivComponent(this.leftPreviewDivCO).addPredicateClassContains('eui-file-upload__preview--left__filename');
    }
    async isFilenameDisplayed() {
        return await (await this.fileUploadPreviewFilenameDivCO.element()).isExisting();
    }
    get previewFilenameACO() {
        return new AComponent(this.fileUploadPreviewFilenameDivCO).addPredicateClassContains('eui-u-text-link');
    }
    async isItemsClickable() {
        return await (await this.previewFilenameACO.element()).isExisting();
    }
    get rightPreviewDivCO() {
        return new DivComponent(this.fileUploadPreviewDivCO).addPredicateClassContains('eui-file-upload__preview--right');
    }
    get fileUploadPreviewFilesizeDivCO() {
        return new DivComponent(this.rightPreviewDivCO).addPredicateClassContains('eui-u-text-no-wrap');
    }
    async isFilesizeDisplayed() {
        return await (await this.fileUploadPreviewFilesizeDivCO.element()).isExisting();
    }
    get fileUploadPreviewFiletypeDivCO() {
        return new DivComponent(this.rightPreviewDivCO).byChildSelector('span');
    }
    async isFiletypeDisplayed() {
        return await (await this.fileUploadPreviewFiletypeDivCO.element()).isExisting();
    }
    get filetypeLabelCO() {
        return new CoEuiLabel(this.fileUploadPreviewFiletypeDivCO);
    }
    get fileUploadPreviewDeleteActionDivCO() {
        return new DivComponent(this.rightPreviewDivCO).byChildSelector('button');
    }
    get fileUploadRemoveBtnCO() {
        return new CoEuiButton(this.fileUploadPreviewDeleteActionDivCO);
    }
    get closeIconSvgCO() {
        return new CoEuiIconSvg(this.fileUploadRemoveBtnCO);
    }
}


