import React from "react";
import { Form } from "react-bootstrap";
import { DurationInput } from "src/components/Shared/DurationInput";
import { FilterSelect } from "src/components/Shared/Select";
import DurationUtils from "./duration";
const renderTextArea = (options: {
value: string | undefined;
isEditing: boolean;
onChange: (value: string) => void;
}) => {
return (
) =>
options.onChange(event.currentTarget.value)
}
value={options.value}
/>
);
};
const renderEditableText = (options: {
title?: string;
value?: string | number;
isEditing: boolean;
onChange: (value: string) => void;
}) => {
return (
) =>
options.onChange(event.currentTarget.value)
}
value={
typeof options.value === "number"
? options.value.toString()
: options.value
}
placeholder={options.title}
/>
);
};
const renderInputGroup = (options: {
title?: string;
placeholder?: string;
value: string | undefined;
isEditing: boolean;
url?: string;
onChange?: (value: string) => void;
}) => {
if (options.url && !options.isEditing) {
return (
{options.value}
);
}
return (
) => {
if (options.onChange) {
options.onChange(event.currentTarget.value);
}
}}
/>
);
};
const renderDurationInput = (options: {
value: number | undefined;
isEditing: boolean;
onChange: (value: number | undefined) => void;
}) => {
if (!options.isEditing) {
let durationString;
if (options.value !== undefined) {
durationString = DurationUtils.secondsToString(options.value);
}
return (
);
}
return (
options.onChange(v)}
/>
);
};
const renderHtmlSelect = (options: {
value?: string | number;
isEditing: boolean;
onChange: (value: string) => void;
selectOptions: Array;
}) => {
if (!options.isEditing) {
return (
);
}
return (
) =>
options.onChange(event.currentTarget.value)
}
>
{options.selectOptions.map((opt) => (
))}
);
};
// TODO: isediting
const renderFilterSelect = (options: {
type: "performers" | "studios" | "tags";
initialId: string | undefined;
onChange: (id: string | undefined) => void;
}) => (
options.onChange(items[0]?.id)}
initialIds={options.initialId ? [options.initialId] : []}
/>
);
// TODO: isediting
const renderMultiSelect = (options: {
type: "performers" | "studios" | "tags";
initialIds: string[] | undefined;
onChange: (ids: string[]) => void;
}) => (
options.onChange(items.map((i) => i.id))}
initialIds={options.initialIds ?? []}
/>
);
const EditableTextUtils = {
renderTextArea,
renderEditableText,
renderInputGroup,
renderDurationInput,
renderHtmlSelect,
renderFilterSelect,
renderMultiSelect,
};
export default EditableTextUtils;