import { DocumentUpload } from "iconsax-react";
import { useEditorStore, type ToolType } from "@/pages/editor/store/editorStore";
import Button from "@/components/Button";

const DocumentUploadComponent = () => {
    return (
        <div className="space-y-4">
            <div>
                <label className="block text-sm mb-2">آپلود سند</label>
                <input
                    type="file"
                    accept=".pdf,.doc,.docx"
                    onChange={(e) => {
                        const file = e.target.files?.[0];
                        if (file) {
                            const reader = new FileReader();
                            reader.onload = (event) => {
                                const fileUrl = event.target?.result as string;
                                const newDocument = {
                                    id: `document-${Date.now()}`,
                                    type: "document" as ToolType,
                                    x: 100,
                                    y: 100,
                                    width: 200,
                                    height: 250,
                                    imageUrl: fileUrl,
                                };
                                const { addObject, setSelectedObjectId, setTool } = useEditorStore.getState();
                                addObject(newDocument);
                                setSelectedObjectId(newDocument.id);
                                setTool("select");
                            };
                            reader.readAsDataURL(file);
                        }
                    }}
                    className="hidden"
                    id="document-upload"
                />
                <Button
                    variant="outline"
                    onClick={() => document.getElementById("document-upload")?.click()}
                    className="w-full"
                >
                    <DocumentUpload size={20} />
                    انتخاب سند
                </Button>
            </div>
        </div>
    );
};

export default DocumentUploadComponent;

