import { ICellRendererParams } from "ag-grid-community";
import BaseRenderer from "./base-renderer";

export default class HyperlinkRenderer extends BaseRenderer {
    public init(params: ICellRendererParams) {
        super.init(params);
        super.setupGui();
    }

    public setupContentGui(): string {
        let href: string = this.getValueToDisplay();
        if (href?.length > 0) {
            return `
                <ui-button class='ui-btn__ag-grid' size='lg' icon='digi-arrow-circle-right' type='ghost' click.delegate='openLink()'>
                </ui-button>
            `;
        }
        return '';
    }

    openLink() {
        window.open(this.getValueToDisplay(), (this.params as any).linkInNewTab ? "_blank" : "_self");
    }
}