'use strict';

var index = require('./index-p7cvUYAE.js');
var lodash = require('./lodash-C4mGy21w.js');
require('./config-state-BIgGhhe9.js');
var utils = require('./utils-CYONRFR6.js');
var Plaid = require('./Plaid-CPESyiiV.js');
require('./Pagination-Dediz133.js');
require('./Business-oBifyXkW.js');
var checkoutsListParamsState = require('./checkouts-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('./_commonjsHelpers-BJu3ubxk.js');
require('./index-W-zoNiyM.js');
require('./dinero-BwNN_k7x.js');

const JustifiCheckoutsListFilters = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.setParamsOnChange = (name, value) => {
            checkoutsListParamsState.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 = {
            status: this.checkoutStatus,
            payment_mode: this.paymentMode,
            checkout_id: this.checkoutId,
            successful_payment_id: this.successfulPaymentId,
            created_after: this.createdAfter,
            created_before: this.createdBefore
        };
        Object.entries(propsToSet).forEach(([key, value]) => {
            if (value) {
                checkoutsListParamsState.propsParams[key] = value;
            }
        });
    }
    get checkoutStatusOptions() {
        return [
            { label: 'All', value: '' },
            { label: 'Created', value: Plaid.ICheckoutStatus.created },
            { label: 'Completed', value: Plaid.ICheckoutStatus.completed },
            { label: 'Attempted', value: Plaid.ICheckoutStatus.attempted },
            { label: 'Expired', value: Plaid.ICheckoutStatus.expired },
        ];
    }
    get checkoutPaymentModeOptions() {
        return [
            { label: 'All', value: '' },
            { label: 'E-commerce', value: Plaid.ICheckoutPaymentModeParam.ecom },
            { label: 'BNPL', value: Plaid.ICheckoutPaymentModeParam.bnpl },
            { label: 'Apple Pay', value: Plaid.ICheckoutPaymentModeParam.apple_pay },
        ];
    }
    render() {
        const filterMenuParams = Object.assign({}, checkoutsListParamsState.filterParams);
        return (index.h(styledHost.StyledHost, { key: '1c4b39ee0103e6905affa774f202dd76f147bc89' }, index.h("table-filters-menu", { key: '9cb0457d0e6ce05925f4e0da04532008020dd46e', params: filterMenuParams, clearParams: checkoutsListParamsState.clearParams, part: parts.filterMenu }, index.h("div", { key: 'e5c370717e3cf2571f2017d185c7f3ea08eab1c8', class: "grid-cols-2 gap-3 p-1" }, index.h("div", { key: '2e3c1832bb800fa9065b189a299234fafa7eb4e3', class: "p-2" }, index.h("form-control-text", { key: '33e1e31d842aa0b8c47e3ea1bc12cc860691f5e3', name: "checkout_id", label: "Checkout ID", inputHandler: this.debouncedSetParamsOnChange, defaultValue: this.checkoutId || checkoutsListParamsState.filterParams.checkout_id, disabled: !!this.checkoutId, part: parts.filterParam })), index.h("div", { key: '4dcfe2f56d8405f376eb4aa52deaea0fb64e8ff5', class: "p-2" }, index.h("form-control-text", { key: '272ba42827048aa45ada6090eaf9574950ebaca2', name: "successful_payment_id", label: "Successful Payment ID", inputHandler: this.debouncedSetParamsOnChange, defaultValue: this.successfulPaymentId || checkoutsListParamsState.filterParams.successful_payment_id, disabled: !!this.successfulPaymentId, part: parts.filterParam })), index.h("div", { key: '7c4e0ad12e0031a70aeaec5a0423d9b0b45c70a4', class: "p-2" }, index.h("form-control-select", { key: '87775c3a0d1de63301dde682f79a7c2c11a4958b', name: "status", label: "Status", options: this.checkoutStatusOptions, inputHandler: this.setParamsOnChange, defaultValue: this.checkoutStatus || checkoutsListParamsState.filterParams.status || '', disabled: !!this.checkoutStatus, part: parts.filterParam })), index.h("div", { key: 'e751b51d9e2725addd6e9b082bf326fc039b0a7a', class: "p-2" }, index.h("form-control-select", { key: '642fc1af53bc89d1604a864f4088781096cd24a2', name: "payment_mode", label: "Payment Mode", options: this.checkoutPaymentModeOptions, inputHandler: this.setParamsOnChange, defaultValue: this.paymentMode || checkoutsListParamsState.filterParams.payment_mode || '', disabled: !!this.paymentMode, part: parts.filterParam })), index.h("div", { key: 'a95638261e002677c51299342d34bafc8a8615b4', class: "p-2" }, index.h("form-control-date", { key: 'ca017b89e5ae0ea3f4d55ade8de2acbdc2062c86', name: "created_after", label: "Created After", inputHandler: this.handleDateInput, defaultValue: utils.convertToLocal(this.createdAfter, { showInputDateTime: true }) ||
                utils.convertToLocal(checkoutsListParamsState.filterParams.created_after, { showInputDateTime: true }), showTime: true, disabled: !!this.createdAfter, part: parts.filterParam })), index.h("div", { key: '0585dff7f655db9da4f3c2124eac6c90b74dbe3b', class: "p-2" }, index.h("form-control-date", { key: '50fee01232661f33c1996549cf6523c92dc937c4', name: "created_before", label: "Created Before", inputHandler: this.handleDateInput, defaultValue: utils.convertToLocal(this.createdBefore, { showInputDateTime: true }) ||
                utils.convertToLocal(checkoutsListParamsState.filterParams.created_before, { showInputDateTime: true }), showTime: true, disabled: !!this.createdBefore, part: parts.filterParam }))))));
    }
};

exports.justifi_checkouts_list_filters = JustifiCheckoutsListFilters;
