import { h } from "@stencil/core";
import { debounce } from "lodash";
import { filterParams, propsParams, clearParams } from "./terminal-orders-list-params-state";
import { StyledHost } from "../../ui-components";
import { TerminalOrderStatus, TerminalOrderType } from "../../api";
import { convertToLocal, convertToUTC } from "../../utils/utils";
import { filterMenu, filterParam } from "../../styles/parts";
export class JustifiTerminalOrdersListFilters {
    constructor() {
        this.setParamsOnChange = (name, value) => {
            filterParams[name] = value;
        };
        this.handleDateInput = (name, value) => {
            const utcDate = convertToUTC(value, { setExactTime: true });
            this.setParamsOnChange(name, utcDate);
        };
    }
    componentWillLoad() {
        this.debouncedSetParamsOnChange = debounce(this.setParamsOnChange, 300);
        const propsToSet = {
            order_status: this.orderStatus,
            order_type: this.orderType,
            created_after: this.createdAfter,
            created_before: this.createdBefore,
            company_name: this.companyName
        };
        Object.entries(propsToSet).forEach(([key, value]) => {
            if (value) {
                propsParams[key] = value;
            }
        });
    }
    get terminalOrderStatusOptions() {
        return [
            { label: 'All', value: '' },
            { label: 'Created', value: TerminalOrderStatus.created },
            { label: 'Completed', value: TerminalOrderStatus.completed },
            { label: 'Submitted', value: TerminalOrderStatus.submitted },
            { label: 'In Progress', value: TerminalOrderStatus.in_progress },
            { label: 'On Hold', value: TerminalOrderStatus.on_hold },
            { label: 'Canceled', value: TerminalOrderStatus.canceled }
        ];
    }
    get terminalOrderTypeOptions() {
        return [
            { label: 'All', value: '' },
            { label: 'Boarding Only', value: TerminalOrderType.boardingOnly },
            { label: 'Boarding Shipping', value: TerminalOrderType.boardingShipping },
        ];
    }
    render() {
        const filterMenuParams = Object.assign({}, filterParams);
        return (h(StyledHost, { key: '287baf0a2de1287195105adbebd501d2bccd21d7' }, h("table-filters-menu", { key: 'b0112de1075f459780d01528f017780c9ceedb18', params: filterMenuParams, clearParams: clearParams, part: filterMenu }, h("div", { key: 'f9acabaf7d2edbe4eabb81edc92b2378ef563012', class: "grid-cols-2 gap-3 p-1" }, h("div", { key: 'e76d3b3771b8084fc5f6bf32fac2c75c3da87abb', class: "p-2" }, h("form-control-select", { key: '9c687e7202a310500e85d3cbce29268ac04cdd4a', name: "order_status", label: "Order Status", options: this.terminalOrderStatusOptions, inputHandler: this.setParamsOnChange, defaultValue: this.orderStatus || filterParams.order_status || '', disabled: !!this.orderStatus, part: filterParam })), h("div", { key: '345ebc972663899a456a7a660863cd81a9770a87', class: "p-2" }, h("form-control-select", { key: '26879377755e826a1d1f236ab5e54a22415451e8', name: "order_type", label: "Order Type", options: this.terminalOrderTypeOptions, inputHandler: this.setParamsOnChange, defaultValue: this.orderType || filterParams.order_type || '', disabled: !!this.orderType, part: filterParam })), h("div", { key: '2a7df2b8c9a3bfbbd76cca1a732c01521b08dd34', class: "p-2" }, h("form-control-date", { key: '3fbceb80eaf7ae48e02221961317d8c77ec2c5a5', name: "created_after", label: "Created After", inputHandler: this.handleDateInput, defaultValue: convertToLocal(this.createdAfter, { showInputDateTime: true }) ||
                convertToLocal(filterParams.created_after, { showInputDateTime: true }), showTime: true, disabled: !!this.createdAfter, part: filterParam })), h("div", { key: '4c3c59ab54215591c5b0eb9a26c45a0265e48d96', class: "p-2" }, h("form-control-date", { key: 'aea46abb41595c0cc5d82edd0f1f09425c0a1701', name: "created_before", label: "Created Before", inputHandler: this.handleDateInput, defaultValue: convertToLocal(this.createdBefore, { showInputDateTime: true }) ||
                convertToLocal(filterParams.created_before, { showInputDateTime: true }), showTime: true, disabled: !!this.createdBefore, part: filterParam })), h("div", { key: 'e83af454cde29c12fcd6e2e37093bf70fd03718c', class: "p-2" }, h("form-control-text", { key: '3c5fe84b5883b7df6247ed1eba1a15871cb882b5', name: "company_name", label: "Company Name", inputHandler: this.debouncedSetParamsOnChange, defaultValue: this.companyName || filterParams.company_name, disabled: !!this.companyName, part: filterParam }))))));
    }
    static get is() { return "justifi-terminal-orders-list-filters"; }
    static get encapsulation() { return "shadow"; }
    static get properties() {
        return {
            "orderStatus": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "TerminalOrderStatus",
                    "resolved": "TerminalOrderStatus.canceled | TerminalOrderStatus.completed | TerminalOrderStatus.created | TerminalOrderStatus.in_progress | TerminalOrderStatus.on_hold | TerminalOrderStatus.submitted",
                    "references": {
                        "TerminalOrderStatus": {
                            "location": "import",
                            "path": "../../api",
                            "id": "src/api/index.ts::TerminalOrderStatus"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "order-status"
            },
            "orderType": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "TerminalOrderType",
                    "resolved": "TerminalOrderType.boardingOnly | TerminalOrderType.boardingShipping",
                    "references": {
                        "TerminalOrderType": {
                            "location": "import",
                            "path": "../../api",
                            "id": "src/api/index.ts::TerminalOrderType"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "order-type"
            },
            "createdAfter": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "created-after"
            },
            "createdBefore": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "created-before"
            },
            "companyName": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "company-name"
            }
        };
    }
}
