import React from 'react';
import { MessageResponse } from '../../components/MessageResponse.js';
import { Text } from '../../ink.js';
import { truncate } from '../../utils/format.js';
import type { CreateOutput } from './CronCreateTool.js';
import type { UpdateOutput } from './CronUpdateTool.js';
import type { DeleteOutput } from './CronDeleteTool.js';
import type { ListOutput } from './CronListTool.js';

// --- CronCreate -------------------------------------------------------------

export function renderCreateToolUseMessage(input: Partial<{
  cron: string;
  prompt: string;
}>): React.ReactNode {
  return `${input.cron ?? ''}${input.prompt ? `: ${truncate(input.prompt, 60, true)}` : ''}`;
}
export function renderCreateResultMessage(output: CreateOutput): React.ReactNode {
  return <MessageResponse>
      <Text>
        Scheduled <Text bold>{output.id}</Text>{' '}
        <Text dimColor>({output.humanSchedule})</Text>
      </Text>
    </MessageResponse>;
}

// --- CronUpdate -------------------------------------------------------------

export function renderUpdateToolUseMessage(input: Partial<{
  id: string;
}>): React.ReactNode {
  return input.id ?? '';
}
export function renderUpdateResultMessage(output: UpdateOutput): React.ReactNode {
  if (!output.updated) {
    return <MessageResponse>
        <Text dimColor>Job {output.id} not found</Text>
      </MessageResponse>;
  }
  return <MessageResponse>
      <Text>
        Updated <Text bold>{output.id}</Text>{' '}
        <Text dimColor>({output.humanSchedule})</Text>
      </Text>
    </MessageResponse>;
}

// --- CronDelete -------------------------------------------------------------

export function renderDeleteToolUseMessage(input: Partial<{
  id: string;
}>): React.ReactNode {
  return input.id ?? '';
}
export function renderDeleteResultMessage(output: DeleteOutput): React.ReactNode {
  return <MessageResponse>
      <Text>
        Cancelled <Text bold>{output.id}</Text>
      </Text>
    </MessageResponse>;
}

// --- CronList ---------------------------------------------------------------

export function renderListToolUseMessage(): React.ReactNode {
  return '';
}
export function renderListResultMessage(output: ListOutput): React.ReactNode {
  if (output.jobs.length === 0) {
    return <MessageResponse>
        <Text dimColor>No scheduled jobs</Text>
      </MessageResponse>;
  }
  return <MessageResponse>
      {output.jobs.map(j => <Text key={j.id}>
          <Text bold>{j.id}</Text>{j.name ? <Text> [{j.name}]</Text> : null} <Text dimColor>{j.humanSchedule}</Text>{j.folder ? <Text dimColor> ({j.folder})</Text> : null}
        </Text>)}
    </MessageResponse>;
}

// --- Shared -----------------------------------------------------------------
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJSZWFjdCIsIk1lc3NhZ2VSZXNwb25zZSIsIlRleHQiLCJ0cnVuY2F0ZSIsIkNyZWF0ZU91dHB1dCIsIkRlbGV0ZU91dHB1dCIsIkxpc3RPdXRwdXQiLCJyZW5kZXJDcmVhdGVUb29sVXNlTWVzc2FnZSIsImlucHV0IiwiUGFydGlhbCIsImNyb24iLCJwcm9tcHQiLCJSZWFjdE5vZGUiLCJyZW5kZXJDcmVhdGVSZXN1bHRNZXNzYWdlIiwib3V0cHV0IiwiaWQiLCJodW1hblNjaGVkdWxlIiwicmVuZGVyRGVsZXRlVG9vbFVzZU1lc3NhZ2UiLCJyZW5kZXJEZWxldGVSZXN1bHRNZXNzYWdlIiwicmVuZGVyTGlzdFRvb2xVc2VNZXNzYWdlIiwicmVuZGVyTGlzdFJlc3VsdE1lc3NhZ2UiLCJqb2JzIiwibGVuZ3RoIiwibWFwIiwiaiJdLCJzb3VyY2VzIjpbIlVJLnRzeCJdLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgUmVhY3QgZnJvbSAncmVhY3QnXG5pbXBvcnQgeyBNZXNzYWdlUmVzcG9uc2UgfSBmcm9tICcuLi8uLi9jb21wb25lbnRzL01lc3NhZ2VSZXNwb25zZS5qcydcbmltcG9ydCB7IFRleHQgfSBmcm9tICcuLi8uLi9pbmsuanMnXG5pbXBvcnQgeyB0cnVuY2F0ZSB9IGZyb20gJy4uLy4uL3V0aWxzL2Zvcm1hdC5qcydcbmltcG9ydCB0eXBlIHsgQ3JlYXRlT3V0cHV0IH0gZnJvbSAnLi9Dcm9uQ3JlYXRlVG9vbC5qcydcbmltcG9ydCB0eXBlIHsgRGVsZXRlT3V0cHV0IH0g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