import { Btn } from "../../../components/btn";
import { Locale } from "../../../components/locale";
import type { TGetCNFunction } from "../../../utils/react/useCN";
import type { IModal, TPresetData } from "../config/types";

/**
 * Получает части внутреннего контента для готового пресета модального окна
 * @returns {TPresetData}
 */
export const getPresetPartials = (preset: IModal["preset"], idModal: IModal["id"], getCN: TGetCNFunction): TPresetData => {
  switch (preset) {
    case "confirm": {
      const confirmHandlerCfg = { action: "confirm", id: idModal };
      const cancelHandlerCfg = { action: "cancel", id: idModal };
      return {
        titleSlot: <Locale code={"modals.confirmTitle"} />,
        contentSlot: null,
        footerSlot: (
          <ul className={getCN("list")}>
            <li key={0}>
              <Btn extraAttrs={{ "data-js-modal-handler": JSON.stringify(confirmHandlerCfg) }}>
                <span className={"btn__label"}>
                  <Locale code={"modals.confirmBtn"} />
                </span>
              </Btn>
            </li>
            <li key={1}>
              <Btn isLight={true} extraAttrs={{ "data-js-modal-handler": JSON.stringify(cancelHandlerCfg) }}>
                <span className={"btn__label"}>
                  <Locale code={"modals.cancelBtn"} />
                </span>
              </Btn>
            </li>
          </ul>
        ),
      };
    }
    case "error":
      return {
        titleSlot: <Locale code={"modals.errorTitle"} />,
        contentSlot: <Locale code={"modals.defaultError"} />,
        footerSlot: null,
      };
    case "success":
      return {
        titleSlot: <Locale code={"modals.successTitle"} />,
        contentSlot: <Locale code={"modals.defaultSuccess"} />,
        footerSlot: null,
      };
    default:
      return {
        titleSlot: null,
        contentSlot: null,
        footerSlot: null,
      };
  }
};
