import { DroppedItemsObj } from "../DocumentContainer"; import React, { useEffect, useState } from "react"; import { dateFormats, dateTimeFormats, timeFormats } from "../../../../utlity/dateTimeFormats"; import { DroppedItem } from "../../../../utlity/types"; import { IoIosArrowDown } from "react-icons/io"; import { TagsTypes } from "../../../../utlity/types"; import LabelAttr from "./LabelAttr"; import RequiredAttr from "./RequiredAttr"; import CurrTimeStampAttr from "./currTimeStampAttr"; import CommonAttrDropDown from "./CommonAttrDropDown"; import MaskTypePassAttr from "./MaskTypePassAttr"; import TemporalDateAttr from "./TemporalDateAttr"; import SelectTagAttr from "./SelectTagAttr"; import MaxMinLenAttr from "./MaxMinLenAttr"; import RecipientsAttrCon from "./RecipientsAttrCon"; import MovableFieldContainer from "./MovableField"; import DirectionalControls from "./DirectionalControls"; // interface DirectionalControlsProps { // onMove: (direction: 'up' | 'down' | 'left' | 'right') => void; // disabled?: boolean; // stepSize?: number; // className?: string; // } export interface DroppedItemProps { droppedItems: DroppedItem[] selectedTag: DroppedItem setDroppedItems: React.Dispatch> selTagKey: string, selTagIndx: number, signClient: boolean, // DirectionalControlsProps: { // onMove: (direction: 'up' | 'down' | 'left' | 'right', stepSize?: number) => void; // disabled?: boolean; // stepSize?: number; // className?: string; // } } export enum TEXT { PARAGRAPH = "paragraph", SINGLE_LINE = "single_line", PASSWORD = "password", } export enum TEMPORAL { DATE = "date", TIME = "time", DATE_TIME = "date_time", } export enum NUMBER { INTEGER = "integer", DECIMAL = "decimal", CURRENCY = "currency" } export enum SELECT { SINGLE_SELECT = "single select", MULTI_SELECT = "multi select" } export enum MASKTYPE { ALL = "all", LAST_FOUR = "last_four", CREDIT_CARD = "credit_Card", NATIONAL_INSURANCE = "national_insurance", SOCIAL_SECURITY = "social_security", SOCIAL_INSURANCE = "social_insurance" } export enum MASKCHARACTER { ASTERISK = "ASTERISK", DOT = "DOT", X = "CROSS", } export const enumMap = { text: TEXT, temporal: TEMPORAL, number: NUMBER, image: String, select: SELECT } export enum DROPDOWNTOGGLE { TYPE, MASK_TYPE, MASK_CHARACTER, DDMMYY_FORMAT } const defaultStyles = { font: "", italic: false, bold: false, underline: false, color: "#000000", textSize: 0 }; const RightSideBar: React.FC = ({ droppedItems, selectedTag, setDroppedItems, selTagKey, selTagIndx, signClient = false }) => { console.log("Right SideBar Called", selectedTag, selTagKey, selTagIndx, droppedItems) const selectedType = selectedTag.type in enumMap && enumMap[selectedTag.type as keyof typeof enumMap]; const [styles, setStyles] = useState(defaultStyles); const [dropDownToggle, setDropDownToggle] = useState(null); const [decimalPlace, setDecimalPlace] = useState(2) const [styleOpen, setStyleOpen] = useState(false); const handlePropertyChange = (changeTo: string, changeWith: string | boolean | number, is24Hrs = null) => { console.log("changeTo", changeTo, "changeWith", changeWith) if (changeTo === '' || changeWith === '') return if (changeTo === "subType" && typeof changeWith === "string" && changeWith.toLowerCase() === "password") { if (!signClient) { setDroppedItems((prev) => ( { ...prev, [selTagKey]: Array.isArray(prev[selTagKey]) ? prev[selTagKey].map((item, i) => i === selTagIndx ? { ...item, [changeTo]: changeWith, maskType: "All", maskCharacter: "ASTERISK", update: true } : item ) : [], } )); } else { setDroppedItems((prev) => { const updated = [...prev]; updated[selTagIndx] = { ...updated[selTagIndx], [changeTo]: changeWith, maskType: "All", maskCharacter: "ASTERISK", update: true } return updated; }) } } else if (changeTo === "subType" && (changeWith === NUMBER.CURRENCY || changeWith === NUMBER.INTEGER || changeWith === NUMBER.DECIMAL)) { let decPlace = changeWith !== NUMBER.DECIMAL ? 0 : decimalPlace; const isCurrency = changeWith === NUMBER.CURRENCY; // const currencyType = null if (!signClient) { setDroppedItems((prev) => ( { ...prev, [selTagKey]: Array.isArray(prev[selTagKey]) // Ensure it's an array ? prev[selTagKey].map((item, i) => i === selTagIndx ? { ...item, [changeTo]: changeWith, decimalPlace: decPlace, isCurrency, update: true } : item ) : [], }// Provide a fallback in case it's undefined or not an array )); } else { setDroppedItems((prev) => { const updated = [...prev]; updated[selTagIndx] = { ...updated[selTagIndx], [changeTo]: changeWith, decimalPlace: decPlace, isCurrency, update: true } return updated; }) } } else if (changeTo === "format" && selectedTag.subType === TEMPORAL.DATE_TIME) { let val = timeFormats[0].format; if (is24Hrs === null) { val = timeFormats[0].format } else if (!is24Hrs) { val = timeFormats[1].format } else { val = timeFormats[0].format } // console.log("val", val, is24Hrs) // if(is24Hrs === null) { // changeWith = changeWith + " " + val; // } if (!signClient) { setDroppedItems((prev) => { const updatedArray = Array.isArray(prev[selTagKey]) ? prev[selTagKey].map((item, i) => { if (i === selTagIndx) { const updatedItem = { ...item, [changeTo]: changeWith + " " + val, update: true }; console.log('Updating item at index', i, 'with:', updatedItem); return updatedItem; } return item; }) : []; return { ...prev, [selTagKey]: updatedArray, }; }); } else { setDroppedItems((prev) => { const updated = [...prev]; updated[selTagIndx] = { ...updated[selTagIndx], [changeTo]: changeWith + " " + val, update: true } return updated; }) } } else { if (!signClient) { setDroppedItems((prev) => { const updatedItems = Array.isArray(prev[selTagKey]) ? prev[selTagKey].map((item, i) => i === selTagIndx ? { ...item, [changeTo]: changeWith, update: true } : item ) : []; return { ...prev, [selTagKey]: updatedItems, }; }); } else { setDroppedItems((prev) => { const updated = [...prev]; updated[selTagIndx] = { ...updated[selTagIndx], [changeTo]: changeWith, update: true } return updated; }) } } setDropDownToggle(null) } useEffect(() => { if (selectedTag.subType === TEMPORAL.DATE || selectedTag.subType === TEMPORAL.DATE_TIME || selectedTag.subType === TEMPORAL.TIME) { if (selectedTag.subType === TEMPORAL.DATE) { handlePropertyChange("format", dateFormats[0].format) } else if (selectedTag.subType === TEMPORAL.DATE_TIME) { handlePropertyChange("format", dateTimeFormats[0].format) } else if (selectedTag.subType === TEMPORAL.TIME) { handlePropertyChange("format", timeFormats[0].format) } } }, [selectedTag.subType]) useEffect(() => { if (selectedTag.label === "temporal") { handlePropertyChange("subType", TEMPORAL.DATE); handlePropertyChange("format", "DD/MM/YY"); } }, []) const handleDecimalPlace = (e: React.ChangeEvent) => { const val = Number(e.target.value) setDecimalPlace(val) handlePropertyChange("decimalPlace", val) } // useEffect(() => { // if ("styles" in selectedTag) { // console.log("styles" in selectedTag) // const fontSize = selectedTag?.styles?.textSize; // const tagHeight = selectedTag?.dimensions?.height - 18; // console.log(fontSize) // if (selectedTag.subType !== TEXT.PASSWORD && selectedTag.subType !== TEXT.PARAGRAPH && tagHeight > (fontSize + fontSize)) { // handlePropertyChange("subType", TEXT.PARAGRAPH) // } else if (selectedTag.subType !== TEXT.PASSWORD && selectedTag.subType !== TEXT.SINGLE_LINE && tagHeight <= (fontSize + fontSize)) { // console.log("Change subType Called from elseif") // handlePropertyChange("subType", TEXT.SINGLE_LINE) // } // } // }, [selectedTag]) useEffect(() => { if (!selectedTag) return; if (!selectedTag.styles) { handlePropertyChange("styles", defaultStyles); setStyles(defaultStyles); } else { setStyles({ ...defaultStyles, ...selectedTag.styles }); } // Optional subType logic const fontSize = selectedTag?.styles?.textSize || defaultStyles.textSize; const tagHeight = selectedTag?.dimensions?.height - 18; if ( selectedTag.type === TagsTypes.TEXT && selectedTag.subType !== TEXT.PASSWORD && selectedTag.subType !== TEXT.PARAGRAPH && tagHeight > fontSize * 2 ) { handlePropertyChange("subType", TEXT.PARAGRAPH); } else if ( selectedTag.subType !== TEXT.PASSWORD && selectedTag.subType !== TEXT.SINGLE_LINE && tagHeight <= fontSize * 2 ) { handlePropertyChange("subType", TEXT.SINGLE_LINE); } }, [selectedTag]); const handleStyleChange = (key, value) => { const updatedStyles = { ...(selectedTag.styles ?? defaultStyles), [key]: value }; setStyles(updatedStyles); handlePropertyChange("styles", updatedStyles); }; const handleDirectionalMove = (direction: 'up' | 'down' | 'left' | 'right', stepSize: number = 5) => { if (!selectedTag) return; const currentItem = droppedItems[selTagKey]?.[selTagIndx]; if (!currentItem) return; let newLeft = currentItem.dimensions.left; let newTop = currentItem.dimensions.top; switch (direction) { case 'up': newTop = Math.max(0, newTop - stepSize); break; case 'down': newTop = newTop + stepSize; break; case 'left': newLeft = Math.max(0, newLeft - stepSize); break; case 'right': newLeft = newLeft + stepSize; break; } if (!signClient) { setDroppedItems({ ...droppedItems, [selTagKey]: Array.isArray(droppedItems[selTagKey]) ? droppedItems[selTagKey].map((item, i) => i === selTagIndx ? { ...item, dimensions: { ...item.dimensions, left: newLeft, top: newTop }, update: true } : item ) : [], }); } else { setDroppedItems((prev) => { const updated = [...prev]; updated[selTagIndx] = { ...updated[selTagIndx], dimensions: { ...item.dimensions, left: newLeft, top: newTop }, update: true } return updated; }) } }; const directionalControlsHandler = (direction: 'up' | 'down' | 'left' | 'right') => { handleDirectionalMove(direction, 5); // Use default stepSize of 5 }; const handleDirectPositionChange = (newLeft: number, newTop: number) => { if (!selectedTag) return; const currentItem = droppedItems[selTagKey]?.[selTagIndx]; if (!currentItem) return; // Ensure values are not negative const clampedLeft = Math.max(0, newLeft); const clampedTop = Math.max(0, newTop); if (!signClient) { setDroppedItems({ ...droppedItems, [selTagKey]: Array.isArray(droppedItems[selTagKey]) ? droppedItems[selTagKey].map((item, i) => i === selTagIndx ? { ...item, dimensions: { ...item.dimensions, left: clampedLeft, top: clampedTop }, update: true } : item ) : [], }); } else { setDroppedItems((prev) => { const updated = [...prev]; updated[selTagIndx] = { ...item, dimensions: { ...item.dimensions, left: clampedLeft, top: clampedTop }, update: true } return updated }) } }; const DirectionalControlsProps = { onMove: directionalControlsHandler, onPositionChange: handleDirectPositionChange, disabled: false, stepSize: 5, className: '' } return ( <> {/* Right Side Bar Start */}

