define([], function () {
    'use strict';

    return function (Component) {
        return Component.extend({
            initialize: function () {
                this._super();

                if (this.dataScope !== 'shippingFields.shipping_date') {
                    return this;
                }

                var config = window.checkoutConfig && window.checkoutConfig.portalpeopleShippingFields;
                var disabledWeekdays = config && Array.isArray(config.disabledWeekdays)
                    ? config.disabledWeekdays
                    : [];
                var disabledDates = config && Array.isArray(config.disabledDates)
                    ? config.disabledDates
                    : [];

                if (!this.options) {
                    this.options = {};
                }

                if (disabledWeekdays.length > 0 || disabledDates.length > 0) {
                    this.options.beforeShowDay = function (date) {
                        // Check if weekday is disabled
                        var dayIndex = date.getDay();
                        if (disabledWeekdays.indexOf(dayIndex) !== -1) {
                            return [false, '', 'Unavailable'];
                        }

                        // Check if specific date is disabled
                        var dateString = date.getFullYear() + '-' +
                            String(date.getMonth() + 1).padStart(2, '0') + '-' +
                            String(date.getDate()).padStart(2, '0');
                        if (disabledDates.indexOf(dateString) !== -1) {
                            return [false, '', 'Unavailable'];
                        }

                        return [true, '', ''];
                    };
                }

                return this;
            }
        });
    };
});
