"use client";
import { EVENT_TYPES, useEventHandlerStore } from "@store/EventHandler.Store";
import { useConfirmStore } from "@store/Confirm.Store";
import Saveable from "@components/Saveable/Saveable";

export default function UserEditLayout({ children }: { children: React.ReactNode }) {
    const confirm = useConfirmStore();
    const eventHandler = useEventHandlerStore();

    return (
        <>
            <Saveable
                onClick={() => {
                    confirm.show(
                        "Estas seguro que queres cambiar la contraseña? Esta acción no se puede deshacer. Será necesario volver a iniciar sesión.",
                        () => {
                            eventHandler.setEventType(EVENT_TYPES.SAVE);
                        },
                        () => {
                            eventHandler.setEventType(EVENT_TYPES.CLEAR);
                        }
                    );
                }}
            >
                {children}
            </Saveable>
        </>
    );
}
