"use client";
import {
ActionButton,
type ActionButtonProps,
} from "@suphark/ui/components/shared/button/base/action-button";
import { useUiText } from "@suphark/ui/components/shared/ui-text";
import type * as React from "react";
import { ActionAdd, ActionSave } from "../semantic-icons";
interface SubmitButtonProps extends ActionButtonProps {
/**
* Toggles the button's default text/icon between Create and Edit modes.
* Defaults to 'false' (Create mode).
*/
isEditing?: boolean;
/**
* (Optional) Custom text to display when isEditing is false.
* Defaults to `UiText.buttons.createNew` ("สร้างใหม่").
*/
createText?: React.ReactNode;
/**
* (Optional) Custom text to display when isEditing is true.
* Defaults to `UiText.save` ("บันทึก").
*/
editText?: React.ReactNode;
}
/**
* A reusable submit button component for forms.
*
* This component wraps `ActionButton` and sets `type="submit"` by default.
* It's designed to be used within a form and receive its loading state
* from the form's `isSubmitting` state.
*
* @param {boolean} [isLoading] - (Required) Pass the form's `isSubmitting` state here.
* @param {boolean} [isEditing] - (Optional) Toggles between Create (false) and Edit (true) modes.
* @param {React.ReactNode} [children] - (Optional) Explicitly sets the button text, overriding defaults.
* @param {React.ReactNode} [createText] - (Optional) Default text for 'Create' mode if children is not set.
* @param {React.ReactNode} [editText] - (Optional) Default text for 'Edit' mode if children is not set.
* @param {React.ReactElement} [icon] - (Optional) Overrides the default icon.
*/
export function SubmitButton({
children,
icon,
isLoading,
isEditing = false,
createText,
editText,
...props
}: SubmitButtonProps) {
const text = useUiText();
const buttonText =
children ??
(isEditing ? (editText ?? text.save) : (createText ?? text.buttons?.createNew ?? "สร้างใหม่"));
const buttonIcon = icon ?? (isEditing ? : );
return (
{buttonText}
);
}