Properties


{ } {selectedTag.label && } {(selectedTag.type !== TagsTypes.SIGNATURE && selectedTag.type !== TagsTypes.INITIALS) && <> } {selectedTag.type.toLowerCase() === TagsTypes.TEMPORAL && } { selectedType && Object.keys(selectedType).length > 0 && } {/* Mask Type */} { selectedTag?.subType === TEXT.PASSWORD && } {/* TEMPORAL DATE FORMAT - START */} { (selectedTag?.subType === TEMPORAL.DATE || selectedTag?.subType === TEMPORAL.TIME || selectedTag?.subType === TEMPORAL.DATE_TIME) && } {/* TEMPORAL DATE FORMAT - END */} {/* NUMBER - DECIMAL PLACES */} { selectedTag?.subType === NUMBER.DECIMAL &&
handleDecimalPlace(e)} value={decimalPlace} className="bg-slate-100 w-full outline-none p-2 rounded" />
} { (selectedTag?.subType === SELECT.SINGLE_SELECT || selectedTag?.subType === SELECT.MULTI_SELECT) && } { (selectedTag.type.toLowerCase() === TagsTypes.TEXT || selectedTag.type.toLowerCase() === TagsTypes.COMPANY) && } {(selectedTag.type.toLowerCase() !== TagsTypes.SIGNATURE && selectedTag.type.toLowerCase() !== TagsTypes.INITIALS) &&
setStyleOpen(!styleOpen)} >
{ styleOpen && <> {/* Font */}
handleStyleChange("font", e.target.value)} />
{/* Text Size */}
handleStyleChange("textSize", parseInt(e.target.value, 10) || 0) } />
{/* Color */}
handleStyleChange("color", e.target.value)} />
{/* Toggles for Bold, Italic, Underline */}
}
}
{/* Right Side Bar End */} ) } export default RightSideBar