import EdenDatesSelector from "../block/eden-dates-selector.js";
import { buildConfirmCancelButtons, openPluginModal, } from "./modal-controller.js";
import t from "../../i18n/index.js";
export default class SelectDatesModal {
    constructor(changeSelection, copiedDates, selectedDates) {
        this.updateDates = () => {
            this.changeSelection(this.datesSelector.getDates());
        };
        this.pasteDates = () => {
            if (!this.copiedDates)
                return;
            this.datesSelector.updateDates(this.copiedDates);
        };
        this.changeSelection = changeSelection;
        this.selectedDates = JSON.parse(selectedDates || "[]");
        this.copiedDates = copiedDates ? JSON.parse(copiedDates) : null;
        this.datesSelector = new EdenDatesSelector(this.selectedDates);
    }
    init() {
        const baseButtons = buildConfirmCancelButtons({
            confirmLabel: t("common.apply"),
            onConfirm: this.updateDates,
        });
        const buttons = this.copiedDates
            ? [
                {
                    value: t("modals.select-dates.paste-dates"),
                    cssClass: "option",
                    onClick: this.pasteDates,
                    keepOpened: true,
                },
                ...baseButtons,
            ]
            : baseButtons;
        this.modal = openPluginModal({
            icon: "calendar",
            width: 620,
            title: t("modals.select-dates.title"),
            content: this.datesSelector,
            buttons,
        });
    }
}
