import { Signal, useSignalEffect } from "@preact/signals"
import { Source, VirtualFile, VirtualTextFile } from "$/apps/source";
import { memo, useEffect } from "preact/compat";

export const Edit = memo(function Edit(props: Edit.Props) {
    const source = props.source as Signal<VirtualFile>;
    const title = props.title;

    useEffect(() => {
        props.contentReady.value = true
    }, [])
    
    useSignalEffect(() => {
        title.value = `${source.value.name} - moed`;
    })

    return <div class="text_content">
        {(source.value as VirtualTextFile).content}
    </div>
})

namespace Edit {
    export type Props = {
        source: Signal<Source>,
        title: Signal<string | undefined>,
        contentReady: Signal<boolean>
    }
}
