import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { Icon, PowerhouseButton } from "@powerhousedao/design-system";
import { useState } from "react";
import { useForm } from "react-hook-form";
import { Disclosure } from "../disclosure/disclosure.js";
import { Divider } from "../divider/divider.js";
import { AvailableOfflineToggle } from "./inputs/available-offline-toggle.js";
import { DeleteDrive } from "./inputs/delete-drive.js";
import { DriveNameInput } from "./inputs/drive-name-input.js";
import { Label } from "./inputs/label.js";
import { LocationInfo } from "./inputs/location-info.js";
import { SharingTypeFormInput } from "./inputs/sharing-type-form-input.js";
export function DriveSettingsForm(props) {
    const { drive, sharingType, availableOffline, onSubmit, handleDeleteDrive } = props;
    const name = drive.header.name;
    const [showLocationSettings, setShowLocationSettings] = useState(false);
    const [showDangerZone, setShowDangerZone] = useState(false);
    const [showDeleteDrive, setShowDeleteDrive] = useState(false);
    const { register, handleSubmit, control } = useForm({
        mode: "onBlur",
        defaultValues: {
            name,
            sharingType,
            availableOffline,
        },
    });
    const location = sharingType === "PUBLIC" ? "SWITCHBOARD" : sharingType;
    return (_jsxs("form", { onSubmit: handleSubmit(onSubmit), children: [_jsx(DriveNameInput, { ...register("name") }), _jsx(Divider, { className: "my-4" }), _jsx(Label, { htmlFor: "sharingType", children: "Sharing settings" }), _jsx(SharingTypeFormInput, { control: control }), _jsx(Divider, { className: "my-3" }), _jsxs(Disclosure, { isOpen: showLocationSettings, onOpenChange: () => setShowLocationSettings(!showLocationSettings), title: "Location", children: [_jsx(LocationInfo, { location: location }), _jsx(AvailableOfflineToggle, { ...register("availableOffline") })] }), _jsx(Divider, { className: "my-3" }), _jsx(Disclosure, { isOpen: showDangerZone, onOpenChange: () => setShowDangerZone(!showDangerZone), title: "Danger zone", children: _jsxs("button", { className: "flex gap-2 py-3 font-semibold text-red-900 transition hover:brightness-125", onClick: () => setShowDeleteDrive(true), type: "button", children: [_jsx(Icon, { name: "Trash" }), "Delete drive"] }) }), showDeleteDrive && showDangerZone ? (_jsx(DeleteDrive, { drive: drive, handleDeleteDrive: handleDeleteDrive, onCancel: () => setShowDeleteDrive(false) })) : (_jsxs(_Fragment, { children: [_jsx(Divider, { className: "my-3" }), _jsx(PowerhouseButton, { className: "mb-4 w-full", type: "submit", children: "Confirm" })] }))] }));
}
//# sourceMappingURL=drive-settings-form.js.map