'use strict';

var index = require('./index-p7cvUYAE.js');
var lodash = require('./lodash-C4mGy21w.js');
var utils = require('./utils-CYONRFR6.js');
var terminalsListParamsState = require('./terminals-list-params-state-vGJZ6Oe2.js');
var parts = require('./parts-BXshb_S-.js');
var styledHost = require('./styled-host-Ch0-dxF-.js');
require('./event-types-YOY5TKUN.js');
require('./config-state-BIgGhhe9.js');
var Plaid = require('./Plaid-CPESyiiV.js');
require('./Pagination-Dediz133.js');
require('./Business-oBifyXkW.js');
require('./_commonjsHelpers-BJu3ubxk.js');
require('./dinero-BwNN_k7x.js');
require('./index-W-zoNiyM.js');

const JustifiTerminalsListFilters = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.setParamsOnChange = (name, value) => {
            terminalsListParamsState.filterParams[name] = value;
        };
        this.handleDateInput = (name, value) => {
            const utcDate = utils.convertToUTC(value, { setExactTime: true });
            this.setParamsOnChange(name, utcDate);
        };
    }
    componentWillLoad() {
        // debounced input handler for text input
        this.debouncedSetParamsOnChange = lodash.lodashExports.debounce(this.setParamsOnChange, 300);
        const propsToSet = {
            terminal_id: this.terminalId,
            status: this.terminalStatus,
            terminal_order_id: this.terminalOrderId,
            provider_id: this.providerId,
            serial_number: this.serialNumber,
            created_after: this.createdAfter,
            created_before: this.createdBefore
        };
        Object.entries(propsToSet).forEach(([key, value]) => {
            if (value) {
                terminalsListParamsState.propsParams[key] = value;
            }
        });
    }
    get terminalStatusOptions() {
        return [
            { label: 'All', value: '' },
            { label: 'Connected', value: Plaid.ITerminalStatus.connected },
            { label: 'Disconnected', value: Plaid.ITerminalStatus.disconnected },
            { label: 'Unknown', value: Plaid.ITerminalStatus.unknown },
            { label: 'Pending Configuration', value: Plaid.ITerminalStatus.pending_configuration },
            { label: 'Archived', value: Plaid.ITerminalStatus.archived }
        ];
    }
    render() {
        const filterMenuParams = Object.assign({}, terminalsListParamsState.filterParams);
        return (index.h(styledHost.StyledHost, { key: '525d0f21fd86348f6fa6f54177f0ad119cf91bf2' }, index.h("table-filters-menu", { key: '70599c95318b14012ca78d108e1e766d1a8c6459', params: filterMenuParams, clearParams: terminalsListParamsState.clearParams, part: parts.filterMenu }, index.h("div", { key: '32c1c355e6a8ac09431f4954484e60670dcc5ff5', class: "grid-cols-2 gap-3 p-1" }, index.h("div", { key: 'ee88118d7a04042cd7f55caaf8cc3aea64fe1760', class: "p-2" }, index.h("form-control-text", { key: 'e56a6496c6fb4263ae571d8ed0f63a9d0a1629da', name: "terminal_id", label: "Terminal ID", inputHandler: this.debouncedSetParamsOnChange, defaultValue: this.terminalId || terminalsListParamsState.filterParams.terminal_id, disabled: !!this.terminalId, part: parts.filterParam })), index.h("div", { key: '2c76c1e127d9cf79b9ed508e6266c33a034597b0', class: "p-2" }, index.h("form-control-text", { key: '75917f144ab87008533d7e2c59c984b6468c36c0', name: "terminal_order_id", label: "Terminal Order ID", inputHandler: this.debouncedSetParamsOnChange, defaultValue: this.terminalOrderId || terminalsListParamsState.filterParams.terminal_order_id, disabled: !!this.terminalOrderId, part: parts.filterParam })), index.h("div", { key: '38162c73f48f3bb2e5f6745c7cf215154fddcbbb', class: "p-2" }, index.h("form-control-text", { key: '096c325deecea07554f5cc8d59a690c8321b6a05', name: "provider_id", label: "Device ID", inputHandler: this.debouncedSetParamsOnChange, defaultValue: this.providerId || terminalsListParamsState.filterParams.provider_id, disabled: !!this.providerId, part: parts.filterParam })), index.h("div", { key: '403264eb68429594acee6a5d97781eafbdb33c81', class: "p-2" }, index.h("form-control-text", { key: 'd39ae5201f328985d72b3a79c65848a49adbbe45', name: "serial_number", label: "Serial Number", inputHandler: this.debouncedSetParamsOnChange, defaultValue: this.serialNumber || terminalsListParamsState.filterParams.serial_number, disabled: !!this.serialNumber, part: parts.filterParam })), index.h("div", { key: 'f609fa409e36463b9e1cd4dc68a6be4d22122553', class: "p-2" }, index.h("form-control-select", { key: 'c19b381e48f030b865003187e470d55b0fcbe373', name: "status", label: "Status", options: this.terminalStatusOptions, inputHandler: this.setParamsOnChange, defaultValue: this.terminalStatus || terminalsListParamsState.filterParams.status || '', disabled: !!this.terminalStatus, part: parts.filterParam })), index.h("div", { key: '12e30437276bf2d7764a61af0a399ea519794904', class: "p-2" }, index.h("form-control-date", { key: 'aa30f779b70a96d9327a2adabdebe5330d453ada', name: "created_after", label: "Created After", inputHandler: this.handleDateInput, defaultValue: utils.convertToLocal(this.createdAfter || terminalsListParamsState.filterParams.created_after, { showInputDateTime: true }), showTime: true, disabled: !!this.createdAfter, part: parts.filterParam })), index.h("div", { key: 'e972337331bb18cdbf1ee40a241ac8de9f7b0553', class: "p-2" }, index.h("form-control-date", { key: 'e76864998f47a37d7fef5b1241a6dd8bc8e8a1a8', name: "created_before", label: "Created Before", inputHandler: this.handleDateInput, defaultValue: utils.convertToLocal(this.createdBefore || terminalsListParamsState.filterParams.created_before, { showInputDateTime: true }), showTime: true, disabled: !!this.createdBefore, part: parts.filterParam }))))));
    }
};

exports.justifi_terminals_list_filters = JustifiTerminalsListFilters;
