(() => {
    "use strict";
    const e = window.wc.blocksCheckout, t = window.React, n = window.wp.element, o = window.wp.i18n,
        c = window.wp.data, {ExperimentalOrderMeta: l} = wc.blocksCheckout;

    function a({handleDeliveryPointChange: e, alsendoConnectDeliveryPoint: n}) {
        return (0, t.createElement)("div", {
            className: "apaczka-delivery-point-wrap",
            style: {display: "none"}
        }, (0, t.createElement)("input", {value: n, type: "text", id: "apaczka-point", onChange: e}))
    }

    const i = JSON.parse('{"apiVersion":2,"name":"alsendo-connect/block","version":"1.0.0","title":"Alsendo Connect Map Button","category":"woocommerce","description":"This code adds map button and adds input to save delivery point data.","supports":{"html":false,"align":false,"multiple":false,"reusable":false},"parent":["woocommerce/checkout-shipping-methods-block"],"attributes":{"lock":{"type":"object","default":{"remove":true,"move":true}},"text":{"type":"string","source":"html","selector":".wp-block-alsendo-connect","default":""}},"textdomain":"alsendo-connect","editorStyle":""}');
    (0, e.registerCheckoutBlock)({
        metadata: i, component: ({checkoutExtensionData: e, extensions: i}) => {
            let s = !1, r = null;
            const [d, p] = (0, n.useState)(""), {setExtensionData: u} = e, m = "alsendo-connect-delivery-point-error", {
                setValidationErrors: h,
                clearValidationError: w
            } = (0, c.useDispatch)("wc/store/validation");
            let g = (0, c.useSelect)((e => e("wc/store/cart").getShippingRates()));
            const [_, k] = (0, n.useState)(!1),
                f = (0, c.useSelect)((e => e("wc/store/checkout").prefersCollection()), []);
            if ((0, n.useEffect)((() => {
                k(f)
            }), [f]), (0, n.useEffect)((() => {
                const e = () => {
                    const e = document.getElementById("shipping-method");
                    if (!e) return;
                    const t = e.querySelectorAll(".wc-block-checkout__shipping-method-option"),
                        n = e.querySelector(".wc-block-checkout__shipping-method-option--selected");
                    if (n && t.length > 0) {
                        const e = Array.from(t).indexOf(n), o = 1 === e;
                        console.log("Selected shipping method index:", e), console.log("isPickup shipping method:", o), o && w(m), k(o)
                    }
                };
                e();
                const t = document.getElementById("shipping-method");
                if (t) {
                    t.addEventListener("click", (t => {
                        setTimeout(e, 100)
                    }));
                    const n = new MutationObserver((() => {
                        e()
                    }));
                    return n.observe(t, {
                        childList: !0,
                        subtree: !0,
                        attributes: !0,
                        attributeFilter: ["class"]
                    }), () => {
                        n.disconnect()
                    }
                }
            }), []), null != g) {
                let e = g[Object.keys(g)[0]];
                if (null != e && e.hasOwnProperty("shipping_rates")) {
                    const t = e.shipping_rates, n = [],
                        o = window.alsendo_connect_block && window.alsendo_connect_block.map_config ? window.alsendo_connect_block.map_config : [];
                    if (null != t) {
                        for (let e of t) if ("pickup_location" !== e.method_id) {
                            if (!0 === e.selected) {
                                r = e.instance_id, e.method_id, null != o[r] && (s = !0)
                            }
                            n.push(e)
                        }
                        if (!r && n.length > 0) {
                            const e = document.getElementsByClassName("wc-block-components-shipping-rates-control")[0];
                            if (null != e) {
                                const t = e.querySelector('input[name^="radio-control-"]:checked');
                                if (null != t) {
                                    let e = t.getAttribute("id");
                                    if (null != e) {
                                        let t = e.split(":");
                                        r = t[t.length - 1], t[0], null != o[r] && (s = !0)
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return (0, n.useEffect)((() => {
                u("apaczka_pl", "apaczka-point", d), d || !s || _ ? w(m) : h({
                    [m]: {
                        message: (0, o.__)("Parcel locker must be choosen.", "alsendo-connect"),
                        hidden: !0
                    }
                })
            }), [d, s, u, _]), (0, t.createElement)(t.Fragment, null, s && !_ && (0, t.createElement)(t.Fragment, null, (0, t.createElement)("button", {
                className: "button alt alsendo_geowidget_show_map_block_checkout",
                id: "geowidget_show_map"
            }, (0, o.__)("Select delivery point", "alsendo-connect")), (0, t.createElement)("div", {
                id: "apaczka_selected_point_data_wrap",
                className: "apaczka_selected_point_data_wrap",
                style: {display: "none"}
            }), (0, t.createElement)(l, null, (0, t.createElement)(a, {
                alsendoConnectDeliveryPoint: d,
                handleDeliveryPointChange: e => {
                    const t = e.target.value;
                    p(t)
                }
            }))))
        }
    })
})();