import { h } from "@stencil/core";
import { ColumnRenderer } from '../column/column.renderer';
export class RenderCell {
    constructor() {
        /**
         * Renderer to use for cell content when the selected cell conditions are met
         * (row: RowData, field: ColumnDefinition, rowIndex?: number) => any;
         */
        this.cell = this.renderCell.bind(this);
        /**
         * Test function for when to use this renderer
         * (column: ColumnDefinition, rowIndex: number, columnIndex: number) => boolean;
         */
        this.when = () => true;
    }
    componentDidLoad() {
        this.anjCellControlDidLoad.emit();
    }
    renderCell({ column, columnIndex, classList, offset, renderer, row, rowIndex }) {
        const attrs = ColumnRenderer.columnAttributes(column, columnIndex, row);
        const refFn = r => column.initCell(r, offset);
        if (this.template) {
            return h("td", Object.assign({}, attrs, { class: classList, ref: r => renderer.cellTemplate(r, offset, column, row, rowIndex, this.template) }));
        }
        else if (this.formatter) {
            return h("td", Object.assign({}, attrs, { class: classList, innerHTML: this.formatter(row, column, rowIndex), ref: refFn }));
        }
        else {
            return h("td", Object.assign({}, attrs, { class: classList, ref: refFn }), this.renderer(row, column, rowIndex));
        }
    }
    static get is() { return "anj-render-cell"; }
    static get properties() { return {
        "formatter": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "CellFormatter",
                "resolved": "(row: RowData, field: ColumnDefinition, rowIndex?: number) => string",
                "references": {
                    "CellFormatter": {
                        "location": "import",
                        "path": "../table.types"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Formatter for cell data"
            }
        },
        "renderer": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "CellRenderer",
                "resolved": "(row: RowData, field: ColumnDefinition, rowIndex?: number) => any",
                "references": {
                    "CellRenderer": {
                        "location": "import",
                        "path": "../table.types"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Renderer for cell data"
            }
        },
        "template": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Name of the template to use"
            },
            "attribute": "template",
            "reflect": false
        },
        "cell": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "CellRenderFn",
                "resolved": "(props: CellProps) => any",
                "references": {
                    "CellRenderFn": {
                        "location": "import",
                        "path": "../table.types"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Renderer to use for cell content when the selected cell conditions are met\n(row: RowData, field: ColumnDefinition, rowIndex?: number) => any;"
            },
            "defaultValue": "this.renderCell.bind(this)"
        },
        "when": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "CellRenderTest",
                "resolved": "(column: ColumnDefinition, rowIndex: number, columnIndex: number) => boolean",
                "references": {
                    "CellRenderTest": {
                        "location": "import",
                        "path": "../table.types"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": "Test function for when to use this renderer\n(column: ColumnDefinition, rowIndex: number, columnIndex: number) => boolean;"
            },
            "defaultValue": "() => true"
        }
    }; }
    static get events() { return [{
            "method": "anjCellControlDidLoad",
            "name": "anjCellControlDidLoad",
            "bubbles": true,
            "cancelable": true,
            "composed": true,
            "docs": {
                "tags": [],
                "text": "Emitted when the selector has been created."
            },
            "complexType": {
                "original": "void",
                "resolved": "void",
                "references": {}
            }
        }]; }
}
